Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 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
4 changes: 4 additions & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ Calls made to retrieve the help output for `canister update-settings` was missin
`WARN` and `ERROR` messages are now clearly labelled as such, and the labels are colored accordingly.
This is now included when running `dfx canister update-settings -h`.

=== fix: canister call uses candid file if canister type cannot be determined

The candid file specified in the field `canisters.<canister name>.candid` of dfx.json, or if that not exists `canisters.<canister name>.remote.candid`, is now used when running `dfx canister call`, even when dfx fails to determine the canister type.

=== fix: btc/canister http adapter socket not found by replica after restart

After running `dfx start --enable-bitcoin` twice in a row (stopping dfx in between), the second
Expand Down
11 changes: 8 additions & 3 deletions e2e/assets/remote/call/mock/dfx.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,15 @@
"canisters": {
"basic": {
"main": "basic.mo",
"dependencies": [ "remote" ]
"dependencies": [
"remote"
]
},
"remote": {
"main": "remote.mo"
"main": "remote.mo",
"remote": {
"candid": "remote.did"
}
}
},
"defaults": {
Expand All @@ -19,4 +24,4 @@
"bind": "127.0.0.1:8000"
}
}
}
}
10 changes: 6 additions & 4 deletions e2e/tests-dfx/remote.bash
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ teardown() {
}

@test "canister call and sign" {
skip
install_asset remote/call/actual
dfx_start
setup_actuallylocal_network
Expand All @@ -36,8 +35,6 @@ teardown() {
setup_local_network
# shellcheck disable=SC2094
cat <<<"$(jq .canisters.remote.remote.id.actuallylocal=\""$REMOTE_CANISTER_ID"\" dfx.json)" >dfx.json
# shellcheck disable=SC2094
cat <<<"$(jq '.canisters.remote.remote.candid="remote.did"' dfx.json)" >dfx.json

# set up: remote method is update, local is query
# call remote method as update to make a change
Expand Down Expand Up @@ -68,6 +65,12 @@ teardown() {
assert_command dfx canister --network actuallylocal call --update remote make_struct '("A update by name", "B update by name")'
assert_eq '(record { a = "A update by name"; b = "B update by name" })'

# This also should work when no canister type can be determined / if no info but the bare minimum of remote id and remote candid is given:
# shellcheck disable=SC2094
cat <<<"$(jq 'del(.canisters.remote.main)' dfx.json)" >dfx.json
assert_command dfx canister --network actuallylocal call --query remote make_struct '("A query by name", "B query by name")'
assert_eq '(record { a = "A query by name"; b = "B query by name" })'

# We can't check this for sign, because dfx canister send outputs something like this:
# To see the content of response, copy-paste the encoded string into cbor.me.
# Response: d9d9f7a2667374617475736[snip]2696e636970616c
Expand All @@ -93,7 +96,6 @@ teardown() {
}

@test "canister create <canister> fails for a remote canister" {
skip
install_asset remote/actual
dfx_start
setup_actuallylocal_network
Expand Down
4 changes: 2 additions & 2 deletions src/dfx/src/commands/remote/generate_binding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ pub fn exec(env: &dyn Environment, opts: GenerateBindingOpts) -> DfxResult {
info!(
log,
"Candid file {} for canister {} does not exist. Skipping.",
candid,
candid.to_string_lossy(),
canister.get_name()
);
continue;
Expand Down Expand Up @@ -104,7 +104,7 @@ pub fn exec(env: &dyn Environment, opts: GenerateBindingOpts) -> DfxResult {
log,
"Generated {} using {} for canister {}.",
main,
candid,
candid.to_string_lossy(),
canister.get_name()
)
}
Expand Down
2 changes: 1 addition & 1 deletion src/dfx/src/config/dfinity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const EMPTY_CONFIG_DEFAULTS_REPLICA: ConfigDefaultsReplica = ConfigDefaultsRepli

#[derive(Clone, Debug, Default, Serialize, Deserialize)]
pub struct ConfigCanistersCanisterRemote {
pub candid: Option<String>,
pub candid: Option<PathBuf>,

// network -> canister ID
pub id: BTreeMap<String, Principal>,
Expand Down
18 changes: 10 additions & 8 deletions src/dfx/src/lib/canister_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use crate::lib::provider::get_network_context;
use crate::util;

use anyhow::{anyhow, bail, Context};
use core::panic;
use fn_error_context::context;
use ic_types::principal::Principal as CanisterId;
use ic_types::Principal;
Expand Down Expand Up @@ -38,7 +39,7 @@ pub struct CanisterInfo {

declarations_config: CanisterDeclarationsConfig,
remote_id: Option<Principal>, // id on the currently selected network
remote_candid: Option<String>, // always exists if the field is configured
remote_candid: Option<PathBuf>, // always exists if the field is configured

workspace_root: PathBuf,
build_root: PathBuf,
Expand Down Expand Up @@ -115,18 +116,14 @@ impl CanisterInfo {
let canister_info = CanisterInfo {
name: name.to_string(),
canister_type,

declarations_config,
remote_id,
remote_candid,

workspace_root: workspace_root.to_path_buf(),
build_root,
output_root,
canister_root,

canister_id,

packtool: build_defaults.get_packtool(),
args: build_defaults.get_args(),
extras,
Expand All @@ -153,13 +150,16 @@ impl CanisterInfo {
pub fn get_declarations_config(&self) -> &CanisterDeclarationsConfig {
&self.declarations_config
}
pub fn is_remote(&self) -> bool {
self.remote_id.is_some()
}
pub fn get_remote_id(&self) -> Option<Principal> {
self.remote_id
}
pub fn get_remote_candid(&self) -> Option<String> {
pub fn get_remote_candid(&self) -> Option<PathBuf> {
self.remote_candid.as_ref().cloned()
}
pub fn get_remote_candid_if_remote(&self) -> Option<String> {
pub fn get_remote_candid_if_remote(&self) -> Option<PathBuf> {
if self.remote_id.is_some() {
self.get_remote_candid()
} else {
Expand Down Expand Up @@ -282,7 +282,9 @@ impl CanisterInfo {
} else if let Ok(info) = self.as_info::<RustCanisterInfo>() {
Some(info.get_output_idl_path().to_path_buf())
} else {
None
self.get_extra_optional("candid")
.unwrap_or(None)
.or_else(|| self.remote_candid.clone())
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/dfx/src/lib/canister_info/custom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ impl CanisterInfoFactory for CustomCanisterInfo {
let workspace_root = info.get_workspace_root();
let output_wasm_path = workspace_root.join(info.get_extra::<PathBuf>("wasm")?);
let candid = if let Some(remote_candid) = info.get_remote_candid_if_remote() {
PathBuf::from(remote_candid)
remote_candid
} else {
info.get_extra::<PathBuf>("candid")?
};
Expand Down
2 changes: 1 addition & 1 deletion src/dfx/src/lib/canister_info/rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ impl CanisterInfoFactory for RustCanisterInfo {
let output_wasm_path =
target_directory.join(format!("wasm32-unknown-unknown/release/{package}.wasm"));
let candid = if let Some(remote_candid) = info.get_remote_candid_if_remote() {
PathBuf::from(remote_candid)
remote_candid
} else {
info.get_extra::<PathBuf>("candid")?
};
Expand Down