Skip to content

Commit

Permalink
fix(zk_toolbox): increase confirmations in testing (#2878)
Browse files Browse the repository at this point in the history
## What ❔

<!-- What are the changes this PR brings about? -->
<!-- Example: This PR adds a PR template to the repo. -->
<!-- (For bigger PRs adding more context is appreciated) -->
Increase confirmations in testing.

## Why ❔

<!-- Why are these changes done? What goal do they contribute to? What
are the principles behind them? -->
<!-- Example: PR templates ensure PR reviewers, observers, and future
iterators are in context about the evolution of repos. -->
Should make CI workflows less flaky.

## Checklist

<!-- Check your PR fulfills the following items. -->
<!-- For draft PRs check the boxes as you complete them. -->

- [x] PR title corresponds to the body of PR (we generate changelog
entries from PRs).
- [x] Tests for the changes have been added / updated.
- [x] Documentation comments have been added / updated.
- [x] Code has been formatted via `zk fmt` and `zk lint`.
  • Loading branch information
manuelmauro authored Sep 16, 2024
1 parent 9ab7200 commit f985e41
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 28 deletions.
6 changes: 3 additions & 3 deletions infrastructure/zk/src/docker.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Command} from 'commander';
import { Command } from 'commander';
import * as utils from 'utils';

const IMAGES = [
Expand Down Expand Up @@ -31,7 +31,7 @@ async function dockerCommand(
dockerOrg: string = 'matterlabs'
) {
// Generating all tags for containers. We need 2 tags here: SHA and SHA+TS
const {stdout: COMMIT_SHORT_SHA}: { stdout: string } = await utils.exec('git rev-parse --short HEAD');
const { stdout: COMMIT_SHORT_SHA }: { stdout: string } = await utils.exec('git rev-parse --short HEAD');
// COMMIT_SHORT_SHA returns with newline, so we need to trim it
const imageTagShaTS: string = process.env.IMAGE_TAG_SUFFIX
? process.env.IMAGE_TAG_SUFFIX
Expand Down Expand Up @@ -126,7 +126,7 @@ async function _build(image: string, tagList: string[], dockerOrg: string, platf
}
buildArgs += extraArgs;

console.log("Build args: ", buildArgs);
console.log('Build args: ', buildArgs);

const buildCommand =
`DOCKER_BUILDKIT=1 docker buildx build ${tagsToBuild}` +
Expand Down
45 changes: 20 additions & 25 deletions zk_toolbox/crates/common/src/ethereum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use ethers::{
};
use types::TokenInfo;

use crate::{logger, wallets::Wallet};
use crate::wallets::Wallet;

pub fn create_ethers_client(
private_key: H256,
Expand Down Expand Up @@ -89,35 +89,30 @@ pub async fn mint_token(
chain_id: u64,
amount: u128,
) -> anyhow::Result<()> {
let client = Arc::new(create_ethers_client(
main_wallet.private_key.unwrap(),
l1_rpc,
Some(chain_id),
)?);
let client = Arc::new(
create_ethers_client(main_wallet.private_key.unwrap(), l1_rpc, Some(chain_id))?
.nonce_manager(main_wallet.address),
);

let contract = TokenContract::new(token_address, client);
// contract

let mut pending_calls = vec![];
for address in addresses {
if let Err(err) = mint(&contract, address, amount).await {
logger::warn(format!("Failed to mint {err}"))
}
pending_calls.push(contract.mint(address, amount.into()));
}

Ok(())
}
let mut pending_txs = vec![];
for call in &pending_calls {
pending_txs.push(
call.send()
.await?
// It's safe to set such low number of confirmations and low interval for localhost
.confirmations(3)
.interval(Duration::from_millis(30)),
);
}

futures::future::join_all(pending_txs).await;

async fn mint<T: Middleware + 'static>(
contract: &TokenContract<T>,
address: Address,
amount: u128,
) -> anyhow::Result<()> {
contract
.mint(address, amount.into())
.send()
.await?
// It's safe to set such low number of confirmations and low interval for localhost
.confirmations(1)
.interval(Duration::from_millis(30))
.await?;
Ok(())
}

0 comments on commit f985e41

Please sign in to comment.