Skip to content

Commit c85974a

Browse files
client: migrate test files from json to js objects (#3653)
* common: test data * devp2p: test data * block: convert block test data * blockchain: convert blockchain test data * client: convert sim json configs * block: adjust BeaconPayloadJSON type * block: adjust from beacon payload test * block: adjust from rpc test * block: adjust remaining blocks test data * block: add chainconfig type * block: adjust types and fix test * blockchain: adjust blockchain test data * blockchain: adjust blockchain test data * client: adjust test type issues * devp2p: fix test type issues * tx: fix test import * devp2p: disable cspell for testdata * monorepo: fix spelling * common: remove unnecessary json parsing * vm: fix type issue in runTx * client: fix type issue in import * vm: fix import * util: add numeric string type * block: use numeric string type * client: migrate test data from json to ts * client: adjust tests * monorepo: misc type issues * vm: fix test imports * client: fix some tests * client: fix geth genesis --------- Co-authored-by: Holger Drewes <[email protected]>
1 parent 0041c53 commit c85974a

File tree

91 files changed

+9864
-9771
lines changed

Some content is hidden

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

91 files changed

+9864
-9771
lines changed

packages/client/src/rpc/modules/engine/CLConnectionManager.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@ type CLConnectionManagerOpts = {
3535
inActivityCb?: () => void
3636
}
3737

38-
type NewPayload = {
38+
export type NewPayload = {
3939
payload: ExecutionPayloadV1 | ExecutionPayloadV2 | ExecutionPayloadV3
4040
response?: PayloadStatusV1
4141
}
4242

43-
type ForkchoiceUpdate = {
43+
export type ForkchoiceUpdate = {
4444
state: ForkchoiceStateV1
4545
response?: ForkchoiceResponseV1
4646
headBlock?: Block

packages/client/test/execution/vmexecution.spec.ts

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,15 @@ import { Chain } from '../../src/blockchain/index.js'
99
import { Config } from '../../src/config.js'
1010
import { VMExecution } from '../../src/execution/index.js'
1111
import { closeRPC, setupChain } from '../rpc/helpers.js'
12-
import blocksDataGoerli from '../testdata/blocks/goerli.json'
13-
import blocksDataMainnet from '../testdata/blocks/mainnet.json'
14-
import testnet from '../testdata/common/testnet.json'
15-
import shanghaiJSON from '../testdata/geth-genesis/withdrawals.json'
12+
import { goerliData } from '../testdata/blocks/goerli.js'
13+
import { mainnetData } from '../testdata/blocks/mainnet.js'
14+
import { testnetData } from '../testdata/common/testnet.js'
15+
import { withdrawalsData } from '../testdata/geth-genesis/withdrawals.js'
1616

17-
import type { BlockData, ExecutionPayload } from '@ethereumjs/block'
17+
import type { ExecutionPayload } from '@ethereumjs/block'
1818
import type { Blockchain } from '@ethereumjs/blockchain'
19-
import type { ChainConfig } from '@ethereumjs/common'
2019

21-
const shanghaiPayload = {
20+
const shanghaiPayload: ExecutionPayload = {
2221
blockNumber: '0x1',
2322
parentHash: '0xfe950635b1bd2a416ff6283b0bbd30176e1b1125ad06fa729da9f3f4c1c61710',
2423
feeRecipient: '0xaa00000000000000000000000000000000000000',
@@ -115,7 +114,7 @@ describe('[VMExecution]', () => {
115114
let newHead = await (exec.vm.blockchain as Blockchain).getIteratorHead!()
116115
assert.deepEqual(newHead.hash(), oldHead.hash(), 'should not modify blockchain on empty run')
117116

118-
blockchain = await createBlockchainFromBlocksData(blocksDataMainnet as BlockData[], {
117+
blockchain = await createBlockchainFromBlocksData(mainnetData, {
119118
validateBlocks: true,
120119
validateConsensus: false,
121120
})
@@ -124,7 +123,7 @@ describe('[VMExecution]', () => {
124123
newHead = await (exec.vm.blockchain as Blockchain).getIteratorHead!()
125124
assert.equal(newHead.header.number, BigInt(5), 'should run all blocks')
126125

127-
const common = createCustomCommon(testnet as ChainConfig, Mainnet)
126+
const common = createCustomCommon(testnetData, Mainnet)
128127
exec = await testSetup(blockchain, common)
129128
await exec.run()
130129
assert.equal(exec.hardfork, 'byzantium', 'should update HF on block run')
@@ -137,7 +136,7 @@ describe('[VMExecution]', () => {
137136
})
138137
let exec = await testSetup(blockchain)
139138

140-
blockchain = await createBlockchainFromBlocksData(blocksDataMainnet as BlockData[], {
139+
blockchain = await createBlockchainFromBlocksData(mainnetData, {
141140
validateBlocks: true,
142141
validateConsensus: false,
143142
})
@@ -181,7 +180,7 @@ describe('[VMExecution]', () => {
181180
let newHead = await (exec.vm.blockchain as Blockchain).getIteratorHead!()
182181
assert.deepEqual(newHead.hash(), oldHead.hash(), 'should not modify blockchain on empty run')
183182

184-
blockchain = await createBlockchainFromBlocksData(blocksDataGoerli as BlockData[], {
183+
blockchain = await createBlockchainFromBlocksData(goerliData, {
185184
validateBlocks: true,
186185
validateConsensus: false,
187186
common,
@@ -193,11 +192,11 @@ describe('[VMExecution]', () => {
193192
})
194193

195194
it('Block execution / Hardforks PoA (goerli)', async () => {
196-
const { server, execution, blockchain } = await setupChain(shanghaiJSON, 'post-merge', {
195+
const { server, execution, blockchain } = await setupChain(withdrawalsData, 'post-merge', {
197196
engine: true,
198197
})
199198

200-
const block = await createBlockFromExecutionPayload(shanghaiPayload as ExecutionPayload, {
199+
const block = await createBlockFromExecutionPayload(shanghaiPayload, {
201200
common: new Common({ chain: Mainnet, hardfork: Hardfork.Shanghai }),
202201
})
203202
const oldHead = await blockchain.getIteratorHead()

packages/client/test/integration/beaconsync.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ import { createCommonFromGethGenesis } from '@ethereumjs/common'
33
import { assert, describe, it, vi } from 'vitest'
44

55
import { Event } from '../../src/types.js'
6-
import genesisJSON from '../testdata/geth-genesis/post-merge.json'
6+
import { postMergeData } from '../testdata/geth-genesis/post-merge.js'
77

88
import { destroy, setup, wait } from './util.js'
99

10-
const common = createCommonFromGethGenesis(genesisJSON, { chain: 'post-merge' })
10+
const common = createCommonFromGethGenesis(postMergeData, { chain: 'post-merge' })
1111
common.setHardforkBy({ blockNumber: BigInt(0) })
1212

1313
describe('should sync blocks', async () => {

packages/client/test/integration/util.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ export async function setup(
6060
safeReorgDistance: 0,
6161
})
6262
// attach server to centralized event bus
63-
;(server.config as any).events = serviceConfig.events
63+
server.config.events = serviceConfig.events
6464
const serviceOpts = {
6565
config: serviceConfig,
6666
chain,

packages/client/test/rpc/debug/getRawReceipts.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { encodeReceipt } from '@ethereumjs/vm'
1313
import { loadKZG } from 'kzg-wasm'
1414
import { assert, describe, it } from 'vitest'
1515

16-
import pow from '../../testdata/geth-genesis/pow.json'
16+
import { powData } from '../../testdata/geth-genesis/pow.js'
1717
import {
1818
dummy,
1919
getRPCClient,
@@ -29,7 +29,7 @@ const method2 = 'debug_getRawReceipts'
2929

3030
describe(method, () => {
3131
it('call with legacy tx', async () => {
32-
const { chain, common, execution, server } = await setupChain(pow, 'pow')
32+
const { chain, common, execution, server } = await setupChain(powData, 'pow')
3333
const rpc = getRPCClient(server)
3434
// construct tx
3535
const tx = createLegacyTx(
@@ -55,7 +55,7 @@ describe(method, () => {
5555

5656
it('call with 1559 tx', async () => {
5757
const { chain, common, execution, server } = await setupChain(
58-
gethGenesisStartLondon(pow),
58+
gethGenesisStartLondon(powData),
5959
'powLondon',
6060
)
6161
const rpc = getRPCClient(server)
@@ -86,7 +86,7 @@ describe(method, () => {
8686
})
8787

8888
it('call with unknown block hash', async () => {
89-
const { server } = await setupChain(pow, 'pow')
89+
const { server } = await setupChain(powData, 'pow')
9090
const rpc = getRPCClient(server)
9191
// get a random tx hash
9292
const res = await rpc.request(method, [

packages/client/test/rpc/debug/getRawTransaction.spec.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { createFeeMarket1559Tx, createLegacyTx } from '@ethereumjs/tx'
22
import { bytesToHex } from '@ethereumjs/util'
33
import { assert, describe, it } from 'vitest'
44

5-
import pow from '../../testdata/geth-genesis/pow.json'
5+
import { powData } from '../../testdata/geth-genesis/pow.js'
66
import {
77
dummy,
88
getRPCClient,
@@ -15,7 +15,9 @@ const method = 'debug_getRawTransaction'
1515

1616
describe(method, () => {
1717
it('call with legacy tx', async () => {
18-
const { chain, common, execution, server } = await setupChain(pow, 'pow', { txLookupLimit: 1 })
18+
const { chain, common, execution, server } = await setupChain(powData, 'pow', {
19+
txLookupLimit: 1,
20+
})
1921
const rpc = getRPCClient(server)
2022
// construct tx
2123
const tx = createLegacyTx(
@@ -37,7 +39,7 @@ describe(method, () => {
3739

3840
it('call with 1559 tx', async () => {
3941
const { chain, common, execution, server } = await setupChain(
40-
gethGenesisStartLondon(pow),
42+
gethGenesisStartLondon(powData),
4143
'powLondon',
4244
)
4345
const rpc = getRPCClient(server)
@@ -60,7 +62,7 @@ describe(method, () => {
6062
})
6163

6264
it('call with unknown tx hash', async () => {
63-
const { server } = await setupChain(pow, 'pow')
65+
const { server } = await setupChain(powData, 'pow')
6466
const rpc = getRPCClient(server)
6567
// get a random tx hash
6668
const res = await rpc.request(method, [

packages/client/test/rpc/debug/storageRangeAt.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { keccak256 } from 'ethereum-cryptography/keccak.js'
55
import { assert, beforeEach, describe, it } from 'vitest'
66

77
import { INTERNAL_ERROR, INVALID_PARAMS } from '../../../src/rpc/error-code.js'
8-
import genesisJSON from '../../testdata/geth-genesis/debug.json'
8+
import { debugData } from '../../testdata/geth-genesis/debug.js'
99
import { dummy, getRPCClient, setupChain } from '../helpers.js'
1010

1111
import type { Block } from '@ethereumjs/block'
@@ -85,7 +85,7 @@ describe(method, () => {
8585
// the second one updates a value in that contract, and the third one deploys
8686
// another contract that does not put anything in its storage.
8787

88-
const { chain, common, execution, server } = await setupChain(genesisJSON, 'post-merge', {
88+
const { chain, common, execution, server } = await setupChain(debugData, 'post-merge', {
8989
txLookupLimit: 0,
9090
})
9191
const rpc = getRPCClient(server)

packages/client/test/rpc/debug/traceCall.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { bytesToHex } from '@ethereumjs/util'
44
import { assert, describe, expect, expectTypeOf, it } from 'vitest'
55

66
import { toRPCTx } from '../../../src/rpc/types.js'
7-
import genesisJSON from '../../testdata/geth-genesis/debug.json'
7+
import { debugData } from '../../testdata/geth-genesis/debug.js'
88
import {
99
createClient,
1010
createManager,
@@ -46,7 +46,7 @@ describe(method, async () => {
4646
})
4747

4848
describe('trace a call', async () => {
49-
const { chain, common, execution, server } = await setupChain(genesisJSON, 'post-merge', {
49+
const { chain, common, execution, server } = await setupChain(debugData, 'post-merge', {
5050
txLookupLimit: 0,
5151
})
5252
const rpc = getRPCClient(server)

packages/client/test/rpc/debug/traceTransaction.spec.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { bytesToHex } from '@ethereumjs/util'
44
import { assert, describe, it } from 'vitest'
55

66
import { INTERNAL_ERROR, INVALID_PARAMS } from '../../../src/rpc/error-code.js'
7-
import genesisJSON from '../../testdata/geth-genesis/debug.json'
7+
import { debugData } from '../../testdata/geth-genesis/debug.js'
88
import { baseSetup, dummy, getRPCClient, runBlockWithTxs, setupChain } from '../helpers.js'
99

1010
const method = 'debug_traceTransaction'
@@ -19,7 +19,7 @@ describe(method, () => {
1919
})
2020

2121
it('call with invalid parameters', async () => {
22-
const { server } = await setupChain(genesisJSON, 'post-merge')
22+
const { server } = await setupChain(debugData, 'post-merge')
2323
const rpc = getRPCClient(server)
2424
let res = await rpc.request(method, ['abcd', {}])
2525
assert.equal(res.error.code, INVALID_PARAMS)
@@ -45,7 +45,7 @@ describe(method, () => {
4545
})
4646

4747
it('call with valid parameters', async () => {
48-
const { chain, common, execution, server } = await setupChain(genesisJSON, 'post-merge', {
48+
const { chain, common, execution, server } = await setupChain(debugData, 'post-merge', {
4949
txLookupLimit: 0,
5050
})
5151
const rpc = getRPCClient(server)
@@ -74,7 +74,7 @@ describe(method, () => {
7474
})
7575

7676
it('call with reverting code', async () => {
77-
const { chain, common, execution, server } = await setupChain(genesisJSON, 'post-merge', {
77+
const { chain, common, execution, server } = await setupChain(debugData, 'post-merge', {
7878
txLookupLimit: 0,
7979
})
8080
const rpc = getRPCClient(server)
@@ -103,7 +103,7 @@ describe(method, () => {
103103
})
104104

105105
it('call with memory enabled', async () => {
106-
const { chain, common, execution, server } = await setupChain(genesisJSON, 'post-merge', {
106+
const { chain, common, execution, server } = await setupChain(debugData, 'post-merge', {
107107
txLookupLimit: 0,
108108
})
109109
const rpc = getRPCClient(server)
@@ -136,7 +136,7 @@ describe(method, () => {
136136
})
137137

138138
it('call with stack disabled', async () => {
139-
const { chain, common, execution, server } = await setupChain(genesisJSON, 'post-merge', {
139+
const { chain, common, execution, server } = await setupChain(debugData, 'post-merge', {
140140
txLookupLimit: 0,
141141
})
142142
const rpc = getRPCClient(server)

packages/client/test/rpc/engine/CLConnectionManager.spec.ts

Lines changed: 26 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -5,42 +5,34 @@ import { assert, describe, expect, it, vi } from 'vitest'
55
import { Config } from '../../../src/index.js'
66
import { CLConnectionManager, ConnectionStatus } from '../../../src/rpc/modules/engine/index.js'
77
import { Event } from '../../../src/types.js'
8-
import genesisJSON from '../../testdata/geth-genesis/post-merge.json'
8+
import { postMergeData } from '../../testdata/geth-genesis/post-merge.js'
99

10-
import type { PrefixedHexString } from '@ethereumjs/util'
10+
import type { ForkchoiceUpdate, NewPayload } from '../../../src/rpc/modules/engine/index.js'
1111

12-
const payload = {
12+
const payload: NewPayload = {
1313
payload: {
14-
parentHash:
15-
'0xff10941138a407482a2651e3eaf0132f66c82ea1386a1f43287aa0fd6298698a' as PrefixedHexString,
16-
feeRecipient: '0xf97e180c050e5ab072211ad2c213eb5aee4df134' as PrefixedHexString,
17-
stateRoot:
18-
'0x9933050575efffde6b1cdbfb9bca2f1a82df1c3e691f5878afe85eaf21df7d4f' as PrefixedHexString,
19-
receiptsRoot:
20-
'0x7d1842a048756ca0aa200ff3eb1b66a52434bc7c1ece5e179eb303a0efa1c944' as PrefixedHexString,
14+
parentHash: '0xff10941138a407482a2651e3eaf0132f66c82ea1386a1f43287aa0fd6298698a',
15+
feeRecipient: '0xf97e180c050e5ab072211ad2c213eb5aee4df134',
16+
stateRoot: '0x9933050575efffde6b1cdbfb9bca2f1a82df1c3e691f5878afe85eaf21df7d4f',
17+
receiptsRoot: '0x7d1842a048756ca0aa200ff3eb1b66a52434bc7c1ece5e179eb303a0efa1c944',
2118
logsBloom:
22-
'0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000040' as PrefixedHexString,
23-
prevRandao:
24-
'0xae8dc2c1223d402fb8e1a48ff6f0f15a543357aca40f34099ef5f5502f97d17d' as PrefixedHexString,
25-
blockNumber: '0xd8d0' as PrefixedHexString,
26-
gasLimit: '0x7a1200' as PrefixedHexString,
27-
gasUsed: '0xc2f8e' as PrefixedHexString,
28-
timestamp: '0x6230c760' as PrefixedHexString,
29-
extraData: '0x' as PrefixedHexString,
30-
baseFeePerGas: '0x3af046a' as PrefixedHexString,
31-
blockHash:
32-
'0x67b92008edff169c08bc186918a843f7363a747b50ed24d59fbfdee2ffd15882' as PrefixedHexString,
19+
'0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000040',
20+
prevRandao: '0xae8dc2c1223d402fb8e1a48ff6f0f15a543357aca40f34099ef5f5502f97d17d',
21+
blockNumber: '0xd8d0',
22+
gasLimit: '0x7a1200',
23+
gasUsed: '0xc2f8e',
24+
timestamp: '0x6230c760',
25+
extraData: '0x',
26+
baseFeePerGas: '0x3af046a',
27+
blockHash: '0x67b92008edff169c08bc186918a843f7363a747b50ed24d59fbfdee2ffd15882',
3328
transactions: [],
3429
},
3530
}
36-
const update = {
31+
const update: ForkchoiceUpdate = {
3732
state: {
38-
headBlockHash:
39-
'0x67b92008edff169c08bc186918a843f7363a747b50ed24d59fbfdee2ffd15882' as PrefixedHexString,
40-
safeBlockHash:
41-
'0x67b92008edff169c08bc186918a843f7363a747b50ed24d59fbfdee2ffd15882' as PrefixedHexString,
42-
finalizedBlockHash:
43-
'0x90ce8a06162cf161cc7323aa30f1de70b30542cd5da65e521884f517a4548017' as PrefixedHexString,
33+
headBlockHash: '0x67b92008edff169c08bc186918a843f7363a747b50ed24d59fbfdee2ffd15882',
34+
safeBlockHash: '0x67b92008edff169c08bc186918a843f7363a747b50ed24d59fbfdee2ffd15882',
35+
finalizedBlockHash: '0x90ce8a06162cf161cc7323aa30f1de70b30542cd5da65e521884f517a4548017',
4436
},
4537
}
4638
describe('starts and stops connection manager', () => {
@@ -57,9 +49,9 @@ describe('starts and stops connection manager', () => {
5749
})
5850

5951
describe('hardfork MergeForkBlock', () => {
60-
;(genesisJSON.config as any).mergeForkBlock = 0
61-
const params = parseGethGenesis(genesisJSON, 'post-merge')
62-
const common = createCommonFromGethGenesis(genesisJSON, { chain: params.name })
52+
postMergeData.config.mergeForkBlock = 0
53+
const params = parseGethGenesis(postMergeData, 'post-merge')
54+
const common = createCommonFromGethGenesis(postMergeData, { chain: params.name })
6355
common.setHardforkBy({ blockNumber: 0 })
6456
const config = new Config({ common })
6557
it('instantiates with config', () => {
@@ -70,10 +62,10 @@ describe('hardfork MergeForkBlock', () => {
7062
})
7163
describe('postmerge hardfork', () => {
7264
it('starts on mergeBlock', async () => {
73-
;(genesisJSON.config as any).mergeForkBlock = 10
74-
const params = parseGethGenesis(genesisJSON, 'post-merge')
65+
postMergeData.config.mergeForkBlock = 10
66+
const params = parseGethGenesis(postMergeData, 'post-merge')
7567

76-
const common = createCommonFromGethGenesis(genesisJSON, {
68+
const common = createCommonFromGethGenesis(postMergeData, {
7769
chain: params.name,
7870
})
7971
common.setHardforkBy({ blockNumber: 11 })

0 commit comments

Comments
 (0)