diff --git a/CHANGELOG.md b/CHANGELOG.md index 90fef9a00b..beeea67a3d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,6 +27,10 @@ It is possible to override this in `.ic-assets.json` like this: } ``` +### fix: Transferring funds too early in `dfx ledger create-canister` with --next-to + +When creating a canister with `dfx ledger create-canister --next-to` on a canister that does not exist (e.g., 2vxsx-fae), then the funds are first transferred away from the users account, but the call then fails to create the new canister, and the funds are not returned to the user's account. + ## Dependencies ### Updated to [agent-rs 0.35.0](https://github.com/dfinity/agent-rs/blob/main/CHANGELOG.md#0350---2024-05-10) diff --git a/e2e/tests-dfx/ledger.bash b/e2e/tests-dfx/ledger.bash index d118c18e28..7a685b0e4b 100644 --- a/e2e/tests-dfx/ledger.bash +++ b/e2e/tests-dfx/ledger.bash @@ -210,6 +210,13 @@ tc_to_num() { assert_match "Refunded at block height" assert_match "with message: Subnet $SUBNET_ID does not exist" + # Verify that registry is queried before sending any ICP to CMC + CANISTER_ID="2vxsx-fae" # anonymous principal + balance=$(dfx ledger balance) + assert_command_fail dfx ledger create-canister --amount=100 --next-to "$CANISTER_ID" "$(dfx identity get-principal)" + # TODO: assert error message once registry is fixed + assert_eq "$balance" "$(dfx ledger balance)" + # Transaction Deduplication t=$(current_time_nanoseconds) diff --git a/src/dfx/src/commands/ledger/create_canister.rs b/src/dfx/src/commands/ledger/create_canister.rs index a64814e05c..6836c47aaa 100644 --- a/src/dfx/src/commands/ledger/create_canister.rs +++ b/src/dfx/src/commands/ledger/create_canister.rs @@ -73,6 +73,11 @@ pub async fn exec(env: &dyn Environment, opts: CreateCanisterOpts) -> DfxResult fetch_root_key_if_needed(env).await?; + let subnet_selection = opts + .subnet_selection + .into_subnet_selection_type(env) + .await?; + let height = transfer_cmc( agent, env.get_logger(), @@ -86,10 +91,6 @@ pub async fn exec(env: &dyn Environment, opts: CreateCanisterOpts) -> DfxResult .await?; println!("Using transfer at block height {height}"); - let subnet_selection = opts - .subnet_selection - .into_subnet_selection_type(env) - .await?; let result = notify_create(agent, controller, height, subnet_selection).await; match result {