Skip to content

Commit

Permalink
test(sns): AdvanceSnsTargetVersion qualification test should use mast…
Browse files Browse the repository at this point in the history
…er-branch canister versions (#3204)

Otherwise it isn't much of a qualification test :D 

This PR also extends the test in a couple other ways to help ensure it
only passes if the upgrades happened as expected
  • Loading branch information
anchpop authored Dec 16, 2024
1 parent 6652691 commit 92d4c47
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 2 deletions.
27 changes: 27 additions & 0 deletions rs/nervous_system/integration_tests/src/pocket_ic_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1228,6 +1228,33 @@ pub mod nns {
version.insert(canister_type, wasm);
version
}

/// Modify the WASM for a given canister type and add it to SNS-W.
/// Returns the new (modified) version that is now at the tip of SNS-W.
pub async fn modify_and_add_master_wasm(
pocket_ic: &PocketIc,
mut version: SnsWasms,
canister_type: SnsCanisterType,
nonce: u32,
) -> SnsWasms {
let wasm = match canister_type {
SnsCanisterType::Root => build_root_sns_wasm(),
SnsCanisterType::Governance => build_governance_sns_wasm(),
SnsCanisterType::Ledger => build_ledger_sns_wasm(),
SnsCanisterType::Swap => build_swap_sns_wasm(),
SnsCanisterType::Index => build_index_ng_sns_wasm(),
SnsCanisterType::Unspecified => {
panic!("Where did you get this canister type from?")
}
SnsCanisterType::Archive => build_archive_sns_wasm(),
};
let wasm = create_modified_sns_wasm(&wasm, Some(nonce));
add_wasm_via_nns_proposal(pocket_ic, wasm.clone())
.await
.unwrap();
version.insert(canister_type, wasm);
version
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use ic_nervous_system_integration_tests::{
},
};
use ic_sns_governance::governance::UPGRADE_STEPS_INTERVAL_REFRESH_BACKOFF_SECONDS;
use ic_sns_governance::pb::v1::upgrade_journal_entry;
use ic_sns_swap::pb::v1::Lifecycle;
use ic_sns_wasm::pb::v1::SnsCanisterType;

Expand Down Expand Up @@ -72,15 +73,17 @@ pub async fn test_sns_upgrade(sns_canisters_to_upgrade: Vec<SnsCanisterType>) {
eprintln!("Upgrade pass {}", upgrade_pass);

eprintln!("Adding all WASMs ...");
let mut expected_upgrade_steps = vec![];
for canister_type in &sns_canisters_to_upgrade {
eprintln!("modify_and_add_wasm for {:?} ...", canister_type);
latest_sns_version = nns::sns_wasm::modify_and_add_wasm(
eprintln!("modify_and_add_master_wasm for {:?} ...", canister_type);
latest_sns_version = nns::sns_wasm::modify_and_add_master_wasm(
&pocket_ic,
latest_sns_version,
*canister_type,
upgrade_pass,
)
.await;
expected_upgrade_steps.push(hash_sns_wasms(&latest_sns_version));
}

eprintln!("wait for the upgrade steps to be refreshed ...");
Expand All @@ -101,6 +104,18 @@ pub async fn test_sns_upgrade(sns_canisters_to_upgrade: Vec<SnsCanisterType>) {
.await
.unwrap();

eprintln!("assert that the upgrade steps are correct ...");
{
assert_eq!(
sns::governance::get_upgrade_journal(&pocket_ic, sns.governance.canister_id)
.await
.upgrade_steps
.unwrap()
.versions[1..],
expected_upgrade_steps
);
}

eprintln!("advance the target version to the latest version. ...");
sns::governance::propose_to_advance_sns_target_version(
&pocket_ic,
Expand All @@ -124,4 +139,37 @@ pub async fn test_sns_upgrade(sns_canisters_to_upgrade: Vec<SnsCanisterType>) {
.await
.unwrap();
}

eprintln!(
"Asserting that there have been {} successful upgrades",
2 * sns_canisters_to_upgrade.len()
);
{
let upgrade_journal =
sns::governance::get_upgrade_journal(&pocket_ic, sns.governance.canister_id)
.await
.upgrade_journal
.unwrap()
.entries;
let upgrade_successes = upgrade_journal
.into_iter()
.filter_map(|entry| entry.event)
.filter(|event| {
matches!(
event,
upgrade_journal_entry::Event::UpgradeOutcome(
upgrade_journal_entry::UpgradeOutcome {
status: Some(upgrade_journal_entry::upgrade_outcome::Status::Success(
_
)),
..
}
)
)
});
assert_eq!(
upgrade_successes.count(),
2 * sns_canisters_to_upgrade.len()
);
}
}

0 comments on commit 92d4c47

Please sign in to comment.