Skip to content

Commit

Permalink
update for new pocketic api
Browse files Browse the repository at this point in the history
  • Loading branch information
adamspofford-dfinity committed Jan 28, 2025
1 parent c560887 commit be760cc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 26 deletions.
17 changes: 4 additions & 13 deletions src/dfx/src/commands/canister/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ use ic_utils::interfaces::management_canister::MgmtMethod;
use ic_utils::interfaces::wallet::{CallForwarder, CallResult};
use ic_utils::interfaces::WalletCanister;
use pocket_ic::common::rest::RawEffectivePrincipal;
use pocket_ic::WasmResult;
use slog::warn;
use std::option::Option;
use std::path::PathBuf;
Expand Down Expand Up @@ -356,7 +355,7 @@ To figure out the id of your wallet, run 'dfx identity get-wallet (--network ic)
CallSender::Impersonate(sender) => {
let pocketic = env.get_pocketic();
if let Some(pocketic) = pocketic {
let res = pocketic
pocketic
.query_call_with_effective_principal(
canister_id,
RawEffectivePrincipal::CanisterId(
Expand All @@ -367,11 +366,7 @@ To figure out the id of your wallet, run 'dfx identity get-wallet (--network ic)
arg_value,
)
.await
.map_err(|err| anyhow!("Failed to perform query call: {}", err))?;
match res {
WasmResult::Reply(data) => data,
WasmResult::Reject(err) => bail!("Canister rejected: {}", err),
}
.map_err(|err| anyhow!("Failed to perform query call: {}", err))?
} else {
bail!("Impersonating sender is only supported for a local PocketIC instance.")
}
Expand Down Expand Up @@ -466,14 +461,10 @@ To figure out the id of your wallet, run 'dfx identity get-wallet (--network ic)
)
.await
.map_err(|err| anyhow!("Failed to submit canister call: {}", err))?;
let res = pocketic
pocketic
.await_call_no_ticks(msg_id)
.await
.map_err(|err| anyhow!("Canister call failed: {}", err))?;
match res {
WasmResult::Reply(data) => data,
WasmResult::Reject(err) => bail!("Canister rejected: {}", err),
}
.map_err(|err| anyhow!("Canister call failed: {}", err))?
} else {
bail!("Impersonating sender is only supported for a local PocketIC instance.")
}
Expand Down
19 changes: 6 additions & 13 deletions src/dfx/src/lib/operations/canister/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ use ic_utils::interfaces::management_canister::{
use ic_utils::interfaces::ManagementCanister;
use ic_utils::Argument;
use pocket_ic::common::rest::RawEffectivePrincipal;
use pocket_ic::WasmResult;
use std::collections::HashSet;
use std::path::PathBuf;

Expand Down Expand Up @@ -77,15 +76,12 @@ where
)
.await
.map_err(|err| anyhow!("Failed to submit management canister call: {}", err))?;
let res = pocketic
let data = pocketic
.await_call_no_ticks(msg_id)
.await
.map_err(|err| anyhow!("Management canister call failed: {}", err))?;
match res {
WasmResult::Reply(data) => decode_args(&data)
.context("Could not decode management canister response.")?,
WasmResult::Reject(err) => bail!("Management canister rejected: {}", err),
}

decode_args(&data).context("Could not decode management canister response.")?
} else {
bail!("Impersonating sender is only supported for a local PocketIC instance.")
}
Expand Down Expand Up @@ -140,7 +136,7 @@ where
CallSender::Impersonate(sender) => {
let pocketic = env.get_pocketic();
if let Some(pocketic) = pocketic {
let res = pocketic
let data = pocketic
.query_call_with_effective_principal(
Principal::management_canister(),
RawEffectivePrincipal::CanisterId(destination_canister.as_slice().to_vec()),
Expand All @@ -152,11 +148,8 @@ where
.map_err(|err| {
anyhow!("Failed to perform management canister query call: {}", err)
})?;
match res {
WasmResult::Reply(data) => decode_args(&data)
.context("Failed to decode management canister query call response.")?,
WasmResult::Reject(err) => bail!("Management canister rejected: {}", err),
}
decode_args(&data)
.context("Failed to decode management canister query call response.")?
} else {
bail!("Impersonating sender is only supported for a local PocketIC instance.")
}
Expand Down

0 comments on commit be760cc

Please sign in to comment.