diff --git a/zk_toolbox/crates/common/src/forge.rs b/zk_toolbox/crates/common/src/forge.rs index 3ae46a8034a8..565c7aa52d96 100644 --- a/zk_toolbox/crates/common/src/forge.rs +++ b/zk_toolbox/crates/common/src/forge.rs @@ -130,16 +130,16 @@ impl ForgeScript { }) } - pub async fn check_the_balance(&self, minimum_value: U256) -> anyhow::Result { + pub async fn get_the_balance(&self) -> anyhow::Result> { let Some(rpc_url) = self.rpc_url() else { - return Ok(true); + return Ok(None); }; let Some(private_key) = self.private_key() else { - return Ok(true); + return Ok(None); }; let client = create_ethers_client(private_key, rpc_url, None)?; let balance = client.get_balance(client.address(), None).await?; - Ok(balance > minimum_value) + Ok(Some(balance)) } } diff --git a/zk_toolbox/crates/zk_inception/src/forge_utils.rs b/zk_toolbox/crates/zk_inception/src/forge_utils.rs index 581d1ec892d4..cabc8ff7566b 100644 --- a/zk_toolbox/crates/zk_inception/src/forge_utils.rs +++ b/zk_toolbox/crates/zk_inception/src/forge_utils.rs @@ -22,11 +22,17 @@ pub async fn check_the_balance(forge: &ForgeScript) -> anyhow::Result<()> { return Ok(()); }; - while !forge - .check_the_balance(U256::from(MINIMUM_BALANCE_FOR_WALLET)) - .await? - { - if !common::PromptConfirm::new(msg_address_doesnt_have_enough_money_prompt(&address)).ask() + let expected_balance = U256::from(MINIMUM_BALANCE_FOR_WALLET); + while let Some(balance) = forge.get_the_balance().await? { + if balance >= expected_balance { + return Ok(()); + } + if !common::PromptConfirm::new(msg_address_doesnt_have_enough_money_prompt( + &address, + balance, + expected_balance, + )) + .ask() { break; } diff --git a/zk_toolbox/crates/zk_inception/src/messages.rs b/zk_toolbox/crates/zk_inception/src/messages.rs index 21f051470555..6d539d422bea 100644 --- a/zk_toolbox/crates/zk_inception/src/messages.rs +++ b/zk_toolbox/crates/zk_inception/src/messages.rs @@ -1,4 +1,7 @@ -use ethers::types::H160; +use ethers::{ + types::{H160, U256}, + utils::format_ether, +}; /// Common messages pub(super) const MSG_SELECTED_CONFIG: &str = "Selected config"; @@ -129,12 +132,15 @@ pub(super) const MSG_FAILED_TO_DROP_PROVER_DATABASE_ERR: &str = "Failed to drop pub(super) fn msg_server_db_url_prompt(chain_name: &str) -> String { format!("Please provide server database url for chain {chain_name}") } + pub(super) fn msg_prover_db_url_prompt(chain_name: &str) -> String { format!("Please provide prover database url for chain {chain_name}") } + pub(super) fn msg_prover_db_name_prompt(chain_name: &str) -> String { format!("Please provide prover database name for chain {chain_name}") } + pub(super) fn msg_server_db_name_prompt(chain_name: &str) -> String { format!("Please provide server database name for chain {chain_name}") } @@ -170,8 +176,15 @@ pub(super) const MSG_BUILDING_L1_CONTRACTS: &str = "Building L1 contracts..."; /// Forge utils related messages pub(super) const MSG_DEPLOYER_PK_NOT_SET_ERR: &str = "Deployer private key is not set"; -pub(super) fn msg_address_doesnt_have_enough_money_prompt(address: &H160) -> String { + +pub(super) fn msg_address_doesnt_have_enough_money_prompt( + address: &H160, + actual: U256, + expected: U256, +) -> String { + let actual = format_ether(actual); + let expected = format_ether(expected); format!( - "Address {address:?} doesn't have enough money to deploy contracts do you want to try again?" + "Address {address:?} doesn't have enough money to deploy contracts only {actual} ETH but expected: {expected} ETH do you want to try again?" ) }