-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: ERC1155 URIStorage Extension (#431)
<!-- Thank you for your interest in contributing to OpenZeppelin! Consider opening an issue for discussion prior to submitting a PR. New features will be merged faster if they were first discussed and designed with the team. Describe the changes introduced in this pull request. Include any context necessary for understanding the PR's purpose. --> Since Erc1155-related benches and tests have become huge, decided to split them into separate files/directories. <!-- Fill in with issue number --> Resolves #351 \#### PR Checklist <!-- Before merging the pull request all of the following must be completed. Feel free to submit a PR or Draft PR even if some items are pending. Some of the items may not apply. --> - [x] Tests - [x] Documentation - [x] Changelog --------- Co-authored-by: Alisander Qoshqosh <[email protected]>
- Loading branch information
1 parent
504b083
commit 36b4dc1
Showing
20 changed files
with
765 additions
and
369 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
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
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 |
---|---|---|
@@ -1,6 +1,8 @@ | ||
//! Common extensions to the ERC-1155 standard. | ||
pub mod burnable; | ||
pub mod metadata_uri; | ||
pub mod uri_storage; | ||
|
||
pub use burnable::IErc1155Burnable; | ||
pub use metadata_uri::{Erc1155MetadataUri, IErc1155MetadataUri}; | ||
pub use uri_storage::Erc1155UriStorage; |
Oops, something went wrong.