From d276fcc103533fdf7eec12b55f202efc74ceeea4 Mon Sep 17 00:00:00 2001 From: Jochem Brouwer Date: Thu, 21 Jul 2022 15:11:19 +0200 Subject: [PATCH] CI: ensure all hardforks and transitions run when there is a "test all hardforks" label on PR (#1901) * vm/tests: update CI * block: semi-address Berlin->London transition bug * vm: add test for transitionTests * ci: update runnerrs * common: fix test * vm: update test count * ci: add london --- .github/workflows/vm-pr.yml | 29 ++++++++------ packages/block/src/header.ts | 9 +++++ packages/blockchain/src/blockchain.ts | 4 +- packages/common/src/common.ts | 18 +++++++++ packages/common/tests/eips.spec.ts | 12 ++++++ packages/vm/package.json | 5 ++- packages/vm/tests/tester/config.ts | 55 ++++++++++++++------------- 7 files changed, 91 insertions(+), 41 deletions(-) diff --git a/.github/workflows/vm-pr.yml b/.github/workflows/vm-pr.yml index f436fdf1b8..7d7dc63abe 100644 --- a/.github/workflows/vm-pr.yml +++ b/.github/workflows/vm-pr.yml @@ -134,19 +134,26 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - # Args to pass to the tester. Note that some have split the slow tests and only - # run on forks where applicable (see PR #489 for numbers on these) - - # Tests were split with --dir and --excludeDir to balance execution times below the 9min mark. + # Args to pass to the tester. args: [ - '--fork=Berlin --expected-test-amount=33', - '--fork=Constantinople --dir=GeneralStateTests/stTimeConsuming --expected-test-amount=15561', - '--fork=Constantinople --excludeDir=stTimeConsuming --expected-test-amount=16836', - '--fork=Petersburg --dir=GeneralStateTests/stTimeConsuming --expected-test-amount=15561', - '--fork=Petersburg --excludeDir=stTimeConsuming --expected-test-amount=16821', - '--fork=Homestead --expected-test-amount=6623', - '--fork=Chainstart --expected-test-amount=4044', + '--fork=Chainstart --verify-test-amount-alltests', + '--fork=Homestead --verify-test-amount-alltests', + '--fork=TangerineWhistle --verify-test-amount-alltests', + '--fork=SpuriousDragon --verify-test-amount-alltests', + '--fork=Byzantium --verify-test-amount-alltests', + '--fork=Constantinople --verify-test-amount-alltests', + '--fork=Petersburg --verify-test-amount-alltests', + '--fork=Istanbul --verify-test-amount-alltests', + '--fork=MuirGlacier --verify-test-amount-alltests', + '--fork=Berlin --verify-test-amount-alltests', + '--fork=London --verify-test-amount-alltests', + '--fork=ByzantiumToConstantinopleFixAt5 --verify-test-amount-alltests', + '--fork=EIP158ToByzantiumAt5 --verify-test-amount-alltests', + '--fork=FrontierToHomesteadAt5 --verify-test-amount-alltests', + '--fork=HomesteadToDaoAt5 --verify-test-amount-alltests', + '--fork=HomesteadToEIP150At5 --verify-test-amount-alltests', + '--fork=BerlinToLondonAt5 --verify-test-amount-alltests', ] fail-fast: false steps: diff --git a/packages/block/src/header.ts b/packages/block/src/header.ts index e01c185fd3..8ccb698f22 100644 --- a/packages/block/src/header.ts +++ b/packages/block/src/header.ts @@ -135,6 +135,15 @@ export class BlockHeader { throw new Error('invalid header. Less values than expected were received') } + // eslint-disable-next-line @typescript-eslint/strict-boolean-expressions + if (opts.common?.isActivatedEIP(1559) && baseFeePerGas === undefined) { + const eip1559ActivationBlock = bigIntToBuffer(opts.common?.eipBlock(1559)!) + // eslint-disable-next-line @typescript-eslint/strict-boolean-expressions + if (eip1559ActivationBlock && eip1559ActivationBlock.equals(number)) { + throw new Error('invalid header. baseFeePerGas should be provided') + } + } + return new BlockHeader( { parentHash, diff --git a/packages/blockchain/src/blockchain.ts b/packages/blockchain/src/blockchain.ts index a1d92f5c4e..c608ac1592 100644 --- a/packages/blockchain/src/blockchain.ts +++ b/packages/blockchain/src/blockchain.ts @@ -586,13 +586,13 @@ export class Blockchain implements BlockchainInterface { } // check blockchain dependent EIP1559 values - if (this._common.isActivatedEIP(1559) === true) { + if (header._common.isActivatedEIP(1559) === true) { // check if the base fee is correct let expectedBaseFee const londonHfBlock = this._common.hardforkBlock(Hardfork.London) const isInitialEIP1559Block = number === londonHfBlock if (isInitialEIP1559Block) { - expectedBaseFee = this._common.param('gasConfig', 'initialBaseFee') + expectedBaseFee = header._common.param('gasConfig', 'initialBaseFee') } else { expectedBaseFee = parentHeader.calcNextBaseFee() } diff --git a/packages/common/src/common.ts b/packages/common/src/common.ts index 9023f2d25f..5e42c9a814 100644 --- a/packages/common/src/common.ts +++ b/packages/common/src/common.ts @@ -547,6 +547,24 @@ export class Common extends EventEmitter { return BigInt(block) } + /** + * Returns the hardfork change block for eip + * @param eip EIP number + * @returns Block number or null if unscheduled + */ + eipBlock(eip: number): bigint | null { + for (const hfChanges of HARDFORK_CHANGES) { + const hf = hfChanges[1] + if ('eips' in hf) { + // eslint-disable-next-line @typescript-eslint/strict-boolean-expressions + if (hf['eips'].includes(eip)) { + return this.hardforkBlock(hfChanges[0]) + } + } + } + return null + } + /** * Returns the hardfork change total difficulty (Merge HF) for hardfork provided or set * @param hardfork Hardfork name, optional if HF set diff --git a/packages/common/tests/eips.spec.ts b/packages/common/tests/eips.spec.ts index 4af5cd5ba4..cef5110185 100644 --- a/packages/common/tests/eips.spec.ts +++ b/packages/common/tests/eips.spec.ts @@ -58,4 +58,16 @@ tape('[Common/EIPs]: Initialization / Chain params', function (t: tape.Test) { st.end() }) + + t.test('eipBlock', function (st: tape.Test) { + const c = new Common({ chain: Chain.Mainnet }) + + let msg = 'should return correct value' + st.ok(c.eipBlock(1559)! === 12965000n, msg) + + msg = 'should return null for unscheduled eip' + st.equal(c.eipBlock(0), null, msg) + + st.end() + }) }) diff --git a/packages/vm/package.json b/packages/vm/package.json index 4b4b31665a..46c93a6e58 100644 --- a/packages/vm/package.json +++ b/packages/vm/package.json @@ -27,12 +27,13 @@ "tape": "tape -r ts-node/register --stack-size=1500", "tester": "ts-node ./tests/tester --stack-size=1500", "test:state": "npm run tester -- --state", - "test:state:allForks": "echo 'Chainstart Homestead dao TangerineWhistle SpuriousDragon Byzantium Constantinople Petersburg Istanbul MuirGlacier Berlin London ByzantiumToConstantinopleFixAt5 EIP158ToByzantiumAt5 FrontierToHomesteadAt5 HomesteadToDaoAt5 HomesteadToEIP150At5' | xargs -n1 | xargs -I v1 npm run test:state -- --fork=v1 --verify-test-amount-alltests", + "test:state:allForks": "echo 'Chainstart Homestead dao TangerineWhistle SpuriousDragon Byzantium Constantinople Petersburg Istanbul MuirGlacier Berlin London ByzantiumToConstantinopleFixAt5 EIP158ToByzantiumAt5 FrontierToHomesteadAt5 HomesteadToDaoAt5 HomesteadToEIP150At5 BerlinToLondonAt5' | xargs -n1 | xargs -I v1 npm run test:state -- --fork=v1 --verify-test-amount-alltests", "test:state:selectedForks": "echo 'Homestead TangerineWhistle SpuriousDragon Petersburg Berlin London' | xargs -n1 | xargs -I v1 npm run test:state -- --fork=v1 --verify-test-amount-alltests", "test:state:slow": "npm run test:state -- --runSkipped=slow", "test:buildIntegrity": "npm run test:state -- --test='stackOverflow'", "test:blockchain": "npm run tester -- --blockchain", - "test:blockchain:allForks": "echo 'Chainstart Homestead dao TangerineWhistle SpuriousDragon Byzantium Constantinople Petersburg Istanbul MuirGlacier Berlin London ByzantiumToConstantinopleFixAt5 EIP158ToByzantiumAt5 FrontierToHomesteadAt5 HomesteadToDaoAt5 HomesteadToEIP150At5' | xargs -n1 | xargs -I v1 npm run tester -- --blockchain --fork=v1 --verify-test-amount-alltests", + "test:blockchain:allForks": "echo 'Chainstart Homestead dao TangerineWhistle SpuriousDragon Byzantium Constantinople Petersburg Istanbul MuirGlacier Berlin London ByzantiumToConstantinopleFixAt5 EIP158ToByzantiumAt5 FrontierToHomesteadAt5 HomesteadToDaoAt5 HomesteadToEIP150At5 BerlinToLondonAt5' | xargs -n1 | xargs -I v1 npm run tester -- --blockchain --fork=v1 --verify-test-amount-alltests", + "test:blockchain:transitionForks": "echo 'ByzantiumToConstantinopleFixAt5 EIP158ToByzantiumAt5 FrontierToHomesteadAt5 HomesteadToDaoAt5 HomesteadToEIP150At5 BerlinToLondonAt5' | xargs -n1 | xargs -I v1 npm run tester -- --blockchain --fork=v1 --verify-test-amount-alltests", "test:API": "npm run tape -- './tests/api/**/*.spec.ts'", "test:API:browser": "karma start karma.conf.js", "test": "echo \"[INFO] Generic test cmd not used. See package.json for more specific test run cmds.\"", diff --git a/packages/vm/tests/tester/config.ts b/packages/vm/tests/tester/config.ts index 0dabfa4c48..8d8490c5a8 100644 --- a/packages/vm/tests/tester/config.ts +++ b/packages/vm/tests/tester/config.ts @@ -263,16 +263,17 @@ export function getTestDirs(network: string, testType: string) { * @returns {Common} the Common which should be used */ export function getCommon(targetNetwork: string) { - let network = targetNetwork.toLowerCase() + let network = targetNetwork + const networkLowercase = network.toLowerCase() if (network.includes('+')) { const index = network.indexOf('+') network = network.slice(0, index) } - if (normalHardforks.map((str) => str.toLowerCase()).includes(network)) { + if (normalHardforks.map((str) => str.toLowerCase()).includes(networkLowercase)) { // normal hard fork, return the common with this hard fork // find the right upper/lowercased version const hfName = normalHardforks.reduce((previousValue, currentValue) => - currentValue.toLowerCase() === network ? currentValue : previousValue + currentValue.toLowerCase() === networkLowercase ? currentValue : previousValue ) const mainnetCommon = new Common({ chain: Chain.Mainnet, hardfork: hfName }) const hardforks = mainnetCommon.hardforks() @@ -355,36 +356,38 @@ export function getCommon(targetNetwork: string) { const expectedTestsFull: any = { BlockchainTests: { - Chainstart: 4385, - Homestead: 7001, + Chainstart: 4496, + Homestead: 7321, Dao: 0, - TangerineWhistle: 4255, - SpuriousDragon: 4305, - Byzantium: 15379, - Constantinople: 32750, - Petersburg: 32735, - Istanbul: 35378, - MuirGlacier: 35378, - Berlin: 33, + TangerineWhistle: 4609, + SpuriousDragon: 4632, + Byzantium: 15703, + Constantinople: 33146, + Petersburg: 33128, + Istanbul: 38773, + MuirGlacier: 38773, + Berlin: 41872, + London: 61547, ByzantiumToConstantinopleFixAt5: 3, EIP158ToByzantiumAt5: 3, - FrontierToHomesteadAt5: 12, - HomesteadToDaoAt5: 18, + FrontierToHomesteadAt5: 13, + HomesteadToDaoAt5: 32, HomesteadToEIP150At5: 3, - BerlinToLondonAt5: 0, + BerlinToLondonAt5: 24, }, GeneralStateTests: { - Chainstart: 896, - Homestead: 1847, + Chainstart: 1045, + Homestead: 2078, Dao: 0, - TangerineWhistle: 969, - SpuriousDragon: 1094, - Byzantium: 4626, - Constantinople: 10402, - Petersburg: 10397, - Istanbul: 10715, - MuirGlacier: 10715, - Berlin: 13065, + TangerineWhistle: 1200, + SpuriousDragon: 1325, + Byzantium: 4857, + Constantinople: 10648, + Petersburg: 10642, + Istanbul: 12439, + MuirGlacier: 12439, + Berlin: 13214, + London: 19449, ByzantiumToConstantinopleFixAt5: 0, EIP158ToByzantiumAt5: 0, FrontierToHomesteadAt5: 0,