Skip to content

Commit 78a4322

Browse files
authored
Merge pull request #21 from BermudaBay/main
fix: nonce stalling by cheat mining an anvil block
2 parents 26bb353 + 8a45ade commit 78a4322

2 files changed

Lines changed: 24 additions & 1 deletion

File tree

mock-contract-deployer/src/index.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ import {
4646
SIMPLE_ACCOUNT_FACTORY_V08_CREATECALL,
4747
SIMPLE_7702_ACCOUNT_IMPLEMENTATION_V08_CREATECALL,
4848
} from "./constants";
49+
import { anvilMine, sleep } from "./utils"
4950

5051
const DETERMINISTIC_DEPLOYER = "0x4e59b44847b379578588920ca78fbf26c0b4956c";
5152
const SAFE_SINGLETON_FACTORY = "0x914d7Fec6aaC8cd542e72Bca78B30650d45643d7";
@@ -507,10 +508,12 @@ const main = async () => {
507508

508509
let onchainNonce = 0;
509510
do {
511+
// Mine a new block including all pending txs so the nonce syncs
512+
await anvilMine(1);
510513
onchainNonce = await client.getTransactionCount({
511514
address: walletClient.account.address,
512515
});
513-
await new Promise((resolve) => setTimeout(resolve, 500));
516+
await sleep(500);
514517
} while (onchainNonce !== nonce);
515518

516519
// ==== SETUP KERNEL V0.6 CONTRACTS ==== //
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
const url = new URL(process.env.ANVIL_RPC || 'http://anvil:8545');
2+
3+
export async function anvilMine(numBlocks: number = 1, interval?: number) {
4+
await fetch(url, {
5+
method: "POST",
6+
headers: { "content-type": "application/json" },
7+
body: JSON.stringify({
8+
jsonrpc: "2.0",
9+
id: 1,
10+
method: "anvil_mine",
11+
params: [ numBlocks, interval ]
12+
})
13+
}).then(res => {
14+
if (!res.ok) throw new Error("anvil_mine failed")
15+
})
16+
}
17+
18+
export async function sleep(ms: number) {
19+
return new Promise(resolve => setTimeout(resolve, ms))
20+
}

0 commit comments

Comments
 (0)