Skip to content

Commit fb3c639

Browse files
authored
fix: Ledger create canister with --next-to transferring funds too early (#3760)
1 parent dae62bd commit fb3c639

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ It is possible to override this in `.ic-assets.json` like this:
2727
}
2828
```
2929

30+
### fix: Transferring funds too early in `dfx ledger create-canister` with --next-to
31+
32+
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.
33+
3034
## Dependencies
3135

3236
### Updated to [agent-rs 0.35.0](https://github.com/dfinity/agent-rs/blob/main/CHANGELOG.md#0350---2024-05-10)

e2e/tests-dfx/ledger.bash

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,13 @@ tc_to_num() {
210210
assert_match "Refunded at block height"
211211
assert_match "with message: Subnet $SUBNET_ID does not exist"
212212

213+
# Verify that registry is queried before sending any ICP to CMC
214+
CANISTER_ID="2vxsx-fae" # anonymous principal
215+
balance=$(dfx ledger balance)
216+
assert_command_fail dfx ledger create-canister --amount=100 --next-to "$CANISTER_ID" "$(dfx identity get-principal)"
217+
# TODO: assert error message once registry is fixed
218+
assert_eq "$balance" "$(dfx ledger balance)"
219+
213220
# Transaction Deduplication
214221
t=$(current_time_nanoseconds)
215222

src/dfx/src/commands/ledger/create_canister.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,11 @@ pub async fn exec(env: &dyn Environment, opts: CreateCanisterOpts) -> DfxResult
7373

7474
fetch_root_key_if_needed(env).await?;
7575

76+
let subnet_selection = opts
77+
.subnet_selection
78+
.into_subnet_selection_type(env)
79+
.await?;
80+
7681
let height = transfer_cmc(
7782
agent,
7883
env.get_logger(),
@@ -86,10 +91,6 @@ pub async fn exec(env: &dyn Environment, opts: CreateCanisterOpts) -> DfxResult
8691
.await?;
8792
println!("Using transfer at block height {height}");
8893

89-
let subnet_selection = opts
90-
.subnet_selection
91-
.into_subnet_selection_type(env)
92-
.await?;
9394
let result = notify_create(agent, controller, height, subnet_selection).await;
9495

9596
match result {

0 commit comments

Comments
 (0)