-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: load blocks from db * fix load blocks * fix: make tests independent * fix: override storage after load blocks * fix: storage * fix: load latest block only * feat: resume using block number hash
- 1.0.2-1
- 1.0.1
- 1.0.1-1
- 1.0.0
- 0.16.2
- 0.16.1
- 0.16.0
- 0.15.0
- 0.14.2-1
- 0.14.1
- 0.14.0
- 0.13.3
- 0.13.2
- 0.13.1
- 0.13.0-1
- 0.12.2
- 0.12.1
- 0.12.1-2
- 0.12.1-1
- 0.12.0
- 0.11.0
- 0.10.2
- 0.10.1
- 0.10.0
- 0.10.0-2
- 0.10.0-1
- 0.9.13
- 0.9.12
- 0.9.11
- 0.9.11-2
- 0.9.11-1
- 0.9.10
- 0.9.9
- 0.9.9-2
- 0.9.9-1
- 0.9.8
- 0.9.8-3
- 0.9.8-2
- 0.9.8-1
- 0.9.7
- 0.9.6
- 0.9.6-4
- 0.9.6-3
- 0.9.6-2
- 0.9.6-1
- 0.9.5
- 0.9.5-4
- 0.9.5-3
- 0.9.5-2
- 0.9.5-1
- 0.9.4
- 0.9.4-6
- 0.9.4-5
- 0.9.4-4
- 0.9.4-3
- 0.9.4-2
- 0.9.4-1
- 0.9.3
- 0.9.3-2
- 0.9.3-1
- 0.9.2
- 0.9.2-6
- 0.9.2-5
- 0.9.2-4
- 0.9.2-3
- 0.9.2-2
- 0.9.2-1
- 0.9.1
- 0.9.1-5
- 0.9.1-4
- 0.9.1-3
- 0.9.1-2
- 0.9.1-1
- 0.9.0
- 0.8.5-6
- 0.8.5-5
- 0.8.5-4
- 0.8.5-3
- 0.8.5-2
- 0.8.5-1
- 0.8.5-0
- 0.8.4
- 0.8.3
- 0.8.1
Showing
6 changed files
with
91 additions
and
8 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
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 |
---|---|---|
@@ -1,29 +1,74 @@ | ||
import { afterAll, assert, describe, expect, it } from 'vitest' | ||
import { assert, describe, expect, it } from 'vitest' | ||
import { resolve } from 'node:path' | ||
import { tmpdir } from 'node:os' | ||
import networks from './networks' | ||
|
||
describe('block-save', async () => { | ||
const acala = await networks.acala({ db: resolve(tmpdir(), 'db.sqlite') }) | ||
const { chain, dev } = acala | ||
|
||
afterAll(async () => { | ||
const buildBlocks = async () => { | ||
// 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() | ||
}) | ||
|
||
return savedHeadHash | ||
} | ||
|
||
it('saved blocks data', async () => { | ||
const acala = await networks.acala({ db: resolve(tmpdir(), 'db.sqlite') }) | ||
const { chain, dev } = acala | ||
await dev.newBlock({ count: 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())) | ||
|
||
await acala.teardown() | ||
}) | ||
|
||
it('load chain using the latest saved block', async () => { | ||
const savedHeadHash = await buildBlocks() | ||
|
||
// load block | ||
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) | ||
|
||
expect(loadedHead?.hash).toEqual(savedHeadHash) | ||
await newAcala.teardown() | ||
}) | ||
|
||
it('load chain using a block number', async () => { | ||
await buildBlocks() | ||
|
||
// load blocks | ||
const newAcala = await networks.acala({ db: resolve(tmpdir(), 'db.sqlite'), resume: 3000001 }) | ||
const newHeadNumber = newAcala.chain.head.number | ||
|
||
expect(newHeadNumber).toEqual(3000001) | ||
await newAcala.teardown() | ||
}) | ||
|
||
it('load chain using a block hash', async () => { | ||
const savedHeadHash = await buildBlocks() | ||
|
||
// load blocks | ||
const newAcala = await networks.acala({ db: resolve(tmpdir(), 'db.sqlite'), resume: savedHeadHash }) | ||
const newHeadNumber = newAcala.chain.head.number | ||
const loadedHead = await newAcala.chain.getBlockAt(newHeadNumber) | ||
|
||
expect(loadedHead?.hash).toEqual(savedHeadHash) | ||
await newAcala.teardown() | ||
}) | ||
}) |
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