Skip to content

Commit

Permalink
test(ICRC_Ledger): FI-1580: Preemptively top of canisters in golden s…
Browse files Browse the repository at this point in the history
…tate 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.
  • Loading branch information
mbjorkqvist authored Nov 19, 2024
1 parent 3859955 commit 8c245cc
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions rs/ledger_suite/icrc1/tests/golden_state_upgrade_downgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -778,6 +781,22 @@ fn archive_wasm() -> Vec<u8> {
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;
Expand Down

0 comments on commit 8c245cc

Please sign in to comment.