diff --git a/CHANGELOG.md b/CHANGELOG.md index 0312236cf..2079d48b1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,26 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Bump scarb to v2.8.3 (#1166) +### Changed (Breaking) + +- Remove openzeppelin_utils::selectors (#1163) +- Remove `DualCase dispatchers` (#1163) + - Remove `try_selector_with_fallback` from `openzeppelin_utils` + - Remove `unwrap_and_cast` module from `openzeppelin_utils` + - Remove `openzeppelin_access::accesscontrol::dual_accesscontrol` + - Remove `openzeppelin_access::ownable::dual_ownable` + - Remove `openzeppelin_account::dual_account` + - Remove `openzeppelin_account::dual_eth_account` + - Remove `openzeppelin_token::erc20::dual20` + - Remove `openzeppelin_token::erc721::dual721` + - Remove `openzeppelin_token::erc721::dual721_receiver` + - Remove `openzeppelin_token::erc1155::dual1155` + - Remove `openzeppelin_token::erc1155::dual1155_receiver` +- `SRC9Component` now uses `ISRC6Dispatcher` instead of `DualCaseAccount` (#1163) +- `ERC20VotesComponent` now uses `ISRC6Dispatcher` instead of `DualCaseAccount` (#1163) +- `ERC721Component` now uses `IERC721ReceiverDispatcher` instead of `DualCaseERC721Receiver` (#1163) +- `ERC1155Component` now uses `IERC1155ReceiverDispatcher` instead of `DualCaseERC1155Receiver` (#1163) + ## 0.17.0 (2024-09-23) ### Added diff --git a/README.md b/README.md index 6e4d27302..1e1e9063f 100644 --- a/README.md +++ b/README.md @@ -110,10 +110,6 @@ mod MyToken { } ``` -### Unsupported - -[`DualCase` dispatchers](https://docs.openzeppelin.com/contracts-cairo/0.17.0/interfaces#dualcase_dispatchers) rely on Sierra's ability to catch a revert to resume execution. Currently, Starknet live chains (testnets and mainnet) don't implement that behavior. Starknet's testing framework does support it. - ## Learn ### Documentation diff --git a/docs/modules/ROOT/pages/api/utilities.adoc b/docs/modules/ROOT/pages/api/utilities.adoc index 32a69935f..9e0802233 100644 --- a/docs/modules/ROOT/pages/api/utilities.adoc +++ b/docs/modules/ROOT/pages/api/utilities.adoc @@ -19,79 +19,13 @@ Module containing core utilities of the library. [.contract-index] .Members -- -.Functions -* xref:#utils-try_selector_with_fallback[`++try_selector_with_fallback(target, selector, fallback, args)++`] - -.Traits -* xref:#utils-UnwrapAndCast[`++UnwrapAndCast++`] - .Inner modules * xref:#utils-cryptography[`++cryptography++`] * xref:#utils-deployments[`++deployments++`] * xref:#utils-math[`++math++`] -* xref:#utils-selectors[`++selectors++`] * xref:#utils-serde[`++serde++`] -- -[#utils-Functions] -==== Functions - -[.contract-item] -[[utils-try_selector_with_fallback]] -==== `[.contract-item-name]#++try_selector_with_fallback++#++(target: ContractAddress, selector: felt252, fallback: felt252, args: Span) → SyscallResult>++` [.item-kind]#function# - -Tries to call a given selector on a given contract, and if it fails, tries to call a fallback selector. - -It was designed for falling back to the `camelCase` selector for backward compatibility in the -case of a failure of the `snake_case` selector. - -Returns a `SyscallResult` with the result of the successful call. - -Note that: - -- If the first call succeeds, the second call is not attempted. - -- If the first call fails with an error different than `ENTRYPOINT_NOT_FOUND`, the error is returned -without falling back to the second selector. - -- If the first call fails with `ENTRYPOINT_NOT_FOUND`, the second call is attempted, and if it fails its -error is returned. - -WARNING: The fallback mechanism won't work on live chains (mainnet or testnets) until -they implement panic handling in their runtime. - -[#utils-Traits] -==== Traits - -[.contract-item] -[[utils-UnwrapAndCast]] -==== `[.contract-item-name]#++UnwrapAndCast++#` [.item-kind]#trait# - -Trait for exposing an `unwrap_and_cast` function to `SyscallResult` objects. This may be useful -when unwrapping a syscall result to a type implementing the `Serde` trait, and you want to avoid the boilerplate of -casting and unwrapping the result multiple times. - -Usage example: - -```cairo -use openzeppelin_utils::selectors; -use openzeppelin_utils::UnwrapAndCast; - -fn call_and_cast_to_bool(target: ContractAddress, args: Span) -> bool { - try_selector_with_fallback( - target, selectors::has_role, selectors::hasRole, args - ).unwrap_and_cast() -} - -fn call_and_cast_to_felt252(target: ContractAddress, args: Span) -> felt252 { - try_selector_with_fallback( - target, selectors::get_role_admin, selectors::getRoleAdmin, args - ).unwrap_and_cast() -} -``` - -Note that it can be automatically casted to any type implementing the `Serde` trait. - [#utils-Inner-Modules] ==== Inner modules @@ -113,12 +47,6 @@ See xref:#deployments[`openzeppelin_utils::deployments`]. See xref:#math[`openzeppelin_utils::math`]. -[.contract-item] -[[utils-selectors]] -==== `[.contract-item-name]#++selectors++#` [.item-kind]#module# - -See xref:#selectors[`openzeppelin_utils::selectors`]. - [.contract-item] [[utils-serde]] ==== `[.contract-item-name]#++serde++#` [.item-kind]#module# @@ -250,19 +178,6 @@ Returns the average of two values. The result is rounded down. NOTE: `T` is a generic value matching different numeric implementations. -[.contract] -[[selectors]] -=== `++selectors++` - -```cairo -use openzeppelin_utils::selectors; -``` - -:selectors: https://github.com/OpenZeppelin/cairo-contracts/blob/release-v0.17.0/packages/utils/src/selectors.cairo[selectors.cairo] - -Module containing constants matching multiple selectors used through the library. -To see the full list of selectors, see {selectors}. - [.contract] [[serde]] === `++serde++` diff --git a/docs/modules/ROOT/pages/guides/snip12.adoc b/docs/modules/ROOT/pages/guides/snip12.adoc index c9e51790c..6e2316067 100644 --- a/docs/modules/ROOT/pages/guides/snip12.adoc +++ b/docs/modules/ROOT/pages/guides/snip12.adoc @@ -241,12 +241,12 @@ TIP: The expected parameter for the `get_message_hash` function is the address o == Full Implementation -:dualcase_dispatchers: xref:/interfaces#dualcase_dispatchers +:isrc6_dispatcher: xref:/api/account#ISRC6 :nonces: xref:/api/utilities#NoncesComponent Finally, the full implementation of the `CustomERC20` contract looks like this: -NOTE: We are using the {dualcase_dispatchers}[`DualCaseAccount`] to verify the signature, +NOTE: We are using the {isrc6_dispatcher}[`ISRC6Dispatcher`] to verify the signature, and the {nonces}[`NoncesComponent`] to handle nonces to prevent replay attacks. [,cairo] @@ -278,7 +278,7 @@ impl StructHashImpl of StructHash { #[starknet::contract] mod CustomERC20 { - use openzeppelin_account::dual_account::{DualCaseAccount, DualCaseAccountTrait}; + use openzeppelin_account::interface::{ISRC6Dispatcher, ISRC6DispatcherTrait}; use openzeppelin_token::erc20::{ERC20Component, ERC20HooksEmptyImpl}; use openzeppelin_utils::cryptography::nonces::NoncesComponent; use starknet::ContractAddress; @@ -348,7 +348,7 @@ mod CustomERC20 { let message = Message { recipient, amount, nonce, expiry }; let hash = message.get_message_hash(owner); - let is_valid_signature_felt = DualCaseAccount { contract_address: owner } + let is_valid_signature_felt = ISRC6Dispatcher { contract_address: owner } .is_valid_signature(hash, signature); // Check either 'VALID' or true for backwards compatibility diff --git a/docs/modules/ROOT/pages/index.adoc b/docs/modules/ROOT/pages/index.adoc index 9e6f5ecbb..59e49dd23 100644 --- a/docs/modules/ROOT/pages/index.adoc +++ b/docs/modules/ROOT/pages/index.adoc @@ -21,7 +21,7 @@ before proceeding, and run the following command to check that the installation ---- $ scarb --version -scarb 2.8.2 (a37b4cbfc 2024-09-09) +scarb 2.8.3 (54938ce3b 2024-09-26) cairo: 2.8.2 (https://crates.io/crates/cairo-lang-compiler/2.8.2) sierra: 1.6.0 ---- diff --git a/docs/modules/ROOT/pages/interfaces.adoc b/docs/modules/ROOT/pages/interfaces.adoc index c01486d9f..8b4b8c10d 100644 --- a/docs/modules/ROOT/pages/interfaces.adoc +++ b/docs/modules/ROOT/pages/interfaces.adoc @@ -13,12 +13,13 @@ use openzeppelin_token::erc20::interface::IERC20; or ```cairo -use openzeppelin_token::erc20::dual20::DualCaseERC20; +use openzeppelin_token::erc20::interface::ERC20ABI; ``` NOTE: For simplicity, we'll use ERC20 as example but the same concepts apply to other modules. == Interface traits + The library offers three types of traits to implement or interact with contracts: === Standard traits @@ -44,6 +45,9 @@ pub trait IERC20 { They describe a contract's complete interface. This is useful to interface with a preset contract offered by this library, such as the ERC20 preset that includes functions from different traits such as `IERC20` and `IERC20Camel`. +NOTE: The library offers an ABI trait for most components, providing all external function signatures +even when most of the time all of them don't need to be implemented at the same time. This can be helpful when interacting with a contract implementing the component, instead of defining a new dispatcher. + ```cairo #[starknet::interface] pub trait ERC20ABI { @@ -72,34 +76,30 @@ pub trait ERC20ABI { ``` === Dispatcher traits -This is a utility trait to interface with contracts whose interface is unknown. Read more in the xref:#dualcase_dispatchers[DualCase Dispatchers] section. -```cairo -#[derive(Copy, Drop)] -pub struct DualCaseERC20 { - contract_address: ContractAddress -} +:interacting-with-another-contract: https://book.cairo-lang.org/ch15-02-interacting-with-another-contract.html[Interacting with another contract] -pub trait DualCaseERC20Trait { - fn name(self: @DualCaseERC20) -> ByteArray; - fn symbol(self: @DualCaseERC20) -> ByteArray; - fn decimals(self: @DualCaseERC20) -> u8; - fn total_supply(self: @DualCaseERC20) -> u256; - fn balance_of(self: @DualCaseERC20, account: ContractAddress) -> u256; - fn allowance(self: @DualCaseERC20, owner: ContractAddress, spender: ContractAddress) -> u256; - fn transfer(self: @DualCaseERC20, recipient: ContractAddress, amount: u256) -> bool; - fn transfer_from( - self: @DualCaseERC20, sender: ContractAddress, recipient: ContractAddress, amount: u256 - ) -> bool; - fn approve(self: @DualCaseERC20, spender: ContractAddress, amount: u256) -> bool; -} +Traits annotated with `#[starknet::interface]` automatically generate a dispatcher that can be used to interact with contracts that implement the given interface. They can be imported by appending the `Dispatcher` and `DispatcherTrait` suffixes to the trait name, like this: + +```cairo +use openzeppelin_token::erc20::interface::{IERC20Dispatcher, IERC20DispatcherTrait}; ``` +Other types of dispatchers are also auto-generated from the annotated trait. See the +{interacting-with-another-contract} section of the Cairo book for more information. + +NOTE: In the example, the `IERC20Dispatcher` is the one used to interact with contracts, but the +`IERC20DispatcherTrait` needs to be in scope for the functions to be available. + == Dual interfaces +WARNING: `camelCase` functions are deprecated and maintained only for Backwards Compatibility. +It's recommended to only use `snake_case` interfaces with contracts and components. The `camelCase` functions will be removed in +future versions. + Following the {great-interface-migration} plan, we added `snake_case` functions to all of our preexisting `camelCase` contracts with the goal of eventually dropping support for the latter. -In short, we offer two types of interfaces and utilities to handle them: +In short, the library offers two types of interfaces and utilities to handle them: 1. `camelCase` interfaces, which are the ones we've been using so far. 2. `snake_case` interfaces, which are the ones we're migrating to. @@ -131,7 +131,7 @@ pub trait IERC20 { === `IERC20Camel` -On top of that, we also offer a `camelCase` version of the same interface: +On top of that, the library also offers a `camelCase` version of the same interface: ```cairo #[starknet::interface] @@ -149,42 +149,3 @@ pub trait IERC20Camel { fn approve(ref self: TState, spender: ContractAddress, amount: u256) -> bool; } ``` - -== `DualCase` dispatchers - -WARNING: `DualCase` dispatchers are deprecated, and they will be removed from the library soon. - -WARNING: `DualCase` dispatchers won't work on live chains (`mainnet` or testnets) until they implement panic handling in their runtime. Dispatchers work fine in testing environments. - -In order to ease this transition, OpenZeppelin Contracts for Cairo offer what we call `DualCase` dispatchers such as `DualCaseERC721` or `DualCaseAccount`. - -These modules wrap a target contract with a compatibility layer to expose a `snake_case` interface no matter what casing the underlying contract uses. -This way, an AMM wouldn't have problems integrating tokens independently of their interface. - -For example: - -```cairo -let token = DualCaseERC20 { contract_address: target }; -token.transfer_from(OWNER(), RECIPIENT(), VALUE); -``` - -This is done by simply executing the `snake_case` version of the function (e.g. `transfer_from`) and falling back to the `camelCase` one (e.g. `transferFrom`) in case it reverts with `ENTRYPOINT_NOT_FOUND`, like this: - -```cairo -fn try_selector_with_fallback( - target: ContractAddress, selector: felt252, fallback: felt252, args: Span -) -> SyscallResult> { - match call_contract_syscall(target, selector, args) { - Result::Ok(ret) => Result::Ok(ret), - Result::Err(errors) => { - if *errors.at(0) == 'ENTRYPOINT_NOT_FOUND' { - return call_contract_syscall(target, fallback, args); - } else { - Result::Err(errors) - } - } - } -} -``` - -Trying the `snake_case` interface first renders `camelCase` calls a bit more expensive since a failed `snake_case` call will always happen before. This is a design choice to incentivize casing adoption/transition as per the {great-interface-migration}. diff --git a/packages/access/src/accesscontrol.cairo b/packages/access/src/accesscontrol.cairo index 7b977e72b..8bfc6fc0b 100644 --- a/packages/access/src/accesscontrol.cairo +++ b/packages/access/src/accesscontrol.cairo @@ -1,5 +1,4 @@ pub mod accesscontrol; -pub mod dual_accesscontrol; pub mod interface; pub use accesscontrol::AccessControlComponent; diff --git a/packages/access/src/accesscontrol/dual_accesscontrol.cairo b/packages/access/src/accesscontrol/dual_accesscontrol.cairo deleted file mode 100644 index 26c383fef..000000000 --- a/packages/access/src/accesscontrol/dual_accesscontrol.cairo +++ /dev/null @@ -1,88 +0,0 @@ -// SPDX-License-Identifier: MIT -// OpenZeppelin Contracts for Cairo v0.17.0 (access/accesscontrol/dual_accesscontrol.cairo) - -use openzeppelin_utils::selectors; -use openzeppelin_utils::serde::SerializedAppend; -use openzeppelin_utils::try_selector_with_fallback; -use openzeppelin_utils::unwrap_and_cast::UnwrapAndCast; -use starknet::ContractAddress; -use starknet::SyscallResultTrait; -use starknet::syscalls::call_contract_syscall; - -#[derive(Copy, Drop)] -pub struct DualCaseAccessControl { - pub contract_address: ContractAddress -} - -pub trait DualCaseAccessControlTrait { - fn has_role(self: @DualCaseAccessControl, role: felt252, account: ContractAddress) -> bool; - fn get_role_admin(self: @DualCaseAccessControl, role: felt252) -> felt252; - fn grant_role(self: @DualCaseAccessControl, role: felt252, account: ContractAddress); - fn revoke_role(self: @DualCaseAccessControl, role: felt252, account: ContractAddress); - fn renounce_role(self: @DualCaseAccessControl, role: felt252, account: ContractAddress); - fn supports_interface(self: @DualCaseAccessControl, interface_id: felt252) -> bool; -} - -impl DualCaseAccessControlImpl of DualCaseAccessControlTrait { - fn has_role(self: @DualCaseAccessControl, role: felt252, account: ContractAddress) -> bool { - let mut args = array![]; - args.append_serde(role); - args.append_serde(account); - - try_selector_with_fallback( - *self.contract_address, selectors::has_role, selectors::hasRole, args.span() - ) - .unwrap_and_cast() - } - - fn get_role_admin(self: @DualCaseAccessControl, role: felt252) -> felt252 { - let mut args = array![]; - args.append_serde(role); - - try_selector_with_fallback( - *self.contract_address, selectors::get_role_admin, selectors::getRoleAdmin, args.span() - ) - .unwrap_and_cast() - } - - fn grant_role(self: @DualCaseAccessControl, role: felt252, account: ContractAddress) { - let mut args = array![]; - args.append_serde(role); - args.append_serde(account); - - try_selector_with_fallback( - *self.contract_address, selectors::grant_role, selectors::grantRole, args.span() - ) - .unwrap_syscall(); - } - - fn revoke_role(self: @DualCaseAccessControl, role: felt252, account: ContractAddress) { - let mut args = array![]; - args.append_serde(role); - args.append_serde(account); - - try_selector_with_fallback( - *self.contract_address, selectors::revoke_role, selectors::revokeRole, args.span() - ) - .unwrap_syscall(); - } - - fn renounce_role(self: @DualCaseAccessControl, role: felt252, account: ContractAddress) { - let mut args = array![]; - args.append_serde(role); - args.append_serde(account); - - try_selector_with_fallback( - *self.contract_address, selectors::renounce_role, selectors::renounceRole, args.span() - ) - .unwrap_syscall(); - } - - fn supports_interface(self: @DualCaseAccessControl, interface_id: felt252) -> bool { - let mut args = array![]; - args.append_serde(interface_id); - - call_contract_syscall(*self.contract_address, selectors::supports_interface, args.span()) - .unwrap_and_cast() - } -} diff --git a/packages/access/src/ownable.cairo b/packages/access/src/ownable.cairo index a2a3a87f5..eb12459d9 100644 --- a/packages/access/src/ownable.cairo +++ b/packages/access/src/ownable.cairo @@ -1,4 +1,3 @@ -pub mod dual_ownable; pub mod interface; pub mod ownable; diff --git a/packages/access/src/ownable/dual_ownable.cairo b/packages/access/src/ownable/dual_ownable.cairo deleted file mode 100644 index 128c72826..000000000 --- a/packages/access/src/ownable/dual_ownable.cairo +++ /dev/null @@ -1,55 +0,0 @@ -// SPDX-License-Identifier: MIT -// OpenZeppelin Contracts for Cairo v0.17.0 (access/ownable/dual_ownable.cairo) - -use openzeppelin_utils::UnwrapAndCast; -use openzeppelin_utils::selectors; -use openzeppelin_utils::serde::SerializedAppend; -use openzeppelin_utils::try_selector_with_fallback; -use starknet::ContractAddress; -use starknet::SyscallResultTrait; -use starknet::syscalls::call_contract_syscall; - -#[derive(Copy, Drop)] -pub struct DualCaseOwnable { - pub contract_address: ContractAddress -} - -pub trait DualCaseOwnableTrait { - fn owner(self: @DualCaseOwnable) -> ContractAddress; - fn transfer_ownership(self: @DualCaseOwnable, new_owner: ContractAddress); - fn renounce_ownership(self: @DualCaseOwnable); -} - -impl DualCaseOwnableImpl of DualCaseOwnableTrait { - fn owner(self: @DualCaseOwnable) -> ContractAddress { - let args = array![]; - - call_contract_syscall(*self.contract_address, selectors::owner, args.span()) - .unwrap_and_cast() - } - - fn transfer_ownership(self: @DualCaseOwnable, new_owner: ContractAddress) { - let mut args = array![]; - args.append_serde(new_owner); - - try_selector_with_fallback( - *self.contract_address, - selectors::transfer_ownership, - selectors::transferOwnership, - args.span() - ) - .unwrap_syscall(); - } - - fn renounce_ownership(self: @DualCaseOwnable) { - let args = array![]; - - try_selector_with_fallback( - *self.contract_address, - selectors::renounce_ownership, - selectors::renounceOwnership, - args.span() - ) - .unwrap_syscall(); - } -} diff --git a/packages/access/src/tests.cairo b/packages/access/src/tests.cairo index a7b4dadfe..4cb72b65b 100644 --- a/packages/access/src/tests.cairo +++ b/packages/access/src/tests.cairo @@ -3,10 +3,6 @@ pub(crate) mod mocks; #[cfg(test)] mod test_accesscontrol; #[cfg(test)] -mod test_dual_accesscontrol; -#[cfg(test)] -mod test_dual_ownable; -#[cfg(test)] mod test_ownable; #[cfg(test)] mod test_ownable_twostep; diff --git a/packages/access/src/tests/mocks.cairo b/packages/access/src/tests/mocks.cairo index f3eca4c97..4f4ebc2d9 100644 --- a/packages/access/src/tests/mocks.cairo +++ b/packages/access/src/tests/mocks.cairo @@ -1,3 +1,2 @@ pub(crate) mod accesscontrol_mocks; -pub(crate) mod non_implementing_mock; pub(crate) mod ownable_mocks; diff --git a/packages/access/src/tests/mocks/accesscontrol_mocks.cairo b/packages/access/src/tests/mocks/accesscontrol_mocks.cairo index 09eee34b1..13f0b8722 100644 --- a/packages/access/src/tests/mocks/accesscontrol_mocks.cairo +++ b/packages/access/src/tests/mocks/accesscontrol_mocks.cairo @@ -37,188 +37,3 @@ pub(crate) mod DualCaseAccessControlMock { self.accesscontrol._grant_role(DEFAULT_ADMIN_ROLE, admin); } } - -#[starknet::contract] -pub(crate) mod SnakeAccessControlMock { - use crate::accesscontrol::AccessControlComponent; - use crate::accesscontrol::DEFAULT_ADMIN_ROLE; - use openzeppelin_introspection::src5::SRC5Component; - use starknet::ContractAddress; - - component!(path: AccessControlComponent, storage: accesscontrol, event: AccessControlEvent); - component!(path: SRC5Component, storage: src5, event: SRC5Event); - - // AccessControl - #[abi(embed_v0)] - impl AccessControlImpl = - AccessControlComponent::AccessControlImpl; - impl AccessControlInternalImpl = AccessControlComponent::InternalImpl; - - // SCR5 - #[abi(embed_v0)] - impl SRC5Impl = SRC5Component::SRC5Impl; - - #[storage] - pub struct Storage { - #[substorage(v0)] - pub accesscontrol: AccessControlComponent::Storage, - #[substorage(v0)] - pub src5: SRC5Component::Storage, - } - - #[event] - #[derive(Drop, starknet::Event)] - enum Event { - #[flat] - AccessControlEvent: AccessControlComponent::Event, - #[flat] - SRC5Event: SRC5Component::Event - } - - #[constructor] - fn constructor(ref self: ContractState, admin: ContractAddress) { - self.accesscontrol.initializer(); - self.accesscontrol._grant_role(DEFAULT_ADMIN_ROLE, admin); - } -} - -#[starknet::contract] -pub(crate) mod CamelAccessControlMock { - use crate::accesscontrol::AccessControlComponent; - use crate::accesscontrol::DEFAULT_ADMIN_ROLE; - use openzeppelin_introspection::src5::SRC5Component; - use starknet::ContractAddress; - - component!(path: AccessControlComponent, storage: accesscontrol, event: AccessControlEvent); - component!(path: SRC5Component, storage: src5, event: SRC5Event); - - // AccessControl - #[abi(embed_v0)] - impl AccessControlCamelImpl = - AccessControlComponent::AccessControlCamelImpl; - impl AccessControlInternalImpl = AccessControlComponent::InternalImpl; - - // SCR5 - #[abi(embed_v0)] - impl SRC5Impl = SRC5Component::SRC5Impl; - - - #[storage] - pub struct Storage { - #[substorage(v0)] - pub accesscontrol: AccessControlComponent::Storage, - #[substorage(v0)] - pub src5: SRC5Component::Storage - } - - #[event] - #[derive(Drop, starknet::Event)] - enum Event { - #[flat] - AccessControlEvent: AccessControlComponent::Event, - #[flat] - SRC5Event: SRC5Component::Event - } - - #[constructor] - fn constructor(ref self: ContractState, admin: ContractAddress) { - self.accesscontrol.initializer(); - self.accesscontrol._grant_role(DEFAULT_ADMIN_ROLE, admin); - } -} - -// Although these modules are designed to panic, functions -// still need a valid return value. We chose: -// -// 3 for felt252 -// false for bool - -#[starknet::contract] -pub(crate) mod SnakeAccessControlPanicMock { - use starknet::ContractAddress; - - #[storage] - pub struct Storage {} - - #[abi(per_item)] - #[generate_trait] - impl ExternalImpl of ExternalTrait { - #[external(v0)] - fn has_role(self: @ContractState, role: felt252, account: ContractAddress) -> bool { - panic!("Some error"); - false - } - - #[external(v0)] - fn get_role_admin(self: @ContractState, role: felt252) -> felt252 { - panic!("Some error"); - 3 - } - - #[external(v0)] - fn grant_role(ref self: ContractState, role: felt252, account: ContractAddress) { - panic!("Some error"); - } - - #[external(v0)] - fn revoke_role(ref self: ContractState, role: felt252, account: ContractAddress) { - panic!("Some error"); - } - - #[external(v0)] - fn renounce_role(ref self: ContractState, role: felt252, account: ContractAddress) { - panic!("Some error"); - } - - #[external(v0)] - fn supports_interface(self: @ContractState, interface_id: felt252) -> bool { - panic!("Some error"); - false - } - } -} - -#[starknet::contract] -pub(crate) mod CamelAccessControlPanicMock { - use starknet::ContractAddress; - - #[storage] - pub struct Storage {} - - #[abi(per_item)] - #[generate_trait] - impl ExternalImpl of ExternalTrait { - #[external(v0)] - fn hasRole(self: @ContractState, role: felt252, account: ContractAddress) -> bool { - panic!("Some error"); - false - } - - #[external(v0)] - fn getRoleAdmin(self: @ContractState, role: felt252) -> felt252 { - panic!("Some error"); - 3 - } - - #[external(v0)] - fn grantRole(ref self: ContractState, role: felt252, account: ContractAddress) { - panic!("Some error"); - } - - #[external(v0)] - fn revokeRole(ref self: ContractState, role: felt252, account: ContractAddress) { - panic!("Some error"); - } - - #[external(v0)] - fn renounceRole(ref self: ContractState, role: felt252, account: ContractAddress) { - panic!("Some error"); - } - - #[external(v0)] - fn supportsInterface(self: @ContractState, interfaceId: felt252) -> bool { - panic!("Some error"); - false - } - } -} diff --git a/packages/access/src/tests/mocks/non_implementing_mock.cairo b/packages/access/src/tests/mocks/non_implementing_mock.cairo deleted file mode 100644 index 67d632c72..000000000 --- a/packages/access/src/tests/mocks/non_implementing_mock.cairo +++ /dev/null @@ -1,10 +0,0 @@ -#[starknet::contract] -pub(crate) mod NonImplementingMock { - #[storage] - pub struct Storage {} - - #[external(v0)] - fn nope(self: @ContractState) -> bool { - false - } -} diff --git a/packages/access/src/tests/mocks/ownable_mocks.cairo b/packages/access/src/tests/mocks/ownable_mocks.cairo index f3456c68a..996a23f91 100644 --- a/packages/access/src/tests/mocks/ownable_mocks.cairo +++ b/packages/access/src/tests/mocks/ownable_mocks.cairo @@ -28,135 +28,6 @@ pub(crate) mod DualCaseOwnableMock { } } -#[starknet::contract] -pub(crate) mod SnakeOwnableMock { - use crate::ownable::OwnableComponent; - use starknet::ContractAddress; - - component!(path: OwnableComponent, storage: ownable, event: OwnableEvent); - - #[abi(embed_v0)] - impl OwnableImpl = OwnableComponent::OwnableImpl; - impl InternalImpl = OwnableComponent::InternalImpl; - - #[storage] - pub struct Storage { - #[substorage(v0)] - pub ownable: OwnableComponent::Storage - } - - #[event] - #[derive(Drop, starknet::Event)] - enum Event { - #[flat] - OwnableEvent: OwnableComponent::Event - } - - #[constructor] - fn constructor(ref self: ContractState, owner: ContractAddress) { - self.ownable.initializer(owner); - } -} - -#[starknet::contract] -pub(crate) mod CamelOwnableMock { - use crate::ownable::OwnableComponent; - use crate::ownable::interface::IOwnable; - use starknet::ContractAddress; - - component!(path: OwnableComponent, storage: ownable, event: OwnableEvent); - - #[abi(embed_v0)] - impl OwnableCamelOnlyImpl = - OwnableComponent::OwnableCamelOnlyImpl; - impl InternalImpl = OwnableComponent::InternalImpl; - - #[storage] - pub struct Storage { - #[substorage(v0)] - pub ownable: OwnableComponent::Storage - } - - #[event] - #[derive(Drop, starknet::Event)] - enum Event { - #[flat] - OwnableEvent: OwnableComponent::Event - } - - #[constructor] - fn constructor(ref self: ContractState, owner: ContractAddress) { - self.ownable.initializer(owner); - } - - #[abi(per_item)] - #[generate_trait] - impl ExternalImpl of ExternalTrait { - #[external(v0)] - fn owner(self: @ContractState) -> ContractAddress { - self.ownable.owner() - } - } -} - -#[starknet::contract] -pub(crate) mod SnakeOwnablePanicMock { - use core::num::traits::Zero; - use starknet::ContractAddress; - - #[storage] - pub struct Storage {} - - #[abi(per_item)] - #[generate_trait] - impl ExternalImpl of ExternalTrait { - #[external(v0)] - fn owner(self: @ContractState) -> ContractAddress { - panic!("Some error"); - Zero::zero() - } - - #[external(v0)] - fn transfer_ownership(ref self: ContractState, new_owner: ContractAddress) { - panic!("Some error"); - } - - #[external(v0)] - fn renounce_ownership(ref self: ContractState) { - panic!("Some error"); - } - } -} - -#[starknet::contract] -pub(crate) mod CamelOwnablePanicMock { - use core::num::traits::Zero; - use starknet::ContractAddress; - - #[storage] - pub struct Storage {} - - #[abi(per_item)] - #[generate_trait] - impl ExternalImpl of ExternalTrait { - #[external(v0)] - fn owner(self: @ContractState) -> ContractAddress { - panic!("Some error"); - Zero::zero() - } - - #[external(v0)] - fn transferOwnership(ref self: ContractState, newOwner: ContractAddress) { - panic!("Some error"); - } - - #[external(v0)] - fn renounceOwnership(ref self: ContractState) { - panic!("Some error"); - } - } -} - #[starknet::contract] pub(crate) mod DualCaseTwoStepOwnableMock { use crate::ownable::OwnableComponent; diff --git a/packages/access/src/tests/test_dual_accesscontrol.cairo b/packages/access/src/tests/test_dual_accesscontrol.cairo deleted file mode 100644 index 8c1032266..000000000 --- a/packages/access/src/tests/test_dual_accesscontrol.cairo +++ /dev/null @@ -1,290 +0,0 @@ -use crate::accesscontrol::DEFAULT_ADMIN_ROLE; -use crate::accesscontrol::dual_accesscontrol::DualCaseAccessControl; -use crate::accesscontrol::dual_accesscontrol::DualCaseAccessControlTrait; -use crate::accesscontrol::interface::{ - IACCESSCONTROL_ID, IAccessControlCamelDispatcher, IAccessControlCamelDispatcherTrait -}; -use crate::accesscontrol::interface::{IAccessControlDispatcher, IAccessControlDispatcherTrait}; -use openzeppelin_testing as utils; -use openzeppelin_testing::constants::{ADMIN, AUTHORIZED, ROLE}; -use openzeppelin_utils::serde::SerializedAppend; -use snforge_std::start_cheat_caller_address; - -// -// Setup -// - -fn setup_snake() -> (DualCaseAccessControl, IAccessControlDispatcher) { - let mut calldata = array![]; - calldata.append_serde(ADMIN()); - let target = utils::declare_and_deploy("SnakeAccessControlMock", calldata); - ( - DualCaseAccessControl { contract_address: target }, - IAccessControlDispatcher { contract_address: target } - ) -} - -fn setup_camel() -> (DualCaseAccessControl, IAccessControlCamelDispatcher) { - let mut calldata = array![]; - calldata.append_serde(ADMIN()); - let target = utils::declare_and_deploy("CamelAccessControlMock", calldata); - ( - DualCaseAccessControl { contract_address: target }, - IAccessControlCamelDispatcher { contract_address: target } - ) -} - -fn setup_non_accesscontrol() -> DualCaseAccessControl { - let target = utils::declare_and_deploy("NonImplementingMock", array![]); - DualCaseAccessControl { contract_address: target } -} - -fn setup_accesscontrol_panic() -> (DualCaseAccessControl, DualCaseAccessControl) { - let snake_target = utils::declare_and_deploy("SnakeAccessControlPanicMock", array![]); - let camel_target = utils::declare_and_deploy("CamelAccessControlPanicMock", array![]); - ( - DualCaseAccessControl { contract_address: snake_target }, - DualCaseAccessControl { contract_address: camel_target } - ) -} - -// -// snake_case target -// - -#[test] -fn test_dual_supports_interface() { - let (dispatcher, _) = setup_snake(); - let supports_iaccesscontrol = dispatcher.supports_interface(IACCESSCONTROL_ID); - assert!(supports_iaccesscontrol); -} - -#[test] -#[ignore] // REASON: should_panic attribute not fit for complex panic messages. -#[should_panic(expected: ('ENTRYPOINT_NOT_FOUND',))] -fn test_dual_no_supports_interface() { - let dispatcher = setup_non_accesscontrol(); - dispatcher.supports_interface(IACCESSCONTROL_ID); -} - -#[test] -#[should_panic(expected: "Some error")] -fn test_dual_supports_interface_exists_and_panics() { - let (snake_dispatcher, _) = setup_accesscontrol_panic(); - snake_dispatcher.supports_interface(IACCESSCONTROL_ID); -} - -#[test] -fn test_dual_has_role() { - let (snake_dispatcher, _) = setup_snake(); - let has_role = snake_dispatcher.has_role(DEFAULT_ADMIN_ROLE, ADMIN()); - assert!(has_role); -} - -#[test] -#[ignore] // REASON: should_panic attribute not fit for complex panic messages. -#[should_panic(expected: ('ENTRYPOINT_NOT_FOUND',))] -fn test_dual_no_has_role() { - let dispatcher = setup_non_accesscontrol(); - dispatcher.has_role(DEFAULT_ADMIN_ROLE, ADMIN()); -} - -#[test] -#[should_panic(expected: "Some error")] -fn test_dual_has_role_exists_and_panics() { - let (dispatcher, _) = setup_accesscontrol_panic(); - dispatcher.has_role(DEFAULT_ADMIN_ROLE, ADMIN()); -} - -#[test] -fn test_dual_get_role_admin() { - let (dispatcher, _) = setup_snake(); - let current_admin_role = dispatcher.get_role_admin(ROLE); - assert_eq!(current_admin_role, DEFAULT_ADMIN_ROLE); -} - -#[test] -#[ignore] // REASON: should_panic attribute not fit for complex panic messages. -#[should_panic(expected: ('ENTRYPOINT_NOT_FOUND',))] -fn test_dual_no_get_role_admin() { - let dispatcher = setup_non_accesscontrol(); - dispatcher.get_role_admin(ROLE); -} - -#[test] -#[should_panic(expected: "Some error")] -fn test_dual_get_role_admin_exists_and_panics() { - let (snake_dispatcher, _) = setup_accesscontrol_panic(); - snake_dispatcher.get_role_admin(ROLE); -} - -#[test] -fn test_dual_grant_role() { - let (dispatcher, target) = setup_snake(); - start_cheat_caller_address(target.contract_address, ADMIN()); - dispatcher.grant_role(ROLE, AUTHORIZED()); - - let has_role = target.has_role(ROLE, AUTHORIZED()); - assert!(has_role); -} - -#[test] -#[ignore] // REASON: should_panic attribute not fit for complex panic messages. -#[should_panic(expected: ('ENTRYPOINT_NOT_FOUND',))] -fn test_dual_no_grant_role() { - let dispatcher = setup_non_accesscontrol(); - dispatcher.grant_role(ROLE, AUTHORIZED()); -} - -#[test] -#[should_panic(expected: "Some error")] -fn test_dual_grant_role_exists_and_panics() { - let (snake_dispatcher, _) = setup_accesscontrol_panic(); - snake_dispatcher.grant_role(ROLE, AUTHORIZED()); -} - -#[test] -fn test_dual_revoke_role() { - let (dispatcher, target) = setup_snake(); - start_cheat_caller_address(target.contract_address, ADMIN()); - dispatcher.revoke_role(ROLE, AUTHORIZED()); - - let has_not_role = !target.has_role(ROLE, AUTHORIZED()); - assert!(has_not_role); -} - -#[test] -#[ignore] // REASON: should_panic attribute not fit for complex panic messages. -#[should_panic(expected: ('ENTRYPOINT_NOT_FOUND',))] -fn test_dual_no_revoke_role() { - let dispatcher = setup_non_accesscontrol(); - dispatcher.revoke_role(ROLE, AUTHORIZED()); -} - -#[test] -#[should_panic(expected: "Some error")] -fn test_dual_revoke_role_exists_and_panics() { - let (snake_dispatcher, _) = setup_accesscontrol_panic(); - snake_dispatcher.revoke_role(ROLE, AUTHORIZED()); -} - -#[test] -fn test_dual_renounce_role() { - let (dispatcher, target) = setup_snake(); - start_cheat_caller_address(target.contract_address, ADMIN()); - dispatcher.renounce_role(DEFAULT_ADMIN_ROLE, ADMIN()); - - let has_not_role = !target.has_role(DEFAULT_ADMIN_ROLE, ADMIN()); - assert!(has_not_role); -} - -#[test] -#[ignore] // REASON: should_panic attribute not fit for complex panic messages. -#[should_panic(expected: ('ENTRYPOINT_NOT_FOUND',))] -fn test_dual_no_renounce_role() { - let dispatcher = setup_non_accesscontrol(); - dispatcher.renounce_role(DEFAULT_ADMIN_ROLE, ADMIN()); -} - -#[test] -#[should_panic(expected: "Some error")] -fn test_dual_renounce_role_exists_and_panics() { - let (snake_dispatcher, _) = setup_accesscontrol_panic(); - snake_dispatcher.renounce_role(DEFAULT_ADMIN_ROLE, ADMIN()); -} - -// -// camelCase target -// - -#[test] -#[ignore] // REASON: foundry entrypoint_not_found error message inconsistent with mainnet. -fn test_dual_hasRole() { - let (dispatcher, _) = setup_camel(); - - let has_role = dispatcher.has_role(DEFAULT_ADMIN_ROLE, ADMIN()); - assert!(has_role); -} - -#[test] -#[ignore] // REASON: foundry entrypoint_not_found error message inconsistent with mainnet. -#[should_panic(expected: "Some error")] -fn test_dual_hasRole_exists_and_panics() { - let (_, camel_dispatcher) = setup_accesscontrol_panic(); - camel_dispatcher.has_role(DEFAULT_ADMIN_ROLE, ADMIN()); -} - -#[test] -#[ignore] // REASON: foundry entrypoint_not_found error message inconsistent with mainnet. -fn test_dual_getRoleAdmin() { - let (dispatcher, _) = setup_camel(); - - let current_admin_role = dispatcher.get_role_admin(ROLE); - assert_eq!(current_admin_role, DEFAULT_ADMIN_ROLE); -} - -#[test] -#[ignore] // REASON: foundry entrypoint_not_found error message inconsistent with mainnet. -#[should_panic(expected: "Some error")] -fn test_dual_getRoleAdmin_exists_and_panics() { - let (_, camel_dispatcher) = setup_accesscontrol_panic(); - camel_dispatcher.get_role_admin(ROLE); -} - -#[test] -#[ignore] // REASON: foundry entrypoint_not_found error message inconsistent with mainnet. -fn test_dual_grantRole() { - let (dispatcher, target) = setup_camel(); - start_cheat_caller_address(target.contract_address, ADMIN()); - dispatcher.grant_role(ROLE, AUTHORIZED()); - - let has_role = target.hasRole(ROLE, AUTHORIZED()); - assert!(has_role); -} - -#[test] -#[ignore] // REASON: foundry entrypoint_not_found error message inconsistent with mainnet. -#[should_panic(expected: "Some error")] -fn test_dual_grantRole_exists_and_panics() { - let (_, camel_dispatcher) = setup_accesscontrol_panic(); - camel_dispatcher.grant_role(ROLE, AUTHORIZED()); -} - -#[test] -#[ignore] // REASON: foundry entrypoint_not_found error message inconsistent with mainnet. -fn test_dual_revokeRole() { - let (dispatcher, target) = setup_camel(); - start_cheat_caller_address(target.contract_address, ADMIN()); - dispatcher.grant_role(ROLE, AUTHORIZED()); - dispatcher.revoke_role(ROLE, AUTHORIZED()); - - let has_not_role = !target.hasRole(ROLE, AUTHORIZED()); - assert!(has_not_role); -} - -#[test] -#[ignore] // REASON: foundry entrypoint_not_found error message inconsistent with mainnet. -#[should_panic(expected: "Some error")] -fn test_dual_revokeRole_exists_and_panics() { - let (_, camel_dispatcher) = setup_accesscontrol_panic(); - camel_dispatcher.revoke_role(ROLE, AUTHORIZED()); -} - -#[test] -#[ignore] // REASON: foundry entrypoint_not_found error message inconsistent with mainnet. -fn test_dual_renounceRole() { - let (dispatcher, target) = setup_camel(); - start_cheat_caller_address(target.contract_address, ADMIN()); - dispatcher.renounce_role(DEFAULT_ADMIN_ROLE, ADMIN()); - - let has_not_role = !target.hasRole(DEFAULT_ADMIN_ROLE, ADMIN()); - assert!(has_not_role); -} - -#[test] -#[ignore] // REASON: foundry entrypoint_not_found error message inconsistent with mainnet. -#[should_panic(expected: "Some error")] -fn test_dual_renounceRole_exists_and_panics() { - let (_, camel_dispatcher) = setup_accesscontrol_panic(); - camel_dispatcher.renounce_role(DEFAULT_ADMIN_ROLE, ADMIN()); -} diff --git a/packages/access/src/tests/test_dual_ownable.cairo b/packages/access/src/tests/test_dual_ownable.cairo deleted file mode 100644 index 97d737032..000000000 --- a/packages/access/src/tests/test_dual_ownable.cairo +++ /dev/null @@ -1,173 +0,0 @@ -use core::num::traits::Zero; -use crate::ownable::dual_ownable::{DualCaseOwnable, DualCaseOwnableTrait}; -use crate::ownable::interface::{ - IOwnableDispatcher, IOwnableCamelOnlyDispatcher, IOwnableDispatcherTrait -}; -use openzeppelin_testing as utils; -use openzeppelin_testing::constants::{OWNER, NEW_OWNER}; -use openzeppelin_utils::serde::SerializedAppend; -use snforge_std::start_cheat_caller_address; - -// -// Setup -// - -fn setup_snake() -> (DualCaseOwnable, IOwnableDispatcher) { - let mut calldata = array![]; - calldata.append_serde(OWNER()); - let target = utils::declare_and_deploy("SnakeOwnableMock", calldata); - (DualCaseOwnable { contract_address: target }, IOwnableDispatcher { contract_address: target }) -} - -fn setup_camel() -> (DualCaseOwnable, IOwnableCamelOnlyDispatcher) { - let mut calldata = array![]; - calldata.append_serde(OWNER()); - let target = utils::declare_and_deploy("CamelOwnableMock", calldata); - ( - DualCaseOwnable { contract_address: target }, - IOwnableCamelOnlyDispatcher { contract_address: target } - ) -} - -fn setup_non_ownable() -> DualCaseOwnable { - let calldata = array![]; - let target = utils::declare_and_deploy("NonImplementingMock", calldata); - DualCaseOwnable { contract_address: target } -} - -fn setup_ownable_panic() -> (DualCaseOwnable, DualCaseOwnable) { - let snake_target = utils::declare_and_deploy("SnakeOwnablePanicMock", array![]); - let camel_target = utils::declare_and_deploy("CamelOwnablePanicMock", array![]); - ( - DualCaseOwnable { contract_address: snake_target }, - DualCaseOwnable { contract_address: camel_target } - ) -} - -// -// Case agnostic methods -// - -#[test] -fn test_dual_owner() { - let (snake_dispatcher, _) = setup_snake(); - let (camel_dispatcher, _) = setup_camel(); - - let snake_owner = snake_dispatcher.owner(); - assert_eq!(snake_owner, OWNER()); - - let camel_owner = camel_dispatcher.owner(); - assert_eq!(camel_owner, OWNER()); -} - -#[test] -#[ignore] // REASON: should_panic attribute not fit for complex panic messages. -#[should_panic(expected: ('ENTRYPOINT_NOT_FOUND',))] -fn test_dual_no_owner() { - let dispatcher = setup_non_ownable(); - dispatcher.owner(); -} - -#[test] -#[should_panic(expected: "Some error")] -fn test_dual_owner_exists_and_panics() { - let (dispatcher, _) = setup_ownable_panic(); - dispatcher.owner(); -} - -// -// snake_case target -// - -#[test] -fn test_dual_transfer_ownership() { - let (dispatcher, target) = setup_snake(); - start_cheat_caller_address(dispatcher.contract_address, OWNER()); - dispatcher.transfer_ownership(NEW_OWNER()); - - let current_owner = target.owner(); - assert_eq!(current_owner, NEW_OWNER()); -} - -#[test] -#[ignore] // REASON: should_panic attribute not fit for complex panic messages. -#[should_panic(expected: ('ENTRYPOINT_NOT_FOUND',))] -fn test_dual_no_transfer_ownership() { - let dispatcher = setup_non_ownable(); - dispatcher.transfer_ownership(NEW_OWNER()); -} - -#[test] -#[should_panic(expected: "Some error")] -fn test_dual_transfer_ownership_exists_and_panics() { - let (dispatcher, _) = setup_ownable_panic(); - dispatcher.transfer_ownership(NEW_OWNER()); -} - -#[test] -fn test_dual_renounce_ownership() { - let (dispatcher, target) = setup_snake(); - start_cheat_caller_address(dispatcher.contract_address, OWNER()); - dispatcher.renounce_ownership(); - - let current_owner = target.owner(); - assert!(current_owner.is_zero()); -} - -#[test] -#[ignore] // REASON: should_panic attribute not fit for complex panic messages. -#[should_panic(expected: ('ENTRYPOINT_NOT_FOUND',))] -fn test_dual_no_renounce_ownership() { - let dispatcher = setup_non_ownable(); - dispatcher.renounce_ownership(); -} - -#[test] -#[should_panic(expected: "Some error")] -fn test_dual_renounce_ownership_exists_and_panics() { - let (dispatcher, _) = setup_ownable_panic(); - dispatcher.renounce_ownership(); -} - -// -// camelCase target -// - -#[test] -#[ignore] // REASON: foundry entrypoint_not_found error message inconsistent with mainnet. -fn test_dual_transferOwnership() { - let (dispatcher, _) = setup_camel(); - start_cheat_caller_address(dispatcher.contract_address, OWNER()); - dispatcher.transfer_ownership(NEW_OWNER()); - - let current_owner = dispatcher.owner(); - assert_eq!(current_owner, NEW_OWNER()); -} - -#[test] -#[ignore] // REASON: foundry entrypoint_not_found error message inconsistent with mainnet. -#[should_panic(expected: "Some error")] -fn test_dual_transferOwnership_exists_and_panics() { - let (_, camel_dispatcher) = setup_ownable_panic(); - camel_dispatcher.transfer_ownership(NEW_OWNER()); -} - -#[test] -#[ignore] // REASON: foundry entrypoint_not_found error message inconsistent with mainnet. -fn test_dual_renounceOwnership() { - let (dispatcher, _) = setup_camel(); - start_cheat_caller_address(dispatcher.contract_address, OWNER()); - dispatcher.renounce_ownership(); - - let current_owner = dispatcher.owner(); - assert!(current_owner.is_zero()); -} - -#[test] -#[ignore] // REASON: foundry entrypoint_not_found error message inconsistent with mainnet. -#[should_panic(expected: "Some error")] -fn test_dual_renounceOwnership_exists_and_panics() { - let (_, camel_dispatcher) = setup_ownable_panic(); - camel_dispatcher.renounce_ownership(); -} - diff --git a/packages/account/src/dual_account.cairo b/packages/account/src/dual_account.cairo deleted file mode 100644 index 5872df0ff..000000000 --- a/packages/account/src/dual_account.cairo +++ /dev/null @@ -1,67 +0,0 @@ -// SPDX-License-Identifier: MIT -// OpenZeppelin Contracts for Cairo v0.17.0 (account/dual_account.cairo) - -use openzeppelin_utils::UnwrapAndCast; -use openzeppelin_utils::selectors; -use openzeppelin_utils::serde::SerializedAppend; -use openzeppelin_utils::try_selector_with_fallback; -use starknet::ContractAddress; -use starknet::SyscallResultTrait; -use starknet::syscalls::call_contract_syscall; - -#[derive(Copy, Drop)] -pub struct DualCaseAccount { - pub contract_address: ContractAddress -} - -pub trait DualCaseAccountTrait { - fn set_public_key(self: @DualCaseAccount, new_public_key: felt252, signature: Span); - fn get_public_key(self: @DualCaseAccount) -> felt252; - fn is_valid_signature( - self: @DualCaseAccount, hash: felt252, signature: Array - ) -> felt252; - fn supports_interface(self: @DualCaseAccount, interface_id: felt252) -> bool; -} - -impl DualCaseAccountImpl of DualCaseAccountTrait { - fn set_public_key(self: @DualCaseAccount, new_public_key: felt252, signature: Span) { - let mut args = array![new_public_key]; - args.append_serde(signature); - - try_selector_with_fallback( - *self.contract_address, selectors::set_public_key, selectors::setPublicKey, args.span() - ) - .unwrap_syscall(); - } - - fn get_public_key(self: @DualCaseAccount) -> felt252 { - let args = array![]; - - try_selector_with_fallback( - *self.contract_address, selectors::get_public_key, selectors::getPublicKey, args.span() - ) - .unwrap_and_cast() - } - - fn is_valid_signature( - self: @DualCaseAccount, hash: felt252, signature: Array - ) -> felt252 { - let mut args = array![hash]; - args.append_serde(signature); - - try_selector_with_fallback( - *self.contract_address, - selectors::is_valid_signature, - selectors::isValidSignature, - args.span() - ) - .unwrap_and_cast() - } - - fn supports_interface(self: @DualCaseAccount, interface_id: felt252) -> bool { - let args = array![interface_id]; - - call_contract_syscall(*self.contract_address, selectors::supports_interface, args.span()) - .unwrap_and_cast() - } -} diff --git a/packages/account/src/dual_eth_account.cairo b/packages/account/src/dual_eth_account.cairo deleted file mode 100644 index f305aa62d..000000000 --- a/packages/account/src/dual_eth_account.cairo +++ /dev/null @@ -1,73 +0,0 @@ -// SPDX-License-Identifier: MIT -// OpenZeppelin Contracts for Cairo v0.17.0 (account/dual_eth_account.cairo) - -use crate::interface::EthPublicKey; -use openzeppelin_utils::UnwrapAndCast; -use openzeppelin_utils::selectors; -use openzeppelin_utils::serde::SerializedAppend; -use openzeppelin_utils::try_selector_with_fallback; -use starknet::ContractAddress; -use starknet::SyscallResultTrait; -use starknet::syscalls::call_contract_syscall; - -#[derive(Copy, Drop)] -pub struct DualCaseEthAccount { - pub contract_address: ContractAddress -} - -pub trait DualCaseEthAccountTrait { - fn set_public_key( - self: @DualCaseEthAccount, new_public_key: EthPublicKey, signature: Span - ); - fn get_public_key(self: @DualCaseEthAccount) -> EthPublicKey; - fn is_valid_signature( - self: @DualCaseEthAccount, hash: felt252, signature: Array - ) -> felt252; - fn supports_interface(self: @DualCaseEthAccount, interface_id: felt252) -> bool; -} - -impl DualCaseEthAccountImpl of DualCaseEthAccountTrait { - fn set_public_key( - self: @DualCaseEthAccount, new_public_key: EthPublicKey, signature: Span - ) { - let mut args = array![]; - args.append_serde(new_public_key); - args.append_serde(signature); - - try_selector_with_fallback( - *self.contract_address, selectors::set_public_key, selectors::setPublicKey, args.span() - ) - .unwrap_syscall(); - } - - fn get_public_key(self: @DualCaseEthAccount) -> EthPublicKey { - let args = array![]; - - try_selector_with_fallback( - *self.contract_address, selectors::get_public_key, selectors::getPublicKey, args.span() - ) - .unwrap_and_cast() - } - - fn is_valid_signature( - self: @DualCaseEthAccount, hash: felt252, signature: Array - ) -> felt252 { - let mut args = array![hash]; - args.append_serde(signature); - - try_selector_with_fallback( - *self.contract_address, - selectors::is_valid_signature, - selectors::isValidSignature, - args.span() - ) - .unwrap_and_cast() - } - - fn supports_interface(self: @DualCaseEthAccount, interface_id: felt252) -> bool { - let args = array![interface_id]; - - call_contract_syscall(*self.contract_address, selectors::supports_interface, args.span()) - .unwrap_and_cast() - } -} diff --git a/packages/account/src/extensions/src9/snip12_utils.cairo b/packages/account/src/extensions/src9/snip12_utils.cairo index 6a397dfe5..b2d81132c 100644 --- a/packages/account/src/extensions/src9/snip12_utils.cairo +++ b/packages/account/src/extensions/src9/snip12_utils.cairo @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -// OpenZeppelin Contracts for Cairo v0.17.0 (account/extensions/src9/snip12.cairo) +// OpenZeppelin Contracts for Cairo v0.17.0 (account/extensions/src9/snip12_utils.cairo) use core::hash::{HashStateTrait, HashStateExTrait}; use core::poseidon::{PoseidonTrait, poseidon_hash_span}; diff --git a/packages/account/src/extensions/src9/src9.cairo b/packages/account/src/extensions/src9/src9.cairo index 460726871..468e1475f 100644 --- a/packages/account/src/extensions/src9/src9.cairo +++ b/packages/account/src/extensions/src9/src9.cairo @@ -10,11 +10,11 @@ /// interface. #[starknet::component] pub mod SRC9Component { - use crate::dual_account::{DualCaseAccount, DualCaseAccountTrait}; use crate::extensions::src9::OutsideExecution; use crate::extensions::src9::interface; use crate::extensions::src9::snip12_utils::OutsideExecutionStructHash; use crate::utils::execute_calls; + use openzeppelin_account::interface::{ISRC6Dispatcher, ISRC6DispatcherTrait}; use openzeppelin_introspection::src5::SRC5Component::InternalTrait as SRC5InternalTrait; use openzeppelin_introspection::src5::SRC5Component; use openzeppelin_utils::cryptography::snip12::{OffchainMessageHash, SNIP12Metadata}; @@ -105,7 +105,7 @@ pub mod SRC9Component { // Make this component agnostic to the account implementation, as long // as the contract implements the SRC6 interface. - let is_valid_signature_felt = DualCaseAccount { contract_address: this } + let is_valid_signature_felt = ISRC6Dispatcher { contract_address: this } .is_valid_signature(outside_tx_hash, signature.into()); // Check either 'VALID' or true for backwards compatibility. diff --git a/packages/account/src/lib.cairo b/packages/account/src/lib.cairo index 6e4ed8a32..366b3eb8f 100644 --- a/packages/account/src/lib.cairo +++ b/packages/account/src/lib.cairo @@ -1,6 +1,4 @@ pub mod account; -pub mod dual_account; -pub mod dual_eth_account; pub mod eth_account; pub mod extensions; pub mod interface; diff --git a/packages/account/src/tests.cairo b/packages/account/src/tests.cairo index c02171f01..660465d02 100644 --- a/packages/account/src/tests.cairo +++ b/packages/account/src/tests.cairo @@ -4,10 +4,6 @@ pub(crate) mod mocks; #[cfg(test)] mod test_account; #[cfg(test)] -mod test_dual_account; -#[cfg(test)] -mod test_dual_eth_account; -#[cfg(test)] mod test_eth_account; #[cfg(test)] mod test_secp256k1; diff --git a/packages/account/src/tests/mocks.cairo b/packages/account/src/tests/mocks.cairo index 3d873c28b..e9e44bf5d 100644 --- a/packages/account/src/tests/mocks.cairo +++ b/packages/account/src/tests/mocks.cairo @@ -1,5 +1,4 @@ pub(crate) mod account_mocks; pub(crate) mod eth_account_mocks; -pub(crate) mod non_implementing_mock; pub(crate) mod simple_mock; pub(crate) mod src9_mocks; diff --git a/packages/account/src/tests/mocks/account_mocks.cairo b/packages/account/src/tests/mocks/account_mocks.cairo index faddfdf9f..893a339c1 100644 --- a/packages/account/src/tests/mocks/account_mocks.cairo +++ b/packages/account/src/tests/mocks/account_mocks.cairo @@ -43,181 +43,3 @@ pub(crate) mod DualCaseAccountMock { self.account.initializer(public_key); } } - -#[starknet::contract(account)] -pub(crate) mod SnakeAccountMock { - use crate::AccountComponent; - use openzeppelin_introspection::src5::SRC5Component; - - component!(path: AccountComponent, storage: account, event: AccountEvent); - component!(path: SRC5Component, storage: src5, event: SRC5Event); - - // Account - #[abi(embed_v0)] - impl SRC6Impl = AccountComponent::SRC6Impl; - #[abi(embed_v0)] - impl PublicKeyImpl = AccountComponent::PublicKeyImpl; - impl AccountInternalImpl = AccountComponent::InternalImpl; - - // SCR5 - #[abi(embed_v0)] - impl SRC5Impl = SRC5Component::SRC5Impl; - - #[storage] - pub struct Storage { - #[substorage(v0)] - pub account: AccountComponent::Storage, - #[substorage(v0)] - pub src5: SRC5Component::Storage - } - - #[event] - #[derive(Drop, starknet::Event)] - enum Event { - #[flat] - AccountEvent: AccountComponent::Event, - #[flat] - SRC5Event: SRC5Component::Event - } - - #[constructor] - fn constructor(ref self: ContractState, public_key: felt252) { - self.account.initializer(public_key); - } -} - -#[starknet::contract(account)] -pub(crate) mod CamelAccountMock { - use crate::AccountComponent; - use openzeppelin_introspection::src5::SRC5Component; - use starknet::account::Call; - - component!(path: AccountComponent, storage: account, event: AccountEvent); - component!(path: SRC5Component, storage: src5, event: SRC5Event); - - // Account - #[abi(embed_v0)] - impl SRC6CamelOnlyImpl = AccountComponent::SRC6CamelOnlyImpl; - #[abi(embed_v0)] - impl PublicKeyCamelImpl = AccountComponent::PublicKeyCamelImpl; - impl SRC6Impl = AccountComponent::SRC6Impl; - impl AccountInternalImpl = AccountComponent::InternalImpl; - - // SCR5 - #[abi(embed_v0)] - impl SRC5Impl = SRC5Component::SRC5Impl; - - #[storage] - pub struct Storage { - #[substorage(v0)] - pub account: AccountComponent::Storage, - #[substorage(v0)] - pub src5: SRC5Component::Storage - } - - #[event] - #[derive(Drop, starknet::Event)] - enum Event { - #[flat] - AccountEvent: AccountComponent::Event, - #[flat] - SRC5Event: SRC5Component::Event - } - - #[constructor] - fn constructor(ref self: ContractState, publicKey: felt252) { - self.account.initializer(publicKey); - } - - #[abi(per_item)] - #[generate_trait] - impl ExternalImpl of ExternalTrait { - #[external(v0)] - fn __execute__(self: @ContractState, mut calls: Array) -> Array> { - self.account.__execute__(calls) - } - - #[external(v0)] - fn __validate__(self: @ContractState, mut calls: Array) -> felt252 { - self.account.__validate__(calls) - } - } -} - -// Although these modules are designed to panic, functions -// still need a valid return value. We chose: -// -// 3 for felt252 -// false for bool - -#[starknet::contract] -pub(crate) mod SnakeAccountPanicMock { - #[storage] - pub struct Storage {} - - #[abi(per_item)] - #[generate_trait] - impl ExternalImpl of ExternalTrait { - #[external(v0)] - fn set_public_key( - ref self: ContractState, new_public_key: felt252, signature: Span - ) { - panic!("Some error"); - } - - #[external(v0)] - fn get_public_key(self: @ContractState) -> felt252 { - panic!("Some error"); - 3 - } - - #[external(v0)] - fn is_valid_signature( - self: @ContractState, hash: felt252, signature: Array - ) -> felt252 { - panic!("Some error"); - 3 - } - - #[external(v0)] - fn supports_interface(self: @ContractState, interface_id: felt252) -> bool { - panic!("Some error"); - false - } - } -} - -#[starknet::contract] -pub(crate) mod CamelAccountPanicMock { - #[storage] - pub struct Storage {} - - #[abi(per_item)] - #[generate_trait] - impl ExternalImpl of ExternalTrait { - #[external(v0)] - fn setPublicKey(ref self: ContractState, newPublicKey: felt252, signature: Span) { - panic!("Some error"); - } - - #[external(v0)] - fn getPublicKey(self: @ContractState) -> felt252 { - panic!("Some error"); - 3 - } - - #[external(v0)] - fn isValidSignature( - self: @ContractState, hash: felt252, signature: Array - ) -> felt252 { - panic!("Some error"); - 3 - } - - #[external(v0)] - fn supportsInterface(self: @ContractState, interfaceId: felt252) -> bool { - panic!("Some error"); - false - } - } -} diff --git a/packages/account/src/tests/mocks/eth_account_mocks.cairo b/packages/account/src/tests/mocks/eth_account_mocks.cairo index 2787e76d1..71ddeb787 100644 --- a/packages/account/src/tests/mocks/eth_account_mocks.cairo +++ b/packages/account/src/tests/mocks/eth_account_mocks.cairo @@ -41,188 +41,3 @@ pub(crate) mod DualCaseEthAccountMock { self.eth_account.initializer(public_key); } } - -#[starknet::contract(account)] -pub(crate) mod SnakeEthAccountMock { - use crate::EthAccountComponent; - use crate::interface::EthPublicKey; - use openzeppelin_introspection::src5::SRC5Component; - - component!(path: EthAccountComponent, storage: eth_account, event: EthAccountEvent); - component!(path: SRC5Component, storage: src5, event: SRC5Event); - - #[abi(embed_v0)] - impl SRC6Impl = EthAccountComponent::SRC6Impl; - #[abi(embed_v0)] - impl PublicKeyImpl = EthAccountComponent::PublicKeyImpl; - #[abi(embed_v0)] - impl SRC5Impl = SRC5Component::SRC5Impl; - impl EthAccountInternalImpl = EthAccountComponent::InternalImpl; - - #[storage] - pub struct Storage { - #[substorage(v0)] - pub eth_account: EthAccountComponent::Storage, - #[substorage(v0)] - pub src5: SRC5Component::Storage - } - - #[event] - #[derive(Drop, starknet::Event)] - enum Event { - #[flat] - EthAccountEvent: EthAccountComponent::Event, - #[flat] - SRC5Event: SRC5Component::Event - } - - #[constructor] - fn constructor(ref self: ContractState, public_key: EthPublicKey) { - self.eth_account.initializer(public_key); - } -} - -#[starknet::contract(account)] -pub(crate) mod CamelEthAccountMock { - use crate::EthAccountComponent; - use crate::interface::EthPublicKey; - use openzeppelin_introspection::src5::SRC5Component; - use starknet::account::Call; - - component!(path: EthAccountComponent, storage: eth_account, event: EthAccountEvent); - component!(path: SRC5Component, storage: src5, event: SRC5Event); - - #[abi(embed_v0)] - impl SRC6CamelOnlyImpl = EthAccountComponent::SRC6CamelOnlyImpl; - #[abi(embed_v0)] - impl PublicKeyCamelImpl = - EthAccountComponent::PublicKeyCamelImpl; - #[abi(embed_v0)] - impl SRC5Impl = SRC5Component::SRC5Impl; - impl SRC6Impl = EthAccountComponent::SRC6Impl; - impl EthAccountInternalImpl = EthAccountComponent::InternalImpl; - - #[storage] - pub struct Storage { - #[substorage(v0)] - pub eth_account: EthAccountComponent::Storage, - #[substorage(v0)] - pub src5: SRC5Component::Storage - } - - #[event] - #[derive(Drop, starknet::Event)] - enum Event { - #[flat] - EthAccountEvent: EthAccountComponent::Event, - #[flat] - SRC5Event: SRC5Component::Event - } - - #[constructor] - fn constructor(ref self: ContractState, publicKey: EthPublicKey) { - self.eth_account.initializer(publicKey); - } - - #[abi(per_item)] - #[generate_trait] - impl ExternalImpl of ExternalTrait { - #[external(v0)] - fn __execute__(self: @ContractState, mut calls: Array) -> Array> { - self.eth_account.__execute__(calls) - } - - #[external(v0)] - fn __validate__(self: @ContractState, mut calls: Array) -> felt252 { - self.eth_account.__validate__(calls) - } - } -} - -// Although these modules are designed to panic, functions -// still need a valid return value. We chose: -// -// 3 for felt252 -// false for bool - -#[starknet::contract] -pub(crate) mod SnakeEthAccountPanicMock { - use crate::interface::EthPublicKey; - use starknet::SyscallResultTrait; - use starknet::secp256_trait::Secp256Trait; - - #[storage] - pub struct Storage {} - - #[abi(per_item)] - #[generate_trait] - impl ExternalImpl of ExternalTrait { - #[external(v0)] - fn set_public_key( - ref self: ContractState, new_public_key: EthPublicKey, signature: Span - ) { - panic!("Some error"); - } - - #[external(v0)] - fn get_public_key(self: @ContractState) -> EthPublicKey { - panic!("Some error"); - Secp256Trait::secp256_ec_new_syscall(3, 3).unwrap_syscall().unwrap() - } - - #[external(v0)] - fn is_valid_signature( - self: @ContractState, hash: felt252, signature: Array - ) -> felt252 { - panic!("Some error"); - 3 - } - - #[external(v0)] - fn supports_interface(self: @ContractState, interface_id: felt252) -> bool { - panic!("Some error"); - false - } - } -} - -#[starknet::contract] -pub(crate) mod CamelEthAccountPanicMock { - use crate::interface::EthPublicKey; - use starknet::SyscallResultTrait; - use starknet::secp256_trait::Secp256Trait; - - #[storage] - pub struct Storage {} - - #[abi(per_item)] - #[generate_trait] - impl ExternalImpl of ExternalTrait { - #[external(v0)] - fn setPublicKey( - ref self: ContractState, newPublicKey: EthPublicKey, signature: Span - ) { - panic!("Some error"); - } - - #[external(v0)] - fn getPublicKey(self: @ContractState) -> EthPublicKey { - panic!("Some error"); - Secp256Trait::secp256_ec_new_syscall(3, 3).unwrap_syscall().unwrap() - } - - #[external(v0)] - fn isValidSignature( - self: @ContractState, hash: felt252, signature: Array - ) -> felt252 { - panic!("Some error"); - 3 - } - - #[external(v0)] - fn supportsInterface(self: @ContractState, interfaceId: felt252) -> bool { - panic!("Some error"); - false - } - } -} diff --git a/packages/account/src/tests/mocks/non_implementing_mock.cairo b/packages/account/src/tests/mocks/non_implementing_mock.cairo deleted file mode 100644 index 67d632c72..000000000 --- a/packages/account/src/tests/mocks/non_implementing_mock.cairo +++ /dev/null @@ -1,10 +0,0 @@ -#[starknet::contract] -pub(crate) mod NonImplementingMock { - #[storage] - pub struct Storage {} - - #[external(v0)] - fn nope(self: @ContractState) -> bool { - false - } -} diff --git a/packages/account/src/tests/test_dual_account.cairo b/packages/account/src/tests/test_dual_account.cairo deleted file mode 100644 index 467f0878e..000000000 --- a/packages/account/src/tests/test_dual_account.cairo +++ /dev/null @@ -1,220 +0,0 @@ -use crate::dual_account::{DualCaseAccountTrait, DualCaseAccount}; -use crate::interface::{AccountABIDispatcherTrait, AccountABIDispatcher}; -use openzeppelin_introspection::interface::ISRC5_ID; - -use openzeppelin_test_common::account::{get_accept_ownership_signature}; -use openzeppelin_testing as utils; -use openzeppelin_testing::constants::TRANSACTION_HASH; -use openzeppelin_testing::constants::stark::{KEY_PAIR, KEY_PAIR_2}; -use openzeppelin_testing::signing::{StarkKeyPair, StarkSerializedSigning}; -use snforge_std::{start_cheat_caller_address}; - -// -// Setup -// - -fn setup_snake(key_pair: StarkKeyPair) -> (DualCaseAccount, AccountABIDispatcher) { - let calldata = array![key_pair.public_key]; - let contract_address = utils::declare_and_deploy("SnakeAccountMock", calldata); - (DualCaseAccount { contract_address }, AccountABIDispatcher { contract_address }) -} - -fn setup_camel(key_pair: StarkKeyPair) -> (DualCaseAccount, AccountABIDispatcher) { - let calldata = array![key_pair.public_key]; - let contract_address = utils::declare_and_deploy("CamelAccountMock", calldata); - (DualCaseAccount { contract_address }, AccountABIDispatcher { contract_address }) -} - -fn setup_non_account() -> DualCaseAccount { - let calldata = array![]; - let contract_address = utils::declare_and_deploy("NonImplementingMock", calldata); - DualCaseAccount { contract_address } -} - -fn setup_account_panic() -> (DualCaseAccount, DualCaseAccount) { - let snake_target = utils::declare_and_deploy("SnakeAccountPanicMock", array![]); - let camel_target = utils::declare_and_deploy("CamelAccountPanicMock", array![]); - ( - DualCaseAccount { contract_address: snake_target }, - DualCaseAccount { contract_address: camel_target } - ) -} - -// -// snake_case target -// - -#[test] -fn test_dual_set_public_key() { - let key_pair = KEY_PAIR(); - let (snake_dispatcher, target) = setup_snake(key_pair); - let new_key_pair = KEY_PAIR_2(); - let signature = get_accept_ownership_signature( - snake_dispatcher.contract_address, key_pair.public_key, new_key_pair - ); - start_cheat_caller_address(target.contract_address, target.contract_address); - - snake_dispatcher.set_public_key(new_key_pair.public_key, signature); - - assert_eq!(target.get_public_key(), new_key_pair.public_key); -} - -#[test] -#[ignore] // REASON: should_panic attribute not fit for complex panic messages. -#[should_panic(expected: ('ENTRYPOINT_NOT_FOUND',))] -fn test_dual_no_set_public_key() { - let dispatcher = setup_non_account(); - let new_public_key = KEY_PAIR_2().public_key; - dispatcher.set_public_key(new_public_key, array![].span()); -} - -#[test] -#[should_panic(expected: "Some error")] -fn test_dual_set_public_key_exists_and_panics() { - let (snake_dispatcher, _) = setup_account_panic(); - let new_public_key = KEY_PAIR_2().public_key; - snake_dispatcher.set_public_key(new_public_key, array![].span()); -} - -#[test] -fn test_dual_get_public_key() { - let key_pair = KEY_PAIR(); - let (snake_dispatcher, _) = setup_snake(key_pair); - let expected_public_key = key_pair.public_key; - assert_eq!(snake_dispatcher.get_public_key(), expected_public_key); -} - -#[test] -#[ignore] // REASON: should_panic attribute not fit for complex panic messages. -#[should_panic(expected: ('ENTRYPOINT_NOT_FOUND',))] -fn test_dual_no_get_public_key() { - let dispatcher = setup_non_account(); - dispatcher.get_public_key(); -} - -#[test] -#[should_panic(expected: "Some error")] -fn test_dual_get_public_key_exists_and_panics() { - let (snake_dispatcher, _) = setup_account_panic(); - snake_dispatcher.get_public_key(); -} - -#[test] -fn test_dual_is_valid_signature() { - let key_pair = KEY_PAIR(); - let (snake_dispatcher, _) = setup_snake(key_pair); - let tx_hash = TRANSACTION_HASH; - let serialized_signature = key_pair.serialized_sign(tx_hash); - - let is_valid = snake_dispatcher.is_valid_signature(tx_hash, serialized_signature); - assert_eq!(is_valid, starknet::VALIDATED); -} - -#[test] -#[ignore] // REASON: should_panic attribute not fit for complex panic messages. -#[should_panic(expected: ('ENTRYPOINT_NOT_FOUND',))] -fn test_dual_no_is_valid_signature() { - let signature = array![]; - - let dispatcher = setup_non_account(); - dispatcher.is_valid_signature(TRANSACTION_HASH, signature); -} - -#[test] -#[should_panic(expected: "Some error")] -fn test_dual_is_valid_signature_exists_and_panics() { - let signature = array![]; - let (snake_dispatcher, _) = setup_account_panic(); - - snake_dispatcher.is_valid_signature(TRANSACTION_HASH, signature); -} - -#[test] -fn test_dual_supports_interface() { - let (snake_dispatcher, _) = setup_snake(KEY_PAIR()); - let supports_isrc5 = snake_dispatcher.supports_interface(ISRC5_ID); - assert!(supports_isrc5); -} - -#[test] -#[ignore] // REASON: should_panic attribute not fit for complex panic messages. -#[should_panic(expected: ('ENTRYPOINT_NOT_FOUND',))] -fn test_dual_no_supports_interface() { - let dispatcher = setup_non_account(); - dispatcher.supports_interface(ISRC5_ID); -} - -#[test] -#[should_panic(expected: "Some error")] -fn test_dual_supports_interface_exists_and_panics() { - let (snake_dispatcher, _) = setup_account_panic(); - snake_dispatcher.supports_interface(ISRC5_ID); -} - -// -// camelCase target -// - -#[test] -#[ignore] // REASON: foundry entrypoint_not_found error message inconsistent with mainnet. -fn test_dual_setPublicKey() { - let key_pair = KEY_PAIR(); - let (camel_dispatcher, target) = setup_camel(key_pair); - let new_key_pair = KEY_PAIR_2(); - let signature = get_accept_ownership_signature( - camel_dispatcher.contract_address, key_pair.public_key, new_key_pair - ); - start_cheat_caller_address(target.contract_address, target.contract_address); - - camel_dispatcher.set_public_key(new_key_pair.public_key, signature); - - assert_eq!(target.getPublicKey(), new_key_pair.public_key); -} - -#[test] -#[ignore] // REASON: foundry entrypoint_not_found error message inconsistent with mainnet. -#[should_panic(expected: "Some error")] -fn test_dual_setPublicKey_exists_and_panics() { - let (_, camel_dispatcher) = setup_account_panic(); - let new_public_key = KEY_PAIR_2().public_key; - camel_dispatcher.set_public_key(new_public_key, array![].span()); -} - -#[test] -#[ignore] // REASON: foundry entrypoint_not_found error message inconsistent with mainnet. -fn test_dual_getPublicKey() { - let key_pair = KEY_PAIR(); - let (camel_dispatcher, _) = setup_camel(key_pair); - let expected_public_key = key_pair.public_key; - assert_eq!(camel_dispatcher.get_public_key(), expected_public_key); -} - -#[test] -#[ignore] // REASON: foundry entrypoint_not_found error message inconsistent with mainnet. -#[should_panic(expected: "Some error")] -fn test_dual_getPublicKey_exists_and_panics() { - let (_, camel_dispatcher) = setup_account_panic(); - camel_dispatcher.get_public_key(); -} - -#[test] -#[ignore] // REASON: foundry entrypoint_not_found error message inconsistent with mainnet. -fn test_dual_isValidSignature() { - let key_pair = KEY_PAIR(); - let (camel_dispatcher, _) = setup_camel(key_pair); - let tx_hash = TRANSACTION_HASH; - let serialized_signature = key_pair.serialized_sign(tx_hash); - - let is_valid = camel_dispatcher.is_valid_signature(tx_hash, serialized_signature); - assert_eq!(is_valid, starknet::VALIDATED); -} - -#[test] -#[ignore] // REASON: foundry entrypoint_not_found error message inconsistent with mainnet. -#[should_panic(expected: "Some error")] -fn test_dual_isValidSignature_exists_and_panics() { - let signature = array![]; - - let (_, camel_dispatcher) = setup_account_panic(); - camel_dispatcher.is_valid_signature(TRANSACTION_HASH, signature); -} diff --git a/packages/account/src/tests/test_dual_eth_account.cairo b/packages/account/src/tests/test_dual_eth_account.cairo deleted file mode 100644 index c62495448..000000000 --- a/packages/account/src/tests/test_dual_eth_account.cairo +++ /dev/null @@ -1,220 +0,0 @@ -use crate::dual_eth_account::{DualCaseEthAccountTrait, DualCaseEthAccount}; -use crate::interface::{EthAccountABIDispatcherTrait, EthAccountABIDispatcher}; -use crate::utils::secp256k1::{DebugSecp256k1Point, Secp256k1PointPartialEq}; -use openzeppelin_introspection::interface::ISRC5_ID; - -use openzeppelin_test_common::eth_account::get_accept_ownership_signature; -use openzeppelin_testing as utils; -use openzeppelin_testing::constants::TRANSACTION_HASH; -use openzeppelin_testing::constants::secp256k1::{KEY_PAIR, KEY_PAIR_2}; -use openzeppelin_testing::signing::{Secp256k1KeyPair, Secp256k1SerializedSigning}; -use openzeppelin_utils::serde::SerializedAppend; -use snforge_std::start_cheat_caller_address; - -// -// Setup -// - -fn setup_snake(key_pair: Secp256k1KeyPair) -> (DualCaseEthAccount, EthAccountABIDispatcher) { - let mut calldata = array![]; - calldata.append_serde(key_pair.public_key); - - let contract_address = utils::declare_and_deploy("SnakeEthAccountMock", calldata); - (DualCaseEthAccount { contract_address }, EthAccountABIDispatcher { contract_address }) -} - -fn setup_camel(key_pair: Secp256k1KeyPair) -> (DualCaseEthAccount, EthAccountABIDispatcher) { - let mut calldata = array![]; - calldata.append_serde(key_pair.public_key); - - let contract_address = utils::declare_and_deploy("CamelEthAccountMock", calldata); - (DualCaseEthAccount { contract_address }, EthAccountABIDispatcher { contract_address }) -} - -fn setup_non_account() -> DualCaseEthAccount { - let calldata = array![]; - let contract_address = utils::declare_and_deploy("NonImplementingMock", calldata); - DualCaseEthAccount { contract_address } -} - -fn setup_account_panic() -> (DualCaseEthAccount, DualCaseEthAccount) { - let snake_target = utils::declare_and_deploy("SnakeEthAccountPanicMock", array![]); - let camel_target = utils::declare_and_deploy("CamelEthAccountPanicMock", array![]); - ( - DualCaseEthAccount { contract_address: snake_target }, - DualCaseEthAccount { contract_address: camel_target } - ) -} - -// -// snake_case target -// - -#[test] -fn test_dual_set_public_key() { - let key_pair = KEY_PAIR(); - let (snake_dispatcher, target) = setup_snake(key_pair); - let contract_address = snake_dispatcher.contract_address; - - let new_key_pair = KEY_PAIR_2(); - start_cheat_caller_address(contract_address, contract_address); - let signature = get_accept_ownership_signature( - contract_address, key_pair.public_key, new_key_pair - ); - snake_dispatcher.set_public_key(new_key_pair.public_key, signature); - - assert_eq!(target.get_public_key(), new_key_pair.public_key); -} - -#[test] -#[ignore] // REASON: should_panic attribute not fit for complex panic messages. -#[should_panic(expected: ('ENTRYPOINT_NOT_FOUND',))] -fn test_dual_no_set_public_key() { - let dispatcher = setup_non_account(); - dispatcher.set_public_key(KEY_PAIR().public_key, array![].span()); -} - -#[test] -#[should_panic(expected: "Some error")] -fn test_dual_set_public_key_exists_and_panics() { - let (dispatcher, _) = setup_account_panic(); - dispatcher.set_public_key(KEY_PAIR().public_key, array![].span()); -} - -#[test] -fn test_dual_get_public_key() { - let key_pair = KEY_PAIR(); - let (snake_dispatcher, _) = setup_snake(key_pair); - assert_eq!(snake_dispatcher.get_public_key(), key_pair.public_key); -} - -#[test] -#[ignore] // REASON: should_panic attribute not fit for complex panic messages. -#[should_panic(expected: ('ENTRYPOINT_NOT_FOUND',))] -fn test_dual_no_get_public_key() { - let dispatcher = setup_non_account(); - dispatcher.get_public_key(); -} - -#[test] -#[should_panic(expected: "Some error")] -fn test_dual_get_public_key_exists_and_panics() { - let (dispatcher, _) = setup_account_panic(); - dispatcher.get_public_key(); -} - -#[test] -fn test_dual_is_valid_signature() { - let key_pair = KEY_PAIR(); - let (snake_dispatcher, _) = setup_snake(key_pair); - - let serialized_signature = key_pair.serialized_sign(TRANSACTION_HASH.into()); - let is_valid = snake_dispatcher.is_valid_signature(TRANSACTION_HASH, serialized_signature); - assert_eq!(is_valid, starknet::VALIDATED); -} - -#[test] -#[ignore] // REASON: should_panic attribute not fit for complex panic messages. -#[should_panic(expected: ('ENTRYPOINT_NOT_FOUND',))] -fn test_dual_no_is_valid_signature() { - let signature = array![]; - - let dispatcher = setup_non_account(); - dispatcher.is_valid_signature(TRANSACTION_HASH, signature); -} - -#[test] -#[should_panic(expected: "Some error")] -fn test_dual_is_valid_signature_exists_and_panics() { - let signature = array![]; - - let (dispatcher, _) = setup_account_panic(); - dispatcher.is_valid_signature(TRANSACTION_HASH, signature); -} - -#[test] -fn test_dual_supports_interface() { - let (snake_dispatcher, _) = setup_snake(KEY_PAIR()); - assert!(snake_dispatcher.supports_interface(ISRC5_ID), "Should implement ISRC5"); -} - -#[test] -#[ignore] // REASON: should_panic attribute not fit for complex panic messages. -#[should_panic(expected: ('ENTRYPOINT_NOT_FOUND',))] -fn test_dual_no_supports_interface() { - let dispatcher = setup_non_account(); - dispatcher.supports_interface(ISRC5_ID); -} - -#[test] -#[should_panic(expected: "Some error")] -fn test_dual_supports_interface_exists_and_panics() { - let (dispatcher, _) = setup_account_panic(); - dispatcher.supports_interface(ISRC5_ID); -} - -// -// camelCase target -// - -#[test] -#[ignore] // REASON: foundry entrypoint_not_found error message inconsistent with mainnet. -fn test_dual_setPublicKey() { - let key_pair = KEY_PAIR(); - let (camel_dispatcher, target) = setup_camel(key_pair); - let contract_address = camel_dispatcher.contract_address; - - start_cheat_caller_address(contract_address, contract_address); - let new_key_pair = KEY_PAIR_2(); - let signature = get_accept_ownership_signature( - contract_address, key_pair.public_key, new_key_pair - ); - - camel_dispatcher.set_public_key(new_key_pair.public_key, signature); - assert_eq!(target.getPublicKey(), new_key_pair.public_key); -} - -#[test] -#[ignore] // REASON: foundry entrypoint_not_found error message inconsistent with mainnet. -#[should_panic(expected: "Some error")] -fn test_dual_setPublicKey_exists_and_panics() { - let (_, dispatcher) = setup_account_panic(); - dispatcher.set_public_key(KEY_PAIR_2().public_key, array![].span()); -} - -#[test] -#[ignore] // REASON: foundry entrypoint_not_found error message inconsistent with mainnet. -fn test_dual_getPublicKey() { - let key_pair = KEY_PAIR(); - let (camel_dispatcher, _) = setup_camel(key_pair); - assert_eq!(camel_dispatcher.get_public_key(), key_pair.public_key); -} - -#[test] -#[ignore] // REASON: foundry entrypoint_not_found error message inconsistent with mainnet. -#[should_panic(expected: "Some error")] -fn test_dual_getPublicKey_exists_and_panics() { - let (_, dispatcher) = setup_account_panic(); - dispatcher.get_public_key(); -} - -#[test] -#[ignore] // REASON: foundry entrypoint_not_found error message inconsistent with mainnet. -fn test_dual_isValidSignature() { - let key_pair = KEY_PAIR(); - let (camel_dispatcher, _) = setup_camel(key_pair); - - let serialized_signature = key_pair.serialized_sign(TRANSACTION_HASH.into()); - let is_valid = camel_dispatcher.is_valid_signature(TRANSACTION_HASH, serialized_signature); - assert_eq!(is_valid, starknet::VALIDATED); -} - -#[test] -#[ignore] // REASON: foundry entrypoint_not_found error message inconsistent with mainnet. -#[should_panic(expected: "Some error")] -fn test_dual_isValidSignature_exists_and_panics() { - let signature = array![]; - - let (_, dispatcher) = setup_account_panic(); - dispatcher.is_valid_signature(TRANSACTION_HASH, signature); -} diff --git a/packages/presets/src/tests/mocks/account_mocks.cairo b/packages/presets/src/tests/mocks/account_mocks.cairo index f8f222dad..c92013f39 100644 --- a/packages/presets/src/tests/mocks/account_mocks.cairo +++ b/packages/presets/src/tests/mocks/account_mocks.cairo @@ -85,61 +85,3 @@ pub(crate) mod SnakeAccountMock { self.account.initializer(public_key); } } - -#[starknet::contract(account)] -pub(crate) mod CamelAccountMock { - use openzeppelin_account::AccountComponent; - use openzeppelin_introspection::src5::SRC5Component; - use starknet::account::Call; - - component!(path: AccountComponent, storage: account, event: AccountEvent); - component!(path: SRC5Component, storage: src5, event: SRC5Event); - - // Account - #[abi(embed_v0)] - impl SRC6CamelOnlyImpl = AccountComponent::SRC6CamelOnlyImpl; - #[abi(embed_v0)] - impl PublicKeyCamelImpl = AccountComponent::PublicKeyCamelImpl; - impl SRC6Impl = AccountComponent::SRC6Impl; - impl AccountInternalImpl = AccountComponent::InternalImpl; - - // SCR5 - #[abi(embed_v0)] - impl SRC5Impl = SRC5Component::SRC5Impl; - - #[storage] - pub struct Storage { - #[substorage(v0)] - pub account: AccountComponent::Storage, - #[substorage(v0)] - pub src5: SRC5Component::Storage - } - - #[event] - #[derive(Drop, starknet::Event)] - enum Event { - #[flat] - AccountEvent: AccountComponent::Event, - #[flat] - SRC5Event: SRC5Component::Event - } - - #[constructor] - fn constructor(ref self: ContractState, publicKey: felt252) { - self.account.initializer(publicKey); - } - - #[abi(per_item)] - #[generate_trait] - impl ExternalImpl of ExternalTrait { - #[external(v0)] - fn __execute__(self: @ContractState, mut calls: Array) -> Array> { - self.account.__execute__(calls) - } - - #[external(v0)] - fn __validate__(self: @ContractState, mut calls: Array) -> felt252 { - self.account.__validate__(calls) - } - } -} diff --git a/packages/presets/src/tests/mocks/erc1155_mocks.cairo b/packages/presets/src/tests/mocks/erc1155_mocks.cairo index ffa4a3ec4..8ebd48000 100644 --- a/packages/presets/src/tests/mocks/erc1155_mocks.cairo +++ b/packages/presets/src/tests/mocks/erc1155_mocks.cairo @@ -48,54 +48,3 @@ pub(crate) mod SnakeERC1155Mock { self.erc1155.mint_with_acceptance_check(recipient, token_id, value, array![].span()); } } - -#[starknet::contract] -pub(crate) mod CamelERC1155Mock { - use openzeppelin_introspection::src5::SRC5Component; - use openzeppelin_token::erc1155::{ERC1155Component, ERC1155HooksEmptyImpl}; - use starknet::ContractAddress; - - component!(path: ERC1155Component, storage: erc1155, event: ERC1155Event); - component!(path: SRC5Component, storage: src5, event: SRC5Event); - - // ERC1155 - #[abi(embed_v0)] - impl ERC1155Camel = ERC1155Component::ERC1155CamelImpl; - #[abi(embed_v0)] - impl ERC1155MetadataURIImpl = - ERC1155Component::ERC1155MetadataURIImpl; - impl ERC1155InternalImpl = ERC1155Component::InternalImpl; - - // SRC5 - #[abi(embed_v0)] - impl SRC5Impl = SRC5Component::SRC5Impl; - - #[storage] - pub struct Storage { - #[substorage(v0)] - pub erc1155: ERC1155Component::Storage, - #[substorage(v0)] - pub src5: SRC5Component::Storage - } - - #[event] - #[derive(Drop, starknet::Event)] - enum Event { - #[flat] - ERC1155Event: ERC1155Component::Event, - #[flat] - SRC5Event: SRC5Component::Event - } - - #[constructor] - fn constructor( - ref self: ContractState, - base_uri: ByteArray, - recipient: ContractAddress, - token_id: u256, - value: u256 - ) { - self.erc1155.initializer(base_uri); - self.erc1155.mint_with_acceptance_check(recipient, token_id, value, array![].span()); - } -} diff --git a/packages/presets/src/tests/mocks/erc1155_receiver_mocks.cairo b/packages/presets/src/tests/mocks/erc1155_receiver_mocks.cairo index cb9f8ac25..30e722593 100644 --- a/packages/presets/src/tests/mocks/erc1155_receiver_mocks.cairo +++ b/packages/presets/src/tests/mocks/erc1155_receiver_mocks.cairo @@ -1,5 +1,5 @@ #[starknet::contract] -pub(crate) mod SnakeERC1155ReceiverMock { +pub(crate) mod DualCaseERC1155ReceiverMock { use openzeppelin_introspection::src5::SRC5Component; use openzeppelin_token::erc1155::ERC1155ReceiverComponent; @@ -8,16 +8,12 @@ pub(crate) mod SnakeERC1155ReceiverMock { path: ERC1155ReceiverComponent, storage: erc1155_receiver, event: ERC1155ReceiverEvent ); - // ERC1155Receiver + // ERC1155Receiver Mixin #[abi(embed_v0)] - impl ERC1155ReceiverImpl = - ERC1155ReceiverComponent::ERC1155ReceiverImpl; + impl ERC1155ReceiverMixinImpl = + ERC1155ReceiverComponent::ERC1155ReceiverMixinImpl; impl ERC1155ReceiverInternalImpl = ERC1155ReceiverComponent::InternalImpl; - // SRC5 - #[abi(embed_v0)] - impl SRC5Impl = SRC5Component::SRC5Impl; - #[storage] pub struct Storage { #[substorage(v0)] diff --git a/packages/presets/src/tests/mocks/erc721_receiver_mocks.cairo b/packages/presets/src/tests/mocks/erc721_receiver_mocks.cairo index 71154e21b..b18b1d647 100644 --- a/packages/presets/src/tests/mocks/erc721_receiver_mocks.cairo +++ b/packages/presets/src/tests/mocks/erc721_receiver_mocks.cairo @@ -1,7 +1,7 @@ const SUCCESS: felt252 = 'SUCCESS'; #[starknet::contract] -pub(crate) mod SnakeERC721ReceiverMock { +pub(crate) mod DualCaseERC721ReceiverMock { use openzeppelin_introspection::src5::SRC5Component; use openzeppelin_token::erc721::ERC721ReceiverComponent; use starknet::ContractAddress; @@ -56,51 +56,7 @@ pub(crate) mod SnakeERC721ReceiverMock { 0 } } - } -} - -#[starknet::contract] -pub(crate) mod CamelERC721ReceiverMock { - use openzeppelin_introspection::src5::SRC5Component; - use openzeppelin_token::erc721::ERC721ReceiverComponent; - use starknet::ContractAddress; - - component!(path: ERC721ReceiverComponent, storage: erc721_receiver, event: ERC721ReceiverEvent); - component!(path: SRC5Component, storage: src5, event: SRC5Event); - - // ERC721Receiver - impl ERC721ReceiverCamelImpl = ERC721ReceiverComponent::ERC721ReceiverCamelImpl; - impl ERC721ReceiverInternalImpl = ERC721ReceiverComponent::InternalImpl; - - // SRC5 - #[abi(embed_v0)] - impl SRC5Impl = SRC5Component::SRC5Impl; - - #[storage] - pub struct Storage { - #[substorage(v0)] - pub erc721_receiver: ERC721ReceiverComponent::Storage, - #[substorage(v0)] - pub src5: SRC5Component::Storage - } - - #[event] - #[derive(Drop, starknet::Event)] - enum Event { - #[flat] - ERC721ReceiverEvent: ERC721ReceiverComponent::Event, - #[flat] - SRC5Event: SRC5Component::Event - } - #[constructor] - fn constructor(ref self: ContractState) { - self.erc721_receiver.initializer(); - } - - #[abi(per_item)] - #[generate_trait] - impl ExternalImpl of ExternalTrait { #[external(v0)] fn onERC721Received( self: @ContractState, @@ -109,11 +65,7 @@ pub(crate) mod CamelERC721ReceiverMock { tokenId: u256, data: Span ) -> felt252 { - if *data.at(0) == super::SUCCESS { - self.erc721_receiver.onERC721Received(operator, from, tokenId, data) - } else { - 0 - } + Self::on_erc721_received(self, operator, from, tokenId, data) } } } diff --git a/packages/presets/src/tests/test_account.cairo b/packages/presets/src/tests/test_account.cairo index b38996e6d..541bd1757 100644 --- a/packages/presets/src/tests/test_account.cairo +++ b/packages/presets/src/tests/test_account.cairo @@ -19,7 +19,6 @@ use openzeppelin_testing::constants::{ }; use openzeppelin_testing::signing::StarkKeyPair; use openzeppelin_token::erc20::interface::IERC20DispatcherTrait; -use openzeppelin_utils::selectors; use openzeppelin_utils::serde::SerializedAppend; use snforge_std::{ start_cheat_signature_global, start_cheat_transaction_version_global, @@ -350,7 +349,7 @@ fn test_execute_with_version(version: Option) { calldata.append_serde(amount); let call = Call { - to: erc20.contract_address, selector: selectors::transfer, calldata: calldata.span() + to: erc20.contract_address, selector: selector!("transfer"), calldata: calldata.span() }; let calls = array![call]; @@ -441,7 +440,7 @@ fn test_multicall() { calldata1.append_serde(recipient1); calldata1.append_serde(amount1); let call1 = Call { - to: erc20.contract_address, selector: selectors::transfer, calldata: calldata1.span() + to: erc20.contract_address, selector: selector!("transfer"), calldata: calldata1.span() }; // Craft 2nd call @@ -450,7 +449,7 @@ fn test_multicall() { calldata2.append_serde(recipient2); calldata2.append_serde(amount2); let call2 = Call { - to: erc20.contract_address, selector: selectors::transfer, calldata: calldata2.span() + to: erc20.contract_address, selector: selector!("transfer"), calldata: calldata2.span() }; // Bundle calls and execute diff --git a/packages/presets/src/tests/test_erc1155.cairo b/packages/presets/src/tests/test_erc1155.cairo index 01c0518c8..7cfb30f97 100644 --- a/packages/presets/src/tests/test_erc1155.cairo +++ b/packages/presets/src/tests/test_erc1155.cairo @@ -2,7 +2,7 @@ use core::num::traits::Zero; use crate::interfaces::{ERC1155UpgradeableABIDispatcher, ERC1155UpgradeableABIDispatcherTrait}; use openzeppelin_test_common::erc1155::ERC1155SpyHelpers; use openzeppelin_test_common::erc1155::{ - setup_account, setup_receiver, setup_camel_receiver, deploy_another_account_at, setup_src5 + setup_account, setup_receiver, deploy_another_account_at, setup_src5 }; use openzeppelin_test_common::erc1155::{get_ids_and_values, get_ids_and_split_values}; use openzeppelin_test_common::ownable::OwnableSpyHelpers; @@ -168,21 +168,6 @@ fn test_safe_transfer_from_to_receiver() { assert_state_after_transfer_single(dispatcher, owner, recipient, TOKEN_ID); } -#[test] -#[ignore] // REASON: foundry entrypoint_not_found error message inconsistent with mainnet. -fn test_safe_transfer_from_to_camel_receiver() { - let (mut spy, dispatcher, owner) = setup_dispatcher(); - let contract = dispatcher.contract_address; - let recipient = setup_camel_receiver(); - - assert_state_before_transfer_single(dispatcher, owner, recipient, TOKEN_ID); - - dispatcher.safe_transfer_from(owner, recipient, TOKEN_ID, TOKEN_VALUE, EMPTY_DATA()); - spy.assert_only_event_transfer_single(contract, owner, owner, recipient, TOKEN_ID, TOKEN_VALUE); - - assert_state_after_transfer_single(dispatcher, owner, recipient, TOKEN_ID); -} - #[test] fn test_safeTransferFrom_to_receiver() { let (mut spy, dispatcher, owner) = setup_dispatcher(); @@ -197,21 +182,6 @@ fn test_safeTransferFrom_to_receiver() { assert_state_after_transfer_single(dispatcher, owner, recipient, TOKEN_ID); } -#[test] -#[ignore] // REASON: foundry entrypoint_not_found error message inconsistent with mainnet. -fn test_safeTransferFrom_to_camel_receiver() { - let (mut spy, dispatcher, owner) = setup_dispatcher(); - let contract = dispatcher.contract_address; - let recipient = setup_camel_receiver(); - - assert_state_before_transfer_single(dispatcher, owner, recipient, TOKEN_ID); - - dispatcher.safeTransferFrom(owner, recipient, TOKEN_ID, TOKEN_VALUE, EMPTY_DATA()); - spy.assert_only_event_transfer_single(contract, owner, owner, recipient, TOKEN_ID, TOKEN_VALUE); - - assert_state_after_transfer_single(dispatcher, owner, recipient, TOKEN_ID); -} - #[test] fn test_safe_transfer_from_to_account() { let (mut spy, dispatcher, owner) = setup_dispatcher(); @@ -393,22 +363,6 @@ fn test_safe_batch_transfer_from_to_receiver() { assert_state_after_transfer_batch(dispatcher, owner, recipient, token_ids, values); } -#[test] -#[ignore] // REASON: foundry entrypoint_not_found error message inconsistent with mainnet. -fn test_safe_batch_transfer_from_to_camel_receiver() { - let (mut spy, dispatcher, owner) = setup_dispatcher(); - let contract = dispatcher.contract_address; - let recipient = setup_camel_receiver(); - let (token_ids, values) = get_ids_and_values(); - - assert_state_before_transfer_batch(dispatcher, owner, recipient, token_ids, values); - - dispatcher.safe_batch_transfer_from(owner, recipient, token_ids, values, EMPTY_DATA()); - spy.assert_only_event_transfer_batch(contract, owner, owner, recipient, token_ids, values); - - assert_state_after_transfer_batch(dispatcher, owner, recipient, token_ids, values); -} - #[test] fn test_safeBatchTransferFrom_to_receiver() { let (mut spy, dispatcher, owner) = setup_dispatcher(); @@ -424,22 +378,6 @@ fn test_safeBatchTransferFrom_to_receiver() { assert_state_after_transfer_batch(dispatcher, owner, recipient, token_ids, values); } -#[test] -#[ignore] // REASON: foundry entrypoint_not_found error message inconsistent with mainnet. -fn test_safeBatchTransferFrom_to_camel_receiver() { - let (mut spy, dispatcher, owner) = setup_dispatcher(); - let contract = dispatcher.contract_address; - let recipient = setup_camel_receiver(); - let (token_ids, values) = get_ids_and_values(); - - assert_state_before_transfer_batch(dispatcher, owner, recipient, token_ids, values); - - dispatcher.safeBatchTransferFrom(owner, recipient, token_ids, values, EMPTY_DATA()); - spy.assert_only_event_transfer_batch(contract, owner, owner, recipient, token_ids, values); - - assert_state_after_transfer_batch(dispatcher, owner, recipient, token_ids, values); -} - #[test] fn test_safe_batch_transfer_from_to_account() { let (mut spy, dispatcher, owner) = setup_dispatcher(); diff --git a/packages/presets/src/tests/test_erc721.cairo b/packages/presets/src/tests/test_erc721.cairo index 2aecede3a..6800e55b8 100644 --- a/packages/presets/src/tests/test_erc721.cairo +++ b/packages/presets/src/tests/test_erc721.cairo @@ -64,11 +64,7 @@ fn setup_dispatcher() -> (EventSpy, ERC721UpgradeableABIDispatcher) { } fn setup_receiver() -> ContractAddress { - utils::declare_and_deploy("SnakeERC721ReceiverMock", array![]) -} - -fn setup_camel_receiver() -> ContractAddress { - utils::declare_and_deploy("CamelERC721ReceiverMock", array![]) + utils::declare_and_deploy("DualCaseERC721ReceiverMock", array![]) } fn setup_account() -> ContractAddress { @@ -76,11 +72,6 @@ fn setup_account() -> ContractAddress { utils::declare_and_deploy("DualCaseAccountMock", calldata) } -fn setup_camel_account() -> ContractAddress { - let mut calldata = array![PUBKEY]; - utils::declare_and_deploy("CamelAccountMock", calldata) -} - // // mint_assets // @@ -513,38 +504,6 @@ fn test_safeTransferFrom_to_account() { assert_state_after_transfer(dispatcher, owner, account, token_id); } -#[test] -fn test_safe_transfer_from_to_account_camel() { - let (mut spy, dispatcher) = setup_dispatcher(); - let account = setup_camel_account(); - let token_id = TOKEN_1; - let owner = OWNER(); - spy.drop_all_events(); - - assert_state_before_transfer(dispatcher, owner, account, token_id); - - dispatcher.safe_transfer_from(owner, account, token_id, DATA(true)); - spy.assert_only_event_transfer(dispatcher.contract_address, owner, account, token_id); - - assert_state_after_transfer(dispatcher, owner, account, token_id); -} - -#[test] -fn test_safeTransferFrom_to_account_camel() { - let (mut spy, dispatcher) = setup_dispatcher(); - let account = setup_camel_account(); - let token_id = TOKEN_1; - let owner = OWNER(); - spy.drop_all_events(); - - assert_state_before_transfer(dispatcher, owner, account, token_id); - - dispatcher.safeTransferFrom(owner, account, token_id, DATA(true)); - spy.assert_only_event_transfer(dispatcher.contract_address, owner, account, token_id); - - assert_state_after_transfer(dispatcher, owner, account, token_id); -} - #[test] fn test_safe_transfer_from_to_receiver() { let (mut spy, dispatcher) = setup_dispatcher(); @@ -575,38 +534,6 @@ fn test_safeTransferFrom_to_receiver() { assert_state_after_transfer(dispatcher, owner, receiver, token_id); } -#[test] -#[ignore] // REASON: foundry entrypoint_not_found error message inconsistent with mainnet. -fn test_safe_transfer_from_to_receiver_camel() { - let (mut spy, dispatcher) = setup_dispatcher(); - let receiver = setup_camel_receiver(); - let token_id = TOKEN_1; - let owner = OWNER(); - - assert_state_before_transfer(dispatcher, owner, receiver, token_id); - - dispatcher.safe_transfer_from(owner, receiver, token_id, DATA(true)); - spy.assert_only_event_transfer(dispatcher.contract_address, owner, receiver, token_id); - - assert_state_after_transfer(dispatcher, owner, receiver, token_id); -} - -#[test] -#[ignore] // REASON: foundry entrypoint_not_found error message inconsistent with mainnet. -fn test_safeTransferFrom_to_receiver_camel() { - let (mut spy, dispatcher) = setup_dispatcher(); - let receiver = setup_camel_receiver(); - let token_id = TOKEN_1; - let owner = OWNER(); - - assert_state_before_transfer(dispatcher, owner, receiver, token_id); - - dispatcher.safeTransferFrom(owner, receiver, token_id, DATA(true)); - spy.assert_only_event_transfer(dispatcher.contract_address, owner, receiver, token_id); - - assert_state_after_transfer(dispatcher, owner, receiver, token_id); -} - #[test] #[should_panic(expected: ('ERC721: safe transfer failed',))] fn test_safe_transfer_from_to_receiver_failure() { @@ -629,30 +556,6 @@ fn test_safeTransferFrom_to_receiver_failure() { dispatcher.safeTransferFrom(owner, receiver, token_id, DATA(false)); } -#[test] -#[ignore] // REASON: foundry entrypoint_not_found error message inconsistent with mainnet. -#[should_panic(expected: ('ERC721: safe transfer failed',))] -fn test_safe_transfer_from_to_receiver_failure_camel() { - let (_, dispatcher) = setup_dispatcher(); - let receiver = setup_camel_receiver(); - let token_id = TOKEN_1; - let owner = OWNER(); - - dispatcher.safe_transfer_from(owner, receiver, token_id, DATA(false)); -} - -#[test] -#[ignore] // REASON: foundry entrypoint_not_found error message inconsistent with mainnet. -#[should_panic(expected: ('ERC721: safe transfer failed',))] -fn test_safeTransferFrom_to_receiver_failure_camel() { - let (_, dispatcher) = setup_dispatcher(); - let receiver = setup_camel_receiver(); - let token_id = TOKEN_1; - let owner = OWNER(); - - dispatcher.safeTransferFrom(owner, receiver, token_id, DATA(false)); -} - #[test] #[ignore] // REASON: foundry entrypoint_not_found error message inconsistent with mainnet. #[should_panic(expected: ('ENTRYPOINT_NOT_FOUND',))] @@ -741,44 +644,6 @@ fn test_safeTransferFrom_to_owner() { assert_state_transfer_to_self(dispatcher, receiver, token_id, 1); } -#[test] -#[ignore] // REASON: foundry entrypoint_not_found error message inconsistent with mainnet. -fn test_safe_transfer_from_to_owner_camel() { - let (mut spy, dispatcher) = setup_dispatcher(); - let token_id = TOKEN_1; - let receiver = setup_camel_receiver(); - - dispatcher.transfer_from(OWNER(), receiver, token_id); - spy.drop_event(); - - assert_state_transfer_to_self(dispatcher, receiver, token_id, 1); - - start_cheat_caller_address(dispatcher.contract_address, receiver); - dispatcher.safe_transfer_from(receiver, receiver, token_id, DATA(true)); - spy.assert_only_event_transfer(dispatcher.contract_address, receiver, receiver, token_id); - - assert_state_transfer_to_self(dispatcher, receiver, token_id, 1); -} - -#[test] -#[ignore] // REASON: foundry entrypoint_not_found error message inconsistent with mainnet. -fn test_safeTransferFrom_to_owner_camel() { - let (mut spy, dispatcher) = setup_dispatcher(); - let token_id = TOKEN_1; - let receiver = setup_camel_receiver(); - - dispatcher.transfer_from(OWNER(), receiver, token_id); - spy.drop_event(); - - assert_state_transfer_to_self(dispatcher, receiver, token_id, 1); - - start_cheat_caller_address(dispatcher.contract_address, receiver); - dispatcher.safeTransferFrom(receiver, receiver, token_id, DATA(true)); - spy.assert_only_event_transfer(dispatcher.contract_address, receiver, receiver, token_id); - - assert_state_transfer_to_self(dispatcher, receiver, token_id, 1); -} - #[test] fn test_safe_transfer_from_approved() { let (mut spy, dispatcher) = setup_dispatcher(); @@ -817,46 +682,6 @@ fn test_safeTransferFrom_approved() { assert_state_after_transfer(dispatcher, owner, receiver, token_id); } -#[test] -#[ignore] // REASON: foundry entrypoint_not_found error message inconsistent with mainnet. -fn test_safe_transfer_from_approved_camel() { - let (mut spy, dispatcher) = setup_dispatcher(); - let receiver = setup_camel_receiver(); - let token_id = TOKEN_1; - let owner = OWNER(); - - assert_state_before_transfer(dispatcher, owner, receiver, token_id); - - dispatcher.approve(OPERATOR(), token_id); - spy.drop_event(); - - start_cheat_caller_address(dispatcher.contract_address, OPERATOR()); - dispatcher.safe_transfer_from(owner, receiver, token_id, DATA(true)); - spy.assert_only_event_transfer(dispatcher.contract_address, owner, receiver, token_id); - - assert_state_after_transfer(dispatcher, owner, receiver, token_id); -} - -#[test] -#[ignore] // REASON: foundry entrypoint_not_found error message inconsistent with mainnet. -fn test_safeTransferFrom_approved_camel() { - let (mut spy, dispatcher) = setup_dispatcher(); - let receiver = setup_camel_receiver(); - let token_id = TOKEN_1; - let owner = OWNER(); - - assert_state_before_transfer(dispatcher, owner, receiver, token_id); - - dispatcher.approve(OPERATOR(), token_id); - spy.drop_event(); - - start_cheat_caller_address(dispatcher.contract_address, OPERATOR()); - dispatcher.safeTransferFrom(owner, receiver, token_id, DATA(true)); - spy.assert_only_event_transfer(dispatcher.contract_address, owner, receiver, token_id); - - assert_state_after_transfer(dispatcher, owner, receiver, token_id); -} - #[test] fn test_safe_transfer_from_approved_for_all() { let (mut spy, dispatcher) = setup_dispatcher(); @@ -895,46 +720,6 @@ fn test_safeTransferFrom_approved_for_all() { assert_state_after_transfer(dispatcher, owner, receiver, token_id); } -#[test] -#[ignore] // REASON: foundry entrypoint_not_found error message inconsistent with mainnet. -fn test_safe_transfer_from_approved_for_all_camel() { - let (mut spy, dispatcher) = setup_dispatcher(); - let receiver = setup_camel_receiver(); - let token_id = TOKEN_1; - let owner = OWNER(); - - assert_state_before_transfer(dispatcher, owner, receiver, token_id); - - dispatcher.set_approval_for_all(OPERATOR(), true); - spy.drop_event(); - - start_cheat_caller_address(dispatcher.contract_address, OPERATOR()); - dispatcher.safe_transfer_from(owner, receiver, token_id, DATA(true)); - spy.assert_only_event_transfer(dispatcher.contract_address, owner, receiver, token_id); - - assert_state_after_transfer(dispatcher, owner, receiver, token_id); -} - -#[test] -#[ignore] // REASON: foundry entrypoint_not_found error message inconsistent with mainnet. -fn test_safeTransferFrom_approved_for_all_camel() { - let (mut spy, dispatcher) = setup_dispatcher(); - let receiver = setup_camel_receiver(); - let token_id = TOKEN_1; - let owner = OWNER(); - - assert_state_before_transfer(dispatcher, owner, receiver, token_id); - - dispatcher.set_approval_for_all(OPERATOR(), true); - spy.drop_event(); - - start_cheat_caller_address(dispatcher.contract_address, OPERATOR()); - dispatcher.safeTransferFrom(owner, receiver, token_id, DATA(true)); - spy.assert_only_event_transfer(dispatcher.contract_address, owner, receiver, token_id); - - assert_state_after_transfer(dispatcher, owner, receiver, token_id); -} - #[test] #[should_panic(expected: ('ERC721: unauthorized caller',))] fn test_safe_transfer_from_unauthorized() { diff --git a/packages/presets/src/tests/test_eth_account.cairo b/packages/presets/src/tests/test_eth_account.cairo index cfb3f0c14..a46d39c64 100644 --- a/packages/presets/src/tests/test_eth_account.cairo +++ b/packages/presets/src/tests/test_eth_account.cairo @@ -21,7 +21,6 @@ use openzeppelin_testing::constants::{CLASS_HASH_ZERO, ZERO, RECIPIENT, CALLER, use openzeppelin_testing::constants::{SALT, QUERY_VERSION, MIN_TRANSACTION_VERSION}; use openzeppelin_testing::signing::Secp256k1KeyPair; use openzeppelin_token::erc20::interface::IERC20DispatcherTrait; -use openzeppelin_utils::selectors; use openzeppelin_utils::serde::SerializedAppend; use snforge_std::{ start_cheat_signature_global, start_cheat_transaction_version_global, @@ -328,7 +327,7 @@ fn test_execute_with_version(version: Option) { calldata.append_serde(amount); let call = Call { - to: erc20.contract_address, selector: selectors::transfer, calldata: calldata.span() + to: erc20.contract_address, selector: selector!("transfer"), calldata: calldata.span() }; let calls = array![call]; @@ -398,7 +397,7 @@ fn test_multicall() { calldata1.append_serde(recipient1); calldata1.append_serde(amount1); let call1 = Call { - to: erc20.contract_address, selector: selectors::transfer, calldata: calldata1.span() + to: erc20.contract_address, selector: selector!("transfer"), calldata: calldata1.span() }; // Craft 2nd call @@ -407,7 +406,7 @@ fn test_multicall() { calldata2.append_serde(recipient2); calldata2.append_serde(amount2); let call2 = Call { - to: erc20.contract_address, selector: selectors::transfer, calldata: calldata2.span() + to: erc20.contract_address, selector: selector!("transfer"), calldata: calldata2.span() }; let calls = array![call1, call2]; diff --git a/packages/test_common/src/erc1155.cairo b/packages/test_common/src/erc1155.cairo index 75350ec22..569c1c781 100644 --- a/packages/test_common/src/erc1155.cairo +++ b/packages/test_common/src/erc1155.cairo @@ -7,16 +7,12 @@ use snforge_std::EventSpy; use starknet::ContractAddress; pub fn setup_receiver() -> ContractAddress { - utils::declare_and_deploy("SnakeERC1155ReceiverMock", array![]) -} - -pub fn setup_camel_receiver() -> ContractAddress { - utils::declare_and_deploy("CamelERC1155ReceiverMock", array![]) + utils::declare_and_deploy("DualCaseERC1155ReceiverMock", array![]) } pub fn setup_account() -> ContractAddress { let calldata = array![PUBKEY]; - utils::declare_and_deploy("SnakeAccountMock", calldata) + utils::declare_and_deploy("DualCaseAccountMock", calldata) } pub fn deploy_another_account_at(existing: ContractAddress, target_address: ContractAddress) { diff --git a/packages/token/src/erc1155.cairo b/packages/token/src/erc1155.cairo index 68a61043a..8d92872cf 100644 --- a/packages/token/src/erc1155.cairo +++ b/packages/token/src/erc1155.cairo @@ -1,5 +1,3 @@ -pub mod dual1155; -pub mod dual1155_receiver; pub mod erc1155; pub mod erc1155_receiver; pub mod interface; diff --git a/packages/token/src/erc1155/dual1155.cairo b/packages/token/src/erc1155/dual1155.cairo deleted file mode 100644 index 95da3bfa2..000000000 --- a/packages/token/src/erc1155/dual1155.cairo +++ /dev/null @@ -1,166 +0,0 @@ -// SPDX-License-Identifier: MIT -// OpenZeppelin Contracts for Cairo v0.17.0 (token/erc1155/dual1155.cairo) - -use openzeppelin_utils::UnwrapAndCast; -use openzeppelin_utils::selectors; -use openzeppelin_utils::serde::SerializedAppend; -use openzeppelin_utils::try_selector_with_fallback; -use starknet::ContractAddress; -use starknet::SyscallResultTrait; -use starknet::syscalls::call_contract_syscall; - -#[derive(Copy, Drop)] -pub struct DualCaseERC1155 { - pub contract_address: ContractAddress -} - -pub trait DualCaseERC1155Trait { - fn uri(self: @DualCaseERC1155, token_id: u256) -> ByteArray; - fn balance_of(self: @DualCaseERC1155, account: ContractAddress, token_id: u256) -> u256; - fn balance_of_batch( - self: @DualCaseERC1155, accounts: Span, token_ids: Span - ) -> Span; - fn safe_transfer_from( - self: @DualCaseERC1155, - from: ContractAddress, - to: ContractAddress, - token_id: u256, - value: u256, - data: Span - ); - fn safe_batch_transfer_from( - self: @DualCaseERC1155, - from: ContractAddress, - to: ContractAddress, - token_ids: Span, - values: Span, - data: Span - ); - fn is_approved_for_all( - self: @DualCaseERC1155, owner: ContractAddress, operator: ContractAddress - ) -> bool; - fn set_approval_for_all(self: @DualCaseERC1155, operator: ContractAddress, approved: bool); - fn supports_interface(self: @DualCaseERC1155, interface_id: felt252) -> bool; -} - -impl DualCaseERC1155Impl of DualCaseERC1155Trait { - fn uri(self: @DualCaseERC1155, token_id: u256) -> ByteArray { - let mut args = array![]; - args.append_serde(token_id); - - call_contract_syscall(*self.contract_address, selectors::uri, args.span()).unwrap_and_cast() - } - - fn balance_of(self: @DualCaseERC1155, account: ContractAddress, token_id: u256) -> u256 { - let mut args = array![]; - args.append_serde(account); - args.append_serde(token_id); - - try_selector_with_fallback( - *self.contract_address, selectors::balance_of, selectors::balanceOf, args.span() - ) - .unwrap_and_cast() - } - - fn balance_of_batch( - self: @DualCaseERC1155, accounts: Span, token_ids: Span - ) -> Span { - let mut args = array![]; - args.append_serde(accounts); - args.append_serde(token_ids); - - try_selector_with_fallback( - *self.contract_address, - selectors::balance_of_batch, - selectors::balanceOfBatch, - args.span() - ) - .unwrap_and_cast() - } - - fn safe_transfer_from( - self: @DualCaseERC1155, - from: ContractAddress, - to: ContractAddress, - token_id: u256, - value: u256, - data: Span - ) { - let mut args = array![]; - args.append_serde(from); - args.append_serde(to); - args.append_serde(token_id); - args.append_serde(value); - args.append_serde(data); - - try_selector_with_fallback( - *self.contract_address, - selectors::safe_transfer_from, - selectors::safeTransferFrom, - args.span() - ) - .unwrap_syscall(); - } - - fn safe_batch_transfer_from( - self: @DualCaseERC1155, - from: ContractAddress, - to: ContractAddress, - token_ids: Span, - values: Span, - data: Span - ) { - let mut args = array![]; - args.append_serde(from); - args.append_serde(to); - args.append_serde(token_ids); - args.append_serde(values); - args.append_serde(data); - - try_selector_with_fallback( - *self.contract_address, - selectors::safe_batch_transfer_from, - selectors::safeBatchTransferFrom, - args.span() - ) - .unwrap_syscall(); - } - - fn is_approved_for_all( - self: @DualCaseERC1155, owner: ContractAddress, operator: ContractAddress - ) -> bool { - let mut args = array![]; - args.append_serde(owner); - args.append_serde(operator); - - try_selector_with_fallback( - *self.contract_address, - selectors::is_approved_for_all, - selectors::isApprovedForAll, - args.span() - ) - .unwrap_and_cast() - } - - fn set_approval_for_all(self: @DualCaseERC1155, operator: ContractAddress, approved: bool) { - let mut args = array![]; - args.append_serde(operator); - args.append_serde(approved); - - try_selector_with_fallback( - *self.contract_address, - selectors::set_approval_for_all, - selectors::setApprovalForAll, - args.span() - ) - .unwrap_syscall(); - } - - fn supports_interface(self: @DualCaseERC1155, interface_id: felt252) -> bool { - let mut args = array![]; - args.append_serde(interface_id); - - call_contract_syscall(*self.contract_address, selectors::supports_interface, args.span()) - .unwrap_and_cast() - } -} diff --git a/packages/token/src/erc1155/dual1155_receiver.cairo b/packages/token/src/erc1155/dual1155_receiver.cairo deleted file mode 100644 index d123224e5..000000000 --- a/packages/token/src/erc1155/dual1155_receiver.cairo +++ /dev/null @@ -1,83 +0,0 @@ -// SPDX-License-Identifier: MIT -// OpenZeppelin Contracts for Cairo v0.17.0 (token/erc1155/dual1155_receiver.cairo) - -use openzeppelin_utils::UnwrapAndCast; -use openzeppelin_utils::selectors; -use openzeppelin_utils::serde::SerializedAppend; -use openzeppelin_utils::try_selector_with_fallback; -use starknet::ContractAddress; - -#[derive(Copy, Drop)] -pub struct DualCaseERC1155Receiver { - pub contract_address: ContractAddress -} - -pub trait DualCaseERC1155ReceiverTrait { - fn on_erc1155_received( - self: @DualCaseERC1155Receiver, - operator: ContractAddress, - from: ContractAddress, - token_id: u256, - value: u256, - data: Span - ) -> felt252; - - fn on_erc1155_batch_received( - self: @DualCaseERC1155Receiver, - operator: ContractAddress, - from: ContractAddress, - token_ids: Span, - values: Span, - data: Span - ) -> felt252; -} - -impl DualCaseERC1155ReceiverImpl of DualCaseERC1155ReceiverTrait { - fn on_erc1155_received( - self: @DualCaseERC1155Receiver, - operator: ContractAddress, - from: ContractAddress, - token_id: u256, - value: u256, - data: Span - ) -> felt252 { - let mut args = array![]; - args.append_serde(operator); - args.append_serde(from); - args.append_serde(token_id); - args.append_serde(value); - args.append_serde(data); - - try_selector_with_fallback( - *self.contract_address, - selectors::on_erc1155_received, - selectors::onERC1155Received, - args.span() - ) - .unwrap_and_cast() - } - - fn on_erc1155_batch_received( - self: @DualCaseERC1155Receiver, - operator: ContractAddress, - from: ContractAddress, - token_ids: Span, - values: Span, - data: Span - ) -> felt252 { - let mut args = array![]; - args.append_serde(operator); - args.append_serde(from); - args.append_serde(token_ids); - args.append_serde(values); - args.append_serde(data); - - try_selector_with_fallback( - *self.contract_address, - selectors::on_erc1155_batch_received, - selectors::onERC1155BatchReceived, - args.span() - ) - .unwrap_and_cast() - } -} diff --git a/packages/token/src/erc1155/erc1155.cairo b/packages/token/src/erc1155/erc1155.cairo index 30128dd42..84dc32580 100644 --- a/packages/token/src/erc1155/erc1155.cairo +++ b/packages/token/src/erc1155/erc1155.cairo @@ -8,7 +8,7 @@ #[starknet::component] pub mod ERC1155Component { use core::num::traits::Zero; - use crate::erc1155::dual1155_receiver::{DualCaseERC1155Receiver, DualCaseERC1155ReceiverTrait}; + use crate::erc1155::interface::{IERC1155ReceiverDispatcher, IERC1155ReceiverDispatcherTrait}; use crate::erc1155::interface; use openzeppelin_account::interface::ISRC6_ID; use openzeppelin_introspection::interface::{ISRC5Dispatcher, ISRC5DispatcherTrait}; @@ -684,7 +684,7 @@ pub mod ERC1155Component { let src5_dispatcher = ISRC5Dispatcher { contract_address: to }; if src5_dispatcher.supports_interface(interface::IERC1155_RECEIVER_ID) { - DualCaseERC1155Receiver { contract_address: to } + IERC1155ReceiverDispatcher { contract_address: to } .on_erc1155_received( get_caller_address(), from, token_id, value, data ) == interface::IERC1155_RECEIVER_ID @@ -705,7 +705,7 @@ pub mod ERC1155Component { let src5_dispatcher = ISRC5Dispatcher { contract_address: to }; if src5_dispatcher.supports_interface(interface::IERC1155_RECEIVER_ID) { - DualCaseERC1155Receiver { contract_address: to } + IERC1155ReceiverDispatcher { contract_address: to } .on_erc1155_batch_received( get_caller_address(), from, token_ids, values, data ) == interface::IERC1155_RECEIVER_ID diff --git a/packages/token/src/erc20.cairo b/packages/token/src/erc20.cairo index e40fbb2bb..0a44a41dd 100644 --- a/packages/token/src/erc20.cairo +++ b/packages/token/src/erc20.cairo @@ -1,4 +1,3 @@ -pub mod dual20; pub mod erc20; pub mod extensions; pub mod interface; diff --git a/packages/token/src/erc20/dual20.cairo b/packages/token/src/erc20/dual20.cairo deleted file mode 100644 index 20cefb030..000000000 --- a/packages/token/src/erc20/dual20.cairo +++ /dev/null @@ -1,107 +0,0 @@ -// SPDX-License-Identifier: MIT -// OpenZeppelin Contracts for Cairo v0.17.0 (token/erc20/dual20.cairo) - -use openzeppelin_utils::UnwrapAndCast; -use openzeppelin_utils::selectors; -use openzeppelin_utils::serde::SerializedAppend; -use openzeppelin_utils::try_selector_with_fallback; -use starknet::ContractAddress; -use starknet::syscalls::call_contract_syscall; - -#[derive(Copy, Drop)] -pub struct DualCaseERC20 { - pub contract_address: ContractAddress -} - -pub trait DualCaseERC20Trait { - fn name(self: @DualCaseERC20) -> ByteArray; - fn symbol(self: @DualCaseERC20) -> ByteArray; - fn decimals(self: @DualCaseERC20) -> u8; - fn total_supply(self: @DualCaseERC20) -> u256; - fn balance_of(self: @DualCaseERC20, account: ContractAddress) -> u256; - fn allowance(self: @DualCaseERC20, owner: ContractAddress, spender: ContractAddress) -> u256; - fn transfer(self: @DualCaseERC20, recipient: ContractAddress, amount: u256) -> bool; - fn transfer_from( - self: @DualCaseERC20, sender: ContractAddress, recipient: ContractAddress, amount: u256 - ) -> bool; - fn approve(self: @DualCaseERC20, spender: ContractAddress, amount: u256) -> bool; -} - -impl DualCaseERC20Impl of DualCaseERC20Trait { - fn name(self: @DualCaseERC20) -> ByteArray { - let args = array![]; - call_contract_syscall(*self.contract_address, selectors::name, args.span()) - .unwrap_and_cast() - } - - fn symbol(self: @DualCaseERC20) -> ByteArray { - let args = array![]; - call_contract_syscall(*self.contract_address, selectors::symbol, args.span()) - .unwrap_and_cast() - } - - fn decimals(self: @DualCaseERC20) -> u8 { - let args = array![]; - call_contract_syscall(*self.contract_address, selectors::decimals, args.span()) - .unwrap_and_cast() - } - - fn total_supply(self: @DualCaseERC20) -> u256 { - let args = array![]; - try_selector_with_fallback( - *self.contract_address, selectors::total_supply, selectors::totalSupply, args.span() - ) - .unwrap_and_cast() - } - - fn balance_of(self: @DualCaseERC20, account: ContractAddress) -> u256 { - let mut args = array![]; - args.append_serde(account); - - try_selector_with_fallback( - *self.contract_address, selectors::balance_of, selectors::balanceOf, args.span() - ) - .unwrap_and_cast() - } - - fn allowance(self: @DualCaseERC20, owner: ContractAddress, spender: ContractAddress) -> u256 { - let mut args = array![]; - args.append_serde(owner); - args.append_serde(spender); - - call_contract_syscall(*self.contract_address, selectors::allowance, args.span()) - .unwrap_and_cast() - } - - fn transfer(self: @DualCaseERC20, recipient: ContractAddress, amount: u256) -> bool { - let mut args = array![]; - args.append_serde(recipient); - args.append_serde(amount); - - call_contract_syscall(*self.contract_address, selectors::transfer, args.span()) - .unwrap_and_cast() - } - - fn transfer_from( - self: @DualCaseERC20, sender: ContractAddress, recipient: ContractAddress, amount: u256 - ) -> bool { - let mut args = array![]; - args.append_serde(sender); - args.append_serde(recipient); - args.append_serde(amount); - - try_selector_with_fallback( - *self.contract_address, selectors::transfer_from, selectors::transferFrom, args.span() - ) - .unwrap_and_cast() - } - - fn approve(self: @DualCaseERC20, spender: ContractAddress, amount: u256) -> bool { - let mut args = array![]; - args.append_serde(spender); - args.append_serde(amount); - - call_contract_syscall(*self.contract_address, selectors::approve, args.span()) - .unwrap_and_cast() - } -} diff --git a/packages/token/src/erc20/extensions/erc20_votes.cairo b/packages/token/src/erc20/extensions/erc20_votes.cairo index a41e6b811..b1dfa1fcb 100644 --- a/packages/token/src/erc20/extensions/erc20_votes.cairo +++ b/packages/token/src/erc20/extensions/erc20_votes.cairo @@ -19,7 +19,7 @@ pub mod ERC20VotesComponent { use core::num::traits::Zero; use crate::erc20::ERC20Component; use crate::erc20::interface::IERC20; - use openzeppelin_account::dual_account::{DualCaseAccount, DualCaseAccountTrait}; + use openzeppelin_account::interface::{ISRC6Dispatcher, ISRC6DispatcherTrait}; use openzeppelin_governance::utils::interfaces::IVotes; use openzeppelin_utils::nonces::NoncesComponent::InternalTrait as NoncesInternalTrait; use openzeppelin_utils::nonces::NoncesComponent; @@ -162,7 +162,7 @@ pub mod ERC20VotesComponent { let delegation = Delegation { delegatee, nonce, expiry }; let hash = delegation.get_message_hash(delegator); - let is_valid_signature_felt = DualCaseAccount { contract_address: delegator } + let is_valid_signature_felt = ISRC6Dispatcher { contract_address: delegator } .is_valid_signature(hash, signature); // Check either 'VALID' or true for backwards compatibility. diff --git a/packages/token/src/erc721.cairo b/packages/token/src/erc721.cairo index 3a08d821a..59fa1d854 100644 --- a/packages/token/src/erc721.cairo +++ b/packages/token/src/erc721.cairo @@ -1,5 +1,3 @@ -pub mod dual721; -pub mod dual721_receiver; pub mod erc721; pub mod erc721_receiver; pub mod extensions; diff --git a/packages/token/src/erc721/dual721.cairo b/packages/token/src/erc721/dual721.cairo deleted file mode 100644 index 7932cd559..000000000 --- a/packages/token/src/erc721/dual721.cairo +++ /dev/null @@ -1,174 +0,0 @@ -// SPDX-License-Identifier: MIT -// OpenZeppelin Contracts for Cairo v0.17.0 (token/erc721/dual721.cairo) - -use openzeppelin_utils::UnwrapAndCast; -use openzeppelin_utils::selectors; -use openzeppelin_utils::serde::SerializedAppend; -use openzeppelin_utils::try_selector_with_fallback; -use starknet::ContractAddress; -use starknet::SyscallResultTrait; -use starknet::syscalls::call_contract_syscall; - -#[derive(Copy, Drop)] -pub struct DualCaseERC721 { - pub contract_address: ContractAddress -} - -pub trait DualCaseERC721Trait { - fn name(self: @DualCaseERC721) -> ByteArray; - fn symbol(self: @DualCaseERC721) -> ByteArray; - fn token_uri(self: @DualCaseERC721, token_id: u256) -> ByteArray; - fn balance_of(self: @DualCaseERC721, account: ContractAddress) -> u256; - fn owner_of(self: @DualCaseERC721, token_id: u256) -> ContractAddress; - fn get_approved(self: @DualCaseERC721, token_id: u256) -> ContractAddress; - fn approve(self: @DualCaseERC721, to: ContractAddress, token_id: u256); - fn set_approval_for_all(self: @DualCaseERC721, operator: ContractAddress, approved: bool); - fn transfer_from( - self: @DualCaseERC721, from: ContractAddress, to: ContractAddress, token_id: u256 - ); - fn is_approved_for_all( - self: @DualCaseERC721, owner: ContractAddress, operator: ContractAddress - ) -> bool; - fn safe_transfer_from( - self: @DualCaseERC721, - from: ContractAddress, - to: ContractAddress, - token_id: u256, - data: Span - ); - fn supports_interface(self: @DualCaseERC721, interface_id: felt252) -> bool; -} - -impl DualCaseERC721Impl of DualCaseERC721Trait { - fn name(self: @DualCaseERC721) -> ByteArray { - call_contract_syscall(*self.contract_address, selectors::name, array![].span()) - .unwrap_and_cast() - } - - fn symbol(self: @DualCaseERC721) -> ByteArray { - call_contract_syscall(*self.contract_address, selectors::symbol, array![].span()) - .unwrap_and_cast() - } - - fn token_uri(self: @DualCaseERC721, token_id: u256) -> ByteArray { - let mut args = array![]; - args.append_serde(token_id); - - try_selector_with_fallback( - *self.contract_address, selectors::token_uri, selectors::tokenURI, args.span() - ) - .unwrap_and_cast() - } - - fn balance_of(self: @DualCaseERC721, account: ContractAddress) -> u256 { - let mut args = array![]; - args.append_serde(account); - - try_selector_with_fallback( - *self.contract_address, selectors::balance_of, selectors::balanceOf, args.span() - ) - .unwrap_and_cast() - } - - fn owner_of(self: @DualCaseERC721, token_id: u256) -> ContractAddress { - let mut args = array![]; - args.append_serde(token_id); - - try_selector_with_fallback( - *self.contract_address, selectors::owner_of, selectors::ownerOf, args.span() - ) - .unwrap_and_cast() - } - - fn get_approved(self: @DualCaseERC721, token_id: u256) -> ContractAddress { - let mut args = array![]; - args.append_serde(token_id); - - try_selector_with_fallback( - *self.contract_address, selectors::get_approved, selectors::getApproved, args.span() - ) - .unwrap_and_cast() - } - - fn is_approved_for_all( - self: @DualCaseERC721, owner: ContractAddress, operator: ContractAddress - ) -> bool { - let mut args = array![]; - args.append_serde(owner); - args.append_serde(operator); - - try_selector_with_fallback( - *self.contract_address, - selectors::is_approved_for_all, - selectors::isApprovedForAll, - args.span() - ) - .unwrap_and_cast() - } - - fn approve(self: @DualCaseERC721, to: ContractAddress, token_id: u256) { - let mut args = array![]; - args.append_serde(to); - args.append_serde(token_id); - call_contract_syscall(*self.contract_address, selectors::approve, args.span()) - .unwrap_syscall(); - } - - fn set_approval_for_all(self: @DualCaseERC721, operator: ContractAddress, approved: bool) { - let mut args = array![]; - args.append_serde(operator); - args.append_serde(approved); - - try_selector_with_fallback( - *self.contract_address, - selectors::set_approval_for_all, - selectors::setApprovalForAll, - args.span() - ) - .unwrap_syscall(); - } - - fn transfer_from( - self: @DualCaseERC721, from: ContractAddress, to: ContractAddress, token_id: u256 - ) { - let mut args = array![]; - args.append_serde(from); - args.append_serde(to); - args.append_serde(token_id); - - try_selector_with_fallback( - *self.contract_address, selectors::transfer_from, selectors::transferFrom, args.span() - ) - .unwrap_syscall(); - } - - fn safe_transfer_from( - self: @DualCaseERC721, - from: ContractAddress, - to: ContractAddress, - token_id: u256, - mut data: Span - ) { - let mut args = array![]; - args.append_serde(from); - args.append_serde(to); - args.append_serde(token_id); - args.append_serde(data); - - try_selector_with_fallback( - *self.contract_address, - selectors::safe_transfer_from, - selectors::safeTransferFrom, - args.span() - ) - .unwrap_syscall(); - } - - fn supports_interface(self: @DualCaseERC721, interface_id: felt252) -> bool { - let mut args = array![]; - args.append_serde(interface_id); - - call_contract_syscall(*self.contract_address, selectors::supports_interface, args.span()) - .unwrap_and_cast() - } -} diff --git a/packages/token/src/erc721/dual721_receiver.cairo b/packages/token/src/erc721/dual721_receiver.cairo deleted file mode 100644 index 1e616c5b6..000000000 --- a/packages/token/src/erc721/dual721_receiver.cairo +++ /dev/null @@ -1,47 +0,0 @@ -// SPDX-License-Identifier: MIT -// OpenZeppelin Contracts for Cairo v0.17.0 (token/erc721/dual721_receiver.cairo) - -use openzeppelin_utils::UnwrapAndCast; -use openzeppelin_utils::selectors; -use openzeppelin_utils::serde::SerializedAppend; -use openzeppelin_utils::try_selector_with_fallback; -use starknet::ContractAddress; - -#[derive(Copy, Drop)] -pub struct DualCaseERC721Receiver { - pub contract_address: ContractAddress -} - -pub trait DualCaseERC721ReceiverTrait { - fn on_erc721_received( - self: @DualCaseERC721Receiver, - operator: ContractAddress, - from: ContractAddress, - token_id: u256, - data: Span - ) -> felt252; -} - -impl DualCaseERC721ReceiverImpl of DualCaseERC721ReceiverTrait { - fn on_erc721_received( - self: @DualCaseERC721Receiver, - operator: ContractAddress, - from: ContractAddress, - token_id: u256, - data: Span - ) -> felt252 { - let mut args = array![]; - args.append_serde(operator); - args.append_serde(from); - args.append_serde(token_id); - args.append_serde(data); - - try_selector_with_fallback( - *self.contract_address, - selectors::on_erc721_received, - selectors::onERC721Received, - args.span() - ) - .unwrap_and_cast() - } -} diff --git a/packages/token/src/erc721/erc721.cairo b/packages/token/src/erc721/erc721.cairo index d19a82cbd..a47874d9a 100644 --- a/packages/token/src/erc721/erc721.cairo +++ b/packages/token/src/erc721/erc721.cairo @@ -8,7 +8,7 @@ #[starknet::component] pub mod ERC721Component { use core::num::traits::Zero; - use crate::erc721::dual721_receiver::{DualCaseERC721Receiver, DualCaseERC721ReceiverTrait}; + use crate::erc721::interface::{IERC721ReceiverDispatcher, IERC721ReceiverDispatcherTrait}; use crate::erc721::interface; use openzeppelin_introspection::interface::{ISRC5Dispatcher, ISRC5DispatcherTrait}; use openzeppelin_introspection::src5::SRC5Component::InternalTrait as SRC5InternalTrait; @@ -813,7 +813,7 @@ pub mod ERC721Component { let src5_dispatcher = ISRC5Dispatcher { contract_address: to }; if src5_dispatcher.supports_interface(interface::IERC721_RECEIVER_ID) { - DualCaseERC721Receiver { contract_address: to } + IERC721ReceiverDispatcher { contract_address: to } .on_erc721_received( get_caller_address(), from, token_id, data ) == interface::IERC721_RECEIVER_ID diff --git a/packages/token/src/tests/erc1155.cairo b/packages/token/src/tests/erc1155.cairo index 799272ec1..e9bbde0ba 100644 --- a/packages/token/src/tests/erc1155.cairo +++ b/packages/token/src/tests/erc1155.cairo @@ -1,4 +1,2 @@ -mod test_dual1155; -mod test_dual1155_receiver; mod test_erc1155; mod test_erc1155_receiver; diff --git a/packages/token/src/tests/erc1155/test_dual1155.cairo b/packages/token/src/tests/erc1155/test_dual1155.cairo deleted file mode 100644 index cc15d9822..000000000 --- a/packages/token/src/tests/erc1155/test_dual1155.cairo +++ /dev/null @@ -1,412 +0,0 @@ -use core::num::traits::Zero; -use crate::erc1155::dual1155::{DualCaseERC1155, DualCaseERC1155Trait}; -use crate::erc1155::interface::IERC1155_ID; -use crate::erc1155::interface::{IERC1155CamelDispatcher, IERC1155CamelDispatcherTrait}; -use crate::erc1155::interface::{IERC1155Dispatcher, IERC1155DispatcherTrait}; -use openzeppelin_test_common::erc1155::{setup_account, setup_receiver}; -use openzeppelin_testing as utils; -use openzeppelin_testing::constants::{ - EMPTY_DATA, OWNER, RECIPIENT, OPERATOR, TOKEN_ID, TOKEN_ID_2, TOKEN_VALUE -}; -use openzeppelin_utils::serde::SerializedAppend; -use snforge_std::start_cheat_caller_address; -use starknet::ContractAddress; - -// -// Setup -// - -fn setup_snake() -> (DualCaseERC1155, IERC1155Dispatcher, ContractAddress) { - let base_uri: ByteArray = "URI"; - let owner = setup_account(); - let mut calldata = array![]; - calldata.append_serde(base_uri); - calldata.append_serde(owner); - calldata.append_serde(TOKEN_ID); - calldata.append_serde(TOKEN_VALUE); - let target = utils::declare_and_deploy("SnakeERC1155Mock", calldata); - ( - DualCaseERC1155 { contract_address: target }, - IERC1155Dispatcher { contract_address: target }, - owner - ) -} - -fn setup_camel() -> (DualCaseERC1155, IERC1155CamelDispatcher, ContractAddress) { - let base_uri: ByteArray = "URI"; - let owner = setup_account(); - let mut calldata = array![]; - calldata.append_serde(base_uri); - calldata.append_serde(owner); - calldata.append_serde(TOKEN_ID); - calldata.append_serde(TOKEN_VALUE); - let target = utils::declare_and_deploy("CamelERC1155Mock", calldata); - ( - DualCaseERC1155 { contract_address: target }, - IERC1155CamelDispatcher { contract_address: target }, - owner - ) -} - -fn setup_non_erc1155() -> DualCaseERC1155 { - let calldata = array![]; - let target = utils::declare_and_deploy("NonImplementingMock", calldata); - DualCaseERC1155 { contract_address: target } -} - -fn setup_erc1155_panic() -> (DualCaseERC1155, DualCaseERC1155) { - let snake_target = utils::declare_and_deploy("SnakeERC1155PanicMock", array![]); - let camel_target = utils::declare_and_deploy("CamelERC1155PanicMock", array![]); - ( - DualCaseERC1155 { contract_address: snake_target }, - DualCaseERC1155 { contract_address: camel_target } - ) -} - -// -// Case agnostic methods -// - -#[test] -fn test_dual_uri_snake() { - let (snake_dispatcher, _, _) = setup_snake(); - assert_eq!(snake_dispatcher.uri(TOKEN_ID), "URI"); -} - -#[test] -fn test_dual_uri_camel() { - let (camel_dispatcher, _, _) = setup_camel(); - assert_eq!(camel_dispatcher.uri(TOKEN_ID), "URI"); -} - -#[test] -#[ignore] // REASON: should_panic attribute not fit for complex panic messages. -#[should_panic(expected: ('ENTRYPOINT_NOT_FOUND',))] -fn test_dual_no_uri() { - let dispatcher = setup_non_erc1155(); - dispatcher.uri(TOKEN_ID); -} - -#[test] -#[should_panic(expected: "Some error")] -fn test_dual_uri_exists_and_panics() { - let (dispatcher, _) = setup_erc1155_panic(); - dispatcher.uri(TOKEN_ID); -} - -// -// snake_case target -// - -#[test] -fn test_dual_balance_of() { - let (dispatcher, _, owner) = setup_snake(); - assert_eq!(dispatcher.balance_of(owner, TOKEN_ID), TOKEN_VALUE); -} - -#[test] -#[ignore] // REASON: should_panic attribute not fit for complex panic messages. -#[should_panic(expected: ('ENTRYPOINT_NOT_FOUND',))] -fn test_dual_no_balance_of() { - let dispatcher = setup_non_erc1155(); - dispatcher.balance_of(OWNER(), TOKEN_ID); -} - -#[test] -#[should_panic(expected: "Some error")] -fn test_dual_balance_of_exists_and_panics() { - let (dispatcher, _) = setup_erc1155_panic(); - dispatcher.balance_of(OWNER(), TOKEN_ID); -} - -#[test] -fn test_dual_balance_of_batch() { - let (dispatcher, _, owner) = setup_snake(); - let accounts = array![owner, RECIPIENT()].span(); - let token_ids = array![TOKEN_ID, TOKEN_ID_2].span(); - - let balances = dispatcher.balance_of_batch(accounts, token_ids); - assert_eq!(*balances.at(0), TOKEN_VALUE); - assert!((*balances.at(1)).is_zero()); -} - -#[test] -#[ignore] // REASON: should_panic attribute not fit for complex panic messages. -#[should_panic(expected: ('ENTRYPOINT_NOT_FOUND',))] -fn test_dual_no_balance_of_batch() { - let dispatcher = setup_non_erc1155(); - let (accounts, token_ids) = get_accounts_and_ids(); - dispatcher.balance_of_batch(accounts, token_ids); -} - -#[test] -#[should_panic(expected: "Some error")] -fn test_dual_balance_of_batch_exists_and_panics() { - let (dispatcher, _) = setup_erc1155_panic(); - let (accounts, token_ids) = get_accounts_and_ids(); - dispatcher.balance_of_batch(accounts, token_ids); -} - -#[test] -fn test_dual_safe_transfer_from() { - let (dispatcher, target, owner) = setup_snake(); - let receiver = setup_receiver(); - - start_cheat_caller_address(dispatcher.contract_address, owner); - dispatcher.safe_transfer_from(owner, receiver, TOKEN_ID, TOKEN_VALUE, EMPTY_DATA()); - assert_eq!(target.balance_of(receiver, TOKEN_ID), TOKEN_VALUE); -} - -#[test] -#[ignore] // REASON: should_panic attribute not fit for complex panic messages. -#[should_panic(expected: ('ENTRYPOINT_NOT_FOUND',))] -fn test_dual_no_safe_transfer_from() { - let dispatcher = setup_non_erc1155(); - dispatcher.safe_transfer_from(OWNER(), RECIPIENT(), TOKEN_ID, TOKEN_VALUE, EMPTY_DATA()); -} - -#[test] -#[should_panic(expected: "Some error")] -fn test_dual_safe_transfer_from_exists_and_panics() { - let (dispatcher, _) = setup_erc1155_panic(); - dispatcher.safe_transfer_from(OWNER(), RECIPIENT(), TOKEN_ID, TOKEN_VALUE, EMPTY_DATA()); -} - -#[test] -fn test_dual_safe_batch_transfer_from() { - let (dispatcher, target, owner) = setup_snake(); - let token_ids = array![TOKEN_ID, TOKEN_ID_2].span(); - let values = array![TOKEN_VALUE, 0].span(); - let receiver = setup_receiver(); - - start_cheat_caller_address(dispatcher.contract_address, owner); - dispatcher.safe_batch_transfer_from(owner, receiver, token_ids, values, EMPTY_DATA()); - assert_eq!(target.balance_of(receiver, TOKEN_ID), TOKEN_VALUE); - assert!(target.balance_of(receiver, TOKEN_ID_2).is_zero()); -} - -#[test] -#[ignore] // REASON: should_panic attribute not fit for complex panic messages. -#[should_panic(expected: ('ENTRYPOINT_NOT_FOUND',))] -fn test_dual_no_safe_batch_transfer_from() { - let dispatcher = setup_non_erc1155(); - let token_ids = array![TOKEN_ID, TOKEN_ID_2].span(); - let values = array![TOKEN_VALUE, 0].span(); - dispatcher.safe_batch_transfer_from(OWNER(), RECIPIENT(), token_ids, values, EMPTY_DATA()); -} - -#[test] -#[should_panic(expected: "Some error")] -fn test_dual_safe_batch_transfer_from_exists_and_panics() { - let (dispatcher, _) = setup_erc1155_panic(); - let token_ids = array![TOKEN_ID, TOKEN_ID_2].span(); - let values = array![TOKEN_VALUE, 0].span(); - dispatcher.safe_batch_transfer_from(OWNER(), RECIPIENT(), token_ids, values, EMPTY_DATA()); -} - -#[test] -fn test_dual_is_approved_for_all() { - let (dispatcher, target, _) = setup_snake(); - - start_cheat_caller_address(dispatcher.contract_address, OWNER()); - target.set_approval_for_all(OPERATOR(), true); - - let is_approved_for_all = dispatcher.is_approved_for_all(OWNER(), OPERATOR()); - assert!(is_approved_for_all); -} - -#[test] -#[ignore] // REASON: should_panic attribute not fit for complex panic messages. -#[should_panic(expected: ('ENTRYPOINT_NOT_FOUND',))] -fn test_dual_no_is_approved_for_all() { - let dispatcher = setup_non_erc1155(); - dispatcher.is_approved_for_all(OWNER(), OPERATOR()); -} - -#[test] -#[should_panic(expected: "Some error")] -fn test_dual_is_approved_for_all_exists_and_panics() { - let (dispatcher, _) = setup_erc1155_panic(); - dispatcher.is_approved_for_all(OWNER(), OPERATOR()); -} - -#[test] -fn test_dual_set_approval_for_all() { - let (dispatcher, target, _) = setup_snake(); - - start_cheat_caller_address(dispatcher.contract_address, OWNER()); - dispatcher.set_approval_for_all(OPERATOR(), true); - - let is_approved_for_all = target.is_approved_for_all(OWNER(), OPERATOR()); - assert!(is_approved_for_all); -} - -#[test] -#[ignore] // REASON: should_panic attribute not fit for complex panic messages. -#[should_panic(expected: ('ENTRYPOINT_NOT_FOUND',))] -fn test_dual_no_set_approval_for_all() { - let dispatcher = setup_non_erc1155(); - dispatcher.set_approval_for_all(OPERATOR(), true); -} - -#[test] -#[should_panic(expected: "Some error")] -fn test_dual_set_approval_for_all_exists_and_panics() { - let (dispatcher, _) = setup_erc1155_panic(); - dispatcher.set_approval_for_all(OPERATOR(), true); -} - -#[test] -fn test_dual_supports_interface() { - let (dispatcher, _, _) = setup_snake(); - let supports_ierc1155 = dispatcher.supports_interface(IERC1155_ID); - assert!(supports_ierc1155); -} - -#[test] -#[ignore] // REASON: should_panic attribute not fit for complex panic messages. -#[should_panic(expected: ('ENTRYPOINT_NOT_FOUND',))] -fn test_dual_no_supports_interface() { - let dispatcher = setup_non_erc1155(); - dispatcher.supports_interface(IERC1155_ID); -} - -#[test] -#[should_panic(expected: "Some error")] -fn test_dual_supports_interface_exists_and_panics() { - let (dispatcher, _) = setup_erc1155_panic(); - dispatcher.supports_interface(IERC1155_ID); -} - -// -// camelCase target -// - -#[test] -#[ignore] // REASON: foundry entrypoint_not_found error message inconsistent with mainnet. -fn test_dual_balanceOf() { - let (dispatcher, _, owner) = setup_camel(); - assert_eq!(dispatcher.balance_of(owner, TOKEN_ID), TOKEN_VALUE); -} - -#[test] -#[ignore] // REASON: foundry entrypoint_not_found error message inconsistent with mainnet. -#[should_panic(expected: "Some error")] -fn test_dual_balanceOf_exists_and_panics() { - let (_, dispatcher) = setup_erc1155_panic(); - dispatcher.balance_of(OWNER(), TOKEN_ID); -} - -#[test] -#[ignore] // REASON: foundry entrypoint_not_found error message inconsistent with mainnet. -fn test_dual_balanceOfBatch() { - let (dispatcher, _, owner) = setup_camel(); - let accounts = array![owner, RECIPIENT()].span(); - let token_ids = array![TOKEN_ID, TOKEN_ID_2].span(); - - let balances = dispatcher.balance_of_batch(accounts, token_ids); - assert_eq!(*balances.at(0), TOKEN_VALUE); - assert!((*balances.at(1)).is_zero()); -} - -#[test] -#[ignore] // REASON: foundry entrypoint_not_found error message inconsistent with mainnet. -#[should_panic(expected: "Some error")] -fn test_dual_balanceOfBatch_exists_and_panics() { - let (_, dispatcher) = setup_erc1155_panic(); - let (accounts, token_ids) = get_accounts_and_ids(); - dispatcher.balance_of_batch(accounts, token_ids); -} - -#[test] -#[ignore] // REASON: foundry entrypoint_not_found error message inconsistent with mainnet. -fn test_dual_safeTransferFrom() { - let (dispatcher, target, owner) = setup_camel(); - let receiver = setup_receiver(); - - start_cheat_caller_address(dispatcher.contract_address, owner); - dispatcher.safe_transfer_from(owner, receiver, TOKEN_ID, TOKEN_VALUE, EMPTY_DATA()); - assert_eq!(target.balanceOf(receiver, TOKEN_ID), TOKEN_VALUE); -} - -#[test] -#[ignore] // REASON: foundry entrypoint_not_found error message inconsistent with mainnet. -#[should_panic(expected: "Some error")] -fn test_dual_safeTransferFrom_exists_and_panics() { - let (_, dispatcher) = setup_erc1155_panic(); - dispatcher.safe_transfer_from(OWNER(), RECIPIENT(), TOKEN_ID, TOKEN_VALUE, EMPTY_DATA()); -} - -#[test] -#[ignore] // REASON: foundry entrypoint_not_found error message inconsistent with mainnet. -fn test_dual_safeBatchTransferFrom() { - let (dispatcher, target, owner) = setup_camel(); - let token_ids = array![TOKEN_ID, TOKEN_ID_2].span(); - let values = array![TOKEN_VALUE, 0].span(); - let receiver = setup_receiver(); - - start_cheat_caller_address(dispatcher.contract_address, owner); - dispatcher.safe_batch_transfer_from(owner, receiver, token_ids, values, EMPTY_DATA()); - assert_eq!(target.balanceOf(receiver, TOKEN_ID), TOKEN_VALUE); - assert!(target.balanceOf(receiver, TOKEN_ID_2).is_zero()); -} - -#[test] -#[ignore] // REASON: foundry entrypoint_not_found error message inconsistent with mainnet. -#[should_panic(expected: "Some error")] -fn test_dual_safeBatchTransferFrom_exists_and_panics() { - let (_, dispatcher) = setup_erc1155_panic(); - let token_ids = array![TOKEN_ID, TOKEN_ID_2].span(); - let values = array![TOKEN_VALUE, 0].span(); - dispatcher.safe_batch_transfer_from(OWNER(), RECIPIENT(), token_ids, values, EMPTY_DATA()); -} - -#[test] -#[ignore] // REASON: foundry entrypoint_not_found error message inconsistent with mainnet. -fn test_dual_isApprovedForAll() { - let (dispatcher, target, _) = setup_camel(); - - start_cheat_caller_address(dispatcher.contract_address, OWNER()); - target.setApprovalForAll(OPERATOR(), true); - - let is_approved_for_all = dispatcher.is_approved_for_all(OWNER(), OPERATOR()); - assert!(is_approved_for_all); -} - -#[test] -#[ignore] // REASON: foundry entrypoint_not_found error message inconsistent with mainnet. -#[should_panic(expected: "Some error")] -fn test_dual_isApprovedForAll_exists_and_panics() { - let (_, dispatcher) = setup_erc1155_panic(); - dispatcher.is_approved_for_all(OWNER(), OPERATOR()); -} - -#[test] -#[ignore] // REASON: foundry entrypoint_not_found error message inconsistent with mainnet. -fn test_dual_setApprovalForAll() { - let (dispatcher, target, _) = setup_camel(); - - start_cheat_caller_address(dispatcher.contract_address, OWNER()); - dispatcher.set_approval_for_all(OPERATOR(), true); - - let is_approved_for_all = target.isApprovedForAll(OWNER(), OPERATOR()); - assert!(is_approved_for_all); -} - -#[test] -#[ignore] // REASON: foundry entrypoint_not_found error message inconsistent with mainnet. -#[should_panic(expected: "Some error")] -fn test_dual_setApprovalForAll_exists_and_panics() { - let (_, dispatcher) = setup_erc1155_panic(); - dispatcher.set_approval_for_all(OPERATOR(), true); -} - -// -// Helpers -// - -fn get_accounts_and_ids() -> (Span, Span) { - let accounts = array![OWNER(), RECIPIENT()].span(); - let ids = array![TOKEN_ID, TOKEN_ID_2].span(); - (accounts, ids) -} diff --git a/packages/token/src/tests/erc1155/test_dual1155_receiver.cairo b/packages/token/src/tests/erc1155/test_dual1155_receiver.cairo deleted file mode 100644 index dc6c56108..000000000 --- a/packages/token/src/tests/erc1155/test_dual1155_receiver.cairo +++ /dev/null @@ -1,148 +0,0 @@ -use crate::erc1155::dual1155_receiver::{DualCaseERC1155Receiver, DualCaseERC1155ReceiverTrait}; -use crate::erc1155::interface::IERC1155_RECEIVER_ID; -use crate::erc1155::interface::{IERC1155ReceiverCamelDispatcher}; -use crate::erc1155::interface::{IERC1155ReceiverDispatcher}; -use openzeppelin_testing as utils; -use openzeppelin_testing::constants::{EMPTY_DATA, OPERATOR, OWNER, TOKEN_ID, TOKEN_VALUE}; - -// -// Setup -// - -fn setup_snake() -> (DualCaseERC1155Receiver, IERC1155ReceiverDispatcher) { - let mut calldata = array![]; - let target = utils::declare_and_deploy("SnakeERC1155ReceiverMock", calldata); - ( - DualCaseERC1155Receiver { contract_address: target }, - IERC1155ReceiverDispatcher { contract_address: target } - ) -} - -fn setup_camel() -> (DualCaseERC1155Receiver, IERC1155ReceiverCamelDispatcher) { - let mut calldata = array![]; - let target = utils::declare_and_deploy("CamelERC1155ReceiverMock", calldata); - ( - DualCaseERC1155Receiver { contract_address: target }, - IERC1155ReceiverCamelDispatcher { contract_address: target } - ) -} - -fn setup_non_erc1155_receiver() -> DualCaseERC1155Receiver { - let calldata = array![]; - let target = utils::declare_and_deploy("NonImplementingMock", calldata); - DualCaseERC1155Receiver { contract_address: target } -} - -fn setup_erc1155_receiver_panic() -> (DualCaseERC1155Receiver, DualCaseERC1155Receiver) { - let snake_target = utils::declare_and_deploy("SnakeERC1155ReceiverPanicMock", array![]); - let camel_target = utils::declare_and_deploy("CamelERC1155ReceiverPanicMock", array![]); - ( - DualCaseERC1155Receiver { contract_address: snake_target }, - DualCaseERC1155Receiver { contract_address: camel_target } - ) -} - -// -// snake_case target -// - -#[test] -fn test_dual_on_erc1155_received() { - let (dispatcher, _) = setup_snake(); - let result = dispatcher - .on_erc1155_received(OPERATOR(), OWNER(), TOKEN_ID, TOKEN_VALUE, EMPTY_DATA()); - assert_eq!(result, IERC1155_RECEIVER_ID,); -} - -#[test] -#[ignore] // REASON: should_panic attribute not fit for complex panic messages. -#[should_panic(expected: ('ENTRYPOINT_NOT_FOUND',))] -fn test_dual_no_on_erc1155_received() { - let dispatcher = setup_non_erc1155_receiver(); - dispatcher.on_erc1155_received(OPERATOR(), OWNER(), TOKEN_ID, TOKEN_VALUE, EMPTY_DATA()); -} - -#[test] -#[should_panic(expected: "Some error")] -fn test_dual_on_erc1155_received_exists_and_panics() { - let (dispatcher, _) = setup_erc1155_receiver_panic(); - dispatcher.on_erc1155_received(OPERATOR(), OWNER(), TOKEN_ID, TOKEN_VALUE, EMPTY_DATA()); -} - -#[test] -fn test_dual_on_erc1155_batch_received() { - let (dispatcher, _) = setup_snake(); - let (token_ids, values) = get_ids_and_values(); - - let result = dispatcher - .on_erc1155_batch_received(OPERATOR(), OWNER(), token_ids, values, EMPTY_DATA()); - assert_eq!(result, IERC1155_RECEIVER_ID); -} - -#[test] -#[ignore] // REASON: should_panic attribute not fit for complex panic messages. -#[should_panic(expected: ('ENTRYPOINT_NOT_FOUND',))] -fn test_dual_no_on_erc1155_batch_received() { - let dispatcher = setup_non_erc1155_receiver(); - let (token_ids, values) = get_ids_and_values(); - dispatcher.on_erc1155_batch_received(OPERATOR(), OWNER(), token_ids, values, EMPTY_DATA()); -} - -#[test] -#[should_panic(expected: "Some error")] -fn test_dual_on_erc1155_batch_received_exists_and_panics() { - let (dispatcher, _) = setup_erc1155_receiver_panic(); - let (token_ids, values) = get_ids_and_values(); - dispatcher.on_erc1155_batch_received(OPERATOR(), OWNER(), token_ids, values, EMPTY_DATA()); -} - -// -// camelCase target -// - -#[test] -#[ignore] // REASON: foundry entrypoint_not_found error message inconsistent with mainnet. -fn test_dual_onERC1155Received() { - let (dispatcher, _) = setup_camel(); - let result = dispatcher - .on_erc1155_received(OPERATOR(), OWNER(), TOKEN_ID, TOKEN_VALUE, EMPTY_DATA()); - assert_eq!(result, IERC1155_RECEIVER_ID); -} - -#[test] -#[ignore] // REASON: foundry entrypoint_not_found error message inconsistent with mainnet. -#[should_panic(expected: "Some error")] -fn test_dual_onERC1155Received_exists_and_panics() { - let (_, dispatcher) = setup_erc1155_receiver_panic(); - dispatcher.on_erc1155_received(OPERATOR(), OWNER(), TOKEN_ID, TOKEN_VALUE, EMPTY_DATA()); -} - -#[test] -#[ignore] // REASON: foundry entrypoint_not_found error message inconsistent with mainnet. -fn test_dual_onERC1155BatchReceived() { - let (dispatcher, _) = setup_camel(); - let (token_ids, values) = get_ids_and_values(); - - let result = dispatcher - .on_erc1155_batch_received(OPERATOR(), OWNER(), token_ids, values, EMPTY_DATA()); - assert_eq!(result, IERC1155_RECEIVER_ID); -} - -#[test] -#[ignore] // REASON: foundry entrypoint_not_found error message inconsistent with mainnet. -#[should_panic(expected: "Some error")] -fn test_dual_onERC1155BatchReceived_exists_and_panics() { - let (_, dispatcher) = setup_erc1155_receiver_panic(); - let (token_ids, values) = get_ids_and_values(); - dispatcher.on_erc1155_batch_received(OPERATOR(), OWNER(), token_ids, values, EMPTY_DATA()); -} - -// -// Helpers -// - -fn get_ids_and_values() -> (Span, Span) { - let token_ids = array![TOKEN_ID, TOKEN_ID].span(); - let values = array![TOKEN_VALUE, TOKEN_VALUE].span(); - (token_ids, values) -} diff --git a/packages/token/src/tests/erc1155/test_erc1155.cairo b/packages/token/src/tests/erc1155/test_erc1155.cairo index 750fdcefd..ffdc620d3 100644 --- a/packages/token/src/tests/erc1155/test_erc1155.cairo +++ b/packages/token/src/tests/erc1155/test_erc1155.cairo @@ -9,7 +9,7 @@ use openzeppelin_test_common::erc1155::{ ERC1155SpyHelpers, get_ids_and_values, get_ids_and_split_values }; use openzeppelin_test_common::erc1155::{ - setup_account, deploy_another_account_at, setup_src5, setup_receiver, setup_camel_receiver + setup_account, deploy_another_account_at, setup_src5, setup_receiver }; use openzeppelin_testing::constants::{ EMPTY_DATA, ZERO, OWNER, RECIPIENT, OPERATOR, OTHER, TOKEN_ID, TOKEN_ID_2, TOKEN_VALUE, @@ -158,26 +158,6 @@ fn test_safe_transfer_from_owner_to_receiver() { assert_state_after_transfer_single(owner, recipient, TOKEN_ID); } -#[test] -#[ignore] // REASON: foundry entrypoint_not_found error message inconsistent with mainnet. -fn test_safe_transfer_from_owner_to_camel_receiver() { - let (mut state, owner) = setup(); - let recipient = setup_camel_receiver(); - let mut spy = spy_events(); - let contract_address = test_address(); - - start_cheat_caller_address(contract_address, owner); - - assert_state_before_transfer_single(owner, recipient, TOKEN_ID); - state.safe_transfer_from(owner, recipient, TOKEN_ID, TOKEN_VALUE, EMPTY_DATA()); - spy - .assert_only_event_transfer_single( - contract_address, owner, owner, recipient, TOKEN_ID, TOKEN_VALUE - ); - - assert_state_after_transfer_single(owner, recipient, TOKEN_ID); -} - #[test] fn test_safeTransferFrom_owner_to_receiver() { let (mut state, owner) = setup(); @@ -197,26 +177,6 @@ fn test_safeTransferFrom_owner_to_receiver() { assert_state_after_transfer_single(owner, recipient, TOKEN_ID); } -#[test] -#[ignore] // REASON: foundry entrypoint_not_found error message inconsistent with mainnet. -fn test_safeTransferFrom_owner_to_camel_receiver() { - let (mut state, owner) = setup(); - let recipient = setup_camel_receiver(); - let mut spy = spy_events(); - let contract_address = test_address(); - - start_cheat_caller_address(contract_address, owner); - - assert_state_before_transfer_single(owner, recipient, TOKEN_ID); - state.safeTransferFrom(owner, recipient, TOKEN_ID, TOKEN_VALUE, EMPTY_DATA()); - spy - .assert_only_event_transfer_single( - contract_address, owner, owner, recipient, TOKEN_ID, TOKEN_VALUE - ); - - assert_state_after_transfer_single(owner, recipient, TOKEN_ID); -} - #[test] fn test_safe_transfer_from_owner_to_account() { let (mut state, owner) = setup(); @@ -423,27 +383,6 @@ fn test_safe_batch_transfer_from_owner_to_receiver() { assert_state_after_transfer_batch(owner, recipient, token_ids, values); } -#[test] -#[ignore] // REASON: foundry entrypoint_not_found error message inconsistent with mainnet. -fn test_safe_batch_transfer_from_owner_to_camel_receiver() { - let (mut state, owner) = setup(); - let recipient = setup_camel_receiver(); - let (token_ids, values) = get_ids_and_values(); - let mut spy = spy_events(); - let contract_address = test_address(); - - start_cheat_caller_address(contract_address, owner); - - assert_state_before_transfer_batch(owner, recipient, token_ids, values); - state.safe_batch_transfer_from(owner, recipient, token_ids, values, EMPTY_DATA()); - spy - .assert_only_event_transfer_batch( - contract_address, owner, owner, recipient, token_ids, values - ); - - assert_state_after_transfer_batch(owner, recipient, token_ids, values); -} - #[test] fn test_safeBatchTransferFrom_owner_to_receiver() { let (mut state, owner) = setup(); @@ -464,27 +403,6 @@ fn test_safeBatchTransferFrom_owner_to_receiver() { assert_state_after_transfer_batch(owner, recipient, token_ids, values); } -#[test] -#[ignore] // REASON: foundry entrypoint_not_found error message inconsistent with mainnet. -fn test_safeBatchTransferFrom_owner_to_camel_receiver() { - let (mut state, owner) = setup(); - let recipient = setup_camel_receiver(); - let (token_ids, values) = get_ids_and_values(); - let mut spy = spy_events(); - let contract_address = test_address(); - - start_cheat_caller_address(contract_address, owner); - - assert_state_before_transfer_batch(owner, recipient, token_ids, values); - state.safeBatchTransferFrom(owner, recipient, token_ids, values, EMPTY_DATA()); - spy - .assert_only_event_transfer_batch( - contract_address, owner, owner, recipient, token_ids, values - ); - - assert_state_after_transfer_batch(owner, recipient, token_ids, values); -} - #[test] fn test_safe_batch_transfer_from_owner_to_account() { let (mut state, owner) = setup(); @@ -919,28 +837,6 @@ fn test_update_wac_single_from_non_zero_to_non_zero() { assert_state_after_transfer_single(owner, recipient, TOKEN_ID); } -#[test] -#[ignore] // REASON: foundry entrypoint_not_found error message inconsistent with mainnet. -fn test_update_wac_single_from_non_zero_to_non_zero_camel_receiver() { - let (mut state, owner) = setup(); - let recipient = setup_camel_receiver(); - let token_ids = array![TOKEN_ID].span(); - let values = array![TOKEN_VALUE].span(); - let mut spy = spy_events(); - let contract_address = test_address(); - - start_cheat_caller_address(contract_address, owner); - - assert_state_before_transfer_single(owner, recipient, TOKEN_ID); - state.update_with_acceptance_check(owner, recipient, token_ids, values, EMPTY_DATA()); - spy - .assert_only_event_transfer_single( - contract_address, owner, owner, recipient, TOKEN_ID, TOKEN_VALUE - ); - - assert_state_after_transfer_single(owner, recipient, TOKEN_ID); -} - #[test] fn test_update_wac_single_from_non_zero_to_non_zero_account() { let (mut state, owner) = setup(); @@ -983,27 +879,6 @@ fn test_update_wac_batch_from_non_zero_to_non_zero() { assert_state_after_transfer_batch(owner, recipient, token_ids, values); } -#[test] -#[ignore] // REASON: foundry entrypoint_not_found error message inconsistent with mainnet. -fn test_update_wac_batch_from_non_zero_to_non_zero_camel_receiver() { - let (mut state, owner) = setup(); - let recipient = setup_camel_receiver(); - let (token_ids, values) = get_ids_and_values(); - let mut spy = spy_events(); - let contract_address = test_address(); - - start_cheat_caller_address(contract_address, owner); - - assert_state_before_transfer_batch(owner, recipient, token_ids, values); - state.update_with_acceptance_check(owner, recipient, token_ids, values, EMPTY_DATA()); - spy - .assert_only_event_transfer_batch( - contract_address, owner, owner, recipient, token_ids, values - ); - - assert_state_after_transfer_batch(owner, recipient, token_ids, values); -} - #[test] fn test_update_wac_batch_from_non_zero_to_non_zero_account() { let (mut state, owner) = setup(); @@ -1057,28 +932,6 @@ fn test_update_wac_from_zero_to_non_zero() { assert_state_after_transfer_from_zero_batch(sender, recipient, token_ids, values); } -#[test] -#[ignore] // REASON: foundry entrypoint_not_found error message inconsistent with mainnet. -fn test_update_wac_from_zero_to_non_zero_camel_receiver() { - let (mut state, owner) = setup(); - let recipient = setup_camel_receiver(); - let sender = ZERO(); - let (token_ids, values) = get_ids_and_values(); - let mut spy = spy_events(); - let contract_address = test_address(); - - start_cheat_caller_address(contract_address, owner); - - assert_state_before_transfer_from_zero_batch(sender, recipient, token_ids); - state.update_with_acceptance_check(sender, recipient, token_ids, values, EMPTY_DATA()); - spy - .assert_only_event_transfer_batch( - contract_address, owner, sender, recipient, token_ids, values - ); - - assert_state_after_transfer_from_zero_batch(sender, recipient, token_ids, values); -} - #[test] fn test_update_wac_from_zero_to_non_zero_account() { let (mut state, owner) = setup(); diff --git a/packages/token/src/tests/erc20.cairo b/packages/token/src/tests/erc20.cairo index 213861a92..4e62efeae 100644 --- a/packages/token/src/tests/erc20.cairo +++ b/packages/token/src/tests/erc20.cairo @@ -1,3 +1,2 @@ -mod test_dual20; mod test_erc20; mod test_erc20_votes; diff --git a/packages/token/src/tests/erc20/test_dual20.cairo b/packages/token/src/tests/erc20/test_dual20.cairo deleted file mode 100644 index d1b926deb..000000000 --- a/packages/token/src/tests/erc20/test_dual20.cairo +++ /dev/null @@ -1,309 +0,0 @@ -use crate::erc20::dual20::{DualCaseERC20, DualCaseERC20Trait}; -use crate::erc20::interface::{IERC20CamelDispatcher, IERC20CamelDispatcherTrait}; -use crate::erc20::interface::{IERC20Dispatcher, IERC20DispatcherTrait}; -use openzeppelin_testing as utils; -use openzeppelin_testing::constants::{ - OWNER, RECIPIENT, SPENDER, OPERATOR, NAME, SYMBOL, DECIMALS, SUPPLY, VALUE -}; -use openzeppelin_utils::serde::SerializedAppend; -use snforge_std::{test_address, start_cheat_caller_address}; - -// -// Setup -// - -fn setup_snake() -> (DualCaseERC20, IERC20Dispatcher) { - let mut calldata = array![]; - calldata.append_serde(NAME()); - calldata.append_serde(SYMBOL()); - calldata.append_serde(SUPPLY); - calldata.append_serde(OWNER()); - let target = utils::declare_and_deploy("SnakeERC20Mock", calldata); - (DualCaseERC20 { contract_address: target }, IERC20Dispatcher { contract_address: target }) -} - -fn setup_camel() -> (DualCaseERC20, IERC20CamelDispatcher) { - let mut calldata = array![]; - calldata.append_serde(NAME()); - calldata.append_serde(SYMBOL()); - calldata.append_serde(SUPPLY); - calldata.append_serde(OWNER()); - let target = utils::declare_and_deploy("CamelERC20Mock", calldata); - (DualCaseERC20 { contract_address: target }, IERC20CamelDispatcher { contract_address: target }) -} - -fn setup_non_erc20() -> DualCaseERC20 { - let calldata = array![]; - let target = utils::declare_and_deploy("NonImplementingMock", calldata); - DualCaseERC20 { contract_address: target } -} - -fn setup_erc20_panic() -> (DualCaseERC20, DualCaseERC20) { - let snake_target = utils::declare_and_deploy("SnakeERC20Panic", array![]); - let camel_target = utils::declare_and_deploy("CamelERC20Panic", array![]); - ( - DualCaseERC20 { contract_address: snake_target }, - DualCaseERC20 { contract_address: camel_target } - ) -} - -// -// Case agnostic methods -// - -#[test] -fn test_dual_name() { - let (snake_dispatcher, _) = setup_snake(); - assert_eq!(snake_dispatcher.name(), NAME()); - - let (camel_dispatcher, _) = setup_camel(); - assert_eq!(camel_dispatcher.name(), NAME()); -} - -#[test] -#[ignore] // REASON: should_panic attribute not fit for complex panic messages. -#[should_panic(expected: ('ENTRYPOINT_NOT_FOUND',))] -fn test_dual_no_name() { - let dispatcher = setup_non_erc20(); - dispatcher.name(); -} - -#[test] -#[should_panic(expected: "Some error")] -fn test_dual_name_exists_and_panics() { - let (dispatcher, _) = setup_erc20_panic(); - dispatcher.name(); -} - -#[test] -fn test_dual_symbol() { - let (snake_dispatcher, _) = setup_snake(); - let (camel_dispatcher, _) = setup_camel(); - assert_eq!(snake_dispatcher.symbol(), SYMBOL()); - assert_eq!(camel_dispatcher.symbol(), SYMBOL()); -} - -#[test] -#[ignore] // REASON: should_panic attribute not fit for complex panic messages. -#[should_panic(expected: ('ENTRYPOINT_NOT_FOUND',))] -fn test_dual_no_symbol() { - let dispatcher = setup_non_erc20(); - dispatcher.symbol(); -} - -#[test] -#[should_panic(expected: "Some error")] -fn test_dual_symbol_exists_and_panics() { - let (dispatcher, _) = setup_erc20_panic(); - dispatcher.symbol(); -} - -#[test] -fn test_dual_decimals() { - let (snake_dispatcher, _) = setup_snake(); - let (camel_dispatcher, _) = setup_camel(); - assert_eq!(snake_dispatcher.decimals(), DECIMALS); - assert_eq!(camel_dispatcher.decimals(), DECIMALS); -} - -#[test] -#[ignore] // REASON: should_panic attribute not fit for complex panic messages. -#[should_panic(expected: ('ENTRYPOINT_NOT_FOUND',))] -fn test_dual_no_decimals() { - let dispatcher = setup_non_erc20(); - dispatcher.decimals(); -} - -#[test] -#[should_panic(expected: "Some error")] -fn test_dual_decimals_exists_and_panics() { - let (dispatcher, _) = setup_erc20_panic(); - dispatcher.decimals(); -} - -#[test] -fn test_dual_transfer() { - let (snake_dispatcher, snake_target) = setup_snake(); - - start_cheat_caller_address(snake_dispatcher.contract_address, OWNER()); - assert!(snake_dispatcher.transfer(RECIPIENT(), VALUE)); - assert_eq!(snake_target.balance_of(RECIPIENT()), VALUE); - - let (camel_dispatcher, camel_target) = setup_camel(); - start_cheat_caller_address(camel_dispatcher.contract_address, OWNER()); - assert!(camel_dispatcher.transfer(RECIPIENT(), VALUE)); - assert_eq!(camel_target.balanceOf(RECIPIENT()), VALUE); -} - -#[test] -#[ignore] // REASON: should_panic attribute not fit for complex panic messages. -#[should_panic(expected: ('ENTRYPOINT_NOT_FOUND',))] -fn test_dual_no_transfer() { - let dispatcher = setup_non_erc20(); - dispatcher.transfer(RECIPIENT(), VALUE); -} - -#[test] -#[should_panic(expected: "Some error")] -fn test_dual_transfer_exists_and_panics() { - let (dispatcher, _) = setup_erc20_panic(); - dispatcher.transfer(RECIPIENT(), VALUE); -} - -#[test] -fn test_dual_approve() { - let (snake_dispatcher, snake_target) = setup_snake(); - start_cheat_caller_address(snake_dispatcher.contract_address, OWNER()); - assert!(snake_dispatcher.approve(SPENDER(), VALUE)); - - let snake_allowance = snake_target.allowance(OWNER(), SPENDER()); - assert_eq!(snake_allowance, VALUE); - - let (camel_dispatcher, camel_target) = setup_camel(); - start_cheat_caller_address(camel_dispatcher.contract_address, OWNER()); - assert!(camel_dispatcher.approve(SPENDER(), VALUE)); - - let camel_allowance = camel_target.allowance(OWNER(), SPENDER()); - assert_eq!(camel_allowance, VALUE); -} - -#[test] -#[ignore] // REASON: should_panic attribute not fit for complex panic messages. -#[should_panic(expected: ('ENTRYPOINT_NOT_FOUND',))] -fn test_dual_no_approve() { - let dispatcher = setup_non_erc20(); - dispatcher.approve(SPENDER(), VALUE); -} - -#[test] -#[should_panic(expected: "Some error")] -fn test_dual_approve_exists_and_panics() { - let (dispatcher, _) = setup_erc20_panic(); - dispatcher.approve(SPENDER(), VALUE); -} - -// -// snake_case target -// - -#[test] -fn test_dual_total_supply() { - let (dispatcher, _) = setup_snake(); - assert_eq!(dispatcher.total_supply(), SUPPLY); -} - -#[test] -#[ignore] // REASON: should_panic attribute not fit for complex panic messages. -#[should_panic(expected: ('ENTRYPOINT_NOT_FOUND',))] -fn test_dual_no_total_supply() { - let dispatcher = setup_non_erc20(); - dispatcher.total_supply(); -} - -#[test] -#[should_panic(expected: "Some error")] -fn test_dual_total_supply_exists_and_panics() { - let (dispatcher, _) = setup_erc20_panic(); - dispatcher.total_supply(); -} - -#[test] -fn test_dual_balance_of() { - let (dispatcher, _) = setup_snake(); - assert_eq!(dispatcher.balance_of(OWNER()), SUPPLY); -} - -#[test] -#[ignore] // REASON: should_panic attribute not fit for complex panic messages. -#[should_panic(expected: ('ENTRYPOINT_NOT_FOUND',))] -fn test_dual_no_balance_of() { - let dispatcher = setup_non_erc20(); - dispatcher.balance_of(OWNER()); -} - -#[test] -#[should_panic(expected: "Some error")] -fn test_dual_balance_of_exists_and_panics() { - let (dispatcher, _) = setup_erc20_panic(); - dispatcher.balance_of(OWNER()); -} - -#[test] -fn test_dual_transfer_from() { - let (dispatcher, target) = setup_snake(); - start_cheat_caller_address(dispatcher.contract_address, OWNER()); - target.approve(OPERATOR(), VALUE); - - start_cheat_caller_address(dispatcher.contract_address, OPERATOR()); - dispatcher.transfer_from(OWNER(), RECIPIENT(), VALUE); - assert_eq!(target.balance_of(RECIPIENT()), VALUE); -} - -#[test] -#[ignore] // REASON: should_panic attribute not fit for complex panic messages. -#[should_panic(expected: ('ENTRYPOINT_NOT_FOUND',))] -fn test_dual_no_transfer_from() { - let dispatcher = setup_non_erc20(); - dispatcher.transfer_from(OWNER(), RECIPIENT(), VALUE); -} - -#[test] -#[should_panic(expected: "Some error")] -fn test_dual_transfer_from_exists_and_panics() { - let (dispatcher, _) = setup_erc20_panic(); - dispatcher.transfer_from(OWNER(), RECIPIENT(), VALUE); -} - -// -// camelCase target -// - -#[test] -#[ignore] // REASON: foundry entrypoint_not_found error message inconsistent with mainnet. -fn test_dual_totalSupply() { - let (dispatcher, _) = setup_camel(); - assert_eq!(dispatcher.total_supply(), SUPPLY); -} - -#[test] -#[ignore] // REASON: foundry entrypoint_not_found error message inconsistent with mainnet. -#[should_panic(expected: "Some error")] -fn test_dual_totalSupply_exists_and_panics() { - let (_, dispatcher) = setup_erc20_panic(); - dispatcher.total_supply(); -} - -#[test] -#[ignore] // REASON: foundry entrypoint_not_found error message inconsistent with mainnet. -fn test_dual_balanceOf() { - let (dispatcher, _) = setup_camel(); - assert_eq!(dispatcher.balance_of(OWNER()), SUPPLY); -} - -#[test] -#[ignore] // REASON: foundry entrypoint_not_found error message inconsistent with mainnet. -#[should_panic(expected: "Some error")] -fn test_dual_balanceOf_exists_and_panics() { - let (_, dispatcher) = setup_erc20_panic(); - dispatcher.balance_of(OWNER()); -} - -#[test] -#[ignore] // REASON: foundry entrypoint_not_found error message inconsistent with mainnet. -fn test_dual_transferFrom() { - let (dispatcher, target) = setup_camel(); - start_cheat_caller_address(test_address(), OWNER()); - target.approve(OPERATOR(), VALUE); - - start_cheat_caller_address(test_address(), OPERATOR()); - dispatcher.transfer_from(OWNER(), RECIPIENT(), VALUE); - assert_eq!(target.balanceOf(RECIPIENT()), VALUE); -} - -#[test] -#[ignore] // REASON: foundry entrypoint_not_found error message inconsistent with mainnet. -#[should_panic(expected: "Some error")] -fn test_dual_transferFrom_exists_and_panics() { - let (_, dispatcher) = setup_erc20_panic(); - dispatcher.transfer_from(OWNER(), RECIPIENT(), VALUE); -} diff --git a/packages/token/src/tests/erc721.cairo b/packages/token/src/tests/erc721.cairo index 38933c7cb..d42d6412a 100644 --- a/packages/token/src/tests/erc721.cairo +++ b/packages/token/src/tests/erc721.cairo @@ -1,5 +1,3 @@ -mod test_dual721; -mod test_dual721_receiver; mod test_erc721; mod test_erc721_enumerable; mod test_erc721_receiver; diff --git a/packages/token/src/tests/erc721/test_dual721.cairo b/packages/token/src/tests/erc721/test_dual721.cairo deleted file mode 100644 index 8fabac436..000000000 --- a/packages/token/src/tests/erc721/test_dual721.cairo +++ /dev/null @@ -1,507 +0,0 @@ -use crate::erc721::dual721::{DualCaseERC721, DualCaseERC721Trait}; -use crate::erc721::interface::IERC721_ID; -use crate::erc721::interface::{IERC721CamelOnlyDispatcher, IERC721CamelOnlyDispatcherTrait}; -use crate::erc721::interface::{IERC721Dispatcher, IERC721DispatcherTrait}; -use openzeppelin_testing as utils; -use openzeppelin_testing::constants::{ - DATA, OWNER, RECIPIENT, SPENDER, OPERATOR, NAME, SYMBOL, BASE_URI, TOKEN_ID -}; -use openzeppelin_utils::serde::SerializedAppend; -use snforge_std::{start_cheat_caller_address}; -use starknet::ContractAddress; - -// -// Setup -// - -fn setup_snake() -> (DualCaseERC721, IERC721Dispatcher) { - let mut calldata = array![]; - calldata.append_serde(NAME()); - calldata.append_serde(SYMBOL()); - calldata.append_serde(BASE_URI()); - calldata.append_serde(OWNER()); - calldata.append_serde(TOKEN_ID); - - let target = utils::declare_and_deploy("SnakeERC721Mock", calldata); - start_cheat_caller_address(target, OWNER()); - (DualCaseERC721 { contract_address: target }, IERC721Dispatcher { contract_address: target }) -} - -fn setup_camel() -> (DualCaseERC721, IERC721CamelOnlyDispatcher) { - let mut calldata = array![]; - calldata.append_serde(NAME()); - calldata.append_serde(SYMBOL()); - calldata.append_serde(BASE_URI()); - calldata.append_serde(OWNER()); - calldata.append_serde(TOKEN_ID); - - let target = utils::declare_and_deploy("CamelERC721Mock", calldata); - start_cheat_caller_address(target, OWNER()); - ( - DualCaseERC721 { contract_address: target }, - IERC721CamelOnlyDispatcher { contract_address: target } - ) -} - -fn setup_non_erc721() -> DualCaseERC721 { - let calldata = array![]; - let target = utils::declare_and_deploy("NonImplementingMock", calldata); - DualCaseERC721 { contract_address: target } -} - -fn setup_erc721_panic() -> (DualCaseERC721, DualCaseERC721) { - let snake_target = utils::declare_and_deploy("SnakeERC721PanicMock", array![]); - let camel_target = utils::declare_and_deploy("CamelERC721PanicMock", array![]); - ( - DualCaseERC721 { contract_address: snake_target }, - DualCaseERC721 { contract_address: camel_target } - ) -} - -fn setup_receiver() -> ContractAddress { - utils::declare_and_deploy("DualCaseERC721ReceiverMock", array![]) -} - -// -// Case agnostic methods -// - -#[test] -fn test_dual_name() { - let (snake_dispatcher, _) = setup_snake(); - assert_eq!(snake_dispatcher.name(), NAME()); - - let (camel_dispatcher, _) = setup_camel(); - assert_eq!(camel_dispatcher.name(), NAME()); -} - -#[test] -#[ignore] // REASON: should_panic attribute not fit for complex panic messages. -#[should_panic(expected: ('ENTRYPOINT_NOT_FOUND',))] -fn test_dual_no_name() { - let dispatcher = setup_non_erc721(); - dispatcher.name(); -} - -#[test] -#[should_panic(expected: "Some error")] -fn test_dual_name_exists_and_panics() { - let (dispatcher, _) = setup_erc721_panic(); - dispatcher.name(); -} - -#[test] -fn test_dual_symbol() { - let (snake_dispatcher, _) = setup_snake(); - let (camel_dispatcher, _) = setup_camel(); - assert_eq!(snake_dispatcher.symbol(), SYMBOL()); - assert_eq!(camel_dispatcher.symbol(), SYMBOL()); -} - -#[test] -#[ignore] // REASON: should_panic attribute not fit for complex panic messages. -#[should_panic(expected: ('ENTRYPOINT_NOT_FOUND',))] -fn test_dual_no_symbol() { - let dispatcher = setup_non_erc721(); - dispatcher.symbol(); -} - -#[test] -#[should_panic(expected: "Some error")] -fn test_dual_symbol_exists_and_panics() { - let (dispatcher, _) = setup_erc721_panic(); - dispatcher.symbol(); -} - -#[test] -fn test_dual_approve() { - let (snake_dispatcher, snake_target) = setup_snake(); - - start_cheat_caller_address(snake_dispatcher.contract_address, OWNER()); - snake_dispatcher.approve(SPENDER(), TOKEN_ID); - assert_eq!(snake_target.get_approved(TOKEN_ID), SPENDER()); - - let (camel_dispatcher, camel_target) = setup_camel(); - - start_cheat_caller_address(camel_dispatcher.contract_address, OWNER()); - camel_dispatcher.approve(SPENDER(), TOKEN_ID); - assert_eq!(camel_target.getApproved(TOKEN_ID), SPENDER()); -} - -#[test] -#[ignore] // REASON: should_panic attribute not fit for complex panic messages. -#[should_panic(expected: ('ENTRYPOINT_NOT_FOUND',))] -fn test_dual_no_approve() { - let dispatcher = setup_non_erc721(); - dispatcher.approve(SPENDER(), TOKEN_ID); -} - -#[test] -#[should_panic(expected: "Some error")] -fn test_dual_approve_exists_and_panics() { - let (dispatcher, _) = setup_erc721_panic(); - dispatcher.approve(SPENDER(), TOKEN_ID); -} - -// -// snake_case target -// - -#[test] -fn test_dual_balance_of() { - let (dispatcher, _) = setup_snake(); - assert_eq!(dispatcher.balance_of(OWNER()), 1); -} - -#[test] -#[ignore] // REASON: should_panic attribute not fit for complex panic messages. -#[should_panic(expected: ('ENTRYPOINT_NOT_FOUND',))] -fn test_dual_no_balance_of() { - let dispatcher = setup_non_erc721(); - dispatcher.balance_of(OWNER()); -} - -#[test] -#[should_panic(expected: "Some error")] -fn test_dual_balance_of_exists_and_panics() { - let (dispatcher, _) = setup_erc721_panic(); - dispatcher.balance_of(OWNER()); -} - -#[test] -fn test_dual_owner_of() { - let (dispatcher, _) = setup_snake(); - assert_eq!(dispatcher.owner_of(TOKEN_ID), OWNER()); -} - -#[test] -#[ignore] // REASON: should_panic attribute not fit for complex panic messages. -#[should_panic(expected: ('ENTRYPOINT_NOT_FOUND',))] -fn test_dual_no_owner_of() { - let dispatcher = setup_non_erc721(); - dispatcher.owner_of(TOKEN_ID); -} - -#[test] -#[should_panic(expected: "Some error")] -fn test_dual_owner_of_exists_and_panics() { - let (dispatcher, _) = setup_erc721_panic(); - dispatcher.owner_of(TOKEN_ID); -} - -#[test] -fn test_dual_transfer_from() { - let (dispatcher, target) = setup_snake(); - dispatcher.transfer_from(OWNER(), RECIPIENT(), TOKEN_ID); - assert_eq!(target.owner_of(TOKEN_ID), RECIPIENT()); -} - -#[test] -#[ignore] // REASON: should_panic attribute not fit for complex panic messages. -#[should_panic(expected: ('ENTRYPOINT_NOT_FOUND',))] -fn test_dual_no_transfer_from() { - let dispatcher = setup_non_erc721(); - dispatcher.transfer_from(OWNER(), RECIPIENT(), TOKEN_ID); -} - -#[test] -#[should_panic(expected: "Some error")] -fn test_dual_transfer_from_exists_and_panics() { - let (dispatcher, _) = setup_erc721_panic(); - dispatcher.transfer_from(OWNER(), RECIPIENT(), TOKEN_ID); -} - -#[test] -fn test_dual_safe_transfer_from() { - let (dispatcher, target) = setup_snake(); - let receiver = setup_receiver(); - dispatcher.safe_transfer_from(OWNER(), receiver, TOKEN_ID, DATA(true)); - assert_eq!(target.owner_of(TOKEN_ID), receiver); -} - -#[test] -#[ignore] // REASON: should_panic attribute not fit for complex panic messages. -#[should_panic(expected: ('ENTRYPOINT_NOT_FOUND',))] -fn test_dual_no_safe_transfer_from() { - let dispatcher = setup_non_erc721(); - dispatcher.safe_transfer_from(OWNER(), RECIPIENT(), TOKEN_ID, DATA(true)); -} - -#[test] -#[should_panic(expected: "Some error")] -fn test_dual_safe_transfer_from_exists_and_panics() { - let (dispatcher, _) = setup_erc721_panic(); - dispatcher.safe_transfer_from(OWNER(), RECIPIENT(), TOKEN_ID, DATA(true)); -} - -#[test] -fn test_dual_get_approved() { - let (dispatcher, target) = setup_snake(); - - start_cheat_caller_address(dispatcher.contract_address, OWNER()); - target.approve(SPENDER(), TOKEN_ID); - assert_eq!(dispatcher.get_approved(TOKEN_ID), SPENDER()); -} - -#[test] -#[ignore] // REASON: should_panic attribute not fit for complex panic messages. -#[should_panic(expected: ('ENTRYPOINT_NOT_FOUND',))] -fn test_dual_no_get_approved() { - let dispatcher = setup_non_erc721(); - dispatcher.get_approved(TOKEN_ID); -} - -#[test] -#[should_panic(expected: "Some error")] -fn test_dual_get_approved_exists_and_panics() { - let (dispatcher, _) = setup_erc721_panic(); - dispatcher.get_approved(TOKEN_ID); -} - -#[test] -fn test_dual_set_approval_for_all() { - let (dispatcher, target) = setup_snake(); - - start_cheat_caller_address(dispatcher.contract_address, OWNER()); - dispatcher.set_approval_for_all(OPERATOR(), true); - - let is_approved_for_all = target.is_approved_for_all(OWNER(), OPERATOR()); - assert!(is_approved_for_all); -} - -#[test] -#[ignore] // REASON: should_panic attribute not fit for complex panic messages. -#[should_panic(expected: ('ENTRYPOINT_NOT_FOUND',))] -fn test_dual_no_set_approval_for_all() { - let dispatcher = setup_non_erc721(); - dispatcher.set_approval_for_all(OPERATOR(), true); -} - -#[test] -#[should_panic(expected: "Some error")] -fn test_dual_set_approval_for_all_exists_and_panics() { - let (dispatcher, _) = setup_erc721_panic(); - dispatcher.set_approval_for_all(OPERATOR(), true); -} - -#[test] -fn test_dual_is_approved_for_all() { - let (dispatcher, target) = setup_snake(); - - start_cheat_caller_address(dispatcher.contract_address, OWNER()); - target.set_approval_for_all(OPERATOR(), true); - - let is_approved_for_all = dispatcher.is_approved_for_all(OWNER(), OPERATOR()); - assert!(is_approved_for_all); -} - -#[test] -#[ignore] // REASON: should_panic attribute not fit for complex panic messages. -#[should_panic(expected: ('ENTRYPOINT_NOT_FOUND',))] -fn test_dual_no_is_approved_for_all() { - let dispatcher = setup_non_erc721(); - dispatcher.is_approved_for_all(OWNER(), OPERATOR()); -} - -#[test] -#[should_panic(expected: "Some error")] -fn test_dual_is_approved_for_all_exists_and_panics() { - let (dispatcher, _) = setup_erc721_panic(); - dispatcher.is_approved_for_all(OWNER(), OPERATOR()); -} - -#[test] -fn test_dual_token_uri() { - let (dispatcher, _) = setup_snake(); - let uri = dispatcher.token_uri(TOKEN_ID); - let expected = format!("{}{}", BASE_URI(), TOKEN_ID); - assert_eq!(uri, expected); -} - -#[test] -#[ignore] // REASON: should_panic attribute not fit for complex panic messages. -#[should_panic(expected: ('ENTRYPOINT_NOT_FOUND',))] -fn test_dual_no_token_uri() { - let dispatcher = setup_non_erc721(); - dispatcher.token_uri(TOKEN_ID); -} - -#[test] -#[should_panic(expected: "Some error")] -fn test_dual_token_uri_exists_and_panics() { - let (dispatcher, _) = setup_erc721_panic(); - dispatcher.token_uri(TOKEN_ID); -} - -#[test] -fn test_dual_supports_interface() { - let (dispatcher, _) = setup_snake(); - let supports_ierc721 = dispatcher.supports_interface(IERC721_ID); - assert!(supports_ierc721); -} - -#[test] -#[ignore] // REASON: should_panic attribute not fit for complex panic messages. -#[should_panic(expected: ('ENTRYPOINT_NOT_FOUND',))] -fn test_dual_no_supports_interface() { - let dispatcher = setup_non_erc721(); - dispatcher.supports_interface(IERC721_ID); -} - -#[test] -#[should_panic(expected: "Some error")] -fn test_dual_supports_interface_exists_and_panics() { - let (dispatcher, _) = setup_erc721_panic(); - dispatcher.supports_interface(IERC721_ID); -} - -// -// camelCase target -// - -#[test] -#[ignore] // REASON: foundry entrypoint_not_found error message inconsistent with mainnet. -fn test_dual_balanceOf() { - let (dispatcher, _) = setup_camel(); - assert_eq!(dispatcher.balance_of(OWNER()), 1); -} - -#[test] -#[ignore] // REASON: foundry entrypoint_not_found error message inconsistent with mainnet. -#[should_panic(expected: "Some error")] -fn test_dual_balanceOf_exists_and_panics() { - let (_, dispatcher) = setup_erc721_panic(); - dispatcher.balance_of(OWNER()); -} - -#[test] -#[ignore] // REASON: foundry entrypoint_not_found error message inconsistent with mainnet. -fn test_dual_ownerOf() { - let (dispatcher, _) = setup_camel(); - let current_owner = dispatcher.owner_of(TOKEN_ID); - assert_eq!(current_owner, OWNER()); -} - -#[test] -#[ignore] // REASON: foundry entrypoint_not_found error message inconsistent with mainnet. -#[should_panic(expected: "Some error")] -fn test_dual_ownerOf_exists_and_panics() { - let (_, dispatcher) = setup_erc721_panic(); - dispatcher.owner_of(TOKEN_ID); -} - -#[test] -#[ignore] // REASON: foundry entrypoint_not_found error message inconsistent with mainnet. -fn test_dual_transferFrom() { - let (dispatcher, target) = setup_camel(); - - start_cheat_caller_address(dispatcher.contract_address, OWNER()); - dispatcher.transfer_from(OWNER(), RECIPIENT(), TOKEN_ID); - - let current_owner = target.ownerOf(TOKEN_ID); - assert_eq!(current_owner, RECIPIENT()); -} - -#[test] -#[ignore] // REASON: foundry entrypoint_not_found error message inconsistent with mainnet. -#[should_panic(expected: "Some error")] -fn test_dual_transferFrom_exists_and_panics() { - let (_, dispatcher) = setup_erc721_panic(); - dispatcher.transfer_from(OWNER(), RECIPIENT(), TOKEN_ID); -} - -#[test] -#[ignore] // REASON: foundry entrypoint_not_found error message inconsistent with mainnet. -fn test_dual_safeTransferFrom() { - let (dispatcher, target) = setup_camel(); - let receiver = setup_receiver(); - dispatcher.safe_transfer_from(OWNER(), receiver, TOKEN_ID, DATA(true)); - - let current_owner = target.ownerOf(TOKEN_ID); - assert_eq!(current_owner, receiver); -} - -#[test] -#[ignore] // REASON: foundry entrypoint_not_found error message inconsistent with mainnet. -#[should_panic(expected: "Some error")] -fn test_dual_safeTransferFrom_exists_and_panics() { - let (_, dispatcher) = setup_erc721_panic(); - dispatcher.safe_transfer_from(OWNER(), RECIPIENT(), TOKEN_ID, DATA(true)); -} - -#[test] -#[ignore] // REASON: foundry entrypoint_not_found error message inconsistent with mainnet. -fn test_dual_getApproved() { - let (dispatcher, _) = setup_camel(); - - start_cheat_caller_address(dispatcher.contract_address, OWNER()); - dispatcher.approve(SPENDER(), TOKEN_ID); - - let approved = dispatcher.get_approved(TOKEN_ID); - assert_eq!(approved, SPENDER()); -} - -#[test] -#[ignore] // REASON: foundry entrypoint_not_found error message inconsistent with mainnet. -#[should_panic(expected: "Some error")] -fn test_dual_getApproved_exists_and_panics() { - let (_, dispatcher) = setup_erc721_panic(); - dispatcher.get_approved(TOKEN_ID); -} - -#[test] -#[ignore] // REASON: foundry entrypoint_not_found error message inconsistent with mainnet. -fn test_dual_setApprovalForAll() { - let (dispatcher, target) = setup_camel(); - - start_cheat_caller_address(dispatcher.contract_address, OWNER()); - dispatcher.set_approval_for_all(OPERATOR(), true); - - let is_approved_for_all = target.isApprovedForAll(OWNER(), OPERATOR()); - assert!(is_approved_for_all); -} - -#[test] -#[ignore] // REASON: foundry entrypoint_not_found error message inconsistent with mainnet. -#[should_panic(expected: "Some error")] -fn test_dual_setApprovalForAll_exists_and_panics() { - let (_, dispatcher) = setup_erc721_panic(); - dispatcher.set_approval_for_all(OPERATOR(), true); -} - -#[test] -#[ignore] // REASON: foundry entrypoint_not_found error message inconsistent with mainnet. -fn test_dual_isApprovedForAll() { - let (dispatcher, target) = setup_camel(); - - start_cheat_caller_address(dispatcher.contract_address, OWNER()); - target.setApprovalForAll(OPERATOR(), true); - - let is_approved_for_all = dispatcher.is_approved_for_all(OWNER(), OPERATOR()); - assert!(is_approved_for_all); -} - -#[test] -#[ignore] // REASON: foundry entrypoint_not_found error message inconsistent with mainnet. -#[should_panic(expected: "Some error")] -fn test_dual_isApprovedForAll_exists_and_panics() { - let (_, dispatcher) = setup_erc721_panic(); - dispatcher.is_approved_for_all(OWNER(), OPERATOR()); -} - -#[test] -#[ignore] // REASON: foundry entrypoint_not_found error message inconsistent with mainnet. -fn test_dual_tokenURI() { - let (dispatcher, _) = setup_camel(); - let uri = dispatcher.token_uri(TOKEN_ID); - let expected = format!("{}{}", BASE_URI(), TOKEN_ID); - assert_eq!(uri, expected); -} - -#[test] -#[ignore] // REASON: foundry entrypoint_not_found error message inconsistent with mainnet. -#[should_panic(expected: "Some error")] -fn test_dual_tokenURI_exists_and_panics() { - let (_, dispatcher) = setup_erc721_panic(); - dispatcher.token_uri(TOKEN_ID); -} diff --git a/packages/token/src/tests/erc721/test_dual721_receiver.cairo b/packages/token/src/tests/erc721/test_dual721_receiver.cairo deleted file mode 100644 index bab5645c8..000000000 --- a/packages/token/src/tests/erc721/test_dual721_receiver.cairo +++ /dev/null @@ -1,93 +0,0 @@ -use crate::erc721::dual721_receiver::{DualCaseERC721Receiver, DualCaseERC721ReceiverTrait}; -use crate::erc721::interface::{ - IERC721ReceiverDispatcher, IERC721ReceiverCamelDispatcher, IERC721_RECEIVER_ID -}; -use openzeppelin_testing as utils; -use openzeppelin_testing::constants::{DATA, OPERATOR, OWNER, TOKEN_ID}; - -// -// Setup -// - -fn setup_snake() -> (DualCaseERC721Receiver, IERC721ReceiverDispatcher) { - let calldata = array![]; - let target = utils::declare_and_deploy("SnakeERC721ReceiverMock", calldata); - ( - DualCaseERC721Receiver { contract_address: target }, - IERC721ReceiverDispatcher { contract_address: target } - ) -} - -fn setup_camel() -> (DualCaseERC721Receiver, IERC721ReceiverCamelDispatcher) { - let calldata = array![]; - let target = utils::declare_and_deploy("CamelERC721ReceiverMock", calldata); - ( - DualCaseERC721Receiver { contract_address: target }, - IERC721ReceiverCamelDispatcher { contract_address: target } - ) -} - -fn setup_non_erc721_receiver() -> DualCaseERC721Receiver { - let calldata = array![]; - let target = utils::declare_and_deploy("NonImplementingMock", calldata); - DualCaseERC721Receiver { contract_address: target } -} - -fn setup_erc721_receiver_panic() -> (DualCaseERC721Receiver, DualCaseERC721Receiver) { - let snake_target = utils::declare_and_deploy("SnakeERC721ReceiverPanicMock", array![]); - let camel_target = utils::declare_and_deploy("CamelERC721ReceiverPanicMock", array![]); - ( - DualCaseERC721Receiver { contract_address: snake_target }, - DualCaseERC721Receiver { contract_address: camel_target } - ) -} - -// -// snake_case target -// - -#[test] -fn test_dual_on_erc721_received() { - let (dispatcher, _) = setup_snake(); - - let on_erc721_received = dispatcher - .on_erc721_received(OPERATOR(), OWNER(), TOKEN_ID, DATA(true)); - assert_eq!(on_erc721_received, IERC721_RECEIVER_ID); -} - -#[test] -#[ignore] // REASON: should_panic attribute not fit for complex panic messages. -#[should_panic(expected: ('ENTRYPOINT_NOT_FOUND',))] -fn test_dual_no_on_erc721_received() { - let dispatcher = setup_non_erc721_receiver(); - dispatcher.on_erc721_received(OPERATOR(), OWNER(), TOKEN_ID, DATA(true)); -} - -#[test] -#[should_panic(expected: "Some error")] -fn test_dual_on_erc721_received_exists_and_panics() { - let (dispatcher, _) = setup_erc721_receiver_panic(); - dispatcher.on_erc721_received(OPERATOR(), OWNER(), TOKEN_ID, DATA(true)); -} - -// -// camelCase target -// - -#[test] -#[ignore] // REASON: foundry entrypoint_not_found error message inconsistent with mainnet. -fn test_dual_onERC721Received() { - let (dispatcher, _) = setup_camel(); - - let on_erc721_received = dispatcher - .on_erc721_received(OPERATOR(), OWNER(), TOKEN_ID, DATA(true)); - assert_eq!(on_erc721_received, IERC721_RECEIVER_ID); -} - -#[test] -#[ignore] // REASON: foundry entrypoint_not_found error message inconsistent with mainnet. -#[should_panic(expected: "Some error")] -fn test_dual_onERC721Received_exists_and_panics() { - let (_, dispatcher) = setup_erc721_receiver_panic(); - dispatcher.on_erc721_received(OPERATOR(), OWNER(), TOKEN_ID, DATA(true)); -} diff --git a/packages/token/src/tests/erc721/test_erc721.cairo b/packages/token/src/tests/erc721/test_erc721.cairo index ebf9c5bd5..d28f9d189 100644 --- a/packages/token/src/tests/erc721/test_erc721.cairo +++ b/packages/token/src/tests/erc721/test_erc721.cairo @@ -37,11 +37,7 @@ fn setup() -> ComponentState { } fn setup_receiver() -> ContractAddress { - utils::declare_and_deploy("SnakeERC721ReceiverMock", array![]) -} - -fn setup_camel_receiver() -> ContractAddress { - utils::declare_and_deploy("CamelERC721ReceiverMock", array![]) + utils::declare_and_deploy("DualCaseERC721ReceiverMock", array![]) } fn setup_account() -> ContractAddress { @@ -49,11 +45,6 @@ fn setup_account() -> ContractAddress { utils::declare_and_deploy("DualCaseAccountMock", calldata) } -fn setup_camel_account() -> ContractAddress { - let calldata = array![PUBKEY]; - utils::declare_and_deploy("CamelAccountMock", calldata) -} - // // Initializers // @@ -595,42 +586,6 @@ fn test_safeTransferFrom_to_account() { assert_state_after_transfer(owner, account, token_id); } -#[test] -fn test_safe_transfer_from_to_account_camel() { - let mut state = setup(); - let contract_address = test_address(); - let account = setup_camel_account(); - let mut spy = spy_events(); - let token_id = TOKEN_ID; - let owner = OWNER(); - - assert_state_before_transfer(owner, account, token_id); - - start_cheat_caller_address(contract_address, owner); - state.safe_transfer_from(owner, account, token_id, DATA(true)); - spy.assert_only_event_transfer(contract_address, owner, account, token_id); - - assert_state_after_transfer(owner, account, token_id); -} - -#[test] -fn test_safeTransferFrom_to_account_camel() { - let mut state = setup(); - let contract_address = test_address(); - let account = setup_camel_account(); - let mut spy = spy_events(); - let token_id = TOKEN_ID; - let owner = OWNER(); - - assert_state_before_transfer(owner, account, token_id); - - start_cheat_caller_address(contract_address, owner); - state.safeTransferFrom(owner, account, token_id, DATA(true)); - spy.assert_only_event_transfer(contract_address, owner, account, token_id); - - assert_state_after_transfer(owner, account, token_id); -} - #[test] fn test_safe_transfer_from_to_receiver() { let mut state = setup(); @@ -667,44 +622,6 @@ fn test_safeTransferFrom_to_receiver() { assert_state_after_transfer(owner, receiver, token_id); } -#[test] -#[ignore] // REASON: foundry entrypoint_not_found error message inconsistent with mainnet. -fn test_safe_transfer_from_to_receiver_camel() { - let mut state = setup(); - let receiver = setup_camel_receiver(); - let contract_address = test_address(); - let mut spy = spy_events(); - let token_id = TOKEN_ID; - let owner = OWNER(); - - assert_state_before_transfer(owner, receiver, token_id); - - start_cheat_caller_address(contract_address, owner); - state.safe_transfer_from(owner, receiver, token_id, DATA(true)); - spy.assert_only_event_transfer(contract_address, owner, receiver, token_id); - - assert_state_after_transfer(owner, receiver, token_id); -} - -#[test] -#[ignore] // REASON: foundry entrypoint_not_found error message inconsistent with mainnet. -fn test_safeTransferFrom_to_receiver_camel() { - let mut state = setup(); - let receiver = setup_camel_receiver(); - let mut spy = spy_events(); - let contract_address = test_address(); - let token_id = TOKEN_ID; - let owner = OWNER(); - - assert_state_before_transfer(owner, receiver, token_id); - - start_cheat_caller_address(contract_address, owner); - state.safeTransferFrom(owner, receiver, token_id, DATA(true)); - spy.assert_only_event_transfer(contract_address, owner, receiver, token_id); - - assert_state_after_transfer(owner, receiver, token_id); -} - #[test] #[should_panic(expected: ('ERC721: safe transfer failed',))] fn test_safe_transfer_from_to_receiver_failure() { @@ -729,32 +646,6 @@ fn test_safeTransferFrom_to_receiver_failure() { state.safeTransferFrom(owner, receiver, token_id, DATA(false)); } -#[test] -#[ignore] // REASON: foundry entrypoint_not_found error message inconsistent with mainnet. -#[should_panic(expected: ('ERC721: safe transfer failed',))] -fn test_safe_transfer_from_to_receiver_failure_camel() { - let mut state = setup(); - let receiver = setup_camel_receiver(); - let token_id = TOKEN_ID; - let owner = OWNER(); - - start_cheat_caller_address(test_address(), owner); - state.safe_transfer_from(owner, receiver, token_id, DATA(false)); -} - -#[test] -#[ignore] // REASON: foundry entrypoint_not_found error message inconsistent with mainnet. -#[should_panic(expected: ('ERC721: safe transfer failed',))] -fn test_safeTransferFrom_to_receiver_failure_camel() { - let mut state = setup(); - let receiver = setup_camel_receiver(); - let token_id = TOKEN_ID; - let owner = OWNER(); - - start_cheat_caller_address(test_address(), owner); - state.safeTransferFrom(owner, receiver, token_id, DATA(false)); -} - #[test] #[ignore] // REASON: should_panic attribute not fit for complex panic messages. #[should_panic(expected: ('ENTRYPOINT_NOT_FOUND',))] @@ -855,54 +746,6 @@ fn test_safeTransferFrom_to_owner() { assert_eq!(state.balance_of(owner), 1); } -#[test] -#[ignore] // REASON: foundry entrypoint_not_found error message inconsistent with mainnet. -fn test_safe_transfer_from_to_owner_camel() { - let mut state = COMPONENT_STATE(); - let token_id = TOKEN_ID; - let owner = setup_camel_receiver(); - let contract_address = test_address(); - - state.initializer(NAME(), SYMBOL(), BASE_URI()); - state.mint(owner, token_id); - - let mut spy = spy_events(); - - assert_eq!(state.owner_of(token_id), owner); - assert_eq!(state.balance_of(owner), 1); - - start_cheat_caller_address(contract_address, owner); - state.safe_transfer_from(owner, owner, token_id, DATA(true)); - spy.assert_only_event_transfer(contract_address, owner, owner, token_id); - - assert_eq!(state.owner_of(token_id), owner); - assert_eq!(state.balance_of(owner), 1); -} - -#[test] -#[ignore] // REASON: foundry entrypoint_not_found error message inconsistent with mainnet. -fn test_safeTransferFrom_to_owner_camel() { - let mut state = COMPONENT_STATE(); - let contract_address = test_address(); - let token_id = TOKEN_ID; - let owner = setup_camel_receiver(); - - state.initializer(NAME(), SYMBOL(), BASE_URI()); - state.mint(owner, token_id); - - assert_eq!(state.owner_of(token_id), owner); - assert_eq!(state.balance_of(owner), 1); - - let mut spy = spy_events(); - - start_cheat_caller_address(contract_address, owner); - state.safeTransferFrom(owner, owner, token_id, DATA(true)); - spy.assert_only_event_transfer(contract_address, owner, owner, token_id); - - assert_eq!(state.owner_of(token_id), owner); - assert_eq!(state.balance_of(owner), 1); -} - #[test] fn test_safe_transfer_from_approved() { let mut state = setup(); @@ -947,49 +790,6 @@ fn test_safeTransferFrom_approved() { assert_state_after_transfer(owner, receiver, token_id); } -#[test] -#[ignore] // REASON: foundry entrypoint_not_found error message inconsistent with mainnet. -fn test_safe_transfer_from_approved_camel() { - let mut state = setup(); - let contract_address = test_address(); - let receiver = setup_camel_receiver(); - let token_id = TOKEN_ID; - let owner = OWNER(); - - assert_state_before_transfer(owner, receiver, token_id); - - start_cheat_caller_address(contract_address, owner); - state.approve(OPERATOR(), token_id); - - let mut spy = spy_events(); - - start_cheat_caller_address(contract_address, OPERATOR()); - state.safe_transfer_from(owner, receiver, token_id, DATA(true)); - spy.assert_only_event_transfer(contract_address, owner, receiver, token_id); - - assert_state_after_transfer(owner, receiver, token_id); -} - -#[test] -#[ignore] // REASON: foundry entrypoint_not_found error message inconsistent with mainnet. -fn test_safeTransferFrom_approved_camel() { - let mut state = setup(); - let contract_address = test_address(); - let receiver = setup_camel_receiver(); - let token_id = TOKEN_ID; - let owner = OWNER(); - let mut spy = spy_events(); - - assert_state_before_transfer(owner, receiver, token_id); - - start_cheat_caller_address(contract_address, owner); - state.approve(OPERATOR(), token_id); - state.safeTransferFrom(owner, receiver, token_id, DATA(true)); - spy.assert_only_event_transfer(contract_address, owner, receiver, token_id); - - assert_state_after_transfer(owner, receiver, token_id); -} - #[test] fn test_safe_transfer_from_approved_for_all() { let mut state = setup(); @@ -1034,48 +834,6 @@ fn test_safeTransferFrom_approved_for_all() { assert_state_after_transfer(owner, receiver, token_id); } -#[test] -#[ignore] // REASON: foundry entrypoint_not_found error message inconsistent with mainnet. -fn test_safe_transfer_from_approved_for_all_camel() { - let mut state = setup(); - let contract_address = test_address(); - let mut spy = spy_events(); - let receiver = setup_camel_receiver(); - let token_id = TOKEN_ID; - let owner = OWNER(); - - assert_state_before_transfer(owner, receiver, token_id); - - start_cheat_caller_address(contract_address, owner); - state.set_approval_for_all(OPERATOR(), true); - - start_cheat_caller_address(contract_address, OPERATOR()); - state.safe_transfer_from(owner, receiver, token_id, DATA(true)); - spy.assert_only_event_transfer(contract_address, owner, receiver, token_id); - - assert_state_after_transfer(owner, receiver, token_id); -} - -#[test] -#[ignore] // REASON: foundry entrypoint_not_found error message inconsistent with mainnet. -fn test_safeTransferFrom_approved_for_all_camel() { - let mut state = setup(); - let contract_address = test_address(); - let receiver = setup_camel_receiver(); - let token_id = TOKEN_ID; - let owner = OWNER(); - let mut spy = spy_events(); - - assert_state_before_transfer(owner, receiver, token_id); - - start_cheat_caller_address(contract_address, owner); - state.set_approval_for_all(OPERATOR(), true); - state.safeTransferFrom(owner, receiver, token_id, DATA(true)); - spy.assert_only_event_transfer(contract_address, owner, receiver, token_id); - - assert_state_after_transfer(owner, receiver, token_id); -} - #[test] #[should_panic(expected: ('ERC721: unauthorized caller',))] fn test_safe_transfer_from_unauthorized() { @@ -1186,22 +944,6 @@ fn test__safe_mint_to_receiver() { assert_state_after_mint(recipient, token_id); } -#[test] -#[ignore] // REASON: foundry entrypoint_not_found error message inconsistent with mainnet. -fn test__safe_mint_to_receiver_camel() { - let mut state = COMPONENT_STATE(); - let contract_address = test_address(); - let mut spy = spy_events(); - let recipient = setup_camel_receiver(); - let token_id = TOKEN_ID; - - assert_state_before_mint(recipient); - state.safe_mint(recipient, token_id, DATA(true)); - spy.assert_only_event_transfer(contract_address, ZERO(), recipient, token_id); - - assert_state_after_mint(recipient, token_id); -} - #[test] fn test__safe_mint_to_account() { let mut state = COMPONENT_STATE(); @@ -1217,21 +959,6 @@ fn test__safe_mint_to_account() { assert_state_after_mint(account, token_id); } -#[test] -fn test__safe_mint_to_account_camel() { - let mut state = COMPONENT_STATE(); - let contract_address = test_address(); - let account = setup_camel_account(); - let mut spy = spy_events(); - let token_id = TOKEN_ID; - - assert_state_before_mint(account); - state.safe_mint(account, token_id, DATA(true)); - spy.assert_only_event_transfer(contract_address, ZERO(), account, token_id); - - assert_state_after_mint(account, token_id); -} - #[test] #[ignore] // REASON: should_panic attribute not fit for complex panic messages. #[should_panic(expected: ('ENTRYPOINT_NOT_FOUND',))] @@ -1257,19 +984,6 @@ fn test__safe_mint_to_receiver_failure() { assert_state_after_mint(recipient, token_id); } -#[test] -#[ignore] // REASON: foundry entrypoint_not_found error message inconsistent with mainnet. -#[should_panic(expected: ('ERC721: safe mint failed',))] -fn test__safe_mint_to_receiver_failure_camel() { - let mut state = COMPONENT_STATE(); - let recipient = setup_camel_receiver(); - let token_id = TOKEN_ID; - - assert_state_before_mint(recipient); - state.safe_mint(recipient, token_id, DATA(false)); - assert_state_after_mint(recipient, token_id); -} - #[test] #[should_panic(expected: ('ERC721: invalid receiver',))] fn test__safe_mint_to_zero() { diff --git a/packages/token/src/tests/mocks.cairo b/packages/token/src/tests/mocks.cairo index 9574a4b7a..35ad0586e 100644 --- a/packages/token/src/tests/mocks.cairo +++ b/packages/token/src/tests/mocks.cairo @@ -7,5 +7,4 @@ pub(crate) mod erc2981_mocks; pub(crate) mod erc721_enumerable_mocks; pub(crate) mod erc721_mocks; pub(crate) mod erc721_receiver_mocks; -pub(crate) mod non_implementing_mock; pub(crate) mod src5_mocks; diff --git a/packages/token/src/tests/mocks/account_mocks.cairo b/packages/token/src/tests/mocks/account_mocks.cairo index f8f222dad..e09f53328 100644 --- a/packages/token/src/tests/mocks/account_mocks.cairo +++ b/packages/token/src/tests/mocks/account_mocks.cairo @@ -43,103 +43,3 @@ pub(crate) mod DualCaseAccountMock { self.account.initializer(public_key); } } - -#[starknet::contract(account)] -pub(crate) mod SnakeAccountMock { - use openzeppelin_account::AccountComponent; - use openzeppelin_introspection::src5::SRC5Component; - - component!(path: AccountComponent, storage: account, event: AccountEvent); - component!(path: SRC5Component, storage: src5, event: SRC5Event); - - // Account - #[abi(embed_v0)] - impl SRC6Impl = AccountComponent::SRC6Impl; - #[abi(embed_v0)] - impl PublicKeyImpl = AccountComponent::PublicKeyImpl; - impl AccountInternalImpl = AccountComponent::InternalImpl; - - // SCR5 - #[abi(embed_v0)] - impl SRC5Impl = SRC5Component::SRC5Impl; - - #[storage] - pub struct Storage { - #[substorage(v0)] - pub account: AccountComponent::Storage, - #[substorage(v0)] - pub src5: SRC5Component::Storage - } - - #[event] - #[derive(Drop, starknet::Event)] - enum Event { - #[flat] - AccountEvent: AccountComponent::Event, - #[flat] - SRC5Event: SRC5Component::Event - } - - #[constructor] - fn constructor(ref self: ContractState, public_key: felt252) { - self.account.initializer(public_key); - } -} - -#[starknet::contract(account)] -pub(crate) mod CamelAccountMock { - use openzeppelin_account::AccountComponent; - use openzeppelin_introspection::src5::SRC5Component; - use starknet::account::Call; - - component!(path: AccountComponent, storage: account, event: AccountEvent); - component!(path: SRC5Component, storage: src5, event: SRC5Event); - - // Account - #[abi(embed_v0)] - impl SRC6CamelOnlyImpl = AccountComponent::SRC6CamelOnlyImpl; - #[abi(embed_v0)] - impl PublicKeyCamelImpl = AccountComponent::PublicKeyCamelImpl; - impl SRC6Impl = AccountComponent::SRC6Impl; - impl AccountInternalImpl = AccountComponent::InternalImpl; - - // SCR5 - #[abi(embed_v0)] - impl SRC5Impl = SRC5Component::SRC5Impl; - - #[storage] - pub struct Storage { - #[substorage(v0)] - pub account: AccountComponent::Storage, - #[substorage(v0)] - pub src5: SRC5Component::Storage - } - - #[event] - #[derive(Drop, starknet::Event)] - enum Event { - #[flat] - AccountEvent: AccountComponent::Event, - #[flat] - SRC5Event: SRC5Component::Event - } - - #[constructor] - fn constructor(ref self: ContractState, publicKey: felt252) { - self.account.initializer(publicKey); - } - - #[abi(per_item)] - #[generate_trait] - impl ExternalImpl of ExternalTrait { - #[external(v0)] - fn __execute__(self: @ContractState, mut calls: Array) -> Array> { - self.account.__execute__(calls) - } - - #[external(v0)] - fn __validate__(self: @ContractState, mut calls: Array) -> felt252 { - self.account.__validate__(calls) - } - } -} diff --git a/packages/token/src/tests/mocks/erc1155_mocks.cairo b/packages/token/src/tests/mocks/erc1155_mocks.cairo index cbf968c76..a7442f8c0 100644 --- a/packages/token/src/tests/mocks/erc1155_mocks.cairo +++ b/packages/token/src/tests/mocks/erc1155_mocks.cairo @@ -50,257 +50,3 @@ pub(crate) mod DualCaseERC1155Mock { self.erc1155.mint_with_acceptance_check(recipient, token_id, value, array![].span()); } } - -#[starknet::contract] -pub(crate) mod SnakeERC1155Mock { - use crate::erc1155::{ERC1155Component, ERC1155HooksEmptyImpl}; - use openzeppelin_introspection::src5::SRC5Component; - use starknet::ContractAddress; - - component!(path: ERC1155Component, storage: erc1155, event: ERC1155Event); - component!(path: SRC5Component, storage: src5, event: SRC5Event); - - // ERC1155 - #[abi(embed_v0)] - impl ERC1155Impl = ERC1155Component::ERC1155Impl; - #[abi(embed_v0)] - impl ERC1155MetadataURIImpl = - ERC1155Component::ERC1155MetadataURIImpl; - impl ERC1155InternalImpl = ERC1155Component::InternalImpl; - - // SRC5 - #[abi(embed_v0)] - impl SRC5Impl = SRC5Component::SRC5Impl; - - #[storage] - pub struct Storage { - #[substorage(v0)] - pub erc1155: ERC1155Component::Storage, - #[substorage(v0)] - pub src5: SRC5Component::Storage - } - - #[event] - #[derive(Drop, starknet::Event)] - enum Event { - #[flat] - ERC1155Event: ERC1155Component::Event, - #[flat] - SRC5Event: SRC5Component::Event - } - - #[constructor] - fn constructor( - ref self: ContractState, - base_uri: ByteArray, - recipient: ContractAddress, - token_id: u256, - value: u256 - ) { - self.erc1155.initializer(base_uri); - self.erc1155.mint_with_acceptance_check(recipient, token_id, value, array![].span()); - } -} - -#[starknet::contract] -pub(crate) mod CamelERC1155Mock { - use crate::erc1155::{ERC1155Component, ERC1155HooksEmptyImpl}; - use openzeppelin_introspection::src5::SRC5Component; - use starknet::ContractAddress; - - component!(path: ERC1155Component, storage: erc1155, event: ERC1155Event); - component!(path: SRC5Component, storage: src5, event: SRC5Event); - - // ERC1155 - #[abi(embed_v0)] - impl ERC1155Camel = ERC1155Component::ERC1155CamelImpl; - #[abi(embed_v0)] - impl ERC1155MetadataURIImpl = - ERC1155Component::ERC1155MetadataURIImpl; - impl ERC1155InternalImpl = ERC1155Component::InternalImpl; - - // SRC5 - #[abi(embed_v0)] - impl SRC5Impl = SRC5Component::SRC5Impl; - - #[storage] - pub struct Storage { - #[substorage(v0)] - pub erc1155: ERC1155Component::Storage, - #[substorage(v0)] - pub src5: SRC5Component::Storage - } - - #[event] - #[derive(Drop, starknet::Event)] - enum Event { - #[flat] - ERC1155Event: ERC1155Component::Event, - #[flat] - SRC5Event: SRC5Component::Event - } - - #[constructor] - fn constructor( - ref self: ContractState, - base_uri: ByteArray, - recipient: ContractAddress, - token_id: u256, - value: u256 - ) { - self.erc1155.initializer(base_uri); - self.erc1155.mint_with_acceptance_check(recipient, token_id, value, array![].span()); - } -} - -#[starknet::contract] -pub(crate) mod SnakeERC1155PanicMock { - use starknet::ContractAddress; - - #[storage] - pub struct Storage {} - - #[abi(per_item)] - #[generate_trait] - impl ExternalImpl of ExternalTrait { - #[external(v0)] - fn uri(self: @ContractState, token_id: u256) -> ByteArray { - panic!("Some error"); - "3" - } - - #[external(v0)] - fn balance_of(self: @ContractState, account: ContractAddress, token_id: u256) -> u256 { - panic!("Some error"); - u256 { low: 3, high: 3 } - } - - #[external(v0)] - fn balance_of_batch( - self: @ContractState, accounts: Span, token_ids: Span - ) -> Span { - panic!("Some error"); - array![u256 { low: 3, high: 3 }].span() - } - - #[external(v0)] - fn safe_transfer_from( - ref self: ContractState, - from: ContractAddress, - to: ContractAddress, - token_id: u256, - value: u256, - data: Span - ) { - panic!("Some error"); - } - - #[external(v0)] - fn safe_batch_transfer_from( - ref self: ContractState, - from: starknet::ContractAddress, - to: starknet::ContractAddress, - token_ids: Span, - values: Span, - data: Span - ) { - panic!("Some error"); - } - - #[external(v0)] - fn is_approved_for_all( - self: @ContractState, owner: ContractAddress, operator: ContractAddress - ) -> bool { - panic!("Some error"); - false - } - - #[external(v0)] - fn set_approval_for_all( - ref self: ContractState, operator: ContractAddress, approved: bool - ) { - panic!("Some error"); - } - - #[external(v0)] - fn supports_interface(self: @ContractState, interface_id: felt252) -> bool { - panic!("Some error"); - false - } - } -} - -#[starknet::contract] -pub(crate) mod CamelERC1155PanicMock { - use starknet::ContractAddress; - - #[storage] - pub struct Storage {} - - #[abi(per_item)] - #[generate_trait] - impl ExternalImpl of ExternalTrait { - #[external(v0)] - fn uri(self: @ContractState, tokenId: u256) -> ByteArray { - panic!("Some error"); - "3" - } - - #[external(v0)] - fn balanceOf(self: @ContractState, account: ContractAddress, tokenId: u256) -> u256 { - panic!("Some error"); - u256 { low: 3, high: 3 } - } - - #[external(v0)] - fn balanceOfBatch( - self: @ContractState, accounts: Span, token_ids: Span - ) -> Span { - panic!("Some error"); - array![u256 { low: 3, high: 3 }].span() - } - - #[external(v0)] - fn safeTransferFrom( - ref self: ContractState, - from: ContractAddress, - to: ContractAddress, - tokenId: u256, - value: u256, - data: Span - ) { - panic!("Some error"); - } - - #[external(v0)] - fn safeBatchTransferFrom( - ref self: ContractState, - from: starknet::ContractAddress, - to: starknet::ContractAddress, - token_ids: Span, - values: Span, - data: Span - ) { - panic!("Some error"); - } - - #[external(v0)] - fn isApprovedForAll( - self: @ContractState, owner: ContractAddress, operator: ContractAddress - ) -> bool { - panic!("Some error"); - false - } - - #[external(v0)] - fn setApprovalForAll(ref self: ContractState, operator: ContractAddress, approved: bool) { - panic!("Some error"); - } - - #[external(v0)] - fn supportsInterface(self: @ContractState, interfaceId: felt252) -> bool { - panic!("Some error"); - false - } - } -} diff --git a/packages/token/src/tests/mocks/erc1155_receiver_mocks.cairo b/packages/token/src/tests/mocks/erc1155_receiver_mocks.cairo index d5018e877..06443f5f5 100644 --- a/packages/token/src/tests/mocks/erc1155_receiver_mocks.cairo +++ b/packages/token/src/tests/mocks/erc1155_receiver_mocks.cairo @@ -38,157 +38,3 @@ pub(crate) mod DualCaseERC1155ReceiverMock { self.erc1155_receiver.initializer(); } } - -#[starknet::contract] -pub(crate) mod SnakeERC1155ReceiverMock { - use crate::erc1155::ERC1155ReceiverComponent; - use openzeppelin_introspection::src5::SRC5Component; - - component!(path: SRC5Component, storage: src5, event: SRC5Event); - component!( - path: ERC1155ReceiverComponent, storage: erc1155_receiver, event: ERC1155ReceiverEvent - ); - - // ERC1155Receiver - #[abi(embed_v0)] - impl ERC1155ReceiverImpl = - ERC1155ReceiverComponent::ERC1155ReceiverImpl; - impl ERC1155ReceiverInternalImpl = ERC1155ReceiverComponent::InternalImpl; - - // SRC5 - #[abi(embed_v0)] - impl SRC5Impl = SRC5Component::SRC5Impl; - - #[storage] - pub struct Storage { - #[substorage(v0)] - pub erc1155_receiver: ERC1155ReceiverComponent::Storage, - #[substorage(v0)] - pub src5: SRC5Component::Storage - } - - #[event] - #[derive(Drop, starknet::Event)] - enum Event { - #[flat] - ERC1155ReceiverEvent: ERC1155ReceiverComponent::Event, - #[flat] - SRC5Event: SRC5Component::Event - } - - #[constructor] - fn constructor(ref self: ContractState) { - self.erc1155_receiver.initializer(); - } -} - -#[starknet::contract] -pub(crate) mod CamelERC1155ReceiverMock { - use crate::erc1155::ERC1155ReceiverComponent; - use openzeppelin_introspection::src5::SRC5Component; - - component!(path: SRC5Component, storage: src5, event: SRC5Event); - component!( - path: ERC1155ReceiverComponent, storage: erc1155_receiver, event: ERC1155ReceiverEvent - ); - - // ERC1155Receiver - #[abi(embed_v0)] - impl ERC1155ReceiverCamelImpl = - ERC1155ReceiverComponent::ERC1155ReceiverCamelImpl; - impl ERC1155ReceiverInternalImpl = ERC1155ReceiverComponent::InternalImpl; - - // SRC5 - #[abi(embed_v0)] - impl SRC5Impl = SRC5Component::SRC5Impl; - - #[storage] - pub struct Storage { - #[substorage(v0)] - pub erc1155_receiver: ERC1155ReceiverComponent::Storage, - #[substorage(v0)] - pub src5: SRC5Component::Storage - } - - #[event] - #[derive(Drop, starknet::Event)] - enum Event { - #[flat] - ERC1155ReceiverEvent: ERC1155ReceiverComponent::Event, - #[flat] - SRC5Event: SRC5Component::Event - } - - #[constructor] - fn constructor(ref self: ContractState) { - self.erc1155_receiver.initializer(); - } -} - -#[starknet::contract] -pub(crate) mod SnakeERC1155ReceiverPanicMock { - use starknet::ContractAddress; - - #[storage] - pub struct Storage {} - - #[external(v0)] - fn on_erc1155_received( - self: @ContractState, - operator: ContractAddress, - from: ContractAddress, - token_id: u256, - value: u256, - data: Span - ) -> felt252 { - panic!("Some error"); - 3 - } - - #[external(v0)] - fn on_erc1155_batch_received( - self: @ContractState, - operator: ContractAddress, - from: ContractAddress, - tokenIds: Span, - values: Span, - data: Span - ) -> felt252 { - panic!("Some error"); - 3 - } -} - -#[starknet::contract] -pub(crate) mod CamelERC1155ReceiverPanicMock { - use starknet::ContractAddress; - - #[storage] - pub struct Storage {} - - #[external(v0)] - fn onERC1155Received( - self: @ContractState, - operator: ContractAddress, - from: ContractAddress, - tokenId: u256, - value: u256, - data: Span - ) -> felt252 { - panic!("Some error"); - 3 - } - - #[external(v0)] - fn onERC1155BatchReceived( - self: @ContractState, - operator: ContractAddress, - from: ContractAddress, - tokenIds: Span, - values: Span, - data: Span - ) -> felt252 { - panic!("Some error"); - 3 - } -} diff --git a/packages/token/src/tests/mocks/erc20_mocks.cairo b/packages/token/src/tests/mocks/erc20_mocks.cairo index bd53190b8..d6b0a799b 100644 --- a/packages/token/src/tests/mocks/erc20_mocks.cairo +++ b/packages/token/src/tests/mocks/erc20_mocks.cairo @@ -38,216 +38,3 @@ pub(crate) mod DualCaseERC20Mock { self.erc20.mint(recipient, initial_supply); } } - -#[starknet::contract] -pub(crate) mod SnakeERC20Mock { - use crate::erc20::{ERC20Component, ERC20HooksEmptyImpl}; - use starknet::ContractAddress; - - component!(path: ERC20Component, storage: erc20, event: ERC20Event); - - #[abi(embed_v0)] - impl ERC20Impl = ERC20Component::ERC20Impl; - #[abi(embed_v0)] - impl ERC20MetadataImpl = ERC20Component::ERC20MetadataImpl; - impl InternalImpl = ERC20Component::InternalImpl; - - #[storage] - pub struct Storage { - #[substorage(v0)] - pub erc20: ERC20Component::Storage - } - - #[event] - #[derive(Drop, starknet::Event)] - enum Event { - #[flat] - ERC20Event: ERC20Component::Event - } - - #[constructor] - fn constructor( - ref self: ContractState, - name: ByteArray, - symbol: ByteArray, - initial_supply: u256, - recipient: ContractAddress - ) { - self.erc20.initializer(name, symbol); - self.erc20.mint(recipient, initial_supply); - } -} - -#[starknet::contract] -pub(crate) mod CamelERC20Mock { - use crate::erc20::{ERC20Component, ERC20HooksEmptyImpl}; - use starknet::ContractAddress; - - component!(path: ERC20Component, storage: erc20, event: ERC20Event); - - #[abi(embed_v0)] - impl ERC20MetadataImpl = ERC20Component::ERC20MetadataImpl; - #[abi(embed_v0)] - impl ERC20CamelOnlyImpl = ERC20Component::ERC20CamelOnlyImpl; - - // `ERC20Impl` is not embedded because it would defeat the purpose of the - // mock. The `ERC20Impl` case-agnostic methods are manually exposed. - impl ERC20Impl = ERC20Component::ERC20Impl; - impl InternalImpl = ERC20Component::InternalImpl; - - #[storage] - pub struct Storage { - #[substorage(v0)] - pub erc20: ERC20Component::Storage - } - - #[event] - #[derive(Drop, starknet::Event)] - enum Event { - #[flat] - ERC20Event: ERC20Component::Event - } - - #[constructor] - fn constructor( - ref self: ContractState, - name: ByteArray, - symbol: ByteArray, - initial_supply: u256, - recipient: ContractAddress - ) { - self.erc20.initializer(name, symbol); - self.erc20.mint(recipient, initial_supply); - } - - #[abi(per_item)] - #[generate_trait] - impl ExternalImpl of ExternalTrait { - #[external(v0)] - fn allowance( - self: @ContractState, owner: ContractAddress, spender: ContractAddress - ) -> u256 { - self.erc20.allowance(owner, spender) - } - - #[external(v0)] - fn transfer(ref self: ContractState, recipient: ContractAddress, amount: u256) -> bool { - self.erc20.transfer(recipient, amount) - } - - #[external(v0)] - fn approve(ref self: ContractState, spender: ContractAddress, amount: u256) -> bool { - self.erc20.approve(spender, amount) - } - } -} - -/// Although these modules are designed to panic, functions -/// still need a valid return value. We chose: -/// -/// 3 for felt252, u8, and u256 -/// zero for ContractAddress -/// false for bool -#[starknet::contract] -pub(crate) mod SnakeERC20Panic { - use starknet::ContractAddress; - - #[storage] - pub struct Storage {} - - #[abi(per_item)] - #[generate_trait] - impl ExternalImpl of ExternalTrait { - #[external(v0)] - fn name(self: @ContractState) -> ByteArray { - panic!("Some error"); - "3" - } - - #[external(v0)] - fn symbol(self: @ContractState) -> ByteArray { - panic!("Some error"); - "3" - } - - #[external(v0)] - fn decimals(self: @ContractState) -> u8 { - panic!("Some error"); - 3 - } - - #[external(v0)] - fn allowance( - self: @ContractState, owner: ContractAddress, spender: ContractAddress - ) -> u256 { - panic!("Some error"); - 3 - } - - #[external(v0)] - fn transfer(ref self: ContractState, recipient: ContractAddress, amount: u256) -> bool { - panic!("Some error"); - false - } - - #[external(v0)] - fn approve(ref self: ContractState, to: ContractAddress, token_id: u256) -> bool { - panic!("Some error"); - false - } - - #[external(v0)] - fn total_supply(self: @ContractState) -> u256 { - panic!("Some error"); - 3 - } - - #[external(v0)] - fn balance_of(self: @ContractState, account: ContractAddress) -> u256 { - panic!("Some error"); - 3 - } - - #[external(v0)] - fn transfer_from( - ref self: ContractState, from: ContractAddress, to: ContractAddress, amount: u256 - ) -> bool { - panic!("Some error"); - false - } - } -} - -#[starknet::contract] -pub(crate) mod CamelERC20Panic { - use starknet::ContractAddress; - - #[storage] - pub struct Storage {} - - #[abi(per_item)] - #[generate_trait] - impl ExternalImpl of ExternalTrait { - #[external(v0)] - fn totalSupply(self: @ContractState) -> u256 { - panic!("Some error"); - 3 - } - - #[external(v0)] - fn balanceOf(self: @ContractState, account: ContractAddress) -> u256 { - panic!("Some error"); - 3 - } - - #[external(v0)] - fn transferFrom( - ref self: ContractState, - sender: ContractAddress, - recipient: ContractAddress, - amount: u256 - ) { - panic!("Some error"); - } - } -} diff --git a/packages/token/src/tests/mocks/erc721_enumerable_mocks.cairo b/packages/token/src/tests/mocks/erc721_enumerable_mocks.cairo index 117bf0237..096dea067 100644 --- a/packages/token/src/tests/mocks/erc721_enumerable_mocks.cairo +++ b/packages/token/src/tests/mocks/erc721_enumerable_mocks.cairo @@ -73,77 +73,3 @@ pub(crate) mod ERC721EnumerableMock { self.erc721.mint(recipient, token_id); } } - -#[starknet::contract] -pub(crate) mod SnakeERC721EnumerableMock { - use crate::erc721::ERC721Component; - use crate::erc721::extensions::ERC721EnumerableComponent; - use openzeppelin_introspection::src5::SRC5Component; - - use starknet::ContractAddress; - - component!(path: ERC721Component, storage: erc721, event: ERC721Event); - component!( - path: ERC721EnumerableComponent, storage: erc721_enumerable, event: ERC721EnumerableEvent - ); - component!(path: SRC5Component, storage: src5, event: SRC5Event); - - // ERC721 - impl ERC721InternalImpl = ERC721Component::InternalImpl; - - // ERC721Enumerable - #[abi(embed_v0)] - impl ERC721EnumerableImpl = - ERC721EnumerableComponent::ERC721EnumerableImpl; - impl ERC721EnumerableInternalImpl = ERC721EnumerableComponent::InternalImpl; - - // SRC5 - impl SRC5Impl = SRC5Component::SRC5Impl; - - #[storage] - pub struct Storage { - #[substorage(v0)] - pub erc721: ERC721Component::Storage, - #[substorage(v0)] - pub erc721_enumerable: ERC721EnumerableComponent::Storage, - #[substorage(v0)] - pub src5: SRC5Component::Storage - } - - #[event] - #[derive(Drop, starknet::Event)] - enum Event { - #[flat] - ERC721Event: ERC721Component::Event, - #[flat] - ERC721EnumerableEvent: ERC721EnumerableComponent::Event, - #[flat] - SRC5Event: SRC5Component::Event - } - - impl ERC721HooksImpl of ERC721Component::ERC721HooksTrait { - fn before_update( - ref self: ERC721Component::ComponentState, - to: ContractAddress, - token_id: u256, - auth: ContractAddress - ) { - let mut contract_state = ERC721Component::HasComponent::get_contract_mut(ref self); - contract_state.erc721_enumerable.before_update(to, token_id); - } - } - - #[constructor] - fn constructor( - ref self: ContractState, - name: ByteArray, - symbol: ByteArray, - base_uri: ByteArray, - recipient: ContractAddress, - token_id: u256 - ) { - self.erc721.initializer(name, symbol, base_uri); - self.erc721_enumerable.initializer(); - self.erc721.mint(recipient, token_id); - } -} diff --git a/packages/token/src/tests/mocks/erc721_mocks.cairo b/packages/token/src/tests/mocks/erc721_mocks.cairo index 0d44f6944..432c72da9 100644 --- a/packages/token/src/tests/mocks/erc721_mocks.cairo +++ b/packages/token/src/tests/mocks/erc721_mocks.cairo @@ -53,295 +53,3 @@ pub(crate) mod DualCaseERC721Mock { self.erc721.mint(recipient, token_id); } } - -#[starknet::contract] -pub(crate) mod SnakeERC721Mock { - use crate::erc721::{ERC721Component, ERC721HooksEmptyImpl}; - use openzeppelin_introspection::src5::SRC5Component; - use starknet::ContractAddress; - - component!(path: ERC721Component, storage: erc721, event: ERC721Event); - component!(path: SRC5Component, storage: src5, event: SRC5Event); - - // ERC721 - #[abi(embed_v0)] - impl ERC721Impl = ERC721Component::ERC721Impl; - #[abi(embed_v0)] - impl ERC721MetadataImpl = ERC721Component::ERC721MetadataImpl; - impl ERC721InternalImpl = ERC721Component::InternalImpl; - - // SRC5 - #[abi(embed_v0)] - impl SRC5Impl = SRC5Component::SRC5Impl; - - #[storage] - pub struct Storage { - #[substorage(v0)] - pub erc721: ERC721Component::Storage, - #[substorage(v0)] - pub src5: SRC5Component::Storage - } - - #[event] - #[derive(Drop, starknet::Event)] - enum Event { - #[flat] - ERC721Event: ERC721Component::Event, - #[flat] - SRC5Event: SRC5Component::Event - } - - #[constructor] - fn constructor( - ref self: ContractState, - name: ByteArray, - symbol: ByteArray, - base_uri: ByteArray, - recipient: ContractAddress, - token_id: u256 - ) { - self.erc721.initializer(name, symbol, base_uri); - self.erc721.mint(recipient, token_id); - } -} - -#[starknet::contract] -pub(crate) mod CamelERC721Mock { - use crate::erc721::ERC721Component::{ERC721Impl, ERC721MetadataImpl}; - use crate::erc721::{ERC721Component, ERC721HooksEmptyImpl}; - use openzeppelin_introspection::src5::SRC5Component; - use starknet::ContractAddress; - - component!(path: ERC721Component, storage: erc721, event: ERC721Event); - component!(path: SRC5Component, storage: src5, event: SRC5Event); - - // ERC721 - #[abi(embed_v0)] - impl ERC721CamelOnly = ERC721Component::ERC721CamelOnlyImpl; - #[abi(embed_v0)] - impl ERC721MetadataCamelOnly = - ERC721Component::ERC721MetadataCamelOnlyImpl; - impl ERC721InternalImpl = ERC721Component::InternalImpl; - - // SRC5 - #[abi(embed_v0)] - impl SRC5Impl = SRC5Component::SRC5Impl; - - #[storage] - pub struct Storage { - #[substorage(v0)] - pub erc721: ERC721Component::Storage, - #[substorage(v0)] - pub src5: SRC5Component::Storage - } - - #[event] - #[derive(Drop, starknet::Event)] - enum Event { - #[flat] - ERC721Event: ERC721Component::Event, - #[flat] - SRC5Event: SRC5Component::Event - } - - #[constructor] - fn constructor( - ref self: ContractState, - name: ByteArray, - symbol: ByteArray, - base_uri: ByteArray, - recipient: ContractAddress, - token_id: u256 - ) { - self.erc721.initializer(name, symbol, base_uri); - self.erc721.mint(recipient, token_id); - } - - /// The following external methods are included because they are case-agnostic - /// and this contract should not embed the snake_case impl. - #[abi(per_item)] - #[generate_trait] - impl ExternalImpl of ExternalTrait { - #[external(v0)] - fn approve(ref self: ContractState, to: ContractAddress, tokenId: u256) { - self.erc721.approve(to, tokenId); - } - - #[external(v0)] - fn name(self: @ContractState) -> ByteArray { - self.erc721.name() - } - - #[external(v0)] - fn symbol(self: @ContractState) -> ByteArray { - self.erc721.symbol() - } - } -} - -/// Although these modules are designed to panic, functions -/// still need a valid return value. We chose: -/// -/// 3 for felt252 -/// zero for ContractAddress -/// u256 { 3, 3 } for u256 -#[starknet::contract] -pub(crate) mod SnakeERC721PanicMock { - use core::num::traits::Zero; - use starknet::ContractAddress; - - #[storage] - pub struct Storage {} - - #[abi(per_item)] - #[generate_trait] - impl ExternalImpl of ExternalTrait { - #[external(v0)] - fn name(self: @ContractState) -> ByteArray { - panic!("Some error"); - "3" - } - - #[external(v0)] - fn symbol(self: @ContractState) -> ByteArray { - panic!("Some error"); - "3" - } - - #[external(v0)] - fn approve(ref self: ContractState, to: ContractAddress, token_id: u256) { - panic!("Some error"); - } - - #[external(v0)] - fn supports_interface(self: @ContractState, interface_id: felt252) -> bool { - panic!("Some error"); - false - } - - #[external(v0)] - fn token_uri(self: @ContractState, token_id: u256) -> felt252 { - panic!("Some error"); - 3 - } - - #[external(v0)] - fn balance_of(self: @ContractState, account: ContractAddress) -> u256 { - panic!("Some error"); - u256 { low: 3, high: 3 } - } - - #[external(v0)] - fn owner_of(self: @ContractState, token_id: u256) -> ContractAddress { - panic!("Some error"); - Zero::zero() - } - - #[external(v0)] - fn get_approved(self: @ContractState, token_id: u256) -> ContractAddress { - panic!("Some error"); - Zero::zero() - } - - #[external(v0)] - fn is_approved_for_all( - self: @ContractState, owner: ContractAddress, operator: ContractAddress - ) -> bool { - panic!("Some error"); - false - } - - #[external(v0)] - fn set_approval_for_all( - ref self: ContractState, operator: ContractAddress, approved: bool - ) { - panic!("Some error"); - } - - #[external(v0)] - fn transfer_from( - ref self: ContractState, from: ContractAddress, to: ContractAddress, token_id: u256 - ) { - panic!("Some error"); - } - - #[external(v0)] - fn safe_transfer_from( - ref self: ContractState, - from: ContractAddress, - to: ContractAddress, - token_id: u256, - data: Span - ) { - panic!("Some error"); - } - } -} - -#[starknet::contract] -pub(crate) mod CamelERC721PanicMock { - use core::num::traits::Zero; - use starknet::ContractAddress; - - #[storage] - pub struct Storage {} - - #[abi(per_item)] - #[generate_trait] - impl ExternalImpl of ExternalTrait { - #[external(v0)] - fn tokenURI(self: @ContractState, tokenId: u256) -> felt252 { - panic!("Some error"); - 3 - } - - #[external(v0)] - fn balanceOf(self: @ContractState, account: ContractAddress) -> u256 { - panic!("Some error"); - u256 { low: 3, high: 3 } - } - - #[external(v0)] - fn ownerOf(self: @ContractState, tokenId: u256) -> ContractAddress { - panic!("Some error"); - Zero::zero() - } - - #[external(v0)] - fn getApproved(self: @ContractState, tokenId: u256) -> ContractAddress { - panic!("Some error"); - Zero::zero() - } - - #[external(v0)] - fn isApprovedForAll( - self: @ContractState, owner: ContractAddress, operator: ContractAddress - ) -> bool { - panic!("Some error"); - false - } - - #[external(v0)] - fn setApprovalForAll(ref self: ContractState, operator: ContractAddress, approved: bool) { - panic!("Some error"); - } - - #[external(v0)] - fn transferFrom( - ref self: ContractState, from: ContractAddress, to: ContractAddress, tokenId: u256 - ) { - panic!("Some error"); - } - - #[external(v0)] - fn safeTransferFrom( - ref self: ContractState, - from: ContractAddress, - to: ContractAddress, - tokenId: u256, - data: Span - ) { - panic!("Some error"); - } - } -} diff --git a/packages/token/src/tests/mocks/erc721_receiver_mocks.cairo b/packages/token/src/tests/mocks/erc721_receiver_mocks.cairo index c65796186..6df306fbd 100644 --- a/packages/token/src/tests/mocks/erc721_receiver_mocks.cairo +++ b/packages/token/src/tests/mocks/erc721_receiver_mocks.cairo @@ -69,169 +69,3 @@ pub(crate) mod DualCaseERC721ReceiverMock { } } } - -#[starknet::contract] -pub(crate) mod SnakeERC721ReceiverMock { - use crate::erc721::ERC721ReceiverComponent; - use openzeppelin_introspection::src5::SRC5Component; - use starknet::ContractAddress; - - component!(path: ERC721ReceiverComponent, storage: erc721_receiver, event: ERC721ReceiverEvent); - component!(path: SRC5Component, storage: src5, event: SRC5Event); - - // ERC721Receiver - impl ERC721ReceiverImpl = ERC721ReceiverComponent::ERC721ReceiverImpl; - impl ERC721ReceiverInternalImpl = ERC721ReceiverComponent::InternalImpl; - - // SRC5 - #[abi(embed_v0)] - impl SRC5Impl = SRC5Component::SRC5Impl; - - #[storage] - pub struct Storage { - #[substorage(v0)] - pub erc721_receiver: ERC721ReceiverComponent::Storage, - #[substorage(v0)] - pub src5: SRC5Component::Storage - } - - #[event] - #[derive(Drop, starknet::Event)] - enum Event { - #[flat] - ERC721ReceiverEvent: ERC721ReceiverComponent::Event, - #[flat] - SRC5Event: SRC5Component::Event - } - - #[constructor] - fn constructor(ref self: ContractState) { - self.erc721_receiver.initializer(); - } - - #[abi(per_item)] - #[generate_trait] - impl ExternalImpl of ExternalTrait { - #[external(v0)] - fn on_erc721_received( - self: @ContractState, - operator: ContractAddress, - from: ContractAddress, - token_id: u256, - data: Span - ) -> felt252 { - if *data.at(0) == super::SUCCESS { - self.erc721_receiver.on_erc721_received(operator, from, token_id, data) - } else { - 0 - } - } - } -} - -#[starknet::contract] -pub(crate) mod CamelERC721ReceiverMock { - use crate::erc721::ERC721ReceiverComponent; - use openzeppelin_introspection::src5::SRC5Component; - use starknet::ContractAddress; - - component!(path: ERC721ReceiverComponent, storage: erc721_receiver, event: ERC721ReceiverEvent); - component!(path: SRC5Component, storage: src5, event: SRC5Event); - - // ERC721Receiver - impl ERC721ReceiverCamelImpl = ERC721ReceiverComponent::ERC721ReceiverCamelImpl; - impl ERC721ReceiverInternalImpl = ERC721ReceiverComponent::InternalImpl; - - // SRC5 - #[abi(embed_v0)] - impl SRC5Impl = SRC5Component::SRC5Impl; - - #[storage] - pub struct Storage { - #[substorage(v0)] - pub erc721_receiver: ERC721ReceiverComponent::Storage, - #[substorage(v0)] - pub src5: SRC5Component::Storage - } - - #[event] - #[derive(Drop, starknet::Event)] - enum Event { - #[flat] - ERC721ReceiverEvent: ERC721ReceiverComponent::Event, - #[flat] - SRC5Event: SRC5Component::Event - } - - #[constructor] - fn constructor(ref self: ContractState) { - self.erc721_receiver.initializer(); - } - - #[abi(per_item)] - #[generate_trait] - impl ExternalImpl of ExternalTrait { - #[external(v0)] - fn onERC721Received( - self: @ContractState, - operator: ContractAddress, - from: ContractAddress, - tokenId: u256, - data: Span - ) -> felt252 { - if *data.at(0) == super::SUCCESS { - self.erc721_receiver.onERC721Received(operator, from, tokenId, data) - } else { - 0 - } - } - } -} - -#[starknet::contract] -pub(crate) mod SnakeERC721ReceiverPanicMock { - use starknet::ContractAddress; - - #[storage] - pub struct Storage {} - - #[abi(per_item)] - #[generate_trait] - impl ExternalImpl of ExternalTrait { - #[external(v0)] - fn on_erc721_received( - self: @ContractState, - operator: ContractAddress, - from: ContractAddress, - token_id: u256, - data: Span - ) -> felt252 { - panic!("Some error"); - 3 - } - } -} - -#[starknet::contract] -pub(crate) mod CamelERC721ReceiverPanicMock { - use starknet::ContractAddress; - - #[storage] - pub struct Storage {} - - #[abi(per_item)] - #[generate_trait] - impl ExternalImpl of ExternalTrait { - #[external(v0)] - fn onERC721Received( - self: @ContractState, - operator: ContractAddress, - from: ContractAddress, - tokenId: u256, - data: Span - ) -> felt252 { - panic!("Some error"); - 3 - } - } -} diff --git a/packages/token/src/tests/mocks/non_implementing_mock.cairo b/packages/token/src/tests/mocks/non_implementing_mock.cairo deleted file mode 100644 index 67d632c72..000000000 --- a/packages/token/src/tests/mocks/non_implementing_mock.cairo +++ /dev/null @@ -1,10 +0,0 @@ -#[starknet::contract] -pub(crate) mod NonImplementingMock { - #[storage] - pub struct Storage {} - - #[external(v0)] - fn nope(self: @ContractState) -> bool { - false - } -} diff --git a/packages/utils/README.md b/packages/utils/README.md index bb6cdc520..00d094f37 100644 --- a/packages/utils/README.md +++ b/packages/utils/README.md @@ -10,7 +10,6 @@ This crate provides components and libraries containing miscellaneous utilities. - [`cryptography`](https://docs.openzeppelin.com/contracts-cairo/0.17.0/api/utilities#cryptography) - [`deployments`](https://docs.openzeppelin.com/contracts-cairo/0.17.0/api/utilities#deployments) - [`math`](https://docs.openzeppelin.com/contracts-cairo/0.17.0/api/utilities#math) -- [`selectors`](https://docs.openzeppelin.com/contracts-cairo/0.17.0/api/utilities#selectors) - [`serde`](https://docs.openzeppelin.com/contracts-cairo/0.17.0/api/utilities#serde) ### Cryptography diff --git a/packages/utils/src/lib.cairo b/packages/utils/src/lib.cairo index 074486181..2e96323af 100644 --- a/packages/utils/src/lib.cairo +++ b/packages/utils/src/lib.cairo @@ -5,32 +5,10 @@ pub mod cryptography; pub mod deployments; pub mod interfaces; pub mod math; -pub mod selectors; pub mod serde; pub mod structs; #[cfg(test)] mod tests; -pub mod unwrap_and_cast; - pub use cryptography::{nonces, snip12}; -pub use unwrap_and_cast::UnwrapAndCast; -use starknet::syscalls::call_contract_syscall; - -use starknet::{ContractAddress, SyscallResult}; - -pub fn try_selector_with_fallback( - target: ContractAddress, selector: felt252, fallback: felt252, args: Span -) -> SyscallResult> { - match call_contract_syscall(target, selector, args) { - Result::Ok(ret) => Result::Ok(ret), - Result::Err(errors) => { - if *errors.at(0) == 'ENTRYPOINT_NOT_FOUND' { - return call_contract_syscall(target, fallback, args); - } else { - Result::Err(errors) - } - } - } -} diff --git a/packages/utils/src/selectors.cairo b/packages/utils/src/selectors.cairo deleted file mode 100644 index 90281206e..000000000 --- a/packages/utils/src/selectors.cairo +++ /dev/null @@ -1,104 +0,0 @@ -// SPDX-License-Identifier: MIT -// OpenZeppelin Contracts for Cairo v0.17.0 (utils/selectors.cairo) - -// -// AccessControl -// - -pub const get_role_admin: felt252 = selector!("get_role_admin"); -pub const getRoleAdmin: felt252 = selector!("getRoleAdmin"); -pub const grant_role: felt252 = selector!("grant_role"); -pub const grantRole: felt252 = selector!("grantRole"); -pub const has_role: felt252 = selector!("has_role"); -pub const hasRole: felt252 = selector!("hasRole"); -pub const renounce_role: felt252 = selector!("renounce_role"); -pub const renounceRole: felt252 = selector!("renounceRole"); -pub const revoke_role: felt252 = selector!("revoke_role"); -pub const revokeRole: felt252 = selector!("revokeRole"); - -// -// Ownable -// - -pub const owner: felt252 = selector!("owner"); -pub const transfer_ownership: felt252 = selector!("transfer_ownership"); -pub const transferOwnership: felt252 = selector!("transferOwnership"); -pub const renounce_ownership: felt252 = selector!("renounce_ownership"); -pub const renounceOwnership: felt252 = selector!("renounceOwnership"); - -// -// ERC721 -// - -pub const name: felt252 = selector!("name"); -pub const symbol: felt252 = selector!("symbol"); -pub const token_uri: felt252 = selector!("token_uri"); -pub const tokenURI: felt252 = selector!("tokenURI"); -pub const balance_of: felt252 = selector!("balance_of"); -pub const balanceOf: felt252 = selector!("balanceOf"); -pub const owner_of: felt252 = selector!("owner_of"); -pub const ownerOf: felt252 = selector!("ownerOf"); -pub const get_approved: felt252 = selector!("get_approved"); -pub const getApproved: felt252 = selector!("getApproved"); -pub const is_approved_for_all: felt252 = selector!("is_approved_for_all"); -pub const isApprovedForAll: felt252 = selector!("isApprovedForAll"); -pub const approve: felt252 = selector!("approve"); -pub const set_approval_for_all: felt252 = selector!("set_approval_for_all"); -pub const setApprovalForAll: felt252 = selector!("setApprovalForAll"); -pub const transfer_from: felt252 = selector!("transfer_from"); -pub const transferFrom: felt252 = selector!("transferFrom"); -pub const safe_transfer_from: felt252 = selector!("safe_transfer_from"); -pub const safeTransferFrom: felt252 = selector!("safeTransferFrom"); - -// -// ERC721Receiver -// - -pub const on_erc721_received: felt252 = selector!("on_erc721_received"); -pub const onERC721Received: felt252 = selector!("onERC721Received"); - -// -// ERC1155 -// - -// The following ERC1155 selectors are already defined in ERC721 above: -// balance_of, balanceOf, set_approval_for_all, -// setApprovalForAll, safe_transfer_from, safeTransferFrom -pub const uri: felt252 = selector!("uri"); -pub const balance_of_batch: felt252 = selector!("balance_of_batch"); -pub const balanceOfBatch: felt252 = selector!("balanceOfBatch"); -pub const safe_batch_transfer_from: felt252 = selector!("safe_batch_transfer_from"); -pub const safeBatchTransferFrom: felt252 = selector!("safeBatchTransferFrom"); - -// -// ERC1155Receiver -// - -pub const on_erc1155_received: felt252 = selector!("on_erc1155_received"); -pub const onERC1155Received: felt252 = selector!("onERC1155Received"); -pub const on_erc1155_batch_received: felt252 = selector!("on_erc1155_batch_received"); -pub const onERC1155BatchReceived: felt252 = selector!("onERC1155BatchReceived"); - -// -// ERC20 -// - -// The following ERC20 selectors are already defined in ERC721 above: -// name, symbol, balance_of, balanceOf, transfer_from, transferFrom, approve -pub const decimals: felt252 = selector!("decimals"); -pub const total_supply: felt252 = selector!("total_supply"); -pub const totalSupply: felt252 = selector!("totalSupply"); -pub const allowance: felt252 = selector!("allowance"); -pub const transfer: felt252 = selector!("transfer"); - -// -// Account -// - -pub const set_public_key: felt252 = selector!("set_public_key"); -pub const setPublicKey: felt252 = selector!("setPublicKey"); -pub const get_public_key: felt252 = selector!("get_public_key"); -pub const getPublicKey: felt252 = selector!("getPublicKey"); -pub const is_valid_signature: felt252 = selector!("is_valid_signature"); -pub const isValidSignature: felt252 = selector!("isValidSignature"); -pub const supports_interface: felt252 = selector!("supports_interface"); diff --git a/packages/utils/src/unwrap_and_cast.cairo b/packages/utils/src/unwrap_and_cast.cairo deleted file mode 100644 index a21d36004..000000000 --- a/packages/utils/src/unwrap_and_cast.cairo +++ /dev/null @@ -1,16 +0,0 @@ -// SPDX-License-Identifier: MIT -// OpenZeppelin Contracts for Cairo v0.17.0 (utils/unwrap_and_cast.cairo) - -use starknet::SyscallResult; -use starknet::SyscallResultTrait; - -pub trait UnwrapAndCast { - fn unwrap_and_cast(self: SyscallResult>) -> T; -} - -impl UnwrapAndCastSerde> of UnwrapAndCast { - fn unwrap_and_cast(self: SyscallResult>) -> T { - let mut result = self.unwrap_syscall(); - Serde::::deserialize(ref result).unwrap() - } -}