Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
111 changes: 46 additions & 65 deletions test/src/e2e.dynval/2/snapshot.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder why this line passed the linter.
It should've been marked as unused import.

import * as stake from "codechain-stakeholder-sdk";
import * as fs from "fs";
import "mocha";
import * as path from "path";
Expand All @@ -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() {
Expand Down
4 changes: 2 additions & 2 deletions test/src/e2e.dynval/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ interface TermWaiter {
target: number;
termPeriods: number;
}
): Promise<void>;
): Promise<stake.TermMetadata>;
}

export function setTermTestTimeout(
Expand Down Expand Up @@ -477,7 +477,7 @@ export function setTermTestTimeout(
termPeriods: number;
}
) {
await node.waitForTermChange(
return await node.waitForTermChange(
waiterParams.target,
termPeriodsToTime(waiterParams.termPeriods, 0.5)
);
Expand Down
2 changes: 1 addition & 1 deletion test/src/helper/spawn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down