Skip to content

Commit 8307f69

Browse files
fix: commands with --all parameter skip remote canisters (#4016)
1 parent e05c888 commit 8307f69

File tree

15 files changed

+113
-21
lines changed

15 files changed

+113
-21
lines changed

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,18 @@ You can use the `--replica` flag already to write scripts that anticipate that c
2525
An extension can define one or more project templates for `dfx new` to use.
2626
These can be new templates or replace the built-in project templates.
2727

28+
### fix: all commands with --all parameter skip remote canisters
29+
30+
This affects the following commands:
31+
- `dfx canister delete`
32+
- `dfx canister deposit-cycles`
33+
- `dfx canister start`
34+
- `dfx canister status`
35+
- `dfx canister stop`
36+
- `dfx canister uninstall-code`
37+
- `dfx canister update-settings`
38+
- `dfx ledger fabricate-cycles`
39+
2840
# 0.24.3
2941

3042
### feat: Bitcoin support in PocketIC

e2e/tests-dfx/cycles-ledger.bash

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,13 @@ current_time_nanoseconds() {
458458
assert_eq "2399699700000 cycles."
459459
assert_command dfx canister status e2e_project_backend
460460
assert_contains "Balance: 3_100_002_100_000 Cycles"
461+
462+
# deposit-cycles --all skips remote canisters
463+
jq '.canisters.remote.remote.id.local="rdmx6-jaaaa-aaaaa-aaadq-cai"' dfx.json | sponge dfx.json
464+
assert_command dfx canister deposit-cycles 10000 --all --identity bob
465+
assert_contains "Skipping canister 'remote' because it is remote for network 'local'"
466+
assert_contains "Depositing 10000 cycles onto e2e_project_backend"
467+
assert_not_contains "Depositing 10000 cycles onto remote"
461468
}
462469

463470
@test "top-up deduplication" {

e2e/tests-dfx/remote.bash

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ teardown() {
137137
assert_match "Canister 'remote' is a remote canister on network 'actuallylocal', and cannot be installed from here."
138138
}
139139

140-
@test "canister create --all, canister install --all skip remote canisters" {
140+
@test "all commands with --all skip remote canisters" {
141141
install_asset remote/actual
142142
dfx_start
143143
setup_actuallylocal_shared_network
@@ -201,6 +201,32 @@ teardown() {
201201
assert_command jq .remote canister_ids.json
202202
assert_eq "null"
203203

204+
assert_command dfx ledger fabricate-cycles --all --t 100 --network actuallylocal
205+
assert_contains "Skipping canister 'remote' because it is remote for network 'actuallylocal'"
206+
207+
assert_command dfx canister status --all --network actuallylocal
208+
assert_contains "Skipping canister 'remote' because it is remote for network 'actuallylocal'"
209+
210+
assert_command dfx canister update-settings --log-visibility public --all --network actuallylocal
211+
assert_contains "Skipping canister 'remote' because it is remote for network 'actuallylocal'"
212+
213+
assert_command dfx canister stop --all --network actuallylocal
214+
assert_contains "Skipping canister 'remote' because it is remote for network 'actuallylocal'"
215+
216+
assert_command dfx canister start --all --network actuallylocal
217+
assert_contains "Skipping canister 'remote' because it is remote for network 'actuallylocal'"
218+
219+
# have to stop to uninstall
220+
assert_command dfx canister stop --all --network actuallylocal
221+
222+
assert_command dfx canister uninstall-code --all --network actuallylocal
223+
assert_contains "Skipping canister 'remote' because it is remote for network 'actuallylocal'"
224+
225+
assert_command dfx build --all --network actuallylocal
226+
227+
assert_command dfx canister delete --all --network actuallylocal
228+
assert_contains "Skipping canister 'remote' because it is remote for network 'actuallylocal'"
229+
204230
# Assert frontend declarations are actually created
205231
dfx generate
206232
assert_file_exists "src/declarations/remote/remote.did"

src/dfx/src/commands/canister/create.rs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use crate::lib::ic_attributes::{
66
get_compute_allocation, get_freezing_threshold, get_log_visibility, get_memory_allocation,
77
get_reserved_cycles_limit, get_wasm_memory_limit, CanisterSettings,
88
};
9-
use crate::lib::operations::canister::create_canister;
9+
use crate::lib::operations::canister::{create_canister, skip_remote_canister};
1010
use crate::lib::root_key::fetch_root_key_if_needed;
1111
use crate::util::clap::parsers::{
1212
compute_allocation_parser, freezing_threshold_parser, log_visibility_parser,
@@ -245,15 +245,7 @@ pub async fn exec(
245245
if pull_canisters_in_config.contains_key(canister_name) {
246246
continue;
247247
}
248-
let canister_is_remote =
249-
config_interface.is_remote_canister(canister_name, &network.name)?;
250-
if canister_is_remote {
251-
info!(
252-
env.get_logger(),
253-
"Skipping canister '{canister_name}' because it is remote for network '{}'",
254-
&network.name,
255-
);
256-
248+
if skip_remote_canister(env, canister_name)? {
257249
continue;
258250
}
259251
let specified_id = config_interface.get_specified_id(canister_name)?;

src/dfx/src/commands/canister/delete.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use crate::lib::error::DfxResult;
33
use crate::lib::ic_attributes::CanisterSettings;
44
use crate::lib::operations::canister;
55
use crate::lib::operations::canister::{
6-
deposit_cycles, start_canister, stop_canister, update_settings,
6+
deposit_cycles, skip_remote_canister, start_canister, stop_canister, update_settings,
77
};
88
use crate::lib::operations::cycles_ledger::wallet_deposit_to_cycles_ledger;
99
use crate::lib::root_key::fetch_root_key_if_needed;
@@ -352,6 +352,9 @@ pub async fn exec(
352352
} else if opts.all {
353353
if let Some(canisters) = &config.get_config().canisters {
354354
for canister in canisters.keys() {
355+
if skip_remote_canister(env, canister)? {
356+
continue;
357+
}
355358
delete_canister(
356359
env,
357360
canister,

src/dfx/src/commands/canister/deposit_cycles.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use std::time::{SystemTime, UNIX_EPOCH};
33
use crate::lib::error::DfxResult;
44
use crate::lib::identity::wallet::get_or_create_wallet_canister;
55
use crate::lib::operations::canister;
6+
use crate::lib::operations::canister::skip_remote_canister;
67
use crate::lib::root_key::fetch_root_key_if_needed;
78
use crate::lib::{environment::Environment, operations::cycles_ledger};
89
use crate::util::clap::parsers::{cycle_amount_parser, icrc_subaccount_parser};
@@ -147,6 +148,10 @@ pub async fn exec(
147148

148149
if let Some(canisters) = &config.get_config().canisters {
149150
for canister in canisters.keys() {
151+
if skip_remote_canister(env, canister)? {
152+
continue;
153+
}
154+
150155
deposit_cycles(
151156
env,
152157
canister,

src/dfx/src/commands/canister/install.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use crate::util::clap::install_mode::{InstallModeHint, InstallModeOpt};
1010
use dfx_core::canister::{install_canister_wasm, install_mode_to_prompt};
1111
use dfx_core::identity::CallSender;
1212

13+
use crate::lib::operations::canister::skip_remote_canister;
1314
use anyhow::bail;
1415
use candid::Principal;
1516
use clap::Parser;
@@ -187,21 +188,14 @@ pub async fn exec(
187188
} else if opts.all {
188189
// Install all canisters.
189190
let config = env.get_config_or_anyhow()?;
190-
let config_interface = config.get_config();
191191
let env_file = config.get_output_env_file(opts.output_env_file)?;
192192
let pull_canisters_in_config = get_pull_canisters_in_config(env)?;
193193
if let Some(canisters) = &config.get_config().canisters {
194194
for canister in canisters.keys() {
195195
if pull_canisters_in_config.contains_key(canister) {
196196
continue;
197197
}
198-
if config_interface.is_remote_canister(canister, &network.name)? {
199-
info!(
200-
env.get_logger(),
201-
"Skipping canister '{}' because it is remote for network '{}'",
202-
canister,
203-
&network.name,
204-
);
198+
if skip_remote_canister(env, canister)? {
205199
continue;
206200
}
207201

src/dfx/src/commands/canister/start.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use crate::lib::environment::Environment;
22
use crate::lib::error::DfxResult;
33
use crate::lib::operations::canister;
4+
use crate::lib::operations::canister::skip_remote_canister;
45
use crate::lib::root_key::fetch_root_key_if_needed;
56
use candid::Principal;
67
use clap::Parser;
@@ -51,8 +52,13 @@ pub async fn exec(
5152
start_canister(env, canister, call_sender).await
5253
} else if opts.all {
5354
let config = env.get_config_or_anyhow()?;
55+
5456
if let Some(canisters) = &config.get_config().canisters {
5557
for canister in canisters.keys() {
58+
if skip_remote_canister(env, canister)? {
59+
continue;
60+
}
61+
5662
start_canister(env, canister, call_sender).await?;
5763
}
5864
}

src/dfx/src/commands/canister/status.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use crate::lib::environment::Environment;
22
use crate::lib::error::DfxResult;
33
use crate::lib::operations::canister;
4+
use crate::lib::operations::canister::skip_remote_canister;
45
use crate::lib::root_key::fetch_root_key_if_needed;
56
use candid::Principal;
67
use clap::Parser;
@@ -95,8 +96,13 @@ pub async fn exec(
9596
canister_status(env, canister, call_sender).await
9697
} else if opts.all {
9798
let config = env.get_config_or_anyhow()?;
99+
98100
if let Some(canisters) = &config.get_config().canisters {
99101
for canister in canisters.keys() {
102+
if skip_remote_canister(env, canister)? {
103+
continue;
104+
}
105+
100106
canister_status(env, canister, call_sender).await?;
101107
}
102108
}

src/dfx/src/commands/canister/stop.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use crate::lib::environment::Environment;
22
use crate::lib::error::DfxResult;
33
use crate::lib::operations::canister;
4+
use crate::lib::operations::canister::skip_remote_canister;
45
use crate::lib::root_key::fetch_root_key_if_needed;
56
use candid::Principal;
67
use clap::Parser;
@@ -52,8 +53,13 @@ pub async fn exec(
5253
stop_canister(env, canister, call_sender).await
5354
} else if opts.all {
5455
let config = env.get_config_or_anyhow()?;
56+
5557
if let Some(canisters) = &config.get_config().canisters {
5658
for canister in canisters.keys() {
59+
if skip_remote_canister(env, canister)? {
60+
continue;
61+
}
62+
5763
stop_canister(env, canister, call_sender).await?;
5864
}
5965
}

0 commit comments

Comments
 (0)