diff --git a/packages/e2e/src/blocks-save.test.ts b/packages/e2e/src/blocks-save.test.ts index 0726287c..2c284f67 100644 --- a/packages/e2e/src/blocks-save.test.ts +++ b/packages/e2e/src/blocks-save.test.ts @@ -4,20 +4,17 @@ import { tmpdir } from 'node:os' import networks from './networks' describe('block-save', async () => { - let savedBlockHash: string - it('saved blocks data', async () => { - const acala = await networks.acala({ db: resolve(tmpdir(), 'testdb.sqlite') }) + const acala = await networks.acala({ db: resolve(tmpdir(), 'db.sqlite') }) const { chain, dev } = acala - const blockNumber = chain.head.number - await dev.newBlock({ count: 2 }) - expect(chain.head.number).eq(blockNumber + 2) + const numberOfBlocks = await chain.db!.getRepository('Block').count() expect(numberOfBlocks).toEqual(2) const block = await chain.getBlockAt(chain.head.number) const blockData = await chain.db!.getRepository('Block').findOne({ where: { number: chain.head.number } }) + assert(block && blockData, 'block and blockData should be defined') expect(blockData.hash).toEqual(block.hash) expect(JSON.stringify(blockData.header)).toEqual(JSON.stringify(block.header)) @@ -25,18 +22,24 @@ describe('block-save', async () => { expect(JSON.stringify(blockData.extrinsics)).toEqual(JSON.stringify(await block.extrinsics)) expect(JSON.stringify(blockData.storageDiff)).toEqual(JSON.stringify(await block.storageDiff())) - savedBlockHash = block.hash - await acala.teardown() }) it('load chain from the saved blocks', async () => { - const acala = await networks.acala({ db: resolve(tmpdir(), 'testdb.sqlite'), resume: true }) - const { chain } = acala + // save blocks + const acala = await networks.acala({ db: resolve(tmpdir(), 'db.sqlite') }) + const { chain, dev } = acala + await dev.newBlock({ count: 2 }) const head = await chain.getBlockAt(chain.head.number) + const savedHeadHash = head?.hash + await acala.teardown() - expect(head?.hash).toEqual(savedBlockHash) + // load blocks + const newAcala = await networks.acala({ db: resolve(tmpdir(), 'db.sqlite'), resume: true }) + const newHeadNumber = newAcala.chain.head.number + const loadedHead = await newAcala.chain.getBlockAt(newHeadNumber) - await acala.teardown() + expect(loadedHead?.hash).toEqual(savedHeadHash) + await newAcala.teardown() }) })