Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate Ownable to component #768

Merged
Merged
Show file tree
Hide file tree
Changes from 118 commits
Commits
Show all changes
119 commits
Select commit Hold shift + click to select a range
331844d
fix: link (#545)
ericnordelo Jan 20, 2023
b9ec20b
add submodule
andrew-fleming Feb 18, 2023
bb40124
update cairo
andrew-fleming Feb 18, 2023
a0c3157
add Cargo and Makefile
andrew-fleming Feb 18, 2023
3a6e20d
update cairo
andrew-fleming Feb 18, 2023
96431de
add deps in cairo_project, create lib
andrew-fleming Feb 18, 2023
7b38706
add presets
andrew-fleming Feb 18, 2023
2fa00dd
add base lib
andrew-fleming Feb 18, 2023
f0036e7
add tests
andrew-fleming Feb 18, 2023
8d781a8
remove old cairo lib and interface
andrew-fleming Feb 18, 2023
ae37b1c
remove unused import
andrew-fleming Feb 18, 2023
da57a91
fix vars
andrew-fleming Feb 18, 2023
fd42fdd
change external funcs to snake case
andrew-fleming Feb 18, 2023
1cb1252
remove unused import
andrew-fleming Feb 18, 2023
f0330cd
update cairo
andrew-fleming Feb 21, 2023
abc737a
add tests for externals
andrew-fleming Feb 21, 2023
4ca2620
add bool assertions
andrew-fleming Feb 21, 2023
8dd8ed3
update cairo
andrew-fleming Feb 22, 2023
091a29c
remove preset mods
andrew-fleming Feb 22, 2023
1c866f2
add IERC20 trait
andrew-fleming Feb 22, 2023
3405063
update cairo
andrew-fleming Feb 22, 2023
8fe3c82
clean up test
andrew-fleming Feb 22, 2023
ad928bc
remove assertion
andrew-fleming Feb 23, 2023
d883eb5
update cairo
andrew-fleming Feb 23, 2023
543501b
simplify max_u256
andrew-fleming Feb 23, 2023
2ecba91
clarify error msg
andrew-fleming Feb 23, 2023
6c3978b
add erc165 + tests
martriay Mar 3, 2023
60365c8
kickstart account module
martriay Mar 3, 2023
be1e9df
clean up python project. ready for rust/cairo1
martriay Mar 7, 2023
c20fd02
rebase to cairo-1
martriay Mar 7, 2023
bce2506
re-structure project
martriay Mar 7, 2023
35ede09
re-structure project
martriay Mar 8, 2023
e55889a
re-structure project
martriay Mar 8, 2023
9d5079c
update makefile
martriay Mar 8, 2023
ae89fa5
bump submodule
martriay Mar 8, 2023
a54e98c
Update erc20 migration branch (#586)
andrew-fleming Mar 28, 2023
91dcad3
Migrate security/initializable (#592)
andrew-fleming Mar 31, 2023
f48da2c
Use zeroable::zero() instead of contract_address_const::<0>() (#598)
Amxx Mar 31, 2023
d671d4c
Migrate security/pausable (#593)
andrew-fleming Mar 31, 2023
e86bcd2
add utils and constants
andrew-fleming Apr 18, 2023
42a160f
Revert "add utils and constants"
andrew-fleming Apr 18, 2023
598c232
Migrate ERC165 (#582)
martriay Apr 26, 2023
b2624ee
Migrate constants (#611)
andrew-fleming Apr 26, 2023
4a4bca9
Set up new CI (#599)
andrew-fleming Apr 27, 2023
0962051
fix formatting (#613)
andrew-fleming Apr 28, 2023
a1950ee
Normalize error message style (#606)
andrew-fleming Apr 28, 2023
c29b45c
Add `BoundedInt` and internal macros, update cairo (#600)
andrew-fleming Apr 28, 2023
e48a682
Migrate ownable (#604)
andrew-fleming May 11, 2023
5f86f65
Migrate security/reentrancyguard (#590)
andrew-fleming May 19, 2023
897facb
Migrate access control (#605)
andrew-fleming May 19, 2023
372de37
Migrate account (#620)
andrew-fleming May 23, 2023
d86eb73
Migrate ERC721 (#619)
martriay May 30, 2023
62688e7
Dual interface dispatcher for ERC721 (#623)
martriay Jul 2, 2023
ba69328
Replace ERC-165 with SRC-5 (Update Interface Ids) (#637)
ericnordelo Jul 2, 2023
8534ec6
Fix conflicts from the dual721 and src5 merge (#641)
andrew-fleming Jul 3, 2023
bc90bd5
Add camel support for ownable (#625)
andrew-fleming Jul 3, 2023
c8fa9f9
Add camel support for access control (#626)
andrew-fleming Jul 5, 2023
3a8e3e7
erc20 dual dispatcher (#622)
andrew-fleming Jul 5, 2023
6a1f729
Add `UnwrapAndCast` trait (#644)
andrew-fleming Jul 6, 2023
bbcb875
add test_dual721 mod (#648)
andrew-fleming Jul 8, 2023
5a27baa
Update account interface (#646)
ericnordelo Jul 10, 2023
ba29133
Add camel support for Account (#647)
ericnordelo Jul 12, 2023
b44f7dc
Add src5 dual dispatcher (#659)
andrew-fleming Jul 12, 2023
33dbd56
Add dual case erc721 receiver (#649)
andrew-fleming Jul 13, 2023
65d03ae
Add owner param to ownable initializer (#660)
ericnordelo Jul 13, 2023
a863859
Migrate SRC5 to Cairo 2 (#664)
ericnordelo Jul 18, 2023
c4590b9
Migrate initializable to cairo2 (#661)
andrew-fleming Jul 18, 2023
f18fcdb
Migrate Account to Cairo 2 (#666)
ericnordelo Jul 20, 2023
dc4a233
Migrate pausable to cairo2 (#662)
andrew-fleming Jul 20, 2023
27514b1
Migrate reentrancyguard to cairo2 (#663)
andrew-fleming Jul 20, 2023
8e10821
Migrate ERC721 to Cairo2 (#667)
ericnordelo Jul 21, 2023
a00a9d3
Migrate ownable to cairo2 (#665)
andrew-fleming Jul 21, 2023
0b40485
Migrate ERC20 to Cairo 2 (#669)
ericnordelo Jul 22, 2023
4e64434
Migrate access control to cairo2 (#668)
andrew-fleming Jul 22, 2023
79fe2db
Migrate to Scarb for cairo-2 (#671)
maciektr Aug 4, 2023
177ad63
Add spdx (#684)
andrew-fleming Aug 4, 2023
495ed8a
feat: sort imports (#679)
ericnordelo Aug 4, 2023
c28c758
Migrate upgrades (#603)
andrew-fleming Aug 10, 2023
f9c30da
Add testing for Ownable events (#675)
ericnordelo Aug 11, 2023
457b98b
Add account events (#687)
andrew-fleming Aug 11, 2023
544ddac
Add testing for AccessControl events (#674)
ericnordelo Aug 15, 2023
4473243
Add testing for Pausable events (#676)
ericnordelo Aug 15, 2023
e95def8
Add testing for ERC20 events (#677)
ericnordelo Aug 15, 2023
77089c1
Add mint to erc721 preset constructor (#700)
andrew-fleming Aug 15, 2023
3e08fa6
Add testing for ERC721 events (#678)
ericnordelo Aug 16, 2023
8307644
Update README and fix scarb package (#688)
martriay Aug 18, 2023
cece32b
Bump scarb and fix dual721 test context (#703)
andrew-fleming Aug 23, 2023
32f9974
add rc version (#708)
martriay Aug 23, 2023
b40c35b
remove unused imports (#707)
andrew-fleming Aug 23, 2023
fbdd759
Upgrade Cairo version and Scarb version to latest releases (#712)
bal7hazar Aug 24, 2023
05429e4
bump antora (#715)
martriay Aug 28, 2023
adac09f
Add selector inline macro/fix `tokenURI` (#724)
andrew-fleming Sep 8, 2023
90be39f
fix: naming convention (#732)
ericnordelo Sep 14, 2023
fcdd6d1
feat: add Errors modules (#691)
ericnordelo Sep 14, 2023
7373daa
Update account docs (#709)
ericnordelo Sep 15, 2023
cbb5bf5
Add Interface & Dispatchers docs (#730)
martriay Sep 20, 2023
4e388f5
Update overview docs (#735)
ericnordelo Sep 20, 2023
a1b559c
remove underscore from name_ and symbol_ (#738)
andrew-fleming Sep 21, 2023
74eb4e8
Add prefixes to storage members (#743)
ericnordelo Sep 26, 2023
420f320
Sanitizing for release. (#736)
ericnordelo Sep 27, 2023
4f973b6
feat: migrate logic
ericnordelo Sep 27, 2023
2f4b1f0
feat: update workflow
ericnordelo Sep 27, 2023
b425e2c
Merge branch 'main' of github.com:OpenZeppelin/cairo-contracts into f…
ericnordelo Oct 2, 2023
354a2cd
fix: docs
ericnordelo Oct 2, 2023
95706b1
feat: apply update reviews
ericnordelo Oct 6, 2023
d2c538b
Merge branch 'main' of github.com:OpenZeppelin/cairo-contracts into f…
ericnordelo Oct 6, 2023
83c1203
refactor: remove imports
ericnordelo Oct 6, 2023
2ae8139
Update src/access/ownable/ownable.cairo
ericnordelo Oct 6, 2023
fb514e1
feat: apply review updates
ericnordelo Oct 6, 2023
25fcab8
Merge branch 'feat/migrate-ownable-to-components' of github.com:ericn…
ericnordelo Oct 6, 2023
54396a6
feat: add comments to camelCase functions
ericnordelo Oct 6, 2023
3fc22bc
fix: comment
ericnordelo Oct 9, 2023
4f24b82
Update docs/modules/ROOT/pages/api/access.adoc
ericnordelo Oct 10, 2023
e112ba1
feat: apply review updates
ericnordelo Oct 11, 2023
95f2f76
Merge branch 'main' of github.com:OpenZeppelin/cairo-contracts into f…
ericnordelo Oct 11, 2023
9d8b0aa
Merge branch 'feat/migrate-ownable-to-components' of github.com:ericn…
ericnordelo Oct 11, 2023
d13b688
feat: update docs
ericnordelo Oct 11, 2023
c823416
feat: update comments
ericnordelo Oct 11, 2023
5dd422e
Update src/tests/utils.cairo
ericnordelo Oct 12, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 26 additions & 13 deletions docs/modules/ROOT/pages/access.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,42 @@ OpenZeppelin Contracts for Cairo provides {ownable-cairo} for implementing owner

=== Usage

Integrating this module into a contract first requires assigning an owner.
Integrating this component into a contract first requires assigning an owner.
The implementing contract's constructor should set the initial owner by passing the owner's address to Ownable's
xref:/api/access.adoc#AccessControl-initializer[`initializer`] like this:

[,javascript]
----
use openzeppelin::access::ownable::Ownable;

#[starknet::contract]
mod MyContract {
use openzeppelin::access::ownable::Ownable as ownable_component;
use starknet::ContractAddress;
use super::Ownable;

component!(path: ownable_component, storage: ownable, event: OwnableEvent);

#[abi(embed_v0)]
impl OwnableImpl = ownable_component::OwnableImpl<ContractState>;
#[abi(embed_v0)]
impl OwnableCamelOnlyImpl =
ownable_component::OwnableCamelOnlyImpl<ContractState>;
impl InternalImpl = ownable_component::InternalImpl<ContractState>;

#[storage]
struct Storage {}
struct Storage {
#[substorage(v0)]
ownable: ownable_component::Storage
}

#[event]
#[derive(Drop, starknet::Event)]
enum Event {
OwnableEvent: ownable_component::Event
}

#[constructor]
fn constructor(self: @ContractState, owner: ContractAddress) {
let mut unsafe_state = Ownable::unsafe_new_contract_state();
Ownable::InternalImpl::initializer(ref unsafe_state, owner);
fn constructor(ref self: ContractState, owner: ContractAddress) {
// Set the initial owner of the contract
self.ownable.initializer(owner);
}

(...)
Expand All @@ -51,15 +67,12 @@ To restrict a function's access to the owner only, add in the `assert_only_owner
----
#[starknet::contract]
mod MyContract {
use openzeppelin::access::ownable::Ownable;

(...)

#[external(v0)]
fn foo(ref self: ContractState) {
fn only_owner_allowed(ref self: ContractState) {
// This function can only be called by the owner
let unsafe_state = Ownable::unsafe_new_contract_state();
Ownable::InternalImpl::assert_only_owner(@unsafe_state);
self.ownable.assert_only_owner();

(...)
}
Expand Down
32 changes: 28 additions & 4 deletions docs/modules/ROOT/pages/api/access.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ use openzeppelin::access::ownable::Ownable;
`Ownable` provides a basic access control mechanism where an account
(an owner) can be granted exclusive access to specific functions.

This module includes the `assert_only_owner` internal to restrict a function to be used only by the owner.
This module includes the internal `assert_only_owner` to restrict a function to be used only by the owner.

[.contract-index]
.External Functions
.Embeddable Functions
--
.OwnableImpl

Expand All @@ -39,6 +39,15 @@ This module includes the `assert_only_owner` internal to restrict a function to
* xref:Ownable-renounce_ownership[`++renounce_ownership(self)++`]
--

[.contract-index]
.camelCase Support
--
.OwnableCamelOnlyImpl

* xref:Ownable-transferOwnership[`++transferOwnership(self, newOwner)++`]
* xref:Ownable-renounceOwnership[`++renounceOwnership(self)++`]
--

[.contract-index]
.Internal Functions
--
Expand All @@ -55,8 +64,8 @@ This module includes the `assert_only_owner` internal to restrict a function to
* xref:Ownable-OwnershipTransferred[`++OwnershipTransferred(previous_owner, new_owner)++`]
--

[#Ownable-External-Functions]
==== External Functions
[#Ownable-Embeddable-Functions]
==== Embeddable Functions

[.contract-item]
[[Ownable-owner]]
Expand All @@ -83,6 +92,21 @@ Leaves the contract without owner. It will not be possible to call
NOTE: Renouncing ownership will leave the contract without an owner,
thereby removing any functionality that is only available to the owner.

[#Ownable-camelCase-Support]
==== camelCase Support

[.contract-item]
Comment on lines +95 to +98
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Much better!

[[Ownable-transferOwnership]]
==== `[.contract-item-name]#++transferOwnership++#++(ref self: ContractState, newOwner: ContractAddress)++` [.item-kind]#external#
andrew-fleming marked this conversation as resolved.
Show resolved Hide resolved

See xref:Ownable-transfer_ownership[transfer_ownership].

[.contract-item]
[[Ownable-renounceOwnership]]
==== `[.contract-item-name]#++renounceOwnership++#++(ref self: ContractState)++` [.item-kind]#external#

See xref:Ownable-renounce_ownership[renounce_ownership].

[#Ownable-Internal-Functions]
==== Internal Functions

Expand Down
8 changes: 3 additions & 5 deletions src/access/ownable/dual_ownable.cairo
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts for Cairo v0.7.0 (access/ownable/dual_ownable.cairo)

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 starknet::ContractAddress;
use starknet::Felt252TryIntoContractAddress;
use starknet::SyscallResultTrait;
use starknet::call_contract_syscall;

Expand All @@ -24,14 +22,14 @@ trait DualCaseOwnableTrait {

impl DualCaseOwnableImpl of DualCaseOwnableTrait {
fn owner(self: @DualCaseOwnable) -> ContractAddress {
let args = ArrayTrait::new();
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 = ArrayTrait::new();
let mut args = array![];
args.append_serde(new_owner);

try_selector_with_fallback(
Expand All @@ -44,7 +42,7 @@ impl DualCaseOwnableImpl of DualCaseOwnableTrait {
}

fn renounce_ownership(self: @DualCaseOwnable) {
let mut args = ArrayTrait::new();
let mut args = array![];

try_selector_with_fallback(
*self.contract_address,
Expand Down
99 changes: 65 additions & 34 deletions src/access/ownable/ownable.cairo
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts for Cairo v0.7.0 (access/ownable/ownable.cairo)

#[starknet::contract]
/// # Ownable Component
///
/// The Ownable component provides a basic access control mechanism, where
/// there is an account (an owner) that can be granted exclusive access to
/// specific functions.
///
/// The initial owner can be set by using the `initializer` function in
/// construction time. This can later be changed with `transfer_ownership`.
#[starknet::component]
mod Ownable {
use openzeppelin::access::ownable::interface;
use starknet::ContractAddress;
Expand Down Expand Up @@ -30,20 +38,72 @@ mod Ownable {
const ZERO_ADDRESS_OWNER: felt252 = 'New owner is the zero address';
}

#[embeddable_as(OwnableImpl)]
impl Ownable<
TContractState, +HasComponent<TContractState>
> of interface::IOwnable<ComponentState<TContractState>> {
/// Returns the address of the current owner.
fn owner(self: @ComponentState<TContractState>) -> ContractAddress {
self.Ownable_owner.read()
}

/// Transfers ownership of the contract to a new address.
fn transfer_ownership(
ref self: ComponentState<TContractState>, new_owner: ContractAddress
) {
assert(!new_owner.is_zero(), Errors::ZERO_ADDRESS_OWNER);
self.assert_only_owner();
self._transfer_ownership(new_owner);
}

/// Leaves the contract without owner. It will not be possible to call `assert_only_owner`
/// functions anymore. Can only be called by the current owner.
fn renounce_ownership(ref self: ComponentState<TContractState>) {
self.assert_only_owner();
self._transfer_ownership(Zeroable::zero());
}
}

/// Adds camelCase support for `IOwnable`.
#[embeddable_as(OwnableCamelOnlyImpl)]
impl OwnableCamelOnly<
TContractState, +HasComponent<TContractState>
> of interface::IOwnableCamelOnly<ComponentState<TContractState>> {
fn transferOwnership(ref self: ComponentState<TContractState>, newOwner: ContractAddress) {
self.transfer_ownership(newOwner);
}

fn renounceOwnership(ref self: ComponentState<TContractState>) {
self.renounce_ownership();
}
ericnordelo marked this conversation as resolved.
Show resolved Hide resolved
}
Comment on lines +68 to +79
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thinking of how users will use the component, IMO it'd be a nice option to also have a single ContractABIImpl which will include all the ABI functions. It's not a huge deal with Ownable, but ERC20, for example, will have four embeddable impls:

  1. ERC20Impl
  2. ERC20NonStandardImpl
  3. ERC20CamelOnlyImpl
  4. ERC20CamelNonStandardImpl

Thoughts?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see your point, but the issue I have with it is that I think users should have the ability to opt-in/out of some impl for components, and having a single big ABI enforces every function by default. Examples of components that I think should have multiple external impl are:

ERC721: the ERC721Metadata impl should be optional, even when is widely used. The standard doesn't require this, and users should be able to not use it IMO.

The ERC20 example as well should have the metadata part as optional, but also the non-standard impl IMO.

I think I lean towards letting multiple impl, even when I feel (agree) this could be improved somehow.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see your point, but the issue I have with it is that I think users should have the ability to opt-in/out of some impl for components, and having a single big ABI enforces every function by default.

Oh, for sure! I was thinking more along the lines of having the implementations that we have now and also one big ABI impl with everything. This gives the user the option to either choose specific impls or use the whole component. I imagine this being quite beneficial for the account and erc721 components

The issue I see, though, is we'd have to rewrite all the methods under the ABI impl or create some sort of multi-impl embeddable mechanism

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I lean towards modularity here, having ERC721, ERC721Metadata, and non-standard (with a more descriptive name, not generic) impls separately and required explicitly in the contract. Having an extra impl with the full ABI seems like an antipattern, because it would be harder to follow IMO.


#[generate_trait]
impl InternalImpl of InternalTrait {
fn initializer(ref self: ContractState, owner: ContractAddress) {
impl InternalImpl<
TContractState, +HasComponent<TContractState>
> of InternalTrait<TContractState> {
/// Sets the contract's initial owner.
///
/// This function should be called at construction time.
fn initializer(ref self: ComponentState<TContractState>, owner: ContractAddress) {
self._transfer_ownership(owner);
}

fn assert_only_owner(self: @ContractState) {
/// Panics if called by any account other than the owner. Use this
/// to restrict access to certain functions to the owner.
fn assert_only_owner(self: @ComponentState<TContractState>) {
let owner: ContractAddress = self.Ownable_owner.read();
let caller: ContractAddress = get_caller_address();
assert(!caller.is_zero(), Errors::ZERO_ADDRESS_CALLER);
assert(caller == owner, Errors::NOT_OWNER);
}

fn _transfer_ownership(ref self: ContractState, new_owner: ContractAddress) {
/// Transfers ownership of the contract to a new address.
///
/// Internal function without access restriction.
fn _transfer_ownership(
ref self: ComponentState<TContractState>, new_owner: ContractAddress
) {
let previous_owner: ContractAddress = self.Ownable_owner.read();
self.Ownable_owner.write(new_owner);
self
Expand All @@ -52,33 +112,4 @@ mod Ownable {
);
}
}

#[external(v0)]
impl OwnableImpl of interface::IOwnable<ContractState> {
fn owner(self: @ContractState) -> ContractAddress {
self.Ownable_owner.read()
}

fn transfer_ownership(ref self: ContractState, new_owner: ContractAddress) {
assert(!new_owner.is_zero(), Errors::ZERO_ADDRESS_OWNER);
self.assert_only_owner();
self._transfer_ownership(new_owner);
}

fn renounce_ownership(ref self: ContractState) {
self.assert_only_owner();
self._transfer_ownership(Zeroable::zero());
}
}

#[external(v0)]
impl OwnableCamelOnlyImpl of interface::IOwnableCamelOnly<ContractState> {
fn transferOwnership(ref self: ContractState, newOwner: ContractAddress) {
OwnableImpl::transfer_ownership(ref self, newOwner);
}

fn renounceOwnership(ref self: ContractState) {
OwnableImpl::renounce_ownership(ref self);
}
}
}
21 changes: 9 additions & 12 deletions src/tests/access/test_dual_ownable.cairo
Original file line number Diff line number Diff line change
@@ -1,33 +1,31 @@
use openzeppelin::access::ownable::dual_ownable::DualCaseOwnable;
use openzeppelin::access::ownable::dual_ownable::DualCaseOwnableTrait;
use openzeppelin::access::ownable::interface::IOwnableCamelOnlyDispatcher;
use openzeppelin::access::ownable::interface::IOwnableCamelOnlyDispatcherTrait;
use openzeppelin::access::ownable::interface::IOwnableDispatcher;
use openzeppelin::access::ownable::interface::IOwnableDispatcherTrait;
use openzeppelin::tests::mocks::dual_ownable_mocks::CamelOwnableMock;
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::mocks::ownable_mocks::CamelOwnableMock;
use openzeppelin::tests::mocks::ownable_mocks::CamelOwnablePanicMock;
use openzeppelin::tests::mocks::ownable_mocks::SnakeOwnableMock;
use openzeppelin::tests::mocks::ownable_mocks::SnakeOwnablePanicMock;
use openzeppelin::tests::utils::constants::{OWNER, NEW_OWNER};
use openzeppelin::tests::utils;
use openzeppelin::utils::serde::SerializedAppend;
use starknet::testing::set_caller_address;
use starknet::testing::set_contract_address;

//
// Setup
//

fn setup_snake() -> (DualCaseOwnable, IOwnableDispatcher) {
let mut calldata = ArrayTrait::new();
let mut calldata = array![];
calldata.append_serde(OWNER());
let target = utils::deploy(SnakeOwnableMock::TEST_CLASS_HASH, calldata);
(DualCaseOwnable { contract_address: target }, IOwnableDispatcher { contract_address: target })
}

fn setup_camel() -> (DualCaseOwnable, IOwnableCamelOnlyDispatcher) {
let mut calldata = ArrayTrait::new();
let mut calldata = array![];
calldata.append_serde(OWNER());
let target = utils::deploy(CamelOwnableMock::TEST_CLASS_HASH, calldata);
(
Expand All @@ -37,14 +35,14 @@ fn setup_camel() -> (DualCaseOwnable, IOwnableCamelOnlyDispatcher) {
}

fn setup_non_ownable() -> DualCaseOwnable {
let calldata = ArrayTrait::new();
let calldata = array![];
let target = utils::deploy(NonImplementingMock::TEST_CLASS_HASH, calldata);
DualCaseOwnable { contract_address: target }
}

fn setup_ownable_panic() -> (DualCaseOwnable, DualCaseOwnable) {
let snake_target = utils::deploy(SnakeOwnablePanicMock::TEST_CLASS_HASH, ArrayTrait::new());
let camel_target = utils::deploy(CamelOwnablePanicMock::TEST_CLASS_HASH, ArrayTrait::new());
let snake_target = utils::deploy(SnakeOwnablePanicMock::TEST_CLASS_HASH, array![]);
let camel_target = utils::deploy(CamelOwnablePanicMock::TEST_CLASS_HASH, array![]);
(
DualCaseOwnable { contract_address: snake_target },
DualCaseOwnable { contract_address: camel_target }
Expand Down Expand Up @@ -118,7 +116,6 @@ fn test_dual_renounce_ownership() {
assert(target.owner().is_zero(), 'Should be zero');
}


#[test]
#[available_gas(2000000)]
#[should_panic(expected: ('ENTRYPOINT_NOT_FOUND',))]
Expand Down
Loading