Skip to content

Commit

Permalink
merge
Browse files Browse the repository at this point in the history
  • Loading branch information
vporton committed Feb 14, 2025
2 parents 49a6353 + 6931d1e commit 181382e
Show file tree
Hide file tree
Showing 30 changed files with 279 additions and 168 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ candid = "0.10.11"
candid_parser = "0.1.4"
dfx-core = { path = "src/dfx-core", version = "0.1.0" }
ic-agent = { version = "0.39", git = "https://github.com/dfinity/agent-rs", rev = "9ebf6314ce2fcb36772c7d81d6d414b4628d6101" }
ic-asset = { path = "src/canisters/frontend/ic-asset", version = "0.21.0" }
ic-asset = { path = "src/canisters/frontend/ic-asset", version = "0.22.0" }
ic-cdk = "0.13.1"
ic-identity-hsm = { version = "0.39", git = "https://github.com/dfinity/agent-rs", rev = "9ebf6314ce2fcb36772c7d81d6d414b4628d6101" }
ic-utils = { version = "0.39", git = "https://github.com/dfinity/agent-rs", rev = "9ebf6314ce2fcb36772c7d81d6d414b4628d6101" }
Expand Down
10 changes: 5 additions & 5 deletions e2e/tests-dfx/assetscanister.bash
Original file line number Diff line number Diff line change
Expand Up @@ -726,24 +726,24 @@ check_permission_failure() {
}

@test "can serve filenames with special characters in filename" {
# This is observed, not expected behavior
# see https://dfinity.atlassian.net/browse/SDK-1247
install_asset assetscanister

dfx_start

echo "filename is an ae symbol" >'src/e2e_project_frontend/assets/æ'

dfx deploy
ID=$(dfx canister id e2e_project_frontend)
PORT=$(get_webserver_port)

dfx canister call --query e2e_project_frontend list '(record {})'

# decode as expected
# decode as expected - %c3%a6 is the utf-8 encoding of the ae symbol
assert_command dfx canister call --query e2e_project_frontend http_request '(record{url="/%c3%a6";headers=vec{};method="GET";body=vec{}})'
assert_match "filename is an ae symbol" # candid looks like blob "filename is \c3\a6\0a"

ID=$(dfx canister id e2e_project_frontend)
PORT=$(get_webserver_port)
assert_command curl --fail -vv http://localhost:"$PORT"/%c3%a6?canisterId="$ID"
assert_match "filename is an ae symbol"

# fails with because %e6 is not valid utf-8 percent encoding
assert_command_fail curl --fail -vv http://localhost:"$PORT"/%e6?canisterId="$ID"
Expand Down
4 changes: 2 additions & 2 deletions e2e/tests-dfx/deploy.bash
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,14 @@ teardown() {
(
cd src
assert_command dfx deploy
assert_match "Installing code for"
assert_match "Installed code for"
)

assert_command dfx canister call hello_backend greet '("Banzai")'
assert_eq '("Hello, Banzai!")'

assert_command dfx deploy
assert_not_match "Installing code for"
assert_not_match "Installed code for"
assert_match "is already installed"
}

Expand Down
4 changes: 2 additions & 2 deletions e2e/tests-dfx/install.bash
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ teardown() {

assert_command dfx canister install --all

assert_match "Installing code for canister e2e_project_backend"
assert_match "Installed code for canister e2e_project_backend"
}

@test "install succeeds with network name" {
Expand All @@ -52,7 +52,7 @@ teardown() {

assert_command dfx canister install --all --network local

assert_match "Installing code for canister e2e_project_backend"
assert_match "Installed code for canister e2e_project_backend"
}

@test "install fails with network name that is not in dfx.json" {
Expand Down
18 changes: 9 additions & 9 deletions e2e/tests-dfx/mode_reinstall.bash
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ teardown() {
assert_command dfx canister install --mode=reinstall hello_backend

assert_match "YOU WILL LOSE ALL DATA IN THE CANISTER"
assert_match "Reinstalling code for canister hello_backend"
assert_match "Reinstalled code for canister hello_backend"
)
}

Expand All @@ -54,7 +54,7 @@ teardown() {

assert_match "YOU WILL LOSE ALL DATA IN THE CANISTER"

assert_not_match "Installing code for canister"
assert_not_match "Installed code for canister"
assert_contains "Refusing to install canister without approval"
assert_contains "User declined consent"
)
Expand All @@ -77,7 +77,7 @@ teardown() {
assert_command dfx deploy --mode=reinstall hello_backend

assert_match "YOU WILL LOSE ALL DATA IN THE CANISTER"
assert_match "Reinstalling code for canister hello_backend"
assert_match "Reinstalled code for canister hello_backend"
)
}

Expand All @@ -90,7 +90,7 @@ teardown() {

assert_match "YOU WILL LOSE ALL DATA IN THE CANISTER"

assert_not_match "Installing code for canister"
assert_not_match "Installed code for canister"
assert_contains "Refusing to install canister without approval"
assert_contains "User declined consent"
)
Expand Down Expand Up @@ -123,7 +123,7 @@ teardown() {
assert_match "You are about to reinstall the hello_frontend canister."
assert_not_match "You are about to reinstall the hello_backend canister."
assert_match "YOU WILL LOSE ALL DATA IN THE CANISTER"
assert_match "Reinstalling code for canister hello_frontend,"
assert_match "Reinstalled code for canister hello_frontend,"
)

# the hello_backend canister should not have been upgraded (which would reset the non-stable var)
Expand All @@ -141,24 +141,24 @@ teardown() {
assert_command dfx deploy --mode=reinstall hello_backend

assert_match "YOU WILL LOSE ALL DATA IN THE CANISTER"
assert_match "Reinstalling code for canister hello_backend"
assert_match "Reinstalled code for canister hello_backend"
)
echo y | (
assert_command dfx deploy --mode=reinstall hello_backend

assert_match "YOU WILL LOSE ALL DATA IN THE CANISTER"
assert_match "Reinstalling code for canister hello_backend"
assert_match "Reinstalled code for canister hello_backend"
)
echo YES | (
assert_command dfx deploy --mode=reinstall hello_backend

assert_match "YOU WILL LOSE ALL DATA IN THE CANISTER"
assert_match "Reinstalling code for canister hello_backend"
assert_match "Reinstalled code for canister hello_backend"
)
echo YeS | (
assert_command dfx deploy --mode=reinstall hello_backend

assert_match "YOU WILL LOSE ALL DATA IN THE CANISTER"
assert_match "Reinstalling code for canister hello_backend"
assert_match "Reinstalled code for canister hello_backend"
)
}
6 changes: 3 additions & 3 deletions e2e/tests-replica/deploy.bash
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ teardown() {
assert_command dfx canister create --all

assert_command dfx deploy
assert_match 'Installing code for canister'
assert_match 'Installed code for canister'
}

@test "dfx deploy supports arguments" {
Expand All @@ -85,13 +85,13 @@ teardown() {
# Therefore, there is no "attempting (install|upgrade)" message.

assert_command dfx deploy hello_backend
assert_match 'Installing code for canister'
assert_match 'Installed code for canister'

assert_command dfx canister call hello_backend greet '("First")'
assert_eq '("Hello, First!")'

assert_command dfx deploy hello_backend --upgrade-unchanged
assert_match 'Upgrading code for canister'
assert_match 'Upgraded code for canister'

assert_command dfx canister call hello_backend greet '("Second")'
assert_eq '("Hello, Second!")'
Expand Down
2 changes: 1 addition & 1 deletion src/canisters/frontend/ic-asset/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ic-asset"
version = "0.21.0"
version = "0.22.0"
authors.workspace = true
edition.workspace = true
repository.workspace = true
Expand Down
9 changes: 7 additions & 2 deletions src/canisters/frontend/icx-asset/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "icx-asset"
version = "0.21.0"
version = "0.22.0"
authors.workspace = true
edition.workspace = true
repository.workspace = true
Expand All @@ -15,7 +15,12 @@ keywords = ["internet-computer", "agent", "icp", "dfinity", "asset"]
anstyle.workspace = true
anyhow.workspace = true
candid = { workspace = true }
clap = { workspace = true, features = ["derive", "cargo", "unstable-styles", "wrap_help" ] }
clap = { workspace = true, features = [
"derive",
"cargo",
"unstable-styles",
"wrap_help",
] }
delay = "0.3.1"
humantime.workspace = true
ic-agent = { workspace = true }
Expand Down
20 changes: 15 additions & 5 deletions src/dfx-core/src/canister/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use crate::{
cli::ask_for_consent,
error::canister::{CanisterBuilderError, CanisterInstallError},
error::{
canister::{CanisterBuilderError, CanisterInstallError},
cli::UserConsent,
},
identity::CallSender,
};
use candid::Principal;
Expand Down Expand Up @@ -28,14 +30,22 @@ pub async fn build_wallet_canister(
.map_err(CanisterBuilderError::WalletCanisterCaller)
}

pub fn install_mode_to_prompt(mode: &InstallMode) -> &'static str {
pub fn install_mode_to_present_tense(mode: &InstallMode) -> &'static str {
match mode {
InstallMode::Install => "Installing",
InstallMode::Reinstall => "Reinstalling",
InstallMode::Upgrade { .. } => "Upgrading",
}
}

pub fn install_mode_to_past_tense(mode: &InstallMode) -> &'static str {
match mode {
InstallMode::Install => "Installed",
InstallMode::Reinstall => "Reinstalled",
InstallMode::Upgrade { .. } => "Upgraded",
}
}

pub async fn install_canister_wasm(
agent: &Agent,
canister_id: Principal,
Expand All @@ -44,10 +54,10 @@ pub async fn install_canister_wasm(
mode: InstallMode,
call_sender: &CallSender,
wasm_module: Vec<u8>,
skip_consent: bool,
ask_for_consent: impl FnOnce(&str) -> Result<(), UserConsent>,
) -> Result<(), CanisterInstallError> {
let mgr = ManagementCanister::create(agent);
if !skip_consent && mode == InstallMode::Reinstall {
if mode == InstallMode::Reinstall {
let msg = if let Some(name) = canister_name {
format!("You are about to reinstall the {name} canister")
} else {
Expand Down
17 changes: 0 additions & 17 deletions src/dfx-core/src/cli/mod.rs

This file was deleted.

1 change: 0 additions & 1 deletion src/dfx-core/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
pub mod canister;
pub mod cli;
pub mod config;
pub mod error;
pub mod extension;
Expand Down
4 changes: 2 additions & 2 deletions src/dfx/src/actors/pocketic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ impl Actor for PocketIc {
}

fn stopping(&mut self, _ctx: &mut Self::Context) -> Running {
warn!(self.logger, "Stopping PocketIC...");
debug!(self.logger, "Stopping PocketIC...");
if let Some(sender) = self.stop_sender.take() {
let _ = sender.send(());
}
Expand All @@ -168,7 +168,7 @@ impl Actor for PocketIc {
let _ = join.join();
}

warn!(self.logger, "Stopped.");
debug!(self.logger, "Stopped.");
Running::Stop
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/dfx/src/commands/canister/delete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@ use crate::lib::operations::canister::{
use crate::lib::operations::cycles_ledger::wallet_deposit_to_cycles_ledger;
use crate::lib::root_key::fetch_root_key_if_needed;
use crate::util::assets::wallet_wasm;
use crate::util::blob_from_arguments;
use crate::util::clap::parsers::{cycle_amount_parser, icrc_subaccount_parser};
use crate::util::{ask_for_consent, blob_from_arguments};
use anyhow::{bail, Context};
use candid::Principal;
use clap::Parser;
use dfx_core::canister::build_wallet_canister;
use dfx_core::cli::ask_for_consent;
use dfx_core::identity::wallet::wallet_canister_id;
use dfx_core::identity::CallSender;
use fn_error_context::context;
Expand Down Expand Up @@ -177,9 +176,10 @@ async fn delete_canister(
// Determine how many cycles we can withdraw.
let status = canister::get_canister_status(env, canister_id, call_sender).await?;
if status.status != CanisterStatus::Stopped && !skip_confirmation {
ask_for_consent(&format!(
"Canister {canister} has not been stopped. Delete anyway?"
))?;
ask_for_consent(
env,
&format!("Canister {canister} has not been stopped. Delete anyway?"),
)?;
}
let agent = env.get_agent();
let mgr = ManagementCanister::create(agent);
Expand Down
34 changes: 26 additions & 8 deletions src/dfx/src/commands/canister/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ use crate::lib::environment::Environment;
use crate::lib::error::DfxResult;
use crate::lib::operations::canister::install_canister::install_canister;
use crate::lib::root_key::fetch_root_key_if_needed;
use crate::util::blob_from_arguments;
use crate::util::clap::argument_from_cli::ArgumentFromCliLongOpt;
use crate::util::clap::install_mode::{InstallModeHint, InstallModeOpt};
use dfx_core::canister::{install_canister_wasm, install_mode_to_prompt};
use crate::util::{ask_for_consent, blob_from_arguments};
use dfx_core::canister::{
install_canister_wasm, install_mode_to_past_tense, install_mode_to_present_tense,
};
use dfx_core::identity::CallSender;

use crate::lib::operations::canister::skip_remote_canister;
Expand Down Expand Up @@ -103,12 +105,15 @@ pub async fn exec(
)?;
let wasm_module = dfx_core::fs::read(wasm_path)?;
let mode = mode_hint.to_install_mode_with_wasm_path()?;
info!(
env.get_logger(),
"{} code for canister {}",
install_mode_to_prompt(&mode),
canister_id,
let spinner = env.new_spinner(
format!(
"{} code for canister {}",
install_mode_to_present_tense(&mode),
canister_id,
)
.into(),
);

install_canister_wasm(
env.get_agent(),
canister_id,
Expand All @@ -117,9 +122,22 @@ pub async fn exec(
mode,
call_sender,
wasm_module,
opts.yes,
|message| {
if opts.yes {
Ok(())
} else {
ask_for_consent(env, message)
}
},
)
.await?;
spinner.finish_and_clear();
info!(
env.get_logger(),
"{} code for canister {}",
install_mode_to_past_tense(&mode),
canister_id
);
Ok(())
} else {
bail!("When installing a canister by its ID, you must specify `--wasm` option.")
Expand Down
Loading

0 comments on commit 181382e

Please sign in to comment.