Skip to content

Commit

Permalink
Update nonce test (#288)
Browse files Browse the repository at this point in the history
  • Loading branch information
boundless-forest committed Feb 20, 2023
1 parent 8f2c12a commit 6117f68
Showing 1 changed file with 42 additions and 11 deletions.
53 changes: 42 additions & 11 deletions tests/ethereum/test-nonce.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,61 @@ import Web3 from "web3";
import { describe } from "mocha";
import { step } from "mocha-steps";
import { expect } from "chai";
import { HOST_HTTP_URL, FAITH, FAITH_P } from "../config";
import { HOST_HTTP_URL, FAITH, FAITH_P, DEFAULT_GAS, customRequest } from "../config";
import { incrementerInfo } from "./contracts/contracts_info";
import { AbiItem } from "web3-utils";

const web3 = new Web3(HOST_HTTP_URL);
describe("Test balances", () => {
describe("Test nonce", () => {
web3.eth.accounts.wallet.add(FAITH_P);
const inc = new web3.eth.Contract(incrementerInfo.abi as AbiItem[]);
inc.options.from = FAITH;
inc.options.gas = DEFAULT_GAS;

let init_nonce;
step("Get the init nonce", async function () {
init_nonce = await web3.eth.getTransactionCount(FAITH);
});

step("Make a transaction", async function () {
step("Increase nonce by 1 after transact create", async () => {
let data = inc.deploy({ data: incrementerInfo.bytecode, arguments: [5] });
let tx = await web3.eth.accounts.signTransaction(
{
from: FAITH,
to: "0x1111111111111111111111111111111111111111",
value: 0x200,
gasPrice: "0x3B9ACA00", // 1000000000,
gas: "0x100000",
data: data.encodeABI(),
gas: DEFAULT_GAS,
},
FAITH_P
);
await web3.eth.sendSignedTransaction(tx.rawTransaction);
}).timeout(60000);
let receipt = await web3.eth.sendSignedTransaction(tx.rawTransaction);

expect(receipt.transactionHash).to.not.be.null;
inc.options.address = receipt.contractAddress;

step("Nonce should be updated after transaction", async function () {
expect(await web3.eth.getTransactionCount(FAITH)).to.be.equal(init_nonce + 1);
});
}).timeout(60000);

step("Increase nonce by 1 after contract call", async function () {
let receipt = await inc.methods.reset().send();
expect(receipt.transactionHash).to.not.be.null;

expect(await web3.eth.getTransactionCount(FAITH)).to.be.equal(init_nonce + 2);
}).timeout(60000);

step("Rpc call doesn't update nonce", async function () {
expect(await inc.methods.number().call()).to.be.equal("0");
expect(await web3.eth.getTransactionCount(FAITH)).to.be.equal(init_nonce + 2);
}).timeout(60000);

step("Increase nonce by 1 after the transaction failed", async function () {
await inc.methods
.increment("0x1234")
.send()
.catch((err) =>
expect(err.message).to.equal(
`Returned error: VM Exception while processing transaction: revert.`
)
);
expect(await web3.eth.getTransactionCount(FAITH)).to.be.equal(init_nonce + 3);
}).timeout(60000);
});

0 comments on commit 6117f68

Please sign in to comment.