diff --git a/src/lib/integration_tests/tests/authentication/when_a_new_user_signs_up_from_a_referral_then_the_new_user_is_given_a_thousand_utility_tokens_for_signing_up_and_the_referrer_and_referee_receive_five_hundred_tokens_as_referral_rewards.rs b/src/lib/integration_tests/tests/authentication/when_a_new_user_signs_up_from_a_referral_then_the_new_user_is_given_a_thousand_utility_tokens_for_signing_up_and_the_referrer_and_referee_receive_five_hundred_tokens_as_referral_rewards.rs index 0a25a7be..d7e28ac7 100644 --- a/src/lib/integration_tests/tests/authentication/when_a_new_user_signs_up_from_a_referral_then_the_new_user_is_given_a_thousand_utility_tokens_for_signing_up_and_the_referrer_and_referee_receive_five_hundred_tokens_as_referral_rewards.rs +++ b/src/lib/integration_tests/tests/authentication/when_a_new_user_signs_up_from_a_referral_then_the_new_user_is_given_a_thousand_utility_tokens_for_signing_up_and_the_referrer_and_referee_receive_five_hundred_tokens_as_referral_rewards.rs @@ -13,7 +13,7 @@ use shared_utils::{ types::canister_specific::individual_user_template::error_types::GetUserUtilityTokenTransactionHistoryError, }; use test_utils::setup::{ - env::{pocket_ic_env::{execute_query, execute_query_multi, execute_update, execute_update_no_res, get_new_pocket_ic_env}, v1::{get_initialized_env_with_provisioned_known_canisters, get_new_state_machine}}, + env::{pocket_ic_env::{execute_query, execute_query_multi, execute_update, execute_update_no_res, get_new_pocket_ic_env, provision_subnet_orchestrator_canister}, v1::{get_initialized_env_with_provisioned_known_canisters, get_new_state_machine}}, test_constants::{get_mock_user_alice_principal_id, get_mock_user_bob_principal_id}, }; @@ -470,21 +470,12 @@ fn when_a_new_user_signs_up_from_a_referral_then_the_new_user_is_given_a_thousan #[test] fn when_a_new_user_signs_up_from_a_referral_then_the_new_user_is_given_a_thousand_utility_tokens_for_signing_up_and_the_referrer_and_referee_receive_five_hundred_tokens_as_referral_rewards_v2() { let (pic, known_principals) = get_new_pocket_ic_env(); - let global_admin_principal = known_principals[&KnownPrincipalType::UserIdGlobalSuperAdmin]; - - let platform_orc = known_principals[&KnownPrincipalType::CanisterIdPlatformOrchestrator]; - let app_subnets = pic.topology().get_app_subnets(); - let user_index_res: Result = execute_update( + let user_index = provision_subnet_orchestrator_canister( &pic, - global_admin_principal, - platform_orc, - "provision_subnet_orchestrator_canister", - &app_subnets[0] + &known_principals, + 0, + None ); - let user_index = user_index_res.unwrap(); - for _ in 0..30 { - pic.tick(); - } let alice_principal = get_mock_user_alice_principal_id(); let alice_canister: Principal = execute_update( diff --git a/src/lib/integration_tests/tests/creator_dao/main.rs b/src/lib/integration_tests/tests/creator_dao/main.rs index d3165152..99ca6d5b 100644 --- a/src/lib/integration_tests/tests/creator_dao/main.rs +++ b/src/lib/integration_tests/tests/creator_dao/main.rs @@ -25,6 +25,7 @@ use shared_utils::constant::{ SNS_TOKEN_LEDGER_MODULE_HASH, SNS_TOKEN_ROOT_MODULE_HASH, SNS_TOKEN_SWAP_MODULE_HASH, }; use shared_utils::types::creator_dao_stats::CreatorDaoTokenStats; +use test_utils::setup::env::pocket_ic_env::provision_subnet_orchestrator_canister; use std::time::{Duration, UNIX_EPOCH}; use std::{collections::HashMap, fmt::Debug, str::FromStr, time::SystemTime, vec}; use test_utils::setup::test_constants::get_mock_user_bob_principal_id; @@ -118,7 +119,7 @@ fn add_wasm(wasm_file: &[u8], canister_type: u32) -> AddWasmPayload { #[test] fn creator_dao_tests() { - let (pocket_ic, known_principal) = get_new_pocket_ic_env(); + let (pocket_ic, mut known_principal) = get_new_pocket_ic_env(); let platform_canister_id = known_principal .get(&KnownPrincipalType::CanisterIdPlatformOrchestrator) .cloned() @@ -126,8 +127,6 @@ fn creator_dao_tests() { let super_admin = get_global_super_admin_principal_id(); - let application_subnets = pocket_ic.topology().get_app_subnets(); - let charlie_global_admin = get_mock_user_charlie_principal_id(); pocket_ic @@ -152,25 +151,12 @@ fn creator_dao_tests() { ) .unwrap(); - let subnet_orchestrator_canister_id: Principal = pocket_ic - .update_call( - platform_canister_id, - charlie_global_admin, - "provision_subnet_orchestrator_canister", - candid::encode_one(application_subnets[1]).unwrap(), - ) - .map(|res| { - let canister_id_result: Result = match res { - WasmResult::Reply(payload) => candid::decode_one(&payload).unwrap(), - _ => panic!("Canister call failed"), - }; - canister_id_result.unwrap() - }) - .unwrap(); - - for i in 0..50 { - pocket_ic.tick(); - } + let subnet_orchestrator_canister_id = provision_subnet_orchestrator_canister( + &pocket_ic, + &known_principal, + 1, + Some(charlie_global_admin), + ); let alice_principal = get_mock_user_alice_principal_id(); let alice_canister_id: Principal = pocket_ic diff --git a/src/lib/integration_tests/tests/creator_dao/test_number_of_creator_tokens.rs b/src/lib/integration_tests/tests/creator_dao/test_number_of_creator_tokens.rs index 1f182875..c33ef972 100644 --- a/src/lib/integration_tests/tests/creator_dao/test_number_of_creator_tokens.rs +++ b/src/lib/integration_tests/tests/creator_dao/test_number_of_creator_tokens.rs @@ -21,7 +21,7 @@ use shared_utils::{ constant::{MAX_LIMIT_FOR_CREATOR_DAO_SNS_TOKEN, SNS_WASM_W_PRINCIPAL_ID}, }; use test_utils::setup::{ - env::pocket_ic_env::get_new_pocket_ic_env, + env::pocket_ic_env::{get_new_pocket_ic_env, provision_subnet_orchestrator_canister}, test_constants::{ get_global_super_admin_principal_id, get_mock_user_alice_principal_id, get_mock_user_charlie_principal_id, @@ -32,7 +32,7 @@ use crate::utils::setup_sns_w_canister_for_creator_dao; #[test] pub fn test_number_of_creator_tokens() { - let (pocket_ic, known_principal) = get_new_pocket_ic_env(); + let (pocket_ic, mut known_principal) = get_new_pocket_ic_env(); let platform_canister_id = known_principal .get(&KnownPrincipalType::CanisterIdPlatformOrchestrator) .cloned() @@ -40,8 +40,6 @@ pub fn test_number_of_creator_tokens() { let super_admin = get_global_super_admin_principal_id(); - let application_subnets = pocket_ic.topology().get_app_subnets(); - let charlie_global_admin = get_mock_user_charlie_principal_id(); pocket_ic @@ -66,25 +64,12 @@ pub fn test_number_of_creator_tokens() { ) .unwrap(); - let subnet_orchestrator_canister_id: Principal = pocket_ic - .update_call( - platform_canister_id, - charlie_global_admin, - "provision_subnet_orchestrator_canister", - candid::encode_one(application_subnets[1]).unwrap(), - ) - .map(|res| { - let canister_id_result: Result = match res { - WasmResult::Reply(payload) => candid::decode_one(&payload).unwrap(), - _ => panic!("Canister call failed"), - }; - canister_id_result.unwrap() - }) - .unwrap(); - - for i in 0..50 { - pocket_ic.tick(); - } + let subnet_orchestrator_canister_id = provision_subnet_orchestrator_canister( + &pocket_ic, + &known_principal, + 1, + Some(charlie_global_admin), + ); let alice_principal = get_mock_user_alice_principal_id(); let alice_canister_id: Principal = pocket_ic diff --git a/src/lib/integration_tests/tests/hot_or_not/bet_maker_canister_tests.rs b/src/lib/integration_tests/tests/hot_or_not/bet_maker_canister_tests.rs index 9f694a3f..b07800c7 100644 --- a/src/lib/integration_tests/tests/hot_or_not/bet_maker_canister_tests.rs +++ b/src/lib/integration_tests/tests/hot_or_not/bet_maker_canister_tests.rs @@ -12,7 +12,7 @@ use shared_utils::{ common::types::known_principal::KnownPrincipalType, }; use test_utils::setup::{ - env::pocket_ic_env::get_new_pocket_ic_env, + env::pocket_ic_env::{get_new_pocket_ic_env, provision_n_subnet_orchestrator_canisters}, test_constants::{ get_mock_user_alice_principal_id, get_mock_user_bob_principal_id, get_mock_user_charlie_principal_id, get_mock_user_dan_principal_id, @@ -47,43 +47,14 @@ fn when_bet_maker_places_bet_on_a_post_it_is_assigned_a_slot_id_and_the_outcome_ .copied() .unwrap(); - let application_subnets = pocket_ic.topology().get_app_subnets(); - - let subnet_orchestrator_canister_id_0 = pocket_ic - .update_call( - platform_orchestrator_canister_id, - global_admin_principal, - "provision_subnet_orchestrator_canister", - candid::encode_one(application_subnets[0]).unwrap(), - ) - .map(|res| { - let canister_id_result: Result = match res { - WasmResult::Reply(payload) => candid::decode_one(&payload).unwrap(), - _ => panic!("Canister call failed"), - }; - canister_id_result.unwrap() - }) - .unwrap(); - - let subnet_orchestrator_canister_id_1 = pocket_ic - .update_call( - platform_orchestrator_canister_id, - global_admin_principal, - "provision_subnet_orchestrator_canister", - candid::encode_one(application_subnets[1]).unwrap(), - ) - .map(|res| { - let canister_id_result: Result = match res { - WasmResult::Reply(payload) => candid::decode_one(&payload).unwrap(), - _ => panic!("Canister call failed"), - }; - canister_id_result.unwrap() - }) - .unwrap(); - - for i in 0..50 { - pocket_ic.tick(); - } + let subnet_orchestrators = provision_n_subnet_orchestrator_canisters( + &pocket_ic, + &known_principal_map, + 2, + None, + ); + let subnet_orchestrator_canister_id_0 = subnet_orchestrators[0]; + let subnet_orchestrator_canister_id_1 = subnet_orchestrators[1]; //Post Creator Canister let alice_canister_id = pocket_ic diff --git a/src/lib/integration_tests/tests/hot_or_not/hotornot_game_simulation_test.rs b/src/lib/integration_tests/tests/hot_or_not/hotornot_game_simulation_test.rs index c5f241e4..06c4da2d 100644 --- a/src/lib/integration_tests/tests/hot_or_not/hotornot_game_simulation_test.rs +++ b/src/lib/integration_tests/tests/hot_or_not/hotornot_game_simulation_test.rs @@ -19,7 +19,7 @@ use shared_utils::{ common::types::known_principal::{self, KnownPrincipalType}, }; use test_utils::setup::{ - env::pocket_ic_env::get_new_pocket_ic_env, + env::pocket_ic_env::{get_new_pocket_ic_env, provision_subnet_orchestrator_canister}, test_constants::{ get_mock_user_alice_principal_id, get_mock_user_bob_principal_id, get_mock_user_charlie_principal_id, get_mock_user_dan_principal_id, @@ -963,37 +963,12 @@ fn hotornot_game_simulation_test() { fn hotornot_game_simulation_test_2() { let (pic, known_principals) = get_new_pocket_ic_env(); - let platform_canister_id = known_principals - .get(&KnownPrincipalType::CanisterIdPlatformOrchestrator) - .cloned() - .unwrap(); - - let global_admin = known_principals - .get(&KnownPrincipalType::UserIdGlobalSuperAdmin) - .cloned() - .unwrap(); - - let application_subnets = pic.topology().get_app_subnets(); - - let subnet_orchestrator_canister_id = pic - .update_call( - platform_canister_id, - global_admin, - "provision_subnet_orchestrator_canister", - candid::encode_one(application_subnets[0]).unwrap(), - ) - .map(|res| { - let canister_id_result: Result = match res { - WasmResult::Reply(payload) => candid::decode_one(&payload).unwrap(), - _ => panic!("Canister call failed"), - }; - canister_id_result.unwrap() - }) - .unwrap(); - - for _ in 0..50 { - pic.tick() - } + let subnet_orchestrator_canister_id = provision_subnet_orchestrator_canister( + &pic, + &known_principals, + 0, + None, + ); // Init N canisters let mut individual_template_canister_ids = vec![]; diff --git a/src/lib/integration_tests/tests/individual_canister/platform_orchestrator_on_receiving_call_from_global_admin_can_make_individual_canister_logs_public_test.rs b/src/lib/integration_tests/tests/individual_canister/platform_orchestrator_on_receiving_call_from_global_admin_can_make_individual_canister_logs_public_test.rs index 12f9e9ea..088fad21 100644 --- a/src/lib/integration_tests/tests/individual_canister/platform_orchestrator_on_receiving_call_from_global_admin_can_make_individual_canister_logs_public_test.rs +++ b/src/lib/integration_tests/tests/individual_canister/platform_orchestrator_on_receiving_call_from_global_admin_can_make_individual_canister_logs_public_test.rs @@ -2,7 +2,7 @@ use candid::Principal; use pocket_ic::WasmResult; use shared_utils::common::types::known_principal::KnownPrincipalType; use test_utils::setup::{ - env::pocket_ic_env::get_new_pocket_ic_env, + env::pocket_ic_env::{get_new_pocket_ic_env, provision_subnet_orchestrator_canister}, test_constants::{ get_global_super_admin_principal_id, get_mock_user_alice_principal_id, get_mock_user_charlie_canister_id, @@ -41,25 +41,12 @@ pub fn platform_orchestrator_on_receiving_call_from_global_admin_can_make_indivi }) .unwrap(); - let subnet_orchestrator_canister_id = pocket_ic - .update_call( - platform_orchestrator_canister_id, - charlie_global_admin_principal, - "provision_subnet_orchestrator_canister", - candid::encode_one(application_subnets[0]).unwrap(), - ) - .map(|res| { - let canister_id_result: Result = match res { - WasmResult::Reply(payload) => candid::decode_one(&payload).unwrap(), - _ => panic!("Canister call failed"), - }; - canister_id_result.unwrap() - }) - .unwrap(); - - for _ in 0..50 { - pocket_ic.tick() - } + let subnet_orchestrator_canister_id = provision_subnet_orchestrator_canister( + &pocket_ic, + &known_principal_map, + 0, + Some(charlie_global_admin_principal), + ); let alice_principal = get_mock_user_alice_principal_id(); diff --git a/src/lib/integration_tests/tests/kv_store/test_namespace.rs b/src/lib/integration_tests/tests/kv_store/test_namespace.rs index 60cf2a8f..94a03e3b 100644 --- a/src/lib/integration_tests/tests/kv_store/test_namespace.rs +++ b/src/lib/integration_tests/tests/kv_store/test_namespace.rs @@ -9,7 +9,7 @@ use shared_utils::{ common::types::known_principal::KnownPrincipalType, }; use test_utils::setup::{ - env::pocket_ic_env::get_new_pocket_ic_env, + env::pocket_ic_env::{get_new_pocket_ic_env, provision_subnet_orchestrator_canister}, test_constants::{get_mock_user_alice_principal_id, get_mock_user_charlie_principal_id}, }; @@ -27,8 +27,6 @@ fn create_new_namespace() { .cloned() .unwrap(); - let application_subnets = pocket_ic.topology().get_app_subnets(); - let charlie_global_admin = get_mock_user_charlie_principal_id(); pocket_ic @@ -40,25 +38,12 @@ fn create_new_namespace() { ) .unwrap(); - let subnet_orchestrator_canister_id: Principal = pocket_ic - .update_call( - platform_canister_id, - charlie_global_admin, - "provision_subnet_orchestrator_canister", - candid::encode_one(application_subnets[1]).unwrap(), - ) - .map(|res| { - let canister_id_result: Result = match res { - WasmResult::Reply(payload) => candid::decode_one(&payload).unwrap(), - _ => panic!("Canister call failed"), - }; - canister_id_result.unwrap() - }) - .unwrap(); - - for i in 0..50 { - pocket_ic.tick(); - } + let subnet_orchestrator_canister_id = provision_subnet_orchestrator_canister( + &pocket_ic, + &known_principal, + 1, + Some(charlie_global_admin), + ); let alice_principal_id = get_mock_user_alice_principal_id(); diff --git a/src/lib/integration_tests/tests/platform_orchestrator/known_principal/update_global_known_principal_test.rs b/src/lib/integration_tests/tests/platform_orchestrator/known_principal/update_global_known_principal_test.rs index cbc58a25..b7181bcc 100644 --- a/src/lib/integration_tests/tests/platform_orchestrator/known_principal/update_global_known_principal_test.rs +++ b/src/lib/integration_tests/tests/platform_orchestrator/known_principal/update_global_known_principal_test.rs @@ -24,7 +24,7 @@ use std::{ time::SystemTime, }; use test_utils::setup::{ - env::pocket_ic_env::get_new_pocket_ic_env, + env::pocket_ic_env::{get_new_pocket_ic_env, provision_n_subnet_orchestrator_canisters}, test_constants::{ get_global_super_admin_principal_id, get_mock_user_alice_canister_id, get_mock_user_alice_principal_id, get_mock_user_bob_canister_id, @@ -107,43 +107,14 @@ fn when_global_known_principal_is_updated_it_is_reflected_in_all_canisters() { .cloned() .unwrap(); - let application_subnets = pocket_ic.topology().get_app_subnets(); - - let first_subnet_orchestrator_canister_id: Principal = pocket_ic - .update_call( - platform_canister_id, - super_admin, - "provision_subnet_orchestrator_canister", - candid::encode_one(application_subnets[1]).unwrap(), - ) - .map(|res| { - let canister_id_result: Result = match res { - WasmResult::Reply(payload) => candid::decode_one(&payload).unwrap(), - _ => panic!("Canister call failed"), - }; - canister_id_result.unwrap() - }) - .unwrap(); - - let second_subnet_orchestrator_canister_id: Principal = pocket_ic - .update_call( - platform_canister_id, - super_admin, - "provision_subnet_orchestrator_canister", - candid::encode_one(application_subnets[1]).unwrap(), - ) - .map(|res| { - let canister_id_result: Result = match res { - WasmResult::Reply(payload) => candid::decode_one(&payload).unwrap(), - _ => panic!("Canister call failed"), - }; - canister_id_result.unwrap() - }) - .unwrap(); - - for _ in 0..30 { - pocket_ic.tick(); - } + let subnet_orchestrators = provision_n_subnet_orchestrator_canisters( + &pocket_ic, + &known_principal, + 2, + None + ); + let first_subnet_orchestrator_canister_id = subnet_orchestrators[0]; + let second_subnet_orchestrator_canister_id = subnet_orchestrators[1]; let governance_canister_id = Principal::from_text(GOVERNANCE_CANISTER_ID).unwrap(); diff --git a/src/lib/integration_tests/tests/platform_orchestrator/known_principal/update_subnet_known_principal_test.rs b/src/lib/integration_tests/tests/platform_orchestrator/known_principal/update_subnet_known_principal_test.rs index 47027ac1..dcf60bca 100644 --- a/src/lib/integration_tests/tests/platform_orchestrator/known_principal/update_subnet_known_principal_test.rs +++ b/src/lib/integration_tests/tests/platform_orchestrator/known_principal/update_subnet_known_principal_test.rs @@ -23,7 +23,7 @@ use std::{ time::SystemTime, }; use test_utils::setup::{ - env::pocket_ic_env::get_new_pocket_ic_env, + env::pocket_ic_env::{get_new_pocket_ic_env, provision_subnet_orchestrator_canister}, test_constants::{ get_global_super_admin_principal_id, get_mock_user_alice_canister_id, get_mock_user_alice_principal_id, v1::CANISTER_INITIAL_CYCLES_FOR_SPAWNING_CANISTERS, @@ -115,27 +115,12 @@ fn when_subnet_known_principal_is_updated_it_is_reflected_in_individual_canister .cloned() .unwrap(); - let application_subnets = pocket_ic.topology().get_app_subnets(); - - let subnet_orchestrator_canister_id: Principal = pocket_ic - .update_call( - platform_canister_id, - super_admin, - "provision_subnet_orchestrator_canister", - candid::encode_one(application_subnets[1]).unwrap(), - ) - .map(|res| { - let canister_id_result: Result = match res { - WasmResult::Reply(payload) => candid::decode_one(&payload).unwrap(), - _ => panic!("Canister call failed"), - }; - canister_id_result.unwrap() - }) - .unwrap(); - - for i in 0..50 { - pocket_ic.tick(); - } + let subnet_orchestrator_canister_id = provision_subnet_orchestrator_canister( + &pocket_ic, + &known_principal, + 1, + None, + ); let post_cache_canister_id = Principal::anonymous(); diff --git a/src/lib/integration_tests/tests/platform_orchestrator/provision_empty_canisters_in_a_subnet_test.rs b/src/lib/integration_tests/tests/platform_orchestrator/provision_empty_canisters_in_a_subnet_test.rs index c92da21f..86a5da5b 100644 --- a/src/lib/integration_tests/tests/platform_orchestrator/provision_empty_canisters_in_a_subnet_test.rs +++ b/src/lib/integration_tests/tests/platform_orchestrator/provision_empty_canisters_in_a_subnet_test.rs @@ -5,7 +5,7 @@ use shared_utils::{ constant::TEST_BACKUP_INDIVIDUAL_USER_CANISTER_BATCH_SIZE, }; use test_utils::setup::{ - env::pocket_ic_env::get_new_pocket_ic_env, test_constants::get_mock_user_charlie_principal_id, + env::pocket_ic_env::{get_new_pocket_ic_env, provision_subnet_orchestrator_canister}, test_constants::get_mock_user_charlie_principal_id, }; #[test] @@ -34,25 +34,12 @@ fn provision_empty_canisters_in_a_subnet_test() { ) .unwrap(); - let subnet_orchestrator_canister_id: Principal = pocket_ic - .update_call( - platform_canister_id, - charlie_global_admin, - "provision_subnet_orchestrator_canister", - candid::encode_one(application_subnets[0]).unwrap(), - ) - .map(|res| { - let canister_id_result: Result = match res { - WasmResult::Reply(payload) => candid::decode_one(&payload).unwrap(), - _ => panic!("Canister call failed"), - }; - canister_id_result.unwrap() - }) - .unwrap(); - - for i in 0..130 { - pocket_ic.tick(); - } + let subnet_orchestrator_canister_id = provision_subnet_orchestrator_canister( + &pocket_ic, + &known_principal, + 0, + Some(charlie_global_admin), + ); let empty_canisters_cnt = pocket_ic .query_call( diff --git a/src/lib/integration_tests/tests/platform_orchestrator/provision_subnet_orchestrator_test.rs b/src/lib/integration_tests/tests/platform_orchestrator/provision_subnet_orchestrator_test.rs index 96319398..d4dda775 100644 --- a/src/lib/integration_tests/tests/platform_orchestrator/provision_subnet_orchestrator_test.rs +++ b/src/lib/integration_tests/tests/platform_orchestrator/provision_subnet_orchestrator_test.rs @@ -8,7 +8,7 @@ use shared_utils::{ common::types::{known_principal::KnownPrincipalType, wasm::WasmType}, }; use test_utils::setup::{ - env::pocket_ic_env::get_new_pocket_ic_env, test_constants::get_mock_user_charlie_principal_id, + env::pocket_ic_env::{self, get_new_pocket_ic_env}, test_constants::get_mock_user_charlie_principal_id, }; pub type CanisterId = Principal; @@ -26,8 +26,6 @@ fn provision_subnet_orchestrator_canister() { .cloned() .unwrap(); - let application_subnets = pocket_ic.topology().get_app_subnets(); - let charlie_global_admin = get_mock_user_charlie_principal_id(); pocket_ic @@ -39,25 +37,12 @@ fn provision_subnet_orchestrator_canister() { ) .unwrap(); - let subnet_orchestrator_canister_id: Principal = pocket_ic - .update_call( - platform_canister_id, - charlie_global_admin, - "provision_subnet_orchestrator_canister", - candid::encode_one(application_subnets[1]).unwrap(), - ) - .map(|res| { - let canister_id_result: Result = match res { - WasmResult::Reply(payload) => candid::decode_one(&payload).unwrap(), - _ => panic!("Canister call failed"), - }; - canister_id_result.unwrap() - }) - .unwrap(); - - for i in 0..110 { - pocket_ic.tick(); - } + let subnet_orchestrator_canister_id = pocket_ic_env::provision_subnet_orchestrator_canister( + &pocket_ic, + &known_principal, + 1, + Some(charlie_global_admin), + ); //Check version Installed let last_upgrade_status: UpgradeStatus = pocket_ic diff --git a/src/lib/integration_tests/tests/platform_orchestrator/register_and_deregister_new_subnet_orchestrator_test.rs b/src/lib/integration_tests/tests/platform_orchestrator/register_and_deregister_new_subnet_orchestrator_test.rs index 2cd25342..5093a147 100644 --- a/src/lib/integration_tests/tests/platform_orchestrator/register_and_deregister_new_subnet_orchestrator_test.rs +++ b/src/lib/integration_tests/tests/platform_orchestrator/register_and_deregister_new_subnet_orchestrator_test.rs @@ -5,14 +5,13 @@ use shared_utils::{ common::types::known_principal::KnownPrincipalType, }; use test_utils::setup::{ - env::pocket_ic_env::get_new_pocket_ic_env, test_constants::get_mock_user_charlie_principal_id, + env::pocket_ic_env::{get_new_pocket_ic_env, provision_subnet_orchestrator_canister, provision_subnet_orchestrator_canister_no_wait}, test_constants::get_mock_user_charlie_principal_id, }; #[test] fn register_subnet_orchestrator_with_platform_orchestrator_test() { let (pocket_ic, known_principal) = get_new_pocket_ic_env(); - let application_subnets = pocket_ic.topology().get_app_subnets(); let platform_canister_id = known_principal .get(&KnownPrincipalType::CanisterIdPlatformOrchestrator) .cloned() @@ -34,25 +33,12 @@ fn register_subnet_orchestrator_with_platform_orchestrator_test() { ) .unwrap(); - let subnet_orchestrator_canister_id: Principal = pocket_ic - .update_call( - platform_canister_id, - charlie_global_admin, - "provision_subnet_orchestrator_canister", - candid::encode_one(application_subnets[1]).unwrap(), - ) - .map(|res| { - let canister_id_result: Result = match res { - WasmResult::Reply(payload) => candid::decode_one(&payload).unwrap(), - _ => panic!("Canister call failed"), - }; - canister_id_result.unwrap() - }) - .unwrap(); - - for i in 0..110 { - pocket_ic.tick(); - } + let subnet_orchestrator_canister_id = provision_subnet_orchestrator_canister( + &pocket_ic, + &known_principal, + 1, + Some(charlie_global_admin), + ); let new_subnet_orchestrator_canister = pocket_ic.create_canister(); pocket_ic.add_cycles(new_subnet_orchestrator_canister, 1_000_000_000_000_000); @@ -222,7 +208,6 @@ fn register_subnet_orchestrator_with_platform_orchestrator_test() { fn deregister_subnet_orchestrator_from_platform_orchestrator() { let (pocket_ic, known_principal) = get_new_pocket_ic_env(); - let application_subnets = pocket_ic.topology().get_app_subnets(); let platform_canister_id = known_principal .get(&KnownPrincipalType::CanisterIdPlatformOrchestrator) .cloned() @@ -244,21 +229,12 @@ fn deregister_subnet_orchestrator_from_platform_orchestrator() { ) .unwrap(); - let subnet_orchestrator_canister_id: Principal = pocket_ic - .update_call( - platform_canister_id, - charlie_global_admin, - "provision_subnet_orchestrator_canister", - candid::encode_one(application_subnets[1]).unwrap(), - ) - .map(|res| { - let canister_id_result: Result = match res { - WasmResult::Reply(payload) => candid::decode_one(&payload).unwrap(), - _ => panic!("Canister call failed"), - }; - canister_id_result.unwrap() - }) - .unwrap(); + let subnet_orchestrator_canister_id = provision_subnet_orchestrator_canister_no_wait( + &pocket_ic, + &known_principal, + 1, + Some(charlie_global_admin), + ); let deregister_new_subnet_orchestrator_res = pocket_ic .update_call( diff --git a/src/lib/integration_tests/tests/platform_orchestrator/reset_ml_feed_cache_test.rs b/src/lib/integration_tests/tests/platform_orchestrator/reset_ml_feed_cache_test.rs index 0dddf794..a821a6b0 100644 --- a/src/lib/integration_tests/tests/platform_orchestrator/reset_ml_feed_cache_test.rs +++ b/src/lib/integration_tests/tests/platform_orchestrator/reset_ml_feed_cache_test.rs @@ -25,7 +25,7 @@ use shared_utils::{ constant::{NNS_CYCLE_MINTING_CANISTER, NNS_LEDGER_CANISTER_ID}, }; use test_utils::setup::{ - env::pocket_ic_env::get_new_pocket_ic_env, + env::pocket_ic_env::{get_new_pocket_ic_env, provision_subnet_orchestrator_canister}, test_constants::{ get_mock_user_alice_principal_id, get_mock_user_bob_principal_id, get_mock_user_charlie_principal_id, get_mock_user_dan_principal_id, @@ -89,25 +89,12 @@ fn reset_ml_feed_cache_test() { ) .unwrap(); - let user_index_canister_id: Principal = pocket_ic - .update_call( - platform_canister_id, - super_admin, - "provision_subnet_orchestrator_canister", - candid::encode_one(application_subnets[1]).unwrap(), - ) - .map(|res| { - let canister_id_result: Result = match res { - WasmResult::Reply(payload) => candid::decode_one(&payload).unwrap(), - _ => panic!("Canister call failed"), - }; - canister_id_result.unwrap() - }) - .unwrap(); - - for i in 0..50 { - pocket_ic.tick(); - } + let user_index_canister_id = provision_subnet_orchestrator_canister( + &pocket_ic, + &known_principal, + 1, + None, + ); // User Index available details - call get_subnet_available_capacity diff --git a/src/lib/integration_tests/tests/platform_orchestrator/update_canisters_last_access_time_test.rs b/src/lib/integration_tests/tests/platform_orchestrator/update_canisters_last_access_time_test.rs index b8c79014..31e0a19b 100644 --- a/src/lib/integration_tests/tests/platform_orchestrator/update_canisters_last_access_time_test.rs +++ b/src/lib/integration_tests/tests/platform_orchestrator/update_canisters_last_access_time_test.rs @@ -25,7 +25,7 @@ use shared_utils::{ constant::{NNS_CYCLE_MINTING_CANISTER, NNS_LEDGER_CANISTER_ID}, }; use test_utils::setup::{ - env::pocket_ic_env::get_new_pocket_ic_env, + env::pocket_ic_env::{get_new_pocket_ic_env, provision_subnet_orchestrator_canister}, test_constants::{ get_mock_user_alice_principal_id, get_mock_user_bob_principal_id, get_mock_user_charlie_principal_id, get_mock_user_dan_principal_id, @@ -96,8 +96,6 @@ fn update_canisters_last_access_time_test() { .cloned() .unwrap(); - let application_subnets = pocket_ic.topology().get_app_subnets(); - let charlie_global_admin = get_mock_user_charlie_principal_id(); let alice_principal_id = get_mock_user_alice_principal_id(); let bob_principal_id = get_mock_user_bob_principal_id(); @@ -112,25 +110,12 @@ fn update_canisters_last_access_time_test() { ) .unwrap(); - let user_index_canister_id: Principal = pocket_ic - .update_call( - platform_canister_id, - super_admin, - "provision_subnet_orchestrator_canister", - candid::encode_one(application_subnets[1]).unwrap(), - ) - .map(|res| { - let canister_id_result: Result = match res { - WasmResult::Reply(payload) => candid::decode_one(&payload).unwrap(), - _ => panic!("Canister call failed"), - }; - canister_id_result.unwrap() - }) - .unwrap(); - - for i in 0..50 { - pocket_ic.tick(); - } + let user_index_canister_id = provision_subnet_orchestrator_canister( + &pocket_ic, + &known_principal, + 1, + None + ); // upgrade pf_orch diff --git a/src/lib/integration_tests/tests/profile/migrate_hotornot_user_to_yral_test.rs b/src/lib/integration_tests/tests/profile/migrate_hotornot_user_to_yral_test.rs index 36450804..cc615858 100644 --- a/src/lib/integration_tests/tests/profile/migrate_hotornot_user_to_yral_test.rs +++ b/src/lib/integration_tests/tests/profile/migrate_hotornot_user_to_yral_test.rs @@ -15,7 +15,7 @@ use std::{ time::Duration, }; use test_utils::setup::{ - env::pocket_ic_env::get_new_pocket_ic_env, + env::pocket_ic_env::{get_new_pocket_ic_env, provision_n_subnet_orchestrator_canisters}, test_constants::{ get_mock_user_alice_principal_id, get_mock_user_bob_principal_id, get_mock_user_charlie_principal_id, get_mock_user_dan_principal_id, @@ -37,43 +37,14 @@ fn test_transfer_token_can_heppen_only_once_from_hot_or_not_canister_to_yral_can .cloned() .unwrap(); - let application_subnets = pocket_ic.topology().get_app_subnets(); - - let hot_or_not_subnet_orchestrator_canister_id: Principal = pocket_ic - .update_call( - platform_canister_id, - super_admin, - "provision_subnet_orchestrator_canister", - candid::encode_one(application_subnets[0]).unwrap(), - ) - .map(|res| { - let canister_id_result: Result = match res { - PocketICWasmResult::Reply(payload) => candid::decode_one(&payload).unwrap(), - _ => panic!("Canister call failed"), - }; - canister_id_result.unwrap() - }) - .unwrap(); - - let yral_subnet_orchestrator_canister_id: Principal = pocket_ic - .update_call( - platform_canister_id, - super_admin, - "provision_subnet_orchestrator_canister", - candid::encode_one(application_subnets[1]).unwrap(), - ) - .map(|res| { - let canister_id_result: Result = match res { - PocketICWasmResult::Reply(payload) => candid::decode_one(&payload).unwrap(), - _ => panic!("Canister call failed"), - }; - canister_id_result.unwrap() - }) - .unwrap(); - - for _ in 0..30 { - pocket_ic.tick(); - } + let subnet_orchestrators = provision_n_subnet_orchestrator_canisters( + &pocket_ic, + &known_principal, + 2, + None, + ); + let hot_or_not_subnet_orchestrator_canister_id = subnet_orchestrators[0]; + let yral_subnet_orchestrator_canister_id = subnet_orchestrators[1]; let post_cache_canister_id = Principal::anonymous(); @@ -540,43 +511,14 @@ fn test_when_user_tries_to_misuse_to_recieve_tokens_and_posts() { .cloned() .unwrap(); - let application_subnets = pocket_ic.topology().get_app_subnets(); - - let hot_or_not_subnet_orchestrator_canister_id: Principal = pocket_ic - .update_call( - platform_canister_id, - super_admin, - "provision_subnet_orchestrator_canister", - candid::encode_one(application_subnets[0]).unwrap(), - ) - .map(|res| { - let canister_id_result: Result = match res { - PocketICWasmResult::Reply(payload) => candid::decode_one(&payload).unwrap(), - _ => panic!("Canister call failed"), - }; - canister_id_result.unwrap() - }) - .unwrap(); - - let yral_subnet_orchestrator_canister_id: Principal = pocket_ic - .update_call( - platform_canister_id, - super_admin, - "provision_subnet_orchestrator_canister", - candid::encode_one(application_subnets[1]).unwrap(), - ) - .map(|res| { - let canister_id_result: Result = match res { - PocketICWasmResult::Reply(payload) => candid::decode_one(&payload).unwrap(), - _ => panic!("Canister call failed"), - }; - canister_id_result.unwrap() - }) - .unwrap(); - - for _ in 0..30 { - pocket_ic.tick(); - } + let subnet_orchestrators = provision_n_subnet_orchestrator_canisters( + &pocket_ic, + &known_principal, + 2, + None, + ); + let hot_or_not_subnet_orchestrator_canister_id = subnet_orchestrators[0]; + let yral_subnet_orchestrator_canister_id = subnet_orchestrators[1]; let post_cache_canister_id = Principal::anonymous(); diff --git a/src/lib/integration_tests/tests/reset_individual_user_canister/reset_individual_canister_can_called_from_governance_canister_and_resetting_would_recharge_the_canister_if_needed_and_will_install_latest_wasm.rs b/src/lib/integration_tests/tests/reset_individual_user_canister/reset_individual_canister_can_called_from_governance_canister_and_resetting_would_recharge_the_canister_if_needed_and_will_install_latest_wasm.rs index 127f6f18..91068155 100644 --- a/src/lib/integration_tests/tests/reset_individual_user_canister/reset_individual_canister_can_called_from_governance_canister_and_resetting_would_recharge_the_canister_if_needed_and_will_install_latest_wasm.rs +++ b/src/lib/integration_tests/tests/reset_individual_user_canister/reset_individual_canister_can_called_from_governance_canister_and_resetting_would_recharge_the_canister_if_needed_and_will_install_latest_wasm.rs @@ -24,7 +24,7 @@ use shared_utils::{ constant::{NNS_CYCLE_MINTING_CANISTER, NNS_LEDGER_CANISTER_ID}, }; use test_utils::setup::{ - env::pocket_ic_env::get_new_pocket_ic_env, + env::pocket_ic_env::{get_new_pocket_ic_env, provision_subnet_orchestrator_canister}, test_constants::{ get_mock_user_alice_principal_id, get_mock_user_bob_principal_id, get_mock_user_charlie_principal_id, get_mock_user_dan_principal_id, @@ -110,26 +110,12 @@ fn reset_individual_canister_test() { ) .unwrap(); - let user_index_canister_id: Principal = pocket_ic - .update_call( - platform_canister_id, - admin_principal_id, - "provision_subnet_orchestrator_canister", - candid::encode_one(application_subnets[1]).unwrap(), - ) - .map(|res| { - let canister_id_result: Result = match res { - WasmResult::Reply(payload) => candid::decode_one(&payload).unwrap(), - _ => panic!("Canister call failed"), - }; - canister_id_result.unwrap() - }) - .unwrap(); - - for i in 0..50 { - pocket_ic.tick(); - } - + let user_index_canister_id = provision_subnet_orchestrator_canister( + &pocket_ic, + &known_principal, + 1, + Some(admin_principal_id), + ); // let user_index_canister_id = pocket_ic.create_canister_with_settings(Some(admin_principal_id), None); // pocket_ic.add_cycles(user_index_canister_id, 2_000_000_000_000_000); // let user_index_wasm = user_index_canister_wasm(); diff --git a/src/lib/integration_tests/tests/subnet_orchestrator/provision_new_available_and_backup_canister_on_signups_if_required.rs b/src/lib/integration_tests/tests/subnet_orchestrator/provision_new_available_and_backup_canister_on_signups_if_required.rs index 8b7f4481..1ce4c13f 100644 --- a/src/lib/integration_tests/tests/subnet_orchestrator/provision_new_available_and_backup_canister_on_signups_if_required.rs +++ b/src/lib/integration_tests/tests/subnet_orchestrator/provision_new_available_and_backup_canister_on_signups_if_required.rs @@ -8,7 +8,7 @@ use shared_utils::{ }, }; use test_utils::setup::{ - env::pocket_ic_env::get_new_pocket_ic_env, test_constants::get_mock_user_charlie_principal_id, + env::pocket_ic_env::{get_new_pocket_ic_env, provision_subnet_orchestrator_canister}, test_constants::get_mock_user_charlie_principal_id, }; #[ignore = "we are not provisioning new backup canisters anymore"] @@ -25,8 +25,6 @@ pub fn provision_new_available_and_backup_canisters_on_signup_if_required() { .cloned() .unwrap(); - let application_subnets = pocket_ic.topology().get_app_subnets(); - let charlie_global_admin = get_mock_user_charlie_principal_id(); pocket_ic @@ -38,26 +36,12 @@ pub fn provision_new_available_and_backup_canisters_on_signup_if_required() { ) .unwrap(); - let subnet_orchestrator_canister_id: Principal = pocket_ic - .update_call( - platform_canister_id, - charlie_global_admin, - "provision_subnet_orchestrator_canister", - candid::encode_one(application_subnets[1]).unwrap(), - ) - .map(|res| { - let canister_id_result: Result = match res { - WasmResult::Reply(payload) => candid::decode_one(&payload).unwrap(), - _ => panic!("Canister call failed"), - }; - canister_id_result.unwrap() - }) - .unwrap(); - - for i in 0..130 { - pocket_ic.tick(); - } - + let subnet_orchestrator_canister_id = provision_subnet_orchestrator_canister( + &pocket_ic, + &known_principal, + 1, + Some(charlie_global_admin), + ); let subnet_available_canister_cnt = pocket_ic .query_call( subnet_orchestrator_canister_id, diff --git a/src/lib/integration_tests/tests/subnet_orchestrator/recharge_individual_canister_when_requested.rs b/src/lib/integration_tests/tests/subnet_orchestrator/recharge_individual_canister_when_requested.rs index cdf1f574..a437bfab 100644 --- a/src/lib/integration_tests/tests/subnet_orchestrator/recharge_individual_canister_when_requested.rs +++ b/src/lib/integration_tests/tests/subnet_orchestrator/recharge_individual_canister_when_requested.rs @@ -2,7 +2,7 @@ use candid::Principal; use pocket_ic::WasmResult; use shared_utils::common::types::known_principal::KnownPrincipalType; use test_utils::setup::{ - env::pocket_ic_env::get_new_pocket_ic_env, + env::pocket_ic_env::{get_new_pocket_ic_env, provision_n_subnet_orchestrator_canisters}, test_constants::{get_mock_user_alice_principal_id, get_mock_user_bob_principal_id}, }; @@ -18,54 +18,15 @@ fn recharge_individual_canister_when_requested() { let mut lucy_winnings = 0_u64; let mut tom_winnigns = 0_u64; - let platform_orchestrator_canister_id = known_principal_map - .get(&KnownPrincipalType::CanisterIdPlatformOrchestrator) - .copied() - .unwrap(); - - let global_admin_principal = known_principal_map - .get(&KnownPrincipalType::UserIdGlobalSuperAdmin) - .copied() - .unwrap(); - - let application_subnets = pocket_ic.topology().get_app_subnets(); - - let subnet_orchestrator_canister_id_0 = pocket_ic - .update_call( - platform_orchestrator_canister_id, - global_admin_principal, - "provision_subnet_orchestrator_canister", - candid::encode_one(application_subnets[0]).unwrap(), - ) - .map(|res| { - let canister_id_result: Result = match res { - WasmResult::Reply(payload) => candid::decode_one(&payload).unwrap(), - _ => panic!("Canister call failed"), - }; - canister_id_result.unwrap() - }) - .unwrap(); - - let subnet_orchestrator_canister_id_1 = pocket_ic - .update_call( - platform_orchestrator_canister_id, - global_admin_principal, - "provision_subnet_orchestrator_canister", - candid::encode_one(application_subnets[1]).unwrap(), - ) - .map(|res| { - let canister_id_result: Result = match res { - WasmResult::Reply(payload) => candid::decode_one(&payload).unwrap(), - _ => panic!("Canister call failed"), - }; - canister_id_result.unwrap() - }) - .unwrap(); - - for i in 0..50 { - pocket_ic.tick(); - } + let subnet_orchestrators = provision_n_subnet_orchestrator_canisters( + &pocket_ic, + &known_principal_map, + 2, + None, + ); + let subnet_orchestrator_canister_id_0 = subnet_orchestrators[0]; + let subnet_orchestrator_canister_id_1 = subnet_orchestrators[1]; //Post Creator Canister let alice_canister_id = pocket_ic .update_call( diff --git a/src/lib/integration_tests/tests/subnet_orchestrator/test_allot_empty_canisters_to_individual_canister.rs b/src/lib/integration_tests/tests/subnet_orchestrator/test_allot_empty_canisters_to_individual_canister.rs index 09df6f38..1d2cedeb 100644 --- a/src/lib/integration_tests/tests/subnet_orchestrator/test_allot_empty_canisters_to_individual_canister.rs +++ b/src/lib/integration_tests/tests/subnet_orchestrator/test_allot_empty_canisters_to_individual_canister.rs @@ -2,7 +2,7 @@ use candid::Principal; use pocket_ic::WasmResult; use shared_utils::common::types::known_principal::KnownPrincipalType; use test_utils::setup::{ - env::pocket_ic_env::get_new_pocket_ic_env, + env::pocket_ic_env::{get_new_pocket_ic_env, provision_subnet_orchestrator_canister}, test_constants::{get_mock_user_alice_principal_id, get_mock_user_charlie_principal_id}, }; @@ -19,8 +19,6 @@ fn test_allot_empty_canisters_to_individual_canister() { .cloned() .unwrap(); - let application_subnets = pocket_ic.topology().get_app_subnets(); - let charlie_global_admin = get_mock_user_charlie_principal_id(); pocket_ic @@ -32,25 +30,12 @@ fn test_allot_empty_canisters_to_individual_canister() { ) .unwrap(); - let subnet_orchestrator_canister_id: Principal = pocket_ic - .update_call( - platform_canister_id, - charlie_global_admin, - "provision_subnet_orchestrator_canister", - candid::encode_one(application_subnets[1]).unwrap(), - ) - .map(|res| { - let canister_id_result: Result = match res { - WasmResult::Reply(payload) => candid::decode_one(&payload).unwrap(), - _ => panic!("Canister call failed"), - }; - canister_id_result.unwrap() - }) - .unwrap(); - - for i in 0..120 { - pocket_ic.tick(); - } + let subnet_orchestrator_canister_id = provision_subnet_orchestrator_canister( + &pocket_ic, + &known_principal, + 1, + Some(charlie_global_admin), + ); let alice_yral_principal_id = get_mock_user_alice_principal_id(); let alice_yral_canister_id = pocket_ic diff --git a/src/lib/integration_tests/tests/subnet_orchestrator/test_mark_subnet_orchestrator_as_maxed_out_once_backup_canisters_are_consumed.rs b/src/lib/integration_tests/tests/subnet_orchestrator/test_mark_subnet_orchestrator_as_maxed_out_once_backup_canisters_are_consumed.rs index 4fce7686..440958a4 100644 --- a/src/lib/integration_tests/tests/subnet_orchestrator/test_mark_subnet_orchestrator_as_maxed_out_once_backup_canisters_are_consumed.rs +++ b/src/lib/integration_tests/tests/subnet_orchestrator/test_mark_subnet_orchestrator_as_maxed_out_once_backup_canisters_are_consumed.rs @@ -8,7 +8,7 @@ use shared_utils::{ }, }; use test_utils::setup::{ - env::pocket_ic_env::get_new_pocket_ic_env, test_constants::get_mock_user_charlie_principal_id, + env::pocket_ic_env::{get_new_pocket_ic_env, provision_subnet_orchestrator_canister}, test_constants::get_mock_user_charlie_principal_id, }; #[test] @@ -24,8 +24,6 @@ fn test_mark_subnet_orchestrator_as_maxed_out_once_backup_canisters_are_consumed .cloned() .unwrap(); - let application_subnets = pocket_ic.topology().get_app_subnets(); - let charlie_global_admin = get_mock_user_charlie_principal_id(); pocket_ic @@ -37,25 +35,12 @@ fn test_mark_subnet_orchestrator_as_maxed_out_once_backup_canisters_are_consumed ) .unwrap(); - let subnet_orchestrator_canister_id: Principal = pocket_ic - .update_call( - platform_canister_id, - charlie_global_admin, - "provision_subnet_orchestrator_canister", - candid::encode_one(application_subnets[1]).unwrap(), - ) - .map(|res| { - let canister_id_result: Result = match res { - WasmResult::Reply(payload) => candid::decode_one(&payload).unwrap(), - _ => panic!("Canister call failed"), - }; - canister_id_result.unwrap() - }) - .unwrap(); - - for i in 0..130 { - pocket_ic.tick(); - } + let subnet_orchestrator_canister_id = provision_subnet_orchestrator_canister( + &pocket_ic, + &known_principal, + 1, + Some(charlie_global_admin), + ); let subnet_available_canister_cnt = pocket_ic .query_call( diff --git a/src/lib/integration_tests/tests/subnet_orchestrator/test_updating_controller_before_upgrading_invidividual_canister.rs b/src/lib/integration_tests/tests/subnet_orchestrator/test_updating_controller_before_upgrading_invidividual_canister.rs index 3f9a489c..8413aa78 100644 --- a/src/lib/integration_tests/tests/subnet_orchestrator/test_updating_controller_before_upgrading_invidividual_canister.rs +++ b/src/lib/integration_tests/tests/subnet_orchestrator/test_updating_controller_before_upgrading_invidividual_canister.rs @@ -5,7 +5,7 @@ use shared_utils::{ common::types::known_principal::KnownPrincipalType, }; use test_utils::setup::{ - env::pocket_ic_env::get_new_pocket_ic_env, + env::pocket_ic_env::{get_new_pocket_ic_env, provision_subnet_orchestrator_canister}, test_constants::{get_mock_user_alice_canister_id, get_mock_user_charlie_principal_id}, }; @@ -35,26 +35,12 @@ fn test_updating_controller_before_upgrading_invidividual_canister() { ) .unwrap(); - let subnet_orchestrator_canister_id: Principal = pocket_ic - .update_call( - platform_canister_id, - charlie_global_admin, - "provision_subnet_orchestrator_canister", - candid::encode_one(application_subnets[1]).unwrap(), - ) - .map(|res| { - let canister_id_result: Result = match res { - WasmResult::Reply(payload) => candid::decode_one(&payload).unwrap(), - _ => panic!("Canister call failed"), - }; - canister_id_result.unwrap() - }) - .unwrap(); - - for _ in 0..110 { - pocket_ic.tick() - } - + let subnet_orchestrator_canister_id = provision_subnet_orchestrator_canister( + &pocket_ic, + &known_principal, + 1, + Some(charlie_global_admin), + ); let alice_yral_principal_id = get_mock_user_alice_canister_id(); let alice_yral_canister_id = pocket_ic diff --git a/src/lib/test_utils/src/setup/env/pocket_ic_env.rs b/src/lib/test_utils/src/setup/env/pocket_ic_env.rs index 6397ba63..d87ea547 100644 --- a/src/lib/test_utils/src/setup/env/pocket_ic_env.rs +++ b/src/lib/test_utils/src/setup/env/pocket_ic_env.rs @@ -194,6 +194,59 @@ pub fn get_new_pocket_ic_env() -> (PocketIc, KnownPrincipalMap) { (pocket_ic, known_principal) } +/// Provision a subnet canister +/// `app_subnet_idx` is the index of the application subnet to use. Set to 0 if you're unsure +/// optionally provide a `caller` for the call, else it uses the global super admin +pub fn provision_subnet_orchestrator_canister(pic: &PocketIc, known_principals: &KnownPrincipalMap, app_subnet_idx: usize, caller: Option) -> Principal { + let user_index = provision_subnet_orchestrator_canister_no_wait(pic, known_principals, app_subnet_idx, caller); + for _ in 0..1000 { + pic.tick(); + } + + user_index +} + +/// use [`provision_subnet_orchestrator_canister`] if you don't know what you're doing +pub fn provision_subnet_orchestrator_canister_no_wait(pic: &PocketIc, known_principals: &KnownPrincipalMap, app_subnet_idx: usize, caller: Option) -> Principal { + let caller = caller.unwrap_or_else(|| known_principals[&KnownPrincipalType::UserIdGlobalSuperAdmin]); + let platform_orc = known_principals[&KnownPrincipalType::CanisterIdPlatformOrchestrator]; + let app_subnets = pic.topology().get_app_subnets(); + let user_index_res: Result = execute_update( + pic, + caller, + platform_orc, + "provision_subnet_orchestrator_canister", + &app_subnets[app_subnet_idx] + ); + let user_index = user_index_res.unwrap(); + user_index +} + +pub fn provision_n_subnet_orchestrator_canisters(pic: &PocketIc, known_principals: &KnownPrincipalMap, n: usize, caller: Option) -> Vec { + let mut out = vec![]; + + let caller = caller.unwrap_or_else(|| known_principals[&KnownPrincipalType::CanisterIdPlatformOrchestrator]); + let platform_orc = known_principals[&KnownPrincipalType::CanisterIdPlatformOrchestrator]; + let app_subnets = pic.topology().get_app_subnets(); + + for subnet in app_subnets.into_iter().take(n) { + let user_index_res: Result = execute_update( + pic, + caller, + platform_orc, + "provision_subnet_orchestrator_canister", + &subnet + ); + out.push(user_index_res.unwrap()); + } + + for _ in 0..(1000 + 10 * n) { + pic.tick() + } + + out +} + pub fn execute_query Deserialize<'x>>( pic: &PocketIc, sender: Principal, diff --git a/src/lib/test_utils/src/setup/env/v1.rs b/src/lib/test_utils/src/setup/env/v1.rs index 2d3aed7a..87aef85a 100644 --- a/src/lib/test_utils/src/setup/env/v1.rs +++ b/src/lib/test_utils/src/setup/env/v1.rs @@ -153,7 +153,7 @@ pub fn provision_individual_user_canisters( ) .unwrap(); - for _ in 0..100 { + for _ in 0..1000 { state_machine.tick(); } }