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

chore(ci): bump PocketIC to v7.0.0 (library) and v8.0.0 (server) #518

Merged
merged 3 commits into from
Feb 28, 2025
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
238 changes: 137 additions & 101 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ itertools = "0.13.0"
lazy_static = "1.4.0"
mockall = "0.12.1"
num-bigint = "0.4"
pocket-ic = "6.0.0"
pocket-ic = "7.0.0"
proc-macro2 = "1.0"
prometheus = "0.13.3"
quote = "1.0"
Expand Down
2 changes: 1 addition & 1 deletion scripts/benchmark-canister.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ print_message "Benchmarking canister at $CANISTER_PATH"
# Install canbench if not already installed
if ! cargo install --list | grep -q canbench; then
print_message "Installing canbench..."
cargo install canbench --version 0.1.8
cargo install canbench --version 0.1.8 --locked
fi

# Changes to the canister path
Expand Down
2 changes: 1 addition & 1 deletion scripts/run-integration-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ fi

cd tests/integration
echo "PocketIC download starting"
curl -sLO https://github.com/dfinity/pocketic/releases/download/7.0.0/pocket-ic-x86_64-$PLATFORM.gz || exit 1
curl -sLO https://github.com/dfinity/pocketic/releases/download/8.0.0/pocket-ic-x86_64-$PLATFORM.gz || exit 1
gzip -df pocket-ic-x86_64-$PLATFORM.gz
mv pocket-ic-x86_64-$PLATFORM pocket-ic
export POCKET_IC_BIN="$(pwd)/pocket-ic"
Expand Down
13 changes: 5 additions & 8 deletions tests/integration/src/control_panel_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use control_panel_api::{ListUserStationsResponse, UploadCanisterModulesInput};
use orbit_essentials::api::ApiResult;
use orbit_essentials::cmc::{SubnetFilter, SubnetSelection};
use pocket_ic::management_canister::CanisterInstallMode;
use pocket_ic::{update_candid_as, CallError, PocketIc};
use pocket_ic::{update_candid_as, PocketIc};
use sha2::{Digest, Sha256};
use station_api::{
AdminInitInput, HealthStatus, SystemInfoResponse, SystemInit as SystemInitArg,
Expand Down Expand Up @@ -847,13 +847,10 @@ fn deploy_station_with_insufficient_cycles() {
station_init_args.clone(),
)
.unwrap_err();
match err {
CallError::Reject(msg) => panic!("Unexpected reject: {}", msg),
CallError::UserError(err) => assert!(err.description.contains(&format!(
"insufficient for transferring {} cycles when deploying the upgrader",
upgrader_initial_cycles
))),
};
assert!(err.reject_message.contains(&format!(
"insufficient for transferring {} cycles when deploying the upgrader",
upgrader_initial_cycles
)));
let cycles_after_failed_install = env.cycle_balance(station);
assert!(cycles_before_install <= cycles_after_failed_install + 50_000_000_000);

Expand Down
15 changes: 6 additions & 9 deletions tests/integration/src/cycles_monitor_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use control_panel_api::{
use ic_ledger_types::AccountIdentifier;
use orbit_essentials::api::ApiResult;

use pocket_ic::{update_candid_as, CallError};
use pocket_ic::update_candid_as;
use sha2::{Digest, Sha256};
use station_api::{HealthStatus, SystemInfoResponse};
use std::time::Duration;
Expand Down Expand Up @@ -148,19 +148,16 @@ fn successful_monitors_stations_and_tops_up() {
assert_eq!(health_status, HealthStatus::Healthy);

// WALLET_ADMIN_USER is not admin of the newly created station and thus the following call should trap
let res: Result<(ApiResult<SystemInfoResponse>,), CallError> = update_candid_as(
let user_error = update_candid_as::<_, (ApiResult<SystemInfoResponse>,)>(
&env,
newly_created_user_station,
WALLET_ADMIN_USER,
"system_info",
(),
);
let user_error = match res.unwrap_err() {
CallError::UserError(user_error) => user_error,
CallError::Reject(message) => panic!("Unexpected reject: {}", message),
};
assert!(user_error.description.contains(
"Canister called `ic0.trap` with message: Unauthorized access to resources: System(SystemInfo)"
)
.unwrap_err();
assert!(user_error.reject_message.contains(
"Canister called `ic0.trap` with message: 'Unauthorized access to resources: System(SystemInfo)'."
));

let upgrader_id = get_system_info(&env, user_id, newly_created_user_station).upgrader_id;
Expand Down
10 changes: 5 additions & 5 deletions tests/integration/src/external_canister_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,7 @@ fn call_external_canister_test() {
call_canister_operation.clone(),
);
assert!(trap_message.contains(
"Canister called `ic0.trap` with message: Unauthorized access to resources: ExternalCanister(Call"
"Canister called `ic0.trap` with message: 'Unauthorized access to resources: ExternalCanister(Call(CallExternalCanister("
));

// nothing should have changed so far
Expand Down Expand Up @@ -801,7 +801,7 @@ fn call_external_canister_test() {
illegal_call_canister_operation.clone(),
);
assert!(trap_message.contains(
"Canister called `ic0.trap` with message: Unauthorized access to resources: ExternalCanister(Call"
"Canister called `ic0.trap` with message: 'Unauthorized access to resources: ExternalCanister(Call(CallExternalCanister("
));

bump_time_to_avoid_ratelimit(&env);
Expand All @@ -821,7 +821,7 @@ fn call_external_canister_test() {
illegal_call_canister_operation.clone(),
);
assert!(trap_message.contains(
"Canister called `ic0.trap` with message: Unauthorized access to resources: ExternalCanister(Call"
"Canister called `ic0.trap` with message: 'Unauthorized access to resources: ExternalCanister(Call(CallExternalCanister("
));

// submit a request labeling the validation method as the execution method which is illegal given the permissions set so far
Expand All @@ -839,7 +839,7 @@ fn call_external_canister_test() {
illegal_call_canister_operation.clone(),
);
assert!(trap_message.contains(
"Canister called `ic0.trap` with message: Unauthorized access to resources: ExternalCanister(Call"
"Canister called `ic0.trap` with message: 'Unauthorized access to resources: ExternalCanister(Call(CallExternalCanister("
));

// nothing should have changed
Expand Down Expand Up @@ -1115,7 +1115,7 @@ fn create_external_canister_with_too_many_cycles() {
)
.unwrap_err();
assert!(err
.description
.reject_message
.contains("The method `try_execute_request` can only be called by the station canister."));

// wait for the requests to be executed
Expand Down
16 changes: 7 additions & 9 deletions tests/integration/src/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::setup::setup_new_env;
use crate::TestEnv;
use candid::{Decode, Encode, Principal};
use orbit_essentials::api::{HttpRequest, HttpResponse};
use pocket_ic::{PocketIc, WasmResult};
use pocket_ic::PocketIc;

fn test_candid_decoding_quota(env: &PocketIc, canister_id: Principal) {
// The anonymous end-user sends a small HTTP request. This should succeed.
Expand All @@ -13,18 +13,15 @@ fn test_candid_decoding_quota(env: &PocketIc, canister_id: Principal) {
body: vec![42; 1_000],
};
let http_request_bytes = Encode!(&http_request).unwrap();
let response = match env
let bytes = env
.update_call(
canister_id,
Principal::anonymous(),
"http_request",
http_request_bytes,
)
.unwrap()
{
WasmResult::Reply(bytes) => Decode!(&bytes, HttpResponse).unwrap(),
WasmResult::Reject(reason) => panic!("Unexpected reject: {}", reason),
};
.unwrap();
let response = Decode!(&bytes, HttpResponse).unwrap();
assert_eq!(response.status_code, 200);

// The anonymous end-user sends a large HTTP request. This should be rejected.
Expand All @@ -39,8 +36,9 @@ fn test_candid_decoding_quota(env: &PocketIc, canister_id: Principal) {
large_http_request_bytes,
)
.unwrap_err();
println!("desc: {}", err.description);
assert!(err.description.contains("Decoding cost exceeds the limit"));
assert!(err
.reject_message
.contains("Decoding cost exceeds the limit"));
}

#[test]
Expand Down
33 changes: 12 additions & 21 deletions tests/integration/src/notification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::utils::{
};
use crate::TestEnv;
use orbit_essentials::api::ApiResult;
use pocket_ic::{update_candid_as, CallError};
use pocket_ic::update_candid_as;
use station_api::{
AddUserOperationInput, EditPermissionOperationInput, ListNotificationsInput,
ListNotificationsResponse, MarkNotificationsReadInput, MeResponse, RequestApprovalStatusDTO,
Expand Down Expand Up @@ -82,12 +82,9 @@ fn notification_authorization() {
(list_notifications_input.clone(),),
)
.unwrap_err();
match err {
CallError::UserError(err) => assert!(err
.description
.contains("Unauthorized access to resources: Notification(List)")),
CallError::Reject(msg) => panic!("Unexpected reject: {}", msg),
};
assert!(err
.reject_message
.contains("Unauthorized access to resources: Notification(List)"));
// and cannot mark foreign notifications read
let err = update_candid_as::<_, (ApiResult<()>,)>(
&env,
Expand All @@ -97,13 +94,10 @@ fn notification_authorization() {
(mark_notifications_read_input.clone(),),
)
.unwrap_err();
match err {
CallError::UserError(err) => assert!(err.description.contains(&format!(
"Unauthorized access to resources: Notification(Update(Id({})))",
admin_notification.id
))),
CallError::Reject(msg) => panic!("Unexpected reject: {}", msg),
};
assert!(err.reject_message.contains(&format!(
"Unauthorized access to resources: Notification(Update(Id({})))",
admin_notification.id
)));

// register new non-admin user
let add_user = AddUserOperationInput {
Expand Down Expand Up @@ -203,11 +197,8 @@ fn notification_authorization() {
(mark_notifications_read_input.clone(),),
)
.unwrap_err();
match err {
CallError::UserError(err) => assert!(err.description.contains(&format!(
"Unauthorized access to resources: Notification(Update(Id({})))",
admin_notification.id
))),
CallError::Reject(msg) => panic!("Unexpected reject: {}", msg),
};
assert!(err.reject_message.contains(&format!(
"Unauthorized access to resources: Notification(Update(Id({})))",
admin_notification.id
)));
}
6 changes: 3 additions & 3 deletions tests/integration/src/station_test_data/asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use super::next_unique_id;
use crate::utils::{submit_request, wait_for_request};
use candid::Principal;
use orbit_essentials::api::ApiResult;
use pocket_ic::{query_candid_as, CallError, PocketIc};
use pocket_ic::{query_candid_as, PocketIc, RejectResponse};
use station_api::{GetAssetInput, GetAssetResponse, ListAssetsInput, ListAssetsResponse};

pub fn add_asset_with_input(
Expand Down Expand Up @@ -97,7 +97,7 @@ pub fn list_assets(
env: &PocketIc,
station_canister_id: Principal,
requester: Principal,
) -> Result<(ApiResult<ListAssetsResponse>,), CallError> {
) -> Result<(ApiResult<ListAssetsResponse>,), RejectResponse> {
query_candid_as::<(ListAssetsInput,), (ApiResult<ListAssetsResponse>,)>(
env,
station_canister_id,
Expand All @@ -112,7 +112,7 @@ pub fn get_asset(
station_canister_id: Principal,
requester: Principal,
asset_id: station_api::UuidDTO,
) -> Result<(ApiResult<GetAssetResponse>,), CallError> {
) -> Result<(ApiResult<GetAssetResponse>,), RejectResponse> {
query_candid_as::<(GetAssetInput,), (ApiResult<GetAssetResponse>,)>(
env,
station_canister_id,
Expand Down
6 changes: 3 additions & 3 deletions tests/integration/src/station_test_data/named_rule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use super::next_unique_id;
use crate::utils::{submit_request, wait_for_request};
use candid::Principal;
use orbit_essentials::api::ApiResult;
use pocket_ic::{query_candid_as, CallError, PocketIc};
use pocket_ic::{query_candid_as, PocketIc, RejectResponse};
use station_api::{
GetNamedRuleInput, GetNamedRuleResponse, ListNamedRulesInput, ListNamedRulesResponse,
RequestPolicyRuleDTO,
Expand Down Expand Up @@ -109,7 +109,7 @@ pub fn list_named_rules(
env: &PocketIc,
station_canister_id: Principal,
requester: Principal,
) -> Result<(ApiResult<ListNamedRulesResponse>,), CallError> {
) -> Result<(ApiResult<ListNamedRulesResponse>,), RejectResponse> {
query_candid_as::<(ListNamedRulesInput,), (ApiResult<ListNamedRulesResponse>,)>(
env,
station_canister_id,
Expand All @@ -125,7 +125,7 @@ pub fn get_named_rule(
station_canister_id: Principal,
requester: Principal,
named_rule_id: station_api::UuidDTO,
) -> Result<(ApiResult<GetNamedRuleResponse>,), CallError> {
) -> Result<(ApiResult<GetNamedRuleResponse>,), RejectResponse> {
query_candid_as::<(GetNamedRuleInput,), (ApiResult<GetNamedRuleResponse>,)>(
env,
station_canister_id,
Expand Down
6 changes: 3 additions & 3 deletions tests/integration/src/station_test_data/request_policy.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::utils::{submit_request, wait_for_request};
use candid::Principal;
use orbit_essentials::api::ApiResult;
use pocket_ic::{query_candid_as, CallError, PocketIc};
use pocket_ic::{query_candid_as, PocketIc, RejectResponse};
use station_api::{
EditRequestPolicyOperationInput, ListRequestPoliciesInput, ListRequestPoliciesResponse,
};
Expand Down Expand Up @@ -32,7 +32,7 @@ pub fn list_request_policies(
env: &PocketIc,
station_canister_id: Principal,
requester: Principal,
) -> Result<(ApiResult<ListRequestPoliciesResponse>,), CallError> {
) -> Result<(ApiResult<ListRequestPoliciesResponse>,), RejectResponse> {
query_candid_as::<(ListRequestPoliciesInput,), (ApiResult<ListRequestPoliciesResponse>,)>(
env,
station_canister_id,
Expand All @@ -50,7 +50,7 @@ pub fn edit_request_policy(
station_canister_id: Principal,
requester: Principal,
input: EditRequestPolicyOperationInput,
) -> Result<(), CallError> {
) -> Result<(), RejectResponse> {
let edit_request_policy_request = submit_request(
env,
requester,
Expand Down
28 changes: 8 additions & 20 deletions tests/integration/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use orbit_essentials::api::ApiResult;
use orbit_essentials::cdk::api::management_canister::main::CanisterId;
use orbit_essentials::types::WasmModuleExtraChunks;
use pocket_ic::management_canister::CanisterStatusResult;
use pocket_ic::{query_candid_as, update_candid_as, CallError, PocketIc, UserError, WasmResult};
use pocket_ic::{query_candid_as, update_candid_as, PocketIc, RejectResponse};
use sha2::Digest;
use sha2::Sha256;
use station_api::{
Expand Down Expand Up @@ -180,7 +180,7 @@ pub fn submit_request_raw(
user_id: Principal,
station_canister_id: CanisterId,
request_operation_input: RequestOperationInput,
) -> Result<(Result<CreateRequestResponse, ApiErrorDTO>,), CallError> {
) -> Result<(Result<CreateRequestResponse, ApiErrorDTO>,), RejectResponse> {
let create_request_input = CreateRequestInput {
operation: request_operation_input,
title: None,
Expand Down Expand Up @@ -213,11 +213,9 @@ pub fn submit_request_with_expected_trap(
station_canister_id: CanisterId,
request_operation_input: RequestOperationInput,
) -> String {
let res = submit_request_raw(env, user_id, station_canister_id, request_operation_input);
match res.unwrap_err() {
CallError::UserError(error) => error.description,
CallError::Reject(message) => panic!("Unexpected reject: {}", message),
}
submit_request_raw(env, user_id, station_canister_id, request_operation_input)
.unwrap_err()
.reject_message
}

pub fn wait_for_request(
Expand Down Expand Up @@ -458,12 +456,8 @@ pub fn update_raw(
sender: Principal,
method: &str,
payload: Vec<u8>,
) -> Result<Vec<u8>, UserError> {
) -> Result<Vec<u8>, RejectResponse> {
env.update_call(canister_id, sender, method, payload)
.map(|res| match res {
WasmResult::Reply(bytes) => bytes,
WasmResult::Reject(message) => panic!("Unexpected reject: {}", message),
})
}

pub fn get_upgrader_disaster_recovery(
Expand Down Expand Up @@ -1133,17 +1127,11 @@ pub(crate) fn deploy_test_canister(env: &PocketIc, controller: Principal) -> Pri
test_canister
}

pub fn expect_await_call_result<T>(result: WasmResult) -> T
pub fn expect_await_call_result<T>(result: Vec<u8>) -> T
where
T: for<'a> ArgumentDecoder<'a>,
{
match result {
WasmResult::Reply(vec) => {
let result: T = decode_args(&vec).expect("Failed to decode result");
result
}
WasmResult::Reject(error) => panic!("Unexpected reject: {error}"),
}
decode_args(&result).expect("Failed to decode result")
}

pub(crate) fn set_disaster_recovery_committee(
Expand Down
Loading