From 64cb1ec8b03da5f1816864565b8698ecb54c0cb2 Mon Sep 17 00:00:00 2001 From: Alisander Qoshqosh Date: Thu, 17 Oct 2024 15:51:47 +0400 Subject: [PATCH 001/109] add storage guard --- Cargo.lock | 31 ++++++++++++++++++- .../src/token/erc721/extensions/enumerable.rs | 10 +++--- lib/motsu-proc/src/test.rs | 6 ++-- lib/motsu/Cargo.toml | 1 + lib/motsu/src/context.rs | 15 +++++++-- 5 files changed, 52 insertions(+), 11 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 953b3db07..cf79155e0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -256,7 +256,7 @@ dependencies = [ "cfg-if", "const-hex", "derive_arbitrary", - "derive_more", + "derive_more 0.99.18", "ethereum_ssz", "getrandom", "hex-literal", @@ -1379,6 +1379,28 @@ dependencies = [ "syn 2.0.68", ] +[[package]] +name = "derive_more" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4a9b99b9cbbe49445b21764dc0625032a89b145a2642e67603e1c936f5458d05" +dependencies = [ + "derive_more-impl", +] + +[[package]] +name = "derive_more-impl" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb7330aeadfbe296029522e6c40f315320aba36fc43a5b3632f3795348f3bd22" +dependencies = [ + "convert_case 0.6.0", + "proc-macro2", + "quote", + "syn 2.0.68", + "unicode-xid", +] + [[package]] name = "digest" version = "0.9.0" @@ -2448,6 +2470,7 @@ version = "0.2.0" dependencies = [ "const-hex", "dashmap 6.1.0", + "derive_more 1.0.0", "motsu-proc", "once_cell", "stylus-sdk", @@ -3984,6 +4007,12 @@ version = "0.1.13" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0336d538f7abc86d282a4189614dfaa90810dfc2c6f6427eaf88e16311dd225d" +[[package]] +name = "unicode-xid" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ebc1c04c71510c7f702b52b7c350734c9ff1295c464a03335b00bb84fc54f853" + [[package]] name = "url" version = "2.5.2" diff --git a/contracts/src/token/erc721/extensions/enumerable.rs b/contracts/src/token/erc721/extensions/enumerable.rs index f35bc97c0..20a892efd 100644 --- a/contracts/src/token/erc721/extensions/enumerable.rs +++ b/contracts/src/token/erc721/extensions/enumerable.rs @@ -454,7 +454,7 @@ mod tests { assert_eq!(owner, alice); let res = - contract._add_token_to_owner_enumeration(alice, token_id, &erc721); + contract._add_token_to_owner_enumeration(alice, token_id, &*erc721); assert!(res.is_ok()); let test_token_id = contract @@ -483,7 +483,7 @@ mod tests { assert_eq!(owner, alice); let res = - contract._add_token_to_owner_enumeration(alice, token_id, &erc721); + contract._add_token_to_owner_enumeration(alice, token_id, &*erc721); assert!(res.is_ok()); let err = @@ -525,7 +525,7 @@ mod tests { assert_eq!(owner, alice); let res = - contract._add_token_to_owner_enumeration(alice, token_id, &erc721); + contract._add_token_to_owner_enumeration(alice, token_id, &*erc721); assert!(res.is_ok()); // Transfer the token from ALICE to BOB. @@ -538,11 +538,11 @@ mod tests { assert_eq!(owner, BOB); let res = contract - ._remove_token_from_owner_enumeration(alice, token_id, &erc721); + ._remove_token_from_owner_enumeration(alice, token_id, &*erc721); assert!(res.is_ok()); let res = - contract._add_token_to_owner_enumeration(BOB, token_id, &erc721); + contract._add_token_to_owner_enumeration(BOB, token_id, &*erc721); assert!(res.is_ok()); let test_token_id = contract diff --git a/lib/motsu-proc/src/test.rs b/lib/motsu-proc/src/test.rs index 2e2425d1e..ffef40d8f 100644 --- a/lib/motsu-proc/src/test.rs +++ b/lib/motsu-proc/src/test.rs @@ -12,7 +12,7 @@ pub(crate) fn test(_attr: &TokenStream, input: TokenStream) -> TokenStream { let sig = &item_fn.sig; let fn_name = &sig.ident; let fn_return_type = &sig.output; - let fn_block = &item_fn.block; + let fn_stmts = &item_fn.block.stmts; let fn_args = &sig.inputs; // Currently, more than one contract per unit test is not supported. @@ -45,7 +45,9 @@ pub(crate) fn test(_attr: &TokenStream, input: TokenStream) -> TokenStream { fn #fn_name() #fn_return_type { use ::motsu::prelude::DefaultStorage; #( #contract_declarations )* - let res = #fn_block; + let res = { + #( #fn_stmts )* + }; ::motsu::prelude::Context::current().reset_storage(); res } diff --git a/lib/motsu/Cargo.toml b/lib/motsu/Cargo.toml index 2bfa39776..f290b3190 100644 --- a/lib/motsu/Cargo.toml +++ b/lib/motsu/Cargo.toml @@ -15,6 +15,7 @@ tiny-keccak.workspace = true stylus-sdk.workspace = true motsu-proc.workspace = true dashmap.workspace = true +derive_more = { version = "1.0.0", features = ["full"] } [lints] workspace = true diff --git a/lib/motsu/src/context.rs b/lib/motsu/src/context.rs index 381d504b9..b55b5e1c4 100644 --- a/lib/motsu/src/context.rs +++ b/lib/motsu/src/context.rs @@ -4,7 +4,13 @@ use std::{collections::HashMap, ptr}; use dashmap::DashMap; use once_cell::sync::Lazy; -use stylus_sdk::{alloy_primitives::uint, prelude::StorageType}; +use stylus_sdk::{ + alloy_primitives::{ + private::derive_more::{Deref, DerefMut}, + uint, + }, + prelude::StorageType, +}; use crate::prelude::{Bytes32, WORD_BYTES}; @@ -101,9 +107,12 @@ pub trait DefaultStorage: StorageType { /// Initializes fields of contract storage and child contract storages with /// default values. #[must_use] - fn default() -> Self { - unsafe { Self::new(uint!(0_U256), 0) } + fn default() -> StorageGuard { + StorageGuard(unsafe { Self::new(uint!(0_U256), 0) }) } } impl DefaultStorage for ST {} + +#[derive(Deref, DerefMut)] +pub struct StorageGuard(ST); From e2fafe80475f99b741c50adbd89debfc586947f3 Mon Sep 17 00:00:00 2001 From: Alisander Qoshqosh Date: Thu, 21 Nov 2024 17:49:11 +0400 Subject: [PATCH 002/109] comment non erc721 unit test --- contracts/src/access/control.rs | 3 ++- contracts/src/access/ownable.rs | 3 ++- contracts/src/access/ownable_two_step.rs | 3 ++- contracts/src/token/erc1155/mod.rs | 3 ++- contracts/src/token/erc20/extensions/burnable.rs | 3 ++- contracts/src/token/erc20/extensions/capped.rs | 3 ++- contracts/src/token/erc20/mod.rs | 3 ++- contracts/src/token/erc20/utils/safe_erc20.rs | 3 ++- contracts/src/token/erc721/extensions/burnable.rs | 3 ++- contracts/src/token/erc721/extensions/consecutive.rs | 3 ++- contracts/src/token/erc721/extensions/enumerable.rs | 3 ++- contracts/src/token/erc721/extensions/uri_storage.rs | 3 ++- contracts/src/utils/nonces.rs | 3 ++- contracts/src/utils/pausable.rs | 3 ++- contracts/src/utils/structs/bitmap.rs | 3 ++- contracts/src/utils/structs/checkpoints/mod.rs | 3 ++- 16 files changed, 32 insertions(+), 16 deletions(-) diff --git a/contracts/src/access/control.rs b/contracts/src/access/control.rs index 1ef997353..6b5f46c7f 100644 --- a/contracts/src/access/control.rs +++ b/contracts/src/access/control.rs @@ -365,7 +365,7 @@ impl AccessControl { } } } - +/* #[cfg(all(test, feature = "std"))] mod tests { use alloy_primitives::{address, Address}; @@ -593,3 +593,4 @@ mod tests { assert_eq!(role_revoked, false); } } +*/ diff --git a/contracts/src/access/ownable.rs b/contracts/src/access/ownable.rs index 50692973f..32e4a7907 100644 --- a/contracts/src/access/ownable.rs +++ b/contracts/src/access/ownable.rs @@ -191,7 +191,7 @@ impl Ownable { evm::log(OwnershipTransferred { previous_owner, new_owner }); } } - +/* #[cfg(all(test, feature = "std"))] mod tests { use alloy_primitives::{address, Address}; @@ -264,3 +264,4 @@ mod tests { assert_eq!(owner, ALICE); } } +*/ diff --git a/contracts/src/access/ownable_two_step.rs b/contracts/src/access/ownable_two_step.rs index f5d9a2be1..184f0fffb 100644 --- a/contracts/src/access/ownable_two_step.rs +++ b/contracts/src/access/ownable_two_step.rs @@ -208,7 +208,7 @@ impl Ownable2Step { self._ownable._transfer_ownership(new_owner); } } - +/* #[cfg(all(test, feature = "std"))] mod tests { use alloy_primitives::{address, Address}; @@ -351,3 +351,4 @@ mod tests { assert_eq!(contract.owner(), msg::sender()); } } +*/ diff --git a/contracts/src/token/erc1155/mod.rs b/contracts/src/token/erc1155/mod.rs index e128f6868..8edb516e0 100644 --- a/contracts/src/token/erc1155/mod.rs +++ b/contracts/src/token/erc1155/mod.rs @@ -1167,7 +1167,7 @@ enum Transfer { /// * `values` - Array of all amount of tokens being transferred. Batch { ids: Vec, values: Vec }, } - +/* #[cfg(all(test, feature = "std"))] mod tests { use alloy_primitives::{address, uint, Address, U256}; @@ -2193,3 +2193,4 @@ mod tests { assert_eq!(actual, expected); } } +*/ diff --git a/contracts/src/token/erc20/extensions/burnable.rs b/contracts/src/token/erc20/extensions/burnable.rs index fce7fe9a3..f2a583eed 100644 --- a/contracts/src/token/erc20/extensions/burnable.rs +++ b/contracts/src/token/erc20/extensions/burnable.rs @@ -76,7 +76,7 @@ impl IErc20Burnable for Erc20 { self._burn(account, value) } } - +/* #[cfg(all(test, feature = "std"))] mod tests { use alloy_primitives::{address, uint, Address, U256}; @@ -184,3 +184,4 @@ mod tests { assert!(matches!(result, Err(Error::InsufficientAllowance(_)))); } } +*/ diff --git a/contracts/src/token/erc20/extensions/capped.rs b/contracts/src/token/erc20/extensions/capped.rs index a971900b5..f37d579c7 100644 --- a/contracts/src/token/erc20/extensions/capped.rs +++ b/contracts/src/token/erc20/extensions/capped.rs @@ -50,7 +50,7 @@ impl Capped { self._cap.get() } } - +/* #[cfg(all(test, feature = "std"))] mod tests { use alloy_primitives::uint; @@ -68,3 +68,4 @@ mod tests { assert_eq!(contract.cap(), value); } } +*/ diff --git a/contracts/src/token/erc20/mod.rs b/contracts/src/token/erc20/mod.rs index 91399f425..ac8c294d6 100644 --- a/contracts/src/token/erc20/mod.rs +++ b/contracts/src/token/erc20/mod.rs @@ -573,7 +573,7 @@ impl Erc20 { Ok(()) } } - +/* #[cfg(all(test, feature = "std"))] mod tests { use alloy_primitives::{address, uint, Address, U256}; @@ -925,3 +925,4 @@ mod tests { assert_eq!(actual, expected); } } +*/ diff --git a/contracts/src/token/erc20/utils/safe_erc20.rs b/contracts/src/token/erc20/utils/safe_erc20.rs index 1669a69cd..7d0b54c4b 100644 --- a/contracts/src/token/erc20/utils/safe_erc20.rs +++ b/contracts/src/token/erc20/utils/safe_erc20.rs @@ -388,7 +388,7 @@ impl SafeErc20 { }) } } - +/* #[cfg(all(test, feature = "std"))] mod tests { use super::SafeErc20; @@ -431,3 +431,4 @@ mod tests { ); } } +*/ diff --git a/contracts/src/token/erc721/extensions/burnable.rs b/contracts/src/token/erc721/extensions/burnable.rs index 31d5701b8..b8e364398 100644 --- a/contracts/src/token/erc721/extensions/burnable.rs +++ b/contracts/src/token/erc721/extensions/burnable.rs @@ -51,7 +51,7 @@ impl IErc721Burnable for Erc721 { Ok(()) } } - +/* #[cfg(all(test, feature = "std"))] mod tests { use alloy_primitives::{address, uint, Address}; @@ -223,3 +223,4 @@ mod tests { )); } } +*/ diff --git a/contracts/src/token/erc721/extensions/consecutive.rs b/contracts/src/token/erc721/extensions/consecutive.rs index 302cb56f4..32576f71f 100644 --- a/contracts/src/token/erc721/extensions/consecutive.rs +++ b/contracts/src/token/erc721/extensions/consecutive.rs @@ -793,7 +793,7 @@ impl Erc721Consecutive { Ok(owner) } } - +/* #[cfg(all(test, feature = "std"))] mod tests { use alloy_primitives::{address, uint, Address, U256}; @@ -1333,3 +1333,4 @@ mod tests { )); } } +*/ diff --git a/contracts/src/token/erc721/extensions/enumerable.rs b/contracts/src/token/erc721/extensions/enumerable.rs index 20a892efd..1e41280aa 100644 --- a/contracts/src/token/erc721/extensions/enumerable.rs +++ b/contracts/src/token/erc721/extensions/enumerable.rs @@ -323,7 +323,7 @@ impl Erc721Enumerable { } } } - +/* #[cfg(all(test, feature = "std"))] mod tests { use alloy_primitives::{address, uint, Address, U256}; @@ -563,3 +563,4 @@ mod tests { assert_eq!(actual, expected); } } +*/ diff --git a/contracts/src/token/erc721/extensions/uri_storage.rs b/contracts/src/token/erc721/extensions/uri_storage.rs index 644a3dc22..f24ab3d59 100644 --- a/contracts/src/token/erc721/extensions/uri_storage.rs +++ b/contracts/src/token/erc721/extensions/uri_storage.rs @@ -102,7 +102,7 @@ impl Erc721UriStorage { Ok(uri) } } - +/* #[cfg(all(test, feature = "std"))] mod tests { use alloy_primitives::U256; @@ -181,3 +181,4 @@ mod tests { ); } } +*/ diff --git a/contracts/src/utils/nonces.rs b/contracts/src/utils/nonces.rs index 752565174..d5d08e598 100644 --- a/contracts/src/utils/nonces.rs +++ b/contracts/src/utils/nonces.rs @@ -106,7 +106,7 @@ impl Nonces { Ok(()) } } - +/* #[cfg(all(test, feature = "std"))] mod tests { use alloy_primitives::U256; @@ -153,3 +153,4 @@ mod tests { )); } } +*/ diff --git a/contracts/src/utils/pausable.rs b/contracts/src/utils/pausable.rs index 1a2ed5ae9..e154a70ec 100644 --- a/contracts/src/utils/pausable.rs +++ b/contracts/src/utils/pausable.rs @@ -146,7 +146,7 @@ impl Pausable { Ok(()) } } - +/* #[cfg(all(test, feature = "std"))] mod tests { use crate::utils::pausable::{Error, Pausable}; @@ -238,3 +238,4 @@ mod tests { assert_eq!(contract.paused(), false); } } +*/ diff --git a/contracts/src/utils/structs/bitmap.rs b/contracts/src/utils/structs/bitmap.rs index 8c9a8d188..3d3ba5af6 100644 --- a/contracts/src/utils/structs/bitmap.rs +++ b/contracts/src/utils/structs/bitmap.rs @@ -91,7 +91,7 @@ impl BitMap { index >> 8 } } - +/* #[cfg(all(test, feature = "std"))] mod tests { use alloy_primitives::{private::proptest::proptest, U256}; @@ -130,3 +130,4 @@ mod tests { }); } } +*/ diff --git a/contracts/src/utils/structs/checkpoints/mod.rs b/contracts/src/utils/structs/checkpoints/mod.rs index 88b1eb22c..55062b617 100644 --- a/contracts/src/utils/structs/checkpoints/mod.rs +++ b/contracts/src/utils/structs/checkpoints/mod.rs @@ -366,7 +366,7 @@ impl Trace { new_checkpoint._value.set(value); } } - +/* #[cfg(all(test, feature = "std"))] mod tests { use alloy_primitives::uint; @@ -526,3 +526,4 @@ mod tests { )); } } +*/ From 02d3468c77083ff79f2f57dc8bc26d3632abeebe Mon Sep 17 00:00:00 2001 From: Alisander Qoshqosh Date: Fri, 22 Nov 2024 10:18:20 +0400 Subject: [PATCH 003/109] ++ --- Cargo.lock | 1 + lib/motsu/Cargo.toml | 1 + lib/motsu/src/context.rs | 81 ++++++++++++++++++++++++++++++++++------ lib/motsu/src/prelude.rs | 2 +- 4 files changed, 73 insertions(+), 12 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index cf79155e0..87ce1d701 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2468,6 +2468,7 @@ checksum = "7843ec2de400bcbc6a6328c958dc38e5359da6e93e72e37bc5246bf1ae776389" name = "motsu" version = "0.2.0" dependencies = [ + "alloy-primitives", "const-hex", "dashmap 6.1.0", "derive_more 1.0.0", diff --git a/lib/motsu/Cargo.toml b/lib/motsu/Cargo.toml index f290b3190..dc4135112 100644 --- a/lib/motsu/Cargo.toml +++ b/lib/motsu/Cargo.toml @@ -16,6 +16,7 @@ stylus-sdk.workspace = true motsu-proc.workspace = true dashmap.workspace = true derive_more = { version = "1.0.0", features = ["full"] } +alloy-primitives = { workspace = true, features = ["arbitrary", "rand"] } [lints] workspace = true diff --git a/lib/motsu/src/context.rs b/lib/motsu/src/context.rs index b55b5e1c4..4c0ba38ad 100644 --- a/lib/motsu/src/context.rs +++ b/lib/motsu/src/context.rs @@ -2,15 +2,10 @@ use std::{collections::HashMap, ptr}; +use alloy_primitives::Address; use dashmap::DashMap; use once_cell::sync::Lazy; -use stylus_sdk::{ - alloy_primitives::{ - private::derive_more::{Deref, DerefMut}, - uint, - }, - prelude::StorageType, -}; +use stylus_sdk::{alloy_primitives::uint, prelude::StorageType}; use crate::prelude::{Bytes32, WORD_BYTES}; @@ -107,12 +102,76 @@ pub trait DefaultStorage: StorageType { /// Initializes fields of contract storage and child contract storages with /// default values. #[must_use] - fn default() -> StorageGuard { - StorageGuard(unsafe { Self::new(uint!(0_U256), 0) }) + fn default() -> Contract { + Contract::random() } } impl DefaultStorage for ST {} -#[derive(Deref, DerefMut)] -pub struct StorageGuard(ST); +pub struct ContractCall { + contract: ST, + caller: Address, +} + +impl ::core::ops::Deref for ContractCall { + type Target = ST; + + #[inline] + fn deref(&self) -> &Self::Target { + &self.contract + } +} + +impl ::core::ops::DerefMut for ContractCall { + #[inline] + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.contract + } +} + +pub struct Contract { + phantom: ::core::marker::PhantomData, + address: Address, +} + +impl Contract { + pub fn new(address: Address) -> Self { + // TODO#q: save contract instance to storage + Self { phantom: ::core::marker::PhantomData, address } + } + + pub fn random() -> Self { + Self::new(Address::random()) + } +} + +pub struct Account { + address: Address, +} + +impl Account { + pub const fn new(address: Address) -> Self { + Self { address } + } + + pub fn random() -> Self { + Self::new(Address::random()) + } + + // TODO#q: we also need an initializer + + pub fn deploys(&self) -> Contract { + Contract::random() + } + + pub fn uses( + &self, + contract: &mut Contract, + ) -> ContractCall { + ContractCall { + contract: unsafe { ST::new(uint!(0_U256), 0) }, + caller: self.address, + } + } +} diff --git a/lib/motsu/src/prelude.rs b/lib/motsu/src/prelude.rs index 5c8798297..5af1b5e21 100644 --- a/lib/motsu/src/prelude.rs +++ b/lib/motsu/src/prelude.rs @@ -1,5 +1,5 @@ //! Common imports for `motsu` tests. pub use crate::{ - context::{Context, DefaultStorage}, + context::{Account, Context, ContractCall, DefaultStorage}, shims::*, }; From d126f0e50d25e47aa3091d2f3b2fd02caadfe334 Mon Sep 17 00:00:00 2001 From: Alisander Qoshqosh Date: Fri, 22 Nov 2024 10:55:12 +0400 Subject: [PATCH 004/109] ++ --- lib/motsu/src/context.rs | 21 +++++++++++++++++++-- lib/motsu/src/shims.rs | 5 +++-- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/lib/motsu/src/context.rs b/lib/motsu/src/context.rs index 4c0ba38ad..e85777387 100644 --- a/lib/motsu/src/context.rs +++ b/lib/motsu/src/context.rs @@ -52,6 +52,16 @@ impl Context { pub fn reset_storage(self) { STORAGE.remove(&self.thread_name); } + + pub(crate) fn set_msg_sender(self, msg_sender: Address) { + let mut storage = STORAGE.entry(self.thread_name).or_default(); + let _ = storage.msg_sender.insert(msg_sender); + } + + pub(crate) fn get_msg_sender(self) -> Address { + let storage = STORAGE.entry(self.thread_name).or_default(); + storage.msg_sender.expect("msg_sender should be set") + } } /// Storage mock: A global mutable key-value store. @@ -80,6 +90,7 @@ impl ThreadName { /// Storage for unit test's mock data. #[derive(Default)] struct MockStorage { + msg_sender: Option
, /// Contract's mock data storage. contract_data: HashMap, } @@ -119,6 +130,7 @@ impl ::core::ops::Deref for ContractCall { #[inline] fn deref(&self) -> &Self::Target { + Context::current().set_msg_sender(self.caller); &self.contract } } @@ -126,6 +138,7 @@ impl ::core::ops::Deref for ContractCall { impl ::core::ops::DerefMut for ContractCall { #[inline] fn deref_mut(&mut self) -> &mut Self::Target { + Context::current().set_msg_sender(self.caller); &mut self.contract } } @@ -141,6 +154,8 @@ impl Contract { Self { phantom: ::core::marker::PhantomData, address } } + // TODO#q: probably we need generic initializer + pub fn random() -> Self { Self::new(Address::random()) } @@ -159,12 +174,14 @@ impl Account { Self::new(Address::random()) } - // TODO#q: we also need an initializer - pub fn deploys(&self) -> Contract { Contract::random() } + pub fn address(&self) -> Address { + self.address + } + pub fn uses( &self, contract: &mut Contract, diff --git a/lib/motsu/src/shims.rs b/lib/motsu/src/shims.rs index a20ebdfce..b5128e723 100644 --- a/lib/motsu/src/shims.rs +++ b/lib/motsu/src/shims.rs @@ -145,8 +145,9 @@ pub const EOA_CODEHASH: &[u8; 66] = /// May panic if fails to parse `MSG_SENDER` as an address. #[no_mangle] pub unsafe extern "C" fn msg_sender(sender: *mut u8) { - let addr = const_hex::const_decode_to_array::<20>(MSG_SENDER).unwrap(); - std::ptr::copy(addr.as_ptr(), sender, 20); + let msg_sender = Context::current().get_msg_sender(); + let x: &[u8; 20] = msg_sender.as_ref(); + std::ptr::copy(x.as_ptr(), sender, 20); } /// Gets the address of the current program. The semantics are equivalent to From ef905e50ebc127a134e7579c4110d8684c0a1b6d Mon Sep 17 00:00:00 2001 From: Alisander Qoshqosh Date: Fri, 22 Nov 2024 11:50:39 +0400 Subject: [PATCH 005/109] ++ --- lib/motsu/src/context.rs | 62 ++++++++++++++++++++++++++++++++-------- 1 file changed, 50 insertions(+), 12 deletions(-) diff --git a/lib/motsu/src/context.rs b/lib/motsu/src/context.rs index e85777387..15dcc42ba 100644 --- a/lib/motsu/src/context.rs +++ b/lib/motsu/src/context.rs @@ -25,7 +25,15 @@ impl Context { /// Get the value at `key` in storage. pub(crate) fn get_bytes(self, key: &Bytes32) -> Bytes32 { let storage = STORAGE.entry(self.thread_name).or_default(); - storage.contract_data.get(key).copied().unwrap_or_default() + let msg_receiver = + storage.msg_receiver.expect("msg_receiver should be set"); + storage + .contracts + .get(&msg_receiver) + .expect("contract receiver should have a storage initialised") + .get(key) + .copied() + .unwrap_or_default() } /// Get the raw value at `key` in storage and write it to `value`. @@ -38,7 +46,13 @@ impl Context { /// Set the value at `key` in storage to `value`. pub(crate) fn set_bytes(self, key: Bytes32, value: Bytes32) { let mut storage = STORAGE.entry(self.thread_name).or_default(); - storage.contract_data.insert(key, value); + let msg_receiver = + storage.msg_receiver.expect("msg_receiver should be set"); + storage + .contracts + .get_mut(&msg_receiver) + .expect("contract receiver should have a storage initialised") + .insert(key, value); } /// Set the raw value at `key` in storage to `value`. @@ -62,6 +76,24 @@ impl Context { let storage = STORAGE.entry(self.thread_name).or_default(); storage.msg_sender.expect("msg_sender should be set") } + + pub(crate) fn set_msg_receiver(self, msg_receiver: Address) { + let mut storage = STORAGE.entry(self.thread_name).or_default(); + let _ = storage.msg_receiver.insert(msg_receiver); + } + + pub(crate) fn get_msg_receiver(self) -> Address { + let storage = STORAGE.entry(self.thread_name).or_default(); + storage.msg_receiver.expect("msg_receiver should be set") + } + + pub(crate) fn init_contract(self, contract_address: Address) { + let mut storage = STORAGE.entry(self.thread_name).or_default(); + if storage.contracts.insert(contract_address, HashMap::new()).is_some() + { + panic!("contract storage already initialized - contract_address: {contract_address}"); + } + } } /// Storage mock: A global mutable key-value store. @@ -90,11 +122,16 @@ impl ThreadName { /// Storage for unit test's mock data. #[derive(Default)] struct MockStorage { + /// Address of the message sender. msg_sender: Option
, + /// Address of the contract that is currently receiving the message. + msg_receiver: Option
, /// Contract's mock data storage. - contract_data: HashMap, + contracts: HashMap, } +type ContractStorage = HashMap; + /// Read the word from location pointed by `ptr`. unsafe fn read_bytes32(ptr: *const u8) -> Bytes32 { let mut res = Bytes32::default(); @@ -122,7 +159,8 @@ impl DefaultStorage for ST {} pub struct ContractCall { contract: ST, - caller: Address, + caller_address: Address, + contract_address: Address, } impl ::core::ops::Deref for ContractCall { @@ -130,7 +168,8 @@ impl ::core::ops::Deref for ContractCall { #[inline] fn deref(&self) -> &Self::Target { - Context::current().set_msg_sender(self.caller); + Context::current().set_msg_sender(self.caller_address); + Context::current().set_msg_receiver(self.contract_address); &self.contract } } @@ -138,7 +177,8 @@ impl ::core::ops::Deref for ContractCall { impl ::core::ops::DerefMut for ContractCall { #[inline] fn deref_mut(&mut self) -> &mut Self::Target { - Context::current().set_msg_sender(self.caller); + Context::current().set_msg_sender(self.caller_address); + Context::current().set_msg_receiver(self.contract_address); &mut self.contract } } @@ -150,7 +190,8 @@ pub struct Contract { impl Contract { pub fn new(address: Address) -> Self { - // TODO#q: save contract instance to storage + Context::current().init_contract(address); + Self { phantom: ::core::marker::PhantomData, address } } @@ -174,10 +215,6 @@ impl Account { Self::new(Address::random()) } - pub fn deploys(&self) -> Contract { - Contract::random() - } - pub fn address(&self) -> Address { self.address } @@ -188,7 +225,8 @@ impl Account { ) -> ContractCall { ContractCall { contract: unsafe { ST::new(uint!(0_U256), 0) }, - caller: self.address, + caller_address: self.address, + contract_address: contract.address, } } } From 7883a6490555f7b8891cac02f540020e6e0666f2 Mon Sep 17 00:00:00 2001 From: Alisander Qoshqosh Date: Fri, 22 Nov 2024 12:47:17 +0400 Subject: [PATCH 006/109] add ping pong test case --- Cargo.lock | 1 + lib/motsu-proc/src/test.rs | 5 -- lib/motsu/Cargo.toml | 1 + lib/motsu/src/context.rs | 10 ++++ lib/motsu/src/lib.rs | 95 ++++++++++++++++++++++++++++++++++++++ 5 files changed, 107 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 87ce1d701..e7d6add19 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2469,6 +2469,7 @@ name = "motsu" version = "0.2.0" dependencies = [ "alloy-primitives", + "alloy-sol-types", "const-hex", "dashmap 6.1.0", "derive_more 1.0.0", diff --git a/lib/motsu-proc/src/test.rs b/lib/motsu-proc/src/test.rs index ffef40d8f..910ba4f25 100644 --- a/lib/motsu-proc/src/test.rs +++ b/lib/motsu-proc/src/test.rs @@ -15,11 +15,6 @@ pub(crate) fn test(_attr: &TokenStream, input: TokenStream) -> TokenStream { let fn_stmts = &item_fn.block.stmts; let fn_args = &sig.inputs; - // Currently, more than one contract per unit test is not supported. - if fn_args.len() > 1 { - error!(fn_args, "expected at most one contract in test signature"); - } - // Whether 1 or none contracts will be declared. let contract_declarations = fn_args.into_iter().map(|arg| { let FnArg::Typed(arg) = arg else { diff --git a/lib/motsu/Cargo.toml b/lib/motsu/Cargo.toml index dc4135112..5f54f0800 100644 --- a/lib/motsu/Cargo.toml +++ b/lib/motsu/Cargo.toml @@ -17,6 +17,7 @@ motsu-proc.workspace = true dashmap.workspace = true derive_more = { version = "1.0.0", features = ["full"] } alloy-primitives = { workspace = true, features = ["arbitrary", "rand"] } +alloy-sol-types.workspace = true [lints] workspace = true diff --git a/lib/motsu/src/context.rs b/lib/motsu/src/context.rs index 15dcc42ba..015f4b78a 100644 --- a/lib/motsu/src/context.rs +++ b/lib/motsu/src/context.rs @@ -163,6 +163,12 @@ pub struct ContractCall { contract_address: Address, } +impl ContractCall { + pub fn address(&self) -> Address { + self.contract_address + } +} + impl ::core::ops::Deref for ContractCall { type Target = ST; @@ -200,6 +206,10 @@ impl Contract { pub fn random() -> Self { Self::new(Address::random()) } + + pub fn address(&self) -> Address { + self.address + } } pub struct Account { diff --git a/lib/motsu/src/lib.rs b/lib/motsu/src/lib.rs index 88eb49707..f2dd0a423 100644 --- a/lib/motsu/src/lib.rs +++ b/lib/motsu/src/lib.rs @@ -48,3 +48,98 @@ pub mod prelude; mod shims; pub use motsu_proc::test; + +#[cfg(all(test))] +mod tests { + #![deny(rustdoc::broken_intra_doc_links)] + extern crate alloc; + + use alloy_primitives::uint; + use stylus_sdk::{ + alloy_primitives::{Address, U256}, + call::Call, + prelude::{public, sol_storage, TopLevelStorage}, + }; + + use crate::context::Account; + + sol_storage! { + pub struct PingContract { + uint256 _pings_count; + // TODO#q: add last pinged address. + } + } + + #[public] + impl PingContract { + fn ping(&mut self, to: Address, value: U256) -> Result> { + let receiver = receiver::PongContract::new(to); + let call = Call::new_in(self); + let value = + receiver.pong(call, value).expect("should pong successfully"); + + let pings_count = self._pings_count.get(); + self._pings_count.set(pings_count + uint!(1_U256)); + Ok(value) + } + + fn ping_count(&self) -> U256 { + self._pings_count.get() + } + } + + unsafe impl TopLevelStorage for PingContract {} + + mod receiver { + use super::alloc; + stylus_sdk::stylus_proc::sol_interface! { + interface PongContract { + #[allow(missing_docs)] + function pong(uint256 value) external returns (uint256); + } + } + } + + sol_storage! { + pub struct PongContract { + uint256 _pongs_count; + uint256 _value; + } + } + + #[public] + impl PongContract { + pub fn pong(&mut self, value: U256) -> Result> { + let pongs_count = self._pongs_count.get(); + self._pongs_count.set(pongs_count + uint!(1_U256)); + Ok(value + uint!(1_U256)) + } + + fn pong_count(&self) -> U256 { + self._pongs_count.get() + } + } + + unsafe impl TopLevelStorage for PongContract {} + + #[test] + fn ping_pong_works() { + use crate::prelude::DefaultStorage; + let mut ping = PingContract::default(); + let ping = &mut ping; + let mut pong = PongContract::default(); + let pong = &mut pong; + + let alice = Account::random(); + let mut ping = alice.uses(ping); + let mut pong = alice.uses(pong); + + let value = uint!(1_U256); + let ponged_value = + ping.ping(pong.address(), value).expect("should ping successfully"); + + assert_eq!(ponged_value, value + uint!(1_U256)); + assert_eq!(ping.ping_count(), uint!(1_U256)); + assert_eq!(pong.pong_count(), uint!(1_U256)); + } +} From f49daf55794635bbd6ec74b761a3d2b012613b9e Mon Sep 17 00:00:00 2001 From: Alisander Qoshqosh Date: Fri, 22 Nov 2024 14:30:47 +0400 Subject: [PATCH 007/109] add test router --- lib/motsu/src/context.rs | 85 ++++++++++++++++++++++++++++++---------- lib/motsu/src/lib.rs | 14 ++++++- 2 files changed, 76 insertions(+), 23 deletions(-) diff --git a/lib/motsu/src/context.rs b/lib/motsu/src/context.rs index 015f4b78a..988e39474 100644 --- a/lib/motsu/src/context.rs +++ b/lib/motsu/src/context.rs @@ -1,11 +1,16 @@ //! Unit-testing context for Stylus contracts. -use std::{collections::HashMap, ptr}; +use std::{borrow::BorrowMut, collections::HashMap, ptr, sync::Mutex}; use alloy_primitives::Address; use dashmap::DashMap; use once_cell::sync::Lazy; -use stylus_sdk::{alloy_primitives::uint, prelude::StorageType}; +use stylus_sdk::{ + abi::Router, + alloy_primitives::uint, + prelude::{StorageType, TopLevelStorage}, + ArbResult, +}; use crate::prelude::{Bytes32, WORD_BYTES}; @@ -28,7 +33,7 @@ impl Context { let msg_receiver = storage.msg_receiver.expect("msg_receiver should be set"); storage - .contracts + .contract_data .get(&msg_receiver) .expect("contract receiver should have a storage initialised") .get(key) @@ -49,7 +54,7 @@ impl Context { let msg_receiver = storage.msg_receiver.expect("msg_receiver should be set"); storage - .contracts + .contract_data .get_mut(&msg_receiver) .expect("contract receiver should have a storage initialised") .insert(key, value); @@ -87,15 +92,44 @@ impl Context { storage.msg_receiver.expect("msg_receiver should be set") } - pub(crate) fn init_contract(self, contract_address: Address) { + pub(crate) fn init_contract( + self, + contract_address: Address, + ) { let mut storage = STORAGE.entry(self.thread_name).or_default(); - if storage.contracts.insert(contract_address, HashMap::new()).is_some() + if storage + .contract_data + .insert(contract_address, HashMap::new()) + .is_some() + { + panic!("contract storage already initialized - contract_address: {contract_address}"); + } + + if storage + .contract_router + .insert( + contract_address, + Mutex::new(Box::new(unsafe { ST::new(uint!(0_U256), 0) })), + ) + .is_some() { panic!("contract storage already initialized - contract_address: {contract_address}"); } } } +/// Read the word from location pointed by `ptr`. +unsafe fn read_bytes32(ptr: *const u8) -> Bytes32 { + let mut res = Bytes32::default(); + ptr::copy(ptr, res.as_mut_ptr(), WORD_BYTES); + res +} + +/// Write the word `bytes` to the location pointed by `ptr`. +unsafe fn write_bytes32(ptr: *mut u8, bytes: Bytes32) { + ptr::copy(bytes.as_ptr(), ptr, WORD_BYTES); +} + /// Storage mock: A global mutable key-value store. /// Allows concurrent access. /// @@ -119,34 +153,40 @@ impl ThreadName { } } -/// Storage for unit test's mock data. +/// Storage for unit test's mock data.x #[derive(Default)] struct MockStorage { /// Address of the message sender. msg_sender: Option
, /// Address of the contract that is currently receiving the message. msg_receiver: Option
, - /// Contract's mock data storage. - contracts: HashMap, + /// Contract's address to mock data storage mapping. + contract_data: HashMap, + // Contract's address to router mapping. + // NOTE: Mutex is important since contract type is not `Sync`. + contract_router: HashMap>>, } type ContractStorage = HashMap; -/// Read the word from location pointed by `ptr`. -unsafe fn read_bytes32(ptr: *const u8) -> Bytes32 { - let mut res = Bytes32::default(); - ptr::copy(ptr, res.as_mut_ptr(), WORD_BYTES); - res +/// A trait for routing messages to the appropriate selector in tests. +pub trait TestRouter: Send { + /// Tries to find and execute a method for the given selector, returning + /// `None` if none is found. + fn route(&mut self, selector: u32, input: &[u8]) -> Option; } -/// Write the word `bytes` to the location pointed by `ptr`. -unsafe fn write_bytes32(ptr: *mut u8, bytes: Bytes32) { - ptr::copy(bytes.as_ptr(), ptr, WORD_BYTES); +impl + TopLevelStorage + BorrowMut + Send> TestRouter + for R +{ + fn route(&mut self, selector: u32, input: &[u8]) -> Option { + >::route(self, selector, input) + } } /// Initializes fields of contract storage and child contract storages with /// default values. -pub trait DefaultStorage: StorageType { +pub trait DefaultStorage: StorageType + TestRouter + 'static { /// Initializes fields of contract storage and child contract storages with /// default values. #[must_use] @@ -155,7 +195,7 @@ pub trait DefaultStorage: StorageType { } } -impl DefaultStorage for ST {} +impl DefaultStorage for ST {} pub struct ContractCall { contract: ST, @@ -194,9 +234,9 @@ pub struct Contract { address: Address, } -impl Contract { +impl Contract { pub fn new(address: Address) -> Self { - Context::current().init_contract(address); + Context::current().init_contract::(address); Self { phantom: ::core::marker::PhantomData, address } } @@ -217,14 +257,17 @@ pub struct Account { } impl Account { + #[must_use] pub const fn new(address: Address) -> Self { Self { address } } + #[must_use] pub fn random() -> Self { Self::new(Address::random()) } + #[must_use] pub fn address(&self) -> Address { self.address } diff --git a/lib/motsu/src/lib.rs b/lib/motsu/src/lib.rs index f2dd0a423..99df163d4 100644 --- a/lib/motsu/src/lib.rs +++ b/lib/motsu/src/lib.rs @@ -58,10 +58,10 @@ mod tests { use stylus_sdk::{ alloy_primitives::{Address, U256}, call::Call, - prelude::{public, sol_storage, TopLevelStorage}, + prelude::{public, sol_storage, StorageType, TopLevelStorage}, }; - use crate::context::Account; + use crate::context::{Account, TestRouter}; sol_storage! { pub struct PingContract { @@ -142,4 +142,14 @@ mod tests { assert_eq!(ping.ping_count(), uint!(1_U256)); assert_eq!(pong.pong_count(), uint!(1_U256)); } + + #[test] + fn smoke() { + let mut ping_contract = unsafe { PingContract::new(uint!(0_U256), 0) }; + ::route( + &mut ping_contract, + 0, + &[0, 0, 0, 0], + ); + } } From 1dc7519ee3eeea9ad40beb76f4a17a302ad8b928 Mon Sep 17 00:00:00 2001 From: Alisander Qoshqosh Date: Fri, 22 Nov 2024 17:42:53 +0400 Subject: [PATCH 008/109] add call shim --- lib/motsu/src/context.rs | 79 +++++++++++++++++++++++++++++++++++++++- lib/motsu/src/shims.rs | 15 ++++---- 2 files changed, 85 insertions(+), 9 deletions(-) diff --git a/lib/motsu/src/context.rs b/lib/motsu/src/context.rs index 988e39474..cd88228a6 100644 --- a/lib/motsu/src/context.rs +++ b/lib/motsu/src/context.rs @@ -1,6 +1,6 @@ //! Unit-testing context for Stylus contracts. -use std::{borrow::BorrowMut, collections::HashMap, ptr, sync::Mutex}; +use std::{borrow::BorrowMut, collections::HashMap, ptr, slice, sync::Mutex}; use alloy_primitives::Address; use dashmap::DashMap; @@ -24,6 +24,7 @@ impl Context { /// Get test context associated with the current test thread. #[must_use] pub fn current() -> Self { + // TODO#q: STORAGE entry call here Self { thread_name: ThreadName::current() } } @@ -116,6 +117,80 @@ impl Context { panic!("contract storage already initialized - contract_address: {contract_address}"); } } + + pub(crate) unsafe fn call_contract_raw( + self, + address: *const u8, + calldata: *const u8, + calldata_len: usize, + return_data_len: *mut usize, + ) -> u8 { + let address_bytes = slice::from_raw_parts(address, 20); + let address = Address::from_slice(address_bytes); + + let input = slice::from_raw_parts(calldata, calldata_len); + let selector = + u32::from_be_bytes(TryInto::try_into(&input[..4]).unwrap()); + + match self.call_contract(address, selector, &input[4..]) { + Ok(res) => { + return_data_len.write(res.len()); + self.set_return_data(res); + 0 + } + Err(err) => { + return_data_len.write(err.len()); + self.set_return_data(err); + 1 + } + } + } + + pub(crate) fn set_return_data(&self, data: Vec) { + let _ = STORAGE + .entry(self.thread_name.clone()) + .or_default() + .call_output + .insert(data); + } + + pub(crate) fn call_contract( + &self, + contract_address: Address, + selector: u32, + input: &[u8], + ) -> ArbResult { + let storage = STORAGE.entry(self.thread_name.clone()).or_default(); + + let router = storage + .contract_router + .get(&contract_address) + .expect("contract router should be set"); + + let mut router = router.lock().expect("should lock test router"); + router.route(selector, input).unwrap_or_else(|| { + panic!("selector not found - selector: {selector}") + }) + } + + pub(crate) unsafe fn read_return_data_raw( + self, + dest: *mut u8, + size: usize, + ) -> usize { + let data = self.get_return_data(); + ptr::copy(data.as_ptr(), dest, size); + 0 + } + + pub(crate) fn get_return_data(&self) -> Vec { + STORAGE + .entry(self.thread_name.clone()) + .or_default() + .call_output + .take() + .expect("call_output should be set") + } } /// Read the word from location pointed by `ptr`. @@ -165,6 +240,8 @@ struct MockStorage { // Contract's address to router mapping. // NOTE: Mutex is important since contract type is not `Sync`. contract_router: HashMap>>, + // Output of a contract call. + call_output: Option>, } type ContractStorage = HashMap; diff --git a/lib/motsu/src/shims.rs b/lib/motsu/src/shims.rs index b5128e723..5dc478bb6 100644 --- a/lib/motsu/src/shims.rs +++ b/lib/motsu/src/shims.rs @@ -236,10 +236,7 @@ pub unsafe extern "C" fn read_return_data( _offset: usize, _size: usize, ) -> usize { - // TODO: #156 - // No-op: we do not use this function in our unit-tests, - // but the binary does include it. - 0 + Context::current().read_return_data_raw(_dest, _size) } /// Calls the contract at the given address with options for passing value and @@ -265,10 +262,12 @@ pub unsafe extern "C" fn call_contract( _gas: u64, _return_data_len: *mut usize, ) -> u8 { - // TODO: #156 - // No-op: we do not use this function in our unit-tests, - // but the binary does include it. - 0 + Context::current().call_contract_raw( + _contract, + _calldata, + _calldata_len, + _return_data_len, + ) } /// Static calls the contract at the given address, with the option to limit the From 092a370d69ec5cb67ec0466a57039da986396108 Mon Sep 17 00:00:00 2001 From: Alisander Qoshqosh Date: Fri, 22 Nov 2024 18:55:52 +0400 Subject: [PATCH 009/109] ++ --- lib/motsu/src/context.rs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/lib/motsu/src/context.rs b/lib/motsu/src/context.rs index cd88228a6..2009c7ef9 100644 --- a/lib/motsu/src/context.rs +++ b/lib/motsu/src/context.rs @@ -160,7 +160,11 @@ impl Context { selector: u32, input: &[u8], ) -> ArbResult { - let storage = STORAGE.entry(self.thread_name.clone()).or_default(); + let mut storage = STORAGE.entry(self.thread_name.clone()).or_default(); + + let previous_receiver = storage.msg_receiver.replace(contract_address); + let previous_sender = storage.msg_sender.take(); + storage.msg_sender = previous_receiver; // now the sender is current contract let router = storage .contract_router @@ -168,9 +172,15 @@ impl Context { .expect("contract router should be set"); let mut router = router.lock().expect("should lock test router"); - router.route(selector, input).unwrap_or_else(|| { + let result = router.route(selector, input).unwrap_or_else(|| { panic!("selector not found - selector: {selector}") - }) + }); + std::mem::drop(router); + + storage.msg_receiver = previous_receiver; + storage.msg_sender = previous_sender; + + result } pub(crate) unsafe fn read_return_data_raw( From e5028fcc1cc756c1feca0a243a3b6c5ebf5c40d3 Mon Sep 17 00:00:00 2001 From: Alisander Qoshqosh Date: Fri, 22 Nov 2024 20:03:55 +0400 Subject: [PATCH 010/109] add msg::value --- lib/motsu/src/context.rs | 4 ++++ lib/motsu/src/shims.rs | 10 ++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/motsu/src/context.rs b/lib/motsu/src/context.rs index 2009c7ef9..5e280c8d9 100644 --- a/lib/motsu/src/context.rs +++ b/lib/motsu/src/context.rs @@ -30,6 +30,9 @@ impl Context { /// Get the value at `key` in storage. pub(crate) fn get_bytes(self, key: &Bytes32) -> Bytes32 { + // TODO#q: fix deadlock here. + // When contract is called from another contract, it access storage + // second time. Split STORAGE into two parts. let storage = STORAGE.entry(self.thread_name).or_default(); let msg_receiver = storage.msg_receiver.expect("msg_receiver should be set"); @@ -139,6 +142,7 @@ impl Context { 0 } Err(err) => { + // TODO#q: how should we process errors? return_data_len.write(err.len()); self.set_return_data(err); 1 diff --git a/lib/motsu/src/shims.rs b/lib/motsu/src/shims.rs index 5dc478bb6..89b7063b1 100644 --- a/lib/motsu/src/shims.rs +++ b/lib/motsu/src/shims.rs @@ -146,8 +146,14 @@ pub const EOA_CODEHASH: &[u8; 66] = #[no_mangle] pub unsafe extern "C" fn msg_sender(sender: *mut u8) { let msg_sender = Context::current().get_msg_sender(); - let x: &[u8; 20] = msg_sender.as_ref(); - std::ptr::copy(x.as_ptr(), sender, 20); + std::ptr::copy(msg_sender.as_ptr(), sender, 20); +} + +/// Get the ETH value (U256) in wei sent to the program. +#[no_mangle] +pub unsafe extern "C" fn msg_value(value: *mut u8) { + let dummy_msg_value: Bytes32 = Bytes32::default(); + std::ptr::copy(dummy_msg_value.as_ptr(), value, 32); } /// Gets the address of the current program. The semantics are equivalent to From c03429d57fd741fe968c511e34bbaa0a99c66362 Mon Sep 17 00:00:00 2001 From: Alisander Qoshqosh Date: Fri, 22 Nov 2024 20:48:26 +0400 Subject: [PATCH 011/109] fix deadlock --- lib/motsu/src/context.rs | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/lib/motsu/src/context.rs b/lib/motsu/src/context.rs index 5e280c8d9..d142f5392 100644 --- a/lib/motsu/src/context.rs +++ b/lib/motsu/src/context.rs @@ -100,8 +100,9 @@ impl Context { self, contract_address: Address, ) { - let mut storage = STORAGE.entry(self.thread_name).or_default(); - if storage + if STORAGE + .entry(self.thread_name.clone()) + .or_default() .contract_data .insert(contract_address, HashMap::new()) .is_some() @@ -109,7 +110,9 @@ impl Context { panic!("contract storage already initialized - contract_address: {contract_address}"); } - if storage + if CALL_STORAGE + .entry(self.thread_name.clone()) + .or_default() .contract_router .insert( contract_address, @@ -151,7 +154,7 @@ impl Context { } pub(crate) fn set_return_data(&self, data: Vec) { - let _ = STORAGE + let _ = CALL_STORAGE .entry(self.thread_name.clone()) .or_default() .call_output @@ -165,22 +168,23 @@ impl Context { input: &[u8], ) -> ArbResult { let mut storage = STORAGE.entry(self.thread_name.clone()).or_default(); - let previous_receiver = storage.msg_receiver.replace(contract_address); let previous_sender = storage.msg_sender.take(); storage.msg_sender = previous_receiver; // now the sender is current contract + drop(storage); - let router = storage + let call_storage = + CALL_STORAGE.entry(self.thread_name.clone()).or_default(); + let router = call_storage .contract_router .get(&contract_address) .expect("contract router should be set"); - let mut router = router.lock().expect("should lock test router"); let result = router.route(selector, input).unwrap_or_else(|| { panic!("selector not found - selector: {selector}") }); - std::mem::drop(router); + let mut storage = STORAGE.entry(self.thread_name.clone()).or_default(); storage.msg_receiver = previous_receiver; storage.msg_sender = previous_sender; @@ -198,7 +202,7 @@ impl Context { } pub(crate) fn get_return_data(&self) -> Vec { - STORAGE + CALL_STORAGE .entry(self.thread_name.clone()) .or_default() .call_output @@ -251,6 +255,18 @@ struct MockStorage { msg_receiver: Option
, /// Contract's address to mock data storage mapping. contract_data: HashMap, +} + +type ContractStorage = HashMap; + +/// The key is the name of the test thread, and the value is external call +/// metadata. +static CALL_STORAGE: Lazy> = + Lazy::new(DashMap::new); + +/// Metadata related to call of external contract. +#[derive(Default)] +struct CallStorage { // Contract's address to router mapping. // NOTE: Mutex is important since contract type is not `Sync`. contract_router: HashMap>>, @@ -258,8 +274,6 @@ struct MockStorage { call_output: Option>, } -type ContractStorage = HashMap; - /// A trait for routing messages to the appropriate selector in tests. pub trait TestRouter: Send { /// Tries to find and execute a method for the given selector, returning From 0c5ac778d23f085f0d72466f64039c4d2f990c48 Mon Sep 17 00:00:00 2001 From: Alisander Qoshqosh Date: Fri, 22 Nov 2024 20:57:42 +0400 Subject: [PATCH 012/109] ping pong works --- lib/motsu/src/context.rs | 42 +++++++++++++++++++++++++--------------- lib/motsu/src/shims.rs | 3 ++- 2 files changed, 28 insertions(+), 17 deletions(-) diff --git a/lib/motsu/src/context.rs b/lib/motsu/src/context.rs index d142f5392..69e3e0b45 100644 --- a/lib/motsu/src/context.rs +++ b/lib/motsu/src/context.rs @@ -76,26 +76,35 @@ impl Context { STORAGE.remove(&self.thread_name); } - pub(crate) fn set_msg_sender(self, msg_sender: Address) { + /// Set the message sender account address. + pub(crate) fn set_msg_sender(self, msg_sender: Address) -> Option
{ let mut storage = STORAGE.entry(self.thread_name).or_default(); - let _ = storage.msg_sender.insert(msg_sender); + storage.msg_sender.replace(msg_sender) } - pub(crate) fn get_msg_sender(self) -> Address { + /// Get the message sender account address. + pub(crate) fn get_msg_sender(self) -> Option
{ let storage = STORAGE.entry(self.thread_name).or_default(); - storage.msg_sender.expect("msg_sender should be set") + storage.msg_sender } - pub(crate) fn set_msg_receiver(self, msg_receiver: Address) { + /// Set the address of the contract, that should be called. + pub(crate) fn set_msg_receiver( + self, + msg_receiver: Address, + ) -> Option
{ let mut storage = STORAGE.entry(self.thread_name).or_default(); - let _ = storage.msg_receiver.insert(msg_receiver); + storage.msg_receiver.replace(msg_receiver) } - pub(crate) fn get_msg_receiver(self) -> Address { + /// Get the address of the contract, that should be called. + pub(crate) fn get_msg_receiver(self) -> Option
{ let storage = STORAGE.entry(self.thread_name).or_default(); - storage.msg_receiver.expect("msg_receiver should be set") + storage.msg_receiver } + /// Initialise contract storage for the current test thread and + /// `contract_address`. pub(crate) fn init_contract( self, contract_address: Address, @@ -171,7 +180,7 @@ impl Context { let previous_receiver = storage.msg_receiver.replace(contract_address); let previous_sender = storage.msg_sender.take(); storage.msg_sender = previous_receiver; // now the sender is current contract - drop(storage); + drop(storage); // TODO#q: use msg_receiver setter (avoid a deadlock the other way) let call_storage = CALL_STORAGE.entry(self.thread_name.clone()).or_default(); @@ -198,7 +207,7 @@ impl Context { ) -> usize { let data = self.get_return_data(); ptr::copy(data.as_ptr(), dest, size); - 0 + data.len() } pub(crate) fn get_return_data(&self) -> Vec { @@ -281,8 +290,9 @@ pub trait TestRouter: Send { fn route(&mut self, selector: u32, input: &[u8]) -> Option; } -impl + TopLevelStorage + BorrowMut + Send> TestRouter - for R +impl TestRouter for R +where + R: Router + TopLevelStorage + BorrowMut + Send, { fn route(&mut self, selector: u32, input: &[u8]) -> Option { >::route(self, selector, input) @@ -319,8 +329,8 @@ impl ::core::ops::Deref for ContractCall { #[inline] fn deref(&self) -> &Self::Target { - Context::current().set_msg_sender(self.caller_address); - Context::current().set_msg_receiver(self.contract_address); + let _ = Context::current().set_msg_sender(self.caller_address); + let _ = Context::current().set_msg_receiver(self.contract_address); &self.contract } } @@ -328,8 +338,8 @@ impl ::core::ops::Deref for ContractCall { impl ::core::ops::DerefMut for ContractCall { #[inline] fn deref_mut(&mut self) -> &mut Self::Target { - Context::current().set_msg_sender(self.caller_address); - Context::current().set_msg_receiver(self.contract_address); + let _ = Context::current().set_msg_sender(self.caller_address); + let _ = Context::current().set_msg_receiver(self.contract_address); &mut self.contract } } diff --git a/lib/motsu/src/shims.rs b/lib/motsu/src/shims.rs index 89b7063b1..1d329e7fb 100644 --- a/lib/motsu/src/shims.rs +++ b/lib/motsu/src/shims.rs @@ -145,7 +145,8 @@ pub const EOA_CODEHASH: &[u8; 66] = /// May panic if fails to parse `MSG_SENDER` as an address. #[no_mangle] pub unsafe extern "C" fn msg_sender(sender: *mut u8) { - let msg_sender = Context::current().get_msg_sender(); + let msg_sender = + Context::current().get_msg_sender().expect("msg_sender should be set"); std::ptr::copy(msg_sender.as_ptr(), sender, 20); } From 924e72e3513084736fc583a8fbb7dd9cae01af63 Mon Sep 17 00:00:00 2001 From: Alisander Qoshqosh Date: Fri, 22 Nov 2024 21:27:19 +0400 Subject: [PATCH 013/109] ++ --- lib/motsu/src/context.rs | 3 --- 1 file changed, 3 deletions(-) diff --git a/lib/motsu/src/context.rs b/lib/motsu/src/context.rs index 69e3e0b45..cf4cd1dba 100644 --- a/lib/motsu/src/context.rs +++ b/lib/motsu/src/context.rs @@ -30,9 +30,6 @@ impl Context { /// Get the value at `key` in storage. pub(crate) fn get_bytes(self, key: &Bytes32) -> Bytes32 { - // TODO#q: fix deadlock here. - // When contract is called from another contract, it access storage - // second time. Split STORAGE into two parts. let storage = STORAGE.entry(self.thread_name).or_default(); let msg_receiver = storage.msg_receiver.expect("msg_receiver should be set"); From 59cc1a2788f72d77e40d0631ee54637e756d0af5 Mon Sep 17 00:00:00 2001 From: Alisander Qoshqosh Date: Fri, 22 Nov 2024 21:49:56 +0400 Subject: [PATCH 014/109] ++ --- lib/motsu/src/context.rs | 78 +++++++++++++++++++++------------------- 1 file changed, 42 insertions(+), 36 deletions(-) diff --git a/lib/motsu/src/context.rs b/lib/motsu/src/context.rs index cf4cd1dba..0b6c9e3d3 100644 --- a/lib/motsu/src/context.rs +++ b/lib/motsu/src/context.rs @@ -3,7 +3,7 @@ use std::{borrow::BorrowMut, collections::HashMap, ptr, slice, sync::Mutex}; use alloy_primitives::Address; -use dashmap::DashMap; +use dashmap::{mapref::one::RefMut, DashMap}; use once_cell::sync::Lazy; use stylus_sdk::{ abi::Router, @@ -28,9 +28,16 @@ impl Context { Self { thread_name: ThreadName::current() } } + /// Get the raw value at `key` in storage and write it to `value`. + pub(crate) unsafe fn get_bytes_raw(self, key: *const u8, value: *mut u8) { + let key = read_bytes32(key); + + write_bytes32(value, self.get_bytes(&key)); + } + /// Get the value at `key` in storage. pub(crate) fn get_bytes(self, key: &Bytes32) -> Bytes32 { - let storage = STORAGE.entry(self.thread_name).or_default(); + let storage = self.get_storage(); let msg_receiver = storage.msg_receiver.expect("msg_receiver should be set"); storage @@ -42,16 +49,15 @@ impl Context { .unwrap_or_default() } - /// Get the raw value at `key` in storage and write it to `value`. - pub(crate) unsafe fn get_bytes_raw(self, key: *const u8, value: *mut u8) { - let key = read_bytes32(key); - - write_bytes32(value, self.get_bytes(&key)); + /// Set the raw value at `key` in storage to `value`. + pub(crate) unsafe fn set_bytes_raw(self, key: *const u8, value: *const u8) { + let (key, value) = (read_bytes32(key), read_bytes32(value)); + self.set_bytes(key, value); } /// Set the value at `key` in storage to `value`. pub(crate) fn set_bytes(self, key: Bytes32, value: Bytes32) { - let mut storage = STORAGE.entry(self.thread_name).or_default(); + let mut storage = self.get_storage(); let msg_receiver = storage.msg_receiver.expect("msg_receiver should be set"); storage @@ -61,43 +67,50 @@ impl Context { .insert(key, value); } - /// Set the raw value at `key` in storage to `value`. - pub(crate) unsafe fn set_bytes_raw(self, key: *const u8, value: *const u8) { - let (key, value) = (read_bytes32(key), read_bytes32(value)); - self.set_bytes(key, value); - } - /// Clears storage, removing all key-value pairs associated with the current /// test thread. pub fn reset_storage(self) { STORAGE.remove(&self.thread_name); } + /// Get reference to the storage for the current test thread. + fn get_storage(&self) -> RefMut<'static, ThreadName, MockStorage> { + STORAGE + .get_mut(&self.thread_name) + .expect("contract should be initialised first") + } + + /// Get reference to the call storage for the current test thread. + fn get_call_storage(&self) -> RefMut<'static, ThreadName, CallStorage> { + CALL_STORAGE + .get_mut(&self.thread_name.clone()) + .expect("contract should be initialised first") + } + /// Set the message sender account address. - pub(crate) fn set_msg_sender(self, msg_sender: Address) -> Option
{ - let mut storage = STORAGE.entry(self.thread_name).or_default(); - storage.msg_sender.replace(msg_sender) + pub(crate) fn set_msg_sender( + &self, + msg_sender: Address, + ) -> Option
{ + self.get_storage().msg_sender.replace(msg_sender) } /// Get the message sender account address. - pub(crate) fn get_msg_sender(self) -> Option
{ - let storage = STORAGE.entry(self.thread_name).or_default(); - storage.msg_sender + pub(crate) fn get_msg_sender(&self) -> Option
{ + self.get_storage().msg_sender } /// Set the address of the contract, that should be called. pub(crate) fn set_msg_receiver( - self, + &self, msg_receiver: Address, ) -> Option
{ - let mut storage = STORAGE.entry(self.thread_name).or_default(); - storage.msg_receiver.replace(msg_receiver) + self.get_storage().msg_receiver.replace(msg_receiver) } /// Get the address of the contract, that should be called. - pub(crate) fn get_msg_receiver(self) -> Option
{ - let storage = STORAGE.entry(self.thread_name).or_default(); - storage.msg_receiver + pub(crate) fn get_msg_receiver(&self) -> Option
{ + self.get_storage().msg_receiver } /// Initialise contract storage for the current test thread and @@ -117,7 +130,7 @@ impl Context { } if CALL_STORAGE - .entry(self.thread_name.clone()) + .entry(self.thread_name) .or_default() .contract_router .insert( @@ -151,7 +164,6 @@ impl Context { 0 } Err(err) => { - // TODO#q: how should we process errors? return_data_len.write(err.len()); self.set_return_data(err); 1 @@ -160,11 +172,7 @@ impl Context { } pub(crate) fn set_return_data(&self, data: Vec) { - let _ = CALL_STORAGE - .entry(self.thread_name.clone()) - .or_default() - .call_output - .insert(data); + let _ = self.get_call_storage().call_output.insert(data); } pub(crate) fn call_contract( @@ -208,9 +216,7 @@ impl Context { } pub(crate) fn get_return_data(&self) -> Vec { - CALL_STORAGE - .entry(self.thread_name.clone()) - .or_default() + self.get_call_storage() .call_output .take() .expect("call_output should be set") From 110d340badbb1e9aed4b62edb3cb02eab6bcdab6 Mon Sep 17 00:00:00 2001 From: Alisander Qoshqosh Date: Fri, 22 Nov 2024 21:55:45 +0400 Subject: [PATCH 015/109] ++ --- lib/motsu/src/context.rs | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/lib/motsu/src/context.rs b/lib/motsu/src/context.rs index 0b6c9e3d3..27c0eb79c 100644 --- a/lib/motsu/src/context.rs +++ b/lib/motsu/src/context.rs @@ -181,14 +181,12 @@ impl Context { selector: u32, input: &[u8], ) -> ArbResult { - let mut storage = STORAGE.entry(self.thread_name.clone()).or_default(); - let previous_receiver = storage.msg_receiver.replace(contract_address); - let previous_sender = storage.msg_sender.take(); - storage.msg_sender = previous_receiver; // now the sender is current contract - drop(storage); // TODO#q: use msg_receiver setter (avoid a deadlock the other way) - - let call_storage = - CALL_STORAGE.entry(self.thread_name.clone()).or_default(); + let previous_receiver = self.set_msg_receiver(contract_address); + let previous_msg_sender = self.set_msg_sender( + previous_receiver.expect("msg_receiver should be set"), + ); + + let call_storage = self.get_call_storage(); let router = call_storage .contract_router .get(&contract_address) @@ -198,9 +196,9 @@ impl Context { panic!("selector not found - selector: {selector}") }); - let mut storage = STORAGE.entry(self.thread_name.clone()).or_default(); + let mut storage = self.get_storage(); storage.msg_receiver = previous_receiver; - storage.msg_sender = previous_sender; + storage.msg_sender = previous_msg_sender; result } @@ -258,7 +256,7 @@ impl ThreadName { } } -/// Storage for unit test's mock data.x +/// Storage for unit test's mock data. #[derive(Default)] struct MockStorage { /// Address of the message sender. From aa577f26048d538aafe7060c03496e153b368457 Mon Sep 17 00:00:00 2001 From: Alisander Qoshqosh Date: Fri, 22 Nov 2024 22:06:57 +0400 Subject: [PATCH 016/109] ++ --- lib/motsu/src/context.rs | 16 ++++++++-------- lib/motsu/src/lib.rs | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/motsu/src/context.rs b/lib/motsu/src/context.rs index 27c0eb79c..3b9d0ccf5 100644 --- a/lib/motsu/src/context.rs +++ b/lib/motsu/src/context.rs @@ -24,7 +24,6 @@ impl Context { /// Get test context associated with the current test thread. #[must_use] pub fn current() -> Self { - // TODO#q: STORAGE entry call here Self { thread_name: ThreadName::current() } } @@ -181,10 +180,12 @@ impl Context { selector: u32, input: &[u8], ) -> ArbResult { - let previous_receiver = self.set_msg_receiver(contract_address); - let previous_msg_sender = self.set_msg_sender( - previous_receiver.expect("msg_receiver should be set"), - ); + let previous_receiver = self + .set_msg_receiver(contract_address) + .expect("previous msg_receiver should be set"); + let previous_msg_sender = self + .set_msg_sender(previous_receiver) + .expect("previous msg_sender should be set"); let call_storage = self.get_call_storage(); let router = call_storage @@ -196,9 +197,8 @@ impl Context { panic!("selector not found - selector: {selector}") }); - let mut storage = self.get_storage(); - storage.msg_receiver = previous_receiver; - storage.msg_sender = previous_msg_sender; + let _ = self.set_msg_receiver(previous_receiver); + let _ = self.set_msg_sender(previous_msg_sender); result } diff --git a/lib/motsu/src/lib.rs b/lib/motsu/src/lib.rs index 99df163d4..b509a74e9 100644 --- a/lib/motsu/src/lib.rs +++ b/lib/motsu/src/lib.rs @@ -134,7 +134,7 @@ mod tests { let mut ping = alice.uses(ping); let mut pong = alice.uses(pong); - let value = uint!(1_U256); + let value = uint!(10_U256); let ponged_value = ping.ping(pong.address(), value).expect("should ping successfully"); From 01401e84467dd3dd4f71173bf4ea2203700c1755 Mon Sep 17 00:00:00 2001 From: Alisander Qoshqosh Date: Sat, 23 Nov 2024 09:57:18 +0400 Subject: [PATCH 017/109] comment erc721 tests --- contracts/src/token/erc721/mod.rs | 2 ++ lib/motsu/src/lib.rs | 10 ---------- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/contracts/src/token/erc721/mod.rs b/contracts/src/token/erc721/mod.rs index 5f6fb886d..2120387a9 100644 --- a/contracts/src/token/erc721/mod.rs +++ b/contracts/src/token/erc721/mod.rs @@ -1175,6 +1175,7 @@ mod tests { U256::from(num) } + /* #[motsu::test] fn error_when_checking_balance_of_invalid_owner(contract: Erc721) { let invalid_owner = Address::ZERO; @@ -2505,4 +2506,5 @@ mod tests { let expected = 0x01ffc9a7; assert_eq!(actual, expected); } + */ } diff --git a/lib/motsu/src/lib.rs b/lib/motsu/src/lib.rs index b509a74e9..d87dbd7d1 100644 --- a/lib/motsu/src/lib.rs +++ b/lib/motsu/src/lib.rs @@ -142,14 +142,4 @@ mod tests { assert_eq!(ping.ping_count(), uint!(1_U256)); assert_eq!(pong.pong_count(), uint!(1_U256)); } - - #[test] - fn smoke() { - let mut ping_contract = unsafe { PingContract::new(uint!(0_U256), 0) }; - ::route( - &mut ping_contract, - 0, - &[0, 0, 0, 0], - ); - } } From 0cd42999ab6db57f6f8b2ba62eb1400feb3ccd3c Mon Sep 17 00:00:00 2001 From: Alisander Qoshqosh Date: Sat, 23 Nov 2024 11:21:10 +0400 Subject: [PATCH 018/109] add erc721 receiver test --- contracts/src/token/erc721/mod.rs | 52 ++++++++++++++++++- lib/motsu/src/context.rs | 83 ++++++++++++++++++------------- lib/motsu/src/shims.rs | 17 +++++-- 3 files changed, 112 insertions(+), 40 deletions(-) diff --git a/contracts/src/token/erc721/mod.rs b/contracts/src/token/erc721/mod.rs index 2120387a9..99752cd84 100644 --- a/contracts/src/token/erc721/mod.rs +++ b/contracts/src/token/erc721/mod.rs @@ -1156,8 +1156,15 @@ impl Erc721 { #[cfg(all(test, feature = "std"))] mod tests { - use alloy_primitives::{address, uint, Address, U256}; - use stylus_sdk::msg; + use alloy_primitives::{ + address, fixed_bytes, uint, Address, FixedBytes, U256, + }; + use motsu::prelude::Account; + use stylus_sdk::{ + abi::Bytes, + msg, + prelude::{public, sol_storage, TopLevelStorage}, + }; use super::{ ERC721IncorrectOwner, ERC721InsufficientApproval, @@ -2507,4 +2514,45 @@ mod tests { assert_eq!(actual, expected); } */ + + sol_storage! { + pub struct Erc721ReceiverMock { + uint256 _received_token_id; + } + } + + #[public] + impl Erc721ReceiverMock { + #[selector(name = "onERC721Received")] + fn on_erc721_received( + &mut self, + operator: Address, + from: Address, + token_id: U256, + data: Bytes, + ) -> FixedBytes<4> { + self._received_token_id.set(token_id); + fixed_bytes!("150b7a02") + } + + fn received_token_id(&self) -> U256 { + self._received_token_id.get() + } + } + + unsafe impl TopLevelStorage for Erc721ReceiverMock {} + + #[motsu::test] + fn on_erc721_received(erc721: Erc721, receiver: Erc721ReceiverMock) { + let alice = Account::random(); + let token_id = random_token_id(); + alice + .uses(erc721) + ._safe_mint(receiver.address(), token_id, vec![0, 1, 2, 3].into()) + .unwrap(); + + let received_token_id = alice.uses(receiver).received_token_id(); + + assert_eq!(received_token_id, token_id); + } } diff --git a/lib/motsu/src/context.rs b/lib/motsu/src/context.rs index 3b9d0ccf5..618b9d3cb 100644 --- a/lib/motsu/src/context.rs +++ b/lib/motsu/src/context.rs @@ -35,7 +35,7 @@ impl Context { } /// Get the value at `key` in storage. - pub(crate) fn get_bytes(self, key: &Bytes32) -> Bytes32 { + fn get_bytes(self, key: &Bytes32) -> Bytes32 { let storage = self.get_storage(); let msg_receiver = storage.msg_receiver.expect("msg_receiver should be set"); @@ -55,7 +55,7 @@ impl Context { } /// Set the value at `key` in storage to `value`. - pub(crate) fn set_bytes(self, key: Bytes32, value: Bytes32) { + fn set_bytes(self, key: Bytes32, value: Bytes32) { let mut storage = self.get_storage(); let msg_receiver = storage.msg_receiver.expect("msg_receiver should be set"); @@ -72,25 +72,8 @@ impl Context { STORAGE.remove(&self.thread_name); } - /// Get reference to the storage for the current test thread. - fn get_storage(&self) -> RefMut<'static, ThreadName, MockStorage> { - STORAGE - .get_mut(&self.thread_name) - .expect("contract should be initialised first") - } - - /// Get reference to the call storage for the current test thread. - fn get_call_storage(&self) -> RefMut<'static, ThreadName, CallStorage> { - CALL_STORAGE - .get_mut(&self.thread_name.clone()) - .expect("contract should be initialised first") - } - /// Set the message sender account address. - pub(crate) fn set_msg_sender( - &self, - msg_sender: Address, - ) -> Option
{ + fn set_msg_sender(&self, msg_sender: Address) -> Option
{ self.get_storage().msg_sender.replace(msg_sender) } @@ -100,21 +83,18 @@ impl Context { } /// Set the address of the contract, that should be called. - pub(crate) fn set_msg_receiver( - &self, - msg_receiver: Address, - ) -> Option
{ + fn set_msg_receiver(&self, msg_receiver: Address) -> Option
{ self.get_storage().msg_receiver.replace(msg_receiver) } /// Get the address of the contract, that should be called. - pub(crate) fn get_msg_receiver(&self) -> Option
{ + fn get_msg_receiver(&self) -> Option
{ self.get_storage().msg_receiver } /// Initialise contract storage for the current test thread and /// `contract_address`. - pub(crate) fn init_contract( + fn init_contract( self, contract_address: Address, ) { @@ -142,6 +122,7 @@ impl Context { } } + /// Call the contract at raw `address` with the given raw `calldata`. pub(crate) unsafe fn call_contract_raw( self, address: *const u8, @@ -170,23 +151,22 @@ impl Context { } } - pub(crate) fn set_return_data(&self, data: Vec) { - let _ = self.get_call_storage().call_output.insert(data); - } - - pub(crate) fn call_contract( + fn call_contract( &self, contract_address: Address, selector: u32, input: &[u8], ) -> ArbResult { + // Set the current contract as message sender and callee contract as + // receiver. let previous_receiver = self .set_msg_receiver(contract_address) - .expect("previous msg_receiver should be set"); + .expect("msg_receiver should be set"); let previous_msg_sender = self .set_msg_sender(previous_receiver) - .expect("previous msg_sender should be set"); + .expect("msg_sender should be set"); + // Call external contract. let call_storage = self.get_call_storage(); let router = call_storage .contract_router @@ -197,12 +177,17 @@ impl Context { panic!("selector not found - selector: {selector}") }); + // Set the previous message sender and receiver back. let _ = self.set_msg_receiver(previous_receiver); let _ = self.set_msg_sender(previous_msg_sender); result } + fn set_return_data(&self, data: Vec) { + let _ = self.get_call_storage().call_output.insert(data); + } + pub(crate) unsafe fn read_return_data_raw( self, dest: *mut u8, @@ -213,12 +198,40 @@ impl Context { data.len() } - pub(crate) fn get_return_data(&self) -> Vec { + fn get_return_data(&self) -> Vec { self.get_call_storage() .call_output .take() .expect("call_output should be set") } + + /// Check if the contract at raw `address` has code. + pub(crate) unsafe fn has_code_raw(self, address: *const u8) -> bool { + let address_bytes = slice::from_raw_parts(address, 20); + let address = Address::from_slice(address_bytes); + self.has_code(address) + } + + /// Check if the contract at `address` has code. + #[must_use] + fn has_code(&self, address: Address) -> bool { + let call_storage = self.get_call_storage(); + call_storage.contract_router.contains_key(&address) + } + + /// Get reference to the storage for the current test thread. + fn get_storage(&self) -> RefMut<'static, ThreadName, MockStorage> { + STORAGE + .get_mut(&self.thread_name) + .expect("contract should be initialised first") + } + + /// Get reference to the call storage for the current test thread. + fn get_call_storage(&self) -> RefMut<'static, ThreadName, CallStorage> { + CALL_STORAGE + .get_mut(&self.thread_name.clone()) + .expect("contract should be initialised first") + } } /// Read the word from location pointed by `ptr`. @@ -279,7 +292,7 @@ static CALL_STORAGE: Lazy> = struct CallStorage { // Contract's address to router mapping. // NOTE: Mutex is important since contract type is not `Sync`. - contract_router: HashMap>>, + contract_router: HashMap>>, // Output of a contract call. call_output: Option>, } diff --git a/lib/motsu/src/shims.rs b/lib/motsu/src/shims.rs index 1d329e7fb..56d22dea7 100644 --- a/lib/motsu/src/shims.rs +++ b/lib/motsu/src/shims.rs @@ -124,10 +124,15 @@ pub const CONTRACT_ADDRESS: &[u8; 42] = /// Arbitrum's CHAID ID. pub const CHAIN_ID: u64 = 42161; -/// Externally Owned Account (EOA) code hash. +/// Externally Owned Account (EOA) code hash (wallet account). pub const EOA_CODEHASH: &[u8; 66] = b"0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470"; +/// Contract Account (CA) code hash (smart contract code). +/// NOTE: can be any 256-bit value to pass `has_code` check. +pub const CA_CODEHASH: &[u8; 66] = + b"0x1111111111111111111111111111111111111111111111111111111111111111"; + /// Gets the address of the account that called the program. For normal /// L2-to-L2 transactions the semantics are equivalent to that of the EVM's /// [`CALLER`] opcode, including in cases arising from [`DELEGATE_CALL`]. @@ -209,9 +214,15 @@ pub unsafe extern "C" fn emit_log(_: *const u8, _: usize, _: usize) { /// /// May panic if fails to parse `ACCOUNT_CODEHASH` as a keccack hash. #[no_mangle] -pub unsafe extern "C" fn account_codehash(_address: *const u8, dest: *mut u8) { +pub unsafe extern "C" fn account_codehash(address: *const u8, dest: *mut u8) { + let code_hash = if Context::current().has_code_raw(address) { + CA_CODEHASH + } else { + EOA_CODEHASH + }; + let account_codehash = - const_hex::const_decode_to_array::<32>(EOA_CODEHASH).unwrap(); + const_hex::const_decode_to_array::<32>(code_hash).unwrap(); std::ptr::copy(account_codehash.as_ptr(), dest, 32); } From 2b944ce6854a17842c1a01c0ce203161bfa1f8b4 Mon Sep 17 00:00:00 2001 From: Alisander Qoshqosh Date: Thu, 28 Nov 2024 07:06:43 +0400 Subject: [PATCH 019/109] use contract wrapper in motsu params --- contracts/src/token/erc721/mod.rs | 13 ++++++++----- lib/motsu-proc/src/test.rs | 1 - lib/motsu/src/context.rs | 31 +++++++++++-------------------- lib/motsu/src/lib.rs | 19 +++++++++---------- lib/motsu/src/prelude.rs | 2 +- 5 files changed, 29 insertions(+), 37 deletions(-) diff --git a/contracts/src/token/erc721/mod.rs b/contracts/src/token/erc721/mod.rs index 99752cd84..566055ed0 100644 --- a/contracts/src/token/erc721/mod.rs +++ b/contracts/src/token/erc721/mod.rs @@ -1159,7 +1159,7 @@ mod tests { use alloy_primitives::{ address, fixed_bytes, uint, Address, FixedBytes, U256, }; - use motsu::prelude::Account; + use motsu::prelude::{Account, Contract}; use stylus_sdk::{ abi::Bytes, msg, @@ -2543,15 +2543,18 @@ mod tests { unsafe impl TopLevelStorage for Erc721ReceiverMock {} #[motsu::test] - fn on_erc721_received(erc721: Erc721, receiver: Erc721ReceiverMock) { + fn on_erc721_received( + erc721: Contract, + receiver: Contract, + ) { let alice = Account::random(); let token_id = random_token_id(); - alice - .uses(erc721) + erc721 + .sender(alice) ._safe_mint(receiver.address(), token_id, vec![0, 1, 2, 3].into()) .unwrap(); - let received_token_id = alice.uses(receiver).received_token_id(); + let received_token_id = receiver.sender(alice).received_token_id(); assert_eq!(received_token_id, token_id); } diff --git a/lib/motsu-proc/src/test.rs b/lib/motsu-proc/src/test.rs index 910ba4f25..05aa9f5c2 100644 --- a/lib/motsu-proc/src/test.rs +++ b/lib/motsu-proc/src/test.rs @@ -38,7 +38,6 @@ pub(crate) fn test(_attr: &TokenStream, input: TokenStream) -> TokenStream { #( #attrs )* #[test] fn #fn_name() #fn_return_type { - use ::motsu::prelude::DefaultStorage; #( #contract_declarations )* let res = { #( #fn_stmts )* diff --git a/lib/motsu/src/context.rs b/lib/motsu/src/context.rs index 618b9d3cb..7736e41c9 100644 --- a/lib/motsu/src/context.rs +++ b/lib/motsu/src/context.rs @@ -313,19 +313,12 @@ where } } -/// Initializes fields of contract storage and child contract storages with -/// default values. -pub trait DefaultStorage: StorageType + TestRouter + 'static { - /// Initializes fields of contract storage and child contract storages with - /// default values. - #[must_use] - fn default() -> Contract { +impl Default for Contract { + fn default() -> Self { Contract::random() } } -impl DefaultStorage for ST {} - pub struct ContractCall { contract: ST, caller_address: Address, @@ -379,8 +372,17 @@ impl Contract { pub fn address(&self) -> Address { self.address } + + pub fn sender(&self, account: Account) -> ContractCall { + ContractCall { + contract: unsafe { ST::new(uint!(0_U256), 0) }, + caller_address: account.address, + contract_address: self.address, + } + } } +#[derive(Clone, Copy)] pub struct Account { address: Address, } @@ -400,15 +402,4 @@ impl Account { pub fn address(&self) -> Address { self.address } - - pub fn uses( - &self, - contract: &mut Contract, - ) -> ContractCall { - ContractCall { - contract: unsafe { ST::new(uint!(0_U256), 0) }, - caller_address: self.address, - contract_address: contract.address, - } - } } diff --git a/lib/motsu/src/lib.rs b/lib/motsu/src/lib.rs index d87dbd7d1..47632130a 100644 --- a/lib/motsu/src/lib.rs +++ b/lib/motsu/src/lib.rs @@ -61,7 +61,7 @@ mod tests { prelude::{public, sol_storage, StorageType, TopLevelStorage}, }; - use crate::context::{Account, TestRouter}; + use crate::context::{Account, Contract, TestRouter}; sol_storage! { pub struct PingContract { @@ -124,22 +124,21 @@ mod tests { #[test] fn ping_pong_works() { - use crate::prelude::DefaultStorage; - let mut ping = PingContract::default(); + let mut ping = Contract::::default(); let ping = &mut ping; - let mut pong = PongContract::default(); + let mut pong = Contract::::default(); let pong = &mut pong; let alice = Account::random(); - let mut ping = alice.uses(ping); - let mut pong = alice.uses(pong); let value = uint!(10_U256); - let ponged_value = - ping.ping(pong.address(), value).expect("should ping successfully"); + let ponged_value = ping + .sender(alice) + .ping(pong.address(), value) + .expect("should ping successfully"); assert_eq!(ponged_value, value + uint!(1_U256)); - assert_eq!(ping.ping_count(), uint!(1_U256)); - assert_eq!(pong.pong_count(), uint!(1_U256)); + assert_eq!(ping.sender(alice).ping_count(), uint!(1_U256)); + assert_eq!(pong.sender(alice).pong_count(), uint!(1_U256)); } } diff --git a/lib/motsu/src/prelude.rs b/lib/motsu/src/prelude.rs index 5af1b5e21..a881a05fb 100644 --- a/lib/motsu/src/prelude.rs +++ b/lib/motsu/src/prelude.rs @@ -1,5 +1,5 @@ //! Common imports for `motsu` tests. pub use crate::{ - context::{Account, Context, ContractCall, DefaultStorage}, + context::{Account, Context, Contract, ContractCall}, shims::*, }; From 0aaa81e65f1ae38f8ae9bc22c27b3f5732eb1634 Mon Sep 17 00:00:00 2001 From: Alisander Qoshqosh Date: Thu, 28 Nov 2024 09:42:58 +0400 Subject: [PATCH 020/109] add msg sender mock --- contracts/src/token/erc721/mod.rs | 18 ++++++++++-------- contracts/src/utils/context.rs | 17 +++++++++++++++++ contracts/src/utils/mod.rs | 1 + lib/motsu/src/context.rs | 2 +- lib/motsu/src/lib.rs | 24 ++++++++++++++++++++++-- 5 files changed, 51 insertions(+), 11 deletions(-) create mode 100644 contracts/src/utils/context.rs diff --git a/contracts/src/token/erc721/mod.rs b/contracts/src/token/erc721/mod.rs index 566055ed0..a32174b20 100644 --- a/contracts/src/token/erc721/mod.rs +++ b/contracts/src/token/erc721/mod.rs @@ -7,11 +7,12 @@ use stylus_sdk::{ abi::Bytes, alloy_sol_types::sol, call::{self, Call, MethodError}, - evm, msg, + evm, prelude::*, }; use crate::utils::{ + context::msg_sender, introspection::erc165::{Erc165, IErc165}, math::storage::{AddAssignUnchecked, SubAssignUnchecked}, }; @@ -161,6 +162,7 @@ impl MethodError for Error { } pub use receiver::IERC721Receiver; + #[allow(missing_docs)] mod receiver { stylus_sdk::stylus_proc::sol_interface! { @@ -505,7 +507,7 @@ impl IErc721 for Erc721 { data: Bytes, ) -> Result<(), Error> { self.transfer_from(from, to, token_id)?; - self._check_on_erc721_received(msg::sender(), from, to, token_id, data) + self._check_on_erc721_received(msg_sender(), from, to, token_id, data) } fn transfer_from( @@ -523,7 +525,7 @@ impl IErc721 for Erc721 { // Setting an "auth" argument enables the `_is_authorized` check which // verifies that the token exists (`from != 0`). Therefore, it is // not needed to verify that the return value is not 0 here. - let previous_owner = self._update(to, token_id, msg::sender())?; + let previous_owner = self._update(to, token_id, msg_sender())?; if previous_owner != from { return Err(ERC721IncorrectOwner { sender: from, @@ -536,7 +538,7 @@ impl IErc721 for Erc721 { } fn approve(&mut self, to: Address, token_id: U256) -> Result<(), Error> { - self._approve(to, token_id, msg::sender(), true) + self._approve(to, token_id, msg_sender(), true) } fn set_approval_for_all( @@ -544,7 +546,7 @@ impl IErc721 for Erc721 { operator: Address, approved: bool, ) -> Result<(), Error> { - self._set_approval_for_all(msg::sender(), operator, approved) + self._set_approval_for_all(msg_sender(), operator, approved) } fn get_approved(&self, token_id: U256) -> Result { @@ -822,7 +824,7 @@ impl Erc721 { ) -> Result<(), Error> { self._mint(to, token_id)?; self._check_on_erc721_received( - msg::sender(), + msg_sender(), Address::ZERO, to, token_id, @@ -967,7 +969,7 @@ impl Erc721 { data: Bytes, ) -> Result<(), Error> { self._transfer(from, to, token_id)?; - self._check_on_erc721_received(msg::sender(), from, to, token_id, data) + self._check_on_erc721_received(msg_sender(), from, to, token_id, data) } /// Approve `to` to operate on `token_id`. @@ -1085,7 +1087,7 @@ impl Erc721 { /// Performs an acceptance check for the provided `operator` by calling /// [`IERC721Receiver::on_erc_721_received`] on the `to` address. The /// `operator` is generally the address that initiated the token transfer - /// (i.e. `msg::sender()`). + /// (i.e. `msg_sender()`). /// /// The acceptance call is not executed and treated as a no-op if the /// target address doesn't contain code (i.e. an EOA). Otherwise, the diff --git a/contracts/src/utils/context.rs b/contracts/src/utils/context.rs new file mode 100644 index 000000000..9f66d44b5 --- /dev/null +++ b/contracts/src/utils/context.rs @@ -0,0 +1,17 @@ +//! Context functions used for mocking unit tests. + +use stylus_sdk::{alloy_primitives::Address, msg}; + +/// Returns the address of the message sender. +#[cfg(test)] +pub fn msg_sender() -> Address { + motsu::prelude::Context::current() + .get_msg_sender() + .expect("msg_sender should be set") +} + +/// Returns the address of the message sender. +#[cfg(not(test))] +pub fn msg_sender() -> Address { + msg::sender() +} diff --git a/contracts/src/utils/mod.rs b/contracts/src/utils/mod.rs index b8f56cef7..4746849b1 100644 --- a/contracts/src/utils/mod.rs +++ b/contracts/src/utils/mod.rs @@ -1,4 +1,5 @@ //! Common Smart Contracts utilities. +pub mod context; pub mod cryptography; pub mod introspection; pub mod math; diff --git a/lib/motsu/src/context.rs b/lib/motsu/src/context.rs index 7736e41c9..631c76e8c 100644 --- a/lib/motsu/src/context.rs +++ b/lib/motsu/src/context.rs @@ -78,7 +78,7 @@ impl Context { } /// Get the message sender account address. - pub(crate) fn get_msg_sender(&self) -> Option
{ + pub fn get_msg_sender(&self) -> Option
{ self.get_storage().msg_sender } diff --git a/lib/motsu/src/lib.rs b/lib/motsu/src/lib.rs index 47632130a..1a62db177 100644 --- a/lib/motsu/src/lib.rs +++ b/lib/motsu/src/lib.rs @@ -63,10 +63,17 @@ mod tests { use crate::context::{Account, Contract, TestRouter}; + /// Message sender that mocks `msg::sender()` in tests. + pub fn msg_sender() -> Address { + crate::prelude::Context::current() + .get_msg_sender() + .expect("msg_sender should be set") + } + sol_storage! { pub struct PingContract { uint256 _pings_count; - // TODO#q: add last pinged address. + address _pinged_from; } } @@ -80,12 +87,17 @@ mod tests { let pings_count = self._pings_count.get(); self._pings_count.set(pings_count + uint!(1_U256)); + self._pinged_from.set(msg_sender()); Ok(value) } fn ping_count(&self) -> U256 { self._pings_count.get() } + + fn pinged_from(&self) -> Address { + self._pinged_from.get() + } } unsafe impl TopLevelStorage for PingContract {} @@ -103,7 +115,7 @@ mod tests { sol_storage! { pub struct PongContract { uint256 _pongs_count; - uint256 _value; + address _ponged_from; } } @@ -112,12 +124,17 @@ mod tests { pub fn pong(&mut self, value: U256) -> Result> { let pongs_count = self._pongs_count.get(); self._pongs_count.set(pongs_count + uint!(1_U256)); + self._ponged_from.set(msg_sender()); Ok(value + uint!(1_U256)) } fn pong_count(&self) -> U256 { self._pongs_count.get() } + + fn ponged_from(&self) -> Address { + self._ponged_from.get() + } } unsafe impl TopLevelStorage for PongContract {} @@ -140,5 +157,8 @@ mod tests { assert_eq!(ponged_value, value + uint!(1_U256)); assert_eq!(ping.sender(alice).ping_count(), uint!(1_U256)); assert_eq!(pong.sender(alice).pong_count(), uint!(1_U256)); + + assert_eq!(ping.sender(alice).pinged_from(), alice.address()); + assert_eq!(pong.sender(alice).ponged_from(), ping.address()); } } From 33454f626a259bf4c97a1e2f68bfd88bdba4822d Mon Sep 17 00:00:00 2001 From: Alisander Qoshqosh Date: Thu, 28 Nov 2024 10:32:31 +0400 Subject: [PATCH 021/109] ++ --- Cargo.lock | 32 +------------------------------- lib/motsu/Cargo.toml | 3 +-- 2 files changed, 2 insertions(+), 33 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e7d6add19..c04a6556f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -256,7 +256,7 @@ dependencies = [ "cfg-if", "const-hex", "derive_arbitrary", - "derive_more 0.99.18", + "derive_more", "ethereum_ssz", "getrandom", "hex-literal", @@ -1379,28 +1379,6 @@ dependencies = [ "syn 2.0.68", ] -[[package]] -name = "derive_more" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4a9b99b9cbbe49445b21764dc0625032a89b145a2642e67603e1c936f5458d05" -dependencies = [ - "derive_more-impl", -] - -[[package]] -name = "derive_more-impl" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cb7330aeadfbe296029522e6c40f315320aba36fc43a5b3632f3795348f3bd22" -dependencies = [ - "convert_case 0.6.0", - "proc-macro2", - "quote", - "syn 2.0.68", - "unicode-xid", -] - [[package]] name = "digest" version = "0.9.0" @@ -2469,10 +2447,8 @@ name = "motsu" version = "0.2.0" dependencies = [ "alloy-primitives", - "alloy-sol-types", "const-hex", "dashmap 6.1.0", - "derive_more 1.0.0", "motsu-proc", "once_cell", "stylus-sdk", @@ -4009,12 +3985,6 @@ version = "0.1.13" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0336d538f7abc86d282a4189614dfaa90810dfc2c6f6427eaf88e16311dd225d" -[[package]] -name = "unicode-xid" -version = "0.2.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ebc1c04c71510c7f702b52b7c350734c9ff1295c464a03335b00bb84fc54f853" - [[package]] name = "url" version = "2.5.2" diff --git a/lib/motsu/Cargo.toml b/lib/motsu/Cargo.toml index 5f54f0800..478376c30 100644 --- a/lib/motsu/Cargo.toml +++ b/lib/motsu/Cargo.toml @@ -15,9 +15,8 @@ tiny-keccak.workspace = true stylus-sdk.workspace = true motsu-proc.workspace = true dashmap.workspace = true -derive_more = { version = "1.0.0", features = ["full"] } alloy-primitives = { workspace = true, features = ["arbitrary", "rand"] } -alloy-sol-types.workspace = true + [lints] workspace = true From 299ecc4bcf5ad13d6b633d58c77af146d12fe40b Mon Sep 17 00:00:00 2001 From: Alisander Qoshqosh Date: Fri, 29 Nov 2024 10:05:43 +0400 Subject: [PATCH 022/109] ++ --- Cargo.lock | 1 + lib/motsu/Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index c04a6556f..d92e01c18 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2447,6 +2447,7 @@ name = "motsu" version = "0.2.0" dependencies = [ "alloy-primitives", + "alloy-sol-types", "const-hex", "dashmap 6.1.0", "motsu-proc", diff --git a/lib/motsu/Cargo.toml b/lib/motsu/Cargo.toml index 478376c30..2376089a2 100644 --- a/lib/motsu/Cargo.toml +++ b/lib/motsu/Cargo.toml @@ -16,7 +16,7 @@ stylus-sdk.workspace = true motsu-proc.workspace = true dashmap.workspace = true alloy-primitives = { workspace = true, features = ["arbitrary", "rand"] } - +alloy-sol-types.workspace = true [lints] workspace = true From 4a747f1a36bb7b7dae57ad8473d3f5ecb0f80b20 Mon Sep 17 00:00:00 2001 From: Alisander Qoshqosh Date: Mon, 2 Dec 2024 16:04:11 +0400 Subject: [PATCH 023/109] comment test not ported test cases --- contracts/src/finance/vesting_wallet.rs | 4 ++-- contracts/src/token/erc1155/extensions/burnable.rs | 2 ++ contracts/src/token/erc1155/extensions/metadata_uri.rs | 4 ++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/contracts/src/finance/vesting_wallet.rs b/contracts/src/finance/vesting_wallet.rs index 24b0e2a89..9b5043a25 100644 --- a/contracts/src/finance/vesting_wallet.rs +++ b/contracts/src/finance/vesting_wallet.rs @@ -511,7 +511,7 @@ impl VestingWallet { #[cfg(all(test, feature = "std"))] mod tests { - use alloy_primitives::{address, uint, Address, U256, U64}; + /*use alloy_primitives::{address, uint, Address, U256, U64}; use stylus_sdk::block; use super::{IVestingWallet, VestingWallet}; @@ -607,5 +607,5 @@ mod tests { ); assert_eq!(two, contract.vesting_schedule(two, start)); assert_eq!(two, contract.vesting_schedule(two, start + U64::from(1))); - } + }*/ } diff --git a/contracts/src/token/erc1155/extensions/burnable.rs b/contracts/src/token/erc1155/extensions/burnable.rs index bae3789f6..111061dec 100644 --- a/contracts/src/token/erc1155/extensions/burnable.rs +++ b/contracts/src/token/erc1155/extensions/burnable.rs @@ -110,6 +110,7 @@ impl Erc1155 { #[cfg(all(test, feature = "std"))] mod tests { + /* use alloy_primitives::{address, Address, U256}; use stylus_sdk::msg; @@ -348,4 +349,5 @@ mod tests { }) if sender == alice && balance == values[0] && needed == to_burn[0] && token_id == token_ids[0] )); } + */ } diff --git a/contracts/src/token/erc1155/extensions/metadata_uri.rs b/contracts/src/token/erc1155/extensions/metadata_uri.rs index 6f822a7df..4a2c12839 100644 --- a/contracts/src/token/erc1155/extensions/metadata_uri.rs +++ b/contracts/src/token/erc1155/extensions/metadata_uri.rs @@ -68,7 +68,7 @@ impl IErc165 for Erc1155MetadataUri { #[cfg(all(test, feature = "std"))] mod tests { - use alloy_primitives::U256; + /*use alloy_primitives::U256; use super::{Erc1155MetadataUri, IErc1155MetadataUri, IErc165}; @@ -98,5 +98,5 @@ mod tests { let actual = ::INTERFACE_ID; let expected = 0x01ffc9a7; assert_eq!(actual, expected); - } + }*/ } From 73c5792dc01f6b64d1e73829fa177d272c888ed3 Mon Sep 17 00:00:00 2001 From: Alisander Qoshqosh Date: Mon, 2 Dec 2024 16:10:18 +0400 Subject: [PATCH 024/109] remove motsu from default members, since we're going to split this library anyway --- Cargo.toml | 2 -- 1 file changed, 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index cf26be1b5..e4cfdffcc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -28,8 +28,6 @@ default-members = [ "contracts", "contracts-proc", "lib/crypto", - "lib/motsu", - "lib/motsu-proc", "lib/e2e-proc", "examples/erc20", "examples/erc20-permit", From abfbbb935f22c30506f696d3226990107eb7195f Mon Sep 17 00:00:00 2001 From: Alisander Qoshqosh Date: Mon, 2 Dec 2024 16:32:52 +0400 Subject: [PATCH 025/109] have cargo hack just for contracts --- .github/workflows/check.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index 71c35acf0..0c96dc55d 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -118,7 +118,7 @@ jobs: # target in this context means one of `--lib`, `--bin`, etc, and not the # target triple. - name: Cargo hack - run: cargo hack check --feature-powerset --depth 2 --release --target wasm32-unknown-unknown --skip std --workspace --exclude e2e --exclude basic-example-script --exclude benches + run: cargo hack check --feature-powerset --depth 2 --release --target wasm32-unknown-unknown --skip std --package openzeppelin-stylus typos: runs-on: ubuntu-latest name: ubuntu / stable / typos From f4a74c54aa714052bafa49685c636652557495da Mon Sep 17 00:00:00 2001 From: Alisander Qoshqosh Date: Mon, 2 Dec 2024 16:33:35 +0400 Subject: [PATCH 026/109] ++ --- lib/motsu/src/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/motsu/src/lib.rs b/lib/motsu/src/lib.rs index 1a62db177..317b60f9a 100644 --- a/lib/motsu/src/lib.rs +++ b/lib/motsu/src/lib.rs @@ -64,6 +64,7 @@ mod tests { use crate::context::{Account, Contract, TestRouter}; /// Message sender that mocks `msg::sender()` in tests. + #[must_use] pub fn msg_sender() -> Address { crate::prelude::Context::current() .get_msg_sender() From 2b688ce000a41386589e5be00477fb28c3940d47 Mon Sep 17 00:00:00 2001 From: Daniel Bigos Date: Fri, 29 Nov 2024 17:33:10 +0100 Subject: [PATCH 027/109] build: bump Stylus SDK and alloy versions (cherry picked from commit e539ee931812135f0c1295754140b0bf01417e4f) --- Cargo.lock | 1186 ++++++++++++++++++++------ Cargo.toml | 16 +- examples/erc1155/src/constructor.sol | 4 +- 3 files changed, 925 insertions(+), 281 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5043d0fc0..95c68d77a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6,8 +6,8 @@ version = 4 name = "access-control-example" version = "0.2.0-alpha.1" dependencies = [ - "alloy", - "alloy-primitives", + "alloy 0.7.2", + "alloy-primitives 0.8.13", "e2e", "eyre", "openzeppelin-stylus", @@ -59,6 +59,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011" dependencies = [ "cfg-if", + "getrandom", "once_cell", "version_check", "zerocopy", @@ -85,20 +86,42 @@ version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0ba1c79677c9ce51c8d45e20845b05e6fb070ea2c863fba03ad6af2c778474bd" dependencies = [ - "alloy-consensus", - "alloy-contract", - "alloy-core", - "alloy-eips", - "alloy-genesis", - "alloy-network", - "alloy-provider", - "alloy-rpc-client", - "alloy-rpc-types", - "alloy-serde", - "alloy-signer", - "alloy-signer-local", - "alloy-transport", - "alloy-transport-http", + "alloy-consensus 0.1.3", + "alloy-contract 0.1.3", + "alloy-core 0.7.6", + "alloy-eips 0.1.3", + "alloy-genesis 0.1.3", + "alloy-network 0.1.3", + "alloy-provider 0.1.3", + "alloy-rpc-client 0.1.3", + "alloy-rpc-types 0.1.3", + "alloy-serde 0.1.3", + "alloy-signer 0.1.3", + "alloy-signer-local 0.1.3", + "alloy-transport 0.1.3", + "alloy-transport-http 0.1.3", +] + +[[package]] +name = "alloy" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "44ab65cb6104c389b46df77b7990cab08780f57e41b412b46d6d12baf7e8c716" +dependencies = [ + "alloy-consensus 0.7.0", + "alloy-contract 0.7.0", + "alloy-core 0.8.13", + "alloy-eips 0.7.0", + "alloy-genesis 0.7.0", + "alloy-network 0.7.0", + "alloy-provider 0.7.0", + "alloy-rpc-client 0.7.0", + "alloy-rpc-types 0.7.0", + "alloy-serde 0.7.0", + "alloy-signer 0.7.0", + "alloy-signer-local 0.7.0", + "alloy-transport 0.7.0", + "alloy-transport-http 0.7.0", ] [[package]] @@ -117,11 +140,42 @@ version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f63a6c9eb45684a5468536bc55379a2af0f45ffa5d756e4e4964532737e1836" dependencies = [ - "alloy-eips", - "alloy-primitives", + "alloy-eips 0.1.3", + "alloy-primitives 0.7.6", + "alloy-rlp", + "alloy-serde 0.1.3", + "c-kzg", + "serde", +] + +[[package]] +name = "alloy-consensus" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3a1ff8439834ab71a4b0ecd1a8ff80b3921c87615f158940c3364f399c732786" +dependencies = [ + "alloy-eips 0.7.0", + "alloy-primitives 0.8.13", "alloy-rlp", - "alloy-serde", + "alloy-serde 0.7.0", + "alloy-trie", + "auto_impl", "c-kzg", + "derive_more 1.0.0", + "serde", +] + +[[package]] +name = "alloy-consensus-any" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "519a86faaa6729464365a90c04eba68539b6d3a30f426edb4b3dafd78920d42f" +dependencies = [ + "alloy-consensus 0.7.0", + "alloy-eips 0.7.0", + "alloy-primitives 0.8.13", + "alloy-rlp", + "alloy-serde 0.7.0", "serde", ] @@ -131,14 +185,34 @@ version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0c26b7d34cb76f826558e9409a010e25257f7bfb5aa5e3dd0042c564664ae159" dependencies = [ - "alloy-dyn-abi", - "alloy-json-abi", - "alloy-network", - "alloy-primitives", - "alloy-provider", - "alloy-rpc-types-eth", - "alloy-sol-types", - "alloy-transport", + "alloy-dyn-abi 0.7.6", + "alloy-json-abi 0.7.6", + "alloy-network 0.1.3", + "alloy-primitives 0.7.6", + "alloy-provider 0.1.3", + "alloy-rpc-types-eth 0.1.3", + "alloy-sol-types 0.7.6", + "alloy-transport 0.1.3", + "futures", + "futures-util", + "thiserror", +] + +[[package]] +name = "alloy-contract" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cca2b353d8b7f160dc930dfa174557acefece6deab5ecd7e6230d38858579eea" +dependencies = [ + "alloy-dyn-abi 0.8.13", + "alloy-json-abi 0.8.13", + "alloy-network 0.7.0", + "alloy-network-primitives", + "alloy-primitives 0.8.13", + "alloy-provider 0.7.0", + "alloy-rpc-types-eth 0.7.0", + "alloy-sol-types 0.8.13", + "alloy-transport 0.7.0", "futures", "futures-util", "thiserror", @@ -150,10 +224,23 @@ version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5af3faff14c12c8b11037e0a093dd157c3702becb8435577a2408534d0758315" dependencies = [ - "alloy-dyn-abi", - "alloy-json-abi", - "alloy-primitives", - "alloy-sol-types", + "alloy-dyn-abi 0.7.6", + "alloy-json-abi 0.7.6", + "alloy-primitives 0.7.6", + "alloy-sol-types 0.7.6", +] + +[[package]] +name = "alloy-core" +version = "0.8.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8d22df68fa7d9744be0b1a9be3260e9aa089fbf41903ab182328333061ed186" +dependencies = [ + "alloy-dyn-abi 0.8.13", + "alloy-json-abi 0.8.13", + "alloy-primitives 0.8.13", + "alloy-rlp", + "alloy-sol-types 0.8.13", ] [[package]] @@ -162,10 +249,27 @@ version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cb6e6436a9530f25010d13653e206fab4c9feddacf21a54de8d7311b275bc56b" dependencies = [ - "alloy-json-abi", - "alloy-primitives", - "alloy-sol-type-parser", - "alloy-sol-types", + "alloy-json-abi 0.7.6", + "alloy-primitives 0.7.6", + "alloy-sol-type-parser 0.7.6", + "alloy-sol-types 0.7.6", + "const-hex", + "itoa", + "serde", + "serde_json", + "winnow 0.6.13", +] + +[[package]] +name = "alloy-dyn-abi" +version = "0.8.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1cf633ae9a1f0c82fdb9e559ed2be1c8e415c3e48fc47e1feaf32c6078ec0cdd" +dependencies = [ + "alloy-json-abi 0.8.13", + "alloy-primitives 0.8.13", + "alloy-sol-type-parser 0.8.14", + "alloy-sol-types 0.8.13", "const-hex", "itoa", "serde", @@ -173,29 +277,81 @@ dependencies = [ "winnow 0.6.13", ] +[[package]] +name = "alloy-eip2930" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0069cf0642457f87a01a014f6dc29d5d893cd4fd8fddf0c3cdfad1bb3ebafc41" +dependencies = [ + "alloy-primitives 0.8.13", + "alloy-rlp", + "serde", +] + +[[package]] +name = "alloy-eip7702" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c986539255fb839d1533c128e190e557e52ff652c9ef62939e233a81dd93f7e" +dependencies = [ + "alloy-primitives 0.8.13", + "alloy-rlp", + "derive_more 1.0.0", + "serde", +] + [[package]] name = "alloy-eips" version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "aa4b0fc6a572ef2eebda0a31a5e393d451abda703fec917c75d9615d8c978cf2" dependencies = [ - "alloy-primitives", + "alloy-primitives 0.7.6", "alloy-rlp", - "alloy-serde", + "alloy-serde 0.1.3", "c-kzg", "once_cell", "serde", "sha2", ] +[[package]] +name = "alloy-eips" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8dedb328c2114284f767e075589ca9de8d5e9c8a91333402f4804a584ed71a38" +dependencies = [ + "alloy-eip2930", + "alloy-eip7702", + "alloy-primitives 0.8.13", + "alloy-rlp", + "alloy-serde 0.7.0", + "c-kzg", + "derive_more 1.0.0", + "once_cell", + "serde", + "sha2", +] + [[package]] name = "alloy-genesis" version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "48450f9c6f0821c1eee00ed912942492ed4f11dd69532825833de23ecc7a2256" dependencies = [ - "alloy-primitives", - "alloy-serde", + "alloy-primitives 0.7.6", + "alloy-serde 0.1.3", + "serde", +] + +[[package]] +name = "alloy-genesis" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4841e8dd4e0f53d76b501fd4c6bc21d95d688bc8ebf0ea359fc6c7ab65b48742" +dependencies = [ + "alloy-primitives 0.8.13", + "alloy-serde 0.7.0", "serde", ] @@ -205,8 +361,20 @@ version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "aaeaccd50238126e3a0ff9387c7c568837726ad4f4e399b528ca88104d6c25ef" dependencies = [ - "alloy-primitives", - "alloy-sol-type-parser", + "alloy-primitives 0.7.6", + "alloy-sol-type-parser 0.7.6", + "serde", + "serde_json", +] + +[[package]] +name = "alloy-json-abi" +version = "0.8.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a500037938085feed8a20dbfc8fce58c599db68c948cfae711147175dee392c" +dependencies = [ + "alloy-primitives 0.8.13", + "alloy-sol-type-parser 0.8.14", "serde", "serde_json", ] @@ -217,7 +385,21 @@ version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d484c2a934d0a4d86f8ad4db8113cb1d607707a6c54f6e78f4f1b4451b47aa70" dependencies = [ - "alloy-primitives", + "alloy-primitives 0.7.6", + "serde", + "serde_json", + "thiserror", + "tracing", +] + +[[package]] +name = "alloy-json-rpc" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "254f770918f96dc4ec88a15e6e2e243358e1719d66b40ef814428e7697079d25" +dependencies = [ + "alloy-primitives 0.8.13", + "alloy-sol-types 0.8.13", "serde", "serde_json", "thiserror", @@ -230,25 +412,86 @@ version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7a20eba9bc551037f0626d6d29e191888638d979943fa4e842e9e6fc72bf0565" dependencies = [ - "alloy-consensus", - "alloy-eips", - "alloy-json-rpc", - "alloy-primitives", - "alloy-rpc-types-eth", - "alloy-serde", - "alloy-signer", - "alloy-sol-types", + "alloy-consensus 0.1.3", + "alloy-eips 0.1.3", + "alloy-json-rpc 0.1.3", + "alloy-primitives 0.7.6", + "alloy-rpc-types-eth 0.1.3", + "alloy-serde 0.1.3", + "alloy-signer 0.1.3", + "alloy-sol-types 0.7.6", + "async-trait", + "auto_impl", + "futures-utils-wasm", + "thiserror", +] + +[[package]] +name = "alloy-network" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "931dd176c6e33355f3dc0170ec69cf5b951f4d73870b276e2c837ab35f9c5136" +dependencies = [ + "alloy-consensus 0.7.0", + "alloy-consensus-any", + "alloy-eips 0.7.0", + "alloy-json-rpc 0.7.0", + "alloy-network-primitives", + "alloy-primitives 0.8.13", + "alloy-rpc-types-any", + "alloy-rpc-types-eth 0.7.0", + "alloy-serde 0.7.0", + "alloy-signer 0.7.0", + "alloy-sol-types 0.8.13", "async-trait", "auto_impl", "futures-utils-wasm", + "serde", + "serde_json", "thiserror", ] +[[package]] +name = "alloy-network-primitives" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa6ec0f23be233e851e31c5e4badfedfa9c7bc177bc37f4e03616072cd40a806" +dependencies = [ + "alloy-consensus 0.7.0", + "alloy-eips 0.7.0", + "alloy-primitives 0.8.13", + "alloy-serde 0.7.0", + "serde", +] + [[package]] name = "alloy-primitives" version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f783611babedbbe90db3478c120fb5f5daacceffc210b39adc0af4fe0da70bad" +dependencies = [ + "alloy-rlp", + "bytes", + "cfg-if", + "const-hex", + "derive_more 0.99.18", + "getrandom", + "hex-literal", + "itoa", + "k256", + "keccak-asm", + "proptest", + "rand", + "ruint", + "serde", + "tiny-keccak", +] + +[[package]] +name = "alloy-primitives" +version = "0.8.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3aeeb5825c2fc8c2662167058347cd0cafc3cb15bcb5cdb1758a63c2dca0409e" dependencies = [ "alloy-rlp", "arbitrary", @@ -256,18 +499,23 @@ dependencies = [ "cfg-if", "const-hex", "derive_arbitrary", - "derive_more", - "ethereum_ssz", + "derive_more 1.0.0", + "foldhash", "getrandom", + "hashbrown 0.15.2", "hex-literal", + "indexmap 2.6.0", "itoa", "k256", "keccak-asm", + "paste", "proptest", "proptest-derive", "rand", "ruint", + "rustc-hash", "serde", + "sha3", "tiny-keccak", ] @@ -278,15 +526,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ad5d89acb7339fad13bc69e7b925232f242835bfd91c82fcb9326b36481bd0f0" dependencies = [ "alloy-chains", - "alloy-consensus", - "alloy-eips", - "alloy-json-rpc", - "alloy-network", - "alloy-primitives", - "alloy-rpc-client", - "alloy-rpc-types-eth", - "alloy-transport", - "alloy-transport-http", + "alloy-consensus 0.1.3", + "alloy-eips 0.1.3", + "alloy-json-rpc 0.1.3", + "alloy-network 0.1.3", + "alloy-primitives 0.7.6", + "alloy-rpc-client 0.1.3", + "alloy-rpc-types-eth 0.1.3", + "alloy-transport 0.1.3", + "alloy-transport-http 0.1.3", "async-stream", "async-trait", "auto_impl", @@ -303,11 +551,48 @@ dependencies = [ "url", ] +[[package]] +name = "alloy-provider" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5545e2cbf2f8f24c68bb887ba0294fa12a2f816b9e72c4f226cd137b77d0e294" +dependencies = [ + "alloy-chains", + "alloy-consensus 0.7.0", + "alloy-eips 0.7.0", + "alloy-json-rpc 0.7.0", + "alloy-network 0.7.0", + "alloy-network-primitives", + "alloy-primitives 0.8.13", + "alloy-rpc-client 0.7.0", + "alloy-rpc-types-eth 0.7.0", + "alloy-transport 0.7.0", + "alloy-transport-http 0.7.0", + "async-stream", + "async-trait", + "auto_impl", + "dashmap 6.1.0", + "futures", + "futures-utils-wasm", + "lru", + "parking_lot", + "pin-project", + "reqwest", + "schnellru", + "serde", + "serde_json", + "thiserror", + "tokio", + "tracing", + "url", + "wasmtimer", +] + [[package]] name = "alloy-rlp" -version = "0.3.7" +version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a43b18702501396fa9bcdeecd533bc85fac75150d308fc0f6800a01e6234a003" +checksum = "da0822426598f95e45dd1ea32a738dac057529a709ee645fcc516ffa4cbde08f" dependencies = [ "alloy-rlp-derive", "arrayvec", @@ -316,13 +601,13 @@ dependencies = [ [[package]] name = "alloy-rlp-derive" -version = "0.3.7" +version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d83524c1f6162fcb5b0decf775498a125066c86dda6066ed609531b0e912f85a" +checksum = "2b09cae092c27b6f1bde952653a22708691802e57bfef4a2973b80bea21efd3f" dependencies = [ "proc-macro2", "quote", - "syn 2.0.68", + "syn 2.0.89", ] [[package]] @@ -331,9 +616,9 @@ version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "479ce003e8c74bbbc7d4235131c1d6b7eaf14a533ae850295b90d240340989cb" dependencies = [ - "alloy-json-rpc", - "alloy-transport", - "alloy-transport-http", + "alloy-json-rpc 0.1.3", + "alloy-transport 0.1.3", + "alloy-transport-http 0.1.3", "futures", "pin-project", "reqwest", @@ -341,19 +626,66 @@ dependencies = [ "serde_json", "tokio", "tokio-stream", - "tower", + "tower 0.4.13", "tracing", "url", ] +[[package]] +name = "alloy-rpc-client" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aed9e40c2a73265ebf70f1e48303ee55920282e1ea5971e832873fb2d32cea74" +dependencies = [ + "alloy-json-rpc 0.7.0", + "alloy-primitives 0.8.13", + "alloy-transport 0.7.0", + "alloy-transport-http 0.7.0", + "futures", + "pin-project", + "reqwest", + "serde", + "serde_json", + "tokio", + "tokio-stream", + "tower 0.5.1", + "tracing", + "url", + "wasmtimer", +] + [[package]] name = "alloy-rpc-types" version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0dfa1dd3e0bc3a3d89744fba8d1511216e83257160da2cd028a18b7d9c026030" dependencies = [ - "alloy-rpc-types-eth", - "alloy-serde", + "alloy-rpc-types-eth 0.1.3", + "alloy-serde 0.1.3", +] + +[[package]] +name = "alloy-rpc-types" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42dea20fa715a6f39ec7adc735cfd9567342870737270ac67795d55896527772" +dependencies = [ + "alloy-primitives 0.8.13", + "alloy-rpc-types-eth 0.7.0", + "alloy-serde 0.7.0", + "serde", +] + +[[package]] +name = "alloy-rpc-types-any" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "79d7620e22d6ed7c58451dd303d0501ade5a8bec9dc8daef0fbc48ceffabbae1" +dependencies = [ + "alloy-consensus 0.7.0", + "alloy-consensus-any", + "alloy-rpc-types-eth 0.7.0", + "alloy-serde 0.7.0", ] [[package]] @@ -362,25 +694,56 @@ version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "13bd7aa9ff9e67f1ba7ee0dd8cebfc95831d1649b0e4eeefae940dc3681079fa" dependencies = [ - "alloy-consensus", - "alloy-eips", - "alloy-primitives", + "alloy-consensus 0.1.3", + "alloy-eips 0.1.3", + "alloy-primitives 0.7.6", "alloy-rlp", - "alloy-serde", - "alloy-sol-types", + "alloy-serde 0.1.3", + "alloy-sol-types 0.7.6", "itertools 0.13.0", "serde", "serde_json", "thiserror", ] +[[package]] +name = "alloy-rpc-types-eth" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df34b88df4deeac9ecfc80ad7cbb26a33e57437b9db8be5b952792feef6134bc" +dependencies = [ + "alloy-consensus 0.7.0", + "alloy-consensus-any", + "alloy-eips 0.7.0", + "alloy-network-primitives", + "alloy-primitives 0.8.13", + "alloy-rlp", + "alloy-serde 0.7.0", + "alloy-sol-types 0.8.13", + "derive_more 1.0.0", + "itertools 0.13.0", + "serde", + "serde_json", +] + [[package]] name = "alloy-serde" version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8913f9e825068d77c516188c221c44f78fd814fce8effe550a783295a2757d19" dependencies = [ - "alloy-primitives", + "alloy-primitives 0.7.6", + "serde", + "serde_json", +] + +[[package]] +name = "alloy-serde" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "43a89fd4cc3f96b3c5c0dd1cebeb63323e4659bbdc837117fa3fd5ac168df7d9" +dependencies = [ + "alloy-primitives 0.8.13", "serde", "serde_json", ] @@ -391,7 +754,21 @@ version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f740e13eb4c6a0e4d0e49738f1e86f31ad2d7ef93be499539f492805000f7237" dependencies = [ - "alloy-primitives", + "alloy-primitives 0.7.6", + "async-trait", + "auto_impl", + "elliptic-curve", + "k256", + "thiserror", +] + +[[package]] +name = "alloy-signer" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "532010243a96d1f8593c2246ec3971bc52303884fa1e43ca0a776798ba178910" +dependencies = [ + "alloy-primitives 0.8.13", "async-trait", "auto_impl", "elliptic-curve", @@ -405,10 +782,10 @@ version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "87db68d926887393a1d0f9c43833b44446ea29d603291e7b20e5d115f31aa4e3" dependencies = [ - "alloy-consensus", - "alloy-network", - "alloy-primitives", - "alloy-signer", + "alloy-consensus 0.1.3", + "alloy-network 0.1.3", + "alloy-primitives 0.7.6", + "alloy-signer 0.1.3", "async-trait", "elliptic-curve", "eth-keystore", @@ -417,54 +794,120 @@ dependencies = [ "thiserror", ] +[[package]] +name = "alloy-signer-local" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8080c0ab2dc729b0cbb183843d08e78d2a1629140c9fc16234d2272abb483bd" +dependencies = [ + "alloy-consensus 0.7.0", + "alloy-network 0.7.0", + "alloy-primitives 0.8.13", + "alloy-signer 0.7.0", + "async-trait", + "k256", + "rand", + "thiserror", +] + [[package]] name = "alloy-sol-macro" version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4bad41a7c19498e3f6079f7744656328699f8ea3e783bdd10d85788cd439f572" dependencies = [ - "alloy-sol-macro-expander", - "alloy-sol-macro-input", + "alloy-sol-macro-expander 0.7.6", + "alloy-sol-macro-input 0.7.6", "proc-macro-error", "proc-macro2", "quote", - "syn 2.0.68", + "syn 2.0.89", +] + +[[package]] +name = "alloy-sol-macro" +version = "0.8.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c0279d09463a4695788a3622fd95443625f7be307422deba4b55dd491a9c7a1" +dependencies = [ + "alloy-sol-macro-expander 0.8.13", + "alloy-sol-macro-input 0.8.13", + "proc-macro-error2", + "proc-macro2", + "quote", + "syn 2.0.89", +] + +[[package]] +name = "alloy-sol-macro-expander" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fd9899da7d011b4fe4c406a524ed3e3f963797dbc93b45479d60341d3a27b252" +dependencies = [ + "alloy-json-abi 0.7.6", + "alloy-sol-macro-input 0.7.6", + "const-hex", + "heck", + "indexmap 2.6.0", + "proc-macro-error", + "proc-macro2", + "quote", + "syn 2.0.89", + "syn-solidity 0.7.6", + "tiny-keccak", +] + +[[package]] +name = "alloy-sol-macro-expander" +version = "0.8.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4feea540fc8233df2ad1156efd744b2075372f43a8f942a68b3b19c8a00e2c12" +dependencies = [ + "alloy-json-abi 0.8.13", + "alloy-sol-macro-input 0.8.13", + "const-hex", + "heck", + "indexmap 2.6.0", + "proc-macro-error2", + "proc-macro2", + "quote", + "syn 2.0.89", + "syn-solidity 0.8.14", + "tiny-keccak", ] [[package]] -name = "alloy-sol-macro-expander" +name = "alloy-sol-macro-input" version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fd9899da7d011b4fe4c406a524ed3e3f963797dbc93b45479d60341d3a27b252" +checksum = "d32d595768fdc61331a132b6f65db41afae41b9b97d36c21eb1b955c422a7e60" dependencies = [ - "alloy-json-abi", - "alloy-sol-macro-input", + "alloy-json-abi 0.7.6", "const-hex", + "dunce", "heck", - "indexmap 2.2.6", - "proc-macro-error", "proc-macro2", "quote", - "syn 2.0.68", - "syn-solidity", - "tiny-keccak", + "serde_json", + "syn 2.0.89", + "syn-solidity 0.7.6", ] [[package]] name = "alloy-sol-macro-input" -version = "0.7.6" +version = "0.8.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d32d595768fdc61331a132b6f65db41afae41b9b97d36c21eb1b955c422a7e60" +checksum = "2a0ad281f3d1b613af814b66977ee698e443d4644a1510962d0241f26e0e53ae" dependencies = [ - "alloy-json-abi", + "alloy-json-abi 0.8.13", "const-hex", "dunce", "heck", "proc-macro2", "quote", "serde_json", - "syn 2.0.68", - "syn-solidity", + "syn 2.0.89", + "syn-solidity 0.8.14", ] [[package]] @@ -476,15 +919,38 @@ dependencies = [ "winnow 0.6.13", ] +[[package]] +name = "alloy-sol-type-parser" +version = "0.8.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac17c6e89a50fb4a758012e4b409d9a0ba575228e69b539fe37d7a1bd507ca4a" +dependencies = [ + "serde", + "winnow 0.6.13", +] + [[package]] name = "alloy-sol-types" version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a49042c6d3b66a9fe6b2b5a8bf0d39fc2ae1ee0310a2a26ffedd79fb097878dd" dependencies = [ - "alloy-json-abi", - "alloy-primitives", - "alloy-sol-macro", + "alloy-json-abi 0.7.6", + "alloy-primitives 0.7.6", + "alloy-sol-macro 0.7.6", + "const-hex", + "serde", +] + +[[package]] +name = "alloy-sol-types" +version = "0.8.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cff34e0682d6665da243a3e81da96f07a2dd50f7e64073e382b1a141f5a2a2f6" +dependencies = [ + "alloy-json-abi 0.8.13", + "alloy-primitives 0.8.13", + "alloy-sol-macro 0.8.13", "const-hex", "serde", ] @@ -495,7 +961,25 @@ version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dd9773e4ec6832346171605c776315544bd06e40f803e7b5b7824b325d5442ca" dependencies = [ - "alloy-json-rpc", + "alloy-json-rpc 0.1.3", + "base64", + "futures-util", + "futures-utils-wasm", + "serde", + "serde_json", + "thiserror", + "tokio", + "tower 0.4.13", + "url", +] + +[[package]] +name = "alloy-transport" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6f295f4b745fb9e4e663d70bc57aed991288912c7aaaf25767def921050ee43" +dependencies = [ + "alloy-json-rpc 0.7.0", "base64", "futures-util", "futures-utils-wasm", @@ -503,8 +987,10 @@ dependencies = [ "serde_json", "thiserror", "tokio", - "tower", + "tower 0.5.1", + "tracing", "url", + "wasmtimer", ] [[package]] @@ -513,15 +999,45 @@ version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ff8ef947b901c0d4e97370f9fa25844cf8b63b1a58fd4011ee82342dc8a9fc6b" dependencies = [ - "alloy-json-rpc", - "alloy-transport", + "alloy-json-rpc 0.1.3", + "alloy-transport 0.1.3", + "reqwest", + "serde_json", + "tower 0.4.13", + "tracing", + "url", +] + +[[package]] +name = "alloy-transport-http" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "39139015a5ec127d9c895b49b484608e27fe4538544f84cdf5eae0bd36339bc6" +dependencies = [ + "alloy-json-rpc 0.7.0", + "alloy-transport 0.7.0", "reqwest", "serde_json", - "tower", + "tower 0.5.1", "tracing", "url", ] +[[package]] +name = "alloy-trie" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6b2e366c0debf0af77766c23694a3f863b02633050e71e096e257ffbd395e50" +dependencies = [ + "alloy-primitives 0.8.13", + "alloy-rlp", + "arrayvec", + "derive_more 1.0.0", + "nybbles", + "smallvec", + "tracing", +] + [[package]] name = "anstream" version = "0.6.14" @@ -726,7 +1242,7 @@ checksum = "16e62a023e7c117e27523144c5d2459f4397fcc3cab0085af8e2224f643a0193" dependencies = [ "proc-macro2", "quote", - "syn 2.0.68", + "syn 2.0.89", ] [[package]] @@ -737,7 +1253,7 @@ checksum = "6e0c28dcc82d7c8ead5cb13beb15405b57b8546e93215673ff8ca0349a028107" dependencies = [ "proc-macro2", "quote", - "syn 2.0.68", + "syn 2.0.89", ] [[package]] @@ -748,7 +1264,7 @@ checksum = "3c87f3f15e7794432337fc718554eaa4dc8f04c9677a950ffe366f20a162ae42" dependencies = [ "proc-macro2", "quote", - "syn 2.0.68", + "syn 2.0.89", ] [[package]] @@ -794,7 +1310,7 @@ checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" name = "basic-example" version = "0.2.0-alpha.1" dependencies = [ - "alloy-primitives", + "alloy-primitives 0.8.13", "openzeppelin-stylus", "stylus-sdk", ] @@ -803,8 +1319,8 @@ dependencies = [ name = "basic-example-script" version = "0.2.0-alpha.1" dependencies = [ - "alloy", - "alloy-primitives", + "alloy 0.7.2", + "alloy-primitives 0.8.13", "basic-example", "koba", "tokio", @@ -814,8 +1330,8 @@ dependencies = [ name = "benches" version = "0.2.0-alpha.1" dependencies = [ - "alloy", - "alloy-primitives", + "alloy 0.7.2", + "alloy-primitives 0.8.13", "e2e", "eyre", "futures", @@ -1029,7 +1545,7 @@ dependencies = [ "heck", "proc-macro2", "quote", - "syn 2.0.68", + "syn 2.0.89", ] [[package]] @@ -1256,8 +1772,8 @@ dependencies = [ name = "cryptography-example" version = "0.2.0-alpha.1" dependencies = [ - "alloy", - "alloy-primitives", + "alloy 0.7.2", + "alloy-primitives 0.8.13", "e2e", "eyre", "openzeppelin-stylus", @@ -1294,7 +1810,7 @@ dependencies = [ "ident_case", "proc-macro2", "quote", - "syn 2.0.68", + "syn 2.0.89", ] [[package]] @@ -1305,7 +1821,7 @@ checksum = "733cabb43482b1a1b53eee8583c2b9e8684d592215ea83efd305dd31bc2f0178" dependencies = [ "darling_core", "quote", - "syn 2.0.68", + "syn 2.0.89", ] [[package]] @@ -1364,7 +1880,7 @@ checksum = "67e77553c4162a157adbf834ebae5b415acbecbeafc7a74b0e886657506a7611" dependencies = [ "proc-macro2", "quote", - "syn 2.0.68", + "syn 2.0.89", ] [[package]] @@ -1377,7 +1893,28 @@ dependencies = [ "proc-macro2", "quote", "rustc_version 0.4.0", - "syn 2.0.68", + "syn 2.0.89", +] + +[[package]] +name = "derive_more" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4a9b99b9cbbe49445b21764dc0625032a89b145a2642e67603e1c936f5458d05" +dependencies = [ + "derive_more-impl", +] + +[[package]] +name = "derive_more-impl" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb7330aeadfbe296029522e6c40f315320aba36fc43a5b3632f3795348f3bd22" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.89", + "unicode-xid", ] [[package]] @@ -1411,7 +1948,7 @@ checksum = "56ce8c6da7551ec6c462cbaf3bfbc75131ebbfa1c944aeaa9dab51ca1c5f0c3b" name = "e2e" version = "0.1.0" dependencies = [ - "alloy", + "alloy 0.7.2", "e2e-proc", "eyre", "koba", @@ -1427,7 +1964,7 @@ version = "0.1.0" dependencies = [ "proc-macro2", "quote", - "syn 2.0.68", + "syn 2.0.89", ] [[package]] @@ -1453,7 +1990,7 @@ dependencies = [ "enum-ordinalize", "proc-macro2", "quote", - "syn 2.0.68", + "syn 2.0.89", ] [[package]] @@ -1518,7 +2055,7 @@ checksum = "0d28318a75d4aead5c4db25382e8ef717932d0346600cacae6357eb5941bc5ff" dependencies = [ "proc-macro2", "quote", - "syn 2.0.68", + "syn 2.0.89", ] [[package]] @@ -1539,7 +2076,7 @@ dependencies = [ "darling", "proc-macro2", "quote", - "syn 2.0.68", + "syn 2.0.89", ] [[package]] @@ -1552,8 +2089,8 @@ checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" name = "erc1155-example" version = "0.2.0-alpha.1" dependencies = [ - "alloy", - "alloy-primitives", + "alloy 0.7.2", + "alloy-primitives 0.8.13", "e2e", "eyre", "openzeppelin-stylus", @@ -1565,8 +2102,8 @@ dependencies = [ name = "erc20-example" version = "0.2.0-alpha.1" dependencies = [ - "alloy", - "alloy-primitives", + "alloy 0.7.2", + "alloy-primitives 0.8.13", "e2e", "eyre", "openzeppelin-stylus", @@ -1578,8 +2115,8 @@ dependencies = [ name = "erc20-permit-example" version = "0.2.0-alpha.1" dependencies = [ - "alloy", - "alloy-primitives", + "alloy 0.7.2", + "alloy-primitives 0.8.13", "e2e", "eyre", "openzeppelin-stylus", @@ -1591,9 +2128,9 @@ dependencies = [ name = "erc721-consecutive-example" version = "0.2.0-alpha.1" dependencies = [ - "alloy", - "alloy-primitives", - "alloy-sol-types", + "alloy 0.7.2", + "alloy-primitives 0.8.13", + "alloy-sol-types 0.8.13", "e2e", "eyre", "openzeppelin-stylus", @@ -1606,8 +2143,8 @@ dependencies = [ name = "erc721-example" version = "0.2.0-alpha.1" dependencies = [ - "alloy", - "alloy-primitives", + "alloy 0.7.2", + "alloy-primitives 0.8.13", "e2e", "eyre", "openzeppelin-stylus", @@ -1620,8 +2157,8 @@ dependencies = [ name = "erc721-metadata-example" version = "0.2.0-alpha.1" dependencies = [ - "alloy", - "alloy-primitives", + "alloy 0.7.2", + "alloy-primitives 0.8.13", "e2e", "eyre", "openzeppelin-stylus", @@ -1662,44 +2199,6 @@ dependencies = [ "uuid 0.8.2", ] -[[package]] -name = "ethbloom" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c22d4b5885b6aa2fe5e8b9329fb8d232bf739e434e6b87347c63bdd00c120f60" -dependencies = [ - "crunchy", - "fixed-hash", - "impl-rlp", - "impl-serde", - "tiny-keccak", -] - -[[package]] -name = "ethereum-types" -version = "0.14.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "02d215cbf040552efcbe99a38372fe80ab9d00268e20012b79fcd0f073edd8ee" -dependencies = [ - "ethbloom", - "fixed-hash", - "impl-rlp", - "impl-serde", - "primitive-types", - "uint", -] - -[[package]] -name = "ethereum_ssz" -version = "0.5.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7d3627f83d8b87b432a5fad9934b4565260722a141a2c40f371f8080adec9425" -dependencies = [ - "ethereum-types", - "itertools 0.10.5", - "smallvec", -] - [[package]] name = "eyre" version = "0.6.12" @@ -1749,7 +2248,6 @@ version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "835c052cb0c08c1acf6ffd71c022172e18723949c8282f2b9f27efbc51e64534" dependencies = [ - "arbitrary", "byteorder", "rand", "rustc-hex", @@ -1762,6 +2260,12 @@ version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" +[[package]] +name = "foldhash" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f81ec6369c545a7d40e4589b5597581fa1c441fe1cce96dd1de43159910a36a2" + [[package]] name = "foreign-types" version = "0.3.2" @@ -1848,7 +2352,7 @@ checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" dependencies = [ "proc-macro2", "quote", - "syn 2.0.68", + "syn 2.0.89", ] [[package]] @@ -1961,6 +2465,12 @@ dependencies = [ "ahash 0.7.8", ] +[[package]] +name = "hashbrown" +version = "0.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "43a3c133739dddd0d2990f9a4bdf8eb4b21ef50e4851ca85ab661199821d510e" + [[package]] name = "hashbrown" version = "0.14.5" @@ -1971,6 +2481,16 @@ dependencies = [ "allocator-api2", ] +[[package]] +name = "hashbrown" +version = "0.15.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf151400ff0baff5465007dd2f3e717f3fe502074ca563069ce3a6629d07b289" +dependencies = [ + "foldhash", + "serde", +] + [[package]] name = "heck" version = "0.5.0" @@ -2097,7 +2617,7 @@ dependencies = [ "pin-project-lite", "socket2", "tokio", - "tower", + "tower 0.4.13", "tower-service", "tracing", ] @@ -2127,24 +2647,6 @@ dependencies = [ "parity-scale-codec", ] -[[package]] -name = "impl-rlp" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f28220f89297a075ddc7245cd538076ee98b01f2a9c23a53a4f1105d5a322808" -dependencies = [ - "rlp", -] - -[[package]] -name = "impl-serde" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ebc88fc67028ae3db0c853baa36269d398d5f45b6982f95549ff5def78c935cd" -dependencies = [ - "serde", -] - [[package]] name = "impl-trait-for-tuples" version = "0.2.2" @@ -2174,12 +2676,14 @@ dependencies = [ [[package]] name = "indexmap" -version = "2.2.6" +version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "168fb715dda47215e360912c096649d23d58bf392ac62f73919e831745e40f26" +checksum = "707907fe3c25f5424cce2cb7e1cbcafee6bdbe735ca90ef77c29e84591e5b9da" dependencies = [ + "arbitrary", "equivalent", - "hashbrown 0.14.5", + "hashbrown 0.15.2", + "serde", ] [[package]] @@ -2280,7 +2784,7 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "80e92e1148d087df999396266311bece9e5311c352821872cccaf5dc67117cfc" dependencies = [ - "alloy", + "alloy 0.1.4", "brotli2", "bytesize", "clap", @@ -2395,8 +2899,8 @@ dependencies = [ name = "merkle-proofs-example" version = "0.2.0-alpha.1" dependencies = [ - "alloy-primitives", - "alloy-sol-types", + "alloy-primitives 0.8.13", + "alloy-sol-types 0.8.13", "openzeppelin-crypto", "stylus-sdk", ] @@ -2409,9 +2913,9 @@ checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" [[package]] name = "mini-alloc" -version = "0.6.0" +version = "0.7.0-beta.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "14eacc4bfcf10da9b6d5185ef51b2dc75434afac34b4d8aabe40f6b141ee071c" +checksum = "6d79b46612e3fc76138ed930cd2e4bbd26ada11954a6d312e3affe4b56df0081" dependencies = [ "cfg-if", ] @@ -2458,13 +2962,13 @@ dependencies = [ name = "motsu-proc" version = "0.2.0" dependencies = [ - "alloy-primitives", - "alloy-sol-types", + "alloy-primitives 0.8.13", + "alloy-sol-types 0.8.13", "motsu", "proc-macro2", "quote", "stylus-sdk", - "syn 2.0.68", + "syn 2.0.89", ] [[package]] @@ -2540,7 +3044,17 @@ checksum = "681030a937600a36906c185595136d26abfebb4aa9c65701cefcaf8578bb982b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.68", + "syn 2.0.89", +] + +[[package]] +name = "nybbles" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95f06be0417d97f81fe4e5c86d7d01b392655a9cac9c19a848aa033e18937b23" +dependencies = [ + "const-hex", + "smallvec", ] [[package]] @@ -2581,7 +3095,7 @@ checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.68", + "syn 2.0.89", ] [[package]] @@ -2620,11 +3134,11 @@ dependencies = [ name = "openzeppelin-stylus" version = "0.2.0-alpha.1" dependencies = [ - "alloy-primitives", - "alloy-sol-macro", - "alloy-sol-macro-expander", - "alloy-sol-macro-input", - "alloy-sol-types", + "alloy-primitives 0.8.13", + "alloy-sol-macro 0.8.13", + "alloy-sol-macro-expander 0.8.13", + "alloy-sol-macro-input 0.8.13", + "alloy-sol-types 0.8.13", "keccak-const", "motsu", "openzeppelin-stylus-proc", @@ -2639,15 +3153,15 @@ dependencies = [ "convert_case 0.6.0", "proc-macro2", "quote", - "syn 2.0.68", + "syn 2.0.89", ] [[package]] name = "ownable-example" version = "0.2.0-alpha.1" dependencies = [ - "alloy", - "alloy-primitives", + "alloy 0.7.2", + "alloy-primitives 0.8.13", "e2e", "eyre", "openzeppelin-stylus", @@ -2659,8 +3173,8 @@ dependencies = [ name = "ownable-two-step" version = "0.2.0-alpha.1" dependencies = [ - "alloy", - "alloy-primitives", + "alloy 0.7.2", + "alloy-primitives 0.8.13", "e2e", "eyre", "openzeppelin-stylus", @@ -2772,7 +3286,7 @@ checksum = "2f38a4412a78282e09a2cf38d195ea5420d15ba0602cb375210efbc877243965" dependencies = [ "proc-macro2", "quote", - "syn 2.0.68", + "syn 2.0.89", ] [[package]] @@ -2817,8 +3331,6 @@ checksum = "0b34d9fd68ae0b74a41b21c03c2f62847aa0ffea044eee893b4c140b37e244e2" dependencies = [ "fixed-hash", "impl-codec", - "impl-rlp", - "impl-serde", "uint", ] @@ -2855,11 +3367,33 @@ dependencies = [ "version_check", ] +[[package]] +name = "proc-macro-error-attr2" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96de42df36bb9bba5542fe9f1a054b8cc87e172759a1868aa05c1f3acc89dfc5" +dependencies = [ + "proc-macro2", + "quote", +] + +[[package]] +name = "proc-macro-error2" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "11ec05c52be0a07b08061f7dd003e7d7092e0472bc731b4af7bb1ef876109802" +dependencies = [ + "proc-macro-error-attr2", + "proc-macro2", + "quote", + "syn 2.0.89", +] + [[package]] name = "proc-macro2" -version = "1.0.86" +version = "1.0.92" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" +checksum = "37d3544b3f2748c54e147655edb5025752e2303145b5aefb3c3ea2c78b973bb0" dependencies = [ "unicode-ident", ] @@ -2886,13 +3420,13 @@ dependencies = [ [[package]] name = "proptest-derive" -version = "0.4.0" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9cf16337405ca084e9c78985114633b6827711d22b9e6ef6c6c0d665eb3f0b6e" +checksum = "6ff7ff745a347b87471d859a377a9a404361e7efc2a971d73424a6d183c0fc77" dependencies = [ "proc-macro2", "quote", - "syn 1.0.109", + "syn 2.0.89", ] [[package]] @@ -2945,6 +3479,7 @@ dependencies = [ "libc", "rand_chacha", "rand_core", + "serde", ] [[package]] @@ -3018,9 +3553,9 @@ dependencies = [ [[package]] name = "regex" -version = "1.10.5" +version = "1.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b91213439dad192326a0d7c6ee3955910425f441d7038e0d6933b0aec5c4517f" +checksum = "b544ef1b4eac5dc2db33ea63606ae9ffcfac26c1416a2806ae0bf5f56b201191" dependencies = [ "aho-corasick", "memchr", @@ -3030,9 +3565,9 @@ dependencies = [ [[package]] name = "regex-automata" -version = "0.4.7" +version = "0.4.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38caf58cc5ef2fed281f89292ef23f6365465ed9a41b7a7754eb4e26496c92df" +checksum = "809e8dc61f6de73b46c85f4c96486310fe304c434cfa43669d7b40f711150908" dependencies = [ "aho-corasick", "memchr", @@ -3041,9 +3576,9 @@ dependencies = [ [[package]] name = "regex-syntax" -version = "0.8.4" +version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a66a03ae7c801facd77a29370b4faec201768915ac14a721ba36f20bc9c209b" +checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c" [[package]] name = "region" @@ -3094,7 +3629,7 @@ dependencies = [ "serde", "serde_json", "serde_urlencoded", - "sync_wrapper", + "sync_wrapper 1.0.1", "tokio", "tokio-native-tls", "tower-service", @@ -3192,6 +3727,12 @@ version = "0.1.24" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" +[[package]] +name = "rustc-hash" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "583034fd73374156e66797ed8e5b0d5690409c9226b22d87cb7f19821c05d152" + [[package]] name = "rustc-hex" version = "2.1.0" @@ -3273,8 +3814,8 @@ checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" name = "safe-erc20-example" version = "0.2.0-alpha.1" dependencies = [ - "alloy", - "alloy-primitives", + "alloy 0.7.2", + "alloy-primitives 0.8.13", "e2e", "eyre", "openzeppelin-stylus", @@ -3300,6 +3841,17 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "schnellru" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c9a8ef13a93c54d20580de1e5c413e624e53121d42fc7e2c11d10ef7f8b02367" +dependencies = [ + "ahash 0.8.11", + "cfg-if", + "hashbrown 0.13.2", +] + [[package]] name = "scopeguard" version = "1.2.0" @@ -3413,7 +3965,7 @@ checksum = "500cbc0ebeb6f46627f50f3f5811ccf6bf00643be300b4c3eabc0ef55dc5b5ba" dependencies = [ "proc-macro2", "quote", - "syn 2.0.68", + "syn 2.0.89", ] [[package]] @@ -3582,36 +4134,38 @@ dependencies = [ "proc-macro2", "quote", "rustversion", - "syn 2.0.68", + "syn 2.0.89", ] [[package]] name = "stylus-proc" -version = "0.6.0" +version = "0.7.0-beta.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9fd02e91dffe7b73df84a861c992494d6b72054bc9a17fe73e147e34e9a64ef3" +checksum = "8abd5d2cb3a10a36101b3d9243eda29daa58aad89b93979afe77c4be89068413" dependencies = [ - "alloy-primitives", - "alloy-sol-types", + "alloy-primitives 0.8.13", + "alloy-sol-types 0.8.13", "cfg-if", "convert_case 0.6.0", "lazy_static", + "proc-macro-error", "proc-macro2", "quote", "regex", "sha3", - "syn 1.0.109", - "syn-solidity", + "syn 2.0.89", + "syn-solidity 0.8.14", + "trybuild", ] [[package]] name = "stylus-sdk" -version = "0.6.0" +version = "0.7.0-beta.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26042693706e29fb7e3cf3d71c99534ac97fca98b6f81ba77ab658022ab2e210" +checksum = "caa33222d37101b3ba7064f1099ae38c7e388eaeac422e58260b7d00346a5267" dependencies = [ - "alloy-primitives", - "alloy-sol-types", + "alloy-primitives 0.8.13", + "alloy-sol-types 0.8.13", "cfg-if", "derivative", "hex", @@ -3640,9 +4194,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.68" +version = "2.0.89" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "901fa70d88b9d6c98022e23b4136f9f3e54e4662c3bc1bd1d84a42a9a0f0c1e9" +checksum = "44d46482f1c1c87acd84dea20c1bf5ebff4c757009ed6bf19cfd36fb10e92c4e" dependencies = [ "proc-macro2", "quote", @@ -3658,9 +4212,27 @@ dependencies = [ "paste", "proc-macro2", "quote", - "syn 2.0.68", + "syn 2.0.89", +] + +[[package]] +name = "syn-solidity" +version = "0.8.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da0523f59468a2696391f2a772edc089342aacd53c3caa2ac3264e598edf119b" +dependencies = [ + "paste", + "proc-macro2", + "quote", + "syn 2.0.89", ] +[[package]] +name = "sync_wrapper" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2047c6ded9c721764247e62cd3b03c09ffc529b2ba5b10ec482ae507a4a70160" + [[package]] name = "sync_wrapper" version = "1.0.1" @@ -3679,6 +4251,12 @@ version = "0.12.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e1fc403891a21bcfb7c37834ba66a547a8f402146eba7265b5a6d88059c9ff2f" +[[package]] +name = "target-triple" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42a4d50cdb458045afc8131fd91b64904da29548bcb63c7236e0844936c13078" + [[package]] name = "tempfile" version = "3.10.1" @@ -3691,6 +4269,15 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "termcolor" +version = "1.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06794f8f6c5c898b3275aebefa6b8a1cb24cd2c6c79397ab15774837a0bc5755" +dependencies = [ + "winapi-util", +] + [[package]] name = "thiserror" version = "1.0.61" @@ -3708,7 +4295,7 @@ checksum = "46c3384250002a6d5af4d114f2845d37b57521033f30d5c3f46c4d70e1197533" dependencies = [ "proc-macro2", "quote", - "syn 2.0.68", + "syn 2.0.89", ] [[package]] @@ -3771,7 +4358,7 @@ checksum = "5f5ae998a069d4b5aba8ee9dad856af7d520c3699e6159b185c2acd48155d39a" dependencies = [ "proc-macro2", "quote", - "syn 2.0.68", + "syn 2.0.89", ] [[package]] @@ -3836,7 +4423,7 @@ version = "0.21.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6a8534fd7f78b5405e860340ad6575217ce99f38d4d5c8f2442cb5ecb50090e1" dependencies = [ - "indexmap 2.2.6", + "indexmap 2.6.0", "toml_datetime", "winnow 0.5.40", ] @@ -3847,7 +4434,7 @@ version = "0.22.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f21c7aaf97f1bd9ca9d4f9e73b0a6c74bd5afef56f2bc931943a6e1c37e04e38" dependencies = [ - "indexmap 2.2.6", + "indexmap 2.6.0", "serde", "serde_spanned", "toml_datetime", @@ -3870,17 +4457,31 @@ dependencies = [ "tracing", ] +[[package]] +name = "tower" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2873938d487c3cfb9aed7546dc9f2711d867c9f90c46b889989a2cb84eba6b4f" +dependencies = [ + "futures-core", + "futures-util", + "pin-project-lite", + "sync_wrapper 0.1.2", + "tower-layer", + "tower-service", +] + [[package]] name = "tower-layer" -version = "0.3.2" +version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c20c8dbed6283a09604c3e69b4b7eeb54e298b8a600d4d5ecb5ad39de609f1d0" +checksum = "121c2a6cda46980bb0fcd1647ffaf6cd3fc79a013de288782836f6df9c48780e" [[package]] name = "tower-service" -version = "0.3.2" +version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6bc1c9ce2b5135ac7f93c72918fc37feb872bdc6a5533a8b85eb4b86bfdae52" +checksum = "8df9b6e13f2d32c91b9bd719c00d1958837bc7dec474d94952798cc8e69eeec3" [[package]] name = "tracing" @@ -3902,7 +4503,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.68", + "syn 2.0.89", ] [[package]] @@ -3920,6 +4521,21 @@ version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" +[[package]] +name = "trybuild" +version = "1.0.101" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8dcd332a5496c026f1e14b7f3d2b7bd98e509660c04239c58b0ba38a12daded4" +dependencies = [ + "glob", + "serde", + "serde_derive", + "serde_json", + "target-triple", + "termcolor", + "toml", +] + [[package]] name = "typenum" version = "1.17.0" @@ -3938,7 +4554,6 @@ version = "0.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "76f64bba2c53b04fcab63c01a7d7427eadc821e3bc48c34dc9ba29c501164b52" dependencies = [ - "arbitrary", "byteorder", "crunchy", "hex", @@ -3984,6 +4599,12 @@ version = "0.1.13" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0336d538f7abc86d282a4189614dfaa90810dfc2c6f6427eaf88e16311dd225d" +[[package]] +name = "unicode-xid" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ebc1c04c71510c7f702b52b7c350734c9ff1295c464a03335b00bb84fc54f853" + [[package]] name = "url" version = "2.5.2" @@ -4039,8 +4660,8 @@ checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" name = "vesting-wallet-example" version = "0.2.0-alpha.1" dependencies = [ - "alloy", - "alloy-primitives", + "alloy 0.7.2", + "alloy-primitives 0.8.13", "e2e", "eyre", "openzeppelin-stylus", @@ -4093,7 +4714,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.68", + "syn 2.0.89", "wasm-bindgen-shared", ] @@ -4150,7 +4771,7 @@ checksum = "e94f17b526d0a461a191c78ea52bbce64071ed5c04c9ffe424dcb38f74171bb7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.68", + "syn 2.0.89", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -4305,6 +4926,20 @@ dependencies = [ "url", ] +[[package]] +name = "wasmtimer" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0048ad49a55b9deb3953841fa1fc5858f0efbcb7a18868c899a360269fac1b23" +dependencies = [ + "futures", + "js-sys", + "parking_lot", + "pin-utils", + "slab", + "wasm-bindgen", +] + [[package]] name = "wast" version = "212.0.0" @@ -4353,6 +4988,15 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" +[[package]] +name = "winapi-util" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf221c93e13a30d793f7645a0e7762c55d169dbb0a49671918a2319d289b10bb" +dependencies = [ + "windows-sys 0.52.0", +] + [[package]] name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" @@ -4595,7 +5239,7 @@ checksum = "15e934569e47891f7d9411f1a451d947a60e000ab3bd24fbb970f000387d1b3b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.68", + "syn 2.0.89", ] [[package]] @@ -4615,5 +5259,5 @@ checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69" dependencies = [ "proc-macro2", "quote", - "syn 2.0.68", + "syn 2.0.89", ] diff --git a/Cargo.toml b/Cargo.toml index cf26be1b5..841770e5d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -69,10 +69,10 @@ pedantic = "warn" all = "warn" [workspace.dependencies] -# stylus-related -stylus-sdk = "0.6.0" +# Stylus SDK related +stylus-sdk = "0.7.0-beta.1" -alloy = { version = "=0.1.4", features = [ +alloy = { version = "=0.7.2", features = [ "contract", "network", "providers", @@ -85,11 +85,11 @@ alloy = { version = "=0.1.4", features = [ # Even though `alloy` includes `alloy-primitives` and `alloy-sol-types` we need # to keep both versions for compatibility with the Stylus SDK. Once they start # using `alloy` we can remove these. -alloy-primitives = { version = "=0.7.6", default-features = false } -alloy-sol-types = { version = "=0.7.6", default-features = false } -alloy-sol-macro = { version = "=0.7.6", default-features = false } -alloy-sol-macro-expander = { version = "=0.7.6", default-features = false } -alloy-sol-macro-input = { version = "=0.7.6", default-features = false } +alloy-primitives = { version = "=0.8.13", default-features = false } +alloy-sol-types = { version = "=0.8.13", default-features = false } +alloy-sol-macro = { version = "=0.8.13", default-features = false } +alloy-sol-macro-expander = { version = "=0.8.13", default-features = false } +alloy-sol-macro-input = { version = "=0.8.13", default-features = false } const-hex = { version = "1.11.1", default-features = false } eyre = "0.6.8" diff --git a/examples/erc1155/src/constructor.sol b/examples/erc1155/src/constructor.sol index 08dd31f1a..cfb15ceb0 100644 --- a/examples/erc1155/src/constructor.sol +++ b/examples/erc1155/src/constructor.sol @@ -4,9 +4,9 @@ pragma solidity ^0.8.24; contract Erc1155Example { mapping(address => mapping(uint256 => uint256)) private _balanceOf; mapping(address => mapping(address => bool)) private _isApprovedForAll; - + string private _uri; - + constructor(string memory uri_) { _uri = uri_; } From ddef560cbb5307529d21c5536392bf1417136d71 Mon Sep 17 00:00:00 2001 From: Daniel Bigos Date: Fri, 29 Nov 2024 18:30:06 +0100 Subject: [PATCH 028/109] fix: move const value in AccessControl (cherry picked from commit 0cab5f9063c101611b6bfd7b5bd14489ebd35db8) --- contracts/src/access/control.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/contracts/src/access/control.rs b/contracts/src/access/control.rs index 1ef997353..c4895ba1e 100644 --- a/contracts/src/access/control.rs +++ b/contracts/src/access/control.rs @@ -116,9 +116,6 @@ sol_storage! { #[public] impl AccessControl { - /// The default admin role. `[0; 32]` by default. - pub const DEFAULT_ADMIN_ROLE: [u8; 32] = [0; 32]; - /// Returns `true` if `account` has been granted `role`. /// /// # Arguments @@ -270,6 +267,9 @@ impl AccessControl { } impl AccessControl { + /// The default admin role. `[0; 32]` by default. + pub const DEFAULT_ADMIN_ROLE: [u8; 32] = [0; 32]; + /// Sets `admin_role` as `role`'s admin role. /// /// # Arguments From 1d27f6cfeefe42e6415e4f8b37b35a95b2f1659e Mon Sep 17 00:00:00 2001 From: Daniel Bigos Date: Mon, 2 Dec 2024 17:56:23 +0100 Subject: [PATCH 029/109] ref: move interfaces to base modules (cherry picked from commit e84084857ac7af4ae3be599e7ab7e14a6faa55f9) --- contracts/src/finance/vesting_wallet.rs | 15 +++---- contracts/src/token/erc1155/mod.rs | 59 +++++++++++++++++++++++-- contracts/src/token/erc1155/receiver.rs | 59 ------------------------- contracts/src/token/erc721/mod.rs | 42 +++++++++--------- 4 files changed, 82 insertions(+), 93 deletions(-) delete mode 100644 contracts/src/token/erc1155/receiver.rs diff --git a/contracts/src/finance/vesting_wallet.rs b/contracts/src/finance/vesting_wallet.rs index 24b0e2a89..6fd5ce987 100644 --- a/contracts/src/finance/vesting_wallet.rs +++ b/contracts/src/finance/vesting_wallet.rs @@ -30,7 +30,7 @@ use stylus_sdk::{ call::{self, call, Call}, contract, evm, function_selector, storage::TopLevelStorage, - stylus_proc::{public, sol_storage, SolidityError}, + stylus_proc::{public, sol_interface, sol_storage, SolidityError}, }; use crate::{ @@ -80,14 +80,11 @@ pub enum Error { InvalidToken(InvalidToken), } -pub use token::IErc20; -#[allow(missing_docs)] -mod token { - stylus_sdk::stylus_proc::sol_interface! { - /// Interface of the ERC-20 token. - interface IErc20 { - function balanceOf(address account) external view returns (uint256); - } +sol_interface! { + /// Interface of the ERC-20 token. + #[allow(missing_docs)] + interface IErc20 { + function balanceOf(address account) external view returns (uint256); } } diff --git a/contracts/src/token/erc1155/mod.rs b/contracts/src/token/erc1155/mod.rs index 1bd927744..ba7df6f09 100644 --- a/contracts/src/token/erc1155/mod.rs +++ b/contracts/src/token/erc1155/mod.rs @@ -10,6 +10,7 @@ use stylus_sdk::{ evm, function_selector, msg, prelude::{public, sol_storage, AddressVM, SolidityError}, storage::TopLevelStorage, + stylus_proc::sol_interface, }; use crate::utils::{ @@ -19,9 +20,6 @@ use crate::utils::{ pub mod extensions; -mod receiver; -pub use receiver::IERC1155Receiver; - const SINGLE_TRANSFER_FN_SELECTOR: [u8; 4] = function_selector!( "onERC1155Received", Address, @@ -179,6 +177,61 @@ impl MethodError for Error { } } +sol_interface! { + /// Interface that must be implemented by smart contracts + /// in order to receive ERC-1155 token transfers. + #[allow(missing_docs)] + interface IERC1155Receiver { + /// Handles the receipt of a single ERC-1155 token type. + /// This function is called at the end of a + /// [`IErc1155::safe_batch_transfer_from`] + /// after the balance has been updated. + /// + /// NOTE: To accept the transfer, + /// this must return [`SINGLE_TRANSFER_FN_SELECTOR`], + /// or its own function selector. + /// + /// * `operator` - The address which initiated the transfer. + /// * `from` - The address which previously owned the token. + /// * `id` - The ID of the token being transferred. + /// * `value` - The amount of tokens being transferred. + /// * `data` - Additional data with no specified format. + #[allow(missing_docs)] + function onERC1155Received( + address operator, + address from, + uint256 id, + uint256 value, + bytes calldata data + ) external returns (bytes4); + + /// Handles the receipt of multiple ERC-1155 token types. + /// This function is called at the end of a + /// [`IErc1155::safe_batch_transfer_from`] + /// after the balances have been updated. + /// + /// NOTE: To accept the transfer(s), + /// this must return [`BATCH_TRANSFER_FN_SELECTOR`], + /// or its own function selector. + /// + /// * `operator` - The address which initiated the batch transfer. + /// * `from` - The address which previously owned the token. + /// * `ids` - An array containing ids of each token being transferred + /// (order and length must match values array). + /// * `values` - An array containing amounts of each token + /// being transferred (order and length must match ids array). + /// * `data` - Additional data with no specified format. + #[allow(missing_docs)] + function onERC1155BatchReceived( + address operator, + address from, + uint256[] calldata ids, + uint256[] calldata values, + bytes calldata data + ) external returns (bytes4); + } +} + sol_storage! { /// State of an [`Erc1155`] token. pub struct Erc1155 { diff --git a/contracts/src/token/erc1155/receiver.rs b/contracts/src/token/erc1155/receiver.rs deleted file mode 100644 index 49da4798f..000000000 --- a/contracts/src/token/erc1155/receiver.rs +++ /dev/null @@ -1,59 +0,0 @@ -#![allow(missing_docs)] -//! Module with an interface required for smart contract -//! in order to receive ERC-1155 token transfers. - -use stylus_sdk::stylus_proc::sol_interface; - -sol_interface! { - /// Interface that must be implemented by smart contracts - /// in order to receive ERC-1155 token transfers. - interface IERC1155Receiver { - /// Handles the receipt of a single ERC-1155 token type. - /// This function is called at the end of a - /// [`IErc1155::safe_batch_transfer_from`] - /// after the balance has been updated. - /// - /// NOTE: To accept the transfer, - /// this must return [`SINGLE_TRANSFER_FN_SELECTOR`], - /// or its own function selector. - /// - /// * `operator` - The address which initiated the transfer. - /// * `from` - The address which previously owned the token. - /// * `id` - The ID of the token being transferred. - /// * `value` - The amount of tokens being transferred. - /// * `data` - Additional data with no specified format. - #[allow(missing_docs)] - function onERC1155Received( - address operator, - address from, - uint256 id, - uint256 value, - bytes calldata data - ) external returns (bytes4); - - /// Handles the receipt of multiple ERC-1155 token types. - /// This function is called at the end of a - /// [`IErc1155::safe_batch_transfer_from`] - /// after the balances have been updated. - /// - /// NOTE: To accept the transfer(s), - /// this must return [`BATCH_TRANSFER_FN_SELECTOR`], - /// or its own function selector. - /// - /// * `operator` - The address which initiated the batch transfer. - /// * `from` - The address which previously owned the token. - /// * `ids` - An array containing ids of each token being transferred - /// (order and length must match values array). - /// * `values` - An array containing amounts of each token - /// being transferred (order and length must match ids array). - /// * `data` - Additional data with no specified format. - #[allow(missing_docs)] - function onERC1155BatchReceived( - address operator, - address from, - uint256[] calldata ids, - uint256[] calldata values, - bytes calldata data - ) external returns (bytes4); - } -} diff --git a/contracts/src/token/erc721/mod.rs b/contracts/src/token/erc721/mod.rs index 5f6fb886d..1a3fe8e4f 100644 --- a/contracts/src/token/erc721/mod.rs +++ b/contracts/src/token/erc721/mod.rs @@ -9,6 +9,7 @@ use stylus_sdk::{ call::{self, Call, MethodError}, evm, msg, prelude::*, + stylus_proc::sol_interface, }; use crate::utils::{ @@ -160,29 +161,26 @@ impl MethodError for Error { } } -pub use receiver::IERC721Receiver; -#[allow(missing_docs)] -mod receiver { - stylus_sdk::stylus_proc::sol_interface! { - /// [`Erc721`] token receiver interface. +sol_interface! { + /// [`Erc721`] token receiver interface. + /// + /// Interface for any contract that wants to support `safe_transfers` + /// from [`Erc721`] asset contracts. + #[allow(missing_docs)] + interface IERC721Receiver { + /// Whenever an [`Erc721`] `token_id` token is transferred + /// to this contract via [`Erc721::safe_transfer_from`]. /// - /// Interface for any contract that wants to support `safe_transfers` - /// from [`Erc721`] asset contracts. - interface IERC721Receiver { - /// Whenever an [`Erc721`] `token_id` token is transferred - /// to this contract via [`Erc721::safe_transfer_from`]. - /// - /// It must return its function selector to confirm the token transfer. - /// If any other value is returned or the interface is not implemented - /// by the recipient, the transfer will be reverted. - #[allow(missing_docs)] - function onERC721Received( - address operator, - address from, - uint256 token_id, - bytes calldata data - ) external returns (bytes4); - } + /// It must return its function selector to confirm the token transfer. + /// If any other value is returned or the interface is not implemented + /// by the recipient, the transfer will be reverted. + #[allow(missing_docs)] + function onERC721Received( + address operator, + address from, + uint256 token_id, + bytes calldata data + ) external returns (bytes4); } } From c3cc640c02b7f497fca8c3d5e8329328505a79dc Mon Sep 17 00:00:00 2001 From: Daniel Bigos Date: Mon, 2 Dec 2024 18:01:59 +0100 Subject: [PATCH 030/109] ref: fix AccessControl example (cherry picked from commit 431b7063d87e1e86581feaf397ed81420cc04eb9) --- examples/access-control/src/lib.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/examples/access-control/src/lib.rs b/examples/access-control/src/lib.rs index 0b4590d1f..af489be33 100644 --- a/examples/access-control/src/lib.rs +++ b/examples/access-control/src/lib.rs @@ -29,8 +29,6 @@ pub const TRANSFER_ROLE: [u8; 32] = [ #[public] #[inherit(Erc20, AccessControl)] impl AccessControlExample { - pub const TRANSFER_ROLE: [u8; 32] = TRANSFER_ROLE; - pub fn make_admin(&mut self, account: Address) -> Result<(), Vec> { self.access.only_role(AccessControl::DEFAULT_ADMIN_ROLE.into())?; self.access @@ -55,3 +53,7 @@ impl AccessControlExample { self.access._set_role_admin(role, new_admin_role) } } + +impl AccessControlExample { + pub const TRANSFER_ROLE: [u8; 32] = TRANSFER_ROLE; +} From e0e71ba87b11e334835a7fc5d5bcfafdd1f3015b Mon Sep 17 00:00:00 2001 From: Daniel Bigos Date: Mon, 2 Dec 2024 18:12:34 +0100 Subject: [PATCH 031/109] fix: add missing Vec imports (cherry picked from commit f921f1be673c48d4a993029d9f49145de715756d) --- contracts/src/access/control.rs | 2 ++ contracts/src/access/ownable.rs | 2 ++ contracts/src/access/ownable_two_step.rs | 2 ++ contracts/src/finance/vesting_wallet.rs | 2 ++ contracts/src/token/erc20/extensions/capped.rs | 3 ++- contracts/src/token/erc20/extensions/metadata.rs | 3 ++- contracts/src/token/erc20/extensions/permit.rs | 2 ++ contracts/src/token/erc20/mod.rs | 2 ++ contracts/src/token/erc20/utils/safe_erc20.rs | 2 ++ contracts/src/token/erc721/extensions/consecutive.rs | 2 +- contracts/src/token/erc721/extensions/enumerable.rs | 3 ++- contracts/src/token/erc721/extensions/metadata.rs | 5 ++++- contracts/src/token/erc721/mod.rs | 3 ++- contracts/src/utils/metadata.rs | 3 +-- contracts/src/utils/nonces.rs | 2 ++ contracts/src/utils/pausable.rs | 2 ++ 16 files changed, 32 insertions(+), 8 deletions(-) diff --git a/contracts/src/access/control.rs b/contracts/src/access/control.rs index c4895ba1e..53515c556 100644 --- a/contracts/src/access/control.rs +++ b/contracts/src/access/control.rs @@ -40,6 +40,8 @@ //! accounts that have been granted it. We recommend using //! `AccessControlDefaultAdminRules` to enforce additional security measures for //! this role. +use alloc::vec::Vec; + use alloy_primitives::{Address, B256}; use alloy_sol_types::sol; use stylus_sdk::{ diff --git a/contracts/src/access/ownable.rs b/contracts/src/access/ownable.rs index 50692973f..89fa892d9 100644 --- a/contracts/src/access/ownable.rs +++ b/contracts/src/access/ownable.rs @@ -8,6 +8,8 @@ //! This module is used through inheritance. It will make available the //! [`Ownable::only_owner`] function, which can be called to restrict operations //! to the owner. +use alloc::vec::Vec; + use alloy_primitives::Address; use alloy_sol_types::sol; use openzeppelin_stylus_proc::interface_id; diff --git a/contracts/src/access/ownable_two_step.rs b/contracts/src/access/ownable_two_step.rs index f5d9a2be1..f244c0dee 100644 --- a/contracts/src/access/ownable_two_step.rs +++ b/contracts/src/access/ownable_two_step.rs @@ -16,6 +16,8 @@ //! This module uses [`Ownable`] as a member, and makes all its public functions //! available. +use alloc::vec::Vec; + use alloy_primitives::Address; use alloy_sol_types::sol; use stylus_sdk::{ diff --git a/contracts/src/finance/vesting_wallet.rs b/contracts/src/finance/vesting_wallet.rs index 6fd5ce987..a1b442425 100644 --- a/contracts/src/finance/vesting_wallet.rs +++ b/contracts/src/finance/vesting_wallet.rs @@ -22,6 +22,8 @@ //! adjustment in the vesting schedule to ensure the vested amount is as //! intended. +use alloc::{vec, vec::Vec}; + use alloy_primitives::{Address, U256, U64}; use alloy_sol_types::sol; use openzeppelin_stylus_proc::interface_id; diff --git a/contracts/src/token/erc20/extensions/capped.rs b/contracts/src/token/erc20/extensions/capped.rs index a971900b5..c4b9ad341 100644 --- a/contracts/src/token/erc20/extensions/capped.rs +++ b/contracts/src/token/erc20/extensions/capped.rs @@ -5,10 +5,11 @@ //! Note that they will not be capped by simply including this module, //! but only once the checks are put in place. +use alloc::vec::Vec; + use alloy_primitives::U256; use alloy_sol_types::sol; use stylus_sdk::stylus_proc::{public, sol_storage, SolidityError}; - sol! { /// Indicates an error related to the operation that failed /// because `total_supply` exceeded the `_cap`. diff --git a/contracts/src/token/erc20/extensions/metadata.rs b/contracts/src/token/erc20/extensions/metadata.rs index 6cc10141f..a333d3865 100644 --- a/contracts/src/token/erc20/extensions/metadata.rs +++ b/contracts/src/token/erc20/extensions/metadata.rs @@ -11,8 +11,9 @@ use crate::utils::introspection::erc165::IErc165; /// Number of decimals used by default on implementors of [`Metadata`]. pub const DEFAULT_DECIMALS: u8 = 18; -use crate::utils::Metadata; +use alloc::vec::Vec; +use crate::utils::Metadata; sol_storage! { /// Metadata of the [`super::super::Erc20`] token. /// diff --git a/contracts/src/token/erc20/extensions/permit.rs b/contracts/src/token/erc20/extensions/permit.rs index 1b58e948d..311b5d7c7 100644 --- a/contracts/src/token/erc20/extensions/permit.rs +++ b/contracts/src/token/erc20/extensions/permit.rs @@ -9,6 +9,8 @@ //! By not relying on [`crate::token::erc20::IErc20::approve`], //! the token holder account doesn’t need to send a transaction, //! and thus is not required to hold Ether at all. +use alloc::vec::Vec; + use alloy_primitives::{b256, keccak256, Address, B256, U256}; use alloy_sol_types::{sol, SolType}; use stylus_sdk::{ diff --git a/contracts/src/token/erc20/mod.rs b/contracts/src/token/erc20/mod.rs index 91399f425..d0f51c421 100644 --- a/contracts/src/token/erc20/mod.rs +++ b/contracts/src/token/erc20/mod.rs @@ -4,6 +4,8 @@ //! revert instead of returning `false` on failure. This behavior is //! nonetheless conventional and does not conflict with the expectations of //! [`Erc20`] applications. +use alloc::vec::Vec; + use alloy_primitives::{Address, FixedBytes, U256}; use alloy_sol_types::sol; use openzeppelin_stylus_proc::interface_id; diff --git a/contracts/src/token/erc20/utils/safe_erc20.rs b/contracts/src/token/erc20/utils/safe_erc20.rs index 28115e227..ba3f7bfe8 100644 --- a/contracts/src/token/erc20/utils/safe_erc20.rs +++ b/contracts/src/token/erc20/utils/safe_erc20.rs @@ -7,6 +7,8 @@ //! your contract, which allows you to call the safe operations as //! `contract.safe_transfer(token_addr, ...)`, etc. +use alloc::vec::Vec; + use alloy_primitives::{Address, U256}; use alloy_sol_types::{sol, SolCall}; use stylus_sdk::{ diff --git a/contracts/src/token/erc721/extensions/consecutive.rs b/contracts/src/token/erc721/extensions/consecutive.rs index 302cb56f4..1f793802b 100644 --- a/contracts/src/token/erc721/extensions/consecutive.rs +++ b/contracts/src/token/erc721/extensions/consecutive.rs @@ -22,7 +22,7 @@ //! restriction on the [`Erc721Consecutive::_update`] function call since it is //! not possible to call a Rust function from the Solidity constructor. -use alloc::vec; +use alloc::{vec, vec::Vec}; use alloy_primitives::{uint, Address, U256}; use alloy_sol_types::sol; diff --git a/contracts/src/token/erc721/extensions/enumerable.rs b/contracts/src/token/erc721/extensions/enumerable.rs index f35bc97c0..70e60bbaf 100644 --- a/contracts/src/token/erc721/extensions/enumerable.rs +++ b/contracts/src/token/erc721/extensions/enumerable.rs @@ -9,6 +9,8 @@ //! interfere with enumerability and should not be used together with //! [`Erc721Enumerable`]. +use alloc::vec::Vec; + use alloy_primitives::{uint, Address, FixedBytes, U256}; use alloy_sol_types::sol; use openzeppelin_stylus_proc::interface_id; @@ -18,7 +20,6 @@ use crate::{ token::{erc721, erc721::IErc721}, utils::introspection::erc165::IErc165, }; - sol! { /// Indicates an error when an `owner`'s token query /// was out of bounds for `index`. diff --git a/contracts/src/token/erc721/extensions/metadata.rs b/contracts/src/token/erc721/extensions/metadata.rs index c1e95e078..d37c83371 100644 --- a/contracts/src/token/erc721/extensions/metadata.rs +++ b/contracts/src/token/erc721/extensions/metadata.rs @@ -1,6 +1,9 @@ //! Optional Metadata of the ERC-721 standard. -use alloc::string::{String, ToString}; +use alloc::{ + string::{String, ToString}, + vec::Vec, +}; use alloy_primitives::{FixedBytes, U256}; use openzeppelin_stylus_proc::interface_id; diff --git a/contracts/src/token/erc721/mod.rs b/contracts/src/token/erc721/mod.rs index 1a3fe8e4f..527c3716d 100644 --- a/contracts/src/token/erc721/mod.rs +++ b/contracts/src/token/erc721/mod.rs @@ -1,5 +1,4 @@ //! Implementation of the [`Erc721`] token standard. -use alloc::vec; use alloy_primitives::{fixed_bytes, uint, Address, FixedBytes, U128, U256}; use openzeppelin_stylus_proc::interface_id; @@ -19,6 +18,8 @@ use crate::utils::{ pub mod extensions; +use alloc::{vec, vec::Vec}; + sol! { /// Emitted when the `token_id` token is transferred from `from` to `to`. /// diff --git a/contracts/src/utils/metadata.rs b/contracts/src/utils/metadata.rs index 7d904dbb0..b4410d12c 100644 --- a/contracts/src/utils/metadata.rs +++ b/contracts/src/utils/metadata.rs @@ -1,8 +1,7 @@ //! Common Metadata Smart Contract. -use alloc::string::String; +use alloc::{string::String, vec, vec::Vec}; use stylus_sdk::stylus_proc::{public, sol_storage}; - sol_storage! { /// Metadata of the token. pub struct Metadata { diff --git a/contracts/src/utils/nonces.rs b/contracts/src/utils/nonces.rs index 13678fcc3..0e55134f5 100644 --- a/contracts/src/utils/nonces.rs +++ b/contracts/src/utils/nonces.rs @@ -2,6 +2,8 @@ //! //! Nonces will only increment. +use alloc::vec::Vec; + use alloy_primitives::{uint, Address, U256}; use alloy_sol_types::sol; use stylus_sdk::stylus_proc::{public, sol_storage, SolidityError}; diff --git a/contracts/src/utils/pausable.rs b/contracts/src/utils/pausable.rs index 1a2ed5ae9..d072c3a38 100644 --- a/contracts/src/utils/pausable.rs +++ b/contracts/src/utils/pausable.rs @@ -14,6 +14,8 @@ //! exposed by default. //! You should expose them manually in your contract's abi. +use alloc::vec::Vec; + use alloy_sol_types::sol; use stylus_sdk::{ evm, msg, From b24bcdf4e869a3794ea3142cff637f3d523baa82 Mon Sep 17 00:00:00 2001 From: Daniel Bigos Date: Wed, 4 Dec 2024 16:36:58 +0100 Subject: [PATCH 032/109] build: use koba with updated alloy --- Cargo.lock | 758 +++++++++++------------------------------------------ Cargo.toml | 2 +- 2 files changed, 160 insertions(+), 600 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 95c68d77a..3119e815c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6,8 +6,8 @@ version = 4 name = "access-control-example" version = "0.2.0-alpha.1" dependencies = [ - "alloy 0.7.2", - "alloy-primitives 0.8.13", + "alloy", + "alloy-primitives", "e2e", "eyre", "openzeppelin-stylus", @@ -80,48 +80,26 @@ version = "0.2.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5c6cb57a04249c6480766f7f7cef5467412af1490f8d1e243141daddada3264f" -[[package]] -name = "alloy" -version = "0.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ba1c79677c9ce51c8d45e20845b05e6fb070ea2c863fba03ad6af2c778474bd" -dependencies = [ - "alloy-consensus 0.1.3", - "alloy-contract 0.1.3", - "alloy-core 0.7.6", - "alloy-eips 0.1.3", - "alloy-genesis 0.1.3", - "alloy-network 0.1.3", - "alloy-provider 0.1.3", - "alloy-rpc-client 0.1.3", - "alloy-rpc-types 0.1.3", - "alloy-serde 0.1.3", - "alloy-signer 0.1.3", - "alloy-signer-local 0.1.3", - "alloy-transport 0.1.3", - "alloy-transport-http 0.1.3", -] - [[package]] name = "alloy" version = "0.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "44ab65cb6104c389b46df77b7990cab08780f57e41b412b46d6d12baf7e8c716" dependencies = [ - "alloy-consensus 0.7.0", - "alloy-contract 0.7.0", - "alloy-core 0.8.13", - "alloy-eips 0.7.0", - "alloy-genesis 0.7.0", - "alloy-network 0.7.0", - "alloy-provider 0.7.0", - "alloy-rpc-client 0.7.0", - "alloy-rpc-types 0.7.0", - "alloy-serde 0.7.0", - "alloy-signer 0.7.0", - "alloy-signer-local 0.7.0", - "alloy-transport 0.7.0", - "alloy-transport-http 0.7.0", + "alloy-consensus", + "alloy-contract", + "alloy-core", + "alloy-eips", + "alloy-genesis", + "alloy-network", + "alloy-provider", + "alloy-rpc-client", + "alloy-rpc-types", + "alloy-serde", + "alloy-signer", + "alloy-signer-local", + "alloy-transport", + "alloy-transport-http", ] [[package]] @@ -134,34 +112,20 @@ dependencies = [ "strum", ] -[[package]] -name = "alloy-consensus" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f63a6c9eb45684a5468536bc55379a2af0f45ffa5d756e4e4964532737e1836" -dependencies = [ - "alloy-eips 0.1.3", - "alloy-primitives 0.7.6", - "alloy-rlp", - "alloy-serde 0.1.3", - "c-kzg", - "serde", -] - [[package]] name = "alloy-consensus" version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3a1ff8439834ab71a4b0ecd1a8ff80b3921c87615f158940c3364f399c732786" dependencies = [ - "alloy-eips 0.7.0", - "alloy-primitives 0.8.13", + "alloy-eips", + "alloy-primitives", "alloy-rlp", - "alloy-serde 0.7.0", + "alloy-serde", "alloy-trie", "auto_impl", "c-kzg", - "derive_more 1.0.0", + "derive_more", "serde", ] @@ -171,93 +135,45 @@ version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "519a86faaa6729464365a90c04eba68539b6d3a30f426edb4b3dafd78920d42f" dependencies = [ - "alloy-consensus 0.7.0", - "alloy-eips 0.7.0", - "alloy-primitives 0.8.13", + "alloy-consensus", + "alloy-eips", + "alloy-primitives", "alloy-rlp", - "alloy-serde 0.7.0", + "alloy-serde", "serde", ] -[[package]] -name = "alloy-contract" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c26b7d34cb76f826558e9409a010e25257f7bfb5aa5e3dd0042c564664ae159" -dependencies = [ - "alloy-dyn-abi 0.7.6", - "alloy-json-abi 0.7.6", - "alloy-network 0.1.3", - "alloy-primitives 0.7.6", - "alloy-provider 0.1.3", - "alloy-rpc-types-eth 0.1.3", - "alloy-sol-types 0.7.6", - "alloy-transport 0.1.3", - "futures", - "futures-util", - "thiserror", -] - [[package]] name = "alloy-contract" version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cca2b353d8b7f160dc930dfa174557acefece6deab5ecd7e6230d38858579eea" dependencies = [ - "alloy-dyn-abi 0.8.13", - "alloy-json-abi 0.8.13", - "alloy-network 0.7.0", + "alloy-dyn-abi", + "alloy-json-abi", + "alloy-network", "alloy-network-primitives", - "alloy-primitives 0.8.13", - "alloy-provider 0.7.0", - "alloy-rpc-types-eth 0.7.0", - "alloy-sol-types 0.8.13", - "alloy-transport 0.7.0", + "alloy-primitives", + "alloy-provider", + "alloy-rpc-types-eth", + "alloy-sol-types", + "alloy-transport", "futures", "futures-util", "thiserror", ] -[[package]] -name = "alloy-core" -version = "0.7.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5af3faff14c12c8b11037e0a093dd157c3702becb8435577a2408534d0758315" -dependencies = [ - "alloy-dyn-abi 0.7.6", - "alloy-json-abi 0.7.6", - "alloy-primitives 0.7.6", - "alloy-sol-types 0.7.6", -] - [[package]] name = "alloy-core" version = "0.8.13" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e8d22df68fa7d9744be0b1a9be3260e9aa089fbf41903ab182328333061ed186" dependencies = [ - "alloy-dyn-abi 0.8.13", - "alloy-json-abi 0.8.13", - "alloy-primitives 0.8.13", + "alloy-dyn-abi", + "alloy-json-abi", + "alloy-primitives", "alloy-rlp", - "alloy-sol-types 0.8.13", -] - -[[package]] -name = "alloy-dyn-abi" -version = "0.7.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cb6e6436a9530f25010d13653e206fab4c9feddacf21a54de8d7311b275bc56b" -dependencies = [ - "alloy-json-abi 0.7.6", - "alloy-primitives 0.7.6", - "alloy-sol-type-parser 0.7.6", - "alloy-sol-types 0.7.6", - "const-hex", - "itoa", - "serde", - "serde_json", - "winnow 0.6.13", + "alloy-sol-types", ] [[package]] @@ -266,10 +182,10 @@ version = "0.8.13" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1cf633ae9a1f0c82fdb9e559ed2be1c8e415c3e48fc47e1feaf32c6078ec0cdd" dependencies = [ - "alloy-json-abi 0.8.13", - "alloy-primitives 0.8.13", - "alloy-sol-type-parser 0.8.14", - "alloy-sol-types 0.8.13", + "alloy-json-abi", + "alloy-primitives", + "alloy-sol-type-parser", + "alloy-sol-types", "const-hex", "itoa", "serde", @@ -283,7 +199,7 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0069cf0642457f87a01a014f6dc29d5d893cd4fd8fddf0c3cdfad1bb3ebafc41" dependencies = [ - "alloy-primitives 0.8.13", + "alloy-primitives", "alloy-rlp", "serde", ] @@ -294,25 +210,10 @@ version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4c986539255fb839d1533c128e190e557e52ff652c9ef62939e233a81dd93f7e" dependencies = [ - "alloy-primitives 0.8.13", - "alloy-rlp", - "derive_more 1.0.0", - "serde", -] - -[[package]] -name = "alloy-eips" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aa4b0fc6a572ef2eebda0a31a5e393d451abda703fec917c75d9615d8c978cf2" -dependencies = [ - "alloy-primitives 0.7.6", + "alloy-primitives", "alloy-rlp", - "alloy-serde 0.1.3", - "c-kzg", - "once_cell", + "derive_more", "serde", - "sha2", ] [[package]] @@ -323,73 +224,37 @@ checksum = "8dedb328c2114284f767e075589ca9de8d5e9c8a91333402f4804a584ed71a38" dependencies = [ "alloy-eip2930", "alloy-eip7702", - "alloy-primitives 0.8.13", + "alloy-primitives", "alloy-rlp", - "alloy-serde 0.7.0", + "alloy-serde", "c-kzg", - "derive_more 1.0.0", + "derive_more", "once_cell", "serde", "sha2", ] -[[package]] -name = "alloy-genesis" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "48450f9c6f0821c1eee00ed912942492ed4f11dd69532825833de23ecc7a2256" -dependencies = [ - "alloy-primitives 0.7.6", - "alloy-serde 0.1.3", - "serde", -] - [[package]] name = "alloy-genesis" version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4841e8dd4e0f53d76b501fd4c6bc21d95d688bc8ebf0ea359fc6c7ab65b48742" dependencies = [ - "alloy-primitives 0.8.13", - "alloy-serde 0.7.0", + "alloy-primitives", + "alloy-serde", "serde", ] -[[package]] -name = "alloy-json-abi" -version = "0.7.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aaeaccd50238126e3a0ff9387c7c568837726ad4f4e399b528ca88104d6c25ef" -dependencies = [ - "alloy-primitives 0.7.6", - "alloy-sol-type-parser 0.7.6", - "serde", - "serde_json", -] - [[package]] name = "alloy-json-abi" version = "0.8.13" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1a500037938085feed8a20dbfc8fce58c599db68c948cfae711147175dee392c" dependencies = [ - "alloy-primitives 0.8.13", - "alloy-sol-type-parser 0.8.14", - "serde", - "serde_json", -] - -[[package]] -name = "alloy-json-rpc" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d484c2a934d0a4d86f8ad4db8113cb1d607707a6c54f6e78f4f1b4451b47aa70" -dependencies = [ - "alloy-primitives 0.7.6", + "alloy-primitives", + "alloy-sol-type-parser", "serde", "serde_json", - "thiserror", - "tracing", ] [[package]] @@ -398,51 +263,31 @@ version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "254f770918f96dc4ec88a15e6e2e243358e1719d66b40ef814428e7697079d25" dependencies = [ - "alloy-primitives 0.8.13", - "alloy-sol-types 0.8.13", + "alloy-primitives", + "alloy-sol-types", "serde", "serde_json", "thiserror", "tracing", ] -[[package]] -name = "alloy-network" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a20eba9bc551037f0626d6d29e191888638d979943fa4e842e9e6fc72bf0565" -dependencies = [ - "alloy-consensus 0.1.3", - "alloy-eips 0.1.3", - "alloy-json-rpc 0.1.3", - "alloy-primitives 0.7.6", - "alloy-rpc-types-eth 0.1.3", - "alloy-serde 0.1.3", - "alloy-signer 0.1.3", - "alloy-sol-types 0.7.6", - "async-trait", - "auto_impl", - "futures-utils-wasm", - "thiserror", -] - [[package]] name = "alloy-network" version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "931dd176c6e33355f3dc0170ec69cf5b951f4d73870b276e2c837ab35f9c5136" dependencies = [ - "alloy-consensus 0.7.0", + "alloy-consensus", "alloy-consensus-any", - "alloy-eips 0.7.0", - "alloy-json-rpc 0.7.0", + "alloy-eips", + "alloy-json-rpc", "alloy-network-primitives", - "alloy-primitives 0.8.13", + "alloy-primitives", "alloy-rpc-types-any", - "alloy-rpc-types-eth 0.7.0", - "alloy-serde 0.7.0", - "alloy-signer 0.7.0", - "alloy-sol-types 0.8.13", + "alloy-rpc-types-eth", + "alloy-serde", + "alloy-signer", + "alloy-sol-types", "async-trait", "auto_impl", "futures-utils-wasm", @@ -457,34 +302,11 @@ version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fa6ec0f23be233e851e31c5e4badfedfa9c7bc177bc37f4e03616072cd40a806" dependencies = [ - "alloy-consensus 0.7.0", - "alloy-eips 0.7.0", - "alloy-primitives 0.8.13", - "alloy-serde 0.7.0", - "serde", -] - -[[package]] -name = "alloy-primitives" -version = "0.7.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f783611babedbbe90db3478c120fb5f5daacceffc210b39adc0af4fe0da70bad" -dependencies = [ - "alloy-rlp", - "bytes", - "cfg-if", - "const-hex", - "derive_more 0.99.18", - "getrandom", - "hex-literal", - "itoa", - "k256", - "keccak-asm", - "proptest", - "rand", - "ruint", + "alloy-consensus", + "alloy-eips", + "alloy-primitives", + "alloy-serde", "serde", - "tiny-keccak", ] [[package]] @@ -499,7 +321,7 @@ dependencies = [ "cfg-if", "const-hex", "derive_arbitrary", - "derive_more 1.0.0", + "derive_more", "foldhash", "getrandom", "hashbrown 0.15.2", @@ -519,38 +341,6 @@ dependencies = [ "tiny-keccak", ] -[[package]] -name = "alloy-provider" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ad5d89acb7339fad13bc69e7b925232f242835bfd91c82fcb9326b36481bd0f0" -dependencies = [ - "alloy-chains", - "alloy-consensus 0.1.3", - "alloy-eips 0.1.3", - "alloy-json-rpc 0.1.3", - "alloy-network 0.1.3", - "alloy-primitives 0.7.6", - "alloy-rpc-client 0.1.3", - "alloy-rpc-types-eth 0.1.3", - "alloy-transport 0.1.3", - "alloy-transport-http 0.1.3", - "async-stream", - "async-trait", - "auto_impl", - "dashmap 5.5.3", - "futures", - "futures-utils-wasm", - "lru", - "pin-project", - "reqwest", - "serde", - "serde_json", - "tokio", - "tracing", - "url", -] - [[package]] name = "alloy-provider" version = "0.7.0" @@ -558,16 +348,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5545e2cbf2f8f24c68bb887ba0294fa12a2f816b9e72c4f226cd137b77d0e294" dependencies = [ "alloy-chains", - "alloy-consensus 0.7.0", - "alloy-eips 0.7.0", - "alloy-json-rpc 0.7.0", - "alloy-network 0.7.0", + "alloy-consensus", + "alloy-eips", + "alloy-json-rpc", + "alloy-network", "alloy-network-primitives", - "alloy-primitives 0.8.13", - "alloy-rpc-client 0.7.0", - "alloy-rpc-types-eth 0.7.0", - "alloy-transport 0.7.0", - "alloy-transport-http 0.7.0", + "alloy-primitives", + "alloy-rpc-client", + "alloy-rpc-types-eth", + "alloy-transport", + "alloy-transport-http", "async-stream", "async-trait", "auto_impl", @@ -610,37 +400,16 @@ dependencies = [ "syn 2.0.89", ] -[[package]] -name = "alloy-rpc-client" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "479ce003e8c74bbbc7d4235131c1d6b7eaf14a533ae850295b90d240340989cb" -dependencies = [ - "alloy-json-rpc 0.1.3", - "alloy-transport 0.1.3", - "alloy-transport-http 0.1.3", - "futures", - "pin-project", - "reqwest", - "serde", - "serde_json", - "tokio", - "tokio-stream", - "tower 0.4.13", - "tracing", - "url", -] - [[package]] name = "alloy-rpc-client" version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "aed9e40c2a73265ebf70f1e48303ee55920282e1ea5971e832873fb2d32cea74" dependencies = [ - "alloy-json-rpc 0.7.0", - "alloy-primitives 0.8.13", - "alloy-transport 0.7.0", - "alloy-transport-http 0.7.0", + "alloy-json-rpc", + "alloy-primitives", + "alloy-transport", + "alloy-transport-http", "futures", "pin-project", "reqwest", @@ -654,25 +423,15 @@ dependencies = [ "wasmtimer", ] -[[package]] -name = "alloy-rpc-types" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0dfa1dd3e0bc3a3d89744fba8d1511216e83257160da2cd028a18b7d9c026030" -dependencies = [ - "alloy-rpc-types-eth 0.1.3", - "alloy-serde 0.1.3", -] - [[package]] name = "alloy-rpc-types" version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "42dea20fa715a6f39ec7adc735cfd9567342870737270ac67795d55896527772" dependencies = [ - "alloy-primitives 0.8.13", - "alloy-rpc-types-eth 0.7.0", - "alloy-serde 0.7.0", + "alloy-primitives", + "alloy-rpc-types-eth", + "alloy-serde", "serde", ] @@ -682,28 +441,10 @@ version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "79d7620e22d6ed7c58451dd303d0501ade5a8bec9dc8daef0fbc48ceffabbae1" dependencies = [ - "alloy-consensus 0.7.0", + "alloy-consensus", "alloy-consensus-any", - "alloy-rpc-types-eth 0.7.0", - "alloy-serde 0.7.0", -] - -[[package]] -name = "alloy-rpc-types-eth" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "13bd7aa9ff9e67f1ba7ee0dd8cebfc95831d1649b0e4eeefae940dc3681079fa" -dependencies = [ - "alloy-consensus 0.1.3", - "alloy-eips 0.1.3", - "alloy-primitives 0.7.6", - "alloy-rlp", - "alloy-serde 0.1.3", - "alloy-sol-types 0.7.6", - "itertools 0.13.0", - "serde", - "serde_json", - "thiserror", + "alloy-rpc-types-eth", + "alloy-serde", ] [[package]] @@ -712,63 +453,38 @@ version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "df34b88df4deeac9ecfc80ad7cbb26a33e57437b9db8be5b952792feef6134bc" dependencies = [ - "alloy-consensus 0.7.0", + "alloy-consensus", "alloy-consensus-any", - "alloy-eips 0.7.0", + "alloy-eips", "alloy-network-primitives", - "alloy-primitives 0.8.13", + "alloy-primitives", "alloy-rlp", - "alloy-serde 0.7.0", - "alloy-sol-types 0.8.13", - "derive_more 1.0.0", + "alloy-serde", + "alloy-sol-types", + "derive_more", "itertools 0.13.0", "serde", "serde_json", ] -[[package]] -name = "alloy-serde" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8913f9e825068d77c516188c221c44f78fd814fce8effe550a783295a2757d19" -dependencies = [ - "alloy-primitives 0.7.6", - "serde", - "serde_json", -] - [[package]] name = "alloy-serde" version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "43a89fd4cc3f96b3c5c0dd1cebeb63323e4659bbdc837117fa3fd5ac168df7d9" dependencies = [ - "alloy-primitives 0.8.13", + "alloy-primitives", "serde", "serde_json", ] -[[package]] -name = "alloy-signer" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f740e13eb4c6a0e4d0e49738f1e86f31ad2d7ef93be499539f492805000f7237" -dependencies = [ - "alloy-primitives 0.7.6", - "async-trait", - "auto_impl", - "elliptic-curve", - "k256", - "thiserror", -] - [[package]] name = "alloy-signer" version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "532010243a96d1f8593c2246ec3971bc52303884fa1e43ca0a776798ba178910" dependencies = [ - "alloy-primitives 0.8.13", + "alloy-primitives", "async-trait", "auto_impl", "elliptic-curve", @@ -776,95 +492,45 @@ dependencies = [ "thiserror", ] -[[package]] -name = "alloy-signer-local" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87db68d926887393a1d0f9c43833b44446ea29d603291e7b20e5d115f31aa4e3" -dependencies = [ - "alloy-consensus 0.1.3", - "alloy-network 0.1.3", - "alloy-primitives 0.7.6", - "alloy-signer 0.1.3", - "async-trait", - "elliptic-curve", - "eth-keystore", - "k256", - "rand", - "thiserror", -] - [[package]] name = "alloy-signer-local" version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e8080c0ab2dc729b0cbb183843d08e78d2a1629140c9fc16234d2272abb483bd" dependencies = [ - "alloy-consensus 0.7.0", - "alloy-network 0.7.0", - "alloy-primitives 0.8.13", - "alloy-signer 0.7.0", + "alloy-consensus", + "alloy-network", + "alloy-primitives", + "alloy-signer", "async-trait", + "eth-keystore", "k256", "rand", "thiserror", ] -[[package]] -name = "alloy-sol-macro" -version = "0.7.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4bad41a7c19498e3f6079f7744656328699f8ea3e783bdd10d85788cd439f572" -dependencies = [ - "alloy-sol-macro-expander 0.7.6", - "alloy-sol-macro-input 0.7.6", - "proc-macro-error", - "proc-macro2", - "quote", - "syn 2.0.89", -] - [[package]] name = "alloy-sol-macro" version = "0.8.13" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5c0279d09463a4695788a3622fd95443625f7be307422deba4b55dd491a9c7a1" dependencies = [ - "alloy-sol-macro-expander 0.8.13", - "alloy-sol-macro-input 0.8.13", + "alloy-sol-macro-expander", + "alloy-sol-macro-input", "proc-macro-error2", "proc-macro2", "quote", "syn 2.0.89", ] -[[package]] -name = "alloy-sol-macro-expander" -version = "0.7.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fd9899da7d011b4fe4c406a524ed3e3f963797dbc93b45479d60341d3a27b252" -dependencies = [ - "alloy-json-abi 0.7.6", - "alloy-sol-macro-input 0.7.6", - "const-hex", - "heck", - "indexmap 2.6.0", - "proc-macro-error", - "proc-macro2", - "quote", - "syn 2.0.89", - "syn-solidity 0.7.6", - "tiny-keccak", -] - [[package]] name = "alloy-sol-macro-expander" version = "0.8.13" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4feea540fc8233df2ad1156efd744b2075372f43a8f942a68b3b19c8a00e2c12" dependencies = [ - "alloy-json-abi 0.8.13", - "alloy-sol-macro-input 0.8.13", + "alloy-json-abi", + "alloy-sol-macro-input", "const-hex", "heck", "indexmap 2.6.0", @@ -872,34 +538,17 @@ dependencies = [ "proc-macro2", "quote", "syn 2.0.89", - "syn-solidity 0.8.14", + "syn-solidity", "tiny-keccak", ] -[[package]] -name = "alloy-sol-macro-input" -version = "0.7.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d32d595768fdc61331a132b6f65db41afae41b9b97d36c21eb1b955c422a7e60" -dependencies = [ - "alloy-json-abi 0.7.6", - "const-hex", - "dunce", - "heck", - "proc-macro2", - "quote", - "serde_json", - "syn 2.0.89", - "syn-solidity 0.7.6", -] - [[package]] name = "alloy-sol-macro-input" version = "0.8.13" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2a0ad281f3d1b613af814b66977ee698e443d4644a1510962d0241f26e0e53ae" dependencies = [ - "alloy-json-abi 0.8.13", + "alloy-json-abi", "const-hex", "dunce", "heck", @@ -907,16 +556,7 @@ dependencies = [ "quote", "serde_json", "syn 2.0.89", - "syn-solidity 0.8.14", -] - -[[package]] -name = "alloy-sol-type-parser" -version = "0.7.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baa2fbd22d353d8685bd9fee11ba2d8b5c3b1d11e56adb3265fcf1f32bfdf404" -dependencies = [ - "winnow 0.6.13", + "syn-solidity", ] [[package]] @@ -929,57 +569,26 @@ dependencies = [ "winnow 0.6.13", ] -[[package]] -name = "alloy-sol-types" -version = "0.7.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a49042c6d3b66a9fe6b2b5a8bf0d39fc2ae1ee0310a2a26ffedd79fb097878dd" -dependencies = [ - "alloy-json-abi 0.7.6", - "alloy-primitives 0.7.6", - "alloy-sol-macro 0.7.6", - "const-hex", - "serde", -] - [[package]] name = "alloy-sol-types" version = "0.8.13" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cff34e0682d6665da243a3e81da96f07a2dd50f7e64073e382b1a141f5a2a2f6" dependencies = [ - "alloy-json-abi 0.8.13", - "alloy-primitives 0.8.13", - "alloy-sol-macro 0.8.13", + "alloy-json-abi", + "alloy-primitives", + "alloy-sol-macro", "const-hex", "serde", ] -[[package]] -name = "alloy-transport" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd9773e4ec6832346171605c776315544bd06e40f803e7b5b7824b325d5442ca" -dependencies = [ - "alloy-json-rpc 0.1.3", - "base64", - "futures-util", - "futures-utils-wasm", - "serde", - "serde_json", - "thiserror", - "tokio", - "tower 0.4.13", - "url", -] - [[package]] name = "alloy-transport" version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b6f295f4b745fb9e4e663d70bc57aed991288912c7aaaf25767def921050ee43" dependencies = [ - "alloy-json-rpc 0.7.0", + "alloy-json-rpc", "base64", "futures-util", "futures-utils-wasm", @@ -993,29 +602,14 @@ dependencies = [ "wasmtimer", ] -[[package]] -name = "alloy-transport-http" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff8ef947b901c0d4e97370f9fa25844cf8b63b1a58fd4011ee82342dc8a9fc6b" -dependencies = [ - "alloy-json-rpc 0.1.3", - "alloy-transport 0.1.3", - "reqwest", - "serde_json", - "tower 0.4.13", - "tracing", - "url", -] - [[package]] name = "alloy-transport-http" version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "39139015a5ec127d9c895b49b484608e27fe4538544f84cdf5eae0bd36339bc6" dependencies = [ - "alloy-json-rpc 0.7.0", - "alloy-transport 0.7.0", + "alloy-json-rpc", + "alloy-transport", "reqwest", "serde_json", "tower 0.5.1", @@ -1029,10 +623,10 @@ version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b6b2e366c0debf0af77766c23694a3f863b02633050e71e096e257ffbd395e50" dependencies = [ - "alloy-primitives 0.8.13", + "alloy-primitives", "alloy-rlp", "arrayvec", - "derive_more 1.0.0", + "derive_more", "nybbles", "smallvec", "tracing", @@ -1310,7 +904,7 @@ checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" name = "basic-example" version = "0.2.0-alpha.1" dependencies = [ - "alloy-primitives 0.8.13", + "alloy-primitives", "openzeppelin-stylus", "stylus-sdk", ] @@ -1319,8 +913,8 @@ dependencies = [ name = "basic-example-script" version = "0.2.0-alpha.1" dependencies = [ - "alloy 0.7.2", - "alloy-primitives 0.8.13", + "alloy", + "alloy-primitives", "basic-example", "koba", "tokio", @@ -1330,8 +924,8 @@ dependencies = [ name = "benches" version = "0.2.0-alpha.1" dependencies = [ - "alloy 0.7.2", - "alloy-primitives 0.8.13", + "alloy", + "alloy-primitives", "e2e", "eyre", "futures", @@ -1579,12 +1173,6 @@ version = "0.9.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" -[[package]] -name = "convert_case" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6245d59a3e82a7fc217c5828a6692dbc6dfb63a0c8c90495621f7b9d79704a0e" - [[package]] name = "convert_case" version = "0.6.0" @@ -1772,8 +1360,8 @@ dependencies = [ name = "cryptography-example" version = "0.2.0-alpha.1" dependencies = [ - "alloy 0.7.2", - "alloy-primitives 0.8.13", + "alloy", + "alloy-primitives", "e2e", "eyre", "openzeppelin-stylus", @@ -1883,19 +1471,6 @@ dependencies = [ "syn 2.0.89", ] -[[package]] -name = "derive_more" -version = "0.99.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f33878137e4dafd7fa914ad4e259e18a4e8e532b9617a2d0150262bf53abfce" -dependencies = [ - "convert_case 0.4.0", - "proc-macro2", - "quote", - "rustc_version 0.4.0", - "syn 2.0.89", -] - [[package]] name = "derive_more" version = "1.0.0" @@ -1948,7 +1523,7 @@ checksum = "56ce8c6da7551ec6c462cbaf3bfbc75131ebbfa1c944aeaa9dab51ca1c5f0c3b" name = "e2e" version = "0.1.0" dependencies = [ - "alloy 0.7.2", + "alloy", "e2e-proc", "eyre", "koba", @@ -2089,8 +1664,8 @@ checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" name = "erc1155-example" version = "0.2.0-alpha.1" dependencies = [ - "alloy 0.7.2", - "alloy-primitives 0.8.13", + "alloy", + "alloy-primitives", "e2e", "eyre", "openzeppelin-stylus", @@ -2102,8 +1677,8 @@ dependencies = [ name = "erc20-example" version = "0.2.0-alpha.1" dependencies = [ - "alloy 0.7.2", - "alloy-primitives 0.8.13", + "alloy", + "alloy-primitives", "e2e", "eyre", "openzeppelin-stylus", @@ -2115,8 +1690,8 @@ dependencies = [ name = "erc20-permit-example" version = "0.2.0-alpha.1" dependencies = [ - "alloy 0.7.2", - "alloy-primitives 0.8.13", + "alloy", + "alloy-primitives", "e2e", "eyre", "openzeppelin-stylus", @@ -2128,9 +1703,9 @@ dependencies = [ name = "erc721-consecutive-example" version = "0.2.0-alpha.1" dependencies = [ - "alloy 0.7.2", - "alloy-primitives 0.8.13", - "alloy-sol-types 0.8.13", + "alloy", + "alloy-primitives", + "alloy-sol-types", "e2e", "eyre", "openzeppelin-stylus", @@ -2143,8 +1718,8 @@ dependencies = [ name = "erc721-example" version = "0.2.0-alpha.1" dependencies = [ - "alloy 0.7.2", - "alloy-primitives 0.8.13", + "alloy", + "alloy-primitives", "e2e", "eyre", "openzeppelin-stylus", @@ -2157,8 +1732,8 @@ dependencies = [ name = "erc721-metadata-example" version = "0.2.0-alpha.1" dependencies = [ - "alloy 0.7.2", - "alloy-primitives 0.8.13", + "alloy", + "alloy-primitives", "e2e", "eyre", "openzeppelin-stylus", @@ -2781,10 +2356,9 @@ checksum = "57d8d8ce877200136358e0bbff3a77965875db3af755a11e1fa6b1b3e2df13ea" [[package]] name = "koba" version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "80e92e1148d087df999396266311bece9e5311c352821872cccaf5dc67117cfc" +source = "git+https://github.com/OpenZeppelin/koba?branch=build%2Fbump-alloy#9f5fc33853088f7c265571c1f90728eb56c5051f" dependencies = [ - "alloy 0.1.4", + "alloy", "brotli2", "bytesize", "clap", @@ -2899,8 +2473,8 @@ dependencies = [ name = "merkle-proofs-example" version = "0.2.0-alpha.1" dependencies = [ - "alloy-primitives 0.8.13", - "alloy-sol-types 0.8.13", + "alloy-primitives", + "alloy-sol-types", "openzeppelin-crypto", "stylus-sdk", ] @@ -2962,8 +2536,8 @@ dependencies = [ name = "motsu-proc" version = "0.2.0" dependencies = [ - "alloy-primitives 0.8.13", - "alloy-sol-types 0.8.13", + "alloy-primitives", + "alloy-sol-types", "motsu", "proc-macro2", "quote", @@ -3134,11 +2708,11 @@ dependencies = [ name = "openzeppelin-stylus" version = "0.2.0-alpha.1" dependencies = [ - "alloy-primitives 0.8.13", - "alloy-sol-macro 0.8.13", - "alloy-sol-macro-expander 0.8.13", - "alloy-sol-macro-input 0.8.13", - "alloy-sol-types 0.8.13", + "alloy-primitives", + "alloy-sol-macro", + "alloy-sol-macro-expander", + "alloy-sol-macro-input", + "alloy-sol-types", "keccak-const", "motsu", "openzeppelin-stylus-proc", @@ -3150,7 +2724,7 @@ dependencies = [ name = "openzeppelin-stylus-proc" version = "0.1.0" dependencies = [ - "convert_case 0.6.0", + "convert_case", "proc-macro2", "quote", "syn 2.0.89", @@ -3160,8 +2734,8 @@ dependencies = [ name = "ownable-example" version = "0.2.0-alpha.1" dependencies = [ - "alloy 0.7.2", - "alloy-primitives 0.8.13", + "alloy", + "alloy-primitives", "e2e", "eyre", "openzeppelin-stylus", @@ -3173,8 +2747,8 @@ dependencies = [ name = "ownable-two-step" version = "0.2.0-alpha.1" dependencies = [ - "alloy 0.7.2", - "alloy-primitives 0.8.13", + "alloy", + "alloy-primitives", "e2e", "eyre", "openzeppelin-stylus", @@ -3814,8 +3388,8 @@ checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" name = "safe-erc20-example" version = "0.2.0-alpha.1" dependencies = [ - "alloy 0.7.2", - "alloy-primitives 0.8.13", + "alloy", + "alloy-primitives", "e2e", "eyre", "openzeppelin-stylus", @@ -4143,10 +3717,10 @@ version = "0.7.0-beta.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8abd5d2cb3a10a36101b3d9243eda29daa58aad89b93979afe77c4be89068413" dependencies = [ - "alloy-primitives 0.8.13", - "alloy-sol-types 0.8.13", + "alloy-primitives", + "alloy-sol-types", "cfg-if", - "convert_case 0.6.0", + "convert_case", "lazy_static", "proc-macro-error", "proc-macro2", @@ -4154,7 +3728,7 @@ dependencies = [ "regex", "sha3", "syn 2.0.89", - "syn-solidity 0.8.14", + "syn-solidity", "trybuild", ] @@ -4164,8 +3738,8 @@ version = "0.7.0-beta.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "caa33222d37101b3ba7064f1099ae38c7e388eaeac422e58260b7d00346a5267" dependencies = [ - "alloy-primitives 0.8.13", - "alloy-sol-types 0.8.13", + "alloy-primitives", + "alloy-sol-types", "cfg-if", "derivative", "hex", @@ -4203,18 +3777,6 @@ dependencies = [ "unicode-ident", ] -[[package]] -name = "syn-solidity" -version = "0.7.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8d71e19bca02c807c9faa67b5a47673ff231b6e7449b251695188522f1dc44b2" -dependencies = [ - "paste", - "proc-macro2", - "quote", - "syn 2.0.89", -] - [[package]] name = "syn-solidity" version = "0.8.14" @@ -4454,7 +4016,6 @@ dependencies = [ "tokio", "tower-layer", "tower-service", - "tracing", ] [[package]] @@ -4489,7 +4050,6 @@ version = "0.1.40" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" dependencies = [ - "log", "pin-project-lite", "tracing-attributes", "tracing-core", @@ -4660,8 +4220,8 @@ checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" name = "vesting-wallet-example" version = "0.2.0-alpha.1" dependencies = [ - "alloy 0.7.2", - "alloy-primitives 0.8.13", + "alloy", + "alloy-primitives", "e2e", "eyre", "openzeppelin-stylus", diff --git a/Cargo.toml b/Cargo.toml index 841770e5d..54a663b4e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -94,7 +94,7 @@ alloy-sol-macro-input = { version = "=0.8.13", default-features = false } const-hex = { version = "1.11.1", default-features = false } eyre = "0.6.8" keccak-const = "0.2.0" -koba = "0.2.0" +koba = { git = "https://github.com/OpenZeppelin/koba", branch = "build/bump-alloy" } once_cell = "1.19.0" rand = "0.8.5" regex = "1.10.4" From 0f40dc46bde2744e332c40ea3655c633137f9e6a Mon Sep 17 00:00:00 2001 From: Daniel Bigos Date: Tue, 3 Dec 2024 09:21:30 +0100 Subject: [PATCH 033/109] build: update E2E crate with new alloy (cherry picked from commit 91a0e8edc06df3ed4e3f6dfd8fcccb7fc063b2c7) --- Cargo.lock | 2 +- lib/e2e/Cargo.toml | 2 +- lib/e2e/src/system.rs | 18 ++++++++++++------ 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3119e815c..2c0d6a37d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1521,7 +1521,7 @@ checksum = "56ce8c6da7551ec6c462cbaf3bfbc75131ebbfa1c944aeaa9dab51ca1c5f0c3b" [[package]] name = "e2e" -version = "0.1.0" +version = "0.2.0" dependencies = [ "alloy", "e2e-proc", diff --git a/lib/e2e/Cargo.toml b/lib/e2e/Cargo.toml index 84a9c6df0..fc8b8ab51 100644 --- a/lib/e2e/Cargo.toml +++ b/lib/e2e/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "e2e" description = "End-to-end Testing for Stylus" -version = "0.1.0" +version = "0.2.0" categories = ["development-tools::testing", "cryptography::cryptocurrencies"] keywords = ["arbitrum", "ethereum", "stylus", "integration-testing", "tests"] authors.workspace = true diff --git a/lib/e2e/src/system.rs b/lib/e2e/src/system.rs index 5d90cd8be..9f622cd24 100644 --- a/lib/e2e/src/system.rs +++ b/lib/e2e/src/system.rs @@ -3,8 +3,8 @@ use alloy::{ primitives::Address, providers::{ fillers::{ - ChainIdFiller, FillProvider, GasFiller, JoinFill, NonceFiller, - WalletFiller, + BlobGasFiller, ChainIdFiller, FillProvider, GasFiller, JoinFill, + NonceFiller, WalletFiller, }, Identity, ProviderBuilder, RootProvider, }, @@ -20,8 +20,11 @@ pub(crate) const RPC_URL_ENV_VAR_NAME: &str = "RPC_URL"; pub type Wallet = FillProvider< JoinFill< JoinFill< - JoinFill, NonceFiller>, - ChainIdFiller, + Identity, + JoinFill< + GasFiller, + JoinFill>, + >, >, WalletFiller, >, @@ -33,8 +36,11 @@ pub type Wallet = FillProvider< /// Convenience type alias that represents an alloy provider. pub type Provider = FillProvider< JoinFill< - JoinFill, NonceFiller>, - ChainIdFiller, + Identity, + JoinFill< + GasFiller, + JoinFill>, + >, >, RootProvider>, Http, From 3c909bf38e3ab7ba757e169060792159e260c7de Mon Sep 17 00:00:00 2001 From: Daniel Bigos Date: Tue, 3 Dec 2024 09:52:56 +0100 Subject: [PATCH 034/109] ref: extract v as u8 from Signature (cherry picked from commit 25d400c9122af0840d51049b3c40ed4c0e464ce3) --- examples/ecdsa/tests/ecdsa.rs | 16 ++++++---------- examples/erc20-permit/tests/erc20permit.rs | 19 ++++++++++++------- 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/examples/ecdsa/tests/ecdsa.rs b/examples/ecdsa/tests/ecdsa.rs index 9380fd9bb..1673a6c90 100644 --- a/examples/ecdsa/tests/ecdsa.rs +++ b/examples/ecdsa/tests/ecdsa.rs @@ -1,7 +1,7 @@ #![cfg(feature = "e2e")] use abi::ECDSA; -use alloy::primitives::{address, b256, uint, Address, B256}; +use alloy::primitives::{address, b256, uint, Address, Parity, B256}; use e2e::{Account, ReceiptExt, Revert}; use eyre::Result; use openzeppelin_stylus::utils::cryptography::ecdsa::SIGNATURE_S_UPPER_BOUND; @@ -108,17 +108,13 @@ async fn recovers_from_v_r_s(alice: Account) -> Result<()> { let contract = ECDSA::new(contract_addr, &alice.wallet); let signature = alice.sign_hash(&HASH).await; + let parity: Parity = signature.v().into(); + let v_byte = parity + .y_parity_byte_non_eip155() + .expect("should be non-EIP155 signature"); let ECDSA::recoverReturn { recovered } = contract - .recover( - HASH, - signature - .v() - .y_parity_byte_non_eip155() - .expect("should be non-EIP155 signature"), - signature.r().into(), - signature.s().into(), - ) + .recover(HASH, v_byte, signature.r().into(), signature.s().into()) .call() .await?; diff --git a/examples/erc20-permit/tests/erc20permit.rs b/examples/erc20-permit/tests/erc20permit.rs index d831c3f43..ab0e155a5 100644 --- a/examples/erc20-permit/tests/erc20permit.rs +++ b/examples/erc20-permit/tests/erc20permit.rs @@ -2,14 +2,14 @@ use abi::Erc20Permit; use alloy::{ - primitives::{b256, keccak256, Address, B256, U256}, + primitives::{b256, keccak256, Address, Parity, B256, U256}, + signers::Signature, sol, sol_types::SolType, }; use alloy_primitives::uint; use e2e::{receipt, send, watch, Account, EventExt, ReceiptExt, Revert}; use eyre::Result; - mod abi; // Saturday, 1 January 2000 00:00:00 @@ -65,6 +65,11 @@ fn permit_struct_hash( ))) } +fn extract_signature_v(signature: &Signature) -> u8 { + let parity: Parity = signature.v().into(); + parity.y_parity_byte_non_eip155().expect("should be non-EIP155 signature") +} + // ============================================================================ // Integration Tests: ERC-20 Permit Extension // ============================================================================ @@ -103,7 +108,7 @@ async fn error_when_expired_deadline_for_permit( bob_addr, balance, EXPIRED_DEADLINE, - signature.v().y_parity_byte_non_eip155().unwrap(), + extract_signature_v(&signature), signature.r().into(), signature.s().into() )) @@ -152,7 +157,7 @@ async fn permit_works(alice: Account, bob: Account) -> Result<()> { bob_addr, balance, FAIR_DEADLINE, - signature.v().y_parity_byte_non_eip155().unwrap(), + extract_signature_v(&signature), signature.r().into(), signature.s().into() ))?; @@ -237,7 +242,7 @@ async fn permit_rejects_reused_signature( bob_addr, balance, FAIR_DEADLINE, - signature.v().y_parity_byte_non_eip155().unwrap(), + extract_signature_v(&signature), signature.r().into(), signature.s().into() ))?; @@ -247,7 +252,7 @@ async fn permit_rejects_reused_signature( bob_addr, balance, FAIR_DEADLINE, - signature.v().y_parity_byte_non_eip155().unwrap(), + extract_signature_v(&signature), signature.r().into(), signature.s().into() )) @@ -312,7 +317,7 @@ async fn permit_rejects_invalid_signature( bob_addr, balance, FAIR_DEADLINE, - signature.v().y_parity_byte_non_eip155().unwrap(), + extract_signature_v(&signature), signature.r().into(), signature.s().into() )) From 1acaa4c1b8fba808cfa5b5b45e4cdc7ee54ebc88 Mon Sep 17 00:00:00 2001 From: Daniel Bigos Date: Tue, 3 Dec 2024 10:09:38 +0100 Subject: [PATCH 035/109] fix: use proper data type for U96 (cherry picked from commit 0596f0c17d2c3b6fa3a116e62fba470f4d3ecd1e) --- examples/erc721-consecutive/tests/erc721-consecutive.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/erc721-consecutive/tests/erc721-consecutive.rs b/examples/erc721-consecutive/tests/erc721-consecutive.rs index 1f50f78c5..ed572ea52 100644 --- a/examples/erc721-consecutive/tests/erc721-consecutive.rs +++ b/examples/erc721-consecutive/tests/erc721-consecutive.rs @@ -4,7 +4,7 @@ use alloy::{ primitives::{Address, U256}, sol, }; -use alloy_primitives::uint; +use alloy_primitives::{uint, aliases::U96}; use e2e::{receipt, watch, Account, EventExt, ReceiptExt, Revert}; use crate::{abi::Erc721, Erc721ConsecutiveExample::constructorCall}; @@ -24,9 +24,9 @@ fn random_token_id() -> U256 { fn ctr(receivers: Vec
, amounts: Vec) -> constructorCall { constructorCall { receivers, - amounts, - firstConsecutiveId: FIRST_CONSECUTIVE_ID, - maxBatchSize: MAX_BATCH_SIZE, + amounts: amounts.iter().map(|v| U96::from(*v)).collect(), + firstConsecutiveId: U96::from(FIRST_CONSECUTIVE_ID), + maxBatchSize: U96::from(MAX_BATCH_SIZE), } } From fa476f146652ca0a6e1178518b7b7f5cde852acc Mon Sep 17 00:00:00 2001 From: Daniel Bigos Date: Tue, 3 Dec 2024 11:50:40 +0100 Subject: [PATCH 036/109] fix: benches (cherry picked from commit 65a0c6ed24b1400a91688a20f32d0b3c3ad87b8c) --- benches/src/lib.rs | 4 ++-- examples/erc721-consecutive/tests/erc721-consecutive.rs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/benches/src/lib.rs b/benches/src/lib.rs index f6f39d9a2..dfbb657f6 100644 --- a/benches/src/lib.rs +++ b/benches/src/lib.rs @@ -3,7 +3,7 @@ use std::process::Command; use alloy::{ primitives::Address, rpc::types::{ - serde_helpers::WithOtherFields, AnyReceiptEnvelope, Log, + serde_helpers::WithOtherFields, AnyReceiptEnvelope, Log, Receipt, TransactionReceipt, }, }; @@ -40,7 +40,7 @@ pub enum CacheOpt { } type ArbTxReceipt = - WithOtherFields>>; + WithOtherFields>>>; async fn deploy( account: &Account, diff --git a/examples/erc721-consecutive/tests/erc721-consecutive.rs b/examples/erc721-consecutive/tests/erc721-consecutive.rs index ed572ea52..740779a42 100644 --- a/examples/erc721-consecutive/tests/erc721-consecutive.rs +++ b/examples/erc721-consecutive/tests/erc721-consecutive.rs @@ -4,7 +4,7 @@ use alloy::{ primitives::{Address, U256}, sol, }; -use alloy_primitives::{uint, aliases::U96}; +use alloy_primitives::{aliases::U96, uint}; use e2e::{receipt, watch, Account, EventExt, ReceiptExt, Revert}; use crate::{abi::Erc721, Erc721ConsecutiveExample::constructorCall}; From 1078a12fd0e6090c4979d27fadf8ec33549bf776 Mon Sep 17 00:00:00 2001 From: Daniel Bigos Date: Wed, 4 Dec 2024 21:10:54 +0100 Subject: [PATCH 037/109] fix: constrain storage ints --- .../src/token/erc1155/extensions/metadata_uri.rs | 2 +- contracts/src/utils/math/storage.rs | 13 +++++++++---- contracts/src/utils/metadata.rs | 2 +- .../src/utils/structs/checkpoints/generic_size.rs | 3 +++ 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/contracts/src/token/erc1155/extensions/metadata_uri.rs b/contracts/src/token/erc1155/extensions/metadata_uri.rs index 6f822a7df..8e7c8debd 100644 --- a/contracts/src/token/erc1155/extensions/metadata_uri.rs +++ b/contracts/src/token/erc1155/extensions/metadata_uri.rs @@ -3,7 +3,7 @@ //! //! [ERC]: https://eips.ethereum.org/EIPS/eip-1155#metadata-extensions -use alloc::string::String; +use alloc::{string::String, vec::Vec}; use alloy_primitives::{FixedBytes, U256}; use alloy_sol_macro::sol; diff --git a/contracts/src/utils/math/storage.rs b/contracts/src/utils/math/storage.rs index 31193c47b..51d891a3b 100644 --- a/contracts/src/utils/math/storage.rs +++ b/contracts/src/utils/math/storage.rs @@ -1,5 +1,6 @@ //! Simple math operations missing in `stylus_sdk::storage`. use alloy_primitives::Uint; +use alloy_sol_types::sol_data::{IntBitCount, SupportedInt}; use stylus_sdk::storage::{StorageGuardMut, StorageUint}; pub(crate) trait AddAssignUnchecked { @@ -8,10 +9,12 @@ pub(crate) trait AddAssignUnchecked { impl<'a, const B: usize, const L: usize> AddAssignUnchecked> for StorageGuardMut<'a, StorageUint> +where + IntBitCount: SupportedInt, { fn add_assign_unchecked(&mut self, rhs: Uint) { - let new_balance = self.get() + rhs; - self.set(new_balance); + let new_value = self.get() + rhs; + self.set(new_value); } } @@ -21,9 +24,11 @@ pub(crate) trait SubAssignUnchecked { impl<'a, const B: usize, const L: usize> SubAssignUnchecked> for StorageGuardMut<'a, StorageUint> +where + IntBitCount: SupportedInt, { fn sub_assign_unchecked(&mut self, rhs: Uint) { - let new_balance = self.get() - rhs; - self.set(new_balance); + let new_value = self.get() - rhs; + self.set(new_value); } } diff --git a/contracts/src/utils/metadata.rs b/contracts/src/utils/metadata.rs index b4410d12c..e668bca34 100644 --- a/contracts/src/utils/metadata.rs +++ b/contracts/src/utils/metadata.rs @@ -1,5 +1,5 @@ //! Common Metadata Smart Contract. -use alloc::{string::String, vec, vec::Vec}; +use alloc::{string::String, vec::Vec}; use stylus_sdk::stylus_proc::{public, sol_storage}; sol_storage! { diff --git a/contracts/src/utils/structs/checkpoints/generic_size.rs b/contracts/src/utils/structs/checkpoints/generic_size.rs index 033700c66..aee10a65e 100644 --- a/contracts/src/utils/structs/checkpoints/generic_size.rs +++ b/contracts/src/utils/structs/checkpoints/generic_size.rs @@ -2,6 +2,7 @@ use core::ops::{Add, Div, Mul, Sub}; +use alloy_sol_types::sol_data::{IntBitCount, SupportedInt}; use stylus_sdk::{alloy_primitives::Uint, prelude::*}; /// Trait that associates types of specific size for checkpoints key and value. @@ -87,6 +88,8 @@ pub trait Accessor { impl Accessor for stylus_sdk::storage::StorageUint +where + IntBitCount: SupportedInt, { type Wraps = Uint; From a9c3fbed98776fdaeb53d9317747f8d3d065b55a Mon Sep 17 00:00:00 2001 From: Daniel Bigos Date: Thu, 5 Dec 2024 15:24:56 +0100 Subject: [PATCH 038/109] build: update koba to v0.3.0 --- Cargo.lock | 5 +++-- Cargo.toml | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2c0d6a37d..4b966c4ba 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2355,8 +2355,9 @@ checksum = "57d8d8ce877200136358e0bbff3a77965875db3af755a11e1fa6b1b3e2df13ea" [[package]] name = "koba" -version = "0.2.0" -source = "git+https://github.com/OpenZeppelin/koba?branch=build%2Fbump-alloy#9f5fc33853088f7c265571c1f90728eb56c5051f" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "648bf93c7aff36defcf825c5a42d32503eb617c85f057a989f34ebfebed99f45" dependencies = [ "alloy", "brotli2", diff --git a/Cargo.toml b/Cargo.toml index 54a663b4e..aeaad6ac9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -94,7 +94,7 @@ alloy-sol-macro-input = { version = "=0.8.13", default-features = false } const-hex = { version = "1.11.1", default-features = false } eyre = "0.6.8" keccak-const = "0.2.0" -koba = { git = "https://github.com/OpenZeppelin/koba", branch = "build/bump-alloy" } +koba = "0.3.0" once_cell = "1.19.0" rand = "0.8.5" regex = "1.10.4" From 94cb034c5f59ea0ffd46c644adc193e13bef4b4d Mon Sep 17 00:00:00 2001 From: Alisander Qoshqosh Date: Fri, 6 Dec 2024 11:55:40 +0400 Subject: [PATCH 039/109] remove not used Provider --- lib/e2e/src/lib.rs | 2 +- lib/e2e/src/system.rs | 30 +----------------------------- 2 files changed, 2 insertions(+), 30 deletions(-) diff --git a/lib/e2e/src/lib.rs b/lib/e2e/src/lib.rs index 539f71aa7..13c2c4dea 100644 --- a/lib/e2e/src/lib.rs +++ b/lib/e2e/src/lib.rs @@ -13,7 +13,7 @@ pub use e2e_proc::test; pub use error::{Panic, PanicCode, Revert}; pub use event::EventExt; pub use receipt::ReceiptExt; -pub use system::{fund_account, provider, Provider, Wallet}; +pub use system::{fund_account, Wallet}; /// This macro provides a shorthand for broadcasting the transaction to the /// network. diff --git a/lib/e2e/src/system.rs b/lib/e2e/src/system.rs index 9f622cd24..1c0613e4a 100644 --- a/lib/e2e/src/system.rs +++ b/lib/e2e/src/system.rs @@ -6,7 +6,7 @@ use alloy::{ BlobGasFiller, ChainIdFiller, FillProvider, GasFiller, JoinFill, NonceFiller, WalletFiller, }, - Identity, ProviderBuilder, RootProvider, + Identity, RootProvider, }, transports::http::{Client, Http}, }; @@ -33,39 +33,11 @@ pub type Wallet = FillProvider< Ethereum, >; -/// Convenience type alias that represents an alloy provider. -pub type Provider = FillProvider< - JoinFill< - Identity, - JoinFill< - GasFiller, - JoinFill>, - >, - >, - RootProvider>, - Http, - Ethereum, ->; - /// Load the `name` environment variable. fn env(name: &str) -> eyre::Result { std::env::var(name).wrap_err(format!("failed to load {name}")) } -/// Returns an alloy provider connected to the `RPC_URL` rpc endpoint. -/// -/// # Panics -/// -/// May panic if unable to load the `RPC_URL` environment variable. -#[must_use] -pub fn provider() -> Provider { - let rpc_url = env(RPC_URL_ENV_VAR_NAME) - .expect("failed to load RPC_URL var from env") - .parse() - .expect("failed to parse RPC_URL string into a URL"); - ProviderBuilder::new().with_recommended_fillers().on_http(rpc_url) -} - /// Send `amount` eth to `address` in the nitro-tesnode. pub fn fund_account(address: Address, amount: u32) -> eyre::Result<()> { let node_script = get_node_path()?.join("test-node.bash"); From 06945d6230c2fc735bcffcc22e059633c5fc07d4 Mon Sep 17 00:00:00 2001 From: Alisander Qoshqosh Date: Fri, 6 Dec 2024 14:43:21 +0400 Subject: [PATCH 040/109] add stylus-sdk patch for external calls --- Cargo.lock | 9 +++------ Cargo.toml | 9 +++++++++ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4b966c4ba..746da475d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2489,8 +2489,7 @@ checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" [[package]] name = "mini-alloc" version = "0.7.0-beta.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d79b46612e3fc76138ed930cd2e4bbd26ada11954a6d312e3affe4b56df0081" +source = "git+https://github.com/qalisander/stylus-sdk-rs?branch=fix-encoding-in-sol-interface#a31d36a883f8b3d30835f05779997b793444e532" dependencies = [ "cfg-if", ] @@ -3715,8 +3714,7 @@ dependencies = [ [[package]] name = "stylus-proc" version = "0.7.0-beta.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8abd5d2cb3a10a36101b3d9243eda29daa58aad89b93979afe77c4be89068413" +source = "git+https://github.com/qalisander/stylus-sdk-rs?branch=fix-encoding-in-sol-interface#a31d36a883f8b3d30835f05779997b793444e532" dependencies = [ "alloy-primitives", "alloy-sol-types", @@ -3736,8 +3734,7 @@ dependencies = [ [[package]] name = "stylus-sdk" version = "0.7.0-beta.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "caa33222d37101b3ba7064f1099ae38c7e388eaeac422e58260b7d00346a5267" +source = "git+https://github.com/qalisander/stylus-sdk-rs?branch=fix-encoding-in-sol-interface#a31d36a883f8b3d30835f05779997b793444e532" dependencies = [ "alloy-primitives", "alloy-sol-types", diff --git a/Cargo.toml b/Cargo.toml index aeaad6ac9..3748f50e5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -136,3 +136,12 @@ incremental = false [profile.dev] panic = "abort" + +# TODO#q: remove this once the fix is released +[patch.crates-io.stylus-sdk] +git = "https://github.com/qalisander/stylus-sdk-rs" +branch = "fix-encoding-in-sol-interface" + +[patch.crates-io.stylus-proc] +git = "https://github.com/qalisander/stylus-sdk-rs" +branch = "fix-encoding-in-sol-interface" From 3a6e6bd3ffec2f428c7c4fc7b8cc4f37440ff076 Mon Sep 17 00:00:00 2001 From: Alisander Qoshqosh Date: Sat, 7 Dec 2024 19:08:45 +0400 Subject: [PATCH 041/109] retrieve tx hashes for block timestamp --- examples/vesting-wallet/tests/vesting-wallet.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/vesting-wallet/tests/vesting-wallet.rs b/examples/vesting-wallet/tests/vesting-wallet.rs index 50f0b48e8..d75ba49c1 100644 --- a/examples/vesting-wallet/tests/vesting-wallet.rs +++ b/examples/vesting-wallet/tests/vesting-wallet.rs @@ -39,7 +39,7 @@ fn ctr( async fn block_timestamp(account: &Account) -> eyre::Result { let timestamp = account .wallet - .get_block(BlockId::latest(), BlockTransactionsKind::Full) + .get_block(BlockId::latest(), BlockTransactionsKind::Hashes) .await? .expect("latest block should exist") .header From d33bdc3d303322263e93907524cba1cf490df771 Mon Sep 17 00:00:00 2001 From: Alisander Qoshqosh Date: Sat, 7 Dec 2024 19:55:29 +0400 Subject: [PATCH 042/109] fix run_check_release test for vesting_wallet --- examples/vesting-wallet/tests/vesting-wallet.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/examples/vesting-wallet/tests/vesting-wallet.rs b/examples/vesting-wallet/tests/vesting-wallet.rs index d75ba49c1..d292b8b7f 100644 --- a/examples/vesting-wallet/tests/vesting-wallet.rs +++ b/examples/vesting-wallet/tests/vesting-wallet.rs @@ -311,9 +311,10 @@ mod erc20_vesting { assert_in_delta(old_alice_balance + released, alice_balance); assert_in_delta(old_contract_balance - released, contract_balance); - assert!( - receipt.emits(VestingWallet::EtherReleased { amount: released }) - ); + assert!(receipt.emits(VestingWallet::ERC20Released { + token: erc20_address, + amount: released + })); Ok(()) } From eb5cc951a3215c15944866995181ef7ae99566e1 Mon Sep 17 00:00:00 2001 From: Alisander Qoshqosh Date: Mon, 9 Dec 2024 17:08:30 +0400 Subject: [PATCH 043/109] update alloy to 0.8.14 --- Cargo.lock | 34 +++++++++++++++++----------------- Cargo.toml | 10 +++++----- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4c813e09e..650e87f1d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -247,9 +247,9 @@ dependencies = [ [[package]] name = "alloy-json-abi" -version = "0.8.13" +version = "0.8.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a500037938085feed8a20dbfc8fce58c599db68c948cfae711147175dee392c" +checksum = "ac4b22b3e51cac09fd2adfcc73b55f447b4df669f983c13f7894ec82b607c63f" dependencies = [ "alloy-primitives", "alloy-sol-type-parser", @@ -311,9 +311,9 @@ dependencies = [ [[package]] name = "alloy-primitives" -version = "0.8.13" +version = "0.8.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3aeeb5825c2fc8c2662167058347cd0cafc3cb15bcb5cdb1758a63c2dca0409e" +checksum = "9db948902dfbae96a73c2fbf1f7abec62af034ab883e4c777c3fd29702bd6e2c" dependencies = [ "alloy-rlp", "arbitrary", @@ -511,9 +511,9 @@ dependencies = [ [[package]] name = "alloy-sol-macro" -version = "0.8.13" +version = "0.8.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c0279d09463a4695788a3622fd95443625f7be307422deba4b55dd491a9c7a1" +checksum = "3bfd7853b65a2b4f49629ec975fee274faf6dff15ab8894c620943398ef283c0" dependencies = [ "alloy-sol-macro-expander", "alloy-sol-macro-input", @@ -525,9 +525,9 @@ dependencies = [ [[package]] name = "alloy-sol-macro-expander" -version = "0.8.13" +version = "0.8.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4feea540fc8233df2ad1156efd744b2075372f43a8f942a68b3b19c8a00e2c12" +checksum = "82ec42f342d9a9261699f8078e57a7a4fda8aaa73c1a212ed3987080e6a9cd13" dependencies = [ "alloy-json-abi", "alloy-sol-macro-input", @@ -544,9 +544,9 @@ dependencies = [ [[package]] name = "alloy-sol-macro-input" -version = "0.8.13" +version = "0.8.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a0ad281f3d1b613af814b66977ee698e443d4644a1510962d0241f26e0e53ae" +checksum = "ed2c50e6a62ee2b4f7ab3c6d0366e5770a21cad426e109c2f40335a1b3aff3df" dependencies = [ "alloy-json-abi", "const-hex", @@ -571,9 +571,9 @@ dependencies = [ [[package]] name = "alloy-sol-types" -version = "0.8.13" +version = "0.8.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cff34e0682d6665da243a3e81da96f07a2dd50f7e64073e382b1a141f5a2a2f6" +checksum = "c9dc0fffe397aa17628160e16b89f704098bf3c9d74d5d369ebc239575936de5" dependencies = [ "alloy-json-abi", "alloy-primitives", @@ -1156,9 +1156,9 @@ checksum = "0b6a852b24ab71dffc585bcb46eaf7959d175cb865a7152e35b348d1b2960422" [[package]] name = "const-hex" -version = "1.12.0" +version = "1.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94fb8a24a26d37e1ffd45343323dc9fe6654ceea44c12f2fcb3d7ac29e610bc6" +checksum = "4b0485bab839b018a8f1723fc5391819fea5f8f0f32288ef8a735fd096b6160c" dependencies = [ "cfg-if", "cpufeatures", @@ -2502,7 +2502,7 @@ checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" [[package]] name = "mini-alloc" version = "0.7.0-beta.1" -source = "git+https://github.com/qalisander/stylus-sdk-rs?branch=fix-encoding-in-sol-interface#a31d36a883f8b3d30835f05779997b793444e532" +source = "git+https://github.com/qalisander/stylus-sdk-rs?branch=fix-encoding-in-sol-interface#2af4d8e232fc90c464eed29d0c0396f330f183ea" dependencies = [ "cfg-if", ] @@ -3727,7 +3727,7 @@ dependencies = [ [[package]] name = "stylus-proc" version = "0.7.0-beta.1" -source = "git+https://github.com/qalisander/stylus-sdk-rs?branch=fix-encoding-in-sol-interface#a31d36a883f8b3d30835f05779997b793444e532" +source = "git+https://github.com/qalisander/stylus-sdk-rs?branch=fix-encoding-in-sol-interface#2af4d8e232fc90c464eed29d0c0396f330f183ea" dependencies = [ "alloy-primitives", "alloy-sol-types", @@ -3747,7 +3747,7 @@ dependencies = [ [[package]] name = "stylus-sdk" version = "0.7.0-beta.1" -source = "git+https://github.com/qalisander/stylus-sdk-rs?branch=fix-encoding-in-sol-interface#a31d36a883f8b3d30835f05779997b793444e532" +source = "git+https://github.com/qalisander/stylus-sdk-rs?branch=fix-encoding-in-sol-interface#2af4d8e232fc90c464eed29d0c0396f330f183ea" dependencies = [ "alloy-primitives", "alloy-sol-types", diff --git a/Cargo.toml b/Cargo.toml index cdfde278f..06f56207c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -87,11 +87,11 @@ alloy = { version = "=0.7.2", features = [ # Even though `alloy` includes `alloy-primitives` and `alloy-sol-types` we need # to keep both versions for compatibility with the Stylus SDK. Once they start # using `alloy` we can remove these. -alloy-primitives = { version = "=0.8.13", default-features = false } -alloy-sol-types = { version = "=0.8.13", default-features = false } -alloy-sol-macro = { version = "=0.8.13", default-features = false } -alloy-sol-macro-expander = { version = "=0.8.13", default-features = false } -alloy-sol-macro-input = { version = "=0.8.13", default-features = false } +alloy-primitives = { version = "=0.8.14", default-features = false } +alloy-sol-types = { version = "=0.8.14", default-features = false } +alloy-sol-macro = { version = "=0.8.14", default-features = false } +alloy-sol-macro-expander = { version = "=0.8.14", default-features = false } +alloy-sol-macro-input = { version = "=0.8.14", default-features = false } const-hex = { version = "1.11.1", default-features = false } eyre = "0.6.8" From c255a90371d7a72c723792105ed1764ec21368dc Mon Sep 17 00:00:00 2001 From: Alisander Qoshqosh Date: Wed, 11 Dec 2024 16:17:50 +0400 Subject: [PATCH 044/109] ++ --- contracts/src/utils/math/storage.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/contracts/src/utils/math/storage.rs b/contracts/src/utils/math/storage.rs index 7d5a07c34..5e709c002 100644 --- a/contracts/src/utils/math/storage.rs +++ b/contracts/src/utils/math/storage.rs @@ -1,5 +1,6 @@ //! Simple math operations missing in `stylus_sdk::storage`. use alloy_primitives::Uint; +use alloy_sol_types::sol_data::{IntBitCount, SupportedInt}; use stylus_sdk::storage::StorageUint; /// Adds value and assign the result to `self`, ignoring overflow. From f8b76459b21c8863e7df48a57e7f8b0c9c9a2857 Mon Sep 17 00:00:00 2001 From: Alisander Qoshqosh Date: Wed, 11 Dec 2024 16:28:40 +0400 Subject: [PATCH 045/109] import alloc::vec::Vec for permit --- contracts/src/token/erc20/extensions/permit.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/contracts/src/token/erc20/extensions/permit.rs b/contracts/src/token/erc20/extensions/permit.rs index 64af6492a..089184048 100644 --- a/contracts/src/token/erc20/extensions/permit.rs +++ b/contracts/src/token/erc20/extensions/permit.rs @@ -12,6 +12,8 @@ //! //! [ERC]: https://eips.ethereum.org/EIPS/eip-2612 +use alloc::vec::Vec; + use alloy_primitives::{b256, keccak256, Address, B256, U256}; use alloy_sol_types::{sol, SolType}; use stylus_sdk::{ From 0f2a246697ce9de751b44f2a138c5b20ea271a7f Mon Sep 17 00:00:00 2001 From: Alisander Qoshqosh Date: Wed, 11 Dec 2024 16:28:59 +0400 Subject: [PATCH 046/109] remove unused code --- lib/e2e/src/lib.rs | 2 +- lib/e2e/src/system.rs | 5 ----- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/lib/e2e/src/lib.rs b/lib/e2e/src/lib.rs index 8c35d7e62..8878ee197 100644 --- a/lib/e2e/src/lib.rs +++ b/lib/e2e/src/lib.rs @@ -13,7 +13,7 @@ pub use e2e_proc::test; pub use error::{Panic, PanicCode, Revert}; pub use event::Ext as EventExt; pub use receipt::Ext as ReceiptExt; -pub use system::{fund_account, provider, Provider, Wallet}; +pub use system::{fund_account, Wallet}; /// This macro provides a shorthand for broadcasting the transaction to the /// network. diff --git a/lib/e2e/src/system.rs b/lib/e2e/src/system.rs index 1ab09c66b..f58591e53 100644 --- a/lib/e2e/src/system.rs +++ b/lib/e2e/src/system.rs @@ -33,11 +33,6 @@ pub type Wallet = FillProvider< Ethereum, >; -/// Load the `name` environment variable. -fn env(name: &str) -> eyre::Result { - std::env::var(name).wrap_err(format!("failed to load {name}")) -} - /// Send `amount` eth to `address` in the nitro-tesnode. /// /// # Errors From f27aed9f42f9949d1124d1f447b451befa317ec7 Mon Sep 17 00:00:00 2001 From: Alisander Qoshqosh Date: Thu, 12 Dec 2024 00:20:12 +0400 Subject: [PATCH 047/109] ++ --- contracts/src/token/erc1155/extensions/supply.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/contracts/src/token/erc1155/extensions/supply.rs b/contracts/src/token/erc1155/extensions/supply.rs index 0c5e218c3..3d965e7ee 100644 --- a/contracts/src/token/erc1155/extensions/supply.rs +++ b/contracts/src/token/erc1155/extensions/supply.rs @@ -358,7 +358,7 @@ impl Erc1155Supply { #[cfg(all(test, feature = "std"))] mod tests { - use alloy_primitives::{address, Address, U256}; + /*use alloy_primitives::{address, Address, U256}; use super::{Erc1155Supply, IErc1155Supply}; use crate::token::erc1155::{ @@ -517,5 +517,5 @@ mod tests { assert_eq!(U256::ZERO, contract.total_supply(token_ids[0])); assert_eq!(U256::ZERO, contract.total_supply_all()); assert!(!contract.exists(token_ids[0])); - } + }*/ } From f0f94acbda4ee07e4d28b8240c0c27109bffdbcb Mon Sep 17 00:00:00 2001 From: Alisander Qoshqosh Date: Thu, 12 Dec 2024 01:01:56 +0400 Subject: [PATCH 048/109] ++ --- Cargo.lock | 3 ++ .../src/token/erc1155/extensions/supply.rs | 4 +- .../token/erc1155/extensions/uri_storage.rs | 4 +- contracts/src/token/erc721/mod.rs | 44 +++++++++---------- 4 files changed, 27 insertions(+), 28 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6c51dee45..62a7a4a8e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3334,6 +3334,9 @@ name = "rustc-hash" version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "583034fd73374156e66797ed8e5b0d5690409c9226b22d87cb7f19821c05d152" +dependencies = [ + "rand", +] [[package]] name = "rustc-hex" diff --git a/contracts/src/token/erc1155/extensions/supply.rs b/contracts/src/token/erc1155/extensions/supply.rs index 0c5e218c3..3d965e7ee 100644 --- a/contracts/src/token/erc1155/extensions/supply.rs +++ b/contracts/src/token/erc1155/extensions/supply.rs @@ -358,7 +358,7 @@ impl Erc1155Supply { #[cfg(all(test, feature = "std"))] mod tests { - use alloy_primitives::{address, Address, U256}; + /*use alloy_primitives::{address, Address, U256}; use super::{Erc1155Supply, IErc1155Supply}; use crate::token::erc1155::{ @@ -517,5 +517,5 @@ mod tests { assert_eq!(U256::ZERO, contract.total_supply(token_ids[0])); assert_eq!(U256::ZERO, contract.total_supply_all()); assert!(!contract.exists(token_ids[0])); - } + }*/ } diff --git a/contracts/src/token/erc1155/extensions/uri_storage.rs b/contracts/src/token/erc1155/extensions/uri_storage.rs index fd0052ab3..19c439a56 100644 --- a/contracts/src/token/erc1155/extensions/uri_storage.rs +++ b/contracts/src/token/erc1155/extensions/uri_storage.rs @@ -87,7 +87,7 @@ impl Erc1155UriStorage { #[cfg(all(test, feature = "std"))] mod tests { - use alloy_primitives::U256; + /*use alloy_primitives::U256; use stylus_sdk::stylus_proc::sol_storage; use super::Erc1155UriStorage; @@ -216,5 +216,5 @@ mod tests { contract.set_base_uri(base_uri.clone()); assert_eq!(base_uri, contract._base_uri.get_string()); - } + }*/ } diff --git a/contracts/src/token/erc721/mod.rs b/contracts/src/token/erc721/mod.rs index 9138e060a..adfc6baf6 100644 --- a/contracts/src/token/erc721/mod.rs +++ b/contracts/src/token/erc721/mod.rs @@ -163,30 +163,26 @@ impl MethodError for Error { } } -pub use receiver::IERC721Receiver; - -#[allow(missing_docs)] -mod receiver { - stylus_sdk::stylus_proc::sol_interface! { - /// [`Erc721`] token receiver interface. +stylus_sdk::stylus_proc::sol_interface! { + /// [`Erc721`] token receiver interface. + /// + /// Interface for any contract that wants to support `safe_transfers` + /// from [`Erc721`] asset contracts. + #[allow(missing_docs)] + interface IERC721Receiver { + /// Whenever an [`Erc721`] `token_id` token is transferred + /// to this contract via [`Erc721::safe_transfer_from`]. /// - /// Interface for any contract that wants to support `safe_transfers` - /// from [`Erc721`] asset contracts. - interface IERC721Receiver { - /// Whenever an [`Erc721`] `token_id` token is transferred - /// to this contract via [`Erc721::safe_transfer_from`]. - /// - /// It must return its function selector to confirm the token transfer. - /// If any other value is returned or the interface is not implemented - /// by the recipient, the transfer will be reverted. - #[allow(missing_docs)] - function onERC721Received( - address operator, - address from, - uint256 token_id, - bytes calldata data - ) external returns (bytes4); - } + /// It must return its function selector to confirm the token transfer. + /// If any other value is returned or the interface is not implemented + /// by the recipient, the transfer will be reverted. + #[allow(missing_docs)] + function onERC721Received( + address operator, + address from, + uint256 token_id, + bytes calldata data + ) external returns (bytes4); } } @@ -2556,7 +2552,7 @@ mod tests { let token_id = random_token_id(); erc721 .sender(alice) - ._safe_mint(receiver.address(), token_id, vec![0, 1, 2, 3].into()) + ._safe_mint(receiver.address(), token_id, &vec![0, 1, 2, 3].into()) .unwrap(); let received_token_id = receiver.sender(alice).received_token_id(); From 32ad8fd9682a385727b4e694b775eb3e870b66c1 Mon Sep 17 00:00:00 2001 From: Alisander Qoshqosh Date: Thu, 12 Dec 2024 03:34:20 +0400 Subject: [PATCH 049/109] test ping_pong_works pass with msg::sender() --- Cargo.lock | 3 --- Cargo.toml | 16 +++++++++++----- contracts/src/utils/context.rs | 4 +--- lib/motsu/Cargo.toml | 2 +- lib/motsu/src/context.rs | 13 ++++++++++++- lib/motsu/src/lib.rs | 30 +++++++++--------------------- lib/motsu/src/shims.rs | 5 +---- 7 files changed, 35 insertions(+), 38 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 62a7a4a8e..18691b716 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2515,7 +2515,6 @@ checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" [[package]] name = "mini-alloc" version = "0.7.0-beta.1" -source = "git+https://github.com/qalisander/stylus-sdk-rs?branch=fix-encoding-in-sol-interface#2af4d8e232fc90c464eed29d0c0396f330f183ea" dependencies = [ "cfg-if", ] @@ -3745,7 +3744,6 @@ dependencies = [ [[package]] name = "stylus-proc" version = "0.7.0-beta.1" -source = "git+https://github.com/qalisander/stylus-sdk-rs?branch=fix-encoding-in-sol-interface#2af4d8e232fc90c464eed29d0c0396f330f183ea" dependencies = [ "alloy-primitives", "alloy-sol-types", @@ -3765,7 +3763,6 @@ dependencies = [ [[package]] name = "stylus-sdk" version = "0.7.0-beta.1" -source = "git+https://github.com/qalisander/stylus-sdk-rs?branch=fix-encoding-in-sol-interface#2af4d8e232fc90c464eed29d0c0396f330f183ea" dependencies = [ "alloy-primitives", "alloy-sol-types", diff --git a/Cargo.toml b/Cargo.toml index a3630ea1d..95446d178 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -148,11 +148,17 @@ default = { extend-ignore-identifiers-re = [ ] } files = { extend-exclude = [] } -# TODO#q: remove this once the fix is released +## TODO#q: remove this once the fix is released +#[patch.crates-io.stylus-sdk] +#git = "https://github.com/qalisander/stylus-sdk-rs" +#branch = "fix-encoding-in-sol-interface" +# +#[patch.crates-io.stylus-proc] +#git = "https://github.com/qalisander/stylus-sdk-rs" +#branch = "fix-encoding-in-sol-interface" + [patch.crates-io.stylus-sdk] -git = "https://github.com/qalisander/stylus-sdk-rs" -branch = "fix-encoding-in-sol-interface" +path = "../stylus-sdk-rs/stylus-sdk" [patch.crates-io.stylus-proc] -git = "https://github.com/qalisander/stylus-sdk-rs" -branch = "fix-encoding-in-sol-interface" +path = "../stylus-sdk-rs/stylus-proc" diff --git a/contracts/src/utils/context.rs b/contracts/src/utils/context.rs index 9f66d44b5..ca442d36a 100644 --- a/contracts/src/utils/context.rs +++ b/contracts/src/utils/context.rs @@ -5,9 +5,7 @@ use stylus_sdk::{alloy_primitives::Address, msg}; /// Returns the address of the message sender. #[cfg(test)] pub fn msg_sender() -> Address { - motsu::prelude::Context::current() - .get_msg_sender() - .expect("msg_sender should be set") + msg::sender() } /// Returns the address of the message sender. diff --git a/lib/motsu/Cargo.toml b/lib/motsu/Cargo.toml index 2376089a2..d3110fbb9 100644 --- a/lib/motsu/Cargo.toml +++ b/lib/motsu/Cargo.toml @@ -12,7 +12,7 @@ version = "0.2.0" const-hex.workspace = true once_cell.workspace = true tiny-keccak.workspace = true -stylus-sdk.workspace = true +stylus-sdk = { version = "0.7.0-beta.1", default-features = false } motsu-proc.workspace = true dashmap.workspace = true alloy-primitives = { workspace = true, features = ["arbitrary", "rand"] } diff --git a/lib/motsu/src/context.rs b/lib/motsu/src/context.rs index 631c76e8c..790517a54 100644 --- a/lib/motsu/src/context.rs +++ b/lib/motsu/src/context.rs @@ -185,7 +185,9 @@ impl Context { } fn set_return_data(&self, data: Vec) { - let _ = self.get_call_storage().call_output.insert(data); + let mut call_storage = self.get_call_storage(); + let _ = call_storage.call_output_len.insert(data.len()); + let _ = call_storage.call_output.insert(data); } pub(crate) unsafe fn read_return_data_raw( @@ -198,6 +200,13 @@ impl Context { data.len() } + pub(crate) fn get_return_data_size(&self) -> usize { + self.get_call_storage() + .call_output_len + .take() + .expect("call_output_len should be set") + } + fn get_return_data(&self) -> Vec { self.get_call_storage() .call_output @@ -295,6 +304,8 @@ struct CallStorage { contract_router: HashMap>>, // Output of a contract call. call_output: Option>, + // Output length of a contract call. + call_output_len: Option, } /// A trait for routing messages to the appropriate selector in tests. diff --git a/lib/motsu/src/lib.rs b/lib/motsu/src/lib.rs index 317b60f9a..81afb4198 100644 --- a/lib/motsu/src/lib.rs +++ b/lib/motsu/src/lib.rs @@ -58,18 +58,11 @@ mod tests { use stylus_sdk::{ alloy_primitives::{Address, U256}, call::Call, + msg, prelude::{public, sol_storage, StorageType, TopLevelStorage}, }; - use crate::context::{Account, Contract, TestRouter}; - - /// Message sender that mocks `msg::sender()` in tests. - #[must_use] - pub fn msg_sender() -> Address { - crate::prelude::Context::current() - .get_msg_sender() - .expect("msg_sender should be set") - } + use crate::context::{Account, Contract}; sol_storage! { pub struct PingContract { @@ -81,14 +74,14 @@ mod tests { #[public] impl PingContract { fn ping(&mut self, to: Address, value: U256) -> Result> { - let receiver = receiver::PongContract::new(to); + let receiver = IPongContract::new(to); let call = Call::new_in(self); let value = receiver.pong(call, value).expect("should pong successfully"); let pings_count = self._pings_count.get(); self._pings_count.set(pings_count + uint!(1_U256)); - self._pinged_from.set(msg_sender()); + self._pinged_from.set(msg::sender()); Ok(value) } @@ -103,13 +96,10 @@ mod tests { unsafe impl TopLevelStorage for PingContract {} - mod receiver { - use super::alloc; - stylus_sdk::stylus_proc::sol_interface! { - interface PongContract { - #[allow(missing_docs)] - function pong(uint256 value) external returns (uint256); - } + stylus_sdk::stylus_proc::sol_interface! { + interface IPongContract { + #[allow(missing_docs)] + function pong(uint256 value) external returns (uint256); } } @@ -125,7 +115,7 @@ mod tests { pub fn pong(&mut self, value: U256) -> Result> { let pongs_count = self._pongs_count.get(); self._pongs_count.set(pongs_count + uint!(1_U256)); - self._ponged_from.set(msg_sender()); + self._ponged_from.set(msg::sender()); Ok(value + uint!(1_U256)) } @@ -143,9 +133,7 @@ mod tests { #[test] fn ping_pong_works() { let mut ping = Contract::::default(); - let ping = &mut ping; let mut pong = Contract::::default(); - let pong = &mut pong; let alice = Account::random(); diff --git a/lib/motsu/src/shims.rs b/lib/motsu/src/shims.rs index d7105c086..a83afc4e3 100644 --- a/lib/motsu/src/shims.rs +++ b/lib/motsu/src/shims.rs @@ -244,10 +244,7 @@ pub unsafe extern "C" fn account_codehash(address: *const u8, dest: *mut u8) { /// [`RETURN_DATA_SIZE`]: https://www.evm.codes/#3d #[no_mangle] pub unsafe extern "C" fn return_data_size() -> usize { - // TODO: #156 - // No-op: we do not use this function in our unit-tests, - // but the binary does include it. - 0 + Context::current().get_return_data_size() } /// Copies the bytes of the last EVM call or deployment return result. From 0b3137010e417d65764ae97e0ce9b2c28ccc2726 Mon Sep 17 00:00:00 2001 From: Alisander Qoshqosh Date: Thu, 12 Dec 2024 03:56:24 +0400 Subject: [PATCH 050/109] remove context msg_sender --- Cargo.toml | 2 +- contracts/Cargo.toml | 3 ++- contracts/src/token/erc721/mod.rs | 16 +++++++--------- contracts/src/utils/context.rs | 15 --------------- contracts/src/utils/mod.rs | 1 - lib/motsu/Cargo.toml | 2 +- 6 files changed, 11 insertions(+), 28 deletions(-) delete mode 100644 contracts/src/utils/context.rs diff --git a/Cargo.toml b/Cargo.toml index 95446d178..64a632085 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -72,7 +72,7 @@ all = "warn" [workspace.dependencies] # Stylus SDK related -stylus-sdk = "0.7.0-beta.1" +stylus-sdk = { version = "0.7.0-beta.1", default-features = false } alloy = { version = "=0.7.2", features = [ "contract", diff --git a/contracts/Cargo.toml b/contracts/Cargo.toml index e305a5de9..a307f13ce 100644 --- a/contracts/Cargo.toml +++ b/contracts/Cargo.toml @@ -14,7 +14,7 @@ alloy-sol-types.workspace = true alloy-sol-macro.workspace = true alloy-sol-macro-expander.workspace = true alloy-sol-macro-input.workspace = true -stylus-sdk.workspace = true +stylus-sdk = { workspace = true, default-features = true } keccak-const.workspace = true openzeppelin-stylus-proc.workspace = true @@ -22,6 +22,7 @@ openzeppelin-stylus-proc.workspace = true alloy-primitives = { workspace = true, features = ["arbitrary"] } motsu.workspace = true rand.workspace = true +stylus-sdk.workspace = true [features] # Enables using the standard library. This is not included in the default diff --git a/contracts/src/token/erc721/mod.rs b/contracts/src/token/erc721/mod.rs index adfc6baf6..6ce105031 100644 --- a/contracts/src/token/erc721/mod.rs +++ b/contracts/src/token/erc721/mod.rs @@ -8,11 +8,9 @@ use stylus_sdk::{ call::{self, Call, MethodError}, evm, function_selector, msg, prelude::*, - stylus_proc::sol_interface, }; use crate::utils::{ - context::msg_sender, introspection::erc165::{Erc165, IErc165}, math::storage::{AddAssignUnchecked, SubAssignUnchecked}, }; @@ -505,7 +503,7 @@ impl IErc721 for Erc721 { data: Bytes, ) -> Result<(), Error> { self.transfer_from(from, to, token_id)?; - self._check_on_erc721_received(msg_sender(), from, to, token_id, &data) + self._check_on_erc721_received(msg::sender(), from, to, token_id, &data) } fn transfer_from( @@ -523,7 +521,7 @@ impl IErc721 for Erc721 { // Setting an "auth" argument enables the `_is_authorized` check which // verifies that the token exists (`from != 0`). Therefore, it is // not needed to verify that the return value is not 0 here. - let previous_owner = self._update(to, token_id, msg_sender())?; + let previous_owner = self._update(to, token_id, msg::sender())?; if previous_owner != from { return Err(ERC721IncorrectOwner { sender: from, @@ -536,7 +534,7 @@ impl IErc721 for Erc721 { } fn approve(&mut self, to: Address, token_id: U256) -> Result<(), Error> { - self._approve(to, token_id, msg_sender(), true) + self._approve(to, token_id, msg::sender(), true) } fn set_approval_for_all( @@ -544,7 +542,7 @@ impl IErc721 for Erc721 { operator: Address, approved: bool, ) -> Result<(), Error> { - self._set_approval_for_all(msg_sender(), operator, approved) + self._set_approval_for_all(msg::sender(), operator, approved) } fn get_approved(&self, token_id: U256) -> Result { @@ -825,7 +823,7 @@ impl Erc721 { ) -> Result<(), Error> { self._mint(to, token_id)?; self._check_on_erc721_received( - msg_sender(), + msg::sender(), Address::ZERO, to, token_id, @@ -970,7 +968,7 @@ impl Erc721 { data: &Bytes, ) -> Result<(), Error> { self._transfer(from, to, token_id)?; - self._check_on_erc721_received(msg_sender(), from, to, token_id, data) + self._check_on_erc721_received(msg::sender(), from, to, token_id, data) } /// Approve `to` to operate on `token_id`. @@ -1088,7 +1086,7 @@ impl Erc721 { /// Performs an acceptance check for the provided `operator` by calling /// [`IERC721Receiver::on_erc_721_received`] on the `to` address. The /// `operator` is generally the address that initiated the token transfer - /// (i.e. `msg_sender()`). + /// (i.e. `msg::sender()`). /// /// The acceptance call is not executed and treated as a no-op if the /// target address doesn't contain code (i.e. an EOA). Otherwise, the diff --git a/contracts/src/utils/context.rs b/contracts/src/utils/context.rs deleted file mode 100644 index ca442d36a..000000000 --- a/contracts/src/utils/context.rs +++ /dev/null @@ -1,15 +0,0 @@ -//! Context functions used for mocking unit tests. - -use stylus_sdk::{alloy_primitives::Address, msg}; - -/// Returns the address of the message sender. -#[cfg(test)] -pub fn msg_sender() -> Address { - msg::sender() -} - -/// Returns the address of the message sender. -#[cfg(not(test))] -pub fn msg_sender() -> Address { - msg::sender() -} diff --git a/contracts/src/utils/mod.rs b/contracts/src/utils/mod.rs index 4746849b1..b8f56cef7 100644 --- a/contracts/src/utils/mod.rs +++ b/contracts/src/utils/mod.rs @@ -1,5 +1,4 @@ //! Common Smart Contracts utilities. -pub mod context; pub mod cryptography; pub mod introspection; pub mod math; diff --git a/lib/motsu/Cargo.toml b/lib/motsu/Cargo.toml index d3110fbb9..2376089a2 100644 --- a/lib/motsu/Cargo.toml +++ b/lib/motsu/Cargo.toml @@ -12,7 +12,7 @@ version = "0.2.0" const-hex.workspace = true once_cell.workspace = true tiny-keccak.workspace = true -stylus-sdk = { version = "0.7.0-beta.1", default-features = false } +stylus-sdk.workspace = true motsu-proc.workspace = true dashmap.workspace = true alloy-primitives = { workspace = true, features = ["arbitrary", "rand"] } From b6898fc72d7c4563a08c9c678b5394332ac53854 Mon Sep 17 00:00:00 2001 From: Alisander Qoshqosh Date: Fri, 13 Dec 2024 20:20:02 +0400 Subject: [PATCH 051/109] post merge fix --- contracts/src/access/control.rs | 10 +++++----- contracts/src/finance/vesting_wallet.rs | 2 +- contracts/src/token/erc1155/mod.rs | 2 +- contracts/src/token/erc721/mod.rs | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/contracts/src/access/control.rs b/contracts/src/access/control.rs index 1126461bb..cc50f3d83 100644 --- a/contracts/src/access/control.rs +++ b/contracts/src/access/control.rs @@ -43,8 +43,8 @@ //! this role. use alloc::vec::Vec; -use alloy_primitives::{Address, B256}; -use alloy_sol_types::sol; +use alloy_primitives::{Address, FixedBytes, B256}; +use sol::*; use stylus_sdk::{ evm, msg, prelude::storage, @@ -126,9 +126,6 @@ pub struct AccessControl { #[public] impl AccessControl { - /// The default admin role. `[0; 32]` by default. - pub const DEFAULT_ADMIN_ROLE: [u8; 32] = [0; 32]; - /// Returns `true` if `account` has been granted `role`. /// /// # Arguments @@ -280,6 +277,9 @@ impl AccessControl { } impl AccessControl { + /// The default admin role. `[0; 32]` by default. + pub const DEFAULT_ADMIN_ROLE: [u8; 32] = [0; 32]; + /// Sets `admin_role` as `role`'s admin role. /// /// # Arguments diff --git a/contracts/src/finance/vesting_wallet.rs b/contracts/src/finance/vesting_wallet.rs index 9efc36acf..8265141bd 100644 --- a/contracts/src/finance/vesting_wallet.rs +++ b/contracts/src/finance/vesting_wallet.rs @@ -34,7 +34,7 @@ use stylus_sdk::{ block, call::{self, call, Call}, contract, evm, function_selector, - prelude::storage, + prelude::{sol_interface, storage}, storage::{StorageMap, StorageU256, StorageU64}, stylus_proc::{public, SolidityError}, }; diff --git a/contracts/src/token/erc1155/mod.rs b/contracts/src/token/erc1155/mod.rs index 52b7929bf..389148b2d 100644 --- a/contracts/src/token/erc1155/mod.rs +++ b/contracts/src/token/erc1155/mod.rs @@ -7,7 +7,7 @@ use stylus_sdk::{ abi::Bytes, call::{self, Call, MethodError}, evm, function_selector, msg, - prelude::{public, storage, AddressVM, SolidityError}, + prelude::{public, sol_interface, storage, AddressVM, SolidityError}, storage::{StorageBool, StorageMap, StorageU256}, }; diff --git a/contracts/src/token/erc721/mod.rs b/contracts/src/token/erc721/mod.rs index a7c402139..6e57f511e 100644 --- a/contracts/src/token/erc721/mod.rs +++ b/contracts/src/token/erc721/mod.rs @@ -1,5 +1,5 @@ //! Implementation of the [`Erc721`] token standard. -use alloc::vec; +use alloc::{vec, vec::Vec}; use alloy_primitives::{uint, Address, FixedBytes, U128, U256}; use openzeppelin_stylus_proc::interface_id; From a16de97459369e3d453512461096c2873cb5e5b5 Mon Sep 17 00:00:00 2001 From: Alisander Qoshqosh Date: Fri, 13 Dec 2024 20:24:44 +0400 Subject: [PATCH 052/109] ++ --- contracts/src/utils/pausable.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/contracts/src/utils/pausable.rs b/contracts/src/utils/pausable.rs index 507a13c0f..3ff800dee 100644 --- a/contracts/src/utils/pausable.rs +++ b/contracts/src/utils/pausable.rs @@ -16,7 +16,6 @@ use alloc::vec::Vec; -use alloy_sol_types::sol; pub use sol::*; use stylus_sdk::{ evm, msg, From acd843af700cc4d1cc36796d6be892b486041632 Mon Sep 17 00:00:00 2001 From: Alisander Qoshqosh Date: Fri, 13 Dec 2024 20:25:43 +0400 Subject: [PATCH 053/109] ++ --- contracts/src/access/control.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contracts/src/access/control.rs b/contracts/src/access/control.rs index cc50f3d83..b14199ae5 100644 --- a/contracts/src/access/control.rs +++ b/contracts/src/access/control.rs @@ -44,7 +44,7 @@ use alloc::vec::Vec; use alloy_primitives::{Address, FixedBytes, B256}; -use sol::*; +pub use sol::*; use stylus_sdk::{ evm, msg, prelude::storage, From 9a84c149174fdbbd928ec6da01bec91be47eb73f Mon Sep 17 00:00:00 2001 From: Alisander Qoshqosh Date: Fri, 13 Dec 2024 21:00:00 +0400 Subject: [PATCH 054/109] post merge fix --- contracts/src/token/erc721/mod.rs | 1 + lib/motsu-proc/src/test.rs | 5 ++--- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/contracts/src/token/erc721/mod.rs b/contracts/src/token/erc721/mod.rs index d5c62cea4..a36196edd 100644 --- a/contracts/src/token/erc721/mod.rs +++ b/contracts/src/token/erc721/mod.rs @@ -2540,6 +2540,7 @@ mod tests { } unsafe impl TopLevelStorage for Erc721ReceiverMock {} + unsafe impl TopLevelStorage for Erc721 {} #[motsu::test] fn on_erc721_received( diff --git a/lib/motsu-proc/src/test.rs b/lib/motsu-proc/src/test.rs index 145848c8c..8036c96a2 100644 --- a/lib/motsu-proc/src/test.rs +++ b/lib/motsu-proc/src/test.rs @@ -37,7 +37,7 @@ pub(crate) fn test(_attr: &TokenStream, input: TokenStream) -> TokenStream { // Test case assumes, that contract's variable has `&mut` reference // to contract's type. quote! { - #arg_binding: &mut #contract_ty + #arg_binding: #contract_ty } }); @@ -45,7 +45,7 @@ pub(crate) fn test(_attr: &TokenStream, input: TokenStream) -> TokenStream { arg_binding_and_ty.iter().map(|(_arg_binding, contract_ty)| { // Pass mutable reference to the contract. quote! { - &mut <#contract_ty>::default() + <#contract_ty>::default() } }); @@ -56,7 +56,6 @@ pub(crate) fn test(_attr: &TokenStream, input: TokenStream) -> TokenStream { #( #attrs )* #[test] fn #fn_name() #fn_return_type { - use ::motsu::prelude::DefaultStorage; let test = | #( #contract_arg_defs ),* | #fn_block; let res = test( #( #contract_args ),* ); ::motsu::prelude::Context::current().reset_storage(); From ed41209cdc362a10d1d6dd45c3d9cae16f7928d4 Mon Sep 17 00:00:00 2001 From: Alisander Qoshqosh Date: Wed, 18 Dec 2024 10:51:03 +0400 Subject: [PATCH 055/109] alloy-primitives 0.8.14 -> 0.8.13 --- Cargo.lock | 30 +++++++++++++++--------------- Cargo.toml | 10 +++++----- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 18691b716..8f7a2d15f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -247,9 +247,9 @@ dependencies = [ [[package]] name = "alloy-json-abi" -version = "0.8.14" +version = "0.8.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac4b22b3e51cac09fd2adfcc73b55f447b4df669f983c13f7894ec82b607c63f" +checksum = "1a500037938085feed8a20dbfc8fce58c599db68c948cfae711147175dee392c" dependencies = [ "alloy-primitives", "alloy-sol-type-parser", @@ -311,9 +311,9 @@ dependencies = [ [[package]] name = "alloy-primitives" -version = "0.8.14" +version = "0.8.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9db948902dfbae96a73c2fbf1f7abec62af034ab883e4c777c3fd29702bd6e2c" +checksum = "3aeeb5825c2fc8c2662167058347cd0cafc3cb15bcb5cdb1758a63c2dca0409e" dependencies = [ "alloy-rlp", "arbitrary", @@ -511,9 +511,9 @@ dependencies = [ [[package]] name = "alloy-sol-macro" -version = "0.8.14" +version = "0.8.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3bfd7853b65a2b4f49629ec975fee274faf6dff15ab8894c620943398ef283c0" +checksum = "5c0279d09463a4695788a3622fd95443625f7be307422deba4b55dd491a9c7a1" dependencies = [ "alloy-sol-macro-expander", "alloy-sol-macro-input", @@ -525,9 +525,9 @@ dependencies = [ [[package]] name = "alloy-sol-macro-expander" -version = "0.8.14" +version = "0.8.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "82ec42f342d9a9261699f8078e57a7a4fda8aaa73c1a212ed3987080e6a9cd13" +checksum = "4feea540fc8233df2ad1156efd744b2075372f43a8f942a68b3b19c8a00e2c12" dependencies = [ "alloy-json-abi", "alloy-sol-macro-input", @@ -544,9 +544,9 @@ dependencies = [ [[package]] name = "alloy-sol-macro-input" -version = "0.8.14" +version = "0.8.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed2c50e6a62ee2b4f7ab3c6d0366e5770a21cad426e109c2f40335a1b3aff3df" +checksum = "2a0ad281f3d1b613af814b66977ee698e443d4644a1510962d0241f26e0e53ae" dependencies = [ "alloy-json-abi", "const-hex", @@ -571,9 +571,9 @@ dependencies = [ [[package]] name = "alloy-sol-types" -version = "0.8.14" +version = "0.8.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c9dc0fffe397aa17628160e16b89f704098bf3c9d74d5d369ebc239575936de5" +checksum = "cff34e0682d6665da243a3e81da96f07a2dd50f7e64073e382b1a141f5a2a2f6" dependencies = [ "alloy-json-abi", "alloy-primitives", @@ -2514,7 +2514,7 @@ checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" [[package]] name = "mini-alloc" -version = "0.7.0-beta.1" +version = "0.7.0-rc.1" dependencies = [ "cfg-if", ] @@ -3743,7 +3743,7 @@ dependencies = [ [[package]] name = "stylus-proc" -version = "0.7.0-beta.1" +version = "0.7.0-rc.1" dependencies = [ "alloy-primitives", "alloy-sol-types", @@ -3762,7 +3762,7 @@ dependencies = [ [[package]] name = "stylus-sdk" -version = "0.7.0-beta.1" +version = "0.7.0-rc.1" dependencies = [ "alloy-primitives", "alloy-sol-types", diff --git a/Cargo.toml b/Cargo.toml index 01e12ee23..cd2bf3cf1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -88,11 +88,11 @@ alloy = { version = "=0.7.2", features = [ # Even though `alloy` includes `alloy-primitives` and `alloy-sol-types` we need # to keep both versions for compatibility with the Stylus SDK. Once they start # using `alloy` we can remove these. -alloy-primitives = { version = "=0.8.14", default-features = false } -alloy-sol-types = { version = "=0.8.14", default-features = false } -alloy-sol-macro = { version = "=0.8.14", default-features = false } -alloy-sol-macro-expander = { version = "=0.8.14", default-features = false } -alloy-sol-macro-input = { version = "=0.8.14", default-features = false } +alloy-primitives = { version = "=0.8.13", default-features = false } +alloy-sol-types = { version = "=0.8.13", default-features = false } +alloy-sol-macro = { version = "=0.8.13", default-features = false } +alloy-sol-macro-expander = { version = "=0.8.13", default-features = false } +alloy-sol-macro-input = { version = "=0.8.13", default-features = false } const-hex = { version = "1.11.1", default-features = false } eyre = "0.6.8" From 780c6ec0e9147d2d21f8d55b50d0b94484d4b92b Mon Sep 17 00:00:00 2001 From: Alisander Qoshqosh Date: Mon, 23 Dec 2024 22:12:41 +0400 Subject: [PATCH 056/109] ++ --- Cargo.lock | 27 +++++++++++++++------------ Cargo.toml | 26 ++++++++++---------------- 2 files changed, 25 insertions(+), 28 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 8f7a2d15f..2ce59e36a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -247,9 +247,9 @@ dependencies = [ [[package]] name = "alloy-json-abi" -version = "0.8.13" +version = "0.8.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a500037938085feed8a20dbfc8fce58c599db68c948cfae711147175dee392c" +checksum = "ac4b22b3e51cac09fd2adfcc73b55f447b4df669f983c13f7894ec82b607c63f" dependencies = [ "alloy-primitives", "alloy-sol-type-parser", @@ -311,9 +311,9 @@ dependencies = [ [[package]] name = "alloy-primitives" -version = "0.8.13" +version = "0.8.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3aeeb5825c2fc8c2662167058347cd0cafc3cb15bcb5cdb1758a63c2dca0409e" +checksum = "9db948902dfbae96a73c2fbf1f7abec62af034ab883e4c777c3fd29702bd6e2c" dependencies = [ "alloy-rlp", "arbitrary", @@ -511,9 +511,9 @@ dependencies = [ [[package]] name = "alloy-sol-macro" -version = "0.8.13" +version = "0.8.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c0279d09463a4695788a3622fd95443625f7be307422deba4b55dd491a9c7a1" +checksum = "3bfd7853b65a2b4f49629ec975fee274faf6dff15ab8894c620943398ef283c0" dependencies = [ "alloy-sol-macro-expander", "alloy-sol-macro-input", @@ -525,9 +525,9 @@ dependencies = [ [[package]] name = "alloy-sol-macro-expander" -version = "0.8.13" +version = "0.8.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4feea540fc8233df2ad1156efd744b2075372f43a8f942a68b3b19c8a00e2c12" +checksum = "82ec42f342d9a9261699f8078e57a7a4fda8aaa73c1a212ed3987080e6a9cd13" dependencies = [ "alloy-json-abi", "alloy-sol-macro-input", @@ -544,9 +544,9 @@ dependencies = [ [[package]] name = "alloy-sol-macro-input" -version = "0.8.13" +version = "0.8.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a0ad281f3d1b613af814b66977ee698e443d4644a1510962d0241f26e0e53ae" +checksum = "ed2c50e6a62ee2b4f7ab3c6d0366e5770a21cad426e109c2f40335a1b3aff3df" dependencies = [ "alloy-json-abi", "const-hex", @@ -571,9 +571,9 @@ dependencies = [ [[package]] name = "alloy-sol-types" -version = "0.8.13" +version = "0.8.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cff34e0682d6665da243a3e81da96f07a2dd50f7e64073e382b1a141f5a2a2f6" +checksum = "c9dc0fffe397aa17628160e16b89f704098bf3c9d74d5d369ebc239575936de5" dependencies = [ "alloy-json-abi", "alloy-primitives", @@ -2515,6 +2515,7 @@ checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" [[package]] name = "mini-alloc" version = "0.7.0-rc.1" +source = "git+https://github.com/OffchainLabs/stylus-sdk-rs?branch=rel%2F0.7.0-rc.1#c2698e7bedb8340fa11caf55ee9332a3a53e5574" dependencies = [ "cfg-if", ] @@ -3744,6 +3745,7 @@ dependencies = [ [[package]] name = "stylus-proc" version = "0.7.0-rc.1" +source = "git+https://github.com/OffchainLabs/stylus-sdk-rs?branch=rel%2F0.7.0-rc.1#c2698e7bedb8340fa11caf55ee9332a3a53e5574" dependencies = [ "alloy-primitives", "alloy-sol-types", @@ -3763,6 +3765,7 @@ dependencies = [ [[package]] name = "stylus-sdk" version = "0.7.0-rc.1" +source = "git+https://github.com/OffchainLabs/stylus-sdk-rs?branch=rel%2F0.7.0-rc.1#c2698e7bedb8340fa11caf55ee9332a3a53e5574" dependencies = [ "alloy-primitives", "alloy-sol-types", diff --git a/Cargo.toml b/Cargo.toml index cd2bf3cf1..51fc0a156 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -73,7 +73,7 @@ all = "warn" [workspace.dependencies] # Stylus SDK related -stylus-sdk = { version = "0.7.0-beta.1", default-features = false } +stylus-sdk = { version = "0.7.0-rc.1", default-features = false } alloy = { version = "=0.7.2", features = [ "contract", @@ -88,11 +88,11 @@ alloy = { version = "=0.7.2", features = [ # Even though `alloy` includes `alloy-primitives` and `alloy-sol-types` we need # to keep both versions for compatibility with the Stylus SDK. Once they start # using `alloy` we can remove these. -alloy-primitives = { version = "=0.8.13", default-features = false } -alloy-sol-types = { version = "=0.8.13", default-features = false } -alloy-sol-macro = { version = "=0.8.13", default-features = false } -alloy-sol-macro-expander = { version = "=0.8.13", default-features = false } -alloy-sol-macro-input = { version = "=0.8.13", default-features = false } +alloy-primitives = { version = "=0.8.14", default-features = false } +alloy-sol-types = { version = "=0.8.14", default-features = false } +alloy-sol-macro = { version = "=0.8.14", default-features = false } +alloy-sol-macro-expander = { version = "=0.8.14", default-features = false } +alloy-sol-macro-input = { version = "=0.8.14", default-features = false } const-hex = { version = "1.11.1", default-features = false } eyre = "0.6.8" @@ -150,16 +150,10 @@ default = { extend-ignore-identifiers-re = [ files = { extend-exclude = [] } ## TODO#q: remove this once the fix is released -#[patch.crates-io.stylus-sdk] -#git = "https://github.com/qalisander/stylus-sdk-rs" -#branch = "fix-encoding-in-sol-interface" -# -#[patch.crates-io.stylus-proc] -#git = "https://github.com/qalisander/stylus-sdk-rs" -#branch = "fix-encoding-in-sol-interface" - [patch.crates-io.stylus-sdk] -path = "../stylus-sdk-rs/stylus-sdk" +git = "https://github.com/OffchainLabs/stylus-sdk-rs" +branch = "rel/0.7.0-rc.1" [patch.crates-io.stylus-proc] -path = "../stylus-sdk-rs/stylus-proc" +git = "https://github.com/OffchainLabs/stylus-sdk-rs" +branch = "rel/0.7.0-rc.1" From 297b574e29b2ab41add434c0f76823b778fd108b Mon Sep 17 00:00:00 2001 From: Alisander Qoshqosh Date: Mon, 23 Dec 2024 23:24:52 +0400 Subject: [PATCH 057/109] patch motsu --- Cargo.lock | 50 ++++++++++++------------- Cargo.toml | 7 +++- contracts/src/finance/vesting_wallet.rs | 2 +- contracts/src/token/erc1155/mod.rs | 2 +- contracts/src/token/erc721/mod.rs | 1 - 5 files changed, 32 insertions(+), 30 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2ce59e36a..0459477be 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,7 +4,7 @@ version = 4 [[package]] name = "access-control-example" -version = "0.2.0-alpha.1" +version = "0.2.0-alpha.2" dependencies = [ "alloy", "alloy-primitives", @@ -902,7 +902,7 @@ checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" [[package]] name = "basic-example" -version = "0.2.0-alpha.1" +version = "0.2.0-alpha.2" dependencies = [ "alloy-primitives", "openzeppelin-stylus", @@ -911,7 +911,7 @@ dependencies = [ [[package]] name = "basic-example-script" -version = "0.2.0-alpha.1" +version = "0.2.0-alpha.2" dependencies = [ "alloy", "alloy-primitives", @@ -922,7 +922,7 @@ dependencies = [ [[package]] name = "benches" -version = "0.2.0-alpha.1" +version = "0.2.0-alpha.2" dependencies = [ "alloy", "alloy-primitives", @@ -1358,7 +1358,7 @@ dependencies = [ [[package]] name = "cryptography-example" -version = "0.2.0-alpha.1" +version = "0.2.0-alpha.2" dependencies = [ "alloy", "alloy-primitives", @@ -1662,7 +1662,7 @@ checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" [[package]] name = "erc1155-example" -version = "0.2.0-alpha.1" +version = "0.2.0-alpha.2" dependencies = [ "alloy", "alloy-primitives", @@ -1675,7 +1675,7 @@ dependencies = [ [[package]] name = "erc1155-metadata-uri-example" -version = "0.2.0-alpha.1" +version = "0.2.0-alpha.2" dependencies = [ "alloy", "alloy-primitives", @@ -1688,7 +1688,7 @@ dependencies = [ [[package]] name = "erc1155-supply-example" -version = "0.2.0-alpha.1" +version = "0.2.0-alpha.2" dependencies = [ "alloy", "alloy-primitives", @@ -1701,7 +1701,7 @@ dependencies = [ [[package]] name = "erc20-example" -version = "0.2.0-alpha.1" +version = "0.2.0-alpha.2" dependencies = [ "alloy", "alloy-primitives", @@ -1714,7 +1714,7 @@ dependencies = [ [[package]] name = "erc20-permit-example" -version = "0.2.0-alpha.1" +version = "0.2.0-alpha.2" dependencies = [ "alloy", "alloy-primitives", @@ -1727,7 +1727,7 @@ dependencies = [ [[package]] name = "erc721-consecutive-example" -version = "0.2.0-alpha.1" +version = "0.2.0-alpha.2" dependencies = [ "alloy", "alloy-primitives", @@ -1742,7 +1742,7 @@ dependencies = [ [[package]] name = "erc721-example" -version = "0.2.0-alpha.1" +version = "0.2.0-alpha.2" dependencies = [ "alloy", "alloy-primitives", @@ -1756,7 +1756,7 @@ dependencies = [ [[package]] name = "erc721-metadata-example" -version = "0.2.0-alpha.1" +version = "0.2.0-alpha.2" dependencies = [ "alloy", "alloy-primitives", @@ -2498,7 +2498,7 @@ dependencies = [ [[package]] name = "merkle-proofs-example" -version = "0.2.0-alpha.1" +version = "0.2.0-alpha.2" dependencies = [ "alloy-primitives", "alloy-sol-types", @@ -2548,7 +2548,8 @@ checksum = "7843ec2de400bcbc6a6328c958dc38e5359da6e93e72e37bc5246bf1ae776389" [[package]] name = "motsu" -version = "0.2.0" +version = "0.2.1" +source = "git+https://github.com/OpenZeppelin/stylus-test-helpers?branch=unit-tests%2Fmultiple-contract-deployment#feb635a55d54463aa51d1c0a81d20903a6cbe99d" dependencies = [ "alloy-primitives", "alloy-sol-types", @@ -2562,14 +2563,11 @@ dependencies = [ [[package]] name = "motsu-proc" -version = "0.2.0" +version = "0.2.1" +source = "git+https://github.com/OpenZeppelin/stylus-test-helpers?branch=unit-tests%2Fmultiple-contract-deployment#feb635a55d54463aa51d1c0a81d20903a6cbe99d" dependencies = [ - "alloy-primitives", - "alloy-sol-types", - "motsu", "proc-macro2", "quote", - "stylus-sdk", "syn 2.0.89", ] @@ -2720,7 +2718,7 @@ dependencies = [ [[package]] name = "openzeppelin-crypto" -version = "0.2.0-alpha.1" +version = "0.2.0-alpha.2" dependencies = [ "crypto-bigint", "educe", @@ -2734,7 +2732,7 @@ dependencies = [ [[package]] name = "openzeppelin-stylus" -version = "0.2.0-alpha.1" +version = "0.2.0-alpha.2" dependencies = [ "alloy-primitives", "alloy-sol-macro", @@ -2760,7 +2758,7 @@ dependencies = [ [[package]] name = "ownable-example" -version = "0.2.0-alpha.1" +version = "0.2.0-alpha.2" dependencies = [ "alloy", "alloy-primitives", @@ -2773,7 +2771,7 @@ dependencies = [ [[package]] name = "ownable-two-step" -version = "0.2.0-alpha.1" +version = "0.2.0-alpha.2" dependencies = [ "alloy", "alloy-primitives", @@ -3417,7 +3415,7 @@ checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" [[package]] name = "safe-erc20-example" -version = "0.2.0-alpha.1" +version = "0.2.0-alpha.2" dependencies = [ "alloy", "alloy-primitives", @@ -4247,7 +4245,7 @@ checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" [[package]] name = "vesting-wallet-example" -version = "0.2.0-alpha.1" +version = "0.2.0-alpha.2" dependencies = [ "alloy", "alloy-primitives", diff --git a/Cargo.toml b/Cargo.toml index 87b1651a0..9a68b3532 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -148,7 +148,7 @@ default = { extend-ignore-identifiers-re = [ ] } files = { extend-exclude = [] } -## TODO#q: remove this once the fix is released +# TODO#q: remove stylus sdk patch once the fix is released [patch.crates-io.stylus-sdk] git = "https://github.com/OffchainLabs/stylus-sdk-rs" branch = "rel/0.7.0-rc.1" @@ -156,3 +156,8 @@ branch = "rel/0.7.0-rc.1" [patch.crates-io.stylus-proc] git = "https://github.com/OffchainLabs/stylus-sdk-rs" branch = "rel/0.7.0-rc.1" + +# TODO#q: remove motsu patch once update is released +[patch.crates-io.motsu] +git = "https://github.com/OpenZeppelin/stylus-test-helpers" +branch = "unit-tests/multiple-contract-deployment" diff --git a/contracts/src/finance/vesting_wallet.rs b/contracts/src/finance/vesting_wallet.rs index 44b7ef9d2..64da824a8 100644 --- a/contracts/src/finance/vesting_wallet.rs +++ b/contracts/src/finance/vesting_wallet.rs @@ -34,8 +34,8 @@ use stylus_sdk::{ block, call::{self, call, Call}, contract, evm, function_selector, - storage::{StorageMap, StorageU256, StorageU64, TopLevelStorage}, prelude::{sol_interface, storage}, + storage::{StorageMap, StorageU256, StorageU64, TopLevelStorage}, stylus_proc::{public, SolidityError}, }; diff --git a/contracts/src/token/erc1155/mod.rs b/contracts/src/token/erc1155/mod.rs index ac842287c..a8a7ab2e7 100644 --- a/contracts/src/token/erc1155/mod.rs +++ b/contracts/src/token/erc1155/mod.rs @@ -7,8 +7,8 @@ use stylus_sdk::{ abi::Bytes, call::{self, Call, MethodError}, evm, function_selector, msg, - storage::{StorageBool, StorageMap, StorageU256, TopLevelStorage}, prelude::{public, sol_interface, storage, AddressVM, SolidityError}, + storage::{StorageBool, StorageMap, StorageU256, TopLevelStorage}, }; use crate::utils::{ diff --git a/contracts/src/token/erc721/mod.rs b/contracts/src/token/erc721/mod.rs index dbe85c93d..7dd5d55de 100644 --- a/contracts/src/token/erc721/mod.rs +++ b/contracts/src/token/erc721/mod.rs @@ -2545,7 +2545,6 @@ mod tests { } unsafe impl TopLevelStorage for Erc721ReceiverMock {} - unsafe impl TopLevelStorage for Erc721 {} #[motsu::test] fn on_erc721_received( From 267289cdb489ebb7f4e02673287c2dd250f3d200 Mon Sep 17 00:00:00 2001 From: Alisander Qoshqosh Date: Tue, 31 Dec 2024 18:47:27 +0400 Subject: [PATCH 058/109] ++ --- contracts/src/token/erc721/mod.rs | 735 +++++++++++++++++++++--------- 1 file changed, 521 insertions(+), 214 deletions(-) diff --git a/contracts/src/token/erc721/mod.rs b/contracts/src/token/erc721/mod.rs index 7dd5d55de..4ff8031e1 100644 --- a/contracts/src/token/erc721/mod.rs +++ b/contracts/src/token/erc721/mod.rs @@ -1186,11 +1186,14 @@ mod tests { U256::from(num) } - /* #[motsu::test] - fn error_when_checking_balance_of_invalid_owner(contract: Erc721) { + fn error_when_checking_balance_of_invalid_owner( + contract: Contract, + ) { let invalid_owner = Address::ZERO; + let alice = Address::random(); let err = contract + .sender(alice) .balance_of(invalid_owner) .expect_err("should return `Error::InvalidOwner`"); assert!(matches!( @@ -1200,18 +1203,25 @@ mod tests { } #[motsu::test] - fn balance_of_zero_balance(contract: Erc721) { - let owner = msg::sender(); - let balance = - contract.balance_of(owner).expect("should return `U256::ZERO`"); + fn balance_of_zero_balance(contract: Contract) { + let owner = Address::random(); + + let balance = contract + .sender(owner) + .balance_of(owner) + .expect("should return `U256::ZERO`"); assert_eq!(U256::ZERO, balance); } #[motsu::test] - fn error_when_checking_owner_of_nonexistent_token(contract: Erc721) { + fn error_when_checking_owner_of_nonexistent_token( + contract: Contract, + ) { let token_id = random_token_id(); + let alice = Address::random(); let err = contract + .sender(alice) .owner_of(token_id) .expect_err("should return Error::NonexistentToken"); @@ -1224,21 +1234,28 @@ mod tests { } #[motsu::test] - fn mints(contract: Erc721) { - let alice = msg::sender(); + fn mints(contract: Contract) { + let alice = Address::random(); + let token_id = random_token_id(); let initial_balance = contract + .sender(alice) .balance_of(alice) .expect("should return the balance of Alice"); - contract._mint(alice, token_id).expect("should mint a token for Alice"); + contract + .sender(alice) + ._mint(alice, token_id) + .expect("should mint a token for Alice"); let owner = contract + .sender(alice) .owner_of(token_id) .expect("should return the owner of the token"); assert_eq!(owner, alice); let balance = contract + .sender(alice) .balance_of(alice) .expect("should return the balance of Alice"); @@ -1246,13 +1263,16 @@ mod tests { } #[motsu::test] - fn error_when_minting_token_id_twice(contract: Erc721) { - let alice = msg::sender(); + fn error_when_minting_token_id_twice(contract: Contract) { + let alice = Address::random(); + let token_id = random_token_id(); contract + .sender(alice) ._mint(alice, token_id) .expect("should mint the token a first time"); let err = contract + .sender(alice) ._mint(alice, token_id) .expect_err("should not mint a token with `token_id` twice"); @@ -1263,12 +1283,13 @@ mod tests { } #[motsu::test] - fn error_when_minting_token_invalid_receiver(contract: Erc721) { + fn error_when_minting_token_invalid_receiver(contract: Contract) { let invalid_receiver = Address::ZERO; - let token_id = random_token_id(); + let alice = Address::random(); let err = contract + .sender(alice) ._mint(invalid_receiver, token_id) .expect_err("should not mint a token for invalid receiver"); @@ -1281,24 +1302,28 @@ mod tests { } #[motsu::test] - fn safe_mints(contract: Erc721) { - let alice = msg::sender(); + fn safe_mints(contract: Contract) { + let alice = Address::random(); let token_id = random_token_id(); let initial_balance = contract + .sender(alice) .balance_of(alice) .expect("should return the balance of Alice"); contract + .sender(alice) ._safe_mint(alice, token_id, &vec![0, 1, 2, 3].into()) .expect("should mint a token for Alice"); let owner = contract + .sender(alice) .owner_of(token_id) .expect("should return the owner of the token"); assert_eq!(owner, alice); let balance = contract + .sender(alice) .balance_of(alice) .expect("should return the balance of Alice"); @@ -1306,14 +1331,16 @@ mod tests { } #[motsu::test] - fn error_when_safe_mint_token_id_twice(contract: Erc721) { - let alice = msg::sender(); + fn error_when_safe_mint_token_id_twice(contract: Contract) { + let alice = Address::random(); let token_id = random_token_id(); contract + .sender(alice) ._mint(alice, token_id) .expect("should mint the token a first time"); let err = contract + .sender(alice) ._safe_mint(alice, token_id, &vec![0, 1, 2, 3].into()) .expect_err("should not mint a token with `token_id` twice"); @@ -1324,12 +1351,14 @@ mod tests { } #[motsu::test] - fn error_when_safe_mint_invalid_receiver(contract: Erc721) { + fn error_when_safe_mint_invalid_receiver(contract: Contract) { + let alice = Address::random(); let invalid_receiver = Address::ZERO; let token_id = random_token_id(); let err = contract + .sender(alice) ._safe_mint(invalid_receiver, token_id, &vec![0, 1, 2, 3].into()) .expect_err("should not mint a token for invalid receiver"); @@ -1342,51 +1371,67 @@ mod tests { } #[motsu::test] - fn transfers_from(contract: Erc721) { - let alice = msg::sender(); + fn transfers_from(contract: Contract) { + let alice = Address::random(); let token_id = random_token_id(); - contract._mint(alice, token_id).expect("should mint a token to Alice"); contract + .sender(alice) + ._mint(alice, token_id) + .expect("should mint a token to Alice"); + contract + .sender(alice) .transfer_from(alice, BOB, token_id) .expect("should transfer a token from Alice to Bob"); let owner = contract + .sender(alice) .owner_of(token_id) .expect("should return the owner of the token"); assert_eq!(owner, BOB); } #[motsu::test] - fn transfers_from_approved_token(contract: Erc721) { - let alice = msg::sender(); + fn transfers_from_approved_token(contract: Contract) { + let alice = Address::random(); let token_id = random_token_id(); - contract._mint(BOB, token_id).expect("should mint token to Bob"); + contract + .sender(alice) + ._mint(BOB, token_id) + .expect("should mint token to Bob"); contract._token_approvals.setter(token_id).set(alice); contract + .sender(alice) .transfer_from(BOB, alice, token_id) .expect("should transfer Bob's token to Alice"); let owner = contract + .sender(alice) .owner_of(token_id) .expect("should return the owner of the token"); assert_eq!(owner, alice); } #[motsu::test] - fn transfers_from_approved_for_all(contract: Erc721) { - let alice = msg::sender(); + fn transfers_from_approved_for_all(contract: Contract) { + let alice = Address::random(); let token_id = random_token_id(); - contract._mint(BOB, token_id).expect("should mint token to Bob"); + contract + .sender(alice) + ._mint(BOB, token_id) + .expect("should mint token to Bob"); // As we cannot change `msg::sender`, we need to use this workaround. contract._operator_approvals.setter(BOB).setter(alice).set(true); - let approved_for_all = contract.is_approved_for_all(BOB, alice); + let approved_for_all = + contract.sender(alice).is_approved_for_all(BOB, alice); assert!(approved_for_all); contract + .sender(alice) .transfer_from(BOB, alice, token_id) .expect("should transfer Bob's token to Alice"); let owner = contract + .sender(alice) .owner_of(token_id) .expect("should return the owner of the token"); assert_eq!(owner, alice); @@ -1394,15 +1439,19 @@ mod tests { #[motsu::test] fn error_when_transfer_from_transfers_to_invalid_receiver( - contract: Erc721, + contract: Contract, ) { - let alice = msg::sender(); + let alice = Address::random(); let token_id = random_token_id(); let invalid_receiver = Address::ZERO; - contract._mint(alice, token_id).expect("should mint a token to Alice"); + contract + .sender(alice) + ._mint(alice, token_id) + .expect("should mint a token to Alice"); let err = contract + .sender(alice) .transfer_from(alice, invalid_receiver, token_id) .expect_err("should not transfer the token to invalid receiver"); @@ -1414,6 +1463,7 @@ mod tests { )); let owner = contract + .sender(alice) .owner_of(token_id) .expect("should return the owner of the token"); assert_eq!(alice, owner); @@ -1421,14 +1471,18 @@ mod tests { #[motsu::test] fn error_when_transfer_from_transfers_from_incorrect_owner( - contract: Erc721, + contract: Contract, ) { - let alice = msg::sender(); + let alice = Address::random(); let token_id = random_token_id(); - contract._mint(alice, token_id).expect("should mint a token to Alice"); + contract + .sender(alice) + ._mint(alice, token_id) + .expect("should mint a token to Alice"); let err = contract + .sender(alice) .transfer_from(DAVE, BOB, token_id) .expect_err("should not transfer the token from incorrect owner"); assert!(matches!( @@ -1449,12 +1503,16 @@ mod tests { #[motsu::test] fn error_when_transfer_from_transfers_with_insufficient_approval( - contract: Erc721, + contract: Contract, ) { - let alice = msg::sender(); + let alice = Address::random(); let token_id = random_token_id(); - contract._mint(BOB, token_id).expect("should mint token to Bob"); + contract + .sender(alice) + ._mint(BOB, token_id) + .expect("should mint token to Bob"); let err = contract + .sender(alice) .transfer_from(BOB, alice, token_id) .expect_err("should not transfer unapproved token"); assert!(matches!( @@ -1467,10 +1525,13 @@ mod tests { } #[motsu::test] - fn error_when_transfer_from_transfers_nonexistent_token(contract: Erc721) { - let alice = msg::sender(); + fn error_when_transfer_from_transfers_nonexistent_token( + contract: Contract, + ) { + let alice = Address::random(); let token_id = random_token_id(); let err = contract + .sender(alice) .transfer_from(alice, BOB, token_id) .expect_err("should not transfer a non-existent token"); assert!(matches!( @@ -1482,16 +1543,21 @@ mod tests { } #[motsu::test] - fn safe_transfers_from(contract: Erc721) { - let alice = msg::sender(); + fn safe_transfers_from(contract: Contract) { + let alice = Address::random(); let token_id = random_token_id(); - contract._mint(alice, token_id).expect("should mint a token to Alice"); + contract + .sender(alice) + ._mint(alice, token_id) + .expect("should mint a token to Alice"); contract + .sender(alice) .safe_transfer_from(alice, BOB, token_id) .expect("should transfer a token from Alice to Bob"); let owner = contract + .sender(alice) .owner_of(token_id) .expect("should return the owner of the token"); @@ -1499,51 +1565,68 @@ mod tests { } #[motsu::test] - fn safe_transfers_from_approved_token(contract: Erc721) { - let alice = msg::sender(); + fn safe_transfers_from_approved_token(contract: Contract) { + let alice = Address::random(); let token_id = random_token_id(); - contract._mint(BOB, token_id).expect("should mint token to Bob"); - contract._token_approvals.setter(token_id).set(alice); contract + .sender(alice) + ._mint(BOB, token_id) + .expect("should mint token to Bob"); + contract.sender(alice)._token_approvals.setter(token_id).set(alice); + contract + .sender(alice) .safe_transfer_from(BOB, alice, token_id) .expect("should transfer Bob's token to Alice"); let owner = contract + .sender(alice) .owner_of(token_id) .expect("should return the owner of the token"); assert_eq!(owner, alice); } #[motsu::test] - fn safe_transfers_from_approved_for_all(contract: Erc721) { - let alice = msg::sender(); + fn safe_transfers_from_approved_for_all(contract: Contract) { + let alice = Address::random(); let token_id = random_token_id(); - contract._mint(BOB, token_id).expect("should mint token to Bob"); + contract + .sender(alice) + ._mint(BOB, token_id) + .expect("should mint token to Bob"); // As we cannot change `msg::sender()`, we need to use this workaround. contract._operator_approvals.setter(BOB).setter(alice).set(true); - let approved_for_all = contract.is_approved_for_all(BOB, alice); + let approved_for_all = + contract.sender(alice).is_approved_for_all(BOB, alice); assert!(approved_for_all); contract + .sender(alice) .safe_transfer_from(BOB, alice, token_id) .expect("should transfer Bob's token to Alice"); let owner = contract + .sender(alice) .owner_of(token_id) .expect("should return the owner of the token"); assert_eq!(owner, alice); } #[motsu::test] - fn error_when_safe_transfer_to_invalid_receiver(contract: Erc721) { - let alice = msg::sender(); + fn error_when_safe_transfer_to_invalid_receiver( + contract: Contract, + ) { + let alice = Address::random(); let token_id = random_token_id(); let invalid_receiver = Address::ZERO; - contract._mint(alice, token_id).expect("should mint a token to Alice"); + contract + .sender(alice) + ._mint(alice, token_id) + .expect("should mint a token to Alice"); let err = contract + .sender(alice) .safe_transfer_from(alice, invalid_receiver, token_id) .expect_err("should not transfer the token to invalid receiver"); @@ -1555,6 +1638,7 @@ mod tests { )); let owner = contract + .sender(alice) .owner_of(token_id) .expect("should return the owner of the token"); assert_eq!(alice, owner); @@ -1562,14 +1646,18 @@ mod tests { #[motsu::test] fn error_when_safe_transfer_from_transfers_from_incorrect_owner( - contract: Erc721, + contract: Contract, ) { - let alice = msg::sender(); + let alice = Address::random(); let token_id = random_token_id(); - contract._mint(alice, token_id).expect("should mint a token to Alice"); + contract + .sender(alice) + ._mint(alice, token_id) + .expect("should mint a token to Alice"); let err = contract + .sender(alice) .safe_transfer_from(DAVE, BOB, token_id) .expect_err("should not transfer the token from incorrect owner"); assert!(matches!( @@ -1590,12 +1678,16 @@ mod tests { #[motsu::test] fn error_when_safe_transfer_from_transfers_with_insufficient_approval( - contract: Erc721, + contract: Contract, ) { - let alice = msg::sender(); + let alice = Address::random(); let token_id = random_token_id(); - contract._mint(BOB, token_id).expect("should mint token to Bob"); + contract + .sender(alice) + ._mint(BOB, token_id) + .expect("should mint token to Bob"); let err = contract + .sender(alice) .safe_transfer_from(BOB, alice, token_id) .expect_err("should not transfer unapproved token"); assert!(matches!( @@ -1609,11 +1701,12 @@ mod tests { #[motsu::test] fn error_when_safe_transfer_from_transfers_nonexistent_token( - contract: Erc721, + contract: Contract, ) { - let alice = msg::sender(); + let alice = Address::random(); let token_id = random_token_id(); let err = contract + .sender(alice) .safe_transfer_from(alice, BOB, token_id) .expect_err("should not transfer a non-existent token"); assert!(matches!( @@ -1625,12 +1718,16 @@ mod tests { } #[motsu::test] - fn safe_transfers_from_with_data(contract: Erc721) { - let alice = msg::sender(); + fn safe_transfers_from_with_data(contract: Contract) { + let alice = Address::random(); let token_id = random_token_id(); - contract._mint(alice, token_id).expect("should mint a token to Alice"); + contract + .sender(alice) + ._mint(alice, token_id) + .expect("should mint a token to Alice"); contract + .sender(alice) .safe_transfer_from_with_data( alice, BOB, @@ -1640,6 +1737,7 @@ mod tests { .expect("should transfer a token from Alice to Bob"); let owner = contract + .sender(alice) .owner_of(token_id) .expect("should return the owner of the token"); @@ -1647,12 +1745,18 @@ mod tests { } #[motsu::test] - fn safe_transfers_from_with_data_approved_token(contract: Erc721) { - let alice = msg::sender(); + fn safe_transfers_from_with_data_approved_token( + contract: Contract, + ) { + let alice = Address::random(); let token_id = random_token_id(); - contract._mint(BOB, token_id).expect("should mint token to Bob"); + contract + .sender(alice) + ._mint(BOB, token_id) + .expect("should mint token to Bob"); contract._token_approvals.setter(token_id).set(alice); contract + .sender(alice) .safe_transfer_from_with_data( BOB, alice, @@ -1661,24 +1765,32 @@ mod tests { ) .expect("should transfer Bob's token to Alice"); let owner = contract + .sender(alice) .owner_of(token_id) .expect("should return the owner of the token"); assert_eq!(owner, alice); } #[motsu::test] - fn safe_transfers_from_with_data_approved_for_all(contract: Erc721) { - let alice = msg::sender(); + fn safe_transfers_from_with_data_approved_for_all( + contract: Contract, + ) { + let alice = Address::random(); let token_id = random_token_id(); - contract._mint(BOB, token_id).expect("should mint token to Bob"); + contract + .sender(alice) + ._mint(BOB, token_id) + .expect("should mint token to Bob"); // As we cannot change `msg::sender()`, we need to use this workaround. contract._operator_approvals.setter(BOB).setter(alice).set(true); - let approved_for_all = contract.is_approved_for_all(BOB, alice); + let approved_for_all = + contract.sender(alice).is_approved_for_all(BOB, alice); assert!(approved_for_all); contract + .sender(alice) .safe_transfer_from_with_data( BOB, alice, @@ -1688,6 +1800,7 @@ mod tests { .expect("should transfer Bob's token to Alice"); let owner = contract + .sender(alice) .owner_of(token_id) .expect("should return the owner of the token"); assert_eq!(owner, alice); @@ -1695,15 +1808,19 @@ mod tests { #[motsu::test] fn error_when_safe_transfer_from_with_data_transfers_to_invalid_receiver( - contract: Erc721, + contract: Contract, ) { - let alice = msg::sender(); + let alice = Address::random(); let token_id = random_token_id(); let invalid_receiver = Address::ZERO; - contract._mint(alice, token_id).expect("should mint a token to Alice"); + contract + .sender(alice) + ._mint(alice, token_id) + .expect("should mint a token to Alice"); let err = contract + .sender(alice) .safe_transfer_from_with_data( alice, invalid_receiver, @@ -1720,6 +1837,7 @@ mod tests { )); let owner = contract + .sender(alice) .owner_of(token_id) .expect("should return the owner of the token"); assert_eq!(alice, owner); @@ -1727,14 +1845,18 @@ mod tests { #[motsu::test] fn error_when_safe_transfer_from_with_data_transfers_from_incorrect_owner( - contract: Erc721, + contract: Contract, ) { - let alice = msg::sender(); + let alice = Address::random(); let token_id = random_token_id(); - contract._mint(alice, token_id).expect("should mint a token to Alice"); + contract + .sender(alice) + ._mint(alice, token_id) + .expect("should mint a token to Alice"); let err = contract + .sender(alice) .safe_transfer_from_with_data( DAVE, BOB, @@ -1762,12 +1884,16 @@ mod tests { #[motsu::test] fn error_when_safe_transfer_from_with_data_transfers_with_insufficient_approval( - contract: Erc721, + contract: Contract, ) { - let alice = msg::sender(); + let alice = Address::random(); let token_id = random_token_id(); - contract._mint(BOB, token_id).expect("should mint token to Bob"); + contract + .sender(alice) + ._mint(BOB, token_id) + .expect("should mint token to Bob"); let err = contract + .sender(alice) .safe_transfer_from_with_data( BOB, alice, @@ -1786,11 +1912,12 @@ mod tests { #[motsu::test] fn error_when_safe_transfer_from_with_data_transfers_nonexistent_token( - contract: Erc721, + contract: Contract, ) { - let alice = msg::sender(); + let alice = Address::random(); let token_id = random_token_id(); let err = contract + .sender(alice) .safe_transfer_from_with_data( alice, BOB, @@ -1807,20 +1934,26 @@ mod tests { } #[motsu::test] - fn approves(contract: Erc721) { - let alice = msg::sender(); + fn approves(contract: Contract) { + let alice = Address::random(); let token_id = random_token_id(); - contract._mint(alice, token_id).expect("should mint a token"); contract + .sender(alice) + ._mint(alice, token_id) + .expect("should mint a token"); + contract + .sender(alice) .approve(BOB, token_id) .expect("should approve Bob for operations on token"); assert_eq!(contract._token_approvals.get(token_id), BOB); } #[motsu::test] - fn error_when_approve_for_nonexistent_token(contract: Erc721) { + fn error_when_approve_for_nonexistent_token(contract: Contract) { + let alice = Address::random(); let token_id = random_token_id(); let err = contract + .sender(alice) .approve(BOB, token_id) .expect_err("should not approve for a non-existent token"); @@ -1833,11 +1966,16 @@ mod tests { } #[motsu::test] - fn error_when_approve_by_invalid_approver(contract: Erc721) { + fn error_when_approve_by_invalid_approver(contract: Contract) { + let alice = Address::random(); let token_id = random_token_id(); - contract._mint(BOB, token_id).expect("should mint a token"); + contract + .sender(alice) + ._mint(BOB, token_id) + .expect("should mint a token"); let err = contract + .sender(alice) .approve(DAVE, token_id) .expect_err("should not approve when invalid approver"); @@ -1850,26 +1988,31 @@ mod tests { } #[motsu::test] - fn approval_for_all(contract: Erc721) { - let alice = msg::sender(); + fn approval_for_all(contract: Contract) { + let alice = Address::random(); contract._operator_approvals.setter(alice).setter(BOB).set(false); contract + .sender(alice) .set_approval_for_all(BOB, true) .expect("should approve Bob for operations on all Alice's tokens"); - assert!(contract.is_approved_for_all(alice, BOB)); + assert!(contract.sender(alice).is_approved_for_all(alice, BOB)); - contract.set_approval_for_all(BOB, false).expect( + contract.sender(alice).set_approval_for_all(BOB, false).expect( "should disapprove Bob for operations on all Alice's tokens", ); - assert!(!contract.is_approved_for_all(alice, BOB)); + assert!(!contract.sender(alice).is_approved_for_all(alice, BOB)); } #[motsu::test] - fn error_when_approval_for_all_for_invalid_operator(contract: Erc721) { + fn error_when_approval_for_all_for_invalid_operator( + contract: Contract, + ) { + let alice = Address::random(); let invalid_operator = Address::ZERO; let err = contract + .sender(alice) .set_approval_for_all(invalid_operator, true) .expect_err("should not approve for all for invalid operator"); @@ -1882,9 +2025,13 @@ mod tests { } #[motsu::test] - fn error_when_get_approved_of_nonexistent_token(contract: Erc721) { + fn error_when_get_approved_of_nonexistent_token( + contract: Contract, + ) { + let alice = Address::random(); let token_id = random_token_id(); let err = contract + .sender(alice) .get_approved(token_id) .expect_err("should not return approved for a non-existent token"); @@ -1897,125 +2044,162 @@ mod tests { } #[motsu::test] - fn owner_of_works(contract: Erc721) { + fn owner_of_works(contract: Contract) { + let alice = Address::random(); let token_id = random_token_id(); - contract._mint(BOB, token_id).expect("should mint a token"); + contract + .sender(alice) + ._mint(BOB, token_id) + .expect("should mint a token"); - let owner = contract._owner_of(token_id); + let owner = contract.sender(alice)._owner_of(token_id); assert_eq!(BOB, owner); } #[motsu::test] - fn owner_of_nonexistent_token(contract: Erc721) { + fn owner_of_nonexistent_token(contract: Contract) { + let alice = Address::random(); let token_id = random_token_id(); - let owner = contract._owner_of(token_id); + let owner = contract.sender(alice)._owner_of(token_id); assert_eq!(Address::ZERO, owner); } #[motsu::test] - fn get_approved_nonexistent_token(contract: Erc721) { + fn get_approved_nonexistent_token(contract: Contract) { + let alice = Address::random(); let token_id = random_token_id(); - let approved = contract._get_approved(token_id); + let approved = contract.sender(alice)._get_approved(token_id); assert_eq!(Address::ZERO, approved); } #[motsu::test] - fn get_approved_token_without_approval(contract: Erc721) { - let alice = msg::sender(); + fn get_approved_token_without_approval(contract: Contract) { + let alice = Address::random(); let token_id = random_token_id(); - contract._mint(alice, token_id).expect("should mint a token"); - let approved = contract._get_approved(token_id); + contract + .sender(alice) + ._mint(alice, token_id) + .expect("should mint a token"); + let approved = contract.sender(alice)._get_approved(token_id); assert_eq!(Address::ZERO, approved); } #[motsu::test] - fn get_approved_token_with_approval(contract: Erc721) { - let alice = msg::sender(); + fn get_approved_token_with_approval(contract: Contract) { + let alice = Address::random(); let token_id = random_token_id(); - contract._mint(alice, token_id).expect("should mint a token"); contract + .sender(alice) + ._mint(alice, token_id) + .expect("should mint a token"); + contract + .sender(alice) .approve(BOB, token_id) .expect("should approve Bob for operations on token"); - let approved = contract._get_approved(token_id); + let approved = contract.sender(alice)._get_approved(token_id); assert_eq!(BOB, approved); } #[motsu::test] - fn get_approved_token_with_approval_for_all(contract: Erc721) { - let alice = msg::sender(); + fn get_approved_token_with_approval_for_all(contract: Contract) { + let alice = Address::random(); let token_id = random_token_id(); - contract._mint(alice, token_id).expect("should mint a token"); contract + .sender(alice) + ._mint(alice, token_id) + .expect("should mint a token"); + contract + .sender(alice) .set_approval_for_all(BOB, true) .expect("should approve Bob for operations on all Alice's tokens"); - let approved = contract._get_approved(token_id); + let approved = contract.sender(alice)._get_approved(token_id); assert_eq!(Address::ZERO, approved); } #[motsu::test] - fn is_authorized_nonexistent_token(contract: Erc721) { - let alice = msg::sender(); + fn is_authorized_nonexistent_token(contract: Contract) { + let alice = Address::random(); let token_id = random_token_id(); - let authorized = contract._is_authorized(alice, BOB, token_id); + let authorized = + contract.sender(alice)._is_authorized(alice, BOB, token_id); assert!(!authorized); } #[motsu::test] - fn is_authorized_token_owner(contract: Erc721) { - let alice = msg::sender(); + fn is_authorized_token_owner(contract: Contract) { + let alice = Address::random(); let token_id = random_token_id(); - contract._mint(alice, token_id).expect("should mint a token"); + contract + .sender(alice) + ._mint(alice, token_id) + .expect("should mint a token"); - let authorized = contract._is_authorized(alice, alice, token_id); + let authorized = + contract.sender(alice)._is_authorized(alice, alice, token_id); assert!(authorized); } #[motsu::test] - fn is_authorized_without_approval(contract: Erc721) { - let alice = msg::sender(); + fn is_authorized_without_approval(contract: Contract) { + let alice = Address::random(); let token_id = random_token_id(); - contract._mint(alice, token_id).expect("should mint a token"); + contract + .sender(alice) + ._mint(alice, token_id) + .expect("should mint a token"); - let authorized = contract._is_authorized(alice, BOB, token_id); + let authorized = + contract.sender(alice)._is_authorized(alice, BOB, token_id); assert!(!authorized); } #[motsu::test] - fn is_authorized_with_approval(contract: Erc721) { - let alice = msg::sender(); + fn is_authorized_with_approval(contract: Contract) { + let alice = Address::random(); let token_id = random_token_id(); - contract._mint(alice, token_id).expect("should mint a token"); contract + .sender(alice) + ._mint(alice, token_id) + .expect("should mint a token"); + contract + .sender(alice) .approve(BOB, token_id) .expect("should approve Bob for operations on token"); - let authorized = contract._is_authorized(alice, BOB, token_id); + let authorized = + contract.sender(alice)._is_authorized(alice, BOB, token_id); assert!(authorized); } #[motsu::test] - fn is_authorized_with_approval_for_all(contract: Erc721) { - let alice = msg::sender(); + fn is_authorized_with_approval_for_all(contract: Contract) { + let alice = Address::random(); let token_id = random_token_id(); - contract._mint(alice, token_id).expect("should mint a token"); contract + .sender(alice) + ._mint(alice, token_id) + .expect("should mint a token"); + contract + .sender(alice) .set_approval_for_all(BOB, true) .expect("should approve Bob for operations on all Alice's tokens"); - let authorized = contract._is_authorized(alice, BOB, token_id); + let authorized = + contract.sender(alice)._is_authorized(alice, BOB, token_id); assert!(authorized); } #[motsu::test] - fn check_authorized_nonexistent_token(contract: Erc721) { - let alice = msg::sender(); + fn check_authorized_nonexistent_token(contract: Contract) { + let alice = Address::random(); let token_id = random_token_id(); let err = contract + .sender(alice) ._check_authorized(Address::ZERO, alice, token_id) .expect_err("should not pass for a non-existent token"); @@ -2028,23 +2212,31 @@ mod tests { } #[motsu::test] - fn check_authorized_token_owner(contract: Erc721) { - let alice = msg::sender(); + fn check_authorized_token_owner(contract: Contract) { + let alice = Address::random(); let token_id = random_token_id(); - contract._mint(alice, token_id).expect("should mint a token"); + contract + .sender(alice) + ._mint(alice, token_id) + .expect("should mint a token"); - let result = contract._check_authorized(alice, alice, token_id); + let result = + contract.sender(alice)._check_authorized(alice, alice, token_id); assert!(result.is_ok()); } #[motsu::test] - fn check_authorized_without_approval(contract: Erc721) { - let alice = msg::sender(); + fn check_authorized_without_approval(contract: Contract) { + let alice = Address::random(); let token_id = random_token_id(); - contract._mint(alice, token_id).expect("should mint a token"); + contract + .sender(alice) + ._mint(alice, token_id) + .expect("should mint a token"); let err = contract + .sender(alice) ._check_authorized(alice, BOB, token_id) .expect_err("should not pass without approval"); @@ -2058,49 +2250,65 @@ mod tests { } #[motsu::test] - fn check_authorized_with_approval(contract: Erc721) { - let alice = msg::sender(); + fn check_authorized_with_approval(contract: Contract) { + let alice = Address::random(); let token_id = random_token_id(); - contract._mint(alice, token_id).expect("should mint a token"); contract + .sender(alice) + ._mint(alice, token_id) + .expect("should mint a token"); + contract + .sender(alice) .approve(BOB, token_id) .expect("should approve Bob for operations on token"); - let result = contract._check_authorized(alice, BOB, token_id); + let result = + contract.sender(alice)._check_authorized(alice, BOB, token_id); assert!(result.is_ok()); } #[motsu::test] - fn check_authorized_with_approval_for_all(contract: Erc721) { - let alice = msg::sender(); + fn check_authorized_with_approval_for_all(contract: Contract) { + let alice = Address::random(); let token_id = random_token_id(); - contract._mint(alice, token_id).expect("should mint a token"); contract + .sender(alice) + ._mint(alice, token_id) + .expect("should mint a token"); + contract + .sender(alice) .set_approval_for_all(BOB, true) .expect("should approve Bob for operations on all Alice's tokens"); - let result = contract._check_authorized(alice, BOB, token_id); + let result = + contract.sender(alice)._check_authorized(alice, BOB, token_id); assert!(result.is_ok()); } #[motsu::test] - fn burns(contract: Erc721) { - let alice = msg::sender(); + fn burns(contract: Contract) { + let alice = Address::random(); let one = uint!(1_U256); let token_id = random_token_id(); - contract._mint(alice, token_id).expect("should mint a token for Alice"); + contract + .sender(alice) + ._mint(alice, token_id) + .expect("should mint a token for Alice"); let initial_balance = contract + .sender(alice) .balance_of(alice) .expect("should return the balance of Alice"); - let result = contract._burn(token_id); + let result = contract.sender(alice)._burn(token_id); let balance = contract + .sender(alice) .balance_of(alice) .expect("should return the balance of Alice"); let err = contract + .sender(alice) .owner_of(token_id) .expect_err("should return Error::NonexistentToken"); @@ -2117,18 +2325,28 @@ mod tests { } #[motsu::test] - fn error_when_get_approved_of_previous_approval_burned(contract: Erc721) { - let alice = msg::sender(); + fn error_when_get_approved_of_previous_approval_burned( + contract: Contract, + ) { + let alice = Address::random(); let token_id = random_token_id(); - contract._mint(alice, token_id).expect("should mint a token for Alice"); contract + .sender(alice) + ._mint(alice, token_id) + .expect("should mint a token for Alice"); + contract + .sender(alice) .approve(BOB, token_id) .expect("should approve a token for Bob"); - contract._burn(token_id).expect("should burn previously minted token"); + contract + .sender(alice) + ._burn(token_id) + .expect("should burn previously minted token"); let err = contract + .sender(alice) .get_approved(token_id) .expect_err("should return Error::NonexistentToken"); @@ -2141,10 +2359,12 @@ mod tests { } #[motsu::test] - fn error_when_burn_nonexistent_token(contract: Erc721) { + fn error_when_burn_nonexistent_token(contract: Contract) { + let alice = Address::random(); let token_id = random_token_id(); let err = contract + .sender(alice) ._burn(token_id) .expect_err("should return Error::NonexistentToken"); @@ -2157,65 +2377,87 @@ mod tests { } #[motsu::test] - fn transfers(contract: Erc721) { - let alice = msg::sender(); + fn transfers(contract: Contract) { + let alice = Address::random(); let token_id = random_token_id(); - contract._mint(alice, token_id).expect("should mint a token to Alice"); contract + .sender(alice) + ._mint(alice, token_id) + .expect("should mint a token to Alice"); + contract + .sender(alice) ._transfer(alice, BOB, token_id) .expect("should transfer a token from Alice to Bob"); let owner = contract + .sender(alice) .owner_of(token_id) .expect("should return the owner of the token"); assert_eq!(owner, BOB); } #[motsu::test] - fn transfers_approved_token(contract: Erc721) { - let alice = msg::sender(); + fn transfers_approved_token(contract: Contract) { + let alice = Address::random(); let token_id = random_token_id(); - contract._mint(BOB, token_id).expect("should mint token to Bob"); + contract + .sender(alice) + ._mint(BOB, token_id) + .expect("should mint token to Bob"); contract._token_approvals.setter(token_id).set(alice); contract + .sender(alice) ._transfer(BOB, alice, token_id) .expect("should transfer Bob's token to Alice"); let owner = contract + .sender(alice) .owner_of(token_id) .expect("should return the owner of the token"); assert_eq!(owner, alice); } #[motsu::test] - fn transfers_approved_for_all(contract: Erc721) { - let alice = msg::sender(); + fn transfers_approved_for_all(contract: Contract) { + let alice = Address::random(); let token_id = random_token_id(); - contract._mint(BOB, token_id).expect("should mint token to Bob"); + contract + .sender(alice) + ._mint(BOB, token_id) + .expect("should mint token to Bob"); // As we cannot change `msg::sender`, we need to use this workaround. contract._operator_approvals.setter(BOB).setter(alice).set(true); - let approved_for_all = contract.is_approved_for_all(BOB, alice); + let approved_for_all = + contract.sender(alice).is_approved_for_all(BOB, alice); assert!(approved_for_all); contract + .sender(alice) ._transfer(BOB, alice, token_id) .expect("should transfer Bob's token to Alice"); let owner = contract + .sender(alice) .owner_of(token_id) .expect("should return the owner of the token"); assert_eq!(owner, alice); } #[motsu::test] - fn error_when_transfer_transfers_to_invalid_receiver(contract: Erc721) { - let alice = msg::sender(); + fn error_when_transfer_transfers_to_invalid_receiver( + contract: Contract, + ) { + let alice = Address::random(); let token_id = random_token_id(); let invalid_receiver = Address::ZERO; - contract._mint(alice, token_id).expect("should mint a token to Alice"); + contract + .sender(alice) + ._mint(alice, token_id) + .expect("should mint a token to Alice"); let err = contract + .sender(alice) ._transfer(alice, invalid_receiver, token_id) .expect_err("should not transfer to invalid receiver"); @@ -2227,19 +2469,26 @@ mod tests { )); let owner = contract + .sender(alice) .owner_of(token_id) .expect("should return the owner of the token"); assert_eq!(alice, owner); } #[motsu::test] - fn error_when_transfer_transfers_from_incorrect_owner(contract: Erc721) { - let alice = msg::sender(); + fn error_when_transfer_transfers_from_incorrect_owner( + contract: Contract, + ) { + let alice = Address::random(); let token_id = random_token_id(); - contract._mint(alice, token_id).expect("should mint a token to Alice"); + contract + .sender(alice) + ._mint(alice, token_id) + .expect("should mint a token to Alice"); let err = contract + .sender(alice) ._transfer(DAVE, BOB, token_id) .expect_err("should not transfer from incorrect owner"); @@ -2260,10 +2509,13 @@ mod tests { } #[motsu::test] - fn error_when_transfer_transfers_nonexistent_token(contract: Erc721) { - let alice = msg::sender(); + fn error_when_transfer_transfers_nonexistent_token( + contract: Contract, + ) { + let alice = Address::random(); let token_id = random_token_id(); let err = contract + .sender(alice) ._transfer(alice, BOB, token_id) .expect_err("should not transfer a non-existent token"); assert!(matches!( @@ -2275,16 +2527,21 @@ mod tests { } #[motsu::test] - fn safe_transfers_internal(contract: Erc721) { - let alice = msg::sender(); + fn safe_transfers_internal(contract: Contract) { + let alice = Address::random(); let token_id = random_token_id(); - contract._mint(alice, token_id).expect("should mint a token to Alice"); + contract + .sender(alice) + ._mint(alice, token_id) + .expect("should mint a token to Alice"); contract + .sender(alice) ._safe_transfer(alice, BOB, token_id, &vec![0, 1, 2, 3].into()) .expect("should transfer a token from Alice to Bob"); let owner = contract + .sender(alice) .owner_of(token_id) .expect("should return the owner of the token"); @@ -2292,51 +2549,68 @@ mod tests { } #[motsu::test] - fn safe_transfers_internal_approved_token(contract: Erc721) { - let alice = msg::sender(); + fn safe_transfers_internal_approved_token(contract: Contract) { + let alice = Address::random(); let token_id = random_token_id(); - contract._mint(BOB, token_id).expect("should mint token to Bob"); + contract + .sender(alice) + ._mint(BOB, token_id) + .expect("should mint token to Bob"); contract._token_approvals.setter(token_id).set(alice); contract + .sender(alice) ._safe_transfer(BOB, alice, token_id, &vec![0, 1, 2, 3].into()) .expect("should transfer Bob's token to Alice"); let owner = contract + .sender(alice) .owner_of(token_id) .expect("should return the owner of the token"); assert_eq!(owner, alice); } #[motsu::test] - fn safe_transfers_internal_approved_for_all(contract: Erc721) { - let alice = msg::sender(); + fn safe_transfers_internal_approved_for_all(contract: Contract) { + let alice = Address::random(); let token_id = random_token_id(); - contract._mint(BOB, token_id).expect("should mint token to Bob"); + contract + .sender(alice) + ._mint(BOB, token_id) + .expect("should mint token to Bob"); // As we cannot change `msg::sender()`, we need to use this workaround. contract._operator_approvals.setter(BOB).setter(alice).set(true); - let approved_for_all = contract.is_approved_for_all(BOB, alice); + let approved_for_all = + contract.sender(alice).is_approved_for_all(BOB, alice); assert!(approved_for_all); contract + .sender(alice) ._safe_transfer(BOB, alice, token_id, &vec![0, 1, 2, 3].into()) .expect("should transfer Bob's token to Alice"); let owner = contract + .sender(alice) .owner_of(token_id) .expect("should return the owner of the token"); assert_eq!(owner, alice); } #[motsu::test] - fn error_when_internal_safe_transfer_to_invalid_receiver(contract: Erc721) { - let alice = msg::sender(); + fn error_when_internal_safe_transfer_to_invalid_receiver( + contract: Contract, + ) { + let alice = Address::random(); let token_id = random_token_id(); let invalid_receiver = Address::ZERO; - contract._mint(alice, token_id).expect("should mint a token to Alice"); + contract + .sender(alice) + ._mint(alice, token_id) + .expect("should mint a token to Alice"); let err = contract + .sender(alice) ._safe_transfer( alice, invalid_receiver, @@ -2353,6 +2627,7 @@ mod tests { )); let owner = contract + .sender(alice) .owner_of(token_id) .expect("should return the owner of the token"); assert_eq!(alice, owner); @@ -2360,14 +2635,18 @@ mod tests { #[motsu::test] fn error_when_internal_safe_transfer_from_incorrect_owner( - contract: Erc721, + contract: Contract, ) { - let alice = msg::sender(); + let alice = Address::random(); let token_id = random_token_id(); - contract._mint(alice, token_id).expect("should mint a token to Alice"); + contract + .sender(alice) + ._mint(alice, token_id) + .expect("should mint a token to Alice"); let err = contract + .sender(alice) ._safe_transfer(DAVE, BOB, token_id, &vec![0, 1, 2, 3].into()) .expect_err("should not transfer the token from incorrect owner"); assert!(matches!( @@ -2387,10 +2666,13 @@ mod tests { } #[motsu::test] - fn error_when_internal_safe_transfer_nonexistent_token(contract: Erc721) { - let alice = msg::sender(); + fn error_when_internal_safe_transfer_nonexistent_token( + contract: Contract, + ) { + let alice = Address::random(); let token_id = random_token_id(); let err = contract + .sender(alice) ._safe_transfer(alice, BOB, token_id, &vec![0, 1, 2, 3].into()) .expect_err("should not transfer a non-existent token"); @@ -2403,20 +2685,28 @@ mod tests { } #[motsu::test] - fn approves_internal(contract: Erc721) { - let alice = msg::sender(); + fn approves_internal(contract: Contract) { + let alice = Address::random(); let token_id = random_token_id(); - contract._mint(alice, token_id).expect("should mint a token"); contract + .sender(alice) + ._mint(alice, token_id) + .expect("should mint a token"); + contract + .sender(alice) ._approve(BOB, token_id, alice, false) .expect("should approve Bob for operations on token"); assert_eq!(contract._token_approvals.get(token_id), BOB); } #[motsu::test] - fn error_when_approve_internal_for_nonexistent_token(contract: Erc721) { + fn error_when_approve_internal_for_nonexistent_token( + contract: Contract, + ) { + let alice = Address::random(); let token_id = random_token_id(); let err = contract + .sender(alice) ._approve(BOB, token_id, msg::sender(), false) .expect_err("should not approve for a non-existent token"); @@ -2429,12 +2719,18 @@ mod tests { } #[motsu::test] - fn error_when_approve_internal_by_invalid_approver(contract: Erc721) { - let alice = msg::sender(); + fn error_when_approve_internal_by_invalid_approver( + contract: Contract, + ) { + let alice = Address::random(); let token_id = random_token_id(); - contract._mint(BOB, token_id).expect("should mint a token"); + contract + .sender(alice) + ._mint(BOB, token_id) + .expect("should mint a token"); let err = contract + .sender(alice) ._approve(DAVE, token_id, alice, false) .expect_err("should not approve when invalid approver"); @@ -2447,28 +2743,31 @@ mod tests { } #[motsu::test] - fn approval_for_all_internal(contract: Erc721) { - let alice = msg::sender(); + fn approval_for_all_internal(contract: Contract) { + let alice = Address::random(); contract._operator_approvals.setter(alice).setter(BOB).set(false); contract + .sender(alice) ._set_approval_for_all(alice, BOB, true) .expect("should approve Bob for operations on all Alice's tokens"); - assert!(contract.is_approved_for_all(alice, BOB)); + assert!(contract.sender(alice).is_approved_for_all(alice, BOB)); - contract._set_approval_for_all(alice, BOB, false).expect( + contract.sender(alice)._set_approval_for_all(alice, BOB, false).expect( "should disapprove Bob for operations on all Alice's tokens", ); - assert!(!contract.is_approved_for_all(alice, BOB)); + assert!(!contract.sender(alice).is_approved_for_all(alice, BOB)); } #[motsu::test] fn error_when_approval_for_all_internal_for_invalid_operator( - contract: Erc721, + contract: Contract, ) { + let alice = Address::random(); let invalid_operator = Address::ZERO; let err = contract + .sender(alice) ._set_approval_for_all(msg::sender(), invalid_operator, true) .expect_err("should not approve for all for invalid operator"); @@ -2481,11 +2780,16 @@ mod tests { } #[motsu::test] - fn require_owned_works(contract: Erc721) { + fn require_owned_works(contract: Contract) { + let alice = Address::random(); let token_id = random_token_id(); - contract._mint(BOB, token_id).expect("should mint a token"); + contract + .sender(alice) + ._mint(BOB, token_id) + .expect("should mint a token"); let owner = contract + .sender(alice) ._require_owned(token_id) .expect("should return the owner of the token"); @@ -2493,9 +2797,13 @@ mod tests { } #[motsu::test] - fn error_when_require_owned_for_nonexistent_token(contract: Erc721) { + fn error_when_require_owned_for_nonexistent_token( + contract: Contract, + ) { + let alice = Address::random(); let token_id = random_token_id(); let err = contract + .sender(alice) ._require_owned(token_id) .expect_err("should return Error::NonexistentToken"); @@ -2517,7 +2825,6 @@ mod tests { let expected = 0x01ffc9a7; assert_eq!(actual, expected); } - */ sol_storage! { pub struct Erc721ReceiverMock { @@ -2551,7 +2858,7 @@ mod tests { erc721: Contract, receiver: Contract, ) { - let alice = Account::random(); + let alice = Address::random(); let token_id = random_token_id(); erc721 .sender(alice) From 6f71be68888e85b77e432546d5db2f2239b77480 Mon Sep 17 00:00:00 2001 From: Alisander Qoshqosh Date: Tue, 31 Dec 2024 19:10:05 +0400 Subject: [PATCH 059/109] ++ --- contracts/src/token/erc721/mod.rs | 114 ++++++++++-------------------- 1 file changed, 36 insertions(+), 78 deletions(-) diff --git a/contracts/src/token/erc721/mod.rs b/contracts/src/token/erc721/mod.rs index 4ff8031e1..e7e413bc8 100644 --- a/contracts/src/token/erc721/mod.rs +++ b/contracts/src/token/erc721/mod.rs @@ -1397,7 +1397,10 @@ mod tests { .sender(alice) ._mint(BOB, token_id) .expect("should mint token to Bob"); - contract._token_approvals.setter(token_id).set(alice); + contract + .sender(BOB) + .approve(alice, token_id) + .expect("should approve Bob's token for Alice"); contract .sender(alice) .transfer_from(BOB, alice, token_id) @@ -1418,8 +1421,10 @@ mod tests { ._mint(BOB, token_id) .expect("should mint token to Bob"); - // As we cannot change `msg::sender`, we need to use this workaround. - contract._operator_approvals.setter(BOB).setter(alice).set(true); + contract + .sender(BOB) + .set_approval_for_all(alice, true) + .expect("should approve all Bob's tokens for Alice"); let approved_for_all = contract.sender(alice).is_approved_for_all(BOB, alice); @@ -1593,8 +1598,10 @@ mod tests { ._mint(BOB, token_id) .expect("should mint token to Bob"); - // As we cannot change `msg::sender()`, we need to use this workaround. - contract._operator_approvals.setter(BOB).setter(alice).set(true); + contract + .sender(BOB) + .set_approval_for_all(alice, true) + .expect("should approve all Bob's tokens for Alice"); let approved_for_all = contract.sender(alice).is_approved_for_all(BOB, alice); @@ -1754,7 +1761,10 @@ mod tests { .sender(alice) ._mint(BOB, token_id) .expect("should mint token to Bob"); - contract._token_approvals.setter(token_id).set(alice); + contract + .sender(BOB) + .approve(alice, token_id) + .expect("should approve Bob's token for Alice"); contract .sender(alice) .safe_transfer_from_with_data( @@ -1782,8 +1792,10 @@ mod tests { ._mint(BOB, token_id) .expect("should mint token to Bob"); - // As we cannot change `msg::sender()`, we need to use this workaround. - contract._operator_approvals.setter(BOB).setter(alice).set(true); + contract + .sender(BOB) + .set_approval_for_all(alice, true) + .expect("should approve all Bob's tokens for Alice"); let approved_for_all = contract.sender(alice).is_approved_for_all(BOB, alice); @@ -1933,21 +1945,6 @@ mod tests { )); } - #[motsu::test] - fn approves(contract: Contract) { - let alice = Address::random(); - let token_id = random_token_id(); - contract - .sender(alice) - ._mint(alice, token_id) - .expect("should mint a token"); - contract - .sender(alice) - .approve(BOB, token_id) - .expect("should approve Bob for operations on token"); - assert_eq!(contract._token_approvals.get(token_id), BOB); - } - #[motsu::test] fn error_when_approve_for_nonexistent_token(contract: Contract) { let alice = Address::random(); @@ -1987,23 +1984,6 @@ mod tests { )); } - #[motsu::test] - fn approval_for_all(contract: Contract) { - let alice = Address::random(); - contract._operator_approvals.setter(alice).setter(BOB).set(false); - - contract - .sender(alice) - .set_approval_for_all(BOB, true) - .expect("should approve Bob for operations on all Alice's tokens"); - assert!(contract.sender(alice).is_approved_for_all(alice, BOB)); - - contract.sender(alice).set_approval_for_all(BOB, false).expect( - "should disapprove Bob for operations on all Alice's tokens", - ); - assert!(!contract.sender(alice).is_approved_for_all(alice, BOB)); - } - #[motsu::test] fn error_when_approval_for_all_for_invalid_operator( contract: Contract, @@ -2403,7 +2383,10 @@ mod tests { .sender(alice) ._mint(BOB, token_id) .expect("should mint token to Bob"); - contract._token_approvals.setter(token_id).set(alice); + contract + .sender(BOB) + .approve(alice, token_id) + .expect("should approve Bob's token for Alice"); contract .sender(alice) ._transfer(BOB, alice, token_id) @@ -2424,8 +2407,10 @@ mod tests { ._mint(BOB, token_id) .expect("should mint token to Bob"); - // As we cannot change `msg::sender`, we need to use this workaround. - contract._operator_approvals.setter(BOB).setter(alice).set(true); + contract + .sender(BOB) + .set_approval_for_all(alice, true) + .expect("should approve all Bob's tokens for Alice"); let approved_for_all = contract.sender(alice).is_approved_for_all(BOB, alice); @@ -2556,7 +2541,10 @@ mod tests { .sender(alice) ._mint(BOB, token_id) .expect("should mint token to Bob"); - contract._token_approvals.setter(token_id).set(alice); + contract + .sender(BOB) + .approve(alice, token_id) + .expect("should approve Bob's token for Alice"); contract .sender(alice) ._safe_transfer(BOB, alice, token_id, &vec![0, 1, 2, 3].into()) @@ -2577,8 +2565,10 @@ mod tests { ._mint(BOB, token_id) .expect("should mint token to Bob"); - // As we cannot change `msg::sender()`, we need to use this workaround. - contract._operator_approvals.setter(BOB).setter(alice).set(true); + contract + .sender(BOB) + .set_approval_for_all(alice, true) + .expect("should approve all Bob's tokens for Alice"); let approved_for_all = contract.sender(alice).is_approved_for_all(BOB, alice); @@ -2684,21 +2674,6 @@ mod tests { )); } - #[motsu::test] - fn approves_internal(contract: Contract) { - let alice = Address::random(); - let token_id = random_token_id(); - contract - .sender(alice) - ._mint(alice, token_id) - .expect("should mint a token"); - contract - .sender(alice) - ._approve(BOB, token_id, alice, false) - .expect("should approve Bob for operations on token"); - assert_eq!(contract._token_approvals.get(token_id), BOB); - } - #[motsu::test] fn error_when_approve_internal_for_nonexistent_token( contract: Contract, @@ -2742,23 +2717,6 @@ mod tests { )); } - #[motsu::test] - fn approval_for_all_internal(contract: Contract) { - let alice = Address::random(); - contract._operator_approvals.setter(alice).setter(BOB).set(false); - - contract - .sender(alice) - ._set_approval_for_all(alice, BOB, true) - .expect("should approve Bob for operations on all Alice's tokens"); - assert!(contract.sender(alice).is_approved_for_all(alice, BOB)); - - contract.sender(alice)._set_approval_for_all(alice, BOB, false).expect( - "should disapprove Bob for operations on all Alice's tokens", - ); - assert!(!contract.sender(alice).is_approved_for_all(alice, BOB)); - } - #[motsu::test] fn error_when_approval_for_all_internal_for_invalid_operator( contract: Contract, From 425cf63a3dcbfacebc017ac4a09891cd91c14d99 Mon Sep 17 00:00:00 2001 From: Alisander Qoshqosh Date: Tue, 31 Dec 2024 20:39:43 +0400 Subject: [PATCH 060/109] ++ --- Cargo.lock | 4 ++-- Cargo.toml | 2 +- contracts/Cargo.toml | 3 +-- contracts/src/token/erc721/mod.rs | 2 +- 4 files changed, 5 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0459477be..c6dd96a76 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2549,7 +2549,7 @@ checksum = "7843ec2de400bcbc6a6328c958dc38e5359da6e93e72e37bc5246bf1ae776389" [[package]] name = "motsu" version = "0.2.1" -source = "git+https://github.com/OpenZeppelin/stylus-test-helpers?branch=unit-tests%2Fmultiple-contract-deployment#feb635a55d54463aa51d1c0a81d20903a6cbe99d" +source = "git+https://github.com/OpenZeppelin/stylus-test-helpers?branch=unit-tests%2Fmultiple-contract-deployment#7bf0dd3fd281755d90f7379fdf952497e49d5212" dependencies = [ "alloy-primitives", "alloy-sol-types", @@ -2564,7 +2564,7 @@ dependencies = [ [[package]] name = "motsu-proc" version = "0.2.1" -source = "git+https://github.com/OpenZeppelin/stylus-test-helpers?branch=unit-tests%2Fmultiple-contract-deployment#feb635a55d54463aa51d1c0a81d20903a6cbe99d" +source = "git+https://github.com/OpenZeppelin/stylus-test-helpers?branch=unit-tests%2Fmultiple-contract-deployment#7bf0dd3fd281755d90f7379fdf952497e49d5212" dependencies = [ "proc-macro2", "quote", diff --git a/Cargo.toml b/Cargo.toml index 9a68b3532..ed059b67b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -71,7 +71,7 @@ all = "warn" [workspace.dependencies] # Stylus SDK related -stylus-sdk = { version = "0.7.0-rc.1", default-features = false } +stylus-sdk = { version = "0.7.0-rc.1", default-features = false, features = ["mini-alloc"] } alloy = { version = "=0.7.2", features = [ "contract", diff --git a/contracts/Cargo.toml b/contracts/Cargo.toml index a307f13ce..e305a5de9 100644 --- a/contracts/Cargo.toml +++ b/contracts/Cargo.toml @@ -14,7 +14,7 @@ alloy-sol-types.workspace = true alloy-sol-macro.workspace = true alloy-sol-macro-expander.workspace = true alloy-sol-macro-input.workspace = true -stylus-sdk = { workspace = true, default-features = true } +stylus-sdk.workspace = true keccak-const.workspace = true openzeppelin-stylus-proc.workspace = true @@ -22,7 +22,6 @@ openzeppelin-stylus-proc.workspace = true alloy-primitives = { workspace = true, features = ["arbitrary"] } motsu.workspace = true rand.workspace = true -stylus-sdk.workspace = true [features] # Enables using the standard library. This is not included in the default diff --git a/contracts/src/token/erc721/mod.rs b/contracts/src/token/erc721/mod.rs index e7e413bc8..621004bd6 100644 --- a/contracts/src/token/erc721/mod.rs +++ b/contracts/src/token/erc721/mod.rs @@ -1163,7 +1163,7 @@ mod tests { use alloy_primitives::{ address, fixed_bytes, uint, Address, FixedBytes, U256, }; - use motsu::prelude::{Account, Contract}; + use motsu::prelude::Contract; use stylus_sdk::{ abi::Bytes, msg, From 0ecc2a3f221b466019596e7c12bbc57f99db0e27 Mon Sep 17 00:00:00 2001 From: Alisander Qoshqosh Date: Tue, 31 Dec 2024 20:45:27 +0400 Subject: [PATCH 061/109] ++ --- .../src/token/erc721/extensions/burnable.rs | 108 ++++++++++++------ 1 file changed, 76 insertions(+), 32 deletions(-) diff --git a/contracts/src/token/erc721/extensions/burnable.rs b/contracts/src/token/erc721/extensions/burnable.rs index b8e364398..f4aa8aa3a 100644 --- a/contracts/src/token/erc721/extensions/burnable.rs +++ b/contracts/src/token/erc721/extensions/burnable.rs @@ -51,10 +51,11 @@ impl IErc721Burnable for Erc721 { Ok(()) } } -/* + #[cfg(all(test, feature = "std"))] mod tests { use alloy_primitives::{address, uint, Address}; + use motsu::prelude::Contract; use stylus_sdk::msg; use super::IErc721Burnable; @@ -66,27 +67,33 @@ mod tests { const BOB: Address = address!("F4EaCDAbEf3c8f1EdE91b6f2A6840bc2E4DD3526"); #[motsu::test] - fn burns(contract: Erc721) { - let alice = msg::sender(); + fn burns(contract: Contract) { + let alice = Address::random(); let one = uint!(1_U256); let token_id = random_token_id(); - contract._mint(alice, token_id).expect("should mint a token for Alice"); + contract + .sender(alice) + ._mint(alice, token_id) + .expect("should mint a token for Alice"); let initial_balance = contract + .sender(alice) .balance_of(alice) .expect("should return the balance of Alice"); - let result = contract.burn(token_id); + let result = contract.sender(alice).burn(token_id); assert!(result.is_ok()); let balance = contract + .sender(alice) .balance_of(alice) .expect("should return the balance of Alice"); assert_eq!(initial_balance - one, balance); let err = contract + .sender(alice) .owner_of(token_id) .expect_err("should return Error::NonexistentToken"); @@ -99,21 +106,30 @@ mod tests { } #[motsu::test] - fn burns_with_approval(contract: Erc721) { - let alice = msg::sender(); + fn burns_with_approval(contract: Contract) { + let alice = Address::random(); let token_id = random_token_id(); - contract._mint(BOB, token_id).expect("should mint a token for Bob"); + contract + .sender(alice) + ._mint(BOB, token_id) + .expect("should mint a token for Bob"); - let initial_balance = - contract.balance_of(BOB).expect("should return the balance of Bob"); + let initial_balance = contract + .sender(alice) + .balance_of(BOB) + .expect("should return the balance of Bob"); - contract._token_approvals.setter(token_id).set(alice); + contract + .sender(BOB) + .approve(alice, token_id) + .expect("should approve a token for Alice"); - let result = contract.burn(token_id); + let result = contract.sender(alice).burn(token_id); assert!(result.is_ok()); let err = contract + .sender(alice) .owner_of(token_id) .expect_err("should return Error::NonexistentToken"); @@ -124,30 +140,40 @@ mod tests { }) if t_id == token_id )); - let balance = - contract.balance_of(BOB).expect("should return the balance of Bob"); + let balance = contract + .sender(alice) + .balance_of(BOB) + .expect("should return the balance of Bob"); assert_eq!(initial_balance - uint!(1_U256), balance); } #[motsu::test] - fn burns_with_approval_for_all(contract: Erc721) { - let alice = msg::sender(); + fn burns_with_approval_for_all(contract: Contract) { + let alice = Address::random(); let token_id = random_token_id(); - contract._mint(BOB, token_id).expect("should mint a token for Bob"); + contract + .sender(alice) + ._mint(BOB, token_id) + .expect("should mint a token for Bob"); - let initial_balance = - contract.balance_of(BOB).expect("should return the balance of Bob"); + let initial_balance = contract + .sender(alice) + .balance_of(BOB) + .expect("should return the balance of Bob"); - // As we cannot change `msg::sender()`, we need to use this workaround. - contract._operator_approvals.setter(BOB).setter(alice).set(true); + contract + .sender(BOB) + .set_approval_for_all(alice, true) + .expect("should approve all Bob's tokens for Alice"); - let result = contract.burn(token_id); + let result = contract.sender(alice).burn(token_id); assert!(result.is_ok()); let err = contract + .sender(alice) .owner_of(token_id) .expect_err("should return Error::NonexistentToken"); @@ -158,25 +184,37 @@ mod tests { }) if t_id == token_id )); - let balance = - contract.balance_of(BOB).expect("should return the balance of Bob"); + let balance = contract + .sender(alice) + .balance_of(BOB) + .expect("should return the balance of Bob"); assert_eq!(initial_balance - uint!(1_U256), balance); } #[motsu::test] - fn error_when_get_approved_of_previous_approval_burned(contract: Erc721) { - let alice = msg::sender(); + fn error_when_get_approved_of_previous_approval_burned( + contract: Contract, + ) { + let alice = Address::random(); let token_id = random_token_id(); - contract._mint(alice, token_id).expect("should mint a token for Alice"); contract + .sender(alice) + ._mint(alice, token_id) + .expect("should mint a token for Alice"); + contract + .sender(alice) .approve(BOB, token_id) .expect("should approve a token for Bob"); - contract.burn(token_id).expect("should burn previously minted token"); + contract + .sender(alice) + .burn(token_id) + .expect("should burn previously minted token"); let err = contract + .sender(alice) .get_approved(token_id) .expect_err("should return Error::NonexistentToken"); @@ -189,12 +227,17 @@ mod tests { } #[motsu::test] - fn error_when_burn_without_approval(contract: Erc721) { + fn error_when_burn_without_approval(contract: Contract) { + let alice = Address::random(); let token_id = random_token_id(); - contract._mint(BOB, token_id).expect("should mint a token for Bob"); + contract + .sender(alice) + ._mint(BOB, token_id) + .expect("should mint a token for Bob"); let err = contract + .sender(alice) .burn(token_id) .expect_err("should not burn unapproved token"); @@ -208,10 +251,12 @@ mod tests { } #[motsu::test] - fn error_when_burn_nonexistent_token(contract: Erc721) { + fn error_when_burn_nonexistent_token(contract: Contract) { + let alice = Address::random(); let token_id = random_token_id(); let err = contract + .sender(alice) .burn(token_id) .expect_err("should return Error::NonexistentToken"); @@ -223,4 +268,3 @@ mod tests { )); } } -*/ From 7ee9dc1f9d20d0da5827854016dd6e0c68375565 Mon Sep 17 00:00:00 2001 From: Alisander Qoshqosh Date: Tue, 31 Dec 2024 21:22:09 +0400 Subject: [PATCH 062/109] ++ --- Cargo.lock | 4 +- .../token/erc721/extensions/consecutive.rs | 288 +++++++++++------- 2 files changed, 186 insertions(+), 106 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c6dd96a76..d608e45ba 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2549,7 +2549,7 @@ checksum = "7843ec2de400bcbc6a6328c958dc38e5359da6e93e72e37bc5246bf1ae776389" [[package]] name = "motsu" version = "0.2.1" -source = "git+https://github.com/OpenZeppelin/stylus-test-helpers?branch=unit-tests%2Fmultiple-contract-deployment#7bf0dd3fd281755d90f7379fdf952497e49d5212" +source = "git+https://github.com/OpenZeppelin/stylus-test-helpers?branch=unit-tests%2Fmultiple-contract-deployment#366a6f5f188981b27765b0d1761733eaa742a3ee" dependencies = [ "alloy-primitives", "alloy-sol-types", @@ -2564,7 +2564,7 @@ dependencies = [ [[package]] name = "motsu-proc" version = "0.2.1" -source = "git+https://github.com/OpenZeppelin/stylus-test-helpers?branch=unit-tests%2Fmultiple-contract-deployment#7bf0dd3fd281755d90f7379fdf952497e49d5212" +source = "git+https://github.com/OpenZeppelin/stylus-test-helpers?branch=unit-tests%2Fmultiple-contract-deployment#366a6f5f188981b27765b0d1761733eaa742a3ee" dependencies = [ "proc-macro2", "quote", diff --git a/contracts/src/token/erc721/extensions/consecutive.rs b/contracts/src/token/erc721/extensions/consecutive.rs index 42bac5ff7..8cdbee459 100644 --- a/contracts/src/token/erc721/extensions/consecutive.rs +++ b/contracts/src/token/erc721/extensions/consecutive.rs @@ -800,10 +800,11 @@ impl Erc721Consecutive { Ok(owner) } } -/* + #[cfg(all(test, feature = "std"))] mod tests { use alloy_primitives::{address, uint, Address, U256}; + use motsu::prelude::Contract; use stylus_sdk::msg; use crate::token::{ @@ -821,49 +822,57 @@ mod tests { const BOB: Address = address!("F4EaCDAbEf3c8f1EdE91b6f2A6840bc2E4DD3526"); const DAVE: Address = address!("0BB78F7e7132d1651B4Fd884B7624394e92156F1"); - fn init( + const FIRST_CONSECUTIVE_TOKEN_ID: U96 = uint!(0_U96); + const MAX_BATCH_SIZE: U96 = uint!(5000_U96); + + fn mint_consecutive( contract: &mut Erc721Consecutive, receivers: Vec
, batches: Vec, - ) -> Vec { - contract._first_consecutive_id.set(uint!(0_U96)); - contract._max_batch_size.set(uint!(5000_U96)); - receivers - .into_iter() - .zip(batches) - .map(|(to, batch_size)| { - contract - ._mint_consecutive(to, batch_size) - .expect("should mint consecutively") - }) - .collect() + ) { + contract._first_consecutive_id.set(FIRST_CONSECUTIVE_TOKEN_ID); + contract._max_batch_size.set(MAX_BATCH_SIZE); + for (to, batch_size) in receivers.into_iter().zip(batches) { + contract + ._mint_consecutive(to, batch_size) + .expect("should mint consecutively"); + } } #[motsu::test] - fn mints(contract: Erc721Consecutive) { - let alice = msg::sender(); + fn mints(contract: Contract) { + let alice = Address::random(); let initial_balance = contract + .sender(alice) .balance_of(alice) .expect("should return the balance of Alice"); let init_tokens_count = uint!(10_U96); - init(contract, vec![alice], vec![init_tokens_count]); + contract.init(alice, |contract| { + mint_consecutive(contract, vec![alice], vec![init_tokens_count]); + }); let balance1 = contract + .sender(alice) .balance_of(alice) .expect("should return the balance of Alice"); assert_eq!(balance1, initial_balance + U256::from(init_tokens_count)); // Check non-consecutive mint. let token_id = random_token_id(); - contract._mint(alice, token_id).expect("should mint a token for Alice"); + contract + .sender(alice) + ._mint(alice, token_id) + .expect("should mint a token for Alice"); let owner = contract + .sender(alice) .owner_of(token_id) .expect("should return the owner of the token"); assert_eq!(owner, alice); let balance2 = contract + .sender(alice) .balance_of(alice) .expect("should return the balance of Alice"); @@ -871,13 +880,17 @@ mod tests { } #[motsu::test] - fn error_when_minting_token_id_twice(contract: Erc721Consecutive) { - let alice = msg::sender(); + fn error_when_minting_token_id_twice( + contract: Contract, + ) { + let alice = Address::random(); let token_id = random_token_id(); contract + .sender(alice) ._mint(alice, token_id) .expect("should mint the token a first time"); let err = contract + .sender(alice) ._mint(alice, token_id) .expect_err("should not mint a token with `token_id` twice"); @@ -890,12 +903,16 @@ mod tests { } #[motsu::test] - fn error_when_minting_token_invalid_receiver(contract: Erc721Consecutive) { + fn error_when_minting_token_invalid_receiver( + contract: Contract, + ) { + let alice = Address::random(); let invalid_receiver = Address::ZERO; let token_id = random_token_id(); let err = contract + .sender(alice) ._mint(invalid_receiver, token_id) .expect_err("should not mint a token for invalid receiver"); @@ -908,8 +925,10 @@ mod tests { } #[motsu::test] - fn error_when_to_is_zero(contract: Erc721Consecutive) { + fn error_when_to_is_zero(contract: Contract) { + let alice = Address::random(); let err = contract + .sender(alice) ._mint_consecutive(Address::ZERO, uint!(11_U96)) .expect_err("should not mint consecutive"); assert!(matches!( @@ -921,10 +940,12 @@ mod tests { } #[motsu::test] - fn error_when_exceed_batch_size(contract: Erc721Consecutive) { - let alice = msg::sender(); - let batch_size = contract._max_batch_size() + uint!(1_U96); + fn error_when_exceed_batch_size(contract: Contract) { + let alice = Address::random(); + let batch_size = + contract.sender(alice)._max_batch_size() + uint!(1_U96); let err = contract + .sender(alice) ._mint_consecutive(alice, batch_size) .expect_err("should not mint consecutive"); assert!(matches!( @@ -933,108 +954,128 @@ mod tests { batch_size, max_batch }) - if batch_size == U256::from(batch_size) && max_batch == U256::from(contract._max_batch_size()) + if batch_size == U256::from(batch_size) && max_batch == U256::from(contract.sender(alice)._max_batch_size()) )); } #[motsu::test] - fn transfers_from(contract: Erc721Consecutive) { - let alice = msg::sender(); + fn transfers_from(contract: Contract) { + let alice = Address::random(); let bob = BOB; // Mint batches of 1000 tokens to Alice and Bob. - let [first_consecutive_token_id, _] = init( - contract, - vec![alice, bob], - vec![uint!(1000_U96), uint!(1000_U96)], - ) - .try_into() - .expect("should have two elements in return vec"); + contract.init(alice, |contract| { + mint_consecutive( + contract, + vec![alice, bob], + vec![uint!(1000_U96), uint!(1000_U96)], + ); + }); // Transfer first consecutive token from Alice to Bob. contract - .transfer_from(alice, bob, U256::from(first_consecutive_token_id)) + .sender(alice) + .transfer_from(alice, bob, U256::from(FIRST_CONSECUTIVE_TOKEN_ID)) .expect("should transfer a token from Alice to Bob"); let owner = contract - .owner_of(U256::from(first_consecutive_token_id)) + .sender(alice) + .owner_of(U256::from(FIRST_CONSECUTIVE_TOKEN_ID)) .expect("token should be owned"); assert_eq!(owner, bob); // Check that balances changed. let alice_balance = contract + .sender(alice) .balance_of(alice) .expect("should return the balance of Alice"); assert_eq!(alice_balance, uint!(1000_U256) - uint!(1_U256)); - let bob_balance = - contract.balance_of(bob).expect("should return the balance of Bob"); + let bob_balance = contract + .sender(alice) + .balance_of(bob) + .expect("should return the balance of Bob"); assert_eq!(bob_balance, uint!(1000_U256) + uint!(1_U256)); // Check non-consecutive mint. let token_id = random_token_id(); - contract._mint(alice, token_id).expect("should mint a token to Alice"); + contract + .sender(alice) + ._mint(alice, token_id) + .expect("should mint a token to Alice"); let alice_balance = contract + .sender(alice) .balance_of(alice) .expect("should return the balance of Alice"); assert_eq!(alice_balance, uint!(1000_U256)); // Check transfer of the token that wasn't minted consecutive. contract + .sender(alice) .transfer_from(alice, BOB, token_id) .expect("should transfer a token from Alice to Bob"); let alice_balance = contract + .sender(alice) .balance_of(alice) .expect("should return the balance of Alice"); assert_eq!(alice_balance, uint!(1000_U256) - uint!(1_U256)); } #[motsu::test] - fn burns(contract: Erc721Consecutive) { - let alice = msg::sender(); + fn burns(contract: Contract) { + let alice = Address::random(); // Mint batch of 1000 tokens to Alice. - let [first_consecutive_token_id] = - init(contract, vec![alice], vec![uint!(1000_U96)]) - .try_into() - .expect("should have two elements in return vec"); + contract.init(alice, |contract| { + mint_consecutive(contract, vec![alice], vec![uint!(1000_U96)]); + }); // Check consecutive token burn. contract - ._burn(U256::from(first_consecutive_token_id)) + .sender(alice) + ._burn(U256::from(FIRST_CONSECUTIVE_TOKEN_ID)) .expect("should burn token"); let alice_balance = contract + .sender(alice) .balance_of(alice) .expect("should return the balance of Alice"); assert_eq!(alice_balance, uint!(1000_U256) - uint!(1_U256)); let err = contract - .owner_of(U256::from(first_consecutive_token_id)) + .sender(alice) + .owner_of(U256::from(FIRST_CONSECUTIVE_TOKEN_ID)) .expect_err("token should not exist"); assert!(matches!( err, Error::Erc721(erc721::Error::NonexistentToken(ERC721NonexistentToken { token_id })) - if token_id == U256::from(first_consecutive_token_id) + if token_id == U256::from(FIRST_CONSECUTIVE_TOKEN_ID) )); // Check non-consecutive token burn. let non_consecutive_token_id = random_token_id(); contract + .sender(alice) ._mint(alice, non_consecutive_token_id) .expect("should mint a token to Alice"); let owner = contract + .sender(alice) .owner_of(non_consecutive_token_id) .expect("should return owner of the token"); assert_eq!(owner, alice); let alice_balance = contract + .sender(alice) .balance_of(alice) .expect("should return the balance of Alice"); assert_eq!(alice_balance, uint!(1000_U256)); - contract._burn(non_consecutive_token_id).expect("should burn token"); + contract + .sender(alice) + ._burn(non_consecutive_token_id) + .expect("should burn token"); let err = contract + .sender(alice) .owner_of(U256::from(non_consecutive_token_id)) .expect_err("token should not exist"); @@ -1047,6 +1088,7 @@ mod tests { // After being burnt the token should not be burnt again. let non_existent_token = non_consecutive_token_id; let err = contract + .sender(alice) ._burn(non_existent_token) .expect_err("should return Error::NonexistentToken"); @@ -1059,16 +1101,21 @@ mod tests { } #[motsu::test] - fn safe_transfer_from(contract: Erc721Consecutive) { - let alice = msg::sender(); + fn safe_transfer_from(contract: Contract) { + let alice = Address::random(); let token_id = random_token_id(); - contract._mint(alice, token_id).expect("should mint a token to Alice"); + contract + .sender(alice) + ._mint(alice, token_id) + .expect("should mint a token to Alice"); contract + .sender(alice) .safe_transfer_from(alice, BOB, token_id) .expect("should transfer a token from Alice to Bob"); let owner = contract + .sender(alice) .owner_of(token_id) .expect("should return the owner of the token"); @@ -1076,15 +1123,25 @@ mod tests { } #[motsu::test] - fn safe_transfers_from_approved_token(contract: Erc721Consecutive) { - let alice = msg::sender(); + fn safe_transfers_from_approved_token( + contract: Contract, + ) { + let alice = Address::random(); let token_id = random_token_id(); - contract._mint(BOB, token_id).expect("should mint token to Bob"); - contract.erc721._token_approvals.setter(token_id).set(alice); contract + .sender(alice) + ._mint(BOB, token_id) + .expect("should mint token to Bob"); + contract + .sender(BOB) + .approve(alice, token_id) + .expect("should approve Bob's token to Alice"); + contract + .sender(alice) .safe_transfer_from(BOB, alice, token_id) .expect("should transfer Bob's token to Alice"); let owner = contract + .sender(alice) .owner_of(token_id) .expect("should return the owner of the token"); assert_eq!(owner, alice); @@ -1092,14 +1149,18 @@ mod tests { #[motsu::test] fn error_when_safe_transfer_from_incorrect_owner( - contract: Erc721Consecutive, + contract: Contract, ) { - let alice = msg::sender(); + let alice = Address::random(); let token_id = random_token_id(); - contract._mint(alice, token_id).expect("should mint a token to Alice"); + contract + .sender(alice) + ._mint(alice, token_id) + .expect("should mint a token to Alice"); let err = contract + .sender(alice) .safe_transfer_from(DAVE, BOB, token_id) .expect_err("should not transfer from incorrect owner"); @@ -1115,11 +1176,12 @@ mod tests { #[motsu::test] fn error_when_internal_safe_transfer_nonexistent_token( - contract: Erc721Consecutive, + contract: Contract, ) { - let alice = msg::sender(); + let alice = Address::random(); let token_id = random_token_id(); let err = contract + .sender(alice) ._safe_transfer(alice, BOB, token_id, &vec![0, 1, 2, 3].into()) .expect_err("should not transfer a non-existent token"); @@ -1133,15 +1195,19 @@ mod tests { #[motsu::test] fn error_when_safe_transfer_to_invalid_receiver( - contract: Erc721Consecutive, + contract: Contract, ) { - let alice = msg::sender(); + let alice = Address::random(); let token_id = random_token_id(); let invalid_receiver = Address::ZERO; - contract._mint(alice, token_id).expect("should mint a token to Alice"); + contract + .sender(alice) + ._mint(alice, token_id) + .expect("should mint a token to Alice"); let err = contract + .sender(alice) .safe_transfer_from(alice, invalid_receiver, token_id) .expect_err("should not transfer the token to invalid receiver"); @@ -1153,18 +1219,23 @@ mod tests { )); let owner = contract + .sender(alice) .owner_of(token_id) .expect("should return the owner of the token"); assert_eq!(alice, owner); } #[motsu::test] - fn safe_transfers_from_with_data(contract: Erc721Consecutive) { - let alice = msg::sender(); + fn safe_transfers_from_with_data(contract: Contract) { + let alice = Address::random(); let token_id = random_token_id(); - contract._mint(alice, token_id).expect("should mint a token to Alice"); + contract + .sender(alice) + ._mint(alice, token_id) + .expect("should mint a token to Alice"); contract + .sender(alice) .safe_transfer_from_with_data( alice, BOB, @@ -1174,6 +1245,7 @@ mod tests { .expect("should transfer a token from Alice to Bob"); let owner = contract + .sender(alice) .owner_of(token_id) .expect("should return the owner of the token"); @@ -1182,15 +1254,19 @@ mod tests { #[motsu::test] fn error_when_internal_safe_transfer_to_invalid_receiver( - contract: Erc721Consecutive, + contract: Contract, ) { - let alice = msg::sender(); + let alice = Address::random(); let token_id = random_token_id(); let invalid_receiver = Address::ZERO; - contract._mint(alice, token_id).expect("should mint a token to Alice"); + contract + .sender(alice) + ._mint(alice, token_id) + .expect("should mint a token to Alice"); let err = contract + .sender(alice) ._safe_transfer( alice, invalid_receiver, @@ -1207,6 +1283,7 @@ mod tests { )); let owner = contract + .sender(alice) .owner_of(token_id) .expect("should return the owner of the token"); assert_eq!(alice, owner); @@ -1214,14 +1291,18 @@ mod tests { #[motsu::test] fn error_when_internal_safe_transfer_from_incorrect_owner( - contract: Erc721Consecutive, + contract: Contract, ) { - let alice = msg::sender(); + let alice = Address::random(); let token_id = random_token_id(); - contract._mint(alice, token_id).expect("should mint a token to Alice"); + contract + .sender(alice) + ._mint(alice, token_id) + .expect("should mint a token to Alice"); let err = contract + .sender(alice) ._safe_transfer(DAVE, BOB, token_id, &vec![0, 1, 2, 3].into()) .expect_err("should not transfer the token from incorrect owner"); assert!(matches!( @@ -1235,24 +1316,28 @@ mod tests { } #[motsu::test] - fn safe_mints(contract: Erc721Consecutive) { - let alice = msg::sender(); + fn safe_mints(contract: Contract) { + let alice = Address::random(); let token_id = random_token_id(); let initial_balance = contract + .sender(alice) .balance_of(alice) .expect("should return the balance of Alice"); contract + .sender(alice) ._safe_mint(alice, token_id, &vec![0, 1, 2, 3].into()) .expect("should mint a token for Alice"); let owner = contract + .sender(alice) .owner_of(token_id) .expect("should return the owner of the token"); assert_eq!(owner, alice); let balance = contract + .sender(alice) .balance_of(alice) .expect("should return the balance of Alice"); @@ -1260,20 +1345,13 @@ mod tests { } #[motsu::test] - fn approves(contract: Erc721Consecutive) { - let alice = msg::sender(); - let token_id = random_token_id(); - contract._mint(alice, token_id).expect("should mint a token"); - contract - .approve(BOB, token_id) - .expect("should approve Bob for operations on token"); - assert_eq!(contract.erc721._token_approvals.get(token_id), BOB); - } - - #[motsu::test] - fn error_when_approve_for_nonexistent_token(contract: Erc721Consecutive) { + fn error_when_approve_for_nonexistent_token( + contract: Contract, + ) { + let alice = Address::random(); let token_id = random_token_id(); let err = contract + .sender(alice) .approve(BOB, token_id) .expect_err("should not approve for a non-existent token"); @@ -1286,11 +1364,18 @@ mod tests { } #[motsu::test] - fn error_when_approve_by_invalid_approver(contract: Erc721Consecutive) { + fn error_when_approve_by_invalid_approver( + contract: Contract, + ) { + let alice = Address::random(); let token_id = random_token_id(); - contract._mint(BOB, token_id).expect("should mint a token"); + contract + .sender(alice) + ._mint(BOB, token_id) + .expect("should mint a token"); let err = contract + .sender(alice) .approve(DAVE, token_id) .expect_err("should not approve when invalid approver"); @@ -1303,32 +1388,28 @@ mod tests { } #[motsu::test] - fn approval_for_all(contract: Erc721Consecutive) { - let alice = msg::sender(); - contract - .erc721 - ._operator_approvals - .setter(alice) - .setter(BOB) - .set(false); - + fn approval_for_all(contract: Contract) { + let alice = Address::random(); contract + .sender(alice) .set_approval_for_all(BOB, true) .expect("should approve Bob for operations on all Alice's tokens"); - assert!(contract.is_approved_for_all(alice, BOB)); + assert!(contract.sender(alice).is_approved_for_all(alice, BOB)); - contract.set_approval_for_all(BOB, false).expect( + contract.sender(alice).set_approval_for_all(BOB, false).expect( "should disapprove Bob for operations on all Alice's tokens", ); - assert!(!contract.is_approved_for_all(alice, BOB)); + assert!(!contract.sender(alice).is_approved_for_all(alice, BOB)); } #[motsu::test] fn error_when_get_approved_of_nonexistent_token( - contract: Erc721Consecutive, + contract: Contract, ) { + let alice = Address::random(); let token_id = random_token_id(); let err = contract + .sender(alice) .get_approved(token_id) .expect_err("should not return approved for a non-existent token"); @@ -1340,4 +1421,3 @@ mod tests { )); } } -*/ From 6e3bf2b0281e4034e08d5124ba07a64aff84728a Mon Sep 17 00:00:00 2001 From: Alisander Qoshqosh Date: Tue, 31 Dec 2024 21:46:03 +0400 Subject: [PATCH 063/109] ++ --- .../src/token/erc721/extensions/enumerable.rs | 123 +++++++++++++----- 1 file changed, 89 insertions(+), 34 deletions(-) diff --git a/contracts/src/token/erc721/extensions/enumerable.rs b/contracts/src/token/erc721/extensions/enumerable.rs index 3b5007af8..48b8aafb0 100644 --- a/contracts/src/token/erc721/extensions/enumerable.rs +++ b/contracts/src/token/erc721/extensions/enumerable.rs @@ -332,35 +332,45 @@ impl Erc721Enumerable { } } } -/* + #[cfg(all(test, feature = "std"))] mod tests { use alloy_primitives::{address, uint, Address, U256}; - use stylus_sdk::msg; + use motsu::prelude::Contract; + use stylus_sdk::{msg, prelude::TopLevelStorage}; use super::{Erc721Enumerable, Error, IErc721Enumerable}; use crate::token::erc721::{tests::random_token_id, Erc721, IErc721}; const BOB: Address = address!("F4EaCDAbEf3c8f1EdE91b6f2A6840bc2E4DD3526"); + unsafe impl TopLevelStorage for Erc721Enumerable {} + #[motsu::test] - fn total_supply_no_tokens(contract: Erc721Enumerable) { - assert_eq!(U256::ZERO, contract.total_supply()); + fn total_supply_no_tokens(contract: Contract) { + let alice = Address::random(); + assert_eq!(U256::ZERO, contract.sender(alice).total_supply()); } #[motsu::test] - fn error_when_token_by_index_is_out_of_bound(contract: Erc721Enumerable) { - assert_eq!(U256::ZERO, contract.total_supply()); + fn error_when_token_by_index_is_out_of_bound( + contract: Contract, + ) { + let alice = Address::random(); + assert_eq!(U256::ZERO, contract.sender(alice).total_supply()); let token_idx = uint!(2024_U256); - let err = contract.token_by_index(token_idx).unwrap_err(); + let err = contract.sender(alice).token_by_index(token_idx).unwrap_err(); assert!(matches!(err, Error::OutOfBoundsIndex(_))); } #[motsu::test] - fn add_token_to_all_tokens_enumeration_works(contract: Erc721Enumerable) { - assert_eq!(U256::ZERO, contract.total_supply()); + fn add_token_to_all_tokens_enumeration_works( + contract: Contract, + ) { + let alice = Address::random(); + assert_eq!(U256::ZERO, contract.sender(alice).total_supply()); let tokens_len = 10; @@ -371,28 +381,38 @@ mod tests { // Store ids for test. tokens_ids.push(token_id); - contract._add_token_to_all_tokens_enumeration(token_id); + contract + .sender(alice) + ._add_token_to_all_tokens_enumeration(token_id); } - assert_eq!(U256::from(tokens_len), contract.total_supply()); + assert_eq!( + U256::from(tokens_len), + contract.sender(alice).total_supply() + ); tokens_ids.iter().enumerate().for_each(|(idx, expected_token_id)| { let token_id = contract + .sender(alice) .token_by_index(U256::from(idx)) .expect("should return token id for"); assert_eq!(*expected_token_id, token_id); }); - let err = contract.token_by_index(U256::from(tokens_len)).unwrap_err(); + let err = contract + .sender(alice) + .token_by_index(U256::from(tokens_len)) + .unwrap_err(); assert!(matches!(err, Error::OutOfBoundsIndex(_))); } #[motsu::test] fn remove_token_from_all_tokens_enumeration_works( - contract: Erc721Enumerable, + contract: Contract, ) { - assert_eq!(U256::ZERO, contract.total_supply()); + let alice = Address::random(); + assert_eq!(U256::ZERO, contract.sender(alice).total_supply()); let initial_tokens_len = 10; @@ -403,36 +423,56 @@ mod tests { // Store ids for test. tokens_ids.push(token_id); - contract._add_token_to_all_tokens_enumeration(token_id); + contract + .sender(alice) + ._add_token_to_all_tokens_enumeration(token_id); } - assert_eq!(U256::from(initial_tokens_len), contract.total_supply()); + assert_eq!( + U256::from(initial_tokens_len), + contract.sender(alice).total_supply() + ); // Remove the last token. let last_token_id = tokens_ids.swap_remove(initial_tokens_len - 1); - contract._remove_token_from_all_tokens_enumeration(last_token_id); - assert_eq!(U256::from(initial_tokens_len - 1), contract.total_supply()); + contract + .sender(alice) + ._remove_token_from_all_tokens_enumeration(last_token_id); + assert_eq!( + U256::from(initial_tokens_len - 1), + contract.sender(alice).total_supply() + ); // Remove the second (`idx = 1`) element // to check that swap_remove operation works as expected. let token_to_remove = tokens_ids.swap_remove(1); - contract._remove_token_from_all_tokens_enumeration(token_to_remove); - assert_eq!(U256::from(initial_tokens_len - 2), contract.total_supply()); + contract + .sender(alice) + ._remove_token_from_all_tokens_enumeration(token_to_remove); + assert_eq!( + U256::from(initial_tokens_len - 2), + contract.sender(alice).total_supply() + ); // Add a new token. let token_id = random_token_id(); tokens_ids.push(token_id); - contract._add_token_to_all_tokens_enumeration(token_id); - assert_eq!(U256::from(initial_tokens_len - 1), contract.total_supply()); + contract.sender(alice)._add_token_to_all_tokens_enumeration(token_id); + assert_eq!( + U256::from(initial_tokens_len - 1), + contract.sender(alice).total_supply() + ); // Check proper indices of tokens. tokens_ids.iter().enumerate().for_each(|(idx, expected_token_id)| { let token_id = contract + .sender(alice) .token_by_index(U256::from(idx)) .expect("should return token id"); assert_eq!(*expected_token_id, token_id); }); let err = contract + .sender(alice) .token_by_index(U256::from(initial_tokens_len - 1)) .unwrap_err(); @@ -446,10 +486,16 @@ mod tests { assert!(matches!(err, Error::EnumerableForbiddenBatchMint(_))); } + // TODO#q: repair Erc721Enumerable and Erc721 integration tests + #[motsu::test] - fn token_of_owner_by_index_works(contract: Erc721Enumerable) { - let alice = msg::sender(); - let mut erc721 = Erc721::default(); + fn token_of_owner_by_index_works( + contract: Contract, + erc721: Contract, + ) { + let alice = Address::random(); + let mut contract = contract.sender(alice); + let mut erc721 = erc721.sender(alice); assert_eq!( U256::ZERO, erc721.balance_of(alice).expect("should return balance of ALICE") @@ -475,10 +521,13 @@ mod tests { #[motsu::test] fn error_when_token_of_owner_for_index_out_of_bound( - contract: Erc721Enumerable, + contract: Contract, + erc721: Contract, ) { - let alice = msg::sender(); - let mut erc721 = Erc721::default(); + let alice = Address::random(); + let mut contract = contract.sender(alice); + let mut erc721 = erc721.sender(alice); + assert_eq!( U256::ZERO, erc721.balance_of(alice).expect("should return balance of ALICE") @@ -502,9 +551,13 @@ mod tests { #[motsu::test] fn error_when_token_of_owner_does_not_own_any_token( - contract: Erc721Enumerable, + contract: Contract, + erc721: Contract, ) { - let erc721 = Erc721::default(); + let alice = Address::random(); + let mut contract = contract.sender(alice); + let mut erc721 = erc721.sender(alice); + assert_eq!( U256::ZERO, erc721.balance_of(BOB).expect("should return balance of BOB") @@ -517,10 +570,13 @@ mod tests { #[motsu::test] fn token_of_owner_by_index_after_transfer_works( - contract: Erc721Enumerable, + contract: Contract, + erc721: Contract, ) { - let alice = msg::sender(); - let mut erc721 = Erc721::default(); + let alice = Address::random(); + let mut contract = contract.sender(alice); + let mut erc721 = erc721.sender(alice); + assert_eq!( U256::ZERO, erc721.balance_of(alice).expect("should return balance of ALICE") @@ -572,4 +628,3 @@ mod tests { assert_eq!(actual, expected); } } -*/ From c302a607e7eb05a8294c1d82a4d5d02d63ed7079 Mon Sep 17 00:00:00 2001 From: Alisander Qoshqosh Date: Tue, 31 Dec 2024 22:06:08 +0400 Subject: [PATCH 064/109] ++ --- .../src/token/erc721/extensions/enumerable.rs | 51 +++++++------------ 1 file changed, 18 insertions(+), 33 deletions(-) diff --git a/contracts/src/token/erc721/extensions/enumerable.rs b/contracts/src/token/erc721/extensions/enumerable.rs index 48b8aafb0..c65482e99 100644 --- a/contracts/src/token/erc721/extensions/enumerable.rs +++ b/contracts/src/token/erc721/extensions/enumerable.rs @@ -487,15 +487,10 @@ mod tests { } // TODO#q: repair Erc721Enumerable and Erc721 integration tests - - #[motsu::test] - fn token_of_owner_by_index_works( - contract: Contract, - erc721: Contract, - ) { - let alice = Address::random(); - let mut contract = contract.sender(alice); - let mut erc721 = erc721.sender(alice); + /*#[motsu::test] + fn token_of_owner_by_index_works(contract: Erc721Enumerable) { + let alice = msg::sender(); + let mut erc721 = Erc721::default(); assert_eq!( U256::ZERO, erc721.balance_of(alice).expect("should return balance of ALICE") @@ -509,7 +504,7 @@ mod tests { assert_eq!(owner, alice); let res = - contract._add_token_to_owner_enumeration(alice, token_id, &*erc721); + contract._add_token_to_owner_enumeration(alice, token_id, &erc721); assert!(res.is_ok()); let test_token_id = contract @@ -521,13 +516,10 @@ mod tests { #[motsu::test] fn error_when_token_of_owner_for_index_out_of_bound( - contract: Contract, - erc721: Contract, + contract: Erc721Enumerable, ) { - let alice = Address::random(); - let mut contract = contract.sender(alice); - let mut erc721 = erc721.sender(alice); - + let alice = msg::sender(); + let mut erc721 = Erc721::default(); assert_eq!( U256::ZERO, erc721.balance_of(alice).expect("should return balance of ALICE") @@ -541,7 +533,7 @@ mod tests { assert_eq!(owner, alice); let res = - contract._add_token_to_owner_enumeration(alice, token_id, &*erc721); + contract._add_token_to_owner_enumeration(alice, token_id, &erc721); assert!(res.is_ok()); let err = @@ -551,13 +543,9 @@ mod tests { #[motsu::test] fn error_when_token_of_owner_does_not_own_any_token( - contract: Contract, - erc721: Contract, + contract: Erc721Enumerable, ) { - let alice = Address::random(); - let mut contract = contract.sender(alice); - let mut erc721 = erc721.sender(alice); - + let erc721 = Erc721::default(); assert_eq!( U256::ZERO, erc721.balance_of(BOB).expect("should return balance of BOB") @@ -570,13 +558,10 @@ mod tests { #[motsu::test] fn token_of_owner_by_index_after_transfer_works( - contract: Contract, - erc721: Contract, + contract: Erc721Enumerable, ) { - let alice = Address::random(); - let mut contract = contract.sender(alice); - let mut erc721 = erc721.sender(alice); - + let alice = msg::sender(); + let mut erc721 = Erc721::default(); assert_eq!( U256::ZERO, erc721.balance_of(alice).expect("should return balance of ALICE") @@ -590,7 +575,7 @@ mod tests { assert_eq!(owner, alice); let res = - contract._add_token_to_owner_enumeration(alice, token_id, &*erc721); + contract._add_token_to_owner_enumeration(alice, token_id, &erc721); assert!(res.is_ok()); // Transfer the token from ALICE to BOB. @@ -603,11 +588,11 @@ mod tests { assert_eq!(owner, BOB); let res = contract - ._remove_token_from_owner_enumeration(alice, token_id, &*erc721); + ._remove_token_from_owner_enumeration(alice, token_id, &erc721); assert!(res.is_ok()); let res = - contract._add_token_to_owner_enumeration(BOB, token_id, &*erc721); + contract._add_token_to_owner_enumeration(BOB, token_id, &erc721); assert!(res.is_ok()); let test_token_id = contract @@ -619,7 +604,7 @@ mod tests { let err = contract.token_of_owner_by_index(alice, U256::ZERO).unwrap_err(); assert!(matches!(err, Error::OutOfBoundsIndex(_))); - } + }*/ #[motsu::test] fn interface_id() { From 4b135dd3e54b1a6329f8ec31f0df2e712515be35 Mon Sep 17 00:00:00 2001 From: Alisander Qoshqosh Date: Mon, 6 Jan 2025 19:38:41 +0400 Subject: [PATCH 065/109] erc721 uri storage tests --- .../token/erc721/extensions/uri_storage.rs | 68 ++++++++----------- 1 file changed, 27 insertions(+), 41 deletions(-) diff --git a/contracts/src/token/erc721/extensions/uri_storage.rs b/contracts/src/token/erc721/extensions/uri_storage.rs index 8cb0964a8..ba0acd283 100644 --- a/contracts/src/token/erc721/extensions/uri_storage.rs +++ b/contracts/src/token/erc721/extensions/uri_storage.rs @@ -110,11 +110,12 @@ impl Erc721UriStorage { Ok(uri) } } -/* + #[cfg(all(test, feature = "std"))] mod tests { - use alloy_primitives::U256; - use stylus_sdk::{msg, prelude::storage}; + use alloy_primitives::{Address, U256}; + use motsu::prelude::Contract; + use stylus_sdk::prelude::{public, storage, TopLevelStorage}; use super::Erc721UriStorage; use crate::token::erc721::{extensions::Erc721Metadata, Erc721}; @@ -131,61 +132,46 @@ mod tests { pub uri_storage: Erc721UriStorage, } - #[motsu::test] - fn get_token_uri_works(contract: Erc721MetadataExample) { - let alice = msg::sender(); - - let token_id = random_token_id(); - - contract - .erc721 - ._mint(alice, token_id) - .expect("should mint a token for Alice"); - - let token_uri = String::from("https://docs.openzeppelin.com/contracts/5.x/api/token/erc721#Erc721URIStorage"); - contract - .uri_storage - ._token_uris - .setter(token_id) - .set_str(token_uri.clone()); + #[public] + impl Erc721MetadataExample { + #[selector(name = "tokenURI")] + fn token_uri(&self, token_id: U256) -> Result> { + Ok(self.uri_storage.token_uri( + token_id, + &self.erc721, + &self.metadata, + )?) + } - assert_eq!( - token_uri, - contract - .uri_storage - .token_uri(token_id, &contract.erc721, &contract.metadata) - .expect("should return token URI") - ); + #[selector(name = "setTokenURI")] + fn set_token_uri(&mut self, token_id: U256, token_uri: String) { + self.uri_storage._set_token_uri(token_id, token_uri); + } } + unsafe impl TopLevelStorage for Erc721MetadataExample {} + #[motsu::test] - fn set_token_uri_works(contract: Erc721MetadataExample) { - let alice = msg::sender(); + fn token_uri_works(contract: Contract) { + let alice = Address::random(); let token_id = random_token_id(); contract + .sender(alice) .erc721 ._mint(alice, token_id) .expect("should mint a token for Alice"); - let initial_token_uri = String::from("https://docs.openzeppelin.com/contracts/5.x/api/token/erc721#Erc721URIStorage"); - contract - .uri_storage - ._token_uris - .setter(token_id) - .set_str(initial_token_uri); - - let token_uri = String::from("Updated Token URI"); - contract.uri_storage._set_token_uri(token_id, token_uri.clone()); + let token_uri = String::from("https://docs.openzeppelin.com/contracts/5.x/api/token/erc721#Erc721URIStorage"); + contract.sender(alice).set_token_uri(token_id, token_uri.clone()); assert_eq!( token_uri, contract - .uri_storage - .token_uri(token_id, &contract.erc721, &contract.metadata) + .sender(alice) + .token_uri(token_id) .expect("should return token URI") ); } } -*/ From c455196f1ca5457fcc199256b6ca53c11f129d13 Mon Sep 17 00:00:00 2001 From: Alisander Qoshqosh Date: Tue, 7 Jan 2025 05:39:19 +0400 Subject: [PATCH 066/109] erc20 tests --- .../src/token/erc20/extensions/burnable.rs | 93 +++--- .../src/token/erc20/extensions/capped.rs | 21 +- contracts/src/token/erc20/mod.rs | 274 +++++++++--------- contracts/src/token/erc20/utils/safe_erc20.rs | 3 +- 4 files changed, 200 insertions(+), 191 deletions(-) diff --git a/contracts/src/token/erc20/extensions/burnable.rs b/contracts/src/token/erc20/extensions/burnable.rs index 5ff59a518..2de39bb01 100644 --- a/contracts/src/token/erc20/extensions/burnable.rs +++ b/contracts/src/token/erc20/extensions/burnable.rs @@ -76,112 +76,101 @@ impl IErc20Burnable for Erc20 { self._burn(account, value) } } -/* + #[cfg(all(test, feature = "std"))] mod tests { - use alloy_primitives::{address, uint, Address, U256}; - use stylus_sdk::msg; + use alloy_primitives::{uint, Address, U256}; + use motsu::prelude::Contract; use super::IErc20Burnable; use crate::token::erc20::{Erc20, Error, IErc20}; #[motsu::test] - fn burns(contract: Erc20) { + fn burns(contract: Contract) { + let alice = Address::random(); + let bob = Address::random(); let zero = U256::ZERO; let one = uint!(1_U256); - assert_eq!(zero, contract.total_supply()); + assert_eq!(zero, contract.sender(alice).total_supply()); // Mint some tokens for msg::sender(). - let sender = msg::sender(); let two = uint!(2_U256); - contract._update(Address::ZERO, sender, two).unwrap(); - assert_eq!(two, contract.balance_of(sender)); - assert_eq!(two, contract.total_supply()); + contract.sender(alice)._update(Address::ZERO, alice, two).unwrap(); + assert_eq!(two, contract.sender(alice).balance_of(alice)); + assert_eq!(two, contract.sender(alice).total_supply()); - contract.burn(one).unwrap(); + contract.sender(alice).burn(one).unwrap(); - assert_eq!(one, contract.balance_of(sender)); - assert_eq!(one, contract.total_supply()); + assert_eq!(one, contract.sender(alice).balance_of(alice)); + assert_eq!(one, contract.sender(alice).total_supply()); } #[motsu::test] - fn burns_errors_when_insufficient_balance(contract: Erc20) { + fn burns_errors_when_insufficient_balance(contract: Contract) { let zero = U256::ZERO; let one = uint!(1_U256); - let sender = msg::sender(); + let alice = Address::random(); - assert_eq!(zero, contract.balance_of(sender)); + assert_eq!(zero, contract.sender(alice).balance_of(alice)); - let result = contract.burn(one); + let result = contract.sender(alice).burn(one); assert!(matches!(result, Err(Error::InsufficientBalance(_)))); } #[motsu::test] - fn burn_from(contract: Erc20) { - let alice = address!("A11CEacF9aa32246d767FCCD72e02d6bCbcC375d"); - let sender = msg::sender(); + fn burn_from(contract: Contract) { + let alice = Address::random(); + let bob = Address::random(); // Alice approves `msg::sender`. let one = uint!(1_U256); - contract._allowances.setter(alice).setter(sender).set(one); + contract.sender(alice).approve(bob, one).unwrap(); // Mint some tokens for Alice. let two = uint!(2_U256); - contract._update(Address::ZERO, alice, two).unwrap(); - assert_eq!(two, contract.balance_of(alice)); - assert_eq!(two, contract.total_supply()); + contract.sender(alice)._update(Address::ZERO, alice, two).unwrap(); + assert_eq!(two, contract.sender(alice).balance_of(alice)); + assert_eq!(two, contract.sender(alice).total_supply()); - contract.burn_from(alice, one).unwrap(); + contract.sender(bob).burn_from(alice, one).unwrap(); - assert_eq!(one, contract.balance_of(alice)); - assert_eq!(one, contract.total_supply()); - assert_eq!(U256::ZERO, contract.allowance(alice, sender)); + assert_eq!(one, contract.sender(alice).balance_of(alice)); + assert_eq!(one, contract.sender(alice).total_supply()); + assert_eq!(U256::ZERO, contract.sender(alice).allowance(bob, alice)); } #[motsu::test] - fn burns_from_errors_when_insufficient_balance(contract: Erc20) { - let alice = address!("A11CEacF9aa32246d767FCCD72e02d6bCbcC375d"); + fn burns_from_errors_when_insufficient_balance(contract: Contract) { + let alice = Address::random(); + let bob = Address::random(); // Alice approves `msg::sender`. let zero = U256::ZERO; let one = uint!(1_U256); - contract._allowances.setter(alice).setter(msg::sender()).set(one); - assert_eq!(zero, contract.balance_of(alice)); + contract.sender(alice).approve(bob, one).unwrap(); + assert_eq!(zero, contract.sender(alice).balance_of(bob)); let one = uint!(1_U256); - let result = contract.burn_from(alice, one); + let result = contract.sender(bob).burn_from(alice, one); assert!(matches!(result, Err(Error::InsufficientBalance(_)))); } #[motsu::test] - fn burns_from_errors_when_invalid_approver(contract: Erc20) { - let one = uint!(1_U256); - - contract - ._allowances - .setter(Address::ZERO) - .setter(msg::sender()) - .set(one); - - let result = contract.burn_from(Address::ZERO, one); - assert!(matches!(result, Err(Error::InvalidApprover(_)))); - } - - #[motsu::test] - fn burns_from_errors_when_insufficient_allowance(contract: Erc20) { - let alice = address!("A11CEacF9aa32246d767FCCD72e02d6bCbcC375d"); + fn burns_from_errors_when_insufficient_allowance( + contract: Contract, + ) { + let alice = Address::random(); // Mint some tokens for Alice. let one = uint!(1_U256); - contract._update(Address::ZERO, alice, one).unwrap(); - assert_eq!(one, contract.balance_of(alice)); + contract.sender(alice)._update(Address::ZERO, alice, one).unwrap(); + assert_eq!(one, contract.sender(alice).balance_of(alice)); - let result = contract.burn_from(alice, one); + let result = contract.sender(alice).burn_from(alice, one); assert!(matches!(result, Err(Error::InsufficientAllowance(_)))); } } -*/ diff --git a/contracts/src/token/erc20/extensions/capped.rs b/contracts/src/token/erc20/extensions/capped.rs index a7da257e9..5ff74214a 100644 --- a/contracts/src/token/erc20/extensions/capped.rs +++ b/contracts/src/token/erc20/extensions/capped.rs @@ -59,22 +59,27 @@ impl Capped { self._cap.get() } } -/* + #[cfg(all(test, feature = "std"))] mod tests { - use alloy_primitives::uint; + use alloy_primitives::{uint, Address}; + use motsu::prelude::Contract; + use stylus_sdk::prelude::TopLevelStorage; use super::Capped; + unsafe impl TopLevelStorage for Capped {} + #[motsu::test] - fn cap_works(contract: Capped) { + fn cap_works(contract: Contract) { + let alice = Address::random(); + let value = uint!(2024_U256); - contract._cap.set(value); - assert_eq!(contract.cap(), value); + contract.init(alice, |contract| contract._cap.set(value)); + assert_eq!(contract.sender(alice).cap(), value); let value = uint!(1_U256); - contract._cap.set(value); - assert_eq!(contract.cap(), value); + contract.init(alice, |contract| contract._cap.set(value)); + assert_eq!(contract.sender(alice).cap(), value); } } -*/ diff --git a/contracts/src/token/erc20/mod.rs b/contracts/src/token/erc20/mod.rs index 6d48d6435..b3ef79d97 100644 --- a/contracts/src/token/erc20/mod.rs +++ b/contracts/src/token/erc20/mod.rs @@ -581,118 +581,121 @@ impl Erc20 { Ok(()) } } -/* + #[cfg(all(test, feature = "std"))] mod tests { use alloy_primitives::{address, uint, Address, U256}; - use stylus_sdk::msg; + use motsu::prelude::Contract; + use stylus_sdk::prelude::TopLevelStorage; use super::{Erc20, Error, IErc20}; use crate::utils::introspection::erc165::IErc165; - #[motsu::test] - fn reads_balance(contract: Erc20) { - let balance = contract.balance_of(Address::ZERO); - assert_eq!(U256::ZERO, balance); - - let owner = msg::sender(); - let one = uint!(1_U256); - contract._balances.setter(owner).set(one); - let balance = contract.balance_of(owner); - assert_eq!(one, balance); - } + unsafe impl TopLevelStorage for Erc20 {} #[motsu::test] - fn update_mint(contract: Erc20) { + fn update_mint(contract: Contract) { let alice = address!("A11CEacF9aa32246d767FCCD72e02d6bCbcC375d"); let one = uint!(1_U256); // Store initial balance & supply. - let initial_balance = contract.balance_of(alice); - let initial_supply = contract.total_supply(); + let initial_balance = contract.sender(alice).balance_of(alice); + let initial_supply = contract.sender(alice).total_supply(); // Mint action should work. - let result = contract._update(Address::ZERO, alice, one); + let result = contract.sender(alice)._update(Address::ZERO, alice, one); assert!(result.is_ok()); // Check updated balance & supply. - assert_eq!(initial_balance + one, contract.balance_of(alice)); - assert_eq!(initial_supply + one, contract.total_supply()); + assert_eq!( + initial_balance + one, + contract.sender(alice).balance_of(alice) + ); + assert_eq!(initial_supply + one, contract.sender(alice).total_supply()); } #[motsu::test] #[should_panic = "should not exceed `U256::MAX` for `_total_supply`"] - fn update_mint_errors_arithmetic_overflow(contract: Erc20) { + fn update_mint_errors_arithmetic_overflow(contract: Contract) { let alice = address!("A11CEacF9aa32246d767FCCD72e02d6bCbcC375d"); let one = uint!(1_U256); - assert_eq!(U256::ZERO, contract.balance_of(alice)); - assert_eq!(U256::ZERO, contract.total_supply()); + assert_eq!(U256::ZERO, contract.sender(alice).balance_of(alice)); + assert_eq!(U256::ZERO, contract.sender(alice).total_supply()); // Initialize state for the test case: // Alice's balance as `U256::MAX`. contract + .sender(alice) ._update(Address::ZERO, alice, U256::MAX) .expect("should mint tokens"); // Mint action should NOT work: // overflow on `_total_supply`. - let _result = contract._update(Address::ZERO, alice, one); + let _result = contract.sender(alice)._update(Address::ZERO, alice, one); } #[motsu::test] - fn mint_works(contract: Erc20) { + fn mint_works(contract: Contract) { let alice = address!("A11CEacF9aa32246d767FCCD72e02d6bCbcC375d"); let one = uint!(1_U256); // Store initial balance & supply. - let initial_balance = contract.balance_of(alice); - let initial_supply = contract.total_supply(); + let initial_balance = contract.sender(alice).balance_of(alice); + let initial_supply = contract.sender(alice).total_supply(); // Mint action should work. - let result = contract._mint(alice, one); + let result = contract.sender(alice)._mint(alice, one); assert!(result.is_ok()); // Check updated balance & supply. - assert_eq!(initial_balance + one, contract.balance_of(alice)); - assert_eq!(initial_supply + one, contract.total_supply()); + assert_eq!( + initial_balance + one, + contract.sender(alice).balance_of(alice) + ); + assert_eq!(initial_supply + one, contract.sender(alice).total_supply()); } #[motsu::test] - fn mint_errors_invalid_receiver(contract: Erc20) { + fn mint_errors_invalid_receiver(contract: Contract) { + let alice = address!("A11CEacF9aa32246d767FCCD72e02d6bCbcC375d"); let receiver = Address::ZERO; let one = uint!(1_U256); // Store initial balance & supply. - let initial_balance = contract.balance_of(receiver); - let initial_supply = contract.total_supply(); + let initial_balance = contract.sender(alice).balance_of(receiver); + let initial_supply = contract.sender(alice).total_supply(); // Mint action should work. - let result = contract._mint(receiver, one); + let result = contract.sender(alice)._mint(receiver, one); assert!(matches!(result, Err(Error::InvalidReceiver(_)))); // Check updated balance & supply. - assert_eq!(initial_balance, contract.balance_of(receiver)); - assert_eq!(initial_supply, contract.total_supply()); + assert_eq!( + initial_balance, + contract.sender(alice).balance_of(receiver) + ); + assert_eq!(initial_supply, contract.sender(alice).total_supply()); } #[motsu::test] #[should_panic = "should not exceed `U256::MAX` for `_total_supply`"] - fn mint_errors_arithmetic_overflow(contract: Erc20) { + fn mint_errors_arithmetic_overflow(contract: Contract) { let alice = address!("A11CEacF9aa32246d767FCCD72e02d6bCbcC375d"); let one = uint!(1_U256); - assert_eq!(U256::ZERO, contract.balance_of(alice)); - assert_eq!(U256::ZERO, contract.total_supply()); + assert_eq!(U256::ZERO, contract.sender(alice).balance_of(alice)); + assert_eq!(U256::ZERO, contract.sender(alice).total_supply()); // Initialize state for the test case: // Alice's balance as `U256::MAX`. contract + .sender(alice) ._update(Address::ZERO, alice, U256::MAX) .expect("should mint tokens"); // Mint action should NOT work -- overflow on `_total_supply`. - let _result = contract._mint(alice, one); + let _result = contract.sender(alice)._mint(alice, one); } #[motsu::test] - fn update_burn(contract: Erc20) { + fn update_burn(contract: Contract) { let alice = address!("A11CEacF9aa32246d767FCCD72e02d6bCbcC375d"); let one = uint!(1_U256); let two = uint!(2_U256); @@ -700,24 +703,28 @@ mod tests { // Initialize state for the test case: // Alice's balance as `two`. contract + .sender(alice) ._update(Address::ZERO, alice, two) .expect("should mint tokens"); // Store initial balance & supply. - let initial_balance = contract.balance_of(alice); - let initial_supply = contract.total_supply(); + let initial_balance = contract.sender(alice).balance_of(alice); + let initial_supply = contract.sender(alice).total_supply(); // Burn action should work. - let result = contract._update(alice, Address::ZERO, one); + let result = contract.sender(alice)._update(alice, Address::ZERO, one); assert!(result.is_ok()); // Check updated balance & supply. - assert_eq!(initial_balance - one, contract.balance_of(alice)); - assert_eq!(initial_supply - one, contract.total_supply()); + assert_eq!( + initial_balance - one, + contract.sender(alice).balance_of(alice) + ); + assert_eq!(initial_supply - one, contract.sender(alice).total_supply()); } #[motsu::test] - fn update_burn_errors_insufficient_balance(contract: Erc20) { + fn update_burn_errors_insufficient_balance(contract: Contract) { let alice = address!("A11CEacF9aa32246d767FCCD72e02d6bCbcC375d"); let one = uint!(1_U256); let two = uint!(2_U256); @@ -725,24 +732,25 @@ mod tests { // Initialize state for the test case: // Alice's balance as `one`. contract + .sender(alice) ._update(Address::ZERO, alice, one) .expect("should mint tokens"); // Store initial balance & supply. - let initial_balance = contract.balance_of(alice); - let initial_supply = contract.total_supply(); + let initial_balance = contract.sender(alice).balance_of(alice); + let initial_supply = contract.sender(alice).total_supply(); // Burn action should NOT work - `InsufficientBalance`. - let result = contract._update(alice, Address::ZERO, two); + let result = contract.sender(alice)._update(alice, Address::ZERO, two); assert!(matches!(result, Err(Error::InsufficientBalance(_)))); // Check proper state (before revert). - assert_eq!(initial_balance, contract.balance_of(alice)); - assert_eq!(initial_supply, contract.total_supply()); + assert_eq!(initial_balance, contract.sender(alice).balance_of(alice)); + assert_eq!(initial_supply, contract.sender(alice).total_supply()); } #[motsu::test] - fn update_transfer(contract: Erc20) { + fn update_transfer(contract: Contract) { let alice = address!("A11CEacF9aa32246d767FCCD72e02d6bCbcC375d"); let bob = address!("B0B0cB49ec2e96DF5F5fFB081acaE66A2cBBc2e2"); let one = uint!(1_U256); @@ -750,27 +758,37 @@ mod tests { // Initialize state for the test case: // Alice's & Bob's balance as `one`. contract + .sender(alice) ._update(Address::ZERO, alice, one) .expect("should mint tokens"); - contract._update(Address::ZERO, bob, one).expect("should mint tokens"); + contract + .sender(alice) + ._update(Address::ZERO, bob, one) + .expect("should mint tokens"); // Store initial balance & supply. - let initial_alice_balance = contract.balance_of(alice); - let initial_bob_balance = contract.balance_of(bob); - let initial_supply = contract.total_supply(); + let initial_alice_balance = contract.sender(alice).balance_of(alice); + let initial_bob_balance = contract.sender(alice).balance_of(bob); + let initial_supply = contract.sender(alice).total_supply(); // Transfer action should work. - let result = contract._update(alice, bob, one); + let result = contract.sender(alice)._update(alice, bob, one); assert!(result.is_ok()); // Check updated balance & supply. - assert_eq!(initial_alice_balance - one, contract.balance_of(alice)); - assert_eq!(initial_bob_balance + one, contract.balance_of(bob)); - assert_eq!(initial_supply, contract.total_supply()); + assert_eq!( + initial_alice_balance - one, + contract.sender(alice).balance_of(alice) + ); + assert_eq!( + initial_bob_balance + one, + contract.sender(alice).balance_of(bob) + ); + assert_eq!(initial_supply, contract.sender(alice).total_supply()); } #[motsu::test] - fn update_transfer_errors_insufficient_balance(contract: Erc20) { + fn update_transfer_errors_insufficient_balance(contract: Contract) { let alice = address!("A11CEacF9aa32246d767FCCD72e02d6bCbcC375d"); let bob = address!("B0B0cB49ec2e96DF5F5fFB081acaE66A2cBBc2e2"); let one = uint!(1_U256); @@ -778,148 +796,147 @@ mod tests { // Initialize state for the test case: // Alice's & Bob's balance as `one`. contract + .sender(alice) ._update(Address::ZERO, alice, one) .expect("should mint tokens"); - contract._update(Address::ZERO, bob, one).expect("should mint tokens"); + contract + .sender(alice) + ._update(Address::ZERO, bob, one) + .expect("should mint tokens"); // Store initial balance & supply. - let initial_alice_balance = contract.balance_of(alice); - let initial_bob_balance = contract.balance_of(bob); - let initial_supply = contract.total_supply(); + let initial_alice_balance = contract.sender(alice).balance_of(alice); + let initial_bob_balance = contract.sender(alice).balance_of(bob); + let initial_supply = contract.sender(alice).total_supply(); // Transfer action should NOT work - `InsufficientBalance`. - let result = contract._update(alice, bob, one + one); + let result = contract.sender(alice)._update(alice, bob, one + one); assert!(matches!(result, Err(Error::InsufficientBalance(_)))); // Check proper state (before revert). - assert_eq!(initial_alice_balance, contract.balance_of(alice)); - assert_eq!(initial_bob_balance, contract.balance_of(bob)); - assert_eq!(initial_supply, contract.total_supply()); + assert_eq!( + initial_alice_balance, + contract.sender(alice).balance_of(alice) + ); + assert_eq!(initial_bob_balance, contract.sender(alice).balance_of(bob)); + assert_eq!(initial_supply, contract.sender(alice).total_supply()); } #[motsu::test] - fn transfers(contract: Erc20) { + fn transfers(contract: Contract) { let alice = address!("A11CEacF9aa32246d767FCCD72e02d6bCbcC375d"); let bob = address!("B0B0cB49ec2e96DF5F5fFB081acaE66A2cBBc2e2"); - // Alice approves `msg::sender`. - let one = uint!(1_U256); - contract._allowances.setter(alice).setter(msg::sender()).set(one); - // Mint some tokens for Alice. let two = uint!(2_U256); - contract._update(Address::ZERO, alice, two).unwrap(); - assert_eq!(two, contract.balance_of(alice)); + contract.sender(alice)._update(Address::ZERO, alice, two).unwrap(); + assert_eq!(two, contract.sender(alice).balance_of(alice)); - contract.transfer_from(alice, bob, one).unwrap(); + let one = uint!(1_U256); + contract.sender(alice).transfer(bob, one).unwrap(); - assert_eq!(one, contract.balance_of(alice)); - assert_eq!(one, contract.balance_of(bob)); + assert_eq!(one, contract.sender(alice).balance_of(alice)); + assert_eq!(one, contract.sender(alice).balance_of(bob)); } #[motsu::test] - fn transfers_from(contract: Erc20) { + fn transfer_from(contract: Contract) { let alice = address!("A11CEacF9aa32246d767FCCD72e02d6bCbcC375d"); let bob = address!("B0B0cB49ec2e96DF5F5fFB081acaE66A2cBBc2e2"); - let sender = msg::sender(); - // Alice approves `msg::sender`. + // Alice approves Bob. let one = uint!(1_U256); - contract._allowances.setter(alice).setter(sender).set(one); + contract.sender(alice).approve(bob, one).unwrap(); // Mint some tokens for Alice. let two = uint!(2_U256); - contract._update(Address::ZERO, alice, two).unwrap(); - assert_eq!(two, contract.balance_of(alice)); + contract.sender(alice)._update(Address::ZERO, alice, two).unwrap(); + assert_eq!(two, contract.sender(alice).balance_of(alice)); - contract.transfer_from(alice, bob, one).unwrap(); + contract.sender(bob).transfer_from(alice, bob, one).unwrap(); - assert_eq!(one, contract.balance_of(alice)); - assert_eq!(one, contract.balance_of(bob)); - assert_eq!(U256::ZERO, contract.allowance(alice, sender)); + assert_eq!(one, contract.sender(alice).balance_of(alice)); + assert_eq!(one, contract.sender(alice).balance_of(bob)); + assert_eq!(U256::ZERO, contract.sender(alice).allowance(alice, bob)); } #[motsu::test] - fn transfer_from_errors_when_insufficient_balance(contract: Erc20) { + fn error_when_transfer_with_insufficient_balance( + contract: Contract, + ) { let alice = address!("A11CEacF9aa32246d767FCCD72e02d6bCbcC375d"); let bob = address!("B0B0cB49ec2e96DF5F5fFB081acaE66A2cBBc2e2"); - // Alice approves `msg::sender`. + // Alice approves Bob. let one = uint!(1_U256); - contract._allowances.setter(alice).setter(msg::sender()).set(one); - assert_eq!(U256::ZERO, contract.balance_of(alice)); + contract.sender(alice).approve(bob, one).unwrap(); - let one = uint!(1_U256); - let result = contract.transfer_from(alice, bob, one); + let result = contract.sender(bob).transfer_from(alice, bob, one); assert!(matches!(result, Err(Error::InsufficientBalance(_)))); } #[motsu::test] - fn transfer_from_errors_when_invalid_approver(contract: Erc20) { + fn error_when_transfer_to_invalid_receiver(contract: Contract) { let alice = address!("A11CEacF9aa32246d767FCCD72e02d6bCbcC375d"); - let one = uint!(1_U256); - contract - ._allowances - .setter(Address::ZERO) - .setter(msg::sender()) - .set(one); - let result = contract.transfer_from(Address::ZERO, alice, one); - assert!(matches!(result, Err(Error::InvalidApprover(_)))); - } + let bob = address!("B0B0cB49ec2e96DF5F5fFB081acaE66A2cBBc2e2"); - #[motsu::test] - fn transfer_from_errors_when_invalid_receiver(contract: Erc20) { - let alice = address!("A11CEacF9aa32246d767FCCD72e02d6bCbcC375d"); + // Alice approves Bob. let one = uint!(1_U256); - contract._allowances.setter(alice).setter(msg::sender()).set(one); - let result = contract.transfer_from(alice, Address::ZERO, one); + contract.sender(alice).approve(bob, one).unwrap(); + + let result = + contract.sender(bob).transfer_from(alice, Address::ZERO, one); assert!(matches!(result, Err(Error::InvalidReceiver(_)))); } #[motsu::test] - fn transfer_from_errors_when_insufficient_allowance(contract: Erc20) { + fn errors_when_transfer_with_insufficient_allowance( + contract: Contract, + ) { let alice = address!("A11CEacF9aa32246d767FCCD72e02d6bCbcC375d"); let bob = address!("B0B0cB49ec2e96DF5F5fFB081acaE66A2cBBc2e2"); // Mint some tokens for Alice. let one = uint!(1_U256); - contract._update(Address::ZERO, alice, one).unwrap(); - assert_eq!(one, contract.balance_of(alice)); + contract.sender(alice)._update(Address::ZERO, alice, one).unwrap(); + assert_eq!(one, contract.sender(alice).balance_of(alice)); - let result = contract.transfer_from(alice, bob, one); + let result = contract.sender(alice).transfer_from(alice, bob, one); assert!(matches!(result, Err(Error::InsufficientAllowance(_)))); } #[motsu::test] - fn reads_allowance(contract: Erc20) { - let owner = msg::sender(); + fn approves_and_reads_allowance(contract: Contract) { let alice = address!("A11CEacF9aa32246d767FCCD72e02d6bCbcC375d"); + let bob = address!("B0B0cB49ec2e96DF5F5fFB081acaE66A2cBBc2e2"); - let allowance = contract.allowance(owner, alice); + let allowance = contract.sender(alice).allowance(alice, bob); assert_eq!(U256::ZERO, allowance); let one = uint!(1_U256); - contract._allowances.setter(owner).setter(alice).set(one); - let allowance = contract.allowance(owner, alice); + contract.sender(alice).approve(bob, one).unwrap(); + let allowance = contract.sender(alice).allowance(alice, bob); assert_eq!(one, allowance); } #[motsu::test] - fn approves(contract: Erc20) { + fn error_when_approve_for_invalid_spender(contract: Contract) { + // alice approves `Address::ZERO` let alice = address!("A11CEacF9aa32246d767FCCD72e02d6bCbcC375d"); - - // `msg::sender` approves Alice. let one = uint!(1_U256); - contract.approve(alice, one).unwrap(); - assert_eq!(one, contract._allowances.get(msg::sender()).get(alice)); + let result = contract.sender(alice).approve(Address::ZERO, one); + assert!(matches!(result, Err(Error::InvalidSpender(_)))); } #[motsu::test] - fn approve_errors_when_invalid_spender(contract: Erc20) { - // `msg::sender` approves `Address::ZERO`. + fn error_when_invalid_approver(contract: Contract) { + let alice = address!("A11CEacF9aa32246d767FCCD72e02d6bCbcC375d"); + let bob = address!("B0B0cB49ec2e96DF5F5fFB081acaE66A2cBBc2e2"); + let one = uint!(1_U256); - let result = contract.approve(Address::ZERO, one); - assert!(matches!(result, Err(Error::InvalidSpender(_)))); + let result = + contract.sender(alice)._approve(Address::ZERO, bob, one, false); + assert!(matches!(result, Err(Error::InvalidApprover(_)))); } #[motsu::test] @@ -933,4 +950,3 @@ mod tests { assert_eq!(actual, expected); } } -*/ diff --git a/contracts/src/token/erc20/utils/safe_erc20.rs b/contracts/src/token/erc20/utils/safe_erc20.rs index 9fb976d51..0e1c156e2 100644 --- a/contracts/src/token/erc20/utils/safe_erc20.rs +++ b/contracts/src/token/erc20/utils/safe_erc20.rs @@ -406,7 +406,7 @@ impl SafeErc20 { }) } } -/* + #[cfg(all(test, feature = "std"))] mod tests { use super::SafeErc20; @@ -440,4 +440,3 @@ mod tests { assert!(!SafeErc20::encodes_true(&[0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1])); } } -*/ From 0ac0b28d91e26a7ccf45b7466914c1abb6ecb542 Mon Sep 17 00:00:00 2001 From: Alisander Qoshqosh Date: Tue, 7 Jan 2025 16:12:06 +0400 Subject: [PATCH 067/109] bump stylus sdk v0.7.0 --- Cargo.lock | 15 +++++++++------ Cargo.toml | 11 +---------- 2 files changed, 10 insertions(+), 16 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d608e45ba..a493508c1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2514,8 +2514,9 @@ checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" [[package]] name = "mini-alloc" -version = "0.7.0-rc.1" -source = "git+https://github.com/OffchainLabs/stylus-sdk-rs?branch=rel%2F0.7.0-rc.1#c2698e7bedb8340fa11caf55ee9332a3a53e5574" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3d986fb074078dcc9a560cc3afe9edf2dcf1f577b854fb65e366c331d8c7753" dependencies = [ "cfg-if", ] @@ -3742,8 +3743,9 @@ dependencies = [ [[package]] name = "stylus-proc" -version = "0.7.0-rc.1" -source = "git+https://github.com/OffchainLabs/stylus-sdk-rs?branch=rel%2F0.7.0-rc.1#c2698e7bedb8340fa11caf55ee9332a3a53e5574" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38b0ee8d057be480a457704f982a38254e13a2a7d42bb4531132d3d440e371a6" dependencies = [ "alloy-primitives", "alloy-sol-types", @@ -3762,8 +3764,9 @@ dependencies = [ [[package]] name = "stylus-sdk" -version = "0.7.0-rc.1" -source = "git+https://github.com/OffchainLabs/stylus-sdk-rs?branch=rel%2F0.7.0-rc.1#c2698e7bedb8340fa11caf55ee9332a3a53e5574" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fec9700e00e9dfa862aad80e6b27e02e9fb0c6745f3f97f616368936faefad5f" dependencies = [ "alloy-primitives", "alloy-sol-types", diff --git a/Cargo.toml b/Cargo.toml index ed059b67b..f8e7973f8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -71,7 +71,7 @@ all = "warn" [workspace.dependencies] # Stylus SDK related -stylus-sdk = { version = "0.7.0-rc.1", default-features = false, features = ["mini-alloc"] } +stylus-sdk = { version = "0.7.0", default-features = false, features = ["mini-alloc"] } alloy = { version = "=0.7.2", features = [ "contract", @@ -148,15 +148,6 @@ default = { extend-ignore-identifiers-re = [ ] } files = { extend-exclude = [] } -# TODO#q: remove stylus sdk patch once the fix is released -[patch.crates-io.stylus-sdk] -git = "https://github.com/OffchainLabs/stylus-sdk-rs" -branch = "rel/0.7.0-rc.1" - -[patch.crates-io.stylus-proc] -git = "https://github.com/OffchainLabs/stylus-sdk-rs" -branch = "rel/0.7.0-rc.1" - # TODO#q: remove motsu patch once update is released [patch.crates-io.motsu] git = "https://github.com/OpenZeppelin/stylus-test-helpers" From 2d29ce0dd9a6c8f4539d9383765422584b0d4bcb Mon Sep 17 00:00:00 2001 From: Alisander Qoshqosh Date: Wed, 15 Jan 2025 19:57:16 +0400 Subject: [PATCH 068/109] ++ --- Cargo.lock | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index fa26f1e73..019baf2a4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2566,9 +2566,10 @@ checksum = "7843ec2de400bcbc6a6328c958dc38e5359da6e93e72e37bc5246bf1ae776389" [[package]] name = "motsu" version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8dc57234641c5dd30332b269b29ea11966496ca5b6e169eb6cf90e4092e84483" +source = "git+https://github.com/OpenZeppelin/stylus-test-helpers?branch=unit-tests%2Fmultiple-contract-deployment#2fe7239f5ea12a05e866d927c5a9407909ca7ddf" dependencies = [ + "alloy-primitives", + "alloy-sol-types", "const-hex", "dashmap 6.1.0", "motsu-proc", @@ -2580,8 +2581,7 @@ dependencies = [ [[package]] name = "motsu-proc" version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1216edabfdae92f935e07c21df8880a494afcc18267af7c8fe60cb979ecd594e" +source = "git+https://github.com/OpenZeppelin/stylus-test-helpers?branch=unit-tests%2Fmultiple-contract-deployment#2fe7239f5ea12a05e866d927c5a9407909ca7ddf" dependencies = [ "proc-macro2", "quote", @@ -3361,6 +3361,9 @@ name = "rustc-hash" version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "583034fd73374156e66797ed8e5b0d5690409c9226b22d87cb7f19821c05d152" +dependencies = [ + "rand", +] [[package]] name = "rustc-hex" From 7b39a37b0136e998b2b6c23edfdeb7b9723e1128 Mon Sep 17 00:00:00 2001 From: Alisander Qoshqosh Date: Wed, 15 Jan 2025 20:37:38 +0400 Subject: [PATCH 069/109] ++ --- contracts/src/token/erc721/mod.rs | 37 +++++++++++-------------------- 1 file changed, 13 insertions(+), 24 deletions(-) diff --git a/contracts/src/token/erc721/mod.rs b/contracts/src/token/erc721/mod.rs index 27d4138c5..4bafec906 100644 --- a/contracts/src/token/erc721/mod.rs +++ b/contracts/src/token/erc721/mod.rs @@ -1245,7 +1245,6 @@ mod tests { fn mints(contract: Contract) { let alice = Address::random(); - let initial_balance = contract .sender(alice) .balance_of(alice) @@ -1712,10 +1711,8 @@ mod tests { } #[motsu::test] - fn safe_transfers_from_with_data(contract: Erc721) { - let alice = msg::sender(); - contract._mint(alice, TOKEN_ID).expect("should mint a token to Alice"); - + fn safe_transfers_from_with_data(contract: Contract) { + let alice = Address::random(); contract .sender(alice) ._mint(alice, TOKEN_ID) @@ -1740,10 +1737,10 @@ mod tests { } #[motsu::test] - fn safe_transfers_from_with_data_approved_token(contract: Erc721) { - let alice = msg::sender(); - contract._mint(BOB, TOKEN_ID).expect("should mint token to Bob"); - contract._token_approvals.setter(TOKEN_ID).set(alice); + fn safe_transfers_from_with_data_approved_token( + contract: Contract, + ) { + let alice = Address::random(); contract .sender(alice) ._mint(BOB, TOKEN_ID) @@ -1928,17 +1925,9 @@ mod tests { } #[motsu::test] - fn approves(contract: Erc721) { - let alice = msg::sender(); - contract._mint(alice, TOKEN_ID).expect("should mint a token"); - contract - .approve(BOB, TOKEN_ID) - .expect("should approve Bob for operations on token"); - assert_eq!(contract._token_approvals.get(TOKEN_ID), BOB); - } + fn error_when_approve_for_nonexistent_token(contract: Contract) { + let alice = Address::random(); - #[motsu::test] - fn error_when_approve_for_nonexistent_token(contract: Erc721) { let err = contract .sender(alice) .approve(BOB, TOKEN_ID) @@ -2309,7 +2298,8 @@ mod tests { } #[motsu::test] - fn error_when_burn_nonexistent_token(contract: Erc721) { + fn error_when_burn_nonexistent_token(contract: Contract) { + let alice = Address::random(); let err = contract .sender(alice) ._burn(TOKEN_ID) @@ -2679,7 +2669,7 @@ mod tests { let err = contract .sender(alice) - ._set_approval_for_all(msg::sender(), invalid_operator, true) + ._set_approval_for_all(alice, invalid_operator, true) .expect_err("should not approve for all for invalid operator"); assert!(matches!( @@ -2768,14 +2758,13 @@ mod tests { receiver: Contract, ) { let alice = Address::random(); - let token_id = random_token_id(); erc721 .sender(alice) - ._safe_mint(receiver.address(), token_id, &vec![0, 1, 2, 3].into()) + ._safe_mint(receiver.address(), TOKEN_ID, &vec![0, 1, 2, 3].into()) .unwrap(); let received_token_id = receiver.sender(alice).received_token_id(); - assert_eq!(received_token_id, token_id); + assert_eq!(received_token_id, TOKEN_ID); } } From 5c0ef1a43adb9c975dccb37b24d6a0dcaf2e108b Mon Sep 17 00:00:00 2001 From: Alisander Qoshqosh Date: Wed, 15 Jan 2025 20:51:03 +0400 Subject: [PATCH 070/109] ++ --- .../src/token/erc20/extensions/flash_mint.rs | 3 +++ .../src/token/erc721/extensions/burnable.rs | 9 +++++--- .../token/erc721/extensions/consecutive.rs | 7 +++--- .../src/token/erc721/extensions/enumerable.rs | 7 +++--- .../token/erc721/extensions/uri_storage.rs | 2 +- contracts/src/token/erc721/mod.rs | 23 ------------------- 6 files changed, 16 insertions(+), 35 deletions(-) diff --git a/contracts/src/token/erc20/extensions/flash_mint.rs b/contracts/src/token/erc20/extensions/flash_mint.rs index 9f1629941..7f794acc0 100644 --- a/contracts/src/token/erc20/extensions/flash_mint.rs +++ b/contracts/src/token/erc20/extensions/flash_mint.rs @@ -350,6 +350,8 @@ impl IErc3156FlashLender for Erc20FlashMint { } } +// TODO#q: migrate flash mint tests +/* // TODO: unignore all tests once it's possible to mock contract address. // NOTE: double check that the tests assert the correct and expected things. #[cfg(all(test, feature = "std"))] @@ -451,3 +453,4 @@ mod tests { assert_eq!(result.is_err(), true); } } +*/ diff --git a/contracts/src/token/erc721/extensions/burnable.rs b/contracts/src/token/erc721/extensions/burnable.rs index 14d2d1d58..67a7f6ccd 100644 --- a/contracts/src/token/erc721/extensions/burnable.rs +++ b/contracts/src/token/erc721/extensions/burnable.rs @@ -54,17 +54,20 @@ impl IErc721Burnable for Erc721 { #[cfg(all(test, feature = "std"))] mod tests { - use alloy_primitives::{address, uint, Address}; + use alloy_primitives::{address, uint, Address, U256}; use motsu::prelude::Contract; use stylus_sdk::msg; use super::IErc721Burnable; - use crate::token::erc721::{ERC721InsufficientApproval, - ERC721NonexistentToken, Erc721, Error, IErc721, + use crate::token::erc721::{ + ERC721InsufficientApproval, ERC721NonexistentToken, Erc721, Error, + IErc721, }; const BOB: Address = address!("F4EaCDAbEf3c8f1EdE91b6f2A6840bc2E4DD3526"); + const TOKEN_ID: U256 = uint!(1_U256); + #[motsu::test] fn burns(contract: Contract) { let alice = Address::random(); diff --git a/contracts/src/token/erc721/extensions/consecutive.rs b/contracts/src/token/erc721/extensions/consecutive.rs index de2796eb7..9bb7b581e 100644 --- a/contracts/src/token/erc721/extensions/consecutive.rs +++ b/contracts/src/token/erc721/extensions/consecutive.rs @@ -824,6 +824,7 @@ mod tests { const FIRST_CONSECUTIVE_TOKEN_ID: U96 = uint!(0_U96); const MAX_BATCH_SIZE: U96 = uint!(5000_U96); const TOKEN_ID: U256 = uint!(1_U256); + const NON_CONSECUTIVE_TOKEN_ID: U256 = uint!(10001_U256); fn mint_consecutive( contract: &mut Erc721Consecutive, @@ -996,7 +997,7 @@ mod tests { // Check non-consecutive mint. contract .sender(alice) - ._mint(alice, TOKEN_ID) + ._mint(alice, NON_CONSECUTIVE_TOKEN_ID) .expect("should mint a token to Alice"); let alice_balance = contract .sender(alice) @@ -1007,7 +1008,7 @@ mod tests { // Check transfer of the token that wasn't minted consecutive. contract .sender(alice) - .transfer_from(alice, BOB, TOKEN_ID) + .transfer_from(alice, BOB, NON_CONSECUTIVE_TOKEN_ID) .expect("should transfer a token from Alice to Bob"); let alice_balance = contract .sender(alice) @@ -1392,10 +1393,8 @@ mod tests { contract: Contract, ) { let alice = Address::random(); - let token_id = random_token_id(); let err = contract .sender(alice) - .get_approved(token_id) .get_approved(TOKEN_ID) .expect_err("should not return approved for a non-existent token"); diff --git a/contracts/src/token/erc721/extensions/enumerable.rs b/contracts/src/token/erc721/extensions/enumerable.rs index ff59a8983..e7742eff7 100644 --- a/contracts/src/token/erc721/extensions/enumerable.rs +++ b/contracts/src/token/erc721/extensions/enumerable.rs @@ -333,15 +333,14 @@ impl Erc721Enumerable { #[cfg(all(test, feature = "std"))] mod tests { + use motsu::prelude::Contract; use stylus_sdk::{ alloy_primitives::{address, uint, Address, U256}, - msg, + prelude::TopLevelStorage, }; - use motsu::prelude::Contract; - use stylus_sdk::{msg, prelude::TopLevelStorage}; use super::{Erc721Enumerable, Error, IErc721Enumerable}; - use crate::token::erc721::{Erc721, IErc721}; + use crate::token::erc721::IErc721; const BOB: Address = address!("F4EaCDAbEf3c8f1EdE91b6f2A6840bc2E4DD3526"); diff --git a/contracts/src/token/erc721/extensions/uri_storage.rs b/contracts/src/token/erc721/extensions/uri_storage.rs index 85359e2bb..3218fd402 100644 --- a/contracts/src/token/erc721/extensions/uri_storage.rs +++ b/contracts/src/token/erc721/extensions/uri_storage.rs @@ -114,7 +114,7 @@ impl Erc721UriStorage { #[cfg(all(test, feature = "std"))] mod tests { - use alloy_primitives::{Address, U256}; + use alloy_primitives::{uint, Address, U256}; use motsu::prelude::Contract; use stylus_sdk::prelude::{public, storage, TopLevelStorage}; diff --git a/contracts/src/token/erc721/mod.rs b/contracts/src/token/erc721/mod.rs index 4bafec906..f765913b5 100644 --- a/contracts/src/token/erc721/mod.rs +++ b/contracts/src/token/erc721/mod.rs @@ -174,29 +174,6 @@ impl MethodError for Error { } } -stylus_sdk::stylus_proc::sol_interface! { - /// [`Erc721`] token receiver interface. - /// - /// Interface for any contract that wants to support `safe_transfers` - /// from [`Erc721`] asset contracts. - #[allow(missing_docs)] - interface IERC721Receiver { - /// Whenever an [`Erc721`] `token_id` token is transferred - /// to this contract via [`Erc721::safe_transfer_from`]. - /// - /// It must return its function selector to confirm the token transfer. - /// If any other value is returned or the interface is not implemented - /// by the recipient, the transfer will be reverted. - #[allow(missing_docs)] - function onERC721Received( - address operator, - address from, - uint256 token_id, - bytes calldata data - ) external returns (bytes4); - } -} - /// State of an [`Erc721`] token. #[storage] pub struct Erc721 { From f6c71b5d8f86e8fc13b1c6090142b4827fd51da4 Mon Sep 17 00:00:00 2001 From: Alisander Qoshqosh Date: Wed, 15 Jan 2025 22:19:15 +0400 Subject: [PATCH 071/109] ++ --- Cargo.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 019baf2a4..d214313a7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2566,7 +2566,7 @@ checksum = "7843ec2de400bcbc6a6328c958dc38e5359da6e93e72e37bc5246bf1ae776389" [[package]] name = "motsu" version = "0.3.0" -source = "git+https://github.com/OpenZeppelin/stylus-test-helpers?branch=unit-tests%2Fmultiple-contract-deployment#2fe7239f5ea12a05e866d927c5a9407909ca7ddf" +source = "git+https://github.com/OpenZeppelin/stylus-test-helpers?branch=unit-tests%2Fmultiple-contract-deployment#8ae0ebd08e03733f4f703326d25894fea24eddda" dependencies = [ "alloy-primitives", "alloy-sol-types", @@ -2581,7 +2581,7 @@ dependencies = [ [[package]] name = "motsu-proc" version = "0.3.0" -source = "git+https://github.com/OpenZeppelin/stylus-test-helpers?branch=unit-tests%2Fmultiple-contract-deployment#2fe7239f5ea12a05e866d927c5a9407909ca7ddf" +source = "git+https://github.com/OpenZeppelin/stylus-test-helpers?branch=unit-tests%2Fmultiple-contract-deployment#8ae0ebd08e03733f4f703326d25894fea24eddda" dependencies = [ "proc-macro2", "quote", From 2b042a7f7743b7768bc0208c344fc660d654f2b2 Mon Sep 17 00:00:00 2001 From: Alisander Qoshqosh Date: Thu, 16 Jan 2025 16:21:33 +0400 Subject: [PATCH 072/109] ++ --- contracts/src/token/erc1155/mod.rs | 287 +++++++++++++++++++---------- 1 file changed, 190 insertions(+), 97 deletions(-) diff --git a/contracts/src/token/erc1155/mod.rs b/contracts/src/token/erc1155/mod.rs index 5085207f0..d1585a66f 100644 --- a/contracts/src/token/erc1155/mod.rs +++ b/contracts/src/token/erc1155/mod.rs @@ -1192,10 +1192,11 @@ enum Transfer { /// * `values` - Array of all amount of tokens being transferred. Batch { ids: Vec, values: Vec }, } -/* + #[cfg(all(test, feature = "std"))] mod tests { use alloy_primitives::{address, uint, Address, U256}; + use motsu::prelude::Contract; use stylus_sdk::msg; use super::{ @@ -1263,21 +1264,22 @@ mod tests { } #[motsu::test] - fn balance_of_zero_balance(contract: Erc1155) { - let owner = msg::sender(); + fn balance_of_zero_balance(contract: Contract) { + let owner = ALICE; let token_id = random_token_ids(1)[0]; - let balance = contract.balance_of(owner, token_id); + let balance = contract.sender(ALICE).balance_of(owner, token_id); assert_eq!(U256::ZERO, balance); } #[motsu::test] - fn error_when_array_length_mismatch(contract: Erc1155) { + fn error_when_array_length_mismatch(contract: Contract) { let token_ids = random_token_ids(3); let accounts = vec![ALICE, BOB, DAVE, CHARLIE]; let ids_length = U256::from(token_ids.len()); let accounts_length = U256::from(accounts.len()); let err = contract + .sender(ALICE) .balance_of_batch(accounts, token_ids) .expect_err("should return `Error::InvalidArrayLength`"); @@ -1291,10 +1293,11 @@ mod tests { } #[motsu::test] - fn balance_of_batch_zero_balance(contract: Erc1155) { + fn balance_of_batch_zero_balance(contract: Contract) { let token_ids = random_token_ids(4); let accounts = vec![ALICE, BOB, DAVE, CHARLIE]; let balances = contract + .sender(ALICE) .balance_of_batch(accounts, token_ids) .expect("should return a vector of `U256::ZERO`"); @@ -1303,26 +1306,32 @@ mod tests { } #[motsu::test] - fn set_approval_for_all(contract: Erc1155) { - let alice = msg::sender(); - contract._operator_approvals.setter(alice).setter(BOB).set(false); + fn set_approval_for_all(contract: Contract) { + contract.init(ALICE, |contract| { + contract._operator_approvals.setter(ALICE).setter(BOB).set(false); + }); contract + .sender(ALICE) .set_approval_for_all(BOB, true) .expect("should approve Bob for operations on all Alice's tokens"); - assert!(contract.is_approved_for_all(alice, BOB)); + assert!(contract.sender(ALICE).is_approved_for_all(ALICE, BOB)); - contract.set_approval_for_all(BOB, false).expect( + contract.sender(ALICE).set_approval_for_all(BOB, false).expect( "should disapprove Bob for operations on all Alice's tokens", ); - assert!(!contract.is_approved_for_all(alice, BOB)); + assert!(!contract.sender(ALICE).is_approved_for_all(ALICE, BOB)); } #[motsu::test] - fn error_when_invalid_operator_set_approval_for_all(contract: Erc1155) { + fn error_when_invalid_operator_set_approval_for_all( + contract: Contract, + ) { + let alice = ALICE; let invalid_operator = Address::ZERO; let err = contract + .sender(alice) .set_approval_for_all(invalid_operator, true) .expect_err("should not approve for all for invalid operator"); @@ -1335,27 +1344,30 @@ mod tests { } #[motsu::test] - fn mints(contract: Erc1155) { - let alice = msg::sender(); + fn mints(contract: Contract) { + let alice = ALICE; let token_id = random_token_ids(1)[0]; let value = random_values(1)[0]; contract + .sender(alice) ._mint(alice, token_id, value, &vec![0, 1, 2, 3].into()) .expect("should mint tokens for Alice"); - let balance = contract.balance_of(alice, token_id); + let balance = contract.sender(alice).balance_of(alice, token_id); assert_eq!(balance, value); } #[motsu::test] - fn error_when_mints_to_invalid_receiver(contract: Erc1155) { + fn error_when_mints_to_invalid_receiver(contract: Contract) { + let alice = ALICE; let invalid_receiver = Address::ZERO; let token_id = random_token_ids(1)[0]; let value = random_values(1)[0]; let err = contract + .sender(alice) ._mint(invalid_receiver, token_id, value, &vec![0, 1, 2, 3].into()) .expect_err("should not mint tokens for invalid receiver"); @@ -1368,13 +1380,15 @@ mod tests { } #[motsu::test] - fn mints_batch(contract: Erc1155) { + fn mints_batch(contract: Contract) { + let alice = ALICE; let token_ids = random_token_ids(4); let values = random_values(4); contract + .sender(alice) ._mint_batch( - ALICE, + alice, token_ids.clone(), values.clone(), &vec![0, 1, 2, 3].into(), @@ -1382,47 +1396,59 @@ mod tests { .expect("should batch mint tokens"); token_ids.iter().zip(values.iter()).for_each(|(&token_id, &value)| { - assert_eq!(value, contract.balance_of(ALICE, token_id)); + assert_eq!( + value, + contract.sender(alice).balance_of(alice, token_id) + ); }); let balances = contract - .balance_of_batch(vec![ALICE; 4], token_ids.clone()) + .sender(alice) + .balance_of_batch(vec![alice; 4], token_ids.clone()) .expect("should return balances"); assert_eq!(values, balances); } #[motsu::test] - fn mints_batch_same_token(contract: Erc1155) { + fn mints_batch_same_token(contract: Contract) { + let alice = ALICE; let token_id = uint!(1_U256); let values = random_values(4); let expected_balance: U256 = values.iter().sum(); contract + .sender(alice) ._mint_batch( - ALICE, + alice, vec![token_id; 4], values.clone(), &vec![0, 1, 2, 3].into(), ) .expect("should batch mint tokens"); - assert_eq!(expected_balance, contract.balance_of(ALICE, token_id)); + assert_eq!( + expected_balance, + contract.sender(alice).balance_of(alice, token_id) + ); let balances = contract - .balance_of_batch(vec![ALICE; 4], vec![token_id; 4]) + .sender(alice) + .balance_of_batch(vec![alice; 4], vec![token_id; 4]) .expect("should return balances"); assert_eq!(vec![expected_balance; 4], balances); } #[motsu::test] - fn error_when_batch_mints_to_invalid_receiver(contract: Erc1155) { + fn error_when_batch_mints_to_invalid_receiver(contract: Contract) { + let alice = ALICE; let token_ids = random_token_ids(1); let values = random_values(1); let invalid_receiver = Address::ZERO; let err = contract + .sender(alice) ._mint_batch( invalid_receiver, token_ids, @@ -1440,12 +1466,14 @@ mod tests { } #[motsu::test] - fn error_when_batch_mints_not_equal_arrays(contract: Erc1155) { + fn error_when_batch_mints_not_equal_arrays(contract: Contract) { + let alice = ALICE; let token_ids = random_token_ids(3); let values = random_values(4); let err = contract - ._mint_batch(ALICE, token_ids, values, &vec![0, 1, 2, 3].into()) + .sender(alice) + ._mint_batch(alice, token_ids, values, &vec![0, 1, 2, 3].into()) .expect_err( "should not batch mint tokens when not equal array lengths", ); @@ -1459,24 +1487,33 @@ mod tests { } #[motsu::test] - fn burns(contract: Erc1155) { - let (token_ids, values) = init(contract, ALICE, 1); + fn burns(contract: Contract) { + let alice = ALICE; + let (token_ids, values) = + contract.init(alice, |contract| init(contract, alice, 1)); + let token_id = token_ids[0]; let value = values[0]; - contract._burn(ALICE, token_id, value).expect("should burn tokens"); + contract + .sender(alice) + ._burn(alice, token_id, value) + .expect("should burn tokens"); - let balances = contract.balance_of(ALICE, token_id); + let balances = contract.sender(alice).balance_of(alice, token_id); assert_eq!(U256::ZERO, balances); } #[motsu::test] - fn error_when_burns_from_invalid_sender(contract: Erc1155) { - let (token_ids, values) = init(contract, ALICE, 1); + fn error_when_burns_from_invalid_sender(contract: Contract) { + let alice = ALICE; + let (token_ids, values) = + contract.init(alice, |contract| init(contract, alice, 1)); let invalid_sender = Address::ZERO; let err = contract + .sender(alice) ._burn(invalid_sender, token_ids[0], values[0]) .expect_err("should not burn token for invalid sender"); @@ -1489,11 +1526,14 @@ mod tests { } #[motsu::test] - fn error_when_burns_with_insufficient_balance(contract: Erc1155) { - let (token_ids, values) = init(contract, ALICE, 1); + fn error_when_burns_with_insufficient_balance(contract: Contract) { + let alice = ALICE; + let (token_ids, values) = + contract.init(alice, |contract| init(contract, alice, 1)); let err = contract - ._burn(ALICE, token_ids[0], values[0] + uint!(1_U256)) + .sender(alice) + ._burn(alice, token_ids[0], values[0] + uint!(1_U256)) .expect_err("should not burn token when insufficient balance"); assert!(matches!( @@ -1508,32 +1548,39 @@ mod tests { } #[motsu::test] - fn burns_batch(contract: Erc1155) { - let (token_ids, values) = init(contract, ALICE, 4); + fn burns_batch(contract: Contract) { + let alice = ALICE; + let (token_ids, values) = + contract.init(alice, |contract| init(contract, alice, 1)); contract - ._burn_batch(ALICE, token_ids.clone(), values.clone()) + .sender(alice) + ._burn_batch(alice, token_ids.clone(), values.clone()) .expect("should batch burn tokens"); let balances = contract - .balance_of_batch(vec![ALICE; 4], token_ids.clone()) + .sender(alice) + .balance_of_batch(vec![alice; 4], token_ids.clone()) .expect("should return balances"); assert_eq!(vec![U256::ZERO; 4], balances); } #[motsu::test] - fn burns_batch_same_token(contract: Erc1155) { + fn burns_batch_same_token(contract: Contract) { + let alice = ALICE; let token_id = uint!(1_U256); let value = uint!(80_U256); contract - ._mint(ALICE, token_id, value, &vec![0, 1, 2, 3].into()) + .sender(alice) + ._mint(alice, token_id, value, &vec![0, 1, 2, 3].into()) .expect("should mint token"); contract + .sender(alice) ._burn_batch( - ALICE, + alice, vec![token_id; 4], vec![ uint!(20_U256), @@ -1544,15 +1591,21 @@ mod tests { ) .expect("should batch burn tokens"); - assert_eq!(U256::ZERO, contract.balance_of(ALICE, token_id)); + assert_eq!( + U256::ZERO, + contract.sender(alice).balance_of(alice, token_id) + ); } #[motsu::test] - fn error_when_batch_burns_from_invalid_sender(contract: Erc1155) { - let (token_ids, values) = init(contract, ALICE, 4); + fn error_when_batch_burns_from_invalid_sender(contract: Contract) { + let alice = ALICE; + let (token_ids, values) = + contract.init(alice, |contract| init(contract, alice, 4)); let invalid_sender = Address::ZERO; let err = contract + .sender(alice) ._burn_batch(invalid_sender, token_ids, values) .expect_err("should not batch burn tokens for invalid sender"); @@ -1565,8 +1618,11 @@ mod tests { } #[motsu::test] - fn error_when_batch_burns_with_insufficient_balance(contract: Erc1155) { - let (token_ids, values) = init(contract, ALICE, 4); + fn error_when_batch_burns_with_insufficient_balance( + contract: Contract, + ) { + let (token_ids, values) = + contract.init(alice, |contract| init(contract, alice, 4)); let err = contract ._burn_batch( @@ -1590,8 +1646,9 @@ mod tests { } #[motsu::test] - fn error_when_batch_burns_not_equal_arrays(contract: Erc1155) { - let (token_ids, values) = init(contract, ALICE, 3); + fn error_when_batch_burns_not_equal_arrays(contract: Contract) { + let (token_ids, values) = + contract.init(alice, |contract| init(contract, alice, 3)); let err = contract ._burn_batch(ALICE, token_ids, append(values, 4)) @@ -1608,9 +1665,10 @@ mod tests { } #[motsu::test] - fn safe_transfer_from(contract: Erc1155) { + fn safe_transfer_from(contract: Contract) { let alice = msg::sender(); - let (token_ids, values) = init(contract, BOB, 2); + let (token_ids, values) = + contract.init(alice, |contract| init(contract, BOB, 2)); let amount_one = values[0] - uint!(1_U256); let amount_two = values[1] - uint!(1_U256); @@ -1643,9 +1701,12 @@ mod tests { } #[motsu::test] - fn error_when_invalid_receiver_safe_transfer_from(contract: Erc1155) { + fn error_when_invalid_receiver_safe_transfer_from( + contract: Contract, + ) { let alice = msg::sender(); - let (token_ids, values) = init(contract, alice, 1); + let (token_ids, values) = + contract.init(alice, |contract| init(contract, alice, 1)); let invalid_receiver = Address::ZERO; let err = contract @@ -1667,9 +1728,12 @@ mod tests { } #[motsu::test] - fn error_when_invalid_sender_safe_transfer_from(contract: Erc1155) { + fn error_when_invalid_sender_safe_transfer_from( + contract: Contract, + ) { let alice = msg::sender(); - let (token_ids, values) = init(contract, alice, 1); + let (token_ids, values) = + contract.init(alice, |contract| init(contract, alice, 1)); let invalid_sender = Address::ZERO; contract @@ -1697,8 +1761,11 @@ mod tests { } #[motsu::test] - fn error_when_missing_approval_safe_transfer_from(contract: Erc1155) { - let (token_ids, values) = init(contract, ALICE, 1); + fn error_when_missing_approval_safe_transfer_from( + contract: Contract, + ) { + let (token_ids, values) = + contract.init(alice, |contract| init(contract, alice, 1)); let err = contract .safe_transfer_from( @@ -1720,10 +1787,12 @@ mod tests { } #[motsu::test] - fn error_when_insufficient_balance_safe_transfer_from(contract: Erc1155) { + fn error_when_insufficient_balance_safe_transfer_from( + contract: Contract, + ) { let alice = msg::sender(); - let (token_ids, values) = init(contract, BOB, 1); - + let (token_ids, values) = + contract.init(alice, |contract| init(contract, BOB, 1)); contract._operator_approvals.setter(BOB).setter(alice).set(true); let err = contract @@ -1748,9 +1817,10 @@ mod tests { } #[motsu::test] - fn safe_transfer_from_with_data(contract: Erc1155) { + fn safe_transfer_from_with_data(contract: Contract) { let alice = msg::sender(); - let (token_ids, values) = init(contract, DAVE, 1); + let (token_ids, values) = + contract.init(alice, |contract| init(contract, DAVE, 1)); contract._operator_approvals.setter(DAVE).setter(alice).set(true); @@ -1771,9 +1841,10 @@ mod tests { #[motsu::test] fn error_when_invalid_receiver_safe_transfer_from_with_data( - contract: Erc1155, + contract: Contract, ) { - let (token_ids, values) = init(contract, DAVE, 1); + let (token_ids, values) = + contract.init(alice, |contract| init(contract, DAVE, 1)); let invalid_receiver = Address::ZERO; let err = contract @@ -1796,10 +1867,11 @@ mod tests { #[motsu::test] fn error_when_invalid_sender_safe_transfer_from_with_data( - contract: Erc1155, + contract: Contract, ) { let alice = msg::sender(); - let (token_ids, values) = init(contract, alice, 1); + let (token_ids, values) = + contract.init(alice, |contract| init(contract, alice, 1)); let invalid_sender = Address::ZERO; contract @@ -1828,9 +1900,10 @@ mod tests { #[motsu::test] fn error_when_missing_approval_safe_transfer_from_with_data( - contract: Erc1155, + contract: Contract, ) { - let (token_ids, values) = init(contract, ALICE, 1); + let (token_ids, values) = + contract.init(alice, |contract| init(contract, alice, 1)); let err = contract .safe_transfer_from( @@ -1853,10 +1926,11 @@ mod tests { #[motsu::test] fn error_when_insufficient_balance_safe_transfer_from_with_data( - contract: Erc1155, + contract: Contract, ) { let alice = msg::sender(); - let (token_ids, values) = init(contract, BOB, 1); + let (token_ids, values) = + contract.init(alice, |contract| init(contract, bob, 1)); contract._operator_approvals.setter(BOB).setter(alice).set(true); @@ -1882,9 +1956,10 @@ mod tests { } #[motsu::test] - fn safe_batch_transfer_from(contract: Erc1155) { + fn safe_batch_transfer_from(contract: Contract) { let alice = msg::sender(); - let (token_ids, values) = init(contract, DAVE, 2); + let (token_ids, values) = + contract.init(alice, |contract| init(contract, dave, 2)); let amount_one = values[0] - uint!(1_U256); let amount_two = values[1] - uint!(1_U256); @@ -1908,9 +1983,12 @@ mod tests { } #[motsu::test] - fn error_when_invalid_receiver_safe_batch_transfer_from(contract: Erc1155) { + fn error_when_invalid_receiver_safe_batch_transfer_from( + contract: Contract, + ) { let alice = msg::sender(); - let (token_ids, values) = init(contract, alice, 4); + let (token_ids, values) = + contract.init(alice, |contract| init(contract, alice, 4)); let invalid_receiver = Address::ZERO; let err = contract @@ -1932,9 +2010,12 @@ mod tests { } #[motsu::test] - fn error_when_invalid_sender_safe_batch_transfer_from(contract: Erc1155) { + fn error_when_invalid_sender_safe_batch_transfer_from( + contract: Contract, + ) { let alice = msg::sender(); - let (token_ids, values) = init(contract, alice, 4); + let (token_ids, values) = + contract.init(alice, |contract| init(contract, alice, 4)); let invalid_sender = Address::ZERO; contract @@ -1962,8 +2043,11 @@ mod tests { } #[motsu::test] - fn error_when_missing_approval_safe_batch_transfer_from(contract: Erc1155) { - let (token_ids, values) = init(contract, ALICE, 2); + fn error_when_missing_approval_safe_batch_transfer_from( + contract: Contract, + ) { + let (token_ids, values) = + contract.init(alice, |contract| init(contract, alice, 2)); let err = contract .safe_batch_transfer_from( @@ -1986,10 +2070,11 @@ mod tests { #[motsu::test] fn error_when_insufficient_balance_safe_batch_transfer_from( - contract: Erc1155, + contract: Contract, ) { let alice = msg::sender(); - let (token_ids, values) = init(contract, CHARLIE, 2); + let (token_ids, values) = + contract.init(alice, |contract| init(contract, CHARLIE, 2)); contract._operator_approvals.setter(CHARLIE).setter(alice).set(true); @@ -2015,9 +2100,12 @@ mod tests { } #[motsu::test] - fn error_when_not_equal_arrays_safe_batch_transfer_from(contract: Erc1155) { + fn error_when_not_equal_arrays_safe_batch_transfer_from( + contract: Contract, + ) { let alice = msg::sender(); - let (token_ids, values) = init(contract, alice, 4); + let (token_ids, values) = + contract.init(alice, |contract| init(contract, alice, 4)); contract._operator_approvals.setter(DAVE).setter(alice).set(true); @@ -2042,9 +2130,10 @@ mod tests { } #[motsu::test] - fn safe_batch_transfer_from_with_data(contract: Erc1155) { + fn safe_batch_transfer_from_with_data(contract: Contract) { let alice = msg::sender(); - let (token_ids, values) = init(contract, DAVE, 2); + let (token_ids, values) = + contract.init(alice, |contract| init(contract, DAVE, 2)); contract._operator_approvals.setter(DAVE).setter(alice).set(true); @@ -2067,10 +2156,11 @@ mod tests { #[motsu::test] fn error_when_invalid_receiver_safe_batch_transfer_from_with_data( - contract: Erc1155, + contract: Contract, ) { let alice = msg::sender(); - let (token_ids, values) = init(contract, alice, 4); + let (token_ids, values) = + contract.init(alice, |contract| init(contract, alice, 4)); let invalid_receiver = Address::ZERO; let err = contract @@ -2093,10 +2183,11 @@ mod tests { #[motsu::test] fn error_when_invalid_sender_safe_batch_transfer_from_with_data( - contract: Erc1155, + contract: Contract, ) { let alice = msg::sender(); - let (token_ids, values) = init(contract, alice, 4); + let (token_ids, values) = + contract.init(alice, |contract| init(contract, alice, 4)); let invalid_sender = Address::ZERO; contract @@ -2125,9 +2216,10 @@ mod tests { #[motsu::test] fn error_when_missing_approval_safe_batch_transfer_from_with_data( - contract: Erc1155, + contract: Contract, ) { - let (token_ids, values) = init(contract, ALICE, 2); + let (token_ids, values) = + contract.init(alice, |contract| init(contract, alice, 2)); let err = contract .safe_batch_transfer_from( @@ -2150,10 +2242,11 @@ mod tests { #[motsu::test] fn error_when_insufficient_balance_safe_batch_transfer_from_with_data( - contract: Erc1155, + contract: Contract, ) { let alice = msg::sender(); - let (token_ids, values) = init(contract, CHARLIE, 2); + let (token_ids, values) = + contract.init(alice, |contract| init(contract, CHARLIE, 2)); contract._operator_approvals.setter(CHARLIE).setter(alice).set(true); @@ -2180,10 +2273,11 @@ mod tests { #[motsu::test] fn error_when_not_equal_arrays_safe_batch_transfer_from_with_data( - contract: Erc1155, + contract: Contract, ) { let alice = msg::sender(); - let (token_ids, values) = init(contract, alice, 4); + let (token_ids, values) = + contract.init(alice, |contract| init(contract, alice, 4)); contract._operator_approvals.setter(DAVE).setter(alice).set(true); @@ -2218,4 +2312,3 @@ mod tests { assert_eq!(actual, expected); } } -*/ From 1aba40b6e9b928b605a121fd54fd4a6297c57e1b Mon Sep 17 00:00:00 2001 From: Alisander Qoshqosh Date: Thu, 16 Jan 2025 18:30:16 +0400 Subject: [PATCH 073/109] ++ --- contracts/src/token/erc1155/mod.rs | 118 ++++++++++++++++++++--------- 1 file changed, 82 insertions(+), 36 deletions(-) diff --git a/contracts/src/token/erc1155/mod.rs b/contracts/src/token/erc1155/mod.rs index d1585a66f..eb42bfdcf 100644 --- a/contracts/src/token/erc1155/mod.rs +++ b/contracts/src/token/erc1155/mod.rs @@ -1621,10 +1621,12 @@ mod tests { fn error_when_batch_burns_with_insufficient_balance( contract: Contract, ) { + let alice = ALICE; let (token_ids, values) = contract.init(alice, |contract| init(contract, alice, 4)); let err = contract + .sender(ALICE) ._burn_batch( ALICE, token_ids.clone(), @@ -1647,11 +1649,13 @@ mod tests { #[motsu::test] fn error_when_batch_burns_not_equal_arrays(contract: Contract) { + let alice = ALICE; let (token_ids, values) = contract.init(alice, |contract| init(contract, alice, 3)); let err = contract - ._burn_batch(ALICE, token_ids, append(values, 4)) + .sender(alice) + ._burn_batch(alice, token_ids, append(values, 4)) .expect_err( "should not batch burn tokens when not equal array lengths", ); @@ -1666,15 +1670,19 @@ mod tests { #[motsu::test] fn safe_transfer_from(contract: Contract) { - let alice = msg::sender(); + let alice = ALICE; let (token_ids, values) = contract.init(alice, |contract| init(contract, BOB, 2)); let amount_one = values[0] - uint!(1_U256); let amount_two = values[1] - uint!(1_U256); - contract._operator_approvals.setter(BOB).setter(alice).set(true); + contract + .sender(BOB) + .set_approval_for_all(alice, true) + .expect("should approve Bob's tokens to Alice"); contract + .sender(alice) .safe_transfer_from( BOB, DAVE, @@ -1684,6 +1692,7 @@ mod tests { ) .expect("should transfer tokens from Alice to Bob"); contract + .sender(alice) .safe_transfer_from( BOB, DAVE, @@ -1693,8 +1702,10 @@ mod tests { ) .expect("should transfer tokens from Alice to Bob"); - let balance_id_one = contract.balance_of(DAVE, token_ids[0]); - let balance_id_two = contract.balance_of(DAVE, token_ids[1]); + let balance_id_one = + contract.sender(alice).balance_of(DAVE, token_ids[0]); + let balance_id_two = + contract.sender(alice).balance_of(DAVE, token_ids[1]); assert_eq!(amount_one, balance_id_one); assert_eq!(amount_two, balance_id_two); @@ -1704,12 +1715,13 @@ mod tests { fn error_when_invalid_receiver_safe_transfer_from( contract: Contract, ) { - let alice = msg::sender(); + let alice = ALICE; let (token_ids, values) = contract.init(alice, |contract| init(contract, alice, 1)); let invalid_receiver = Address::ZERO; let err = contract + .sender(alice) .safe_transfer_from( alice, invalid_receiver, @@ -1727,7 +1739,8 @@ mod tests { )); } - #[motsu::test] + // TODO#q: fix this test + /*#[motsu::test] fn error_when_invalid_sender_safe_transfer_from( contract: Contract, ) { @@ -1737,12 +1750,12 @@ mod tests { let invalid_sender = Address::ZERO; contract - ._operator_approvals - .setter(invalid_sender) - .setter(alice) - .set(true); + .sender(alice) + ._set_approval_for_all(invalid_sender, alice, true) + .expect("should approve Bob's tokens to Alice"); let err = contract + .sender(alice) .safe_transfer_from( invalid_sender, BOB, @@ -1758,19 +1771,23 @@ mod tests { sender }) if sender == invalid_sender )); - } + }*/ #[motsu::test] fn error_when_missing_approval_safe_transfer_from( contract: Contract, ) { + let alice = ALICE; + let bob = BOB; + let (token_ids, values) = contract.init(alice, |contract| init(contract, alice, 1)); let err = contract + .sender(alice) .safe_transfer_from( - ALICE, - BOB, + alice, + bob, token_ids[0], values[0], vec![].into(), @@ -1790,12 +1807,16 @@ mod tests { fn error_when_insufficient_balance_safe_transfer_from( contract: Contract, ) { - let alice = msg::sender(); + let alice = ALICE; let (token_ids, values) = contract.init(alice, |contract| init(contract, BOB, 1)); - contract._operator_approvals.setter(BOB).setter(alice).set(true); + contract + .sender(BOB) + .set_approval_for_all(alice, true) + .expect("should approve Bob's tokens to Alice"); let err = contract + .sender(alice) .safe_transfer_from( BOB, DAVE, @@ -1822,7 +1843,10 @@ mod tests { let (token_ids, values) = contract.init(alice, |contract| init(contract, DAVE, 1)); - contract._operator_approvals.setter(DAVE).setter(alice).set(true); + contract + .sender(DAVE) + .set_approval_for_all(alice, true) + .expect("should approve Dave's tokens to Alice"); contract .safe_transfer_from( @@ -1865,6 +1889,7 @@ mod tests { )); } + // TODO#q: fix this test #[motsu::test] fn error_when_invalid_sender_safe_transfer_from_with_data( contract: Contract, @@ -1875,12 +1900,12 @@ mod tests { let invalid_sender = Address::ZERO; contract - ._operator_approvals - .setter(invalid_sender) - .setter(alice) - .set(true); + .sender(invalid_sender) + .set_approval_for_all(alice, true) + .unwrap(); let err = contract + .sender(alice) .safe_transfer_from( invalid_sender, CHARLIE, @@ -1932,7 +1957,10 @@ mod tests { let (token_ids, values) = contract.init(alice, |contract| init(contract, bob, 1)); - contract._operator_approvals.setter(BOB).setter(alice).set(true); + contract + .sender(BOB) + .set_approval_for_all(alice, true) + .expect("should approve Bob's tokens to Alice"); let err = contract .safe_transfer_from( @@ -1963,7 +1991,10 @@ mod tests { let amount_one = values[0] - uint!(1_U256); let amount_two = values[1] - uint!(1_U256); - contract._operator_approvals.setter(DAVE).setter(alice).set(true); + contract + .sender(DAVE) + .set_approval_for_all(alice, true) + .expect("should approve Dave's tokens to Alice"); contract .safe_batch_transfer_from( @@ -2009,6 +2040,7 @@ mod tests { )); } + // TODO#q: fix this test #[motsu::test] fn error_when_invalid_sender_safe_batch_transfer_from( contract: Contract, @@ -2019,10 +2051,9 @@ mod tests { let invalid_sender = Address::ZERO; contract - ._operator_approvals - .setter(invalid_sender) - .setter(alice) - .set(true); + .sender(invalid_sender) + .set_approval_for_all(alice, true) + .unwrap(); let err = contract .safe_batch_transfer_from( @@ -2076,7 +2107,10 @@ mod tests { let (token_ids, values) = contract.init(alice, |contract| init(contract, CHARLIE, 2)); - contract._operator_approvals.setter(CHARLIE).setter(alice).set(true); + contract + .sender(CHARLIE) + .set_approval_for_all(alice, true) + .expect("should approve Charlie's tokens to Alice"); let err = contract .safe_batch_transfer_from( @@ -2107,7 +2141,10 @@ mod tests { let (token_ids, values) = contract.init(alice, |contract| init(contract, alice, 4)); - contract._operator_approvals.setter(DAVE).setter(alice).set(true); + contract + .sender(DAVE) + .set_approval_for_all(alice, true) + .expect("should approve Dave's tokens to Alice"); let err = contract .safe_batch_transfer_from( @@ -2135,7 +2172,10 @@ mod tests { let (token_ids, values) = contract.init(alice, |contract| init(contract, DAVE, 2)); - contract._operator_approvals.setter(DAVE).setter(alice).set(true); + contract + .sender(DAVE) + .set_approval_for_all(alice, true) + .expect("should approve Dave's tokens to Alice"); contract .safe_batch_transfer_from( @@ -2181,6 +2221,7 @@ mod tests { )); } + // TODO#q: fix this test #[motsu::test] fn error_when_invalid_sender_safe_batch_transfer_from_with_data( contract: Contract, @@ -2191,10 +2232,9 @@ mod tests { let invalid_sender = Address::ZERO; contract - ._operator_approvals - .setter(invalid_sender) - .setter(alice) - .set(true); + .sender(invalid_sender) + .set_approval_for_all(alice, true) + .unwrap(); let err = contract .safe_batch_transfer_from( @@ -2248,7 +2288,10 @@ mod tests { let (token_ids, values) = contract.init(alice, |contract| init(contract, CHARLIE, 2)); - contract._operator_approvals.setter(CHARLIE).setter(alice).set(true); + contract + .sender(CHARLIE) + .set_approval_for_all(alice, true) + .expect("should approve Charlie's tokens to Alice"); let err = contract .safe_batch_transfer_from( @@ -2279,7 +2322,10 @@ mod tests { let (token_ids, values) = contract.init(alice, |contract| init(contract, alice, 4)); - contract._operator_approvals.setter(DAVE).setter(alice).set(true); + contract + .sender(DAVE) + .set_approval_for_all(alice, true) + .expect("should approve Dave's tokens to Alice"); let err = contract .safe_batch_transfer_from( From eedad10401f855360d6a2ea5f0e11459bccf2469 Mon Sep 17 00:00:00 2001 From: Alisander Qoshqosh Date: Thu, 16 Jan 2025 21:37:43 +0400 Subject: [PATCH 074/109] ++ --- contracts/src/token/erc1155/mod.rs | 258 +++++++++++------- .../src/token/erc721/extensions/enumerable.rs | 2 +- 2 files changed, 165 insertions(+), 95 deletions(-) diff --git a/contracts/src/token/erc1155/mod.rs b/contracts/src/token/erc1155/mod.rs index eb42bfdcf..58b50acf8 100644 --- a/contracts/src/token/erc1155/mod.rs +++ b/contracts/src/token/erc1155/mod.rs @@ -1307,20 +1307,23 @@ mod tests { #[motsu::test] fn set_approval_for_all(contract: Contract) { - contract.init(ALICE, |contract| { - contract._operator_approvals.setter(ALICE).setter(BOB).set(false); + let alice = ALICE; + let bob = BOB; + + contract.init(alice, |contract| { + contract._operator_approvals.setter(alice).setter(bob).set(false); }); contract - .sender(ALICE) - .set_approval_for_all(BOB, true) + .sender(alice) + .set_approval_for_all(bob, true) .expect("should approve Bob for operations on all Alice's tokens"); - assert!(contract.sender(ALICE).is_approved_for_all(ALICE, BOB)); + assert!(contract.sender(alice).is_approved_for_all(alice, bob)); - contract.sender(ALICE).set_approval_for_all(BOB, false).expect( + contract.sender(alice).set_approval_for_all(bob, false).expect( "should disapprove Bob for operations on all Alice's tokens", ); - assert!(!contract.sender(ALICE).is_approved_for_all(ALICE, BOB)); + assert!(!contract.sender(alice).is_approved_for_all(alice, bob)); } #[motsu::test] @@ -1626,9 +1629,9 @@ mod tests { contract.init(alice, |contract| init(contract, alice, 4)); let err = contract - .sender(ALICE) + .sender(alice) ._burn_batch( - ALICE, + alice, token_ids.clone(), values.clone().into_iter().map(|x| x + uint!(1_U256)).collect(), ) @@ -1671,21 +1674,24 @@ mod tests { #[motsu::test] fn safe_transfer_from(contract: Contract) { let alice = ALICE; + let bob = BOB; + let dave = DAVE; + let (token_ids, values) = - contract.init(alice, |contract| init(contract, BOB, 2)); + contract.init(alice, |contract| init(contract, bob, 2)); let amount_one = values[0] - uint!(1_U256); let amount_two = values[1] - uint!(1_U256); contract - .sender(BOB) + .sender(bob) .set_approval_for_all(alice, true) .expect("should approve Bob's tokens to Alice"); contract .sender(alice) .safe_transfer_from( - BOB, - DAVE, + bob, + dave, token_ids[0], amount_one, vec![].into(), @@ -1694,8 +1700,8 @@ mod tests { contract .sender(alice) .safe_transfer_from( - BOB, - DAVE, + bob, + dave, token_ids[1], amount_two, vec![].into(), @@ -1703,9 +1709,9 @@ mod tests { .expect("should transfer tokens from Alice to Bob"); let balance_id_one = - contract.sender(alice).balance_of(DAVE, token_ids[0]); + contract.sender(alice).balance_of(dave, token_ids[0]); let balance_id_two = - contract.sender(alice).balance_of(DAVE, token_ids[1]); + contract.sender(alice).balance_of(dave, token_ids[1]); assert_eq!(amount_one, balance_id_one); assert_eq!(amount_two, balance_id_two); @@ -1739,7 +1745,7 @@ mod tests { )); } - // TODO#q: fix this test + // TODO#q: fix test error_when_invalid_sender_safe_transfer_from /*#[motsu::test] fn error_when_invalid_sender_safe_transfer_from( contract: Contract, @@ -1784,7 +1790,7 @@ mod tests { contract.init(alice, |contract| init(contract, alice, 1)); let err = contract - .sender(alice) + .sender(bob) .safe_transfer_from( alice, bob, @@ -1799,7 +1805,7 @@ mod tests { Error::MissingApprovalForAll(ERC1155MissingApprovalForAll { operator, owner - }) if operator == msg::sender() && owner == ALICE + }) if operator == bob && owner == alice )); } @@ -1808,18 +1814,21 @@ mod tests { contract: Contract, ) { let alice = ALICE; + let bob = BOB; + let dave = DAVE; + let (token_ids, values) = - contract.init(alice, |contract| init(contract, BOB, 1)); + contract.init(alice, |contract| init(contract, bob, 1)); contract - .sender(BOB) + .sender(bob) .set_approval_for_all(alice, true) .expect("should approve Bob's tokens to Alice"); let err = contract .sender(alice) .safe_transfer_from( - BOB, - DAVE, + bob, + dave, token_ids[0], values[0] + uint!(1_U256), vec![].into(), @@ -1833,32 +1842,36 @@ mod tests { balance, needed, token_id - }) if sender == BOB && balance == values[0] && needed == values[0] + uint!(1_U256) && token_id == token_ids[0] + }) if sender == bob && balance == values[0] && needed == values[0] + uint!(1_U256) && token_id == token_ids[0] )); } #[motsu::test] fn safe_transfer_from_with_data(contract: Contract) { - let alice = msg::sender(); + let alice = ALICE; + let dave = DAVE; + let charlie = CHARLIE; + let (token_ids, values) = - contract.init(alice, |contract| init(contract, DAVE, 1)); + contract.init(alice, |contract| init(contract, dave, 1)); contract - .sender(DAVE) + .sender(dave) .set_approval_for_all(alice, true) .expect("should approve Dave's tokens to Alice"); contract + .sender(alice) .safe_transfer_from( - DAVE, - CHARLIE, + dave, + charlie, token_ids[0], values[0], vec![0, 1, 2, 3].into(), ) .expect("should transfer tokens from Alice to Bob"); - let balance = contract.balance_of(CHARLIE, token_ids[0]); + let balance = contract.sender(alice).balance_of(charlie, token_ids[0]); assert_eq!(values[0], balance); } @@ -1867,13 +1880,17 @@ mod tests { fn error_when_invalid_receiver_safe_transfer_from_with_data( contract: Contract, ) { + let alice = ALICE; + let dave = DAVE; + let (token_ids, values) = - contract.init(alice, |contract| init(contract, DAVE, 1)); + contract.init(alice, |contract| init(contract, dave, 1)); let invalid_receiver = Address::ZERO; let err = contract + .sender(alice) .do_safe_transfer_from( - DAVE, + dave, invalid_receiver, token_ids, values, @@ -1889,8 +1906,8 @@ mod tests { )); } - // TODO#q: fix this test - #[motsu::test] + // TODO#q: fix test error_when_invalid_sender_safe_transfer_from_with_data + /*#[motsu::test] fn error_when_invalid_sender_safe_transfer_from_with_data( contract: Contract, ) { @@ -1921,19 +1938,23 @@ mod tests { sender }) if sender == invalid_sender )); - } + }*/ #[motsu::test] fn error_when_missing_approval_safe_transfer_from_with_data( contract: Contract, ) { + let alice = ALICE; + let bob = BOB; + let (token_ids, values) = contract.init(alice, |contract| init(contract, alice, 1)); let err = contract + .sender(bob) .safe_transfer_from( - ALICE, - BOB, + alice, + bob, token_ids[0], values[0], vec![0, 1, 2, 3].into(), @@ -1945,7 +1966,7 @@ mod tests { Error::MissingApprovalForAll(ERC1155MissingApprovalForAll { operator, owner - }) if operator == msg::sender() && owner == ALICE + }) if operator == bob && owner == alice )); } @@ -1953,19 +1974,23 @@ mod tests { fn error_when_insufficient_balance_safe_transfer_from_with_data( contract: Contract, ) { - let alice = msg::sender(); + let alice = ALICE; + let bob = BOB; + let dave = DAVE; + let (token_ids, values) = contract.init(alice, |contract| init(contract, bob, 1)); contract - .sender(BOB) + .sender(bob) .set_approval_for_all(alice, true) .expect("should approve Bob's tokens to Alice"); let err = contract + .sender(alice) .safe_transfer_from( - BOB, - DAVE, + bob, + dave, token_ids[0], values[0] + uint!(1_U256), vec![0, 1, 2, 3].into(), @@ -1979,35 +2004,41 @@ mod tests { balance, needed, token_id - }) if sender == BOB && balance == values[0] && needed == values[0] + uint!(1_U256) && token_id == token_ids[0] + }) if sender == bob && balance == values[0] && needed == values[0] + uint!(1_U256) && token_id == token_ids[0] )); } #[motsu::test] fn safe_batch_transfer_from(contract: Contract) { - let alice = msg::sender(); + let alice = ALICE; + let bob = BOB; + let dave = DAVE; + let (token_ids, values) = contract.init(alice, |contract| init(contract, dave, 2)); let amount_one = values[0] - uint!(1_U256); let amount_two = values[1] - uint!(1_U256); contract - .sender(DAVE) + .sender(dave) .set_approval_for_all(alice, true) .expect("should approve Dave's tokens to Alice"); contract + .sender(alice) .safe_batch_transfer_from( - DAVE, - BOB, + dave, + bob, token_ids.clone(), vec![amount_one, amount_two], vec![].into(), ) .expect("should transfer tokens from Alice to Bob"); - let balance_id_one = contract.balance_of(BOB, token_ids[0]); - let balance_id_two = contract.balance_of(BOB, token_ids[1]); + let balance_id_one = + contract.sender(alice).balance_of(bob, token_ids[0]); + let balance_id_two = + contract.sender(alice).balance_of(bob, token_ids[1]); assert_eq!(amount_one, balance_id_one); assert_eq!(amount_two, balance_id_two); @@ -2017,12 +2048,14 @@ mod tests { fn error_when_invalid_receiver_safe_batch_transfer_from( contract: Contract, ) { - let alice = msg::sender(); + let alice = ALICE; + let (token_ids, values) = contract.init(alice, |contract| init(contract, alice, 4)); let invalid_receiver = Address::ZERO; let err = contract + .sender(alice) .safe_batch_transfer_from( alice, invalid_receiver, @@ -2040,12 +2073,12 @@ mod tests { )); } - // TODO#q: fix this test - #[motsu::test] + // TODO#q: fix test error_when_invalid_sender_safe_batch_transfer_from + /*#[motsu::test] fn error_when_invalid_sender_safe_batch_transfer_from( contract: Contract, ) { - let alice = msg::sender(); + let alice = ALICE; let (token_ids, values) = contract.init(alice, |contract| init(contract, alice, 4)); let invalid_sender = Address::ZERO; @@ -2056,6 +2089,7 @@ mod tests { .unwrap(); let err = contract + .sender(ALICE) .safe_batch_transfer_from( invalid_sender, CHARLIE, @@ -2071,19 +2105,23 @@ mod tests { sender }) if sender == invalid_sender )); - } + }*/ #[motsu::test] fn error_when_missing_approval_safe_batch_transfer_from( contract: Contract, ) { + let alice = ALICE; + let bob = BOB; + let (token_ids, values) = contract.init(alice, |contract| init(contract, alice, 2)); let err = contract + .sender(bob) .safe_batch_transfer_from( - ALICE, - BOB, + alice, + bob, token_ids.clone(), values.clone(), vec![].into(), @@ -2095,7 +2133,7 @@ mod tests { Error::MissingApprovalForAll(ERC1155MissingApprovalForAll { operator, owner - }) if operator == msg::sender() && owner == ALICE + }) if operator == bob && owner == alice )); } @@ -2103,19 +2141,23 @@ mod tests { fn error_when_insufficient_balance_safe_batch_transfer_from( contract: Contract, ) { - let alice = msg::sender(); + let alice = ALICE; + let charlie = CHARLIE; + let bob = BOB; + let (token_ids, values) = - contract.init(alice, |contract| init(contract, CHARLIE, 2)); + contract.init(alice, |contract| init(contract, charlie, 2)); contract - .sender(CHARLIE) + .sender(charlie) .set_approval_for_all(alice, true) .expect("should approve Charlie's tokens to Alice"); let err = contract + .sender(alice) .safe_batch_transfer_from( - CHARLIE, - BOB, + charlie, + bob, token_ids.clone(), vec![values[0] + uint!(1_U256), values[1]], vec![].into(), @@ -2129,7 +2171,7 @@ mod tests { balance, needed, token_id - }) if sender == CHARLIE && balance == values[0] && needed == values[0] + uint!(1_U256) && token_id == token_ids[0] + }) if sender == charlie && balance == values[0] && needed == values[0] + uint!(1_U256) && token_id == token_ids[0] )); } @@ -2137,19 +2179,23 @@ mod tests { fn error_when_not_equal_arrays_safe_batch_transfer_from( contract: Contract, ) { - let alice = msg::sender(); + let alice = ALICE; + let dave = DAVE; + let charlie = CHARLIE; + let (token_ids, values) = contract.init(alice, |contract| init(contract, alice, 4)); contract - .sender(DAVE) + .sender(dave) .set_approval_for_all(alice, true) .expect("should approve Dave's tokens to Alice"); let err = contract + .sender(alice) .safe_batch_transfer_from( - DAVE, - CHARLIE, + dave, + charlie, token_ids.clone(), append(values, 4), vec![].into(), @@ -2168,27 +2214,33 @@ mod tests { #[motsu::test] fn safe_batch_transfer_from_with_data(contract: Contract) { - let alice = msg::sender(); + let alice = ALICE; + let bob = BOB; + let dave = DAVE; + let (token_ids, values) = - contract.init(alice, |contract| init(contract, DAVE, 2)); + contract.init(alice, |contract| init(contract, dave, 2)); contract - .sender(DAVE) + .sender(dave) .set_approval_for_all(alice, true) .expect("should approve Dave's tokens to Alice"); contract + .sender(alice) .safe_batch_transfer_from( - DAVE, - BOB, + dave, + bob, token_ids.clone(), values.clone(), vec![0, 1, 2, 3].into(), ) .expect("should transfer tokens from Alice to Bob"); - let balance_id_one = contract.balance_of(BOB, token_ids[0]); - let balance_id_two = contract.balance_of(BOB, token_ids[1]); + let balance_id_one = + contract.sender(alice).balance_of(bob, token_ids[0]); + let balance_id_two = + contract.sender(alice).balance_of(bob, token_ids[1]); assert_eq!(values[0], balance_id_one); assert_eq!(values[1], balance_id_two); @@ -2198,12 +2250,14 @@ mod tests { fn error_when_invalid_receiver_safe_batch_transfer_from_with_data( contract: Contract, ) { - let alice = msg::sender(); + let alice = ALICE; + let (token_ids, values) = contract.init(alice, |contract| init(contract, alice, 4)); let invalid_receiver = Address::ZERO; let err = contract + .sender(alice) .safe_batch_transfer_from( alice, invalid_receiver, @@ -2221,12 +2275,15 @@ mod tests { )); } - // TODO#q: fix this test - #[motsu::test] + // TODO#q: fix test + // error_when_invalid_sender_safe_batch_transfer_from_with_data + /*#[motsu::test] fn error_when_invalid_sender_safe_batch_transfer_from_with_data( contract: Contract, ) { - let alice = msg::sender(); + let alice = ALICE; + let charlie = CHARLIE; + let (token_ids, values) = contract.init(alice, |contract| init(contract, alice, 4)); let invalid_sender = Address::ZERO; @@ -2237,9 +2294,10 @@ mod tests { .unwrap(); let err = contract + .sender(alice) .safe_batch_transfer_from( invalid_sender, - CHARLIE, + charlie, token_ids.clone(), values.clone(), vec![0, 1, 2, 3].into(), @@ -2252,19 +2310,23 @@ mod tests { sender }) if sender == invalid_sender )); - } + }*/ #[motsu::test] fn error_when_missing_approval_safe_batch_transfer_from_with_data( contract: Contract, ) { + let alice = ALICE; + let bob = BOB; + let (token_ids, values) = contract.init(alice, |contract| init(contract, alice, 2)); let err = contract + .sender(alice) .safe_batch_transfer_from( - ALICE, - BOB, + alice, + bob, token_ids.clone(), values.clone(), vec![0, 1, 2, 3].into(), @@ -2276,7 +2338,7 @@ mod tests { Error::MissingApprovalForAll(ERC1155MissingApprovalForAll { operator, owner - }) if operator == msg::sender() && owner == ALICE + }) if operator == msg::sender() && owner == alice )); } @@ -2284,19 +2346,23 @@ mod tests { fn error_when_insufficient_balance_safe_batch_transfer_from_with_data( contract: Contract, ) { - let alice = msg::sender(); + let alice = ALICE; + let bob = BOB; + let charlie = CHARLIE; + let (token_ids, values) = - contract.init(alice, |contract| init(contract, CHARLIE, 2)); + contract.init(alice, |contract| init(contract, charlie, 2)); contract - .sender(CHARLIE) + .sender(charlie) .set_approval_for_all(alice, true) .expect("should approve Charlie's tokens to Alice"); let err = contract + .sender(alice) .safe_batch_transfer_from( - CHARLIE, - BOB, + charlie, + bob, token_ids.clone(), vec![values[0] + uint!(1_U256), values[1]], vec![0, 1, 2, 3].into(), @@ -2310,7 +2376,7 @@ mod tests { balance, needed, token_id - }) if sender == CHARLIE && balance == values[0] && needed == values[0] + uint!(1_U256) && token_id == token_ids[0] + }) if sender == charlie && balance == values[0] && needed == values[0] + uint!(1_U256) && token_id == token_ids[0] )); } @@ -2318,19 +2384,23 @@ mod tests { fn error_when_not_equal_arrays_safe_batch_transfer_from_with_data( contract: Contract, ) { - let alice = msg::sender(); + let alice = ALICE; + let dave = DAVE; + let charlie = CHARLIE; + let (token_ids, values) = contract.init(alice, |contract| init(contract, alice, 4)); contract - .sender(DAVE) + .sender(dave) .set_approval_for_all(alice, true) .expect("should approve Dave's tokens to Alice"); let err = contract + .sender(alice) .safe_batch_transfer_from( - DAVE, - CHARLIE, + dave, + charlie, token_ids.clone(), append(values, 4), vec![0, 1, 2, 3].into(), diff --git a/contracts/src/token/erc721/extensions/enumerable.rs b/contracts/src/token/erc721/extensions/enumerable.rs index e7742eff7..20bf22d87 100644 --- a/contracts/src/token/erc721/extensions/enumerable.rs +++ b/contracts/src/token/erc721/extensions/enumerable.rs @@ -486,7 +486,7 @@ mod tests { assert!(matches!(err, Error::EnumerableForbiddenBatchMint(_))); } - // TODO#q: repair Erc721Enumerable and Erc721 integration tests + // TODO#q: fix Erc721Enumerable and Erc721 integration tests /*#[motsu::test] fn token_of_owner_by_index_works(contract: Erc721Enumerable) { let alice = msg::sender(); From 75176c34d7e844a778ed562eb0c45a97c542bdd8 Mon Sep 17 00:00:00 2001 From: Alisander Qoshqosh Date: Fri, 17 Jan 2025 00:04:59 +0400 Subject: [PATCH 075/109] ++ --- contracts/src/token/erc1155/mod.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/contracts/src/token/erc1155/mod.rs b/contracts/src/token/erc1155/mod.rs index 58b50acf8..def9d6da4 100644 --- a/contracts/src/token/erc1155/mod.rs +++ b/contracts/src/token/erc1155/mod.rs @@ -1554,7 +1554,7 @@ mod tests { fn burns_batch(contract: Contract) { let alice = ALICE; let (token_ids, values) = - contract.init(alice, |contract| init(contract, alice, 1)); + contract.init(alice, |contract| init(contract, alice, 4)); contract .sender(alice) @@ -1646,7 +1646,7 @@ mod tests { balance, needed, token_id - }) if sender == ALICE && balance == values[0] && needed == values[0] + uint!(1_U256) && token_id == token_ids[0] + }) if sender == alice && balance == values[0] && needed == values[0] + uint!(1_U256) && token_id == token_ids[0] )); } @@ -2323,7 +2323,7 @@ mod tests { contract.init(alice, |contract| init(contract, alice, 2)); let err = contract - .sender(alice) + .sender(bob) .safe_batch_transfer_from( alice, bob, @@ -2338,7 +2338,7 @@ mod tests { Error::MissingApprovalForAll(ERC1155MissingApprovalForAll { operator, owner - }) if operator == msg::sender() && owner == alice + }) if operator == bob && owner == alice )); } From 09944a7cb1bbb30c8a7d72c1d7e771e084e1fe59 Mon Sep 17 00:00:00 2001 From: Alisander Qoshqosh Date: Fri, 17 Jan 2025 01:08:20 +0400 Subject: [PATCH 076/109] ++ --- Cargo.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d214313a7..4544faecc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2566,7 +2566,7 @@ checksum = "7843ec2de400bcbc6a6328c958dc38e5359da6e93e72e37bc5246bf1ae776389" [[package]] name = "motsu" version = "0.3.0" -source = "git+https://github.com/OpenZeppelin/stylus-test-helpers?branch=unit-tests%2Fmultiple-contract-deployment#8ae0ebd08e03733f4f703326d25894fea24eddda" +source = "git+https://github.com/OpenZeppelin/stylus-test-helpers?branch=unit-tests%2Fmultiple-contract-deployment#41e9882712cccc82d36fa037c302eda1359b2922" dependencies = [ "alloy-primitives", "alloy-sol-types", @@ -2581,7 +2581,7 @@ dependencies = [ [[package]] name = "motsu-proc" version = "0.3.0" -source = "git+https://github.com/OpenZeppelin/stylus-test-helpers?branch=unit-tests%2Fmultiple-contract-deployment#8ae0ebd08e03733f4f703326d25894fea24eddda" +source = "git+https://github.com/OpenZeppelin/stylus-test-helpers?branch=unit-tests%2Fmultiple-contract-deployment#41e9882712cccc82d36fa037c302eda1359b2922" dependencies = [ "proc-macro2", "quote", From db1984cf32fd8cf0021c559fd1d50e4eb40cccae Mon Sep 17 00:00:00 2001 From: Alisander Qoshqosh Date: Fri, 31 Jan 2025 23:26:26 +0400 Subject: [PATCH 077/109] comment erc4626 tests --- contracts/src/token/erc20/extensions/erc4626.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/contracts/src/token/erc20/extensions/erc4626.rs b/contracts/src/token/erc20/extensions/erc4626.rs index cad03ab9a..cb32a83b4 100644 --- a/contracts/src/token/erc20/extensions/erc4626.rs +++ b/contracts/src/token/erc20/extensions/erc4626.rs @@ -1143,9 +1143,11 @@ impl Erc4626 { } } -// TODO: Add missing tests once `motsu` supports calling external contracts. +// TODO#q: Add missing tests once `motsu` supports calling external contracts. #[cfg(all(test, feature = "std"))] mod tests { + // TODO#q: fix erc4626 tests + /* use alloy_primitives::{address, U256, U8}; use stylus_sdk::{msg, prelude::storage}; @@ -1213,4 +1215,5 @@ mod tests { let decimals = contract.erc4626.decimals(); assert_eq!(decimals, underlying_decimals + new_decimal_offset); } + */ } From a0b916f1110f6e7952f1ee254493e48096aa4746 Mon Sep 17 00:00:00 2001 From: Alisander Qoshqosh Date: Fri, 31 Jan 2025 23:47:08 +0400 Subject: [PATCH 078/109] use user injection at erc721 --- .../src/token/erc721/extensions/burnable.rs | 62 +- .../token/erc721/extensions/consecutive.rs | 132 +++-- .../src/token/erc721/extensions/enumerable.rs | 16 +- .../token/erc721/extensions/uri_storage.rs | 7 +- contracts/src/token/erc721/mod.rs | 541 ++++++++++-------- 5 files changed, 433 insertions(+), 325 deletions(-) diff --git a/contracts/src/token/erc721/extensions/burnable.rs b/contracts/src/token/erc721/extensions/burnable.rs index 67a7f6ccd..8e8fc0992 100644 --- a/contracts/src/token/erc721/extensions/burnable.rs +++ b/contracts/src/token/erc721/extensions/burnable.rs @@ -54,7 +54,7 @@ impl IErc721Burnable for Erc721 { #[cfg(all(test, feature = "std"))] mod tests { - use alloy_primitives::{address, uint, Address, U256}; + use alloy_primitives::{uint, Address, U256}; use motsu::prelude::Contract; use stylus_sdk::msg; @@ -64,13 +64,10 @@ mod tests { IErc721, }; - const BOB: Address = address!("F4EaCDAbEf3c8f1EdE91b6f2A6840bc2E4DD3526"); - const TOKEN_ID: U256 = uint!(1_U256); #[motsu::test] - fn burns(contract: Contract) { - let alice = Address::random(); + fn burns(contract: Contract, alice: Address) { let one = uint!(1_U256); contract @@ -107,21 +104,23 @@ mod tests { } #[motsu::test] - fn burns_with_approval(contract: Contract) { - let alice = Address::random(); - + fn burns_with_approval( + contract: Contract, + alice: Address, + bob: Address, + ) { contract .sender(alice) - ._mint(BOB, TOKEN_ID) + ._mint(bob, TOKEN_ID) .expect("should mint a token for Bob"); let initial_balance = contract .sender(alice) - .balance_of(BOB) + .balance_of(bob) .expect("should return the balance of Bob"); contract - .sender(BOB) + .sender(bob) .approve(alice, TOKEN_ID) .expect("should approve a token for Alice"); @@ -142,28 +141,30 @@ mod tests { let balance = contract .sender(alice) - .balance_of(BOB) + .balance_of(bob) .expect("should return the balance of Bob"); assert_eq!(initial_balance - uint!(1_U256), balance); } #[motsu::test] - fn burns_with_approval_for_all(contract: Contract) { - let alice = Address::random(); - + fn burns_with_approval_for_all( + contract: Contract, + alice: Address, + bob: Address, + ) { contract .sender(alice) - ._mint(BOB, TOKEN_ID) + ._mint(bob, TOKEN_ID) .expect("should mint a token for Bob"); let initial_balance = contract .sender(alice) - .balance_of(BOB) + .balance_of(bob) .expect("should return the balance of Bob"); contract - .sender(BOB) + .sender(bob) .set_approval_for_all(alice, true) .expect("should approve all Bob's tokens for Alice"); @@ -185,7 +186,7 @@ mod tests { let balance = contract .sender(alice) - .balance_of(BOB) + .balance_of(bob) .expect("should return the balance of Bob"); assert_eq!(initial_balance - uint!(1_U256), balance); @@ -194,16 +195,16 @@ mod tests { #[motsu::test] fn error_when_get_approved_of_previous_approval_burned( contract: Contract, + alice: Address, + bob: Address, ) { - let alice = Address::random(); - contract .sender(alice) ._mint(alice, TOKEN_ID) .expect("should mint a token for Alice"); contract .sender(alice) - .approve(BOB, TOKEN_ID) + .approve(bob, TOKEN_ID) .expect("should approve a token for Bob"); contract @@ -225,12 +226,14 @@ mod tests { } #[motsu::test] - fn error_when_burn_without_approval(contract: Contract) { - let alice = Address::random(); - + fn error_when_burn_without_approval( + contract: Contract, + alice: Address, + bob: Address, + ) { contract .sender(alice) - ._mint(BOB, TOKEN_ID) + ._mint(bob, TOKEN_ID) .expect("should mint a token for Bob"); let err = contract @@ -248,9 +251,10 @@ mod tests { } #[motsu::test] - fn error_when_burn_nonexistent_token(contract: Contract) { - let alice = Address::random(); - + fn error_when_burn_nonexistent_token( + contract: Contract, + alice: Address, + ) { let err = contract .sender(alice) .burn(TOKEN_ID) diff --git a/contracts/src/token/erc721/extensions/consecutive.rs b/contracts/src/token/erc721/extensions/consecutive.rs index 4fcb3d6ea..135826c47 100644 --- a/contracts/src/token/erc721/extensions/consecutive.rs +++ b/contracts/src/token/erc721/extensions/consecutive.rs @@ -800,7 +800,7 @@ impl Erc721Consecutive { #[cfg(all(test, feature = "std"))] mod tests { - use alloy_primitives::{address, uint, Address, U256}; + use alloy_primitives::{uint, Address, U256}; use motsu::prelude::Contract; use stylus_sdk::msg; @@ -815,9 +815,6 @@ mod tests { }, }; - const BOB: Address = address!("F4EaCDAbEf3c8f1EdE91b6f2A6840bc2E4DD3526"); - const DAVE: Address = address!("0BB78F7e7132d1651B4Fd884B7624394e92156F1"); - const FIRST_CONSECUTIVE_TOKEN_ID: U96 = uint!(0_U96); const MAX_BATCH_SIZE: U96 = uint!(5000_U96); const TOKEN_ID: U256 = uint!(1_U256); @@ -838,9 +835,7 @@ mod tests { } #[motsu::test] - fn mints(contract: Contract) { - let alice = Address::random(); - + fn mints(contract: Contract, alice: Address) { let initial_balance = contract .sender(alice) .balance_of(alice) @@ -880,8 +875,8 @@ mod tests { #[motsu::test] fn error_when_minting_token_id_twice( contract: Contract, + alice: Address, ) { - let alice = Address::random(); contract .sender(alice) ._mint(alice, TOKEN_ID) @@ -902,8 +897,8 @@ mod tests { #[motsu::test] fn error_when_minting_token_invalid_receiver( contract: Contract, + alice: Address, ) { - let alice = Address::random(); let invalid_receiver = Address::ZERO; let err = contract @@ -920,8 +915,10 @@ mod tests { } #[motsu::test] - fn error_when_to_is_zero(contract: Contract) { - let alice = Address::random(); + fn error_when_to_is_zero( + contract: Contract, + alice: Address, + ) { let err = contract .sender(alice) ._mint_consecutive(Address::ZERO, uint!(11_U96)) @@ -935,8 +932,10 @@ mod tests { } #[motsu::test] - fn error_when_exceed_batch_size(contract: Contract) { - let alice = Address::random(); + fn error_when_exceed_batch_size( + contract: Contract, + alice: Address, + ) { let batch_size = contract.sender(alice)._max_batch_size() + uint!(1_U96); let err = contract @@ -954,10 +953,11 @@ mod tests { } #[motsu::test] - fn transfers_from(contract: Contract) { - let alice = Address::random(); - let bob = BOB; - + fn transfers_from( + contract: Contract, + alice: Address, + bob: Address, + ) { // Mint batches of 1000 tokens to Alice and Bob. contract.init(alice, |contract| { mint_consecutive( @@ -1005,7 +1005,7 @@ mod tests { // Check transfer of the token that wasn't minted consecutive. contract .sender(alice) - .transfer_from(alice, BOB, NON_CONSECUTIVE_TOKEN_ID) + .transfer_from(alice, bob, NON_CONSECUTIVE_TOKEN_ID) .expect("should transfer a token from Alice to Bob"); let alice_balance = contract .sender(alice) @@ -1015,9 +1015,7 @@ mod tests { } #[motsu::test] - fn burns(contract: Contract) { - let alice = Address::random(); - + fn burns(contract: Contract, alice: Address) { // Mint batch of 1000 tokens to Alice. contract.init(alice, |contract| { mint_consecutive(contract, vec![alice], vec![uint!(1000_U96)]); @@ -1095,8 +1093,11 @@ mod tests { } #[motsu::test] - fn safe_transfer_from(contract: Contract) { - let alice = Address::random(); + fn safe_transfer_from( + contract: Contract, + alice: Address, + bob: Address, + ) { contract .sender(alice) ._mint(alice, TOKEN_ID) @@ -1104,7 +1105,7 @@ mod tests { contract .sender(alice) - .safe_transfer_from(alice, BOB, TOKEN_ID) + .safe_transfer_from(alice, bob, TOKEN_ID) .expect("should transfer a token from Alice to Bob"); let owner = contract @@ -1112,25 +1113,26 @@ mod tests { .owner_of(TOKEN_ID) .expect("should return the owner of the token"); - assert_eq!(owner, BOB); + assert_eq!(owner, bob); } #[motsu::test] fn safe_transfers_from_approved_token( contract: Contract, + alice: Address, + bob: Address, ) { - let alice = Address::random(); contract .sender(alice) - ._mint(BOB, TOKEN_ID) + ._mint(bob, TOKEN_ID) .expect("should mint token to Bob"); contract - .sender(BOB) + .sender(bob) .approve(alice, TOKEN_ID) .expect("should approve Bob's token to Alice"); contract .sender(alice) - .safe_transfer_from(BOB, alice, TOKEN_ID) + .safe_transfer_from(bob, alice, TOKEN_ID) .expect("should transfer Bob's token to Alice"); let owner = contract .sender(alice) @@ -1142,9 +1144,10 @@ mod tests { #[motsu::test] fn error_when_safe_transfer_from_incorrect_owner( contract: Contract, + alice: Address, + bob: Address, + dave: Address, ) { - let alice = Address::random(); - contract .sender(alice) ._mint(alice, TOKEN_ID) @@ -1152,7 +1155,7 @@ mod tests { let err = contract .sender(alice) - .safe_transfer_from(DAVE, BOB, TOKEN_ID) + .safe_transfer_from(dave, bob, TOKEN_ID) .expect_err("should not transfer from incorrect owner"); assert!(matches!( @@ -1161,18 +1164,19 @@ mod tests { sender, token_id: t_id, owner - })) if sender == DAVE && t_id == TOKEN_ID && owner == alice + })) if sender == dave && t_id == TOKEN_ID && owner == alice )); } #[motsu::test] fn error_when_internal_safe_transfer_nonexistent_token( contract: Contract, + alice: Address, + bob: Address, ) { - let alice = Address::random(); let err = contract .sender(alice) - ._safe_transfer(alice, BOB, TOKEN_ID, &vec![0, 1, 2, 3].into()) + ._safe_transfer(alice, bob, TOKEN_ID, &vec![0, 1, 2, 3].into()) .expect_err("should not transfer a non-existent token"); assert!(matches!( @@ -1186,8 +1190,8 @@ mod tests { #[motsu::test] fn error_when_safe_transfer_to_invalid_receiver( contract: Contract, + alice: Address, ) { - let alice = Address::random(); let invalid_receiver = Address::ZERO; contract @@ -1215,8 +1219,11 @@ mod tests { } #[motsu::test] - fn safe_transfers_from_with_data(contract: Contract) { - let alice = Address::random(); + fn safe_transfers_from_with_data( + contract: Contract, + alice: Address, + bob: Address, + ) { contract .sender(alice) ._mint(alice, TOKEN_ID) @@ -1226,7 +1233,7 @@ mod tests { .sender(alice) .safe_transfer_from_with_data( alice, - BOB, + bob, TOKEN_ID, vec![0, 1, 2, 3].into(), ) @@ -1237,14 +1244,14 @@ mod tests { .owner_of(TOKEN_ID) .expect("should return the owner of the token"); - assert_eq!(owner, BOB); + assert_eq!(owner, bob); } #[motsu::test] fn error_when_internal_safe_transfer_to_invalid_receiver( contract: Contract, + alice: Address, ) { - let alice = Address::random(); let invalid_receiver = Address::ZERO; contract @@ -1279,9 +1286,10 @@ mod tests { #[motsu::test] fn error_when_internal_safe_transfer_from_incorrect_owner( contract: Contract, + alice: Address, + bob: Address, + dave: Address, ) { - let alice = Address::random(); - contract .sender(alice) ._mint(alice, TOKEN_ID) @@ -1289,7 +1297,7 @@ mod tests { let err = contract .sender(alice) - ._safe_transfer(DAVE, BOB, TOKEN_ID, &vec![0, 1, 2, 3].into()) + ._safe_transfer(dave, bob, TOKEN_ID, &vec![0, 1, 2, 3].into()) .expect_err("should not transfer the token from incorrect owner"); assert!(matches!( err, @@ -1297,14 +1305,12 @@ mod tests { sender, token_id: t_id, owner - })) if sender == DAVE && t_id == TOKEN_ID && owner == alice + })) if sender == dave && t_id == TOKEN_ID && owner == alice )); } #[motsu::test] - fn safe_mints(contract: Contract) { - let alice = Address::random(); - + fn safe_mints(contract: Contract, alice: Address) { let initial_balance = contract .sender(alice) .balance_of(alice) @@ -1332,11 +1338,12 @@ mod tests { #[motsu::test] fn error_when_approve_for_nonexistent_token( contract: Contract, + alice: Address, + bob: Address, ) { - let alice = Address::random(); let err = contract .sender(alice) - .approve(BOB, TOKEN_ID) + .approve(bob, TOKEN_ID) .expect_err("should not approve for a non-existent token"); assert!(matches!( @@ -1350,16 +1357,18 @@ mod tests { #[motsu::test] fn error_when_approve_by_invalid_approver( contract: Contract, + alice: Address, + bob: Address, + dave: Address, ) { - let alice = Address::random(); contract .sender(alice) - ._mint(BOB, TOKEN_ID) + ._mint(bob, TOKEN_ID) .expect("should mint a token"); let err = contract .sender(alice) - .approve(DAVE, TOKEN_ID) + .approve(dave, TOKEN_ID) .expect_err("should not approve when invalid approver"); assert!(matches!( @@ -1371,25 +1380,28 @@ mod tests { } #[motsu::test] - fn approval_for_all(contract: Contract) { - let alice = Address::random(); + fn approval_for_all( + contract: Contract, + alice: Address, + bob: Address, + ) { contract .sender(alice) - .set_approval_for_all(BOB, true) + .set_approval_for_all(bob, true) .expect("should approve Bob for operations on all Alice's tokens"); - assert!(contract.sender(alice).is_approved_for_all(alice, BOB)); + assert!(contract.sender(alice).is_approved_for_all(alice, bob)); - contract.sender(alice).set_approval_for_all(BOB, false).expect( + contract.sender(alice).set_approval_for_all(bob, false).expect( "should disapprove Bob for operations on all Alice's tokens", ); - assert!(!contract.sender(alice).is_approved_for_all(alice, BOB)); + assert!(!contract.sender(alice).is_approved_for_all(alice, bob)); } #[motsu::test] fn error_when_get_approved_of_nonexistent_token( contract: Contract, + alice: Address, ) { - let alice = Address::random(); let err = contract .sender(alice) .get_approved(TOKEN_ID) diff --git a/contracts/src/token/erc721/extensions/enumerable.rs b/contracts/src/token/erc721/extensions/enumerable.rs index 20bf22d87..2abf40ca8 100644 --- a/contracts/src/token/erc721/extensions/enumerable.rs +++ b/contracts/src/token/erc721/extensions/enumerable.rs @@ -335,28 +335,28 @@ impl Erc721Enumerable { mod tests { use motsu::prelude::Contract; use stylus_sdk::{ - alloy_primitives::{address, uint, Address, U256}, + alloy_primitives::{uint, Address, U256}, prelude::TopLevelStorage, }; use super::{Erc721Enumerable, Error, IErc721Enumerable}; use crate::token::erc721::IErc721; - const BOB: Address = address!("F4EaCDAbEf3c8f1EdE91b6f2A6840bc2E4DD3526"); - unsafe impl TopLevelStorage for Erc721Enumerable {} #[motsu::test] - fn total_supply_no_tokens(contract: Contract) { - let alice = Address::random(); + fn total_supply_no_tokens( + contract: Contract, + alice: Address, + ) { assert_eq!(U256::ZERO, contract.sender(alice).total_supply()); } #[motsu::test] fn error_when_token_by_index_is_out_of_bound( contract: Contract, + alice: Address, ) { - let alice = Address::random(); assert_eq!(U256::ZERO, contract.sender(alice).total_supply()); let token_idx = uint!(2024_U256); @@ -368,8 +368,8 @@ mod tests { #[motsu::test] fn add_token_to_all_tokens_enumeration_works( contract: Contract, + alice: Address, ) { - let alice = Address::random(); assert_eq!(U256::ZERO, contract.sender(alice).total_supply()); let tokens_len = 10; @@ -410,8 +410,8 @@ mod tests { #[motsu::test] fn remove_token_from_all_tokens_enumeration_works( contract: Contract, + alice: Address, ) { - let alice = Address::random(); assert_eq!(U256::ZERO, contract.sender(alice).total_supply()); let initial_tokens_len = 10; diff --git a/contracts/src/token/erc721/extensions/uri_storage.rs b/contracts/src/token/erc721/extensions/uri_storage.rs index 3218fd402..e3c4990c3 100644 --- a/contracts/src/token/erc721/extensions/uri_storage.rs +++ b/contracts/src/token/erc721/extensions/uri_storage.rs @@ -150,9 +150,10 @@ mod tests { unsafe impl TopLevelStorage for Erc721MetadataExample {} #[motsu::test] - fn token_uri_works(contract: Contract) { - let alice = Address::random(); - + fn token_uri_works( + contract: Contract, + alice: Address, + ) { contract .sender(alice) .erc721 diff --git a/contracts/src/token/erc721/mod.rs b/contracts/src/token/erc721/mod.rs index c3819c6c2..4037f201a 100644 --- a/contracts/src/token/erc721/mod.rs +++ b/contracts/src/token/erc721/mod.rs @@ -1151,9 +1151,7 @@ impl Erc721 { #[cfg(all(test, feature = "std"))] mod tests { - use alloy_primitives::{ - address, fixed_bytes, uint, Address, FixedBytes, U256, - }; + use alloy_primitives::{fixed_bytes, uint, Address, FixedBytes, U256}; use motsu::prelude::Contract; use stylus_sdk::{ abi::Bytes, @@ -1169,17 +1167,14 @@ mod tests { }; use crate::utils::introspection::erc165::IErc165; - const BOB: Address = address!("F4EaCDAbEf3c8f1EdE91b6f2A6840bc2E4DD3526"); - const DAVE: Address = address!("0BB78F7e7132d1651B4Fd884B7624394e92156F1"); - const TOKEN_ID: U256 = uint!(1_U256); #[motsu::test] fn error_when_checking_balance_of_invalid_owner( contract: Contract, + alice: Address, ) { let invalid_owner = Address::ZERO; - let alice = Address::random(); let err = contract .sender(alice) .balance_of(invalid_owner) @@ -1191,9 +1186,7 @@ mod tests { } #[motsu::test] - fn balance_of_zero_balance(contract: Contract) { - let owner = Address::random(); - + fn balance_of_zero_balance(contract: Contract, owner: Address) { let balance = contract .sender(owner) .balance_of(owner) @@ -1204,9 +1197,8 @@ mod tests { #[motsu::test] fn error_when_checking_owner_of_nonexistent_token( contract: Contract, + alice: Address, ) { - let alice = Address::random(); - let err = contract .sender(alice) .owner_of(TOKEN_ID) @@ -1221,9 +1213,7 @@ mod tests { } #[motsu::test] - fn mints(contract: Contract) { - let alice = Address::random(); - + fn mints(contract: Contract, alice: Address) { let initial_balance = contract .sender(alice) .balance_of(alice) @@ -1248,9 +1238,10 @@ mod tests { } #[motsu::test] - fn error_when_minting_token_id_twice(contract: Contract) { - let alice = Address::random(); - + fn error_when_minting_token_id_twice( + contract: Contract, + alice: Address, + ) { contract .sender(alice) ._mint(alice, TOKEN_ID) @@ -1267,9 +1258,11 @@ mod tests { } #[motsu::test] - fn error_when_minting_token_invalid_receiver(contract: Contract) { + fn error_when_minting_token_invalid_receiver( + contract: Contract, + alice: Address, + ) { let invalid_receiver = Address::ZERO; - let alice = Address::random(); let err = contract .sender(alice) @@ -1285,9 +1278,7 @@ mod tests { } #[motsu::test] - fn safe_mints(contract: Contract) { - let alice = Address::random(); - + fn safe_mints(contract: Contract, alice: Address) { let initial_balance = contract .sender(alice) .balance_of(alice) @@ -1313,8 +1304,10 @@ mod tests { } #[motsu::test] - fn error_when_safe_mint_token_id_twice(contract: Contract) { - let alice = Address::random(); + fn error_when_safe_mint_token_id_twice( + contract: Contract, + alice: Address, + ) { contract .sender(alice) ._mint(alice, TOKEN_ID) @@ -1332,8 +1325,10 @@ mod tests { } #[motsu::test] - fn error_when_safe_mint_invalid_receiver(contract: Contract) { - let alice = Address::random(); + fn error_when_safe_mint_invalid_receiver( + contract: Contract, + alice: Address, + ) { let invalid_receiver = Address::ZERO; let err = contract @@ -1350,37 +1345,43 @@ mod tests { } #[motsu::test] - fn transfers_from(contract: Contract) { - let alice = Address::random(); + fn transfers_from( + contract: Contract, + alice: Address, + bob: Address, + ) { contract .sender(alice) ._mint(alice, TOKEN_ID) .expect("should mint a token to Alice"); contract .sender(alice) - .transfer_from(alice, BOB, TOKEN_ID) + .transfer_from(alice, bob, TOKEN_ID) .expect("should transfer a token from Alice to Bob"); let owner = contract .sender(alice) .owner_of(TOKEN_ID) .expect("should return the owner of the token"); - assert_eq!(owner, BOB); + assert_eq!(owner, bob); } #[motsu::test] - fn transfers_from_approved_token(contract: Contract) { - let alice = Address::random(); + fn transfers_from_approved_token( + contract: Contract, + alice: Address, + bob: Address, + ) { contract .sender(alice) - ._mint(BOB, TOKEN_ID) + ._mint(bob, TOKEN_ID) .expect("should mint token to Bob"); contract - .sender(BOB) + .sender(bob) .approve(alice, TOKEN_ID) .expect("should approve Bob's token for Alice"); contract .sender(alice) - .transfer_from(BOB, alice, TOKEN_ID) + .transfer_from(bob, alice, TOKEN_ID) .expect("should transfer Bob's token to Alice"); let owner = contract .sender(alice) @@ -1390,25 +1391,28 @@ mod tests { } #[motsu::test] - fn transfers_from_approved_for_all(contract: Contract) { - let alice = Address::random(); + fn transfers_from_approved_for_all( + contract: Contract, + alice: Address, + bob: Address, + ) { contract .sender(alice) - ._mint(BOB, TOKEN_ID) + ._mint(bob, TOKEN_ID) .expect("should mint token to Bob"); contract - .sender(BOB) + .sender(bob) .set_approval_for_all(alice, true) .expect("should approve all Bob's tokens for Alice"); let approved_for_all = - contract.sender(alice).is_approved_for_all(BOB, alice); + contract.sender(alice).is_approved_for_all(bob, alice); assert!(approved_for_all); contract .sender(alice) - .transfer_from(BOB, alice, TOKEN_ID) + .transfer_from(bob, alice, TOKEN_ID) .expect("should transfer Bob's token to Alice"); let owner = contract @@ -1421,8 +1425,8 @@ mod tests { #[motsu::test] fn error_when_transfer_from_transfers_to_invalid_receiver( contract: Contract, + alice: Address, ) { - let alice = Address::random(); let invalid_receiver = Address::ZERO; contract @@ -1452,9 +1456,10 @@ mod tests { #[motsu::test] fn error_when_transfer_from_transfers_from_incorrect_owner( contract: Contract, + alice: Address, + bob: Address, + dave: Address, ) { - let alice = Address::random(); - contract .sender(alice) ._mint(alice, TOKEN_ID) @@ -1462,7 +1467,7 @@ mod tests { let err = contract .sender(alice) - .transfer_from(DAVE, BOB, TOKEN_ID) + .transfer_from(dave, bob, TOKEN_ID) .expect_err("should not transfer the token from incorrect owner"); assert!(matches!( err, @@ -1470,7 +1475,7 @@ mod tests { sender, token_id: t_id, owner - }) if sender == DAVE && t_id == TOKEN_ID && owner == alice + }) if sender == dave && t_id == TOKEN_ID && owner == alice )); // NOTE: We can't check this here, but we cover this in our e2e tests. @@ -1483,15 +1488,16 @@ mod tests { #[motsu::test] fn error_when_transfer_from_transfers_with_insufficient_approval( contract: Contract, + alice: Address, + bob: Address, ) { - let alice = Address::random(); contract .sender(alice) - ._mint(BOB, TOKEN_ID) + ._mint(bob, TOKEN_ID) .expect("should mint token to Bob"); let err = contract .sender(alice) - .transfer_from(BOB, alice, TOKEN_ID) + .transfer_from(bob, alice, TOKEN_ID) .expect_err("should not transfer unapproved token"); assert!(matches!( err, @@ -1505,11 +1511,12 @@ mod tests { #[motsu::test] fn error_when_transfer_from_transfers_nonexistent_token( contract: Contract, + alice: Address, + bob: Address, ) { - let alice = Address::random(); let err = contract .sender(alice) - .transfer_from(alice, BOB, TOKEN_ID) + .transfer_from(alice, bob, TOKEN_ID) .expect_err("should not transfer a non-existent token"); assert!(matches!( err, @@ -1520,8 +1527,11 @@ mod tests { } #[motsu::test] - fn safe_transfers_from(contract: Contract) { - let alice = Address::random(); + fn safe_transfers_from( + contract: Contract, + alice: Address, + bob: Address, + ) { contract .sender(alice) ._mint(alice, TOKEN_ID) @@ -1529,7 +1539,7 @@ mod tests { contract .sender(alice) - .safe_transfer_from(alice, BOB, TOKEN_ID) + .safe_transfer_from(alice, bob, TOKEN_ID) .expect("should transfer a token from Alice to Bob"); let owner = contract @@ -1537,20 +1547,23 @@ mod tests { .owner_of(TOKEN_ID) .expect("should return the owner of the token"); - assert_eq!(owner, BOB); + assert_eq!(owner, bob); } #[motsu::test] - fn safe_transfers_from_approved_token(contract: Contract) { - let alice = Address::random(); + fn safe_transfers_from_approved_token( + contract: Contract, + alice: Address, + bob: Address, + ) { contract .sender(alice) - ._mint(BOB, TOKEN_ID) + ._mint(bob, TOKEN_ID) .expect("should mint token to Bob"); contract.sender(alice)._token_approvals.setter(TOKEN_ID).set(alice); contract .sender(alice) - .safe_transfer_from(BOB, alice, TOKEN_ID) + .safe_transfer_from(bob, alice, TOKEN_ID) .expect("should transfer Bob's token to Alice"); let owner = contract .sender(alice) @@ -1560,25 +1573,28 @@ mod tests { } #[motsu::test] - fn safe_transfers_from_approved_for_all(contract: Contract) { - let alice = Address::random(); + fn safe_transfers_from_approved_for_all( + contract: Contract, + alice: Address, + bob: Address, + ) { contract .sender(alice) - ._mint(BOB, TOKEN_ID) + ._mint(bob, TOKEN_ID) .expect("should mint token to Bob"); contract - .sender(BOB) + .sender(bob) .set_approval_for_all(alice, true) .expect("should approve all Bob's tokens for Alice"); let approved_for_all = - contract.sender(alice).is_approved_for_all(BOB, alice); + contract.sender(alice).is_approved_for_all(bob, alice); assert!(approved_for_all); contract .sender(alice) - .safe_transfer_from(BOB, alice, TOKEN_ID) + .safe_transfer_from(bob, alice, TOKEN_ID) .expect("should transfer Bob's token to Alice"); let owner = contract @@ -1591,8 +1607,8 @@ mod tests { #[motsu::test] fn error_when_safe_transfer_to_invalid_receiver( contract: Contract, + alice: Address, ) { - let alice = Address::random(); let invalid_receiver = Address::ZERO; contract @@ -1622,9 +1638,10 @@ mod tests { #[motsu::test] fn error_when_safe_transfer_from_transfers_from_incorrect_owner( contract: Contract, + alice: Address, + bob: Address, + dave: Address, ) { - let alice = Address::random(); - contract .sender(alice) ._mint(alice, TOKEN_ID) @@ -1632,7 +1649,7 @@ mod tests { let err = contract .sender(alice) - .safe_transfer_from(DAVE, BOB, TOKEN_ID) + .safe_transfer_from(dave, bob, TOKEN_ID) .expect_err("should not transfer the token from incorrect owner"); assert!(matches!( err, @@ -1640,7 +1657,7 @@ mod tests { owner, sender, token_id: t_id - }) if sender == DAVE && t_id == TOKEN_ID && owner == alice + }) if sender == dave && t_id == TOKEN_ID && owner == alice )); // NOTE: We can't check this here, but we cover this in our e2e tests. @@ -1653,15 +1670,16 @@ mod tests { #[motsu::test] fn error_when_safe_transfer_from_transfers_with_insufficient_approval( contract: Contract, + alice: Address, + bob: Address, ) { - let alice = Address::random(); contract .sender(alice) - ._mint(BOB, TOKEN_ID) + ._mint(bob, TOKEN_ID) .expect("should mint token to Bob"); let err = contract .sender(alice) - .safe_transfer_from(BOB, alice, TOKEN_ID) + .safe_transfer_from(bob, alice, TOKEN_ID) .expect_err("should not transfer unapproved token"); assert!(matches!( err, @@ -1675,11 +1693,12 @@ mod tests { #[motsu::test] fn error_when_safe_transfer_from_transfers_nonexistent_token( contract: Contract, + alice: Address, + bob: Address, ) { - let alice = Address::random(); let err = contract .sender(alice) - .safe_transfer_from(alice, BOB, TOKEN_ID) + .safe_transfer_from(alice, bob, TOKEN_ID) .expect_err("should not transfer a non-existent token"); assert!(matches!( err, @@ -1690,8 +1709,11 @@ mod tests { } #[motsu::test] - fn safe_transfers_from_with_data(contract: Contract) { - let alice = Address::random(); + fn safe_transfers_from_with_data( + contract: Contract, + alice: Address, + bob: Address, + ) { contract .sender(alice) ._mint(alice, TOKEN_ID) @@ -1701,7 +1723,7 @@ mod tests { .sender(alice) .safe_transfer_from_with_data( alice, - BOB, + bob, TOKEN_ID, vec![0, 1, 2, 3].into(), ) @@ -1712,26 +1734,27 @@ mod tests { .owner_of(TOKEN_ID) .expect("should return the owner of the token"); - assert_eq!(owner, BOB); + assert_eq!(owner, bob); } #[motsu::test] fn safe_transfers_from_with_data_approved_token( contract: Contract, + alice: Address, + bob: Address, ) { - let alice = Address::random(); contract .sender(alice) - ._mint(BOB, TOKEN_ID) + ._mint(bob, TOKEN_ID) .expect("should mint token to Bob"); contract - .sender(BOB) + .sender(bob) .approve(alice, TOKEN_ID) .expect("should approve Bob's token for Alice"); contract .sender(alice) .safe_transfer_from_with_data( - BOB, + bob, alice, TOKEN_ID, vec![0, 1, 2, 3].into(), @@ -1747,26 +1770,27 @@ mod tests { #[motsu::test] fn safe_transfers_from_with_data_approved_for_all( contract: Contract, + alice: Address, + bob: Address, ) { - let alice = Address::random(); contract .sender(alice) - ._mint(BOB, TOKEN_ID) + ._mint(bob, TOKEN_ID) .expect("should mint token to Bob"); contract - .sender(BOB) + .sender(bob) .set_approval_for_all(alice, true) .expect("should approve all Bob's tokens for Alice"); let approved_for_all = - contract.sender(alice).is_approved_for_all(BOB, alice); + contract.sender(alice).is_approved_for_all(bob, alice); assert!(approved_for_all); contract .sender(alice) .safe_transfer_from_with_data( - BOB, + bob, alice, TOKEN_ID, vec![0, 1, 2, 3].into(), @@ -1783,8 +1807,8 @@ mod tests { #[motsu::test] fn error_when_safe_transfer_from_with_data_transfers_to_invalid_receiver( contract: Contract, + alice: Address, ) { - let alice = Address::random(); let invalid_receiver = Address::ZERO; contract @@ -1819,9 +1843,10 @@ mod tests { #[motsu::test] fn error_when_safe_transfer_from_with_data_transfers_from_incorrect_owner( contract: Contract, + alice: Address, + bob: Address, + dave: Address, ) { - let alice = Address::random(); - contract .sender(alice) ._mint(alice, TOKEN_ID) @@ -1830,8 +1855,8 @@ mod tests { let err = contract .sender(alice) .safe_transfer_from_with_data( - DAVE, - BOB, + dave, + bob, TOKEN_ID, vec![0, 1, 2, 3].into(), ) @@ -1842,7 +1867,7 @@ mod tests { sender, token_id: t_id, owner - }) if sender == DAVE && t_id == TOKEN_ID && owner == alice + }) if sender == dave && t_id == TOKEN_ID && owner == alice )); @@ -1857,16 +1882,17 @@ mod tests { #[motsu::test] fn error_when_safe_transfer_from_with_data_transfers_with_insufficient_approval( contract: Contract, + alice: Address, + bob: Address, ) { - let alice = Address::random(); contract .sender(alice) - ._mint(BOB, TOKEN_ID) + ._mint(bob, TOKEN_ID) .expect("should mint token to Bob"); let err = contract .sender(alice) .safe_transfer_from_with_data( - BOB, + bob, alice, TOKEN_ID, vec![0, 1, 2, 3].into(), @@ -1884,13 +1910,14 @@ mod tests { #[motsu::test] fn error_when_safe_transfer_from_with_data_transfers_nonexistent_token( contract: Contract, + alice: Address, + bob: Address, ) { - let alice = Address::random(); let err = contract .sender(alice) .safe_transfer_from_with_data( alice, - BOB, + bob, TOKEN_ID, vec![0, 1, 2, 3].into(), ) @@ -1904,12 +1931,14 @@ mod tests { } #[motsu::test] - fn error_when_approve_for_nonexistent_token(contract: Contract) { - let alice = Address::random(); - + fn error_when_approve_for_nonexistent_token( + contract: Contract, + alice: Address, + bob: Address, + ) { let err = contract .sender(alice) - .approve(BOB, TOKEN_ID) + .approve(bob, TOKEN_ID) .expect_err("should not approve for a non-existent token"); assert!(matches!( @@ -1921,16 +1950,20 @@ mod tests { } #[motsu::test] - fn error_when_approve_by_invalid_approver(contract: Contract) { - let alice = Address::random(); + fn error_when_approve_by_invalid_approver( + contract: Contract, + alice: Address, + bob: Address, + dave: Address, + ) { contract .sender(alice) - ._mint(BOB, TOKEN_ID) + ._mint(bob, TOKEN_ID) .expect("should mint a token"); let err = contract .sender(alice) - .approve(DAVE, TOKEN_ID) + .approve(dave, TOKEN_ID) .expect_err("should not approve when invalid approver"); assert!(matches!( @@ -1944,8 +1977,8 @@ mod tests { #[motsu::test] fn error_when_approval_for_all_for_invalid_operator( contract: Contract, + alice: Address, ) { - let alice = Address::random(); let invalid_operator = Address::ZERO; let err = contract @@ -1964,8 +1997,8 @@ mod tests { #[motsu::test] fn error_when_get_approved_of_nonexistent_token( contract: Contract, + alice: Address, ) { - let alice = Address::random(); let err = contract .sender(alice) .get_approved(TOKEN_ID) @@ -1980,35 +2013,40 @@ mod tests { } #[motsu::test] - fn owner_of_works(contract: Contract) { - let alice = Address::random(); + fn owner_of_works( + contract: Contract, + alice: Address, + bob: Address, + ) { contract .sender(alice) - ._mint(BOB, TOKEN_ID) + ._mint(bob, TOKEN_ID) .expect("should mint a token"); let owner = contract.sender(alice)._owner_of(TOKEN_ID); - assert_eq!(BOB, owner); + assert_eq!(bob, owner); } #[motsu::test] - fn owner_of_nonexistent_token(contract: Contract) { - let alice = Address::random(); + fn owner_of_nonexistent_token(contract: Contract, alice: Address) { let owner = contract.sender(alice)._owner_of(TOKEN_ID); assert_eq!(Address::ZERO, owner); } #[motsu::test] - fn get_approved_nonexistent_token(contract: Contract) { - let alice = Address::random(); + fn get_approved_nonexistent_token( + contract: Contract, + alice: Address, + ) { let approved = contract.sender(alice)._get_approved(TOKEN_ID); assert_eq!(Address::ZERO, approved); } #[motsu::test] - fn get_approved_token_without_approval(contract: Contract) { - let alice = Address::random(); - + fn get_approved_token_without_approval( + contract: Contract, + alice: Address, + ) { contract .sender(alice) ._mint(alice, TOKEN_ID) @@ -2018,33 +2056,37 @@ mod tests { } #[motsu::test] - fn get_approved_token_with_approval(contract: Contract) { - let alice = Address::random(); - + fn get_approved_token_with_approval( + contract: Contract, + alice: Address, + bob: Address, + ) { contract .sender(alice) ._mint(alice, TOKEN_ID) .expect("should mint a token"); contract .sender(alice) - .approve(BOB, TOKEN_ID) + .approve(bob, TOKEN_ID) .expect("should approve Bob for operations on token"); let approved = contract.sender(alice)._get_approved(TOKEN_ID); - assert_eq!(BOB, approved); + assert_eq!(bob, approved); } #[motsu::test] - fn get_approved_token_with_approval_for_all(contract: Contract) { - let alice = Address::random(); - + fn get_approved_token_with_approval_for_all( + contract: Contract, + alice: Address, + bob: Address, + ) { contract .sender(alice) ._mint(alice, TOKEN_ID) .expect("should mint a token"); contract .sender(alice) - .set_approval_for_all(BOB, true) + .set_approval_for_all(bob, true) .expect("should approve Bob for operations on all Alice's tokens"); let approved = contract.sender(alice)._get_approved(TOKEN_ID); @@ -2052,16 +2094,18 @@ mod tests { } #[motsu::test] - fn is_authorized_nonexistent_token(contract: Contract) { - let alice = Address::random(); + fn is_authorized_nonexistent_token( + contract: Contract, + alice: Address, + bob: Address, + ) { let authorized = - contract.sender(alice)._is_authorized(alice, BOB, TOKEN_ID); + contract.sender(alice)._is_authorized(alice, bob, TOKEN_ID); assert!(!authorized); } #[motsu::test] - fn is_authorized_token_owner(contract: Contract) { - let alice = Address::random(); + fn is_authorized_token_owner(contract: Contract, alice: Address) { contract .sender(alice) ._mint(alice, TOKEN_ID) @@ -2073,55 +2117,66 @@ mod tests { } #[motsu::test] - fn is_authorized_without_approval(contract: Contract) { - let alice = Address::random(); + fn is_authorized_without_approval( + contract: Contract, + alice: Address, + bob: Address, + ) { contract .sender(alice) ._mint(alice, TOKEN_ID) .expect("should mint a token"); let authorized = - contract.sender(alice)._is_authorized(alice, BOB, TOKEN_ID); + contract.sender(alice)._is_authorized(alice, bob, TOKEN_ID); assert!(!authorized); } #[motsu::test] - fn is_authorized_with_approval(contract: Contract) { - let alice = Address::random(); + fn is_authorized_with_approval( + contract: Contract, + alice: Address, + bob: Address, + ) { contract .sender(alice) ._mint(alice, TOKEN_ID) .expect("should mint a token"); contract .sender(alice) - .approve(BOB, TOKEN_ID) + .approve(bob, TOKEN_ID) .expect("should approve Bob for operations on token"); let authorized = - contract.sender(alice)._is_authorized(alice, BOB, TOKEN_ID); + contract.sender(alice)._is_authorized(alice, bob, TOKEN_ID); assert!(authorized); } #[motsu::test] - fn is_authorized_with_approval_for_all(contract: Contract) { - let alice = Address::random(); + fn is_authorized_with_approval_for_all( + contract: Contract, + alice: Address, + bob: Address, + ) { contract .sender(alice) ._mint(alice, TOKEN_ID) .expect("should mint a token"); contract .sender(alice) - .set_approval_for_all(BOB, true) + .set_approval_for_all(bob, true) .expect("should approve Bob for operations on all Alice's tokens"); let authorized = - contract.sender(alice)._is_authorized(alice, BOB, TOKEN_ID); + contract.sender(alice)._is_authorized(alice, bob, TOKEN_ID); assert!(authorized); } #[motsu::test] - fn check_authorized_nonexistent_token(contract: Contract) { - let alice = Address::random(); + fn check_authorized_nonexistent_token( + contract: Contract, + alice: Address, + ) { let err = contract .sender(alice) ._check_authorized(Address::ZERO, alice, TOKEN_ID) @@ -2136,8 +2191,10 @@ mod tests { } #[motsu::test] - fn check_authorized_token_owner(contract: Contract) { - let alice = Address::random(); + fn check_authorized_token_owner( + contract: Contract, + alice: Address, + ) { contract .sender(alice) ._mint(alice, TOKEN_ID) @@ -2150,8 +2207,11 @@ mod tests { } #[motsu::test] - fn check_authorized_without_approval(contract: Contract) { - let alice = Address::random(); + fn check_authorized_without_approval( + contract: Contract, + alice: Address, + bob: Address, + ) { contract .sender(alice) ._mint(alice, TOKEN_ID) @@ -2159,7 +2219,7 @@ mod tests { let err = contract .sender(alice) - ._check_authorized(alice, BOB, TOKEN_ID) + ._check_authorized(alice, bob, TOKEN_ID) .expect_err("should not pass without approval"); assert!(matches!( @@ -2167,47 +2227,52 @@ mod tests { Error::InsufficientApproval(ERC721InsufficientApproval { operator, token_id: t_id - }) if operator == BOB && t_id == TOKEN_ID + }) if operator == bob && t_id == TOKEN_ID )); } #[motsu::test] - fn check_authorized_with_approval(contract: Contract) { - let alice = Address::random(); + fn check_authorized_with_approval( + contract: Contract, + alice: Address, + bob: Address, + ) { contract .sender(alice) ._mint(alice, TOKEN_ID) .expect("should mint a token"); contract .sender(alice) - .approve(BOB, TOKEN_ID) + .approve(bob, TOKEN_ID) .expect("should approve Bob for operations on token"); let result = - contract.sender(alice)._check_authorized(alice, BOB, TOKEN_ID); + contract.sender(alice)._check_authorized(alice, bob, TOKEN_ID); assert!(result.is_ok()); } #[motsu::test] - fn check_authorized_with_approval_for_all(contract: Contract) { - let alice = Address::random(); + fn check_authorized_with_approval_for_all( + contract: Contract, + alice: Address, + bob: Address, + ) { contract .sender(alice) ._mint(alice, TOKEN_ID) .expect("should mint a token"); contract .sender(alice) - .set_approval_for_all(BOB, true) + .set_approval_for_all(bob, true) .expect("should approve Bob for operations on all Alice's tokens"); let result = - contract.sender(alice)._check_authorized(alice, BOB, TOKEN_ID); + contract.sender(alice)._check_authorized(alice, bob, TOKEN_ID); assert!(result.is_ok()); } #[motsu::test] - fn burns(contract: Contract) { - let alice = Address::random(); + fn burns(contract: Contract, alice: Address) { let one = uint!(1_U256); contract @@ -2246,16 +2311,16 @@ mod tests { #[motsu::test] fn error_when_get_approved_of_previous_approval_burned( contract: Contract, + alice: Address, + bob: Address, ) { - let alice = Address::random(); - contract .sender(alice) ._mint(alice, TOKEN_ID) .expect("should mint a token for Alice"); contract .sender(alice) - .approve(BOB, TOKEN_ID) + .approve(bob, TOKEN_ID) .expect("should approve a token for Bob"); contract @@ -2277,8 +2342,10 @@ mod tests { } #[motsu::test] - fn error_when_burn_nonexistent_token(contract: Contract) { - let alice = Address::random(); + fn error_when_burn_nonexistent_token( + contract: Contract, + alice: Address, + ) { let err = contract .sender(alice) ._burn(TOKEN_ID) @@ -2293,37 +2360,39 @@ mod tests { } #[motsu::test] - fn transfers(contract: Contract) { - let alice = Address::random(); + fn transfers(contract: Contract, alice: Address, bob: Address) { contract .sender(alice) ._mint(alice, TOKEN_ID) .expect("should mint a token to Alice"); contract .sender(alice) - ._transfer(alice, BOB, TOKEN_ID) + ._transfer(alice, bob, TOKEN_ID) .expect("should transfer a token from Alice to Bob"); let owner = contract .sender(alice) .owner_of(TOKEN_ID) .expect("should return the owner of the token"); - assert_eq!(owner, BOB); + assert_eq!(owner, bob); } #[motsu::test] - fn transfers_approved_token(contract: Contract) { - let alice = Address::random(); + fn transfers_approved_token( + contract: Contract, + alice: Address, + bob: Address, + ) { contract .sender(alice) - ._mint(BOB, TOKEN_ID) + ._mint(bob, TOKEN_ID) .expect("should mint token to Bob"); contract - .sender(BOB) + .sender(bob) .approve(alice, TOKEN_ID) .expect("should approve Bob's token for Alice"); contract .sender(alice) - ._transfer(BOB, alice, TOKEN_ID) + ._transfer(bob, alice, TOKEN_ID) .expect("should transfer Bob's token to Alice"); let owner = contract .sender(alice) @@ -2333,25 +2402,28 @@ mod tests { } #[motsu::test] - fn transfers_approved_for_all(contract: Contract) { - let alice = Address::random(); + fn transfers_approved_for_all( + contract: Contract, + alice: Address, + bob: Address, + ) { contract .sender(alice) - ._mint(BOB, TOKEN_ID) + ._mint(bob, TOKEN_ID) .expect("should mint token to Bob"); contract - .sender(BOB) + .sender(bob) .set_approval_for_all(alice, true) .expect("should approve all Bob's tokens for Alice"); let approved_for_all = - contract.sender(alice).is_approved_for_all(BOB, alice); + contract.sender(alice).is_approved_for_all(bob, alice); assert!(approved_for_all); contract .sender(alice) - ._transfer(BOB, alice, TOKEN_ID) + ._transfer(bob, alice, TOKEN_ID) .expect("should transfer Bob's token to Alice"); let owner = contract @@ -2364,8 +2436,8 @@ mod tests { #[motsu::test] fn error_when_transfer_transfers_to_invalid_receiver( contract: Contract, + alice: Address, ) { - let alice = Address::random(); let invalid_receiver = Address::ZERO; contract @@ -2395,9 +2467,10 @@ mod tests { #[motsu::test] fn error_when_transfer_transfers_from_incorrect_owner( contract: Contract, + alice: Address, + bob: Address, + dave: Address, ) { - let alice = Address::random(); - contract .sender(alice) ._mint(alice, TOKEN_ID) @@ -2405,7 +2478,7 @@ mod tests { let err = contract .sender(alice) - ._transfer(DAVE, BOB, TOKEN_ID) + ._transfer(dave, bob, TOKEN_ID) .expect_err("should not transfer from incorrect owner"); assert!(matches!( @@ -2414,7 +2487,7 @@ mod tests { sender, token_id: t_id, owner - }) if sender == DAVE && t_id == TOKEN_ID && owner == alice + }) if sender == dave && t_id == TOKEN_ID && owner == alice )); // NOTE: We can't check this here, but we cover this in our e2e tests. @@ -2427,11 +2500,12 @@ mod tests { #[motsu::test] fn error_when_transfer_transfers_nonexistent_token( contract: Contract, + alice: Address, + bob: Address, ) { - let alice = Address::random(); let err = contract .sender(alice) - ._transfer(alice, BOB, TOKEN_ID) + ._transfer(alice, bob, TOKEN_ID) .expect_err("should not transfer a non-existent token"); assert!(matches!( err, @@ -2442,8 +2516,11 @@ mod tests { } #[motsu::test] - fn safe_transfers_internal(contract: Contract) { - let alice = Address::random(); + fn safe_transfers_internal( + contract: Contract, + alice: Address, + bob: Address, + ) { contract .sender(alice) ._mint(alice, TOKEN_ID) @@ -2451,7 +2528,7 @@ mod tests { contract .sender(alice) - ._safe_transfer(alice, BOB, TOKEN_ID, &vec![0, 1, 2, 3].into()) + ._safe_transfer(alice, bob, TOKEN_ID, &vec![0, 1, 2, 3].into()) .expect("should transfer a token from Alice to Bob"); let owner = contract @@ -2459,23 +2536,26 @@ mod tests { .owner_of(TOKEN_ID) .expect("should return the owner of the token"); - assert_eq!(owner, BOB); + assert_eq!(owner, bob); } #[motsu::test] - fn safe_transfers_internal_approved_token(contract: Contract) { - let alice = Address::random(); + fn safe_transfers_internal_approved_token( + contract: Contract, + alice: Address, + bob: Address, + ) { contract .sender(alice) - ._mint(BOB, TOKEN_ID) + ._mint(bob, TOKEN_ID) .expect("should mint token to Bob"); contract - .sender(BOB) + .sender(bob) .approve(alice, TOKEN_ID) .expect("should approve Bob's token for Alice"); contract .sender(alice) - ._safe_transfer(BOB, alice, TOKEN_ID, &vec![0, 1, 2, 3].into()) + ._safe_transfer(bob, alice, TOKEN_ID, &vec![0, 1, 2, 3].into()) .expect("should transfer Bob's token to Alice"); let owner = contract .sender(alice) @@ -2485,25 +2565,28 @@ mod tests { } #[motsu::test] - fn safe_transfers_internal_approved_for_all(contract: Contract) { - let alice = Address::random(); + fn safe_transfers_internal_approved_for_all( + contract: Contract, + alice: Address, + bob: Address, + ) { contract .sender(alice) - ._mint(BOB, TOKEN_ID) + ._mint(bob, TOKEN_ID) .expect("should mint token to Bob"); contract - .sender(BOB) + .sender(bob) .set_approval_for_all(alice, true) .expect("should approve all Bob's tokens for Alice"); let approved_for_all = - contract.sender(alice).is_approved_for_all(BOB, alice); + contract.sender(alice).is_approved_for_all(bob, alice); assert!(approved_for_all); contract .sender(alice) - ._safe_transfer(BOB, alice, TOKEN_ID, &vec![0, 1, 2, 3].into()) + ._safe_transfer(bob, alice, TOKEN_ID, &vec![0, 1, 2, 3].into()) .expect("should transfer Bob's token to Alice"); let owner = contract @@ -2516,8 +2599,8 @@ mod tests { #[motsu::test] fn error_when_internal_safe_transfer_to_invalid_receiver( contract: Contract, + alice: Address, ) { - let alice = Address::random(); let invalid_receiver = Address::ZERO; contract @@ -2552,9 +2635,10 @@ mod tests { #[motsu::test] fn error_when_internal_safe_transfer_from_incorrect_owner( contract: Contract, + alice: Address, + bob: Address, + dave: Address, ) { - let alice = Address::random(); - contract .sender(alice) ._mint(alice, TOKEN_ID) @@ -2562,7 +2646,7 @@ mod tests { let err = contract .sender(alice) - ._safe_transfer(DAVE, BOB, TOKEN_ID, &vec![0, 1, 2, 3].into()) + ._safe_transfer(dave, bob, TOKEN_ID, &vec![0, 1, 2, 3].into()) .expect_err("should not transfer the token from incorrect owner"); assert!(matches!( err, @@ -2570,7 +2654,7 @@ mod tests { sender, token_id: t_id, owner - }) if sender == DAVE && t_id == TOKEN_ID && owner == alice + }) if sender == dave && t_id == TOKEN_ID && owner == alice )); // NOTE: We can't check this here, but we cover this in our e2e tests. @@ -2583,11 +2667,12 @@ mod tests { #[motsu::test] fn error_when_internal_safe_transfer_nonexistent_token( contract: Contract, + alice: Address, + bob: Address, ) { - let alice = Address::random(); let err = contract .sender(alice) - ._safe_transfer(alice, BOB, TOKEN_ID, &vec![0, 1, 2, 3].into()) + ._safe_transfer(alice, bob, TOKEN_ID, &vec![0, 1, 2, 3].into()) .expect_err("should not transfer a non-existent token"); assert!(matches!( @@ -2601,11 +2686,12 @@ mod tests { #[motsu::test] fn error_when_approve_internal_for_nonexistent_token( contract: Contract, + alice: Address, + bob: Address, ) { - let alice = Address::random(); let err = contract .sender(alice) - ._approve(BOB, TOKEN_ID, msg::sender(), false) + ._approve(bob, TOKEN_ID, msg::sender(), false) .expect_err("should not approve for a non-existent token"); assert!(matches!( @@ -2619,16 +2705,18 @@ mod tests { #[motsu::test] fn error_when_approve_internal_by_invalid_approver( contract: Contract, + alice: Address, + bob: Address, + dave: Address, ) { - let alice = Address::random(); contract .sender(alice) - ._mint(BOB, TOKEN_ID) + ._mint(bob, TOKEN_ID) .expect("should mint a token"); let err = contract .sender(alice) - ._approve(DAVE, TOKEN_ID, alice, false) + ._approve(dave, TOKEN_ID, alice, false) .expect_err("should not approve when invalid approver"); assert!(matches!( @@ -2642,8 +2730,8 @@ mod tests { #[motsu::test] fn error_when_approval_for_all_internal_for_invalid_operator( contract: Contract, + alice: Address, ) { - let alice = Address::random(); let invalid_operator = Address::ZERO; let err = contract @@ -2660,11 +2748,14 @@ mod tests { } #[motsu::test] - fn require_owned_works(contract: Contract) { - let alice = Address::random(); + fn require_owned_works( + contract: Contract, + alice: Address, + bob: Address, + ) { contract .sender(alice) - ._mint(BOB, TOKEN_ID) + ._mint(bob, TOKEN_ID) .expect("should mint a token"); let owner = contract @@ -2672,14 +2763,14 @@ mod tests { ._require_owned(TOKEN_ID) .expect("should return the owner of the token"); - assert_eq!(BOB, owner); + assert_eq!(bob, owner); } #[motsu::test] fn error_when_require_owned_for_nonexistent_token( contract: Contract, + alice: Address, ) { - let alice = Address::random(); let err = contract .sender(alice) ._require_owned(TOKEN_ID) @@ -2735,8 +2826,8 @@ mod tests { fn on_erc721_received( erc721: Contract, receiver: Contract, + alice: Address, ) { - let alice = Address::random(); erc721 .sender(alice) ._safe_mint(receiver.address(), TOKEN_ID, &vec![0, 1, 2, 3].into()) From fdd8035faad794049a5362db816f037b237e442e Mon Sep 17 00:00:00 2001 From: Alisander Qoshqosh Date: Sat, 1 Feb 2025 00:00:50 +0400 Subject: [PATCH 079/109] use user injection at erc20 --- contracts/src/token/erc1155/mod.rs | 1 - .../src/token/erc20/extensions/burnable.rs | 29 +++-- .../src/token/erc20/extensions/capped.rs | 4 +- contracts/src/token/erc20/mod.rs | 101 +++++++++--------- 4 files changed, 66 insertions(+), 69 deletions(-) diff --git a/contracts/src/token/erc1155/mod.rs b/contracts/src/token/erc1155/mod.rs index def9d6da4..de645fb58 100644 --- a/contracts/src/token/erc1155/mod.rs +++ b/contracts/src/token/erc1155/mod.rs @@ -1197,7 +1197,6 @@ enum Transfer { mod tests { use alloy_primitives::{address, uint, Address, U256}; use motsu::prelude::Contract; - use stylus_sdk::msg; use super::{ ERC1155InsufficientBalance, ERC1155InvalidArrayLength, diff --git a/contracts/src/token/erc20/extensions/burnable.rs b/contracts/src/token/erc20/extensions/burnable.rs index 2de39bb01..56d4ac6e5 100644 --- a/contracts/src/token/erc20/extensions/burnable.rs +++ b/contracts/src/token/erc20/extensions/burnable.rs @@ -86,15 +86,13 @@ mod tests { use crate::token::erc20::{Erc20, Error, IErc20}; #[motsu::test] - fn burns(contract: Contract) { - let alice = Address::random(); - let bob = Address::random(); + fn burns(contract: Contract, alice: Address) { let zero = U256::ZERO; let one = uint!(1_U256); assert_eq!(zero, contract.sender(alice).total_supply()); - // Mint some tokens for msg::sender(). + // Mint some tokens for Alice. let two = uint!(2_U256); contract.sender(alice)._update(Address::ZERO, alice, two).unwrap(); @@ -108,10 +106,12 @@ mod tests { } #[motsu::test] - fn burns_errors_when_insufficient_balance(contract: Contract) { + fn burns_errors_when_insufficient_balance( + contract: Contract, + alice: Address, + ) { let zero = U256::ZERO; let one = uint!(1_U256); - let alice = Address::random(); assert_eq!(zero, contract.sender(alice).balance_of(alice)); @@ -120,10 +120,7 @@ mod tests { } #[motsu::test] - fn burn_from(contract: Contract) { - let alice = Address::random(); - let bob = Address::random(); - + fn burn_from(contract: Contract, alice: Address, bob: Address) { // Alice approves `msg::sender`. let one = uint!(1_U256); contract.sender(alice).approve(bob, one).unwrap(); @@ -142,10 +139,11 @@ mod tests { } #[motsu::test] - fn burns_from_errors_when_insufficient_balance(contract: Contract) { - let alice = Address::random(); - let bob = Address::random(); - + fn burns_from_errors_when_insufficient_balance( + contract: Contract, + alice: Address, + bob: Address, + ) { // Alice approves `msg::sender`. let zero = U256::ZERO; let one = uint!(1_U256); @@ -162,9 +160,8 @@ mod tests { #[motsu::test] fn burns_from_errors_when_insufficient_allowance( contract: Contract, + alice: Address, ) { - let alice = Address::random(); - // Mint some tokens for Alice. let one = uint!(1_U256); contract.sender(alice)._update(Address::ZERO, alice, one).unwrap(); diff --git a/contracts/src/token/erc20/extensions/capped.rs b/contracts/src/token/erc20/extensions/capped.rs index 51388a97a..48d703afe 100644 --- a/contracts/src/token/erc20/extensions/capped.rs +++ b/contracts/src/token/erc20/extensions/capped.rs @@ -72,9 +72,7 @@ mod tests { unsafe impl TopLevelStorage for Capped {} #[motsu::test] - fn cap_works(contract: Contract) { - let alice = Address::random(); - + fn cap_works(contract: Contract, alice: Address) { let value = uint!(2024_U256); contract.init(alice, |contract| contract._cap.set(value)); assert_eq!(contract.sender(alice).cap(), value); diff --git a/contracts/src/token/erc20/mod.rs b/contracts/src/token/erc20/mod.rs index 3178316ba..17b9856b6 100644 --- a/contracts/src/token/erc20/mod.rs +++ b/contracts/src/token/erc20/mod.rs @@ -593,7 +593,7 @@ impl Erc20 { #[cfg(all(test, feature = "std"))] mod tests { - use alloy_primitives::{address, uint, Address, U256}; + use alloy_primitives::{uint, Address, U256}; use motsu::prelude::Contract; use stylus_sdk::prelude::TopLevelStorage; @@ -603,8 +603,7 @@ mod tests { unsafe impl TopLevelStorage for Erc20 {} #[motsu::test] - fn update_mint(contract: Contract) { - let alice = address!("A11CEacF9aa32246d767FCCD72e02d6bCbcC375d"); + fn update_mint(contract: Contract, alice: Address) { let one = uint!(1_U256); // Store initial balance & supply. @@ -625,8 +624,10 @@ mod tests { #[motsu::test] #[should_panic = "should not exceed `U256::MAX` for `_total_supply`"] - fn update_mint_errors_arithmetic_overflow(contract: Contract) { - let alice = address!("A11CEacF9aa32246d767FCCD72e02d6bCbcC375d"); + fn update_mint_errors_arithmetic_overflow( + contract: Contract, + alice: Address, + ) { let one = uint!(1_U256); assert_eq!(U256::ZERO, contract.sender(alice).balance_of(alice)); assert_eq!(U256::ZERO, contract.sender(alice).total_supply()); @@ -643,8 +644,7 @@ mod tests { } #[motsu::test] - fn mint_works(contract: Contract) { - let alice = address!("A11CEacF9aa32246d767FCCD72e02d6bCbcC375d"); + fn mint_works(contract: Contract, alice: Address) { let one = uint!(1_U256); // Store initial balance & supply. @@ -664,8 +664,7 @@ mod tests { } #[motsu::test] - fn mint_errors_invalid_receiver(contract: Contract) { - let alice = address!("A11CEacF9aa32246d767FCCD72e02d6bCbcC375d"); + fn mint_errors_invalid_receiver(contract: Contract, alice: Address) { let receiver = Address::ZERO; let one = uint!(1_U256); @@ -687,8 +686,10 @@ mod tests { #[motsu::test] #[should_panic = "should not exceed `U256::MAX` for `_total_supply`"] - fn mint_errors_arithmetic_overflow(contract: Contract) { - let alice = address!("A11CEacF9aa32246d767FCCD72e02d6bCbcC375d"); + fn mint_errors_arithmetic_overflow( + contract: Contract, + alice: Address, + ) { let one = uint!(1_U256); assert_eq!(U256::ZERO, contract.sender(alice).balance_of(alice)); assert_eq!(U256::ZERO, contract.sender(alice).total_supply()); @@ -704,8 +705,7 @@ mod tests { } #[motsu::test] - fn update_burn(contract: Contract) { - let alice = address!("A11CEacF9aa32246d767FCCD72e02d6bCbcC375d"); + fn update_burn(contract: Contract, alice: Address) { let one = uint!(1_U256); let two = uint!(2_U256); @@ -733,8 +733,10 @@ mod tests { } #[motsu::test] - fn update_burn_errors_insufficient_balance(contract: Contract) { - let alice = address!("A11CEacF9aa32246d767FCCD72e02d6bCbcC375d"); + fn update_burn_errors_insufficient_balance( + contract: Contract, + alice: Address, + ) { let one = uint!(1_U256); let two = uint!(2_U256); @@ -759,9 +761,11 @@ mod tests { } #[motsu::test] - fn update_transfer(contract: Contract) { - let alice = address!("A11CEacF9aa32246d767FCCD72e02d6bCbcC375d"); - let bob = address!("B0B0cB49ec2e96DF5F5fFB081acaE66A2cBBc2e2"); + fn update_transfer( + contract: Contract, + alice: Address, + bob: Address, + ) { let one = uint!(1_U256); // Initialize state for the test case: @@ -797,9 +801,11 @@ mod tests { } #[motsu::test] - fn update_transfer_errors_insufficient_balance(contract: Contract) { - let alice = address!("A11CEacF9aa32246d767FCCD72e02d6bCbcC375d"); - let bob = address!("B0B0cB49ec2e96DF5F5fFB081acaE66A2cBBc2e2"); + fn update_transfer_errors_insufficient_balance( + contract: Contract, + alice: Address, + bob: Address, + ) { let one = uint!(1_U256); // Initialize state for the test case: @@ -832,10 +838,7 @@ mod tests { } #[motsu::test] - fn transfers(contract: Contract) { - let alice = address!("A11CEacF9aa32246d767FCCD72e02d6bCbcC375d"); - let bob = address!("B0B0cB49ec2e96DF5F5fFB081acaE66A2cBBc2e2"); - + fn transfers(contract: Contract, alice: Address, bob: Address) { // Mint some tokens for Alice. let two = uint!(2_U256); contract.sender(alice)._update(Address::ZERO, alice, two).unwrap(); @@ -849,10 +852,7 @@ mod tests { } #[motsu::test] - fn transfer_from(contract: Contract) { - let alice = address!("A11CEacF9aa32246d767FCCD72e02d6bCbcC375d"); - let bob = address!("B0B0cB49ec2e96DF5F5fFB081acaE66A2cBBc2e2"); - + fn transfer_from(contract: Contract, alice: Address, bob: Address) { // Alice approves Bob. let one = uint!(1_U256); contract.sender(alice).approve(bob, one).unwrap(); @@ -872,10 +872,9 @@ mod tests { #[motsu::test] fn error_when_transfer_with_insufficient_balance( contract: Contract, + alice: Address, + bob: Address, ) { - let alice = address!("A11CEacF9aa32246d767FCCD72e02d6bCbcC375d"); - let bob = address!("B0B0cB49ec2e96DF5F5fFB081acaE66A2cBBc2e2"); - // Alice approves Bob. let one = uint!(1_U256); contract.sender(alice).approve(bob, one).unwrap(); @@ -885,10 +884,11 @@ mod tests { } #[motsu::test] - fn error_when_transfer_to_invalid_receiver(contract: Contract) { - let alice = address!("A11CEacF9aa32246d767FCCD72e02d6bCbcC375d"); - let bob = address!("B0B0cB49ec2e96DF5F5fFB081acaE66A2cBBc2e2"); - + fn error_when_transfer_to_invalid_receiver( + contract: Contract, + alice: Address, + bob: Address, + ) { // Alice approves Bob. let one = uint!(1_U256); contract.sender(alice).approve(bob, one).unwrap(); @@ -901,10 +901,9 @@ mod tests { #[motsu::test] fn errors_when_transfer_with_insufficient_allowance( contract: Contract, + alice: Address, + bob: Address, ) { - let alice = address!("A11CEacF9aa32246d767FCCD72e02d6bCbcC375d"); - let bob = address!("B0B0cB49ec2e96DF5F5fFB081acaE66A2cBBc2e2"); - // Mint some tokens for Alice. let one = uint!(1_U256); contract.sender(alice)._update(Address::ZERO, alice, one).unwrap(); @@ -915,10 +914,11 @@ mod tests { } #[motsu::test] - fn approves_and_reads_allowance(contract: Contract) { - let alice = address!("A11CEacF9aa32246d767FCCD72e02d6bCbcC375d"); - let bob = address!("B0B0cB49ec2e96DF5F5fFB081acaE66A2cBBc2e2"); - + fn approves_and_reads_allowance( + contract: Contract, + alice: Address, + bob: Address, + ) { let allowance = contract.sender(alice).allowance(alice, bob); assert_eq!(U256::ZERO, allowance); @@ -929,19 +929,22 @@ mod tests { } #[motsu::test] - fn error_when_approve_for_invalid_spender(contract: Contract) { + fn error_when_approve_for_invalid_spender( + contract: Contract, + alice: Address, + ) { // alice approves `Address::ZERO` - let alice = address!("A11CEacF9aa32246d767FCCD72e02d6bCbcC375d"); let one = uint!(1_U256); let result = contract.sender(alice).approve(Address::ZERO, one); assert!(matches!(result, Err(Error::InvalidSpender(_)))); } #[motsu::test] - fn error_when_invalid_approver(contract: Contract) { - let alice = address!("A11CEacF9aa32246d767FCCD72e02d6bCbcC375d"); - let bob = address!("B0B0cB49ec2e96DF5F5fFB081acaE66A2cBBc2e2"); - + fn error_when_invalid_approver( + contract: Contract, + alice: Address, + bob: Address, + ) { let one = uint!(1_U256); let result = contract.sender(alice)._approve(Address::ZERO, bob, one, false); From b1fbed2fa16ee344a62d710fd2f464abca151e55 Mon Sep 17 00:00:00 2001 From: Alisander Qoshqosh Date: Sat, 1 Feb 2025 00:21:24 +0400 Subject: [PATCH 080/109] use user injection at erc1155 --- contracts/src/token/erc1155/mod.rs | 246 +++++++++++++++-------------- 1 file changed, 126 insertions(+), 120 deletions(-) diff --git a/contracts/src/token/erc1155/mod.rs b/contracts/src/token/erc1155/mod.rs index de645fb58..114743f3e 100644 --- a/contracts/src/token/erc1155/mod.rs +++ b/contracts/src/token/erc1155/mod.rs @@ -1195,7 +1195,7 @@ enum Transfer { #[cfg(all(test, feature = "std"))] mod tests { - use alloy_primitives::{address, uint, Address, U256}; + use alloy_primitives::{uint, Address, U256}; use motsu::prelude::Contract; use super::{ @@ -1207,12 +1207,6 @@ mod tests { }; use crate::utils::introspection::erc165::IErc165; - const ALICE: Address = address!("A11CEacF9aa32246d767FCCD72e02d6bCbcC375d"); - const BOB: Address = address!("F4EaCDAbEf3c8f1EdE91b6f2A6840bc2E4DD3526"); - const DAVE: Address = address!("0BB78F7e7132d1651B4Fd884B7624394e92156F1"); - const CHARLIE: Address = - address!("B0B0cB49ec2e96DF5F5fFB081acaE66A2cBBc2e2"); - pub(crate) fn random_token_ids(size: usize) -> Vec { (0..size).map(U256::from).collect() } @@ -1263,22 +1257,28 @@ mod tests { } #[motsu::test] - fn balance_of_zero_balance(contract: Contract) { - let owner = ALICE; + fn balance_of_zero_balance(contract: Contract, alice: Address) { + let owner = alice; let token_id = random_token_ids(1)[0]; - let balance = contract.sender(ALICE).balance_of(owner, token_id); + let balance = contract.sender(alice).balance_of(owner, token_id); assert_eq!(U256::ZERO, balance); } #[motsu::test] - fn error_when_array_length_mismatch(contract: Contract) { + fn error_when_array_length_mismatch( + contract: Contract, + alice: Address, + bob: Address, + dave: Address, + charlie: Address, + ) { let token_ids = random_token_ids(3); - let accounts = vec![ALICE, BOB, DAVE, CHARLIE]; + let accounts = vec![alice, bob, dave, charlie]; let ids_length = U256::from(token_ids.len()); let accounts_length = U256::from(accounts.len()); let err = contract - .sender(ALICE) + .sender(alice) .balance_of_batch(accounts, token_ids) .expect_err("should return `Error::InvalidArrayLength`"); @@ -1292,11 +1292,17 @@ mod tests { } #[motsu::test] - fn balance_of_batch_zero_balance(contract: Contract) { + fn balance_of_batch_zero_balance( + contract: Contract, + alice: Address, + bob: Address, + dave: Address, + charlie: Address, + ) { let token_ids = random_token_ids(4); - let accounts = vec![ALICE, BOB, DAVE, CHARLIE]; + let accounts = vec![alice, bob, dave, charlie]; let balances = contract - .sender(ALICE) + .sender(alice) .balance_of_batch(accounts, token_ids) .expect("should return a vector of `U256::ZERO`"); @@ -1305,10 +1311,11 @@ mod tests { } #[motsu::test] - fn set_approval_for_all(contract: Contract) { - let alice = ALICE; - let bob = BOB; - + fn set_approval_for_all( + contract: Contract, + alice: Address, + bob: Address, + ) { contract.init(alice, |contract| { contract._operator_approvals.setter(alice).setter(bob).set(false); }); @@ -1328,8 +1335,8 @@ mod tests { #[motsu::test] fn error_when_invalid_operator_set_approval_for_all( contract: Contract, + alice: Address, ) { - let alice = ALICE; let invalid_operator = Address::ZERO; let err = contract @@ -1346,8 +1353,7 @@ mod tests { } #[motsu::test] - fn mints(contract: Contract) { - let alice = ALICE; + fn mints(contract: Contract, alice: Address) { let token_id = random_token_ids(1)[0]; let value = random_values(1)[0]; @@ -1362,8 +1368,10 @@ mod tests { } #[motsu::test] - fn error_when_mints_to_invalid_receiver(contract: Contract) { - let alice = ALICE; + fn error_when_mints_to_invalid_receiver( + contract: Contract, + alice: Address, + ) { let invalid_receiver = Address::ZERO; let token_id = random_token_ids(1)[0]; let value = random_values(1)[0]; @@ -1382,8 +1390,7 @@ mod tests { } #[motsu::test] - fn mints_batch(contract: Contract) { - let alice = ALICE; + fn mints_batch(contract: Contract, alice: Address) { let token_ids = random_token_ids(4); let values = random_values(4); @@ -1413,8 +1420,7 @@ mod tests { } #[motsu::test] - fn mints_batch_same_token(contract: Contract) { - let alice = ALICE; + fn mints_batch_same_token(contract: Contract, alice: Address) { let token_id = uint!(1_U256); let values = random_values(4); let expected_balance: U256 = values.iter().sum(); @@ -1443,8 +1449,10 @@ mod tests { } #[motsu::test] - fn error_when_batch_mints_to_invalid_receiver(contract: Contract) { - let alice = ALICE; + fn error_when_batch_mints_to_invalid_receiver( + contract: Contract, + alice: Address, + ) { let token_ids = random_token_ids(1); let values = random_values(1); let invalid_receiver = Address::ZERO; @@ -1468,8 +1476,10 @@ mod tests { } #[motsu::test] - fn error_when_batch_mints_not_equal_arrays(contract: Contract) { - let alice = ALICE; + fn error_when_batch_mints_not_equal_arrays( + contract: Contract, + alice: Address, + ) { let token_ids = random_token_ids(3); let values = random_values(4); @@ -1489,8 +1499,7 @@ mod tests { } #[motsu::test] - fn burns(contract: Contract) { - let alice = ALICE; + fn burns(contract: Contract, alice: Address) { let (token_ids, values) = contract.init(alice, |contract| init(contract, alice, 1)); @@ -1508,8 +1517,10 @@ mod tests { } #[motsu::test] - fn error_when_burns_from_invalid_sender(contract: Contract) { - let alice = ALICE; + fn error_when_burns_from_invalid_sender( + contract: Contract, + alice: Address, + ) { let (token_ids, values) = contract.init(alice, |contract| init(contract, alice, 1)); let invalid_sender = Address::ZERO; @@ -1528,8 +1539,10 @@ mod tests { } #[motsu::test] - fn error_when_burns_with_insufficient_balance(contract: Contract) { - let alice = ALICE; + fn error_when_burns_with_insufficient_balance( + contract: Contract, + alice: Address, + ) { let (token_ids, values) = contract.init(alice, |contract| init(contract, alice, 1)); @@ -1545,13 +1558,12 @@ mod tests { balance, needed, token_id - }) if sender == ALICE && balance == values[0] && needed == values[0] + uint!(1_U256) && token_id == token_ids[0] + }) if sender == alice && balance == values[0] && needed == values[0] + uint!(1_U256) && token_id == token_ids[0] )); } #[motsu::test] - fn burns_batch(contract: Contract) { - let alice = ALICE; + fn burns_batch(contract: Contract, alice: Address) { let (token_ids, values) = contract.init(alice, |contract| init(contract, alice, 4)); @@ -1569,8 +1581,7 @@ mod tests { } #[motsu::test] - fn burns_batch_same_token(contract: Contract) { - let alice = ALICE; + fn burns_batch_same_token(contract: Contract, alice: Address) { let token_id = uint!(1_U256); let value = uint!(80_U256); @@ -1600,8 +1611,10 @@ mod tests { } #[motsu::test] - fn error_when_batch_burns_from_invalid_sender(contract: Contract) { - let alice = ALICE; + fn error_when_batch_burns_from_invalid_sender( + contract: Contract, + alice: Address, + ) { let (token_ids, values) = contract.init(alice, |contract| init(contract, alice, 4)); let invalid_sender = Address::ZERO; @@ -1622,8 +1635,8 @@ mod tests { #[motsu::test] fn error_when_batch_burns_with_insufficient_balance( contract: Contract, + alice: Address, ) { - let alice = ALICE; let (token_ids, values) = contract.init(alice, |contract| init(contract, alice, 4)); @@ -1650,8 +1663,10 @@ mod tests { } #[motsu::test] - fn error_when_batch_burns_not_equal_arrays(contract: Contract) { - let alice = ALICE; + fn error_when_batch_burns_not_equal_arrays( + contract: Contract, + alice: Address, + ) { let (token_ids, values) = contract.init(alice, |contract| init(contract, alice, 3)); @@ -1671,11 +1686,12 @@ mod tests { } #[motsu::test] - fn safe_transfer_from(contract: Contract) { - let alice = ALICE; - let bob = BOB; - let dave = DAVE; - + fn safe_transfer_from( + contract: Contract, + alice: Address, + bob: Address, + dave: Address, + ) { let (token_ids, values) = contract.init(alice, |contract| init(contract, bob, 2)); let amount_one = values[0] - uint!(1_U256); @@ -1719,8 +1735,8 @@ mod tests { #[motsu::test] fn error_when_invalid_receiver_safe_transfer_from( contract: Contract, + alice: Address, ) { - let alice = ALICE; let (token_ids, values) = contract.init(alice, |contract| init(contract, alice, 1)); let invalid_receiver = Address::ZERO; @@ -1763,7 +1779,7 @@ mod tests { .sender(alice) .safe_transfer_from( invalid_sender, - BOB, + bob, token_ids[0], values[0], vec![].into(), @@ -1781,10 +1797,9 @@ mod tests { #[motsu::test] fn error_when_missing_approval_safe_transfer_from( contract: Contract, + alice: Address, + bob: Address, ) { - let alice = ALICE; - let bob = BOB; - let (token_ids, values) = contract.init(alice, |contract| init(contract, alice, 1)); @@ -1811,11 +1826,10 @@ mod tests { #[motsu::test] fn error_when_insufficient_balance_safe_transfer_from( contract: Contract, + alice: Address, + bob: Address, + dave: Address, ) { - let alice = ALICE; - let bob = BOB; - let dave = DAVE; - let (token_ids, values) = contract.init(alice, |contract| init(contract, bob, 1)); contract @@ -1846,11 +1860,12 @@ mod tests { } #[motsu::test] - fn safe_transfer_from_with_data(contract: Contract) { - let alice = ALICE; - let dave = DAVE; - let charlie = CHARLIE; - + fn safe_transfer_from_with_data( + contract: Contract, + alice: Address, + dave: Address, + charlie: Address, + ) { let (token_ids, values) = contract.init(alice, |contract| init(contract, dave, 1)); @@ -1878,10 +1893,9 @@ mod tests { #[motsu::test] fn error_when_invalid_receiver_safe_transfer_from_with_data( contract: Contract, + alice: Address, + dave: Address, ) { - let alice = ALICE; - let dave = DAVE; - let (token_ids, values) = contract.init(alice, |contract| init(contract, dave, 1)); let invalid_receiver = Address::ZERO; @@ -1924,7 +1938,7 @@ mod tests { .sender(alice) .safe_transfer_from( invalid_sender, - CHARLIE, + charlie, token_ids[0], values[0], vec![0, 1, 2, 3].into(), @@ -1942,10 +1956,9 @@ mod tests { #[motsu::test] fn error_when_missing_approval_safe_transfer_from_with_data( contract: Contract, + alice: Address, + bob: Address, ) { - let alice = ALICE; - let bob = BOB; - let (token_ids, values) = contract.init(alice, |contract| init(contract, alice, 1)); @@ -1972,11 +1985,10 @@ mod tests { #[motsu::test] fn error_when_insufficient_balance_safe_transfer_from_with_data( contract: Contract, + alice: Address, + bob: Address, + dave: Address, ) { - let alice = ALICE; - let bob = BOB; - let dave = DAVE; - let (token_ids, values) = contract.init(alice, |contract| init(contract, bob, 1)); @@ -2008,11 +2020,12 @@ mod tests { } #[motsu::test] - fn safe_batch_transfer_from(contract: Contract) { - let alice = ALICE; - let bob = BOB; - let dave = DAVE; - + fn safe_batch_transfer_from( + contract: Contract, + alice: Address, + bob: Address, + dave: Address, + ) { let (token_ids, values) = contract.init(alice, |contract| init(contract, dave, 2)); let amount_one = values[0] - uint!(1_U256); @@ -2046,9 +2059,8 @@ mod tests { #[motsu::test] fn error_when_invalid_receiver_safe_batch_transfer_from( contract: Contract, + alice: Address, ) { - let alice = ALICE; - let (token_ids, values) = contract.init(alice, |contract| init(contract, alice, 4)); let invalid_receiver = Address::ZERO; @@ -2077,7 +2089,7 @@ mod tests { fn error_when_invalid_sender_safe_batch_transfer_from( contract: Contract, ) { - let alice = ALICE; + let (token_ids, values) = contract.init(alice, |contract| init(contract, alice, 4)); let invalid_sender = Address::ZERO; @@ -2088,10 +2100,10 @@ mod tests { .unwrap(); let err = contract - .sender(ALICE) + .sender(alice) .safe_batch_transfer_from( invalid_sender, - CHARLIE, + charlie, token_ids.clone(), values.clone(), vec![].into(), @@ -2109,10 +2121,9 @@ mod tests { #[motsu::test] fn error_when_missing_approval_safe_batch_transfer_from( contract: Contract, + alice: Address, + bob: Address, ) { - let alice = ALICE; - let bob = BOB; - let (token_ids, values) = contract.init(alice, |contract| init(contract, alice, 2)); @@ -2139,11 +2150,10 @@ mod tests { #[motsu::test] fn error_when_insufficient_balance_safe_batch_transfer_from( contract: Contract, + alice: Address, + bob: Address, + charlie: Address, ) { - let alice = ALICE; - let charlie = CHARLIE; - let bob = BOB; - let (token_ids, values) = contract.init(alice, |contract| init(contract, charlie, 2)); @@ -2177,11 +2187,10 @@ mod tests { #[motsu::test] fn error_when_not_equal_arrays_safe_batch_transfer_from( contract: Contract, + alice: Address, + dave: Address, + charlie: Address, ) { - let alice = ALICE; - let dave = DAVE; - let charlie = CHARLIE; - let (token_ids, values) = contract.init(alice, |contract| init(contract, alice, 4)); @@ -2212,11 +2221,12 @@ mod tests { } #[motsu::test] - fn safe_batch_transfer_from_with_data(contract: Contract) { - let alice = ALICE; - let bob = BOB; - let dave = DAVE; - + fn safe_batch_transfer_from_with_data( + contract: Contract, + alice: Address, + bob: Address, + dave: Address, + ) { let (token_ids, values) = contract.init(alice, |contract| init(contract, dave, 2)); @@ -2248,9 +2258,8 @@ mod tests { #[motsu::test] fn error_when_invalid_receiver_safe_batch_transfer_from_with_data( contract: Contract, + alice: Address, ) { - let alice = ALICE; - let (token_ids, values) = contract.init(alice, |contract| init(contract, alice, 4)); let invalid_receiver = Address::ZERO; @@ -2280,8 +2289,8 @@ mod tests { fn error_when_invalid_sender_safe_batch_transfer_from_with_data( contract: Contract, ) { - let alice = ALICE; - let charlie = CHARLIE; + + let charlie = charlie; let (token_ids, values) = contract.init(alice, |contract| init(contract, alice, 4)); @@ -2314,10 +2323,9 @@ mod tests { #[motsu::test] fn error_when_missing_approval_safe_batch_transfer_from_with_data( contract: Contract, + alice: Address, + bob: Address, ) { - let alice = ALICE; - let bob = BOB; - let (token_ids, values) = contract.init(alice, |contract| init(contract, alice, 2)); @@ -2344,11 +2352,10 @@ mod tests { #[motsu::test] fn error_when_insufficient_balance_safe_batch_transfer_from_with_data( contract: Contract, + alice: Address, + bob: Address, + charlie: Address, ) { - let alice = ALICE; - let bob = BOB; - let charlie = CHARLIE; - let (token_ids, values) = contract.init(alice, |contract| init(contract, charlie, 2)); @@ -2382,11 +2389,10 @@ mod tests { #[motsu::test] fn error_when_not_equal_arrays_safe_batch_transfer_from_with_data( contract: Contract, + alice: Address, + dave: Address, + charlie: Address, ) { - let alice = ALICE; - let dave = DAVE; - let charlie = CHARLIE; - let (token_ids, values) = contract.init(alice, |contract| init(contract, alice, 4)); From 9552a52ee11de7dab26196e7da25dcd7b5f965c2 Mon Sep 17 00:00:00 2001 From: Alisander Qoshqosh Date: Sat, 1 Feb 2025 00:54:09 +0400 Subject: [PATCH 081/109] migrate Erc1155Burnable --- .../src/token/erc1155/extensions/burnable.rs | 163 +++++++++++------- 1 file changed, 102 insertions(+), 61 deletions(-) diff --git a/contracts/src/token/erc1155/extensions/burnable.rs b/contracts/src/token/erc1155/extensions/burnable.rs index 111061dec..f142a93b0 100644 --- a/contracts/src/token/erc1155/extensions/burnable.rs +++ b/contracts/src/token/erc1155/extensions/burnable.rs @@ -110,9 +110,9 @@ impl Erc1155 { #[cfg(all(test, feature = "std"))] mod tests { - /* - use alloy_primitives::{address, Address, U256}; - use stylus_sdk::msg; + + use alloy_primitives::{Address, U256}; + use motsu::prelude::Contract; use super::IErc1155Burnable; use crate::token::erc1155::{ @@ -121,8 +121,6 @@ mod tests { ERC1155MissingApprovalForAll, Erc1155, Error, IErc1155, }; - const BOB: Address = address!("F4EaCDAbEf3c8f1EdE91b6f2A6840bc2E4DD3526"); - fn init( contract: &mut Erc1155, receiver: Address, @@ -143,46 +141,62 @@ mod tests { } #[motsu::test] - fn burns(contract: Erc1155) { - let alice = msg::sender(); - let (token_ids, values) = init(contract, alice, 1); + fn burns(contract: Contract, alice: Address) { + let (token_ids, values) = + contract.init(alice, |contract| init(contract, alice, 1)); - let initial_balance = contract.balance_of(alice, token_ids[0]); + let initial_balance = + contract.sender(alice).balance_of(alice, token_ids[0]); assert_eq!(values[0], initial_balance); contract + .sender(alice) .burn(alice, token_ids[0], values[0]) .expect("should burn own tokens"); - let balance = contract.balance_of(alice, token_ids[0]); + let balance = contract.sender(alice).balance_of(alice, token_ids[0]); assert_eq!(U256::ZERO, balance); } #[motsu::test] - fn burns_with_approval(contract: Erc1155) { - let alice = msg::sender(); - let (token_ids, values) = init(contract, BOB, 1); - - let initial_balance = contract.balance_of(BOB, token_ids[0]); + fn burns_with_approval( + contract: Contract, + alice: Address, + bob: Address, + ) { + let (token_ids, values) = + contract.init(alice, |contract| init(contract, bob, 1)); + + let initial_balance = + contract.sender(alice).balance_of(bob, token_ids[0]); assert_eq!(values[0], initial_balance); - contract._operator_approvals.setter(BOB).setter(alice).set(true); + contract + .sender(bob) + .set_approval_for_all(alice, true) + .expect("should approve Bob's tokens to Alice"); contract - .burn(BOB, token_ids[0], values[0]) + .sender(alice) + .burn(bob, token_ids[0], values[0]) .expect("should burn Bob's token"); - let balance = contract.balance_of(BOB, token_ids[0]); + let balance = contract.sender(alice).balance_of(bob, token_ids[0]); assert_eq!(U256::ZERO, balance); } #[motsu::test] - fn error_when_missing_approval_burns(contract: Erc1155) { - let alice = msg::sender(); - let (token_ids, values) = init(contract, BOB, 1); + fn error_when_missing_approval_burns( + contract: Contract, + alice: Address, + bob: Address, + ) { + let (token_ids, values) = + contract.init(alice, |contract| init(contract, bob, 1)); let err = contract - .burn(BOB, token_ids[0], values[0]) + .sender(alice) + .burn(bob, token_ids[0], values[0]) .expect_err("should not burn tokens without approval"); assert!(matches!( @@ -190,23 +204,26 @@ mod tests { Error::MissingApprovalForAll(ERC1155MissingApprovalForAll { owner, operator - }) if owner == BOB && operator == alice + }) if owner == bob && operator == alice )); } #[motsu::test] - fn error_when_invalid_sender_burns(contract: Erc1155) { - let alice = msg::sender(); - let (token_ids, values) = init(contract, alice, 1); + fn error_when_invalid_sender_burns( + contract: Contract, + alice: Address, + ) { + let (token_ids, values) = + contract.init(alice, |contract| init(contract, alice, 1)); let invalid_sender = Address::ZERO; contract - ._operator_approvals - .setter(invalid_sender) - .setter(alice) - .set(true); + .sender(invalid_sender) + .set_approval_for_all(alice, true) + .expect("should approve Bob's tokens to Alice"); let err = contract + .sender(alice) .burn(invalid_sender, token_ids[0], values[0]) .expect_err("should not burn tokens from the `Address::ZERO`"); @@ -219,15 +236,19 @@ mod tests { } #[motsu::test] - fn error_when_insufficient_balance_burn(contract: Erc1155) { - let alice = msg::sender(); - let (token_ids, values) = init(contract, alice, 1); + fn error_when_insufficient_balance_burn( + contract: Contract, + alice: Address, + ) { + let (token_ids, values) = + contract.init(alice, |contract| init(contract, alice, 1)); let token_id = token_ids[0]; let value = values[0]; let to_burn = value + U256::from(1); let err = contract + .sender(alice) .burn(alice, token_id, to_burn) .expect_err("should return `ERC1155InsufficientBalance`"); @@ -243,54 +264,68 @@ mod tests { } #[motsu::test] - fn burns_batch(contract: Erc1155) { - let alice = msg::sender(); - let (token_ids, values) = init(contract, alice, 4); + fn burns_batch(contract: Contract, alice: Address) { + let (token_ids, values) = + contract.init(alice, |contract| init(contract, alice, 4)); for (&token_id, &value) in token_ids.iter().zip(values.iter()) { - let balance = contract.balance_of(alice, token_id); + let balance = contract.sender(alice).balance_of(alice, token_id); assert_eq!(value, balance); } contract + .sender(alice) .burn_batch(alice, token_ids.clone(), values.clone()) .expect("should burn own tokens in batch"); for token_id in token_ids { - let balance = contract.balance_of(alice, token_id); + let balance = contract.sender(alice).balance_of(alice, token_id); assert_eq!(U256::ZERO, balance); } } #[motsu::test] - fn burns_batch_with_approval(contract: Erc1155) { - let alice = msg::sender(); - let (token_ids, values) = init(contract, BOB, 4); + fn burns_batch_with_approval( + contract: Contract, + alice: Address, + bob: Address, + ) { + let (token_ids, values) = + contract.init(alice, |contract| init(contract, bob, 4)); for (&token_id, &value) in token_ids.iter().zip(values.iter()) { - let balance = contract.balance_of(BOB, token_id); + let balance = contract.sender(alice).balance_of(bob, token_id); assert_eq!(value, balance); } - contract._operator_approvals.setter(BOB).setter(alice).set(true); + contract + .sender(bob) + .set_approval_for_all(alice, true) + .expect("should approve Bob's tokens to Alice"); contract - .burn_batch(BOB, token_ids.clone(), values.clone()) + .sender(alice) + .burn_batch(bob, token_ids.clone(), values.clone()) .expect("should burn Bob's tokens in batch"); for token_id in token_ids { - let balance = contract.balance_of(BOB, token_id); + let balance = contract.sender(alice).balance_of(bob, token_id); assert_eq!(U256::ZERO, balance); } } #[motsu::test] - fn error_when_missing_approval_burn_batch(contract: Erc1155) { - let alice = msg::sender(); - let (token_ids, values) = init(contract, BOB, 2); + fn error_when_missing_approval_burn_batch( + contract: Contract, + alice: Address, + bob: Address, + ) { + let (token_ids, values) = + contract.init(alice, |contract| init(contract, bob, 2)); let err = contract - .burn_batch(BOB, token_ids.clone(), values.clone()) + .sender(alice) + .burn_batch(bob, token_ids.clone(), values.clone()) .expect_err("should not burn tokens in batch without approval"); assert!(matches!( @@ -298,23 +333,26 @@ mod tests { Error::MissingApprovalForAll(ERC1155MissingApprovalForAll { owner, operator - }) if owner == BOB && operator == alice + }) if owner == bob && operator == alice )); } #[motsu::test] - fn error_when_invalid_sender_burn_batch(contract: Erc1155) { - let alice = msg::sender(); - let (token_ids, values) = init(contract, alice, 5); + fn error_when_invalid_sender_burn_batch( + contract: Contract, + alice: Address, + ) { + let (token_ids, values) = + contract.init(alice, |contract| init(contract, alice, 5)); let invalid_sender = Address::ZERO; contract - ._operator_approvals - .setter(invalid_sender) - .setter(alice) - .set(true); + .sender(invalid_sender) + .set_approval_for_all(alice, true) + .expect("should approve Bob's tokens to Alice"); let err = contract + .sender(alice) .burn_batch(invalid_sender, token_ids.clone(), values.clone()) .expect_err( "should not burn tokens in batch from the `Address::ZERO`", @@ -329,13 +367,17 @@ mod tests { } #[motsu::test] - fn error_when_insufficient_balance_burn_batch(contract: Erc1155) { - let alice = msg::sender(); - let (token_ids, values) = init(contract, alice, 5); + fn error_when_insufficient_balance_burn_batch( + contract: Contract, + alice: Address, + ) { + let (token_ids, values) = + contract.init(alice, |contract| init(contract, alice, 5)); let to_burn: Vec = values.iter().map(|v| v + U256::from(1)).collect(); let err = contract + .sender(alice) .burn_batch(alice, token_ids.clone(), to_burn.clone()) .expect_err("should return `ERC1155InsufficientBalance`"); @@ -349,5 +391,4 @@ mod tests { }) if sender == alice && balance == values[0] && needed == to_burn[0] && token_id == token_ids[0] )); } - */ } From c8b7aa9a3d3c734934c30c3ea79cd6aac93ec235 Mon Sep 17 00:00:00 2001 From: Alisander Qoshqosh Date: Sat, 1 Feb 2025 01:36:10 +0400 Subject: [PATCH 082/109] migrate Erc1155MetadataUri --- .../token/erc1155/extensions/metadata_uri.rs | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/contracts/src/token/erc1155/extensions/metadata_uri.rs b/contracts/src/token/erc1155/extensions/metadata_uri.rs index ba258f21a..dbc37119f 100644 --- a/contracts/src/token/erc1155/extensions/metadata_uri.rs +++ b/contracts/src/token/erc1155/extensions/metadata_uri.rs @@ -75,21 +75,29 @@ impl IErc165 for Erc1155MetadataUri { #[cfg(all(test, feature = "std"))] mod tests { - /* - use stylus_sdk::alloy_primitives::uint; + use alloy_primitives::Address; + use motsu::prelude::Contract; + use stylus_sdk::{alloy_primitives::uint, prelude::TopLevelStorage}; use super::{Erc1155MetadataUri, IErc1155MetadataUri, IErc165}; + unsafe impl TopLevelStorage for Erc1155MetadataUri {} + #[motsu::test] - fn uri_ignores_token_id(contract: Erc1155MetadataUri) { + fn uri_ignores_token_id( + contract: Contract, + alice: Address, + ) { let uri = String::from("https://token-cdn-domain/\\{id\\}.json"); - contract._uri.set_str(uri.clone()); + contract.init(alice, |contract| { + contract._uri.set_str(uri.clone()); + }); let token_id = uint!(1_U256); - assert_eq!(uri, contract.uri(token_id)); + assert_eq!(uri, contract.sender(alice).uri(token_id)); let token_id = uint!(2_U256); - assert_eq!(uri, contract.uri(token_id)); + assert_eq!(uri, contract.sender(alice).uri(token_id)); } #[motsu::test] @@ -101,5 +109,5 @@ mod tests { let actual = ::INTERFACE_ID; let expected = 0x01ffc9a7; assert_eq!(actual, expected); - }*/ + } } From 37d874efab2e4650d9047e27151188a38e1effbd Mon Sep 17 00:00:00 2001 From: Alisander Qoshqosh Date: Sat, 1 Feb 2025 01:53:52 +0400 Subject: [PATCH 083/109] migrate Erc1155Supply --- .../src/token/erc1155/extensions/supply.rs | 173 ++++++++++++------ 1 file changed, 122 insertions(+), 51 deletions(-) diff --git a/contracts/src/token/erc1155/extensions/supply.rs b/contracts/src/token/erc1155/extensions/supply.rs index 1b391da44..47f556271 100644 --- a/contracts/src/token/erc1155/extensions/supply.rs +++ b/contracts/src/token/erc1155/extensions/supply.rs @@ -358,7 +358,9 @@ impl Erc1155Supply { #[cfg(all(test, feature = "std"))] mod tests { - /*use alloy_primitives::{address, Address, U256}; + use alloy_primitives::{Address, U256}; + use motsu::prelude::Contract; + use stylus_sdk::prelude::TopLevelStorage; use super::{Erc1155Supply, IErc1155Supply}; use crate::token::erc1155::{ @@ -366,8 +368,7 @@ mod tests { ERC1155InvalidReceiver, ERC1155InvalidSender, Error, IErc1155, }; - const ALICE: Address = address!("A11CEacF9aa32246d767FCCD72e02d6bCbcC375d"); - const BOB: Address = address!("B0B0cB49ec2e96DF5F5fFB081acaE66A2cBBc2e2"); + unsafe impl TopLevelStorage for Erc1155Supply {} fn init( contract: &mut Erc1155Supply, @@ -389,41 +390,61 @@ mod tests { } #[motsu::test] - fn before_mint(contract: Erc1155Supply) { + fn before_mint(contract: Contract, alice: Address) { let token_id = random_token_ids(1)[0]; - assert_eq!(U256::ZERO, contract.total_supply(token_id)); - assert_eq!(U256::ZERO, contract.total_supply_all()); - assert!(!contract.exists(token_id)); + assert_eq!(U256::ZERO, contract.sender(alice).total_supply(token_id)); + assert_eq!(U256::ZERO, contract.sender(alice).total_supply_all()); + assert!(!contract.sender(alice).exists(token_id)); } #[motsu::test] - fn after_mint_single(contract: Erc1155Supply) { - let (token_ids, values) = init(contract, ALICE, 1); - assert_eq!(values[0], contract.balance_of(ALICE, token_ids[0])); - assert_eq!(values[0], contract.total_supply(token_ids[0])); - assert_eq!(values[0], contract.total_supply_all()); - assert!(contract.exists(token_ids[0])); + fn after_mint_single( + contract: Contract, + alice: Address, + bob: Address, + ) { + let (token_ids, values) = + contract.init(alice, |contract| init(contract, bob, 1)); + assert_eq!( + values[0], + contract.sender(alice).balance_of(bob, token_ids[0]) + ); + assert_eq!( + values[0], + contract.sender(alice).total_supply(token_ids[0]) + ); + assert_eq!(values[0], contract.sender(alice).total_supply_all()); + assert!(contract.sender(alice).exists(token_ids[0])); } #[motsu::test] - fn after_mint_batch(contract: Erc1155Supply) { - let (token_ids, values) = init(contract, ALICE, 4); + fn after_mint_batch( + contract: Contract, + alice: Address, + bob: Address, + ) { + let (token_ids, values) = + contract.init(alice, |contract| init(contract, bob, 4)); for (&token_id, &value) in token_ids.iter().zip(values.iter()) { - assert_eq!(value, contract.balance_of(ALICE, token_id)); - assert_eq!(value, contract.total_supply(token_id)); - assert!(contract.exists(token_id)); + assert_eq!(value, contract.sender(alice).balance_of(bob, token_id)); + assert_eq!(value, contract.sender(alice).total_supply(token_id)); + assert!(contract.sender(alice).exists(token_id)); } let total_supply_all: U256 = values.iter().sum(); - assert_eq!(total_supply_all, contract.total_supply_all()); + assert_eq!(total_supply_all, contract.sender(alice).total_supply_all()); } #[motsu::test] - fn mint_reverts_on_invalid_receiver(contract: Erc1155Supply) { + fn mint_reverts_on_invalid_receiver( + contract: Contract, + alice: Address, + ) { let token_id = random_token_ids(1)[0]; let two = U256::from(2); let invalid_receiver = Address::ZERO; let err = contract + .sender(alice) ._mint(invalid_receiver, token_id, two, &vec![].into()) .expect_err("should revert with `InvalidReceiver`"); @@ -437,64 +458,107 @@ mod tests { #[motsu::test] #[should_panic = "should not exceed `U256::MAX` for `_total_supply`"] - fn mint_panics_on_total_supply_overflow(contract: Erc1155Supply) { + fn mint_panics_on_total_supply_overflow( + contract: Contract, + alice: Address, + bob: Address, + dave: Address, + ) { let token_id = random_token_ids(1)[0]; let two = U256::from(2); let three = U256::from(3); contract - ._mint(ALICE, token_id, U256::MAX / two, &vec![].into()) - .expect("should mint to ALICE"); + .sender(alice) + ._mint(bob, token_id, U256::MAX / two, &vec![].into()) + .expect("should mint to bob"); contract - ._mint(BOB, token_id, U256::MAX / two, &vec![].into()) - .expect("should mint to BOB"); - let _ = contract._mint(ALICE, token_id, three, &vec![].into()); + .sender(alice) + ._mint(dave, token_id, U256::MAX / two, &vec![].into()) + .expect("should mint to dave"); + let _ = + contract.sender(alice)._mint(bob, token_id, three, &vec![].into()); } #[motsu::test] #[should_panic = "should not exceed `U256::MAX` for `_total_supply_all`"] - fn mint_panics_on_total_supply_all_overflow(contract: Erc1155Supply) { + fn mint_panics_on_total_supply_all_overflow( + contract: Contract, + alice: Address, + bob: Address, + ) { let token_ids = random_token_ids(2); contract - ._mint(ALICE, token_ids[0], U256::MAX, &vec![].into()) + .sender(alice) + ._mint(bob, token_ids[0], U256::MAX, &vec![].into()) .expect("should mint"); - let _ = - contract._mint(ALICE, token_ids[1], U256::from(1), &vec![].into()); + let _ = contract.sender(alice)._mint( + bob, + token_ids[1], + U256::from(1), + &vec![].into(), + ); } #[motsu::test] - fn after_burn_single(contract: Erc1155Supply) { - let (token_ids, values) = init(contract, ALICE, 1); - contract._burn(ALICE, token_ids[0], values[0]).expect("should burn"); - - assert_eq!(U256::ZERO, contract.total_supply(token_ids[0])); - assert_eq!(U256::ZERO, contract.total_supply_all()); - assert!(!contract.exists(token_ids[0])); + fn after_burn_single( + contract: Contract, + alice: Address, + bob: Address, + ) { + let (token_ids, values) = + contract.init(alice, |contract| init(contract, bob, 1)); + contract + .sender(alice) + ._burn(bob, token_ids[0], values[0]) + .expect("should burn"); + + assert_eq!( + U256::ZERO, + contract.sender(alice).total_supply(token_ids[0]) + ); + assert_eq!(U256::ZERO, contract.sender(alice).total_supply_all()); + assert!(!contract.sender(alice).exists(token_ids[0])); } #[motsu::test] - fn after_burn_batch(contract: Erc1155Supply) { - let (token_ids, values) = init(contract, ALICE, 4); + fn after_burn_batch( + contract: Contract, + alice: Address, + bob: Address, + ) { + let (token_ids, values) = + contract.init(alice, |contract| init(contract, bob, 4)); contract - ._burn_batch(ALICE, token_ids.clone(), values.clone()) + .sender(alice) + ._burn_batch(bob, token_ids.clone(), values.clone()) .expect("should burn batch"); for &token_id in &token_ids { assert_eq!( U256::ZERO, - contract.erc1155.balance_of(ALICE, token_id) + contract.sender(alice).erc1155.balance_of(bob, token_id) + ); + assert!(!contract.sender(alice).exists(token_id)); + assert_eq!( + U256::ZERO, + contract.sender(alice).total_supply(token_id) ); - assert!(!contract.exists(token_id)); - assert_eq!(U256::ZERO, contract.total_supply(token_id)); } - assert_eq!(U256::ZERO, contract.total_supply_all()); + assert_eq!(U256::ZERO, contract.sender(alice).total_supply_all()); } #[motsu::test] - fn burn_reverts_when_invalid_sender(contract: Erc1155Supply) { - let (token_ids, values) = init(contract, ALICE, 1); + fn burn_reverts_when_invalid_sender( + contract: Contract, + alice: Address, + bob: Address, + ) { + let (token_ids, values) = + contract.init(alice, |contract| init(contract, bob, 1)); let invalid_sender = Address::ZERO; let err = contract + .sender(alice) ._burn(invalid_sender, token_ids[0], values[0]) .expect_err("should not burn token for invalid sender"); @@ -507,15 +571,22 @@ mod tests { } #[motsu::test] - fn supply_unaffected_by_no_op(contract: Erc1155Supply) { + fn supply_unaffected_by_no_op( + contract: Contract, + alice: Address, + ) { let token_ids = random_token_ids(1); let values = random_values(1); contract + .sender(alice) ._update(Address::ZERO, Address::ZERO, token_ids.clone(), values) .expect("should supply"); - assert_eq!(U256::ZERO, contract.total_supply(token_ids[0])); - assert_eq!(U256::ZERO, contract.total_supply_all()); - assert!(!contract.exists(token_ids[0])); - }*/ + assert_eq!( + U256::ZERO, + contract.sender(alice).total_supply(token_ids[0]) + ); + assert_eq!(U256::ZERO, contract.sender(alice).total_supply_all()); + assert!(!contract.sender(alice).exists(token_ids[0])); + } } From f3e8990a0e64b52f52472460afee21a6108ce052 Mon Sep 17 00:00:00 2001 From: Alisander Qoshqosh Date: Sat, 1 Feb 2025 02:28:19 +0400 Subject: [PATCH 084/109] ++ --- .../token/erc1155/extensions/uri_storage.rs | 31 ++++++++++++------- contracts/src/token/erc1155/mod.rs | 9 +++--- .../src/token/erc20/extensions/erc4626.rs | 2 +- .../src/token/erc721/extensions/enumerable.rs | 2 +- 4 files changed, 27 insertions(+), 17 deletions(-) diff --git a/contracts/src/token/erc1155/extensions/uri_storage.rs b/contracts/src/token/erc1155/extensions/uri_storage.rs index 49a5fc523..fae3e1212 100644 --- a/contracts/src/token/erc1155/extensions/uri_storage.rs +++ b/contracts/src/token/erc1155/extensions/uri_storage.rs @@ -92,10 +92,11 @@ impl Erc1155UriStorage { #[cfg(all(test, feature = "std"))] mod tests { - /* + // TODO#q: rewrite Erc1155UriStorage tests + /*use motsu::prelude::Contract; use stylus_sdk::{ alloy_primitives::{uint, U256}, - prelude::storage, + prelude::{public, storage, TopLevelStorage}, }; use super::Erc1155UriStorage; @@ -103,15 +104,22 @@ mod tests { #[storage] struct Erc1155MetadataExample { + #[borrow] pub metadata_uri: Erc1155MetadataUri, pub uri_storage: Erc1155UriStorage, } + #[public] + #[inherit(Erc1155MetadataUri)] + impl Erc1155MetadataExample {} + + unsafe impl TopLevelStorage for Erc1155MetadataExample {} + const TOKEN_ID: U256 = uint!(1_U256); #[motsu::test] fn uri_returns_metadata_uri_when_token_uri_is_not_set( - contract: Erc1155MetadataExample, + contract: Contract, ) { let uri = "https://some.metadata/token/uri"; @@ -125,7 +133,7 @@ mod tests { #[motsu::test] fn uri_returns_empty_string_when_no_uri_is_set( - contract: Erc1155MetadataExample, + contract: Contract, ) { assert!(contract .uri_storage @@ -135,7 +143,7 @@ mod tests { #[motsu::test] fn uri_returns_token_uri_when_base_uri_is_empty( - contract: Erc1155MetadataExample, + contract: Contract, ) { let token_uri = "https://some.short/token/uri"; @@ -153,7 +161,7 @@ mod tests { #[motsu::test] fn uri_returns_concatenated_base_uri_and_token_uri( - contract: Erc1155MetadataExample, + contract: Contract, ) { let base_uri = "https://some.base.uri"; let token_uri = "/some/token/uri"; @@ -173,7 +181,7 @@ mod tests { #[motsu::test] fn uri_ignores_metadata_uri_when_token_uri_is_set( - contract: Erc1155MetadataExample, + contract: Contract, ) { let uri = "https://some.metadata/token/uri"; let token_uri = "https://some.short/token/uri"; @@ -192,7 +200,7 @@ mod tests { } #[motsu::test] - fn test_set_uri(contract: Erc1155MetadataExample) { + fn test_set_uri(contract: Contract) { let uri = "https://some.metadata/token/uri"; let token_uri = "https://some.short/token/uri".to_string(); @@ -210,12 +218,13 @@ mod tests { ); } + unsafe impl TopLevelStorage for Erc1155UriStorage {} + #[motsu::test] - fn test_set_base_uri(contract: Erc1155UriStorage) { + fn test_set_base_uri(contract: Contract) { let base_uri = "https://docs.openzeppelin.com/".to_string(); contract.set_base_uri(base_uri.clone()); assert_eq!(base_uri, contract._base_uri.get_string()); - } - */ + }*/ } diff --git a/contracts/src/token/erc1155/mod.rs b/contracts/src/token/erc1155/mod.rs index 114743f3e..4406bfe1f 100644 --- a/contracts/src/token/erc1155/mod.rs +++ b/contracts/src/token/erc1155/mod.rs @@ -1760,7 +1760,7 @@ mod tests { )); } - // TODO#q: fix test error_when_invalid_sender_safe_transfer_from + // TODO#q: rewrite test error_when_invalid_sender_safe_transfer_from /*#[motsu::test] fn error_when_invalid_sender_safe_transfer_from( contract: Contract, @@ -1919,7 +1919,8 @@ mod tests { )); } - // TODO#q: fix test error_when_invalid_sender_safe_transfer_from_with_data + // TODO#q: rewrite test + // error_when_invalid_sender_safe_transfer_from_with_data /*#[motsu::test] fn error_when_invalid_sender_safe_transfer_from_with_data( contract: Contract, @@ -2084,7 +2085,7 @@ mod tests { )); } - // TODO#q: fix test error_when_invalid_sender_safe_batch_transfer_from + // TODO#q: rewrite test error_when_invalid_sender_safe_batch_transfer_from /*#[motsu::test] fn error_when_invalid_sender_safe_batch_transfer_from( contract: Contract, @@ -2283,7 +2284,7 @@ mod tests { )); } - // TODO#q: fix test + // TODO#q: rewrite test // error_when_invalid_sender_safe_batch_transfer_from_with_data /*#[motsu::test] fn error_when_invalid_sender_safe_batch_transfer_from_with_data( diff --git a/contracts/src/token/erc20/extensions/erc4626.rs b/contracts/src/token/erc20/extensions/erc4626.rs index cb32a83b4..c557e6d2f 100644 --- a/contracts/src/token/erc20/extensions/erc4626.rs +++ b/contracts/src/token/erc20/extensions/erc4626.rs @@ -1146,7 +1146,7 @@ impl Erc4626 { // TODO#q: Add missing tests once `motsu` supports calling external contracts. #[cfg(all(test, feature = "std"))] mod tests { - // TODO#q: fix erc4626 tests + // TODO#q: rewrite erc4626 tests /* use alloy_primitives::{address, U256, U8}; use stylus_sdk::{msg, prelude::storage}; diff --git a/contracts/src/token/erc721/extensions/enumerable.rs b/contracts/src/token/erc721/extensions/enumerable.rs index 2abf40ca8..ea6092ab0 100644 --- a/contracts/src/token/erc721/extensions/enumerable.rs +++ b/contracts/src/token/erc721/extensions/enumerable.rs @@ -486,7 +486,7 @@ mod tests { assert!(matches!(err, Error::EnumerableForbiddenBatchMint(_))); } - // TODO#q: fix Erc721Enumerable and Erc721 integration tests + // TODO#q: rewrite Erc721Enumerable and Erc721 integration tests /*#[motsu::test] fn token_of_owner_by_index_works(contract: Erc721Enumerable) { let alice = msg::sender(); From 954efdbaedcd7578919a289a4b008dcf984b0ab6 Mon Sep 17 00:00:00 2001 From: Alisander Qoshqosh Date: Sat, 1 Feb 2025 02:33:53 +0400 Subject: [PATCH 085/109] ++ --- contracts/src/access/control.rs | 2 ++ contracts/src/access/ownable.rs | 2 ++ contracts/src/access/ownable_two_step.rs | 2 ++ contracts/src/finance/vesting_wallet.rs | 1 + contracts/src/utils/nonces.rs | 2 ++ contracts/src/utils/pausable.rs | 2 ++ 6 files changed, 11 insertions(+) diff --git a/contracts/src/access/control.rs b/contracts/src/access/control.rs index 5e3b5d0d8..3095a3921 100644 --- a/contracts/src/access/control.rs +++ b/contracts/src/access/control.rs @@ -373,6 +373,8 @@ impl AccessControl { } } } + +// TODO#q: migrate control tests /* #[cfg(all(test, feature = "std"))] mod tests { diff --git a/contracts/src/access/ownable.rs b/contracts/src/access/ownable.rs index ccfb0fe82..11704faa7 100644 --- a/contracts/src/access/ownable.rs +++ b/contracts/src/access/ownable.rs @@ -200,6 +200,8 @@ impl Ownable { evm::log(OwnershipTransferred { previous_owner, new_owner }); } } + +// TODO#q: migrate Ownable tests /* #[cfg(all(test, feature = "std"))] mod tests { diff --git a/contracts/src/access/ownable_two_step.rs b/contracts/src/access/ownable_two_step.rs index 55d38b1f8..c098a9074 100644 --- a/contracts/src/access/ownable_two_step.rs +++ b/contracts/src/access/ownable_two_step.rs @@ -218,6 +218,8 @@ impl Ownable2Step { self._ownable._transfer_ownership(new_owner); } } + +// TODO#q: migrate Ownable2Step tests /* #[cfg(all(test, feature = "std"))] mod tests { diff --git a/contracts/src/finance/vesting_wallet.rs b/contracts/src/finance/vesting_wallet.rs index 807b32d41..8bb6cf2d2 100644 --- a/contracts/src/finance/vesting_wallet.rs +++ b/contracts/src/finance/vesting_wallet.rs @@ -518,6 +518,7 @@ impl VestingWallet { #[cfg(all(test, feature = "std"))] mod tests { + // TODO#q: migrate vesting wallet /* use alloy_primitives::{address, uint, Address, U256, U64}; use stylus_sdk::block; diff --git a/contracts/src/utils/nonces.rs b/contracts/src/utils/nonces.rs index ddd548278..4362242fd 100644 --- a/contracts/src/utils/nonces.rs +++ b/contracts/src/utils/nonces.rs @@ -112,6 +112,8 @@ impl Nonces { Ok(()) } } + +// TODO#q: migrate Nonces /* #[cfg(all(test, feature = "std"))] mod tests { diff --git a/contracts/src/utils/pausable.rs b/contracts/src/utils/pausable.rs index 4d98ba60c..bb4c32df0 100644 --- a/contracts/src/utils/pausable.rs +++ b/contracts/src/utils/pausable.rs @@ -155,6 +155,8 @@ impl Pausable { Ok(()) } } + +// TODO#q: migrate Pausable /* #[cfg(all(test, feature = "std"))] mod tests { From e900b98f9956d9683f4b0b4a6cc7795540f20361 Mon Sep 17 00:00:00 2001 From: Alisander Qoshqosh Date: Sat, 1 Feb 2025 17:05:17 +0400 Subject: [PATCH 086/109] migrate access control tests --- contracts/src/access/control.rs | 309 ++++++++++++++++++++------------ 1 file changed, 195 insertions(+), 114 deletions(-) diff --git a/contracts/src/access/control.rs b/contracts/src/access/control.rs index 3095a3921..b7d531f43 100644 --- a/contracts/src/access/control.rs +++ b/contracts/src/access/control.rs @@ -374,12 +374,11 @@ impl AccessControl { } } -// TODO#q: migrate control tests -/* #[cfg(all(test, feature = "std"))] mod tests { - use alloy_primitives::{address, Address}; - use stylus_sdk::msg; + use alloy_primitives::Address; + use motsu::prelude::Contract; + use stylus_sdk::{msg, prelude::TopLevelStorage}; use super::{AccessControl, Error}; @@ -398,209 +397,291 @@ mod tests { OTHER_ROLE = "879ce0d4bfd332649ca3552efe772a38d64a315eb70ab69689fd309c735946b5"; } - const ALICE: Address = address!("A11CEacF9aa32246d767FCCD72e02d6bCbcC375d"); + const DEFAULT_ADMIN_ROLE: [u8; 32] = AccessControl::DEFAULT_ADMIN_ROLE; - // Since we don't have constructors, we need to call this to setup - // `msg::sender` as a member of `ROLE`. - // - // NOTE: Once we have support for setting `msg::sender` and constructor, - // this function shouldn't be needed. - fn _grant_role_to_msg_sender(contract: &mut AccessControl, role: [u8; 32]) { - contract - ._roles - .setter(role.into()) - .has_role - .insert(msg::sender(), true); - } + unsafe impl TopLevelStorage for AccessControl {} #[motsu::test] - fn default_role_is_default_admin(contract: AccessControl) { - let role_admin = contract.get_role_admin(ROLE.into()); - assert_eq!(role_admin, AccessControl::DEFAULT_ADMIN_ROLE); + fn default_role_is_default_admin( + contract: Contract, + alice: Address, + ) { + let role_admin = contract.sender(alice).get_role_admin(ROLE.into()); + assert_eq!(role_admin, DEFAULT_ADMIN_ROLE); } #[motsu::test] - fn default_admin_roles_admin_is_itself(contract: AccessControl) { - const DEFAULT_ADMIN_ROLE: [u8; 32] = AccessControl::DEFAULT_ADMIN_ROLE; - let role_admin = contract.get_role_admin(DEFAULT_ADMIN_ROLE.into()); + fn default_admin_roles_admin_is_itself( + contract: Contract, + alice: Address, + ) { + let role_admin = + contract.sender(alice).get_role_admin(DEFAULT_ADMIN_ROLE.into()); assert_eq!(role_admin, DEFAULT_ADMIN_ROLE); } #[motsu::test] - fn non_admin_cannot_grant_role_to_others(contract: AccessControl) { - let err = contract.grant_role(ROLE.into(), ALICE).unwrap_err(); + fn non_admin_cannot_grant_role_to_others( + contract: Contract, + alice: Address, + bob: Address, + ) { + let err = + contract.sender(alice).grant_role(ROLE.into(), bob).unwrap_err(); assert!(matches!(err, Error::UnauthorizedAccount(_))); } #[motsu::test] - fn accounts_can_be_granted_roles_multiple_times(contract: AccessControl) { - _grant_role_to_msg_sender(contract, AccessControl::DEFAULT_ADMIN_ROLE); - - contract.grant_role(ROLE.into(), ALICE).unwrap(); - contract.grant_role(ROLE.into(), ALICE).unwrap(); - let has_role = contract.has_role(ROLE.into(), ALICE); + fn accounts_can_be_granted_roles_multiple_times( + contract: Contract, + alice: Address, + bob: Address, + ) { + contract.sender(alice)._grant_role(DEFAULT_ADMIN_ROLE.into(), alice); + + contract.sender(alice).grant_role(ROLE.into(), bob).unwrap(); + contract.sender(alice).grant_role(ROLE.into(), bob).unwrap(); + let has_role = contract.sender(alice).has_role(ROLE.into(), bob); assert!(has_role); } #[motsu::test] - fn not_granted_roles_can_be_revoked(contract: AccessControl) { - _grant_role_to_msg_sender(contract, AccessControl::DEFAULT_ADMIN_ROLE); - - let has_role = contract.has_role(ROLE.into(), ALICE); + fn not_granted_roles_can_be_revoked( + contract: Contract, + alice: Address, + bob: Address, + ) { + contract.sender(alice)._grant_role(DEFAULT_ADMIN_ROLE.into(), alice); + + let has_role = contract.sender(alice).has_role(ROLE.into(), bob); assert!(!has_role); - contract.revoke_role(ROLE.into(), ALICE).unwrap(); - let has_role = contract.has_role(ROLE.into(), ALICE); + contract.sender(alice).revoke_role(ROLE.into(), bob).unwrap(); + let has_role = contract.sender(alice).has_role(ROLE.into(), bob); assert!(!has_role); } #[motsu::test] - fn admin_can_revoke_role(contract: AccessControl) { - _grant_role_to_msg_sender(contract, AccessControl::DEFAULT_ADMIN_ROLE); - contract._roles.setter(ROLE.into()).has_role.insert(ALICE, true); - - let has_role = contract.has_role(ROLE.into(), ALICE); + fn admin_can_revoke_role( + contract: Contract, + alice: Address, + bob: Address, + ) { + contract.sender(alice)._grant_role(DEFAULT_ADMIN_ROLE.into(), alice); + contract.sender(alice).grant_role(ROLE.into(), bob).unwrap(); + + let has_role = contract.sender(alice).has_role(ROLE.into(), bob); assert!(has_role); - contract.revoke_role(ROLE.into(), ALICE).unwrap(); - let has_role = contract.has_role(ROLE.into(), ALICE); + contract.sender(alice).revoke_role(ROLE.into(), bob).unwrap(); + let has_role = contract.sender(alice).has_role(ROLE.into(), bob); assert!(!has_role); } #[motsu::test] - fn non_admin_cannot_revoke_role(contract: AccessControl) { - contract._roles.setter(ROLE.into()).has_role.insert(ALICE, true); - - let has_role = contract.has_role(ROLE.into(), ALICE); + fn non_admin_cannot_revoke_role( + contract: Contract, + alice: Address, + bob: Address, + ) { + contract.sender(bob)._grant_role(ROLE.into(), bob); + + let has_role = contract.sender(alice).has_role(ROLE.into(), bob); assert!(has_role); - let err = contract.revoke_role(ROLE.into(), ALICE).unwrap_err(); + let err = + contract.sender(alice).revoke_role(ROLE.into(), bob).unwrap_err(); assert!(matches!(err, Error::UnauthorizedAccount(_))); } #[motsu::test] - fn roles_can_be_revoked_multiple_times(contract: AccessControl) { - _grant_role_to_msg_sender(contract, AccessControl::DEFAULT_ADMIN_ROLE); - - contract.revoke_role(ROLE.into(), ALICE).unwrap(); - contract.revoke_role(ROLE.into(), ALICE).unwrap(); - let has_role = contract.has_role(ROLE.into(), ALICE); + fn roles_can_be_revoked_multiple_times( + contract: Contract, + alice: Address, + bob: Address, + ) { + contract.sender(alice)._grant_role(DEFAULT_ADMIN_ROLE.into(), alice); + + contract.sender(alice).revoke_role(ROLE.into(), bob).unwrap(); + contract.sender(alice).revoke_role(ROLE.into(), bob).unwrap(); + let has_role = contract.sender(alice).has_role(ROLE.into(), bob); assert!(!has_role); } #[motsu::test] - fn bearer_can_renounce_role(contract: AccessControl) { - _grant_role_to_msg_sender(contract, ROLE); + fn bearer_can_renounce_role( + contract: Contract, + alice: Address, + ) { + contract.sender(alice)._grant_role(ROLE.into(), alice); - let has_role = contract.has_role(ROLE.into(), msg::sender()); + let has_role = contract.sender(alice).has_role(ROLE.into(), alice); assert!(has_role); - contract.renounce_role(ROLE.into(), msg::sender()).unwrap(); - let has_role = contract.has_role(ROLE.into(), msg::sender()); + contract.sender(alice).renounce_role(ROLE.into(), alice).unwrap(); + let has_role = contract.sender(alice).has_role(ROLE.into(), alice); assert!(!has_role); } #[motsu::test] - fn only_sender_can_renounce(contract: AccessControl) { - _grant_role_to_msg_sender(contract, ROLE); - let err = contract.renounce_role(ROLE.into(), ALICE).unwrap_err(); + fn only_sender_can_renounce( + contract: Contract, + alice: Address, + bob: Address, + ) { + contract.sender(alice)._grant_role(ROLE.into(), alice); + let err = + contract.sender(alice).renounce_role(ROLE.into(), bob).unwrap_err(); assert!(matches!(err, Error::BadConfirmation(_))); } #[motsu::test] - fn roles_can_be_renounced_multiple_times(contract: AccessControl) { - _grant_role_to_msg_sender(contract, ROLE); - - let sender = msg::sender(); - contract.renounce_role(ROLE.into(), sender).unwrap(); - contract.renounce_role(ROLE.into(), sender).unwrap(); - let has_role = contract.has_role(ROLE.into(), ALICE); + fn roles_can_be_renounced_multiple_times( + contract: Contract, + alice: Address, + bob: Address, + ) { + contract.sender(alice)._grant_role(ROLE.into(), alice); + + contract.sender(alice).renounce_role(ROLE.into(), alice).unwrap(); + contract.sender(alice).renounce_role(ROLE.into(), alice).unwrap(); + let has_role = contract.sender(alice).has_role(ROLE.into(), bob); assert!(!has_role); } #[motsu::test] - fn a_roles_admin_role_can_change(contract: AccessControl) { - contract._set_role_admin(ROLE.into(), OTHER_ROLE.into()); - _grant_role_to_msg_sender(contract, OTHER_ROLE); - - let admin_role = contract.get_role_admin(ROLE.into()); + fn a_roles_admin_role_can_change( + contract: Contract, + alice: Address, + ) { + contract.sender(alice)._set_role_admin(ROLE.into(), OTHER_ROLE.into()); + contract.sender(alice)._grant_role(OTHER_ROLE.into(), alice); + + let admin_role = contract.sender(alice).get_role_admin(ROLE.into()); assert_eq!(admin_role, OTHER_ROLE); } #[motsu::test] - fn the_new_admin_can_grant_roles(contract: AccessControl) { - contract._set_role_admin(ROLE.into(), OTHER_ROLE.into()); - _grant_role_to_msg_sender(contract, OTHER_ROLE); - - contract.grant_role(ROLE.into(), ALICE).unwrap(); - let has_role = contract.has_role(ROLE.into(), ALICE); + fn the_new_admin_can_grant_roles( + contract: Contract, + alice: Address, + bob: Address, + ) { + contract.sender(alice)._set_role_admin(ROLE.into(), OTHER_ROLE.into()); + contract.sender(alice)._grant_role(OTHER_ROLE.into(), alice); + + contract.sender(alice).grant_role(ROLE.into(), bob).unwrap(); + let has_role = contract.sender(alice).has_role(ROLE.into(), bob); assert!(has_role); } #[motsu::test] - fn the_new_admin_can_revoke_roles(contract: AccessControl) { - contract._set_role_admin(ROLE.into(), OTHER_ROLE.into()); - _grant_role_to_msg_sender(contract, OTHER_ROLE); - - contract._roles.setter(ROLE.into()).has_role.insert(ALICE, true); - contract.revoke_role(ROLE.into(), ALICE).unwrap(); - let has_role = contract.has_role(ROLE.into(), ALICE); + fn the_new_admin_can_revoke_roles( + contract: Contract, + alice: Address, + bob: Address, + ) { + contract.sender(alice)._set_role_admin(ROLE.into(), OTHER_ROLE.into()); + contract.sender(alice)._grant_role(OTHER_ROLE.into(), alice); + contract.sender(alice)._grant_role(OTHER_ROLE.into(), bob); + + contract.sender(alice).revoke_role(ROLE.into(), bob).unwrap(); + let has_role = contract.sender(alice).has_role(ROLE.into(), bob); assert!(!has_role); } #[motsu::test] - fn previous_admins_no_longer_grant_roles(contract: AccessControl) { - _grant_role_to_msg_sender(contract, ROLE); - contract._set_role_admin(ROLE.into(), OTHER_ROLE.into()); + fn previous_admins_no_longer_grant_roles( + contract: Contract, + alice: Address, + bob: Address, + ) { + contract.sender(alice)._grant_role(ROLE.into(), alice); + contract.sender(alice)._set_role_admin(ROLE.into(), OTHER_ROLE.into()); - let err = contract.grant_role(ROLE.into(), ALICE).unwrap_err(); + let err = + contract.sender(alice).grant_role(ROLE.into(), bob).unwrap_err(); assert!(matches!(err, Error::UnauthorizedAccount(_))); } #[motsu::test] - fn previous_admins_no_longer_revoke_roles(contract: AccessControl) { - _grant_role_to_msg_sender(contract, ROLE); - contract._set_role_admin(ROLE.into(), OTHER_ROLE.into()); + fn previous_admins_no_longer_revoke_roles( + contract: Contract, + alice: Address, + bob: Address, + ) { + contract.sender(alice)._grant_role(ROLE.into(), alice); + contract.sender(alice)._set_role_admin(ROLE.into(), OTHER_ROLE.into()); - let err = contract.revoke_role(ROLE.into(), ALICE).unwrap_err(); + let err = + contract.sender(alice).revoke_role(ROLE.into(), bob).unwrap_err(); assert!(matches!(err, Error::UnauthorizedAccount(_))); } #[motsu::test] - fn does_not_revert_if_sender_has_role(contract: AccessControl) { - _grant_role_to_msg_sender(contract, ROLE); - contract._check_role(ROLE.into(), msg::sender()).unwrap(); + fn does_not_revert_if_sender_has_role( + contract: Contract, + alice: Address, + ) { + contract.sender(alice)._grant_role(ROLE.into(), alice); + + contract.sender(alice)._check_role(ROLE.into(), alice).unwrap(); } #[motsu::test] - fn reverts_if_sender_doesnt_have_role(contract: AccessControl) { - let err = contract._check_role(ROLE.into(), msg::sender()).unwrap_err(); - assert!(matches!(err, Error::UnauthorizedAccount(_))); + fn reverts_if_sender_doesnt_have_role( + contract: Contract, + alice: Address, + ) { let err = - contract._check_role(OTHER_ROLE.into(), msg::sender()).unwrap_err(); + contract.sender(alice)._check_role(ROLE.into(), alice).unwrap_err(); + assert!(matches!(err, Error::UnauthorizedAccount(_))); + let err = contract + .sender(alice) + ._check_role(OTHER_ROLE.into(), alice) + .unwrap_err(); assert!(matches!(err, Error::UnauthorizedAccount(_))); } #[motsu::test] - fn internal_grant_role_true_if_no_role(contract: AccessControl) { - let role_granted = contract._grant_role(ROLE.into(), ALICE); + fn internal_grant_role_true_if_no_role( + contract: Contract, + alice: Address, + bob: Address, + ) { + let role_granted = contract.sender(alice)._grant_role(ROLE.into(), bob); assert!(role_granted); } #[motsu::test] - fn internal_grant_role_false_if_role(contract: AccessControl) { - contract._roles.setter(ROLE.into()).has_role.insert(ALICE, true); - let role_granted = contract._grant_role(ROLE.into(), ALICE); + fn internal_grant_role_false_if_role( + contract: Contract, + alice: Address, + bob: Address, + ) { + contract.sender(alice)._grant_role(ROLE.into(), bob); + + let role_granted = contract.sender(alice)._grant_role(ROLE.into(), bob); assert!(!role_granted); } #[motsu::test] - fn internal_revoke_role_true_if_role(contract: AccessControl) { - contract._roles.setter(ROLE.into()).has_role.insert(ALICE, true); - let role_revoked = contract._revoke_role(ROLE.into(), ALICE); + fn internal_revoke_role_true_if_role( + contract: Contract, + alice: Address, + bob: Address, + ) { + contract.sender(alice)._grant_role(ROLE.into(), bob); + + let role_revoked = + contract.sender(alice)._revoke_role(ROLE.into(), bob); assert!(role_revoked); } #[motsu::test] - fn internal_revoke_role_false_if_no_role(contract: AccessControl) { - let role_revoked = contract._revoke_role(ROLE.into(), ALICE); + fn internal_revoke_role_false_if_no_role( + contract: Contract, + alice: Address, + bob: Address, + ) { + let role_revoked = + contract.sender(alice)._revoke_role(ROLE.into(), bob); assert!(!role_revoked); } } -*/ From 8773475e28806f102c995bd7d2d436c74b267a7c Mon Sep 17 00:00:00 2001 From: Alisander Qoshqosh Date: Sat, 1 Feb 2025 18:45:44 +0400 Subject: [PATCH 087/109] migrate ownable tests --- contracts/src/access/ownable.rs | 99 +++++++++++++++++++++------------ 1 file changed, 62 insertions(+), 37 deletions(-) diff --git a/contracts/src/access/ownable.rs b/contracts/src/access/ownable.rs index 11704faa7..e3938a7d0 100644 --- a/contracts/src/access/ownable.rs +++ b/contracts/src/access/ownable.rs @@ -201,78 +201,103 @@ impl Ownable { } } -// TODO#q: migrate Ownable tests -/* #[cfg(all(test, feature = "std"))] mod tests { - use alloy_primitives::{address, Address}; - use stylus_sdk::msg; + use alloy_primitives::Address; + use motsu::prelude::Contract; + use stylus_sdk::{msg, prelude::TopLevelStorage}; use super::{Error, IOwnable, Ownable}; - const ALICE: Address = address!("A11CEacF9aa32246d767FCCD72e02d6bCbcC375d"); + unsafe impl TopLevelStorage for Ownable {} #[motsu::test] - fn reads_owner(contract: Ownable) { - contract._owner.set(msg::sender()); - let owner = contract.owner(); + fn reads_owner(contract: Contract, alice: Address) { + contract.init(alice, |contract| contract._owner.set(alice)); + let owner = contract.sender(alice).owner(); assert_eq!(owner, msg::sender()); } #[motsu::test] - fn transfers_ownership(contract: Ownable) { - contract._owner.set(msg::sender()); - - contract.transfer_ownership(ALICE).expect("should transfer ownership"); - let owner = contract._owner.get(); - assert_eq!(owner, ALICE); + fn transfers_ownership( + contract: Contract, + alice: Address, + bob: Address, + ) { + contract.init(alice, |contract| contract._owner.set(alice)); + + contract + .sender(alice) + .transfer_ownership(bob) + .expect("should transfer ownership"); + let owner = contract.sender(alice).owner(); + assert_eq!(owner, bob); } #[motsu::test] - fn prevents_non_onwers_from_transferring(contract: Ownable) { + fn prevents_non_onwers_from_transferring( + contract: Contract, + alice: Address, + bob: Address, + ) { // Alice must be set as owner, because we can't set the // `msg::sender` yet. - contract._owner.set(ALICE); + contract.init(alice, |contract| contract._owner.set(bob)); - let bob = address!("B0B0cB49ec2e96DF5F5fFB081acaE66A2cBBc2e2"); - let err = contract.transfer_ownership(bob).unwrap_err(); + let err = contract.sender(alice).transfer_ownership(bob).unwrap_err(); assert!(matches!(err, Error::UnauthorizedAccount(_))); } #[motsu::test] - fn prevents_reaching_stuck_state(contract: Ownable) { - contract._owner.set(msg::sender()); - - let err = contract.transfer_ownership(Address::ZERO).unwrap_err(); + fn prevents_reaching_stuck_state( + contract: Contract, + alice: Address, + ) { + contract.init(alice, |contract| contract._owner.set(alice)); + + let err = contract + .sender(alice) + .transfer_ownership(Address::ZERO) + .unwrap_err(); assert!(matches!(err, Error::InvalidOwner(_))); } #[motsu::test] - fn loses_ownership_after_renouncing(contract: Ownable) { - contract._owner.set(msg::sender()); - - let _ = contract.renounce_ownership(); - let owner = contract._owner.get(); + fn loses_ownership_after_renouncing( + contract: Contract, + alice: Address, + ) { + contract.init(alice, |contract| contract._owner.set(alice)); + + let _ = contract.sender(alice).renounce_ownership(); + let owner = contract.sender(alice).owner(); assert_eq!(owner, Address::ZERO); } #[motsu::test] - fn prevents_non_owners_from_renouncing(contract: Ownable) { + fn prevents_non_owners_from_renouncing( + contract: Contract, + alice: Address, + bob: Address, + ) { // Alice must be set as owner, because we can't set the // `msg::sender` yet. - contract._owner.set(ALICE); + contract.init(alice, |contract| contract._owner.set(bob)); - let err = contract.renounce_ownership().unwrap_err(); + let err = contract.sender(alice).renounce_ownership().unwrap_err(); assert!(matches!(err, Error::UnauthorizedAccount(_))); } #[motsu::test] - fn recovers_access_using_internal_transfer(contract: Ownable) { - contract._owner.set(ALICE); - - contract._transfer_ownership(ALICE); - let owner = contract._owner.get(); - assert_eq!(owner, ALICE); + fn recovers_access_using_internal_transfer( + contract: Contract, + alice: Address, + bob: Address, + ) { + contract.init(alice, |contract| contract._owner.set(bob)); + + contract.sender(alice)._transfer_ownership(bob); + let owner = contract.sender(alice).owner(); + assert_eq!(owner, bob); } } -*/ From b7b941761edb1cffe33e044554aa4c933ff86930 Mon Sep 17 00:00:00 2001 From: Alisander Qoshqosh Date: Sat, 1 Feb 2025 18:48:51 +0400 Subject: [PATCH 088/109] migrate ownable tests --- contracts/src/access/ownable.rs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/contracts/src/access/ownable.rs b/contracts/src/access/ownable.rs index e3938a7d0..818a5c52a 100644 --- a/contracts/src/access/ownable.rs +++ b/contracts/src/access/ownable.rs @@ -240,8 +240,6 @@ mod tests { alice: Address, bob: Address, ) { - // Alice must be set as owner, because we can't set the - // `msg::sender` yet. contract.init(alice, |contract| contract._owner.set(bob)); let err = contract.sender(alice).transfer_ownership(bob).unwrap_err(); @@ -280,8 +278,6 @@ mod tests { alice: Address, bob: Address, ) { - // Alice must be set as owner, because we can't set the - // `msg::sender` yet. contract.init(alice, |contract| contract._owner.set(bob)); let err = contract.sender(alice).renounce_ownership().unwrap_err(); From e71abe73eec668fbe342dc05fd12ae62e15451d7 Mon Sep 17 00:00:00 2001 From: Alisander Qoshqosh Date: Sat, 1 Feb 2025 19:23:55 +0400 Subject: [PATCH 089/109] migrate Ownable2Step tests --- contracts/src/access/ownable_two_step.rs | 218 ++++++++++++++++------- contracts/src/utils/structs/bitmap.rs | 2 + 2 files changed, 151 insertions(+), 69 deletions(-) diff --git a/contracts/src/access/ownable_two_step.rs b/contracts/src/access/ownable_two_step.rs index c098a9074..d35cf77a1 100644 --- a/contracts/src/access/ownable_two_step.rs +++ b/contracts/src/access/ownable_two_step.rs @@ -219,49 +219,69 @@ impl Ownable2Step { } } -// TODO#q: migrate Ownable2Step tests -/* #[cfg(all(test, feature = "std"))] mod tests { - use alloy_primitives::{address, Address}; - use stylus_sdk::msg; + use alloy_primitives::Address; + use motsu::prelude::Contract; + use stylus_sdk::prelude::TopLevelStorage; use super::{Error, IOwnable2Step, Ownable2Step, OwnableError}; - const ALICE: Address = address!("A11CEacF9aa32246d767FCCD72e02d6bCbcC375d"); - const BOB: Address = address!("B0B0cB49ec2e96DF5F5fFB081acaE66A2cBBc2e2"); + unsafe impl TopLevelStorage for Ownable2Step {} #[motsu::test] - fn reads_owner(contract: Ownable2Step) { - contract._ownable._owner.set(msg::sender()); - let owner = contract.owner(); - assert_eq!(owner, msg::sender()); + fn reads_owner(contract: Contract, alice: Address) { + contract.init(alice, |contract| { + contract._ownable._owner.set(alice); + }); + let owner = contract.sender(alice).owner(); + assert_eq!(owner, alice); } #[motsu::test] - fn reads_pending_owner(contract: Ownable2Step) { - contract._pending_owner.set(ALICE); - let pending_owner = contract.pending_owner(); - assert_eq!(pending_owner, ALICE); + fn reads_pending_owner( + contract: Contract, + alice: Address, + bob: Address, + ) { + contract.init(alice, |contract| { + contract._pending_owner.set(bob); + }); + + let pending_owner = contract.sender(alice).pending_owner(); + assert_eq!(pending_owner, bob); } #[motsu::test] - fn initiates_ownership_transfer(contract: Ownable2Step) { - contract._ownable._owner.set(msg::sender()); + fn initiates_ownership_transfer( + contract: Contract, + alice: Address, + bob: Address, + ) { + contract.init(alice, |contract| { + contract._ownable._owner.set(alice); + }); contract - .transfer_ownership(ALICE) + .sender(alice) + .transfer_ownership(bob) .expect("should initiate ownership transfer"); - let pending_owner = contract._pending_owner.get(); - assert_eq!(pending_owner, ALICE); - assert_eq!(contract.owner(), msg::sender()); + + assert_eq!(contract.sender(alice).owner(), alice); } #[motsu::test] - fn prevents_non_owners_from_initiating_transfer(contract: Ownable2Step) { - contract._ownable._owner.set(ALICE); + fn prevents_non_owners_from_initiating_transfer( + contract: Contract, + alice: Address, + bob: Address, + dave: Address, + ) { + contract.init(alice, |contract| { + contract._ownable._owner.set(bob); + }); - let err = contract.transfer_ownership(BOB).unwrap_err(); + let err = contract.sender(alice).transfer_ownership(dave).unwrap_err(); assert!(matches!( err, Error::Ownable(OwnableError::UnauthorizedAccount(_)) @@ -269,21 +289,37 @@ mod tests { } #[motsu::test] - fn accepts_ownership(contract: Ownable2Step) { - contract._ownable._owner.set(ALICE); - contract._pending_owner.set(msg::sender()); + fn accepts_ownership( + contract: Contract, + alice: Address, + bob: Address, + ) { + contract.init(alice, |contract| { + contract._ownable._owner.set(bob); + contract._pending_owner.set(alice); + }); - contract.accept_ownership().expect("should accept ownership"); - assert_eq!(contract.owner(), msg::sender()); - assert_eq!(contract.pending_owner(), Address::ZERO); + contract + .sender(alice) + .accept_ownership() + .expect("should accept ownership"); + assert_eq!(contract.sender(alice).owner(), alice); + assert_eq!(contract.sender(alice).pending_owner(), Address::ZERO); } #[motsu::test] - fn prevents_non_pending_owner_from_accepting(contract: Ownable2Step) { - contract._ownable._owner.set(ALICE); - contract._pending_owner.set(BOB); + fn prevents_non_pending_owner_from_accepting( + contract: Contract, + alice: Address, + bob: Address, + dave: Address, + ) { + contract.init(alice, |contract| { + contract._ownable._owner.set(bob); + contract._pending_owner.set(dave); + }); - let err = contract.accept_ownership().unwrap_err(); + let err = contract.sender(alice).accept_ownership().unwrap_err(); assert!(matches!( err, Error::Ownable(OwnableError::UnauthorizedAccount(_)) @@ -291,36 +327,54 @@ mod tests { } #[motsu::test] - fn completes_two_step_ownership_transfer(contract: Ownable2Step) { - contract._ownable._owner.set(msg::sender()); + fn completes_two_step_ownership_transfer( + contract: Contract, + alice: Address, + bob: Address, + ) { + contract.init(alice, |contract| { + contract._ownable._owner.set(alice); + }); contract - .transfer_ownership(ALICE) + .sender(alice) + .transfer_ownership(bob) .expect("should initiate ownership transfer"); - assert_eq!(contract.pending_owner(), ALICE); + assert_eq!(contract.sender(alice).pending_owner(), bob); - // Simulate ALICE accepting ownership, since we cannot set `msg::sender` - // in tests yet. - contract._pending_owner.set(msg::sender()); - contract.accept_ownership().expect("should accept ownership"); + contract + .sender(bob) + .accept_ownership() + .expect("should accept ownership"); - assert_eq!(contract.owner(), msg::sender()); - assert_eq!(contract.pending_owner(), Address::ZERO); + assert_eq!(contract.sender(alice).owner(), bob); + assert_eq!(contract.sender(alice).pending_owner(), Address::ZERO); } #[motsu::test] - fn renounces_ownership(contract: Ownable2Step) { - contract._ownable._owner.set(msg::sender()); + fn renounces_ownership(contract: Contract, alice: Address) { + contract.init(alice, |contract| { + contract._ownable._owner.set(alice); + }); - contract.renounce_ownership().expect("should renounce ownership"); - assert_eq!(contract.owner(), Address::ZERO); + contract + .sender(alice) + .renounce_ownership() + .expect("should renounce ownership"); + assert_eq!(contract.sender(alice).owner(), Address::ZERO); } #[motsu::test] - fn prevents_non_owners_from_renouncing(contract: Ownable2Step) { - contract._ownable._owner.set(ALICE); + fn prevents_non_owners_from_renouncing( + contract: Contract, + alice: Address, + bob: Address, + ) { + contract.init(alice, |contract| { + contract._ownable._owner.set(bob); + }); - let err = contract.renounce_ownership().unwrap_err(); + let err = contract.sender(alice).renounce_ownership().unwrap_err(); assert!(matches!( err, Error::Ownable(OwnableError::UnauthorizedAccount(_)) @@ -328,39 +382,65 @@ mod tests { } #[motsu::test] - fn cancels_transfer_on_renounce(contract: Ownable2Step) { - contract._ownable._owner.set(msg::sender()); - contract._pending_owner.set(ALICE); + fn cancels_transfer_on_renounce( + contract: Contract, + alice: Address, + bob: Address, + ) { + contract.init(alice, |contract| { + contract._ownable._owner.set(alice); + contract._pending_owner.set(bob); + }); - contract.renounce_ownership().expect("should renounce ownership"); - assert_eq!(contract.owner(), Address::ZERO); - assert_eq!(contract.pending_owner(), Address::ZERO); + contract + .sender(alice) + .renounce_ownership() + .expect("should renounce ownership"); + assert_eq!(contract.sender(alice).owner(), Address::ZERO); + assert_eq!(contract.sender(alice).pending_owner(), Address::ZERO); } #[motsu::test] - fn allows_owner_to_cancel_transfer(contract: Ownable2Step) { - contract._ownable._owner.set(msg::sender()); - contract._pending_owner.set(ALICE); + fn allows_owner_to_cancel_transfer( + contract: Contract, + alice: Address, + bob: Address, + ) { + contract.init(alice, |contract| { + contract._ownable._owner.set(alice); + contract._pending_owner.set(bob); + }); contract + .sender(alice) .transfer_ownership(Address::ZERO) .expect("should cancel transfer"); - assert_eq!(contract.pending_owner(), Address::ZERO); - assert_eq!(contract.owner(), msg::sender()); + assert_eq!(contract.sender(alice).pending_owner(), Address::ZERO); + assert_eq!(contract.sender(alice).owner(), alice); } #[motsu::test] - fn allows_owner_to_overwrite_transfer(contract: Ownable2Step) { - contract._ownable._owner.set(msg::sender()); + fn allows_owner_to_overwrite_transfer( + contract: Contract, + alice: Address, + bob: Address, + dave: Address, + ) { + contract.init(alice, |contract| { + contract._ownable._owner.set(alice); + }); contract - .transfer_ownership(ALICE) + .sender(alice) + .transfer_ownership(bob) .expect("should initiate ownership transfer"); - assert_eq!(contract.pending_owner(), ALICE); + assert_eq!(contract.sender(alice).pending_owner(), bob); - contract.transfer_ownership(BOB).expect("should overwrite transfer"); - assert_eq!(contract.pending_owner(), BOB); - assert_eq!(contract.owner(), msg::sender()); + contract + .sender(alice) + .transfer_ownership(dave) + .expect("should overwrite transfer"); + assert_eq!(contract.sender(alice).pending_owner(), dave); + assert_eq!(contract.sender(alice).owner(), alice); } } -*/ diff --git a/contracts/src/utils/structs/bitmap.rs b/contracts/src/utils/structs/bitmap.rs index 3d1f3c469..9eb8b81b5 100644 --- a/contracts/src/utils/structs/bitmap.rs +++ b/contracts/src/utils/structs/bitmap.rs @@ -94,6 +94,8 @@ impl BitMap { index >> 8 } } + +// TODO#q: migrate bitmap prop tests /* #[cfg(all(test, feature = "std"))] mod tests { From 37a6d77f4faf6b3968b7a06fc384ec9eef546064 Mon Sep 17 00:00:00 2001 From: Alisander Qoshqosh Date: Sat, 1 Feb 2025 19:34:51 +0400 Subject: [PATCH 090/109] migrate bitmap tests --- Cargo.lock | 4 ++-- contracts/src/utils/structs/bitmap.rs | 27 +++++++++++++++++---------- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a69948ac7..7b5cfba7b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2579,7 +2579,7 @@ checksum = "7843ec2de400bcbc6a6328c958dc38e5359da6e93e72e37bc5246bf1ae776389" [[package]] name = "motsu" version = "0.3.0" -source = "git+https://github.com/OpenZeppelin/stylus-test-helpers?branch=unit-tests%2Fmultiple-contract-deployment#41e9882712cccc82d36fa037c302eda1359b2922" +source = "git+https://github.com/OpenZeppelin/stylus-test-helpers?branch=unit-tests%2Fmultiple-contract-deployment#d3e60a53e85d556ff81491c22d5fefd664366408" dependencies = [ "alloy-primitives", "alloy-sol-types", @@ -2594,7 +2594,7 @@ dependencies = [ [[package]] name = "motsu-proc" version = "0.3.0" -source = "git+https://github.com/OpenZeppelin/stylus-test-helpers?branch=unit-tests%2Fmultiple-contract-deployment#41e9882712cccc82d36fa037c302eda1359b2922" +source = "git+https://github.com/OpenZeppelin/stylus-test-helpers?branch=unit-tests%2Fmultiple-contract-deployment#d3e60a53e85d556ff81491c22d5fefd664366408" dependencies = [ "proc-macro2", "quote", diff --git a/contracts/src/utils/structs/bitmap.rs b/contracts/src/utils/structs/bitmap.rs index 9eb8b81b5..a4078e2e0 100644 --- a/contracts/src/utils/structs/bitmap.rs +++ b/contracts/src/utils/structs/bitmap.rs @@ -95,18 +95,24 @@ impl BitMap { } } -// TODO#q: migrate bitmap prop tests -/* #[cfg(all(test, feature = "std"))] mod tests { - use alloy_primitives::{private::proptest::proptest, U256}; + use alloy_primitives::{private::proptest::proptest, Address, U256}; + use motsu::prelude::Contract; + use stylus_sdk::prelude::{public, TopLevelStorage}; use crate::utils::structs::bitmap::BitMap; + unsafe impl TopLevelStorage for BitMap {} + + #[public] + impl BitMap {} + #[motsu::test] fn set_value() { - proptest!(|(value: U256)| { - let mut bit_map = BitMap::default(); + proptest!(|(value: U256, alice: Address)| { + let bit_map = Contract::::new(); + let mut bit_map = bit_map.sender(alice); assert!(!bit_map.get(value)); bit_map.set(value); assert!(bit_map.get(value)); @@ -115,8 +121,9 @@ mod tests { #[motsu::test] fn unset_value() { - proptest!(|(value: U256)| { - let mut bit_map = BitMap::default(); + proptest!(|(value: U256, alice: Address)| { + let bit_map = Contract::::new(); + let mut bit_map = bit_map.sender(alice); bit_map.set(value); assert!(bit_map.get(value)); bit_map.unset(value); @@ -126,8 +133,9 @@ mod tests { #[motsu::test] fn set_to_value() { - proptest!(|(value: U256)| { - let mut bit_map = BitMap::default(); + proptest!(|(value: U256, alice: Address)| { + let bit_map = Contract::::new(); + let mut bit_map = bit_map.sender(alice); bit_map.set_to(value, true); assert!(bit_map.get(value)); bit_map.set_to(value, false); @@ -135,4 +143,3 @@ mod tests { }); } } -*/ From c0ff1a189c63b4cb3a5d768735de63f210c63716 Mon Sep 17 00:00:00 2001 From: Alisander Qoshqosh Date: Sat, 1 Feb 2025 20:52:43 +0400 Subject: [PATCH 091/109] migrate nonces tests --- contracts/src/utils/nonces.rs | 41 +++++++++++++++++------------------ 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/contracts/src/utils/nonces.rs b/contracts/src/utils/nonces.rs index 4362242fd..043dd31d1 100644 --- a/contracts/src/utils/nonces.rs +++ b/contracts/src/utils/nonces.rs @@ -113,52 +113,51 @@ impl Nonces { } } -// TODO#q: migrate Nonces -/* #[cfg(all(test, feature = "std"))] mod tests { - use alloy_primitives::U256; - use stylus_sdk::msg; + use alloy_primitives::{Address, U256}; + use motsu::prelude::Contract; + use stylus_sdk::prelude::TopLevelStorage; use super::ONE; use crate::utils::nonces::{Error, Nonces}; + unsafe impl TopLevelStorage for Nonces {} + #[motsu::test] - fn initiate_nonce(contract: Nonces) { - assert_eq!(contract.nonces(msg::sender()), U256::ZERO); + fn initiate_nonce(contract: Contract, alice: Address) { + assert_eq!(contract.sender(alice).nonces(alice), U256::ZERO); } #[motsu::test] - fn use_nonce(contract: Nonces) { - let owner = msg::sender(); - - let use_nonce = contract.use_nonce(owner); + fn use_nonce(contract: Contract, alice: Address) { + let use_nonce = contract.sender(alice).use_nonce(alice); assert_eq!(use_nonce, U256::ZERO); - let nonce = contract.nonces(owner); + let nonce = contract.sender(alice).nonces(alice); assert_eq!(nonce, ONE); } #[motsu::test] - fn use_checked_nonce(contract: Nonces) { - let owner = msg::sender(); - - let use_checked_nonce = contract.use_checked_nonce(owner, U256::ZERO); + fn use_checked_nonce(contract: Contract, alice: Address) { + let use_checked_nonce = + contract.sender(alice).use_checked_nonce(alice, U256::ZERO); assert!(use_checked_nonce.is_ok()); - let nonce = contract.nonces(owner); + let nonce = contract.sender(alice).nonces(alice); assert_eq!(nonce, ONE); } #[motsu::test] - fn use_checked_nonce_invalid_nonce(contract: Nonces) { - let owner = msg::sender(); - - let use_checked_nonce = contract.use_checked_nonce(owner, ONE); + fn use_checked_nonce_invalid_nonce( + contract: Contract, + alice: Address, + ) { + let use_checked_nonce = + contract.sender(alice).use_checked_nonce(alice, ONE); assert!(matches!( use_checked_nonce, Err(Error::InvalidAccountNonce(_)) )); } } -*/ From da58844e5377671393e3e35c20d1eac7a14347f9 Mon Sep 17 00:00:00 2001 From: Alisander Qoshqosh Date: Sat, 1 Feb 2025 21:18:56 +0400 Subject: [PATCH 092/109] migrate pausable tests --- contracts/src/utils/pausable.rs | 116 +++++++++++++++++++------------- 1 file changed, 69 insertions(+), 47 deletions(-) diff --git a/contracts/src/utils/pausable.rs b/contracts/src/utils/pausable.rs index bb4c32df0..bb35702b8 100644 --- a/contracts/src/utils/pausable.rs +++ b/contracts/src/utils/pausable.rs @@ -156,97 +156,119 @@ impl Pausable { } } -// TODO#q: migrate Pausable -/* #[cfg(all(test, feature = "std"))] mod tests { + use alloy_primitives::Address; + use motsu::prelude::Contract; + use stylus_sdk::prelude::TopLevelStorage; + use crate::utils::pausable::{Error, Pausable}; - #[motsu::test] - fn paused_works(contract: Pausable) { - contract._paused.set(false); - assert!(!contract.paused()); + unsafe impl TopLevelStorage for Pausable {} + + fn construct_paused(contract: &mut Pausable) { contract._paused.set(true); - assert!(contract.paused()); + } + fn construct_unpaused(contract: &mut Pausable) { + contract._paused.set(false); } #[motsu::test] - fn when_not_paused_works(contract: Pausable) { - contract._paused.set(false); - assert!(!contract.paused()); + fn paused_works(contract: Contract, alice: Address) { + contract.init(alice, construct_paused); + assert!(contract.sender(alice).paused()); - let result = contract.when_not_paused(); - assert!(result.is_ok()); + contract.init(alice, construct_unpaused); + assert!(!contract.sender(alice).paused()); } #[motsu::test] - fn when_not_paused_errors_when_paused(contract: Pausable) { - contract._paused.set(true); - assert!(contract.paused()); + fn when_not_paused_works(contract: Contract, alice: Address) { + contract.init(alice, construct_unpaused); - let result = contract.when_not_paused(); + let result = contract.sender(alice).when_not_paused(); + assert!(result.is_ok()); + } + + #[motsu::test] + fn when_not_paused_errors_when_paused( + contract: Contract, + alice: Address, + ) { + contract.init(alice, construct_paused); + assert!(contract.sender(alice).paused()); + + let result = contract.sender(alice).when_not_paused(); assert!(matches!(result, Err(Error::EnforcedPause(_)))); } #[motsu::test] - fn when_paused_works(contract: Pausable) { - contract._paused.set(true); - assert!(contract.paused()); + fn when_paused_works(contract: Contract, alice: Address) { + contract.sender(alice).pause().unwrap(); + assert!(contract.sender(alice).paused()); - let result = contract.when_paused(); + let result = contract.sender(alice).when_paused(); assert!(result.is_ok()); } #[motsu::test] - fn when_paused_errors_when_not_paused(contract: Pausable) { - contract._paused.set(false); - assert!(!contract.paused()); - - let result = contract.when_paused(); + fn when_paused_errors_when_not_paused( + contract: Contract, + alice: Address, + ) { + contract.init(alice, construct_unpaused); + assert!(!contract.sender(alice).paused()); + + let result = contract.sender(alice).when_paused(); assert!(matches!(result, Err(Error::ExpectedPause(_)))); } #[motsu::test] - fn pause_works(contract: Pausable) { - contract._paused.set(false); - assert!(!contract.paused()); + fn pause_works(contract: Contract, alice: Address) { + contract.init(alice, construct_unpaused); + assert!(!contract.sender(alice).paused()); // Pause the contract - let res = contract.pause(); + let res = contract.sender(alice).pause(); assert!(res.is_ok()); - assert!(contract.paused()); + assert!(contract.sender(alice).paused()); } #[motsu::test] - fn pause_errors_when_already_paused(contract: Pausable) { - contract._paused.set(true); - assert!(contract.paused()); - - let result = contract.pause(); + fn pause_errors_when_already_paused( + contract: Contract, + alice: Address, + ) { + contract.init(alice, construct_paused); + assert!(contract.sender(alice).paused()); + + let result = contract.sender(alice).pause(); assert!(matches!(result, Err(Error::EnforcedPause(_)))); - assert!(contract.paused()); + assert!(contract.sender(alice).paused()); } #[motsu::test] - fn unpause_works(contract: Pausable) { - contract._paused.set(true); - assert!(contract.paused()); + fn unpause_works(contract: Contract, alice: Address) { + contract.init(alice, construct_paused); + assert!(contract.sender(alice).paused()); // Unpause the paused contract - let res = contract.unpause(); + let res = contract.sender(alice).unpause(); assert!(res.is_ok()); - assert!(!contract.paused()); + assert!(!contract.sender(alice).paused()); } #[motsu::test] - fn unpause_errors_when_already_unpaused(contract: Pausable) { - contract._paused.set(false); - assert!(!contract.paused()); + fn unpause_errors_when_already_unpaused( + contract: Contract, + alice: Address, + ) { + contract.init(alice, construct_unpaused); + assert!(!contract.sender(alice).paused()); // Unpause the unpaused contract - let result = contract.unpause(); + let result = contract.sender(alice).unpause(); assert!(matches!(result, Err(Error::ExpectedPause(_)))); - assert!(!contract.paused()); + assert!(!contract.sender(alice).paused()); } } -*/ From 3083696afc8c0102b2e440a70a33a9726c0b3fb3 Mon Sep 17 00:00:00 2001 From: Alisander Qoshqosh Date: Sat, 1 Feb 2025 21:38:27 +0400 Subject: [PATCH 093/109] ++ --- contracts/src/utils/structs/bitmap.rs | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/contracts/src/utils/structs/bitmap.rs b/contracts/src/utils/structs/bitmap.rs index a4078e2e0..4c98f00b5 100644 --- a/contracts/src/utils/structs/bitmap.rs +++ b/contracts/src/utils/structs/bitmap.rs @@ -97,7 +97,10 @@ impl BitMap { #[cfg(all(test, feature = "std"))] mod tests { - use alloy_primitives::{private::proptest::proptest, Address, U256}; + use alloy_primitives::{ + private::proptest::{prop_assert, proptest}, + Address, U256, + }; use motsu::prelude::Contract; use stylus_sdk::prelude::{public, TopLevelStorage}; @@ -113,9 +116,9 @@ mod tests { proptest!(|(value: U256, alice: Address)| { let bit_map = Contract::::new(); let mut bit_map = bit_map.sender(alice); - assert!(!bit_map.get(value)); + prop_assert!(!bit_map.get(value)); bit_map.set(value); - assert!(bit_map.get(value)); + prop_assert!(bit_map.get(value)); }); } @@ -125,9 +128,9 @@ mod tests { let bit_map = Contract::::new(); let mut bit_map = bit_map.sender(alice); bit_map.set(value); - assert!(bit_map.get(value)); + prop_assert!(bit_map.get(value)); bit_map.unset(value); - assert!(!bit_map.get(value)); + prop_assert!(!bit_map.get(value)); }); } @@ -137,9 +140,9 @@ mod tests { let bit_map = Contract::::new(); let mut bit_map = bit_map.sender(alice); bit_map.set_to(value, true); - assert!(bit_map.get(value)); + prop_assert!(bit_map.get(value)); bit_map.set_to(value, false); - assert!(!bit_map.get(value)); + prop_assert!(!bit_map.get(value)); }); } } From d933c5f9a2aade9302e7c4178229b2175f3173f8 Mon Sep 17 00:00:00 2001 From: Alisander Qoshqosh Date: Sat, 1 Feb 2025 22:27:11 +0400 Subject: [PATCH 094/109] migrate vesting_westing --- Cargo.lock | 4 +- Cargo.toml | 2 +- contracts/src/access/control.rs | 2 +- contracts/src/finance/vesting_wallet.rs | 139 +++++++++++------- .../token/erc721/extensions/consecutive.rs | 2 +- .../src/token/erc721/extensions/enumerable.rs | 2 + examples/access-control/src/lib.rs | 4 - 7 files changed, 94 insertions(+), 61 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7b5cfba7b..276d52cec 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2579,7 +2579,7 @@ checksum = "7843ec2de400bcbc6a6328c958dc38e5359da6e93e72e37bc5246bf1ae776389" [[package]] name = "motsu" version = "0.3.0" -source = "git+https://github.com/OpenZeppelin/stylus-test-helpers?branch=unit-tests%2Fmultiple-contract-deployment#d3e60a53e85d556ff81491c22d5fefd664366408" +source = "git+https://github.com/OpenZeppelin/stylus-test-helpers?branch=main#480e012b150cb701c986662d111fed29d2c22179" dependencies = [ "alloy-primitives", "alloy-sol-types", @@ -2594,7 +2594,7 @@ dependencies = [ [[package]] name = "motsu-proc" version = "0.3.0" -source = "git+https://github.com/OpenZeppelin/stylus-test-helpers?branch=unit-tests%2Fmultiple-contract-deployment#d3e60a53e85d556ff81491c22d5fefd664366408" +source = "git+https://github.com/OpenZeppelin/stylus-test-helpers?branch=main#480e012b150cb701c986662d111fed29d2c22179" dependencies = [ "proc-macro2", "quote", diff --git a/Cargo.toml b/Cargo.toml index 8e88dd1f7..daf8e65be 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -154,4 +154,4 @@ files = { extend-exclude = [] } # TODO#q: remove motsu patch once update is released [patch.crates-io.motsu] git = "https://github.com/OpenZeppelin/stylus-test-helpers" -branch = "unit-tests/multiple-contract-deployment" +branch = "main" diff --git a/contracts/src/access/control.rs b/contracts/src/access/control.rs index b7d531f43..68fb68934 100644 --- a/contracts/src/access/control.rs +++ b/contracts/src/access/control.rs @@ -378,7 +378,7 @@ impl AccessControl { mod tests { use alloy_primitives::Address; use motsu::prelude::Contract; - use stylus_sdk::{msg, prelude::TopLevelStorage}; + use stylus_sdk::prelude::TopLevelStorage; use super::{AccessControl, Error}; diff --git a/contracts/src/finance/vesting_wallet.rs b/contracts/src/finance/vesting_wallet.rs index 8bb6cf2d2..fbb608760 100644 --- a/contracts/src/finance/vesting_wallet.rs +++ b/contracts/src/finance/vesting_wallet.rs @@ -25,7 +25,7 @@ //! adjustment in the vesting schedule to ensure the vested amount is as //! intended. -use alloc::{vec, vec::Vec}; +use alloc::vec::Vec; use alloy_primitives::{Address, U256, U64}; use openzeppelin_stylus_proc::interface_id; @@ -518,104 +518,139 @@ impl VestingWallet { #[cfg(all(test, feature = "std"))] mod tests { - // TODO#q: migrate vesting wallet - /* - use alloy_primitives::{address, uint, Address, U256, U64}; + use alloy_primitives::{uint, Address, U256, U64}; + use motsu::prelude::Contract; use stylus_sdk::block; use super::{IVestingWallet, VestingWallet}; + use crate::token::erc20::Erc20; + + const BALANCE: u64 = 1000; - const TOKEN: Address = address!("A11CEacF9aa32246d767FCCD72e02d6bCbcC375d"); const DURATION: u64 = 4 * 365 * 86400; // 4 years fn start() -> u64 { block::timestamp() + 3600 // 1 hour } - fn init( - contract: &mut VestingWallet, - start: u64, - duration: u64, - ) -> (U64, U64) { - let start = U64::from(start); - let duration = U64::from(duration); - contract._start.set(start); - contract._duration.set(duration); - (start, duration) + impl VestingWallet { + fn init(&mut self, start: u64, duration: u64) -> (U64, U64) { + let start = U64::from(start); + let duration = U64::from(duration); + self._start.set(start); + self._duration.set(duration); + (start, duration) + } } #[motsu::test] - fn reads_start(contract: VestingWallet) { - let (start, _) = init(contract, start(), 0); - assert_eq!(U256::from(start), contract.start()); + fn reads_start(contract: Contract, alice: Address) { + let (start, _) = contract.sender(alice).init(start(), DURATION); + assert_eq!(U256::from(start), contract.sender(alice).start()); } #[motsu::test] - fn reads_duration(contract: VestingWallet) { - let (_, duration) = init(contract, 0, DURATION); - assert_eq!(U256::from(duration), contract.duration()); + fn reads_duration(contract: Contract, alice: Address) { + let (_, duration) = contract.sender(alice).init(0, DURATION); + assert_eq!(U256::from(duration), contract.sender(alice).duration()); } #[motsu::test] - fn reads_end(contract: VestingWallet) { - let (start, duration) = init(contract, start(), DURATION); - assert_eq!(U256::from(start + duration), contract.end()); - } + fn reads_end(contract: Contract, alice: Address) { + let (start, duration) = contract.sender(alice).init(start(), DURATION); - #[motsu::test] - fn reads_max_end(contract: VestingWallet) { - init(contract, u64::MAX, u64::MAX); - assert_eq!(U256::from(U64::MAX) + U256::from(U64::MAX), contract.end()); + assert_eq!(U256::from(start + duration), contract.sender(alice).end()); } #[motsu::test] - fn reads_released_eth(contract: VestingWallet) { - let one = uint!(1_U256); - contract._released.set(one); - assert_eq!(one, contract.released_eth()); - } - - #[motsu::test] - fn reads_released_erc20(contract: VestingWallet) { - let one = uint!(1_U256); - contract._erc20_released.setter(TOKEN).set(one); - assert_eq!(one, contract.released_erc20(TOKEN)); + fn reads_max_end(contract: Contract, alice: Address) { + contract.sender(alice).init(u64::MAX, u64::MAX); + assert_eq!( + U256::from(U64::MAX) + U256::from(U64::MAX), + contract.sender(alice).end() + ); } #[motsu::test] - fn gets_vesting_schedule(contract: VestingWallet) { - let (start, duration) = init(contract, start(), DURATION); + fn gets_vesting_schedule( + contract: Contract, + alice: Address, + ) { + let (start, duration) = contract.sender(alice).init(start(), DURATION); let one = uint!(1_U256); let two = uint!(2_U256); assert_eq!( U256::ZERO, - contract.vesting_schedule(two, start - U64::from(1)) + contract.sender(alice).vesting_schedule(two, start - U64::from(1)) ); assert_eq!( one, - contract.vesting_schedule(two, start + duration / U64::from(2)) + contract + .sender(alice) + .vesting_schedule(two, start + duration / U64::from(2)) ); - assert_eq!(two, contract.vesting_schedule(two, start + duration)); assert_eq!( two, - contract.vesting_schedule(two, start + duration + U64::from(1)) + contract.sender(alice).vesting_schedule(two, start + duration) + ); + assert_eq!( + two, + contract + .sender(alice) + .vesting_schedule(two, start + duration + U64::from(1)) ); } #[motsu::test] - fn gets_vesting_schedule_zero_duration(contract: VestingWallet) { - let (start, _) = init(contract, start(), 0); + fn gets_vesting_schedule_zero_duration( + contract: Contract, + alice: Address, + ) { + let (start, _) = contract.sender(alice).init(start(), 0); let two = uint!(2_U256); assert_eq!( U256::ZERO, - contract.vesting_schedule(two, start - U64::from(1)) + contract.sender(alice).vesting_schedule(two, start - U64::from(1)) + ); + assert_eq!(two, contract.sender(alice).vesting_schedule(two, start)); + assert_eq!( + two, + contract.sender(alice).vesting_schedule(two, start + U64::from(1)) ); - assert_eq!(two, contract.vesting_schedule(two, start)); - assert_eq!(two, contract.vesting_schedule(two, start + U64::from(1))); } - */ + + #[motsu::test] + fn check_vested_amount_erc20( + vesting_wallet: Contract, + erc20: Contract, + alice: Address, + ) { + vesting_wallet.sender(alice).init(start(), DURATION); + erc20 + .sender(alice) + ._mint(vesting_wallet.address(), U256::from(BALANCE)) + .unwrap(); + + let start = start(); + for i in 0..64 { + let timestamp = i * DURATION / 60 + start; + let expected_amount = U256::from(std::cmp::min( + BALANCE, + BALANCE * (timestamp - start) / DURATION, + )); + + let vested_amount = vesting_wallet + .sender(alice) + .vested_amount_erc20(erc20.address(), timestamp) + .unwrap(); + assert_eq!( + expected_amount, vested_amount, + "\n---\ni: {i}\nstart: {start}\ntimestamp: {timestamp}\n---\n" + ); + } + } } diff --git a/contracts/src/token/erc721/extensions/consecutive.rs b/contracts/src/token/erc721/extensions/consecutive.rs index 135826c47..7afcd97ef 100644 --- a/contracts/src/token/erc721/extensions/consecutive.rs +++ b/contracts/src/token/erc721/extensions/consecutive.rs @@ -24,7 +24,7 @@ //! //! [ERC]: https://eips.ethereum.org/EIPS/eip-2309 -use alloc::vec; +use alloc::{vec, vec::Vec}; use alloy_primitives::{uint, Address, U256}; use stylus_sdk::{ diff --git a/contracts/src/token/erc721/extensions/enumerable.rs b/contracts/src/token/erc721/extensions/enumerable.rs index ea6092ab0..e7ad07f9c 100644 --- a/contracts/src/token/erc721/extensions/enumerable.rs +++ b/contracts/src/token/erc721/extensions/enumerable.rs @@ -9,6 +9,8 @@ //! interfere with enumerability and should not be used together with //! [`Erc721Enumerable`]. +use alloc::vec::Vec; + use alloy_primitives::{uint, Address, FixedBytes, U256}; use openzeppelin_stylus_proc::interface_id; pub use sol::*; diff --git a/examples/access-control/src/lib.rs b/examples/access-control/src/lib.rs index 94e4cd57a..744b2e1e9 100644 --- a/examples/access-control/src/lib.rs +++ b/examples/access-control/src/lib.rs @@ -48,7 +48,3 @@ impl AccessControlExample { self.access._set_role_admin(role, new_admin_role) } } - -impl AccessControlExample { - pub const TRANSFER_ROLE: [u8; 32] = TRANSFER_ROLE; -} From 1fb8a09346399d5e71834072a209288137631a29 Mon Sep 17 00:00:00 2001 From: Alisander Qoshqosh Date: Tue, 4 Feb 2025 18:55:48 +0400 Subject: [PATCH 095/109] update motsu branch --- Cargo.lock | 4 ++-- Cargo.toml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 276d52cec..c05d688c0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2579,7 +2579,7 @@ checksum = "7843ec2de400bcbc6a6328c958dc38e5359da6e93e72e37bc5246bf1ae776389" [[package]] name = "motsu" version = "0.3.0" -source = "git+https://github.com/OpenZeppelin/stylus-test-helpers?branch=main#480e012b150cb701c986662d111fed29d2c22179" +source = "git+https://github.com/OpenZeppelin/stylus-test-helpers?branch=mock-msg-value-and-balance#a6f825168dd9b2a671853df4d57c6337ef01c5be" dependencies = [ "alloy-primitives", "alloy-sol-types", @@ -2594,7 +2594,7 @@ dependencies = [ [[package]] name = "motsu-proc" version = "0.3.0" -source = "git+https://github.com/OpenZeppelin/stylus-test-helpers?branch=main#480e012b150cb701c986662d111fed29d2c22179" +source = "git+https://github.com/OpenZeppelin/stylus-test-helpers?branch=mock-msg-value-and-balance#a6f825168dd9b2a671853df4d57c6337ef01c5be" dependencies = [ "proc-macro2", "quote", diff --git a/Cargo.toml b/Cargo.toml index daf8e65be..cf5480080 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -154,4 +154,4 @@ files = { extend-exclude = [] } # TODO#q: remove motsu patch once update is released [patch.crates-io.motsu] git = "https://github.com/OpenZeppelin/stylus-test-helpers" -branch = "main" +branch = "mock-msg-value-and-balance" From bd2693c7afeee49d306f0389599f7a60c8f59566 Mon Sep 17 00:00:00 2001 From: Alisander Qoshqosh Date: Tue, 4 Feb 2025 19:19:59 +0400 Subject: [PATCH 096/109] ++ --- Cargo.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c05d688c0..4d6589204 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2579,7 +2579,7 @@ checksum = "7843ec2de400bcbc6a6328c958dc38e5359da6e93e72e37bc5246bf1ae776389" [[package]] name = "motsu" version = "0.3.0" -source = "git+https://github.com/OpenZeppelin/stylus-test-helpers?branch=mock-msg-value-and-balance#a6f825168dd9b2a671853df4d57c6337ef01c5be" +source = "git+https://github.com/OpenZeppelin/stylus-test-helpers?branch=mock-msg-value-and-balance#410c775f422c51da5d6b70c88fc92393fec0023e" dependencies = [ "alloy-primitives", "alloy-sol-types", @@ -2594,7 +2594,7 @@ dependencies = [ [[package]] name = "motsu-proc" version = "0.3.0" -source = "git+https://github.com/OpenZeppelin/stylus-test-helpers?branch=mock-msg-value-and-balance#a6f825168dd9b2a671853df4d57c6337ef01c5be" +source = "git+https://github.com/OpenZeppelin/stylus-test-helpers?branch=mock-msg-value-and-balance#410c775f422c51da5d6b70c88fc92393fec0023e" dependencies = [ "proc-macro2", "quote", From 8fd968b9385b1b3523c0aea4698ad074ebf6900f Mon Sep 17 00:00:00 2001 From: Alisander Qoshqosh Date: Tue, 4 Feb 2025 19:22:08 +0400 Subject: [PATCH 097/109] ++ --- .github/workflows/check.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index 80c606731..557f13452 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -118,7 +118,7 @@ jobs: # target in this context means one of `--lib`, `--bin`, etc, and not the # target triple. - name: Cargo hack - run: cargo hack check --feature-powerset --depth 2 --release --target wasm32-unknown-unknown --skip std --package openzeppelin-stylus + run: cargo hack check --feature-powerset --depth 2 --release --target wasm32-unknown-unknown --skip std --workspace --exclude e2e --exclude basic-example-script --exclude benches typos: runs-on: ubuntu-latest name: ubuntu / stable / typos From edb955b895efb03de411e404eb287c0a91049856 Mon Sep 17 00:00:00 2001 From: Alisander Qoshqosh Date: Tue, 4 Feb 2025 19:40:19 +0400 Subject: [PATCH 098/109] ++ --- Cargo.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4d6589204..08e7b2470 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2579,7 +2579,7 @@ checksum = "7843ec2de400bcbc6a6328c958dc38e5359da6e93e72e37bc5246bf1ae776389" [[package]] name = "motsu" version = "0.3.0" -source = "git+https://github.com/OpenZeppelin/stylus-test-helpers?branch=mock-msg-value-and-balance#410c775f422c51da5d6b70c88fc92393fec0023e" +source = "git+https://github.com/OpenZeppelin/stylus-test-helpers?branch=mock-msg-value-and-balance#0b48d1c962e07e20d8b4a01890b418ef5677a649" dependencies = [ "alloy-primitives", "alloy-sol-types", @@ -2594,7 +2594,7 @@ dependencies = [ [[package]] name = "motsu-proc" version = "0.3.0" -source = "git+https://github.com/OpenZeppelin/stylus-test-helpers?branch=mock-msg-value-and-balance#410c775f422c51da5d6b70c88fc92393fec0023e" +source = "git+https://github.com/OpenZeppelin/stylus-test-helpers?branch=mock-msg-value-and-balance#0b48d1c962e07e20d8b4a01890b418ef5677a649" dependencies = [ "proc-macro2", "quote", From 898dd78441e32e364e7566353d0acac4afa778c4 Mon Sep 17 00:00:00 2001 From: Daniel Bigos Date: Wed, 5 Feb 2025 11:52:10 +0100 Subject: [PATCH 099/109] build: update motsu patch --- Cargo.lock | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 08e7b2470..4905e2f6b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2579,7 +2579,7 @@ checksum = "7843ec2de400bcbc6a6328c958dc38e5359da6e93e72e37bc5246bf1ae776389" [[package]] name = "motsu" version = "0.3.0" -source = "git+https://github.com/OpenZeppelin/stylus-test-helpers?branch=mock-msg-value-and-balance#0b48d1c962e07e20d8b4a01890b418ef5677a649" +source = "git+https://github.com/OpenZeppelin/stylus-test-helpers?branch=mock-msg-value-and-balance#155327b54a121a2a93945cbda77f9bfeb55c4a3a" dependencies = [ "alloy-primitives", "alloy-sol-types", @@ -2594,7 +2594,7 @@ dependencies = [ [[package]] name = "motsu-proc" version = "0.3.0" -source = "git+https://github.com/OpenZeppelin/stylus-test-helpers?branch=mock-msg-value-and-balance#0b48d1c962e07e20d8b4a01890b418ef5677a649" +source = "git+https://github.com/OpenZeppelin/stylus-test-helpers?branch=mock-msg-value-and-balance#155327b54a121a2a93945cbda77f9bfeb55c4a3a" dependencies = [ "proc-macro2", "quote", @@ -4624,7 +4624,7 @@ version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cf221c93e13a30d793f7645a0e7762c55d169dbb0a49671918a2319d289b10bb" dependencies = [ - "windows-sys 0.52.0", + "windows-sys 0.48.0", ] [[package]] From c5bc3419c65307ac48a4b40c1e94231001d8076a Mon Sep 17 00:00:00 2001 From: Daniel Bigos Date: Wed, 5 Feb 2025 13:37:20 +0100 Subject: [PATCH 100/109] test: migrate rest of Erc1155 unit tests --- .../proptest-regressions/utils/math/alloy.txt | 8 ++++ contracts/src/token/erc1155/mod.rs | 46 ++++++++----------- 2 files changed, 27 insertions(+), 27 deletions(-) create mode 100644 contracts/proptest-regressions/utils/math/alloy.txt diff --git a/contracts/proptest-regressions/utils/math/alloy.txt b/contracts/proptest-regressions/utils/math/alloy.txt new file mode 100644 index 000000000..38d765b0f --- /dev/null +++ b/contracts/proptest-regressions/utils/math/alloy.txt @@ -0,0 +1,8 @@ +# Seeds for failure cases proptest has generated in the past. It is +# automatically read and these particular cases re-run before any +# novel cases are generated. +# +# It is recommended to check this file in to source control so that +# everyone who runs the test benefits from these saved cases. +cc f58ea2d53136bc78804abf3cc86633f05fad78c146b9462904fbac613cd74a2b # shrinks to x = 0, y = 0 +cc eef31162ab6714625e038aa5625425e31970b3637872924e6d6ab6de8f9cc12a # shrinks to x = 6277101735386680763835789423207666416102355444464034512896, y = 6277101735386680763835789423207666416102355444464034512896 diff --git a/contracts/src/token/erc1155/mod.rs b/contracts/src/token/erc1155/mod.rs index d35b276fc..7d7163cd5 100644 --- a/contracts/src/token/erc1155/mod.rs +++ b/contracts/src/token/erc1155/mod.rs @@ -1695,26 +1695,25 @@ mod tests { )); } - // TODO#q: rewrite test error_when_invalid_sender_safe_transfer_from - /*#[motsu::test] + #[motsu::test] fn error_when_invalid_sender_safe_transfer_from( contract: Contract, + alice: Address, ) { - let alice = msg::sender(); let (token_ids, values) = contract.init(alice, |contract| init(contract, alice, 1)); let invalid_sender = Address::ZERO; contract - .sender(alice) - ._set_approval_for_all(invalid_sender, alice, true) - .expect("should approve Bob's tokens to Alice"); + .sender(invalid_sender) + .set_approval_for_all(alice, true) + .unwrap(); let err = contract .sender(alice) .safe_transfer_from( invalid_sender, - bob, + alice, token_ids[0], values[0], vec![].into(), @@ -1727,7 +1726,7 @@ mod tests { sender }) if sender == invalid_sender )); - }*/ + } #[motsu::test] fn error_when_missing_approval_safe_transfer_from( @@ -1854,13 +1853,11 @@ mod tests { )); } - // TODO#q: rewrite test - // error_when_invalid_sender_safe_transfer_from_with_data - /*#[motsu::test] + #[motsu::test] fn error_when_invalid_sender_safe_transfer_from_with_data( contract: Contract, + alice: Address, ) { - let alice = msg::sender(); let (token_ids, values) = contract.init(alice, |contract| init(contract, alice, 1)); let invalid_sender = Address::ZERO; @@ -1874,7 +1871,7 @@ mod tests { .sender(alice) .safe_transfer_from( invalid_sender, - charlie, + alice, token_ids[0], values[0], vec![0, 1, 2, 3].into(), @@ -1887,7 +1884,7 @@ mod tests { sender }) if sender == invalid_sender )); - }*/ + } #[motsu::test] fn error_when_missing_approval_safe_transfer_from_with_data( @@ -2020,12 +2017,11 @@ mod tests { )); } - // TODO#q: rewrite test error_when_invalid_sender_safe_batch_transfer_from - /*#[motsu::test] + #[motsu::test] fn error_when_invalid_sender_safe_batch_transfer_from( contract: Contract, + alice: Address, ) { - let (token_ids, values) = contract.init(alice, |contract| init(contract, alice, 4)); let invalid_sender = Address::ZERO; @@ -2039,7 +2035,7 @@ mod tests { .sender(alice) .safe_batch_transfer_from( invalid_sender, - charlie, + alice, token_ids.clone(), values.clone(), vec![].into(), @@ -2052,7 +2048,7 @@ mod tests { sender }) if sender == invalid_sender )); - }*/ + } #[motsu::test] fn error_when_missing_approval_safe_batch_transfer_from( @@ -2219,15 +2215,11 @@ mod tests { )); } - // TODO#q: rewrite test - // error_when_invalid_sender_safe_batch_transfer_from_with_data - /*#[motsu::test] + #[motsu::test] fn error_when_invalid_sender_safe_batch_transfer_from_with_data( contract: Contract, + alice: Address, ) { - - let charlie = charlie; - let (token_ids, values) = contract.init(alice, |contract| init(contract, alice, 4)); let invalid_sender = Address::ZERO; @@ -2241,7 +2233,7 @@ mod tests { .sender(alice) .safe_batch_transfer_from( invalid_sender, - charlie, + alice, token_ids.clone(), values.clone(), vec![0, 1, 2, 3].into(), @@ -2254,7 +2246,7 @@ mod tests { sender }) if sender == invalid_sender )); - }*/ + } #[motsu::test] fn error_when_missing_approval_safe_batch_transfer_from_with_data( From 3ebb1aec49e3d2d8c3086f769d335950d28c3052 Mon Sep 17 00:00:00 2001 From: Daniel Bigos Date: Wed, 5 Feb 2025 17:23:28 +0100 Subject: [PATCH 101/109] test: migrate Erc4626 unit tests --- .../src/token/erc20/extensions/erc4626.rs | 77 ++++++++++++------- 1 file changed, 49 insertions(+), 28 deletions(-) diff --git a/contracts/src/token/erc20/extensions/erc4626.rs b/contracts/src/token/erc20/extensions/erc4626.rs index c557e6d2f..b4d143818 100644 --- a/contracts/src/token/erc20/extensions/erc4626.rs +++ b/contracts/src/token/erc20/extensions/erc4626.rs @@ -1146,10 +1146,9 @@ impl Erc4626 { // TODO#q: Add missing tests once `motsu` supports calling external contracts. #[cfg(all(test, feature = "std"))] mod tests { - // TODO#q: rewrite erc4626 tests - /* - use alloy_primitives::{address, U256, U8}; - use stylus_sdk::{msg, prelude::storage}; + use alloy_primitives::{address, Address, U256, U8}; + use motsu::prelude::Contract; + use stylus_sdk::{msg, prelude::*}; use super::{Erc4626, IErc4626}; use crate::token::erc20::Erc20; @@ -1160,60 +1159,82 @@ mod tests { erc20: Erc20, } + #[public] + impl Erc4626TestExample { + fn asset(&self) -> Address { + self.erc4626.asset() + } + + fn max_deposit(&self, receiver: Address) -> U256 { + self.erc4626.max_deposit(receiver) + } + + fn max_mint(&self, receiver: Address) -> U256 { + self.erc4626.max_mint(receiver) + } + + fn max_redeem(&self, owner: Address) -> U256 { + self.erc4626.max_redeem(owner, &self.erc20) + } + } + unsafe impl TopLevelStorage for Erc4626TestExample {} + #[motsu::test] - fn asset_works(contract: Erc4626TestExample) { + fn asset_works(contract: Contract, alice: Address) { let asset = address!("DeaDbeefdEAdbeefdEadbEEFdeadbeEFdEaDbeeF"); - contract.erc4626.asset.set(asset); - assert_eq!(contract.erc4626.asset(), asset); + contract.init(alice, |contract| contract.erc4626.asset.set(asset)); + assert_eq!(contract.sender(alice).erc4626.asset(), asset); } #[motsu::test] - fn max_deposit(contract: Erc4626TestExample) { - let bob = address!("B0B0cB49ec2e96DF5F5fFB081acaE66A2cBBc2e2"); - let max_deposit = contract.erc4626.max_deposit(bob); + fn max_deposit(contract: Contract, alice: Address) { + let max_deposit = contract.sender(alice).max_deposit(alice); assert_eq!(max_deposit, U256::MAX); } - #[motsu::test] - fn max_mint(contract: Erc4626TestExample) { - let bob = address!("B0B0cB49ec2e96DF5F5fFB081acaE66A2cBBc2e2"); - let max_mint = contract.erc4626.max_mint(bob); + fn max_mint(contract: Contract, alice: Address) { + let max_mint = contract.sender(alice).max_mint(alice); assert_eq!(max_mint, U256::MAX); } #[motsu::test] - fn max_redeem_works(contract: Erc4626TestExample) { + fn max_redeem_works( + contract: Contract, + alice: Address, + ) { let assets = U256::from(1000); - let alice = msg::sender(); - contract.erc20._mint(alice, assets).expect("should mint assets"); - let max_redeem = contract.erc4626.max_redeem(alice, &contract.erc20); + contract.init(alice, |contract| { + contract.erc20._mint(alice, assets).expect("should mint assets"); + }); + let max_redeem = contract.sender(alice).max_redeem(alice); assert_eq!(assets, max_redeem); } #[motsu::test] - fn decimals_offset(contract: Erc4626TestExample) { - let decimals_offset = contract.erc4626._decimals_offset(); + fn decimals_offset(contract: Contract, alice: Address) { + let decimals_offset = contract.sender(alice).erc4626._decimals_offset(); assert_eq!(decimals_offset, U8::ZERO); let new_decimal_offset = U8::from(10); - contract.erc4626.decimals_offset.set(new_decimal_offset); + contract.sender(alice).erc4626.decimals_offset.set(new_decimal_offset); - let decimals_offset = contract.erc4626._decimals_offset(); + let decimals_offset = contract.sender(alice).erc4626._decimals_offset(); assert_eq!(decimals_offset, new_decimal_offset); } #[motsu::test] - fn decimals(contract: Erc4626TestExample) { + fn decimals(contract: Contract, alice: Address) { let underlying_decimals = U8::from(17); - contract.erc4626.underlying_decimals.set(underlying_decimals); - let decimals = contract.erc4626.decimals(); + contract.init(alice, |contract| { + contract.erc4626.underlying_decimals.set(underlying_decimals); + }); + let decimals = contract.sender(alice).erc4626.decimals(); assert_eq!(decimals, underlying_decimals); let new_decimal_offset = U8::from(10); - contract.erc4626.decimals_offset.set(new_decimal_offset); + contract.sender(alice).erc4626.decimals_offset.set(new_decimal_offset); - let decimals = contract.erc4626.decimals(); + let decimals = contract.sender(alice).erc4626.decimals(); assert_eq!(decimals, underlying_decimals + new_decimal_offset); } - */ } From a3c93f0a082fdd69e03978768591bc4e1f70dc37 Mon Sep 17 00:00:00 2001 From: Daniel Bigos Date: Wed, 5 Feb 2025 18:02:48 +0100 Subject: [PATCH 102/109] test: migrate Checkpoints unit tests --- .../src/utils/structs/checkpoints/mod.rs | 268 +++++++++++++----- 1 file changed, 201 insertions(+), 67 deletions(-) diff --git a/contracts/src/utils/structs/checkpoints/mod.rs b/contracts/src/utils/structs/checkpoints/mod.rs index 89cc98352..7001cd447 100644 --- a/contracts/src/utils/structs/checkpoints/mod.rs +++ b/contracts/src/utils/structs/checkpoints/mod.rs @@ -373,17 +373,29 @@ impl Trace { new_checkpoint._value.set(value); } } -/* + #[cfg(all(test, feature = "std"))] mod tests { - use alloy_primitives::uint; + use alloy_primitives::{uint, Address}; + use stylus_sdk::prelude::*; use crate::utils::structs::checkpoints::{ generic_size::S160, CheckpointUnorderedInsertion, Error, Trace, }; + unsafe impl TopLevelStorage for Trace {} + + #[public] + impl Trace { + fn dummy(&self) -> u8 { + 0 + } + } + + use motsu::prelude::Contract; + #[motsu::test] - fn push(checkpoint: Trace) { + fn push(checkpoint: Contract>, alice: Address) { let first_key = uint!(1_U96); let first_value = uint!(11_U160); @@ -393,19 +405,37 @@ mod tests { let third_key = uint!(3_U96); let third_value = uint!(33_U160); - checkpoint.push(first_key, first_value).expect("push first"); - checkpoint.push(second_key, second_value).expect("push second"); - checkpoint.push(third_key, third_value).expect("push third"); + checkpoint + .sender(alice) + .push(first_key, first_value) + .expect("push first"); + checkpoint + .sender(alice) + .push(second_key, second_value) + .expect("push second"); + checkpoint + .sender(alice) + .push(third_key, third_value) + .expect("push third"); + + assert_eq!(checkpoint.sender(alice).length(), uint!(3_U256)); - assert_eq!(checkpoint.length(), uint!(3_U256)); - - assert_eq!(checkpoint.at(uint!(0_U32)), (first_key, first_value)); - assert_eq!(checkpoint.at(uint!(1_U32)), (second_key, second_value)); - assert_eq!(checkpoint.at(uint!(2_U32)), (third_key, third_value)); + assert_eq!( + checkpoint.sender(alice).at(uint!(0_U32)), + (first_key, first_value) + ); + assert_eq!( + checkpoint.sender(alice).at(uint!(1_U32)), + (second_key, second_value) + ); + assert_eq!( + checkpoint.sender(alice).at(uint!(2_U32)), + (third_key, third_value) + ); } #[motsu::test] - fn push_same_value(checkpoint: Trace) { + fn push_same_value(checkpoint: Contract>, alice: Address) { let first_key = uint!(1_U96); let first_value = uint!(11_U160); @@ -415,114 +445,219 @@ mod tests { let third_key = uint!(2_U96); let third_value = uint!(222_U160); - checkpoint.push(first_key, first_value).expect("push first"); - checkpoint.push(second_key, second_value).expect("push second"); - checkpoint.push(third_key, third_value).expect("push third"); + checkpoint + .sender(alice) + .push(first_key, first_value) + .expect("push first"); + checkpoint + .sender(alice) + .push(second_key, second_value) + .expect("push second"); + checkpoint + .sender(alice) + .push(third_key, third_value) + .expect("push third"); assert_eq!( - checkpoint.length(), + checkpoint.sender(alice).length(), uint!(2_U256), "two checkpoints should be stored since third_value overrides second_value" ); - assert_eq!(checkpoint.at(uint!(0_U32)), (first_key, first_value)); - assert_eq!(checkpoint.at(uint!(1_U32)), (third_key, third_value)); + assert_eq!( + checkpoint.sender(alice).at(uint!(0_U32)), + (first_key, first_value) + ); + assert_eq!( + checkpoint.sender(alice).at(uint!(1_U32)), + (third_key, third_value) + ); } - #[motsu::test] - fn lower_lookup(checkpoint: Trace) { - checkpoint.push(uint!(1_U96), uint!(11_U160)).expect("push first"); - checkpoint.push(uint!(3_U96), uint!(33_U160)).expect("push second"); - checkpoint.push(uint!(5_U96), uint!(55_U160)).expect("push third"); - - assert_eq!(checkpoint.lower_lookup(uint!(2_U96)), uint!(33_U160)); - assert_eq!(checkpoint.lower_lookup(uint!(3_U96)), uint!(33_U160)); - assert_eq!(checkpoint.lower_lookup(uint!(4_U96)), uint!(55_U160)); - assert_eq!(checkpoint.lower_lookup(uint!(6_U96)), uint!(0_U160)); + fn lower_lookup(checkpoint: Contract>, alice: Address) { + checkpoint + .sender(alice) + .push(uint!(1_U96), uint!(11_U160)) + .expect("push first"); + checkpoint + .sender(alice) + .push(uint!(3_U96), uint!(33_U160)) + .expect("push second"); + checkpoint + .sender(alice) + .push(uint!(5_U96), uint!(55_U160)) + .expect("push third"); + + assert_eq!( + checkpoint.sender(alice).lower_lookup(uint!(2_U96)), + uint!(33_U160) + ); + assert_eq!( + checkpoint.sender(alice).lower_lookup(uint!(3_U96)), + uint!(33_U160) + ); + assert_eq!( + checkpoint.sender(alice).lower_lookup(uint!(4_U96)), + uint!(55_U160) + ); + assert_eq!( + checkpoint.sender(alice).lower_lookup(uint!(6_U96)), + uint!(0_U160) + ); } #[motsu::test] - fn upper_lookup(checkpoint: Trace) { - checkpoint.push(uint!(1_U96), uint!(11_U160)).expect("push first"); - checkpoint.push(uint!(3_U96), uint!(33_U160)).expect("push second"); - checkpoint.push(uint!(5_U96), uint!(55_U160)).expect("push third"); - - assert_eq!(checkpoint.upper_lookup(uint!(2_U96)), uint!(11_U160)); - assert_eq!(checkpoint.upper_lookup(uint!(1_U96)), uint!(11_U160)); - assert_eq!(checkpoint.upper_lookup(uint!(4_U96)), uint!(33_U160)); - assert_eq!(checkpoint.upper_lookup(uint!(0_U96)), uint!(0_U160)); + fn upper_lookup(checkpoint: Contract>, alice: Address) { + checkpoint + .sender(alice) + .push(uint!(1_U96), uint!(11_U160)) + .expect("push first"); + checkpoint + .sender(alice) + .push(uint!(3_U96), uint!(33_U160)) + .expect("push second"); + checkpoint + .sender(alice) + .push(uint!(5_U96), uint!(55_U160)) + .expect("push third"); + + assert_eq!( + checkpoint.sender(alice).upper_lookup(uint!(2_U96)), + uint!(11_U160) + ); + assert_eq!( + checkpoint.sender(alice).upper_lookup(uint!(1_U96)), + uint!(11_U160) + ); + assert_eq!( + checkpoint.sender(alice).upper_lookup(uint!(4_U96)), + uint!(33_U160) + ); + assert_eq!( + checkpoint.sender(alice).upper_lookup(uint!(0_U96)), + uint!(0_U160) + ); } #[motsu::test] - fn upper_lookup_recent(checkpoint: Trace) { + fn upper_lookup_recent(checkpoint: Contract>, alice: Address) { // `upper_lookup_recent` has different optimizations for "short" (<=5) // and "long" (>5) checkpoint arrays. // // Validate the first approach for a short checkpoint array. - checkpoint.push(uint!(1_U96), uint!(11_U160)).expect("push first"); - checkpoint.push(uint!(3_U96), uint!(33_U160)).expect("push second"); - checkpoint.push(uint!(5_U96), uint!(55_U160)).expect("push third"); + checkpoint + .sender(alice) + .push(uint!(1_U96), uint!(11_U160)) + .expect("push first"); + checkpoint + .sender(alice) + .push(uint!(3_U96), uint!(33_U160)) + .expect("push second"); + checkpoint + .sender(alice) + .push(uint!(5_U96), uint!(55_U160)) + .expect("push third"); assert_eq!( - checkpoint.upper_lookup_recent(uint!(2_U96)), + checkpoint.sender(alice).upper_lookup_recent(uint!(2_U96)), uint!(11_U160) ); assert_eq!( - checkpoint.upper_lookup_recent(uint!(1_U96)), + checkpoint.sender(alice).upper_lookup_recent(uint!(1_U96)), uint!(11_U160) ); assert_eq!( - checkpoint.upper_lookup_recent(uint!(4_U96)), + checkpoint.sender(alice).upper_lookup_recent(uint!(4_U96)), uint!(33_U160) ); // Validate the second approach for a long checkpoint array. - checkpoint.push(uint!(7_U96), uint!(77_U160)).expect("push fourth"); - checkpoint.push(uint!(9_U96), uint!(99_U160)).expect("push fifth"); - checkpoint.push(uint!(11_U96), uint!(111_U160)).expect("push sixth"); + checkpoint + .sender(alice) + .push(uint!(7_U96), uint!(77_U160)) + .expect("push fourth"); + checkpoint + .sender(alice) + .push(uint!(9_U96), uint!(99_U160)) + .expect("push fifth"); + checkpoint + .sender(alice) + .push(uint!(11_U96), uint!(111_U160)) + .expect("push sixth"); assert_eq!( - checkpoint.upper_lookup_recent(uint!(7_U96)), + checkpoint.sender(alice).upper_lookup_recent(uint!(7_U96)), uint!(77_U160) ); assert_eq!( - checkpoint.upper_lookup_recent(uint!(9_U96)), + checkpoint.sender(alice).upper_lookup_recent(uint!(9_U96)), uint!(99_U160) ); assert_eq!( - checkpoint.upper_lookup_recent(uint!(11_U96)), + checkpoint.sender(alice).upper_lookup_recent(uint!(11_U96)), uint!(111_U160) ); - assert_eq!(checkpoint.upper_lookup_recent(uint!(0_U96)), uint!(0_U160)); + assert_eq!( + checkpoint.sender(alice).upper_lookup_recent(uint!(0_U96)), + uint!(0_U160) + ); } #[motsu::test] - fn latest(checkpoint: Trace) { - assert_eq!(checkpoint.latest(), uint!(0_U160)); - checkpoint.push(uint!(1_U96), uint!(11_U160)).expect("push first"); - checkpoint.push(uint!(3_U96), uint!(33_U160)).expect("push second"); - checkpoint.push(uint!(5_U96), uint!(55_U160)).expect("push third"); - assert_eq!(checkpoint.latest(), uint!(55_U160)); + fn latest(checkpoint: Contract>, alice: Address) { + assert_eq!(checkpoint.sender(alice).latest(), uint!(0_U160)); + checkpoint + .sender(alice) + .push(uint!(1_U96), uint!(11_U160)) + .expect("push first"); + checkpoint + .sender(alice) + .push(uint!(3_U96), uint!(33_U160)) + .expect("push second"); + checkpoint + .sender(alice) + .push(uint!(5_U96), uint!(55_U160)) + .expect("push third"); + assert_eq!(checkpoint.sender(alice).latest(), uint!(55_U160)); } #[motsu::test] - fn latest_checkpoint(checkpoint: Trace) { - assert_eq!(checkpoint.latest_checkpoint(), None); - checkpoint.push(uint!(1_U96), uint!(11_U160)).expect("push first"); - checkpoint.push(uint!(3_U96), uint!(33_U160)).expect("push second"); - checkpoint.push(uint!(5_U96), uint!(55_U160)).expect("push third"); + fn latest_checkpoint(checkpoint: Contract>, alice: Address) { + assert_eq!(checkpoint.sender(alice).latest_checkpoint(), None); + checkpoint + .sender(alice) + .push(uint!(1_U96), uint!(11_U160)) + .expect("push first"); + checkpoint + .sender(alice) + .push(uint!(3_U96), uint!(33_U160)) + .expect("push second"); + checkpoint + .sender(alice) + .push(uint!(5_U96), uint!(55_U160)) + .expect("push third"); assert_eq!( - checkpoint.latest_checkpoint(), + checkpoint.sender(alice).latest_checkpoint(), Some((uint!(5_U96), uint!(55_U160))) ); } #[motsu::test] - fn error_when_unordered_insertion(checkpoint: Trace) { - checkpoint.push(uint!(1_U96), uint!(11_U160)).expect("push first"); - checkpoint.push(uint!(3_U96), uint!(33_U160)).expect("push second"); + fn error_when_unordered_insertion( + checkpoint: Contract>, + alice: Address, + ) { + checkpoint + .sender(alice) + .push(uint!(1_U96), uint!(11_U160)) + .expect("push first"); + checkpoint + .sender(alice) + .push(uint!(3_U96), uint!(33_U160)) + .expect("push second"); let err = checkpoint + .sender(alice) .push(uint!(2_U96), uint!(22_U160)) .expect_err("should not push value lower then last one"); assert!(matches!( @@ -533,4 +668,3 @@ mod tests { )); } } -*/ From b60e0a8838a5afdf76ef4d9a83cebd0d99d7c969 Mon Sep 17 00:00:00 2001 From: Daniel Bigos Date: Wed, 5 Feb 2025 18:20:41 +0100 Subject: [PATCH 103/109] test: migrate Erc1155UriStorage unit tests --- .../token/erc1155/extensions/uri_storage.rs | 135 +++++++++--------- 1 file changed, 70 insertions(+), 65 deletions(-) diff --git a/contracts/src/token/erc1155/extensions/uri_storage.rs b/contracts/src/token/erc1155/extensions/uri_storage.rs index d325c2a7e..315fda4a6 100644 --- a/contracts/src/token/erc1155/extensions/uri_storage.rs +++ b/contracts/src/token/erc1155/extensions/uri_storage.rs @@ -42,7 +42,7 @@ impl Erc1155UriStorage { /// # Examples /// /// ```rust,ignore - /// pub fn uri(&self, token_id: U256) -> String { + /// fn uri(&self, token_id: U256) -> String { /// self.uri_storage.uri(token_id, &self.metadata_uri) /// } /// ``` @@ -96,12 +96,9 @@ impl Erc1155UriStorage { #[cfg(all(test, feature = "std"))] mod tests { - // TODO#q: rewrite Erc1155UriStorage tests - /*use motsu::prelude::Contract; - use stylus_sdk::{ - alloy_primitives::{uint, U256}, - prelude::{public, storage, TopLevelStorage}, - }; + use alloy_primitives::{uint, Address, U256}; + use motsu::prelude::Contract; + use stylus_sdk::prelude::*; use super::Erc1155UriStorage; use crate::token::erc1155::extensions::Erc1155MetadataUri; @@ -114,8 +111,11 @@ mod tests { } #[public] - #[inherit(Erc1155MetadataUri)] - impl Erc1155MetadataExample {} + impl Erc1155MetadataExample { + fn uri(&self, token_id: U256) -> String { + self.uri_storage.uri(token_id, &self.metadata_uri) + } + } unsafe impl TopLevelStorage for Erc1155MetadataExample {} @@ -124,111 +124,116 @@ mod tests { #[motsu::test] fn uri_returns_metadata_uri_when_token_uri_is_not_set( contract: Contract, + alice: Address, ) { let uri = "https://some.metadata/token/uri"; - contract.metadata_uri._uri.set_str(uri.to_owned()); + contract.init(alice, |contract| { + contract.metadata_uri._uri.set_str(uri.to_owned()); + }); - assert_eq!( - uri, - contract.uri_storage.uri(TOKEN_ID, &contract.metadata_uri) - ); + assert_eq!(uri, contract.sender(alice).uri(TOKEN_ID)); } - #[motsu::test] fn uri_returns_empty_string_when_no_uri_is_set( contract: Contract, + alice: Address, ) { - assert!(contract - .uri_storage - .uri(TOKEN_ID, &contract.metadata_uri) - .is_empty()); + assert!(contract.sender(alice).uri(TOKEN_ID).is_empty()); } #[motsu::test] fn uri_returns_token_uri_when_base_uri_is_empty( contract: Contract, + alice: Address, ) { let token_uri = "https://some.short/token/uri"; - contract - .uri_storage - ._token_uris - .setter(TOKEN_ID) - .set_str(token_uri.to_owned()); + contract.init(alice, |contract| { + contract + .uri_storage + ._token_uris + .setter(TOKEN_ID) + .set_str(token_uri.to_owned()); + }); - assert_eq!( - token_uri, - contract.uri_storage.uri(TOKEN_ID, &contract.metadata_uri) - ); + assert_eq!(token_uri, contract.sender(alice).uri(TOKEN_ID)); } #[motsu::test] fn uri_returns_concatenated_base_uri_and_token_uri( contract: Contract, + alice: Address, ) { let base_uri = "https://some.base.uri"; let token_uri = "/some/token/uri"; - contract.uri_storage._base_uri.set_str(base_uri.to_owned()); - contract - .uri_storage - ._token_uris - .setter(TOKEN_ID) - .set_str(token_uri.to_owned()); + contract.init(alice, |contract| { + contract.uri_storage._base_uri.set_str(base_uri.to_owned()); + contract + .uri_storage + ._token_uris + .setter(TOKEN_ID) + .set_str(token_uri.to_owned()); + }); assert_eq!( base_uri.to_string() + token_uri, - contract.uri_storage.uri(TOKEN_ID, &contract.metadata_uri) + contract.sender(alice).uri(TOKEN_ID) ); } #[motsu::test] fn uri_ignores_metadata_uri_when_token_uri_is_set( contract: Contract, + alice: Address, ) { let uri = "https://some.metadata/token/uri"; let token_uri = "https://some.short/token/uri"; - contract.metadata_uri._uri.set_str(uri.to_owned()); - contract - .uri_storage - ._token_uris - .setter(TOKEN_ID) - .set_str(token_uri.to_owned()); + contract.init(alice, |contract| { + contract.metadata_uri._uri.set_str(uri.to_owned()); + contract + .uri_storage + ._token_uris + .setter(TOKEN_ID) + .set_str(token_uri.to_owned()); + }); - assert_eq!( - token_uri, - contract.uri_storage.uri(TOKEN_ID, &contract.metadata_uri) - ); + assert_eq!(token_uri, contract.sender(alice).uri(TOKEN_ID)); } - #[motsu::test] - fn test_set_uri(contract: Contract) { + fn test_set_uri( + contract: Contract, + alice: Address, + ) { let uri = "https://some.metadata/token/uri"; let token_uri = "https://some.short/token/uri".to_string(); - contract.metadata_uri._uri.set_str(uri.to_owned()); + contract.init(alice, |contract| { + contract.metadata_uri._uri.set_str(uri.to_owned()); + contract.uri_storage.set_token_uri( + TOKEN_ID, + token_uri.clone(), + &contract.metadata_uri, + ); + }); - contract.uri_storage.set_token_uri( - TOKEN_ID, - token_uri.clone(), - &contract.metadata_uri, - ); - - assert_eq!( - token_uri, - contract.uri_storage.uri(TOKEN_ID, &contract.metadata_uri) - ); + assert_eq!(token_uri, contract.sender(alice).uri(TOKEN_ID)); } - - unsafe impl TopLevelStorage for Erc1155UriStorage {} - #[motsu::test] - fn test_set_base_uri(contract: Contract) { + fn test_set_base_uri( + contract: Contract, + alice: Address, + ) { let base_uri = "https://docs.openzeppelin.com/".to_string(); - contract.set_base_uri(base_uri.clone()); + contract.init(alice, |contract| { + contract.uri_storage.set_base_uri(base_uri.clone()); + }); - assert_eq!(base_uri, contract._base_uri.get_string()); - }*/ + assert_eq!( + base_uri, + contract.sender(alice).uri_storage._base_uri.get_string() + ); + } } From ee7dff625dd721b6a67d6b3278642e03bcfc0064 Mon Sep 17 00:00:00 2001 From: Daniel Bigos Date: Wed, 5 Feb 2025 19:23:49 +0100 Subject: [PATCH 104/109] test: fix Erc20FlashMint unit tests Refers #470 --- .../src/token/erc20/extensions/flash_mint.rs | 231 ++++++++++++------ 1 file changed, 160 insertions(+), 71 deletions(-) diff --git a/contracts/src/token/erc20/extensions/flash_mint.rs b/contracts/src/token/erc20/extensions/flash_mint.rs index f7535c78d..466b93ab6 100644 --- a/contracts/src/token/erc20/extensions/flash_mint.rs +++ b/contracts/src/token/erc20/extensions/flash_mint.rs @@ -335,107 +335,196 @@ impl IErc3156FlashLender for Erc20FlashMint { } } -// TODO#q: migrate flash mint tests -/* -// TODO: unignore all tests once it's possible to mock contract address. -// NOTE: double check that the tests assert the correct and expected things. #[cfg(all(test, feature = "std"))] mod tests { use alloy_primitives::{address, uint, Address, U256}; - use stylus_sdk::msg; + use motsu::prelude::{Account, Contract}; + use stylus_sdk::{abi::Bytes, msg, prelude::*}; + + use super::{ + ERC3156ExceededMaxLoan, ERC3156InvalidReceiver, + ERC3156UnsupportedToken, Erc20, Erc20FlashMint, Error, + IErc3156FlashLender, + }; + + #[storage] + struct Erc20FlashMintTestExample { + erc20_flash_mint: Erc20FlashMint, + erc20: Erc20, + } + + #[public] + impl Erc20FlashMintTestExample { + fn max_flash_loan(&self, token: Address) -> U256 { + self.erc20_flash_mint.max_flash_loan(token, &self.erc20) + } - use super::{Erc20, Erc20FlashMint, Error, IErc3156FlashLender}; + fn flash_fee( + &self, + token: Address, + value: U256, + ) -> Result { + self.erc20_flash_mint.flash_fee(token, value) + } + + fn flash_loan( + &mut self, + receiver: Address, + token: Address, + value: U256, + data: Bytes, + ) -> Result { + self.erc20_flash_mint.flash_loan( + receiver, + token, + value, + data, + &mut self.erc20, + ) + } + } - const ALICE: Address = address!("A11CEacF9aa32246d767FCCD72e02d6bCbcC375d"); - const TOKEN_ADDRESS: Address = - address!("dce82b5f92c98f27f116f70491a487effdb6a2a9"); - const INVALID_TOKEN_ADDRESS: Address = - address!("dce82b5f92c98f27f116f70491a487effdb6a2aa"); + unsafe impl TopLevelStorage for Erc20FlashMintTestExample {} #[motsu::test] - #[ignore] - fn max_flash_loan_token_match(contract: Erc20FlashMint) { - let erc20 = Erc20::default(); - let max_flash_loan = contract.max_flash_loan(TOKEN_ADDRESS, &erc20); + fn max_flash_loan_token_match( + contract: Contract, + alice: Address, + ) { + let max_flash_loan = + contract.sender(alice).max_flash_loan(contract.address()); assert_eq!(max_flash_loan, U256::MAX); } #[motsu::test] - #[ignore] - fn max_flash_loan_token_mismatch(contract: Erc20FlashMint) { - let erc20 = Erc20::default(); - let max_flash_loan = - contract.max_flash_loan(INVALID_TOKEN_ADDRESS, &erc20); + fn max_flash_loan_token_mismatch( + contract: Contract, + alice: Address, + ) { + let max_flash_loan = contract.sender(alice).max_flash_loan(alice); assert_eq!(max_flash_loan, U256::MIN); } #[motsu::test] - #[ignore] - fn max_flash_loan_when_token_minted(contract: Erc20FlashMint) { - let mut erc20 = Erc20::default(); - erc20._mint(msg::sender(), uint!(10000_U256)).unwrap(); - let max_flash_loan = contract.max_flash_loan(TOKEN_ADDRESS, &erc20); - assert_eq!(max_flash_loan, U256::MAX - uint!(10000_U256)); + fn max_flash_loan_when_token_minted( + contract: Contract, + alice: Address, + ) { + let initial_supply = uint!(10000_U256); + + contract.init(alice, |contract| { + _ = contract.erc20._mint(alice, initial_supply).unwrap(); + }); + + let max_flash_loan = + contract.sender(alice).max_flash_loan(contract.address()); + + assert_eq!(max_flash_loan, U256::MAX - initial_supply); } #[motsu::test] - #[ignore] - fn flash_fee(contract: Erc20FlashMint) { - let flash_fee = - contract.flash_fee(TOKEN_ADDRESS, uint!(1000_U256)).unwrap(); - assert_eq!(flash_fee, U256::MIN); + fn flash_fee( + contract: Contract, + alice: Address, + ) { + let flash_fee_value = uint!(69_U256); + contract.init(alice, |contract| { + contract.erc20_flash_mint.flash_fee_value.set(flash_fee_value); + }); + + let flash_fee = contract + .sender(alice) + .flash_fee(contract.address(), uint!(1000_U256)) + .expect("should return flash fee value"); + + assert_eq!(flash_fee, flash_fee_value); } #[motsu::test] - #[ignore] - fn error_flash_fee_when_invalid_token(contract: Erc20FlashMint) { - let result = - contract.flash_fee(INVALID_TOKEN_ADDRESS, uint!(1000_U256)); - assert!(matches!(result, Err(Error::UnsupportedToken(_)))); + fn flash_fee_reverts_when_invalid_token( + contract: Contract, + alice: Address, + ) { + let invalid_token = alice; + + let err = contract + .sender(alice) + .flash_fee(invalid_token, uint!(1000_U256)) + .expect_err("should return Error::UnsupportedToken"); + + assert!(matches!( + err, + Error::UnsupportedToken(ERC3156UnsupportedToken { token }) + if token == invalid_token + )); } #[motsu::test] - #[ignore] - fn error_flash_loan_when_exceeded_max_loan(contract: Erc20FlashMint) { - let mut erc20 = Erc20::default(); - let _ = erc20._mint(msg::sender(), uint!(10000_U256)); - let result = contract.flash_loan( - msg::sender(), - TOKEN_ADDRESS, - U256::MAX, - vec![0, 1].into(), - &mut erc20, - ); - assert!(matches!(result, Err(Error::ExceededMaxLoan(_)))); + fn flash_loan_reverts_when_exceeded_max_loan( + contract: Contract, + alice: Address, + ) { + let initial_supply = uint!(10000_U256); + + contract.init(alice, |contract| { + _ = contract.erc20._mint(msg::sender(), initial_supply).unwrap(); + }); + + let err = contract + .sender(alice) + .flash_loan(alice, contract.address(), U256::MAX, vec![0, 1].into()) + .expect_err("should return Error::ExceededMaxLoan"); + + assert!(matches!( + err, + Error::ExceededMaxLoan(ERC3156ExceededMaxLoan { max_loan }) + if max_loan == U256::MAX - initial_supply + )); } #[motsu::test] - #[ignore] - fn error_flash_loan_when_zero_receiver_address(contract: Erc20FlashMint) { - let mut erc20 = Erc20::default(); + fn flash_loan_reverts_when_receiver_is_zero_address( + contract: Contract, + alice: Address, + ) { let invalid_reciver = Address::ZERO; - let result = contract.flash_loan( - invalid_reciver, - TOKEN_ADDRESS, - uint!(1000_U256), - vec![0, 1].into(), - &mut erc20, - ); - assert_eq!(result.is_err(), true); + let err = contract + .sender(alice) + .flash_loan( + invalid_reciver, + contract.address(), + uint!(1000_U256), + vec![0, 1].into(), + ) + .expect_err("should return Error::InvalidReceiver"); + + assert!(matches!( + err, + Error::InvalidReceiver(ERC3156InvalidReceiver { receiver }) if receiver == invalid_reciver + )); } #[motsu::test] - #[ignore] - fn error_flash_loan_when_invalid_receiver(contract: Erc20FlashMint) { - let mut erc20 = Erc20::default(); - let result = contract.flash_loan( - ALICE, - TOKEN_ADDRESS, - uint!(1000_U256), - vec![0, 1].into(), - &mut erc20, - ); - assert_eq!(result.is_err(), true); + fn flash_loan_reverts_when_invalid_receiver( + contract: Contract, + alice: Address, + ) { + let invalid_receiver = alice; + + let err = contract + .sender(alice) + .flash_loan( + invalid_receiver, + contract.address(), + uint!(1000_U256), + vec![0, 1].into(), + ) + .expect_err("should return Error::InvalidReceiver"); + + assert!(matches!( + err, + Error::InvalidReceiver(ERC3156InvalidReceiver { receiver }) + if receiver == invalid_receiver + )); } } -*/ From 6f0b193ea172bf2a21134ee495f40068524719a1 Mon Sep 17 00:00:00 2001 From: Daniel Bigos Date: Thu, 6 Feb 2025 09:47:17 +0100 Subject: [PATCH 105/109] test: migrate Erc721Enumerable tests --- .../src/token/erc721/extensions/enumerable.rs | 325 ++++++++++++------ .../src/utils/structs/checkpoints/mod.rs | 6 +- 2 files changed, 215 insertions(+), 116 deletions(-) diff --git a/contracts/src/token/erc721/extensions/enumerable.rs b/contracts/src/token/erc721/extensions/enumerable.rs index cb30b9e31..bc0fa9473 100644 --- a/contracts/src/token/erc721/extensions/enumerable.rs +++ b/contracts/src/token/erc721/extensions/enumerable.rs @@ -339,64 +339,86 @@ mod tests { use motsu::prelude::Contract; use stylus_sdk::{ alloy_primitives::{uint, Address, U256}, - prelude::TopLevelStorage, + prelude::*, }; - use super::{Erc721Enumerable, Error, IErc721Enumerable}; - use crate::token::erc721::IErc721; + use super::{ + ERC721EnumerableForbiddenBatchMint, ERC721OutOfBoundsIndex, + Erc721Enumerable, Error, IErc721Enumerable, + }; + use crate::token::erc721::{Erc721, IErc721}; + + #[storage] + struct Erc721EnumerableTestExample { + pub erc721: Erc721, + pub enumerable: Erc721Enumerable, + } - unsafe impl TopLevelStorage for Erc721Enumerable {} + unsafe impl TopLevelStorage for Erc721EnumerableTestExample {} + + #[public] + impl Erc721EnumerableTestExample {} #[motsu::test] fn total_supply_no_tokens( - contract: Contract, + contract: Contract, alice: Address, ) { - assert_eq!(U256::ZERO, contract.sender(alice).total_supply()); + assert_eq!( + U256::ZERO, + contract.sender(alice).enumerable.total_supply() + ); } #[motsu::test] - fn error_when_token_by_index_is_out_of_bound( - contract: Contract, + fn reverts_when_token_by_index_is_out_of_bound( + contract: Contract, alice: Address, ) { - assert_eq!(U256::ZERO, contract.sender(alice).total_supply()); - let token_idx = uint!(2024_U256); - let err = contract.sender(alice).token_by_index(token_idx).unwrap_err(); - assert!(matches!(err, Error::OutOfBoundsIndex(_))); + let err = contract + .sender(alice) + .enumerable + .token_by_index(token_idx) + .expect_err("should return Error::OutOfBoundsIndex"); + + assert!(matches!( + err, + Error::OutOfBoundsIndex(ERC721OutOfBoundsIndex { + owner, + index + }) if owner.is_zero() && index == token_idx + )); } #[motsu::test] fn add_token_to_all_tokens_enumeration_works( - contract: Contract, + contract: Contract, alice: Address, ) { - assert_eq!(U256::ZERO, contract.sender(alice).total_supply()); - let tokens_len = 10; let mut tokens_ids = Vec::new(); for token_id in 0..tokens_len { let token_id = U256::from(token_id); - // Store ids for test. tokens_ids.push(token_id); - contract .sender(alice) + .enumerable ._add_token_to_all_tokens_enumeration(token_id); } assert_eq!( U256::from(tokens_len), - contract.sender(alice).total_supply() + contract.sender(alice).enumerable.total_supply() ); tokens_ids.iter().enumerate().for_each(|(idx, expected_token_id)| { let token_id = contract .sender(alice) + .enumerable .token_by_index(U256::from(idx)) .expect("should return token id for"); assert_eq!(*expected_token_id, token_id); @@ -404,45 +426,51 @@ mod tests { let err = contract .sender(alice) + .enumerable .token_by_index(U256::from(tokens_len)) - .unwrap_err(); - - assert!(matches!(err, Error::OutOfBoundsIndex(_))); + .expect_err("should return Error::OutOfBoundsIndex"); + + assert!(matches!( + err, + Error::OutOfBoundsIndex(ERC721OutOfBoundsIndex { + owner, + index + }) if owner.is_zero() && index == U256::from(tokens_len) + )); } #[motsu::test] fn remove_token_from_all_tokens_enumeration_works( - contract: Contract, + contract: Contract, alice: Address, ) { - assert_eq!(U256::ZERO, contract.sender(alice).total_supply()); - let initial_tokens_len = 10; let mut tokens_ids = Vec::new(); for token_id in 0..initial_tokens_len { let token_id = U256::from(token_id); - // Store ids for test. tokens_ids.push(token_id); contract .sender(alice) + .enumerable ._add_token_to_all_tokens_enumeration(token_id); } assert_eq!( U256::from(initial_tokens_len), - contract.sender(alice).total_supply() + contract.sender(alice).enumerable.total_supply() ); // Remove the last token. let last_token_id = tokens_ids.swap_remove(initial_tokens_len - 1); contract .sender(alice) + .enumerable ._remove_token_from_all_tokens_enumeration(last_token_id); assert_eq!( U256::from(initial_tokens_len - 1), - contract.sender(alice).total_supply() + contract.sender(alice).enumerable.total_supply() ); // Remove the second (`idx = 1`) element @@ -450,25 +478,30 @@ mod tests { let token_to_remove = tokens_ids.swap_remove(1); contract .sender(alice) + .enumerable ._remove_token_from_all_tokens_enumeration(token_to_remove); assert_eq!( U256::from(initial_tokens_len - 2), - contract.sender(alice).total_supply() + contract.sender(alice).enumerable.total_supply() ); // Add a new token. let token_id = U256::from(initial_tokens_len); tokens_ids.push(token_id); - contract.sender(alice)._add_token_to_all_tokens_enumeration(token_id); + contract + .sender(alice) + .enumerable + ._add_token_to_all_tokens_enumeration(token_id); assert_eq!( U256::from(initial_tokens_len - 1), - contract.sender(alice).total_supply() + contract.sender(alice).enumerable.total_supply() ); // Check proper indices of tokens. tokens_ids.iter().enumerate().for_each(|(idx, expected_token_id)| { let token_id = contract .sender(alice) + .enumerable .token_by_index(U256::from(idx)) .expect("should return token id"); assert_eq!(*expected_token_id, token_id); @@ -476,41 +509,64 @@ mod tests { let err = contract .sender(alice) + .enumerable .token_by_index(U256::from(initial_tokens_len - 1)) - .unwrap_err(); + .expect_err("should return Error::OutOfBoundsIndex"); - assert!(matches!(err, Error::OutOfBoundsIndex(_))); + assert!(matches!(err, Error::OutOfBoundsIndex(ERC721OutOfBoundsIndex { + owner, + index + }) if owner.is_zero() && index == U256::from(initial_tokens_len - 1) + )); } #[motsu::test] fn check_increase_balance() { assert!(Erc721Enumerable::_check_increase_balance(0).is_ok()); - let err = Erc721Enumerable::_check_increase_balance(1).unwrap_err(); - assert!(matches!(err, Error::EnumerableForbiddenBatchMint(_))); - } - // TODO#q: rewrite Erc721Enumerable and Erc721 integration tests - /*#[motsu::test] - fn token_of_owner_by_index_works(contract: Erc721Enumerable) { - let alice = msg::sender(); - let mut erc721 = Erc721::default(); - assert_eq!( - U256::ZERO, - erc721.balance_of(alice).expect("should return balance of ALICE") - ); + let err = Erc721Enumerable::_check_increase_balance(1) + .expect_err("should return Error::EnumerableForbiddenBatchMint"); + assert!(matches!( + err, + Error::EnumerableForbiddenBatchMint( + ERC721EnumerableForbiddenBatchMint {} + ) + )); + } + + #[motsu::test] + fn token_of_owner_by_index_works( + contract: Contract, + alice: Address, + ) { let token_id = uint!(1_U256); - erc721._mint(alice, token_id).expect("should mint a token for ALICE"); - let owner = erc721 + contract + .sender(alice) + .erc721 + ._mint(alice, token_id) + .expect("should mint a token for {{alice}}"); + + let owner = contract + .sender(alice) + .erc721 .owner_of(token_id) .expect("should return the owner of the token"); assert_eq!(owner, alice); - let res = - contract._add_token_to_owner_enumeration(alice, token_id, &erc721); - assert!(res.is_ok()); + contract + .sender(alice) + .enumerable + ._add_token_to_owner_enumeration( + alice, + token_id, + &contract.sender(alice).erc721, + ) + .expect("should add token to owner enumeration"); let test_token_id = contract + .sender(alice) + .enumerable .token_of_owner_by_index(alice, U256::ZERO) .expect("should return `token_id`"); @@ -518,96 +574,143 @@ mod tests { } #[motsu::test] - fn error_when_token_of_owner_for_index_out_of_bound( - contract: Erc721Enumerable, + fn reverts_when_token_of_owner_for_index_out_of_bound( + contract: Contract, + alice: Address, ) { - let alice = msg::sender(); - let mut erc721 = Erc721::default(); - assert_eq!( - U256::ZERO, - erc721.balance_of(alice).expect("should return balance of ALICE") - ); - let token_id = uint!(1_U256); - erc721._mint(alice, token_id).expect("should mint a token for ALICE"); - let owner = erc721 + contract + .sender(alice) + .erc721 + ._mint(alice, token_id) + .expect("should mint a token for {{alice}}"); + + let owner = contract + .sender(alice) + .erc721 .owner_of(token_id) .expect("should return the owner of the token"); + assert_eq!(owner, alice); - let res = - contract._add_token_to_owner_enumeration(alice, token_id, &erc721); - assert!(res.is_ok()); + contract + .sender(alice) + .enumerable + ._add_token_to_owner_enumeration( + alice, + token_id, + &contract.sender(alice).erc721, + ) + .expect("should add token to owner enumeration"); + + let token_idx = uint!(1_U256); - let err = - contract.token_of_owner_by_index(alice, uint!(1_U256)).unwrap_err(); - assert!(matches!(err, Error::OutOfBoundsIndex(_))); + let err = contract + .sender(alice) + .enumerable + .token_of_owner_by_index(alice, token_idx) + .expect_err("should return Error::OutOfBoundsIndex"); + + assert!(matches!(err, Error::OutOfBoundsIndex(ERC721OutOfBoundsIndex { + owner, + index + }) if owner == alice && index == token_idx + )); } #[motsu::test] - fn error_when_token_of_owner_does_not_own_any_token( - contract: Erc721Enumerable, + fn reverts_when_token_of_owner_does_not_own_any_token( + contract: Contract, + alice: Address, ) { - let erc721 = Erc721::default(); - assert_eq!( - U256::ZERO, - erc721.balance_of(BOB).expect("should return balance of BOB") - ); + let token_idx = U256::ZERO; - let err = - contract.token_of_owner_by_index(BOB, U256::ZERO).unwrap_err(); - assert!(matches!(err, Error::OutOfBoundsIndex(_))); + let err = contract + .sender(alice) + .enumerable + .token_of_owner_by_index(alice, token_idx) + .expect_err("should return Error::OutOfBoundsIndex"); + + assert!(matches!(err, Error::OutOfBoundsIndex(ERC721OutOfBoundsIndex { + owner, + index + }) if owner == alice && index == token_idx + )); } #[motsu::test] fn token_of_owner_by_index_after_transfer_works( - contract: Erc721Enumerable, + contract: Contract, + alice: Address, + bob: Address, ) { - let alice = msg::sender(); - let mut erc721 = Erc721::default(); - assert_eq!( - U256::ZERO, - erc721.balance_of(alice).expect("should return balance of ALICE") - ); - let token_id = uint!(1_U256); - erc721._mint(alice, token_id).expect("should mint a token for ALICE"); - let owner = erc721 - .owner_of(token_id) - .expect("should return the owner of the token"); - assert_eq!(owner, alice); + contract + .sender(alice) + .erc721 + ._mint(alice, token_id) + .expect("should mint a token for {{alice}}"); - let res = - contract._add_token_to_owner_enumeration(alice, token_id, &erc721); - assert!(res.is_ok()); + contract + .sender(alice) + .enumerable + ._add_token_to_owner_enumeration( + alice, + token_id, + &contract.sender(alice).erc721, + ) + .expect("should add token to owner enumeration"); + + // Transfer the token from alice to bob. + contract + .sender(alice) + .erc721 + .transfer_from(alice, bob, token_id) + .expect("should transfer the token from {{alice}} to {{bob}}"); - // Transfer the token from ALICE to BOB. - erc721 - .transfer_from(alice, BOB, token_id) - .expect("should transfer the token from ALICE to BOB"); - let owner = erc721 - .owner_of(token_id) - .expect("should return the owner of the token"); - assert_eq!(owner, BOB); + // Remove the token from alice's enumeration. + contract + .sender(alice) + .enumerable + ._remove_token_from_owner_enumeration( + alice, + token_id, + &contract.sender(alice).erc721, + ) + .expect("should remove token from {{alice}} enumeration"); - let res = contract - ._remove_token_from_owner_enumeration(alice, token_id, &erc721); - assert!(res.is_ok()); + contract + .sender(bob) + .enumerable + ._add_token_to_owner_enumeration( + bob, + token_id, + &contract.sender(bob).erc721, + ) + .expect("should add token to {{bob}} enumeration"); - let res = - contract._add_token_to_owner_enumeration(BOB, token_id, &erc721); - assert!(res.is_ok()); + let token_idx = U256::ZERO; let test_token_id = contract - .token_of_owner_by_index(BOB, U256::ZERO) + .sender(bob) + .enumerable + .token_of_owner_by_index(bob, token_idx) .expect("should return `token_id`"); assert_eq!(token_id, test_token_id); - let err = - contract.token_of_owner_by_index(alice, U256::ZERO).unwrap_err(); - assert!(matches!(err, Error::OutOfBoundsIndex(_))); - }*/ + let err = contract + .sender(alice) + .enumerable + .token_of_owner_by_index(alice, token_idx) + .expect_err("should return Error::OutOfBoundsIndex"); + + assert!(matches!(err, Error::OutOfBoundsIndex(ERC721OutOfBoundsIndex { + owner, + index + }) if owner == alice && index == token_idx + )); + } #[motsu::test] fn interface_id() { diff --git a/contracts/src/utils/structs/checkpoints/mod.rs b/contracts/src/utils/structs/checkpoints/mod.rs index 7001cd447..0e7b67716 100644 --- a/contracts/src/utils/structs/checkpoints/mod.rs +++ b/contracts/src/utils/structs/checkpoints/mod.rs @@ -386,11 +386,7 @@ mod tests { unsafe impl TopLevelStorage for Trace {} #[public] - impl Trace { - fn dummy(&self) -> u8 { - 0 - } - } + impl Trace {} use motsu::prelude::Contract; From 62499ded24914939b271eb17f267dd627708fe2e Mon Sep 17 00:00:00 2001 From: Daniel Bigos Date: Thu, 6 Feb 2025 10:22:03 +0100 Subject: [PATCH 106/109] ref: unpack Result from watch! macro --- benches/src/erc721.rs | 6 +- benches/src/lib.rs | 2 +- benches/src/vesting_wallet.rs | 4 +- contracts/src/access/ownable.rs | 2 +- .../src/token/erc1155/extensions/supply.rs | 5 +- .../token/erc1155/extensions/uri_storage.rs | 1 + .../src/token/erc20/extensions/erc4626.rs | 2 +- .../src/token/erc20/extensions/flash_mint.rs | 4 +- contracts/src/token/erc721/mod.rs | 6 +- contracts/src/utils/math/alloy.rs | 4 +- .../access-control/tests/access_control.rs | 18 +- .../tests/erc1155-metadata-uri.rs | 4 +- .../erc1155-supply/tests/erc1155-supply.rs | 62 +++---- examples/erc1155/tests/erc1155.rs | 155 +++++++++--------- .../tests/erc20-flash-mint.rs | 20 +-- examples/erc20-permit/tests/erc20permit.rs | 30 ++-- examples/erc20/tests/erc20.rs | 66 ++++---- .../tests/erc721-consecutive.rs | 10 +- examples/erc721-metadata/tests/erc721.rs | 10 +- examples/erc721/tests/erc721.rs | 144 ++++++++-------- examples/safe-erc20/tests/erc20.rs | 48 +++--- .../tests/erc20_that_does_not_return.rs | 48 +++--- .../tests/usdt_approval_behavior.rs | 12 +- .../vesting-wallet/tests/vesting-wallet.rs | 6 +- 24 files changed, 338 insertions(+), 331 deletions(-) diff --git a/benches/src/erc721.rs b/benches/src/erc721.rs index f606fee64..9f56b8fef 100644 --- a/benches/src/erc721.rs +++ b/benches/src/erc721.rs @@ -57,9 +57,9 @@ pub async fn run(cache_opt: Opt) -> eyre::Result> { let token_3 = uint!(3_U256); let token_4 = uint!(4_U256); - let _ = receipt!(contract.mint(alice_addr, token_2))?; - let _ = receipt!(contract.mint(alice_addr, token_3))?; - let _ = receipt!(contract.mint(alice_addr, token_4))?; + _ = receipt!(contract.mint(alice_addr, token_2))?; + _ = receipt!(contract.mint(alice_addr, token_3))?; + _ = receipt!(contract.mint(alice_addr, token_4))?; // IMPORTANT: Order matters! use Erc721::*; diff --git a/benches/src/lib.rs b/benches/src/lib.rs index a65cd8927..a5ef29c46 100644 --- a/benches/src/lib.rs +++ b/benches/src/lib.rs @@ -125,7 +125,7 @@ fn cache_contract( ) -> eyre::Result<()> { // We don't need a status code. // Since it is not zero when the contract is already cached. - let _ = Command::new("cargo") + _ = Command::new("cargo") .args(["stylus", "cache", "bid"]) .args(["-e", &env("RPC_URL")?]) .args(["--private-key", &format!("0x{}", account.pk())]) diff --git a/benches/src/vesting_wallet.rs b/benches/src/vesting_wallet.rs index 977efcb83..ef1610905 100644 --- a/benches/src/vesting_wallet.rs +++ b/benches/src/vesting_wallet.rs @@ -66,8 +66,8 @@ pub async fn run(cache_opt: Opt) -> eyre::Result> { let contract = VestingWallet::new(contract_addr, &alice_wallet); let erc20 = Erc20::new(erc20_addr, &alice_wallet); - let _ = receipt!(contract.receiveEther().value(uint!(1000_U256)))?; - let _ = receipt!(erc20.mint(contract_addr, uint!(1000_U256)))?; + _ = receipt!(contract.receiveEther().value(uint!(1000_U256)))?; + _ = receipt!(erc20.mint(contract_addr, uint!(1000_U256)))?; // IMPORTANT: Order matters! use VestingWallet::*; diff --git a/contracts/src/access/ownable.rs b/contracts/src/access/ownable.rs index 607541765..1c7d000f2 100644 --- a/contracts/src/access/ownable.rs +++ b/contracts/src/access/ownable.rs @@ -265,7 +265,7 @@ mod tests { ) { contract.init(alice, |contract| contract._owner.set(alice)); - let _ = contract.sender(alice).renounce_ownership(); + _ = contract.sender(alice).renounce_ownership(); let owner = contract.sender(alice).owner(); assert_eq!(owner, Address::ZERO); } diff --git a/contracts/src/token/erc1155/extensions/supply.rs b/contracts/src/token/erc1155/extensions/supply.rs index 67650254f..65cb32c19 100644 --- a/contracts/src/token/erc1155/extensions/supply.rs +++ b/contracts/src/token/erc1155/extensions/supply.rs @@ -476,8 +476,7 @@ mod tests { .sender(alice) ._mint(dave, token_id, U256::MAX / two, &vec![].into()) .expect("should mint to dave"); - let _ = - contract.sender(alice)._mint(bob, token_id, three, &vec![].into()); + _ = contract.sender(alice)._mint(bob, token_id, three, &vec![].into()); } #[motsu::test] @@ -492,7 +491,7 @@ mod tests { .sender(alice) ._mint(bob, token_ids[0], U256::MAX, &vec![].into()) .expect("should mint"); - let _ = contract.sender(alice)._mint( + _ = contract.sender(alice)._mint( bob, token_ids[1], U256::from(1), diff --git a/contracts/src/token/erc1155/extensions/uri_storage.rs b/contracts/src/token/erc1155/extensions/uri_storage.rs index 315fda4a6..e54728dd5 100644 --- a/contracts/src/token/erc1155/extensions/uri_storage.rs +++ b/contracts/src/token/erc1155/extensions/uri_storage.rs @@ -135,6 +135,7 @@ mod tests { assert_eq!(uri, contract.sender(alice).uri(TOKEN_ID)); } + #[motsu::test] fn uri_returns_empty_string_when_no_uri_is_set( contract: Contract, alice: Address, diff --git a/contracts/src/token/erc20/extensions/erc4626.rs b/contracts/src/token/erc20/extensions/erc4626.rs index b4d143818..dd3250f81 100644 --- a/contracts/src/token/erc20/extensions/erc4626.rs +++ b/contracts/src/token/erc20/extensions/erc4626.rs @@ -1148,7 +1148,7 @@ impl Erc4626 { mod tests { use alloy_primitives::{address, Address, U256, U8}; use motsu::prelude::Contract; - use stylus_sdk::{msg, prelude::*}; + use stylus_sdk::prelude::*; use super::{Erc4626, IErc4626}; use crate::token::erc20::Erc20; diff --git a/contracts/src/token/erc20/extensions/flash_mint.rs b/contracts/src/token/erc20/extensions/flash_mint.rs index 466b93ab6..bc6529c38 100644 --- a/contracts/src/token/erc20/extensions/flash_mint.rs +++ b/contracts/src/token/erc20/extensions/flash_mint.rs @@ -337,8 +337,8 @@ impl IErc3156FlashLender for Erc20FlashMint { #[cfg(all(test, feature = "std"))] mod tests { - use alloy_primitives::{address, uint, Address, U256}; - use motsu::prelude::{Account, Contract}; + use alloy_primitives::{uint, Address, U256}; + use motsu::prelude::Contract; use stylus_sdk::{abi::Bytes, msg, prelude::*}; use super::{ diff --git a/contracts/src/token/erc721/mod.rs b/contracts/src/token/erc721/mod.rs index 02981bb81..34eb8f740 100644 --- a/contracts/src/token/erc721/mod.rs +++ b/contracts/src/token/erc721/mod.rs @@ -2692,10 +2692,10 @@ mod tests { #[selector(name = "onERC721Received")] fn on_erc721_received( &mut self, - operator: Address, - from: Address, + _operator: Address, + _from: Address, token_id: U256, - data: Bytes, + _data: Bytes, ) -> FixedBytes<4> { self._received_token_id.set(token_id); fixed_bytes!("150b7a02") diff --git a/contracts/src/utils/math/alloy.rs b/contracts/src/utils/math/alloy.rs index e0019262a..94d3eb827 100644 --- a/contracts/src/utils/math/alloy.rs +++ b/contracts/src/utils/math/alloy.rs @@ -251,7 +251,7 @@ mod tests { #[should_panic = "division by U256::ZERO in `Math::mul_div`"] fn check_mul_div_panics_when_denominator_is_zero() { proptest!(|(x: U256, y: U256)| { - let _ = x.mul_div(y, U256::ZERO, Rounding::Floor); + _ = x.mul_div(y, U256::ZERO, Rounding::Floor); }) } @@ -261,7 +261,7 @@ mod tests { proptest!(|(x: U256, y: U256)| { prop_assume!(x != U256::ZERO, "Guaranteed `x` for overflow."); prop_assume!(y > U256::MAX / x, "Guaranteed `y` for overflow."); - let _ = x.mul_div(y, U256::from(1), Rounding::Floor); + _ = x.mul_div(y, U256::from(1), Rounding::Floor); }) } } diff --git a/examples/access-control/tests/access_control.rs b/examples/access-control/tests/access_control.rs index d8eb52c29..f2f48fcd6 100644 --- a/examples/access-control/tests/access_control.rs +++ b/examples/access-control/tests/access_control.rs @@ -144,7 +144,7 @@ async fn admin_can_revoke_role(alice: Account, bob: Account) -> Result<()> { let alice_addr = alice.address(); let bob_addr = bob.address(); - let _ = watch!(contract.grantRole(ROLE.into(), bob_addr))?; + _ = watch!(contract.grantRole(ROLE.into(), bob_addr))?; let receipt = receipt!(contract.revokeRole(ROLE.into(), bob_addr))?; assert!(receipt.emits(RoleRevoked { @@ -167,7 +167,7 @@ async fn error_when_non_admin_revokes_role( let alice_addr = alice.address(); let bob_addr = bob.address(); - let _ = watch!(contract.grantRole(ROLE.into(), alice_addr))?; + _ = watch!(contract.grantRole(ROLE.into(), alice_addr))?; let contract = AccessControl::new(contract_addr, &bob.wallet); let err = send!(contract.revokeRole(ROLE.into(), alice_addr)) @@ -191,7 +191,7 @@ async fn roles_can_be_revoked_multiple_times( let alice_addr = alice.address(); let bob_addr = bob.address(); - let _ = watch!(contract.revokeRole(ROLE.into(), bob_addr))?; + _ = watch!(contract.revokeRole(ROLE.into(), bob_addr))?; let receipt = receipt!(contract.revokeRole(ROLE.into(), bob_addr))?; assert!(!receipt.emits(RoleRevoked { role: ROLE.into(), @@ -224,7 +224,7 @@ async fn bearer_can_renounce_role(alice: Account, bob: Account) -> Result<()> { let contract_addr = alice.as_deployer().deploy().await?.address()?; let contract = AccessControl::new(contract_addr, &alice.wallet); - let _ = watch!(contract.grantRole(ROLE.into(), bob_addr))?; + _ = watch!(contract.grantRole(ROLE.into(), bob_addr))?; let contract = AccessControl::new(contract_addr, &bob.wallet); let receipt = receipt!(contract.renounceRole(ROLE.into(), bob_addr))?; @@ -248,7 +248,7 @@ async fn error_when_the_one_renouncing_is_not_the_sender( let alice_addr = alice.address(); let bob_addr = bob.address(); - let _ = watch!(contract.grantRole(ROLE.into(), bob_addr))?; + _ = watch!(contract.grantRole(ROLE.into(), bob_addr))?; let contract = AccessControl::new(contract_addr, &bob.wallet); let err = send!(contract.renounceRole(ROLE.into(), alice_addr)) @@ -264,7 +264,7 @@ async fn roles_can_be_renounced_multiple_times(alice: Account) -> Result<()> { let contract_addr = alice.as_deployer().deploy().await?.address()?; let contract = AccessControl::new(contract_addr, &alice.wallet); - let _ = watch!(contract.renounceRole(ROLE.into(), alice_addr))?; + _ = watch!(contract.renounceRole(ROLE.into(), alice_addr))?; let receipt = receipt!(contract.renounceRole(ROLE.into(), alice_addr))?; assert!(!receipt.emits(RoleRevoked { role: ROLE.into(), @@ -314,7 +314,7 @@ async fn the_new_admin_can_grant_roles( newAdminRole: NEW_ADMIN_ROLE.into() })); - let _ = watch!(contract.grantRole(NEW_ADMIN_ROLE.into(), bob_addr))?; + _ = watch!(contract.grantRole(NEW_ADMIN_ROLE.into(), bob_addr))?; let contract = AccessControl::new(contract_addr, &bob.wallet); let receipt = receipt!(contract.grantRole(ROLE.into(), alice_addr))?; @@ -346,10 +346,10 @@ async fn the_new_admin_can_revoke_roles( newAdminRole: NEW_ADMIN_ROLE.into() })); - let _ = watch!(contract.grantRole(NEW_ADMIN_ROLE.into(), bob_addr))?; + _ = watch!(contract.grantRole(NEW_ADMIN_ROLE.into(), bob_addr))?; let contract = AccessControl::new(contract_addr, &bob.wallet); - let _ = watch!(contract.grantRole(ROLE.into(), alice_addr))?; + _ = watch!(contract.grantRole(ROLE.into(), alice_addr))?; let receipt = receipt!(contract.revokeRole(ROLE.into(), alice_addr))?; assert!(receipt.emits(RoleRevoked { role: ROLE.into(), diff --git a/examples/erc1155-metadata-uri/tests/erc1155-metadata-uri.rs b/examples/erc1155-metadata-uri/tests/erc1155-metadata-uri.rs index d57642c2c..73884c2f7 100644 --- a/examples/erc1155-metadata-uri/tests/erc1155-metadata-uri.rs +++ b/examples/erc1155-metadata-uri/tests/erc1155-metadata-uri.rs @@ -81,7 +81,7 @@ async fn uri_returns_concatenated_base_uri_and_token_uri( let token_uri = "/some/token/uri"; let expected_uri = BASE_URI.to_owned() + token_uri; - let _ = watch!(contract.setBaseURI(BASE_URI.to_owned()))?; + _ = watch!(contract.setBaseURI(BASE_URI.to_owned()))?; let receipt = receipt!(contract.setTokenURI(token_id, token_uri.to_owned()))?; @@ -142,7 +142,7 @@ async fn uri_ignores_metadata_uri_when_token_uri_is_set( let token_uri = "/some/token/uri"; let expected_uri = BASE_URI.to_owned() + token_uri; - let _ = watch!(contract.setBaseURI(BASE_URI.to_owned()))?; + _ = watch!(contract.setBaseURI(BASE_URI.to_owned()))?; let receipt = receipt!(contract.setTokenURI(token_id, token_uri.to_owned()))?; diff --git a/examples/erc1155-supply/tests/erc1155-supply.rs b/examples/erc1155-supply/tests/erc1155-supply.rs index bf6682185..d851d0e51 100644 --- a/examples/erc1155-supply/tests/erc1155-supply.rs +++ b/examples/erc1155-supply/tests/erc1155-supply.rs @@ -260,18 +260,18 @@ async fn mint_panics_on_total_supply_overflow( let two = U256::from(2); let three = U256::from(3); - let _ = watch!(contract.mint( + _ = watch!(contract.mint( alice_addr, token_id, U256::MAX / two, vec![].into() - )); - let _ = watch!(contract.mint( + ))?; + _ = watch!(contract.mint( bob_addr, token_id, U256::MAX / two, vec![].into() - )); + ))?; let err = send!(contract.mint(alice_addr, token_id, three, vec![].into())) .expect_err("should panic due to total_supply overflow"); @@ -291,12 +291,12 @@ async fn mint_panics_on_total_supply_all_overflow( let alice_addr = alice.address(); let token_ids = random_token_ids(2); - let _ = watch!(contract.mint( + _ = watch!(contract.mint( alice_addr, token_ids[0], U256::MAX, vec![].into() - )); + ))?; let err = send!(contract.mint( alice_addr, @@ -320,7 +320,7 @@ async fn burn(alice: Account) -> eyre::Result<()> { let token_id = random_token_ids(1)[0]; let value = random_values(1)[0]; - let _ = watch!(contract.mint(alice_addr, token_id, value, vec![].into())); + _ = watch!(contract.mint(alice_addr, token_id, value, vec![].into()))?; let receipt = receipt!(contract.burn(alice_addr, token_id, value))?; @@ -357,9 +357,9 @@ async fn burn_with_approval(alice: Account, bob: Account) -> eyre::Result<()> { let token_id = random_token_ids(1)[0]; let value = random_values(1)[0]; - let _ = watch!(contract.mint(bob_addr, token_id, value, vec![].into())); + _ = watch!(contract.mint(bob_addr, token_id, value, vec![].into()))?; - let _ = watch!(contract_bob.setApprovalForAll(alice_addr, true)); + _ = watch!(contract_bob.setApprovalForAll(alice_addr, true))?; let receipt = receipt!(contract.burn(bob_addr, token_id, value))?; @@ -393,12 +393,12 @@ async fn burn_batch(alice: Account) -> eyre::Result<()> { let token_ids = random_token_ids(4); let values = random_values(4); - let _ = watch!(contract.mintBatch( + _ = watch!(contract.mintBatch( alice_addr, token_ids.clone(), values.clone(), vec![].into() - )); + ))?; let receipt = receipt!(contract.burnBatch( alice_addr, @@ -445,14 +445,14 @@ async fn burn_batch_with_approval( let token_ids = random_token_ids(4); let values = random_values(4); - let _ = watch!(contract.mintBatch( + _ = watch!(contract.mintBatch( bob_addr, token_ids.clone(), values.clone(), vec![].into() - )); + ))?; - let _ = watch!(contract_bob.setApprovalForAll(alice_addr, true)); + _ = watch!(contract_bob.setApprovalForAll(alice_addr, true))?; let receipt = receipt!(contract.burnBatch( bob_addr, @@ -498,7 +498,7 @@ async fn supply_unaffected_by_safe_transfer_from( let token_id = random_token_ids(1)[0]; let value = random_values(1)[0]; - let _ = watch!(contract.mint(alice_addr, token_id, value, vec![].into())); + _ = watch!(contract.mint(alice_addr, token_id, value, vec![].into()))?; // assert balances as expected after mint let alice_balance = @@ -564,12 +564,12 @@ async fn supply_unaffected_by_safe_transfer_from_batch( let token_ids = random_token_ids(4); let values = random_values(4); - let _ = watch!(contract.mintBatch( + _ = watch!(contract.mintBatch( alice_addr, token_ids.clone(), values.clone(), vec![].into() - )); + ))?; // assert balances as expected after mint for (&token_id, &value) in token_ids.iter().zip(values.iter()) { @@ -739,12 +739,12 @@ async fn safe_transfer_from(alice: Account, bob: Account) -> eyre::Result<()> { let bob_addr = bob.address(); let token_id = random_token_ids(1)[0]; let value = random_values(1)[0]; - let _ = watch!(contract.mint( + _ = watch!(contract.mint( alice_addr, token_id, value, vec![0, 1, 2, 3].into() - )); + ))?; let Erc1155Supply::balanceOfReturn { balance: initial_alice_balance } = contract.balanceOf(alice_addr, token_id).call().await?; @@ -792,14 +792,14 @@ async fn safe_transfer_from_with_approval( let token_id = random_token_ids(1)[0]; let value = random_values(1)[0]; - let _ = watch!(contract_bob.mint( + _ = watch!(contract_bob.mint( bob_addr, token_id, value, vec![0, 1, 2, 3].into() - )); + ))?; - let _ = watch!(contract_bob.setApprovalForAll(alice_addr, true)); + _ = watch!(contract_bob.setApprovalForAll(alice_addr, true))?; let Erc1155Supply::balanceOfReturn { balance: initial_alice_balance } = contract_alice.balanceOf(alice_addr, token_id).call().await?; @@ -848,12 +848,12 @@ async fn safe_transfer_to_receiver_contract( let token_id = random_token_ids(1)[0]; let value = random_values(1)[0]; - let _ = watch!(contract.mint( + _ = watch!(contract.mint( alice_addr, token_id, value, vec![0, 1, 2, 3].into() - )); + ))?; let Erc1155Supply::balanceOfReturn { balance: initial_alice_balance } = contract.balanceOf(alice_addr, token_id).call().await?; @@ -908,12 +908,12 @@ async fn safe_batch_transfer_from( let token_ids = random_token_ids(2); let values = random_values(2); - let _ = watch!(contract_alice.mintBatch( + _ = watch!(contract_alice.mintBatch( alice_addr, token_ids.clone(), values.clone(), vec![].into() - )); + ))?; let Erc1155Supply::balanceOfBatchReturn { balances: initial_alice_balances, @@ -979,12 +979,12 @@ async fn safe_batch_transfer_to_receiver_contract( let token_ids = random_token_ids(2); let values = random_values(2); - let _ = watch!(contract.mintBatch( + _ = watch!(contract.mintBatch( alice_addr, token_ids.clone(), values.clone(), vec![].into() - )); + ))?; let Erc1155Supply::balanceOfBatchReturn { balances: initial_alice_balances, @@ -1066,14 +1066,14 @@ async fn safe_batch_transfer_from_with_approval( let token_ids = random_token_ids(2); let values = random_values(2); - let _ = watch!(contract_alice.mintBatch( + _ = watch!(contract_alice.mintBatch( bob_addr, token_ids.clone(), values.clone(), vec![].into() - )); + ))?; - let _ = watch!(contract_bob.setApprovalForAll(alice_addr, true)); + _ = watch!(contract_bob.setApprovalForAll(alice_addr, true))?; let Erc1155Supply::balanceOfBatchReturn { balances: initial_dave_balances } = contract_alice diff --git a/examples/erc1155/tests/erc1155.rs b/examples/erc1155/tests/erc1155.rs index 8953ee18d..4729bf83f 100644 --- a/examples/erc1155/tests/erc1155.rs +++ b/examples/erc1155/tests/erc1155.rs @@ -620,12 +620,12 @@ async fn safe_transfer_from(alice: Account, bob: Account) -> eyre::Result<()> { let bob_addr = bob.address(); let token_id = random_token_ids(1)[0]; let value = random_values(1)[0]; - let _ = watch!(contract.mint( + _ = watch!(contract.mint( alice_addr, token_id, value, vec![0, 1, 2, 3].into() - )); + ))?; let Erc1155::balanceOfReturn { balance: initial_alice_balance } = contract.balanceOf(alice_addr, token_id).call().await?; @@ -673,14 +673,14 @@ async fn safe_transfer_from_with_approval( let token_id = random_token_ids(1)[0]; let value = random_values(1)[0]; - let _ = watch!(contract_bob.mint( + _ = watch!(contract_bob.mint( bob_addr, token_id, value, vec![0, 1, 2, 3].into() - )); + ))?; - let _ = watch!(contract_bob.setApprovalForAll(alice_addr, true)); + _ = watch!(contract_bob.setApprovalForAll(alice_addr, true))?; let Erc1155::balanceOfReturn { balance: initial_alice_balance } = contract_alice.balanceOf(alice_addr, token_id).call().await?; @@ -729,12 +729,12 @@ async fn safe_transfer_to_receiver_contract( let token_id = random_token_ids(1)[0]; let value = random_values(1)[0]; - let _ = watch!(contract.mint( + _ = watch!(contract.mint( alice_addr, token_id, value, vec![0, 1, 2, 3].into() - )); + ))?; let Erc1155::balanceOfReturn { balance: initial_alice_balance } = contract.balanceOf(alice_addr, token_id).call().await?; @@ -793,7 +793,7 @@ async fn errors_when_receiver_reverts_with_reason( let token_id = random_token_ids(1)[0]; let value = random_values(1)[0]; - let _ = watch!(contract.mint( + _ = watch!(contract.mint( alice_addr, token_id, value, @@ -833,7 +833,7 @@ async fn errors_when_receiver_reverts_without_reason( let token_id = random_token_ids(1)[0]; let value = random_values(1)[0]; - let _ = watch!(contract.mint( + _ = watch!(contract.mint( alice_addr, token_id, value, @@ -869,7 +869,7 @@ async fn errors_when_receiver_panics(alice: Account) -> eyre::Result<()> { let token_id = random_token_ids(1)[0]; let value = random_values(1)[0]; - let _ = watch!(contract.mint( + _ = watch!(contract.mint( alice_addr, token_id, value, @@ -903,7 +903,7 @@ async fn errors_when_invalid_receiver_contract( let token_id = random_token_ids(1)[0]; let value = random_values(1)[0]; - let _ = watch!(contract.mint( + _ = watch!(contract.mint( alice_addr, token_id, value, @@ -937,7 +937,7 @@ async fn error_when_invalid_receiver_safe_transfer_from( let invalid_receiver = Address::ZERO; let token_id = random_token_ids(1)[0]; let value = random_values(1)[0]; - let _ = watch!(contract.mint(alice_addr, token_id, value, vec![].into())); + _ = watch!(contract.mint(alice_addr, token_id, value, vec![].into()))?; let err = send!(contract.safeTransferFrom( alice_addr, @@ -969,7 +969,7 @@ async fn error_when_missing_approval_safe_transfer_from( let dave_addr = dave.address(); let token_id = random_token_ids(1)[0]; let value = random_values(1)[0]; - let _ = watch!(contract.mint(bob_addr, token_id, value, vec![].into())); + _ = watch!(contract.mint(bob_addr, token_id, value, vec![].into()))?; let err = send!(contract.safeTransferFrom( bob_addr, @@ -1004,9 +1004,8 @@ async fn error_when_insufficient_balance_safe_transfer_from( let token_id = random_token_ids(1)[0]; let value = random_values(1)[0]; - let _ = - watch!(contract_alice.mint(bob_addr, token_id, value, vec![].into())); - let _ = watch!(contract_bob.setApprovalForAll(alice_addr, true)); + _ = watch!(contract_alice.mint(bob_addr, token_id, value, vec![].into()))?; + _ = watch!(contract_bob.setApprovalForAll(alice_addr, true))?; let err = send!(contract_alice.safeTransferFrom( bob_addr, @@ -1040,12 +1039,12 @@ async fn safe_batch_transfer_from( let token_ids = random_token_ids(2); let values = random_values(2); - let _ = watch!(contract_alice.mintBatch( + _ = watch!(contract_alice.mintBatch( alice_addr, token_ids.clone(), values.clone(), vec![].into() - )); + ))?; let Erc1155::balanceOfBatchReturn { balances: initial_alice_balances } = contract_alice @@ -1110,12 +1109,12 @@ async fn safe_batch_transfer_to_receiver_contract( let token_ids = random_token_ids(2); let values = random_values(2); - let _ = watch!(contract.mintBatch( + _ = watch!(contract.mintBatch( alice_addr, token_ids.clone(), values.clone(), vec![].into() - )); + ))?; let Erc1155::balanceOfBatchReturn { balances: initial_alice_balances } = contract @@ -1198,12 +1197,12 @@ async fn errors_when_receiver_reverts_with_reason_in_batch_transfer( let token_ids = random_token_ids(2); let values = random_values(2); - let _ = watch!(contract.mintBatch( + _ = watch!(contract.mintBatch( alice_addr, token_ids.clone(), values.clone(), vec![].into() - )); + ))?; let err = send!(contract.safeBatchTransferFrom( alice_addr, @@ -1238,12 +1237,12 @@ async fn errors_when_receiver_reverts_without_reason_in_batch_transfer( let token_ids = random_token_ids(2); let values = random_values(2); - let _ = watch!(contract.mintBatch( + _ = watch!(contract.mintBatch( alice_addr, token_ids.clone(), values.clone(), vec![].into() - )); + ))?; let err = send!(contract.safeBatchTransferFrom( alice_addr, @@ -1276,12 +1275,12 @@ async fn errors_when_receiver_panics_in_batch_transfer( let token_ids = random_token_ids(2); let values = random_values(2); - let _ = watch!(contract.mintBatch( + _ = watch!(contract.mintBatch( alice_addr, token_ids.clone(), values.clone(), vec![].into() - )); + ))?; let err = send!(contract.safeBatchTransferFrom( alice_addr, @@ -1310,12 +1309,12 @@ async fn errors_when_invalid_receiver_contract_in_batch_transfer( let token_ids = random_token_ids(2); let values = random_values(2); - let _ = watch!(contract.mintBatch( + _ = watch!(contract.mintBatch( alice_addr, token_ids.clone(), values.clone(), vec![].into() - )); + ))?; let err = send!(contract.safeBatchTransferFrom( alice_addr, @@ -1349,14 +1348,14 @@ async fn safe_batch_transfer_from_with_approval( let token_ids = random_token_ids(2); let values = random_values(2); - let _ = watch!(contract_alice.mintBatch( + _ = watch!(contract_alice.mintBatch( bob_addr, token_ids.clone(), values.clone(), vec![].into() - )); + ))?; - let _ = watch!(contract_bob.setApprovalForAll(alice_addr, true)); + _ = watch!(contract_bob.setApprovalForAll(alice_addr, true))?; let Erc1155::balanceOfBatchReturn { balances: initial_dave_balances } = contract_alice @@ -1418,12 +1417,12 @@ async fn error_when_invalid_receiver_safe_batch_transfer_from( let token_ids = random_token_ids(2); let values = random_values(2); - let _ = watch!(contract.mintBatch( + _ = watch!(contract.mintBatch( alice_addr, token_ids.clone(), values.clone(), vec![].into() - )); + ))?; let err = send!(contract.safeBatchTransferFrom( alice_addr, @@ -1454,12 +1453,12 @@ async fn error_invalid_array_length_in_safe_batch_transfer_from( let token_ids = random_token_ids(2); let values = random_values(2); - let _ = watch!(contract_alice.mintBatch( + _ = watch!(contract_alice.mintBatch( alice_addr, token_ids.clone(), values.clone(), vec![].into() - )); + ))?; let err = send!(contract_alice.safeBatchTransferFrom( alice_addr, @@ -1493,12 +1492,12 @@ async fn error_when_missing_approval_safe_batch_transfer_from( let token_ids = random_token_ids(4); let values = random_values(4); - let _ = watch!(contract.mintBatch( + _ = watch!(contract.mintBatch( bob_addr, token_ids.clone(), values.clone(), vec![].into() - )); + ))?; let err = send!(contract.safeBatchTransferFrom( bob_addr, @@ -1533,13 +1532,13 @@ async fn error_when_insufficient_balance_safe_batch_transfer_from( let token_ids = random_token_ids(2); let values = random_values(2); - let _ = watch!(contract_alice.mintBatch( + _ = watch!(contract_alice.mintBatch( bob_addr, token_ids.clone(), values.clone(), vec![].into() - )); - let _ = watch!(contract_bob.setApprovalForAll(alice_addr, true)); + ))?; + _ = watch!(contract_bob.setApprovalForAll(alice_addr, true))?; let err = send!(contract_alice.safeBatchTransferFrom( bob_addr, @@ -1573,12 +1572,12 @@ async fn burns(alice: Account) -> eyre::Result<()> { let token_ids = random_token_ids(1); let values = random_values(1); - let _ = watch!(contract.mint( + _ = watch!(contract.mint( alice_addr, token_ids[0], values[0], vec![].into() - )); + ))?; let initial_balance = contract.balanceOf(alice_addr, token_ids[0]).call().await?.balance; @@ -1612,14 +1611,18 @@ async fn burns_with_approval(alice: Account, bob: Account) -> eyre::Result<()> { let token_ids = random_token_ids(1); let values = random_values(1); - let _ = - watch!(contract.mint(bob_addr, token_ids[0], values[0], vec![].into())); + _ = watch!(contract.mint( + bob_addr, + token_ids[0], + values[0], + vec![].into() + ))?; let initial_balance = contract.balanceOf(bob_addr, token_ids[0]).call().await?.balance; assert_eq!(values[0], initial_balance); - let _ = watch!(contract_bob.setApprovalForAll(alice_addr, true)); + _ = watch!(contract_bob.setApprovalForAll(alice_addr, true))?; let receipt = receipt!(contract.burn(bob_addr, token_ids[0], values[0]))?; @@ -1651,8 +1654,12 @@ async fn error_when_missing_approval_burn( let token_ids = random_token_ids(1); let values = random_values(1); - let _ = - watch!(contract.mint(bob_addr, token_ids[0], values[0], vec![].into())); + _ = watch!(contract.mint( + bob_addr, + token_ids[0], + values[0], + vec![].into() + ))?; let err = send!(contract.burn(bob_addr, token_ids[0], values[0])) .expect_err("should return `ERC1155MissingApprovalForAll`"); @@ -1677,7 +1684,7 @@ async fn error_when_insufficient_balance_burn( let value = random_values(1)[0]; let to_burn = value + uint!(1_U256); - let _ = watch!(contract.mint(alice_addr, token_id, value, vec![].into())); + _ = watch!(contract.mint(alice_addr, token_id, value, vec![].into()))?; let err = send!(contract.burn(alice_addr, token_id, to_burn)) .expect_err("should return `ERC1155InsufficientBalance`"); @@ -1701,12 +1708,12 @@ async fn burns_batch(alice: Account) -> eyre::Result<()> { let token_ids = random_token_ids(4); let values = random_values(4); - let _ = watch!(contract.mintBatch( + _ = watch!(contract.mintBatch( alice_addr, token_ids.clone(), values.clone(), vec![].into() - )); + ))?; for (&id, &value) in token_ids.iter().zip(values.iter()) { let balance = contract.balanceOf(alice_addr, id).call().await?.balance; @@ -1749,19 +1756,19 @@ async fn burns_batch_with_approval( let token_ids = random_token_ids(4); let values = random_values(4); - let _ = watch!(contract.mintBatch( + _ = watch!(contract.mintBatch( bob_addr, token_ids.clone(), values.clone(), vec![].into() - )); + ))?; for (&id, &value) in token_ids.iter().zip(values.iter()) { let balance = contract.balanceOf(bob_addr, id).call().await?.balance; assert_eq!(value, balance); } - let _ = watch!(contract_bob.setApprovalForAll(alice_addr, true)); + _ = watch!(contract_bob.setApprovalForAll(alice_addr, true))?; let receipt = receipt!(contract.burnBatch( bob_addr, @@ -1798,12 +1805,12 @@ async fn error_when_missing_approval_burn_batch( let token_ids = random_token_ids(2); let values = random_values(2); - let _ = watch!(contract.mintBatch( + _ = watch!(contract.mintBatch( bob_addr, token_ids.clone(), values.clone(), vec![].into() - )); + ))?; let err = send!(contract.burnBatch(bob_addr, token_ids, values)) .expect_err("should return `ERC1155MissingApprovalForAll`"); @@ -1828,12 +1835,12 @@ async fn error_when_insufficient_balance_burn_batch( let values = random_values(2); let to_burn: Vec = values.iter().map(|v| v + uint!(1_U256)).collect(); - let _ = watch!(contract.mintBatch( + _ = watch!(contract.mintBatch( alice_addr, token_ids.clone(), values.clone(), vec![].into() - )); + ))?; let err = send!(contract.burnBatch( alice_addr, @@ -1914,7 +1921,7 @@ async fn pause_reverts_in_paused_state(alice: Account) -> eyre::Result<()> { let contract = Erc1155::new(contract_addr, &alice.wallet); - let _ = watch!(contract.pause())?; + _ = watch!(contract.pause())?; let err = send!(contract.pause()).expect_err("should return `EnforcedPause`"); @@ -1930,7 +1937,7 @@ async fn unpauses(alice: Account) -> eyre::Result<()> { let contract = Erc1155::new(contract_addr, &alice.wallet); - let _ = watch!(contract.pause())?; + _ = watch!(contract.pause())?; let receipt = receipt!(contract.unpause())?; @@ -1970,7 +1977,7 @@ async fn mint_reverts_in_paused_state(alice: Account) -> eyre::Result<()> { let token_id = random_token_ids(1)[0]; let value = random_values(1)[0]; - let _ = watch!(contract.pause())?; + _ = watch!(contract.pause())?; let err = send!(contract.mint( alice_addr, @@ -1996,7 +2003,7 @@ async fn mint_batch_reverts_in_paused_state( let token_ids = random_token_ids(3); let values = random_values(3); - let _ = watch!(contract.pause())?; + _ = watch!(contract.pause())?; let err = send!(contract.mintBatch( alice_addr, @@ -2020,14 +2027,14 @@ async fn burn_reverts_in_paused_state(alice: Account) -> eyre::Result<()> { let token_ids = random_token_ids(1); let values = random_values(1); - let _ = watch!(contract.mint( + _ = watch!(contract.mint( alice_addr, token_ids[0], values[0], vec![].into() - )); + ))?; - let _ = watch!(contract.pause())?; + _ = watch!(contract.pause())?; let err = send!(contract.burn(alice_addr, token_ids[0], values[0])) .expect_err("should return `EnforcedPause`"); @@ -2048,14 +2055,14 @@ async fn burn_batch_reverts_in_paused_state( let token_ids = random_token_ids(4); let values = random_values(4); - let _ = watch!(contract.mintBatch( + _ = watch!(contract.mintBatch( alice_addr, token_ids.clone(), values.clone(), vec![].into() - )); + ))?; - let _ = watch!(contract.pause())?; + _ = watch!(contract.pause())?; let err = send!(contract.burnBatch( alice_addr, @@ -2081,14 +2088,14 @@ async fn safe_transfer_from_reverts_in_paused_state( let bob_addr = bob.address(); let token_id = random_token_ids(1)[0]; let value = random_values(1)[0]; - let _ = watch!(contract.mint( + _ = watch!(contract.mint( alice_addr, token_id, value, vec![0, 1, 2, 3].into() - )); + ))?; - let _ = watch!(contract.pause())?; + _ = watch!(contract.pause())?; let err = send!(contract.safeTransferFrom( alice_addr, @@ -2117,14 +2124,14 @@ async fn safe_batch_transfer_from_reverts_in_paused_state( let token_ids = random_token_ids(2); let values = random_values(2); - let _ = watch!(contract_alice.mintBatch( + _ = watch!(contract_alice.mintBatch( alice_addr, token_ids.clone(), values.clone(), vec![].into() - )); + ))?; - let _ = watch!(contract_alice.pause())?; + _ = watch!(contract_alice.pause())?; let err = send!(contract_alice.safeBatchTransferFrom( alice_addr, @@ -2151,7 +2158,7 @@ async fn set_approval_for_all_does_not_revert_in_paused_state( let alice_addr = alice.address(); let bob_addr = bob.address(); - let _ = watch!(contract.pause())?; + _ = watch!(contract.pause())?; let approved_value = true; let receipt = diff --git a/examples/erc20-flash-mint/tests/erc20-flash-mint.rs b/examples/erc20-flash-mint/tests/erc20-flash-mint.rs index 988e045f5..0edb0f882 100644 --- a/examples/erc20-flash-mint/tests/erc20-flash-mint.rs +++ b/examples/erc20-flash-mint/tests/erc20-flash-mint.rs @@ -68,7 +68,7 @@ async fn max_flash_loan(alice: Account) -> Result<()> { let alice_addr = alice.address(); let mint_amount = uint!(1_000_000_U256); - let _ = watch!(contract.mint(alice_addr, mint_amount))?; + _ = watch!(contract.mint(alice_addr, mint_amount))?; let max_loan = contract.maxFlashLoan(contract_addr).call().await?.maxLoan; assert_eq!(U256::MAX - mint_amount, max_loan); @@ -89,7 +89,7 @@ async fn max_flash_loan_return_zero_if_no_more_tokens_to_mint( let contract = Erc20FlashMint::new(contract_addr, &alice.wallet); let alice_addr = alice.address(); - let _ = watch!(contract.mint(alice_addr, U256::MAX))?; + _ = watch!(contract.mint(alice_addr, U256::MAX))?; let max_loan = contract.maxFlashLoan(contract_addr).call().await?.maxLoan; assert_eq!(U256::MIN, max_loan); @@ -111,7 +111,7 @@ async fn max_flash_loan_returns_zero_on_invalid_address( let alice_addr = alice.address(); let mint_amount = uint!(1_000_000_U256); - let _ = watch!(contract.mint(alice_addr, mint_amount))?; + _ = watch!(contract.mint(alice_addr, mint_amount))?; // non-token address let max_loan = contract.maxFlashLoan(alice_addr).call().await?.maxLoan; @@ -194,7 +194,7 @@ async fn flash_loan_with_fee(alice: Account) -> Result<()> { let erc20 = Erc20FlashMint::new(erc20_addr, &alice.wallet); let borrower_addr = borrower::deploy(&alice.wallet, true, true).await?; - let _ = watch!(erc20.mint(borrower_addr, FLASH_FEE_VALUE))?; + _ = watch!(erc20.mint(borrower_addr, FLASH_FEE_VALUE))?; let loan_amount = uint!(1_000_000_U256); let borrower_balance = erc20.balanceOf(borrower_addr).call().await?.balance; @@ -311,7 +311,7 @@ async fn flash_loan_with_fee_and_fee_receiver(alice: Account) -> Result<()> { let erc20 = Erc20FlashMint::new(erc20_addr, &alice.wallet); let borrower_addr = borrower::deploy(&alice.wallet, true, true).await?; - let _ = watch!(erc20.mint(borrower_addr, FLASH_FEE_VALUE))?; + _ = watch!(erc20.mint(borrower_addr, FLASH_FEE_VALUE))?; let loan_amount = uint!(1_000_000_U256); let borrower_balance = erc20.balanceOf(borrower_addr).call().await?.balance; @@ -383,7 +383,7 @@ async fn flash_loan_reverts_when_loan_amount_greater_than_max_loan( let max_loan = U256::from(1); let loan_amount = U256::from(2); - let _ = watch!(erc20.mint(borrower_addr, U256::MAX - max_loan))?; + _ = watch!(erc20.mint(borrower_addr, U256::MAX - max_loan))?; let err = send!(erc20.flashLoan( borrower_addr, @@ -475,7 +475,7 @@ async fn flash_loan_reverts_when_invalid_receiver( let erc20 = Erc20FlashMint::new(erc20_addr, &alice.wallet); let borrower_addr = borrower::deploy(&alice.wallet, true, true).await?; - let _ = watch!(erc20.mint(borrower_addr, FLASH_FEE_VALUE))?; + _ = watch!(erc20.mint(borrower_addr, FLASH_FEE_VALUE))?; let loan_amount = U256::from(1); let invalid_receivers = &[alice.address(), Address::ZERO]; @@ -510,7 +510,7 @@ async fn flash_loan_reverts_when_receiver_callback_reverts( let erc20 = Erc20FlashMint::new(erc20_addr, &alice.wallet); let borrower_addr = borrower::deploy(&alice.wallet, true, true).await?; - let _ = watch!(erc20.mint(borrower_addr, FLASH_FEE_VALUE))?; + _ = watch!(erc20.mint(borrower_addr, FLASH_FEE_VALUE))?; let loan_amount = U256::from(1); let err = send!(erc20.flashLoan( @@ -541,7 +541,7 @@ async fn flash_loan_reverts_when_receiver_returns_invalid_callback_value( let erc20 = Erc20FlashMint::new(erc20_addr, &alice.wallet); let borrower_addr = borrower::deploy(&alice.wallet, false, true).await?; - let _ = watch!(erc20.mint(borrower_addr, FLASH_FEE_VALUE))?; + _ = watch!(erc20.mint(borrower_addr, FLASH_FEE_VALUE))?; let loan_amount = U256::from(1); let err = send!(erc20.flashLoan( @@ -572,7 +572,7 @@ async fn flash_loan_reverts_when_receiver_doesnt_approve_allowance( let erc20 = Erc20FlashMint::new(erc20_addr, &alice.wallet); let borrower_addr = borrower::deploy(&alice.wallet, true, false).await?; - let _ = watch!(erc20.mint(borrower_addr, FLASH_FEE_VALUE))?; + _ = watch!(erc20.mint(borrower_addr, FLASH_FEE_VALUE))?; let loan_amount = U256::from(1); let err = send!(erc20.flashLoan( diff --git a/examples/erc20-permit/tests/erc20permit.rs b/examples/erc20-permit/tests/erc20permit.rs index 022bd4162..590e04403 100644 --- a/examples/erc20-permit/tests/erc20permit.rs +++ b/examples/erc20-permit/tests/erc20permit.rs @@ -85,7 +85,7 @@ async fn error_when_expired_deadline_for_permit( let bob_addr = bob.address(); let balance = uint!(10_U256); - let _ = watch!(contract_alice.mint(alice_addr, balance))?; + _ = watch!(contract_alice.mint(alice_addr, balance))?; let struct_hash = permit_struct_hash( alice_addr, @@ -128,7 +128,7 @@ async fn permit_works(alice: Account, bob: Account) -> Result<()> { let bob_addr = bob.address(); let balance = uint!(10_U256); - let _ = watch!(contract_alice.mint(alice_addr, balance))?; + _ = watch!(contract_alice.mint(alice_addr, balance))?; let struct_hash = permit_struct_hash( alice_addr, @@ -219,7 +219,7 @@ async fn permit_rejects_reused_signature( let bob_addr = bob.address(); let balance = uint!(10_U256); - let _ = watch!(contract_alice.mint(alice_addr, balance))?; + _ = watch!(contract_alice.mint(alice_addr, balance))?; let struct_hash = permit_struct_hash( alice_addr, @@ -237,7 +237,7 @@ async fn permit_rejects_reused_signature( )) .await; - let _ = watch!(contract_alice.permit( + _ = watch!(contract_alice.permit( alice_addr, bob_addr, balance, @@ -294,7 +294,7 @@ async fn permit_rejects_invalid_signature( let bob_addr = bob.address(); let balance = uint!(10_U256); - let _ = watch!(contract_alice.mint(alice_addr, balance))?; + _ = watch!(contract_alice.mint(alice_addr, balance))?; let struct_hash = permit_struct_hash( alice_addr, @@ -417,7 +417,7 @@ async fn transfers(alice: Account, bob: Account) -> Result<()> { let balance = uint!(10_U256); let value = uint!(1_U256); - let _ = watch!(contract_alice.mint(alice.address(), balance))?; + _ = watch!(contract_alice.mint(alice.address(), balance))?; let Erc20Permit::balanceOfReturn { balance: initial_alice_balance } = contract_alice.balanceOf(alice_addr).call().await?; @@ -461,7 +461,7 @@ async fn transfer_rejects_insufficient_balance( let balance = uint!(10_U256); let value = uint!(11_U256); - let _ = watch!(contract_alice.mint(alice.address(), balance))?; + _ = watch!(contract_alice.mint(alice.address(), balance))?; let Erc20Permit::balanceOfReturn { balance: initial_alice_balance } = contract_alice.balanceOf(alice_addr).call().await?; @@ -502,7 +502,7 @@ async fn transfer_rejects_invalid_receiver(alice: Account) -> Result<()> { let balance = uint!(10_U256); let value = uint!(1_U256); - let _ = watch!(contract_alice.mint(alice.address(), balance))?; + _ = watch!(contract_alice.mint(alice.address(), balance))?; let Erc20Permit::balanceOfReturn { balance: initial_alice_balance } = contract_alice.balanceOf(alice_addr).call().await?; @@ -662,7 +662,7 @@ async fn transfers_from(alice: Account, bob: Account) -> Result<()> { let balance = uint!(10_U256); let value = uint!(1_U256); - let _ = watch!(contract_alice.mint(alice.address(), balance))?; + _ = watch!(contract_alice.mint(alice.address(), balance))?; let Erc20Permit::balanceOfReturn { balance: initial_alice_balance } = contract_alice.balanceOf(alice_addr).call().await?; @@ -671,7 +671,7 @@ async fn transfers_from(alice: Account, bob: Account) -> Result<()> { let Erc20Permit::totalSupplyReturn { totalSupply: initial_supply } = contract_alice.totalSupply().call().await?; - let _ = watch!(contract_alice.approve(bob_addr, balance))?; + _ = watch!(contract_alice.approve(bob_addr, balance))?; let Erc20Permit::allowanceReturn { allowance: initial_allowance } = contract_alice.allowance(alice_addr, bob_addr).call().await?; @@ -717,7 +717,7 @@ async fn transfer_from_reverts_insufficient_balance( let balance = uint!(1_U256); let value = uint!(10_U256); - let _ = watch!(contract_alice.mint(alice.address(), balance))?; + _ = watch!(contract_alice.mint(alice.address(), balance))?; let Erc20Permit::balanceOfReturn { balance: initial_alice_balance } = contract_alice.balanceOf(alice_addr).call().await?; @@ -726,7 +726,7 @@ async fn transfer_from_reverts_insufficient_balance( let Erc20Permit::totalSupplyReturn { totalSupply: initial_supply } = contract_alice.totalSupply().call().await?; - let _ = watch!(contract_alice.approve(bob_addr, value))?; + _ = watch!(contract_alice.approve(bob_addr, value))?; let Erc20Permit::allowanceReturn { allowance: initial_allowance } = contract_alice.allowance(alice_addr, bob_addr).call().await?; @@ -772,7 +772,7 @@ async fn transfer_from_rejects_insufficient_allowance( let balance = uint!(10_U256); let value = uint!(1_U256); - let _ = watch!(contract_alice.mint(alice.address(), balance))?; + _ = watch!(contract_alice.mint(alice.address(), balance))?; let Erc20Permit::balanceOfReturn { balance: initial_alice_balance } = contract_alice.balanceOf(alice_addr).call().await?; @@ -828,7 +828,7 @@ async fn transfer_from_rejects_invalid_receiver( let balance = uint!(10_U256); let value = uint!(1_U256); - let _ = watch!(contract_alice.mint(alice.address(), balance))?; + _ = watch!(contract_alice.mint(alice.address(), balance))?; let Erc20Permit::balanceOfReturn { balance: initial_alice_balance } = contract_alice.balanceOf(alice_addr).call().await?; @@ -837,7 +837,7 @@ async fn transfer_from_rejects_invalid_receiver( let Erc20Permit::totalSupplyReturn { totalSupply: initial_supply } = contract_alice.totalSupply().call().await?; - let _ = watch!(contract_alice.approve(bob_addr, balance))?; + _ = watch!(contract_alice.approve(bob_addr, balance))?; let Erc20Permit::allowanceReturn { allowance: initial_allowance } = contract_alice.allowance(alice_addr, bob_addr).call().await?; diff --git a/examples/erc20/tests/erc20.rs b/examples/erc20/tests/erc20.rs index 9aaca888f..30b3df59b 100644 --- a/examples/erc20/tests/erc20.rs +++ b/examples/erc20/tests/erc20.rs @@ -151,7 +151,7 @@ async fn mints_rejects_overflow(alice: Account) -> Result<()> { let one = uint!(1_U256); - let _ = watch!(contract.mint(alice_addr, max_cap))?; + _ = watch!(contract.mint(alice_addr, max_cap))?; let Erc20::balanceOfReturn { balance: initial_balance } = contract.balanceOf(alice_addr).call().await?; @@ -191,7 +191,7 @@ async fn transfers(alice: Account, bob: Account) -> Result<()> { let balance = uint!(10_U256); let value = uint!(1_U256); - let _ = watch!(contract_alice.mint(alice.address(), balance))?; + _ = watch!(contract_alice.mint(alice.address(), balance))?; let Erc20::balanceOfReturn { balance: initial_alice_balance } = contract_alice.balanceOf(alice_addr).call().await?; @@ -240,7 +240,7 @@ async fn transfer_rejects_insufficient_balance( let balance = uint!(10_U256); let value = uint!(11_U256); - let _ = watch!(contract_alice.mint(alice.address(), balance))?; + _ = watch!(contract_alice.mint(alice.address(), balance))?; let Erc20::balanceOfReturn { balance: initial_alice_balance } = contract_alice.balanceOf(alice_addr).call().await?; @@ -286,7 +286,7 @@ async fn transfer_rejects_invalid_receiver(alice: Account) -> Result<()> { let balance = uint!(10_U256); let value = uint!(1_U256); - let _ = watch!(contract_alice.mint(alice.address(), balance))?; + _ = watch!(contract_alice.mint(alice.address(), balance))?; let Erc20::balanceOfReturn { balance: initial_alice_balance } = contract_alice.balanceOf(alice_addr).call().await?; @@ -459,7 +459,7 @@ async fn transfers_from(alice: Account, bob: Account) -> Result<()> { let balance = uint!(10_U256); let value = uint!(1_U256); - let _ = watch!(contract_alice.mint(alice.address(), balance))?; + _ = watch!(contract_alice.mint(alice.address(), balance))?; let Erc20::balanceOfReturn { balance: initial_alice_balance } = contract_alice.balanceOf(alice_addr).call().await?; @@ -468,7 +468,7 @@ async fn transfers_from(alice: Account, bob: Account) -> Result<()> { let Erc20::totalSupplyReturn { totalSupply: initial_supply } = contract_alice.totalSupply().call().await?; - let _ = watch!(contract_alice.approve(bob_addr, balance))?; + _ = watch!(contract_alice.approve(bob_addr, balance))?; let Erc20::allowanceReturn { allowance: initial_allowance } = contract_alice.allowance(alice_addr, bob_addr).call().await?; @@ -519,7 +519,7 @@ async fn transfer_from_reverts_insufficient_balance( let balance = uint!(1_U256); let value = uint!(10_U256); - let _ = watch!(contract_alice.mint(alice.address(), balance))?; + _ = watch!(contract_alice.mint(alice.address(), balance))?; let Erc20::balanceOfReturn { balance: initial_alice_balance } = contract_alice.balanceOf(alice_addr).call().await?; @@ -528,7 +528,7 @@ async fn transfer_from_reverts_insufficient_balance( let Erc20::totalSupplyReturn { totalSupply: initial_supply } = contract_alice.totalSupply().call().await?; - let _ = watch!(contract_alice.approve(bob_addr, value))?; + _ = watch!(contract_alice.approve(bob_addr, value))?; let Erc20::allowanceReturn { allowance: initial_allowance } = contract_alice.allowance(alice_addr, bob_addr).call().await?; @@ -579,7 +579,7 @@ async fn transfer_from_rejects_insufficient_allowance( let balance = uint!(10_U256); let value = uint!(1_U256); - let _ = watch!(contract_alice.mint(alice.address(), balance))?; + _ = watch!(contract_alice.mint(alice.address(), balance))?; let Erc20::balanceOfReturn { balance: initial_alice_balance } = contract_alice.balanceOf(alice_addr).call().await?; @@ -640,7 +640,7 @@ async fn transfer_from_rejects_invalid_receiver( let balance = uint!(10_U256); let value = uint!(1_U256); - let _ = watch!(contract_alice.mint(alice.address(), balance))?; + _ = watch!(contract_alice.mint(alice.address(), balance))?; let Erc20::balanceOfReturn { balance: initial_alice_balance } = contract_alice.balanceOf(alice_addr).call().await?; @@ -649,7 +649,7 @@ async fn transfer_from_rejects_invalid_receiver( let Erc20::totalSupplyReturn { totalSupply: initial_supply } = contract_alice.totalSupply().call().await?; - let _ = watch!(contract_alice.approve(bob_addr, balance))?; + _ = watch!(contract_alice.approve(bob_addr, balance))?; let Erc20::allowanceReturn { allowance: initial_allowance } = contract_alice.allowance(alice_addr, bob_addr).call().await?; @@ -697,7 +697,7 @@ async fn burns(alice: Account) -> Result<()> { let balance = uint!(10_U256); let value = uint!(1_U256); - let _ = watch!(contract_alice.mint(alice.address(), balance))?; + _ = watch!(contract_alice.mint(alice.address(), balance))?; let Erc20::balanceOfReturn { balance: initial_balance } = contract_alice.balanceOf(alice_addr).call().await?; @@ -737,7 +737,7 @@ async fn burn_rejects_insufficient_balance(alice: Account) -> Result<()> { let balance = uint!(10_U256); let value = uint!(11_U256); - let _ = watch!(contract_alice.mint(alice.address(), balance))?; + _ = watch!(contract_alice.mint(alice.address(), balance))?; let Erc20::balanceOfReturn { balance: initial_balance } = contract_alice.balanceOf(alice_addr).call().await?; @@ -780,7 +780,7 @@ async fn burns_from(alice: Account, bob: Account) -> Result<()> { let balance = uint!(10_U256); let value = uint!(1_U256); - let _ = watch!(contract_alice.mint(alice.address(), balance))?; + _ = watch!(contract_alice.mint(alice.address(), balance))?; let Erc20::balanceOfReturn { balance: initial_alice_balance } = contract_alice.balanceOf(alice_addr).call().await?; @@ -789,7 +789,7 @@ async fn burns_from(alice: Account, bob: Account) -> Result<()> { let Erc20::totalSupplyReturn { totalSupply: initial_supply } = contract_alice.totalSupply().call().await?; - let _ = watch!(contract_alice.approve(bob_addr, balance))?; + _ = watch!(contract_alice.approve(bob_addr, balance))?; let Erc20::allowanceReturn { allowance: initial_allowance } = contract_alice.allowance(alice_addr, bob_addr).call().await?; @@ -839,7 +839,7 @@ async fn burn_from_reverts_insufficient_balance( let balance = uint!(1_U256); let value = uint!(10_U256); - let _ = watch!(contract_alice.mint(alice.address(), balance))?; + _ = watch!(contract_alice.mint(alice.address(), balance))?; let Erc20::balanceOfReturn { balance: initial_alice_balance } = contract_alice.balanceOf(alice_addr).call().await?; @@ -848,7 +848,7 @@ async fn burn_from_reverts_insufficient_balance( let Erc20::totalSupplyReturn { totalSupply: initial_supply } = contract_alice.totalSupply().call().await?; - let _ = watch!(contract_alice.approve(bob_addr, value))?; + _ = watch!(contract_alice.approve(bob_addr, value))?; let Erc20::allowanceReturn { allowance: initial_allowance } = contract_alice.allowance(alice_addr, bob_addr).call().await?; @@ -899,7 +899,7 @@ async fn burn_from_rejects_insufficient_allowance( let balance = uint!(10_U256); let value = uint!(1_U256); - let _ = watch!(contract_alice.mint(alice.address(), balance))?; + _ = watch!(contract_alice.mint(alice.address(), balance))?; let Erc20::balanceOfReturn { balance: initial_alice_balance } = contract_alice.balanceOf(alice_addr).call().await?; @@ -959,7 +959,7 @@ async fn mint_rejects_exceeding_cap(alice: Account) -> Result<()> { let cap = CAP; let balance = cap - one; - let _ = watch!(contract_alice.mint(alice_addr, balance))?; + _ = watch!(contract_alice.mint(alice_addr, balance))?; let Erc20::balanceOfReturn { balance: initial_balance } = contract_alice.balanceOf(alice_addr).call().await?; @@ -999,7 +999,7 @@ async fn mint_rejects_when_cap_reached(alice: Account) -> Result<()> { let cap = CAP; let balance = cap; - let _ = watch!(contract_alice.mint(alice_addr, balance))?; + _ = watch!(contract_alice.mint(alice_addr, balance))?; let Erc20::balanceOfReturn { balance: initial_balance } = contract_alice.balanceOf(alice_addr).call().await?; @@ -1077,7 +1077,7 @@ async fn pause_reverts_in_paused_state(alice: Account) -> eyre::Result<()> { let contract = Erc20::new(contract_addr, &alice.wallet); - let _ = watch!(contract.pause())?; + _ = watch!(contract.pause())?; let err = send!(contract.pause()).expect_err("should return `EnforcedPause`"); @@ -1097,7 +1097,7 @@ async fn unpauses(alice: Account) -> eyre::Result<()> { .address()?; let contract = Erc20::new(contract_addr, &alice.wallet); - let _ = watch!(contract.pause())?; + _ = watch!(contract.pause())?; let receipt = receipt!(contract.unpause())?; @@ -1147,14 +1147,14 @@ async fn error_when_burn_in_paused_state(alice: Account) -> Result<()> { let balance = uint!(10_U256); let value = uint!(1_U256); - let _ = watch!(contract.mint(alice.address(), balance))?; + _ = watch!(contract.mint(alice.address(), balance))?; let Erc20::balanceOfReturn { balance: initial_balance } = contract.balanceOf(alice_addr).call().await?; let Erc20::totalSupplyReturn { totalSupply: initial_supply } = contract.totalSupply().call().await?; - let _ = watch!(contract.pause())?; + _ = watch!(contract.pause())?; let err = send!(contract.burn(value)).expect_err("should return `EnforcedPause`"); @@ -1191,7 +1191,7 @@ async fn error_when_burn_from_in_paused_state( let balance = uint!(10_U256); let value = uint!(1_U256); - let _ = watch!(contract_alice.mint(alice.address(), balance))?; + _ = watch!(contract_alice.mint(alice.address(), balance))?; let Erc20::balanceOfReturn { balance: initial_alice_balance } = contract_alice.balanceOf(alice_addr).call().await?; @@ -1200,12 +1200,12 @@ async fn error_when_burn_from_in_paused_state( let Erc20::totalSupplyReturn { totalSupply: initial_supply } = contract_alice.totalSupply().call().await?; - let _ = watch!(contract_alice.approve(bob_addr, balance))?; + _ = watch!(contract_alice.approve(bob_addr, balance))?; let Erc20::allowanceReturn { allowance: initial_allowance } = contract_alice.allowance(alice_addr, bob_addr).call().await?; - let _ = watch!(contract_alice.pause())?; + _ = watch!(contract_alice.pause())?; let err = send!(contract_bob.burnFrom(alice_addr, value)) .expect_err("should return `EnforcedPause`"); @@ -1247,7 +1247,7 @@ async fn error_when_mint_in_paused_state(alice: Account) -> Result<()> { assert_eq!(U256::ZERO, initial_balance); assert_eq!(U256::ZERO, initial_supply); - let _ = watch!(contract.pause())?; + _ = watch!(contract.pause())?; let err = send!(contract.mint(alice_addr, uint!(1_U256))) .expect_err("should return `EnforcedPause`"); @@ -1280,7 +1280,7 @@ async fn error_when_transfer_in_paused_state( let balance = uint!(10_U256); - let _ = watch!(contract_alice.mint(alice.address(), balance))?; + _ = watch!(contract_alice.mint(alice.address(), balance))?; let Erc20::balanceOfReturn { balance: initial_alice_balance } = contract_alice.balanceOf(alice_addr).call().await?; @@ -1289,7 +1289,7 @@ async fn error_when_transfer_in_paused_state( let Erc20::totalSupplyReturn { totalSupply: initial_supply } = contract_alice.totalSupply().call().await?; - let _ = watch!(contract_alice.pause())?; + _ = watch!(contract_alice.pause())?; let err = send!(contract_alice.transfer(bob_addr, uint!(1_U256))) .expect_err("should return `EnforcedPause`"); @@ -1325,7 +1325,7 @@ async fn error_when_transfer_from(alice: Account, bob: Account) -> Result<()> { let balance = uint!(10_U256); - let _ = watch!(contract_alice.mint(alice.address(), balance))?; + _ = watch!(contract_alice.mint(alice.address(), balance))?; let Erc20::balanceOfReturn { balance: initial_alice_balance } = contract_alice.balanceOf(alice_addr).call().await?; @@ -1334,12 +1334,12 @@ async fn error_when_transfer_from(alice: Account, bob: Account) -> Result<()> { let Erc20::totalSupplyReturn { totalSupply: initial_supply } = contract_alice.totalSupply().call().await?; - let _ = watch!(contract_alice.approve(bob_addr, balance))?; + _ = watch!(contract_alice.approve(bob_addr, balance))?; let Erc20::allowanceReturn { allowance: initial_allowance } = contract_alice.allowance(alice_addr, bob_addr).call().await?; - let _ = watch!(contract_alice.pause())?; + _ = watch!(contract_alice.pause())?; let err = send!(contract_bob.transferFrom(alice_addr, bob_addr, uint!(1_U256))) diff --git a/examples/erc721-consecutive/tests/erc721-consecutive.rs b/examples/erc721-consecutive/tests/erc721-consecutive.rs index 740779a42..c94f3314d 100644 --- a/examples/erc721-consecutive/tests/erc721-consecutive.rs +++ b/examples/erc721-consecutive/tests/erc721-consecutive.rs @@ -71,7 +71,7 @@ async fn mints(alice: Account) -> eyre::Result<()> { assert_eq!(balance1, U256::from(batch_size)); let token_id = random_token_id(); - let _ = watch!(contract.mint(alice.address(), token_id))?; + _ = watch!(contract.mint(alice.address(), token_id))?; let Erc721::balanceOfReturn { balance: balance2 } = contract.balanceOf(alice.address()).call().await?; @@ -130,7 +130,7 @@ async fn transfers_from(alice: Account, bob: Account) -> eyre::Result<()> { let first_consecutive_token_id = U256::from(FIRST_CONSECUTIVE_ID); // Transfer first consecutive token from Alice to Bob. - let _ = watch!(contract.transferFrom( + _ = watch!(contract.transferFrom( alice.address(), bob.address(), first_consecutive_token_id @@ -150,13 +150,13 @@ async fn transfers_from(alice: Account, bob: Account) -> eyre::Result<()> { // Test non-consecutive mint. let token_id = random_token_id(); - let _ = watch!(contract.mint(alice.address(), token_id))?; + _ = watch!(contract.mint(alice.address(), token_id))?; let Erc721::balanceOfReturn { balance: alice_balance } = contract.balanceOf(alice.address()).call().await?; assert_eq!(alice_balance, uint!(1000_U256)); // Test transfer of the token that wasn't minted consecutive. - let _ = watch!(contract.transferFrom( + _ = watch!(contract.transferFrom( alice.address(), bob.address(), token_id @@ -206,7 +206,7 @@ async fn burns(alice: Account) -> eyre::Result<()> { // Check non-consecutive token burn. let non_consecutive_token_id = random_token_id(); - let _ = watch!(contract.mint(alice.address(), non_consecutive_token_id))?; + _ = watch!(contract.mint(alice.address(), non_consecutive_token_id))?; let Erc721::ownerOfReturn { ownerOf } = contract.ownerOf(non_consecutive_token_id).call().await?; assert_eq!(ownerOf, alice.address()); diff --git a/examples/erc721-metadata/tests/erc721.rs b/examples/erc721-metadata/tests/erc721.rs index de604757d..66c9e5af9 100644 --- a/examples/erc721-metadata/tests/erc721.rs +++ b/examples/erc721-metadata/tests/erc721.rs @@ -100,7 +100,7 @@ async fn return_empty_token_uri_when_without_base_uri_and_token_uri( let token_id = random_token_id(); - let _ = watch!(contract.mint(alice.address(), token_id))?; + _ = watch!(contract.mint(alice.address(), token_id))?; let Erc721::tokenURIReturn { tokenURI } = contract.tokenURI(token_id).call().await?; @@ -127,7 +127,7 @@ async fn return_token_uri_with_base_uri_and_without_token_uri( let token_id = random_token_id(); - let _ = watch!(contract.mint(alice.address(), token_id))?; + _ = watch!(contract.mint(alice.address(), token_id))?; let Erc721::tokenURIReturn { tokenURI } = contract.tokenURI(token_id).call().await?; @@ -153,7 +153,7 @@ async fn return_token_uri_with_base_uri_and_token_uri( let token_id = random_token_id(); - let _ = watch!(contract.mint(alice.address(), token_id))?; + _ = watch!(contract.mint(alice.address(), token_id))?; let token_uri = String::from( "blob/main/contracts/src/token/erc721/extensions/uri_storage.rs", @@ -204,7 +204,7 @@ async fn set_token_uri_before_mint(alice: Account) -> eyre::Result<()> { assert!(receipt.emits(Erc721::MetadataUpdate { tokenId: token_id })); - let _ = watch!(contract.mint(alice.address(), token_id))?; + _ = watch!(contract.mint(alice.address(), token_id))?; let Erc721::tokenURIReturn { tokenURI } = contract.tokenURI(token_id).call().await?; @@ -233,7 +233,7 @@ async fn return_token_uri_after_burn_and_remint( let token_id = random_token_id(); - let _ = watch!(contract.mint(alice.address(), token_id))?; + _ = watch!(contract.mint(alice.address(), token_id))?; let receipt = receipt!(contract.burn(token_id))?; diff --git a/examples/erc721/tests/erc721.rs b/examples/erc721/tests/erc721.rs index 97f8983c2..477036731 100644 --- a/examples/erc721/tests/erc721.rs +++ b/examples/erc721/tests/erc721.rs @@ -117,7 +117,7 @@ async fn error_when_minting_token_id_twice(alice: Account) -> eyre::Result<()> { let alice_addr = alice.address(); let token_id = random_token_id(); - let _ = watch!(contract.mint(alice_addr, token_id))?; + _ = watch!(contract.mint(alice_addr, token_id))?; let err = send!(contract.mint(alice_addr, token_id)) .expect_err("should not mint a token id twice"); @@ -154,7 +154,7 @@ async fn transfers_from(alice: Account, bob: Account) -> eyre::Result<()> { let alice_addr = alice.address(); let bob_addr = bob.address(); let token_id = random_token_id(); - let _ = watch!(contract.mint(alice_addr, token_id))?; + _ = watch!(contract.mint(alice_addr, token_id))?; let Erc721::balanceOfReturn { balance: initial_alice_balance } = contract.balanceOf(alice_addr).call().await?; @@ -201,8 +201,8 @@ async fn transfers_from_approved_token( let bob_addr = bob.address(); let token_id = random_token_id(); - let _ = watch!(contract_alice.mint(alice_addr, token_id))?; - let _ = watch!(contract_alice.approve(bob_addr, token_id))?; + _ = watch!(contract_alice.mint(alice_addr, token_id))?; + _ = watch!(contract_alice.approve(bob_addr, token_id))?; let Erc721::balanceOfReturn { balance: initial_alice_balance } = contract_alice.balanceOf(alice_addr).call().await?; @@ -249,8 +249,8 @@ async fn transfers_from_approved_for_all( let bob_addr = bob.address(); let token_id = random_token_id(); - let _ = watch!(contract_alice.mint(alice_addr, token_id))?; - let _ = watch!(contract_alice.setApprovalForAll(bob_addr, true))?; + _ = watch!(contract_alice.mint(alice_addr, token_id))?; + _ = watch!(contract_alice.setApprovalForAll(bob_addr, true))?; let Erc721::balanceOfReturn { balance: initial_alice_balance } = contract_alice.balanceOf(alice_addr).call().await?; @@ -295,7 +295,7 @@ async fn error_when_transfer_to_invalid_receiver( let invalid_receiver = Address::ZERO; let token_id = random_token_id(); - let _ = watch!(contract.mint(alice_addr, token_id))?; + _ = watch!(contract.mint(alice_addr, token_id))?; let err = send!(contract.transferFrom(alice_addr, invalid_receiver, token_id)) @@ -327,7 +327,7 @@ async fn error_when_transfer_from_incorrect_owner( let token_id = random_token_id(); - let _ = watch!(contract.mint(alice_addr, token_id))?; + _ = watch!(contract.mint(alice_addr, token_id))?; let err = send!(contract.transferFrom(dave_addr, bob_addr, token_id)) .expect_err("should not transfer the token from incorrect owner"); @@ -356,7 +356,7 @@ async fn error_when_transfer_with_insufficient_approval( let alice_addr = alice.address(); let bob_addr = bob.address(); let token_id = random_token_id(); - let _ = watch!(contract.mint(alice_addr, token_id))?; + _ = watch!(contract.mint(alice_addr, token_id))?; let contract = Erc721::new(contract_addr, &bob.wallet); let err = send!(contract.transferFrom(alice_addr, bob_addr, token_id)) @@ -412,7 +412,7 @@ async fn safe_transfers_from(alice: Account, bob: Account) -> eyre::Result<()> { let alice_addr = alice.address(); let bob_addr = bob.address(); let token_id = random_token_id(); - let _ = watch!(contract.mint(alice_addr, token_id))?; + _ = watch!(contract.mint(alice_addr, token_id))?; let Erc721::balanceOfReturn { balance: initial_alice_balance } = contract.balanceOf(alice_addr).call().await?; @@ -460,7 +460,7 @@ async fn safe_transfers_to_receiver_contract( let alice_addr = alice.address(); let token_id = random_token_id(); - let _ = watch!(contract.mint(alice_addr, token_id))?; + _ = watch!(contract.mint(alice_addr, token_id))?; let Erc721::balanceOfReturn { balance: initial_alice_balance } = contract.balanceOf(alice_addr).call().await?; @@ -517,8 +517,8 @@ async fn safe_transfers_from_approved_token( let bob_addr = bob.address(); let token_id = random_token_id(); - let _ = watch!(contract_alice.mint(alice_addr, token_id))?; - let _ = watch!(contract_alice.approve(bob_addr, token_id))?; + _ = watch!(contract_alice.mint(alice_addr, token_id))?; + _ = watch!(contract_alice.approve(bob_addr, token_id))?; let Erc721::balanceOfReturn { balance: initial_alice_balance } = contract_alice.balanceOf(alice_addr).call().await?; @@ -566,8 +566,8 @@ async fn safe_transfers_from_approved_for_all( let bob_addr = bob.address(); let token_id = random_token_id(); - let _ = watch!(contract_alice.mint(alice_addr, token_id))?; - let _ = watch!(contract_alice.setApprovalForAll(bob_addr, true))?; + _ = watch!(contract_alice.mint(alice_addr, token_id))?; + _ = watch!(contract_alice.setApprovalForAll(bob_addr, true))?; let Erc721::balanceOfReturn { balance: initial_alice_balance } = contract_alice.balanceOf(alice_addr).call().await?; @@ -613,7 +613,7 @@ async fn error_when_safe_transfer_to_invalid_receiver( let invalid_receiver = Address::ZERO; let token_id = random_token_id(); - let _ = watch!(contract.mint(alice_addr, token_id))?; + _ = watch!(contract.mint(alice_addr, token_id))?; let err = send!(contract.safeTransferFrom_0( alice_addr, @@ -647,7 +647,7 @@ async fn error_when_safe_transfer_from_incorrect_owner( let token_id = random_token_id(); - let _ = watch!(contract.mint(alice_addr, token_id))?; + _ = watch!(contract.mint(alice_addr, token_id))?; let err = send!(contract.safeTransferFrom_0(dave_addr, bob_addr, token_id)) .expect_err("should not transfer the token from incorrect owner"); @@ -676,7 +676,7 @@ async fn error_when_safe_transfer_with_insufficient_approval( let alice_addr = alice.address(); let bob_addr = bob.address(); let token_id = random_token_id(); - let _ = watch!(contract.mint(alice_addr, token_id))?; + _ = watch!(contract.mint(alice_addr, token_id))?; let contract = Erc721::new(contract_addr, &bob.wallet); @@ -738,7 +738,7 @@ async fn safe_transfers_from_with_data( let alice_addr = alice.address(); let bob_addr = bob.address(); let token_id = random_token_id(); - let _ = watch!(contract.mint(alice_addr, token_id))?; + _ = watch!(contract.mint(alice_addr, token_id))?; let Erc721::balanceOfReturn { balance: initial_alice_balance } = contract.balanceOf(alice_addr).call().await?; @@ -791,7 +791,7 @@ async fn safe_transfers_with_data_to_receiver_contract( let token_id = random_token_id(); let data: Bytes = fixed_bytes!("deadbeef").into(); - let _ = watch!(contract.mint(alice_addr, token_id))?; + _ = watch!(contract.mint(alice_addr, token_id))?; let Erc721::balanceOfReturn { balance: initial_alice_balance } = contract.balanceOf(alice_addr).call().await?; @@ -849,8 +849,8 @@ async fn safe_transfers_from_with_data_approved_token( let bob_addr = bob.address(); let token_id = random_token_id(); - let _ = watch!(contract_alice.mint(alice_addr, token_id))?; - let _ = watch!(contract_alice.approve(bob_addr, token_id))?; + _ = watch!(contract_alice.mint(alice_addr, token_id))?; + _ = watch!(contract_alice.approve(bob_addr, token_id))?; let Erc721::balanceOfReturn { balance: initial_alice_balance } = contract_alice.balanceOf(alice_addr).call().await?; @@ -901,8 +901,8 @@ async fn safe_transfers_from_with_data_approved_for_all( let bob_addr = bob.address(); let token_id = random_token_id(); - let _ = watch!(contract_alice.mint(alice_addr, token_id))?; - let _ = watch!(contract_alice.setApprovalForAll(bob_addr, true))?; + _ = watch!(contract_alice.mint(alice_addr, token_id))?; + _ = watch!(contract_alice.setApprovalForAll(bob_addr, true))?; let Erc721::balanceOfReturn { balance: initial_alice_balance } = contract_alice.balanceOf(alice_addr).call().await?; @@ -951,7 +951,7 @@ async fn error_when_safe_transfer_with_data_to_invalid_receiver( let invalid_receiver = Address::ZERO; let token_id = random_token_id(); - let _ = watch!(contract.mint(alice_addr, token_id))?; + _ = watch!(contract.mint(alice_addr, token_id))?; let err = send!(contract.safeTransferFrom_1( alice_addr, @@ -986,7 +986,7 @@ async fn error_when_safe_transfer_with_data_from_incorrect_owner( let token_id = random_token_id(); - let _ = watch!(contract.mint(alice_addr, token_id))?; + _ = watch!(contract.mint(alice_addr, token_id))?; let err = send!(contract.safeTransferFrom_1( dave_addr, @@ -1020,7 +1020,7 @@ async fn error_when_safe_transfer_with_data_with_insufficient_approval( let alice_addr = alice.address(); let bob_addr = bob.address(); let token_id = random_token_id(); - let _ = watch!(contract.mint(alice_addr, token_id))?; + _ = watch!(contract.mint(alice_addr, token_id))?; let contract = Erc721::new(contract_addr, &bob.wallet); @@ -1095,7 +1095,7 @@ async fn errors_when_receiver_reverts_with_reason( let alice_addr = alice.address(); let token_id = random_token_id(); - let _ = watch!(contract.mint(alice_addr, token_id))?; + _ = watch!(contract.mint(alice_addr, token_id))?; let err = send!(contract.safeTransferFrom_0( alice_addr, @@ -1127,7 +1127,7 @@ async fn errors_when_receiver_reverts_without_reason( let alice_addr = alice.address(); let token_id = random_token_id(); - let _ = watch!(contract.mint(alice_addr, token_id))?; + _ = watch!(contract.mint(alice_addr, token_id))?; let err = send!(contract.safeTransferFrom_0( alice_addr, @@ -1155,7 +1155,7 @@ async fn errors_when_receiver_panics(alice: Account) -> eyre::Result<()> { let alice_addr = alice.address(); let token_id = random_token_id(); - let _ = watch!(contract.mint(alice_addr, token_id))?; + _ = watch!(contract.mint(alice_addr, token_id))?; let err = send!(contract.safeTransferFrom_0( alice_addr, @@ -1180,7 +1180,7 @@ async fn approves(alice: Account, bob: Account) -> eyre::Result<()> { let bob_addr = bob.address(); let token_id = random_token_id(); - let _ = watch!(contract.mint(alice_addr, token_id))?; + _ = watch!(contract.mint(alice_addr, token_id))?; let Erc721::getApprovedReturn { approved } = contract.getApproved(token_id).call().await?; @@ -1235,7 +1235,7 @@ async fn error_when_approve_by_invalid_approver( let bob_addr = bob.address(); let token_id = random_token_id(); - let _ = watch!(contract_alice.mint(alice_addr, token_id))?; + _ = watch!(contract_alice.mint(alice_addr, token_id))?; let err = send!(contract_bob.approve(bob_addr, token_id)) .expect_err("should not approve when invalid approver"); @@ -1636,7 +1636,7 @@ async fn pause_reverts_in_paused_state(alice: Account) -> eyre::Result<()> { let contract = Erc721::new(contract_addr, &alice.wallet); - let _ = watch!(contract.pause())?; + _ = watch!(contract.pause())?; let err = send!(contract.pause()).expect_err("should return `EnforcedPause`"); @@ -1651,7 +1651,7 @@ async fn unpauses(alice: Account) -> eyre::Result<()> { let contract_addr = alice.as_deployer().deploy().await?.address()?; let contract = Erc721::new(contract_addr, &alice.wallet); - let _ = watch!(contract.pause())?; + _ = watch!(contract.pause())?; let receipt = receipt!(contract.unpause())?; @@ -1689,12 +1689,12 @@ async fn error_when_burn_in_paused_state(alice: Account) -> eyre::Result<()> { let alice_addr = alice.address(); let token_id = random_token_id(); - let _ = watch!(contract.mint(alice_addr, token_id))?; + _ = watch!(contract.mint(alice_addr, token_id))?; let Erc721::balanceOfReturn { balance: initial_balance } = contract.balanceOf(alice_addr).call().await?; - let _ = watch!(contract.pause()); + _ = watch!(contract.pause()); let err = send!(contract.burn(token_id)) .expect_err("should return `EnforcedPause`"); @@ -1721,7 +1721,7 @@ async fn error_when_mint_in_paused_state(alice: Account) -> eyre::Result<()> { let alice_addr = alice.address(); let token_id = random_token_id(); - let _ = watch!(contract.pause()); + _ = watch!(contract.pause())?; let err = send!(contract.mint(alice_addr, token_id)) .expect_err("should return `EnforcedPause`"); @@ -1755,7 +1755,7 @@ async fn error_when_transfer_in_paused_state( let alice_addr = alice.address(); let bob_addr = bob.address(); let token_id = random_token_id(); - let _ = watch!(contract.mint(alice_addr, token_id))?; + _ = watch!(contract.mint(alice_addr, token_id))?; let Erc721::balanceOfReturn { balance: initial_alice_balance } = contract.balanceOf(alice_addr).call().await?; @@ -1763,7 +1763,7 @@ async fn error_when_transfer_in_paused_state( let Erc721::balanceOfReturn { balance: initial_bob_balance } = contract.balanceOf(bob_addr).call().await?; - let _ = watch!(contract.pause()); + _ = watch!(contract.pause())?; let err = send!(contract.transferFrom(alice_addr, bob_addr, token_id)) .expect_err("should return `EnforcedPause`"); @@ -1796,7 +1796,7 @@ async fn error_when_safe_transfer_in_paused_state( let alice_addr = alice.address(); let bob_addr = bob.address(); let token_id = random_token_id(); - let _ = watch!(contract.mint(alice_addr, token_id))?; + _ = watch!(contract.mint(alice_addr, token_id))?; let Erc721::balanceOfReturn { balance: initial_alice_balance } = contract.balanceOf(alice_addr).call().await?; @@ -1804,7 +1804,7 @@ async fn error_when_safe_transfer_in_paused_state( let Erc721::balanceOfReturn { balance: initial_bob_balance } = contract.balanceOf(bob_addr).call().await?; - let _ = watch!(contract.pause()); + _ = watch!(contract.pause())?; let err = send!(contract.safeTransferFrom_0(alice_addr, bob_addr, token_id)) @@ -1838,7 +1838,7 @@ async fn error_when_safe_transfer_with_data_in_paused_state( let alice_addr = alice.address(); let bob_addr = bob.address(); let token_id = random_token_id(); - let _ = watch!(contract.mint(alice_addr, token_id))?; + _ = watch!(contract.mint(alice_addr, token_id))?; let Erc721::balanceOfReturn { balance: initial_alice_balance } = contract.balanceOf(alice_addr).call().await?; @@ -1846,7 +1846,7 @@ async fn error_when_safe_transfer_with_data_in_paused_state( let Erc721::balanceOfReturn { balance: initial_bob_balance } = contract.balanceOf(bob_addr).call().await?; - let _ = watch!(contract.pause()); + _ = watch!(contract.pause())?; let err = send!(contract.safeTransferFrom_1( alice_addr, @@ -1886,7 +1886,7 @@ async fn error_when_safe_mint_in_paused_state( let Erc721::balanceOfReturn { balance: initial_alice_balance } = contract.balanceOf(alice_addr).call().await?; - let _ = watch!(contract.pause())?; + _ = watch!(contract.pause())?; let err = send!(contract.safeMint( alice_addr, @@ -1925,7 +1925,7 @@ async fn burns(alice: Account) -> eyre::Result<()> { let alice_addr = alice.address(); let token_id = random_token_id(); - let _ = watch!(contract.mint(alice_addr, token_id))?; + _ = watch!(contract.mint(alice_addr, token_id))?; let Erc721::balanceOfReturn { balance: initial_balance } = contract.balanceOf(alice_addr).call().await?; @@ -1969,8 +1969,8 @@ async fn burns_approved_token( let bob_addr = bob.address(); let token_id = random_token_id(); - let _ = watch!(contract_alice.mint(alice_addr, token_id))?; - let _ = watch!(contract_alice.approve(bob_addr, token_id))?; + _ = watch!(contract_alice.mint(alice_addr, token_id))?; + _ = watch!(contract_alice.approve(bob_addr, token_id))?; let Erc721::balanceOfReturn { balance: initial_balance } = contract_alice.balanceOf(alice_addr).call().await?; @@ -2014,8 +2014,8 @@ async fn burns_approved_for_all( let bob_addr = bob.address(); let token_id = random_token_id(); - let _ = watch!(contract_alice.mint(alice_addr, token_id))?; - let _ = watch!(contract_alice.setApprovalForAll(bob_addr, true))?; + _ = watch!(contract_alice.mint(alice_addr, token_id))?; + _ = watch!(contract_alice.setApprovalForAll(bob_addr, true))?; let Erc721::balanceOfReturn { balance: initial_balance } = contract_alice.balanceOf(alice_addr).call().await?; @@ -2057,7 +2057,7 @@ async fn error_when_burn_with_insufficient_approval( let alice_addr = alice.address(); let bob_addr = bob.address(); let token_id = random_token_id(); - let _ = watch!(contract.mint(alice_addr, token_id))?; + _ = watch!(contract.mint(alice_addr, token_id))?; let Erc721::balanceOfReturn { balance: initial_balance } = contract.balanceOf(alice_addr).call().await?; @@ -2106,10 +2106,10 @@ async fn totally_supply_works(alice: Account) -> eyre::Result<()> { let alice_addr = alice.address(); let token_1 = random_token_id(); - let _ = watch!(contract.mint(alice_addr, token_1))?; + _ = watch!(contract.mint(alice_addr, token_1))?; let token_2 = random_token_id(); - let _ = watch!(contract.mint(alice_addr, token_2))?; + _ = watch!(contract.mint(alice_addr, token_2))?; let Erc721::totalSupplyReturn { totalSupply } = contract.totalSupply().call().await?; @@ -2128,8 +2128,8 @@ async fn error_when_checking_token_of_owner_by_index_out_of_bound( let alice_addr = alice.address(); - let _ = watch!(contract.mint(alice_addr, random_token_id()))?; - let _ = watch!(contract.mint(alice_addr, random_token_id()))?; + _ = watch!(contract.mint(alice_addr, random_token_id()))?; + _ = watch!(contract.mint(alice_addr, random_token_id()))?; let index_out_of_bound = uint!(2_U256); @@ -2180,10 +2180,10 @@ async fn token_of_owner_by_index_works(alice: Account) -> eyre::Result<()> { let alice_addr = alice.address(); let token_0 = random_token_id(); - let _ = watch!(contract.mint(alice_addr, token_0))?; + _ = watch!(contract.mint(alice_addr, token_0))?; let token_1 = random_token_id(); - let _ = watch!(contract.mint(alice_addr, token_1))?; + _ = watch!(contract.mint(alice_addr, token_1))?; let Erc721::tokenOfOwnerByIndexReturn { tokenId } = contract.tokenOfOwnerByIndex(alice_addr, uint!(0_U256)).call().await?; @@ -2208,13 +2208,13 @@ async fn token_of_owner_by_index_after_transfer_to_another_account( let bob_addr = bob.address(); let token_0 = random_token_id(); - let _ = watch!(contract.mint(alice_addr, token_0))?; + _ = watch!(contract.mint(alice_addr, token_0))?; let token_1 = random_token_id(); - let _ = watch!(contract.mint(alice_addr, token_1))?; + _ = watch!(contract.mint(alice_addr, token_1))?; - let _ = watch!(contract.transferFrom(alice_addr, bob_addr, token_1))?; - let _ = watch!(contract.transferFrom(alice_addr, bob_addr, token_0))?; + _ = watch!(contract.transferFrom(alice_addr, bob_addr, token_1))?; + _ = watch!(contract.transferFrom(alice_addr, bob_addr, token_0))?; // should be in reverse order let index = uint!(0_U256); @@ -2285,8 +2285,8 @@ async fn error_when_checking_token_by_index_out_of_bound( let alice_addr = alice.address(); - let _ = watch!(contract.mint(alice_addr, random_token_id()))?; - let _ = watch!(contract.mint(alice_addr, random_token_id()))?; + _ = watch!(contract.mint(alice_addr, random_token_id()))?; + _ = watch!(contract.mint(alice_addr, random_token_id()))?; let index_out_of_bound = uint!(2_U256); @@ -2312,10 +2312,10 @@ async fn token_by_index_works(alice: Account) -> eyre::Result<()> { let alice_addr = alice.address(); let token_0 = random_token_id(); - let _ = watch!(contract.mint(alice_addr, token_0))?; + _ = watch!(contract.mint(alice_addr, token_0))?; let token_1 = random_token_id(); - let _ = watch!(contract.mint(alice_addr, token_1))?; + _ = watch!(contract.mint(alice_addr, token_1))?; let Erc721::tokenByIndexReturn { tokenId } = contract.tokenByIndex(uint!(0_U256)).call().await?; @@ -2336,12 +2336,12 @@ async fn token_by_index_after_burn(alice: Account) -> eyre::Result<()> { let alice_addr = alice.address(); let token_0 = random_token_id(); - let _ = watch!(contract.mint(alice_addr, token_0))?; + _ = watch!(contract.mint(alice_addr, token_0))?; let token_1 = random_token_id(); - let _ = watch!(contract.mint(alice_addr, token_1))?; + _ = watch!(contract.mint(alice_addr, token_1))?; - let _ = watch!(contract.burn(token_1))?; + _ = watch!(contract.burn(token_1))?; let Erc721::tokenByIndexReturn { tokenId } = contract.tokenByIndex(uint!(0_U256)).call().await?; @@ -2377,18 +2377,18 @@ async fn token_by_index_after_burn_and_some_mints( let alice_addr = alice.address(); let token_0 = random_token_id(); - let _ = watch!(contract.mint(alice_addr, token_0))?; + _ = watch!(contract.mint(alice_addr, token_0))?; let token_1 = random_token_id(); - let _ = watch!(contract.mint(alice_addr, token_1))?; + _ = watch!(contract.mint(alice_addr, token_1))?; - let _ = watch!(contract.burn(token_1))?; + _ = watch!(contract.burn(token_1))?; let token_2 = random_token_id(); - let _ = watch!(contract.mint(alice_addr, token_2))?; + _ = watch!(contract.mint(alice_addr, token_2))?; let token_3 = random_token_id(); - let _ = watch!(contract.mint(alice_addr, token_3))?; + _ = watch!(contract.mint(alice_addr, token_3))?; let Erc721::tokenByIndexReturn { tokenId } = contract.tokenByIndex(uint!(0_U256)).call().await?; diff --git a/examples/safe-erc20/tests/erc20.rs b/examples/safe-erc20/tests/erc20.rs index ae534333e..b5d5569df 100644 --- a/examples/safe-erc20/tests/erc20.rs +++ b/examples/safe-erc20/tests/erc20.rs @@ -30,7 +30,7 @@ mod transfers { let erc20_address = erc20::deploy(&alice.wallet).await?; let erc20_alice = ERC20Mock::new(erc20_address, &alice.wallet); - let _ = watch!(erc20_alice.mint(safe_erc20_addr, balance)); + _ = watch!(erc20_alice.mint(safe_erc20_addr, balance))?; let initial_safe_erc20_balance = erc20_alice.balanceOf(safe_erc20_addr).call().await?._0; @@ -117,8 +117,8 @@ mod transfers { let erc20_address = erc20::deploy(&alice.wallet).await?; let erc20_alice = ERC20Mock::new(erc20_address, &alice.wallet); - let _ = watch!(erc20_alice.mint(alice_addr, balance)); - let _ = watch!(erc20_alice.approve(safe_erc20_addr, value)); + _ = watch!(erc20_alice.mint(alice_addr, balance))?; + _ = watch!(erc20_alice.approve(safe_erc20_addr, value))?; let initial_alice_balance = erc20_alice.balanceOf(alice_addr).call().await?._0; @@ -164,7 +164,7 @@ mod transfers { let erc20_address = erc20::deploy(&alice.wallet).await?; let erc20_alice = ERC20Mock::new(erc20_address, &alice.wallet); - let _ = watch!(erc20_alice.approve(safe_erc20_addr, value)); + _ = watch!(erc20_alice.approve(safe_erc20_addr, value))?; let initial_alice_balance = erc20_alice.balanceOf(alice_addr).call().await?._0; @@ -210,11 +210,11 @@ mod approvals { let erc20_address = erc20::deploy(&alice.wallet).await?; let erc20_alice = ERC20Mock::new(erc20_address, &alice.wallet); - let _ = watch!(erc20_alice.regular_approve( + _ = watch!(erc20_alice.regular_approve( safe_erc20_addr, spender_addr, U256::ZERO - )); + ))?; let value = uint!(100_U256); @@ -253,11 +253,11 @@ mod approvals { let erc20_address = erc20::deploy(&alice.wallet).await?; let erc20_alice = ERC20Mock::new(erc20_address, &alice.wallet); - let _ = watch!(erc20_alice.regular_approve( + _ = watch!(erc20_alice.regular_approve( safe_erc20_addr, spender_addr, U256::ZERO - )); + ))?; let receipt = receipt!(safe_erc20_alice.forceApprove( erc20_address, @@ -294,11 +294,11 @@ mod approvals { let erc20_address = erc20::deploy(&alice.wallet).await?; let erc20_alice = ERC20Mock::new(erc20_address, &alice.wallet); - let _ = watch!(erc20_alice.regular_approve( + _ = watch!(erc20_alice.regular_approve( safe_erc20_addr, spender_addr, U256::ZERO - )); + ))?; let value = uint!(10_U256); @@ -337,11 +337,11 @@ mod approvals { let erc20_address = erc20::deploy(&alice.wallet).await?; let erc20_alice = ERC20Mock::new(erc20_address, &alice.wallet); - let _ = watch!(erc20_alice.regular_approve( + _ = watch!(erc20_alice.regular_approve( safe_erc20_addr, spender_addr, U256::MAX - )); + ))?; let value = uint!(1_U256); @@ -370,11 +370,11 @@ mod approvals { let erc20_address = erc20::deploy(&alice.wallet).await?; let erc20_alice = ERC20Mock::new(erc20_address, &alice.wallet); - let _ = watch!(erc20_alice.regular_approve( + _ = watch!(erc20_alice.regular_approve( safe_erc20_addr, spender_addr, U256::ZERO - )); + ))?; let value = uint!(10_U256); @@ -414,11 +414,11 @@ mod approvals { let allowance = uint!(100_U256); - let _ = watch!(erc20_alice.regular_approve( + _ = watch!(erc20_alice.regular_approve( safe_erc20_addr, spender_addr, allowance - )); + ))?; let value = uint!(20_U256); @@ -459,11 +459,11 @@ mod approvals { let allowance = uint!(100_U256); - let _ = watch!(erc20_alice.regular_approve( + _ = watch!(erc20_alice.regular_approve( safe_erc20_addr, spender_addr, allowance - )); + ))?; let receipt = receipt!(safe_erc20_alice.forceApprove( erc20_address, @@ -502,11 +502,11 @@ mod approvals { let allowance = uint!(100_U256); - let _ = watch!(erc20_alice.regular_approve( + _ = watch!(erc20_alice.regular_approve( safe_erc20_addr, spender_addr, allowance - )); + ))?; let value = uint!(10_U256); @@ -547,11 +547,11 @@ mod approvals { let allowance = uint!(100_U256); - let _ = watch!(erc20_alice.regular_approve( + _ = watch!(erc20_alice.regular_approve( safe_erc20_addr, spender_addr, allowance - )); + ))?; let value = uint!(50_U256); @@ -592,11 +592,11 @@ mod approvals { let allowance = uint!(100_U256); - let _ = watch!(erc20_alice.regular_approve( + _ = watch!(erc20_alice.regular_approve( safe_erc20_addr, spender_addr, allowance - )); + ))?; let value = uint!(200_U256); diff --git a/examples/safe-erc20/tests/erc20_that_does_not_return.rs b/examples/safe-erc20/tests/erc20_that_does_not_return.rs index 9fbffe3f9..d591677b5 100644 --- a/examples/safe-erc20/tests/erc20_that_does_not_return.rs +++ b/examples/safe-erc20/tests/erc20_that_does_not_return.rs @@ -30,7 +30,7 @@ mod transfers { let erc20_address = erc20_no_return::deploy(&alice.wallet).await?; let erc20_alice = ERC20NoReturnMock::new(erc20_address, &alice.wallet); - let _ = watch!(erc20_alice.mint(safe_erc20_addr, balance)); + _ = watch!(erc20_alice.mint(safe_erc20_addr, balance))?; let initial_safe_erc20_balance = erc20_alice.balanceOf(safe_erc20_addr).call().await?._0; @@ -116,8 +116,8 @@ mod transfers { let erc20_address = erc20_no_return::deploy(&alice.wallet).await?; let erc20_alice = ERC20NoReturnMock::new(erc20_address, &alice.wallet); - let _ = watch!(erc20_alice.mint(alice_addr, balance)); - let _ = watch!(erc20_alice.approve(safe_erc20_addr, value)); + _ = watch!(erc20_alice.mint(alice_addr, balance))?; + _ = watch!(erc20_alice.approve(safe_erc20_addr, value))?; let initial_alice_balance = erc20_alice.balanceOf(alice_addr).call().await?._0; @@ -163,7 +163,7 @@ mod transfers { let erc20_address = erc20_no_return::deploy(&alice.wallet).await?; let erc20_alice = ERC20NoReturnMock::new(erc20_address, &alice.wallet); - let _ = watch!(erc20_alice.approve(safe_erc20_addr, value)); + _ = watch!(erc20_alice.approve(safe_erc20_addr, value))?; let initial_alice_balance = erc20_alice.balanceOf(alice_addr).call().await?._0; @@ -209,11 +209,11 @@ mod approvals { let erc20_alice = ERC20NoReturnMock::new(erc20_address, &alice.wallet); - let _ = watch!(erc20_alice.regular_approve( + _ = watch!(erc20_alice.regular_approve( safe_erc20_addr, spender_addr, U256::ZERO - )); + ))?; let value = uint!(100_U256); @@ -253,11 +253,11 @@ mod approvals { let erc20_alice = ERC20NoReturnMock::new(erc20_address, &alice.wallet); - let _ = watch!(erc20_alice.regular_approve( + _ = watch!(erc20_alice.regular_approve( safe_erc20_addr, spender_addr, U256::ZERO - )); + ))?; let receipt = receipt!(safe_erc20_alice.forceApprove( erc20_address, @@ -295,11 +295,11 @@ mod approvals { let erc20_alice = ERC20NoReturnMock::new(erc20_address, &alice.wallet); - let _ = watch!(erc20_alice.regular_approve( + _ = watch!(erc20_alice.regular_approve( safe_erc20_addr, spender_addr, U256::ZERO - )); + ))?; let value = uint!(10_U256); @@ -339,11 +339,11 @@ mod approvals { let erc20_alice = ERC20NoReturnMock::new(erc20_address, &alice.wallet); - let _ = watch!(erc20_alice.regular_approve( + _ = watch!(erc20_alice.regular_approve( safe_erc20_addr, spender_addr, U256::MAX - )); + ))?; let value = uint!(1_U256); @@ -373,11 +373,11 @@ mod approvals { let erc20_alice = ERC20NoReturnMock::new(erc20_address, &alice.wallet); - let _ = watch!(erc20_alice.regular_approve( + _ = watch!(erc20_alice.regular_approve( safe_erc20_addr, spender_addr, U256::ZERO - )); + ))?; let value = uint!(10_U256); @@ -418,11 +418,11 @@ mod approvals { let allowance = uint!(100_U256); - let _ = watch!(erc20_alice.regular_approve( + _ = watch!(erc20_alice.regular_approve( safe_erc20_addr, spender_addr, allowance - )); + ))?; let value = uint!(20_U256); @@ -464,11 +464,11 @@ mod approvals { let allowance = uint!(100_U256); - let _ = watch!(erc20_alice.regular_approve( + _ = watch!(erc20_alice.regular_approve( safe_erc20_addr, spender_addr, allowance - )); + ))?; let receipt = receipt!(safe_erc20_alice.forceApprove( erc20_address, @@ -508,11 +508,11 @@ mod approvals { let allowance = uint!(100_U256); - let _ = watch!(erc20_alice.regular_approve( + _ = watch!(erc20_alice.regular_approve( safe_erc20_addr, spender_addr, allowance - )); + ))?; let value = uint!(10_U256); @@ -554,11 +554,11 @@ mod approvals { let allowance = uint!(100_U256); - let _ = watch!(erc20_alice.regular_approve( + _ = watch!(erc20_alice.regular_approve( safe_erc20_addr, spender_addr, allowance - )); + ))?; let value = uint!(50_U256); @@ -600,11 +600,11 @@ mod approvals { let allowance = uint!(100_U256); - let _ = watch!(erc20_alice.regular_approve( + _ = watch!(erc20_alice.regular_approve( safe_erc20_addr, spender_addr, allowance - )); + ))?; let value = uint!(200_U256); diff --git a/examples/safe-erc20/tests/usdt_approval_behavior.rs b/examples/safe-erc20/tests/usdt_approval_behavior.rs index 9530a3ca0..1290c1d25 100644 --- a/examples/safe-erc20/tests/usdt_approval_behavior.rs +++ b/examples/safe-erc20/tests/usdt_approval_behavior.rs @@ -23,11 +23,11 @@ async fn safe_increase_allowance_works( let init_approval = uint!(100_U256); let value = uint!(10_U256); - let _ = watch!(erc20_alice.regular_approve( + _ = watch!(erc20_alice.regular_approve( safe_erc20_addr, bob_addr, init_approval - )); + ))?; let initial_bob_allowance = erc20_alice.allowance(safe_erc20_addr, bob_addr).call().await?._0; @@ -67,11 +67,11 @@ async fn safe_decrease_allowance_works( let init_approval = uint!(100_U256); let value = uint!(10_U256); - let _ = watch!(erc20_alice.regular_approve( + _ = watch!(erc20_alice.regular_approve( safe_erc20_addr, bob_addr, init_approval - )); + ))?; let initial_bob_allowance = erc20_alice.allowance(safe_erc20_addr, bob_addr).call().await?._0; @@ -108,11 +108,11 @@ async fn force_approve_works(alice: Account, bob: Account) -> eyre::Result<()> { let init_approval = uint!(100_U256); let updated_approval = uint!(10_U256); - let _ = watch!(erc20_alice.regular_approve( + _ = watch!(erc20_alice.regular_approve( safe_erc20_addr, bob_addr, init_approval - )); + ))?; let initial_bob_allowance = erc20_alice.allowance(safe_erc20_addr, bob_addr).call().await?._0; diff --git a/examples/vesting-wallet/tests/vesting-wallet.rs b/examples/vesting-wallet/tests/vesting-wallet.rs index d292b8b7f..e1d6f3973 100644 --- a/examples/vesting-wallet/tests/vesting-wallet.rs +++ b/examples/vesting-wallet/tests/vesting-wallet.rs @@ -121,7 +121,7 @@ mod ether_vesting { .address()?; let contract = VestingWallet::new(contract_addr, &account.wallet); - let _ = watch!(contract.receiveEther().value(U256::from(allocation)))?; + _ = watch!(contract.receiveEther().value(U256::from(allocation)))?; Ok(contract_addr) } @@ -248,7 +248,7 @@ mod erc20_vesting { ) -> eyre::Result
{ let erc20_address = erc20::deploy(&account.wallet).await?; let erc20 = ERC20Mock::new(erc20_address, &account.wallet); - let _ = watch!(erc20.mint(mint_to, allocation))?; + _ = watch!(erc20.mint(mint_to, allocation))?; Ok(erc20_address) } @@ -263,7 +263,7 @@ mod erc20_vesting { let erc20_address = erc20_return_false::deploy(&account.wallet).await?; let erc20 = ERC20ReturnFalseMock::new(erc20_address, &account.wallet); - let _ = watch!(erc20.mint(mint_to, U256::from(allocation)))?; + _ = watch!(erc20.mint(mint_to, U256::from(allocation)))?; Ok(erc20_address) } From 601e3ddf8ef53903d5796105abc3d030f241fa8b Mon Sep 17 00:00:00 2001 From: Alisander Qoshqosh Date: Thu, 6 Feb 2025 16:33:34 +0400 Subject: [PATCH 107/109] remove unrelated todo --- contracts/src/token/erc20/extensions/erc4626.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/contracts/src/token/erc20/extensions/erc4626.rs b/contracts/src/token/erc20/extensions/erc4626.rs index dd3250f81..a8b733f26 100644 --- a/contracts/src/token/erc20/extensions/erc4626.rs +++ b/contracts/src/token/erc20/extensions/erc4626.rs @@ -1143,7 +1143,6 @@ impl Erc4626 { } } -// TODO#q: Add missing tests once `motsu` supports calling external contracts. #[cfg(all(test, feature = "std"))] mod tests { use alloy_primitives::{address, Address, U256, U8}; From 03dd1969a743f5e49bbb88537a6228da1ac94619 Mon Sep 17 00:00:00 2001 From: Daniel Bigos Date: Fri, 7 Feb 2025 14:10:24 +0100 Subject: [PATCH 108/109] chore: bring back TODO comment Co-authored-by: Nenad --- contracts/src/token/erc20/extensions/erc4626.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/contracts/src/token/erc20/extensions/erc4626.rs b/contracts/src/token/erc20/extensions/erc4626.rs index a8b733f26..410446814 100644 --- a/contracts/src/token/erc20/extensions/erc4626.rs +++ b/contracts/src/token/erc20/extensions/erc4626.rs @@ -1143,6 +1143,7 @@ impl Erc4626 { } } +// TODO: Add missing tests once `motsu` supports calling external contracts. #[cfg(all(test, feature = "std"))] mod tests { use alloy_primitives::{address, Address, U256, U8}; From d0d23e22b787d504807fc80f1d3d1ed4426c8885 Mon Sep 17 00:00:00 2001 From: Daniel Bigos Date: Fri, 7 Feb 2025 14:36:14 +0100 Subject: [PATCH 109/109] ref: improve code style --- GUIDELINES.md | 2 +- benches/src/erc721.rs | 6 +- benches/src/lib.rs | 2 +- benches/src/vesting_wallet.rs | 4 +- contracts/src/access/ownable.rs | 9 +- .../src/token/erc1155/extensions/supply.rs | 2 + .../src/token/erc20/extensions/flash_mint.rs | 12 +- .../src/token/erc721/extensions/burnable.rs | 3 +- .../token/erc721/extensions/consecutive.rs | 3 +- contracts/src/token/erc721/mod.rs | 5 +- contracts/src/utils/math/alloy.rs | 2 + .../access-control/tests/access_control.rs | 18 +- .../tests/erc1155-metadata-uri.rs | 4 +- .../erc1155-supply/tests/erc1155-supply.rs | 48 ++-- examples/erc1155/tests/erc1155.rs | 116 ++++----- .../tests/erc20-flash-mint.rs | 20 +- examples/erc20-permit/tests/erc20permit.rs | 30 +-- examples/erc20/tests/erc20.rs | 66 ++--- examples/erc4626/tests/erc4626.rs | 228 ++++++++---------- .../tests/erc721-consecutive.rs | 14 +- examples/erc721-metadata/tests/erc721.rs | 10 +- examples/erc721/tests/erc721.rs | 146 +++++------ examples/safe-erc20/tests/erc20.rs | 28 +-- .../tests/erc20_that_does_not_return.rs | 28 +-- .../tests/usdt_approval_behavior.rs | 6 +- .../vesting-wallet/tests/vesting-wallet.rs | 6 +- fuzz/fuzz_targets/keccak/memory_safety.rs | 4 +- 27 files changed, 383 insertions(+), 439 deletions(-) diff --git a/GUIDELINES.md b/GUIDELINES.md index 537df22de..493bd82d8 100644 --- a/GUIDELINES.md +++ b/GUIDELINES.md @@ -249,7 +249,7 @@ Then you will be able to run e2e tests: ### Running fuzz tests -To run fuzz tests, you need to have [cargo-fuzz] installed. +To run fuzz tests, you need to have [cargo-fuzz] installed. Then from the root of the project you can use `cargo fuzz list` to view the list of all existing fuzz targets: ```shell diff --git a/benches/src/erc721.rs b/benches/src/erc721.rs index 9f56b8fef..2791f099a 100644 --- a/benches/src/erc721.rs +++ b/benches/src/erc721.rs @@ -57,9 +57,9 @@ pub async fn run(cache_opt: Opt) -> eyre::Result> { let token_3 = uint!(3_U256); let token_4 = uint!(4_U256); - _ = receipt!(contract.mint(alice_addr, token_2))?; - _ = receipt!(contract.mint(alice_addr, token_3))?; - _ = receipt!(contract.mint(alice_addr, token_4))?; + receipt!(contract.mint(alice_addr, token_2))?; + receipt!(contract.mint(alice_addr, token_3))?; + receipt!(contract.mint(alice_addr, token_4))?; // IMPORTANT: Order matters! use Erc721::*; diff --git a/benches/src/lib.rs b/benches/src/lib.rs index a5ef29c46..f674cc6c4 100644 --- a/benches/src/lib.rs +++ b/benches/src/lib.rs @@ -125,7 +125,7 @@ fn cache_contract( ) -> eyre::Result<()> { // We don't need a status code. // Since it is not zero when the contract is already cached. - _ = Command::new("cargo") + Command::new("cargo") .args(["stylus", "cache", "bid"]) .args(["-e", &env("RPC_URL")?]) .args(["--private-key", &format!("0x{}", account.pk())]) diff --git a/benches/src/vesting_wallet.rs b/benches/src/vesting_wallet.rs index ef1610905..ddc175171 100644 --- a/benches/src/vesting_wallet.rs +++ b/benches/src/vesting_wallet.rs @@ -66,8 +66,8 @@ pub async fn run(cache_opt: Opt) -> eyre::Result> { let contract = VestingWallet::new(contract_addr, &alice_wallet); let erc20 = Erc20::new(erc20_addr, &alice_wallet); - _ = receipt!(contract.receiveEther().value(uint!(1000_U256)))?; - _ = receipt!(erc20.mint(contract_addr, uint!(1000_U256)))?; + receipt!(contract.receiveEther().value(uint!(1000_U256)))?; + receipt!(erc20.mint(contract_addr, uint!(1000_U256)))?; // IMPORTANT: Order matters! use VestingWallet::*; diff --git a/contracts/src/access/ownable.rs b/contracts/src/access/ownable.rs index 1c7d000f2..6fe36f793 100644 --- a/contracts/src/access/ownable.rs +++ b/contracts/src/access/ownable.rs @@ -203,7 +203,7 @@ impl Ownable { mod tests { use alloy_primitives::Address; use motsu::prelude::Contract; - use stylus_sdk::{msg, prelude::TopLevelStorage}; + use stylus_sdk::prelude::TopLevelStorage; use super::{Error, IOwnable, Ownable}; @@ -213,7 +213,7 @@ mod tests { fn reads_owner(contract: Contract, alice: Address) { contract.init(alice, |contract| contract._owner.set(alice)); let owner = contract.sender(alice).owner(); - assert_eq!(owner, msg::sender()); + assert_eq!(owner, alice); } #[motsu::test] @@ -265,7 +265,10 @@ mod tests { ) { contract.init(alice, |contract| contract._owner.set(alice)); - _ = contract.sender(alice).renounce_ownership(); + contract + .sender(alice) + .renounce_ownership() + .expect("should renounce ownership"); let owner = contract.sender(alice).owner(); assert_eq!(owner, Address::ZERO); } diff --git a/contracts/src/token/erc1155/extensions/supply.rs b/contracts/src/token/erc1155/extensions/supply.rs index 65cb32c19..bf30f7dfd 100644 --- a/contracts/src/token/erc1155/extensions/supply.rs +++ b/contracts/src/token/erc1155/extensions/supply.rs @@ -476,6 +476,7 @@ mod tests { .sender(alice) ._mint(dave, token_id, U256::MAX / two, &vec![].into()) .expect("should mint to dave"); + // This should panic. _ = contract.sender(alice)._mint(bob, token_id, three, &vec![].into()); } @@ -491,6 +492,7 @@ mod tests { .sender(alice) ._mint(bob, token_ids[0], U256::MAX, &vec![].into()) .expect("should mint"); + // This should panic. _ = contract.sender(alice)._mint( bob, token_ids[1], diff --git a/contracts/src/token/erc20/extensions/flash_mint.rs b/contracts/src/token/erc20/extensions/flash_mint.rs index bc6529c38..cd7699f76 100644 --- a/contracts/src/token/erc20/extensions/flash_mint.rs +++ b/contracts/src/token/erc20/extensions/flash_mint.rs @@ -339,7 +339,7 @@ impl IErc3156FlashLender for Erc20FlashMint { mod tests { use alloy_primitives::{uint, Address, U256}; use motsu::prelude::Contract; - use stylus_sdk::{abi::Bytes, msg, prelude::*}; + use stylus_sdk::{abi::Bytes, prelude::*}; use super::{ ERC3156ExceededMaxLoan, ERC3156InvalidReceiver, @@ -413,7 +413,10 @@ mod tests { let initial_supply = uint!(10000_U256); contract.init(alice, |contract| { - _ = contract.erc20._mint(alice, initial_supply).unwrap(); + contract + .erc20 + ._mint(alice, initial_supply) + .expect("should mint {{initial_supply}} tokens for {{alice}}"); }); let max_flash_loan = @@ -467,7 +470,10 @@ mod tests { let initial_supply = uint!(10000_U256); contract.init(alice, |contract| { - _ = contract.erc20._mint(msg::sender(), initial_supply).unwrap(); + contract + .erc20 + ._mint(alice, initial_supply) + .expect("should mint {{initial_supply}} tokens for {{alice}}"); }); let err = contract diff --git a/contracts/src/token/erc721/extensions/burnable.rs b/contracts/src/token/erc721/extensions/burnable.rs index 8fd2f574d..7c9432f50 100644 --- a/contracts/src/token/erc721/extensions/burnable.rs +++ b/contracts/src/token/erc721/extensions/burnable.rs @@ -48,7 +48,6 @@ impl IErc721Burnable for Erc721 { mod tests { use alloy_primitives::{uint, Address, U256}; use motsu::prelude::Contract; - use stylus_sdk::msg; use super::IErc721Burnable; use crate::token::erc721::{ @@ -238,7 +237,7 @@ mod tests { Error::InsufficientApproval(ERC721InsufficientApproval { operator, token_id: t_id, - }) if operator == msg::sender() && t_id == TOKEN_ID + }) if operator == alice && t_id == TOKEN_ID )); } diff --git a/contracts/src/token/erc721/extensions/consecutive.rs b/contracts/src/token/erc721/extensions/consecutive.rs index 9924a3069..f18907511 100644 --- a/contracts/src/token/erc721/extensions/consecutive.rs +++ b/contracts/src/token/erc721/extensions/consecutive.rs @@ -759,7 +759,6 @@ impl Erc721Consecutive { mod tests { use alloy_primitives::{uint, Address, U256}; use motsu::prelude::Contract; - use stylus_sdk::msg; use crate::token::{ erc721, @@ -1332,7 +1331,7 @@ mod tests { err, Error::Erc721(erc721::Error::InvalidApprover(ERC721InvalidApprover { approver - })) if approver == msg::sender() + })) if approver == alice )); } diff --git a/contracts/src/token/erc721/mod.rs b/contracts/src/token/erc721/mod.rs index 34eb8f740..32f90299f 100644 --- a/contracts/src/token/erc721/mod.rs +++ b/contracts/src/token/erc721/mod.rs @@ -1041,7 +1041,6 @@ mod tests { use motsu::prelude::Contract; use stylus_sdk::{ abi::Bytes, - msg, prelude::{public, sol_storage, TopLevelStorage}, }; @@ -1856,7 +1855,7 @@ mod tests { err, Error::InvalidApprover(ERC721InvalidApprover { approver - }) if approver == msg::sender() + }) if approver == alice )); } @@ -2577,7 +2576,7 @@ mod tests { ) { let err = contract .sender(alice) - ._approve(bob, TOKEN_ID, msg::sender(), false) + ._approve(bob, TOKEN_ID, alice, false) .expect_err("should not approve for a non-existent token"); assert!(matches!( diff --git a/contracts/src/utils/math/alloy.rs b/contracts/src/utils/math/alloy.rs index 94d3eb827..0e8cfa0b3 100644 --- a/contracts/src/utils/math/alloy.rs +++ b/contracts/src/utils/math/alloy.rs @@ -251,6 +251,7 @@ mod tests { #[should_panic = "division by U256::ZERO in `Math::mul_div`"] fn check_mul_div_panics_when_denominator_is_zero() { proptest!(|(x: U256, y: U256)| { + // This should panic. _ = x.mul_div(y, U256::ZERO, Rounding::Floor); }) } @@ -261,6 +262,7 @@ mod tests { proptest!(|(x: U256, y: U256)| { prop_assume!(x != U256::ZERO, "Guaranteed `x` for overflow."); prop_assume!(y > U256::MAX / x, "Guaranteed `y` for overflow."); + // This should panic. _ = x.mul_div(y, U256::from(1), Rounding::Floor); }) } diff --git a/examples/access-control/tests/access_control.rs b/examples/access-control/tests/access_control.rs index f2f48fcd6..08482e9a8 100644 --- a/examples/access-control/tests/access_control.rs +++ b/examples/access-control/tests/access_control.rs @@ -144,7 +144,7 @@ async fn admin_can_revoke_role(alice: Account, bob: Account) -> Result<()> { let alice_addr = alice.address(); let bob_addr = bob.address(); - _ = watch!(contract.grantRole(ROLE.into(), bob_addr))?; + watch!(contract.grantRole(ROLE.into(), bob_addr))?; let receipt = receipt!(contract.revokeRole(ROLE.into(), bob_addr))?; assert!(receipt.emits(RoleRevoked { @@ -167,7 +167,7 @@ async fn error_when_non_admin_revokes_role( let alice_addr = alice.address(); let bob_addr = bob.address(); - _ = watch!(contract.grantRole(ROLE.into(), alice_addr))?; + watch!(contract.grantRole(ROLE.into(), alice_addr))?; let contract = AccessControl::new(contract_addr, &bob.wallet); let err = send!(contract.revokeRole(ROLE.into(), alice_addr)) @@ -191,7 +191,7 @@ async fn roles_can_be_revoked_multiple_times( let alice_addr = alice.address(); let bob_addr = bob.address(); - _ = watch!(contract.revokeRole(ROLE.into(), bob_addr))?; + watch!(contract.revokeRole(ROLE.into(), bob_addr))?; let receipt = receipt!(contract.revokeRole(ROLE.into(), bob_addr))?; assert!(!receipt.emits(RoleRevoked { role: ROLE.into(), @@ -224,7 +224,7 @@ async fn bearer_can_renounce_role(alice: Account, bob: Account) -> Result<()> { let contract_addr = alice.as_deployer().deploy().await?.address()?; let contract = AccessControl::new(contract_addr, &alice.wallet); - _ = watch!(contract.grantRole(ROLE.into(), bob_addr))?; + watch!(contract.grantRole(ROLE.into(), bob_addr))?; let contract = AccessControl::new(contract_addr, &bob.wallet); let receipt = receipt!(contract.renounceRole(ROLE.into(), bob_addr))?; @@ -248,7 +248,7 @@ async fn error_when_the_one_renouncing_is_not_the_sender( let alice_addr = alice.address(); let bob_addr = bob.address(); - _ = watch!(contract.grantRole(ROLE.into(), bob_addr))?; + watch!(contract.grantRole(ROLE.into(), bob_addr))?; let contract = AccessControl::new(contract_addr, &bob.wallet); let err = send!(contract.renounceRole(ROLE.into(), alice_addr)) @@ -264,7 +264,7 @@ async fn roles_can_be_renounced_multiple_times(alice: Account) -> Result<()> { let contract_addr = alice.as_deployer().deploy().await?.address()?; let contract = AccessControl::new(contract_addr, &alice.wallet); - _ = watch!(contract.renounceRole(ROLE.into(), alice_addr))?; + watch!(contract.renounceRole(ROLE.into(), alice_addr))?; let receipt = receipt!(contract.renounceRole(ROLE.into(), alice_addr))?; assert!(!receipt.emits(RoleRevoked { role: ROLE.into(), @@ -314,7 +314,7 @@ async fn the_new_admin_can_grant_roles( newAdminRole: NEW_ADMIN_ROLE.into() })); - _ = watch!(contract.grantRole(NEW_ADMIN_ROLE.into(), bob_addr))?; + watch!(contract.grantRole(NEW_ADMIN_ROLE.into(), bob_addr))?; let contract = AccessControl::new(contract_addr, &bob.wallet); let receipt = receipt!(contract.grantRole(ROLE.into(), alice_addr))?; @@ -346,10 +346,10 @@ async fn the_new_admin_can_revoke_roles( newAdminRole: NEW_ADMIN_ROLE.into() })); - _ = watch!(contract.grantRole(NEW_ADMIN_ROLE.into(), bob_addr))?; + watch!(contract.grantRole(NEW_ADMIN_ROLE.into(), bob_addr))?; let contract = AccessControl::new(contract_addr, &bob.wallet); - _ = watch!(contract.grantRole(ROLE.into(), alice_addr))?; + watch!(contract.grantRole(ROLE.into(), alice_addr))?; let receipt = receipt!(contract.revokeRole(ROLE.into(), alice_addr))?; assert!(receipt.emits(RoleRevoked { role: ROLE.into(), diff --git a/examples/erc1155-metadata-uri/tests/erc1155-metadata-uri.rs b/examples/erc1155-metadata-uri/tests/erc1155-metadata-uri.rs index 73884c2f7..8507af985 100644 --- a/examples/erc1155-metadata-uri/tests/erc1155-metadata-uri.rs +++ b/examples/erc1155-metadata-uri/tests/erc1155-metadata-uri.rs @@ -81,7 +81,7 @@ async fn uri_returns_concatenated_base_uri_and_token_uri( let token_uri = "/some/token/uri"; let expected_uri = BASE_URI.to_owned() + token_uri; - _ = watch!(contract.setBaseURI(BASE_URI.to_owned()))?; + watch!(contract.setBaseURI(BASE_URI.to_owned()))?; let receipt = receipt!(contract.setTokenURI(token_id, token_uri.to_owned()))?; @@ -142,7 +142,7 @@ async fn uri_ignores_metadata_uri_when_token_uri_is_set( let token_uri = "/some/token/uri"; let expected_uri = BASE_URI.to_owned() + token_uri; - _ = watch!(contract.setBaseURI(BASE_URI.to_owned()))?; + watch!(contract.setBaseURI(BASE_URI.to_owned()))?; let receipt = receipt!(contract.setTokenURI(token_id, token_uri.to_owned()))?; diff --git a/examples/erc1155-supply/tests/erc1155-supply.rs b/examples/erc1155-supply/tests/erc1155-supply.rs index d851d0e51..d4ab48657 100644 --- a/examples/erc1155-supply/tests/erc1155-supply.rs +++ b/examples/erc1155-supply/tests/erc1155-supply.rs @@ -260,18 +260,13 @@ async fn mint_panics_on_total_supply_overflow( let two = U256::from(2); let three = U256::from(3); - _ = watch!(contract.mint( + watch!(contract.mint( alice_addr, token_id, U256::MAX / two, vec![].into() ))?; - _ = watch!(contract.mint( - bob_addr, - token_id, - U256::MAX / two, - vec![].into() - ))?; + watch!(contract.mint(bob_addr, token_id, U256::MAX / two, vec![].into()))?; let err = send!(contract.mint(alice_addr, token_id, three, vec![].into())) .expect_err("should panic due to total_supply overflow"); @@ -291,12 +286,7 @@ async fn mint_panics_on_total_supply_all_overflow( let alice_addr = alice.address(); let token_ids = random_token_ids(2); - _ = watch!(contract.mint( - alice_addr, - token_ids[0], - U256::MAX, - vec![].into() - ))?; + watch!(contract.mint(alice_addr, token_ids[0], U256::MAX, vec![].into()))?; let err = send!(contract.mint( alice_addr, @@ -320,7 +310,7 @@ async fn burn(alice: Account) -> eyre::Result<()> { let token_id = random_token_ids(1)[0]; let value = random_values(1)[0]; - _ = watch!(contract.mint(alice_addr, token_id, value, vec![].into()))?; + watch!(contract.mint(alice_addr, token_id, value, vec![].into()))?; let receipt = receipt!(contract.burn(alice_addr, token_id, value))?; @@ -357,9 +347,9 @@ async fn burn_with_approval(alice: Account, bob: Account) -> eyre::Result<()> { let token_id = random_token_ids(1)[0]; let value = random_values(1)[0]; - _ = watch!(contract.mint(bob_addr, token_id, value, vec![].into()))?; + watch!(contract.mint(bob_addr, token_id, value, vec![].into()))?; - _ = watch!(contract_bob.setApprovalForAll(alice_addr, true))?; + watch!(contract_bob.setApprovalForAll(alice_addr, true))?; let receipt = receipt!(contract.burn(bob_addr, token_id, value))?; @@ -393,7 +383,7 @@ async fn burn_batch(alice: Account) -> eyre::Result<()> { let token_ids = random_token_ids(4); let values = random_values(4); - _ = watch!(contract.mintBatch( + watch!(contract.mintBatch( alice_addr, token_ids.clone(), values.clone(), @@ -445,14 +435,14 @@ async fn burn_batch_with_approval( let token_ids = random_token_ids(4); let values = random_values(4); - _ = watch!(contract.mintBatch( + watch!(contract.mintBatch( bob_addr, token_ids.clone(), values.clone(), vec![].into() ))?; - _ = watch!(contract_bob.setApprovalForAll(alice_addr, true))?; + watch!(contract_bob.setApprovalForAll(alice_addr, true))?; let receipt = receipt!(contract.burnBatch( bob_addr, @@ -498,7 +488,7 @@ async fn supply_unaffected_by_safe_transfer_from( let token_id = random_token_ids(1)[0]; let value = random_values(1)[0]; - _ = watch!(contract.mint(alice_addr, token_id, value, vec![].into()))?; + watch!(contract.mint(alice_addr, token_id, value, vec![].into()))?; // assert balances as expected after mint let alice_balance = @@ -564,7 +554,7 @@ async fn supply_unaffected_by_safe_transfer_from_batch( let token_ids = random_token_ids(4); let values = random_values(4); - _ = watch!(contract.mintBatch( + watch!(contract.mintBatch( alice_addr, token_ids.clone(), values.clone(), @@ -739,7 +729,7 @@ async fn safe_transfer_from(alice: Account, bob: Account) -> eyre::Result<()> { let bob_addr = bob.address(); let token_id = random_token_ids(1)[0]; let value = random_values(1)[0]; - _ = watch!(contract.mint( + watch!(contract.mint( alice_addr, token_id, value, @@ -792,14 +782,14 @@ async fn safe_transfer_from_with_approval( let token_id = random_token_ids(1)[0]; let value = random_values(1)[0]; - _ = watch!(contract_bob.mint( + watch!(contract_bob.mint( bob_addr, token_id, value, vec![0, 1, 2, 3].into() ))?; - _ = watch!(contract_bob.setApprovalForAll(alice_addr, true))?; + watch!(contract_bob.setApprovalForAll(alice_addr, true))?; let Erc1155Supply::balanceOfReturn { balance: initial_alice_balance } = contract_alice.balanceOf(alice_addr, token_id).call().await?; @@ -848,7 +838,7 @@ async fn safe_transfer_to_receiver_contract( let token_id = random_token_ids(1)[0]; let value = random_values(1)[0]; - _ = watch!(contract.mint( + watch!(contract.mint( alice_addr, token_id, value, @@ -908,7 +898,7 @@ async fn safe_batch_transfer_from( let token_ids = random_token_ids(2); let values = random_values(2); - _ = watch!(contract_alice.mintBatch( + watch!(contract_alice.mintBatch( alice_addr, token_ids.clone(), values.clone(), @@ -979,7 +969,7 @@ async fn safe_batch_transfer_to_receiver_contract( let token_ids = random_token_ids(2); let values = random_values(2); - _ = watch!(contract.mintBatch( + watch!(contract.mintBatch( alice_addr, token_ids.clone(), values.clone(), @@ -1066,14 +1056,14 @@ async fn safe_batch_transfer_from_with_approval( let token_ids = random_token_ids(2); let values = random_values(2); - _ = watch!(contract_alice.mintBatch( + watch!(contract_alice.mintBatch( bob_addr, token_ids.clone(), values.clone(), vec![].into() ))?; - _ = watch!(contract_bob.setApprovalForAll(alice_addr, true))?; + watch!(contract_bob.setApprovalForAll(alice_addr, true))?; let Erc1155Supply::balanceOfBatchReturn { balances: initial_dave_balances } = contract_alice diff --git a/examples/erc1155/tests/erc1155.rs b/examples/erc1155/tests/erc1155.rs index 4729bf83f..e07c9514e 100644 --- a/examples/erc1155/tests/erc1155.rs +++ b/examples/erc1155/tests/erc1155.rs @@ -620,7 +620,7 @@ async fn safe_transfer_from(alice: Account, bob: Account) -> eyre::Result<()> { let bob_addr = bob.address(); let token_id = random_token_ids(1)[0]; let value = random_values(1)[0]; - _ = watch!(contract.mint( + watch!(contract.mint( alice_addr, token_id, value, @@ -673,14 +673,14 @@ async fn safe_transfer_from_with_approval( let token_id = random_token_ids(1)[0]; let value = random_values(1)[0]; - _ = watch!(contract_bob.mint( + watch!(contract_bob.mint( bob_addr, token_id, value, vec![0, 1, 2, 3].into() ))?; - _ = watch!(contract_bob.setApprovalForAll(alice_addr, true))?; + watch!(contract_bob.setApprovalForAll(alice_addr, true))?; let Erc1155::balanceOfReturn { balance: initial_alice_balance } = contract_alice.balanceOf(alice_addr, token_id).call().await?; @@ -729,7 +729,7 @@ async fn safe_transfer_to_receiver_contract( let token_id = random_token_ids(1)[0]; let value = random_values(1)[0]; - _ = watch!(contract.mint( + watch!(contract.mint( alice_addr, token_id, value, @@ -793,7 +793,7 @@ async fn errors_when_receiver_reverts_with_reason( let token_id = random_token_ids(1)[0]; let value = random_values(1)[0]; - _ = watch!(contract.mint( + watch!(contract.mint( alice_addr, token_id, value, @@ -833,7 +833,7 @@ async fn errors_when_receiver_reverts_without_reason( let token_id = random_token_ids(1)[0]; let value = random_values(1)[0]; - _ = watch!(contract.mint( + watch!(contract.mint( alice_addr, token_id, value, @@ -869,7 +869,7 @@ async fn errors_when_receiver_panics(alice: Account) -> eyre::Result<()> { let token_id = random_token_ids(1)[0]; let value = random_values(1)[0]; - _ = watch!(contract.mint( + watch!(contract.mint( alice_addr, token_id, value, @@ -903,7 +903,7 @@ async fn errors_when_invalid_receiver_contract( let token_id = random_token_ids(1)[0]; let value = random_values(1)[0]; - _ = watch!(contract.mint( + watch!(contract.mint( alice_addr, token_id, value, @@ -937,7 +937,7 @@ async fn error_when_invalid_receiver_safe_transfer_from( let invalid_receiver = Address::ZERO; let token_id = random_token_ids(1)[0]; let value = random_values(1)[0]; - _ = watch!(contract.mint(alice_addr, token_id, value, vec![].into()))?; + watch!(contract.mint(alice_addr, token_id, value, vec![].into()))?; let err = send!(contract.safeTransferFrom( alice_addr, @@ -969,7 +969,7 @@ async fn error_when_missing_approval_safe_transfer_from( let dave_addr = dave.address(); let token_id = random_token_ids(1)[0]; let value = random_values(1)[0]; - _ = watch!(contract.mint(bob_addr, token_id, value, vec![].into()))?; + watch!(contract.mint(bob_addr, token_id, value, vec![].into()))?; let err = send!(contract.safeTransferFrom( bob_addr, @@ -1004,8 +1004,8 @@ async fn error_when_insufficient_balance_safe_transfer_from( let token_id = random_token_ids(1)[0]; let value = random_values(1)[0]; - _ = watch!(contract_alice.mint(bob_addr, token_id, value, vec![].into()))?; - _ = watch!(contract_bob.setApprovalForAll(alice_addr, true))?; + watch!(contract_alice.mint(bob_addr, token_id, value, vec![].into()))?; + watch!(contract_bob.setApprovalForAll(alice_addr, true))?; let err = send!(contract_alice.safeTransferFrom( bob_addr, @@ -1039,7 +1039,7 @@ async fn safe_batch_transfer_from( let token_ids = random_token_ids(2); let values = random_values(2); - _ = watch!(contract_alice.mintBatch( + watch!(contract_alice.mintBatch( alice_addr, token_ids.clone(), values.clone(), @@ -1109,7 +1109,7 @@ async fn safe_batch_transfer_to_receiver_contract( let token_ids = random_token_ids(2); let values = random_values(2); - _ = watch!(contract.mintBatch( + watch!(contract.mintBatch( alice_addr, token_ids.clone(), values.clone(), @@ -1197,7 +1197,7 @@ async fn errors_when_receiver_reverts_with_reason_in_batch_transfer( let token_ids = random_token_ids(2); let values = random_values(2); - _ = watch!(contract.mintBatch( + watch!(contract.mintBatch( alice_addr, token_ids.clone(), values.clone(), @@ -1237,7 +1237,7 @@ async fn errors_when_receiver_reverts_without_reason_in_batch_transfer( let token_ids = random_token_ids(2); let values = random_values(2); - _ = watch!(contract.mintBatch( + watch!(contract.mintBatch( alice_addr, token_ids.clone(), values.clone(), @@ -1275,7 +1275,7 @@ async fn errors_when_receiver_panics_in_batch_transfer( let token_ids = random_token_ids(2); let values = random_values(2); - _ = watch!(contract.mintBatch( + watch!(contract.mintBatch( alice_addr, token_ids.clone(), values.clone(), @@ -1309,7 +1309,7 @@ async fn errors_when_invalid_receiver_contract_in_batch_transfer( let token_ids = random_token_ids(2); let values = random_values(2); - _ = watch!(contract.mintBatch( + watch!(contract.mintBatch( alice_addr, token_ids.clone(), values.clone(), @@ -1348,14 +1348,14 @@ async fn safe_batch_transfer_from_with_approval( let token_ids = random_token_ids(2); let values = random_values(2); - _ = watch!(contract_alice.mintBatch( + watch!(contract_alice.mintBatch( bob_addr, token_ids.clone(), values.clone(), vec![].into() ))?; - _ = watch!(contract_bob.setApprovalForAll(alice_addr, true))?; + watch!(contract_bob.setApprovalForAll(alice_addr, true))?; let Erc1155::balanceOfBatchReturn { balances: initial_dave_balances } = contract_alice @@ -1417,7 +1417,7 @@ async fn error_when_invalid_receiver_safe_batch_transfer_from( let token_ids = random_token_ids(2); let values = random_values(2); - _ = watch!(contract.mintBatch( + watch!(contract.mintBatch( alice_addr, token_ids.clone(), values.clone(), @@ -1453,7 +1453,7 @@ async fn error_invalid_array_length_in_safe_batch_transfer_from( let token_ids = random_token_ids(2); let values = random_values(2); - _ = watch!(contract_alice.mintBatch( + watch!(contract_alice.mintBatch( alice_addr, token_ids.clone(), values.clone(), @@ -1492,7 +1492,7 @@ async fn error_when_missing_approval_safe_batch_transfer_from( let token_ids = random_token_ids(4); let values = random_values(4); - _ = watch!(contract.mintBatch( + watch!(contract.mintBatch( bob_addr, token_ids.clone(), values.clone(), @@ -1532,13 +1532,13 @@ async fn error_when_insufficient_balance_safe_batch_transfer_from( let token_ids = random_token_ids(2); let values = random_values(2); - _ = watch!(contract_alice.mintBatch( + watch!(contract_alice.mintBatch( bob_addr, token_ids.clone(), values.clone(), vec![].into() ))?; - _ = watch!(contract_bob.setApprovalForAll(alice_addr, true))?; + watch!(contract_bob.setApprovalForAll(alice_addr, true))?; let err = send!(contract_alice.safeBatchTransferFrom( bob_addr, @@ -1572,12 +1572,7 @@ async fn burns(alice: Account) -> eyre::Result<()> { let token_ids = random_token_ids(1); let values = random_values(1); - _ = watch!(contract.mint( - alice_addr, - token_ids[0], - values[0], - vec![].into() - ))?; + watch!(contract.mint(alice_addr, token_ids[0], values[0], vec![].into()))?; let initial_balance = contract.balanceOf(alice_addr, token_ids[0]).call().await?.balance; @@ -1611,18 +1606,13 @@ async fn burns_with_approval(alice: Account, bob: Account) -> eyre::Result<()> { let token_ids = random_token_ids(1); let values = random_values(1); - _ = watch!(contract.mint( - bob_addr, - token_ids[0], - values[0], - vec![].into() - ))?; + watch!(contract.mint(bob_addr, token_ids[0], values[0], vec![].into()))?; let initial_balance = contract.balanceOf(bob_addr, token_ids[0]).call().await?.balance; assert_eq!(values[0], initial_balance); - _ = watch!(contract_bob.setApprovalForAll(alice_addr, true))?; + watch!(contract_bob.setApprovalForAll(alice_addr, true))?; let receipt = receipt!(contract.burn(bob_addr, token_ids[0], values[0]))?; @@ -1654,12 +1644,7 @@ async fn error_when_missing_approval_burn( let token_ids = random_token_ids(1); let values = random_values(1); - _ = watch!(contract.mint( - bob_addr, - token_ids[0], - values[0], - vec![].into() - ))?; + watch!(contract.mint(bob_addr, token_ids[0], values[0], vec![].into()))?; let err = send!(contract.burn(bob_addr, token_ids[0], values[0])) .expect_err("should return `ERC1155MissingApprovalForAll`"); @@ -1684,7 +1669,7 @@ async fn error_when_insufficient_balance_burn( let value = random_values(1)[0]; let to_burn = value + uint!(1_U256); - _ = watch!(contract.mint(alice_addr, token_id, value, vec![].into()))?; + watch!(contract.mint(alice_addr, token_id, value, vec![].into()))?; let err = send!(contract.burn(alice_addr, token_id, to_burn)) .expect_err("should return `ERC1155InsufficientBalance`"); @@ -1708,7 +1693,7 @@ async fn burns_batch(alice: Account) -> eyre::Result<()> { let token_ids = random_token_ids(4); let values = random_values(4); - _ = watch!(contract.mintBatch( + watch!(contract.mintBatch( alice_addr, token_ids.clone(), values.clone(), @@ -1756,7 +1741,7 @@ async fn burns_batch_with_approval( let token_ids = random_token_ids(4); let values = random_values(4); - _ = watch!(contract.mintBatch( + watch!(contract.mintBatch( bob_addr, token_ids.clone(), values.clone(), @@ -1768,7 +1753,7 @@ async fn burns_batch_with_approval( assert_eq!(value, balance); } - _ = watch!(contract_bob.setApprovalForAll(alice_addr, true))?; + watch!(contract_bob.setApprovalForAll(alice_addr, true))?; let receipt = receipt!(contract.burnBatch( bob_addr, @@ -1805,7 +1790,7 @@ async fn error_when_missing_approval_burn_batch( let token_ids = random_token_ids(2); let values = random_values(2); - _ = watch!(contract.mintBatch( + watch!(contract.mintBatch( bob_addr, token_ids.clone(), values.clone(), @@ -1835,7 +1820,7 @@ async fn error_when_insufficient_balance_burn_batch( let values = random_values(2); let to_burn: Vec = values.iter().map(|v| v + uint!(1_U256)).collect(); - _ = watch!(contract.mintBatch( + watch!(contract.mintBatch( alice_addr, token_ids.clone(), values.clone(), @@ -1921,7 +1906,7 @@ async fn pause_reverts_in_paused_state(alice: Account) -> eyre::Result<()> { let contract = Erc1155::new(contract_addr, &alice.wallet); - _ = watch!(contract.pause())?; + watch!(contract.pause())?; let err = send!(contract.pause()).expect_err("should return `EnforcedPause`"); @@ -1937,7 +1922,7 @@ async fn unpauses(alice: Account) -> eyre::Result<()> { let contract = Erc1155::new(contract_addr, &alice.wallet); - _ = watch!(contract.pause())?; + watch!(contract.pause())?; let receipt = receipt!(contract.unpause())?; @@ -1977,7 +1962,7 @@ async fn mint_reverts_in_paused_state(alice: Account) -> eyre::Result<()> { let token_id = random_token_ids(1)[0]; let value = random_values(1)[0]; - _ = watch!(contract.pause())?; + watch!(contract.pause())?; let err = send!(contract.mint( alice_addr, @@ -2003,7 +1988,7 @@ async fn mint_batch_reverts_in_paused_state( let token_ids = random_token_ids(3); let values = random_values(3); - _ = watch!(contract.pause())?; + watch!(contract.pause())?; let err = send!(contract.mintBatch( alice_addr, @@ -2027,14 +2012,9 @@ async fn burn_reverts_in_paused_state(alice: Account) -> eyre::Result<()> { let token_ids = random_token_ids(1); let values = random_values(1); - _ = watch!(contract.mint( - alice_addr, - token_ids[0], - values[0], - vec![].into() - ))?; + watch!(contract.mint(alice_addr, token_ids[0], values[0], vec![].into()))?; - _ = watch!(contract.pause())?; + watch!(contract.pause())?; let err = send!(contract.burn(alice_addr, token_ids[0], values[0])) .expect_err("should return `EnforcedPause`"); @@ -2055,14 +2035,14 @@ async fn burn_batch_reverts_in_paused_state( let token_ids = random_token_ids(4); let values = random_values(4); - _ = watch!(contract.mintBatch( + watch!(contract.mintBatch( alice_addr, token_ids.clone(), values.clone(), vec![].into() ))?; - _ = watch!(contract.pause())?; + watch!(contract.pause())?; let err = send!(contract.burnBatch( alice_addr, @@ -2088,14 +2068,14 @@ async fn safe_transfer_from_reverts_in_paused_state( let bob_addr = bob.address(); let token_id = random_token_ids(1)[0]; let value = random_values(1)[0]; - _ = watch!(contract.mint( + watch!(contract.mint( alice_addr, token_id, value, vec![0, 1, 2, 3].into() ))?; - _ = watch!(contract.pause())?; + watch!(contract.pause())?; let err = send!(contract.safeTransferFrom( alice_addr, @@ -2124,14 +2104,14 @@ async fn safe_batch_transfer_from_reverts_in_paused_state( let token_ids = random_token_ids(2); let values = random_values(2); - _ = watch!(contract_alice.mintBatch( + watch!(contract_alice.mintBatch( alice_addr, token_ids.clone(), values.clone(), vec![].into() ))?; - _ = watch!(contract_alice.pause())?; + watch!(contract_alice.pause())?; let err = send!(contract_alice.safeBatchTransferFrom( alice_addr, @@ -2158,7 +2138,7 @@ async fn set_approval_for_all_does_not_revert_in_paused_state( let alice_addr = alice.address(); let bob_addr = bob.address(); - _ = watch!(contract.pause())?; + watch!(contract.pause())?; let approved_value = true; let receipt = diff --git a/examples/erc20-flash-mint/tests/erc20-flash-mint.rs b/examples/erc20-flash-mint/tests/erc20-flash-mint.rs index 0edb0f882..aaa4370d6 100644 --- a/examples/erc20-flash-mint/tests/erc20-flash-mint.rs +++ b/examples/erc20-flash-mint/tests/erc20-flash-mint.rs @@ -68,7 +68,7 @@ async fn max_flash_loan(alice: Account) -> Result<()> { let alice_addr = alice.address(); let mint_amount = uint!(1_000_000_U256); - _ = watch!(contract.mint(alice_addr, mint_amount))?; + watch!(contract.mint(alice_addr, mint_amount))?; let max_loan = contract.maxFlashLoan(contract_addr).call().await?.maxLoan; assert_eq!(U256::MAX - mint_amount, max_loan); @@ -89,7 +89,7 @@ async fn max_flash_loan_return_zero_if_no_more_tokens_to_mint( let contract = Erc20FlashMint::new(contract_addr, &alice.wallet); let alice_addr = alice.address(); - _ = watch!(contract.mint(alice_addr, U256::MAX))?; + watch!(contract.mint(alice_addr, U256::MAX))?; let max_loan = contract.maxFlashLoan(contract_addr).call().await?.maxLoan; assert_eq!(U256::MIN, max_loan); @@ -111,7 +111,7 @@ async fn max_flash_loan_returns_zero_on_invalid_address( let alice_addr = alice.address(); let mint_amount = uint!(1_000_000_U256); - _ = watch!(contract.mint(alice_addr, mint_amount))?; + watch!(contract.mint(alice_addr, mint_amount))?; // non-token address let max_loan = contract.maxFlashLoan(alice_addr).call().await?.maxLoan; @@ -194,7 +194,7 @@ async fn flash_loan_with_fee(alice: Account) -> Result<()> { let erc20 = Erc20FlashMint::new(erc20_addr, &alice.wallet); let borrower_addr = borrower::deploy(&alice.wallet, true, true).await?; - _ = watch!(erc20.mint(borrower_addr, FLASH_FEE_VALUE))?; + watch!(erc20.mint(borrower_addr, FLASH_FEE_VALUE))?; let loan_amount = uint!(1_000_000_U256); let borrower_balance = erc20.balanceOf(borrower_addr).call().await?.balance; @@ -311,7 +311,7 @@ async fn flash_loan_with_fee_and_fee_receiver(alice: Account) -> Result<()> { let erc20 = Erc20FlashMint::new(erc20_addr, &alice.wallet); let borrower_addr = borrower::deploy(&alice.wallet, true, true).await?; - _ = watch!(erc20.mint(borrower_addr, FLASH_FEE_VALUE))?; + watch!(erc20.mint(borrower_addr, FLASH_FEE_VALUE))?; let loan_amount = uint!(1_000_000_U256); let borrower_balance = erc20.balanceOf(borrower_addr).call().await?.balance; @@ -383,7 +383,7 @@ async fn flash_loan_reverts_when_loan_amount_greater_than_max_loan( let max_loan = U256::from(1); let loan_amount = U256::from(2); - _ = watch!(erc20.mint(borrower_addr, U256::MAX - max_loan))?; + watch!(erc20.mint(borrower_addr, U256::MAX - max_loan))?; let err = send!(erc20.flashLoan( borrower_addr, @@ -475,7 +475,7 @@ async fn flash_loan_reverts_when_invalid_receiver( let erc20 = Erc20FlashMint::new(erc20_addr, &alice.wallet); let borrower_addr = borrower::deploy(&alice.wallet, true, true).await?; - _ = watch!(erc20.mint(borrower_addr, FLASH_FEE_VALUE))?; + watch!(erc20.mint(borrower_addr, FLASH_FEE_VALUE))?; let loan_amount = U256::from(1); let invalid_receivers = &[alice.address(), Address::ZERO]; @@ -510,7 +510,7 @@ async fn flash_loan_reverts_when_receiver_callback_reverts( let erc20 = Erc20FlashMint::new(erc20_addr, &alice.wallet); let borrower_addr = borrower::deploy(&alice.wallet, true, true).await?; - _ = watch!(erc20.mint(borrower_addr, FLASH_FEE_VALUE))?; + watch!(erc20.mint(borrower_addr, FLASH_FEE_VALUE))?; let loan_amount = U256::from(1); let err = send!(erc20.flashLoan( @@ -541,7 +541,7 @@ async fn flash_loan_reverts_when_receiver_returns_invalid_callback_value( let erc20 = Erc20FlashMint::new(erc20_addr, &alice.wallet); let borrower_addr = borrower::deploy(&alice.wallet, false, true).await?; - _ = watch!(erc20.mint(borrower_addr, FLASH_FEE_VALUE))?; + watch!(erc20.mint(borrower_addr, FLASH_FEE_VALUE))?; let loan_amount = U256::from(1); let err = send!(erc20.flashLoan( @@ -572,7 +572,7 @@ async fn flash_loan_reverts_when_receiver_doesnt_approve_allowance( let erc20 = Erc20FlashMint::new(erc20_addr, &alice.wallet); let borrower_addr = borrower::deploy(&alice.wallet, true, false).await?; - _ = watch!(erc20.mint(borrower_addr, FLASH_FEE_VALUE))?; + watch!(erc20.mint(borrower_addr, FLASH_FEE_VALUE))?; let loan_amount = U256::from(1); let err = send!(erc20.flashLoan( diff --git a/examples/erc20-permit/tests/erc20permit.rs b/examples/erc20-permit/tests/erc20permit.rs index 590e04403..2d20315e0 100644 --- a/examples/erc20-permit/tests/erc20permit.rs +++ b/examples/erc20-permit/tests/erc20permit.rs @@ -85,7 +85,7 @@ async fn error_when_expired_deadline_for_permit( let bob_addr = bob.address(); let balance = uint!(10_U256); - _ = watch!(contract_alice.mint(alice_addr, balance))?; + watch!(contract_alice.mint(alice_addr, balance))?; let struct_hash = permit_struct_hash( alice_addr, @@ -128,7 +128,7 @@ async fn permit_works(alice: Account, bob: Account) -> Result<()> { let bob_addr = bob.address(); let balance = uint!(10_U256); - _ = watch!(contract_alice.mint(alice_addr, balance))?; + watch!(contract_alice.mint(alice_addr, balance))?; let struct_hash = permit_struct_hash( alice_addr, @@ -219,7 +219,7 @@ async fn permit_rejects_reused_signature( let bob_addr = bob.address(); let balance = uint!(10_U256); - _ = watch!(contract_alice.mint(alice_addr, balance))?; + watch!(contract_alice.mint(alice_addr, balance))?; let struct_hash = permit_struct_hash( alice_addr, @@ -237,7 +237,7 @@ async fn permit_rejects_reused_signature( )) .await; - _ = watch!(contract_alice.permit( + watch!(contract_alice.permit( alice_addr, bob_addr, balance, @@ -294,7 +294,7 @@ async fn permit_rejects_invalid_signature( let bob_addr = bob.address(); let balance = uint!(10_U256); - _ = watch!(contract_alice.mint(alice_addr, balance))?; + watch!(contract_alice.mint(alice_addr, balance))?; let struct_hash = permit_struct_hash( alice_addr, @@ -417,7 +417,7 @@ async fn transfers(alice: Account, bob: Account) -> Result<()> { let balance = uint!(10_U256); let value = uint!(1_U256); - _ = watch!(contract_alice.mint(alice.address(), balance))?; + watch!(contract_alice.mint(alice.address(), balance))?; let Erc20Permit::balanceOfReturn { balance: initial_alice_balance } = contract_alice.balanceOf(alice_addr).call().await?; @@ -461,7 +461,7 @@ async fn transfer_rejects_insufficient_balance( let balance = uint!(10_U256); let value = uint!(11_U256); - _ = watch!(contract_alice.mint(alice.address(), balance))?; + watch!(contract_alice.mint(alice.address(), balance))?; let Erc20Permit::balanceOfReturn { balance: initial_alice_balance } = contract_alice.balanceOf(alice_addr).call().await?; @@ -502,7 +502,7 @@ async fn transfer_rejects_invalid_receiver(alice: Account) -> Result<()> { let balance = uint!(10_U256); let value = uint!(1_U256); - _ = watch!(contract_alice.mint(alice.address(), balance))?; + watch!(contract_alice.mint(alice.address(), balance))?; let Erc20Permit::balanceOfReturn { balance: initial_alice_balance } = contract_alice.balanceOf(alice_addr).call().await?; @@ -662,7 +662,7 @@ async fn transfers_from(alice: Account, bob: Account) -> Result<()> { let balance = uint!(10_U256); let value = uint!(1_U256); - _ = watch!(contract_alice.mint(alice.address(), balance))?; + watch!(contract_alice.mint(alice.address(), balance))?; let Erc20Permit::balanceOfReturn { balance: initial_alice_balance } = contract_alice.balanceOf(alice_addr).call().await?; @@ -671,7 +671,7 @@ async fn transfers_from(alice: Account, bob: Account) -> Result<()> { let Erc20Permit::totalSupplyReturn { totalSupply: initial_supply } = contract_alice.totalSupply().call().await?; - _ = watch!(contract_alice.approve(bob_addr, balance))?; + watch!(contract_alice.approve(bob_addr, balance))?; let Erc20Permit::allowanceReturn { allowance: initial_allowance } = contract_alice.allowance(alice_addr, bob_addr).call().await?; @@ -717,7 +717,7 @@ async fn transfer_from_reverts_insufficient_balance( let balance = uint!(1_U256); let value = uint!(10_U256); - _ = watch!(contract_alice.mint(alice.address(), balance))?; + watch!(contract_alice.mint(alice.address(), balance))?; let Erc20Permit::balanceOfReturn { balance: initial_alice_balance } = contract_alice.balanceOf(alice_addr).call().await?; @@ -726,7 +726,7 @@ async fn transfer_from_reverts_insufficient_balance( let Erc20Permit::totalSupplyReturn { totalSupply: initial_supply } = contract_alice.totalSupply().call().await?; - _ = watch!(contract_alice.approve(bob_addr, value))?; + watch!(contract_alice.approve(bob_addr, value))?; let Erc20Permit::allowanceReturn { allowance: initial_allowance } = contract_alice.allowance(alice_addr, bob_addr).call().await?; @@ -772,7 +772,7 @@ async fn transfer_from_rejects_insufficient_allowance( let balance = uint!(10_U256); let value = uint!(1_U256); - _ = watch!(contract_alice.mint(alice.address(), balance))?; + watch!(contract_alice.mint(alice.address(), balance))?; let Erc20Permit::balanceOfReturn { balance: initial_alice_balance } = contract_alice.balanceOf(alice_addr).call().await?; @@ -828,7 +828,7 @@ async fn transfer_from_rejects_invalid_receiver( let balance = uint!(10_U256); let value = uint!(1_U256); - _ = watch!(contract_alice.mint(alice.address(), balance))?; + watch!(contract_alice.mint(alice.address(), balance))?; let Erc20Permit::balanceOfReturn { balance: initial_alice_balance } = contract_alice.balanceOf(alice_addr).call().await?; @@ -837,7 +837,7 @@ async fn transfer_from_rejects_invalid_receiver( let Erc20Permit::totalSupplyReturn { totalSupply: initial_supply } = contract_alice.totalSupply().call().await?; - _ = watch!(contract_alice.approve(bob_addr, balance))?; + watch!(contract_alice.approve(bob_addr, balance))?; let Erc20Permit::allowanceReturn { allowance: initial_allowance } = contract_alice.allowance(alice_addr, bob_addr).call().await?; diff --git a/examples/erc20/tests/erc20.rs b/examples/erc20/tests/erc20.rs index 30b3df59b..55cf6ba94 100644 --- a/examples/erc20/tests/erc20.rs +++ b/examples/erc20/tests/erc20.rs @@ -151,7 +151,7 @@ async fn mints_rejects_overflow(alice: Account) -> Result<()> { let one = uint!(1_U256); - _ = watch!(contract.mint(alice_addr, max_cap))?; + watch!(contract.mint(alice_addr, max_cap))?; let Erc20::balanceOfReturn { balance: initial_balance } = contract.balanceOf(alice_addr).call().await?; @@ -191,7 +191,7 @@ async fn transfers(alice: Account, bob: Account) -> Result<()> { let balance = uint!(10_U256); let value = uint!(1_U256); - _ = watch!(contract_alice.mint(alice.address(), balance))?; + watch!(contract_alice.mint(alice.address(), balance))?; let Erc20::balanceOfReturn { balance: initial_alice_balance } = contract_alice.balanceOf(alice_addr).call().await?; @@ -240,7 +240,7 @@ async fn transfer_rejects_insufficient_balance( let balance = uint!(10_U256); let value = uint!(11_U256); - _ = watch!(contract_alice.mint(alice.address(), balance))?; + watch!(contract_alice.mint(alice.address(), balance))?; let Erc20::balanceOfReturn { balance: initial_alice_balance } = contract_alice.balanceOf(alice_addr).call().await?; @@ -286,7 +286,7 @@ async fn transfer_rejects_invalid_receiver(alice: Account) -> Result<()> { let balance = uint!(10_U256); let value = uint!(1_U256); - _ = watch!(contract_alice.mint(alice.address(), balance))?; + watch!(contract_alice.mint(alice.address(), balance))?; let Erc20::balanceOfReturn { balance: initial_alice_balance } = contract_alice.balanceOf(alice_addr).call().await?; @@ -459,7 +459,7 @@ async fn transfers_from(alice: Account, bob: Account) -> Result<()> { let balance = uint!(10_U256); let value = uint!(1_U256); - _ = watch!(contract_alice.mint(alice.address(), balance))?; + watch!(contract_alice.mint(alice.address(), balance))?; let Erc20::balanceOfReturn { balance: initial_alice_balance } = contract_alice.balanceOf(alice_addr).call().await?; @@ -468,7 +468,7 @@ async fn transfers_from(alice: Account, bob: Account) -> Result<()> { let Erc20::totalSupplyReturn { totalSupply: initial_supply } = contract_alice.totalSupply().call().await?; - _ = watch!(contract_alice.approve(bob_addr, balance))?; + watch!(contract_alice.approve(bob_addr, balance))?; let Erc20::allowanceReturn { allowance: initial_allowance } = contract_alice.allowance(alice_addr, bob_addr).call().await?; @@ -519,7 +519,7 @@ async fn transfer_from_reverts_insufficient_balance( let balance = uint!(1_U256); let value = uint!(10_U256); - _ = watch!(contract_alice.mint(alice.address(), balance))?; + watch!(contract_alice.mint(alice.address(), balance))?; let Erc20::balanceOfReturn { balance: initial_alice_balance } = contract_alice.balanceOf(alice_addr).call().await?; @@ -528,7 +528,7 @@ async fn transfer_from_reverts_insufficient_balance( let Erc20::totalSupplyReturn { totalSupply: initial_supply } = contract_alice.totalSupply().call().await?; - _ = watch!(contract_alice.approve(bob_addr, value))?; + watch!(contract_alice.approve(bob_addr, value))?; let Erc20::allowanceReturn { allowance: initial_allowance } = contract_alice.allowance(alice_addr, bob_addr).call().await?; @@ -579,7 +579,7 @@ async fn transfer_from_rejects_insufficient_allowance( let balance = uint!(10_U256); let value = uint!(1_U256); - _ = watch!(contract_alice.mint(alice.address(), balance))?; + watch!(contract_alice.mint(alice.address(), balance))?; let Erc20::balanceOfReturn { balance: initial_alice_balance } = contract_alice.balanceOf(alice_addr).call().await?; @@ -640,7 +640,7 @@ async fn transfer_from_rejects_invalid_receiver( let balance = uint!(10_U256); let value = uint!(1_U256); - _ = watch!(contract_alice.mint(alice.address(), balance))?; + watch!(contract_alice.mint(alice.address(), balance))?; let Erc20::balanceOfReturn { balance: initial_alice_balance } = contract_alice.balanceOf(alice_addr).call().await?; @@ -649,7 +649,7 @@ async fn transfer_from_rejects_invalid_receiver( let Erc20::totalSupplyReturn { totalSupply: initial_supply } = contract_alice.totalSupply().call().await?; - _ = watch!(contract_alice.approve(bob_addr, balance))?; + watch!(contract_alice.approve(bob_addr, balance))?; let Erc20::allowanceReturn { allowance: initial_allowance } = contract_alice.allowance(alice_addr, bob_addr).call().await?; @@ -697,7 +697,7 @@ async fn burns(alice: Account) -> Result<()> { let balance = uint!(10_U256); let value = uint!(1_U256); - _ = watch!(contract_alice.mint(alice.address(), balance))?; + watch!(contract_alice.mint(alice.address(), balance))?; let Erc20::balanceOfReturn { balance: initial_balance } = contract_alice.balanceOf(alice_addr).call().await?; @@ -737,7 +737,7 @@ async fn burn_rejects_insufficient_balance(alice: Account) -> Result<()> { let balance = uint!(10_U256); let value = uint!(11_U256); - _ = watch!(contract_alice.mint(alice.address(), balance))?; + watch!(contract_alice.mint(alice.address(), balance))?; let Erc20::balanceOfReturn { balance: initial_balance } = contract_alice.balanceOf(alice_addr).call().await?; @@ -780,7 +780,7 @@ async fn burns_from(alice: Account, bob: Account) -> Result<()> { let balance = uint!(10_U256); let value = uint!(1_U256); - _ = watch!(contract_alice.mint(alice.address(), balance))?; + watch!(contract_alice.mint(alice.address(), balance))?; let Erc20::balanceOfReturn { balance: initial_alice_balance } = contract_alice.balanceOf(alice_addr).call().await?; @@ -789,7 +789,7 @@ async fn burns_from(alice: Account, bob: Account) -> Result<()> { let Erc20::totalSupplyReturn { totalSupply: initial_supply } = contract_alice.totalSupply().call().await?; - _ = watch!(contract_alice.approve(bob_addr, balance))?; + watch!(contract_alice.approve(bob_addr, balance))?; let Erc20::allowanceReturn { allowance: initial_allowance } = contract_alice.allowance(alice_addr, bob_addr).call().await?; @@ -839,7 +839,7 @@ async fn burn_from_reverts_insufficient_balance( let balance = uint!(1_U256); let value = uint!(10_U256); - _ = watch!(contract_alice.mint(alice.address(), balance))?; + watch!(contract_alice.mint(alice.address(), balance))?; let Erc20::balanceOfReturn { balance: initial_alice_balance } = contract_alice.balanceOf(alice_addr).call().await?; @@ -848,7 +848,7 @@ async fn burn_from_reverts_insufficient_balance( let Erc20::totalSupplyReturn { totalSupply: initial_supply } = contract_alice.totalSupply().call().await?; - _ = watch!(contract_alice.approve(bob_addr, value))?; + watch!(contract_alice.approve(bob_addr, value))?; let Erc20::allowanceReturn { allowance: initial_allowance } = contract_alice.allowance(alice_addr, bob_addr).call().await?; @@ -899,7 +899,7 @@ async fn burn_from_rejects_insufficient_allowance( let balance = uint!(10_U256); let value = uint!(1_U256); - _ = watch!(contract_alice.mint(alice.address(), balance))?; + watch!(contract_alice.mint(alice.address(), balance))?; let Erc20::balanceOfReturn { balance: initial_alice_balance } = contract_alice.balanceOf(alice_addr).call().await?; @@ -959,7 +959,7 @@ async fn mint_rejects_exceeding_cap(alice: Account) -> Result<()> { let cap = CAP; let balance = cap - one; - _ = watch!(contract_alice.mint(alice_addr, balance))?; + watch!(contract_alice.mint(alice_addr, balance))?; let Erc20::balanceOfReturn { balance: initial_balance } = contract_alice.balanceOf(alice_addr).call().await?; @@ -999,7 +999,7 @@ async fn mint_rejects_when_cap_reached(alice: Account) -> Result<()> { let cap = CAP; let balance = cap; - _ = watch!(contract_alice.mint(alice_addr, balance))?; + watch!(contract_alice.mint(alice_addr, balance))?; let Erc20::balanceOfReturn { balance: initial_balance } = contract_alice.balanceOf(alice_addr).call().await?; @@ -1077,7 +1077,7 @@ async fn pause_reverts_in_paused_state(alice: Account) -> eyre::Result<()> { let contract = Erc20::new(contract_addr, &alice.wallet); - _ = watch!(contract.pause())?; + watch!(contract.pause())?; let err = send!(contract.pause()).expect_err("should return `EnforcedPause`"); @@ -1097,7 +1097,7 @@ async fn unpauses(alice: Account) -> eyre::Result<()> { .address()?; let contract = Erc20::new(contract_addr, &alice.wallet); - _ = watch!(contract.pause())?; + watch!(contract.pause())?; let receipt = receipt!(contract.unpause())?; @@ -1147,14 +1147,14 @@ async fn error_when_burn_in_paused_state(alice: Account) -> Result<()> { let balance = uint!(10_U256); let value = uint!(1_U256); - _ = watch!(contract.mint(alice.address(), balance))?; + watch!(contract.mint(alice.address(), balance))?; let Erc20::balanceOfReturn { balance: initial_balance } = contract.balanceOf(alice_addr).call().await?; let Erc20::totalSupplyReturn { totalSupply: initial_supply } = contract.totalSupply().call().await?; - _ = watch!(contract.pause())?; + watch!(contract.pause())?; let err = send!(contract.burn(value)).expect_err("should return `EnforcedPause`"); @@ -1191,7 +1191,7 @@ async fn error_when_burn_from_in_paused_state( let balance = uint!(10_U256); let value = uint!(1_U256); - _ = watch!(contract_alice.mint(alice.address(), balance))?; + watch!(contract_alice.mint(alice.address(), balance))?; let Erc20::balanceOfReturn { balance: initial_alice_balance } = contract_alice.balanceOf(alice_addr).call().await?; @@ -1200,12 +1200,12 @@ async fn error_when_burn_from_in_paused_state( let Erc20::totalSupplyReturn { totalSupply: initial_supply } = contract_alice.totalSupply().call().await?; - _ = watch!(contract_alice.approve(bob_addr, balance))?; + watch!(contract_alice.approve(bob_addr, balance))?; let Erc20::allowanceReturn { allowance: initial_allowance } = contract_alice.allowance(alice_addr, bob_addr).call().await?; - _ = watch!(contract_alice.pause())?; + watch!(contract_alice.pause())?; let err = send!(contract_bob.burnFrom(alice_addr, value)) .expect_err("should return `EnforcedPause`"); @@ -1247,7 +1247,7 @@ async fn error_when_mint_in_paused_state(alice: Account) -> Result<()> { assert_eq!(U256::ZERO, initial_balance); assert_eq!(U256::ZERO, initial_supply); - _ = watch!(contract.pause())?; + watch!(contract.pause())?; let err = send!(contract.mint(alice_addr, uint!(1_U256))) .expect_err("should return `EnforcedPause`"); @@ -1280,7 +1280,7 @@ async fn error_when_transfer_in_paused_state( let balance = uint!(10_U256); - _ = watch!(contract_alice.mint(alice.address(), balance))?; + watch!(contract_alice.mint(alice.address(), balance))?; let Erc20::balanceOfReturn { balance: initial_alice_balance } = contract_alice.balanceOf(alice_addr).call().await?; @@ -1289,7 +1289,7 @@ async fn error_when_transfer_in_paused_state( let Erc20::totalSupplyReturn { totalSupply: initial_supply } = contract_alice.totalSupply().call().await?; - _ = watch!(contract_alice.pause())?; + watch!(contract_alice.pause())?; let err = send!(contract_alice.transfer(bob_addr, uint!(1_U256))) .expect_err("should return `EnforcedPause`"); @@ -1325,7 +1325,7 @@ async fn error_when_transfer_from(alice: Account, bob: Account) -> Result<()> { let balance = uint!(10_U256); - _ = watch!(contract_alice.mint(alice.address(), balance))?; + watch!(contract_alice.mint(alice.address(), balance))?; let Erc20::balanceOfReturn { balance: initial_alice_balance } = contract_alice.balanceOf(alice_addr).call().await?; @@ -1334,12 +1334,12 @@ async fn error_when_transfer_from(alice: Account, bob: Account) -> Result<()> { let Erc20::totalSupplyReturn { totalSupply: initial_supply } = contract_alice.totalSupply().call().await?; - _ = watch!(contract_alice.approve(bob_addr, balance))?; + watch!(contract_alice.approve(bob_addr, balance))?; let Erc20::allowanceReturn { allowance: initial_allowance } = contract_alice.allowance(alice_addr, bob_addr).call().await?; - _ = watch!(contract_alice.pause())?; + watch!(contract_alice.pause())?; let err = send!(contract_bob.transferFrom(alice_addr, bob_addr, uint!(1_U256))) diff --git a/examples/erc4626/tests/erc4626.rs b/examples/erc4626/tests/erc4626.rs index e1ed397cd..b7359af52 100644 --- a/examples/erc4626/tests/erc4626.rs +++ b/examples/erc4626/tests/erc4626.rs @@ -62,7 +62,7 @@ async fn deploy( // Mint initial tokens to the vault if initial_tokens > U256::ZERO { let asset = ERC20Mock::new(asset_addr, &account.wallet); - _ = watch!(asset.mint(contract_addr, initial_tokens))?; + watch!(asset.mint(contract_addr, initial_tokens))?; } Ok((contract_addr, asset_addr)) @@ -139,7 +139,7 @@ mod total_assets { let asset = ERC20Mock::new(asset_addr, &alice.wallet); // Transfer additional tokens directly to the vault - _ = watch!(asset.mint(contract_addr, additional_amount))?; + watch!(asset.mint(contract_addr, additional_amount))?; let total = contract.totalAssets().call().await?.totalAssets; assert_eq!(initial_deposit + additional_amount, total); @@ -219,12 +219,8 @@ mod total_assets { let alice_addr = alice.address(); // Simulate withdrawal by transferring tokens out - _ = watch!(asset.regular_approve( - contract_addr, - alice_addr, - withdrawal - ))?; - _ = watch!(asset.transferFrom(contract_addr, alice_addr, withdrawal))?; + watch!(asset.regular_approve(contract_addr, alice_addr, withdrawal))?; + watch!(asset.transferFrom(contract_addr, alice_addr, withdrawal))?; let total = contract.totalAssets().call().await?.totalAssets; assert_eq!(initial_deposit - withdrawal, total); @@ -410,13 +406,13 @@ mod convert_to_assets { let expected_assets = shares; // Mint shares - _ = watch!(asset.mint(alice.address(), expected_assets))?; - _ = watch!(asset.regular_approve( + watch!(asset.mint(alice.address(), expected_assets))?; + watch!(asset.regular_approve( alice.address(), contract_addr, expected_assets ))?; - _ = watch!(contract.mint(shares, alice.address()))?; + watch!(contract.mint(shares, alice.address()))?; let assets = contract.convertToAssets(shares).call().await?.assets; @@ -656,7 +652,7 @@ mod deposit { let erc20_alice = ERC20Mock::new(asset_addr, &alice.wallet); let alice_address = alice.address(); - _ = watch!(erc20_alice.mint(alice_address, uint!(1000_U256)))?; + watch!(erc20_alice.mint(alice_address, uint!(1000_U256)))?; let initial_alice_balance = erc20_alice.balanceOf(alice_address).call().await?._0; @@ -694,14 +690,14 @@ mod deposit { let erc20_alice = ERC20Mock::new(asset_addr, &alice.wallet); let alice_address = alice.address(); - _ = watch!(erc20_alice.mint(alice_address, assets_to_convert))?; + watch!(erc20_alice.mint(alice_address, assets_to_convert))?; let initial_alice_balance = erc20_alice.balanceOf(alice_address).call().await?._0; let initial_alice_shares = contract.balanceOf(alice_address).call().await?.balance; - _ = watch!(erc20_alice.regular_approve( + watch!(erc20_alice.regular_approve( alice_address, contract_addr, assets_to_convert @@ -738,14 +734,14 @@ mod deposit { let erc20_alice = ERC20Mock::new(asset_addr, &alice.wallet); let alice_address = alice.address(); - _ = watch!(erc20_alice.mint(alice_address, assets_to_convert))?; + watch!(erc20_alice.mint(alice_address, assets_to_convert))?; let initial_alice_balance = erc20_alice.balanceOf(alice_address).call().await?._0; let initial_alice_shares = contract.balanceOf(alice_address).call().await?.balance; - _ = watch!(erc20_alice.regular_approve( + watch!(erc20_alice.regular_approve( alice_address, contract_addr, assets_to_convert @@ -784,8 +780,8 @@ mod deposit { let erc20_alice = ERC20Mock::new(asset_addr, &alice.wallet); let alice_address = alice.address(); - _ = watch!(erc20_alice.mint(alice_address, assets_to_convert))?; - _ = watch!(erc20_alice.regular_approve( + watch!(erc20_alice.mint(alice_address, assets_to_convert))?; + watch!(erc20_alice.regular_approve( alice_address, contract_addr, assets_to_convert @@ -827,7 +823,7 @@ mod deposit { let erc20_alice = ERC20Mock::new(asset_addr, &alice.wallet); let alice_address = alice.address(); - _ = watch!(erc20_alice.mint(alice_address, assets_to_convert))?; + watch!(erc20_alice.mint(alice_address, assets_to_convert))?; let err = send!(contract.deposit(assets_to_convert, alice_address)) .expect_err("should return `SafeErc20FailedOperation`"); @@ -870,12 +866,8 @@ mod deposit { let assets = uint!(10_U256); - _ = watch!(asset.mint(alice.address(), assets))?; - _ = watch!(asset.regular_approve( - alice.address(), - contract_addr, - assets - ))?; + watch!(asset.mint(alice.address(), assets))?; + watch!(asset.regular_approve(alice.address(), contract_addr, assets))?; let err = send!(contract.deposit(assets, alice.address())) .expect_err("should panic due to decimal offset overflow"); @@ -1069,12 +1061,8 @@ mod mint { let shares = uint!(69_U256); let assets = uint!(6969_U256); - _ = watch!(asset.mint(alice.address(), assets))?; - _ = watch!(asset.regular_approve( - alice_address, - contract_addr, - assets - ))?; + watch!(asset.mint(alice.address(), assets))?; + watch!(asset.regular_approve(alice_address, contract_addr, assets))?; let initial_alice_assets = asset.balanceOf(alice_address).call().await?._0; @@ -1112,7 +1100,7 @@ mod mint { let shares = uint!(69_U256); let assets = uint!(6969_U256); - _ = watch!(asset.mint(alice.address(), assets))?; + watch!(asset.mint(alice.address(), assets))?; let err = send!(contract.mint(shares, alice_address)) .expect_err("should return `SafeErc20FailedOperation`"); @@ -1153,12 +1141,8 @@ mod mint { let shares = uint!(10_U256); let assets = shares; // expected 1:1 - _ = watch!(asset.mint(alice.address(), assets))?; - _ = watch!(asset.regular_approve( - alice.address(), - contract_addr, - assets - ))?; + watch!(asset.mint(alice.address(), assets))?; + watch!(asset.regular_approve(alice.address(), contract_addr, assets))?; let err = send!(contract.mint(shares, alice.address())) .expect_err("should panic due to decimal offset overflow"); @@ -1214,13 +1198,13 @@ mod max_withdraw { let assets_to_deposit = uint!(1010_U256); // Mint some shares to alice - _ = watch!(asset.mint(alice.address(), assets_to_deposit))?; - _ = watch!(asset.regular_approve( + watch!(asset.mint(alice.address(), assets_to_deposit))?; + watch!(asset.regular_approve( alice.address(), contract_addr, assets_to_deposit ))?; - _ = watch!(contract.mint(shares_to_mint, alice.address()))?; + watch!(contract.mint(shares_to_mint, alice.address()))?; let max = contract.maxWithdraw(alice.address()).call().await?.maxWithdraw; @@ -1246,13 +1230,13 @@ mod max_withdraw { let assets_to_deposit = shares_to_mint; // Mint some shares to alice - _ = watch!(asset.mint(alice.address(), assets_to_deposit))?; - _ = watch!(asset.regular_approve( + watch!(asset.mint(alice.address(), assets_to_deposit))?; + watch!(asset.regular_approve( alice.address(), contract_addr, assets_to_deposit ))?; - _ = watch!(contract.mint(shares_to_mint, alice.address()))?; + watch!(contract.mint(shares_to_mint, alice.address()))?; let max = contract.maxWithdraw(alice.address()).call().await?.maxWithdraw; @@ -1280,22 +1264,22 @@ mod max_withdraw { let assets_to_deposit_bob = uint!(100_U256); // Mint some shares to alice - _ = watch!(asset.mint(alice.address(), assets_to_deposit))?; - _ = watch!(asset.regular_approve( + watch!(asset.mint(alice.address(), assets_to_deposit))?; + watch!(asset.regular_approve( alice.address(), contract_addr, assets_to_deposit ))?; - _ = watch!(contract.mint(shares_to_mint, alice.address()))?; + watch!(contract.mint(shares_to_mint, alice.address()))?; // Mint some shares to bob - _ = watch!(asset.mint(bob.address(), assets_to_deposit_bob))?; - _ = watch!(asset.regular_approve( + watch!(asset.mint(bob.address(), assets_to_deposit_bob))?; + watch!(asset.regular_approve( bob.address(), contract_addr, assets_to_deposit_bob ))?; - _ = watch!(contract_bob.mint(shares_to_mint, bob.address()))?; + watch!(contract_bob.mint(shares_to_mint, bob.address()))?; let max = contract.maxWithdraw(alice.address()).call().await?.maxWithdraw; @@ -1524,13 +1508,13 @@ mod withdraw { let asset = ERC20Mock::new(asset_addr, &alice.wallet); // Mint shares - _ = watch!(asset.mint(alice.address(), assets_to_deposit))?; - _ = watch!(asset.regular_approve( + watch!(asset.mint(alice.address(), assets_to_deposit))?; + watch!(asset.regular_approve( alice.address(), contract_addr, assets_to_deposit ))?; - _ = watch!(contract.mint(shares_to_mint, alice.address()))?; + watch!(contract.mint(shares_to_mint, alice.address()))?; let max_withdraw = contract.maxWithdraw(alice.address()).call().await?.maxWithdraw; @@ -1593,13 +1577,13 @@ mod withdraw { let asset = ERC20Mock::new(asset_addr, &alice.wallet); // Mint shares to alice - _ = watch!(asset.mint(alice.address(), assets_to_deposit))?; - _ = watch!(asset.regular_approve( + watch!(asset.mint(alice.address(), assets_to_deposit))?; + watch!(asset.regular_approve( alice.address(), contract_addr, assets_to_deposit ))?; - _ = watch!(contract.mint(shares_to_mint, alice.address()))?; + watch!(contract.mint(shares_to_mint, alice.address()))?; // Bob tries to withdraw without allowance let err = send!(bob_contract.withdraw( @@ -1672,13 +1656,13 @@ mod withdraw { let contract = Erc4626::new(contract_addr, &alice.wallet); // Setup failing asset - _ = watch!(failing_asset.mint(alice.address(), assets_to_deposit))?; - _ = watch!(failing_asset.regular_approve( + watch!(failing_asset.mint(alice.address(), assets_to_deposit))?; + watch!(failing_asset.regular_approve( alice.address(), contract_addr, assets_to_deposit ))?; - _ = watch!(contract.mint(shares_to_mint, alice.address()))?; + watch!(contract.mint(shares_to_mint, alice.address()))?; let err = send!(contract.withdraw( assets_to_withdraw, @@ -1701,13 +1685,13 @@ mod withdraw { let asset = ERC20Mock::new(asset_addr, &alice.wallet); // Mint maximum shares - _ = watch!(asset.mint(alice.address(), U256::MAX))?; - _ = watch!(asset.regular_approve( + watch!(asset.mint(alice.address(), U256::MAX))?; + watch!(asset.regular_approve( alice.address(), contract_addr, U256::MAX ))?; - _ = watch!(contract.mint(U256::MAX, alice.address()))?; + watch!(contract.mint(U256::MAX, alice.address()))?; let err = send!(contract.withdraw( U256::MAX, @@ -1740,13 +1724,13 @@ mod withdraw { assert_eq!(U256::ZERO, initial_max_withdraw); // Mint shares - _ = watch!(asset.mint(alice.address(), assets_to_deposit))?; - _ = watch!(asset.regular_approve( + watch!(asset.mint(alice.address(), assets_to_deposit))?; + watch!(asset.regular_approve( alice.address(), contract_addr, assets_to_deposit ))?; - _ = watch!(contract.mint(shares_to_mint, alice.address()))?; + watch!(contract.mint(shares_to_mint, alice.address()))?; let alice_balance = asset.balanceOf(alice.address()).call().await?._0; let bob_balance = asset.balanceOf(bob.address()).call().await?._0; @@ -1831,13 +1815,13 @@ mod withdraw { assert_eq!(initial_assets, initial_total_assets); // Mint shares - _ = watch!(asset.mint(alice.address(), assets_to_deposit))?; - _ = watch!(asset.regular_approve( + watch!(asset.mint(alice.address(), assets_to_deposit))?; + watch!(asset.regular_approve( alice.address(), contract_addr, assets_to_deposit ))?; - _ = watch!(contract.mint(shares_to_mint, alice.address()))?; + watch!(contract.mint(shares_to_mint, alice.address()))?; let alice_balance = asset.balanceOf(alice.address()).call().await?._0; let bob_balance = asset.balanceOf(bob.address()).call().await?._0; @@ -1956,8 +1940,8 @@ mod withdraw { // Mint and approve for all users for user in [&alice, &bob, &charlie] { - _ = watch!(asset.mint(user.address(), uint!(1000_U256)))?; - _ = watch!(asset.regular_approve( + watch!(asset.mint(user.address(), uint!(1000_U256)))?; + watch!(asset.regular_approve( user.address(), contract_addr, uint!(1000_U256) @@ -1965,22 +1949,22 @@ mod withdraw { } // Each user deposits different amounts - _ = watch!(contract_alice.mint(uint!(100_U256), alice.address()))?; - _ = watch!(contract_bob.mint(uint!(200_U256), bob.address()))?; - _ = watch!(contract_charlie.mint(uint!(300_U256), charlie.address()))?; + watch!(contract_alice.mint(uint!(100_U256), alice.address()))?; + watch!(contract_bob.mint(uint!(200_U256), bob.address()))?; + watch!(contract_charlie.mint(uint!(300_U256), charlie.address()))?; // Each user withdraws different percentages - _ = watch!(contract_alice.withdraw( + watch!(contract_alice.withdraw( uint!(50_U256), alice.address(), alice.address() ))?; // 50% for alice - _ = watch!(contract_bob.withdraw( + watch!(contract_bob.withdraw( uint!(100_U256), bob.address(), bob.address() ))?; // 50% for bob - _ = watch!(contract_charlie.withdraw( + watch!(contract_charlie.withdraw( uint!(300_U256), charlie.address(), charlie.address() @@ -2031,8 +2015,8 @@ mod withdraw { // Mint and approve for all users for user in [&alice, &bob, &charlie] { - _ = watch!(asset.mint(user.address(), uint!(10000_U256)))?; - _ = watch!(asset.regular_approve( + watch!(asset.mint(user.address(), uint!(10000_U256)))?; + watch!(asset.regular_approve( user.address(), contract_addr, uint!(10000_U256) @@ -2040,9 +2024,9 @@ mod withdraw { } // Each user deposits different amounts - _ = watch!(contract_alice.mint(uint!(10_U256), alice.address()))?; - _ = watch!(contract_bob.mint(uint!(20_U256), bob.address()))?; - _ = watch!(contract_charlie.mint(uint!(30_U256), charlie.address()))?; + watch!(contract_alice.mint(uint!(10_U256), alice.address()))?; + watch!(contract_bob.mint(uint!(20_U256), bob.address()))?; + watch!(contract_charlie.mint(uint!(30_U256), charlie.address()))?; // Verify share distribution considers initial assets let alice_assets_before = contract_alice @@ -2059,17 +2043,17 @@ mod withdraw { .maxWithdraw; // Each user withdraws - _ = watch!(contract_alice.withdraw( + watch!(contract_alice.withdraw( alice_assets_before, alice.address(), alice.address() ))?; // 100% - _ = watch!(contract_bob.withdraw( + watch!(contract_bob.withdraw( uint!(1010_U256), bob.address(), bob.address() ))?; // 50% - _ = watch!(contract_charlie.withdraw( + watch!(contract_charlie.withdraw( charlie_assets_before, charlie.address(), charlie.address() @@ -2104,20 +2088,16 @@ mod withdraw { let assets = uint!(2000_U256); // Setup deposits - _ = watch!(asset.mint(alice.address(), assets))?; - _ = watch!(asset.regular_approve( - alice.address(), - contract_addr, - assets - ))?; - _ = watch!(contract.mint(shares, alice.address()))?; + watch!(asset.mint(alice.address(), assets))?; + watch!(asset.regular_approve(alice.address(), contract_addr, assets))?; + watch!(contract.mint(shares, alice.address()))?; // Record initial conversion rate let initial_rate = contract.convertToAssets(uint!(1_U256)).call().await?.assets; // Perform partial withdrawal - _ = watch!(contract.withdraw( + watch!(contract.withdraw( uint!(500_U256), alice.address(), alice.address() @@ -2146,13 +2126,13 @@ mod withdraw { let asset = ERC20Mock::new(asset_addr, &alice.wallet); // Setup initial state - _ = watch!(asset.mint(alice.address(), assets_to_deposit))?; - _ = watch!(asset.regular_approve( + watch!(asset.mint(alice.address(), assets_to_deposit))?; + watch!(asset.regular_approve( alice.address(), contract_addr, assets_to_deposit ))?; - _ = watch!(contract.mint(shares_to_mint, alice.address()))?; + watch!(contract.mint(shares_to_mint, alice.address()))?; // Record state before failed withdrawal let pre_total_assets = contract.totalAssets().call().await?.totalAssets; @@ -2162,7 +2142,7 @@ mod withdraw { contract.maxRedeem(alice.address()).call().await?.maxRedeem; // Attempt excessive withdrawal - _ = send!(contract.withdraw( + send!(contract.withdraw( excessive_assets_to_withdraw, alice.address(), alice.address() @@ -2252,13 +2232,13 @@ mod max_redeem { let shares_to_mint = uint!(69_U256); // Mint some shares to alice - _ = watch!(asset.mint(alice.address(), assets_to_deposit))?; - _ = watch!(asset.regular_approve( + watch!(asset.mint(alice.address(), assets_to_deposit))?; + watch!(asset.regular_approve( alice.address(), contract_addr, assets_to_deposit ))?; - _ = watch!(contract.mint(shares_to_mint, alice.address()))?; + watch!(contract.mint(shares_to_mint, alice.address()))?; let max = contract.maxRedeem(alice.address()).call().await?.maxRedeem; assert_eq!(shares_to_mint, max); @@ -2282,16 +2262,16 @@ mod max_redeem { let transfer_amount = uint!(40_U256); // Mint shares to alice - _ = watch!(asset.mint(alice.address(), assets_to_deposit))?; - _ = watch!(asset.regular_approve( + watch!(asset.mint(alice.address(), assets_to_deposit))?; + watch!(asset.regular_approve( alice.address(), contract_addr, assets_to_deposit ))?; - _ = watch!(contract.mint(shares_to_mint, alice.address()))?; + watch!(contract.mint(shares_to_mint, alice.address()))?; // Transfer some shares to bob - _ = watch!(contract.transfer(bob.address(), transfer_amount))?; + watch!(contract.transfer(bob.address(), transfer_amount))?; let alice_max = contract.maxRedeem(alice.address()).call().await?.maxRedeem; @@ -2317,26 +2297,26 @@ mod max_redeem { let assets_for_second_mint = uint!(5050_U256); // First mint - _ = watch!(asset.mint(alice.address(), assets_for_first_mint))?; - _ = watch!(asset.regular_approve( + watch!(asset.mint(alice.address(), assets_for_first_mint))?; + watch!(asset.regular_approve( alice.address(), contract_addr, assets_for_first_mint ))?; - _ = watch!(contract.mint(first_mint, alice.address()))?; + watch!(contract.mint(first_mint, alice.address()))?; let max_after_first = contract.maxRedeem(alice.address()).call().await?.maxRedeem; assert_eq!(first_mint, max_after_first); // Second mint - _ = watch!(asset.mint(alice.address(), assets_for_second_mint))?; - _ = watch!(asset.regular_approve( + watch!(asset.mint(alice.address(), assets_for_second_mint))?; + watch!(asset.regular_approve( alice.address(), contract_addr, assets_for_second_mint ))?; - _ = watch!(contract.mint(second_mint, alice.address()))?; + watch!(contract.mint(second_mint, alice.address()))?; let max_after_second = contract.maxRedeem(alice.address()).call().await?.maxRedeem; @@ -2519,13 +2499,9 @@ mod redeem { let shares = uint!(69_U256); // Mint some shares to alice - _ = watch!(asset.mint(alice.address(), assets))?; - _ = watch!(asset.regular_approve( - alice.address(), - contract_addr, - assets - ))?; - _ = watch!(contract.mint(shares, alice.address()))?; + watch!(asset.mint(alice.address(), assets))?; + watch!(asset.regular_approve(alice.address(), contract_addr, assets))?; + watch!(contract.mint(shares, alice.address()))?; let initial_alice_assets = asset.balanceOf(alice_address).call().await?._0; @@ -2570,13 +2546,9 @@ mod redeem { let shares = uint!(69_U256); // Mint some shares to alice - _ = watch!(asset.mint(alice.address(), assets))?; - _ = watch!(asset.regular_approve( - alice.address(), - contract_addr, - assets - ))?; - _ = watch!(contract.mint(shares, alice.address()))?; + watch!(asset.mint(alice.address(), assets))?; + watch!(asset.regular_approve(alice.address(), contract_addr, assets))?; + watch!(contract.mint(shares, alice.address()))?; let err = send!(contract_bob.redeem(shares, alice_address, alice_address)) @@ -2604,13 +2576,9 @@ mod redeem { let shares = uint!(69_U256); // Mint some shares to alice - _ = watch!(asset.mint(alice.address(), assets))?; - _ = watch!(asset.regular_approve( - alice.address(), - contract_addr, - assets - ))?; - _ = watch!(contract.mint(shares, alice.address()))?; + watch!(asset.mint(alice.address(), assets))?; + watch!(asset.regular_approve(alice.address(), contract_addr, assets))?; + watch!(contract.mint(shares, alice.address()))?; let err = send!(contract.redeem( shares + uint!(1_U256), diff --git a/examples/erc721-consecutive/tests/erc721-consecutive.rs b/examples/erc721-consecutive/tests/erc721-consecutive.rs index c94f3314d..a24373b7b 100644 --- a/examples/erc721-consecutive/tests/erc721-consecutive.rs +++ b/examples/erc721-consecutive/tests/erc721-consecutive.rs @@ -71,7 +71,7 @@ async fn mints(alice: Account) -> eyre::Result<()> { assert_eq!(balance1, U256::from(batch_size)); let token_id = random_token_id(); - _ = watch!(contract.mint(alice.address(), token_id))?; + watch!(contract.mint(alice.address(), token_id))?; let Erc721::balanceOfReturn { balance: balance2 } = contract.balanceOf(alice.address()).call().await?; @@ -130,7 +130,7 @@ async fn transfers_from(alice: Account, bob: Account) -> eyre::Result<()> { let first_consecutive_token_id = U256::from(FIRST_CONSECUTIVE_ID); // Transfer first consecutive token from Alice to Bob. - _ = watch!(contract.transferFrom( + watch!(contract.transferFrom( alice.address(), bob.address(), first_consecutive_token_id @@ -150,17 +150,13 @@ async fn transfers_from(alice: Account, bob: Account) -> eyre::Result<()> { // Test non-consecutive mint. let token_id = random_token_id(); - _ = watch!(contract.mint(alice.address(), token_id))?; + watch!(contract.mint(alice.address(), token_id))?; let Erc721::balanceOfReturn { balance: alice_balance } = contract.balanceOf(alice.address()).call().await?; assert_eq!(alice_balance, uint!(1000_U256)); // Test transfer of the token that wasn't minted consecutive. - _ = watch!(contract.transferFrom( - alice.address(), - bob.address(), - token_id - ))?; + watch!(contract.transferFrom(alice.address(), bob.address(), token_id))?; let Erc721::balanceOfReturn { balance: alice_balance } = contract.balanceOf(alice.address()).call().await?; assert_eq!(alice_balance, uint!(1000_U256) - uint!(1_U256)); @@ -206,7 +202,7 @@ async fn burns(alice: Account) -> eyre::Result<()> { // Check non-consecutive token burn. let non_consecutive_token_id = random_token_id(); - _ = watch!(contract.mint(alice.address(), non_consecutive_token_id))?; + watch!(contract.mint(alice.address(), non_consecutive_token_id))?; let Erc721::ownerOfReturn { ownerOf } = contract.ownerOf(non_consecutive_token_id).call().await?; assert_eq!(ownerOf, alice.address()); diff --git a/examples/erc721-metadata/tests/erc721.rs b/examples/erc721-metadata/tests/erc721.rs index 66c9e5af9..7d62644fa 100644 --- a/examples/erc721-metadata/tests/erc721.rs +++ b/examples/erc721-metadata/tests/erc721.rs @@ -100,7 +100,7 @@ async fn return_empty_token_uri_when_without_base_uri_and_token_uri( let token_id = random_token_id(); - _ = watch!(contract.mint(alice.address(), token_id))?; + watch!(contract.mint(alice.address(), token_id))?; let Erc721::tokenURIReturn { tokenURI } = contract.tokenURI(token_id).call().await?; @@ -127,7 +127,7 @@ async fn return_token_uri_with_base_uri_and_without_token_uri( let token_id = random_token_id(); - _ = watch!(contract.mint(alice.address(), token_id))?; + watch!(contract.mint(alice.address(), token_id))?; let Erc721::tokenURIReturn { tokenURI } = contract.tokenURI(token_id).call().await?; @@ -153,7 +153,7 @@ async fn return_token_uri_with_base_uri_and_token_uri( let token_id = random_token_id(); - _ = watch!(contract.mint(alice.address(), token_id))?; + watch!(contract.mint(alice.address(), token_id))?; let token_uri = String::from( "blob/main/contracts/src/token/erc721/extensions/uri_storage.rs", @@ -204,7 +204,7 @@ async fn set_token_uri_before_mint(alice: Account) -> eyre::Result<()> { assert!(receipt.emits(Erc721::MetadataUpdate { tokenId: token_id })); - _ = watch!(contract.mint(alice.address(), token_id))?; + watch!(contract.mint(alice.address(), token_id))?; let Erc721::tokenURIReturn { tokenURI } = contract.tokenURI(token_id).call().await?; @@ -233,7 +233,7 @@ async fn return_token_uri_after_burn_and_remint( let token_id = random_token_id(); - _ = watch!(contract.mint(alice.address(), token_id))?; + watch!(contract.mint(alice.address(), token_id))?; let receipt = receipt!(contract.burn(token_id))?; diff --git a/examples/erc721/tests/erc721.rs b/examples/erc721/tests/erc721.rs index 477036731..3f1ded996 100644 --- a/examples/erc721/tests/erc721.rs +++ b/examples/erc721/tests/erc721.rs @@ -117,7 +117,7 @@ async fn error_when_minting_token_id_twice(alice: Account) -> eyre::Result<()> { let alice_addr = alice.address(); let token_id = random_token_id(); - _ = watch!(contract.mint(alice_addr, token_id))?; + watch!(contract.mint(alice_addr, token_id))?; let err = send!(contract.mint(alice_addr, token_id)) .expect_err("should not mint a token id twice"); @@ -154,7 +154,7 @@ async fn transfers_from(alice: Account, bob: Account) -> eyre::Result<()> { let alice_addr = alice.address(); let bob_addr = bob.address(); let token_id = random_token_id(); - _ = watch!(contract.mint(alice_addr, token_id))?; + watch!(contract.mint(alice_addr, token_id))?; let Erc721::balanceOfReturn { balance: initial_alice_balance } = contract.balanceOf(alice_addr).call().await?; @@ -201,8 +201,8 @@ async fn transfers_from_approved_token( let bob_addr = bob.address(); let token_id = random_token_id(); - _ = watch!(contract_alice.mint(alice_addr, token_id))?; - _ = watch!(contract_alice.approve(bob_addr, token_id))?; + watch!(contract_alice.mint(alice_addr, token_id))?; + watch!(contract_alice.approve(bob_addr, token_id))?; let Erc721::balanceOfReturn { balance: initial_alice_balance } = contract_alice.balanceOf(alice_addr).call().await?; @@ -249,8 +249,8 @@ async fn transfers_from_approved_for_all( let bob_addr = bob.address(); let token_id = random_token_id(); - _ = watch!(contract_alice.mint(alice_addr, token_id))?; - _ = watch!(contract_alice.setApprovalForAll(bob_addr, true))?; + watch!(contract_alice.mint(alice_addr, token_id))?; + watch!(contract_alice.setApprovalForAll(bob_addr, true))?; let Erc721::balanceOfReturn { balance: initial_alice_balance } = contract_alice.balanceOf(alice_addr).call().await?; @@ -295,7 +295,7 @@ async fn error_when_transfer_to_invalid_receiver( let invalid_receiver = Address::ZERO; let token_id = random_token_id(); - _ = watch!(contract.mint(alice_addr, token_id))?; + watch!(contract.mint(alice_addr, token_id))?; let err = send!(contract.transferFrom(alice_addr, invalid_receiver, token_id)) @@ -327,7 +327,7 @@ async fn error_when_transfer_from_incorrect_owner( let token_id = random_token_id(); - _ = watch!(contract.mint(alice_addr, token_id))?; + watch!(contract.mint(alice_addr, token_id))?; let err = send!(contract.transferFrom(dave_addr, bob_addr, token_id)) .expect_err("should not transfer the token from incorrect owner"); @@ -356,7 +356,7 @@ async fn error_when_transfer_with_insufficient_approval( let alice_addr = alice.address(); let bob_addr = bob.address(); let token_id = random_token_id(); - _ = watch!(contract.mint(alice_addr, token_id))?; + watch!(contract.mint(alice_addr, token_id))?; let contract = Erc721::new(contract_addr, &bob.wallet); let err = send!(contract.transferFrom(alice_addr, bob_addr, token_id)) @@ -412,7 +412,7 @@ async fn safe_transfers_from(alice: Account, bob: Account) -> eyre::Result<()> { let alice_addr = alice.address(); let bob_addr = bob.address(); let token_id = random_token_id(); - _ = watch!(contract.mint(alice_addr, token_id))?; + watch!(contract.mint(alice_addr, token_id))?; let Erc721::balanceOfReturn { balance: initial_alice_balance } = contract.balanceOf(alice_addr).call().await?; @@ -460,7 +460,7 @@ async fn safe_transfers_to_receiver_contract( let alice_addr = alice.address(); let token_id = random_token_id(); - _ = watch!(contract.mint(alice_addr, token_id))?; + watch!(contract.mint(alice_addr, token_id))?; let Erc721::balanceOfReturn { balance: initial_alice_balance } = contract.balanceOf(alice_addr).call().await?; @@ -517,8 +517,8 @@ async fn safe_transfers_from_approved_token( let bob_addr = bob.address(); let token_id = random_token_id(); - _ = watch!(contract_alice.mint(alice_addr, token_id))?; - _ = watch!(contract_alice.approve(bob_addr, token_id))?; + watch!(contract_alice.mint(alice_addr, token_id))?; + watch!(contract_alice.approve(bob_addr, token_id))?; let Erc721::balanceOfReturn { balance: initial_alice_balance } = contract_alice.balanceOf(alice_addr).call().await?; @@ -566,8 +566,8 @@ async fn safe_transfers_from_approved_for_all( let bob_addr = bob.address(); let token_id = random_token_id(); - _ = watch!(contract_alice.mint(alice_addr, token_id))?; - _ = watch!(contract_alice.setApprovalForAll(bob_addr, true))?; + watch!(contract_alice.mint(alice_addr, token_id))?; + watch!(contract_alice.setApprovalForAll(bob_addr, true))?; let Erc721::balanceOfReturn { balance: initial_alice_balance } = contract_alice.balanceOf(alice_addr).call().await?; @@ -613,7 +613,7 @@ async fn error_when_safe_transfer_to_invalid_receiver( let invalid_receiver = Address::ZERO; let token_id = random_token_id(); - _ = watch!(contract.mint(alice_addr, token_id))?; + watch!(contract.mint(alice_addr, token_id))?; let err = send!(contract.safeTransferFrom_0( alice_addr, @@ -647,7 +647,7 @@ async fn error_when_safe_transfer_from_incorrect_owner( let token_id = random_token_id(); - _ = watch!(contract.mint(alice_addr, token_id))?; + watch!(contract.mint(alice_addr, token_id))?; let err = send!(contract.safeTransferFrom_0(dave_addr, bob_addr, token_id)) .expect_err("should not transfer the token from incorrect owner"); @@ -676,7 +676,7 @@ async fn error_when_safe_transfer_with_insufficient_approval( let alice_addr = alice.address(); let bob_addr = bob.address(); let token_id = random_token_id(); - _ = watch!(contract.mint(alice_addr, token_id))?; + watch!(contract.mint(alice_addr, token_id))?; let contract = Erc721::new(contract_addr, &bob.wallet); @@ -738,7 +738,7 @@ async fn safe_transfers_from_with_data( let alice_addr = alice.address(); let bob_addr = bob.address(); let token_id = random_token_id(); - _ = watch!(contract.mint(alice_addr, token_id))?; + watch!(contract.mint(alice_addr, token_id))?; let Erc721::balanceOfReturn { balance: initial_alice_balance } = contract.balanceOf(alice_addr).call().await?; @@ -791,7 +791,7 @@ async fn safe_transfers_with_data_to_receiver_contract( let token_id = random_token_id(); let data: Bytes = fixed_bytes!("deadbeef").into(); - _ = watch!(contract.mint(alice_addr, token_id))?; + watch!(contract.mint(alice_addr, token_id))?; let Erc721::balanceOfReturn { balance: initial_alice_balance } = contract.balanceOf(alice_addr).call().await?; @@ -849,8 +849,8 @@ async fn safe_transfers_from_with_data_approved_token( let bob_addr = bob.address(); let token_id = random_token_id(); - _ = watch!(contract_alice.mint(alice_addr, token_id))?; - _ = watch!(contract_alice.approve(bob_addr, token_id))?; + watch!(contract_alice.mint(alice_addr, token_id))?; + watch!(contract_alice.approve(bob_addr, token_id))?; let Erc721::balanceOfReturn { balance: initial_alice_balance } = contract_alice.balanceOf(alice_addr).call().await?; @@ -901,8 +901,8 @@ async fn safe_transfers_from_with_data_approved_for_all( let bob_addr = bob.address(); let token_id = random_token_id(); - _ = watch!(contract_alice.mint(alice_addr, token_id))?; - _ = watch!(contract_alice.setApprovalForAll(bob_addr, true))?; + watch!(contract_alice.mint(alice_addr, token_id))?; + watch!(contract_alice.setApprovalForAll(bob_addr, true))?; let Erc721::balanceOfReturn { balance: initial_alice_balance } = contract_alice.balanceOf(alice_addr).call().await?; @@ -951,7 +951,7 @@ async fn error_when_safe_transfer_with_data_to_invalid_receiver( let invalid_receiver = Address::ZERO; let token_id = random_token_id(); - _ = watch!(contract.mint(alice_addr, token_id))?; + watch!(contract.mint(alice_addr, token_id))?; let err = send!(contract.safeTransferFrom_1( alice_addr, @@ -986,7 +986,7 @@ async fn error_when_safe_transfer_with_data_from_incorrect_owner( let token_id = random_token_id(); - _ = watch!(contract.mint(alice_addr, token_id))?; + watch!(contract.mint(alice_addr, token_id))?; let err = send!(contract.safeTransferFrom_1( dave_addr, @@ -1020,7 +1020,7 @@ async fn error_when_safe_transfer_with_data_with_insufficient_approval( let alice_addr = alice.address(); let bob_addr = bob.address(); let token_id = random_token_id(); - _ = watch!(contract.mint(alice_addr, token_id))?; + watch!(contract.mint(alice_addr, token_id))?; let contract = Erc721::new(contract_addr, &bob.wallet); @@ -1095,7 +1095,7 @@ async fn errors_when_receiver_reverts_with_reason( let alice_addr = alice.address(); let token_id = random_token_id(); - _ = watch!(contract.mint(alice_addr, token_id))?; + watch!(contract.mint(alice_addr, token_id))?; let err = send!(contract.safeTransferFrom_0( alice_addr, @@ -1127,7 +1127,7 @@ async fn errors_when_receiver_reverts_without_reason( let alice_addr = alice.address(); let token_id = random_token_id(); - _ = watch!(contract.mint(alice_addr, token_id))?; + watch!(contract.mint(alice_addr, token_id))?; let err = send!(contract.safeTransferFrom_0( alice_addr, @@ -1155,7 +1155,7 @@ async fn errors_when_receiver_panics(alice: Account) -> eyre::Result<()> { let alice_addr = alice.address(); let token_id = random_token_id(); - _ = watch!(contract.mint(alice_addr, token_id))?; + watch!(contract.mint(alice_addr, token_id))?; let err = send!(contract.safeTransferFrom_0( alice_addr, @@ -1180,7 +1180,7 @@ async fn approves(alice: Account, bob: Account) -> eyre::Result<()> { let bob_addr = bob.address(); let token_id = random_token_id(); - _ = watch!(contract.mint(alice_addr, token_id))?; + watch!(contract.mint(alice_addr, token_id))?; let Erc721::getApprovedReturn { approved } = contract.getApproved(token_id).call().await?; @@ -1235,7 +1235,7 @@ async fn error_when_approve_by_invalid_approver( let bob_addr = bob.address(); let token_id = random_token_id(); - _ = watch!(contract_alice.mint(alice_addr, token_id))?; + watch!(contract_alice.mint(alice_addr, token_id))?; let err = send!(contract_bob.approve(bob_addr, token_id)) .expect_err("should not approve when invalid approver"); @@ -1521,7 +1521,7 @@ async fn error_when_safe_mint_to_invalid_sender_with_data( let token_id = random_token_id(); let data: Bytes = fixed_bytes!("deadbeef").into(); - _ = watch!(contract.mint(alice.address(), token_id))?; + watch!(contract.mint(alice.address(), token_id))?; let err = send!(contract.safeMint(bob.address(), token_id, data)) .expect_err("should not safe mint an existing token"); @@ -1636,7 +1636,7 @@ async fn pause_reverts_in_paused_state(alice: Account) -> eyre::Result<()> { let contract = Erc721::new(contract_addr, &alice.wallet); - _ = watch!(contract.pause())?; + watch!(contract.pause())?; let err = send!(contract.pause()).expect_err("should return `EnforcedPause`"); @@ -1651,7 +1651,7 @@ async fn unpauses(alice: Account) -> eyre::Result<()> { let contract_addr = alice.as_deployer().deploy().await?.address()?; let contract = Erc721::new(contract_addr, &alice.wallet); - _ = watch!(contract.pause())?; + watch!(contract.pause())?; let receipt = receipt!(contract.unpause())?; @@ -1689,12 +1689,12 @@ async fn error_when_burn_in_paused_state(alice: Account) -> eyre::Result<()> { let alice_addr = alice.address(); let token_id = random_token_id(); - _ = watch!(contract.mint(alice_addr, token_id))?; + watch!(contract.mint(alice_addr, token_id))?; let Erc721::balanceOfReturn { balance: initial_balance } = contract.balanceOf(alice_addr).call().await?; - _ = watch!(contract.pause()); + watch!(contract.pause()); let err = send!(contract.burn(token_id)) .expect_err("should return `EnforcedPause`"); @@ -1721,7 +1721,7 @@ async fn error_when_mint_in_paused_state(alice: Account) -> eyre::Result<()> { let alice_addr = alice.address(); let token_id = random_token_id(); - _ = watch!(contract.pause())?; + watch!(contract.pause())?; let err = send!(contract.mint(alice_addr, token_id)) .expect_err("should return `EnforcedPause`"); @@ -1755,7 +1755,7 @@ async fn error_when_transfer_in_paused_state( let alice_addr = alice.address(); let bob_addr = bob.address(); let token_id = random_token_id(); - _ = watch!(contract.mint(alice_addr, token_id))?; + watch!(contract.mint(alice_addr, token_id))?; let Erc721::balanceOfReturn { balance: initial_alice_balance } = contract.balanceOf(alice_addr).call().await?; @@ -1763,7 +1763,7 @@ async fn error_when_transfer_in_paused_state( let Erc721::balanceOfReturn { balance: initial_bob_balance } = contract.balanceOf(bob_addr).call().await?; - _ = watch!(contract.pause())?; + watch!(contract.pause())?; let err = send!(contract.transferFrom(alice_addr, bob_addr, token_id)) .expect_err("should return `EnforcedPause`"); @@ -1796,7 +1796,7 @@ async fn error_when_safe_transfer_in_paused_state( let alice_addr = alice.address(); let bob_addr = bob.address(); let token_id = random_token_id(); - _ = watch!(contract.mint(alice_addr, token_id))?; + watch!(contract.mint(alice_addr, token_id))?; let Erc721::balanceOfReturn { balance: initial_alice_balance } = contract.balanceOf(alice_addr).call().await?; @@ -1804,7 +1804,7 @@ async fn error_when_safe_transfer_in_paused_state( let Erc721::balanceOfReturn { balance: initial_bob_balance } = contract.balanceOf(bob_addr).call().await?; - _ = watch!(contract.pause())?; + watch!(contract.pause())?; let err = send!(contract.safeTransferFrom_0(alice_addr, bob_addr, token_id)) @@ -1838,7 +1838,7 @@ async fn error_when_safe_transfer_with_data_in_paused_state( let alice_addr = alice.address(); let bob_addr = bob.address(); let token_id = random_token_id(); - _ = watch!(contract.mint(alice_addr, token_id))?; + watch!(contract.mint(alice_addr, token_id))?; let Erc721::balanceOfReturn { balance: initial_alice_balance } = contract.balanceOf(alice_addr).call().await?; @@ -1846,7 +1846,7 @@ async fn error_when_safe_transfer_with_data_in_paused_state( let Erc721::balanceOfReturn { balance: initial_bob_balance } = contract.balanceOf(bob_addr).call().await?; - _ = watch!(contract.pause())?; + watch!(contract.pause())?; let err = send!(contract.safeTransferFrom_1( alice_addr, @@ -1886,7 +1886,7 @@ async fn error_when_safe_mint_in_paused_state( let Erc721::balanceOfReturn { balance: initial_alice_balance } = contract.balanceOf(alice_addr).call().await?; - _ = watch!(contract.pause())?; + watch!(contract.pause())?; let err = send!(contract.safeMint( alice_addr, @@ -1925,7 +1925,7 @@ async fn burns(alice: Account) -> eyre::Result<()> { let alice_addr = alice.address(); let token_id = random_token_id(); - _ = watch!(contract.mint(alice_addr, token_id))?; + watch!(contract.mint(alice_addr, token_id))?; let Erc721::balanceOfReturn { balance: initial_balance } = contract.balanceOf(alice_addr).call().await?; @@ -1969,8 +1969,8 @@ async fn burns_approved_token( let bob_addr = bob.address(); let token_id = random_token_id(); - _ = watch!(contract_alice.mint(alice_addr, token_id))?; - _ = watch!(contract_alice.approve(bob_addr, token_id))?; + watch!(contract_alice.mint(alice_addr, token_id))?; + watch!(contract_alice.approve(bob_addr, token_id))?; let Erc721::balanceOfReturn { balance: initial_balance } = contract_alice.balanceOf(alice_addr).call().await?; @@ -2014,8 +2014,8 @@ async fn burns_approved_for_all( let bob_addr = bob.address(); let token_id = random_token_id(); - _ = watch!(contract_alice.mint(alice_addr, token_id))?; - _ = watch!(contract_alice.setApprovalForAll(bob_addr, true))?; + watch!(contract_alice.mint(alice_addr, token_id))?; + watch!(contract_alice.setApprovalForAll(bob_addr, true))?; let Erc721::balanceOfReturn { balance: initial_balance } = contract_alice.balanceOf(alice_addr).call().await?; @@ -2057,7 +2057,7 @@ async fn error_when_burn_with_insufficient_approval( let alice_addr = alice.address(); let bob_addr = bob.address(); let token_id = random_token_id(); - _ = watch!(contract.mint(alice_addr, token_id))?; + watch!(contract.mint(alice_addr, token_id))?; let Erc721::balanceOfReturn { balance: initial_balance } = contract.balanceOf(alice_addr).call().await?; @@ -2106,10 +2106,10 @@ async fn totally_supply_works(alice: Account) -> eyre::Result<()> { let alice_addr = alice.address(); let token_1 = random_token_id(); - _ = watch!(contract.mint(alice_addr, token_1))?; + watch!(contract.mint(alice_addr, token_1))?; let token_2 = random_token_id(); - _ = watch!(contract.mint(alice_addr, token_2))?; + watch!(contract.mint(alice_addr, token_2))?; let Erc721::totalSupplyReturn { totalSupply } = contract.totalSupply().call().await?; @@ -2128,8 +2128,8 @@ async fn error_when_checking_token_of_owner_by_index_out_of_bound( let alice_addr = alice.address(); - _ = watch!(contract.mint(alice_addr, random_token_id()))?; - _ = watch!(contract.mint(alice_addr, random_token_id()))?; + watch!(contract.mint(alice_addr, random_token_id()))?; + watch!(contract.mint(alice_addr, random_token_id()))?; let index_out_of_bound = uint!(2_U256); @@ -2180,10 +2180,10 @@ async fn token_of_owner_by_index_works(alice: Account) -> eyre::Result<()> { let alice_addr = alice.address(); let token_0 = random_token_id(); - _ = watch!(contract.mint(alice_addr, token_0))?; + watch!(contract.mint(alice_addr, token_0))?; let token_1 = random_token_id(); - _ = watch!(contract.mint(alice_addr, token_1))?; + watch!(contract.mint(alice_addr, token_1))?; let Erc721::tokenOfOwnerByIndexReturn { tokenId } = contract.tokenOfOwnerByIndex(alice_addr, uint!(0_U256)).call().await?; @@ -2208,13 +2208,13 @@ async fn token_of_owner_by_index_after_transfer_to_another_account( let bob_addr = bob.address(); let token_0 = random_token_id(); - _ = watch!(contract.mint(alice_addr, token_0))?; + watch!(contract.mint(alice_addr, token_0))?; let token_1 = random_token_id(); - _ = watch!(contract.mint(alice_addr, token_1))?; + watch!(contract.mint(alice_addr, token_1))?; - _ = watch!(contract.transferFrom(alice_addr, bob_addr, token_1))?; - _ = watch!(contract.transferFrom(alice_addr, bob_addr, token_0))?; + watch!(contract.transferFrom(alice_addr, bob_addr, token_1))?; + watch!(contract.transferFrom(alice_addr, bob_addr, token_0))?; // should be in reverse order let index = uint!(0_U256); @@ -2285,8 +2285,8 @@ async fn error_when_checking_token_by_index_out_of_bound( let alice_addr = alice.address(); - _ = watch!(contract.mint(alice_addr, random_token_id()))?; - _ = watch!(contract.mint(alice_addr, random_token_id()))?; + watch!(contract.mint(alice_addr, random_token_id()))?; + watch!(contract.mint(alice_addr, random_token_id()))?; let index_out_of_bound = uint!(2_U256); @@ -2312,10 +2312,10 @@ async fn token_by_index_works(alice: Account) -> eyre::Result<()> { let alice_addr = alice.address(); let token_0 = random_token_id(); - _ = watch!(contract.mint(alice_addr, token_0))?; + watch!(contract.mint(alice_addr, token_0))?; let token_1 = random_token_id(); - _ = watch!(contract.mint(alice_addr, token_1))?; + watch!(contract.mint(alice_addr, token_1))?; let Erc721::tokenByIndexReturn { tokenId } = contract.tokenByIndex(uint!(0_U256)).call().await?; @@ -2336,12 +2336,12 @@ async fn token_by_index_after_burn(alice: Account) -> eyre::Result<()> { let alice_addr = alice.address(); let token_0 = random_token_id(); - _ = watch!(contract.mint(alice_addr, token_0))?; + watch!(contract.mint(alice_addr, token_0))?; let token_1 = random_token_id(); - _ = watch!(contract.mint(alice_addr, token_1))?; + watch!(contract.mint(alice_addr, token_1))?; - _ = watch!(contract.burn(token_1))?; + watch!(contract.burn(token_1))?; let Erc721::tokenByIndexReturn { tokenId } = contract.tokenByIndex(uint!(0_U256)).call().await?; @@ -2377,18 +2377,18 @@ async fn token_by_index_after_burn_and_some_mints( let alice_addr = alice.address(); let token_0 = random_token_id(); - _ = watch!(contract.mint(alice_addr, token_0))?; + watch!(contract.mint(alice_addr, token_0))?; let token_1 = random_token_id(); - _ = watch!(contract.mint(alice_addr, token_1))?; + watch!(contract.mint(alice_addr, token_1))?; - _ = watch!(contract.burn(token_1))?; + watch!(contract.burn(token_1))?; let token_2 = random_token_id(); - _ = watch!(contract.mint(alice_addr, token_2))?; + watch!(contract.mint(alice_addr, token_2))?; let token_3 = random_token_id(); - _ = watch!(contract.mint(alice_addr, token_3))?; + watch!(contract.mint(alice_addr, token_3))?; let Erc721::tokenByIndexReturn { tokenId } = contract.tokenByIndex(uint!(0_U256)).call().await?; diff --git a/examples/safe-erc20/tests/erc20.rs b/examples/safe-erc20/tests/erc20.rs index b5d5569df..563b3a176 100644 --- a/examples/safe-erc20/tests/erc20.rs +++ b/examples/safe-erc20/tests/erc20.rs @@ -30,7 +30,7 @@ mod transfers { let erc20_address = erc20::deploy(&alice.wallet).await?; let erc20_alice = ERC20Mock::new(erc20_address, &alice.wallet); - _ = watch!(erc20_alice.mint(safe_erc20_addr, balance))?; + watch!(erc20_alice.mint(safe_erc20_addr, balance))?; let initial_safe_erc20_balance = erc20_alice.balanceOf(safe_erc20_addr).call().await?._0; @@ -117,8 +117,8 @@ mod transfers { let erc20_address = erc20::deploy(&alice.wallet).await?; let erc20_alice = ERC20Mock::new(erc20_address, &alice.wallet); - _ = watch!(erc20_alice.mint(alice_addr, balance))?; - _ = watch!(erc20_alice.approve(safe_erc20_addr, value))?; + watch!(erc20_alice.mint(alice_addr, balance))?; + watch!(erc20_alice.approve(safe_erc20_addr, value))?; let initial_alice_balance = erc20_alice.balanceOf(alice_addr).call().await?._0; @@ -164,7 +164,7 @@ mod transfers { let erc20_address = erc20::deploy(&alice.wallet).await?; let erc20_alice = ERC20Mock::new(erc20_address, &alice.wallet); - _ = watch!(erc20_alice.approve(safe_erc20_addr, value))?; + watch!(erc20_alice.approve(safe_erc20_addr, value))?; let initial_alice_balance = erc20_alice.balanceOf(alice_addr).call().await?._0; @@ -210,7 +210,7 @@ mod approvals { let erc20_address = erc20::deploy(&alice.wallet).await?; let erc20_alice = ERC20Mock::new(erc20_address, &alice.wallet); - _ = watch!(erc20_alice.regular_approve( + watch!(erc20_alice.regular_approve( safe_erc20_addr, spender_addr, U256::ZERO @@ -253,7 +253,7 @@ mod approvals { let erc20_address = erc20::deploy(&alice.wallet).await?; let erc20_alice = ERC20Mock::new(erc20_address, &alice.wallet); - _ = watch!(erc20_alice.regular_approve( + watch!(erc20_alice.regular_approve( safe_erc20_addr, spender_addr, U256::ZERO @@ -294,7 +294,7 @@ mod approvals { let erc20_address = erc20::deploy(&alice.wallet).await?; let erc20_alice = ERC20Mock::new(erc20_address, &alice.wallet); - _ = watch!(erc20_alice.regular_approve( + watch!(erc20_alice.regular_approve( safe_erc20_addr, spender_addr, U256::ZERO @@ -337,7 +337,7 @@ mod approvals { let erc20_address = erc20::deploy(&alice.wallet).await?; let erc20_alice = ERC20Mock::new(erc20_address, &alice.wallet); - _ = watch!(erc20_alice.regular_approve( + watch!(erc20_alice.regular_approve( safe_erc20_addr, spender_addr, U256::MAX @@ -370,7 +370,7 @@ mod approvals { let erc20_address = erc20::deploy(&alice.wallet).await?; let erc20_alice = ERC20Mock::new(erc20_address, &alice.wallet); - _ = watch!(erc20_alice.regular_approve( + watch!(erc20_alice.regular_approve( safe_erc20_addr, spender_addr, U256::ZERO @@ -414,7 +414,7 @@ mod approvals { let allowance = uint!(100_U256); - _ = watch!(erc20_alice.regular_approve( + watch!(erc20_alice.regular_approve( safe_erc20_addr, spender_addr, allowance @@ -459,7 +459,7 @@ mod approvals { let allowance = uint!(100_U256); - _ = watch!(erc20_alice.regular_approve( + watch!(erc20_alice.regular_approve( safe_erc20_addr, spender_addr, allowance @@ -502,7 +502,7 @@ mod approvals { let allowance = uint!(100_U256); - _ = watch!(erc20_alice.regular_approve( + watch!(erc20_alice.regular_approve( safe_erc20_addr, spender_addr, allowance @@ -547,7 +547,7 @@ mod approvals { let allowance = uint!(100_U256); - _ = watch!(erc20_alice.regular_approve( + watch!(erc20_alice.regular_approve( safe_erc20_addr, spender_addr, allowance @@ -592,7 +592,7 @@ mod approvals { let allowance = uint!(100_U256); - _ = watch!(erc20_alice.regular_approve( + watch!(erc20_alice.regular_approve( safe_erc20_addr, spender_addr, allowance diff --git a/examples/safe-erc20/tests/erc20_that_does_not_return.rs b/examples/safe-erc20/tests/erc20_that_does_not_return.rs index d591677b5..8b665732b 100644 --- a/examples/safe-erc20/tests/erc20_that_does_not_return.rs +++ b/examples/safe-erc20/tests/erc20_that_does_not_return.rs @@ -30,7 +30,7 @@ mod transfers { let erc20_address = erc20_no_return::deploy(&alice.wallet).await?; let erc20_alice = ERC20NoReturnMock::new(erc20_address, &alice.wallet); - _ = watch!(erc20_alice.mint(safe_erc20_addr, balance))?; + watch!(erc20_alice.mint(safe_erc20_addr, balance))?; let initial_safe_erc20_balance = erc20_alice.balanceOf(safe_erc20_addr).call().await?._0; @@ -116,8 +116,8 @@ mod transfers { let erc20_address = erc20_no_return::deploy(&alice.wallet).await?; let erc20_alice = ERC20NoReturnMock::new(erc20_address, &alice.wallet); - _ = watch!(erc20_alice.mint(alice_addr, balance))?; - _ = watch!(erc20_alice.approve(safe_erc20_addr, value))?; + watch!(erc20_alice.mint(alice_addr, balance))?; + watch!(erc20_alice.approve(safe_erc20_addr, value))?; let initial_alice_balance = erc20_alice.balanceOf(alice_addr).call().await?._0; @@ -163,7 +163,7 @@ mod transfers { let erc20_address = erc20_no_return::deploy(&alice.wallet).await?; let erc20_alice = ERC20NoReturnMock::new(erc20_address, &alice.wallet); - _ = watch!(erc20_alice.approve(safe_erc20_addr, value))?; + watch!(erc20_alice.approve(safe_erc20_addr, value))?; let initial_alice_balance = erc20_alice.balanceOf(alice_addr).call().await?._0; @@ -209,7 +209,7 @@ mod approvals { let erc20_alice = ERC20NoReturnMock::new(erc20_address, &alice.wallet); - _ = watch!(erc20_alice.regular_approve( + watch!(erc20_alice.regular_approve( safe_erc20_addr, spender_addr, U256::ZERO @@ -253,7 +253,7 @@ mod approvals { let erc20_alice = ERC20NoReturnMock::new(erc20_address, &alice.wallet); - _ = watch!(erc20_alice.regular_approve( + watch!(erc20_alice.regular_approve( safe_erc20_addr, spender_addr, U256::ZERO @@ -295,7 +295,7 @@ mod approvals { let erc20_alice = ERC20NoReturnMock::new(erc20_address, &alice.wallet); - _ = watch!(erc20_alice.regular_approve( + watch!(erc20_alice.regular_approve( safe_erc20_addr, spender_addr, U256::ZERO @@ -339,7 +339,7 @@ mod approvals { let erc20_alice = ERC20NoReturnMock::new(erc20_address, &alice.wallet); - _ = watch!(erc20_alice.regular_approve( + watch!(erc20_alice.regular_approve( safe_erc20_addr, spender_addr, U256::MAX @@ -373,7 +373,7 @@ mod approvals { let erc20_alice = ERC20NoReturnMock::new(erc20_address, &alice.wallet); - _ = watch!(erc20_alice.regular_approve( + watch!(erc20_alice.regular_approve( safe_erc20_addr, spender_addr, U256::ZERO @@ -418,7 +418,7 @@ mod approvals { let allowance = uint!(100_U256); - _ = watch!(erc20_alice.regular_approve( + watch!(erc20_alice.regular_approve( safe_erc20_addr, spender_addr, allowance @@ -464,7 +464,7 @@ mod approvals { let allowance = uint!(100_U256); - _ = watch!(erc20_alice.regular_approve( + watch!(erc20_alice.regular_approve( safe_erc20_addr, spender_addr, allowance @@ -508,7 +508,7 @@ mod approvals { let allowance = uint!(100_U256); - _ = watch!(erc20_alice.regular_approve( + watch!(erc20_alice.regular_approve( safe_erc20_addr, spender_addr, allowance @@ -554,7 +554,7 @@ mod approvals { let allowance = uint!(100_U256); - _ = watch!(erc20_alice.regular_approve( + watch!(erc20_alice.regular_approve( safe_erc20_addr, spender_addr, allowance @@ -600,7 +600,7 @@ mod approvals { let allowance = uint!(100_U256); - _ = watch!(erc20_alice.regular_approve( + watch!(erc20_alice.regular_approve( safe_erc20_addr, spender_addr, allowance diff --git a/examples/safe-erc20/tests/usdt_approval_behavior.rs b/examples/safe-erc20/tests/usdt_approval_behavior.rs index 1290c1d25..727a9fcbf 100644 --- a/examples/safe-erc20/tests/usdt_approval_behavior.rs +++ b/examples/safe-erc20/tests/usdt_approval_behavior.rs @@ -23,7 +23,7 @@ async fn safe_increase_allowance_works( let init_approval = uint!(100_U256); let value = uint!(10_U256); - _ = watch!(erc20_alice.regular_approve( + watch!(erc20_alice.regular_approve( safe_erc20_addr, bob_addr, init_approval @@ -67,7 +67,7 @@ async fn safe_decrease_allowance_works( let init_approval = uint!(100_U256); let value = uint!(10_U256); - _ = watch!(erc20_alice.regular_approve( + watch!(erc20_alice.regular_approve( safe_erc20_addr, bob_addr, init_approval @@ -108,7 +108,7 @@ async fn force_approve_works(alice: Account, bob: Account) -> eyre::Result<()> { let init_approval = uint!(100_U256); let updated_approval = uint!(10_U256); - _ = watch!(erc20_alice.regular_approve( + watch!(erc20_alice.regular_approve( safe_erc20_addr, bob_addr, init_approval diff --git a/examples/vesting-wallet/tests/vesting-wallet.rs b/examples/vesting-wallet/tests/vesting-wallet.rs index e1d6f3973..6eae5faf4 100644 --- a/examples/vesting-wallet/tests/vesting-wallet.rs +++ b/examples/vesting-wallet/tests/vesting-wallet.rs @@ -121,7 +121,7 @@ mod ether_vesting { .address()?; let contract = VestingWallet::new(contract_addr, &account.wallet); - _ = watch!(contract.receiveEther().value(U256::from(allocation)))?; + watch!(contract.receiveEther().value(U256::from(allocation)))?; Ok(contract_addr) } @@ -248,7 +248,7 @@ mod erc20_vesting { ) -> eyre::Result
{ let erc20_address = erc20::deploy(&account.wallet).await?; let erc20 = ERC20Mock::new(erc20_address, &account.wallet); - _ = watch!(erc20.mint(mint_to, allocation))?; + watch!(erc20.mint(mint_to, allocation))?; Ok(erc20_address) } @@ -263,7 +263,7 @@ mod erc20_vesting { let erc20_address = erc20_return_false::deploy(&account.wallet).await?; let erc20 = ERC20ReturnFalseMock::new(erc20_address, &account.wallet); - _ = watch!(erc20.mint(mint_to, U256::from(allocation)))?; + watch!(erc20.mint(mint_to, U256::from(allocation)))?; Ok(erc20_address) } diff --git a/fuzz/fuzz_targets/keccak/memory_safety.rs b/fuzz/fuzz_targets/keccak/memory_safety.rs index 0b72b8a2b..787c2d948 100644 --- a/fuzz/fuzz_targets/keccak/memory_safety.rs +++ b/fuzz/fuzz_targets/keccak/memory_safety.rs @@ -16,9 +16,9 @@ fuzz_target!(|data: &[u8]| { hasher.update(&data[..i]); let mut new_hasher = KeccakBuilder.build_hasher(); new_hasher.update(&data[i..]); - let _ = new_hasher.finalize(); + _ = new_hasher.finalize(); } // Finalize the original hasher - let _ = hasher.finalize(); + _ = hasher.finalize(); });