From b9b5c3608717416b3c0e963e53e927a8bb1e04a4 Mon Sep 17 00:00:00 2001 From: Adam Spofford <93943719+adamspofford-dfinity@users.noreply.github.com> Date: Thu, 21 Dec 2023 13:51:12 -0800 Subject: [PATCH 1/3] chore: Add the 0.15.3 header to the changelog (#3486) Includes everything up to #3485. --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4636033002..2ec80cf5d7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ # UNRELEASED +# 0.15.3 + ### fix: allow `http://localhost:*` as `connect-src` in the asset canister's CSP This will enable browsing the asset canister at `http://.localhost:` in most browsers. From 4346ed71594df5d37aac3b662964275ea5a3d1f3 Mon Sep 17 00:00:00 2001 From: Marcin Nowak-Liebiediew Date: Fri, 22 Dec 2023 13:42:21 +0100 Subject: [PATCH 2/3] feat!: update `dfx cycles` commands with maninet `cycles-ledger` canister ID (#3481) --- CHANGELOG.md | 4 + docs/cli-reference/dfx-cycles.md | 3 - e2e/tests-dfx/cycles-ledger.bash | 173 ++++++++++---------- src/dfx/src/commands/cycles/balance.rs | 9 +- src/dfx/src/commands/cycles/top_up.rs | 7 - src/dfx/src/commands/cycles/transfer.rs | 7 - src/dfx/src/lib/operations/cycles_ledger.rs | 19 ++- 7 files changed, 104 insertions(+), 118 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2ec80cf5d7..f5b196998f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ # UNRELEASED +### feat!: update `dfx cycles` commands with mainnet `cycles-ledger` canister ID + +The `dfx cycles` command no longer needs nor accepts the `--cycles-ledger-canister-id ` parameter. + # 0.15.3 ### fix: allow `http://localhost:*` as `connect-src` in the asset canister's CSP diff --git a/docs/cli-reference/dfx-cycles.md b/docs/cli-reference/dfx-cycles.md index 936abdc986..718d388d9c 100644 --- a/docs/cli-reference/dfx-cycles.md +++ b/docs/cli-reference/dfx-cycles.md @@ -41,12 +41,9 @@ You can specify the following arguments for the `dfx cycles balance` command. | `--owner ` | Display the balance of this principal | | `--subaccount ` | Display the balance of this subaccount | | `--precise` | Displays the exact balance, without scaling to trillions of cycles. | -| `--cycles-ledger-canister-id ` | Specify the ID of the cycles ledger canister. | ### Examples -> **NOTE**: None of the examples below specify the `--cycles-ledger-canister-id` option, but it is required until the cycles ledger canister ID is known. - Check the cycles balance of the selected identity. ``` diff --git a/e2e/tests-dfx/cycles-ledger.bash b/e2e/tests-dfx/cycles-ledger.bash index a878e8cc60..7345d85da7 100644 --- a/e2e/tests-dfx/cycles-ledger.bash +++ b/e2e/tests-dfx/cycles-ledger.bash @@ -29,6 +29,11 @@ add_cycles_ledger_canisters_to_project() { jq -s '.[0] * .[1]' ../dfx.json dfx.json | sponge dfx.json } +deploy_cycles_ledger() { + assert_command dfx deploy cycles-ledger --specified-id "um5iw-rqaaa-aaaaq-qaaba-cai" + assert_command dfx deploy cycles-depositor --argument "(record {ledger_id = principal \"$(dfx canister id cycles-ledger)\"})" --with-cycles 10000000000000 --specified-id "ul4oc-4iaaa-aaaaq-qaabq-cai" +} + current_time_nanoseconds() { echo "$(date +%s)"000000000 } @@ -41,19 +46,18 @@ current_time_nanoseconds() { ALICE_SUBACCT2_CANDID="\9C\9B\9A\03\04\05\06\07\08\09\0a\0b\0c\0d\0e\0f\10\11\12\13\14\15\16\17\18\19\1a\1b\1c\1d\1e\1f" BOB=$(dfx identity get-principal --identity bob) - assert_command dfx deploy cycles-ledger - assert_command dfx deploy cycles-depositor --argument "(record {ledger_id = principal \"$(dfx canister id cycles-ledger)\"})" --with-cycles 10000000000000 + deploy_cycles_ledger - assert_command dfx cycles balance --cycles-ledger-canister-id "$(dfx canister id cycles-ledger)" --identity alice --precise + assert_command dfx cycles balance --identity alice --precise assert_eq "0 cycles." - assert_command dfx cycles balance --cycles-ledger-canister-id "$(dfx canister id cycles-ledger)" --identity alice + assert_command dfx cycles balance --identity alice assert_eq "0.000 TC (trillion cycles)." - assert_command dfx cycles balance --cycles-ledger-canister-id "$(dfx canister id cycles-ledger)" --identity bob --precise + assert_command dfx cycles balance --identity bob --precise assert_eq "0 cycles." - assert_command dfx cycles balance --cycles-ledger-canister-id "$(dfx canister id cycles-ledger)" --identity bob + assert_command dfx cycles balance --identity bob assert_eq "0.000 TC (trillion cycles)." @@ -70,40 +74,40 @@ current_time_nanoseconds() { assert_eq "(record { balance = 2_900_000_000_000 : nat; txid = 3 : nat })" - assert_command dfx cycles balance --cycles-ledger-canister-id "$(dfx canister id cycles-ledger)" --precise --identity alice + assert_command dfx cycles balance --precise --identity alice assert_eq "1700400200150 cycles." - assert_command dfx cycles balance --cycles-ledger-canister-id "$(dfx canister id cycles-ledger)" --precise --identity alice --subaccount "$ALICE_SUBACCT1" + assert_command dfx cycles balance --precise --identity alice --subaccount "$ALICE_SUBACCT1" assert_eq "3750000000000 cycles." - assert_command dfx cycles balance --cycles-ledger-canister-id "$(dfx canister id cycles-ledger)" --precise --identity alice --subaccount "$ALICE_SUBACCT2" + assert_command dfx cycles balance --precise --identity alice --subaccount "$ALICE_SUBACCT2" assert_eq "760500000000 cycles." - assert_command dfx cycles balance --cycles-ledger-canister-id "$(dfx canister id cycles-ledger)" --precise --identity bob + assert_command dfx cycles balance --precise --identity bob assert_eq "2900000000000 cycles." - assert_command dfx cycles balance --cycles-ledger-canister-id "$(dfx canister id cycles-ledger)" --identity alice + assert_command dfx cycles balance --identity alice assert_eq "1.700 TC (trillion cycles)." - assert_command dfx cycles balance --cycles-ledger-canister-id "$(dfx canister id cycles-ledger)" --identity alice --subaccount "$ALICE_SUBACCT1" + assert_command dfx cycles balance --identity alice --subaccount "$ALICE_SUBACCT1" assert_eq "3.750 TC (trillion cycles)." - assert_command dfx cycles balance --cycles-ledger-canister-id "$(dfx canister id cycles-ledger)" --identity alice --subaccount "$ALICE_SUBACCT2" + assert_command dfx cycles balance --identity alice --subaccount "$ALICE_SUBACCT2" assert_eq "0.760 TC (trillion cycles)." - assert_command dfx cycles balance --cycles-ledger-canister-id "$(dfx canister id cycles-ledger)" --identity bob + assert_command dfx cycles balance --identity bob assert_eq "2.900 TC (trillion cycles)." # can see cycles balance of other accounts - assert_command dfx cycles balance --owner "$ALICE" --cycles-ledger-canister-id "$(dfx canister id cycles-ledger)" --identity bob + assert_command dfx cycles balance --owner "$ALICE" --identity bob assert_eq "1.700 TC (trillion cycles)." - assert_command dfx cycles balance --owner "$ALICE" --subaccount "$ALICE_SUBACCT1" --cycles-ledger-canister-id "$(dfx canister id cycles-ledger)" --identity bob + assert_command dfx cycles balance --owner "$ALICE" --subaccount "$ALICE_SUBACCT1" --identity bob assert_eq "3.750 TC (trillion cycles)." - assert_command dfx cycles balance --owner "$BOB" --cycles-ledger-canister-id "$(dfx canister id cycles-ledger)" --identity anonymous + assert_command dfx cycles balance --owner "$BOB" --identity anonymous assert_eq "2.900 TC (trillion cycles)." } @@ -116,73 +120,72 @@ current_time_nanoseconds() { BOB=$(dfx identity get-principal --identity bob) BOB_SUBACCT1="7C7B7A030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f" - assert_command dfx deploy cycles-ledger - assert_command dfx deploy cycles-depositor --argument "(record {ledger_id = principal \"$(dfx canister id cycles-ledger)\"})" --with-cycles 10000000000000 + deploy_cycles_ledger assert_command dfx canister call cycles-depositor deposit "(record {to = record{owner = principal \"$ALICE\";};cycles = 3_000_000_000_000;})" --identity cycle-giver assert_command dfx canister call cycles-depositor deposit "(record {to = record{owner = principal \"$ALICE\"; subaccount = opt blob \"$ALICE_SUBACCT1_CANDID\"};cycles = 2_000_000_000_000;})" --identity cycle-giver assert_command dfx canister call cycles-depositor deposit "(record {to = record{owner = principal \"$ALICE\"; subaccount = opt blob \"$ALICE_SUBACCT2_CANDID\"};cycles = 1_000_000_000_000;})" --identity cycle-giver # account to account - assert_command dfx cycles balance --cycles-ledger-canister-id "$(dfx canister id cycles-ledger)" --precise --identity alice + assert_command dfx cycles balance --precise --identity alice assert_eq "3000000000000 cycles." - assert_command dfx cycles balance --cycles-ledger-canister-id "$(dfx canister id cycles-ledger)" --precise --identity bob + assert_command dfx cycles balance --precise --identity bob assert_eq "0 cycles." - assert_command dfx cycles transfer "$BOB" 100000 --cycles-ledger-canister-id "$(dfx canister id cycles-ledger)" --identity alice + assert_command dfx cycles transfer "$BOB" 100000 --identity alice assert_eq "Transfer sent at block index 3" - assert_command dfx cycles balance --cycles-ledger-canister-id "$(dfx canister id cycles-ledger)" --precise --identity alice + assert_command dfx cycles balance --precise --identity alice assert_eq "2999899900000 cycles." - assert_command dfx cycles balance --cycles-ledger-canister-id "$(dfx canister id cycles-ledger)" --precise --identity bob + assert_command dfx cycles balance --precise --identity bob assert_eq "100000 cycles." # account to subaccount - assert_command dfx cycles balance --cycles-ledger-canister-id "$(dfx canister id cycles-ledger)" --precise --identity alice + assert_command dfx cycles balance --precise --identity alice assert_eq "2999899900000 cycles." - assert_command dfx cycles balance --cycles-ledger-canister-id "$(dfx canister id cycles-ledger)" --precise --identity bob --subaccount "$BOB_SUBACCT1" + assert_command dfx cycles balance --precise --identity bob --subaccount "$BOB_SUBACCT1" assert_eq "0 cycles." - assert_command dfx cycles transfer "$BOB" 100000 --cycles-ledger-canister-id "$(dfx canister id cycles-ledger)" --identity alice --to-subaccount "$BOB_SUBACCT1" + assert_command dfx cycles transfer "$BOB" 100000 --identity alice --to-subaccount "$BOB_SUBACCT1" assert_eq "Transfer sent at block index 4" - assert_command dfx cycles balance --cycles-ledger-canister-id "$(dfx canister id cycles-ledger)" --precise --identity alice + assert_command dfx cycles balance --precise --identity alice assert_eq "2999799800000 cycles." - assert_command dfx cycles balance --cycles-ledger-canister-id "$(dfx canister id cycles-ledger)" --precise --identity bob --subaccount "$BOB_SUBACCT1" + assert_command dfx cycles balance --precise --identity bob --subaccount "$BOB_SUBACCT1" assert_eq "100000 cycles." # subaccount to account - assert_command dfx cycles balance --cycles-ledger-canister-id "$(dfx canister id cycles-ledger)" --precise --identity alice --subaccount "$ALICE_SUBACCT2" + assert_command dfx cycles balance --precise --identity alice --subaccount "$ALICE_SUBACCT2" assert_eq "1000000000000 cycles." - assert_command dfx cycles balance --cycles-ledger-canister-id "$(dfx canister id cycles-ledger)" --precise --identity bob + assert_command dfx cycles balance --precise --identity bob assert_eq "100000 cycles." - assert_command dfx cycles transfer "$BOB" 700000 --cycles-ledger-canister-id "$(dfx canister id cycles-ledger)" --identity alice --from-subaccount "$ALICE_SUBACCT2" + assert_command dfx cycles transfer "$BOB" 700000 --identity alice --from-subaccount "$ALICE_SUBACCT2" assert_eq "Transfer sent at block index 5" - assert_command dfx cycles balance --cycles-ledger-canister-id "$(dfx canister id cycles-ledger)" --precise --identity alice --subaccount "$ALICE_SUBACCT2" + assert_command dfx cycles balance --precise --identity alice --subaccount "$ALICE_SUBACCT2" assert_eq "999899300000 cycles." - assert_command dfx cycles balance --cycles-ledger-canister-id "$(dfx canister id cycles-ledger)" --precise --identity bob + assert_command dfx cycles balance --precise --identity bob assert_eq "800000 cycles." # subaccount to subaccount - assert_command dfx cycles balance --cycles-ledger-canister-id "$(dfx canister id cycles-ledger)" --precise --identity alice --subaccount "$ALICE_SUBACCT2" + assert_command dfx cycles balance --precise --identity alice --subaccount "$ALICE_SUBACCT2" assert_eq "999899300000 cycles." - assert_command dfx cycles balance --cycles-ledger-canister-id "$(dfx canister id cycles-ledger)" --precise --identity bob --subaccount "$BOB_SUBACCT1" + assert_command dfx cycles balance --precise --identity bob --subaccount "$BOB_SUBACCT1" assert_eq "100000 cycles." - assert_command dfx cycles transfer "$BOB" 400000 --cycles-ledger-canister-id "$(dfx canister id cycles-ledger)" --identity alice --to-subaccount "$BOB_SUBACCT1" --from-subaccount "$ALICE_SUBACCT2" + assert_command dfx cycles transfer "$BOB" 400000 --identity alice --to-subaccount "$BOB_SUBACCT1" --from-subaccount "$ALICE_SUBACCT2" assert_eq "Transfer sent at block index 6" - assert_command dfx cycles balance --cycles-ledger-canister-id "$(dfx canister id cycles-ledger)" --precise --identity alice --subaccount "$ALICE_SUBACCT2" + assert_command dfx cycles balance --precise --identity alice --subaccount "$ALICE_SUBACCT2" assert_eq "999798900000 cycles." - assert_command dfx cycles balance --cycles-ledger-canister-id "$(dfx canister id cycles-ledger)" --precise --identity bob --subaccount "$BOB_SUBACCT1" + assert_command dfx cycles balance --precise --identity bob --subaccount "$BOB_SUBACCT1" assert_eq "500000 cycles." } @@ -190,68 +193,67 @@ current_time_nanoseconds() { ALICE=$(dfx identity get-principal --identity alice) BOB=$(dfx identity get-principal --identity bob) - assert_command dfx deploy cycles-ledger - assert_command dfx deploy cycles-depositor --argument "(record {ledger_id = principal \"$(dfx canister id cycles-ledger)\"})" --with-cycles 10000000000000 + deploy_cycles_ledger assert_command dfx canister call cycles-depositor deposit "(record {to = record{owner = principal \"$ALICE\";};cycles = 3_000_000_000_000;})" --identity cycle-giver - assert_command dfx cycles balance --precise --identity alice --cycles-ledger-canister-id "$(dfx canister id cycles-ledger)" + assert_command dfx cycles balance --precise --identity alice assert_eq "3000000000000 cycles." - assert_command dfx cycles balance --precise --identity bob --cycles-ledger-canister-id "$(dfx canister id cycles-ledger)" + assert_command dfx cycles balance --precise --identity bob assert_eq "0 cycles." t=$(current_time_nanoseconds) - assert_command dfx cycles transfer "$BOB" 100000 --created-at-time "$t" --memo 1 --identity alice --cycles-ledger-canister-id "$(dfx canister id cycles-ledger)" + assert_command dfx cycles transfer "$BOB" 100000 --created-at-time "$t" --memo 1 --identity alice assert_eq "Transfer sent at block index 1" - assert_command dfx cycles balance --precise --identity alice --cycles-ledger-canister-id "$(dfx canister id cycles-ledger)" + assert_command dfx cycles balance --precise --identity alice assert_eq "2999899900000 cycles." - assert_command dfx cycles balance --precise --identity bob --cycles-ledger-canister-id "$(dfx canister id cycles-ledger)" + assert_command dfx cycles balance --precise --identity bob assert_eq "100000 cycles." # same memo and created-at-time: dupe - assert_command dfx cycles transfer "$BOB" 100000 --created-at-time "$t" --memo 1 --identity alice --cycles-ledger-canister-id "$(dfx canister id cycles-ledger)" + assert_command dfx cycles transfer "$BOB" 100000 --created-at-time "$t" --memo 1 --identity alice # shellcheck disable=SC2154 assert_contains "transaction is a duplicate of another transaction in block 1" "$stderr" # shellcheck disable=SC2154 assert_eq "Transfer sent at block index 1" "$stdout" - assert_command dfx cycles balance --precise --identity alice --cycles-ledger-canister-id "$(dfx canister id cycles-ledger)" + assert_command dfx cycles balance --precise --identity alice assert_eq "2999899900000 cycles." - assert_command dfx cycles balance --precise --identity bob --cycles-ledger-canister-id "$(dfx canister id cycles-ledger)" + assert_command dfx cycles balance --precise --identity bob assert_eq "100000 cycles." # different memo and same created-at-time same: not dupe - assert_command dfx cycles transfer "$BOB" 100000 --created-at-time "$t" --memo 2 --identity alice --cycles-ledger-canister-id "$(dfx canister id cycles-ledger)" + assert_command dfx cycles transfer "$BOB" 100000 --created-at-time "$t" --memo 2 --identity alice assert_contains "Transfer sent at block index 2" - assert_command dfx cycles balance --precise --identity alice --cycles-ledger-canister-id "$(dfx canister id cycles-ledger)" + assert_command dfx cycles balance --precise --identity alice assert_eq "2999799800000 cycles." - assert_command dfx cycles balance --precise --identity bob --cycles-ledger-canister-id "$(dfx canister id cycles-ledger)" + assert_command dfx cycles balance --precise --identity bob assert_eq "200000 cycles." # same memo and different created-at-time same: not dupe - assert_command dfx cycles transfer "$BOB" 100000 --created-at-time $((t+1)) --memo 1 --identity alice --cycles-ledger-canister-id "$(dfx canister id cycles-ledger)" + assert_command dfx cycles transfer "$BOB" 100000 --created-at-time $((t+1)) --memo 1 --identity alice assert_contains "Transfer sent at block index 3" - assert_command dfx cycles balance --precise --identity alice --cycles-ledger-canister-id "$(dfx canister id cycles-ledger)" + assert_command dfx cycles balance --precise --identity alice assert_eq "2999699700000 cycles." - assert_command dfx cycles balance --precise --identity bob --cycles-ledger-canister-id "$(dfx canister id cycles-ledger)" + assert_command dfx cycles balance --precise --identity bob assert_eq "300000 cycles." } @test "top up canister principal check" { BOB=$(dfx identity get-principal --identity bob) - assert_command dfx deploy cycles-ledger + deploy_cycles_ledger - assert_command_fail dfx cycles top-up "$BOB" 600000 --identity alice --cycles-ledger-canister-id "$(dfx canister id cycles-ledger)" + assert_command_fail dfx cycles top-up "$BOB" 600000 --identity alice assert_contains "Invalid receiver: $BOB. Make sure the receiver is a canister." } @@ -266,8 +268,7 @@ current_time_nanoseconds() { BOB_SUBACCT2="6C6B6A030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f" BOB_SUBACCT2_CANDID="\6C\6B\6A\03\04\05\06\07\08\09\0a\0b\0c\0d\0e\0f\10\11\12\13\14\15\16\17\18\19\1a\1b\1c\1d\1e\1f" - assert_command dfx deploy cycles-ledger - assert_command dfx deploy cycles-depositor --argument "(record {ledger_id = principal \"$(dfx canister id cycles-ledger)\"})" --with-cycles 10000000000000 + deploy_cycles_ledger assert_command dfx deploy @@ -276,40 +277,40 @@ current_time_nanoseconds() { assert_command dfx canister call cycles-depositor deposit "(record {to = record{owner = principal \"$BOB\"; subaccount = opt blob \"$BOB_SUBACCT2_CANDID\"};cycles = 2_700_000_000_000;})" --identity cycle-giver # account to canister - assert_command dfx cycles balance --cycles-ledger-canister-id "$(dfx canister id cycles-ledger)" --precise --identity bob + assert_command dfx cycles balance --precise --identity bob assert_eq "2400000000000 cycles." assert_command dfx canister status e2e_project_backend assert_contains "Balance: 3_100_000_000_000 Cycles" - assert_command dfx cycles top-up e2e_project_backend 100000 --cycles-ledger-canister-id "$(dfx canister id cycles-ledger)" --identity bob + assert_command dfx cycles top-up e2e_project_backend 100000 --identity bob - assert_command dfx cycles balance --cycles-ledger-canister-id "$(dfx canister id cycles-ledger)" --precise --identity bob + assert_command dfx cycles balance --precise --identity bob assert_eq "2399899900000 cycles." assert_command dfx canister status e2e_project_backend assert_contains "Balance: 3_100_000_100_000 Cycles" # subaccount to canister - assert_command dfx cycles balance --cycles-ledger-canister-id "$(dfx canister id cycles-ledger)" --precise --identity bob --subaccount "$BOB_SUBACCT1" + assert_command dfx cycles balance --precise --identity bob --subaccount "$BOB_SUBACCT1" assert_eq "2600000000000 cycles." assert_command dfx canister status e2e_project_backend assert_contains "Balance: 3_100_000_100_000 Cycles" - assert_command dfx cycles top-up e2e_project_backend 300000 --cycles-ledger-canister-id "$(dfx canister id cycles-ledger)" --identity bob --from-subaccount "$BOB_SUBACCT1" + assert_command dfx cycles top-up e2e_project_backend 300000 --identity bob --from-subaccount "$BOB_SUBACCT1" - assert_command dfx cycles balance --cycles-ledger-canister-id "$(dfx canister id cycles-ledger)" --precise --identity bob --subaccount "$BOB_SUBACCT1" + assert_command dfx cycles balance --precise --identity bob --subaccount "$BOB_SUBACCT1" assert_eq "2599899700000 cycles." assert_command dfx canister status e2e_project_backend assert_contains "Balance: 3_100_000_400_000 Cycles" # subaccount to canister - by canister id - assert_command dfx cycles balance --cycles-ledger-canister-id "$(dfx canister id cycles-ledger)" --precise --identity bob --subaccount "$BOB_SUBACCT2" + assert_command dfx cycles balance --precise --identity bob --subaccount "$BOB_SUBACCT2" assert_eq "2700000000000 cycles." assert_command dfx canister status e2e_project_backend assert_contains "Balance: 3_100_000_400_000 Cycles" - assert_command dfx cycles top-up "$(dfx canister id e2e_project_backend)" 600000 --cycles-ledger-canister-id "$(dfx canister id cycles-ledger)" --identity bob --from-subaccount "$BOB_SUBACCT2" + assert_command dfx cycles top-up "$(dfx canister id e2e_project_backend)" 600000 --identity bob --from-subaccount "$BOB_SUBACCT2" - assert_command dfx cycles balance --cycles-ledger-canister-id "$(dfx canister id cycles-ledger)" --precise --identity bob --subaccount "$BOB_SUBACCT2" + assert_command dfx cycles balance --precise --identity bob --subaccount "$BOB_SUBACCT2" assert_eq "2699899400000 cycles." assert_command dfx canister status e2e_project_backend assert_contains "Balance: 3_100_001_000_000 Cycles" @@ -326,8 +327,7 @@ current_time_nanoseconds() { BOB_SUBACCT2="6C6B6A030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f" BOB_SUBACCT2_CANDID="\6C\6B\6A\03\04\05\06\07\08\09\0a\0b\0c\0d\0e\0f\10\11\12\13\14\15\16\17\18\19\1a\1b\1c\1d\1e\1f" - assert_command dfx deploy cycles-ledger - assert_command dfx deploy cycles-depositor --argument "(record {ledger_id = principal \"$(dfx canister id cycles-ledger)\"})" --with-cycles 10000000000000 + deploy_cycles_ledger assert_command dfx deploy @@ -336,33 +336,33 @@ current_time_nanoseconds() { assert_command dfx canister call cycles-depositor deposit "(record {to = record{owner = principal \"$BOB\"; subaccount = opt blob \"$BOB_SUBACCT2_CANDID\"};cycles = 2_700_000_000_000;})" --identity cycle-giver # account to canister - assert_command dfx cycles balance --cycles-ledger-canister-id "$(dfx canister id cycles-ledger)" --precise --identity bob + assert_command dfx cycles balance --precise --identity bob assert_eq "2400000000000 cycles." assert_command dfx canister status e2e_project_backend assert_contains "Balance: 3_100_000_000_000 Cycles" t=$(current_time_nanoseconds) - assert_command dfx cycles top-up "$(dfx canister id e2e_project_backend)" --created-at-time "$t" 100000 --cycles-ledger-canister-id "$(dfx canister id cycles-ledger)" --identity bob + assert_command dfx cycles top-up "$(dfx canister id e2e_project_backend)" --created-at-time "$t" 100000 --identity bob assert_eq "Transfer sent at block index 3" - assert_command dfx cycles balance --cycles-ledger-canister-id "$(dfx canister id cycles-ledger)" --precise --identity bob + assert_command dfx cycles balance --precise --identity bob assert_eq "2399899900000 cycles." assert_command dfx canister status e2e_project_backend assert_contains "Balance: 3_100_000_100_000 Cycles" # same created-at-time: dupe - assert_command dfx cycles top-up "$(dfx canister id e2e_project_backend)" --created-at-time "$t" 100000 --cycles-ledger-canister-id "$(dfx canister id cycles-ledger)" --identity bob + assert_command dfx cycles top-up "$(dfx canister id e2e_project_backend)" --created-at-time "$t" 100000 --identity bob # shellcheck disable=SC2154 assert_contains "transaction is a duplicate of another transaction in block 3" "$stderr" # shellcheck disable=SC2154 assert_contains "Transfer sent at block index 3" "$stdout" - assert_command dfx cycles balance --cycles-ledger-canister-id "$(dfx canister id cycles-ledger)" --precise --identity bob + assert_command dfx cycles balance --precise --identity bob assert_eq "2399899900000 cycles." # different created-at-time: not dupe - assert_command dfx cycles top-up "$(dfx canister id e2e_project_backend)" --created-at-time $((t+1)) 100000 --cycles-ledger-canister-id "$(dfx canister id cycles-ledger)" --identity bob + assert_command dfx cycles top-up "$(dfx canister id e2e_project_backend)" --created-at-time $((t+1)) 100000 --identity bob assert_eq "Transfer sent at block index 4" - assert_command dfx cycles balance --cycles-ledger-canister-id "$(dfx canister id cycles-ledger)" --precise --identity bob + assert_command dfx cycles balance --precise --identity bob assert_eq "2399799800000 cycles." } @@ -371,8 +371,7 @@ current_time_nanoseconds() { ALICE=$(dfx identity get-principal --identity alice) BOB=$(dfx identity get-principal --identity bob) - assert_command dfx deploy cycles-ledger - assert_command dfx deploy cycles-depositor --argument "(record {ledger_id = principal \"$(dfx canister id cycles-ledger)\"})" --with-cycles 10000000000000 + deploy_cycles_ledger assert_command dfx ledger balance --identity cycle-giver assert_eq "1000000000.00000000 ICP" @@ -382,10 +381,10 @@ current_time_nanoseconds() { dfx canister status cycles-depositor - assert_command dfx cycles balance --cycles-ledger-canister-id "$(dfx canister id cycles-ledger)" --identity alice --precise + assert_command dfx cycles balance --identity alice --precise assert_eq "0 cycles." - assert_command dfx cycles balance --cycles-ledger-canister-id "$(dfx canister id cycles-ledger)" --identity bob --precise + assert_command dfx cycles balance --identity bob --precise assert_eq "0 cycles." @@ -395,22 +394,22 @@ current_time_nanoseconds() { assert_command dfx canister status cycles-depositor assert_contains "Balance: 9_999_500_000_000 Cycles" - assert_command dfx cycles balance --cycles-ledger-canister-id "$(dfx canister id cycles-ledger)" --identity alice --precise + assert_command dfx cycles balance --identity alice --precise assert_eq "500000000 cycles." - assert_command dfx cycles transfer "$BOB" 100000 --cycles-ledger-canister-id "$(dfx canister id cycles-ledger)" --identity alice + assert_command dfx cycles transfer "$BOB" 100000 --identity alice assert_eq "Transfer sent at block index 1" - assert_command dfx cycles balance --cycles-ledger-canister-id "$(dfx canister id cycles-ledger)" --identity alice --precise + assert_command dfx cycles balance --identity alice --precise assert_eq "399900000 cycles." - assert_command dfx cycles balance --cycles-ledger-canister-id "$(dfx canister id cycles-ledger)" --identity bob --precise + assert_command dfx cycles balance --identity bob --precise assert_eq "100000 cycles." - assert_command dfx cycles top-up cycles-depositor 100000 --cycles-ledger-canister-id "$(dfx canister id cycles-ledger)" --identity alice + assert_command dfx cycles top-up cycles-depositor 100000 --identity alice assert_eq "Transfer sent at block index 2" - assert_command dfx cycles balance --cycles-ledger-canister-id "$(dfx canister id cycles-ledger)" --identity alice --precise + assert_command dfx cycles balance --identity alice --precise assert_eq "299800000 cycles." assert_command dfx canister status cycles-depositor diff --git a/src/dfx/src/commands/cycles/balance.rs b/src/dfx/src/commands/cycles/balance.rs index bfddfd64b7..dbba2673fb 100644 --- a/src/dfx/src/commands/cycles/balance.rs +++ b/src/dfx/src/commands/cycles/balance.rs @@ -21,12 +21,6 @@ pub struct CyclesBalanceOpts { /// Get balance raw value (without upscaling to trillions of cycles). #[arg(long)] precise: bool, - - /// Canister ID of the cycles ledger canister. - /// If not specified, the default cycles ledger canister ID will be used. - // todo: remove this. See https://dfinity.atlassian.net/browse/SDK-1262 - #[arg(long)] - cycles_ledger_canister_id: Principal, } pub async fn exec(env: &dyn Environment, opts: CyclesBalanceOpts) -> DfxResult { @@ -41,8 +35,7 @@ pub async fn exec(env: &dyn Environment, opts: CyclesBalanceOpts) -> DfxResult { let subaccount = opts.subaccount.map(|x| x.0); - let balance = - cycles_ledger::balance(agent, owner, subaccount, opts.cycles_ledger_canister_id).await?; + let balance = cycles_ledger::balance(agent, owner, subaccount).await?; if opts.precise { println!("{} cycles.", balance); diff --git a/src/dfx/src/commands/cycles/top_up.rs b/src/dfx/src/commands/cycles/top_up.rs index 70e49bcc4f..f381c888d3 100644 --- a/src/dfx/src/commands/cycles/top_up.rs +++ b/src/dfx/src/commands/cycles/top_up.rs @@ -27,12 +27,6 @@ pub struct TopUpOpts { /// https://internetcomputer.org/docs/current/developer-docs/integrations/icrc-1/#transaction-deduplication- #[arg(long)] created_at_time: Option, - - /// Canister ID of the cycles ledger canister. - /// If not specified, the default cycles ledger canister ID will be used. - // todo: remove this. See https://dfinity.atlassian.net/browse/SDK-1262 - #[arg(long)] - cycles_ledger_canister_id: Principal, } pub async fn exec(env: &dyn Environment, opts: TopUpOpts) -> DfxResult { @@ -58,7 +52,6 @@ pub async fn exec(env: &dyn Environment, opts: TopUpOpts) -> DfxResult { amount, created_at_time, from_subaccount, - opts.cycles_ledger_canister_id, ) .await; if result.is_err() && opts.created_at_time.is_none() { diff --git a/src/dfx/src/commands/cycles/transfer.rs b/src/dfx/src/commands/cycles/transfer.rs index 97c1cf9d01..8f004a04a4 100644 --- a/src/dfx/src/commands/cycles/transfer.rs +++ b/src/dfx/src/commands/cycles/transfer.rs @@ -35,12 +35,6 @@ pub struct TransferOpts { /// Memo. #[arg(long)] memo: Option, - - /// Canister ID of the cycles ledger canister. - /// If not specified, the default cycles ledger canister ID will be used. - // todo: remove this. See https://dfinity.atlassian.net/browse/SDK-1262 - #[arg(long)] - cycles_ledger_canister_id: Principal, } pub async fn exec(env: &dyn Environment, opts: TransferOpts) -> DfxResult { @@ -68,7 +62,6 @@ pub async fn exec(env: &dyn Environment, opts: TransferOpts) -> DfxResult { to_subaccount, created_at_time, opts.memo, - opts.cycles_ledger_canister_id, ) .await; if result.is_err() && opts.created_at_time.is_none() { diff --git a/src/dfx/src/lib/operations/cycles_ledger.rs b/src/dfx/src/lib/operations/cycles_ledger.rs index c82a561760..f0be18bac3 100644 --- a/src/dfx/src/lib/operations/cycles_ledger.rs +++ b/src/dfx/src/lib/operations/cycles_ledger.rs @@ -16,16 +16,17 @@ use slog::{info, Logger}; const ICRC1_BALANCE_OF_METHOD: &str = "icrc1_balance_of"; const ICRC1_TRANSFER_METHOD: &str = "icrc1_transfer"; const SEND_METHOD: &str = "send"; +const CYCLES_LEDGER_CANISTER_ID: Principal = + Principal::from_slice(&[0x00, 0x00, 0x00, 0x00, 0x02, 0x10, 0x00, 0x02, 0x01, 0x01]); pub async fn balance( agent: &Agent, owner: Principal, subaccount: Option, - cycles_ledger_canister_id: Principal, ) -> DfxResult { let canister = Canister::builder() .with_agent(agent) - .with_canister_id(cycles_ledger_canister_id) + .with_canister_id(CYCLES_LEDGER_CANISTER_ID) .build()?; let arg = icrc1::account::Account { owner, subaccount }; @@ -58,11 +59,10 @@ pub async fn transfer( to_subaccount: Option, created_at_time: u64, memo: Option, - cycles_ledger_canister_id: Principal, ) -> DfxResult { let canister = Canister::builder() .with_agent(agent) - .with_canister_id(cycles_ledger_canister_id) + .with_canister_id(CYCLES_LEDGER_CANISTER_ID) .build()?; let retry_policy = ExponentialBackoff::default(); @@ -118,11 +118,10 @@ pub async fn send( amount: u128, created_at_time: u64, from_subaccount: Option, - cycles_ledger_canister_id: Principal, ) -> DfxResult { let canister = Canister::builder() .with_agent(agent) - .with_canister_id(cycles_ledger_canister_id) + .with_canister_id(CYCLES_LEDGER_CANISTER_ID) .build()?; let retry_policy = ExponentialBackoff::default(); @@ -170,3 +169,11 @@ pub async fn send( Ok(block_index) } + +#[test] +fn ledger_canister_id_text_representation() { + assert_eq!( + Principal::from_text("um5iw-rqaaa-aaaaq-qaaba-cai").unwrap(), + CYCLES_LEDGER_CANISTER_ID + ); +} From 4399f83e3f44f5c86391acb113a4bfe3ee8fc515 Mon Sep 17 00:00:00 2001 From: Vincent Zhang <118719397+vincent-dfinity@users.noreply.github.com> Date: Tue, 9 Jan 2024 01:51:16 +0800 Subject: [PATCH 3/3] Update dfx-ledger.md (#3492) Fix the sample for `dfx ledger fabricate-cycles`. --- docs/cli-reference/dfx-ledger.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/docs/cli-reference/dfx-ledger.md b/docs/cli-reference/dfx-ledger.md index 20f64b56a6..bb44cdb942 100644 --- a/docs/cli-reference/dfx-ledger.md +++ b/docs/cli-reference/dfx-ledger.md @@ -177,7 +177,7 @@ If no amount is specified, 10T cycles are used by default. If you are developing locally and want to add 8T cycles to all your canisters in your procject, you can do so like this: ``` -dfx ledger fabricate-cycles --all --amount 8000000000000 +dfx ledger fabricate-cycles --all --cycles 8000000000000 ``` The command displays output similar to the following: @@ -185,8 +185,6 @@ The command displays output similar to the following: ``` Fabricating 8000000000000 cycles onto hello_backend Fabricated 8000000000000 cycles, updated balance: 11_899_662_119_932 cycles -Fabricating 8000000000000 cycles onto hello_frontend -Fabricated 8000000000000 cycles, updated balance: 11_899_075_504_924 cycles ``` If you would rather only add the cycles to the canister called 'hello' and don't want to type all the zeros, you can do it like this: