From 8c245cc38eb4142f50713a55c5e158c3035e9bc2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mathias=20Bj=C3=B6rkqvist?= Date: Tue, 19 Nov 2024 19:33:45 +0100 Subject: [PATCH] test(ICRC_Ledger): FI-1580: Preemptively top of canisters in golden state test (#2659) Preemptively top up ledger suite canisters before running upgrade/downgrade tests on them, so that they do not run out of cycles during the test, which would cause the test to fail. --- .../tests/golden_state_upgrade_downgrade.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/rs/ledger_suite/icrc1/tests/golden_state_upgrade_downgrade.rs b/rs/ledger_suite/icrc1/tests/golden_state_upgrade_downgrade.rs index 79f3c3f7e30..c36245c47ea 100644 --- a/rs/ledger_suite/icrc1/tests/golden_state_upgrade_downgrade.rs +++ b/rs/ledger_suite/icrc1/tests/golden_state_upgrade_downgrade.rs @@ -151,6 +151,9 @@ impl LedgerSuiteConfig { CanisterId::unchecked_from_principal(PrincipalId::from_str(self.ledger_id).unwrap()); let index_canister_id = CanisterId::unchecked_from_principal(PrincipalId::from_str(self.index_id).unwrap()); + // Top up the ledger suite canisters so that they do not risk running out of cycles as + // part of the upgrade/downgrade testing. + top_up_canisters(state_machine, ledger_canister_id, index_canister_id); let mut previous_ledger_state = None; if self.extended_testing { previous_ledger_state = Some(LedgerState::verify_state_and_generate_transactions( @@ -778,6 +781,22 @@ fn archive_wasm() -> Vec { load_wasm_using_env_var("IC_ICRC1_ARCHIVE_WASM_PATH") } +fn top_up_canisters( + state_machine: &StateMachine, + ledger_canister_id: CanisterId, + index_canister_id: CanisterId, +) { + const TOP_UP_AMOUNT: u128 = 2_000_000_000_000_000; // 2_000 T cycles + let archives = list_archives(state_machine, ledger_canister_id); + for archive in archives { + let archive_canister_id = + CanisterId::unchecked_from_principal(PrincipalId(archive.canister_id)); + state_machine.add_cycles(archive_canister_id, TOP_UP_AMOUNT); + } + state_machine.add_cycles(ledger_canister_id, TOP_UP_AMOUNT); + state_machine.add_cycles(index_canister_id, TOP_UP_AMOUNT); +} + mod index { use super::*; use candid::Decode;