Skip to content

Commit

Permalink
fixup! sns-testing: check that NNS canisters exist before deploying
Browse files Browse the repository at this point in the history
  • Loading branch information
rvem committed Feb 14, 2025
1 parent 9fcdc8b commit 02fd5b5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
13 changes: 5 additions & 8 deletions rs/sns/testing/src/nns_dapp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ async fn validate_subnet_setup(pocket_ic: &PocketIc) {
let _sns_subnet_id = topology.get_nns().expect("SNS subnet not found");
let _ii_subnet_id = topology.get_ii().expect("II subnet not found");
let app_subnet_ids = topology.get_app_subnets();
assert!(app_subnet_ids.len() > 0, "No application subnets found");
assert!(!app_subnet_ids.is_empty(), "No application subnets found");
}

async fn check_canister_exists(pocket_ic: &PocketIc, canister_id: &CanisterId) -> bool {
Expand All @@ -52,16 +52,11 @@ pub async fn bootstrap_nns(pocket_ic: &PocketIc) {
let canisters_exist = join_all(
ALL_NNS_CANISTER_IDS
.iter()
.map(|canister_id| async { check_canister_exists(pocket_ic, *canister_id).await }),
.map(|canister_id| async { check_canister_exists(pocket_ic, canister_id).await }),
)
.await;

// Don't do anything if all NNS canister are already installed
if canisters_exist.iter().all(|exists| *exists) {
();
} else if canisters_exist.iter().any(|exists| *exists) {
panic!("Some NNS canisters are missing, we cannot fix this automatically at the moment");
} else {
if !canisters_exist.iter().any(|exists| *exists) {
// TODO @rvem: at some point in the future we might want to use
// non-default 'initial_balances' as well as 'neurons_fund_hotkeys' to provide
// tokens and neuron hotkeys for user-provided indentities.
Expand All @@ -72,6 +67,8 @@ pub async fn bootstrap_nns(pocket_ic: &PocketIc) {
nns_installer.with_index_canister();
nns_installer.install(pocket_ic).await;
add_wasms_to_sns_wasm(pocket_ic, false).await.unwrap();
} else if !canisters_exist.iter().all(|exists| *exists) {
panic!("Some NNS canisters are missing, we cannot fix this automatically at the moment");
}

install_frontend_nns_canisters(pocket_ic).await;
Expand Down
2 changes: 1 addition & 1 deletion rs/sns/testing/src/sns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ pub async fn create_sns(
.await
.expect("Expecting the swap to be open after creation");
smoke_test_participate_and_finalize(pocket_ic, sns.swap.canister_id, swap_parameters).await;
await_swap_lifecycle(&pocket_ic, sns.swap.canister_id, Lifecycle::Committed)
await_swap_lifecycle(pocket_ic, sns.swap.canister_id, Lifecycle::Committed)
.await
.expect("Expecting the swap to be commited after creation and swap completion");
(sns, proposal_id)
Expand Down

0 comments on commit 02fd5b5

Please sign in to comment.