-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into promote-release-0.15.1
- Loading branch information
Showing
57 changed files
with
533 additions
and
152 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
# dfx cycles | ||
|
||
> **NOTE**: The cycles ledger is in development and the dfx cycles command is not expected to work on mainnet at this time. | ||
Use the `dfx cycles` command to manage cycles associated with an identity's principal. | ||
|
||
The basic syntax for running `dfx cycles` commands is: | ||
|
||
``` bash | ||
dfx cycles [subcommand] [options] | ||
``` | ||
|
||
The following subcommands are available: | ||
|
||
| Command | Description | | ||
|---------------------------------------|--------------------------------------------------------------------------------------| | ||
| [`balance`](#dfx-ledger-balance) | Prints the account balance of the user. | | ||
| `help` | Displays usage information message for a specified subcommand. | | ||
|
||
To view usage information for a specific subcommand, specify the subcommand and the `--help` flag. For example, to see usage information for `dfx cycles balance`, you can run the following command: | ||
|
||
`dfx cycles balance --help` | ||
|
||
## dfx cycles balance | ||
|
||
Use the `dfx cycles balance` command to print your account balance or that of another user. | ||
|
||
### Basic usage | ||
|
||
``` bash | ||
dfx cycles balance [flag] --network ic | ||
``` | ||
|
||
### Options | ||
|
||
You can specify the following arguments for the `dfx cycles balance` command. | ||
|
||
| Option | Description | | ||
|---------------------------------------------|---------------------------------------------------------------------| | ||
| `--owner <principal>` | Display the balance of this principal | | ||
| `--subaccount <subaccount>` | Display the balance of this subaccount | | ||
| `--precise` | Displays the exact balance, without scaling to trillions of cycles. | | ||
| `--cycles-ledger-canister-id <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. | ||
|
||
``` | ||
$ dfx cycles balance --network ic | ||
89.000 TC (trillion cycles). | ||
``` | ||
|
||
To see the exact amount of cycles, you can use the `--precise` option: | ||
``` | ||
$ dfx cycles balance --network ic --precise | ||
89000000000000 cycles. | ||
``` | ||
|
||
You can use the `dfx cycles balance` command to check the balance of another principal: | ||
|
||
``` bash | ||
dfx cycles balance --owner raxcz-bidhr-evrzj-qyivt-nht5a-eltcc-24qfc-o6cvi-hfw7j-dcecz-kae --network ic | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"canisters": { | ||
"cycles-ledger": { | ||
"type": "custom", | ||
"wasm": "cycles-ledger.wasm.gz", | ||
"candid": "cycles-ledger.did" | ||
}, | ||
"cycles-depositor": { | ||
"type": "custom", | ||
"wasm": "cycles-depositor.wasm.gz", | ||
"candid": "cycles-depositor.did" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
#!/usr/bin/env bats | ||
|
||
load ../utils/_ | ||
load ../utils/cycles-ledger | ||
|
||
setup() { | ||
standard_setup | ||
install_asset cycles-ledger | ||
install_shared_asset subnet_type/shared_network_settings/system | ||
install_cycles_ledger_canisters | ||
|
||
dfx identity new --storage-mode plaintext cycle-giver | ||
dfx identity new --storage-mode plaintext alice | ||
dfx identity new --storage-mode plaintext bob | ||
|
||
dfx_start_for_nns_install | ||
|
||
dfx extension install nns --version 0.2.1 || true | ||
dfx nns install --ledger-accounts "$(dfx ledger account-id --identity cycle-giver)" | ||
} | ||
|
||
teardown() { | ||
dfx_stop | ||
|
||
standard_teardown | ||
} | ||
|
||
@test "cycles ledger balance" { | ||
ALICE=$(dfx identity get-principal --identity alice) | ||
ALICE_SUBACCT1="000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f" | ||
ALICE_SUBACCT1_CANDID="\00\01\02\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" | ||
ALICE_SUBACCT2="9C9B9A030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f" | ||
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 | ||
|
||
assert_command dfx cycles balance --cycles-ledger-canister-id "$(dfx canister id cycles-ledger)" --identity alice --precise | ||
assert_eq "0 cycles." | ||
|
||
assert_command dfx cycles balance --cycles-ledger-canister-id "$(dfx canister id cycles-ledger)" --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_eq "0 cycles." | ||
|
||
assert_command dfx cycles balance --cycles-ledger-canister-id "$(dfx canister id cycles-ledger)" --identity bob | ||
assert_eq "0.000 TC (trillion cycles)." | ||
|
||
|
||
assert_command dfx canister call cycles-depositor deposit "(record {to = record{owner = principal \"$ALICE\";};cycles = 1_700_400_200_150;})" --identity cycle-giver | ||
assert_eq "(record { balance = 1_700_400_200_150 : nat; txid = 0 : nat })" | ||
|
||
assert_command dfx canister call cycles-depositor deposit "(record {to = record{owner = principal \"$ALICE\"; subaccount = opt blob \"$ALICE_SUBACCT1_CANDID\"};cycles = 3_750_000_000_000;})" --identity cycle-giver | ||
assert_eq "(record { balance = 3_750_000_000_000 : nat; txid = 1 : nat })" | ||
|
||
assert_command dfx canister call cycles-depositor deposit "(record {to = record{owner = principal \"$ALICE\"; subaccount = opt blob \"$ALICE_SUBACCT2_CANDID\"};cycles = 760_500_000_000;})" --identity cycle-giver | ||
assert_eq "(record { balance = 760_500_000_000 : nat; txid = 2 : nat })" | ||
|
||
assert_command dfx canister call cycles-depositor deposit "(record {to = record{owner = principal \"$BOB\";};cycles = 2_900_000_000_000;})" --identity cycle-giver | ||
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_eq "1700400200150 cycles." | ||
|
||
assert_command dfx cycles balance --cycles-ledger-canister-id "$(dfx canister id cycles-ledger)" --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_eq "760500000000 cycles." | ||
|
||
assert_command dfx cycles balance --cycles-ledger-canister-id "$(dfx canister id cycles-ledger)" --precise --identity bob | ||
assert_eq "2900000000000 cycles." | ||
|
||
|
||
assert_command dfx cycles balance --cycles-ledger-canister-id "$(dfx canister id cycles-ledger)" --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_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_eq "0.760 TC (trillion cycles)." | ||
|
||
assert_command dfx cycles balance --cycles-ledger-canister-id "$(dfx canister id cycles-ledger)" --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_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_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_eq "2.900 TC (trillion cycles)." | ||
} | ||
|
||
@test "cycles ledger howto" { | ||
# This is the equivalent of https://www.notion.so/dfinityorg/How-to-install-and-test-the-cycles-ledger-521c9f3c410f4a438514a03e35464299 | ||
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 | ||
|
||
assert_command dfx ledger balance --identity cycle-giver | ||
assert_eq "1000000000.00000000 ICP" | ||
|
||
assert_command dfx canister status cycles-depositor | ||
assert_contains "Balance: 10_000_000_000_000 Cycles" | ||
|
||
dfx canister status cycles-depositor | ||
|
||
assert_command dfx cycles balance --cycles-ledger-canister-id "$(dfx canister id cycles-ledger)" --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_eq "0 cycles." | ||
|
||
|
||
assert_command dfx canister call cycles-depositor deposit "(record {to = record{owner = principal \"$ALICE\";};cycles = 500_000_000;})" --identity cycle-giver | ||
assert_eq "(record { balance = 500_000_000 : nat; txid = 0 : nat })" | ||
|
||
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_eq "500000000 cycles." | ||
|
||
assert_command dfx canister call cycles-ledger icrc1_transfer "(record {to = record{owner = principal \"$BOB\"}; amount = 100_000;})" --identity alice | ||
assert_eq "(variant { Ok = 1 : nat })" | ||
|
||
assert_command dfx cycles balance --cycles-ledger-canister-id "$(dfx canister id cycles-ledger)" --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_eq "100000 cycles." | ||
|
||
assert_command dfx canister call cycles-ledger send "(record {amount = 100_000;to = principal \"$(dfx canister id cycles-depositor)\"})" --identity alice | ||
assert_eq "(variant { Ok = 2 : nat })" | ||
|
||
assert_command dfx cycles balance --cycles-ledger-canister-id "$(dfx canister id cycles-ledger)" --identity alice --precise | ||
assert_eq "299800000 cycles." | ||
|
||
assert_command dfx canister status cycles-depositor | ||
assert_contains "Balance: 9_999_500_100_000 Cycles" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
CYCLES_LEDGER_VERSION="0.2.1" | ||
|
||
build_artifact_url() { | ||
echo "https://raw.githubusercontent.com/dfinity/sdk/cycles-ledger-prerelease/cycles-ledger-v$CYCLES_LEDGER_VERSION/${1}" | ||
} | ||
|
||
downloaded_cycles_ledger_canisters_dir() { | ||
echo "$DFX_CACHE_ROOT/canisters/cycles-ledger/$CYCLES_LEDGER_VERSION" | ||
} | ||
|
||
download_cycles_ledger_canisters() { | ||
DOWNLOAD_DIR="$DFX_CACHE_ROOT/.download" | ||
DEST_DIR="$(downloaded_cycles_ledger_canisters_dir)" | ||
|
||
if test -d "$DEST_DIR"; then | ||
return | ||
fi | ||
|
||
rm -rf "$DOWNLOAD_DIR" | ||
mkdir -p "$DOWNLOAD_DIR" "$(dirname "$DEST_DIR")" | ||
|
||
for name in cycles-ledger cycles-depositor; do | ||
for ext in wasm.gz wasm.gz.sha256 did; do | ||
URL=$(build_artifact_url "${name}.${ext}") | ||
curl -v --fail -o "$DOWNLOAD_DIR/${name}.${ext}" "$URL" | ||
done | ||
done | ||
|
||
( cd "$DOWNLOAD_DIR" && shasum -c cycles-ledger.wasm.gz.sha256 && shasum -c cycles-depositor.wasm.gz.sha256 ) | ||
mv "$DOWNLOAD_DIR" "$DEST_DIR" | ||
} | ||
|
||
install_cycles_ledger_canisters() { | ||
download_cycles_ledger_canisters | ||
cp "$(downloaded_cycles_ledger_canisters_dir)"/* . | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.