Skip to content

Commit

Permalink
Merge branch 'main' into 0xneshi/ref-paus-erc721
Browse files Browse the repository at this point in the history
  • Loading branch information
0xNeshi authored Nov 27, 2024
2 parents 0fa0a34 + e256e75 commit 91444b8
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -127,4 +127,4 @@ jobs:
uses: actions/checkout@v4

- name: Check spelling of files in the workspace
uses: crate-ci/typos@v1.27.3
uses: crate-ci/typos@v1.28.0
1 change: 1 addition & 0 deletions benches/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ pub mod erc1155;
pub mod erc20;
pub mod erc721;
pub mod merkle_proofs;
pub mod ownable;
pub mod report;

#[derive(Debug, Deserialize)]
Expand Down
4 changes: 3 additions & 1 deletion benches/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use benches::{
access_control, erc20, erc721, merkle_proofs, report::BenchmarkReport,
access_control, erc20, erc721, merkle_proofs, ownable,
report::BenchmarkReport,
};
use futures::FutureExt;

Expand All @@ -10,6 +11,7 @@ async fn main() -> eyre::Result<()> {
erc20::bench().boxed(),
erc721::bench().boxed(),
merkle_proofs::bench().boxed(),
ownable::bench().boxed(),
])
.await?
.into_iter()
Expand Down
86 changes: 86 additions & 0 deletions benches/src/ownable.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
use alloy::{
network::{AnyNetwork, EthereumWallet},
primitives::Address,
providers::ProviderBuilder,
sol,
sol_types::{SolCall, SolConstructor},
};
use e2e::{receipt, Account};

use crate::{
report::{ContractReport, FunctionReport},
CacheOpt,
};

sol!(
#[sol(rpc)]
contract Ownable {
function owner() external view returns (address owner);
function renounceOwnership() external onlyOwner;
function transferOwnership(address newOwner) external;
}
);

sol!("../examples/ownable/src/constructor.sol");

pub async fn bench() -> eyre::Result<ContractReport> {
let reports = run_with(CacheOpt::None).await?;
let report = reports
.into_iter()
.try_fold(ContractReport::new("Ownable"), ContractReport::add)?;

let cached_reports = run_with(CacheOpt::Bid(0)).await?;
let report = cached_reports
.into_iter()
.try_fold(report, ContractReport::add_cached)?;

Ok(report)
}

pub async fn run_with(
cache_opt: CacheOpt,
) -> eyre::Result<Vec<FunctionReport>> {
let alice = Account::new().await?;
let alice_wallet = ProviderBuilder::new()
.network::<AnyNetwork>()
.with_recommended_fillers()
.wallet(EthereumWallet::from(alice.signer.clone()))
.on_http(alice.url().parse()?);

let bob = Account::new().await?;
let bob_addr = bob.address();
let bob_wallet = ProviderBuilder::new()
.network::<AnyNetwork>()
.with_recommended_fillers()
.wallet(EthereumWallet::from(bob.signer.clone()))
.on_http(bob.url().parse()?);

let contract_addr = deploy(&alice, cache_opt).await?;

let contract = Ownable::new(contract_addr, &alice_wallet);
let contract_bob = Ownable::new(contract_addr, &bob_wallet);

// IMPORTANT: Order matters!
use Ownable::*;
#[rustfmt::skip]
let receipts = vec![
(ownerCall::SIGNATURE, receipt!(contract.owner())?),
(transferOwnershipCall::SIGNATURE, receipt!(contract.transferOwnership(bob_addr))?),
(renounceOwnershipCall::SIGNATURE, receipt!(contract_bob.renounceOwnership())?),
];

receipts
.into_iter()
.map(FunctionReport::new)
.collect::<eyre::Result<Vec<_>>>()
}

async fn deploy(
account: &Account,
cache_opt: CacheOpt,
) -> eyre::Result<Address> {
let args =
OwnableExample::constructorCall { initialOwner: account.address() };
let args = alloy::hex::encode(args.abi_encode());
crate::deploy(account, "ownable", Some(args), cache_opt).await
}

0 comments on commit 91444b8

Please sign in to comment.