diff --git a/test/src/e2e.dynval/2/snapshot.test.ts b/test/src/e2e.dynval/2/snapshot.test.ts index cc04a44438..32374c992d 100644 --- a/test/src/e2e.dynval/2/snapshot.test.ts +++ b/test/src/e2e.dynval/2/snapshot.test.ts @@ -17,8 +17,6 @@ import * as chai from "chai"; import { expect } from "chai"; import * as chaiAsPromised from "chai-as-promised"; -import { SDK } from "codechain-sdk"; -import * as stake from "codechain-stakeholder-sdk"; import * as fs from "fs"; import "mocha"; import * as path from "path"; @@ -36,73 +34,56 @@ const SNAPSHOT_PATH = `${__dirname}/../../../../snapshot/`; describe("Snapshot for Tendermint with Dynamic Validator", function() { const promiseExpect = new PromiseExpect(); const snapshotValidators = validators.slice(0, 3); + const { nodes } = withNodes(this, { + promiseExpect, + overrideParams: { + maxNumOfValidators: 3 + }, + validators: snapshotValidators.map((signer, index) => ({ + signer, + delegation: 5000, + deposit: 10_000_000 - index // tie-breaker + })), + modify: () => { + mkdirp.sync(SNAPSHOT_PATH); + const snapshotPath = fs.mkdtempSync(SNAPSHOT_PATH); + return { + additionalArgv: [ + "--snapshot-path", + snapshotPath, + "--config", + SNAPSHOT_CONFIG + ], + nodeAdditionalProperties: { + snapshotPath + } + }; + } + }); - describe("Snapshot", async function() { - const { nodes } = withNodes(this, { - promiseExpect, - overrideParams: { - maxNumOfValidators: 3 - }, - validators: snapshotValidators.map((signer, index) => ({ - signer, - delegation: 5000, - deposit: 10_000_000 - index // tie-breaker - })), - modify: () => { - mkdirp.sync(SNAPSHOT_PATH); - const snapshotPath = fs.mkdtempSync(SNAPSHOT_PATH); - return { - additionalArgv: [ - "--snapshot-path", - snapshotPath, - "--config", - SNAPSHOT_CONFIG - ], - nodeAdditionalProperties: { - snapshotPath - } - }; - } + it("should be exist after some time", async function() { + const termWaiter = setTermTestTimeout(this, { + terms: 1 + }); + const termMetadata = await termWaiter.waitNodeUntilTerm(nodes[0], { + target: 2, + termPeriods: 1 }); - it("should be exist after some time", async function() { - const termWaiter = setTermTestTimeout(this, { - terms: 1 - }); - await termWaiter.waitNodeUntilTerm(nodes[0], { - target: 2, - termPeriods: 1 - }); - const blockNumber = await nodes[0].sdk.rpc.chain.getBestBlockNumber(); - const termMetadata = await stake.getTermMetadata( - nodes[0].sdk, - blockNumber - ); - - expect(termMetadata).not.to.be.null; - const { - currentTermId, - lastTermFinishedBlockNumber - } = termMetadata!; - expect(currentTermId).to.be.equals(2); - expect(lastTermFinishedBlockNumber).to.be.lte(blockNumber); - - const blockHash = (await nodes[0].sdk.rpc.chain.getBlockHash( - lastTermFinishedBlockNumber - ))!; - const stateRoot = (await nodes[0].sdk.rpc.chain.getBlock( - blockHash - ))!.stateRoot; - expect( - fs.existsSync( - path.join( - nodes[0].snapshotPath, - blockHash.toString(), - stateRoot.toString() - ) + const blockHash = (await nodes[0].sdk.rpc.chain.getBlockHash( + termMetadata.lastTermFinishedBlockNumber + ))!; + const stateRoot = (await nodes[0].sdk.rpc.chain.getBlock(blockHash))! + .stateRoot; + expect( + fs.existsSync( + path.join( + nodes[0].snapshotPath, + blockHash.toString(), + stateRoot.toString() ) - ).to.be.true; - }); + ) + ).to.be.true; }); afterEach(async function() { diff --git a/test/src/e2e.dynval/setup.ts b/test/src/e2e.dynval/setup.ts index fdaf8c5a80..ca5a9e25cb 100644 --- a/test/src/e2e.dynval/setup.ts +++ b/test/src/e2e.dynval/setup.ts @@ -445,7 +445,7 @@ interface TermWaiter { target: number; termPeriods: number; } - ): Promise; + ): Promise; } export function setTermTestTimeout( @@ -477,7 +477,7 @@ export function setTermTestTimeout( termPeriods: number; } ) { - await node.waitForTermChange( + return await node.waitForTermChange( waiterParams.target, termPeriodsToTime(waiterParams.termPeriods, 0.5) ); diff --git a/test/src/helper/spawn.ts b/test/src/helper/spawn.ts index a2919bb290..020fc1aaa6 100644 --- a/test/src/helper/spawn.ts +++ b/test/src/helper/spawn.ts @@ -855,7 +855,7 @@ export default class CodeChain { while (true) { const termMetadata = await stake.getTermMetadata(this.sdk); if (termMetadata && termMetadata.currentTermId >= target) { - break; + return termMetadata; } await wait(1000); if (timeout) {