Skip to content

Commit

Permalink
fix: make tests independent
Browse files Browse the repository at this point in the history
  • Loading branch information
qiweiii committed Sep 11, 2023
1 parent a995fb5 commit 42b9727
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions packages/e2e/src/blocks-save.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,42 @@ 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))
expect(blockData.parentHash).toEqual((await block.parentBlock)!.hash)
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()
})
})

0 comments on commit 42b9727

Please sign in to comment.