Skip to content

Commit

Permalink
fix: Ledger create canister with --next-to transferring funds too e…
Browse files Browse the repository at this point in the history
…arly (#3760)
  • Loading branch information
fxgst authored May 21, 2024
1 parent dae62bd commit fb3c639
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 7 additions & 0 deletions e2e/tests-dfx/ledger.bash
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
9 changes: 5 additions & 4 deletions src/dfx/src/commands/ledger/create_canister.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -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 {
Expand Down

0 comments on commit fb3c639

Please sign in to comment.