Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

## DFX

### fix: Save SNS canister IDs

SNS canister IDs were not being parsed reliably. Now the candid file is being specified explicitly, which resolves the issue in at least some cases.

### feat: NNS usability improvements

The command line interface for nns commands has been updated to:
Expand Down
5 changes: 5 additions & 0 deletions e2e/tests-dfx/sns.bash
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,9 @@ SNS_CONFIG_FILE_NAME="sns.yml"
install_asset sns/valid
dfx sns config validate
dfx sns deploy
# SNS canister IDs should be saved
dfx canister id sns_governance
dfx canister id sns_ledger
dfx canister id sns_root
dfx canister id sns_swap
}
3 changes: 2 additions & 1 deletion src/dfx/src/commands/sns/deploy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ pub struct DeployOpts {}

/// Executes the command line `dfx sns deploy`.
pub fn exec(env: &dyn Environment, _opts: DeployOpts) -> DfxResult {
println!("Creating SNS canisters. This typically takes about one minute...");
let config = env.get_config_or_anyhow()?;
let path = config.get_project_root().join(sns::CONFIG_FILE_NAME);

deploy_sns(env, &path)?;
println!("{}", deploy_sns(env, &path)?);
Ok(())
}
27 changes: 25 additions & 2 deletions src/dfx/src/lib/sns/deploy.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//! Code for creating an SNS.
use anyhow::bail;
use fn_error_context::context;
use std::ffi::OsString;
use std::path::Path;
Expand All @@ -10,11 +11,33 @@ use crate::Environment;
/// Creates an SNS. This requires funds but no proposal.
#[context("Failed to deploy SNS with config: {}", path.display())]
pub fn deploy_sns(env: &dyn Environment, path: &Path) -> DfxResult<String> {
// Note: It MAY be possible to get the did file location using existing sdk methods.
let did_file = "candid/nns-sns-wasm.did";
if !Path::new(did_file).exists() {
bail!("Missing did file at '{did_file}'. Please run 'dfx nns import' to get the file.");
}

// Note: The --network flag is not available at the moment,
// so this always applies to local canister IDs.
// This will have to be expanded to cover deployments to
// mainnet quite soon.
let canister_ids_file = ".dfx/local/canister_ids.json";

let args = vec![
OsString::from("deploy"),
OsString::from("--init-config-file"),
OsString::from(path),
OsString::from("--candid"),
OsString::from(did_file),
OsString::from("--save-to"),
OsString::from(canister_ids_file),
];
call_bundled(env, "sns", &args)
.map(|stdout| format!("Deployed SNS: {}\n{}", path.display(), stdout))
call_bundled(env, "sns", &args).map(|stdout| {
format!(
"Deployed SNS:\nSNS config: {}\nCanister ID file: {}\n\n{}",
path.display(),
canister_ids_file,
stdout
)
})
}