Skip to content

Commit

Permalink
Fix snapshot block estimation in test
Browse files Browse the repository at this point in the history
  • Loading branch information
foriequal0 committed Dec 9, 2019
1 parent d270684 commit 246eca5
Showing 1 changed file with 20 additions and 15 deletions.
35 changes: 20 additions & 15 deletions test/src/e2e.dynval/2/snapshot.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@
import * as chai from "chai";
import { expect } from "chai";
import * as chaiAsPromised from "chai-as-promised";
import * as stake from "codechain-stakeholder-sdk";
import * as fs from "fs";
import "mocha";
import * as path from "path";

import mkdirp = require("mkdirp");
import { validators } from "../../../tendermint.dynval/constants";
import { PromiseExpect } from "../../helper/promise";
import CodeChain from "../../helper/spawn";
import { setTermTestTimeout, withNodes } from "../setup";

chai.use(chaiAsPromised);
Expand All @@ -37,7 +39,8 @@ describe("Snapshot for Tendermint with Dynamic Validator", function() {
const { nodes } = withNodes(this, {
promiseExpect,
overrideParams: {
maxNumOfValidators: 3
maxNumOfValidators: 3,
era: 1
},
validators: snapshotValidators.map((signer, index) => ({
signer,
Expand All @@ -63,30 +66,32 @@ describe("Snapshot for Tendermint with Dynamic Validator", function() {

it("should be exist after some time", async function() {
const termWaiter = setTermTestTimeout(this, {
terms: 1
terms: 2
});
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;
const snapshotBlock = await getSnapshotBlock(nodes[0], termMetadata);
expect(
fs.existsSync(
path.join(
nodes[0].snapshotPath,
blockHash.toString(),
stateRoot.toString()
)
path.join(
nodes[0].snapshotPath,
snapshotBlock.hash.toString(),
snapshotBlock.stateRoot.toString()
)
).to.be.true;
).to.satisfy(fs.existsSync);
});

afterEach(async function() {
promiseExpect.checkFulfilled();
});
});

async function getSnapshotBlock(
node: CodeChain,
termMetadata: stake.TermMetadata
) {
const blockNumber = termMetadata.lastTermFinishedBlockNumber + 1;
await node.waitBlockNumber(blockNumber);
return (await node.sdk.rpc.chain.getBlock(blockNumber))!;
}

0 comments on commit 246eca5

Please sign in to comment.