Skip to content

Commit ee298a8

Browse files
committed
Adapt e2e.dynval2 to work with foundry
1 parent 8221c17 commit ee298a8

File tree

7 files changed

+142
-100
lines changed

7 files changed

+142
-100
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ describe("Auto Self Nomination", function() {
6363

6464
const aliceNode = findNode(nodes, alice);
6565
const selfNominationHash = await selfNominate(
66+
aliceNode.rpc,
6667
aliceNode.testFramework,
6768
alice,
6869
10

test/src/e2e.dynval/2/dv.n+1.test.ts

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import { validators } from "../../../tendermint.dynval/constants";
2323
import { faucetAddress, faucetSecret } from "../../helper/constants";
2424
import { PromiseExpect } from "../../helper/promise";
2525
import { findNode, setTermTestTimeout, withNodes } from "../setup";
26+
import { H256 } from "codechain-primitives/lib";
2627

2728
describe("Dynamic Validator N -> N+1", function() {
2829
const promiseExpect = new PromiseExpect();
@@ -99,13 +100,13 @@ describe("Dynamic Validator N -> N+1", function() {
99100
)
100101
.sign({
101102
secret: betty.privateKey,
102-
seq: await bettyNode.testFramework.rpc.chain.getSeq(
103-
betty.platformAddress
104-
),
103+
seq: (await bettyNode.rpc.chain.getSeq({
104+
address: betty.platformAddress.toString()
105+
}))!,
105106
fee: 10
106107
});
107-
const nominateTxHash = bettyNode.testFramework.rpc.chain.sendSignedTransaction(
108-
nominateTx
108+
const nominateTxHash = await bettyNode.rpc.mempool.sendSignedTransaction(
109+
{ tx: nominateTx.rlpBytes().toString("hex") }
109110
);
110111
const delegateTx = stake
111112
.createDelegateCCSTransaction(
@@ -115,15 +116,18 @@ describe("Dynamic Validator N -> N+1", function() {
115116
)
116117
.sign({
117118
secret: faucetSecret,
118-
seq: await bettyNode.testFramework.rpc.chain.getSeq(
119-
faucetAddress
120-
),
119+
seq: (await bettyNode.rpc.chain.getSeq({
120+
address: faucetAddress.toString()
121+
}))!,
121122
fee: 10
122123
});
123-
const delegateTxHash = bettyNode.testFramework.rpc.chain.sendSignedTransaction(
124-
delegateTx
124+
const delegateTxHash = await bettyNode.rpc.mempool.sendSignedTransaction(
125+
{ tx: delegateTx.rlpBytes().toString("hex") }
125126
);
126-
await checkingNode.waitForTx([nominateTxHash, delegateTxHash]);
127+
await checkingNode.waitForTx([
128+
new H256(nominateTxHash),
129+
new H256(delegateTxHash)
130+
]);
127131

128132
await termWaiter.waitNodeUntilTerm(checkingNode, {
129133
target: 2,
@@ -161,15 +165,15 @@ describe("Dynamic Validator N -> N+1", function() {
161165
)
162166
.sign({
163167
secret: betty.privateKey,
164-
seq: await checkingNode.testFramework.rpc.chain.getSeq(
165-
betty.platformAddress
166-
),
168+
seq: (await checkingNode.rpc.chain.getSeq({
169+
address: betty.platformAddress.toString()
170+
}))!,
167171
fee: 10
168172
});
169-
const nominateTxHash = checkingNode.testFramework.rpc.chain.sendSignedTransaction(
170-
nominateTx
173+
const nominateTxHash = await checkingNode.rpc.mempool.sendSignedTransaction(
174+
{ tx: nominateTx.rlpBytes().toString("hex") }
171175
);
172-
await checkingNode.waitForTx(nominateTxHash);
176+
await checkingNode.waitForTx(new H256(nominateTxHash));
173177

174178
await termWaiter.waitNodeUntilTerm(checkingNode, {
175179
target: 2,
@@ -199,9 +203,9 @@ describe("Dynamic Validator N -> N+1", function() {
199203

200204
const checkingNode = nodes[0];
201205
await beforeInsertionCheck(checkingNode.rpc);
202-
const faucetSeq = await checkingNode.testFramework.rpc.chain.getSeq(
203-
faucetAddress
204-
);
206+
const faucetSeq = (await checkingNode.rpc.chain.getSeq({
207+
address: faucetAddress.toString()
208+
}))!;
205209
const delegateTx = stake
206210
.createDelegateCCSTransaction(
207211
checkingNode.testFramework,
@@ -213,10 +217,10 @@ describe("Dynamic Validator N -> N+1", function() {
213217
seq: faucetSeq,
214218
fee: 10
215219
});
216-
const delegateTxHash = checkingNode.testFramework.rpc.chain.sendSignedTransaction(
217-
delegateTx
220+
const delegateTxHash = await checkingNode.rpc.mempool.sendSignedTransaction(
221+
{ tx: delegateTx.rlpBytes().toString("hex") }
218222
);
219-
await checkingNode.waitForTx(delegateTxHash);
223+
await checkingNode.waitForTx(new H256(delegateTxHash));
220224

221225
await termWaiter.waitNodeUntilTerm(checkingNode, {
222226
target: 2,

test/src/e2e.dynval/2/dv.nomination.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ describe("Nomination", function() {
5858

5959
const aliceNode = findNode(nodes, alice);
6060
const selfNominationHash = await selfNominate(
61+
aliceNode.rpc,
6162
aliceNode.testFramework,
6263
alice,
6364
10

test/src/e2e.dynval/2/dv.shutdown.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,9 @@ describe("Shutdown test", function() {
101101
let lastBlockNumber: number;
102102
while (true) {
103103
lastBlockNumber = await node.getBestBlockNumber();
104-
const block = (await node.testFramework.rpc.chain.getBlock(
105-
lastBlockNumber
106-
))!;
104+
const block = (await node.rpc.chain.getBlockByNumber({
105+
blockNumber: lastBlockNumber
106+
}))!;
107107
if (block.timestamp >= targetTS) {
108108
return;
109109
}
@@ -257,8 +257,8 @@ describe("Shutdown test", function() {
257257
2,
258258
"Term should be changed"
259259
);
260-
const block = (await getObserver().node.testFramework.rpc.chain.getBlock(
261-
blockNumberAtStop + 1
260+
const block = (await getObserver().node.rpc.chain.getBlockByNumber(
261+
{ blockNumber: blockNumberAtStop + 1 }
262262
))!;
263263
expect(getValidators().addrs).to.include(
264264
block.author.toString(),

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

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import * as stake from "../../stakeholder/src";
2323
import { validators } from "../../../tendermint.dynval/constants";
2424
import { PromiseExpect } from "../../helper/promise";
2525
import { setTermTestTimeout, withNodes } from "../setup";
26+
import { H256 } from "codechain-primitives/lib";
2627

2728
chai.use(chaiAsPromised);
2829

@@ -135,16 +136,19 @@ describe("Jail state transition test", function() {
135136
10_000_000,
136137
""
137138
);
138-
const hash = await node.testFramework.rpc.chain.sendSignedTransaction(
139-
nomination.sign({
140-
secret: alice.privateKey,
141-
seq: await node.testFramework.rpc.chain.getSeq(
142-
alice.platformAddress
143-
),
144-
fee: 10
145-
})
146-
);
147-
await node.waitForTx(hash);
139+
const hash = await node.rpc.mempool.sendSignedTransaction({
140+
tx: nomination
141+
.sign({
142+
secret: alice.privateKey,
143+
seq: (await node.rpc.chain.getSeq({
144+
address: alice.platformAddress.toString()
145+
}))!,
146+
fee: 10
147+
})
148+
.rlpBytes()
149+
.toString("hex")
150+
});
151+
await node.waitForTx(new H256(hash));
148152

149153
await termWaiter.waitNodeUntilTerm(node, { target: 5, termPeriods: 1 });
150154
expect(await isCandidate(alice)).to.be.true;
@@ -161,16 +165,19 @@ describe("Jail state transition test", function() {
161165
10_000_000,
162166
""
163167
);
164-
const hash = await node.testFramework.rpc.chain.sendSignedTransaction(
165-
nomination.sign({
166-
secret: alice.privateKey,
167-
seq: await node.testFramework.rpc.chain.getSeq(
168-
alice.platformAddress
169-
),
170-
fee: 10
171-
})
172-
);
173-
await expect(node.waitForTx(hash)).rejectedWith(
168+
const hash = await node.rpc.mempool.sendSignedTransaction({
169+
tx: nomination
170+
.sign({
171+
secret: alice.privateKey,
172+
seq: (await node.rpc.chain.getSeq({
173+
address: alice.platformAddress.toString()
174+
}))!,
175+
fee: 10
176+
})
177+
.rlpBytes()
178+
.toString("hex")
179+
});
180+
await expect(node.waitForTx(new H256(hash))).rejectedWith(
174181
"Account is still in custody"
175182
);
176183
await termWaiter.waitNodeUntilTerm(node, { target: 3, termPeriods: 1 });

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

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import { faucetAddress, faucetSecret } from "../../helper/constants";
2929
import { PromiseExpect } from "../../helper/promise";
3030
import CodeChain, { Signer } from "../../helper/spawn";
3131
import { setTermTestTimeout, withNodes } from "../setup";
32+
import { H256 } from "codechain-primitives/lib";
3233

3334
chai.use(chaiAsPromised);
3435

@@ -125,14 +126,14 @@ describe("Snapshot for Tendermint with Dynamic Validator", function() {
125126
await freshValidatorCheck(nodes[0].rpc);
126127

127128
expect(
128-
await node.testFramework.rpc.chain.getBlock(
129-
snapshotBlock.number - 1
130-
)
129+
await node.rpc.chain.getBlockByNumber({
130+
blockNumber: snapshotBlock.number - 1
131+
})
131132
).to.be.null;
132133
expect(
133-
await node.testFramework.rpc.chain.getBlock(
134-
snapshotBlock.number
135-
)
134+
await node.rpc.chain.getBlockByNumber({
135+
blockNumber: snapshotBlock.number
136+
})
136137
).not.to.be.null;
137138
// Check that the freshNodeValidator is still a validator & make sure it doesn't have a block/header before termMetadata1.
138139
} catch (e) {
@@ -169,11 +170,13 @@ async function getSnapshotBlock(
169170
) {
170171
const blockNumber = termMetadata.lastTermFinishedBlockNumber + 1;
171172
await node.waitBlockNumber(blockNumber);
172-
return (await node.testFramework.rpc.chain.getBlock(blockNumber))!;
173+
return (await node.rpc.chain.getBlockByNumber({ blockNumber }))!;
173174
}
174175

175176
async function makeItValidator(node: CodeChain, freshNodeValidator: Signer) {
176-
const faucetSeq = await node.testFramework.rpc.chain.getSeq(faucetAddress);
177+
const faucetSeq = (await node.rpc.chain.getSeq({
178+
address: faucetAddress.toString()
179+
}))!;
177180
const payTx = node.testFramework.core
178181
.createPayTransaction({
179182
recipient: freshNodeValidator.platformAddress,
@@ -185,19 +188,27 @@ async function makeItValidator(node: CodeChain, freshNodeValidator: Signer) {
185188
fee: 10
186189
});
187190
await node.waitForTx(
188-
await node.testFramework.rpc.chain.sendSignedTransaction(payTx)
191+
new H256(
192+
await node.rpc.mempool.sendSignedTransaction({
193+
tx: payTx.rlpBytes().toString("hex")
194+
})
195+
)
189196
);
190197
const selfNominateTx = stake
191198
.createSelfNominateTransaction(node.testFramework, 10000000, "")
192199
.sign({
193200
secret: freshNodeValidator.privateKey,
194-
seq: await node.testFramework.rpc.chain.getSeq(
195-
freshNodeValidator.platformAddress
196-
),
201+
seq: (await node.rpc.chain.getSeq({
202+
address: freshNodeValidator.platformAddress.toString()
203+
}))!,
197204
fee: 10
198205
});
199206
await node.waitForTx(
200-
await node.testFramework.rpc.chain.sendSignedTransaction(selfNominateTx)
207+
new H256(
208+
await node.rpc.mempool.sendSignedTransaction({
209+
tx: selfNominateTx.rlpBytes().toString("hex")
210+
})
211+
)
201212
);
202213
const delegateTx = stake
203214
.createDelegateCCSTransaction(
@@ -211,6 +222,10 @@ async function makeItValidator(node: CodeChain, freshNodeValidator: Signer) {
211222
fee: 10
212223
});
213224
await node.waitForTx(
214-
await node.testFramework.rpc.chain.sendSignedTransaction(delegateTx)
225+
new H256(
226+
await node.rpc.mempool.sendSignedTransaction({
227+
tx: delegateTx.rlpBytes().toString("hex")
228+
})
229+
)
215230
);
216231
}

0 commit comments

Comments
 (0)