From 302ec00c15cfc54658f043b6dd3f0fe661a62e61 Mon Sep 17 00:00:00 2001 From: Hamish Peebles Date: Wed, 22 Nov 2023 10:25:08 +0000 Subject: [PATCH] Avoid exceeding ingress message size limit in tests (#4820) --- .../src/client/group_index.rs | 100 +++++++++++++++- .../src/client/notifications_index.rs | 54 +++++++++ .../src/client/storage_index.rs | 25 +++- .../src/client/user_index.rs | 74 +++++++++++- backend/integration_tests/src/setup.rs | 107 ++++++++++-------- 5 files changed, 307 insertions(+), 53 deletions(-) diff --git a/backend/integration_tests/src/client/group_index.rs b/backend/integration_tests/src/client/group_index.rs index f5f4409cd2..af479ac67a 100644 --- a/backend/integration_tests/src/client/group_index.rs +++ b/backend/integration_tests/src/client/group_index.rs @@ -11,11 +11,15 @@ generate_update_call!(add_local_group_index_canister); generate_update_call!(delete_frozen_group); generate_update_call!(freeze_group); generate_update_call!(unfreeze_group); +generate_update_call!(upgrade_community_canister_wasm); +generate_update_call!(upgrade_group_canister_wasm); +generate_update_call!(upgrade_local_group_index_canister_wasm); pub mod happy_path { use crate::User; + use candid::Principal; use pocket_ic::PocketIc; - use types::{CanisterId, CommunityMatch, GroupMatch}; + use types::{CanisterId, CanisterWasm, CommunityMatch, GroupMatch}; pub fn explore_communities(env: &PocketIc, sender: &User, group_index_canister_id: CanisterId) -> Vec { let response = super::explore_communities( @@ -56,4 +60,98 @@ pub mod happy_path { panic!("'explore_groups' error: {response:?}"); } } + + pub fn upgrade_local_group_index_canister_wasm( + env: &mut PocketIc, + sender: Principal, + group_index_canister_id: CanisterId, + wasm: CanisterWasm, + ) { + let response = super::upgrade_local_group_index_canister_wasm( + env, + sender, + group_index_canister_id, + &group_index_canister::upgrade_local_group_index_canister_wasm::Args { + wasm, + filter: None, + use_for_new_canisters: None, + }, + ); + + assert!(matches!( + response, + group_index_canister::upgrade_local_group_index_canister_wasm::Response::Success + )); + } + + pub fn upgrade_group_canister_wasm( + env: &mut PocketIc, + sender: Principal, + group_index_canister_id: CanisterId, + wasm: CanisterWasm, + ) { + let response = super::upgrade_group_canister_wasm( + env, + sender, + group_index_canister_id, + &group_index_canister::upgrade_group_canister_wasm::Args { + wasm, + filter: None, + use_for_new_canisters: None, + }, + ); + + assert!(matches!( + response, + group_index_canister::upgrade_group_canister_wasm::Response::Success + )); + } + + pub fn upgrade_community_canister_wasm( + env: &mut PocketIc, + sender: Principal, + group_index_canister_id: CanisterId, + wasm: CanisterWasm, + ) { + let response = super::upgrade_community_canister_wasm( + env, + sender, + group_index_canister_id, + &group_index_canister::upgrade_community_canister_wasm::Args { + wasm, + filter: None, + use_for_new_canisters: None, + }, + ); + + assert!(matches!( + response, + group_index_canister::upgrade_community_canister_wasm::Response::Success + )); + } + + pub fn add_local_group_index_canister( + env: &mut PocketIc, + sender: Principal, + group_index_canister_id: CanisterId, + local_group_index_canister_id: CanisterId, + local_user_index_canister_id: CanisterId, + notifications_canister_id: CanisterId, + ) { + let response = super::add_local_group_index_canister( + env, + sender, + group_index_canister_id, + &group_index_canister::add_local_group_index_canister::Args { + canister_id: local_group_index_canister_id, + local_user_index_canister_id, + notifications_canister_id, + }, + ); + + assert!(matches!( + response, + group_index_canister::add_local_group_index_canister::Response::Success + )); + } } diff --git a/backend/integration_tests/src/client/notifications_index.rs b/backend/integration_tests/src/client/notifications_index.rs index d76795790c..07c024ab94 100644 --- a/backend/integration_tests/src/client/notifications_index.rs +++ b/backend/integration_tests/src/client/notifications_index.rs @@ -6,3 +6,57 @@ use notifications_index_canister::*; // Updates generate_update_call!(add_notifications_canister); generate_update_call!(push_subscription); +generate_update_call!(upgrade_notifications_canister_wasm); + +pub mod happy_path { + use candid::Principal; + use pocket_ic::PocketIc; + use types::{CanisterId, CanisterWasm}; + + pub fn upgrade_notifications_canister_wasm( + env: &mut PocketIc, + sender: Principal, + notifications_index_canister_id: CanisterId, + wasm: CanisterWasm, + ) { + let response = super::upgrade_notifications_canister_wasm( + env, + sender, + notifications_index_canister_id, + ¬ifications_index_canister::upgrade_notifications_canister_wasm::Args { + wasm, + filter: None, + use_for_new_canisters: None, + }, + ); + + assert!(matches!( + response, + notifications_index_canister::upgrade_notifications_canister_wasm::Response::Success + )); + } + + pub fn add_notifications_canister( + env: &mut PocketIc, + sender: Principal, + notifications_index_canister_id: CanisterId, + notifications_canister_id: CanisterId, + local_user_index_canister_id: CanisterId, + local_group_index_canister_id: CanisterId, + ) { + let response = super::add_notifications_canister( + env, + sender, + notifications_index_canister_id, + ¬ifications_index_canister::add_notifications_canister::Args { + canister_id: notifications_canister_id, + authorizers: vec![local_user_index_canister_id, local_group_index_canister_id], + }, + ); + + assert!(matches!( + response, + notifications_index_canister::add_notifications_canister::Response::Success + )); + } +} diff --git a/backend/integration_tests/src/client/storage_index.rs b/backend/integration_tests/src/client/storage_index.rs index cf1442f142..49aaacb8be 100644 --- a/backend/integration_tests/src/client/storage_index.rs +++ b/backend/integration_tests/src/client/storage_index.rs @@ -19,7 +19,7 @@ pub mod happy_path { use pocket_ic::PocketIc; use storage_index_canister::add_or_update_users::UserConfig; use storage_index_canister::user::UserRecord; - use types::CanisterId; + use types::{CanisterId, CanisterWasm}; use utils::hasher::hash_bytes; pub fn add_or_update_users(env: &mut PocketIc, sender: Principal, canister_id: CanisterId, users: Vec) { @@ -75,4 +75,27 @@ pub mod happy_path { panic!("'user' error: {response:?}"); } } + + pub fn upgrade_notifications_canister_wasm( + env: &mut PocketIc, + sender: Principal, + storage_index_canister_id: CanisterId, + wasm: CanisterWasm, + ) { + let response = super::upgrade_bucket_canister_wasm( + env, + sender, + storage_index_canister_id, + &storage_index_canister::upgrade_bucket_canister_wasm::Args { + wasm, + filter: None, + use_for_new_canisters: None, + }, + ); + + assert!(matches!( + response, + storage_index_canister::upgrade_bucket_canister_wasm::Response::Success + )); + } } diff --git a/backend/integration_tests/src/client/user_index.rs b/backend/integration_tests/src/client/user_index.rs index b9998a2cd7..2741fe316a 100644 --- a/backend/integration_tests/src/client/user_index.rs +++ b/backend/integration_tests/src/client/user_index.rs @@ -21,12 +21,15 @@ generate_update_call!(set_display_name); generate_update_call!(set_username); generate_update_call!(suspend_user); generate_update_call!(unsuspend_user); +generate_update_call!(upgrade_local_user_index_canister_wasm); generate_update_call!(upgrade_user_canister_wasm); pub mod happy_path { use candid::Principal; use pocket_ic::PocketIc; - use types::{CanisterId, Cryptocurrency, DiamondMembershipDetails, DiamondMembershipPlanDuration, UserId, UserSummary}; + use types::{ + CanisterId, CanisterWasm, Cryptocurrency, DiamondMembershipDetails, DiamondMembershipPlanDuration, UserId, UserSummary, + }; use user_index_canister::users_v2::UserGroup; pub fn current_user( @@ -105,4 +108,73 @@ pub mod happy_path { result.users } + + pub fn upgrade_local_user_index_canister_wasm( + env: &mut PocketIc, + sender: Principal, + user_index_canister_id: CanisterId, + wasm: CanisterWasm, + ) { + let response = super::upgrade_local_user_index_canister_wasm( + env, + sender, + user_index_canister_id, + &user_index_canister::upgrade_local_user_index_canister_wasm::Args { + wasm, + filter: None, + use_for_new_canisters: None, + }, + ); + + assert!(matches!( + response, + user_index_canister::upgrade_local_user_index_canister_wasm::Response::Success + )); + } + + pub fn upgrade_user_canister_wasm( + env: &mut PocketIc, + sender: Principal, + user_index_canister_id: CanisterId, + wasm: CanisterWasm, + ) { + let response = super::upgrade_user_canister_wasm( + env, + sender, + user_index_canister_id, + &user_index_canister::upgrade_user_canister_wasm::Args { + wasm, + filter: None, + use_for_new_canisters: None, + }, + ); + + assert!(matches!( + response, + user_index_canister::upgrade_user_canister_wasm::Response::Success + )); + } + + pub fn add_local_user_index_canister( + env: &mut PocketIc, + sender: Principal, + user_index_canister_id: CanisterId, + local_user_index_canister_id: CanisterId, + notifications_canister_id: CanisterId, + ) { + let response = super::add_local_user_index_canister( + env, + sender, + user_index_canister_id, + &user_index_canister::add_local_user_index_canister::Args { + canister_id: local_user_index_canister_id, + notifications_canister_id, + }, + ); + + assert!(matches!( + response, + user_index_canister::add_local_user_index_canister::Response::Success + )); + } } diff --git a/backend/integration_tests/src/setup.rs b/backend/integration_tests/src/setup.rs index 48b27bb863..26d8961a3b 100644 --- a/backend/integration_tests/src/setup.rs +++ b/backend/integration_tests/src/setup.rs @@ -11,7 +11,7 @@ use std::collections::{HashMap, HashSet}; use std::env; use std::path::Path; use storage_index_canister::init::CyclesDispenserConfig; -use types::{BuildVersion, CanisterId}; +use types::{BuildVersion, CanisterId, CanisterWasm}; pub static POCKET_IC_BIN: &str = "./pocket-ic"; @@ -51,12 +51,12 @@ pub fn setup_new_env() -> TestEnv { fn install_canisters(env: &mut PocketIc, controller: Principal) -> CanisterIds { let nns_canister_ids: Vec<_> = (0..12).map(|_| create_canister(env, controller)).collect(); - let nns_governance_canister_id = nns_canister_ids[1]; - let nns_ledger_canister_id = nns_canister_ids[2]; - let nns_root_canister_id = nns_canister_ids[3]; - let cycles_minting_canister_id = nns_canister_ids[4]; - let sns_wasm_canister_id = nns_canister_ids[10]; - let nns_index_canister_id = nns_canister_ids[11]; + let nns_governance_canister_id = nns_canister_ids[1]; // rrkah-fqaaa-aaaaa-aaaaq-cai + let nns_ledger_canister_id = nns_canister_ids[2]; // ryjl3-tyaaa-aaaaa-aaaba-cai + let nns_root_canister_id = nns_canister_ids[3]; // r7inp-6aaaa-aaaaa-aaabq-cai + let cycles_minting_canister_id = nns_canister_ids[4]; // rkp4c-7iaaa-aaaaa-aaaca-cai + let sns_wasm_canister_id = nns_canister_ids[10]; // qaa6y-5yaaa-aaaaa-aaafa-cai + let nns_index_canister_id = nns_canister_ids[11]; // qhbym-qaaaa-aaaaa-aaafq-cai let user_index_canister_id = create_canister(env, controller); let group_index_canister_id = create_canister(env, controller); @@ -92,8 +92,8 @@ fn install_canisters(env: &mut PocketIc, controller: Principal) -> CanisterIds { let user_index_init_args = user_index_canister::init::Args { service_principals: vec![controller], - user_canister_wasm, - local_user_index_canister_wasm, + user_canister_wasm: CanisterWasm::default(), + local_user_index_canister_wasm: CanisterWasm::default(), group_index_canister_id, notifications_index_canister_id, proposals_bot_canister_id, @@ -113,9 +113,9 @@ fn install_canisters(env: &mut PocketIc, controller: Principal) -> CanisterIds { let group_index_init_args = group_index_canister::init::Args { service_principals: vec![controller], - group_canister_wasm, - community_canister_wasm, - local_group_index_canister_wasm, + group_canister_wasm: CanisterWasm::default(), + community_canister_wasm: CanisterWasm::default(), + local_group_index_canister_wasm: CanisterWasm::default(), user_index_canister_id, cycles_dispenser_canister_id, proposals_bot_user_id: proposals_bot_canister_id.into(), @@ -136,7 +136,7 @@ fn install_canisters(env: &mut PocketIc, controller: Principal) -> CanisterIds { user_index_canister_id, authorizers: vec![user_index_canister_id, group_index_canister_id], cycles_dispenser_canister_id, - notifications_canister_wasm, + notifications_canister_wasm: CanisterWasm::default(), wasm_version: BuildVersion::min(), test_mode: true, }; @@ -184,7 +184,7 @@ fn install_canisters(env: &mut PocketIc, controller: Principal) -> CanisterIds { let storage_index_init_args = storage_index_canister::init::Args { governance_principals: vec![controller], user_controllers: vec![user_index_canister_id, group_index_canister_id], - bucket_canister_wasm: storage_bucket_canister_wasm, + bucket_canister_wasm: CanisterWasm::default(), cycles_dispenser_config: CyclesDispenserConfig { canister_id: cycles_dispenser_canister_id, min_cycles_balance: 200 * T, @@ -250,56 +250,63 @@ fn install_canisters(env: &mut PocketIc, controller: Principal) -> CanisterIds { registry_init_args, ); - let add_local_group_index_canister_response = client::group_index::add_local_group_index_canister( + client::user_index::happy_path::upgrade_user_canister_wasm(env, controller, user_index_canister_id, user_canister_wasm); + client::user_index::happy_path::upgrade_local_user_index_canister_wasm( env, controller, - group_index_canister_id, - &group_index_canister::add_local_group_index_canister::Args { - canister_id: local_group_index_canister_id, - local_user_index_canister_id, - notifications_canister_id, - }, + user_index_canister_id, + local_user_index_canister_wasm, ); - assert!( - matches!( - add_local_group_index_canister_response, - group_index_canister::add_local_group_index_canister::Response::Success - ), - "{add_local_group_index_canister_response:?}" + client::user_index::happy_path::add_local_user_index_canister( + env, + controller, + user_index_canister_id, + local_user_index_canister_id, + notifications_canister_id, ); - let add_local_user_index_canister_response = client::user_index::add_local_user_index_canister( + client::group_index::happy_path::upgrade_group_canister_wasm(env, controller, group_index_canister_id, group_canister_wasm); + client::group_index::happy_path::upgrade_community_canister_wasm( env, controller, - user_index_canister_id, - &user_index_canister::add_local_user_index_canister::Args { - canister_id: local_user_index_canister_id, - notifications_canister_id, - }, + group_index_canister_id, + community_canister_wasm, ); - assert!( - matches!( - add_local_user_index_canister_response, - user_index_canister::add_local_user_index_canister::Response::Success - ), - "{add_local_user_index_canister_response:?}" + client::group_index::happy_path::upgrade_local_group_index_canister_wasm( + env, + controller, + group_index_canister_id, + local_group_index_canister_wasm, + ); + client::group_index::happy_path::add_local_group_index_canister( + env, + controller, + group_index_canister_id, + local_group_index_canister_id, + local_user_index_canister_id, + notifications_canister_id, ); - let add_notifications_canister_response = client::notifications_index::add_notifications_canister( + client::notifications_index::happy_path::upgrade_notifications_canister_wasm( env, controller, notifications_index_canister_id, - ¬ifications_index_canister::add_notifications_canister::Args { - canister_id: notifications_canister_id, - authorizers: vec![local_user_index_canister_id, local_group_index_canister_id], - }, + notifications_canister_wasm, + ); + client::notifications_index::happy_path::add_notifications_canister( + env, + controller, + notifications_index_canister_id, + notifications_canister_id, + local_user_index_canister_id, + local_group_index_canister_id, ); - assert!( - matches!( - add_notifications_canister_response, - notifications_index_canister::add_notifications_canister::Response::Success - ), - "{add_notifications_canister_response:?}" + + client::storage_index::happy_path::upgrade_notifications_canister_wasm( + env, + controller, + storage_index_canister_id, + storage_bucket_canister_wasm, ); let minting_account = AccountIdentifier::new(&controller, &DEFAULT_SUBACCOUNT);