Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(zk_toolbox): Show balance #2254

Merged
merged 1 commit into from
Jun 17, 2024
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
8 changes: 4 additions & 4 deletions zk_toolbox/crates/common/src/forge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,16 +130,16 @@ impl ForgeScript {
})
}

pub async fn check_the_balance(&self, minimum_value: U256) -> anyhow::Result<bool> {
pub async fn get_the_balance(&self) -> anyhow::Result<Option<U256>> {
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))
}
}

Expand Down
16 changes: 11 additions & 5 deletions zk_toolbox/crates/zk_inception/src/forge_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
19 changes: 16 additions & 3 deletions zk_toolbox/crates/zk_inception/src/messages.rs
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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}")
}
Expand Down Expand Up @@ -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?"
)
}
Loading