-
Notifications
You must be signed in to change notification settings - Fork 772
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Implement debug_setHead * Update packages/client/src/rpc/modules/debug.ts Co-authored-by: acolytec3 <[email protected]> * Complete the implementation of debug_setHead * Add helpers for creating blockchains and blocks for testing * Add test for debug_setHead * Set head of vmexecution as well * Do not prerun block before setting as vmexecution head * Move and export testSetup function and clean up tests * Remove unused util functions * Do not return nonstandard string from debug_setHead * Fix lint issues --------- Co-authored-by: acolytec3 <[email protected]>
- Loading branch information
Showing
4 changed files
with
87 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { createBlockchainFromBlocksData } from '@ethereumjs/blockchain' | ||
import { assert, describe, it } from 'vitest' | ||
|
||
import { mainnetData } from '../../testdata/blocks/mainnet.js' | ||
import { createClient, createManager, getRPCClient, startRPC, testSetup } from '../helpers.js' | ||
|
||
import type { Blockchain } from '@ethereumjs/blockchain' | ||
|
||
const method = 'debug_setHead' | ||
|
||
describe(method, async () => { | ||
it('call with valid arguments', async () => { | ||
const blockchain = await createBlockchainFromBlocksData(mainnetData, { | ||
validateBlocks: true, | ||
validateConsensus: false, | ||
}) | ||
const blocks = await blockchain.getBlocks(0, 6, 0, false) | ||
const exec = await testSetup(blockchain) | ||
await exec.run() | ||
const newHead = await (exec.vm.blockchain as Blockchain).getIteratorHead!() | ||
assert.equal(newHead.header.number, BigInt(5), 'should run all blocks') | ||
|
||
const a = await createClient({ blockchain }) | ||
await a.service.skeleton?.open() | ||
;(a.service.execution as any) = exec | ||
|
||
const manager = createManager(a) | ||
const rpc = getRPCClient(startRPC(manager.getMethods())) | ||
assert.equal( | ||
await a.service.skeleton?.headHash(), | ||
undefined, | ||
'should return undefined when head is not set', | ||
) | ||
for (let i = 0; i < blocks.length; i++) { | ||
await rpc.request(method, [`0x${i}`]) | ||
assert.deepEqual( | ||
await a.service.skeleton?.headHash()!, | ||
blocks[i].header.hash(), | ||
`skeleton chain should return hash of block number ${i} set as head`, | ||
) | ||
assert.deepEqual( | ||
a.service.execution.chainStatus?.hash!, | ||
blocks[i].header.hash(), | ||
`vm execution should set hash to new head`, | ||
) | ||
} | ||
}, 30000) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters