-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/main' into unit-tests/multiple-c…
…ontract-deployment # Conflicts: # contracts/src/token/erc721/mod.rs # lib/motsu/src/shims.rs
- Loading branch information
Showing
78 changed files
with
7,711 additions
and
679 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -127,4 +127,4 @@ jobs: | |
uses: actions/checkout@v4 | ||
|
||
- name: Check spelling of files in the workspace | ||
uses: crate-ci/[email protected].1 | ||
uses: crate-ci/[email protected].2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
use alloy::{ | ||
network::{AnyNetwork, EthereumWallet}, | ||
primitives::Address, | ||
providers::ProviderBuilder, | ||
sol, | ||
sol_types::{SolCall, SolConstructor}, | ||
uint, | ||
}; | ||
use e2e::{receipt, Account}; | ||
|
||
use crate::{ | ||
report::{ContractReport, FunctionReport}, | ||
CacheOpt, | ||
}; | ||
|
||
sol!( | ||
#[sol(rpc)] | ||
contract Erc1155MetadataUri { | ||
function uri(uint256 id) external view returns (string memory uri); | ||
function setTokenURI(uint256 tokenId, string memory tokenURI) external; | ||
function setBaseURI(string memory tokenURI) external; | ||
} | ||
); | ||
|
||
sol!("../examples/erc1155-metadata-uri/src/constructor.sol"); | ||
|
||
const URI: &str = "https://github.com/OpenZeppelin/rust-contracts-stylus"; | ||
const BASE_URI: &str = "https://github.com"; | ||
const TOKEN_URI: &str = "/some/token/uri"; | ||
|
||
pub async fn bench() -> eyre::Result<ContractReport> { | ||
let reports = run_with(CacheOpt::None).await?; | ||
let report = reports.into_iter().try_fold( | ||
ContractReport::new("Erc1155MetadataUri"), | ||
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 contract_addr = deploy(&alice, cache_opt).await?; | ||
|
||
let contract = Erc1155MetadataUri::new(contract_addr, &alice_wallet); | ||
|
||
let token_id = uint!(1_U256); | ||
|
||
// IMPORTANT: Order matters! | ||
use Erc1155MetadataUri::*; | ||
#[rustfmt::skip] | ||
let receipts = vec![ | ||
(setTokenURICall::SIGNATURE, receipt!(contract.setTokenURI(token_id, TOKEN_URI.to_owned()))?), | ||
(setBaseURICall::SIGNATURE, receipt!(contract.setBaseURI(BASE_URI.to_owned()))?), | ||
(uriCall::SIGNATURE, receipt!(contract.uri(token_id))?), | ||
]; | ||
|
||
receipts | ||
.into_iter() | ||
.map(FunctionReport::new) | ||
.collect::<eyre::Result<Vec<_>>>() | ||
} | ||
|
||
async fn deploy( | ||
account: &Account, | ||
cache_opt: CacheOpt, | ||
) -> eyre::Result<Address> { | ||
let args = | ||
Erc1155MetadataUriExample::constructorCall { uri_: URI.to_owned() }; | ||
let args = alloy::hex::encode(args.abi_encode()); | ||
crate::deploy(account, "erc1155-metadata-uri", Some(args), cache_opt).await | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
use alloy::{ | ||
network::{AnyNetwork, EthereumWallet}, | ||
primitives::Address, | ||
providers::ProviderBuilder, | ||
sol, | ||
sol_types::SolCall, | ||
uint, | ||
}; | ||
use e2e::{receipt, Account}; | ||
|
||
use crate::{ | ||
report::{ContractReport, FunctionReport}, | ||
CacheOpt, | ||
}; | ||
|
||
sol!( | ||
#[sol(rpc)] | ||
contract Erc1155Supply { | ||
function mint(address to, uint256 id, uint256 amount, bytes memory data) external; | ||
function totalSupply(uint256 id) external view returns (uint256); | ||
function totalSupply() external view returns (uint256); | ||
function exists(uint256 id) external view returns (bool); | ||
} | ||
); | ||
|
||
pub async fn bench() -> eyre::Result<ContractReport> { | ||
let reports = run_with(CacheOpt::None).await?; | ||
let report = reports | ||
.into_iter() | ||
.try_fold(ContractReport::new("Erc1155Supply"), 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_addr = alice.address(); | ||
let alice_wallet = ProviderBuilder::new() | ||
.network::<AnyNetwork>() | ||
.with_recommended_fillers() | ||
.wallet(EthereumWallet::from(alice.signer.clone())) | ||
.on_http(alice.url().parse()?); | ||
|
||
let contract_addr = deploy(&alice, cache_opt).await?; | ||
|
||
let contract = Erc1155Supply::new(contract_addr, &alice_wallet); | ||
|
||
let token = uint!(1_U256); | ||
let value = uint!(100_U256); | ||
|
||
// IMPORTANT: Order matters! | ||
use Erc1155Supply::*; | ||
#[rustfmt::skip] | ||
let receipts = vec![ | ||
(mintCall::SIGNATURE, receipt!(contract.mint(alice_addr, token, value, vec![].into()))?), | ||
(existsCall::SIGNATURE, receipt!(contract.exists(token))?), | ||
(totalSupply_0Call::SIGNATURE, receipt!(contract.totalSupply_0(token))?), | ||
(totalSupply_1Call::SIGNATURE, receipt!(contract.totalSupply_1())?), | ||
]; | ||
|
||
receipts | ||
.into_iter() | ||
.map(FunctionReport::new) | ||
.collect::<eyre::Result<Vec<_>>>() | ||
} | ||
|
||
async fn deploy( | ||
account: &Account, | ||
cache_opt: CacheOpt, | ||
) -> eyre::Result<Address> { | ||
crate::deploy(account, "erc1155-supply", None, cache_opt).await | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
doc-valid-idents = ["OpenZeppelin", ".."] |
Oops, something went wrong.