From 3703043ff3c08d0fd673af83c6fe640cb8c94ec1 Mon Sep 17 00:00:00 2001 From: SeongChan Lee Date: Wed, 20 Nov 2019 18:00:54 +0900 Subject: [PATCH 1/2] Change waitNodeUntilTerm to return TermMetadata --- test/src/e2e.dynval/2/snapshot.test.ts | 20 ++------------------ test/src/e2e.dynval/setup.ts | 4 ++-- test/src/helper/spawn.ts | 2 +- 3 files changed, 5 insertions(+), 21 deletions(-) diff --git a/test/src/e2e.dynval/2/snapshot.test.ts b/test/src/e2e.dynval/2/snapshot.test.ts index cc04a44438..a2e26daf91 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"; @@ -69,26 +67,13 @@ describe("Snapshot for Tendermint with Dynamic Validator", function() { const termWaiter = setTermTestTimeout(this, { terms: 1 }); - await termWaiter.waitNodeUntilTerm(nodes[0], { + const termMetadata = 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 + termMetadata.lastTermFinishedBlockNumber ))!; const stateRoot = (await nodes[0].sdk.rpc.chain.getBlock( blockHash @@ -104,7 +89,6 @@ describe("Snapshot for Tendermint with Dynamic Validator", function() { ).to.be.true; }); }); - afterEach(async function() { promiseExpect.checkFulfilled(); }); 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) { From 75419dc2d0c60535494fc1f0a4c90919f1fa14d1 Mon Sep 17 00:00:00 2001 From: SeongChan Lee Date: Wed, 20 Nov 2019 18:06:50 +0900 Subject: [PATCH 2/2] Remove unnecessary nested 'describe' --- test/src/e2e.dynval/2/snapshot.test.ts | 97 +++++++++++++------------- 1 file changed, 47 insertions(+), 50 deletions(-) diff --git a/test/src/e2e.dynval/2/snapshot.test.ts b/test/src/e2e.dynval/2/snapshot.test.ts index a2e26daf91..32374c992d 100644 --- a/test/src/e2e.dynval/2/snapshot.test.ts +++ b/test/src/e2e.dynval/2/snapshot.test.ts @@ -34,61 +34,58 @@ 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 - }); - const termMetadata = await termWaiter.waitNodeUntilTerm(nodes[0], { - target: 2, - termPeriods: 1 - }); - - 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() - ) + 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() { promiseExpect.checkFulfilled(); });