Skip to content

Commit b15c349

Browse files
committed
Remove all sdk functtions from e2e tests
Previously, there were some sdk functions that were not replaced. In this commit, all of them remove and e2e tests rely on foundry rpc completely
1 parent 08b8d02 commit b15c349

14 files changed

+757
-510
lines changed

test/src/e2e/chain.test.ts

Lines changed: 57 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ import {
2525
invalidAddress
2626
} from "../helper/constants";
2727
import CodeChain from "../helper/spawn";
28-
import { H160, H256, U64 } from "../sdk/src/core/classes";
28+
import { PlatformAddress } from "../sdk/src/core/classes";
29+
import { H160, H256, H512, U64 } from "../sdk/src/core/classes";
2930
const RLP = require("rlp");
3031

3132
describe("chain", function() {
@@ -80,10 +81,14 @@ describe("chain", function() {
8081
blockNumber: bestBlockNumber
8182
});
8283
expect(
83-
(await node.testFramework.rpc.chain.getBlock(blockHash!))!.number
84+
(await node.rpc.chain.getBlockByHash({ blockHash: blockHash! }))!
85+
.number
8486
).to.equal(bestBlockNumber);
85-
expect(await node.testFramework.rpc.chain.getBlock(invalidH256)).to.be
86-
.null;
87+
expect(
88+
await node.rpc.chain.getBlockByHash({
89+
blockHash: `0x${invalidH256.toString()}`
90+
})
91+
).to.be.null;
8792
});
8893

8994
it("getSeq", async function() {
@@ -97,7 +102,7 @@ describe("chain", function() {
97102
blockNumber: null
98103
})
99104
).to.equal(0);
100-
const bestBlockNumber = await node.testFramework.rpc.chain.getBestBlockNumber();
105+
const bestBlockNumber = await node.rpc.chain.getBestBlockNumber();
101106
await node.rpc.chain.getSeq({
102107
address: faucetAddress.toString(),
103108
blockNumber: 0
@@ -160,16 +165,14 @@ describe("chain", function() {
160165
});
161166

162167
it("getBlockReward", async function() {
163-
// FIXME: Add an API to SDK
164-
const reward = await node.testFramework.rpc.sendRpcRequest(
165-
"engine_getBlockReward",
166-
[10]
167-
);
168+
const reward = (await node.rpc.engine.getBlockReward({
169+
blockNumber: 10
170+
}))!;
168171
expect(reward).to.equal(0);
169172
});
170173

171174
it("getPendingTransactions", async function() {
172-
const pending = await node.testFramework.rpc.chain.getPendingTransactions();
175+
const pending = await node.rpc.mempool.getPendingTransactions();
173176
expect(pending.transactions.length).to.equal(0);
174177
});
175178

@@ -182,21 +185,26 @@ describe("chain", function() {
182185
address: faucetAddress.toString(),
183186
blockNumber: null
184187
}))!;
185-
const hash = await node.testFramework.rpc.chain.sendSignedTransaction(
186-
tx.sign({
187-
secret: faucetSecret,
188-
fee: 10,
189-
seq
190-
})
191-
);
188+
const sig = tx.sign({
189+
secret: faucetSecret,
190+
fee: 10,
191+
seq
192+
});
193+
const bytes = sig.rlpBytes().toString("hex");
194+
const hash = await node.rpc.mempool.sendSignedTransaction({
195+
tx: `0x${bytes}`
196+
});
192197
expect(
193198
await node.rpc.chain.containsTransaction({
194-
transactionHash: "0x".concat(hash.toString())
199+
transactionHash: hash
195200
})
196201
).be.true;
197-
const signed = await node.testFramework.rpc.chain.getTransaction(hash);
198-
expect(signed).not.null;
199-
expect(signed!.unsigned).to.deep.equal(tx);
202+
const thetx = (await node.rpc.chain.getTransaction({
203+
transactionHash: hash
204+
}))!;
205+
expect(thetx).not.null;
206+
expect(thetx.sig).to.equal(`0x${sig.signature()}`);
207+
expect(+thetx.fee).to.equal(Number(tx.fee()!.toString()));
200208
});
201209

202210
it("sendPayTx, getTransactionSigner", async function() {
@@ -208,26 +216,37 @@ describe("chain", function() {
208216
address: faucetAddress.toString(),
209217
blockNumber: null
210218
}))!;
211-
const hash = await node.testFramework.rpc.chain.sendSignedTransaction(
212-
tx.sign({
213-
secret: faucetSecret,
214-
fee: 10,
215-
seq
216-
})
217-
);
218-
expect(await node.testFramework.rpc.chain.containsTransaction(hash)).be
219-
.true;
220-
const signer = await node.testFramework.rpc.sendRpcRequest(
221-
"chain_getTransactionSigner",
222-
[hash]
223-
);
219+
const sig = tx.sign({
220+
secret: faucetSecret,
221+
fee: 10,
222+
seq
223+
});
224+
const bytes = sig.rlpBytes().toString("hex");
225+
const hash = await node.rpc.mempool.sendSignedTransaction({
226+
tx: `0x${bytes}`
227+
});
228+
expect(
229+
await node.rpc.chain.containsTransaction({ transactionHash: hash })
230+
).be.true;
231+
const signer = await node.rpc.chain.getTransactionSigner({
232+
transactionHash: hash
233+
});
224234
expect(signer).equal(faucetAddress.toString());
225-
const signed = await node.testFramework.rpc.chain.getTransaction(hash);
235+
const signed = (await node.rpc.chain.getTransaction({
236+
transactionHash: hash
237+
}))!;
238+
const publicKey = new H512(
239+
node.testFramework.util.recoverEcdsa(
240+
tx.unsignedHash().toString(),
241+
signed.sig
242+
)
243+
);
226244
expect(signed).not.null;
227-
expect(signed!.unsigned).to.deep.equal(tx);
245+
expect(signed.sig).to.equal(`0x${sig.signature()}`);
246+
expect(+signed.fee).to.equal(Number(tx.fee()!.toString()));
228247
expect(
229248
node.testFramework.core.classes.PlatformAddress.fromPublic(
230-
signed!.getSignerPublic(),
249+
publicKey,
231250
{ networkId: "tc" }
232251
).toString()
233252
).equal(signer);

0 commit comments

Comments
 (0)