Skip to content

Commit 98748e9

Browse files
HoOngEemajecty
authored andcommitted
Add test case: ban from the validators
1 parent 401843c commit 98748e9

File tree

1 file changed

+91
-0
lines changed

1 file changed

+91
-0
lines changed

test/src/e2e.dynval/dv.double-vote.test.ts

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ import { validators as originalValidators } from "../../tendermint.dynval/consta
3434
import { faucetAddress, faucetSecret } from "../helper/constants";
3535
import { PromiseExpect } from "../helper/promise";
3636
import { Signer } from "../helper/spawn";
37+
import CodeChain from "../helper/spawn";
38+
import { withNodes, setTermTestTimeout } from "./setup";
3739

3840
chai.use(chaiAsPromised);
3941

@@ -146,6 +148,95 @@ async function ensureAliceIsBanned(sdk: SDK, blockNumber: number) {
146148
describe("Report Double Vote", function() {
147149
const promiseExpect = new PromiseExpect();
148150

151+
async function getAliceIndex(
152+
sdk: SDK,
153+
blockNumber: number
154+
): Promise<number> {
155+
return (await stake.getPossibleAuthors(sdk, blockNumber))!
156+
.map(platfromAddr => platfromAddr.toString())
157+
.indexOf(alice.platformAddress.toString());
158+
}
159+
160+
async function waitUntilAliceGetBanned(
161+
checkingNode: CodeChain,
162+
reportTxHash: H256
163+
): Promise<number> {
164+
await checkingNode.waitForTx(reportTxHash);
165+
const blockNumberAfterReport =
166+
(await checkingNode.sdk.rpc.chain.getBestBlockNumber()) + 1;
167+
await checkingNode.waitBlockNumber(blockNumberAfterReport);
168+
return blockNumberAfterReport;
169+
}
170+
171+
describe("Ban from the validator state", async function() {
172+
const { nodes } = withNodes(this, {
173+
promiseExpect,
174+
validators: allDynValidators.map(signer => ({
175+
signer,
176+
delegation: 5_000,
177+
deposit: 10_000_000
178+
}))
179+
});
180+
181+
it("alice should be banned from the validators", async function() {
182+
const secsPerblock = 3;
183+
this.slow(secsPerblock * 7 * 1000);
184+
this.timeout(secsPerblock * 14 * 1000);
185+
186+
const checkingNode = nodes[1];
187+
const blockNumber = await checkingNode.sdk.rpc.chain.getBestBlockNumber();
188+
const termMetadata = await stake.getTermMetadata(
189+
checkingNode.sdk,
190+
blockNumber
191+
);
192+
const currentTermInitialBlockNumber =
193+
termMetadata!.lastTermFinishedBlockNumber + 1;
194+
expect(termMetadata!.currentTermId).to.be.equals(1);
195+
await expectPossibleAuthors(checkingNode.sdk, allDynValidators);
196+
await checkingNode.waitBlockNumber(
197+
currentTermInitialBlockNumber + 1
198+
);
199+
const aliceIdx = await getAliceIndex(
200+
checkingNode.sdk,
201+
currentTermInitialBlockNumber
202+
);
203+
204+
const [message1, message2] = createDoubleVoteMessages(
205+
{
206+
height: currentTermInitialBlockNumber,
207+
view: 0,
208+
step: "precommit",
209+
privKey: alice.privateKey,
210+
signerIdx: aliceIdx
211+
},
212+
H256.ensure(
213+
"730f75dafd73e047b86acb2dbd74e75dcb93272fa084a9082848f2341aa1abb6"
214+
),
215+
H256.ensure(
216+
"07f5937c9760f50867a78fa68982b1096cec0798448abf9395cd778fcded6f8d"
217+
)
218+
);
219+
220+
const reportTx = createReportDoubleVoteTransaction(
221+
checkingNode.sdk,
222+
message1,
223+
message2
224+
);
225+
const reportTxHash = await checkingNode.sdk.rpc.chain.sendSignedTransaction(
226+
reportTx.sign({
227+
secret: faucetSecret,
228+
seq: await checkingNode.sdk.rpc.chain.getSeq(faucetAddress),
229+
fee: 10
230+
})
231+
);
232+
const blockNumberAfterReport = await waitUntilAliceGetBanned(
233+
checkingNode,
234+
reportTxHash
235+
);
236+
await ensureAliceIsBanned(checkingNode.sdk, blockNumberAfterReport);
237+
});
238+
});
239+
149240
afterEach(async function() {
150241
promiseExpect.checkFulfilled();
151242
});

0 commit comments

Comments
 (0)