Skip to content

Commit

Permalink
client: Increase client test coverage (#2757)
Browse files Browse the repository at this point in the history
* Write test to test vmexecution's executeBlocks function

* Write test to test fullsync's processBlocks function

---------

Co-authored-by: acolytec3 <konjou@gmail.com>
  • Loading branch information
scorbajio and acolytec3 authored Jun 6, 2023
1 parent 399247b commit 3b1976b
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
19 changes: 19 additions & 0 deletions packages/client/test/execution/vmexecution.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,25 @@ tape('[VMExecution]', async (t) => {
t.end()
})

t.test('Test block execution using executeBlocks function', async (t) => {
let blockchain = await Blockchain.create({
validateBlocks: true,
validateConsensus: false,
})
let exec = await testSetup(blockchain)

blockchain = await Blockchain.fromBlocksData(blocksDataMainnet, {
validateBlocks: true,
validateConsensus: false,
})
exec = await testSetup(blockchain)
await exec.run()

t.doesNotThrow(async () => exec.executeBlocks(1, 5, []), 'blocks should execute without error')

t.end()
})

t.test('Should fail opening if vmPromise already assigned', async (t) => {
const blockchain = await Blockchain.create({
validateBlocks: true,
Expand Down
26 changes: 26 additions & 0 deletions packages/client/test/sync/fullsync.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,32 @@ tape('[FullSynchronizer]', async (t) => {
td.verify(chain.putBlocks([newBlock]))
})

t.test('should process blocks', async (t) => {
const config = new Config({ transports: [], accountCache: 10000, storageCache: 1000 })
const pool = new PeerPool() as any
const chain = await Chain.create({ config })
const sync = new FullSynchronizer({
config,
interval: 1,
pool,
chain,
txPool,
execution,
})

const chainTip = Block.fromBlockData({
header: {},
})
const newBlock = Block.fromBlockData({
header: {
parentHash: chainTip.hash(),
},
})

sync.running = true
t.ok(await sync.processBlocks([newBlock]), 'should successfully process blocks')
})

t.test('should reset td', (t) => {
td.reset()
t.end()
Expand Down

0 comments on commit 3b1976b

Please sign in to comment.