diff --git a/crates/loam-cli/src/commands/build/clients.rs b/crates/loam-cli/src/commands/build/clients.rs index 9210f096..1fd8cdc3 100644 --- a/crates/loam-cli/src/commands/build/clients.rs +++ b/crates/loam-cli/src/commands/build/clients.rs @@ -225,6 +225,14 @@ export default new Client.Client({{ Ok(()) } + async fn account_exists(account_name: &str) -> Result { + // TODO: this is a workaround until generate is changed to not overwrite accounts + Ok(cli::keys::fund::Cmd::parse_arg_vec(&[account_name])? + .run() + .await + .is_ok()) + } + async fn handle_accounts(accounts: Option<&[env_toml::Account]>) -> Result<(), Error> { let Some(accounts) = accounts else { return Err(Error::NeedAtLeastOneAccount); @@ -244,10 +252,17 @@ export default new Client.Client({{ }; for account in accounts { - eprintln!("🔐 creating keys for {:?}", account.name); - cli::keys::generate::Cmd::parse_arg_vec(&[&account.name])? - .run() - .await?; + if Self::account_exists(&account.name).await? { + eprintln!( + "ℹī¸ account {:?} already exists, skipping key creation", + account.name + ); + } else { + eprintln!("🔐 creating keys for {:?}", account.name); + cli::keys::generate::Cmd::parse_arg_vec(&[&account.name])? + .run() + .await?; + } } std::env::set_var("STELLAR_ACCOUNT", &default_account); diff --git a/crates/loam-cli/tests/it/build_clients/accounts.rs b/crates/loam-cli/tests/it/build_clients/accounts.rs index 0422beba..21a946e6 100644 --- a/crates/loam-cli/tests/it/build_clients/accounts.rs +++ b/crates/loam-cli/tests/it/build_clients/accounts.rs @@ -25,6 +25,11 @@ soroban_token_contract.client = false assert!(env.cwd.join(".soroban/identity/alice.toml").exists()); assert!(env.cwd.join(".soroban/identity/bob.toml").exists()); + // check that they dont get overwritten if build is run again + let stderr = env.loam("build").assert().success().stderr_as_str(); + assert!(stderr.contains("account \"alice\" already exists")); + assert!(stderr.contains("account \"bob\" already exists")); + // check that they're actually funded let stderr = env .soroban("keys")