Skip to content

Commit 09058bd

Browse files
committed
Adapt e2e.dynval1 tests to work with foundry-rpc
1 parent 60165b5 commit 09058bd

File tree

5 files changed

+367
-256
lines changed

5 files changed

+367
-256
lines changed

test/src/e2e.dynval/1/dv.changeParams.test.ts

Lines changed: 88 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,12 @@ import RPC from "foundry-rpc";
2121
import "mocha";
2222
import * as stake from "../../stakeholder/src";
2323

24+
import { H256 } from "codechain-primitives/lib";
2425
import { validators } from "../../../tendermint.dynval/constants";
2526
import { faucetAddress, faucetSecret } from "../../helper/constants";
2627
import { PromiseExpect } from "../../helper/promise";
2728
import { changeParams, setTermTestTimeout, withNodes } from "../setup";
29+
import { ERROR } from "../../helper/error";
2830

2931
chai.use(chaiAsPromised);
3032

@@ -74,9 +76,9 @@ describe("Change commonParams that affects validator set", function() {
7476

7577
await checkingNode.waitForTx(changeTxHash);
7678

77-
const faucetSeq = await checkingNode.testFramework.rpc.chain.getSeq(
78-
faucetAddress
79-
);
79+
const faucetSeq = (await checkingNode.rpc.chain.getSeq({
80+
address: faucetAddress.toString()
81+
}))!;
8082

8183
const revoked = validators.slice(0, 3);
8284
const untouched = validators.slice(3, 5);
@@ -96,12 +98,12 @@ describe("Change commonParams that affects validator set", function() {
9698

9799
const revokeTxHashes = await Promise.all(
98100
revokeTxs.map(tx =>
99-
checkingNode.testFramework.rpc.chain.sendSignedTransaction(
100-
tx
101-
)
101+
checkingNode.rpc.mempool.sendSignedTransaction({
102+
tx: `${tx.rlpBytes().toString("hex")}`
103+
})
102104
)
103105
);
104-
await checkingNode.waitForTx(revokeTxHashes);
106+
await checkingNode.waitForTx(new H256(revokeTxHashes[0]));
105107
await termWaiter.waitNodeUntilTerm(checkingNode, {
106108
target: 2,
107109
termPeriods: 1
@@ -226,8 +228,10 @@ describe("Change commonParams that doesn't affects validator set", function() {
226228

227229
const [ts1, ts2, ts3] = await Promise.all(
228230
[term1Metadata, term2Metadata, term3Metadata].map(m =>
229-
nodes[0].testFramework.rpc.chain
230-
.getBlock(m.lastTermFinishedBlockNumber)
231+
nodes[0].rpc.chain
232+
.getBlockByNumber({
233+
blockNumber: m.lastTermFinishedBlockNumber
234+
})
231235
.then(block => block!.timestamp)
232236
)
233237
);
@@ -266,14 +270,19 @@ describe("Change commonParams that doesn't affects validator set", function() {
266270
})
267271
.sign({
268272
secret: faucetSecret,
269-
seq: await checkingNode.testFramework.rpc.chain.getSeq(
270-
faucetAddress
271-
),
273+
seq: (await checkingNode.rpc.chain.getSeq({
274+
address: faucetAddress.toString()
275+
}))!,
272276
fee: 10
273277
});
274-
await expect(
275-
checkingNode.testFramework.rpc.chain.sendSignedTransaction(tx)
276-
).rejectedWith(/Too Low Fee/);
278+
try {
279+
await checkingNode.rpc.mempool.sendSignedTransaction({
280+
tx: tx.rlpBytes().toString("hex")
281+
});
282+
expect.fail();
283+
} catch (e) {
284+
expect(e.toString()).is.include(ERROR.TOO_LOW_FEE);
285+
}
277286
});
278287
});
279288

@@ -298,29 +307,41 @@ describe("Change commonParams that doesn't affects validator set", function() {
298307
});
299308
await checkingNode.waitForTx(changeTxHash);
300309
const normalNomination = nominationWithMetadata(129);
301-
const seq = await checkingNode.testFramework.rpc.chain.getSeq(
302-
alice.platformAddress
303-
);
304-
const normalHash = await checkingNode.testFramework.rpc.chain.sendSignedTransaction(
305-
normalNomination.sign({
306-
secret: alice.privateKey,
307-
seq,
308-
fee: 10
309-
})
310+
const seq = (await checkingNode.rpc.chain.getSeq({
311+
address: alice.platformAddress.toString()
312+
}))!;
313+
const normalHash = await checkingNode.rpc.mempool.sendSignedTransaction(
314+
{
315+
tx: normalNomination
316+
.sign({
317+
secret: alice.privateKey,
318+
seq,
319+
fee: 10
320+
})
321+
.rlpBytes()
322+
.toString("hex")
323+
}
310324
);
311-
await checkingNode.waitForTx(normalHash);
325+
await checkingNode.waitForTx(new H256(normalHash));
312326

313327
const largeNomination = nominationWithMetadata(257);
314-
315-
await expect(
316-
checkingNode.testFramework.rpc.chain.sendSignedTransaction(
317-
largeNomination.sign({
318-
secret: alice.privateKey,
319-
seq: seq + 1,
320-
fee: 10
321-
})
322-
)
323-
).rejectedWith(/Too long/);
328+
try {
329+
await checkingNode.rpc.mempool.sendSignedTransaction({
330+
tx: largeNomination
331+
.sign({
332+
secret: alice.privateKey,
333+
seq: seq + 1,
334+
fee: 10
335+
})
336+
.rlpBytes()
337+
.toString("hex")
338+
});
339+
expect.fail();
340+
} catch (e) {
341+
expect(e.toString()).is.include(
342+
ERROR.ACTION_DATA_HANDLER_NOT_FOUND
343+
);
344+
}
324345
});
325346

326347
it("Should apply smaller metadata limit after decrement", async function() {
@@ -335,28 +356,41 @@ describe("Change commonParams that doesn't affects validator set", function() {
335356
});
336357
await checkingNode.waitForTx(changeTxHash);
337358
const normalNomination = nominationWithMetadata(63);
338-
const seq = await checkingNode.testFramework.rpc.chain.getSeq(
339-
alice.platformAddress
340-
);
341-
const normalHash = await checkingNode.testFramework.rpc.chain.sendSignedTransaction(
342-
normalNomination.sign({
343-
secret: alice.privateKey,
344-
seq,
345-
fee: 10
346-
})
359+
const seq = (await checkingNode.rpc.chain.getSeq({
360+
address: alice.platformAddress.toString()
361+
}))!;
362+
const normalHash = await checkingNode.rpc.mempool.sendSignedTransaction(
363+
{
364+
tx: normalNomination
365+
.sign({
366+
secret: alice.privateKey,
367+
seq,
368+
fee: 10
369+
})
370+
.rlpBytes()
371+
.toString("hex")
372+
}
347373
);
348-
await checkingNode.waitForTx(normalHash);
374+
await checkingNode.waitForTx(new H256(normalHash));
349375

350376
const largeNomination = nominationWithMetadata(127);
351-
await expect(
352-
checkingNode.testFramework.rpc.chain.sendSignedTransaction(
353-
largeNomination.sign({
354-
secret: alice.privateKey,
355-
seq: seq + 1,
356-
fee: 10
357-
})
358-
)
359-
).rejectedWith(/Too long/);
377+
try {
378+
await checkingNode.rpc.mempool.sendSignedTransaction({
379+
tx: largeNomination
380+
.sign({
381+
secret: alice.privateKey,
382+
seq: seq + 1,
383+
fee: 10
384+
})
385+
.rlpBytes()
386+
.toString("hex")
387+
});
388+
expect.fail();
389+
} catch (e) {
390+
expect(e.toString()).is.include(
391+
ERROR.ACTION_DATA_HANDLER_NOT_FOUND
392+
);
393+
}
360394
});
361395
});
362396

0 commit comments

Comments
 (0)