diff --git a/e2e/tests-dfx/cycles-ledger.bash b/e2e/tests-dfx/cycles-ledger.bash index b2dbc443ed..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,8 +46,7 @@ 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 --identity alice --precise assert_eq "0 cycles." @@ -116,8 +120,7 @@ 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 @@ -190,8 +193,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 canister call cycles-depositor deposit "(record {to = record{owner = principal \"$ALICE\";};cycles = 3_000_000_000_000;})" --identity cycle-giver @@ -249,7 +251,7 @@ current_time_nanoseconds() { @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 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 @@ -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 @@ -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" diff --git a/src/dfx/src/lib/operations/cycles_ledger.rs b/src/dfx/src/lib/operations/cycles_ledger.rs index 4a5a9a4af4..94549052ce 100644 --- a/src/dfx/src/lib/operations/cycles_ledger.rs +++ b/src/dfx/src/lib/operations/cycles_ledger.rs @@ -16,7 +16,15 @@ 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: &str = "um5iw-rqaaa-aaaaq-qaaba-cai"; +const CYCLES_LEDGER_CANISTER_ID: Principal = + Principal::from_slice(&[0x00, 0x00, 0x00, 0x00, 0x02, 0x10, 0x00, 0x02, 0x01, 0x01]); +#[test] +fn ledger_canister_id_text_representation() { + assert_eq!( + "um5iw-rqaaa-aaaaq-qaaba-cai", + CYCLES_LEDGER_CANISTER_ID.to_text() + ); +} pub async fn balance( agent: &Agent,