diff --git a/CHANGELOG.md b/CHANGELOG.md index 75feea1e46..551d4a36bf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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: diff --git a/e2e/tests-dfx/sns.bash b/e2e/tests-dfx/sns.bash index 08417e8228..7cf574da47 100755 --- a/e2e/tests-dfx/sns.bash +++ b/e2e/tests-dfx/sns.bash @@ -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 } diff --git a/src/dfx/src/commands/sns/deploy.rs b/src/dfx/src/commands/sns/deploy.rs index 3fd5764864..657b7c7496 100644 --- a/src/dfx/src/commands/sns/deploy.rs +++ b/src/dfx/src/commands/sns/deploy.rs @@ -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(()) } diff --git a/src/dfx/src/lib/sns/deploy.rs b/src/dfx/src/lib/sns/deploy.rs index 06a3dc0227..96f03e720b 100644 --- a/src/dfx/src/lib/sns/deploy.rs +++ b/src/dfx/src/lib/sns/deploy.rs @@ -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; @@ -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 { + // 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 + ) + }) }