diff --git a/packages/client/src/execution/vmexecution.ts b/packages/client/src/execution/vmexecution.ts index ff7b6ff549..ebe0970cbd 100644 --- a/packages/client/src/execution/vmexecution.ts +++ b/packages/client/src/execution/vmexecution.ts @@ -42,7 +42,7 @@ type ChainStatus = { export class VMExecution extends Execution { private _lock = new Lock() - public vm: VM + public vm!: VM public merkleVM: VM | undefined public verkleVM: VM | undefined public hardfork: string = '' @@ -89,15 +89,7 @@ export class VMExecution extends Execution { constructor(options: ExecutionOptions) { super(options) - if (this.config.vm === undefined) { - if (this.config.chainCommon.gteHardfork(Hardfork.Prague)) { - this.setupVerkleVM() - this.vm = this.verkleVM! - } else { - this.setupMerkleVM() - this.vm = this.merkleVM! - } - } else { + if (this.config.vm !== undefined) { this.vm = this.config.vm ;(this.vm as any).blockchain = this.chain.blockchain } @@ -124,11 +116,11 @@ export class VMExecution extends Execution { } } - setupMerkleVM() { + async setupMerkleVM() { if (this.merkleVM !== undefined) { return } - const trie = new Trie({ + const trie = await Trie.create({ db: new LevelDB(this.stateDB), useKeyHashing: true, cacheSize: this.config.trieCache, @@ -160,22 +152,23 @@ export class VMExecution extends Execution { size: this.config.codeCache, }, }) - this.merkleVM = new (VM as any)({ + this.merkleVM = await VM.create({ common: this.config.execCommon, blockchain: this.chain.blockchain, stateManager, profilerOpts: this.config.vmProfilerOpts, }) + this.vm = this.merkleVM } - setupVerkleVM() { + async setupVerkleVM() { if (this.verkleVM !== undefined) { return } this.config.logger.info(`Setting up verkleVM`) const stateManager = new StatelessVerkleStateManager() - this.verkleVM = new (VM as any)({ + this.verkleVM = await VM.create({ common: this.config.execCommon, blockchain: this.chain.blockchain, stateManager, @@ -190,13 +183,13 @@ export class VMExecution extends Execution { return this.runWithLock(async () => { if (this.merkleVM === undefined) { - this.setupMerkleVM() + await this.setupMerkleVM() } const merkleVM = this.merkleVM! const merkleStateManager = merkleVM.stateManager as DefaultStateManager if (this.verkleVM === undefined) { - this.setupVerkleVM() + await this.setupVerkleVM() } const verkleVM = this.verkleVM! const verkleStateManager = verkleVM.stateManager as StatelessVerkleStateManager @@ -223,7 +216,21 @@ export class VMExecution extends Execution { return } - await this.vm.init() + if (this.config.execCommon.gteHardfork(Hardfork.Prague)) { + if (!this.config.statelessVerkle) { + throw Error(`Currently stateful verkle execution not supported`) + } + this.config.logger.info(`Skipping VM verkle statemanager genesis hardfork=${this.hardfork}`) + await this.setupVerkleVM() + this.vm = this.verkleVM! + } else { + this.config.logger.info( + `Initializing VM merkle statemanager genesis hardfork=${this.hardfork}` + ) + await this.setupMerkleVM() + this.vm = this.merkleVM! + } + if (typeof this.vm.blockchain.getIteratorHead !== 'function') { throw new Error('cannot get iterator head: blockchain has no getIteratorHead function') } @@ -235,6 +242,14 @@ export class VMExecution extends Execution { root: stateRoot, hash: headBlock.hash(), } + if (number === BIGINT_0) { + const genesisState = + this.chain['_customGenesisState'] ?? getGenesis(Number(this.vm.common.chainId())) + if (!genesisState) { + throw new Error('genesisState not available') + } + await this.vm.stateManager.generateCanonicalGenesis(genesisState) + } if (typeof this.vm.blockchain.getTotalDifficulty !== 'function') { throw new Error('cannot get iterator head: blockchain has no getTotalDifficulty function') @@ -243,29 +258,6 @@ export class VMExecution extends Execution { this.config.execCommon.setHardforkBy({ blockNumber: number, td, timestamp }) this.hardfork = this.config.execCommon.hardfork() - if (this.config.execCommon.gteHardfork(Hardfork.Prague)) { - if (!this.config.statelessVerkle) { - throw Error(`Currently stateful verkle execution not supported`) - } - this.config.logger.info(`Skipping VM verkle statemanager genesis hardfork=${this.hardfork}`) - this.setupVerkleVM() - this.vm = this.verkleVM! - } else { - this.config.logger.info( - `Initializing VM merkle statemanager genesis hardfork=${this.hardfork}` - ) - this.setupMerkleVM() - this.vm = this.merkleVM! - if (number === BIGINT_0) { - const genesisState = - this.chain['_customGenesisState'] ?? getGenesis(Number(this.vm.common.chainId())) - if (!genesisState) { - throw new Error('genesisState not available') - } - await this.vm.stateManager.generateCanonicalGenesis(genesisState) - } - } - await super.open() // TODO: Should a run be started to execute any left over blocks? // void this.run() @@ -305,11 +297,11 @@ export class VMExecution extends Execution { }) if (this.config.execCommon.gteHardfork(Hardfork.Prague)) { // verkleVM should already exist but we can still do an allocation just to be safe - this.setupVerkleVM() + await this.setupVerkleVM() this.vm = this.verkleVM! } else { // its could be a rest to a pre-merkle when the chain was never initialized - this.setupMerkleVM() + await this.setupMerkleVM() this.vm = this.merkleVM! } diff --git a/packages/client/src/service/txpool.ts b/packages/client/src/service/txpool.ts index 88a774f78d..affa3519f4 100644 --- a/packages/client/src/service/txpool.ts +++ b/packages/client/src/service/txpool.ts @@ -86,7 +86,6 @@ type GasPrice = { export class TxPool { private config: Config private service: FullEthereumService - private vm: VM private opened: boolean @@ -170,7 +169,6 @@ export class TxPool { constructor(options: TxPoolOptions) { this.config = options.config this.service = options.service - this.vm = this.service.execution.vm this.pool = new Map() this.txsInPool = 0 @@ -316,7 +314,7 @@ export class TxPool { } // Copy VM in order to not overwrite the state root of the VMExecution module which may be concurrently running blocks - const vmCopy = await this.vm.shallowCopy() + const vmCopy = await this.service.execution.vm.shallowCopy() // Set state root to latest block so that account balance is correct when doing balance check await vmCopy.stateManager.setStateRoot(block.stateRoot) let account = await vmCopy.stateManager.getAccount(senderAddress) diff --git a/packages/client/test/client.spec.ts b/packages/client/test/client.spec.ts index 50a18b5306..cfa6f9420e 100644 --- a/packages/client/test/client.spec.ts +++ b/packages/client/test/client.spec.ts @@ -62,6 +62,7 @@ describe('[EthereumClient]', async () => { const server = new Server() as any const config = new Config({ server, accountCache: 10000, storageCache: 1000 }) const client = await EthereumClient.create({ config, metaDB: new MemoryLevel() }) + await (client.services[0] as any)['execution'].setupMerkleVM() await client.start() assert.ok(client.started, 'started') assert.equal(await client.start(), false, 'already started') diff --git a/packages/client/test/miner/miner.spec.ts b/packages/client/test/miner/miner.spec.ts index 4512670d23..ee48a223bb 100644 --- a/packages/client/test/miner/miner.spec.ts +++ b/packages/client/test/miner/miner.spec.ts @@ -72,6 +72,12 @@ describe('[Miner]', async () => { validateDifficulty: () => undefined, }, validateHeader: () => {}, + getIteratorHead: () => { + return Block.fromBlockData({ header: { number: 1 } }) + }, + getTotalDifficulty: () => { + return 1n + }, // eslint-disable-next-line no-invalid-this shallowCopy: () => this.blockchain, _init: async () => undefined, @@ -225,6 +231,7 @@ describe('[Miner]', async () => { }) const miner = new Miner({ config: customConfig, service, skipHardForkValidation: true }) const { txPool } = service + await service.execution.open() const { vm } = service.execution txPool.start() @@ -257,8 +264,8 @@ describe('[Miner]', async () => { // no skipHardForkValidation const miner = new Miner({ config: goerliConfig, service }) const { txPool } = service + await service.execution.setupMerkleVM() const { vm } = service.execution - txPool.start() miner.start() @@ -297,6 +304,7 @@ describe('[Miner]', async () => { }) const miner = new Miner({ config: customConfig, service, skipHardForkValidation: true }) const { txPool } = service + await service.execution.open() const { vm } = service.execution txPool.start() miner.start() @@ -346,6 +354,7 @@ describe('[Miner]', async () => { }) const miner = new Miner({ config, service, skipHardForkValidation: true }) const { txPool } = service + await service.execution.open() const { vm, receiptsManager } = service.execution txPool.start() miner.start() @@ -417,6 +426,7 @@ describe('[Miner]', async () => { }) const miner = new Miner({ config, service, skipHardForkValidation: true }) const { txPool } = service + await service.execution.open() const { vm } = service.execution txPool.start() miner.start() @@ -448,7 +458,10 @@ describe('[Miner]', async () => { it("assembleBlocks() -> should stop assembling a block after it's full", async () => { const chain = new FakeChain() as any const gasLimit = 100000 - const block = Block.fromBlockData({ header: { gasLimit } }, { common: customCommon }) + const block = Block.fromBlockData( + { header: { gasLimit } }, + { common: customCommon, setHardfork: true } + ) Object.defineProperty(chain, 'headers', { get() { return { latest: block.header, height: BigInt(0) } @@ -463,6 +476,7 @@ describe('[Miner]', async () => { config: customConfig, chain, }) + await service.execution.open() const miner = new Miner({ config: customConfig, service, skipHardForkValidation: true }) const { txPool } = service const { vm } = service.execution @@ -492,7 +506,7 @@ describe('[Miner]', async () => { miner.stop() txPool.stop() } - await (miner as any).queueNextAssembly(0) + await miner['queueNextAssembly'](0) await wait(500) }) /***************************************************************************************** diff --git a/packages/client/test/miner/pendingBlock.spec.ts b/packages/client/test/miner/pendingBlock.spec.ts index 04340681a2..649751a17e 100644 --- a/packages/client/test/miner/pendingBlock.spec.ts +++ b/packages/client/test/miner/pendingBlock.spec.ts @@ -80,6 +80,7 @@ const setup = () => { shallowCopy: () => service.execution.vm, setStateRoot: () => {}, blockchain: mockBlockchain({}), + common: new Common({ chain: 'mainnet' }), }, }, } @@ -218,7 +219,7 @@ describe('[PendingBlock]', async () => { // set gas limit low so that can accomodate 2 txs const prevGasLimit = common['_chainParams'].genesis.gasLimit - common['_chainParams'].genesis.gasLimit = BigInt(50000) + common['_chainParams'].genesis.gasLimit = 50000 const vm = await VM.create({ common }) await setBalance(vm, A.address, BigInt(5000000000000000)) @@ -337,7 +338,9 @@ describe('[PendingBlock]', async () => { it('should throw when blockchain does not have getTotalDifficulty function', async () => { const { txPool } = setup() const pendingBlock = new PendingBlock({ config, txPool, skipHardForkValidation: true }) - const vm = (txPool as any).vm + const vm = txPool['service'].execution.vm + // override total difficulty function to trigger error case + vm.blockchain.getTotalDifficulty = undefined try { await pendingBlock.start(vm, new Block()) assert.fail('should have thrown') diff --git a/packages/client/test/rpc/admin/nodeInfo.spec.ts b/packages/client/test/rpc/admin/nodeInfo.spec.ts index 48e0da0d7e..a560c1a8f5 100644 --- a/packages/client/test/rpc/admin/nodeInfo.spec.ts +++ b/packages/client/test/rpc/admin/nodeInfo.spec.ts @@ -6,7 +6,7 @@ const method = 'admin_nodeInfo' describe(method, () => { it('works', async () => { - const manager = createManager(createClient({ opened: true })) + const manager = createManager(await createClient({ opened: true })) const rpc = getRpcClient(startRPC(manager.getMethods())) const res = await rpc.request(method, []) diff --git a/packages/client/test/rpc/debug/traceCall.spec.ts b/packages/client/test/rpc/debug/traceCall.spec.ts index e8e044c5fb..9b63357e65 100644 --- a/packages/client/test/rpc/debug/traceCall.spec.ts +++ b/packages/client/test/rpc/debug/traceCall.spec.ts @@ -19,8 +19,8 @@ import type { RpcTx } from '../../../src/rpc/types.js' const method = 'debug_traceCall' -describe(method, () => { - const manager = createManager(createClient({ opened: true })) +describe(method, async () => { + const manager = createManager(await createClient({ opened: true })) const methods = manager.getMethods() const server = startRPC(methods) const rpc = getRpcClient(server) diff --git a/packages/client/test/rpc/debug/traceTransaction.spec.ts b/packages/client/test/rpc/debug/traceTransaction.spec.ts index d2c317cf71..ec07a48289 100644 --- a/packages/client/test/rpc/debug/traceTransaction.spec.ts +++ b/packages/client/test/rpc/debug/traceTransaction.spec.ts @@ -11,7 +11,7 @@ const method = 'debug_traceTransaction' describe(method, () => { it('call with invalid configuration', async () => { - const { rpc } = baseSetup({ engine: false, includeVM: true }) + const { rpc } = await baseSetup({ engine: false, includeVM: true }) const res = await rpc.request(method, ['0xabcd', {}]) assert.equal(res.error.code, INTERNAL_ERROR) diff --git a/packages/client/test/rpc/engine/exchangeCapabilities.spec.ts b/packages/client/test/rpc/engine/exchangeCapabilities.spec.ts index 913fe54a69..358a1f0c60 100644 --- a/packages/client/test/rpc/engine/exchangeCapabilities.spec.ts +++ b/packages/client/test/rpc/engine/exchangeCapabilities.spec.ts @@ -6,7 +6,7 @@ const method = 'engine_exchangeCapabilities' describe(method, () => { it('call with invalid payloadId', async () => { - const { rpc } = baseSetup({ engine: true }) + const { rpc } = await baseSetup({ engine: true }) const res = await rpc.request(method, []) diff --git a/packages/client/test/rpc/engine/forkchoiceUpdatedV1.spec.ts b/packages/client/test/rpc/engine/forkchoiceUpdatedV1.spec.ts index 53974efd18..2cda972f43 100644 --- a/packages/client/test/rpc/engine/forkchoiceUpdatedV1.spec.ts +++ b/packages/client/test/rpc/engine/forkchoiceUpdatedV1.spec.ts @@ -51,7 +51,7 @@ const validPayload = [validForkChoiceState, validPayloadAttributes] describe(method, () => { it('call with invalid head block hash without 0x', async () => { - const { rpc } = baseSetup({ engine: true, includeVM: true }) + const { rpc } = await baseSetup({ engine: true, includeVM: true }) const invalidForkChoiceState = { ...validForkChoiceState, headBlockHash: 'invalid formatted head block hash', @@ -66,7 +66,7 @@ describe(method, () => { }) it('call with invalid hex string as block hash', async () => { - const { rpc } = baseSetup({ engine: true, includeVM: true }) + const { rpc } = await baseSetup({ engine: true, includeVM: true }) const invalidForkChoiceState = { ...validForkChoiceState, diff --git a/packages/client/test/rpc/engine/getPayloadBodiesByHashV1.spec.ts b/packages/client/test/rpc/engine/getPayloadBodiesByHashV1.spec.ts index 55069ffaa5..f6ecd44977 100644 --- a/packages/client/test/rpc/engine/getPayloadBodiesByHashV1.spec.ts +++ b/packages/client/test/rpc/engine/getPayloadBodiesByHashV1.spec.ts @@ -14,7 +14,7 @@ const method = 'engine_getPayloadBodiesByHashV1' describe(method, () => { it('call with too many hashes', async () => { - const { rpc } = baseSetup({ engine: true, includeVM: true }) + const { rpc } = await baseSetup({ engine: true, includeVM: true }) const tooManyHashes: string[] = [] for (let x = 0; x < 35; x++) { tooManyHashes.push(bytesToHex(randomBytes(32))) diff --git a/packages/client/test/rpc/engine/getPayloadBodiesByRangeV1.spec.ts b/packages/client/test/rpc/engine/getPayloadBodiesByRangeV1.spec.ts index 9ba9fe1519..1ddfb52afd 100644 --- a/packages/client/test/rpc/engine/getPayloadBodiesByRangeV1.spec.ts +++ b/packages/client/test/rpc/engine/getPayloadBodiesByRangeV1.spec.ts @@ -14,7 +14,7 @@ const method = 'engine_getPayloadBodiesByRangeV1' describe(method, () => { it('call with too many hashes', async () => { - const { rpc } = baseSetup({ engine: true, includeVM: true }) + const { rpc } = await baseSetup({ engine: true, includeVM: true }) const res = await rpc.request(method, ['0x1', '0x55']) assert.equal(res.error.code, TOO_LARGE_REQUEST) @@ -22,7 +22,7 @@ describe(method, () => { }) it('call with invalid parameters', async () => { - const { rpc } = baseSetup({ engine: true, includeVM: true }) + const { rpc } = await baseSetup({ engine: true, includeVM: true }) const res = await rpc.request(method, ['0x0', '0x0']) assert.equal(res.error.code, INVALID_PARAMS) diff --git a/packages/client/test/rpc/engine/getPayloadV1.spec.ts b/packages/client/test/rpc/engine/getPayloadV1.spec.ts index 3b522a678c..1af1d7ec8e 100644 --- a/packages/client/test/rpc/engine/getPayloadV1.spec.ts +++ b/packages/client/test/rpc/engine/getPayloadV1.spec.ts @@ -21,7 +21,7 @@ const validPayload = [validForkChoiceState, validPayloadAttributes] describe(method, () => { it('call with invalid payloadId', async () => { - const { rpc } = baseSetup({ engine: true, includeVM: true }) + const { rpc } = await baseSetup({ engine: true, includeVM: true }) const res = await rpc.request(method, [1]) assert.equal(res.error.code, INVALID_PARAMS) @@ -29,7 +29,7 @@ describe(method, () => { }) it('call with unknown payloadId', async () => { - const { rpc } = baseSetup({ engine: true, includeVM: true }) + const { rpc } = await baseSetup({ engine: true, includeVM: true }) const res = await rpc.request(method, ['0x123']) assert.equal(res.error.code, -32001, 'Unknown payload') diff --git a/packages/client/test/rpc/engine/getPayloadV3.spec.ts b/packages/client/test/rpc/engine/getPayloadV3.spec.ts index 271dfe035b..1a8a2288f8 100644 --- a/packages/client/test/rpc/engine/getPayloadV3.spec.ts +++ b/packages/client/test/rpc/engine/getPayloadV3.spec.ts @@ -49,7 +49,7 @@ const method = 'engine_getPayloadV3' describe(method, () => { it('call with invalid payloadId', async () => { - const { rpc } = baseSetup({ engine: true, includeVM: true }) + const { rpc } = await baseSetup({ engine: true, includeVM: true }) const res = await rpc.request(method, [1]) assert.equal(res.error.code, INVALID_PARAMS) @@ -57,7 +57,7 @@ describe(method, () => { }) it('call with unknown payloadId', async () => { - const { rpc } = baseSetup({ engine: true, includeVM: true }) + const { rpc } = await baseSetup({ engine: true, includeVM: true }) const res = await rpc.request(method, ['0x123']) assert.equal(res.error.code, -32001, 'Unknown payload') @@ -87,7 +87,6 @@ describe(method, () => { let res = await rpc.request('engine_forkchoiceUpdatedV3', validPayload) const payloadId = res.result.payloadId assert.ok(payloadId !== undefined && payloadId !== null, 'valid payloadId should be received') - ;(service.txPool as any).vm.common.setHardfork(Hardfork.Cancun) const txBlobs = getBlobs('hello world') const txCommitments = blobsToCommitments(txBlobs) @@ -110,7 +109,6 @@ describe(method, () => { { common } ).sign(pkey) - service.txPool['vm'].common.setHardfork(Hardfork.Cancun) await service.txPool.add(tx, true) res = await rpc.request('engine_getPayloadV3', [payloadId]) diff --git a/packages/client/test/rpc/engine/newPayloadV1.spec.ts b/packages/client/test/rpc/engine/newPayloadV1.spec.ts index 14b36d63f4..b11ef12641 100644 --- a/packages/client/test/rpc/engine/newPayloadV1.spec.ts +++ b/packages/client/test/rpc/engine/newPayloadV1.spec.ts @@ -14,7 +14,7 @@ const [blockData] = blocks describe(method, () => { it('call with invalid block hash without 0x', async () => { - const { rpc } = baseSetup({ engine: true, includeVM: true }) + const { rpc } = await baseSetup({ engine: true, includeVM: true }) const blockDataWithInvalidParentHash = [ { @@ -33,7 +33,7 @@ describe(method, () => { }) it('call with invalid hex string as block hash', async () => { - const { rpc } = baseSetup({ engine: true, includeVM: true }) + const { rpc } = await baseSetup({ engine: true, includeVM: true }) const blockDataWithInvalidBlockHash = [{ ...blockData, blockHash: '0x-invalid-block-hash' }] const res = await rpc.request(method, blockDataWithInvalidBlockHash) diff --git a/packages/client/test/rpc/engine/newPayloadV2.spec.ts b/packages/client/test/rpc/engine/newPayloadV2.spec.ts index 221d185cb1..b0e5a02b68 100644 --- a/packages/client/test/rpc/engine/newPayloadV2.spec.ts +++ b/packages/client/test/rpc/engine/newPayloadV2.spec.ts @@ -14,7 +14,7 @@ const [blockData] = blocks describe(`${method}: call with executionPayloadV1`, () => { it('call with invalid block hash without 0x', async () => { - const { rpc } = baseSetup({ engine: true, includeVM: true }) + const { rpc } = await baseSetup({ engine: true, includeVM: true }) const blockDataWithInvalidParentHash = [ { @@ -33,7 +33,7 @@ describe(`${method}: call with executionPayloadV1`, () => { }) it('call with invalid hex string as block hash', async () => { - const { rpc } = baseSetup({ engine: true, includeVM: true }) + const { rpc } = await baseSetup({ engine: true, includeVM: true }) const blockDataWithInvalidBlockHash = [{ ...blockData, blockHash: '0x-invalid-block-hash' }] const res = await rpc.request(method, blockDataWithInvalidBlockHash) diff --git a/packages/client/test/rpc/eth/blockNumber.spec.ts b/packages/client/test/rpc/eth/blockNumber.spec.ts index 4f76219d11..cf507166ac 100644 --- a/packages/client/test/rpc/eth/blockNumber.spec.ts +++ b/packages/client/test/rpc/eth/blockNumber.spec.ts @@ -16,7 +16,7 @@ describe(method, () => { } }, } - const manager = createManager(createClient({ chain: mockChain })) + const manager = createManager(await createClient({ chain: mockChain })) const rpc = getRpcClient(startRPC(manager.getMethods())) const res = await rpc.request(method, []) diff --git a/packages/client/test/rpc/eth/call.spec.ts b/packages/client/test/rpc/eth/call.spec.ts index 22f3a4c653..0d4e50b656 100644 --- a/packages/client/test/rpc/eth/call.spec.ts +++ b/packages/client/test/rpc/eth/call.spec.ts @@ -14,14 +14,14 @@ const method = 'eth_call' describe(method, () => { it('call with valid arguments', async () => { - const common = new Common({ chain: Chain.Mainnet, hardfork: Hardfork.Istanbul }) + const common = new Common({ chain: Chain.Mainnet, hardfork: Hardfork.Chainstart }) const blockchain = await Blockchain.create({ common, validateBlocks: false, validateConsensus: false, }) - const client = createClient({ blockchain, commonChain: common, includeVM: true }) + const client = await createClient({ blockchain, commonChain: common, includeVM: true }) const manager = createManager(client) const rpc = getRpcClient(startRPC(manager.getMethods())) @@ -123,7 +123,7 @@ describe(method, () => { it('call with unsupported block argument', async () => { const blockchain = await Blockchain.create() - const client = createClient({ blockchain, includeVM: true }) + const client = await createClient({ blockchain, includeVM: true }) const manager = createManager(client) const rpc = getRpcClient(startRPC(manager.getMethods())) @@ -149,7 +149,7 @@ describe(method, () => { it('call with invalid hex params', async () => { const blockchain = await Blockchain.create() - const client = createClient({ blockchain, includeVM: true }) + const client = await createClient({ blockchain, includeVM: true }) const manager = createManager(client) const rpc = getRpcClient(startRPC(manager.getMethods())) diff --git a/packages/client/test/rpc/eth/chainId.spec.ts b/packages/client/test/rpc/eth/chainId.spec.ts index e65a4be89f..a827c875a2 100644 --- a/packages/client/test/rpc/eth/chainId.spec.ts +++ b/packages/client/test/rpc/eth/chainId.spec.ts @@ -7,14 +7,14 @@ const method = 'eth_chainId' describe(method, () => { it('calls', async () => { - const { rpc } = baseSetup() + const { rpc } = await baseSetup() const res = await rpc.request(method, []) assert.equal(typeof res.result, 'string', 'chainId should be a string') }) it('returns 1 for Mainnet', async () => { - const { rpc } = baseSetup() + const { rpc } = await baseSetup() const res = await rpc.request(method, []) @@ -23,7 +23,7 @@ describe(method, () => { it('returns 3 for Goerli', async () => { const manager = createManager( - createClient({ opened: true, commonChain: new Common({ chain: Chain.Goerli }) }) + await createClient({ opened: true, commonChain: new Common({ chain: Chain.Goerli }) }) ) const rpc = getRpcClient(startRPC(manager.getMethods())) diff --git a/packages/client/test/rpc/eth/coinbase.spec.ts b/packages/client/test/rpc/eth/coinbase.spec.ts index 5029589ee5..70f5143023 100644 --- a/packages/client/test/rpc/eth/coinbase.spec.ts +++ b/packages/client/test/rpc/eth/coinbase.spec.ts @@ -7,7 +7,7 @@ const method = 'eth_coinbase' describe(method, () => { it('call', async () => { const coinbase: string = '0xebea8bff2be13d7e5e2b9d8809f7581e65fb0909' - const { rpc } = baseSetup({ + const { rpc } = await baseSetup({ minerCoinbase: coinbase, }) diff --git a/packages/client/test/rpc/eth/estimateGas.spec.ts b/packages/client/test/rpc/eth/estimateGas.spec.ts index 9d75d5fe1d..89f67eac5a 100644 --- a/packages/client/test/rpc/eth/estimateGas.spec.ts +++ b/packages/client/test/rpc/eth/estimateGas.spec.ts @@ -26,7 +26,7 @@ describe( validateConsensus: false, }) - const client = createClient({ blockchain, commonChain: common, includeVM: true }) + const client = await createClient({ blockchain, commonChain: common, includeVM: true }) const manager = createManager(client) const rpc = getRpcClient(startRPC(manager.getMethods())) @@ -179,7 +179,7 @@ describe( it('call with unsupported block argument', async () => { const blockchain = await Blockchain.create() - const client = createClient({ blockchain, includeVM: true }) + const client = await createClient({ blockchain, includeVM: true }) const manager = createManager(client) const rpc = getRpcClient(startRPC(manager.getMethods())) diff --git a/packages/client/test/rpc/eth/getBalance.spec.ts b/packages/client/test/rpc/eth/getBalance.spec.ts index 084a866fff..64a9257bb5 100644 --- a/packages/client/test/rpc/eth/getBalance.spec.ts +++ b/packages/client/test/rpc/eth/getBalance.spec.ts @@ -17,10 +17,10 @@ describe( method, () => { it('ensure balance deducts after a tx', async () => { - const common = new Common({ chain: Chain.Mainnet, hardfork: Hardfork.Istanbul }) + const common = new Common({ chain: Chain.Mainnet, hardfork: Hardfork.Chainstart }) const blockchain = await Blockchain.create({ common }) - const client = createClient({ blockchain, commonChain: common, includeVM: true }) + const client = await createClient({ blockchain, commonChain: common, includeVM: true }) const manager = createManager(client) const rpc = getRpcClient(startRPC(manager.getMethods())) @@ -95,7 +95,7 @@ describe( it('call with unsupported block argument', async () => { const blockchain = await Blockchain.create() - const client = createClient({ blockchain, includeVM: true }) + const client = await createClient({ blockchain, includeVM: true }) const manager = createManager(client) const rpc = getRpcClient(startRPC(manager.getMethods())) diff --git a/packages/client/test/rpc/eth/getBlockByHash.spec.ts b/packages/client/test/rpc/eth/getBlockByHash.spec.ts index 65ba28fd9c..5416ada56d 100644 --- a/packages/client/test/rpc/eth/getBlockByHash.spec.ts +++ b/packages/client/test/rpc/eth/getBlockByHash.spec.ts @@ -7,7 +7,7 @@ const method = 'eth_getBlockByHash' describe(method, () => { it('call with valid arguments', async () => { - const { rpc } = baseSetup() + const { rpc } = await baseSetup() const blockHash = '0x910abca1728c53e8d6df870dd7af5352e974357dc58205dea1676be17ba6becf' let includeTransactions = false @@ -23,7 +23,7 @@ describe(method, () => { }) it('call with false for second argument', async () => { - const { rpc } = baseSetup() + const { rpc } = await baseSetup() const res = await rpc.request(method, [ '0xdc0818cf78f21a8e70579cb46a43643f78291264dda342ae31049421c82d21ae', @@ -38,7 +38,7 @@ describe(method, () => { }) it('call with invalid block hash without 0x', async () => { - const { rpc } = baseSetup() + const { rpc } = await baseSetup() const res = await rpc.request(method, ['WRONG BLOCK NUMBER', true]) assert.equal(res.error.code, INVALID_PARAMS) @@ -46,7 +46,7 @@ describe(method, () => { }) it('call with invalid hex string as block hash', async () => { - const { rpc } = baseSetup() + const { rpc } = await baseSetup() const res = await rpc.request(method, ['0xWRONG BLOCK NUMBER', true]) assert.equal(res.error.code, INVALID_PARAMS) @@ -54,7 +54,7 @@ describe(method, () => { }) it('call without second parameter', async () => { - const { rpc } = baseSetup() + const { rpc } = await baseSetup() const res = await rpc.request(method, ['0x0']) assert.equal(res.error.code, INVALID_PARAMS) @@ -62,7 +62,7 @@ describe(method, () => { }) it('call with invalid second parameter', async () => { - const { rpc } = baseSetup() + const { rpc } = await baseSetup() const res = await rpc.request(method, ['0x0', 'INVALID PARAMETER']) assert.equal(res.error.code, INVALID_PARAMS) diff --git a/packages/client/test/rpc/eth/getBlockByNumber.spec.ts b/packages/client/test/rpc/eth/getBlockByNumber.spec.ts index 801fd206cb..dc5493317c 100644 --- a/packages/client/test/rpc/eth/getBlockByNumber.spec.ts +++ b/packages/client/test/rpc/eth/getBlockByNumber.spec.ts @@ -66,7 +66,7 @@ const method = 'eth_getBlockByNumber' describe(method, async () => { it('call with valid arguments', async () => { - const manager = createManager(createClient({ chain: createChain() })) + const manager = createManager(await createClient({ chain: createChain() })) const rpc = getRpcClient(startRPC(manager.getMethods())) const res = await rpc.request(method, ['0x0', false]) @@ -74,7 +74,7 @@ describe(method, async () => { }) it('call with false for second argument', async () => { - const manager = createManager(createClient({ chain: createChain() })) + const manager = createManager(await createClient({ chain: createChain() })) const rpc = getRpcClient(startRPC(manager.getMethods())) const res = await rpc.request(method, ['0x0', false]) @@ -87,7 +87,7 @@ describe(method, async () => { }) it('call with earliest param', async () => { - const manager = createManager(createClient({ chain: createChain() })) + const manager = createManager(await createClient({ chain: createChain() })) const rpc = getRpcClient(startRPC(manager.getMethods())) const res = await rpc.request(method, ['earliest', false]) @@ -95,7 +95,7 @@ describe(method, async () => { }) it('call with latest param', async () => { - const manager = createManager(createClient({ chain: createChain() })) + const manager = createManager(await createClient({ chain: createChain() })) const rpc = getRpcClient(startRPC(manager.getMethods())) const res = await rpc.request(method, ['latest', false]) @@ -104,7 +104,7 @@ describe(method, async () => { }) it('call with unimplemented pending param', async () => { - const manager = createManager(createClient({ chain: createChain() })) + const manager = createManager(await createClient({ chain: createChain() })) const rpc = getRpcClient(startRPC(manager.getMethods())) const res = await rpc.request(method, ['pending', true]) @@ -114,7 +114,7 @@ describe(method, async () => { }) it('call with non-string block number', async () => { - const manager = createManager(createClient({ chain: createChain() })) + const manager = createManager(await createClient({ chain: createChain() })) const rpc = getRpcClient(startRPC(manager.getMethods())) const res = await rpc.request(method, [10, true]) @@ -123,7 +123,7 @@ describe(method, async () => { }) it('call with invalid block number', async () => { - const manager = createManager(createClient({ chain: createChain() })) + const manager = createManager(await createClient({ chain: createChain() })) const rpc = getRpcClient(startRPC(manager.getMethods())) const res = await rpc.request(method, ['WRONG BLOCK NUMBER', true]) @@ -136,7 +136,7 @@ describe(method, async () => { }) it('call without second parameter', async () => { - const manager = createManager(createClient({ chain: createChain() })) + const manager = createManager(await createClient({ chain: createChain() })) const rpc = getRpcClient(startRPC(manager.getMethods())) const res = await rpc.request(method, ['0x0']) @@ -145,7 +145,7 @@ describe(method, async () => { }) it('call with invalid second parameter', async () => { - const manager = createManager(createClient({ chain: createChain() })) + const manager = createManager(await createClient({ chain: createChain() })) const rpc = getRpcClient(startRPC(manager.getMethods())) const res = await rpc.request(method, ['0x0', 'INVALID PARAMETER']) @@ -153,7 +153,7 @@ describe(method, async () => { }) it('call with transaction objects', async () => { - const manager = createManager(createClient({ chain: createChain() })) + const manager = createManager(await createClient({ chain: createChain() })) const rpc = getRpcClient(startRPC(manager.getMethods())) const res = await rpc.request(method, ['latest', true]) @@ -170,7 +170,7 @@ describe(method, async () => { }, { common } ) - const manager = createManager(createClient({ chain: createChain(block1 as any) })) + const manager = createManager(await createClient({ chain: createChain(block1 as any) })) const rpc = getRpcClient(startRPC(manager.getMethods())) const res = await rpc.request(method, ['latest', true]) diff --git a/packages/client/test/rpc/eth/getBlockTransactionCountByHash.spec.ts b/packages/client/test/rpc/eth/getBlockTransactionCountByHash.spec.ts index e74ebaa5de..795de44e7c 100644 --- a/packages/client/test/rpc/eth/getBlockTransactionCountByHash.spec.ts +++ b/packages/client/test/rpc/eth/getBlockTransactionCountByHash.spec.ts @@ -7,7 +7,7 @@ const method = 'eth_getBlockTransactionCountByHash' describe(method, () => { it('call with valid arguments', async () => { - const { rpc } = baseSetup() + const { rpc } = await baseSetup() const res = await rpc.request(method, [ '0x910abca1728c53e8d6df870dd7af5352e974357dc58205dea1676be17ba6becf', @@ -16,7 +16,7 @@ describe(method, () => { }, 10000) it('call with invalid block hash without 0x', async () => { - const { rpc } = baseSetup() + const { rpc } = await baseSetup() const res = await rpc.request(method, ['WRONG BLOCK NUMBER']) assert.equal(res.error.code, INVALID_PARAMS) @@ -24,7 +24,7 @@ describe(method, () => { }) it('call with invalid hex string as block hash', async () => { - const { rpc } = baseSetup() + const { rpc } = await baseSetup() const res = await rpc.request(method, ['0xWRONG BLOCK NUMBER', true]) assert.equal(res.error.code, INVALID_PARAMS) @@ -32,7 +32,7 @@ describe(method, () => { }) it('call without first parameter', async () => { - const { rpc } = baseSetup() + const { rpc } = await baseSetup() const res = await rpc.request(method, []) assert.equal(res.error.code, INVALID_PARAMS) @@ -40,7 +40,7 @@ describe(method, () => { }) it('call with invalid second parameter', async () => { - const { rpc } = baseSetup() + const { rpc } = await baseSetup() const res = await rpc.request(method, ['INVALID PARAMETER']) assert.equal(res.error.code, INVALID_PARAMS) diff --git a/packages/client/test/rpc/eth/getBlockTransactionCountByNumber.spec.ts b/packages/client/test/rpc/eth/getBlockTransactionCountByNumber.spec.ts index c4f5af3e56..552bd8c3ca 100644 --- a/packages/client/test/rpc/eth/getBlockTransactionCountByNumber.spec.ts +++ b/packages/client/test/rpc/eth/getBlockTransactionCountByNumber.spec.ts @@ -13,7 +13,7 @@ import type { FullEthereumService } from '../../../src/service/index.js' const method = 'eth_getBlockTransactionCountByNumber' -const common = new Common({ chain: Chain.Mainnet, hardfork: Hardfork.Istanbul }) +const common = new Common({ chain: Chain.Mainnet, hardfork: Hardfork.Chainstart }) describe(method, () => { it('call with valid arguments', async () => { @@ -23,7 +23,7 @@ describe(method, () => { validateConsensus: false, }) - const client = createClient({ blockchain, commonChain: common, includeVM: true }) + const client = await createClient({ blockchain, commonChain: common, includeVM: true }) const manager = createManager(client) const rpc = getRpcClient(startRPC(manager.getMethods())) @@ -61,7 +61,7 @@ describe(method, () => { // verify that the transaction count is 1 const res = await rpc.request(method, ['latest']) assert.equal(res.result, '0x1', 'should return the correct block transaction count(1)') - }, 20000) + }) it('call with valid arguments (multiple transactions)', async () => { const blockchain = await Blockchain.create({ @@ -70,7 +70,7 @@ describe(method, () => { validateConsensus: false, }) - const client = createClient({ blockchain, commonChain: common, includeVM: true }) + const client = await createClient({ blockchain, commonChain: common, includeVM: true }) const manager = createManager(client) const rpc = getRpcClient(startRPC(manager.getMethods())) @@ -126,12 +126,12 @@ describe(method, () => { // specify the block number instead of using latest const res = await rpc.request(method, ['0x1']) assert.equal(res.result, '0x3', 'should return the correct block transaction count(3)') - }, 30000) + }) it('call with unsupported block argument', async () => { const blockchain = await Blockchain.create() - const client = createClient({ blockchain, includeVM: true }) + const client = await createClient({ blockchain, includeVM: true }) const manager = createManager(client) const rpc = getRpcClient(startRPC(manager.getMethods())) diff --git a/packages/client/test/rpc/eth/getCode.spec.ts b/packages/client/test/rpc/eth/getCode.spec.ts index 16ff8cfc09..741cf024b1 100644 --- a/packages/client/test/rpc/eth/getCode.spec.ts +++ b/packages/client/test/rpc/eth/getCode.spec.ts @@ -13,13 +13,13 @@ import type { FullEthereumService } from '../../../src/service/index.js' const method = 'eth_getCode' -const common = new Common({ chain: Chain.Mainnet, hardfork: Hardfork.Istanbul }) +const common = new Common({ chain: Chain.Mainnet, hardfork: Hardfork.Chainstart }) describe(method, () => { it('call with valid arguments', async () => { const blockchain = await Blockchain.create({ common }) - const client = createClient({ blockchain, commonChain: common, includeVM: true }) + const client = await createClient({ blockchain, commonChain: common, includeVM: true }) const manager = createManager(client) const rpc = getRpcClient(startRPC(manager.getMethods())) @@ -34,7 +34,7 @@ describe(method, () => { // verify code is null const res = await rpc.request(method, [address.toString(), 'latest']) assert.equal(res.result, '0x', 'should return the correct code') - }, 20000) + }) it('ensure returns correct code', async () => { const blockchain = await Blockchain.create({ @@ -43,7 +43,7 @@ describe(method, () => { validateConsensus: false, }) - const client = createClient({ blockchain, commonChain: common, includeVM: true }) + const client = await createClient({ blockchain, commonChain: common, includeVM: true }) const manager = createManager(client) const rpc = getRpcClient(startRPC(manager.getMethods())) @@ -100,7 +100,7 @@ describe(method, () => { it('call with unsupported block argument', async () => { const blockchain = await Blockchain.create() - const client = createClient({ blockchain, includeVM: true }) + const client = await createClient({ blockchain, includeVM: true }) const manager = createManager(client) const rpc = getRpcClient(startRPC(manager.getMethods())) diff --git a/packages/client/test/rpc/eth/getProof.spec.ts b/packages/client/test/rpc/eth/getProof.spec.ts index c6e4cabcf7..a254fa6859 100644 --- a/packages/client/test/rpc/eth/getProof.spec.ts +++ b/packages/client/test/rpc/eth/getProof.spec.ts @@ -1,6 +1,6 @@ import { Block } from '@ethereumjs/block' import { Blockchain } from '@ethereumjs/blockchain' -import { Chain, Common, Hardfork } from '@ethereumjs/common' +import { Common } from '@ethereumjs/common' import { LegacyTransaction } from '@ethereumjs/tx' import { Address, bigIntToHex } from '@ethereumjs/util' import { assert, describe, it } from 'vitest' @@ -33,7 +33,59 @@ const expectedProof = { ], } -const common = new Common({ chain: Chain.Mainnet, hardfork: Hardfork.Istanbul }) +// Note: this is all added to ensure to run on Istanbul hardfork, and without a mainnet genesis state setup +// Without this, the test will fail because the store() method uses SHR +// Which is only available since Constantinople (and thus also in Istanbul) +// Preserving to use Istanbul as hardfork as per the original test +const testnetData = { + name: 'testnet2', + chainId: 12345, + networkId: 12345, + defaultHardfork: 'istanbul', + consensus: { + type: 'pow', + algorithm: 'ethash', + }, + genesis: { + gasLimit: 1000000, + difficulty: 1, + nonce: '0x0000000000000000', + extraData: '0x', + }, + hardforks: [ + { + name: 'chainstart', + block: 0, + }, + { + name: 'homestead', + block: 0, + }, + { + name: 'tangerineWhistle', + block: 0, + }, + { + name: 'spuriousDragon', + block: 0, + }, + { + name: 'byzantium', + block: 0, + }, + { + name: 'constantinople', + block: 0, + }, + { + name: 'istanbul', + block: 0, + }, + ], + bootstrapNodes: [], +} + +const common = new Common({ chain: 'testnet2', customChains: [testnetData] }) describe(method, async () => { it('call with valid arguments', async () => { @@ -43,7 +95,7 @@ describe(method, async () => { validateConsensus: false, }) - const client = createClient({ blockchain, commonChain: common, includeVM: true }) + const client = await createClient({ blockchain, commonChain: common, includeVM: true }) const manager = createManager(client) const rpc = getRpcClient(startRPC(manager.getMethods())) diff --git a/packages/client/test/rpc/eth/getTransactionByBlockHashAndIndex.spec.ts b/packages/client/test/rpc/eth/getTransactionByBlockHashAndIndex.spec.ts index 6a7ab3201f..6d80d17ccf 100644 --- a/packages/client/test/rpc/eth/getTransactionByBlockHashAndIndex.spec.ts +++ b/packages/client/test/rpc/eth/getTransactionByBlockHashAndIndex.spec.ts @@ -45,7 +45,7 @@ describe(method, async () => { }) it('call with no argument', async () => { - const { rpc } = baseSetup() + const { rpc } = await baseSetup() const res = await rpc.request(method, []) assert.equal(res.error.code, INVALID_PARAMS) @@ -64,7 +64,7 @@ describe(method, async () => { }) it('call with invalid block hash', async () => { - const { rpc } = baseSetup() + const { rpc } = await baseSetup() const mockBlockHash = 'INVALID_BLOCKHASH' const mockTxIndex = '0x1' @@ -75,7 +75,7 @@ describe(method, async () => { }) it('call without tx hash', async () => { - const { rpc } = baseSetup() + const { rpc } = await baseSetup() const mockBlockHash = '0x572856aae9a653012a7df7aeb56bfb7fe77f5bcb4b69fd971c04e989f6ccf9b1' @@ -85,7 +85,7 @@ describe(method, async () => { }) it('call with invalid tx hash', async () => { - const { rpc } = baseSetup() + const { rpc } = await baseSetup() const mockBlockHash = '0x572856aae9a653012a7df7aeb56bfb7fe77f5bcb4b69fd971c04e989f6ccf9b1' const mockTxIndex = 'INVALIDA_TXINDEX' @@ -96,7 +96,7 @@ describe(method, async () => { }) it('call with out-of-bound tx hash ', async () => { - const { rpc } = baseSetup() + const { rpc } = await baseSetup() const mockBlockHash = '0x572856aae9a653012a7df7aeb56bfb7fe77f5bcb4b69fd971c04e989f6ccf9b1' const mockTxIndex = '0x10' diff --git a/packages/client/test/rpc/eth/getTransactionCount.spec.ts b/packages/client/test/rpc/eth/getTransactionCount.spec.ts index ef1adef6ba..b758018158 100644 --- a/packages/client/test/rpc/eth/getTransactionCount.spec.ts +++ b/packages/client/test/rpc/eth/getTransactionCount.spec.ts @@ -13,7 +13,7 @@ import type { FullEthereumService } from '../../../src/service' const method = 'eth_getTransactionCount' -const common = new Common({ chain: Chain.Mainnet, hardfork: Hardfork.Istanbul }) +const common = new Common({ chain: Chain.Mainnet, hardfork: Hardfork.Chainstart }) describe(method, () => { it('call with valid arguments', async () => { @@ -23,7 +23,7 @@ describe(method, () => { validateConsensus: false, }) - const client = createClient({ blockchain, commonChain: common, includeVM: true }) + const client = await createClient({ blockchain, commonChain: common, includeVM: true }) const manager = createManager(client) const rpc = getRpcClient(startRPC(manager.getMethods())) @@ -72,12 +72,12 @@ describe(method, () => { // call with nonexistent account res = await rpc.request(method, [`0x${'11'.repeat(20)}`, 'latest']) assert.equal(res.result, `0x0`, 'should return 0x0 for nonexistent account') - }, 20000) + }, 30000) it('call with unsupported block argument', async () => { const blockchain = await Blockchain.create() - const client = createClient({ blockchain, includeVM: true }) + const client = await createClient({ blockchain, includeVM: true }) const manager = createManager(client) const rpc = getRpcClient(startRPC(manager.getMethods())) diff --git a/packages/client/test/rpc/eth/getUncleCountByBlockNumber.spec.ts b/packages/client/test/rpc/eth/getUncleCountByBlockNumber.spec.ts index 07c79f3d93..b731541324 100644 --- a/packages/client/test/rpc/eth/getUncleCountByBlockNumber.spec.ts +++ b/packages/client/test/rpc/eth/getUncleCountByBlockNumber.spec.ts @@ -27,7 +27,7 @@ describe(method, () => { it('call with valid arguments', async () => { const mockUncleCount = 3 - const manager = createManager(createClient({ chain: createChain() })) + const manager = createManager(await createClient({ chain: createChain() })) const rpc = getRpcClient(startRPC(manager.getMethods())) const res = await rpc.request(method, ['0x1']) @@ -35,7 +35,7 @@ describe(method, () => { }) it('call with invalid block number', async () => { - const manager = createManager(createClient({ chain: createChain() })) + const manager = createManager(await createClient({ chain: createChain() })) const rpc = getRpcClient(startRPC(manager.getMethods())) const res = await rpc.request(method, ['0x5a']) diff --git a/packages/client/test/rpc/eth/protocolVersion.spec.ts b/packages/client/test/rpc/eth/protocolVersion.spec.ts index 2e23a95c58..552402f768 100644 --- a/packages/client/test/rpc/eth/protocolVersion.spec.ts +++ b/packages/client/test/rpc/eth/protocolVersion.spec.ts @@ -6,7 +6,7 @@ const method = 'eth_protocolVersion' describe(method, () => { it('call', async () => { - const { rpc } = baseSetup() + const { rpc } = await baseSetup() const res = await rpc.request(method, []) assert.equal(typeof res.result, 'string', 'protocol version should be a string') diff --git a/packages/client/test/rpc/eth/sendRawTransaction.spec.ts b/packages/client/test/rpc/eth/sendRawTransaction.spec.ts index 4229a31a08..a7ca536f3e 100644 --- a/packages/client/test/rpc/eth/sendRawTransaction.spec.ts +++ b/packages/client/test/rpc/eth/sendRawTransaction.spec.ts @@ -43,7 +43,7 @@ describe(method, () => { hf.timestamp = undefined }) const syncTargetHeight = common.hardforkBlock(Hardfork.London) - const { rpc, client } = baseSetup({ syncTargetHeight, includeVM: true }) + const { rpc, client } = await baseSetup({ syncTargetHeight, includeVM: true }) // Mainnet EIP-1559 tx const txData = @@ -74,7 +74,7 @@ describe(method, () => { const originalSetStateRoot = DefaultStateManager.prototype.setStateRoot DefaultStateManager.prototype.setStateRoot = (): any => {} const syncTargetHeight = new Common({ chain: Chain.Mainnet }).hardforkBlock(Hardfork.London) - const { rpc } = baseSetup({ syncTargetHeight, includeVM: true }) + const { rpc } = await baseSetup({ syncTargetHeight, includeVM: true }) const transaction = LegacyTransaction.fromTxData({ gasLimit: 21000, @@ -101,7 +101,7 @@ describe(method, () => { const originalSetStateRoot = DefaultStateManager.prototype.setStateRoot DefaultStateManager.prototype.setStateRoot = (): any => {} const syncTargetHeight = new Common({ chain: Chain.Mainnet }).hardforkBlock(Hardfork.London) - const { rpc } = baseSetup({ syncTargetHeight, includeVM: true }) + const { rpc } = await baseSetup({ syncTargetHeight, includeVM: true }) // Mainnet EIP-1559 tx const txData = @@ -116,7 +116,7 @@ describe(method, () => { }) it('call with sync target height not set yet', async () => { - const { rpc, client } = baseSetup() + const { rpc, client } = await baseSetup() client.config.synchronized = false // Mainnet EIP-1559 tx @@ -134,7 +134,7 @@ describe(method, () => { it('call with invalid tx (wrong chain ID)', async () => { const syncTargetHeight = new Common({ chain: Chain.Mainnet }).hardforkBlock(Hardfork.London) - const { rpc } = baseSetup({ syncTargetHeight, includeVM: true }) + const { rpc } = await baseSetup({ syncTargetHeight, includeVM: true }) // Baikal EIP-1559 tx const txData = @@ -147,7 +147,7 @@ describe(method, () => { it('call with unsigned tx', async () => { const syncTargetHeight = new Common({ chain: Chain.Mainnet }).hardforkBlock(Hardfork.London) - const { rpc } = baseSetup({ syncTargetHeight }) + const { rpc } = await baseSetup({ syncTargetHeight }) // Mainnet EIP-1559 tx const txData = @@ -178,7 +178,7 @@ describe(method, () => { const common = new Common({ chain: Chain.Mainnet, hardfork: Hardfork.London }) const syncTargetHeight = common.hardforkBlock(Hardfork.London) - const { rpc, client } = baseSetup({ + const { rpc, client } = await baseSetup({ commonChain: common, syncTargetHeight, includeVM: true, @@ -228,7 +228,7 @@ describe(method, () => { hardfork: Hardfork.Cancun, }) common.setHardfork(Hardfork.Cancun) - const { rpc, client } = baseSetup({ + const { rpc, client } = await baseSetup({ commonChain: common, includeVM: true, syncTargetHeight: 100n, diff --git a/packages/client/test/rpc/eth/syncing.spec.ts b/packages/client/test/rpc/eth/syncing.spec.ts index 9382bdcc87..c773b06094 100644 --- a/packages/client/test/rpc/eth/syncing.spec.ts +++ b/packages/client/test/rpc/eth/syncing.spec.ts @@ -10,7 +10,7 @@ const method = 'eth_syncing' describe(method, () => { it('should return false when the client is synchronized', async () => { - const client = createClient() + const client = await createClient() const manager = createManager(client) const rpc = getRpcClient(startRPC(manager.getMethods())) @@ -24,7 +24,7 @@ describe(method, () => { }) it('should return no peer available error', async () => { - const client = createClient({ noPeers: true }) + const client = await createClient({ noPeers: true }) const manager = createManager(client) const rpcServer = startRPC(manager.getMethods()) const rpc = getRpcClient(rpcServer) @@ -38,7 +38,7 @@ describe(method, () => { }) it('should return highest block header unavailable error', async () => { - const client = createClient() + const client = await createClient() const manager = createManager(client) const rpcServer = startRPC(manager.getMethods()) const rpc = getRpcClient(rpcServer) @@ -56,7 +56,7 @@ describe(method, () => { }) it('should return syncing status object when unsynced', async () => { - const client = createClient() + const client = await createClient() const manager = createManager(client) const rpcServer = startRPC(manager.getMethods()) const rpc = getRpcClient(rpcServer) diff --git a/packages/client/test/rpc/helpers.ts b/packages/client/test/rpc/helpers.ts index 9c85b0c7e8..088ec55da4 100644 --- a/packages/client/test/rpc/helpers.ts +++ b/packages/client/test/rpc/helpers.ts @@ -84,7 +84,7 @@ export function createManager(client: EthereumClient) { return new Manager(client, client.config) } -export function createClient(clientOpts: Partial = {}) { +export async function createClient(clientOpts: Partial = {}) { const common: Common = clientOpts.commonChain ?? new Common({ chain: ChainEnum.Mainnet }) const genesisState = clientOpts.genesisState ?? getGenesis(Number(common.chainId())) ?? {} const config = new Config({ @@ -145,6 +145,7 @@ export function createClient(clientOpts: Partial = {}) { if (!(clientOpts.includeVM === false)) { const metaDB: any = clientOpts.enableMetaDB === true ? new MemoryLevel() : undefined execution = new VMExecution({ config, chain, metaDB }) + await execution.open() } let peers = [1, 2, 3] @@ -192,8 +193,8 @@ export function createClient(clientOpts: Partial = {}) { return client as EthereumClient } -export function baseSetup(clientOpts: any = {}) { - const client = createClient(clientOpts) +export async function baseSetup(clientOpts: any = {}) { + const client = await createClient(clientOpts) const manager = createManager(client) const engineMethods = clientOpts.engine === true ? manager.getMethods(true) : {} const server = startRPC({ ...manager.getMethods(), ...engineMethods }) @@ -235,7 +236,7 @@ export async function setupChain(genesisFile: any, chainName = 'dev', clientOpts }) // for the client we can pass both genesisState and genesisStateRoot and let it s - const client = createClient({ + const client = await createClient({ ...clientOpts, commonChain: common, blockchain, diff --git a/packages/client/test/rpc/mockBlockchain.ts b/packages/client/test/rpc/mockBlockchain.ts index 3ea21d066a..f4f40d4fdf 100644 --- a/packages/client/test/rpc/mockBlockchain.ts +++ b/packages/client/test/rpc/mockBlockchain.ts @@ -15,6 +15,7 @@ export function mockBlockchain(options: any = {}) { hash: () => toBytes(blockHash), header: { number: BigInt(number), + hash: () => toBytes(blockHash), }, toJSON: () => ({ ...Block.fromBlockData({ header: { number } }).toJSON(), @@ -35,6 +36,12 @@ export function mockBlockchain(options: any = {}) { getCanonicalHeadHeader: () => { return Block.fromBlockData().header }, + getIteratorHead: () => { + return block + }, + getTotalDifficulty: () => { + return number + }, genesisBlock: block, shallowCopy() { return this diff --git a/packages/client/test/rpc/net/listening.spec.ts b/packages/client/test/rpc/net/listening.spec.ts index 76221ef1ec..ed6f138855 100644 --- a/packages/client/test/rpc/net/listening.spec.ts +++ b/packages/client/test/rpc/net/listening.spec.ts @@ -6,7 +6,7 @@ const method = 'net_listening' describe(method, () => { it('call while listening', async () => { - const manager = createManager(createClient({ opened: true })) + const manager = createManager(await createClient({ opened: true })) const rpc = getRpcClient(startRPC(manager.getMethods())) const res = await rpc.request(method, []) @@ -17,7 +17,7 @@ describe(method, () => { }) it('call while not listening', async () => { - const manager = createManager(createClient({ opened: false })) + const manager = createManager(await createClient({ opened: false })) const rpc = getRpcClient(startRPC(manager.getMethods())) const res = await rpc.request(method, []) diff --git a/packages/client/test/rpc/net/peerCount.spec.ts b/packages/client/test/rpc/net/peerCount.spec.ts index abe2e3a9f2..50d32f6629 100644 --- a/packages/client/test/rpc/net/peerCount.spec.ts +++ b/packages/client/test/rpc/net/peerCount.spec.ts @@ -6,7 +6,7 @@ const method = 'net_peerCount' describe(method, () => { it('call', async () => { - const manager = createManager(createClient({ opened: true })) + const manager = createManager(await createClient({ opened: true })) const rpc = getRpcClient(startRPC(manager.getMethods())) const res = await rpc.request(method, []) diff --git a/packages/client/test/rpc/net/version.spec.ts b/packages/client/test/rpc/net/version.spec.ts index f82d80c81d..c57f6d8069 100644 --- a/packages/client/test/rpc/net/version.spec.ts +++ b/packages/client/test/rpc/net/version.spec.ts @@ -1,4 +1,3 @@ -import { BlockHeader } from '@ethereumjs/block' import { Chain, Common } from '@ethereumjs/common' import { assert, describe, it, vi } from 'vitest' @@ -19,7 +18,7 @@ function compareResult(result: any, chainId: any) { describe(method, () => { it('call on mainnet', async () => { - const { rpc } = baseSetup() + const { rpc } = await baseSetup() const res = await rpc.request(method, []) @@ -27,25 +26,23 @@ describe(method, () => { compareResult(result, '1') }) - it('call on sepolia', async () => { - // Stub out block consensusFormatValidation checks - BlockHeader.prototype['_consensusFormatValidation'] = vi.fn() + it('call on holesky', async () => { const manager = createManager( - createClient({ opened: true, commonChain: new Common({ chain: Chain.Sepolia }) }) + await createClient({ opened: true, commonChain: new Common({ chain: Chain.Holesky }) }) ) const rpc = getRpcClient(startRPC(manager.getMethods())) const res = await rpc.request(method, []) const { result } = res - compareResult(result, '11155111') + compareResult(result, '17000') vi.resetAllMocks() }) it('call on goerli', async () => { const manager = createManager( - createClient({ opened: true, commonChain: new Common({ chain: Chain.Goerli }) }) + await createClient({ opened: true, commonChain: new Common({ chain: Chain.Goerli }) }) ) const rpc = getRpcClient(startRPC(manager.getMethods())) diff --git a/packages/client/test/rpc/rpc.spec.ts b/packages/client/test/rpc/rpc.spec.ts index 3a2759f8ff..7700adb9b3 100644 --- a/packages/client/test/rpc/rpc.spec.ts +++ b/packages/client/test/rpc/rpc.spec.ts @@ -178,7 +178,7 @@ describe('callWithStackTrace', () => { throw new Error('This is not the block you are looking for') }, } - const manager = createManager(createClient({ chain: mockChain })) + const manager = createManager(await createClient({ chain: mockChain })) const server = startRPC(manager.getMethods(false, true)) const rpc = Client.http({ @@ -198,7 +198,7 @@ describe('callWithStackTrace', () => { throw new Error('This is not the block you are looking for') }, } - const manager = createManager(createClient({ chain: mockChain })) + const manager = createManager(await createClient({ chain: mockChain })) const server = startRPC(manager.getMethods(false, false)) const rpc = Client.http({ diff --git a/packages/client/test/rpc/txpool/content.spec.ts b/packages/client/test/rpc/txpool/content.spec.ts index 99a4c42f13..d83844d921 100644 --- a/packages/client/test/rpc/txpool/content.spec.ts +++ b/packages/client/test/rpc/txpool/content.spec.ts @@ -21,7 +21,7 @@ describe(method, () => { validateConsensus: false, }) - const client = createClient({ blockchain, commonChain: common, includeVM: true }) + const client = await createClient({ blockchain, commonChain: common, includeVM: true }) const manager = createManager(client) const rpc = getRpcClient(startRPC(manager.getMethods())) const { execution } = client.services.find((s) => s.name === 'eth') as FullEthereumService @@ -79,5 +79,5 @@ describe(method, () => { 1, 'received one pending transaction back from response' ) - }, 20000) + }) }) diff --git a/packages/client/test/rpc/web3/clientVersion.spec.ts b/packages/client/test/rpc/web3/clientVersion.spec.ts index 61c84b2793..a59e27a5dc 100644 --- a/packages/client/test/rpc/web3/clientVersion.spec.ts +++ b/packages/client/test/rpc/web3/clientVersion.spec.ts @@ -7,7 +7,7 @@ const method = 'web3_clientVersion' describe(method, () => { it('call', async () => { - const { rpc } = baseSetup() + const { rpc } = await baseSetup() const res = await rpc.request(method, []) diff --git a/packages/client/test/rpc/web3/sha3.spec.ts b/packages/client/test/rpc/web3/sha3.spec.ts index cd942a71e0..31706682fa 100644 --- a/packages/client/test/rpc/web3/sha3.spec.ts +++ b/packages/client/test/rpc/web3/sha3.spec.ts @@ -18,7 +18,7 @@ function compareErrorMsg(error: any, errorMsg: any) { describe(method, () => { it('call with one valid parameter', async () => { - const { rpc } = baseSetup() + const { rpc } = await baseSetup() const res = await rpc.request(method, ['0x68656c6c6f20776f726c64']) const { result } = res @@ -31,7 +31,7 @@ describe(method, () => { }) it('call with one non-hex parameter', async () => { - const { rpc } = baseSetup() + const { rpc } = await baseSetup() const res = await rpc.request(method, ['hello world']) const { error } = res @@ -41,7 +41,7 @@ describe(method, () => { }) it('call with no parameters', async () => { - const { rpc } = baseSetup() + const { rpc } = await baseSetup() const res = await rpc.request(method, []) const { error } = res diff --git a/packages/client/vitest.config.unit.ts b/packages/client/vitest.config.unit.ts index 616147f7cb..1d7df8f600 100644 --- a/packages/client/vitest.config.unit.ts +++ b/packages/client/vitest.config.unit.ts @@ -4,6 +4,6 @@ export default defineConfig({ test: { silent: true, exclude: ['test/integration', 'test/sim', 'test/cli'], - testTimeout: 180000, + testTimeout: 300000, }, })