Skip to content

Commit

Permalink
Migrate Ownable to component (#768)
Browse files Browse the repository at this point in the history
* fix: link (#545)

* add submodule

* update cairo

* add Cargo and Makefile

* update cairo

* add deps in cairo_project, create lib

* add presets

* add base lib

* add tests

* remove old cairo lib and interface

* remove unused import

* fix vars

* change external funcs to snake case

* remove unused import

* update cairo

* add tests for externals

* add bool assertions

* update cairo

* remove preset mods

* add IERC20 trait

* update cairo

* clean up test

* remove assertion

* update cairo

* simplify max_u256

* clarify error msg

* add erc165 + tests

* kickstart account module

* clean up python project. ready for rust/cairo1

* re-structure project

* re-structure project

* re-structure project

* update makefile

* bump submodule

* Update erc20 migration branch (#586)

* Change the spelling of "StarkNet" to "Starknet" (#557)

* fix: link (#545)

* change StarkNet to Starknet

---------

Co-authored-by: Eric Nordelo <eric.nordelo39@gmail.com>

* add Cargo and Makefile

* add deps in cairo_project, create lib

* add presets

* add base lib

* add tests

* remove old cairo lib and interface

* remove unused import

* fix vars

* change external funcs to snake case

* remove unused import

* add tests for externals

* add bool assertions

* remove preset mods

* add IERC20 trait

* clean up test

* remove assertion

* simplify max_u256

* clarify error msg

* clean up python project. ready for rust/cairo1

* add erc165 + tests

* kickstart account module

* re-structure project

* re-structure project

* re-structure project

* update makefile

* re-structure project

* update to felt252, add use ContractAddress

* formatting

* remove colons from storage, remove _mint from initializer

* add constructor test

* add comments

* fix format

* check error msg in tests

* set max_u256 as func

* update cairo

* update cargo

* revert doc commit

* remove __init__

* refix link

---------

Co-authored-by: kongtaoxing <69096526+kongtaoxing@users.noreply.github.com>
Co-authored-by: Eric Nordelo <eric.nordelo39@gmail.com>
Co-authored-by: Martín Triay <martriay@gmail.com>

* Migrate security/initializable (#592)

* update cairo

* fix path

* add security mod

* add initializable

* add tests

* Update src/openzeppelin/security/initializable.cairo

Co-authored-by: Martín Triay <martriay@gmail.com>

* remove underscore

* add internal macros

---------

Co-authored-by: Martín Triay <martriay@gmail.com>

* Use zeroable::zero() instead of contract_address_const::<0>() (#598)

* use zeroable for address

* cleanup import

* Migrate security/pausable (#593)

* fix path

* add security mod

* add pausable

* add mock

* add tests

* add security mod

* update cargo

* update cairo

* Apply suggestions from code review

Co-authored-by: Martín Triay <martriay@gmail.com>

* remove underscore from _paused

* remove unused imports

* add test assertion for is_paused

* move mocks inside tests crate

* remove underscore

* add blank line

---------

Co-authored-by: Martín Triay <martriay@gmail.com>

* add utils and constants

* Revert "add utils and constants"

This reverts commit e86bcd2107b052e13c58a9af7907e1f82e427a60.

* Migrate ERC165 (#582)

* Apply suggestions from code review

Co-authored-by: Andrew Fleming <fleming-andrew@protonmail.com>
Co-authored-by: Hadrien Croubois <hadrien.croubois@gmail.com>

* apply review suggestions

* remove unused import

* add internal macro

* add deregister

---------

Co-authored-by: Andrew Fleming <fleming-andrew@protonmail.com>
Co-authored-by: Hadrien Croubois <hadrien.croubois@gmail.com>

* Migrate constants (#611)

* add utils and constants

* simplify role val

* add context comments for interface ids

* Set up new CI (#599)

* add lint and test

* fix name

* add md linter

* add header

* remove extra line

* add blank line

* remove env

* change name

* fix on condition

* change name

* fix formatting

* remove trailing comma in storage

* fix formatting (#613)

* Normalize error message style (#606)

* normalize error msg

* update cairo

* update Cargo

* fix test command

* update should_panic syntax

* use super for interface import

* Add `BoundedInt` and internal macros, update cairo (#600)

* update cairo

* update Cargo

* remove path flag

* refactor _spend_allowance with BoundedInt

* add BoundedInt for u256_max

* add internal macros

* update cairo

* update cairo

* update Cargo

* remove import

* update expected syntax

* remove redundant maxu256 fn

* update expected syntax

* Update src/openzeppelin/tests/test_erc20.cairo

Co-authored-by: Hadrien Croubois <hadrien.croubois@gmail.com>

* use into trait

* use address zeroable in mod

* set cairo to alpha7

* update Cargo

---------

Co-authored-by: Hadrien Croubois <hadrien.croubois@gmail.com>

* Migrate ownable (#604)

* add ownable

* add ownable tests

* simplify renounce

* fix formatting

* add internal macros

* Apply suggestions from code review

Co-authored-by: Martín Triay <martriay@gmail.com>

* add test_transfer_ownership_from_zero

* update cairo to alpha7

* update Cargo

* fix expected syntax

* update cairo to rc0

* update Cargo

* fix import

* simplify imports

* Apply suggestions from code review

Co-authored-by: Eric Nordelo <eric.nordelo39@gmail.com>

* Update src/openzeppelin/token/erc20.cairo

Co-authored-by: Eric Nordelo <eric.nordelo39@gmail.com>

* fix set_caller_address

---------

Co-authored-by: Martín Triay <martriay@gmail.com>
Co-authored-by: Eric Nordelo <eric.nordelo39@gmail.com>

* Migrate security/reentrancyguard (#590)

* add reentrancyguard

* update Cargo

* remove mytest

* add reentrancy mocks

* add utils

* finish tests

* remove unused func

* add comments

* clean up code

* clean up code

* Apply suggestions from code review

Co-authored-by: Martín Triay <martriay@gmail.com>

* remove underscore

* remove constructor in mock

* update interface name

* change count_this_recursive to count_external_recursive

* move mocks inside tests dir

* remove underscore

* update cairo to alpha7

* update Cargo

* add withdraw_gas

* fix formatting

* update cairo to rc0

* update Cargo

* fix import

* simplify imports

* remove duplicate import

* rename mod

* add mock interface

* finish tests

* update cairo

* add new line

* Update src/openzeppelin/tests/mocks/reentrancy_mock.cairo

Co-authored-by: Eric Nordelo <eric.nordelo39@gmail.com>

* import dispatchers

* fix formatting

* Apply suggestions from code review

Co-authored-by: Martín Triay <martriay@gmail.com>

* add deploy fn to utils

* use deploy from utils

---------

Co-authored-by: Martín Triay <martriay@gmail.com>
Co-authored-by: Eric Nordelo <eric.nordelo39@gmail.com>

* Migrate access control (#605)

* add accesscontrol

* add accesscontrol tests

* remove mock, add impl to contract

* fix formatting

* remove accesscontrol mock

* formatting, remove unused imports

* integrate erc165

* fix typo

* update cairo to alpha7

* update Cargo

* update expected syntax

* update expected syntax

* update cairo to rc0

* update Cargo

* fix import

* simplify imports

* Apply suggestions from code review

Co-authored-by: Martín Triay <martriay@gmail.com>

* fix storage mapping name

* rename impl

* add warning

* fix comment

* remove constructor, setup test constructor in setup

* fix format

* fix import format

* add test for granting already granted role

* add clarity to revoke role test

* add test for revoking already revoked role

* add test for renouncing already renounced role

* add test for revoked admin role losing privileges

* fix test_role_admin_cycle

* add target func as comment

* add default admin tests

* refactor tests, rename actors

* add tests for has_role and set_role_admin

* tidy up tests

* add general doc for events

* fix assert_only_role test

* remove redundant test

* remove unnecessary assertion

* remove duplicate test

* Update src/openzeppelin/access/accesscontrol.cairo

Co-authored-by: Martín Triay <martriay@gmail.com>

* fix imports, define constants locally

* Apply suggestions from code review

Co-authored-by: Martín Triay <martriay@gmail.com>

* fix test name

* bump cairo

* fix formatting

---------

Co-authored-by: Martín Triay <martriay@gmail.com>

* Migrate account (#620)

* continue account implementation

* add missing account interface functions

* tidy up module

* fix validate

* bump cairo + account changes

* fix __execute__, add serde, rename felt>felt252

* tidy up code

* add account tests

* complete account implementation

* Apply suggestions from code review

Co-authored-by: Andrew Fleming <fleming-andrew@protonmail.com>
Co-authored-by: Hadrien Croubois <hadrien.croubois@gmail.com>

* apply review suggestions

* remove unused import

* clarify __execute__ guard

* add account tests

* add internals

* tidy up

* add internal macro

* add internal macro

* add deregister

* update erc165

* feat: refactor account and add validate_transaction test

* feat: work on span serde

* feat: add test for validate

* refactor: remove unnecessary imports

* refactor: tests

* feat: implement test_execute

* Update src/openzeppelin/tests/test_account.cairo

Co-authored-by: Martín Triay <martriay@gmail.com>

* Update src/openzeppelin/tests/test_account.cairo

Co-authored-by: Martín Triay <martriay@gmail.com>

* feat: update from review

* feat: format files

* feat: SpanSerde compiling version

* feat: update tests and interface

* feat: format file

* feat: add test for multicall

* feat: add more tests

* test: remove unused function

* refactor: update ERC20 interface and module

* feat: add impl again

* refactor: apply review comments

* test: execute out of gas

* refactor: is valid signature because of lack of short circuit condicionals

* refactor: apply updates from reviews

* feat: add SpanSerde implementation

* refactor: remove span_to_array

* Update src/openzeppelin/tests/test_account.cairo

Co-authored-by: Andrew Fleming <fleming.andrew@protonmail.com>

* Update src/openzeppelin/account.cairo

Co-authored-by: Andrew Fleming <fleming.andrew@protonmail.com>

* test: update from review

* feat: splitting account interface and abi

* feat: add new account files

* remove underscore on mod api methods

* remove comment

* remove underscore

* move erc1271 id to interface

* remove unused import

* integrate deploy util

* add comments for validate dummy params

* add initializer

* change error msg

* add empty sig tests

* move test

* replace dummy args, fix comments

* fix formatting

* tidy up code

* add erc20 transfer call in execute test

* tidy up imports

* remove unused const

---------

Co-authored-by: Martín Triay <martriay@gmail.com>
Co-authored-by: Hadrien Croubois <hadrien.croubois@gmail.com>
Co-authored-by: Eric Nordelo <eric.nordelo39@gmail.com>

* Migrate ERC721 (#619)

* continue account implementation

* add missing account interface functions

* tidy up module

* fix validate

* bump cairo + account changes

* fix __execute__, add serde, rename felt>felt252

* tidy up code

* WIP ERC721

* make format

* fix dispatcher call

* clean

* working on tests

* replace match with `is_some()` and `is_none()` for readeability

* erc721 tests

* use Option.expect

* add account tests

* check panic reason

* rename _owner() to _owner_of()

* spacing

* complete account implementation

* apply recommandation for PR

* Apply suggestions from code review

Co-authored-by: Andrew Fleming <fleming.andrew@protonmail.com>

* check low level ownership int

* prefix test function with test_

* Apply suggestions from code review

Co-authored-by: Andrew Fleming <fleming-andrew@protonmail.com>
Co-authored-by: Hadrien Croubois <hadrien.croubois@gmail.com>

* apply review suggestions

* remove unused import

* clarify __execute__ guard

* add account tests

* add internals

* tidy up

* update ERC165 ids to u32

* apply sugestions from code review

* Apply suggestions from code review

Co-authored-by: Martín Triay <martriay@gmail.com>

* update & expand tests

* update lock

* add internal macro

* add internal macro

* add deregister

* update erc165

* wip (dispatched issue)

* fix abi

* start array→span transition

* minimise account dependency

* add SpanSerde in utils

* add dual interfaces

* update test message. fix linter

* split interfaces from preset module

* fix linter

* rename metadata id var

* add camelCase to traits

* fully implement dual interface traits

* simplify _owner_of

* add constructor and getter tests

* add token_uri tests

* remove conflictive test

* add erc721receiver. add IERC721ABI

* add safe_transfer_from tests

* add safe_mint tests

* Update src/openzeppelin/token/erc721/interface.cairo

Co-authored-by: Eric Nordelo <eric.nordelo39@gmail.com>

* move erc721 abi next to module

* address review comments

---------

Co-authored-by: Hadrien Croubois <hadrien.croubois@gmail.com>
Co-authored-by: Andrew Fleming <fleming.andrew@protonmail.com>
Co-authored-by: Andrew Fleming <fleming-andrew@protonmail.com>
Co-authored-by: Eric Nordelo <eric.nordelo39@gmail.com>

* Dual interface dispatcher for ERC721 (#623)

* add dual interface dispatcher draft

* complete dual721 implementation

* fix format

* add felt252 <> bool casts

* simplify Felt252IntoBool

* make felt252 into -> try_into

* add base test suite

* implement most tests

* add mocks

* add tests for panic cases

* fix some tests

* fix format

* fix more tests

* fix tests

* apply review feedback

* normalize mock names

* add token_uri tests

* rename non implementing mock

* move comment

* upgrade to cairo 1.1.1

* Update src/openzeppelin/utils.cairo

Co-authored-by: Eric Nordelo <eric.nordelo39@gmail.com>

* address review comments

---------

Co-authored-by: Eric Nordelo <eric.nordelo39@gmail.com>

* Replace ERC-165 with SRC-5 (Update Interface Ids) (#637)

* feat: add src5 module

* refactor: interface ids and account standard interface

* refactor: naming convention

* refactor: separate interfaces

* feat: apply last SNIP update

* fix: account interface signature

* feat: apply updates from review

* fix: accesscontrol interface id

* Update src/openzeppelin/account/account.cairo

Co-authored-by: Andrew Fleming <fleming.andrew@protonmail.com>

* feat: apply update from review

---------

Co-authored-by: Andrew Fleming <fleming.andrew@protonmail.com>

* Fix conflicts from the dual721 and src5 merge (#641)

* add abi to interfaces

* change u32 to felt

* Add camel support for ownable (#625)

* add camel support

* add camel tests

* nest ownable into dir

* move interface

* add dual ownable

* add const selectors

* add try_selector_with_fallback and bool impl

* nest access tests in test dirs

* move accesscontrol and ownable test mods

* move tests

* move tests

* add mocks

* add dual ownable tests

* add panic traits

* tidy up tests

* fix formatting

* remove comments

* fix hierarchy

* remove import comments

* remove comment

* Apply suggestions from code review

Co-authored-by: Martín Triay <martriay@gmail.com>

* remove unused import

* fix camel dispatcher

* normalize assert error msg

* fix formatting

* remove redundant assertion

* change selector casing

* remove unused import

* fix comments, add ref for ignored tests

* fix comments

* remove panic trait

* bump to cairo v1.1.1

* update Cargo

* remove ignore from tests

* Apply suggestions from code review

Co-authored-by: Eric Nordelo <eric.nordelo39@gmail.com>

* remove selectors from constants

* add selectors to selectors.cairo

* remove selector bindings

* fix comment

* remove/fix comments

* fix conflicts

* Update src/openzeppelin/utils/selectors.cairo

Co-authored-by: Eric Nordelo <eric.nordelo39@gmail.com>

---------

Co-authored-by: Martín Triay <martriay@gmail.com>
Co-authored-by: Eric Nordelo <eric.nordelo39@gmail.com>

* Add camel support for access control (#626)

* add camel support

* add camel tests

* move accesscontrol into dir

* separate interface

* add try_selector_with_fallback and bool impl

* add const selectors

* add dual accesscontrol

* move access tests

* add panic trait

* add accesscontrol mocks

* add dual accesscontrol tests

* fix formatting

* Apply suggestions from code review

Co-authored-by: Eric Nordelo <eric.nordelo39@gmail.com>

* add comment to supportsInterface

* add tests for supports_interface

* remove comments

* alphabetize use clauses

* remove util panic trait

* remove unused imports

* remove unused imports

* remove unused import

* update selector casings

* Apply suggestions from code review

Co-authored-by: Martín Triay <martriay@gmail.com>

* fix casing on target calls

* add space to comments

* remove comments, add ref with ignored tests

* remove unused imports

* remove selectors from constants

* add selectors to selectors mod

* fix formatting

* reorder selectors

* fix comment

* update interface id

* replace erc165 with src5

* fix conflicts

* replace u32 with felt

* add abi to interfaces

* remove ignore from tests

* fix formatting

* fix comment

* remove camel supportsInterface

* fix comment consistency

* Update src/openzeppelin/tests/access/test_dual_accesscontrol.cairo

Co-authored-by: Eric Nordelo <eric.nordelo39@gmail.com>

* add append_serde

* change append to append_serde

* remove unused import

* remove bindings

---------

Co-authored-by: Eric Nordelo <eric.nordelo39@gmail.com>
Co-authored-by: Martín Triay <martriay@gmail.com>

* erc20 dual dispatcher (#622)

* add camel methods

* update erc20 dispatcher path

* refactor tests, add tests for camel methods

* fix formatting

* add try_selector_with_fallback and bool impl

* add erc20 selectors

* add abi to traits

* add dual20 mocks

* add panic trait

* add dual20 mocks

* add dual20

* add dual20

* add dual20 tests

* tidy up tests

* move tests to token dir

* fix formatting

* clean up tests

* restructure token tests

* remove panic trait

* reorder imports

* remove unused imports

* fix comments

* update const selector casings

* remove comments

* Apply suggestions from code review

Co-authored-by: Eric Nordelo <eric.nordelo39@gmail.com>

* change target member to contract_address

* fix formatting

* fix dispatcher calls

* change dispatcher to dual_dispatcher

* reorder use clauses

* move selectors to selectors mod

* fix formatting

* reorder selectors

* remove duplicate selectors

* remove ignore

* simplify dispatcher vars

* fix comment

* Apply suggestions from code review

Co-authored-by: Eric Nordelo <eric.nordelo39@gmail.com>

* fix test constants

* add SerializedAppend trait

* integrate append_serde

* integrate append_serde and utils selector

* change u256 fns to constants

* change u256 fns to constants

* move dual721 test to token/, apply append_serde, change u256 fn to constant

* fix formatting

* add append_serde

* move append_serde to serde

* update append_serde path

* change dispatcher to IERC20

* remove unnecessary into()

* remove bindings

* add binding to empty arrays

* fix formatting

---------

Co-authored-by: Eric Nordelo <eric.nordelo39@gmail.com>

* Add `UnwrapAndCast` trait (#644)

* add unwrap_and_cast trait and impls

* use unwrap_and_cast

* tidy up code

* add UnwrapAndCastU8 impl

* reorder use clauses

* use unwrap_and_cast on view fns

* add test_dual721 mod (#648)

* Update account interface (#646)

* feat: update interface and ids

* refactor: format files

* feat: update from reviews

* Update src/openzeppelin/account/account.cairo

Co-authored-by: Andrew Fleming <fleming.andrew@protonmail.com>

---------

Co-authored-by: Andrew Fleming <fleming.andrew@protonmail.com>

* Add camel support for Account (#647)

* feat: update interface and ids

* refactor: format files

* feat: update from reviews

* feat: add dual interface to account

* fix: tests

* feat: add tests

* feat: add more tests

* feat: apply review suggestions

* feat: apply review updates

* Update src/openzeppelin/tests/account/test_dual_account.cairo

Co-authored-by: Andrew Fleming <fleming.andrew@protonmail.com>

---------

Co-authored-by: Andrew Fleming <fleming.andrew@protonmail.com>

* Add src5 dual dispatcher (#659)

* add dual src5

* add dual src5 tests and mocks

* add felt impl

* remove unused imports, integrate unwrap_and_cast for felts

* add supports_interface to interface

* add supports_interface to erc721 interface

* add camelCase supportsInterface test

* add dual supports_interface to mocks

* add dual supports_interface tests

* add dual supports_interface to tests

* add comment

* fix formatting

* clean up test

* add comments

* remove unused imports

* fix interface

* fix src5 impl

* apply review suggestion

* Add dual case erc721 receiver (#649)

* add 721 holder

* add 721 receiver selectors

* add abis

* add dual receiver

* add dual receiver mocks

* add dual 721 receiver and holder mods

* add dual 721 receiver tests

* integrate dual case receiver

* remove camel supportsInterface

* add isrc5 impl

* add isrc5 impl

* fix formatting

* change receiver import

* remove unused mod

* add isrc5 impl

* remove mod

* fix formatting

* remove conflict

* add felt impl to UnwrapAndCast

* clean up mocks

* add camelCase ISRC5 impl

* add camelCase tests for safe methods

* fix test

* remove unused imports

* remove unused imports

* remove unused imports

* Apply suggestions from code review

Co-authored-by: Eric Nordelo <eric.nordelo39@gmail.com>

* add transferFrom and safeTransferFrom tests

* fix comments

* fix comments

---------

Co-authored-by: Eric Nordelo <eric.nordelo39@gmail.com>

* Add owner param to ownable initializer (#660)

* feat: add owner param to ownable initializer

* feat: apply review updates

* fix: remove unnecessary mut

* Update src/openzeppelin/tests/access/test_dual_ownable.cairo

Co-authored-by: Andrew Fleming <fleming.andrew@protonmail.com>

---------

Co-authored-by: Andrew Fleming <fleming.andrew@protonmail.com>

* Migrate SRC5 to Cairo 2 (#664)

* feat: migrate files

* feat: add interface.cairo

* feat: apply review updates

* refactor: improve readability

* Migrate initializable to cairo2 (#661)

* bump to cairo v2.0.2

* update Cargo

* comment out mods

* update initializable syntax

* move security tests

* update initializable tests

* fix formatting

* update cairo

* update Cargo

* simplify and clarify tests

* fix formatting

* Apply suggestions from code review

Co-authored-by: Eric Nordelo <eric.nordelo39@gmail.com>

* fix tests

---------

Co-authored-by: Eric Nordelo <eric.nordelo39@gmail.com>

* Migrate Account to Cairo 2 (#666)

* feat: migrate files

* feat: add interface.cairo

* feat: apply review updates

* refactor: improve readability

* fix: dual account tests

* fix: account tests

* feat: apply review updates

* Migrate pausable to cairo2 (#662)

* bump to cairo v2.0.2

* update Cargo

* comment out mods

* update initializable syntax

* move security tests

* update initializable tests

* fix formatting

* update pausable syntax

* update pausable tests

* update cairo

* update Cargo

* simplify and clarify tests

* fix formatting

* simplify and clarify tests

* Apply suggestions from code review

Co-authored-by: Eric Nordelo <eric.nordelo39@gmail.com>

* fix tests

* change StorageTrait to InternalTrait

* use InternalImpl

* add external pausable impl

* Apply suggestions from code review

Co-authored-by: Eric Nordelo <eric.nordelo39@gmail.com>

---------

Co-authored-by: Eric Nordelo <eric.nordelo39@gmail.com>

* Migrate reentrancyguard to cairo2 (#663)

* bump to cairo v2.0.2

* update Cargo

* comment out mods

* update initializable syntax

* move security tests

* update initializable tests

* fix formatting

* remove SpanSerde

* update reentrancyguard syntax

* add reentrancyguard mocks

* update reentrancyguard tests

* update cairo

* update Cargo

* simplify and clarify tests

* fix formatting

* simplify and clarify tests

* fix formatting

* Apply suggestions from code review

Co-authored-by: Eric Nordelo <eric.nordelo39@gmail.com>

* fix tests

* change StorageTrait to InternalTrait

* remove internal is_entered

* use internal contract state

* Apply suggestions from code review

Co-authored-by: Eric Nordelo <eric.nordelo39@gmail.com>

* fix import order

* change generic state to TState

---------

Co-authored-by: Eric Nordelo <eric.nordelo39@gmail.com>

* Migrate ERC721 to Cairo2 (#667)

* feat: migrate files

* feat: add interface.cairo

* feat: apply review updates

* refactor: improve readability

* fix: dual account tests

* fix: account tests

* fix: mocks

* fix: dual721 tests

* fix: erc721 tests

* feat: apply review updates

* feat: apply review suggestions

* Migrate ownable to cairo2 (#665)

* bump to cairo v2.0.2

* update Cargo

* comment out mods

* update initializable syntax

* move security tests

* update initializable tests

* fix formatting

* remove SpanSerde

* update ownable syntax

* add ownable_camel impl

* update syntax in ownable mocks

* update ownable tests

* fix formatting

* update cairo

* update Cargo

* simplify and clarify tests

* fix formatting

* simplify internal fns

* add initializer

* fix constructor, tidy up code

* fix tests

* Apply suggestions from code review

Co-authored-by: Eric Nordelo <eric.nordelo39@gmail.com>

* fix tests

* change StorageTrait to InternalTrait

* start refactor

* change impls to external fns

* use IOwnableCamelOnly

* fix tests

* remove unneeded mut

* remove unneeded mut

* Apply suggestions from code review

Co-authored-by: Eric Nordelo <eric.nordelo39@gmail.com>

* change to TState

* fix formatting

* remove Ownable prefix in fn calls

* remove internal owner fn

* use internal state trait to read owner

---------

Co-authored-by: Eric Nordelo <eric.nordelo39@gmail.com>

* Migrate ERC20 to Cairo 2 (#669)

* feat: fix tests

* feat: apply review updates

* Migrate access control to cairo2 (#668)

* bump to cairo v2.0.2

* update Cargo

* comment out mods

* update initializable syntax

* move security tests

* update initializable tests

* fix formatting

* remove SpanSerde

* update ownable syntax

* add ownable_camel impl

* update syntax in ownable mocks

* update ownable tests

* fix formatting

* update cairo

* update Cargo

* simplify and clarify tests

* fix formatting

* simplify internal fns

* add initializer

* fix constructor, tidy up code

* fix tests

* Apply suggestions from code review

Co-authored-by: Eric Nordelo <eric.nordelo39@gmail.com>

* fix tests

* change StorageTrait to InternalTrait

* update syntax

* update mocks

* start updating tests

* start refactor

* change impls to external fns

* use IOwnableCamelOnly

* fix tests

* remove unneeded mut

* remove unneeded mut

* fix mocks

* simplify events

* change array syntax

* update syntax in tests

* fix formatting

* Apply suggestions from code review

Co-authored-by: Eric Nordelo <eric.nordelo39@gmail.com>

* add space between events

* fix generic state

* add space between events

* fix formatting

---------

Co-authored-by: Eric Nordelo <eric.nordelo39@gmail.com>

* Migrate to Scarb for cairo-2 (#671)

* Migrate to Scarb

* Hide tests module behind cfg

* Add spdx (#684)

* add spdx

* add spdx

* feat: sort imports (#679)

* Migrate upgrades (#603)

* add upgrades to lib

* add proxy mod

* update cairo

* update Cargo

* fix test command

* add upgrades

* fix spelling

* add upgrade test

* fix spelling

* add upgrade_and_call

* update cairo

* update Cargo

* add events

* tidy up code

* fix format

* update cairo to alpha7

* update Cargo

* fix expected syntax

* fix conflict

* update expected syntax

* formatting

* update cairo to rc0

* update Cargo

* fix import

* refactor mocks

* start test refactor

* simplify upgrades, add upgrade_and_call

* refactor mocks

* refactor upgrades

* refactor tests

* fix imports, add impl

* fix imports

* fix formatting

* add abis to mocks

* refactor tests with dispatchers

* fix formatting

* start migration

* update syntax

* update syntax in mocks

* fix tests

* add line

* remove line

* add upgradeable trait

* replace interface impl with trait impl

* fix formatting

* add assertion

* add tests for events

* Apply suggestions from code review

Co-authored-by: Eric Nordelo <eric.nordelo39@gmail.com>

* move logic to internal impl

* add interface

* update paths

* fix formatting

* simplify imports

* Apply suggestions from code review

Co-authored-by: Eric Nordelo <eric.nordelo39@gmail.com>

* Apply suggestions from code review

Co-authored-by: Martín Triay <martriay@gmail.com>

* remove upgrade_and_call, test event in separate test

* remove upgrade_and_call

* remove unused import

* reorder imports, tidy up code

---------

Co-authored-by: Eric Nordelo <eric.nordelo39@gmail.com>
Co-authored-by: Martín Triay <martriay@gmail.com>

* Add testing for Ownable events (#675)

* feat: add tests for ownable events

* feat: improve tests

* Update src/tests/utils.cairo

Co-authored-by: Martín Triay <martriay@gmail.com>

---------

Co-authored-by: Martín Triay <martriay@gmail.com>

* Add account events (#687)

* feat: add tests for ownable events

* define account events

* add event to set_public_key

* add event test

* change param name

* fix event emit param

* fix formatting

* add tests for events

* add default checks in tests

* feat: improve tests

* Apply suggestions from code review

Co-authored-by: Eric Nordelo <eric.nordelo39@gmail.com>

* reorder imports, remove Account prefix

* fix events

* fix formatting

* Update src/tests/utils.cairo

Co-authored-by: Martín Triay <martriay@gmail.com>

* add event checks, use ZERO from constants

* fix formatting

---------

Co-authored-by: Eric Nordelo <eric.nordelo39@gmail.com>
Co-authored-by: Martín Triay <martriay@gmail.com>

* Add testing for AccessControl events (#674)

* feat: add testing for events

* feat: add tests for ownable events

* feat: improve tests

* feat: apply review updates

* Add testing for Pausable events (#676)

* feat: add testing for events

* feat: add tests for ownable events

* feat: add tests for pausable events

* Update src/openzeppelin/tests/security/test_pausable.cairo

Co-authored-by: Andrew Fleming <fleming.andrew@protonmail.com>

* feat: improve tests

* feat: apply review updates

* feat: apply review updates

---------

Co-authored-by: Andrew Fleming <fleming.andrew@protonmail.com>
Co-authored-by: Martín Triay <martriay@gmail.com>

* Add testing for ERC20 events (#677)

* feat: add testing for events

* feat: add tests for ownable events

* feat: add tests for pausable events

* feat: add tests for erc20 events

* Update src/openzeppelin/tests/security/test_pausable.cairo

Co-authored-by: Andrew Fleming <fleming.andrew@protonmail.com>

* feat: apply review updates

* feat: improve tests

* feat: apply review updates

* feat: apply review updates

* feat: apply review updates

---------

Co-authored-by: Andrew Fleming <fleming.andrew@protonmail.com>
Co-authored-by: Martín Triay <martriay@gmail.com>

* Add mint to erc721 preset constructor (#700)

* add _mint to constructor

* add constructor assertions

* fix formatting

* Add testing for ERC721 events (#678)

* feat: add testing for events

* feat: add tests for ownable events

* feat: add tests for pausable events

* feat: add tests for erc20 events

* feat: add tests for erc721 events

* Update src/openzeppelin/tests/security/test_pausable.cairo

Co-authored-by: Andrew Fleming <fleming.andrew@protonmail.com>

* feat: apply review updates

* feat: add test helper for events

* feat: improve tests

* feat: apply review updates

* feat: apply review updates

* feat: apply review updates

* feat: apply review updates

* feat: apply review updates

---------

Co-authored-by: Andrew Fleming <fleming.andrew@protonmail.com>

* Update README and fix scarb package (#688)

* update README to cairo-2 and scarb usage. bump scarb package version

* update readme

fix linter issues

fix linter issues

fix linter issues

update readme

* add main to CI

* update readme

* update readme

* rename starknet

* fix linter

* update readme

* Update README.md

Co-authored-by: Andrew Fleming <fleming-andrew@protonmail.com>

* Update README.md

Co-authored-by: Andrew Fleming <fleming-andrew@protonmail.com>

* update CONTRIBUTING

* fix linting

* Update CONTRIBUTING.md

Co-authored-by: Andrew Fleming <fleming-andrew@protonmail.com>

* Update CONTRIBUTING.md

Co-authored-by: Andrew Fleming <fleming-andrew@protonmail.com>

* apply review changes

* fix linter

* fix typo

---------

Co-authored-by: Andrew Fleming <fleming-andrew@protonmail.com>

* Bump scarb and fix dual721 test context (#703)

* bump scarb and cairo version

* fix testing context

---------

Co-authored-by: Martín Triay <martriay@gmail.com>

* add rc version (#708)

* remove unused imports (#707)

* Upgrade Cairo version and Scarb version to latest releases (#712)

* 👽️ Update code due to breaking changes

* ⬆️ Upgrade scarb and cairo versions

* 💄 Code format

* bump antora (#715)

* Add selector inline macro/fix `tokenURI` (#724)

* update selectors

* use inline selector

* remove selectors file

* remove import

* fix camel tokenURI

* fix formatting

* re-add selectors mod

* import from selectors mod

* fix formatting

* import selector

* fix: naming convention (#732)

* feat: add Errors modules (#691)

* Update account docs (#709)

* feat: update format and add api

* fix: typo

* feat: add counterfactual deployment doc

* feat: add API entries

* feat: add events

* Update docs/modules/ROOT/pages/accounts.adoc

Co-authored-by: Andrew Fleming <fleming.andrew@protonmail.com>

* Update docs/modules/ROOT/pages/accounts.adoc

Co-authored-by: Andrew Fleming <fleming.andrew@protonmail.com>

* Update docs/modules/ROOT/pages/accounts.adoc

Co-authored-by: Andrew Fleming <fleming.andrew@protonmail.com>

* Update docs/modules/ROOT/pages/guides/deployment.adoc

Co-authored-by: Andrew Fleming <fleming.andrew@protonmail.com>

* Update docs/modules/ROOT/pages/guides/deployment.adoc

Co-authored-by: Andrew Fleming <fleming.andrew@protonmail.com>

* feat: update from reviews

* feat: apply review updates

* feat: update docs

* Update docs/modules/ROOT/pages/api/account.adoc

Co-authored-by: Martín Triay <martriay@gmail.com>

* Update docs/modules/ROOT/pages/accounts.adoc

Co-authored-by: Martín Triay <martriay@gmail.com>

* Update docs/modules/ROOT/pages/accounts.adoc

Co-authored-by: Martín Triay <martriay@gmail.com>

* Update docs/modules/ROOT/pages/accounts.adoc

Co-authored-by: Martín Triay <martriay@gmail.com>

* Update docs/modules/ROOT/pages/accounts.adoc

Co-authored-by: Martín Triay <martriay@gmail.com>

* Update docs/modules/ROOT/pages/accounts.adoc

Co-authored-by: Martín Triay <martriay@gmail.com>

* Update docs/modules/ROOT/pages/accounts.adoc

Co-authored-by: Martín Triay <martriay@gmail.com>

* Update docs/modules/ROOT/pages/accounts.adoc

Co-authored-by: Martín Triay <martriay@gmail.com>

* Update docs/modules/ROOT/pages/api/account.adoc

Co-authored-by: Martín Triay <martriay@gmail.com>

* Update docs/modules/ROOT/pages/api/account.adoc

Co-authored-by: Martín Triay <martriay@gmail.com>

* Update docs/modules/ROOT/pages/accounts.adoc

Co-authored-by: Martín Triay <martriay@gmail.com>

* Update docs/modules/ROOT/pages/accounts.adoc

Co-authored-by: Martín Triay <martriay@gmail.com>

* Update docs/modules/ROOT/pages/accounts.adoc

Co-authored-by: Martín Triay <martriay@gmail.com>

* Update docs/modules/ROOT/pages/guides/deployment.adoc

Co-authored-by: Martín Triay <martriay@gmail.com>

* Update docs/modules/ROOT/pages/guides/deployment.adoc

Co-authored-by: Martín Triay <martriay@gmail.com>

* Update docs/modules/ROOT/pages/guides/deployment.adoc

Co-authored-by: Martín Triay <martriay@gmail.com>

* Update docs/modules/ROOT/pages/guides/deployment.adoc

Co-authored-by: Martín Triay <martriay@gmail.com>

* Update docs/modules/ROOT/pages/api/account.adoc

Co-authored-by: Martín Triay <martriay@gmail.com>

* Update docs/modules/ROOT/pages/api/account.adoc

Co-authored-by: Martín Triay <martriay@gmail.com>

* Update docs/modules/ROOT/pages/api/account.adoc

Co-authored-by: Martín Triay <martriay@gmail.com>

* Update docs/modules/ROOT/pages/api/account.adoc

Co-authored-by: Martín Triay <martriay@gmail.com>

* Update docs/modules/ROOT/pages/api/account.adoc

Co-authored-by: Martín Triay <martriay@gmail.com>

* Update docs/modules/ROOT/pages/api/account.adoc

Co-authored-by: Martín Triay <martriay@gmail.com>

* feat: apply review updates

* fix: account casing

* feat: add headers

* Update docs/modules/ROOT/pages/api/account.adoc

Co-authored-by: Martín Triay <martriay@gmail.com>

* feat: add link

* feat: move API

* Update docs/modules/ROOT/pages/accounts.adoc

Co-authored-by: Andrew Fleming <fleming.andrew@protonmail.com>

* Update docs/modules/ROOT/pages/accounts.adoc

Co-authored-by: Andrew Fleming <fleming.andrew@protonmail.com>

* Update docs/modules/ROOT/pages/accounts.adoc

Co-authored-by: Andrew Fleming <fleming.andrew@protonmail.com>

* Update docs/modules/ROOT/pages/accounts.adoc

Co-authored-by: Andrew Fleming <fleming.andrew@protonmail.com>

* refactor: update wording

* Update docs/antora.yml

Co-authored-by: Andrew Fleming <fleming.andrew@protonmail.com>

* Update docs/modules/ROOT/pages/api/account.adoc

Co-authored-by: Martín Triay <martriay@gmail.com>

* Update docs/modules/ROOT/pages/api/account.adoc

Co-authored-by: Martín Triay <martriay@gmail.com>

* feat: apply update reviews

* Update docs/modules/ROOT/pages/api/account.adoc

Co-authored-by: Martín Triay <martriay@gmail.com>

* refactor: UI

* fix: UI

* feat: focus on SRC6

* Update docs/modules/ROOT/pages/accounts.adoc

Co-authored-by: Martín Triay <martriay@gmail.com>

* feat: apply review updates

---------

Co-authored-by: Andrew Fleming <fleming.andrew@protonmail.com>
Co-authored-by: Martín Triay <martriay@gmail.com>

* Add Interface & Dispatchers docs (#730)

* feat: update format and add api

* fix: typo

* feat: add counterfactual deployment doc

* feat: add API entries

* feat: add events

* Update docs/modules/ROOT/pages/accounts.adoc

Co-authored-by: Andrew Fleming <fleming.andrew@protonmail.com>

* Update docs/modules/ROOT/pages/accounts.adoc

Co-authored-by: Andrew Fleming <fleming.andrew@protonmail.com>

* Update docs/modules/ROOT/pages/accounts.adoc

Co-authored-by: Andrew Fleming <fleming.andrew@protonmail.com>

* Update docs/modules/ROOT/pages/guides/deployment.adoc

Co-authored-by: Andrew Fleming <fleming.andrew@protonmail.com>

* Update docs/modules/ROOT/pages/guides/deployment.adoc

Co-authored-by: Andrew Fleming <fleming.andrew@protonmail.com>

* feat: update from reviews

* feat: apply review updates

* feat: update docs

* Update docs/modules/ROOT/pages/api/account.adoc

Co-authored-by: Martín Triay <martriay@gmail.com>

* Update docs/modules/ROOT/pages/accounts.adoc

Co-authored-by: Martín Triay <martriay@gmail.com>

* Update docs/modules/ROOT/pages/accounts.adoc

Co-authored-by: Martín Triay <martriay@gmail.com>

* Update docs/modules/ROOT/pages/accounts.adoc

Co-authored-by: Martín Triay <martriay@gmail.com>

* Update docs/modules/ROOT/pages/accounts.adoc

Co-authored-by: Martín Triay <martriay@gmail.com>

* Update docs/modules/ROOT/pages/accounts.adoc

Co-authored-by: Martín Triay <martriay@gmail.com>

* Update docs/modules/ROOT/pages/accounts.adoc

Co-authored-by: Martín Triay <martriay@gmail.com>

* Update docs/modules/ROOT/pages/accounts.adoc

Co-authored-by: Martín Triay <martriay@gmail.com>

* Update docs/modules/ROOT/pages/api/account.adoc

Co-authored-by: Martín Triay <martriay@gmail.com>

* Update docs/modules/ROOT/pages/api/account.adoc

Co-authored-by: Martín Triay <martriay@gmail.com>

* Update docs/modules/ROOT/pages/accounts.adoc

Co-authored-by: Martín Triay <martriay@gmail.com>

* Update docs/modules/ROOT/pages/accounts.adoc

Co-authored-by: Martín Triay <martriay@gmail.com>

* Update docs/modules/ROOT/pages/accounts.adoc

Co-authored-by: Martín Triay <martriay@gmail.com>

* Update docs/modules/ROOT/pages/guides/deployment.adoc

Co-authored-by: Martín Triay <martriay@gmail.com>

* Update docs/modules/ROOT/pages/guides/deployment.adoc

Co-authored-by: Martín Triay <martriay@gmail.com>

* Update docs/modules/ROOT/pages/guides/deployment.adoc

Co-authored-by: Martín Triay <martriay@gmail.com>

* Update docs/modules/ROOT/pages/guides/deployment.adoc

Co-authored-by: Martín Triay <martriay@gmail.com>

* Update docs/modules/ROOT/pages/api/account.adoc

Co-authored-by: Martín Triay <martriay@gmail.com>

* Update docs/modules/ROOT/pages/api/account.adoc

Co-authored-by: Martín Triay <martriay@gmail.com>

* Update docs/modules/ROOT/pages/api/account.adoc

Co-authored-by: Martín Triay <martriay@gmail.com>

* Update docs/modules/ROOT/pages/api/account.adoc

Co-authored-by: Martín Triay <martriay@gmail.com>

* Update docs/modules/ROOT/pages/api/account.adoc

Co-authored-by: Martín Triay <martriay@gmail.com>

* Update docs/modules/ROOT/pages/api/account.adoc

Co-authored-by: Martín Triay <martriay@gmail.com>

* feat: apply review updates

* fix: account casing

* feat: add headers

* Update docs/modules/ROOT/pages/api/account.adoc

Co-authored-by: Martín Triay <martriay@gmail.com>

* feat: add link

* feat: move API

* Update docs/modules/ROOT/pages/accounts.adoc

Co-authored-by: Andrew Fleming <fleming.andrew@protonmail.com>

* Update docs/modules/ROOT/pages/accounts.adoc

Co-authored-by: Andrew Fleming <fleming.andrew@protonmail.com>

* Update docs/modules/ROOT/pages/accounts.adoc

Co-authored-by: Andrew Fleming <fleming.andrew@protonmail.com>

* Update docs/modules/ROOT/pages/accounts.adoc

Co-authored-by: Andrew Fleming <fleming.andrew@protonmail.com>

* refactor: update wording

* Update docs/antora.yml

Co-authored-by: Andrew Fleming <fleming.andrew@protonmail.com>

* Update docs/modules/ROOT/pages/api/account.adoc

Co-authored-by: Martín Triay <martriay@gmail.com>

* Update docs/modules/ROOT/pages/api/account.adoc

Co-authored-by: Martín Triay <martriay@gmail.com>

* feat: apply update reviews

* Update docs/modules/ROOT/pages/api/account.adoc

Co-authored-by: Martín Triay <martriay@gmail.com>

* refactor: UI

* fix: UI

* feat: focus on SRC6

* add interface & dispatchers docs

* apply review feedback

* address feedback comments

---------

Co-authored-by: Eric Nordelo <eric.nordelo39@gmail.com>
Co-authored-by: Andrew Fleming <fleming.andrew@protonmail.com>

* Update overview docs (#735)

* feat: update format and add api

* fix: typo

* feat: add counterfactual deployment doc

* feat: add API entries

* feat: add events

* Update docs/modules/ROOT/pages/accounts.adoc

Co-authored-by: Andrew Fleming <fleming.andrew@protonmail.com>

* Update docs/modules/ROOT/pages/accounts.adoc

Co-authored-by: Andrew Fleming <fleming.andrew@protonmail.com>

* Update docs/modules/ROOT/pages/accounts.adoc

Co-authored-by: Andrew Fleming <fleming.andrew@protonmail.com>

* Update docs/modules/ROOT/pages/guides/deployment.adoc

Co-authored-by: Andrew Fleming <fleming.andrew@protonmail.com>

* Update docs/modules/ROOT/pages/guides/deployment.adoc

Co-authored-by: Andrew Fleming <fleming.andrew@protonmail.com>

* feat: update from reviews

* feat: apply review updates

* feat: update docs

* Update docs/modules/ROOT/pages/api/account.adoc

Co-authored-by: Martín Triay <martriay@gmail.com>

* Update docs/modules/ROOT/pages/accounts.adoc

Co-authored-by: Martín Triay <martriay@gmail.com>

* Update docs/modules/ROOT/pages/accounts.adoc

Co-authored-by: Martín Triay <martriay@gmail.com>

* Update docs/modules/ROOT/pages/accounts.adoc

Co-authored-by: Martín Triay <martriay@gmail.com>

* Update docs/modules/ROOT/pages/accounts.adoc

Co-authored-by: Martín Triay <martriay@gmail.com>

* Update docs/modules/ROOT/pages/accounts.adoc

Co-authored-by: Martín Triay <martriay@gmail.com>

* Update docs/modules/ROOT/pages/accounts.adoc

Co-authored-by: Martín Triay <martriay@gmail.com>

* Update docs/modules/ROOT/pages/accounts.adoc

Co-authored-by: Martín Triay <martriay@gmail.com>

* Update docs/modules/ROOT/pages/api/account.adoc

Co-authored-by: Martín Triay <martriay@gmail.com>

* Update docs/modules/ROOT/pages/api/account.adoc

Co-authored-by: Martín Triay <martriay@gmail.com>

* Update docs/modules/ROOT/pages/accounts.adoc

Co-authored-by: Martín Triay <martriay@gmail.com>

* Update docs/modules/ROOT/pages/accounts.adoc

Co-authored-by: Martín Triay <martriay@gmail.com>

* Update docs/modules/ROOT/pages/accounts.adoc

Co-authored-by: Martín Triay <martriay@gmail.com>

* Update docs/modules/ROOT/pages/guides/deployment.adoc

Co-authored-by: Martín Triay <martriay@gmail.com>

* Update docs/modules/ROOT/pages/guides/deployment.adoc

Co-authored-by: Martín Triay <martriay@gmail.com>

* Update docs/modules/ROOT/pages/guides/deployment.adoc

Co-authored-by: Martín Triay <martriay@gmail.com>

* Update docs/modules/ROOT/pages/guides/deployment.adoc

Co-authored-by: Martín Triay <martriay@gmail.com>

* Update docs/modules/ROOT/pages/api/account.adoc

Co-authored-by: Martín Triay <martriay@gmail.com>

* Update docs/modules/ROOT/pages/api/account.adoc

Co-authored-by: Martín Triay <martriay@gmail.com>

* Update docs/modules/ROOT/pages/api/account.adoc

Co-authored-by: Martín Triay <martriay@gmail.com>

* Update docs/modules/ROOT/pages/api/account.adoc

Co-authored-by: Martín Triay <martriay@gmail.com>

* Update docs/modules/ROOT/pages/api/account.adoc

Co-authored-by: Martín Triay <martriay@gmail.com>

* Update docs/modules/ROOT/pages/api/account.adoc

Co-authored-by: Martín Triay <martriay@gmail.com>

* feat: apply review updates

* fix: account casing

* feat: add headers

* Update docs/modules/ROOT/pages/api/account.adoc

Co-authored-by: Martín Triay <martriay@gmail.com>

* feat: add link

* feat: move API

* Update docs/modules/ROOT/pages/accounts.adoc

Co-authored-by: Andrew Fleming <fleming.andrew@protonmail.com>

* Update docs/modules/ROOT/pages/accounts.adoc

Co-authored-by: Andrew Fleming <fleming.andrew@protonmail.com>

* Update docs/modules/ROOT/pages/accounts.adoc

Co-authored-by: Andrew Fleming <fleming.andrew@protonmail.com>

* Update docs/modules/ROOT/pages/accounts.adoc

Co-authored-by: Andrew Fleming <fleming.andrew@protonmail.com>

* refactor: update wording

* Update docs/antora.yml

Co-authored-by: Andrew Fleming <fleming.andrew@protonmail.com>

* Update docs/modules/ROOT/pages/api/account.adoc

Co-authored-by: Martín Triay <martriay@gmail.com>

* Update docs/modules/ROOT/pages/api/account.adoc

Co-authored-by: Martín Triay <martriay@gmail.com>

* feat: apply update reviews

* Update docs/modules/ROOT/pages/api/account.adoc

Co-authored-by: Martín Triay <martriay@gmail.com>

* refactor: UI

* fix: UI

* feat: focus on SRC6

* Update docs/modules/ROOT/pages/accounts.adoc

Co-authored-by: Martín Triay <martriay@gmail.com>

* feat: update overview

* feat: apply review updates

* Update docs/modules/ROOT/pages/index.adoc

Co-authored-by: Martín Triay <martriay@gmail.com>

* feat: apply review updates

* Update docs/modules/ROOT/pages/index.adoc

Co-authored-by: Andrew Fleming <fleming.andrew@protonmail.com>

* feat: apply review updates

* Update docs/modules/ROOT/pages/index.adoc

Co-authored-by: Andrew Fleming <fleming.andrew@protonmail.com>

---------

Co-authored-by: Andrew Fleming <fleming.andrew@protonmail.com>
Co-authored-by: Martín Triay <martriay@gmail.com>

* remove underscore from name_ and symbol_ (#738)

* Add prefixes to storage members (#743)

* feat: add prefixes

* Update src/access/accesscontrol/accesscontrol.cairo

Co-authored-by: Andrew Fleming <fleming.andrew@protonmail.com>

---------

Co-authored-by: Andrew Fleming <fleming.andrew@protonmail.com>

* Sanitizing for release. (#736)

* refactor: sanitizing

* feat: sanitizing

* feat: apply review updates

* feat: apply review updates

* feat: migrate logic

* feat: update workflow

* fix: docs

* feat: apply update reviews

* refactor: remove imports

* Update src/access/ownable/ownable.cairo

Co-authored-by: Andrew Fleming <fleming.andrew@protonmail.com>

* feat: apply review updates

* feat: add comments to camelCase functions

* fix: comment

* Update docs/modules/ROOT/pages/api/access.adoc

Co-authored-by: Andrew Fleming <fleming.andrew@protonmail.com>

* feat: apply review updates

* feat: update docs

* feat: update comments

* Update src/tests/utils.cairo

Co-authored-by: Andrew Fleming <fleming.andrew@protonmail.com>

---------

Co-authored-by: Andrew <fleming-andrew@protonmail.com>
Co-authored-by: Martín Triay <martriay@gmail.com>
Co-authored-by: kongtaoxing <69096526+kongtaoxing@users.noreply.github.com>
Co-authored-by: Hadrien Croubois <hadrien.croubois@gmail.com>
Co-authored-by: Andrew Fleming <fleming.andrew@protonmail.com>
Co-authored-by: maciektr <mtratnowiecki@gmail.com>
Co-authored-by: Bal7hazar @ Carbonable <bal7hazar@proton.me>
  • Loading branch information
8 people committed Oct 12, 2023
1 parent af876a7 commit b08d0e0
Show file tree
Hide file tree
Showing 9 changed files with 311 additions and 222 deletions.
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]
[[Ownable-transferOwnership]]
==== `[.contract-item-name]#++transferOwnership++#++(ref self: ContractState, newOwner: ContractAddress)++` [.item-kind]#external#

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();
}
}

#[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

0 comments on commit b08d0e0

Please sign in to comment.