Skip to content

Commit bf0d9ef

Browse files
committed
Fix snapshot block estimation in test
1 parent 8a1cc1f commit bf0d9ef

File tree

1 file changed

+20
-15
lines changed

1 file changed

+20
-15
lines changed

test/src/e2e.dynval/2/snapshot.test.ts

+20-15
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,15 @@
1717
import * as chai from "chai";
1818
import { expect } from "chai";
1919
import * as chaiAsPromised from "chai-as-promised";
20+
import * as stake from "codechain-stakeholder-sdk";
2021
import * as fs from "fs";
2122
import "mocha";
2223
import * as path from "path";
2324

2425
import mkdirp = require("mkdirp");
2526
import { validators } from "../../../tendermint.dynval/constants";
2627
import { PromiseExpect } from "../../helper/promise";
28+
import CodeChain from "../../helper/spawn";
2729
import { setTermTestTimeout, withNodes } from "../setup";
2830

2931
chai.use(chaiAsPromised);
@@ -37,7 +39,8 @@ describe("Snapshot for Tendermint with Dynamic Validator", function() {
3739
const { nodes } = withNodes(this, {
3840
promiseExpect,
3941
overrideParams: {
40-
maxNumOfValidators: 3
42+
maxNumOfValidators: 3,
43+
era: 1
4144
},
4245
validators: snapshotValidators.map((signer, index) => ({
4346
signer,
@@ -63,30 +66,32 @@ describe("Snapshot for Tendermint with Dynamic Validator", function() {
6366

6467
it("should be exist after some time", async function() {
6568
const termWaiter = setTermTestTimeout(this, {
66-
terms: 1
69+
terms: 2
6770
});
6871
const termMetadata = await termWaiter.waitNodeUntilTerm(nodes[0], {
6972
target: 2,
7073
termPeriods: 1
7174
});
72-
73-
const blockHash = (await nodes[0].sdk.rpc.chain.getBlockHash(
74-
termMetadata.lastTermFinishedBlockNumber
75-
))!;
76-
const stateRoot = (await nodes[0].sdk.rpc.chain.getBlock(blockHash))!
77-
.stateRoot;
75+
const snapshotBlock = await getSnapshotBlock(nodes[0], termMetadata);
7876
expect(
79-
fs.existsSync(
80-
path.join(
81-
nodes[0].snapshotPath,
82-
blockHash.toString(),
83-
stateRoot.toString()
84-
)
77+
path.join(
78+
nodes[0].snapshotPath,
79+
snapshotBlock.hash.toString(),
80+
snapshotBlock.stateRoot.toString()
8581
)
86-
).to.be.true;
82+
).to.satisfy(fs.existsSync);
8783
});
8884

8985
afterEach(async function() {
9086
promiseExpect.checkFulfilled();
9187
});
9288
});
89+
90+
async function getSnapshotBlock(
91+
node: CodeChain,
92+
termMetadata: stake.TermMetadata
93+
) {
94+
const blockNumber = termMetadata.lastTermFinishedBlockNumber + 1;
95+
await node.waitBlockNumber(blockNumber);
96+
return (await node.sdk.rpc.chain.getBlock(blockNumber))!;
97+
}

0 commit comments

Comments
 (0)