Skip to content

Commit

Permalink
refactor(integration_tests): update wait time for provision_subnet_or…
Browse files Browse the repository at this point in the history
…chestrator
  • Loading branch information
rupansh committed Nov 29, 2024
1 parent 41a16a1 commit 4a1cd56
Show file tree
Hide file tree
Showing 23 changed files with 223 additions and 585 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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},
};

Expand Down Expand Up @@ -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<Principal, String> = 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(
Expand Down
30 changes: 8 additions & 22 deletions src/lib/integration_tests/tests/creator_dao/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -118,16 +119,14 @@ 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()
.unwrap();

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
Expand All @@ -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<Principal, String> = 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -32,16 +32,14 @@ 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()
.unwrap();

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
Expand All @@ -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<Principal, String> = 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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<Principal, String> = 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<Principal, String> = 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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<Principal, String> = 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![];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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<Principal, String> = 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();

Expand Down
29 changes: 7 additions & 22 deletions src/lib/integration_tests/tests/kv_store/test_namespace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
};

Expand All @@ -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
Expand All @@ -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<Principal, String> = 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();

Expand Down
Loading

0 comments on commit 4a1cd56

Please sign in to comment.