Skip to content

Commit

Permalink
Merge branch 'master' into SDK-1308-dfx-calls-cycles-faucet-endpoint-…
Browse files Browse the repository at this point in the history
…if-no-wallet-exists
  • Loading branch information
Marcin Nowak-Liebiediew authored Jan 24, 2024
2 parents 3cc4fc7 + c62bbdb commit 46a4c2c
Show file tree
Hide file tree
Showing 9 changed files with 77 additions and 18 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ If the local did file doesn't contain `import` or init args, we will not perform

### fix: subtyping check reports the special opt rule as error

### fix: can now run several dfx canister commands outside of a project

The following commands now work outside of a project:
- `dfx canister start <specific canister id>`
- `dfx canister stop <specific canister id>`
- `dfx canister deposit-cycles <amount> <specific canister id>`
- `dfx canister uninstall-code <specific canister id>`

# 0.16.0

### feat: large canister modules now supported
Expand Down
37 changes: 37 additions & 0 deletions e2e/tests-dfx/start.bash
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,43 @@ teardown() {
standard_teardown
}

@test "start and stop outside project" {
dfx_start

mkdir subdir
cd subdir || exit 1
dfx_new
assert_command dfx deploy
CANISTER_ID="$(dfx canister id e2e_project_backend)"
cd ..
assert_command dfx canister status "$CANISTER_ID"
assert_contains "Status: Running"
assert_command dfx canister stop "$CANISTER_ID"
assert_command dfx canister status "$CANISTER_ID"
assert_contains "Status: Stopped"
assert_command dfx canister start "$CANISTER_ID"
assert_command dfx canister status "$CANISTER_ID"
assert_contains "Status: Running"
}

@test "uninstall-code outside of a project" {
dfx_start

mkdir subdir
cd subdir || exit 1
dfx_new
assert_command dfx deploy
CANISTER_ID="$(dfx canister id e2e_project_backend)"
cd ..
assert_command dfx canister status "$CANISTER_ID"
assert_contains "Module hash: 0x"
assert_command dfx canister uninstall-code "$CANISTER_ID"
assert_contains "Uninstalling code for canister $CANISTER_ID"
assert_command dfx canister status "$CANISTER_ID"
assert_contains "Module hash: None"
}


@test "icx-proxy domain configuration in string form" {
create_networks_json
jq '.local.proxy.domain="xyz.domain"' "$E2E_NETWORKS_JSON" | sponge "$E2E_NETWORKS_JSON"
Expand Down
22 changes: 22 additions & 0 deletions e2e/tests-dfx/wallet.bash
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,28 @@ teardown() {
standard_teardown
}

@test "deposit cycles inside a project" {
dfx_start

dfx_new
assert_command dfx deploy
assert_command dfx canister deposit-cycles 47 e2e_project_backend
assert_contains "Deposited 47 cycles"
}

@test "deposit cycles outside a project" {
dfx_start

mkdir subdir
cd subdir || exit 1
dfx_new
assert_command dfx deploy
CANISTER_ID="$(dfx canister id e2e_project_backend)"
cd ..
assert_command dfx canister deposit-cycles 42 "$CANISTER_ID"
assert_contains "Deposited 42 cycles"
}

@test "DFX_WALLET_WASM environment variable overrides wallet module wasm at installation" {
dfx_new hello
dfx_start
Expand Down
4 changes: 2 additions & 2 deletions src/dfx/src/commands/canister/deposit_cycles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,11 @@ pub async fn exec(
// amount has been validated by cycle_amount_validator
let cycles = opts.cycles;

let config = env.get_config_or_anyhow()?;

if let Some(canister) = opts.canister.as_deref() {
deposit_cycles(env, canister, call_sender, cycles).await
} else if opts.all {
let config = env.get_config_or_anyhow()?;

if let Some(canisters) = &config.get_config().canisters {
for canister in canisters.keys() {
deposit_cycles(env, canister, call_sender, cycles)
Expand Down
2 changes: 1 addition & 1 deletion src/dfx/src/commands/canister/start.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ pub async fn exec(
opts: CanisterStartOpts,
call_sender: &CallSender,
) -> DfxResult {
let config = env.get_config_or_anyhow()?;
fetch_root_key_if_needed(env).await?;

if let Some(canister) = opts.canister.as_deref() {
start_canister(env, canister, call_sender).await
} else if opts.all {
let config = env.get_config_or_anyhow()?;
if let Some(canisters) = &config.get_config().canisters {
for canister in canisters.keys() {
start_canister(env, canister, call_sender).await?;
Expand Down
3 changes: 1 addition & 2 deletions src/dfx/src/commands/canister/stop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,12 @@ pub async fn exec(
opts: CanisterStopOpts,
call_sender: &CallSender,
) -> DfxResult {
let config = env.get_config_or_anyhow()?;

fetch_root_key_if_needed(env).await?;

if let Some(canister) = opts.canister.as_deref() {
stop_canister(env, canister, call_sender).await
} else if opts.all {
let config = env.get_config_or_anyhow()?;
if let Some(canisters) = &config.get_config().canisters {
for canister in canisters.keys() {
stop_canister(env, canister, call_sender).await?;
Expand Down
4 changes: 2 additions & 2 deletions src/dfx/src/commands/canister/uninstall_code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@ pub async fn exec(
opts: UninstallCodeOpts,
call_sender: &CallSender,
) -> DfxResult {
let config = env.get_config_or_anyhow()?;

fetch_root_key_if_needed(env).await?;

if let Some(canister) = opts.canister.as_deref() {
uninstall_code(env, canister, call_sender).await
} else if opts.all {
let config = env.get_config_or_anyhow()?;

if let Some(canisters) = &config.get_config().canisters {
for canister in canisters.keys() {
uninstall_code(env, canister, call_sender).await?;
Expand Down
8 changes: 2 additions & 6 deletions src/dfx/src/commands/new.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ use dfx_core::config::model::dfinity::CONFIG_FILE_NAME;
use dfx_core::json::{load_json_file, save_json_file};
use fn_error_context::context;
use indicatif::HumanBytes;
use lazy_static::lazy_static;
use semver::Version;
use serde_json::Value;
use slog::{info, warn, Logger};
Expand All @@ -30,15 +29,12 @@ const RELEASE_ROOT: &str = "https://sdk.dfinity.org";
// The dist-tag to use when getting the version from NPM.
const AGENT_JS_DEFAULT_INSTALL_DIST_TAG: &str = "latest";

lazy_static! {
// Tested on a phone tethering connection. This should be fine with
// little impact to the user, given that "new" is supposedly a
// heavy-weight operation. Thus, worst case we are utilizing the user
// expectation for the duration to have a more expensive version
// check.
static ref CHECK_VERSION_TIMEOUT: Duration = Duration::from_secs(2);

}
const CHECK_VERSION_TIMEOUT: Duration = Duration::from_secs(2);

/// Creates a new project.
#[derive(Parser)]
Expand Down Expand Up @@ -417,7 +413,7 @@ pub fn exec(env: &dyn Environment, opts: NewOpts) -> DfxResult {

// It is fine for the following command to timeout or fail. We
// drop the error.
let latest_version = get_latest_version(RELEASE_ROOT, Some(*CHECK_VERSION_TIMEOUT)).ok();
let latest_version = get_latest_version(RELEASE_ROOT, Some(CHECK_VERSION_TIMEOUT)).ok();

if is_upgrade_necessary(latest_version.as_ref(), current_version) {
warn_upgrade(log, latest_version.as_ref(), current_version);
Expand Down
7 changes: 2 additions & 5 deletions src/dfx/src/lib/info/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
use lazy_static::lazy_static;
lazy_static! {
static ref REPLICA_REV_STR: String = env!("DFX_ASSET_REPLICA_REV").to_string();
}
const REPLICA_REV_STR: &str = env!("DFX_ASSET_REPLICA_REV");

pub fn replica_rev() -> &'static str {
&REPLICA_REV_STR
REPLICA_REV_STR
}

0 comments on commit 46a4c2c

Please sign in to comment.