Skip to content

Commit a5b0dc3

Browse files
authored
testdata: add testdata package (#3940)
* chore: add testdata package * testdata: fix build * chore: use exact version number instead of workspace:* * chore: add 4844 testdata to testdata packgae * chore: refactor testdata * chore: npm i * chore: migrate more test files2 * refactor: eip4844 test data2 * refactor: migate withdrawals geth genesis * refactor: gethGenesis misc data cleanup * refactor: migrate goerli and other test data * refactor: post merge geth genesis * fix: failing tests * refactor: more geth genesis test data * refactor: prelondon test data * chore: restructure folder * refactor: consolidate 4844 files and create chainConfigs folder * chore: add missing allocations * client: fix test * monorepo: remove build step
1 parent d6d3858 commit a5b0dc3

File tree

139 files changed

+465
-11712
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

139 files changed

+465
-11712
lines changed

package-lock.json

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"test:node": "npm run test:node --workspaces --if-present",
2121
"test:browser": "npm run test:browser --workspaces --if-present",
2222
"preinstall": "npm run checkNpmVersion",
23-
"postinstall": "npm run build --workspaces",
23+
"postinstall": "npm run build --workspaces --if-present",
2424
"prepare": "git config --local core.hooksPath .githooks",
2525
"sc": "npm run spellcheck",
2626
"sort-package-json": "sort-package-json \"package.json\" \"packages/*/package.json\"",

packages/block/examples/clique.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import { createBlock } from '@ethereumjs/block'
22
import { Common, Hardfork } from '@ethereumjs/common'
3+
import { goerliChainConfig } from '@ethereumjs/testdata'
34

4-
import { Goerli } from '../test/testdata/goerliCommon.ts'
5-
6-
const common = new Common({ chain: Goerli, hardfork: Hardfork.Chainstart })
5+
const common = new Common({ chain: goerliChainConfig, hardfork: Hardfork.Chainstart })
76

87
console.log(common.consensusType()) // 'poa'
98
console.log(common.consensusAlgorithm()) // 'clique'

packages/block/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
"ethereum-cryptography": "^3.1.0"
5959
},
6060
"devDependencies": {
61+
"@ethereumjs/testdata": "1.0.0",
6162
"@paulmillr/trusted-setups": "^0.1.2",
6263
"micro-eth-signer": "^0.14.0"
6364
},

packages/block/test/block.spec.ts

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
import { Common, Hardfork, Mainnet, createCustomCommon } from '@ethereumjs/common'
22
import { RLP } from '@ethereumjs/rlp'
3+
import {
4+
goerliChainConfig,
5+
preLondonTestDataBlocks1,
6+
preLondonTestDataBlocks2,
7+
testnetMergeChainConfig,
8+
} from '@ethereumjs/testdata'
39
import { createLegacyTx } from '@ethereumjs/tx'
410
import { KECCAK256_RLP_ARRAY, bytesToHex, equalsBytes, hexToBytes, toBytes } from '@ethereumjs/util'
511
import { assert, describe, it } from 'vitest'
@@ -17,11 +23,7 @@ import {
1723
} from '../src/index.ts'
1824

1925
import { genesisHashesTestData } from './testdata/genesisHashesTest.ts'
20-
import { Goerli } from './testdata/goerliCommon.ts'
2126
import { testdataFromRPCGoerliData } from './testdata/testdata-from-rpc-goerli.ts'
22-
import { testdataPreLondon2Data } from './testdata/testdata_pre-london-2.ts'
23-
import { testdataPreLondonData } from './testdata/testdata_pre-london.ts'
24-
import { testnetMergeData } from './testdata/testnetMerge.ts'
2527

2628
import type { NestedUint8Array, PrefixedHexString } from '@ethereumjs/util'
2729

@@ -83,7 +85,7 @@ describe('[Block]: block functions', () => {
8385
})
8486

8587
it('initialization -> setHardfork option', () => {
86-
const common = createCustomCommon(testnetMergeData, Mainnet)
88+
const common = createCustomCommon(testnetMergeChainConfig, Mainnet)
8789

8890
let block = createBlock(
8991
{
@@ -135,7 +137,7 @@ describe('[Block]: block functions', () => {
135137

136138
it('should test block validation on pow chain', async () => {
137139
const common = new Common({ chain: Mainnet, hardfork: Hardfork.Istanbul })
138-
const blockRlp = hexToBytes(testdataPreLondonData.blocks[0].rlp as PrefixedHexString)
140+
const blockRlp = hexToBytes(preLondonTestDataBlocks1.blocks[0].rlp as PrefixedHexString)
139141
try {
140142
createBlockFromRLP(blockRlp, { common })
141143
assert.isTrue(true, 'should pass')
@@ -145,7 +147,7 @@ describe('[Block]: block functions', () => {
145147
})
146148

147149
it('should test block validation on poa chain', async () => {
148-
const common = new Common({ chain: Goerli, hardfork: Hardfork.Chainstart })
150+
const common = new Common({ chain: goerliChainConfig, hardfork: Hardfork.Chainstart })
149151

150152
try {
151153
createBlockFromRPC(testdataFromRPCGoerliData, [], { common })
@@ -161,7 +163,7 @@ describe('[Block]: block functions', () => {
161163
}
162164

163165
it('should test transaction validation - invalid tx trie', async () => {
164-
const blockRlp = hexToBytes(testdataPreLondonData.blocks[0].rlp as PrefixedHexString)
166+
const blockRlp = hexToBytes(preLondonTestDataBlocks1.blocks[0].rlp as PrefixedHexString)
165167
const common = new Common({ chain: Mainnet, hardfork: Hardfork.London })
166168
const block = createBlockFromRLP(blockRlp, { common, freeze: false })
167169
await testTransactionValidation(block)
@@ -203,7 +205,7 @@ describe('[Block]: block functions', () => {
203205

204206
it('should test transaction validation with legacy tx in london', async () => {
205207
const common = new Common({ chain: Mainnet, hardfork: Hardfork.London })
206-
const blockRlp = hexToBytes(testdataPreLondonData.blocks[0].rlp as PrefixedHexString)
208+
const blockRlp = hexToBytes(preLondonTestDataBlocks1.blocks[0].rlp as PrefixedHexString)
207209
const block = createBlockFromRLP(blockRlp, { common, freeze: false })
208210
await testTransactionValidation(block)
209211
// @ts-expect-error -- Assigning to read-only property
@@ -217,7 +219,7 @@ describe('[Block]: block functions', () => {
217219

218220
it('should test uncles hash validation', async () => {
219221
const common = new Common({ chain: Mainnet, hardfork: Hardfork.Istanbul })
220-
const blockRlp = hexToBytes(testdataPreLondon2Data.blocks[2].rlp as PrefixedHexString)
222+
const blockRlp = hexToBytes(preLondonTestDataBlocks2.blocks[2].rlp as PrefixedHexString)
221223
const block = createBlockFromRLP(blockRlp, { common, freeze: false })
222224
assert.equal(block.uncleHashIsValid(), true)
223225
// @ts-expect-error -- Assigning to read-only property
@@ -355,7 +357,7 @@ describe('[Block]: block functions', () => {
355357
it('should return the same block data from raw()', () => {
356358
const common = new Common({ chain: Mainnet, hardfork: Hardfork.Istanbul })
357359
const block = createBlockFromRLP(
358-
toBytes(testdataPreLondon2Data.blocks[2].rlp as PrefixedHexString),
360+
toBytes(preLondonTestDataBlocks2.blocks[2].rlp as PrefixedHexString),
359361
{
360362
common,
361363
},
@@ -367,7 +369,7 @@ describe('[Block]: block functions', () => {
367369
it('should test toJSON', () => {
368370
const common = new Common({ chain: Mainnet, hardfork: Hardfork.Istanbul })
369371
const block = createBlockFromRLP(
370-
toBytes(testdataPreLondon2Data.blocks[2].rlp as PrefixedHexString),
372+
toBytes(preLondonTestDataBlocks2.blocks[2].rlp as PrefixedHexString),
371373
{
372374
common,
373375
},
@@ -377,7 +379,7 @@ describe('[Block]: block functions', () => {
377379

378380
it('DAO hardfork', () => {
379381
const blockData = RLP.decode(
380-
testdataPreLondon2Data.blocks[0].rlp as PrefixedHexString,
382+
preLondonTestDataBlocks2.blocks[0].rlp as PrefixedHexString,
381383
) as NestedUint8Array
382384
// Set block number from test block to mainnet DAO fork block 1920000
383385
blockData[0][8] = hexToBytes('0x1D4C00')

packages/block/test/clique.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ import {
1313
createSealedCliqueBlockHeader,
1414
} from '../src/index.ts'
1515

16-
import { Goerli } from './testdata/goerliCommon.ts'
16+
import { goerliChainConfig } from '@ethereumjs/testdata'
1717

1818
describe('[Header]: Clique PoA Functionality', () => {
19-
const common = new Common({ chain: Goerli, hardfork: Hardfork.Chainstart })
19+
const common = new Common({ chain: goerliChainConfig, hardfork: Hardfork.Chainstart })
2020

2121
it('Header Data', () => {
2222
let header = createBlockHeader({ number: 1 })

packages/block/test/eip4844block.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ import { fakeExponential, getNumBlobs } from '../src/helpers.ts'
1414
import { createBlock, createBlockHeader } from '../src/index.ts'
1515
import { paramsBlock } from '../src/params.ts'
1616

17-
import { hardfork4844Data } from './testdata/4844-hardfork.ts'
17+
import { eip4844GethGenesis } from '@ethereumjs/testdata'
1818

1919
import type { TypedTransaction } from '@ethereumjs/tx'
2020

2121
describe('EIP4844 header tests', () => {
2222
const kzg = new microEthKZG(trustedSetup)
2323

24-
const common = createCommonFromGethGenesis(hardfork4844Data, {
24+
const common = createCommonFromGethGenesis(eip4844GethGenesis, {
2525
chain: 'customChain',
2626
hardfork: Hardfork.Cancun,
2727
customCrypto: { kzg },
@@ -96,7 +96,7 @@ describe('EIP4844 header tests', () => {
9696
describe('blob gas tests', () => {
9797
const kzg = new microEthKZG(trustedSetup)
9898

99-
const common = createCommonFromGethGenesis(hardfork4844Data, {
99+
const common = createCommonFromGethGenesis(eip4844GethGenesis, {
100100
chain: 'customChain',
101101
hardfork: Hardfork.Cancun,
102102
params: paramsBlock,
@@ -154,7 +154,7 @@ describe('blob gas tests', () => {
154154
describe('transaction validation tests', () => {
155155
const kzg = new microEthKZG(trustedSetup)
156156

157-
const common = createCommonFromGethGenesis(hardfork4844Data, {
157+
const common = createCommonFromGethGenesis(eip4844GethGenesis, {
158158
chain: 'customChain',
159159
hardfork: Hardfork.Cancun,
160160
params: paramsBlock,

packages/block/test/from-beacon-payload.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ import { assert, describe, expect, it } from 'vitest'
55

66
import { createBlockFromBeaconPayloadJSON, createBlockHeader } from '../src/index.ts'
77

8-
import { devnet4844Config } from './testdata/4844-devnet.ts'
8+
import { eip4844GethGenesis } from '@ethereumjs/testdata'
99
import { payloadKaustinenData } from './testdata/payload-kaustinen.ts'
1010
import { payloadSlot87335Data } from './testdata/payload-slot-87335.ts'
1111
import { payloadSlot87475Data } from './testdata/payload-slot-87475.ts'
12-
import { testnetVerkleKaustinenData } from './testdata/testnetVerkleKaustinen.ts'
12+
import { verkleKaustinenGethGenesis } from './testdata/testnetVerkleKaustinen.ts'
1313

1414
const kzg = new microEthKZG(trustedSetup)
1515
describe('[fromExecutionPayloadJSON]: 4844 devnet 5', () => {
16-
const commonConfig = { ...devnet4844Config }
16+
const commonConfig = { ...eip4844GethGenesis }
1717
commonConfig.config = { ...commonConfig.config, chainId: 4844001005 }
1818
const network = 'sharding'
1919
const common = createCommonFromGethGenesis(commonConfig, {
@@ -74,7 +74,7 @@ describe('[fromExecutionPayloadJSON]: kaustinen', () => {
7474
const network = 'kaustinen'
7575

7676
// safely change chainId without modifying underlying json
77-
const common = createCommonFromGethGenesis(testnetVerkleKaustinenData, {
77+
const common = createCommonFromGethGenesis(verkleKaustinenGethGenesis, {
7878
chain: network,
7979
eips: [6800],
8080
})

packages/block/test/from-rpc.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import {
88
createBlockHeaderFromRPC,
99
} from '../src/index.ts'
1010

11+
import { goerliChainConfig } from '@ethereumjs/testdata'
1112
import { alchemy14151203Data } from './testdata/alchemy14151203.ts'
12-
import { Goerli } from './testdata/goerliCommon.ts'
1313
import { infuraGoerliBlock10536893Data } from './testdata/infura-goerli-block-10536893.ts'
1414
import { infura2000004withTransactionsData } from './testdata/infura2000004withTransactions.ts'
1515
import { infura2000004withoutTransactionsData } from './testdata/infura2000004withoutTransactions.ts'
@@ -91,7 +91,7 @@ describe('[fromRPC]:', () => {
9191
})
9292

9393
it('should create a block from london hardfork', () => {
94-
const common = new Common({ chain: Goerli, hardfork: Hardfork.London })
94+
const common = new Common({ chain: goerliChainConfig, hardfork: Hardfork.London })
9595
const block = createBlockFromRPC(testdataFromRPCGoerliLondonData, [], { common })
9696
assert.equal(
9797
`0x${block.header.baseFeePerGas?.toString(16)}`,
@@ -172,7 +172,7 @@ describe('[fromRPC] - Alchemy/Infura API block responses', () => {
172172
})
173173

174174
it('should correctly parse a cancun block over rpc', () => {
175-
const common = new Common({ chain: Goerli, hardfork: Hardfork.Cancun })
175+
const common = new Common({ chain: goerliChainConfig, hardfork: Hardfork.Cancun })
176176
const block = createBlockHeaderFromRPC(infuraGoerliBlock10536893Data, { common }) // cspell:disable-line
177177
const hash = hexToBytes(infuraGoerliBlock10536893Data.hash)
178178
assert.isTrue(equalsBytes(block.hash(), hash))

packages/block/test/header.spec.ts

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { Common, Hardfork, Mainnet } from '@ethereumjs/common'
22
import { RLP } from '@ethereumjs/rlp'
3+
import { goerliBlocks, goerliChainConfig, mainnetBlocks } from '@ethereumjs/testdata'
34
import {
45
KECCAK256_RLP,
56
KECCAK256_RLP_ARRAY,
@@ -21,9 +22,6 @@ import {
2122
} from '../src/index.ts'
2223

2324
import { bcBlockGasLimitTestData } from './testdata/bcBlockGasLimitTest.ts'
24-
import { blocksGoerliData } from './testdata/blocks_goerli.ts'
25-
import { blocksMainnetData } from './testdata/blocks_mainnet.ts'
26-
import { Goerli } from './testdata/goerliCommon.ts'
2725

2826
import type { CliqueConfig } from '@ethereumjs/common'
2927
import type { PrefixedHexString } from '@ethereumjs/util'
@@ -177,7 +175,7 @@ describe('[Block]: Header functions', () => {
177175
})
178176

179177
it('Initialization -> Clique Blocks', () => {
180-
const common = new Common({ chain: Goerli, hardfork: Hardfork.Chainstart })
178+
const common = new Common({ chain: goerliChainConfig, hardfork: Hardfork.Chainstart })
181179
const header = createBlockHeader({ extraData: new Uint8Array(97) }, { common })
182180
assert.isDefined(bytesToHex(header.hash()), 'default block should initialize')
183181
})
@@ -219,7 +217,7 @@ describe('[Block]: Header functions', () => {
219217
)
220218

221219
// PoA
222-
common = new Common({ chain: Goerli, hardfork: Hardfork.Chainstart })
220+
common = new Common({ chain: goerliChainConfig, hardfork: Hardfork.Chainstart })
223221
genesis = createBlock({ header: { extraData: new Uint8Array(97) } }, { common })
224222

225223
parentHash = genesis.hash()
@@ -271,7 +269,7 @@ describe('[Block]: Header functions', () => {
271269
})
272270

273271
it('should skip consensusFormatValidation if flag is set to false', () => {
274-
const common = new Common({ chain: Goerli, hardfork: Hardfork.Chainstart })
272+
const common = new Common({ chain: goerliChainConfig, hardfork: Hardfork.Chainstart })
275273

276274
assert.doesNotThrow(
277275
() =>
@@ -319,7 +317,7 @@ describe('[Block]: Header functions', () => {
319317
it('header validation -> poa checks', () => {
320318
const headerData = testDataPreLondon.blocks[0].blockHeader
321319
322-
const common = new Common({ chain: Goerli, hardfork: Hardfork.Istanbul })
320+
const common = new Common({ chain: goerliChainConfig, hardfork: Hardfork.Istanbul })
323321
const blockchain = new Mockchain()
324322
325323
const genesisRlp = toBytes(testDataPreLondon.genesisRLP)
@@ -453,15 +451,15 @@ describe('[Block]: Header functions', () => {
453451

454452
it('should test hash() function', () => {
455453
let common = new Common({ chain: Mainnet, hardfork: Hardfork.Chainstart })
456-
let header = createBlockHeader(blocksMainnetData[0]['header'], { common })
454+
let header = createBlockHeader(mainnetBlocks[0]['header'], { common })
457455
assert.equal(
458456
bytesToHex(header.hash()),
459457
'0x88e96d4537bea4d9c05d12549907b32561d3bf31f45aae734cdc119f13406cb6',
460458
'correct PoW hash (mainnet block 1)',
461459
)
462460

463-
common = new Common({ chain: Goerli, hardfork: Hardfork.Chainstart })
464-
header = createBlockHeader(blocksGoerliData[0]['header'], { common })
461+
common = new Common({ chain: goerliChainConfig, hardfork: Hardfork.Chainstart })
462+
header = createBlockHeader(goerliBlocks[0]['header'], { common })
465463
assert.equal(
466464
bytesToHex(header.hash()),
467465
'0x8f5bab218b6bb34476f51ca588e9f4553a3a7ce5e13a66c660a5283e97e9a85a',

0 commit comments

Comments
 (0)