Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Groundwork to support multi subnet integration tests #7076

Merged
merged 6 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 2 additions & 8 deletions backend/integration_tests/src/airdrop_bot_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,7 @@ fn airdrop_end_to_end(v2: bool) {
);

for user in users.iter() {
client::local_user_index::happy_path::join_channel(
env,
user.principal,
canister_ids.local_user_index,
community_id,
channel_id,
);
client::community::happy_path::join_channel(env, user.principal, community_id, channel_id);
}

tick_many(env, 10);
Expand All @@ -75,7 +69,7 @@ fn airdrop_end_to_end(v2: bool) {
client::local_user_index::happy_path::invite_users_to_channel(
env,
&owner,
canister_ids.local_user_index,
canister_ids.local_user_index(env, community_id),
community_id,
channel_id,
vec![airdrop_bot_user_id],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ fn get_batched_events_succeeds() {
let local_user_index_canister::chat_events::Response::Success(result) = client::local_user_index::chat_events(
env,
user1.principal,
canister_ids.local_user_index,
canister_ids.local_user_index(env, user1.canister()),
&local_user_index_canister::chat_events::Args {
requests: vec![
EventsArgs {
Expand Down Expand Up @@ -99,11 +99,13 @@ fn get_batched_summaries_succeeds() {

let start = now_millis(env);

let local_user_index = canister_ids.local_user_index(env, user1.canister());

let local_user_index_canister::group_and_community_summary_updates::Response::Success(responses) =
client::local_user_index::group_and_community_summary_updates(
env,
user1.principal,
canister_ids.local_user_index,
local_user_index,
&local_user_index_canister::group_and_community_summary_updates::Args {
requests: vec![
SummaryUpdatesArgs {
Expand Down Expand Up @@ -142,7 +144,7 @@ fn get_batched_summaries_succeeds() {
client::local_user_index::group_and_community_summary_updates(
env,
user1.principal,
canister_ids.local_user_index,
local_user_index,
&local_user_index_canister::group_and_community_summary_updates::Args {
requests: vec![
SummaryUpdatesArgs {
Expand Down
28 changes: 18 additions & 10 deletions backend/integration_tests/src/bot_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ fn e2e_bot_test() {
env.tick();

// Confirm bot returned in `selected_initial`
let response = client::group::happy_path::selected_initial(env, &user, group_id);
let response = client::group::happy_path::selected_initial(env, user.principal, group_id);
assert_eq!(response.bots.len(), 1);
assert_eq!(response.bots[0].user_id, bot.id);

Expand All @@ -99,8 +99,12 @@ fn e2e_bot_test() {
}),
chat,
};
let response =
client::local_user_index::access_token(env, user.principal, canister_ids.local_user_index, &access_token_args);
let response = client::local_user_index::access_token(
env,
user.principal,
canister_ids.local_user_index(env, group_id),
&access_token_args,
);

// Confirm bot is unauthorised
assert!(matches!(
Expand All @@ -119,11 +123,15 @@ fn e2e_bot_test() {
assert_eq!(response.bots_added_or_updated[0].user_id, bot.id);

// Try again to get an access token to call the greet command
let access_token =
match client::local_user_index::access_token(env, user.principal, canister_ids.local_user_index, &access_token_args) {
local_user_index_canister::access_token::Response::Success(access_token) => access_token,
response => panic!("'access_token' error: {response:?}"),
};
let access_token = match client::local_user_index::access_token(
env,
user.principal,
canister_ids.local_user_index(env, group_id),
&access_token_args,
) {
local_user_index_canister::access_token::Response::Success(access_token) => access_token,
response => panic!("'access_token' error: {response:?}"),
};

println!("ACCESS TOKEN: {access_token}");

Expand All @@ -133,7 +141,7 @@ fn e2e_bot_test() {
let response = client::local_user_index::execute_bot_command(
env,
bot_principal,
canister_ids.local_user_index,
canister_ids.local_user_index(env, group_id),
&local_user_index_canister::execute_bot_command::Args {
action: BotAction::SendMessage(BotMessageAction {
content: MessageContent::Text(TextContent { text: text.clone() }),
Expand Down Expand Up @@ -167,7 +175,7 @@ fn e2e_bot_test() {
let response = client::local_user_index::execute_bot_command(
env,
bot_principal,
canister_ids.local_user_index,
canister_ids.local_user_index(env, group_id),
&local_user_index_canister::execute_bot_command::Args {
action: BotAction::SendMessage(BotMessageAction {
content: MessageContent::Text(TextContent { text: text.clone() }),
Expand Down
6 changes: 3 additions & 3 deletions backend/integration_tests/src/change_group_role_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ fn owner_can_promote_to_and_demote_from_owner() {

client::group::happy_path::change_role(env, user1.principal, group_id, user2.user_id, GroupRole::Owner);

let summary1 = client::group::happy_path::summary(env, &user2, group_id);
let summary1 = client::group::happy_path::summary(env, user2.principal, group_id);
assert!(matches!(summary1.role, GroupRole::Owner));

client::group::happy_path::change_role(env, user1.principal, group_id, user2.user_id, GroupRole::Admin);

let summary1 = client::group::happy_path::summary(env, &user2, group_id);
let summary1 = client::group::happy_path::summary(env, user2.principal, group_id);
assert!(matches!(summary1.role, GroupRole::Admin));
}

Expand All @@ -36,7 +36,7 @@ fn init_test_data(env: &mut PocketIc, canister_ids: &CanisterIds, controller: Pr
let group_name = random_string();

let group_id = client::user::happy_path::create_group(env, &user1, &group_name, true, true);
client::local_user_index::happy_path::join_group(env, user2.principal, canister_ids.local_user_index, group_id);
client::group::happy_path::join_group(env, user2.principal, group_id);

TestData { user1, user2, group_id }
}
Expand Down
42 changes: 32 additions & 10 deletions backend/integration_tests/src/client/community.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ pub const STABLE_MEMORY_MAP_MEMORY_ID: MemoryId = MemoryId::new(3);
generate_msgpack_query_call!(channel_summary);
generate_msgpack_query_call!(events);
generate_msgpack_query_call!(events_by_index);
generate_msgpack_query_call!(local_user_index);
generate_msgpack_query_call!(search_channel);
generate_msgpack_query_call!(selected_channel_initial);
generate_msgpack_query_call!(selected_channel_updates_v2);
Expand Down Expand Up @@ -53,10 +54,10 @@ pub mod happy_path {
use pocket_ic::PocketIc;
use testing::rng::random_from_u128;
use types::{
AccessGate, ChannelId, ChatId, CommunityCanisterChannelSummary, CommunityCanisterCommunitySummary,
CommunityCanisterCommunitySummaryUpdates, CommunityId, CommunityRole, EventIndex, EventsResponse, GroupReplyContext,
GroupRole, MessageContentInitial, MessageId, MessageIndex, PollVotes, Reaction, Rules, SlashCommandPermissions,
TextContent, TimestampMillis, UserId, VoteOperation,
AccessGate, CanisterId, ChannelId, ChatId, CommunityCanisterChannelSummary, CommunityCanisterCommunitySummary,
CommunityCanisterCommunitySummaryUpdates, CommunityId, CommunityRole, Empty, EventIndex, EventsResponse,
GroupReplyContext, GroupRole, MessageContentInitial, MessageId, MessageIndex, PollVotes, Reaction, Rules,
SlashCommandPermissions, TextContent, TimestampMillis, UserId, VoteOperation,
};

pub fn create_channel(
Expand Down Expand Up @@ -126,6 +127,20 @@ pub mod happy_path {
}
}

pub fn join_community(
env: &mut PocketIc,
sender: Principal,
community_id: CommunityId,
) -> CommunityCanisterCommunitySummary {
let local_user_index = local_user_index(env, community_id);
crate::client::local_user_index::happy_path::join_community(env, sender, local_user_index, community_id, None)
}

pub fn join_channel(env: &mut PocketIc, sender: Principal, community_id: CommunityId, channel_id: ChannelId) {
let local_user_index = local_user_index(env, community_id);
crate::client::local_user_index::happy_path::join_channel(env, sender, local_user_index, community_id, channel_id);
}

pub fn leave_channel(env: &mut PocketIc, sender: Principal, community_id: CommunityId, channel_id: ChannelId) {
let response = super::leave_channel(
env,
Expand Down Expand Up @@ -414,10 +429,10 @@ pub mod happy_path {
}
}

pub fn summary(env: &PocketIc, sender: &User, community_id: CommunityId) -> CommunityCanisterCommunitySummary {
pub fn summary(env: &PocketIc, sender: Principal, community_id: CommunityId) -> CommunityCanisterCommunitySummary {
let response = super::summary(
env,
sender.principal,
sender,
community_id.into(),
&community_canister::summary::Args {
on_behalf_of: None,
Expand All @@ -433,13 +448,13 @@ pub mod happy_path {

pub fn summary_updates(
env: &PocketIc,
sender: &User,
sender: Principal,
community_id: CommunityId,
updates_since: TimestampMillis,
) -> Option<CommunityCanisterCommunitySummaryUpdates> {
match super::summary_updates(
env,
sender.principal,
sender,
community_id.into(),
&community_canister::summary_updates::Args {
on_behalf_of: None,
Expand All @@ -455,12 +470,12 @@ pub mod happy_path {

pub fn selected_initial(
env: &PocketIc,
sender: &User,
sender: Principal,
community_id: CommunityId,
) -> community_canister::selected_initial::SuccessResult {
let response = super::selected_initial(
env,
sender.principal,
sender,
community_id.into(),
&community_canister::selected_initial::Args { invite_code: None },
);
Expand Down Expand Up @@ -742,4 +757,11 @@ pub mod happy_path {
response => panic!("'update_bot' error: {response:?}"),
}
}

pub fn local_user_index(env: &PocketIc, community_id: CommunityId) -> CanisterId {
let community_canister::local_user_index::Response::Success(local_user_index) =
super::local_user_index(env, Principal::anonymous(), community_id.into(), &Empty {});

local_user_index
}
}
37 changes: 23 additions & 14 deletions backend/integration_tests/src/client/group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ pub const CHAT_EVENTS_MEMORY_ID: MemoryId = MemoryId::new(3);
generate_msgpack_query_call!(events);
generate_msgpack_query_call!(events_by_index);
generate_msgpack_query_call!(events_window);
generate_msgpack_query_call!(local_user_index);
generate_msgpack_query_call!(public_summary);
generate_msgpack_query_call!(selected_initial);
generate_msgpack_query_call!(selected_updates_v2);
Expand Down Expand Up @@ -49,9 +50,10 @@ pub mod happy_path {
use pocket_ic::PocketIc;
use testing::rng::random_from_u128;
use types::{
ChatId, EventIndex, EventsResponse, GroupCanisterGroupChatSummary, GroupCanisterGroupChatSummaryUpdates,
GroupReplyContext, GroupRole, MessageContentInitial, MessageId, MessageIndex, Milliseconds, PollVotes, Reaction,
SlashCommandPermissions, TextContent, TimestampMillis, UserId, VideoCallType, VoteOperation,
CanisterId, ChatId, Empty, EventIndex, EventsResponse, GroupCanisterGroupChatSummary,
GroupCanisterGroupChatSummaryUpdates, GroupReplyContext, GroupRole, MessageContentInitial, MessageId, MessageIndex,
Milliseconds, PollVotes, Reaction, SlashCommandPermissions, TextContent, TimestampMillis, UserId, VideoCallType,
VoteOperation,
};

pub fn send_text_message(
Expand Down Expand Up @@ -159,6 +161,11 @@ pub mod happy_path {
}
}

pub fn join_group(env: &mut PocketIc, sender: Principal, group_chat_id: ChatId) {
let local_user_index = local_user_index(env, group_chat_id);
crate::client::local_user_index::happy_path::join_group(env, sender, local_user_index, group_chat_id);
}

pub fn update_group(
env: &mut PocketIc,
sender: Principal,
Expand Down Expand Up @@ -325,15 +332,10 @@ pub mod happy_path {

pub fn selected_initial(
env: &PocketIc,
sender: &User,
sender: Principal,
group_chat_id: ChatId,
) -> group_canister::selected_initial::SuccessResult {
let response = super::selected_initial(
env,
sender.principal,
group_chat_id.into(),
&group_canister::selected_initial::Args {},
);
let response = super::selected_initial(env, sender, group_chat_id.into(), &group_canister::selected_initial::Args {});

match response {
group_canister::selected_initial::Response::Success(result) => result,
Expand Down Expand Up @@ -361,10 +363,10 @@ pub mod happy_path {
}
}

pub fn summary(env: &PocketIc, sender: &User, group_chat_id: ChatId) -> GroupCanisterGroupChatSummary {
pub fn summary(env: &PocketIc, sender: Principal, group_chat_id: ChatId) -> GroupCanisterGroupChatSummary {
let response = super::summary(
env,
sender.principal,
sender,
group_chat_id.into(),
&group_canister::summary::Args { on_behalf_of: None },
);
Expand All @@ -377,13 +379,13 @@ pub mod happy_path {

pub fn summary_updates(
env: &PocketIc,
sender: &User,
sender: Principal,
group_chat_id: ChatId,
updates_since: TimestampMillis,
) -> Option<GroupCanisterGroupChatSummaryUpdates> {
let response = super::summary_updates(
env,
sender.principal,
sender,
group_chat_id.into(),
&group_canister::summary_updates::Args {
on_behalf_of: None,
Expand Down Expand Up @@ -604,4 +606,11 @@ pub mod happy_path {
response => panic!("'update_bot' error: {response:?}"),
}
}

pub fn local_user_index(env: &PocketIc, group_id: ChatId) -> CanisterId {
let group_canister::local_user_index::Response::Success(local_user_index) =
super::local_user_index(env, Principal::anonymous(), group_id.into(), &Empty {});

local_user_index
}
}
1 change: 1 addition & 0 deletions backend/integration_tests/src/client/local_user_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ pub mod happy_path {
principal,
user_id: res.user_id,
public_key,
local_user_index: canister_id,
},
response => panic!("'register_user' error: {response:?}"),
}
Expand Down
4 changes: 3 additions & 1 deletion backend/integration_tests/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,10 +190,12 @@ fn register_user_internal(
true,
);

let local_user_index = user_index::happy_path::user_registration_canister(env, canister_ids.user_index);

let user = local_user_index::happy_path::register_user_with_referrer(
env,
Principal::self_authenticating(&create_identity_result.user_key),
canister_ids.local_user_index,
local_user_index,
create_identity_result.user_key,
referral_code,
);
Expand Down
5 changes: 5 additions & 0 deletions backend/integration_tests/src/client/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ generate_msgpack_update_call!(set_token_enabled);

pub mod happy_path {
use super::*;
use crate::client::INIT_CYCLES_BALANCE;
use candid::Principal;
use pocket_ic::PocketIc;
use registry_canister::subnets::Subnet;
Expand All @@ -37,6 +38,10 @@ pub mod happy_path {
let subnets::Response::Success(subnets) = super::subnets(env, sender, registry_canister_id, &Empty {});

if let Some(subnet) = subnets.into_iter().find(|s| s.subnet_id == subnet_id) {
env.add_cycles(subnet.local_user_index, INIT_CYCLES_BALANCE);
env.add_cycles(subnet.local_group_index, INIT_CYCLES_BALANCE);
env.add_cycles(subnet.notifications_canister, INIT_CYCLES_BALANCE);

return subnet;
}
}
Expand Down
Loading
Loading