Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: make anvil_setNonce test use a random wallet #568

Merged
merged 1 commit into from
Jan 31, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 14 additions & 7 deletions e2e-tests/test/anvil-apis.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,32 +256,39 @@ describe("anvil_setNonce", function () {
const richWallet = new Wallet(RichAccounts[0].PrivateKey).connect(provider);
const userWallet = Wallet.createRandom().connect(provider);

// Simply asserts that `richWallet` can still send successful transactions
// Fund `userWallet` from `richWallet`
const fundTxResponse = await richWallet.sendTransaction({
to: userWallet.address,
value: ethers.parseEther("10"),
});
await fundTxResponse.wait();

// Simply asserts that `userWallet` can still send successful transactions
async function assertCanSendTx() {
const tx = {
to: userWallet.address,
value: ethers.parseEther("0.42"),
};

const txResponse = await richWallet.sendTransaction(tx);
const txResponse = await userWallet.sendTransaction(tx);
const txReceipt = await txResponse.wait();
expect(txReceipt.status).to.equal(1);
expect(txReceipt!.status).to.equal(1);
}

const newNonce = 42;

// Advance nonce to 42
await provider.send("anvil_setNonce", [richWallet.address, ethers.toBeHex(newNonce)]);
await provider.send("anvil_setNonce", [userWallet.address, ethers.toBeHex(newNonce)]);

// Assert
expect(await richWallet.getNonce()).to.equal(newNonce);
expect(await userWallet.getNonce()).to.equal(newNonce);
await assertCanSendTx();

// Rollback nonce to 0
await provider.send("anvil_setNonce", [richWallet.address, ethers.toBeHex(0)]);
await provider.send("anvil_setNonce", [userWallet.address, ethers.toBeHex(0)]);

// Assert
expect(await richWallet.getNonce()).to.equal(0);
expect(await userWallet.getNonce()).to.equal(0);
await assertCanSendTx();
});
});
Expand Down