Skip to content

Commit

Permalink
fix: load dfx.json with extension-defined canister type (#153)
Browse files Browse the repository at this point in the history
  • Loading branch information
ericswanson-dfinity authored Nov 8, 2024
1 parent a8ed39b commit c9885ba
Show file tree
Hide file tree
Showing 8 changed files with 87 additions and 30 deletions.
52 changes: 29 additions & 23 deletions Cargo.lock

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

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ license = "Apache-2.0"
repository = "https://github.com/dfinity/dfx-extensions"

[workspace.dependencies]
dfx-core = { git = "https://github.com/dfinity/sdk", rev = "993ae6df38caef8aae5291570b78954334d16b21" }
dfx-core = "0.1.1"
dfx-extensions-utils.path = "./extensions-utils"

anyhow = "^1"
Expand All @@ -21,8 +21,8 @@ flate2 = { version = "1.0.25", default-features = false, features = [
] }
fn-error-context = "0.2.1"
futures-util = "0.3.28"
ic-agent = { git = "https://github.com/dfinity/agent-rs", rev = "6e11a350112f9b907c4d590d8217f340e153d898" }
ic-utils = { git = "https://github.com/dfinity/agent-rs", rev = "6e11a350112f9b907c4d590d8217f340e153d898" }
ic-agent = "=0.38.0"
ic-utils = "=0.38.0"
reqwest = { version = "^0.11.22", default-features = false, features = [
"blocking",
"json",
Expand Down
1 change: 1 addition & 0 deletions extensions/nns/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<!-- next-header -->

## [Unreleased] - ReleaseDate
- Fixed a bug where `dfx nns install` and `dfx nns import` would fail if a canister type in dfx.json was defined by an extension.

## [0.4.6] - 2024-10-10
- Unchanged from 0.4.5
Expand Down
37 changes: 37 additions & 0 deletions extensions/nns/e2e/tests/nns.bash
Original file line number Diff line number Diff line change
Expand Up @@ -175,3 +175,40 @@ assert_nns_canister_id_matches() {
fi
}

@test "dfx nns install with a canister type defined by another extension" {
install_shared_asset subnet_type/shared_network_settings/system
dfx_start_for_nns_install

CACHE_DIR=$(dfx cache show)
mkdir -p "$CACHE_DIR"/extensions/embera
cat > "$CACHE_DIR"/extensions/embera/extension.json <<EOF
{
"name": "embera",
"version": "0.1.0",
"homepage": "https://github.com/dfinity/dfx-extensions",
"authors": "DFINITY",
"summary": "Test extension for e2e purposes.",
"categories": [],
"keywords": [],
"canister_type": {
"defaults": {
"type": "custom",
"wasm": ".embera/{{canister_name}}/{{canister_name}}.wasm"
}
}
}
EOF
cat > dfx.json <<EOF
{
"canisters": {
"c1": {
"type": "embera",
"candid": "main.did",
"main": "main-file.embera"
}
}
}
EOF

dfx nns install
}
6 changes: 5 additions & 1 deletion extensions/nns/src/commands/import.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
//! Code for the command line: `dfx nns import`
use std::{collections::BTreeMap, path::Path};

use dfx_core::config::cache::get_version_from_cache_path;
use dfx_core::config::model::canister_id_store::CanisterIds;
use dfx_core::config::model::dfinity::Config;
use dfx_core::extension::manager::ExtensionManager;
use dfx_extensions_utils::{
get_canisters_json_object, get_network_mappings, import_canister_definitions, new_logger,
replica_rev, set_remote_canister_ids, ImportNetworkMapping, NNS_CORE,
Expand All @@ -26,7 +28,9 @@ pub struct ImportOpts {

/// Executes `dfx nns import`
pub async fn exec(opts: ImportOpts, dfx_cache_path: &Path) -> anyhow::Result<()> {
let config = Config::from_current_dir(None)?;
let version = get_version_from_cache_path(dfx_cache_path)?;
let extension_manager = ExtensionManager::new(&version)?;
let config = Config::from_current_dir(Some(&extension_manager))?;
if config.is_none() {
anyhow::bail!(crate::errors::DFXJSON_NOT_FOUND);
}
Expand Down
8 changes: 6 additions & 2 deletions extensions/nns/src/commands/install.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Code for the command line: `dfx nns install`
use crate::install_nns::{get_and_check_replica_url, get_with_retries, install_nns};
use clap::Parser;
use dfx_core::DfxInterface;
use dfx_core::DfxInterfaceBuilder;
use dfx_extensions_utils::new_logger;
use std::path::Path;

Expand All @@ -28,7 +28,11 @@ pub struct InstallOpts {

/// Executes `dfx nns install`.
pub async fn exec(opts: InstallOpts, dfx_cache_path: &Path) -> anyhow::Result<()> {
let dfx = DfxInterface::anonymous().await?;
let dfx = DfxInterfaceBuilder::new()
.anonymous()
.with_extension_manager_from_cache_path(dfx_cache_path)?
.build()
.await?;
let mut network_descriptor = dfx.network_descriptor().clone();
if let Some(ref mut local_server_descriptor) = &mut network_descriptor.local_server_descriptor {
local_server_descriptor.load_settings_digest()?;
Expand Down
1 change: 1 addition & 0 deletions extensions/sns/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<!-- next-header -->

## [Unreleased] - ReleaseDate
- Fixed a bug where `dfx sns import` would fail if a canister type in dfx.json was defined by an extension.

## [0.4.6] - 2024-10-11
- Added `dfx sns health` command.
Expand Down
6 changes: 5 additions & 1 deletion extensions/sns/src/commands/import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ use dfx_extensions_utils::{
};

use clap::Parser;
use dfx_core::config::cache::get_version_from_cache_path;
use dfx_core::extension::manager::ExtensionManager;

/// Imports the sns canisters
#[derive(Parser)]
Expand All @@ -23,7 +25,9 @@ pub struct SnsImportOpts {

/// Executes the command line `dfx sns import`.
pub async fn exec(opts: SnsImportOpts, dfx_cache_path: &Path) -> anyhow::Result<()> {
let config = Config::from_current_dir(None)?;
let version = get_version_from_cache_path(dfx_cache_path)?;
let extension_manager = ExtensionManager::new(&version)?;
let config = Config::from_current_dir(Some(&extension_manager))?;
if config.is_none() {
anyhow::bail!(crate::errors::DFXJSON_NOT_FOUND);
}
Expand Down

0 comments on commit c9885ba

Please sign in to comment.