Skip to content

Commit

Permalink
test(ICP_Ledger): FI-1589: Adapt ICP golden state test to ledger migr…
Browse files Browse the repository at this point in the history
…ation v3 (#3007)

After the allowances in the ICP ledger have been migrated to stable
structures (in V3 of the migration to stable structures), downgrading to
the previous version is not supported. This PR proposes to change the
ICP golden state test accordingly, verifying that the downgrade indeed
fails as expected.

---------

Co-authored-by: Maciej Modelski <[email protected]>
Co-authored-by: IDX GitHub Automation <[email protected]>
Co-authored-by: maciejdfinity <[email protected]>
Co-authored-by: mraszyk <[email protected]>
  • Loading branch information
5 people authored Dec 11, 2024
1 parent c58e00f commit d29a9ea
Showing 1 changed file with 24 additions and 11 deletions.
35 changes: 24 additions & 11 deletions rs/ledger_suite/icp/tests/golden_nns_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use ic_nns_constants::{
LEDGER_CANISTER_INDEX_IN_NNS_SUBNET, LEDGER_INDEX_CANISTER_INDEX_IN_NNS_SUBNET,
};
use ic_nns_test_utils_golden_nns_state::new_state_machine_with_golden_nns_state_or_panic;
use ic_state_machine_tests::StateMachine;
use ic_state_machine_tests::{ErrorCode, StateMachine, UserError};
use icp_ledger::{
AccountIdentifier, Archives, Block, FeatureFlags, LedgerCanisterPayload, UpgradeArgs,
};
Expand Down Expand Up @@ -294,14 +294,29 @@ impl Setup {
pub fn upgrade_to_master(&self) {
println!("Upgrading to master version");
self.upgrade_index(&self.master_wasms.index);
self.upgrade_ledger(&self.master_wasms.ledger);
self.upgrade_ledger(&self.master_wasms.ledger)
.expect("should successfully upgrade ledger to new local version");
self.upgrade_archive_canisters(&self.master_wasms.archive);
}

pub fn downgrade_to_mainnet(&self) {
println!("Downgrading to mainnet version");
self.upgrade_index(&self.mainnet_wasms.index);
self.upgrade_ledger(&self.mainnet_wasms.ledger);
match self.upgrade_ledger(&self.mainnet_wasms.ledger) {
Ok(_) => {
panic!("should fail to downgrade ledger to mainnet version");
}
Err(err) => {
// The ledger will still be running the master version, while the other canisters
// will be downgraded to the mainnet version. This is not an ideal situation, nor
// is it expected to happen in practice, but for the moment let's run the test to
// completion.
err.assert_contains(
ErrorCode::CanisterCalledTrap,
"Trying to downgrade from incompatible version",
);
}
}
self.upgrade_archive_canisters(&self.mainnet_wasms.archive);
}

Expand Down Expand Up @@ -355,19 +370,17 @@ impl Setup {
.expect("should successfully upgrade index to new local version");
}

fn upgrade_ledger(&self, wasm: &Wasm) {
fn upgrade_ledger(&self, wasm: &Wasm) -> Result<(), UserError> {
let ledger_upgrade_args: LedgerCanisterPayload =
LedgerCanisterPayload::Upgrade(Some(UpgradeArgs {
icrc1_minting_account: None,
feature_flags: Some(FeatureFlags { icrc2: true }),
}));

self.state_machine
.upgrade_canister(
LEDGER_CANISTER_ID,
wasm.clone().bytes(),
Encode!(&ledger_upgrade_args).unwrap(),
)
.expect("should successfully upgrade ledger to new local version");
self.state_machine.upgrade_canister(
LEDGER_CANISTER_ID,
wasm.clone().bytes(),
Encode!(&ledger_upgrade_args).unwrap(),
)
}
}

0 comments on commit d29a9ea

Please sign in to comment.