Skip to content

Commit 4704bf2

Browse files
committed
test: getTransactionCount
1 parent e20f9a7 commit 4704bf2

File tree

2 files changed

+78
-0
lines changed

2 files changed

+78
-0
lines changed

client/src/tests.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export async function run(
2424
await import("./tests/eth/getBalance");
2525
await import("./tests/eth/getTransactionByHash");
2626
await import("./tests/eth/newFilter");
27+
await import("./tests/eth/getTransactionCount");
2728

2829
mocha.run();
2930
}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
import * as tests from "../../tests";
2+
import Receive from "./getBalance.sol";
3+
import assert from "assert";
4+
import { ethers } from "ethers";
5+
6+
const blockchain = tests.blockchain;
7+
const wallet = tests.wallet;
8+
9+
if (!blockchain || !wallet) {
10+
throw "not ready";
11+
}
12+
13+
describe("getTransactionCount", () => {
14+
let contract: ethers.Contract;
15+
before(async () => {
16+
const deployer = (await blockchain.listAccounts())[0];
17+
const factory = ethers.ContractFactory.fromSolidity(
18+
Receive.Receive,
19+
deployer
20+
);
21+
22+
contract = await factory.deploy();
23+
await blockchain.send("evm_mine", [{ blocks: 1 }]);
24+
await contract.deploymentTransaction()?.wait(1);
25+
});
26+
27+
it("sending transaction from eoa increases nonce", async () => {
28+
const src = (await blockchain.listAccounts())[0];
29+
const dest = (await wallet.listAccounts())[0];
30+
31+
const balance = "0x100000000000000000000";
32+
await blockchain.send("evm_setAccountBalance", [src.address, balance]);
33+
34+
const walletInitalNonce = await wallet.getTransactionCount(src.address);
35+
const ganacheInitalNonce = await blockchain.getTransactionCount(
36+
src.address
37+
);
38+
39+
assert.equal(
40+
walletInitalNonce.toString(),
41+
ganacheInitalNonce.toString(),
42+
"wallet's nonce matches ganache's before sending transaction"
43+
);
44+
45+
const response = await src.sendTransaction({
46+
to: dest,
47+
value: 0n,
48+
});
49+
50+
await blockchain.send("evm_mine", [{ blocks: 1 }]);
51+
52+
const transaction = await wallet.getTransaction(response.hash);
53+
if (!transaction) {
54+
throw "no transaction";
55+
}
56+
console.log(transaction);
57+
await transaction.wait(1);
58+
59+
const walletFinalNonce = await wallet.send("eth_getTransactionCount", [
60+
src.address,
61+
]);
62+
const ganacheFinalNonce = await blockchain.send(
63+
"eth_getTransactionCount",
64+
[src.address]
65+
);
66+
67+
assert.equal(
68+
walletFinalNonce.toString(),
69+
ganacheFinalNonce.toString(),
70+
"wallet's nonce matches ganache's after sending transaction"
71+
);
72+
73+
const expected = 1 + walletInitalNonce;
74+
75+
assert.equal(walletFinalNonce, expected);
76+
});
77+
});

0 commit comments

Comments
 (0)