From a1028f3d989a1d6eadee73040fb8c5751e2e68fa Mon Sep 17 00:00:00 2001 From: Kaya Gokalp Date: Thu, 7 Nov 2024 16:26:37 -0800 Subject: [PATCH 1/2] fix: forc-deploy asks for password before checking if the wallet exists --- forc-plugins/forc-client/src/op/deploy.rs | 9 +++++++-- forc-plugins/forc-client/src/util/tx.rs | 3 --- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/forc-plugins/forc-client/src/op/deploy.rs b/forc-plugins/forc-client/src/op/deploy.rs index ace89c3ddae..8f86c333672 100644 --- a/forc-plugins/forc-client/src/op/deploy.rs +++ b/forc-plugins/forc-client/src/op/deploy.rs @@ -7,8 +7,8 @@ use crate::{ pkg::{built_pkgs, create_proxy_contract, update_proxy_address_in_manifest}, target::Target, tx::{ - prompt_forc_wallet_password, select_account, update_proxy_contract_target, - SignerSelectionMode, + check_and_create_wallet_at_default_path, prompt_forc_wallet_password, select_account, + update_proxy_contract_target, SignerSelectionMode, }, }, }; @@ -1002,6 +1002,11 @@ async fn setup_deployment_account( } else if let Some(arn) = &command.aws_kms_signer { SignerSelectionMode::AwsSigner(arn.clone()) } else { + // Check if we have a wallet in the default path + // If there is one we will ask for the password + // If not we will ask the user to either create a new one or import one + let wallet_path = default_wallet_path(); + check_and_create_wallet_at_default_path(&wallet_path)?; println_action_green("", &format!("Wallet: {}", default_wallet_path().display())); let password = prompt_forc_wallet_password()?; SignerSelectionMode::ForcWallet(password) diff --git a/forc-plugins/forc-client/src/util/tx.rs b/forc-plugins/forc-client/src/util/tx.rs index e9f8b220121..dd9002a8055 100644 --- a/forc-plugins/forc-client/src/util/tx.rs +++ b/forc-plugins/forc-client/src/util/tx.rs @@ -170,9 +170,6 @@ pub(crate) async fn select_account( match wallet_mode { SignerSelectionMode::ForcWallet(password) => { let wallet_path = default_wallet_path(); - check_and_create_wallet_at_default_path(&wallet_path)?; - // TODO: This is a very simple TUI, we should consider adding a nice TUI - // capabilities for selections and answer collection. let accounts = collect_user_accounts(&wallet_path, password)?; let account_balances = collect_account_balances(&accounts, provider).await?; let base_asset_id = provider.base_asset_id(); From 29e4562393b364fe6e9564789d65b9d96e8db7e8 Mon Sep 17 00:00:00 2001 From: Kaya Gokalp Date: Thu, 7 Nov 2024 23:27:09 -0800 Subject: [PATCH 2/2] update interactive cli test for deployment --- forc-plugins/forc-client/tests/deploy.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/forc-plugins/forc-client/tests/deploy.rs b/forc-plugins/forc-client/tests/deploy.rs index afabb238e82..b06d6aa96ed 100644 --- a/forc-plugins/forc-client/tests/deploy.rs +++ b/forc-plugins/forc-client/tests/deploy.rs @@ -693,7 +693,7 @@ async fn test_non_owner_fails_to_set_target() { // It would also require overriding `default_wallet_path` function for tests, so as not to interfere with the user's wallet. #[test] -fn test_deploy_interactive_wrong_password() -> Result<(), rexpect::error::Error> { +fn test_deploy_interactive_missing_wallet() -> Result<(), rexpect::error::Error> { let (mut node, port) = run_node(); let node_url = format!("http://127.0.0.1:{}/v1/graphql", port); @@ -711,9 +711,8 @@ fn test_deploy_interactive_wrong_password() -> Result<(), rexpect::error::Error> process .exp_string("\u{1b}[1;32mConfirming\u{1b}[0m transactions [deploy standalone_contract]")?; process.exp_string(&format!("Network: {node_url}"))?; - process.exp_string("Wallet: ")?; - process.exp_string("Wallet password")?; - process.send_line("mock_password")?; + process.exp_regex("Could not find a wallet at")?; + process.send_line("n")?; process.process.exit()?; node.kill().unwrap();