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

feat: cache contracts before benching #254

Merged
merged 11 commits into from
Sep 27, 2024
3 changes: 3 additions & 0 deletions .github/workflows/gas-bench.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ jobs:
with:
key: "gas-bench"

- name: install cargo-stylus
run: cargo install [email protected] [email protected]

- name: install solc
run: |
curl -LO https://github.com/ethereum/solidity/releases/download/v0.8.21/solc-static-linux
Expand Down
16 changes: 16 additions & 0 deletions benches/src/erc20.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::process::Command;

use alloy::{
network::{AnyNetwork, EthereumWallet},
primitives::Address,
Expand All @@ -8,6 +10,7 @@ use alloy::{
};
use alloy_primitives::U256;
use e2e::{receipt, Account};
use eyre::{bail, Context};

use crate::report::Report;

Expand Down Expand Up @@ -60,6 +63,19 @@ pub async fn bench() -> eyre::Result<Report> {
let contract = Erc20::new(contract_addr, &alice_wallet);
let contract_bob = Erc20::new(contract_addr, &bob_wallet);

// Add contract to cache manager. We leave the bid unspecified, since we
// should have plenty of room to fill the cache (can hold ~4k contracts).
let status = Command::new("cargo-stylus")
.arg("cache")
.args(&["-e", &std::env::var("RPC_URL")?])
.args(&["--private-key", &format!("0x{}", alice.pk())])
.args(&["--address", &format!("{}", contract_addr)])
.status()
.with_context(|| "`cargo stylus cache` failed:")?;
if !status.success() {
bail!("Failed to cache Erc20 contract");
}

// IMPORTANT: Order matters!
use Erc20::*;
#[rustfmt::skip]
Expand Down
Loading