From 420f320084033628d8aa4477107d84f2c21e0eea Mon Sep 17 00:00:00 2001 From: Eric Nordelo Date: Wed, 27 Sep 2023 16:09:54 +0200 Subject: [PATCH] Sanitizing for release. (#736) * refactor: sanitizing * feat: sanitizing * feat: apply review updates * feat: apply review updates --- src/access/accesscontrol/accesscontrol.cairo | 9 ++--- .../accesscontrol/dual_accesscontrol.cairo | 2 - src/access/ownable/dual_ownable.cairo | 6 --- src/access/ownable/ownable.cairo | 1 - src/account.cairo | 2 - src/account/account.cairo | 33 ++++------------ src/account/dual_account.cairo | 2 - src/account/interface.cairo | 2 - src/introspection/dual_src5.cairo | 1 - src/introspection/src5.cairo | 5 +++ src/tests/access/test_accesscontrol.cairo | 1 - .../access/test_dual_accesscontrol.cairo | 1 - src/tests/access/test_dual_ownable.cairo | 16 +------- src/tests/access/test_ownable.cairo | 2 - src/tests/account/test_account.cairo | 7 +--- src/tests/introspection/test_dual_src5.cairo | 1 - src/tests/mocks/erc721_receiver.cairo | 4 +- src/tests/mocks/upgrades_v1.cairo | 1 - src/tests/mocks/upgrades_v2.cairo | 1 - src/tests/security/test_pausable.cairo | 1 - src/tests/token/test_dual20.cairo | 29 ++------------ src/tests/token/test_dual721.cairo | 38 ++----------------- src/tests/token/test_dual721_receiver.cairo | 30 +-------------- src/tests/token/test_erc20.cairo | 5 --- src/tests/token/test_erc721.cairo | 18 +-------- src/tests/upgrades/test_upgradeable.cairo | 14 +------ src/tests/utils.cairo | 1 - src/tests/utils/constants.cairo | 18 +++++++++ src/token/erc20/dual20.cairo | 1 - src/token/erc20/erc20.cairo | 1 - src/token/erc721/dual721.cairo | 1 - src/token/erc721/dual721_receiver.cairo | 2 - src/token/erc721/erc721.cairo | 14 ++----- src/token/erc721/interface.cairo | 1 - src/upgrades/upgradeable.cairo | 1 - src/utils.cairo | 4 -- src/utils/serde.cairo | 2 - src/utils/unwrap_and_cast.cairo | 4 -- 38 files changed, 51 insertions(+), 231 deletions(-) diff --git a/src/access/accesscontrol/accesscontrol.cairo b/src/access/accesscontrol/accesscontrol.cairo index 0f3aa7535..cd7cdde3a 100644 --- a/src/access/accesscontrol/accesscontrol.cairo +++ b/src/access/accesscontrol/accesscontrol.cairo @@ -7,6 +7,7 @@ mod AccessControl { use openzeppelin::introspection::interface::ISRC5; use openzeppelin::introspection::interface::ISRC5Camel; use openzeppelin::introspection::src5::SRC5; + use openzeppelin::introspection::src5::unsafe_state as src5_state; use starknet::ContractAddress; use starknet::get_caller_address; @@ -66,16 +67,14 @@ mod AccessControl { #[external(v0)] impl SRC5Impl of ISRC5 { fn supports_interface(self: @ContractState, interface_id: felt252) -> bool { - let unsafe_state = SRC5::unsafe_new_contract_state(); - SRC5::SRC5Impl::supports_interface(@unsafe_state, interface_id) + SRC5::SRC5Impl::supports_interface(@src5_state(), interface_id) } } #[external(v0)] impl SRC5CamelImpl of ISRC5Camel { fn supportsInterface(self: @ContractState, interfaceId: felt252) -> bool { - let unsafe_state = SRC5::unsafe_new_contract_state(); - SRC5::SRC5CamelImpl::supportsInterface(@unsafe_state, interfaceId) + SRC5::SRC5CamelImpl::supportsInterface(@src5_state(), interfaceId) } } @@ -138,7 +137,7 @@ mod AccessControl { #[generate_trait] impl InternalImpl of InternalTrait { fn initializer(ref self: ContractState) { - let mut unsafe_state = SRC5::unsafe_new_contract_state(); + let mut unsafe_state = src5_state(); SRC5::InternalImpl::register_interface(ref unsafe_state, interface::IACCESSCONTROL_ID); } diff --git a/src/access/accesscontrol/dual_accesscontrol.cairo b/src/access/accesscontrol/dual_accesscontrol.cairo index eb086840e..1fa18ff1d 100644 --- a/src/access/accesscontrol/dual_accesscontrol.cairo +++ b/src/access/accesscontrol/dual_accesscontrol.cairo @@ -1,8 +1,6 @@ // SPDX-License-Identifier: MIT // OpenZeppelin Contracts for Cairo v0.7.0 (access/accesscontrol/dual_accesscontrol.cairo) -use array::ArrayTrait; - use openzeppelin::utils::Felt252TryIntoBool; use openzeppelin::utils::UnwrapAndCast; use openzeppelin::utils::selectors; diff --git a/src/access/ownable/dual_ownable.cairo b/src/access/ownable/dual_ownable.cairo index 03d2ba51b..923f97c5b 100644 --- a/src/access/ownable/dual_ownable.cairo +++ b/src/access/ownable/dual_ownable.cairo @@ -1,21 +1,15 @@ // SPDX-License-Identifier: MIT // OpenZeppelin Contracts for Cairo v0.7.0 (access/ownable/dual_ownable.cairo) -use array::ArrayTrait; -use array::SpanTrait; -use core::result::ResultTrait; - use openzeppelin::utils::Felt252TryIntoBool; use openzeppelin::utils::UnwrapAndCast; use openzeppelin::utils::selectors; use openzeppelin::utils::serde::SerializedAppend; use openzeppelin::utils::try_selector_with_fallback; -use option::OptionTrait; use starknet::ContractAddress; use starknet::Felt252TryIntoContractAddress; use starknet::SyscallResultTrait; use starknet::call_contract_syscall; -use traits::TryInto; #[derive(Copy, Drop)] struct DualCaseOwnable { diff --git a/src/access/ownable/ownable.cairo b/src/access/ownable/ownable.cairo index 856de8190..9fac9da4a 100644 --- a/src/access/ownable/ownable.cairo +++ b/src/access/ownable/ownable.cairo @@ -6,7 +6,6 @@ mod Ownable { use openzeppelin::access::ownable::interface; use starknet::ContractAddress; use starknet::get_caller_address; - use zeroable::Zeroable; #[storage] struct Storage { diff --git a/src/account.cairo b/src/account.cairo index 1ca2c1578..501227b0b 100644 --- a/src/account.cairo +++ b/src/account.cairo @@ -3,8 +3,6 @@ mod dual_account; mod interface; use account::Account; -use account::QUERY_VERSION; -use account::TRANSACTION_VERSION; use interface::AccountABIDispatcher; use interface::AccountABIDispatcherTrait; use interface::AccountCamelABIDispatcher; diff --git a/src/account/account.cairo b/src/account/account.cairo index 90408a30f..ef73ef44a 100644 --- a/src/account/account.cairo +++ b/src/account/account.cairo @@ -1,18 +1,6 @@ // SPDX-License-Identifier: MIT // OpenZeppelin Contracts for Cairo v0.7.0 (account/account.cairo) -use array::ArrayTrait; -use array::SpanTrait; -use option::OptionTrait; -use serde::Serde; -use starknet::ContractAddress; -use starknet::account::Call; - -const TRANSACTION_VERSION: felt252 = 1; - -// 2**128 + TRANSACTION_VERSION -const QUERY_VERSION: felt252 = 340282366920938463463374607431768211457; - trait PublicKeyTrait { fn set_public_key(ref self: TState, new_public_key: felt252); fn get_public_key(self: @TState) -> felt252; @@ -25,24 +13,21 @@ trait PublicKeyCamelTrait { #[starknet::contract] mod Account { - use array::ArrayTrait; - use array::SpanTrait; - use box::BoxTrait; use ecdsa::check_ecdsa_signature; use openzeppelin::account::interface; use openzeppelin::introspection::interface::ISRC5; use openzeppelin::introspection::interface::ISRC5Camel; use openzeppelin::introspection::src5::SRC5; - use option::OptionTrait; + use openzeppelin::introspection::src5::unsafe_state as src5_state; + use starknet::account::Call; use starknet::get_caller_address; use starknet::get_contract_address; use starknet::get_tx_info; - use super::Call; - use super::QUERY_VERSION; - use super::TRANSACTION_VERSION; - use zeroable::Zeroable; + const TRANSACTION_VERSION: felt252 = 1; + // 2**128 + TRANSACTION_VERSION + const QUERY_VERSION: felt252 = 0x100000000000000000000000000000001; #[storage] struct Storage { @@ -134,16 +119,14 @@ mod Account { #[external(v0)] impl SRC5Impl of ISRC5 { fn supports_interface(self: @ContractState, interface_id: felt252) -> bool { - let unsafe_state = SRC5::unsafe_new_contract_state(); - SRC5::SRC5Impl::supports_interface(@unsafe_state, interface_id) + SRC5::SRC5Impl::supports_interface(@src5_state(), interface_id) } } #[external(v0)] impl SRC5CamelImpl of ISRC5Camel { fn supportsInterface(self: @ContractState, interfaceId: felt252) -> bool { - let unsafe_state = SRC5::unsafe_new_contract_state(); - SRC5::SRC5CamelImpl::supportsInterface(@unsafe_state, interfaceId) + SRC5::SRC5CamelImpl::supportsInterface(@src5_state(), interfaceId) } } @@ -188,7 +171,7 @@ mod Account { #[generate_trait] impl InternalImpl of InternalTrait { fn initializer(ref self: ContractState, _public_key: felt252) { - let mut unsafe_state = SRC5::unsafe_new_contract_state(); + let mut unsafe_state = src5_state(); SRC5::InternalImpl::register_interface(ref unsafe_state, interface::ISRC6_ID); self._set_public_key(_public_key); } diff --git a/src/account/dual_account.cairo b/src/account/dual_account.cairo index 9e4d321c8..0f0ddfdee 100644 --- a/src/account/dual_account.cairo +++ b/src/account/dual_account.cairo @@ -1,8 +1,6 @@ // SPDX-License-Identifier: MIT // OpenZeppelin Contracts for Cairo v0.7.0 (account/dual_account.cairo) -use array::ArrayTrait; -use array::SpanTrait; use openzeppelin::utils::UnwrapAndCast; use openzeppelin::utils::selectors; use openzeppelin::utils::serde::SerializedAppend; diff --git a/src/account/interface.cairo b/src/account/interface.cairo index b9a5abbef..e58c5bb30 100644 --- a/src/account/interface.cairo +++ b/src/account/interface.cairo @@ -1,8 +1,6 @@ // SPDX-License-Identifier: MIT // OpenZeppelin Contracts for Cairo v0.7.0 (account/interface.cairo) -use array::ArrayTrait; -use array::SpanTrait; use starknet::ContractAddress; use starknet::account::Call; diff --git a/src/introspection/dual_src5.cairo b/src/introspection/dual_src5.cairo index 48d7c9c68..6d68e89ec 100644 --- a/src/introspection/dual_src5.cairo +++ b/src/introspection/dual_src5.cairo @@ -1,7 +1,6 @@ // SPDX-License-Identifier: MIT // OpenZeppelin Contracts for Cairo v0.7.0 (introspection/dual_src5.cairo) -use array::ArrayTrait; use openzeppelin::utils::UnwrapAndCast; use openzeppelin::utils::selectors; use openzeppelin::utils::try_selector_with_fallback; diff --git a/src/introspection/src5.cairo b/src/introspection/src5.cairo index 3b94f4218..ec8ec85b5 100644 --- a/src/introspection/src5.cairo +++ b/src/introspection/src5.cairo @@ -43,3 +43,8 @@ mod SRC5 { } } } + +#[inline(always)] +fn unsafe_state() -> SRC5::ContractState { + SRC5::unsafe_new_contract_state() +} diff --git a/src/tests/access/test_accesscontrol.cairo b/src/tests/access/test_accesscontrol.cairo index c8aeab26b..d86dd4490 100644 --- a/src/tests/access/test_accesscontrol.cairo +++ b/src/tests/access/test_accesscontrol.cairo @@ -11,7 +11,6 @@ use openzeppelin::tests::utils::constants::{ ADMIN, AUTHORIZED, OTHER, OTHER_ADMIN, ROLE, OTHER_ROLE, ZERO }; use openzeppelin::tests::utils; -use option::OptionTrait; use starknet::ContractAddress; use starknet::contract_address_const; use starknet::testing; diff --git a/src/tests/access/test_dual_accesscontrol.cairo b/src/tests/access/test_dual_accesscontrol.cairo index 0a2f3527d..b7f922963 100644 --- a/src/tests/access/test_dual_accesscontrol.cairo +++ b/src/tests/access/test_dual_accesscontrol.cairo @@ -1,4 +1,3 @@ -use array::ArrayTrait; use openzeppelin::access::accesscontrol::DEFAULT_ADMIN_ROLE; use openzeppelin::access::accesscontrol::interface::IACCESSCONTROL_ID; use openzeppelin::access::accesscontrol::interface::IAccessControlDispatcherTrait; diff --git a/src/tests/access/test_dual_ownable.cairo b/src/tests/access/test_dual_ownable.cairo index 8055bd1fc..40f736bf5 100644 --- a/src/tests/access/test_dual_ownable.cairo +++ b/src/tests/access/test_dual_ownable.cairo @@ -9,25 +9,11 @@ use openzeppelin::tests::mocks::dual_ownable_mocks::CamelOwnablePanicMock; use openzeppelin::tests::mocks::dual_ownable_mocks::SnakeOwnableMock; use openzeppelin::tests::mocks::dual_ownable_mocks::SnakeOwnablePanicMock; use openzeppelin::tests::mocks::non_implementing_mock::NonImplementingMock; +use openzeppelin::tests::utils::constants::{OWNER, NEW_OWNER}; use openzeppelin::tests::utils; use openzeppelin::utils::serde::SerializedAppend; -use starknet::ContractAddress; -use starknet::contract_address_const; use starknet::testing::set_caller_address; use starknet::testing::set_contract_address; -use zeroable::Zeroable; - -// -// Constants -// - -fn OWNER() -> ContractAddress { - contract_address_const::<10>() -} - -fn NEW_OWNER() -> ContractAddress { - contract_address_const::<20>() -} // // Setup diff --git a/src/tests/access/test_ownable.cairo b/src/tests/access/test_ownable.cairo index 5c68a490a..8bb58ac01 100644 --- a/src/tests/access/test_ownable.cairo +++ b/src/tests/access/test_ownable.cairo @@ -6,11 +6,9 @@ use openzeppelin::access::ownable::Ownable::Ownable_owner::InternalContractMembe use openzeppelin::access::ownable::Ownable; use openzeppelin::tests::utils::constants::{ZERO, OTHER, OWNER}; use openzeppelin::tests::utils; -use option::OptionTrait; use starknet::ContractAddress; use starknet::contract_address_const; use starknet::testing; -use zeroable::Zeroable; // // Setup diff --git a/src/tests/account/test_account.cairo b/src/tests/account/test_account.cairo index 83bea533b..2ca9550a8 100644 --- a/src/tests/account/test_account.cairo +++ b/src/tests/account/test_account.cairo @@ -1,5 +1,3 @@ -use array::ArrayTrait; -use core::traits::Into; use openzeppelin::account::Account::OwnerAdded; use openzeppelin::account::Account::OwnerRemoved; use openzeppelin::account::Account::PublicKeyCamelImpl; @@ -7,8 +5,7 @@ use openzeppelin::account::Account::PublicKeyImpl; use openzeppelin::account::Account; use openzeppelin::account::AccountABIDispatcher; use openzeppelin::account::AccountABIDispatcherTrait; -use openzeppelin::account::QUERY_VERSION; -use openzeppelin::account::TRANSACTION_VERSION; +use openzeppelin::account::Account::{TRANSACTION_VERSION, QUERY_VERSION}; use openzeppelin::account::interface::ISRC6_ID; use openzeppelin::introspection::interface::ISRC5_ID; use openzeppelin::tests::utils; @@ -18,8 +15,6 @@ use openzeppelin::token::erc20::interface::IERC20Dispatcher; use openzeppelin::token::erc20::interface::IERC20DispatcherTrait; use openzeppelin::utils::selectors; use openzeppelin::utils::serde::SerializedAppend; -use option::OptionTrait; -use serde::Serde; use starknet::ContractAddress; use starknet::account::Call; use starknet::contract_address_const; diff --git a/src/tests/introspection/test_dual_src5.cairo b/src/tests/introspection/test_dual_src5.cairo index f2122f2e1..9720e8968 100644 --- a/src/tests/introspection/test_dual_src5.cairo +++ b/src/tests/introspection/test_dual_src5.cairo @@ -1,4 +1,3 @@ -use array::ArrayTrait; use openzeppelin::introspection::dual_src5::DualCaseSRC5; use openzeppelin::introspection::dual_src5::DualCaseSRC5Trait; use openzeppelin::introspection::interface::ISRC5CamelDispatcher; diff --git a/src/tests/mocks/erc721_receiver.cairo b/src/tests/mocks/erc721_receiver.cairo index 9205f6d97..240246019 100644 --- a/src/tests/mocks/erc721_receiver.cairo +++ b/src/tests/mocks/erc721_receiver.cairo @@ -1,9 +1,7 @@ -const SUCCESS: felt252 = 123123; -const FAILURE: felt252 = 456456; +use openzeppelin::tests::utils::constants::{FAILURE, SUCCESS}; #[starknet::contract] mod ERC721Receiver { - use array::SpanTrait; use openzeppelin::introspection::interface::ISRC5; use openzeppelin::introspection::interface::ISRC5Camel; use openzeppelin::introspection::src5::SRC5; diff --git a/src/tests/mocks/upgrades_v1.cairo b/src/tests/mocks/upgrades_v1.cairo index d851f59d9..37d5c19b3 100644 --- a/src/tests/mocks/upgrades_v1.cairo +++ b/src/tests/mocks/upgrades_v1.cairo @@ -2,7 +2,6 @@ // The functions are NOT PROTECTED. // DO NOT USE IN PRODUCTION. -use array::ArrayTrait; use starknet::ClassHash; #[starknet::interface] diff --git a/src/tests/mocks/upgrades_v2.cairo b/src/tests/mocks/upgrades_v2.cairo index f0ad60ee7..322c47ba1 100644 --- a/src/tests/mocks/upgrades_v2.cairo +++ b/src/tests/mocks/upgrades_v2.cairo @@ -2,7 +2,6 @@ // The functions are NOT PROTECTED. // DO NOT USE IN PRODUCTION. -use array::ArrayTrait; use starknet::ClassHash; #[starknet::interface] diff --git a/src/tests/security/test_pausable.cairo b/src/tests/security/test_pausable.cairo index 26497e121..faf1fcfc6 100644 --- a/src/tests/security/test_pausable.cairo +++ b/src/tests/security/test_pausable.cairo @@ -5,7 +5,6 @@ use openzeppelin::security::pausable::Pausable::Unpaused; use openzeppelin::security::pausable::Pausable; use openzeppelin::tests::utils::constants::{CALLER, ZERO}; use openzeppelin::tests::utils; -use option::OptionTrait; use starknet::contract_address_const; use starknet::ContractAddress; use starknet::testing; diff --git a/src/tests/token/test_dual20.cairo b/src/tests/token/test_dual20.cairo index aa0bd2306..948e1f882 100644 --- a/src/tests/token/test_dual20.cairo +++ b/src/tests/token/test_dual20.cairo @@ -1,9 +1,11 @@ -use array::ArrayTrait; use openzeppelin::tests::mocks::camel20_mock::CamelERC20Mock; use openzeppelin::tests::mocks::erc20_panic::CamelERC20Panic; use openzeppelin::tests::mocks::erc20_panic::SnakeERC20Panic; use openzeppelin::tests::mocks::non_implementing_mock::NonImplementingMock; use openzeppelin::tests::mocks::snake20_mock::SnakeERC20Mock; +use openzeppelin::tests::utils::constants::{ + OWNER, RECIPIENT, SPENDER, OPERATOR, NAME, SYMBOL, DECIMALS, SUPPLY, VALUE +}; use openzeppelin::tests::utils; use openzeppelin::token::erc20::dual20::DualCaseERC20; use openzeppelin::token::erc20::dual20::DualCaseERC20Trait; @@ -12,33 +14,8 @@ use openzeppelin::token::erc20::interface::IERC20CamelDispatcherTrait; use openzeppelin::token::erc20::interface::IERC20Dispatcher; use openzeppelin::token::erc20::interface::IERC20DispatcherTrait; use openzeppelin::utils::serde::SerializedAppend; -use starknet::ContractAddress; -use starknet::contract_address_const; use starknet::testing::set_contract_address; -// -// Constants -// - -const NAME: felt252 = 111; -const SYMBOL: felt252 = 222; -const DECIMALS: u8 = 18_u8; -const SUPPLY: u256 = 2000; -const VALUE: u256 = 300; - -fn OWNER() -> ContractAddress { - contract_address_const::<10>() -} -fn SPENDER() -> ContractAddress { - contract_address_const::<20>() -} -fn RECIPIENT() -> ContractAddress { - contract_address_const::<30>() -} -fn OPERATOR() -> ContractAddress { - contract_address_const::<40>() -} - // // Setup // diff --git a/src/tests/token/test_dual721.cairo b/src/tests/token/test_dual721.cairo index fc65cc426..0beb985a4 100644 --- a/src/tests/token/test_dual721.cairo +++ b/src/tests/token/test_dual721.cairo @@ -1,12 +1,12 @@ -use array::ArrayTrait; use openzeppelin::tests::mocks::camel721_mock::CamelERC721Mock; use openzeppelin::tests::mocks::erc721_panic_mock::CamelERC721PanicMock; use openzeppelin::tests::mocks::erc721_panic_mock::SnakeERC721PanicMock; use openzeppelin::tests::mocks::erc721_receiver::ERC721Receiver; -use openzeppelin::tests::mocks::erc721_receiver::FAILURE; -use openzeppelin::tests::mocks::erc721_receiver::SUCCESS; use openzeppelin::tests::mocks::non_implementing_mock::NonImplementingMock; use openzeppelin::tests::mocks::snake721_mock::SnakeERC721Mock; +use openzeppelin::tests::utils::constants::{ + DATA, OWNER, RECIPIENT, SPENDER, OPERATOR, OTHER, NAME, SYMBOL, URI, TOKEN_ID +}; use openzeppelin::tests::utils; use openzeppelin::token::erc721::dual721::DualCaseERC721; use openzeppelin::token::erc721::dual721::DualCaseERC721Trait; @@ -17,41 +17,9 @@ use openzeppelin::token::erc721::interface::IERC721DispatcherTrait; use openzeppelin::token::erc721::interface::IERC721_ID; use openzeppelin::utils::serde::SerializedAppend; use starknet::ContractAddress; -use starknet::contract_address_const; use starknet::testing::set_caller_address; use starknet::testing::set_contract_address; -// -// Constants -// - -const NAME: felt252 = 111; -const SYMBOL: felt252 = 222; -const URI: felt252 = 333; -const TOKEN_ID: u256 = 7; - -fn OWNER() -> ContractAddress { - contract_address_const::<10>() -} -fn RECIPIENT() -> ContractAddress { - contract_address_const::<20>() -} -fn SPENDER() -> ContractAddress { - contract_address_const::<30>() -} -fn OPERATOR() -> ContractAddress { - contract_address_const::<40>() -} -fn DATA(success: bool) -> Span { - let mut data = array![]; - if success { - data.append_serde(SUCCESS); - } else { - data.append_serde(FAILURE); - } - data.span() -} - // // Setup // diff --git a/src/tests/token/test_dual721_receiver.cairo b/src/tests/token/test_dual721_receiver.cairo index 876661b8c..84644dcf2 100644 --- a/src/tests/token/test_dual721_receiver.cairo +++ b/src/tests/token/test_dual721_receiver.cairo @@ -1,11 +1,9 @@ -use array::ArrayTrait; use openzeppelin::tests::mocks::dual721_receiver_mocks::CamelERC721ReceiverMock; use openzeppelin::tests::mocks::dual721_receiver_mocks::CamelERC721ReceiverPanicMock; use openzeppelin::tests::mocks::dual721_receiver_mocks::SnakeERC721ReceiverMock; use openzeppelin::tests::mocks::dual721_receiver_mocks::SnakeERC721ReceiverPanicMock; -use openzeppelin::tests::mocks::erc721_receiver::FAILURE; -use openzeppelin::tests::mocks::erc721_receiver::SUCCESS; use openzeppelin::tests::mocks::non_implementing_mock::NonImplementingMock; +use openzeppelin::tests::utils::constants::{DATA, OPERATOR, OWNER, TOKEN_ID}; use openzeppelin::tests::utils; use openzeppelin::token::erc721::dual721_receiver::DualCaseERC721Receiver; use openzeppelin::token::erc721::dual721_receiver::DualCaseERC721ReceiverTrait; @@ -14,32 +12,6 @@ use openzeppelin::token::erc721::interface::IERC721ReceiverCamelDispatcherTrait; use openzeppelin::token::erc721::interface::IERC721ReceiverDispatcher; use openzeppelin::token::erc721::interface::IERC721ReceiverDispatcherTrait; use openzeppelin::token::erc721::interface::IERC721_RECEIVER_ID; -use starknet::ContractAddress; -use starknet::contract_address_const; - -// -// Constants -// - -const TOKEN_ID: u256 = 7; - -fn DATA(success: bool) -> Span { - let mut data = ArrayTrait::new(); - if success { - data.append(SUCCESS); - } else { - data.append(FAILURE); - } - data.span() -} - -fn OWNER() -> ContractAddress { - contract_address_const::<10>() -} - -fn OPERATOR() -> ContractAddress { - contract_address_const::<20>() -} // // Setup diff --git a/src/tests/token/test_erc20.cairo b/src/tests/token/test_erc20.cairo index 4109e909a..6ff440859 100644 --- a/src/tests/token/test_erc20.cairo +++ b/src/tests/token/test_erc20.cairo @@ -1,6 +1,4 @@ use integer::BoundedInt; -use integer::u256; -use integer::u256_from_felt252; use openzeppelin::tests::utils::constants::{ ZERO, OWNER, SPENDER, RECIPIENT, NAME, SYMBOL, DECIMALS, SUPPLY, VALUE }; @@ -11,12 +9,9 @@ use openzeppelin::token::erc20::ERC20::ERC20Impl; use openzeppelin::token::erc20::ERC20::InternalImpl; use openzeppelin::token::erc20::ERC20::Transfer; use openzeppelin::token::erc20::ERC20; -use option::OptionTrait; use starknet::ContractAddress; use starknet::contract_address_const; use starknet::testing; -use traits::Into; -use zeroable::Zeroable; // // Setup diff --git a/src/tests/token/test_erc721.cairo b/src/tests/token/test_erc721.cairo index 25265d7e4..4299928f9 100644 --- a/src/tests/token/test_erc721.cairo +++ b/src/tests/token/test_erc721.cairo @@ -1,7 +1,6 @@ use ERC721::ERC721_owners::InternalContractMemberStateTrait as OwnersTrait; use ERC721::ERC721_token_approvals::InternalContractMemberStateTrait as TokenApprovalsTrait; -use array::ArrayTrait; use integer::u256; use integer::u256_from_felt252; use openzeppelin::account::Account; @@ -10,11 +9,9 @@ use openzeppelin::introspection; use openzeppelin::tests::mocks::camel_account_mock::CamelAccountMock; use openzeppelin::tests::mocks::dual721_receiver_mocks::CamelERC721ReceiverMock; use openzeppelin::tests::mocks::erc721_receiver::ERC721Receiver; -use openzeppelin::tests::mocks::erc721_receiver::FAILURE; -use openzeppelin::tests::mocks::erc721_receiver::SUCCESS; use openzeppelin::tests::mocks::non_implementing_mock::NonImplementingMock; use openzeppelin::tests::utils::constants::{ - ZERO, OWNER, RECIPIENT, SPENDER, OPERATOR, OTHER, NAME, SYMBOL, URI, TOKEN_ID, PUBKEY, + DATA, ZERO, OWNER, RECIPIENT, SPENDER, OPERATOR, OTHER, NAME, SYMBOL, URI, TOKEN_ID, PUBKEY, }; use openzeppelin::tests::utils; use openzeppelin::token::erc721::ERC721::{ @@ -23,22 +20,9 @@ use openzeppelin::token::erc721::ERC721::{ }; use openzeppelin::token::erc721::ERC721; use openzeppelin::token::erc721; -use option::OptionTrait; use starknet::contract_address_const; use starknet::ContractAddress; use starknet::testing; -use traits::Into; -use zeroable::Zeroable; - -fn DATA(success: bool) -> Span { - let mut data = array![]; - if success { - data.append(SUCCESS); - } else { - data.append(FAILURE); - } - data.span() -} // // Setup diff --git a/src/tests/upgrades/test_upgradeable.cairo b/src/tests/upgrades/test_upgradeable.cairo index 20b9c48c3..c43f8518f 100644 --- a/src/tests/upgrades/test_upgradeable.cairo +++ b/src/tests/upgrades/test_upgradeable.cairo @@ -1,20 +1,16 @@ -use array::ArrayTrait; use openzeppelin::tests::mocks::upgrades_v1::IUpgradesV1Dispatcher; use openzeppelin::tests::mocks::upgrades_v1::IUpgradesV1DispatcherTrait; use openzeppelin::tests::mocks::upgrades_v2::IUpgradesV2Dispatcher; use openzeppelin::tests::mocks::upgrades_v2::IUpgradesV2DispatcherTrait; use openzeppelin::tests::mocks::upgrades_v1::UpgradesV1; use openzeppelin::tests::mocks::upgrades_v2::UpgradesV2; +use openzeppelin::tests::utils::constants::{CLASS_HASH_ZERO, ZERO}; use openzeppelin::tests::utils; use openzeppelin::upgrades::upgradeable::Upgradeable::Upgraded; -use option::OptionTrait; use starknet::ClassHash; use starknet::ContractAddress; use starknet::Felt252TryIntoClassHash; -use starknet::class_hash_const; -use starknet::contract_address_const; use starknet::testing; -use traits::TryInto; const VALUE: felt252 = 123; @@ -22,14 +18,6 @@ fn V2_CLASS_HASH() -> ClassHash { UpgradesV2::TEST_CLASS_HASH.try_into().unwrap() } -fn CLASS_HASH_ZERO() -> ClassHash { - class_hash_const::<0>() -} - -fn ZERO() -> ContractAddress { - contract_address_const::<0>() -} - // // Setup // diff --git a/src/tests/utils.cairo b/src/tests/utils.cairo index 77d711c53..e0ebeacb3 100644 --- a/src/tests/utils.cairo +++ b/src/tests/utils.cairo @@ -7,7 +7,6 @@ use option::OptionTrait; use starknet::class_hash::Felt252TryIntoClassHash; use starknet::ContractAddress; use starknet::testing; -use traits::TryInto; fn deploy(contract_class_hash: felt252, calldata: Array) -> ContractAddress { let (address, _) = starknet::deploy_syscall( diff --git a/src/tests/utils/constants.cairo b/src/tests/utils/constants.cairo index a66b6e721..73d22eb41 100644 --- a/src/tests/utils/constants.cairo +++ b/src/tests/utils/constants.cairo @@ -1,4 +1,6 @@ +use starknet::ClassHash; use starknet::ContractAddress; +use starknet::class_hash_const; use starknet::contract_address_const; const NAME: felt252 = 'NAME'; @@ -11,6 +13,8 @@ const OTHER_ROLE: felt252 = 'OTHER_ROLE'; const URI: felt252 = 'URI'; const TOKEN_ID: u256 = 21; const PUBKEY: felt252 = 'PUBKEY'; +const SUCCESS: felt252 = 123123; +const FAILURE: felt252 = 456456; fn ADMIN() -> ContractAddress { contract_address_const::<'ADMIN'>() @@ -24,6 +28,10 @@ fn ZERO() -> ContractAddress { contract_address_const::<0>() } +fn CLASS_HASH_ZERO() -> ClassHash { + class_hash_const::<0>() +} + fn CALLER() -> ContractAddress { contract_address_const::<'CALLER'>() } @@ -55,3 +63,13 @@ fn RECIPIENT() -> ContractAddress { fn OPERATOR() -> ContractAddress { contract_address_const::<'OPERATOR'>() } + +fn DATA(success: bool) -> Span { + let mut data = array![]; + if success { + data.append(SUCCESS); + } else { + data.append(FAILURE); + } + data.span() +} diff --git a/src/token/erc20/dual20.cairo b/src/token/erc20/dual20.cairo index dfb54584b..bbd8d8aae 100644 --- a/src/token/erc20/dual20.cairo +++ b/src/token/erc20/dual20.cairo @@ -1,7 +1,6 @@ // SPDX-License-Identifier: MIT // OpenZeppelin Contracts for Cairo v0.7.0 (token/erc20/dual20.cairo) -use array::ArrayTrait; use openzeppelin::utils::UnwrapAndCast; use openzeppelin::utils::selectors; use openzeppelin::utils::serde::SerializedAppend; diff --git a/src/token/erc20/erc20.cairo b/src/token/erc20/erc20.cairo index 36b32c593..c62cd3803 100644 --- a/src/token/erc20/erc20.cairo +++ b/src/token/erc20/erc20.cairo @@ -8,7 +8,6 @@ mod ERC20 { use openzeppelin::token::erc20::interface::IERC20CamelOnly; use starknet::ContractAddress; use starknet::get_caller_address; - use zeroable::Zeroable; #[storage] struct Storage { diff --git a/src/token/erc721/dual721.cairo b/src/token/erc721/dual721.cairo index 041f267a2..2df75e071 100644 --- a/src/token/erc721/dual721.cairo +++ b/src/token/erc721/dual721.cairo @@ -1,7 +1,6 @@ // SPDX-License-Identifier: MIT // OpenZeppelin Contracts for Cairo v0.7.0 (token/erc721/dual721.cairo) -use array::ArrayTrait; use openzeppelin::utils::UnwrapAndCast; use openzeppelin::utils::selectors; use openzeppelin::utils::serde::SerializedAppend; diff --git a/src/token/erc721/dual721_receiver.cairo b/src/token/erc721/dual721_receiver.cairo index 650285d6d..a32011a37 100644 --- a/src/token/erc721/dual721_receiver.cairo +++ b/src/token/erc721/dual721_receiver.cairo @@ -1,13 +1,11 @@ // SPDX-License-Identifier: MIT // OpenZeppelin Contracts for Cairo v0.7.0 (token/erc721/dual721_receiver.cairo) -use array::ArrayTrait; 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; #[derive(Copy, Drop)] struct DualCaseERC721Receiver { diff --git a/src/token/erc721/erc721.cairo b/src/token/erc721/erc721.cairo index 660a92919..d67952f2d 100644 --- a/src/token/erc721/erc721.cairo +++ b/src/token/erc721/erc721.cairo @@ -1,24 +1,20 @@ // SPDX-License-Identifier: MIT // OpenZeppelin Contracts for Cairo v0.7.0 (token/erc721/erc721.cairo) -use starknet::ContractAddress; - #[starknet::contract] mod ERC721 { - use array::SpanTrait; use openzeppelin::account; use openzeppelin::introspection::dual_src5::DualCaseSRC5; use openzeppelin::introspection::dual_src5::DualCaseSRC5Trait; use openzeppelin::introspection::interface::ISRC5; use openzeppelin::introspection::interface::ISRC5Camel; + use openzeppelin::introspection::src5::unsafe_state as src5_state; use openzeppelin::introspection::src5; use openzeppelin::token::erc721::dual721_receiver::DualCaseERC721Receiver; use openzeppelin::token::erc721::dual721_receiver::DualCaseERC721ReceiverTrait; use openzeppelin::token::erc721::interface; - use option::OptionTrait; use starknet::ContractAddress; use starknet::get_caller_address; - use zeroable::Zeroable; #[storage] struct Storage { @@ -92,16 +88,14 @@ mod ERC721 { #[external(v0)] impl SRC5Impl of ISRC5 { fn supports_interface(self: @ContractState, interface_id: felt252) -> bool { - let unsafe_state = src5::SRC5::unsafe_new_contract_state(); - src5::SRC5::SRC5Impl::supports_interface(@unsafe_state, interface_id) + src5::SRC5::SRC5Impl::supports_interface(@src5_state(), interface_id) } } #[external(v0)] impl SRC5CamelImpl of ISRC5Camel { fn supportsInterface(self: @ContractState, interfaceId: felt252) -> bool { - let unsafe_state = src5::SRC5::unsafe_new_contract_state(); - src5::SRC5::SRC5CamelImpl::supportsInterface(@unsafe_state, interfaceId) + src5::SRC5::SRC5CamelImpl::supportsInterface(@src5_state(), interfaceId) } } @@ -242,7 +236,7 @@ mod ERC721 { self.ERC721_name.write(name); self.ERC721_symbol.write(symbol); - let mut unsafe_state = src5::SRC5::unsafe_new_contract_state(); + let mut unsafe_state = src5_state(); src5::SRC5::InternalImpl::register_interface(ref unsafe_state, interface::IERC721_ID); src5::SRC5::InternalImpl::register_interface( ref unsafe_state, interface::IERC721_METADATA_ID diff --git a/src/token/erc721/interface.cairo b/src/token/erc721/interface.cairo index 86125721d..6fdc68272 100644 --- a/src/token/erc721/interface.cairo +++ b/src/token/erc721/interface.cairo @@ -1,7 +1,6 @@ // SPDX-License-Identifier: MIT // OpenZeppelin Contracts for Cairo v0.7.0 (token/erc721/interface.cairo) -use array::SpanTrait; use starknet::ContractAddress; const IERC721_ID: felt252 = 0x33eb2f84c309543403fd69f0d0f363781ef06ef6faeb0131ff16ea3175bd943; diff --git a/src/upgrades/upgradeable.cairo b/src/upgrades/upgradeable.cairo index b10978d85..de9e546f2 100644 --- a/src/upgrades/upgradeable.cairo +++ b/src/upgrades/upgradeable.cairo @@ -2,7 +2,6 @@ mod Upgradeable { use starknet::ClassHash; use starknet::SyscallResult; - use zeroable::Zeroable; #[storage] struct Storage {} diff --git a/src/utils.cairo b/src/utils.cairo index 38b0b35dd..5396a17f6 100644 --- a/src/utils.cairo +++ b/src/utils.cairo @@ -6,10 +6,6 @@ mod selectors; mod serde; mod unwrap_and_cast; -use array::ArrayTrait; -use array::SpanTrait; -use box::BoxTrait; -use option::OptionTrait; use starknet::ContractAddress; use starknet::SyscallResult; use starknet::SyscallResultTrait; diff --git a/src/utils/serde.cairo b/src/utils/serde.cairo index 23fdad21b..2a4951355 100644 --- a/src/utils/serde.cairo +++ b/src/utils/serde.cairo @@ -1,8 +1,6 @@ // SPDX-License-Identifier: MIT // OpenZeppelin Contracts for Cairo v0.7.0 (utils/serde.cairo) -use serde::Serde; - trait SerializedAppend { fn append_serde(ref self: Array, value: T); } diff --git a/src/utils/unwrap_and_cast.cairo b/src/utils/unwrap_and_cast.cairo index 9e58009a2..f625c08a2 100644 --- a/src/utils/unwrap_and_cast.cairo +++ b/src/utils/unwrap_and_cast.cairo @@ -1,15 +1,11 @@ // SPDX-License-Identifier: MIT // OpenZeppelin Contracts for Cairo v0.7.0 (utils/unwrap_and_cast.cairo) -use array::SpanTrait; - use openzeppelin::utils::Felt252TryIntoBool; -use option::OptionTrait; use starknet::ContractAddress; use starknet::Felt252TryIntoContractAddress; use starknet::SyscallResult; use starknet::SyscallResultTrait; -use traits::TryInto; trait UnwrapAndCast { fn unwrap_and_cast(self: SyscallResult>) -> T;