@@ -38,8 +38,8 @@ import { assert, describe, it } from 'vitest'
38
38
import { createVM , runBlock } from '../../src/index.js'
39
39
import { getDAOCommon , setupPreConditions } from '../util.js'
40
40
41
- import * as testData from './testdata/blockchain.json '
42
- import * as testnet from './testdata/testnet.json '
41
+ import { blockchainData } from './testdata/blockchain.js '
42
+ import { testnetData } from './testdata/testnet.js '
43
43
import { createAccountWithDefaults , setBalance , setupVM } from './utils.js'
44
44
45
45
import type { VM } from '../../src/index.js'
@@ -50,7 +50,6 @@ import type {
50
50
RunBlockOpts ,
51
51
} from '../../src/types.js'
52
52
import type { Block , BlockBytes } from '@ethereumjs/block'
53
- import type { ChainConfig } from '@ethereumjs/common'
54
53
import type { MerkleStateManager } from '@ethereumjs/statemanager'
55
54
import type { AuthorizationListBytesItem , TypedTransaction } from '@ethereumjs/tx'
56
55
import type { NestedUint8Array , PrefixedHexString } from '@ethereumjs/util'
@@ -59,13 +58,13 @@ const common = new Common({ chain: Mainnet, hardfork: Hardfork.Berlin })
59
58
describe ( 'runBlock() -> successful API parameter usage' , async ( ) => {
60
59
async function simpleRun ( vm : VM ) {
61
60
const common = new Common ( { chain : Mainnet , hardfork : Hardfork . London } )
62
- const genesisRlp = hexToBytes ( testData . default . genesisRLP as PrefixedHexString )
61
+ const genesisRlp = hexToBytes ( blockchainData . genesisRLP as PrefixedHexString )
63
62
const genesis = createBlockFromRLP ( genesisRlp , { common } )
64
63
65
- const blockRlp = hexToBytes ( testData . default . blocks [ 0 ] . rlp as PrefixedHexString )
64
+ const blockRlp = hexToBytes ( blockchainData . blocks [ 0 ] . rlp as PrefixedHexString )
66
65
const block = createBlockFromRLP ( blockRlp , { common } )
67
66
68
- await setupPreConditions ( vm . stateManager , testData )
67
+ await setupPreConditions ( vm . stateManager , blockchainData )
69
68
70
69
assert . deepEqual (
71
70
( vm . stateManager as MerkleStateManager ) [ '_trie' ] . root ( ) ,
@@ -88,12 +87,12 @@ describe('runBlock() -> successful API parameter usage', async () => {
88
87
}
89
88
90
89
async function uncleRun ( vm : VM ) {
91
- const testData = await import ( './testdata/uncleData.json ' )
90
+ const { uncleData } = await import ( './testdata/uncleData.js ' )
92
91
93
- await setupPreConditions ( vm . stateManager , testData )
92
+ await setupPreConditions ( vm . stateManager , uncleData )
94
93
95
94
const common = new Common ( { chain : Mainnet , hardfork : Hardfork . London } )
96
- const block1Rlp = hexToBytes ( testData . default . blocks [ 0 ] . rlp as PrefixedHexString )
95
+ const block1Rlp = hexToBytes ( uncleData . blocks [ 0 ] . rlp as PrefixedHexString )
97
96
const block1 = createBlockFromRLP ( block1Rlp , { common } )
98
97
await runBlock ( vm , {
99
98
block : block1 ,
@@ -102,7 +101,7 @@ describe('runBlock() -> successful API parameter usage', async () => {
102
101
skipHardForkValidation : true ,
103
102
} )
104
103
105
- const block2Rlp = hexToBytes ( testData . default . blocks [ 1 ] . rlp as PrefixedHexString )
104
+ const block2Rlp = hexToBytes ( uncleData . blocks [ 1 ] . rlp as PrefixedHexString )
106
105
const block2 = createBlockFromRLP ( block2Rlp , { common } )
107
106
await runBlock ( vm , {
108
107
block : block2 ,
@@ -112,7 +111,7 @@ describe('runBlock() -> successful API parameter usage', async () => {
112
111
skipHardForkValidation : true ,
113
112
} )
114
113
115
- const block3Rlp = toBytes ( testData . default . blocks [ 2 ] . rlp as PrefixedHexString )
114
+ const block3Rlp = toBytes ( uncleData . blocks [ 2 ] . rlp as PrefixedHexString )
116
115
const block3 = createBlockFromRLP ( block3Rlp , { common } )
117
116
await runBlock ( vm , {
118
117
block : block3 ,
@@ -128,7 +127,7 @@ describe('runBlock() -> successful API parameter usage', async () => {
128
127
129
128
assert . equal (
130
129
`0x${ uncleReward } ` ,
131
- testData . default . postState [ '0xb94f5374fce5ed0000000097c15331677e6ebf0b' ] . balance ,
130
+ uncleData . postState [ '0xb94f5374fce5ed0000000097c15331677e6ebf0b' ] . balance ,
132
131
'calculated balance should equal postState balance' ,
133
132
)
134
133
}
@@ -153,7 +152,7 @@ describe('runBlock() -> successful API parameter usage', async () => {
153
152
} )
154
153
155
154
it ( 'PoW block, Common custom chain (Common customChains constructor option)' , async ( ) => {
156
- const common = createCustomCommon ( testnet . default as ChainConfig , Mainnet , {
155
+ const common = createCustomCommon ( testnetData , Mainnet , {
157
156
hardfork : Hardfork . Berlin ,
158
157
} )
159
158
const vm = await setupVM ( { common } )
@@ -227,7 +226,7 @@ describe('runBlock() -> API parameter usage/data errors', async () => {
227
226
228
227
it ( 'should fail when runTx fails' , async ( ) => {
229
228
const common = new Common ( { chain : Mainnet , hardfork : Hardfork . London } )
230
- const blockRlp = hexToBytes ( testData . default . blocks [ 0 ] . rlp as PrefixedHexString )
229
+ const blockRlp = hexToBytes ( blockchainData . blocks [ 0 ] . rlp as PrefixedHexString )
231
230
const block = createBlockFromRLP ( blockRlp , { common } )
232
231
233
232
// The mocked VM uses a mocked runTx
@@ -254,7 +253,7 @@ describe('runBlock() -> API parameter usage/data errors', async () => {
254
253
const blockchain = await createBlockchain ( )
255
254
const vm = await createVM ( { common, blockchain } )
256
255
257
- const blockRlp = hexToBytes ( testData . default . blocks [ 0 ] . rlp as PrefixedHexString )
256
+ const blockRlp = hexToBytes ( blockchainData . blocks [ 0 ] . rlp as PrefixedHexString )
258
257
const block = Object . create ( createBlockFromRLP ( blockRlp , { common } ) )
259
258
260
259
await runBlock ( vm , { block } )
@@ -269,7 +268,7 @@ describe('runBlock() -> API parameter usage/data errors', async () => {
269
268
270
269
it ( 'should fail when no `validateHeader` method exists on blockchain class' , async ( ) => {
271
270
const vm = await createVM ( { common } )
272
- const blockRlp = hexToBytes ( testData . default . blocks [ 0 ] . rlp as PrefixedHexString )
271
+ const blockRlp = hexToBytes ( blockchainData . blocks [ 0 ] . rlp as PrefixedHexString )
273
272
const block = Object . create ( createBlockFromRLP ( blockRlp , { common } ) )
274
273
; ( vm . blockchain as any ) . validateHeader = undefined
275
274
try {
@@ -286,7 +285,7 @@ describe('runBlock() -> API parameter usage/data errors', async () => {
286
285
it ( 'should fail when tx gas limit higher than block gas limit' , async ( ) => {
287
286
const vm = await createVM ( { common } )
288
287
289
- const blockRlp = hexToBytes ( testData . default . blocks [ 0 ] . rlp as PrefixedHexString )
288
+ const blockRlp = hexToBytes ( blockchainData . blocks [ 0 ] . rlp as PrefixedHexString )
290
289
const block = Object . create ( createBlockFromRLP ( blockRlp , { common } ) )
291
290
// modify first tx's gasLimit
292
291
const { nonce, gasPrice, to, value, data, v, r, s } = block . transactions [ 0 ]
@@ -311,13 +310,11 @@ describe('runBlock() -> runtime behavior', async () => {
311
310
312
311
const vm = await setupVM ( { common } )
313
312
314
- const block1 = RLP . decode (
315
- testData . default . blocks [ 0 ] . rlp as PrefixedHexString ,
316
- ) as NestedUint8Array
313
+ const block1 = RLP . decode ( blockchainData . blocks [ 0 ] . rlp as PrefixedHexString ) as NestedUint8Array
317
314
// edit extra data of this block to "dao-hard-fork"
318
315
block1 [ 0 ] [ 12 ] = utf8ToBytes ( 'dao-hard-fork' )
319
316
const block = createBlockFromBytesArray ( block1 as BlockBytes , { common } )
320
- await setupPreConditions ( vm . stateManager , testData )
317
+ await setupPreConditions ( vm . stateManager , blockchainData )
321
318
322
319
// fill two original DAO child-contracts with funds and the recovery account with funds in order to verify that the balance gets summed correctly
323
320
const fundBalance1 = BigInt ( '0x1111' )
@@ -451,10 +448,10 @@ async function runWithHf(hardfork: string) {
451
448
const common = new Common ( { chain : Mainnet , hardfork } )
452
449
const vm = await setupVM ( { common } )
453
450
454
- const blockRlp = hexToBytes ( testData . default . blocks [ 0 ] . rlp as PrefixedHexString )
451
+ const blockRlp = hexToBytes ( blockchainData . blocks [ 0 ] . rlp as PrefixedHexString )
455
452
const block = createBlockFromRLP ( blockRlp , { common } )
456
453
457
- await setupPreConditions ( vm . stateManager , testData )
454
+ await setupPreConditions ( vm . stateManager , blockchainData )
458
455
459
456
const res = await runBlock ( vm , {
460
457
block,
@@ -487,7 +484,7 @@ describe('runBlock() -> tx types', async () => {
487
484
async function simpleRun ( vm : VM , transactions : TypedTransaction [ ] ) {
488
485
const common = vm . common
489
486
490
- const blockRlp = hexToBytes ( testData . default . blocks [ 0 ] . rlp as PrefixedHexString )
487
+ const blockRlp = hexToBytes ( blockchainData . blocks [ 0 ] . rlp as PrefixedHexString )
491
488
const block = createBlockFromRLP ( blockRlp , { common, freeze : false } )
492
489
493
490
//@ts -ignore read-only property
@@ -498,7 +495,7 @@ describe('runBlock() -> tx types', async () => {
498
495
block . header . baseFeePerGas = BigInt ( 7 )
499
496
}
500
497
501
- await setupPreConditions ( vm . stateManager , testData )
498
+ await setupPreConditions ( vm . stateManager , blockchainData )
502
499
503
500
const res = await runBlock ( vm , {
504
501
block,
0 commit comments