@@ -70,8 +70,10 @@ pub struct SweeperFundingSetup {
7070}
7171
7272impl SweeperFundingSetup {
73- /// The fee account is funded before the minter is installed, not after: the funding task starts
74- /// with the minter, so a test seeding it afterwards would race its own arrangement.
73+ /// The fee account is funded once the deposit has been credited and before the timers are
74+ /// re-armed, which is the one window in which no funding check can be running: leaving it empty
75+ /// until then means the install-time check has nothing to burn however the timers interleave, so
76+ /// the post-upgrade run is deterministically the first that can fund.
7577 pub fn new_live ( ) -> Self {
7678 Self :: new_live_with_fee_account_balance ( FEE_ACCOUNT_BALANCE )
7779 }
@@ -104,7 +106,7 @@ impl SweeperFundingSetup {
104106 env. add_cycles ( canister, u128:: from ( u64:: MAX ) ) ;
105107 }
106108
107- install_ledger ( & env, ledger_id, minter_id, fee_account_balance ) ;
109+ install_ledger ( & env, ledger_id, minter_id) ;
108110 install_evm_rpc ( & env, evm_rpc_id, anvil. url ( ) ) ;
109111
110112 // Live before installing the minter: its install-time timers issue outcalls immediately.
@@ -137,10 +139,14 @@ impl SweeperFundingSetup {
137139 setup
138140 . anvil
139141 . set_balance ( & setup. minter_address , MINTER_ETH_BALANCE ) ;
140- // The install-time funding check races the scrape, so it will have seen a zero balance, and
141- // the next scheduled one is a whole interval away. Re-arm the timers once the deposit has
142- // landed so tests start from a minter that can actually fund.
143142 setup. await_deposit_credited ( Duration :: from_secs ( 300 ) ) ;
143+ // Funded here rather than at install: with an empty fee account the install-time check
144+ // cannot burn, whichever way it and the scrape interleave. Safe to do now because the next
145+ // scheduled check is a whole interval away, so nothing is watching until the upgrade below
146+ // re-arms the timers — which makes that run the first one able to fund.
147+ if fee_account_balance > 0 {
148+ setup. mint_cketh ( setup. fee_account ( ) , fee_account_balance) ;
149+ }
144150 setup. upgrade_minter ( ) ;
145151 setup
146152 }
@@ -385,15 +391,12 @@ fn long_lived_server_url() -> Url {
385391 . clone ( )
386392}
387393
388- fn install_ledger (
389- env : & PocketIc ,
390- ledger_id : Principal ,
391- minter_id : Principal ,
392- fee_account_balance : u128 ,
393- ) {
394+ /// Installs the ckETH ledger with every balance empty. The fee account is credited afterwards, by
395+ /// [`SweeperFundingSetup::new_live`], for the reason given there.
396+ fn install_ledger ( env : & PocketIc , ledger_id : Principal , minter_id : Principal ) {
394397 use ic_icrc1_ledger:: InitArgsBuilder as LedgerInitArgsBuilder ;
395398
396- let mut builder = LedgerInitArgsBuilder :: with_symbol_and_name ( "ckETH" , "ckETH" )
399+ let builder = LedgerInitArgsBuilder :: with_symbol_and_name ( "ckETH" , "ckETH" )
397400 . with_minting_account ( minter_id)
398401 . with_transfer_fee ( CKETH_TRANSFER_FEE )
399402 . with_max_memo_length ( 80 )
@@ -402,15 +405,6 @@ fn install_ledger(
402405 icrc2 : true ,
403406 icrc152 : false ,
404407 } ) ;
405- if fee_account_balance > 0 {
406- builder = builder. with_initial_balance (
407- Account {
408- owner : minter_id,
409- subaccount : Some ( ic_cketh_minter:: CKETH_FEE_SUBACCOUNT ) ,
410- } ,
411- fee_account_balance,
412- ) ;
413- }
414408 let args = LedgerArgument :: Init ( builder. build ( ) ) ;
415409 env. install_canister (
416410 ledger_id,
0 commit comments