Skip to content

Commit

Permalink
fix: dfx deploy to the playground fails for a fresh project; CLI read…
Browse files Browse the repository at this point in the history
  • Loading branch information
dfx-json committed Nov 14, 2024
1 parent 3969afb commit f2996de
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 11 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@

# 0.24.2

### 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: Support canister log allowed viewer list

Added support for the canister log allowed viewer list, enabling specified users to access a canister's logs without needing to be set as the canister's controller.
Expand Down
5 changes: 5 additions & 0 deletions docs/cli-reference/dfx-envars.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
9 changes: 4 additions & 5 deletions e2e/tests-dfx/generate.bash
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down
14 changes: 14 additions & 0 deletions e2e/tests-dfx/playground.bash
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,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'"
Expand Down
9 changes: 4 additions & 5 deletions src/dfx/src/commands/generate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -14,14 +15,12 @@ pub struct GenerateOpts {
/// If you do not specify a canister name, generates types for all canisters.
canister_name: Option<String>,

// 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<String>,
#[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.
Expand Down
2 changes: 1 addition & 1 deletion src/dfx/src/lib/network/network_opt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>,

/// Shorthand for --network=playground.
Expand Down

0 comments on commit f2996de

Please sign in to comment.