From ca58ec788a1199aea18ae6a0eded72dc62161a7f Mon Sep 17 00:00:00 2001 From: Eric Swanson <64809312+ericswanson-dfinity@users.noreply.github.com> Date: Wed, 13 Nov 2024 20:50:00 -0800 Subject: [PATCH 1/3] fix: dfx deploy to the playground fails for a fresh project; CLI reads DFX_NETWORK (#3987) Fixes https://dfinity.atlassian.net/browse/SDK-1882 Fixes https://dfinity.atlassian.net/browse/SDK-1860 Fixes https://dfinity.atlassian.net/browse/SDK-1605 --- CHANGELOG.md | 9 +++++++++ docs/cli-reference/dfx-envars.mdx | 5 +++++ e2e/tests-dfx/generate.bash | 9 ++++----- e2e/tests-dfx/playground.bash | 14 ++++++++++++++ src/dfx/src/commands/generate.rs | 9 ++++----- src/dfx/src/lib/network/network_opt.rs | 2 +- 6 files changed, 37 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1117ac68b8..fa65924aeb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,15 @@ # UNRELEASED +### feat: all commands will use the DFX_NETWORK from the environment + +If `DFX_NETWORK` is set in the environment, all commands will use that network by default. +The `--network` parameter will take precedence if provided. + +### fix: dfx generate now honors the --network parameter +This fixes an issue where `dfx deploy --playground` would fail if the project +had not been previously built for the local network. + ### feat: facade pull ICP, ckBTC, ckETH ledger canisters The ledger canisters can be pulled even though they are not really "pullable". diff --git a/docs/cli-reference/dfx-envars.mdx b/docs/cli-reference/dfx-envars.mdx index 4b9f0ea558..0c1b742f2f 100644 --- a/docs/cli-reference/dfx-envars.mdx +++ b/docs/cli-reference/dfx-envars.mdx @@ -40,6 +40,11 @@ Use the `DFX_INSTALLATION_ROOT` environment variable to specify a different loca The `.cache/dfinity/uninstall.sh` script uses this environment variable to identify the root directory for your SDK installation. +## DFX_NETWORK + +Use the `DFX_NETWORK` environment variable to specify the network that you want to use when you run `dfx` commands. +If you pass the `--network` option to a `dfx` command, the value of the `DFX_NETWORK` environment variable is ignored. + ## DFX_VERSION Use the `DFX_VERSION` environment variable to identify a specific version of the SDK that you want to install. diff --git a/e2e/tests-dfx/generate.bash b/e2e/tests-dfx/generate.bash index f007654f77..67955956d3 100755 --- a/e2e/tests-dfx/generate.bash +++ b/e2e/tests-dfx/generate.bash @@ -139,14 +139,13 @@ teardown() { assert_command dfx generate } -@test "dfx generate --network is still valid" { - # The option has no effect, but is still accepted to not break existing scripts +@test "dfx generate --network is accepted" { dfx_new hello assert_command dfx generate --network local + assert_file_exists ".dfx/local/canisters/hello_backend/service.did" - # Option is not advertised anymore - assert_command dfx generate --help - assert_not_contains "--network" + assert_command dfx generate --playground + assert_file_exists ".dfx/playground/canisters/hello_backend/service.did" } @test "dfx generate does not delete source candid file of Rust canister when bindings contains no did" { diff --git a/e2e/tests-dfx/playground.bash b/e2e/tests-dfx/playground.bash index 1fb928006f..77cd0b866e 100644 --- a/e2e/tests-dfx/playground.bash +++ b/e2e/tests-dfx/playground.bash @@ -76,6 +76,20 @@ setup_playground() { assert_command dfx canister --playground info "$CANISTER" } +@test "deploy fresh project to playground" { + cd .. + rm -rf hello + dfx_new_frontend hello + + [[ "$USE_POCKETIC" ]] && assert_command dfx canister create --all --playground + [[ "$USE_POCKETIC" ]] && assert_command dfx ledger fabricate-cycles --t 9999999 --canister hello_backend --playground + [[ "$USE_POCKETIC" ]] && assert_command dfx ledger fabricate-cycles --t 9999999 --canister hello_frontend --playground + + assert_command dfx deploy --playground + assert_command dfx canister --playground call hello_backend greet '("player")' + assert_match "Hello, player!" +} + @test "Handle timeout correctly" { assert_command dfx canister create hello_backend --playground -vv assert_match "Reserved canister 'hello_backend'" diff --git a/src/dfx/src/commands/generate.rs b/src/dfx/src/commands/generate.rs index 17992ef765..840958162d 100644 --- a/src/dfx/src/commands/generate.rs +++ b/src/dfx/src/commands/generate.rs @@ -4,6 +4,7 @@ use crate::lib::builders::BuildConfig; use crate::lib::environment::Environment; use crate::lib::error::DfxResult; use crate::lib::models::canister::CanisterPool; +use crate::lib::network::network_opt::NetworkOpt; use clap::Parser; use tokio::runtime::Runtime; @@ -14,14 +15,12 @@ pub struct GenerateOpts { /// If you do not specify a canister name, generates types for all canisters. canister_name: Option, - // Deprecated/hidden because it had/has no effect. - // Cannot use 'hide' on a flattened object - inlined the flattened network specifier - #[arg(long, global = true, hide = true)] - network: Option, + #[command(flatten)] + network: NetworkOpt, } pub fn exec(env: &dyn Environment, opts: GenerateOpts) -> DfxResult { - let env = create_anonymous_agent_environment(env, None)?; + let env = create_anonymous_agent_environment(env, opts.network.to_network_name())?; let log = env.get_logger(); // Read the config. diff --git a/src/dfx/src/lib/network/network_opt.rs b/src/dfx/src/lib/network/network_opt.rs index ab46426c9d..5e264f5bb1 100644 --- a/src/dfx/src/lib/network/network_opt.rs +++ b/src/dfx/src/lib/network/network_opt.rs @@ -9,7 +9,7 @@ pub struct NetworkOpt { /// A valid URL (starting with `http:` or `https:`) can be used here, and a special /// ephemeral network will be created specifically for this request. E.g. /// "http://localhost:12345/" is a valid network name. - #[arg(long, global(true), group = "network-select")] + #[arg(long, env = "DFX_NETWORK", global(true), group = "network-select")] network: Option, /// Shorthand for --network=playground. From 6cfec6aea6a43850e70ee91ee1a263f2116cb5b7 Mon Sep 17 00:00:00 2001 From: mraszyk <31483726+mraszyk@users.noreply.github.com> Date: Thu, 14 Nov 2024 14:44:28 +0100 Subject: [PATCH 2/3] chore: enable canister logs tests for PocketIC (#3990) --- scripts/workflows/e2e-matrix.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/scripts/workflows/e2e-matrix.py b/scripts/workflows/e2e-matrix.py index c48f831211..a039189045 100755 --- a/scripts/workflows/e2e-matrix.py +++ b/scripts/workflows/e2e-matrix.py @@ -25,10 +25,6 @@ def test_scripts(prefix): { "backend": "pocketic", "test": "dfx/canister_http_adapter" - }, - { - "backend": "pocketic", - "test": "dfx/canister_logs" } ] } From bd0e8bb916fc9f15fcbd8c9ab4f67794ac86eb35 Mon Sep 17 00:00:00 2001 From: DFINITY bot <58022693+dfinity-bot@users.noreply.github.com> Date: Thu, 14 Nov 2024 17:11:36 +0100 Subject: [PATCH 3/3] chore: update Motoko version to 0.13.3 (#3988) --- CHANGELOG.md | 4 ++++ nix/sources.json | 18 +++++++++--------- src/dfx/assets/dfx-asset-sources.toml | 16 ++++++++-------- 3 files changed, 21 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fa65924aeb..14c8373544 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -56,6 +56,10 @@ You must open a new terminal to continue developing. If you'd prefer to stop, qu ## Dependencies +### Motoko + +Updated Motoko to [0.13.3](https://github.com/dfinity/motoko/releases/tag/0.13.3) + ### Replica Updated replica to elected commit a62848817cec7ae50618a87a526c85d020283fd9. diff --git a/nix/sources.json b/nix/sources.json index db0a8a1d63..79f8cf4d8b 100644 --- a/nix/sources.json +++ b/nix/sources.json @@ -130,27 +130,27 @@ "builtin": false, "description": "The Motoko base library", "owner": "dfinity", - "sha256": "0qq8dlzjy4dkp5jn2ly21aw8n024fmkvhisca2qswhsqbg2wwv3x", + "sha256": "0i2jrys9qj6w776f3nrifhvs7s4rrhwlnqmd7dlawd0qk8ns4zk9", "type": "tarball", - "url": "https://github.com/dfinity/motoko/releases/download/0.13.2/motoko-base-library.tar.gz", + "url": "https://github.com/dfinity/motoko/releases/download/0.13.3/motoko-base-library.tar.gz", "url_template": "https://github.com/dfinity/motoko/releases/download//motoko-base-library.tar.gz", - "version": "0.13.2" + "version": "0.13.3" }, "motoko-x86_64-darwin": { "builtin": false, - "sha256": "1pb5jn7nr5s18hqpcvzc4szkdnrk2h417d6dpwnrrx8l3fqvx1m3", + "sha256": "0c4njswid1z3aw298y2vd7sx618ijb8ixgjsh99vlazm9yai5wi1", "type": "file", - "url": "https://github.com/dfinity/motoko/releases/download/0.13.2/motoko-Darwin-x86_64-0.13.2.tar.gz", + "url": "https://github.com/dfinity/motoko/releases/download/0.13.3/motoko-Darwin-x86_64-0.13.3.tar.gz", "url_template": "https://github.com/dfinity/motoko/releases/download//motoko-Darwin-x86_64-.tar.gz", - "version": "0.13.2" + "version": "0.13.3" }, "motoko-x86_64-linux": { "builtin": false, - "sha256": "1i1adh7a5yn10a8k1sjnl8bp8k2sxfmmy5smy2phj28lzwm374j9", + "sha256": "110hx0da5bspv4ida3xwf2mpiwmn6axq8cnnq0vinzfrajb5r2qm", "type": "file", - "url": "https://github.com/dfinity/motoko/releases/download/0.13.2/motoko-Linux-x86_64-0.13.2.tar.gz", + "url": "https://github.com/dfinity/motoko/releases/download/0.13.3/motoko-Linux-x86_64-0.13.3.tar.gz", "url_template": "https://github.com/dfinity/motoko/releases/download//motoko-Linux-x86_64-.tar.gz", - "version": "0.13.2" + "version": "0.13.3" }, "pocket-ic-x86_64-darwin": { "rev": "a62848817cec7ae50618a87a526c85d020283fd9", diff --git a/src/dfx/assets/dfx-asset-sources.toml b/src/dfx/assets/dfx-asset-sources.toml index e1b61ae29f..1940059a57 100644 --- a/src/dfx/assets/dfx-asset-sources.toml +++ b/src/dfx/assets/dfx-asset-sources.toml @@ -22,8 +22,8 @@ url = 'https://download.dfinity.systems/ic/a62848817cec7ae50618a87a526c85d020283 sha256 = 'f999d8a7e582bee1dce787d36224f749cf17d52c0623e0752cdbffba47879f4c' [x86_64-darwin.motoko] -url = 'https://github.com/dfinity/motoko/releases/download/0.13.2/motoko-Darwin-x86_64-0.13.2.tar.gz' -sha256 = 'a386beb11b14f59c2dbfcdb413081433db36bf26ec6f76314441976c8f9565dd' +url = 'https://github.com/dfinity/motoko/releases/download/0.13.3/motoko-Darwin-x86_64-0.13.3.tar.gz' +sha256 = '21f212954ff52bba53825abe1ed1921105d3f5695b78940457e38716b9969630' # The replica, canister_sandbox and compiler_sandbox binaries must have the same revision. [x86_64-darwin.replica] @@ -53,8 +53,8 @@ url = 'https://download.dfinity.systems/ic/a62848817cec7ae50618a87a526c85d020283 sha256 = 'fd47abe1876c3bf08246f97908c6badb3cf84ca402d8f4015759883d69689af6' [x86_64-darwin.motoko-base] -url = 'https://github.com/dfinity/motoko/releases/download/0.13.2/motoko-base-library.tar.gz' -sha256 = 'd456d015745af15ce8ee731ce184163b8f2385a1ba45741393da667f08a376db' +url = 'https://github.com/dfinity/motoko/releases/download/0.13.3/motoko-base-library.tar.gz' +sha256 = 'e48cb7ea6685f5afcfc189f7f3292ca015dda5e1b4c19fb30c7f1211f8733adc' [x86_64-darwin.ic-btc-canister] url = 'https://github.com/dfinity/bitcoin-canister/releases/download/release%2F2023-10-13/ic-btc-canister.wasm.gz' @@ -81,8 +81,8 @@ url = 'https://download.dfinity.systems/ic/a62848817cec7ae50618a87a526c85d020283 sha256 = 'a13497bf7d255b3a235b14967934ec766a93dca1b410ce953880d86fb4b5c422' [x86_64-linux.motoko] -url = 'https://github.com/dfinity/motoko/releases/download/0.13.2/motoko-Linux-x86_64-0.13.2.tar.gz' -sha256 = '4992332aff140909aff055175fabeb5a4c7417a256ea309102c1faa20e6c2ac4' +url = 'https://github.com/dfinity/motoko/releases/download/0.13.3/motoko-Linux-x86_64-0.13.3.tar.gz' +sha256 = '158b5c9654d97d1b37c0d63284bb32b6f278ab70bc0fd522d957afa21ae81084' # The replica, canister_sandbox and compiler_sandbox binaries must have the same revision. [x86_64-linux.replica] @@ -112,8 +112,8 @@ url = 'https://download.dfinity.systems/ic/a62848817cec7ae50618a87a526c85d020283 sha256 = '7b14e2a196dd24ab171990ea755746f4b8c0776eaca64951be4150f83c019099' [x86_64-linux.motoko-base] -url = 'https://github.com/dfinity/motoko/releases/download/0.13.2/motoko-base-library.tar.gz' -sha256 = 'd456d015745af15ce8ee731ce184163b8f2385a1ba45741393da667f08a376db' +url = 'https://github.com/dfinity/motoko/releases/download/0.13.3/motoko-base-library.tar.gz' +sha256 = 'e48cb7ea6685f5afcfc189f7f3292ca015dda5e1b4c19fb30c7f1211f8733adc' [x86_64-linux.ic-btc-canister] url = 'https://github.com/dfinity/bitcoin-canister/releases/download/release%2F2023-10-13/ic-btc-canister.wasm.gz'