|
| 1 | +use alloy::{ |
| 2 | + network::{AnyNetwork, EthereumWallet}, |
| 3 | + primitives::Address, |
| 4 | + providers::ProviderBuilder, |
| 5 | + sol, |
| 6 | + sol_types::SolCall, |
| 7 | + uint, |
| 8 | +}; |
| 9 | +use e2e::{receipt, Account}; |
| 10 | + |
| 11 | +use crate::{ |
| 12 | + report::{ContractReport, FunctionReport}, |
| 13 | + Opt, |
| 14 | +}; |
| 15 | + |
| 16 | +sol!( |
| 17 | + #[sol(rpc)] |
| 18 | + contract Erc6909 { |
| 19 | + function balanceOf(address owner, uint256 id) external view returns (uint256 balance); |
| 20 | + function allowance(address owner, address spender, uint256 id) external view returns (uint256 allowance); |
| 21 | + function isOperator(address owner, address spender) external view returns (bool approved); |
| 22 | + function approve(address spender, uint256 id, uint256 amount) external returns (bool); |
| 23 | + function setOperator(address spender, bool approved) external returns (bool); |
| 24 | + function transfer(address receiver, uint256 id, uint256 amount) external returns (bool); |
| 25 | + function transferFrom(address sender, address receiver, uint256 id, uint256 amount) external returns (bool); |
| 26 | + function mint(address to, uint256 id, uint256 amount) external; |
| 27 | + function burn(address from, uint256 id, uint256 amount) external; |
| 28 | + } |
| 29 | +); |
| 30 | + |
| 31 | +pub async fn bench() -> eyre::Result<ContractReport> { |
| 32 | + ContractReport::generate("Erc6909", run).await |
| 33 | +} |
| 34 | + |
| 35 | +pub async fn run(cache_opt: Opt) -> eyre::Result<Vec<FunctionReport>> { |
| 36 | + let alice = Account::new().await?; |
| 37 | + let alice_addr = alice.address(); |
| 38 | + let alice_wallet = ProviderBuilder::new() |
| 39 | + .network::<AnyNetwork>() |
| 40 | + .with_recommended_fillers() |
| 41 | + .wallet(EthereumWallet::from(alice.signer.clone())) |
| 42 | + .on_http(alice.url().parse()?); |
| 43 | + |
| 44 | + let bob = Account::new().await?; |
| 45 | + let bob_addr = bob.address(); |
| 46 | + let bob_wallet = ProviderBuilder::new() |
| 47 | + .network::<AnyNetwork>() |
| 48 | + .with_recommended_fillers() |
| 49 | + .wallet(EthereumWallet::from(bob.signer.clone())) |
| 50 | + .on_http(bob.url().parse()?); |
| 51 | + |
| 52 | + let contract_addr = deploy(&alice, cache_opt).await?; |
| 53 | + |
| 54 | + let contract = Erc6909::new(contract_addr, &alice_wallet); |
| 55 | + let contract_bob = Erc6909::new(contract_addr, &bob_wallet); |
| 56 | + |
| 57 | + let token_id = uint!(1_U256); |
| 58 | + let amount = uint!(100_U256); |
| 59 | + let one = uint!(1_U256); |
| 60 | + |
| 61 | + // IMPORTANT: Order matters! |
| 62 | + use Erc6909::*; |
| 63 | + #[rustfmt::skip] |
| 64 | + let receipts = vec![ |
| 65 | + (mintCall::SIGNATURE, receipt!(contract.mint(alice_addr, token_id, amount))?), |
| 66 | + (balanceOfCall::SIGNATURE, receipt!(contract.balanceOf(alice_addr, token_id))?), |
| 67 | + (allowanceCall::SIGNATURE, receipt!(contract.allowance(alice_addr, bob_addr, token_id))?), |
| 68 | + (isOperatorCall::SIGNATURE, receipt!(contract.isOperator(alice_addr, bob_addr))?), |
| 69 | + (setOperatorCall::SIGNATURE, receipt!(contract.setOperator(bob_addr, true))?), |
| 70 | + (transferCall::SIGNATURE, receipt!(contract.transfer(bob_addr, token_id, one))?), |
| 71 | + (approveCall::SIGNATURE, receipt!(contract.approve(bob_addr, token_id, one))?), |
| 72 | + (transferFromCall::SIGNATURE, receipt!(contract_bob.transferFrom(alice_addr, bob_addr, token_id, one))?), |
| 73 | + (burnCall::SIGNATURE, receipt!(contract.burn(alice_addr, token_id, one))?), |
| 74 | + ]; |
| 75 | + |
| 76 | + receipts |
| 77 | + .into_iter() |
| 78 | + .map(FunctionReport::new) |
| 79 | + .collect::<eyre::Result<Vec<_>>>() |
| 80 | +} |
| 81 | + |
| 82 | +async fn deploy(account: &Account, cache_opt: Opt) -> eyre::Result<Address> { |
| 83 | + crate::deploy(account, "erc6909", None, cache_opt).await |
| 84 | +} |
0 commit comments