Skip to content

Commit

Permalink
Merge branch 'master' into promote-release-0.15.1
Browse files Browse the repository at this point in the history
  • Loading branch information
ericswanson-dfinity authored Oct 12, 2023
2 parents 35ec0d7 + 5ba48e3 commit 18416fe
Show file tree
Hide file tree
Showing 57 changed files with 533 additions and 152 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ The parameter was erroneously passed twice. Now it is passed only once.

Removed this warning: "Project-specific networks are deprecated and will be removed after February 2023." While we may remove project-specific networks in the future, it is not imminent. One key requirement is the ability to run more than one subnet type at one time.

### feat: added `cycles balance` command

This won't work on mainnet yet, but it can work locally after installing the cycles ledger.

## Dependencies

### icx-proxy
Expand Down
15 changes: 15 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ aes-gcm = "0.9.4"
anyhow = "1.0.56"
anstyle = "1.0.0"
argon2 = "0.4.0"
backoff = "0.4.0"
backoff = { version = "0.4.0", features = [ "futures", "tokio" ] }
base64 = "0.13.0"
byte-unit = "4.0.14"
bytes = "1.2.1"
Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@ This command will install a binary compatible with your operating system, and ad

Find a release for your architecture [here](https://github.com/dfinity/sdk/releases).

#### in GitHub Action, using [`dfinity/setup-dfx`](https://github.com/dfinity/setup-dfx)

```yml
steps:
- name: Install dfx
uses: dfinity/setup-dfx@main
```
### Getting Help
Once the `IC SDK` is installed, get acquainted with its capabilities by entering.
Expand Down
67 changes: 67 additions & 0 deletions docs/cli-reference/dfx-cycles.md
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
```

2 changes: 2 additions & 0 deletions docs/cli-reference/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ When you have the SDK installed, you can use the following commands to specify t

- [dfx canister](./dfx-canister.md)

- [dfx cycles](./dfx-cycles.md)

- [dfx deploy](./dfx-deploy.md)

- [dfx deps](./dfx-deps.md)
Expand Down
14 changes: 14 additions & 0 deletions e2e/assets/cycles-ledger/dfx.json
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"
}
}
}
151 changes: 151 additions & 0 deletions e2e/tests-dfx/cycles-ledger.bash
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"
}
36 changes: 36 additions & 0 deletions e2e/utils/cycles-ledger.bash
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)"/* .
}
24 changes: 12 additions & 12 deletions nix/sources.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
"homepage": "https://rustsec.org",
"owner": "RustSec",
"repo": "advisory-db",
"rev": "9b6403d856f71291aabb91511b53fa79c2758745",
"sha256": "1b839a6bja6x1660737yfv7b7qfldcjd36g2s3a1v74q3f6zv5nw",
"rev": "da470caa84d3dd3be02657a9cb35bd5269636127",
"sha256": "1hm7dkr0zpjrqjrdjw2sg0zyvnpi5nia8nkwi0cn9nzy7nniq002",
"type": "tarball",
"url": "https://github.com/RustSec/advisory-db/archive/9b6403d856f71291aabb91511b53fa79c2758745.tar.gz",
"url": "https://github.com/RustSec/advisory-db/archive/da470caa84d3dd3be02657a9cb35bd5269636127.tar.gz",
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
},
"canister_sandbox-x86_64-darwin": {
Expand Down Expand Up @@ -160,27 +160,27 @@
"builtin": false,
"description": "The Motoko base library",
"owner": "dfinity",
"sha256": "18qp0d8mr6hcnbym81a4hgvj036vm0qdbjb833w1rqqhibv1083s",
"sha256": "1ks5fflz4yjfqaf3lq6izdz7fqkczi40m3hc3rifjm8p618pxc2c",
"type": "tarball",
"url": "https://github.com/dfinity/motoko/releases/download/0.9.8/motoko-base-library.tar.gz",
"url": "https://github.com/dfinity/motoko/releases/download/0.10.0/motoko-base-library.tar.gz",
"url_template": "https://github.com/dfinity/motoko/releases/download/<version>/motoko-base-library.tar.gz",
"version": "0.9.8"
"version": "0.10.0"
},
"motoko-x86_64-darwin": {
"builtin": false,
"sha256": "153lnpkdna9dv76zvmy44farsy8r4ixv4yi8bf5qnkr9dmkmrdr7",
"sha256": "0kxxmx39sjy99qddhmd1m7v5jpcmlnhr1a7ffcv45xs0iva032x3",
"type": "file",
"url": "https://github.com/dfinity/motoko/releases/download/0.9.8/motoko-Darwin-x86_64-0.9.8.tar.gz",
"url": "https://github.com/dfinity/motoko/releases/download/0.10.0/motoko-Darwin-x86_64-0.10.0.tar.gz",
"url_template": "https://github.com/dfinity/motoko/releases/download/<version>/motoko-Darwin-x86_64-<version>.tar.gz",
"version": "0.9.8"
"version": "0.10.0"
},
"motoko-x86_64-linux": {
"builtin": false,
"sha256": "11yaciq3fq6fckqrw9gh5wb23cz5wxk9fij0z107nsiys9z46g2i",
"sha256": "1639zr4hx1rhi0mkip75z600l6hkhysych9jy5l4lmy4gyrkn9h6",
"type": "file",
"url": "https://github.com/dfinity/motoko/releases/download/0.9.8/motoko-Linux-x86_64-0.9.8.tar.gz",
"url": "https://github.com/dfinity/motoko/releases/download/0.10.0/motoko-Linux-x86_64-0.10.0.tar.gz",
"url_template": "https://github.com/dfinity/motoko/releases/download/<version>/motoko-Linux-x86_64-<version>.tar.gz",
"version": "0.9.8"
"version": "0.10.0"
},
"replica-x86_64-darwin": {
"builtin": false,
Expand Down
Loading

0 comments on commit 18416fe

Please sign in to comment.