File tree Expand file tree Collapse file tree
mock-contract-deployer/src Expand file tree Collapse file tree Original file line number Diff line number Diff 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
5051const DETERMINISTIC_DEPLOYER = "0x4e59b44847b379578588920ca78fbf26c0b4956c" ;
5152const 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 ==== //
Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments