From 4f1d539232feaed4967a56ca024d7495befab255 Mon Sep 17 00:00:00 2001 From: Eric Nordelo Date: Fri, 2 Aug 2024 13:57:35 +0200 Subject: [PATCH] Migrate to multiple packages (workspace) (#1065) * Migrate erc20 tests (#1022) * feat: migrate event tests * feat: update workflow * feat: add foundry utils * feat: finish erc20 and erc20votes migration * feat: remove dual case tests * refactor: format files * refactor: variable name * Update src/tests/token.cairo Co-authored-by: Andrew Fleming * Update src/tests/token/erc20.cairo Co-authored-by: Andrew Fleming * Update src/tests/utils/foundry.cairo Co-authored-by: Andrew Fleming * Update src/tests/token/erc20/test_erc20_votes.cairo Co-authored-by: Andrew Fleming * feat: apply review updates --------- Co-authored-by: Andrew Fleming * Snforge utils and some common changes (#1030) * Update gitignore with snfoundry cache dir * Delete foundry utils file * Add snfoundry-related test utils, comment out previous utils * Update ERC20 event helpers * Update ERC20 tests * Update ERC20Votes tests * Run linter * Add util function to drop single event * Fix review issues * Make Github workflow run on every PR * Fix review issues * Bump snforge version * Support snforge 0.26 in test utils * Update ERC20 tests to support snforge upgrade * Run linter * Re-add dual20 tests (#1028) * feat: migrate event tests * feat: update workflow * feat: add foundry utils * feat: finish erc20 and erc20votes migration * feat: remove dual case tests * refactor: format files * refactor: variable name * Update src/tests/token.cairo Co-authored-by: Andrew Fleming * Update src/tests/token/erc20.cairo Co-authored-by: Andrew Fleming * Update src/tests/utils/foundry.cairo Co-authored-by: Andrew Fleming * Update src/tests/token/erc20/test_erc20_votes.cairo Co-authored-by: Andrew Fleming * feat: apply review updates * feat: readd dual20 tests * refactor: remove unnecessary import * feat: add dual20 import --------- Co-authored-by: Andrew Fleming * Migrate security tests (#1034) * migrate pausable and initializable tests * migrate reentrancy guard tests * clean up tests * fix fmt * add event trait to pausable, fix tests * Apply suggestions from code review Co-authored-by: Eric Nordelo * fix fmt --------- Co-authored-by: Eric Nordelo * refacto repo into packages * fmt * Migrate erc1155 tests (#1037) * feat: update common module * feat: migrate dual modules * feat: finish component test migration * refactor: remove unnecessary imports * feat: apply review updates * Migrate erc721 tests (#1027) * feat: migrate event tests * feat: update workflow * feat: add foundry utils * feat: finish erc20 and erc20votes migration * feat: remove dual case tests * refactor: format files * refactor: variable name * Update src/tests/token.cairo Co-authored-by: Andrew Fleming * Update src/tests/token/erc20.cairo Co-authored-by: Andrew Fleming * Update src/tests/utils/foundry.cairo Co-authored-by: Andrew Fleming * Update src/tests/token/erc20/test_erc20_votes.cairo Co-authored-by: Andrew Fleming * feat: apply review updates * feat: migrate erc721 components tests * refactor: remove extra line * feat: apply review updates * feat: update utilities * feat: apply review updates * fix: ignore tests --------- Co-authored-by: Andrew Fleming * Check ignored tests (#1049) * test: check ignored tests and add reason * feat: apply review updates * Migrate Ownable tests (#1033) * Update ERC20Votes tests * Run linter * Add test helpers for Ownable tests * Migrate Ownable tests * Migrate OwnableTwoStep tests * Migrate Ownable Dual Dispatcher tests * Support event changes in snforge 0.26 * Resolve review issues * Address review comments * Migrate Upgrades tests (#1051) * Migrate Upgrades tests to Foundry * Update src/tests/upgrades/test_upgradeable.cairo Co-authored-by: Andrew Fleming * Update src/tests/upgrades/test_upgradeable.cairo Co-authored-by: Andrew Fleming --------- Co-authored-by: Eric Nordelo Co-authored-by: Andrew Fleming * Migrate erc20 preset tests (#1055) * feat: include erc20 preset tests * feat: tests updated * feat: remove unused imports * feat: add deployments * Update src/tests/utils/common.cairo Co-authored-by: Andrew Fleming * feat: apply review updates --------- Co-authored-by: Andrew Fleming * feat: update ignored tests messages (#1056) * Migrate erc1155 preset tests (#1057) * feat: update tests * refactor: remove unnecessary import * Migrate cryptography and UDC tests (#1059) * fix import name * migrate cryptography tests * migrate udc tests * fix fmt * fix impl name * fix event assertions * re-add class hash helper * Migrate eth account tests (#1058) * feat: update dual_eth_account tests * feat: update eth_account tests * refactor: remove unused helpers * refactor: some inconsistencies * Update src/tests/account/ethereum/test_eth_account.cairo Co-authored-by: immrsd <103599616+immrsd@users.noreply.github.com> * feat: apply review updates * refactor: format files * Update src/tests/account/ethereum/test_eth_account.cairo Co-authored-by: Andrew Fleming --------- Co-authored-by: immrsd <103599616+immrsd@users.noreply.github.com> Co-authored-by: Andrew Fleming * Migrate eth account preset tests (#1060) * feat: update dual_eth_account tests * feat: update eth_account tests * refactor: remove unused helpers * feat: update eth account preset tests * Update src/tests/account/ethereum/test_eth_account.cairo Co-authored-by: immrsd <103599616+immrsd@users.noreply.github.com> * Update src/tests/presets/test_eth_account.cairo Co-authored-by: immrsd <103599616+immrsd@users.noreply.github.com> * feat: apply review updates --------- Co-authored-by: immrsd <103599616+immrsd@users.noreply.github.com> * Migrate AccessControl Tests (#1044) * Migrate AccessControl tests * Migrate AccessControl Dual Dispatcher tests * Fix imports * Address review comments * Update error messages * Bring back separator line * Fix ignore reasons in access module * Fix review issues * Migrate Starknet Account tests (#1050) * Update test utils and helpers * Update signature tests * Update account tests * Update dual account tests * Run linter * Run linter * Fix review issues * Update ignore reason messages * Run linter * Support eth account tests changes * Run linter * Improve setup functions, remove unused imports * Remove unnecessary accept_ownership step, make use of serialized_sign fn * feat: make contracts build * feat: update packages Scarb.toml * refactor: remove gitmodules file * feat: refactor tests * feat: update workflow * feat: test utils * feat: add missing tests * fix: tests * fix: remaining tests * refactor: format files * tmp: workflow update * feat: add entry to CHANGELOG and update README * doc: update imports * Migrate Starknet Account Preset tests (#1069) * Update test utils and helpers * Update signature tests * Update account tests * Update dual account tests * Run linter * Run linter * Fix review issues * Update ignore reason messages * Run linter * Support eth account tests changes * Run linter * Improve setup functions, remove unused imports * Remove unnecessary accept_ownership step, make use of serialized_sign fn * Migrate Starknet Account Preset tests, make some code improvements * Run linter * Remove unnecessary clone * Update the comment for assert_entrypoint_not_found_error function * Minor review fixes * Bump scarb, merge changes from main in snforge migration (#1076) * Remove unnecessary `mut`, minor fixes (#1032) * clean up code * change array syntax * fix fmt * Improve SNIP12 examples (#1036) * docs: improve examples * refactor: remove empty line * Update docs/modules/ROOT/pages/guides/snip12.adoc Co-authored-by: Andrew Fleming --------- Co-authored-by: Andrew Fleming * Release v0.15.0-rc.0 (#1039) * feat: update CHANGELOG * Bump version to 0.15.0-rc.0 * docs: add missing header * feat: apply review suggestions --------- Co-authored-by: ericnordelo * Bump cairo to 2.7.0-rc.1 (#1025) * feat: migrate modules * feat: delete cairo_project.toml * feat: update tests * feat: apply review updates * fix: remove extra line * feat: add CHANGELOG entry * fix: CHANGELOG * Bump Scarb to 2.7.0-rc.2 (#1052) * bump scarb to 2.7.0-rc.2 * add changelog entry * update changelog entry * bump scarb in installation page * Add timelock component (#996) * start timelock comp draft * move timelock to own dir, finish drafting component * tmp: add utility impls * add timelock mock * add test mod for timelock * fix commnet * add constructor to timelock mock * set min_delay in initializer * start tests * fix fmt * fix schedule assertion * add schedule tests * fix fmt * remove unused import * fix errs, _before_call * start execute tests * fix fmt * fix after_call * add execute tests * add abi interface * add reentrancy mock for timelock * add tests for cancel and update_delay * fix hash_op test * add execute with predecessor test * add timelock utils, add operation_state debug impl * fix fmt * improve imports * improve _execute * add basic mock for tests * add tmp call struct * add batch fns to interface * add batch fns * refactor tests to use dedicated mock, add batch tests * fix fmt * remove use clause * add timelock mixin * fix interface name * improve event assertions * fix execute and schedule events * fix fmt * add safe token transfer tests * fix fmt * tidy up code * add descriptions to events * clean up code * inline CallPartialEq fns * start fn descriptions * remove comments * remove comment * fix fmt * add changelog entries * improve spacing * add line break to hash test * clean up tests * clean up tests * fix constants in attacker impl * add initializer helper, register access control support * add _before_call and _after_call tests * fix reentrant batch mock call * add _schedule and _execute tests * add timelock description * fix formatting * fix comments * fix comment * fmt * tidy up tests * remove batch helper fn * remove event from mocks * Apply suggestions from code review Co-authored-by: Eric Nordelo * update spdx * remove token receiver support * add additional cancel tests * Apply suggestions from code review Co-authored-by: Eric Nordelo * initializer: remove mut, use while loop * fix fmt * add assert_only_self fn * fix getter comments re: pending/waiting * add assert_only_role * add specific op errors * make event names consistent * fix test * remove serialization from HashCallImpl * remove unused components from mock * clean up code * update to 2.7.0-rc.1 * fix fmt * import Call from corelib * update spdx * fix fmt * move OperationState, derive debug * fix fmt * fix hash impls * add for loops * fix PartialEq, add tests * fix fmt * simplify mixin fns * switch Poseidon to Pedersen * make admin a req in initializer * update tests with admin * fix fmt * fix comment * undo changes * add no admin initializer test --------- Co-authored-by: Eric Nordelo * bump scarb to 2.7.0-rc.4 (#1064) * bump scarb to 2.7.0-rc.4 * add changelog * bump scarb in installation page * feat: update workflow and fix warning (#1066) * Add actionlint (#1067) * add actionlint for workflows * remove codecov and gitmodules * bump checkout to v4, add double quotes, fmt * bump md lint * re-add cairo version * group redirects * fix link in security * add local actionlint matcher json * re-add changelog entry * add tmp usc install to ci * fix ci --------- Co-authored-by: Eric Nordelo Co-authored-by: ericnordelo Co-authored-by: JChoy * Migrate timelock tests (#1061) * Remove unnecessary `mut`, minor fixes (#1032) * clean up code * change array syntax * fix fmt * Improve SNIP12 examples (#1036) * docs: improve examples * refactor: remove empty line * Update docs/modules/ROOT/pages/guides/snip12.adoc Co-authored-by: Andrew Fleming --------- Co-authored-by: Andrew Fleming * Release v0.15.0-rc.0 (#1039) * feat: update CHANGELOG * Bump version to 0.15.0-rc.0 * docs: add missing header * feat: apply review suggestions --------- Co-authored-by: ericnordelo * Bump cairo to 2.7.0-rc.1 (#1025) * feat: migrate modules * feat: delete cairo_project.toml * feat: update tests * feat: apply review updates * fix: remove extra line * feat: add CHANGELOG entry * fix: CHANGELOG * Bump Scarb to 2.7.0-rc.2 (#1052) * bump scarb to 2.7.0-rc.2 * add changelog entry * update changelog entry * bump scarb in installation page * Add timelock component (#996) * start timelock comp draft * move timelock to own dir, finish drafting component * tmp: add utility impls * add timelock mock * add test mod for timelock * fix commnet * add constructor to timelock mock * set min_delay in initializer * start tests * fix fmt * fix schedule assertion * add schedule tests * fix fmt * remove unused import * fix errs, _before_call * start execute tests * fix fmt * fix after_call * add execute tests * add abi interface * add reentrancy mock for timelock * add tests for cancel and update_delay * fix hash_op test * add execute with predecessor test * add timelock utils, add operation_state debug impl * fix fmt * improve imports * improve _execute * add basic mock for tests * add tmp call struct * add batch fns to interface * add batch fns * refactor tests to use dedicated mock, add batch tests * fix fmt * remove use clause * add timelock mixin * fix interface name * improve event assertions * fix execute and schedule events * fix fmt * add safe token transfer tests * fix fmt * tidy up code * add descriptions to events * clean up code * inline CallPartialEq fns * start fn descriptions * remove comments * remove comment * fix fmt * add changelog entries * improve spacing * add line break to hash test * clean up tests * clean up tests * fix constants in attacker impl * add initializer helper, register access control support * add _before_call and _after_call tests * fix reentrant batch mock call * add _schedule and _execute tests * add timelock description * fix formatting * fix comments * fix comment * fmt * tidy up tests * remove batch helper fn * remove event from mocks * Apply suggestions from code review Co-authored-by: Eric Nordelo * update spdx * remove token receiver support * add additional cancel tests * Apply suggestions from code review Co-authored-by: Eric Nordelo * initializer: remove mut, use while loop * fix fmt * add assert_only_self fn * fix getter comments re: pending/waiting * add assert_only_role * add specific op errors * make event names consistent * fix test * remove serialization from HashCallImpl * remove unused components from mock * clean up code * update to 2.7.0-rc.1 * fix fmt * import Call from corelib * update spdx * fix fmt * move OperationState, derive debug * fix fmt * fix hash impls * add for loops * fix PartialEq, add tests * fix fmt * simplify mixin fns * switch Poseidon to Pedersen * make admin a req in initializer * update tests with admin * fix fmt * fix comment * undo changes * add no admin initializer test --------- Co-authored-by: Eric Nordelo * fix fmt * bump scarb to 2.7.0-rc.4 (#1064) * bump scarb to 2.7.0-rc.4 * add changelog * bump scarb in installation page * fix fmt * feat: update workflow and fix warning (#1066) * bump scarb * add tmp usc install in ci * fix changelog --------- Co-authored-by: Eric Nordelo Co-authored-by: ericnordelo Co-authored-by: JChoy * Update docs/modules/ROOT/pages/components.adoc Co-authored-by: Andrew Fleming * Update docs/modules/ROOT/pages/components.adoc Co-authored-by: Andrew Fleming * feat: apply review updates * feat: update governance package * refactor: format files * refactor: remove unused files * fix: workflow * refactor: remove warnings * feat: remove old tests --------- Co-authored-by: Andrew Fleming Co-authored-by: immrsd <103599616+immrsd@users.noreply.github.com> Co-authored-by: Andrew Fleming Co-authored-by: Alex Metelli Co-authored-by: ericnordelo Co-authored-by: JChoy --- .github/workflows/test.yml | 4 +- CHANGELOG.md | 11 ++ README.md | 8 + Scarb.lock | 90 +++++++++++ Scarb.toml | 53 ++++++- docs/modules/ROOT/pages/api/utilities.adoc | 12 +- packages/access/Scarb.toml | 31 ++++ .../access/src}/accesscontrol.cairo | 0 .../src}/accesscontrol/accesscontrol.cairo | 8 +- .../accesscontrol/dual_accesscontrol.cairo | 8 +- .../access/src}/accesscontrol/interface.cairo | 0 .../access/src/lib.cairo | 2 + .../access/src}/ownable.cairo | 0 .../access/src}/ownable/dual_ownable.cairo | 8 +- .../access/src}/ownable/interface.cairo | 0 .../access/src}/ownable/ownable.cairo | 4 +- .../access/src/tests.cairo | 8 +- .../access/src/tests}/common.cairo | 11 +- packages/access/src/tests/mocks.cairo | 3 + .../tests/mocks/accesscontrol_mocks.cairo | 18 +-- .../tests/mocks/non_implementing_mock.cairo | 0 .../src}/tests/mocks/ownable_mocks.cairo | 8 +- .../src/tests}/test_accesscontrol.cairo | 14 +- .../src/tests}/test_dual_accesscontrol.cairo | 16 +- .../access/src/tests}/test_dual_ownable.cairo | 10 +- .../access/src/tests}/test_ownable.cairo | 10 +- .../src/tests}/test_ownable_twostep.cairo | 14 +- packages/account/Scarb.toml | 32 ++++ .../account/src}/account.cairo | 12 +- .../account/src}/dual_account.cairo | 8 +- .../account/src}/dual_eth_account.cairo | 10 +- .../account/src}/eth_account.cairo | 16 +- .../account/src}/interface.cairo | 0 .../account/src/lib.cairo | 2 + packages/account/src/tests.cairo | 8 + .../account/src/tests}/ethereum.cairo | 4 +- .../account/src/tests}/ethereum/common.cairo | 40 ++--- .../ethereum/test_dual_eth_account.cairo | 20 +-- .../tests}/ethereum/test_eth_account.cairo | 30 ++-- packages/account/src/tests/mocks.cairo | 4 + .../src}/tests/mocks/account_mocks.cairo | 12 +- .../account/src/tests/mocks/erc20_mocks.cairo | 40 +++++ .../src}/tests/mocks/eth_account_mocks.cairo | 22 +-- .../tests/mocks/non_implementing_mock.cairo | 10 ++ .../account/src/tests}/starknet.cairo | 3 + .../account/src/tests}/starknet/common.cairo | 16 +- .../src/tests}/starknet/test_account.cairo | 28 ++-- .../tests}/starknet/test_dual_account.cairo | 16 +- .../account/src/tests}/test_secp256k1.cairo | 2 +- .../account/src/tests}/test_signature.cairo | 4 +- .../account/src}/utils.cairo | 0 .../account/src}/utils/secp256k1.cairo | 4 +- .../account/src}/utils/signature.cairo | 2 +- packages/governance/Scarb.toml | 32 ++++ .../governance/src/lib.cairo | 2 + packages/governance/src/tests.cairo | 6 + packages/governance/src/tests/mocks.cairo | 2 + .../tests/mocks/non_implementing_mock.cairo | 10 ++ .../src}/tests/mocks/timelock_mocks.cairo | 8 +- .../governance/src/tests}/test_timelock.cairo | 50 +++--- .../governance/src/tests}/test_utils.cairo | 2 +- .../governance/src}/timelock.cairo | 0 .../governance/src}/timelock/interface.cairo | 2 +- .../src}/timelock/timelock_controller.cairo | 16 +- .../governance/src}/timelock/utils.cairo | 0 .../src}/timelock/utils/call_impls.cairo | 6 +- .../governance/src}/utils.cairo | 0 .../governance/src}/utils/interfaces.cairo | 0 .../src}/utils/interfaces/votes.cairo | 0 packages/introspection/Scarb.toml | 30 ++++ .../introspection/src}/interface.cairo | 0 .../introspection/src/lib.cairo | 2 + .../introspection/src}/src5.cairo | 2 +- packages/introspection/src/tests.cairo | 4 + packages/introspection/src/tests/mocks.cairo | 1 + .../src}/tests/mocks/src5_mocks.cairo | 2 +- .../introspection/src/tests}/test_src5.cairo | 8 +- packages/presets/Scarb.toml | 35 +++++ .../presets/src}/account.cairo | 12 +- .../presets/src}/erc1155.cairo | 12 +- .../presets/src}/erc20.cairo | 10 +- .../presets/src}/erc721.cairo | 12 +- .../presets/src}/eth_account.cairo | 10 +- .../presets/src}/interfaces.cairo | 0 .../presets/src}/interfaces/account.cairo | 0 .../presets/src}/interfaces/erc1155.cairo | 0 .../presets/src}/interfaces/erc20.cairo | 0 .../presets/src}/interfaces/erc721.cairo | 0 .../presets/src}/interfaces/eth_account.cairo | 2 +- packages/presets/src/lib.cairo | 16 ++ .../presets/src/tests.cairo | 9 +- .../presets/src}/tests/mocks.cairo | 9 -- .../src/tests/mocks/account_mocks.cairo | 145 +++++++++++++++++ .../src/tests/mocks/erc1155_mocks.cairo | 101 ++++++++++++ .../tests/mocks/erc1155_receiver_mocks.cairo | 43 +++++ .../presets/src/tests/mocks/erc20_mocks.cairo | 79 ++++++++++ .../src/tests/mocks/erc721_mocks.cairo | 50 ++++++ .../tests/mocks/erc721_receiver_mocks.cairo | 119 ++++++++++++++ .../src/tests/mocks/eth_account_mocks.cairo | 39 +++++ .../tests/mocks/non_implementing_mock.cairo | 10 ++ .../presets/src/tests/mocks/src5_mocks.cairo | 22 +++ .../presets/src/tests}/test_account.cairo | 43 +++-- .../presets/src/tests}/test_erc1155.cairo | 34 ++-- .../presets/src/tests}/test_erc20.cairo | 32 ++-- .../presets/src/tests}/test_erc721.cairo | 36 ++--- .../presets/src/tests}/test_eth_account.cairo | 34 ++-- .../src/tests}/test_universal_deployer.cairo | 19 ++- .../presets/src}/universal_deployer.cairo | 4 +- packages/security/Scarb.toml | 31 ++++ .../security/src}/initializable.cairo | 2 +- .../security/src}/interface.cairo | 0 .../security/src/lib.cairo | 2 + .../security/src}/pausable.cairo | 2 +- .../security/src}/reentrancyguard.cairo | 0 .../security/src/tests.cairo | 5 + packages/security/src/tests/mocks.cairo | 3 + .../tests/mocks/initializable_mocks.cairo | 2 +- .../src}/tests/mocks/pausable_mocks.cairo | 2 +- .../src}/tests/mocks/reentrancy_mocks.cairo | 2 +- .../src/tests}/test_initializable.cairo | 6 +- .../security/src/tests}/test_pausable.cairo | 12 +- .../src/tests}/test_reentrancyguard.cairo | 8 +- packages/token/Scarb.toml | 33 ++++ .../token/src}/erc1155.cairo | 0 .../token/src}/erc1155/dual1155.cairo | 8 +- .../src}/erc1155/dual1155_receiver.cairo | 8 +- .../token/src}/erc1155/erc1155.cairo | 19 ++- .../token/src}/erc1155/erc1155_receiver.cairo | 10 +- .../token/src}/erc1155/interface.cairo | 0 {src/token => packages/token/src}/erc20.cairo | 0 .../token/src}/erc20/dual20.cairo | 8 +- .../token/src}/erc20/erc20.cairo | 6 +- .../token/src}/erc20/extensions.cairo | 0 .../src}/erc20/extensions/erc20_votes.cairo | 16 +- .../token/src}/erc20/interface.cairo | 2 +- .../token => packages/token/src}/erc721.cairo | 0 .../token/src}/erc721/dual721.cairo | 8 +- .../token/src}/erc721/dual721_receiver.cairo | 8 +- .../token/src}/erc721/erc721.cairo | 15 +- .../token/src}/erc721/erc721_receiver.cairo | 12 +- .../token/src}/erc721/interface.cairo | 0 .../token/src/lib.cairo | 2 + packages/token/src/tests.cairo | 5 + .../token/src/tests}/erc1155.cairo | 6 +- .../token/src/tests}/erc1155/common.cairo | 28 ++-- .../src/tests}/erc1155/test_dual1155.cairo | 16 +- .../erc1155/test_dual1155_receiver.cairo | 12 +- .../src/tests}/erc1155/test_erc1155.cairo | 22 +-- .../erc1155/test_erc1155_receiver.cairo | 12 +- .../token/src/tests}/erc20.cairo | 5 +- .../token/src/tests}/erc20/common.cairo | 8 +- .../token/src/tests}/erc20/test_dual20.cairo | 12 +- .../token/src/tests}/erc20/test_erc20.cairo | 29 ++-- .../src/tests}/erc20/test_erc20_votes.cairo | 40 ++--- .../token/src/tests}/erc721.cairo | 6 +- .../token/src/tests}/erc721/common.cairo | 8 +- .../src/tests}/erc721/test_dual721.cairo | 18 +-- .../tests}/erc721/test_dual721_receiver.cairo | 19 ++- .../token/src/tests}/erc721/test_erc721.cairo | 36 ++--- .../tests}/erc721/test_erc721_receiver.cairo | 12 +- packages/token/src/tests/mocks.cairo | 9 ++ .../token/src/tests/mocks/account_mocks.cairo | 145 +++++++++++++++++ .../src}/tests/mocks/erc1155_mocks.cairo | 12 +- .../tests/mocks/erc1155_receiver_mocks.cairo | 14 +- .../token/src}/tests/mocks/erc20_mocks.cairo | 6 +- .../src}/tests/mocks/erc20_votes_mocks.cairo | 10 +- .../token/src}/tests/mocks/erc721_mocks.cairo | 14 +- .../tests/mocks/erc721_receiver_mocks.cairo | 14 +- .../tests/mocks/non_implementing_mock.cairo | 10 ++ .../token/src/tests/mocks/src5_mocks.cairo | 22 +++ packages/upgrades/Scarb.toml | 31 ++++ .../upgrades/src}/interface.cairo | 0 .../upgrades/src/lib.cairo | 2 + packages/upgrades/src/tests.cairo | 5 + .../upgrades/src/tests}/common.cairo | 8 +- packages/upgrades/src/tests/mocks.cairo | 1 + .../src}/tests/mocks/upgrades_mocks.cairo | 4 +- .../src/tests}/test_upgradeable.cairo | 16 +- .../upgrades/src}/upgradeable.cairo | 0 packages/utils/Scarb.toml | 28 ++++ .../utils/src}/cryptography.cairo | 0 .../utils/src}/cryptography/interface.cairo | 0 .../utils/src}/cryptography/nonces.cairo | 2 +- .../utils/src}/cryptography/snip12.cairo | 0 .../utils/src}/deployments.cairo | 5 +- .../utils/src}/deployments/interface.cairo | 0 .../utils/src}/interfaces.cairo | 4 +- .../utils/src/lib.cairo | 6 + {src/utils => packages/utils/src}/math.cairo | 0 .../utils/src}/selectors.cairo | 0 {src/utils => packages/utils/src}/serde.cairo | 0 .../utils/src}/structs.cairo | 0 .../utils/src}/structs/checkpoint.cairo | 19 ++- .../utils/src}/structs/storage_array.cairo | 0 .../utils/src/test_utils.cairo | 2 +- .../utils/src/test_utils}/common.cairo | 0 packages/utils/src/test_utils/constants.cairo | 148 ++++++++++++++++++ .../utils/src/test_utils}/deployment.cairo | 5 +- .../utils/src/test_utils}/events.cairo | 0 .../utils/src/test_utils}/signing.cairo | 0 .../utils/src/tests.cairo | 2 + packages/utils/src/tests/mocks.cairo | 1 + .../utils/src}/tests/mocks/nonces_mocks.cairo | 2 +- .../utils/src/tests}/test_nonces.cairo | 10 +- .../utils/src/tests}/test_snip12.cairo | 4 +- .../utils/src}/unwrap_and_cast.cairo | 0 src/lib.cairo | 19 ++- src/presets.cairo | 14 -- src/tests.cairo | 21 --- src/tests/account.cairo | 5 - src/tests/governance.cairo | 2 - src/tests/introspection.cairo | 1 - src/tests/token.cairo | 3 - src/tests/upgrades.cairo | 3 - src/tests/utils/constants.cairo | 148 ------------------ 215 files changed, 2231 insertions(+), 890 deletions(-) create mode 100644 packages/access/Scarb.toml rename {src/access => packages/access/src}/accesscontrol.cairo (100%) rename {src/access => packages/access/src}/accesscontrol/accesscontrol.cairo (97%) rename {src/access => packages/access/src}/accesscontrol/dual_accesscontrol.cairo (94%) rename {src/access => packages/access/src}/accesscontrol/interface.cairo (100%) rename src/access.cairo => packages/access/src/lib.cairo (71%) rename {src/access => packages/access/src}/ownable.cairo (100%) rename {src/access => packages/access/src}/ownable/dual_ownable.cairo (89%) rename {src/access => packages/access/src}/ownable/interface.cairo (100%) rename {src/access => packages/access/src}/ownable/ownable.cairo (99%) rename src/tests/access.cairo => packages/access/src/tests.cairo (54%) rename {src/tests/access => packages/access/src/tests}/common.cairo (72%) create mode 100644 packages/access/src/tests/mocks.cairo rename {src => packages/access/src}/tests/mocks/accesscontrol_mocks.cairo (91%) rename {src => packages/access/src}/tests/mocks/non_implementing_mock.cairo (100%) rename {src => packages/access/src}/tests/mocks/ownable_mocks.cairo (95%) rename {src/tests/access => packages/access/src/tests}/test_accesscontrol.cairo (96%) rename {src/tests/access => packages/access/src/tests}/test_dual_accesscontrol.cairo (94%) rename {src/tests/access => packages/access/src/tests}/test_dual_ownable.cairo (94%) rename {src/tests/access => packages/access/src/tests}/test_ownable.cairo (94%) rename {src/tests/access => packages/access/src/tests}/test_ownable_twostep.cairo (95%) create mode 100644 packages/account/Scarb.toml rename {src/account => packages/account/src}/account.cairo (96%) rename {src/account => packages/account/src}/dual_account.cairo (92%) rename {src/account => packages/account/src}/dual_eth_account.cairo (90%) rename {src/account => packages/account/src}/eth_account.cairo (96%) rename {src/account => packages/account/src}/interface.cairo (100%) rename src/account.cairo => packages/account/src/lib.cairo (92%) create mode 100644 packages/account/src/tests.cairo rename {src/tests/account => packages/account/src/tests}/ethereum.cairo (54%) rename {src/tests/account => packages/account/src/tests}/ethereum/common.cairo (69%) rename {src/tests/account => packages/account/src/tests}/ethereum/test_dual_eth_account.cairo (91%) rename {src/tests/account => packages/account/src/tests}/ethereum/test_eth_account.cairo (94%) create mode 100644 packages/account/src/tests/mocks.cairo rename {src => packages/account/src}/tests/mocks/account_mocks.cairo (94%) create mode 100644 packages/account/src/tests/mocks/erc20_mocks.cairo rename {src => packages/account/src}/tests/mocks/eth_account_mocks.cairo (91%) create mode 100644 packages/account/src/tests/mocks/non_implementing_mock.cairo rename {src/tests/account => packages/account/src/tests}/starknet.cairo (70%) rename {src/tests/account => packages/account/src/tests}/starknet/common.cairo (83%) rename {src/tests/account => packages/account/src/tests}/starknet/test_account.cairo (94%) rename {src/tests/account => packages/account/src/tests}/starknet/test_dual_account.cairo (92%) rename {src/tests/account => packages/account/src/tests}/test_secp256k1.cairo (98%) rename {src/tests/account => packages/account/src/tests}/test_signature.cairo (95%) rename {src/account => packages/account/src}/utils.cairo (100%) rename {src/account => packages/account/src}/utils/secp256k1.cairo (93%) rename {src/account => packages/account/src}/utils/signature.cairo (96%) create mode 100644 packages/governance/Scarb.toml rename src/governance.cairo => packages/governance/src/lib.cairo (73%) create mode 100644 packages/governance/src/tests.cairo create mode 100644 packages/governance/src/tests/mocks.cairo create mode 100644 packages/governance/src/tests/mocks/non_implementing_mock.cairo rename {src => packages/governance/src}/tests/mocks/timelock_mocks.cairo (94%) rename {src/tests/governance => packages/governance/src/tests}/test_timelock.cairo (97%) rename {src/tests/governance => packages/governance/src/tests}/test_utils.cairo (98%) rename {src/governance => packages/governance/src}/timelock.cairo (100%) rename {src/governance => packages/governance/src}/timelock/interface.cairo (98%) rename {src/governance => packages/governance/src}/timelock/timelock_controller.cairo (97%) rename {src/governance => packages/governance/src}/timelock/utils.cairo (100%) rename {src/governance => packages/governance/src}/timelock/utils/call_impls.cairo (83%) rename {src/governance => packages/governance/src}/utils.cairo (100%) rename {src/governance => packages/governance/src}/utils/interfaces.cairo (100%) rename {src/governance => packages/governance/src}/utils/interfaces/votes.cairo (100%) create mode 100644 packages/introspection/Scarb.toml rename {src/introspection => packages/introspection/src}/interface.cairo (100%) rename src/introspection.cairo => packages/introspection/src/lib.cairo (73%) rename {src/introspection => packages/introspection/src}/src5.cairo (97%) create mode 100644 packages/introspection/src/tests.cairo create mode 100644 packages/introspection/src/tests/mocks.cairo rename {src => packages/introspection/src}/tests/mocks/src5_mocks.cairo (88%) rename {src/tests/introspection => packages/introspection/src/tests}/test_src5.cairo (83%) create mode 100644 packages/presets/Scarb.toml rename {src/presets => packages/presets/src}/account.cairo (83%) rename {src/presets => packages/presets/src}/erc1155.cairo (90%) rename {src/presets => packages/presets/src}/erc20.cairo (90%) rename {src/presets => packages/presets/src}/erc721.cairo (90%) rename {src/presets => packages/presets/src}/eth_account.cairo (87%) rename {src/presets => packages/presets/src}/interfaces.cairo (100%) rename {src/presets => packages/presets/src}/interfaces/account.cairo (100%) rename {src/presets => packages/presets/src}/interfaces/erc1155.cairo (100%) rename {src/presets => packages/presets/src}/interfaces/erc20.cairo (100%) rename {src/presets => packages/presets/src}/interfaces/erc721.cairo (100%) rename {src/presets => packages/presets/src}/interfaces/eth_account.cairo (96%) create mode 100644 packages/presets/src/lib.cairo rename src/tests/presets.cairo => packages/presets/src/tests.cairo (51%) rename {src => packages/presets/src}/tests/mocks.cairo (50%) create mode 100644 packages/presets/src/tests/mocks/account_mocks.cairo create mode 100644 packages/presets/src/tests/mocks/erc1155_mocks.cairo create mode 100644 packages/presets/src/tests/mocks/erc1155_receiver_mocks.cairo create mode 100644 packages/presets/src/tests/mocks/erc20_mocks.cairo create mode 100644 packages/presets/src/tests/mocks/erc721_mocks.cairo create mode 100644 packages/presets/src/tests/mocks/erc721_receiver_mocks.cairo create mode 100644 packages/presets/src/tests/mocks/eth_account_mocks.cairo create mode 100644 packages/presets/src/tests/mocks/non_implementing_mock.cairo create mode 100644 packages/presets/src/tests/mocks/src5_mocks.cairo rename {src/tests/presets => packages/presets/src/tests}/test_account.cairo (93%) rename {src/tests/presets => packages/presets/src/tests}/test_erc1155.cairo (97%) rename {src/tests/presets => packages/presets/src/tests}/test_erc20.cairo (94%) rename {src/tests/presets => packages/presets/src/tests}/test_erc721.cairo (97%) rename {src/tests/presets => packages/presets/src/tests}/test_eth_account.cairo (95%) rename {src/tests/presets => packages/presets/src/tests}/test_universal_deployer.cairo (86%) rename {src/presets => packages/presets/src}/universal_deployer.cairo (95%) create mode 100644 packages/security/Scarb.toml rename {src/security => packages/security/src}/initializable.cairo (96%) rename {src/security => packages/security/src}/interface.cairo (100%) rename src/security.cairo => packages/security/src/lib.cairo (94%) rename {src/security => packages/security/src}/pausable.cairo (98%) rename {src/security => packages/security/src}/reentrancyguard.cairo (100%) rename src/tests/security.cairo => packages/security/src/tests.cairo (52%) create mode 100644 packages/security/src/tests/mocks.cairo rename {src => packages/security/src}/tests/mocks/initializable_mocks.cairo (88%) rename {src => packages/security/src}/tests/mocks/pausable_mocks.cairo (90%) rename {src => packages/security/src}/tests/mocks/reentrancy_mocks.cairo (97%) rename {src/tests/security => packages/security/src/tests}/test_initializable.cairo (72%) rename {src/tests/security => packages/security/src/tests}/test_pausable.cairo (90%) rename {src/tests/security => packages/security/src/tests}/test_reentrancyguard.cairo (90%) create mode 100644 packages/token/Scarb.toml rename {src/token => packages/token/src}/erc1155.cairo (100%) rename {src/token => packages/token/src}/erc1155/dual1155.cairo (96%) rename {src/token => packages/token/src}/erc1155/dual1155_receiver.cairo (92%) rename {src/token => packages/token/src}/erc1155/erc1155.cairo (97%) rename {src/token => packages/token/src}/erc1155/erc1155_receiver.cairo (94%) rename {src/token => packages/token/src}/erc1155/interface.cairo (100%) rename {src/token => packages/token/src}/erc20.cairo (100%) rename {src/token => packages/token/src}/erc20/dual20.cairo (95%) rename {src/token => packages/token/src}/erc20/erc20.cairo (99%) rename {src/token => packages/token/src}/erc20/extensions.cairo (100%) rename {src/token => packages/token/src}/erc20/extensions/erc20_votes.cairo (95%) rename {src/token => packages/token/src}/erc20/interface.cairo (98%) rename {src/token => packages/token/src}/erc721.cairo (100%) rename {src/token => packages/token/src}/erc721/dual721.cairo (96%) rename {src/token => packages/token/src}/erc721/dual721_receiver.cairo (86%) rename {src/token => packages/token/src}/erc721/erc721.cairo (98%) rename {src/token => packages/token/src}/erc721/erc721_receiver.cairo (89%) rename {src/token => packages/token/src}/erc721/interface.cairo (100%) rename src/token.cairo => packages/token/src/lib.cairo (75%) create mode 100644 packages/token/src/tests.cairo rename {src/tests/token => packages/token/src/tests}/erc1155.cairo (57%) rename {src/tests/token => packages/token/src/tests}/erc1155/common.cairo (80%) rename {src/tests/token => packages/token/src/tests}/erc1155/test_dual1155.cairo (96%) rename {src/tests/token => packages/token/src/tests}/erc1155/test_dual1155_receiver.cairo (93%) rename {src/tests/token => packages/token/src/tests}/erc1155/test_erc1155.cairo (98%) rename {src/tests/token => packages/token/src/tests}/erc1155/test_erc1155_receiver.cairo (82%) rename {src/tests/token => packages/token/src/tests}/erc20.cairo (50%) rename {src/tests/token => packages/token/src/tests}/erc20/common.cairo (85%) rename {src/tests/token => packages/token/src/tests}/erc20/test_dual20.cairo (95%) rename {src/tests/token => packages/token/src/tests}/erc20/test_erc20.cairo (93%) rename {src/tests/token => packages/token/src/tests}/erc20/test_erc20_votes.cairo (89%) rename {src/tests/token => packages/token/src/tests}/erc721.cairo (56%) rename {src/tests/token => packages/token/src/tests}/erc721/common.cairo (89%) rename {src/tests/token => packages/token/src/tests}/erc721/test_dual721.cairo (97%) rename {src/tests/token => packages/token/src/tests}/erc721/test_dual721_receiver.cairo (82%) rename {src/tests/token => packages/token/src/tests}/erc721/test_erc721.cairo (98%) rename {src/tests/token => packages/token/src/tests}/erc721/test_erc721_receiver.cairo (72%) create mode 100644 packages/token/src/tests/mocks.cairo create mode 100644 packages/token/src/tests/mocks/account_mocks.cairo rename {src => packages/token/src}/tests/mocks/erc1155_mocks.cairo (95%) rename {src => packages/token/src}/tests/mocks/erc1155_receiver_mocks.cairo (92%) rename {src => packages/token/src}/tests/mocks/erc20_mocks.cairo (96%) rename {src => packages/token/src}/tests/mocks/erc20_votes_mocks.cairo (88%) rename {src => packages/token/src}/tests/mocks/erc721_mocks.cairo (94%) rename {src => packages/token/src}/tests/mocks/erc721_receiver_mocks.cairo (93%) create mode 100644 packages/token/src/tests/mocks/non_implementing_mock.cairo create mode 100644 packages/token/src/tests/mocks/src5_mocks.cairo create mode 100644 packages/upgrades/Scarb.toml rename {src/upgrades => packages/upgrades/src}/interface.cairo (100%) rename src/upgrades.cairo => packages/upgrades/src/lib.cairo (84%) create mode 100644 packages/upgrades/src/tests.cairo rename {src/tests/upgrades => packages/upgrades/src/tests}/common.cairo (72%) create mode 100644 packages/upgrades/src/tests/mocks.cairo rename {src => packages/upgrades/src}/tests/mocks/upgrades_mocks.cairo (96%) rename {src/tests/upgrades => packages/upgrades/src/tests}/test_upgradeable.cairo (79%) rename {src/upgrades => packages/upgrades/src}/upgradeable.cairo (100%) create mode 100644 packages/utils/Scarb.toml rename {src/utils => packages/utils/src}/cryptography.cairo (100%) rename {src/utils => packages/utils/src}/cryptography/interface.cairo (100%) rename {src/utils => packages/utils/src}/cryptography/nonces.cairo (97%) rename {src/utils => packages/utils/src}/cryptography/snip12.cairo (100%) rename {src/utils => packages/utils/src}/deployments.cairo (95%) rename {src/utils => packages/utils/src}/deployments/interface.cairo (100%) rename {src/utils => packages/utils/src}/interfaces.cairo (57%) rename src/utils.cairo => packages/utils/src/lib.cairo (95%) rename {src/utils => packages/utils/src}/math.cairo (100%) rename {src/utils => packages/utils/src}/selectors.cairo (100%) rename {src/utils => packages/utils/src}/serde.cairo (100%) rename {src/utils => packages/utils/src}/structs.cairo (100%) rename {src/utils => packages/utils/src}/structs/checkpoint.cairo (94%) rename {src/utils => packages/utils/src}/structs/storage_array.cairo (100%) rename src/tests/utils.cairo => packages/utils/src/test_utils.cairo (93%) rename {src/tests/utils => packages/utils/src/test_utils}/common.cairo (100%) create mode 100644 packages/utils/src/test_utils/constants.cairo rename {src/tests/utils => packages/utils/src/test_utils}/deployment.cairo (89%) rename {src/tests/utils => packages/utils/src/test_utils}/events.cairo (100%) rename {src/tests/utils => packages/utils/src/test_utils}/signing.cairo (100%) rename src/tests/cryptography.cairo => packages/utils/src/tests.cairo (59%) create mode 100644 packages/utils/src/tests/mocks.cairo rename {src => packages/utils/src}/tests/mocks/nonces_mocks.cairo (88%) rename {src/tests/cryptography => packages/utils/src/tests}/test_nonces.cairo (77%) rename {src/tests/cryptography => packages/utils/src/tests}/test_snip12.cairo (94%) rename {src/utils => packages/utils/src}/unwrap_and_cast.cairo (100%) delete mode 100644 src/presets.cairo delete mode 100644 src/tests.cairo delete mode 100644 src/tests/account.cairo delete mode 100644 src/tests/governance.cairo delete mode 100644 src/tests/introspection.cairo delete mode 100644 src/tests/token.cairo delete mode 100644 src/tests/upgrades.cairo delete mode 100644 src/tests/utils/constants.cairo diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 7e7d36e0b..b23c28c55 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -33,9 +33,9 @@ jobs: *.md !PULL_REQUEST_TEMPLATE.md - name: Cairo lint - run: scarb fmt --check + run: scarb fmt --check --workspace - name: Temporary USC manually install run: | curl -L https://raw.githubusercontent.com/software-mansion/universal-sierra-compiler/master/scripts/install.sh | sh -s -- v2.2.0-rc.1 - name: Cairo test - run: snforge test + run: snforge test --workspace diff --git a/CHANGELOG.md b/CHANGELOG.md index a1ff29a21..e2b941d27 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,12 +12,23 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - TimelockController component (#996) - HashCall implementation (#996) +- Separated package for each submodule (#1065) + - `openzeppelin_access` + - `openzeppelin_account` + - `openzeppelin_governance` + - `openzeppelin_introspection` + - `openzeppelin_presets` + - `openzeppelin_security` + - `openzeppelin_token` + - `openzeppelin_upgrades` + - `openzeppelin_utils` ### Changed - Bump scarb to v2.7.0-rc.1 (#1025) - Bump scarb to v2.7.0-rc.2 (#1052) - Bump scarb to v2.7.0-rc.4 (#1064) +- Bump scarb to v2.7.0 (#1065) ## 0.15.0-rc.0 (2024-07-8) diff --git a/README.md b/README.md index beee9ab5a..82615cb0e 100644 --- a/README.md +++ b/README.md @@ -46,6 +46,13 @@ Edit `scarb.toml` and add: openzeppelin = { git = "https://github.com/OpenZeppelin/cairo-contracts.git", tag = "v0.15.0-rc.0" } ``` +The previous example would import the entire library. we can also add each package as a separated dependency to improve the time for building by not including modules that won't be used: + +```toml +[dependencies] +openzeppelin_token = { git = "https://github.com/OpenZeppelin/cairo-contracts.git", tag = "v0.15.0-rc.0" } +``` + Build the project to download it: ```bash @@ -65,6 +72,7 @@ For example, this is how to write an ERC20-compliant contract: ```cairo #[starknet::contract] mod MyToken { + // If only the token package was added as a dependency, use `openzeppelin_token::` instead use openzeppelin::token::erc20::{ERC20Component, ERC20HooksEmptyImpl}; use starknet::ContractAddress; diff --git a/Scarb.lock b/Scarb.lock index 8e9562d62..11da63c54 100644 --- a/Scarb.lock +++ b/Scarb.lock @@ -4,6 +4,96 @@ version = 1 [[package]] name = "openzeppelin" version = "0.15.0-rc.0" +dependencies = [ + "openzeppelin_access", + "openzeppelin_account", + "openzeppelin_governance", + "openzeppelin_introspection", + "openzeppelin_presets", + "openzeppelin_security", + "openzeppelin_token", + "openzeppelin_upgrades", + "openzeppelin_utils", + "snforge_std", +] + +[[package]] +name = "openzeppelin_access" +version = "0.15.0-rc.0" +dependencies = [ + "openzeppelin_introspection", + "openzeppelin_utils", + "snforge_std", +] + +[[package]] +name = "openzeppelin_account" +version = "0.15.0-rc.0" +dependencies = [ + "openzeppelin_introspection", + "openzeppelin_token", + "openzeppelin_utils", + "snforge_std", +] + +[[package]] +name = "openzeppelin_governance" +version = "0.15.0-rc.0" +dependencies = [ + "openzeppelin_access", + "openzeppelin_introspection", + "openzeppelin_utils", + "snforge_std", +] + +[[package]] +name = "openzeppelin_introspection" +version = "0.15.0-rc.0" +dependencies = [ + "snforge_std", +] + +[[package]] +name = "openzeppelin_presets" +version = "0.15.0-rc.0" +dependencies = [ + "openzeppelin_access", + "openzeppelin_account", + "openzeppelin_introspection", + "openzeppelin_token", + "openzeppelin_upgrades", + "snforge_std", +] + +[[package]] +name = "openzeppelin_security" +version = "0.15.0-rc.0" +dependencies = [ + "openzeppelin_utils", + "snforge_std", +] + +[[package]] +name = "openzeppelin_token" +version = "0.15.0-rc.0" +dependencies = [ + "openzeppelin_account", + "openzeppelin_governance", + "openzeppelin_introspection", + "snforge_std", +] + +[[package]] +name = "openzeppelin_upgrades" +version = "0.15.0-rc.0" +dependencies = [ + "openzeppelin_utils", + "snforge_std", +] + +[[package]] +name = "openzeppelin_utils" +version = "0.15.0-rc.0" dependencies = [ "snforge_std", ] diff --git a/Scarb.toml b/Scarb.toml index 0c175288a..4025a6503 100644 --- a/Scarb.toml +++ b/Scarb.toml @@ -1,21 +1,59 @@ +[workspace] +members = [ + "packages/access", + "packages/account", + "packages/governance", + "packages/introspection", + "packages/presets", + "packages/security", + "packages/token", + "packages/upgrades", + "packages/utils", +] + [package] name = "openzeppelin" +version.workspace = true + +[workspace.package] version = "0.15.0-rc.0" edition = "2023_11" -cairo-version = "2.7.0-rc.3" -scarb-version = "2.7.0-rc.4" +cairo-version = "2.7.0" +scarb-version = "2.7.0" authors = ["OpenZeppelin Community "] description = "OpenZeppelin Contracts written in Cairo for StarkNet, a decentralized ZK Rollup" documentation = "https://docs.openzeppelin.com/contracts-cairo" readme = "README.md" repository = "https://github.com/OpenZeppelin/cairo-contracts" license-file = "LICENSE" -keywords = ["openzeppelin", "starknet", "cairo", "contracts", "security", "standards"] +keywords = [ + "openzeppelin", + "starknet", + "cairo", + "contracts", + "security", + "standards", +] -[dependencies] -starknet = "2.7.0-rc.3" +[workspace.dependencies] +starknet = "2.7.0" snforge_std = { git = "https://github.com/foundry-rs/starknet-foundry.git", tag = "v0.26.0" } +[dependencies] +starknet.workspace = true +openzeppelin_access = { path = "packages/access" } +openzeppelin_account = { path = "packages/account" } +openzeppelin_governance = { path = "packages/governance" } +openzeppelin_introspection = { path = "packages/introspection" } +openzeppelin_presets = { path = "packages/presets" } +openzeppelin_security = { path = "packages/security" } +openzeppelin_token = { path = "packages/token" } +openzeppelin_upgrades = { path = "packages/upgrades" } +openzeppelin_utils = { path = "packages/utils" } + +[dev-dependencies] +snforge_std.workspace = true + [lib] [[target.starknet-contract]] @@ -23,5 +61,8 @@ allowed-libfuncs-list.name = "experimental" sierra = true casm = false -[tool.fmt] +[workspace.tool.fmt] sort-module-level-items = true + +[tool] +fmt.workspace = true diff --git a/docs/modules/ROOT/pages/api/utilities.adoc b/docs/modules/ROOT/pages/api/utilities.adoc index d103d311d..56c28ef5f 100644 --- a/docs/modules/ROOT/pages/api/utilities.adoc +++ b/docs/modules/ROOT/pages/api/utilities.adoc @@ -3,7 +3,7 @@ :deploy_syscall: link:https://docs.starknet.io/documentation/architecture_and_concepts/Smart_Contracts/system-calls-cairo1/#deploy[deploy_syscall] The following documentation provides reasoning and examples for functions and constants found in `openzeppelin::utils` -and `openzeppelin::tests::utils`. +and `use openzeppelin::utils::test_utils;`. CAUTION: Expect this module to evolve (as it has already done). @@ -387,7 +387,7 @@ xref:/guides/snip12.adoc[SNIP12 and Typed Messages] guide. === `++utils++` ```cairo -use openzeppelin::tests::utils; +use openzeppelin::utils::test_utils; ``` Module containing utilities for testing the library. @@ -420,14 +420,14 @@ Usage example: ```cairo use openzeppelin::presets::AccountUpgradeable; -use openzeppelin::tests::utils; +use openzeppelin::utils::test_utils; use starknet::ContractAddress; const PUBKEY: felt252 = 'PUBKEY'; fn deploy_test_contract() -> ContractAddress { let calldata = array![PUBKEY]; - utils::deploy(AccountUpgradeable::TEST_CLASS_HASH, calldata) + test_utils::deploy(AccountUpgradeable::TEST_CLASS_HASH, calldata) } ``` @@ -459,7 +459,7 @@ Requirements: Usage example: ```cairo -use openzeppelin::tests::utils; +use openzeppelin::utils::test_utils; use openzeppelin::token::erc20::ERC20Component; use openzeppelin::token::erc20::ERC20Component::Transfer; use starknet::ContractAddress; @@ -467,7 +467,7 @@ use starknet::ContractAddress; fn assert_emitted_event( target: ContractAddress, from: ContractAddress, to: ContractAddress, value: u256 ) { - let event = utils::pop_log::(target).unwrap(); + let event = test_utils::pop_log::(target).unwrap(); let expected = ERC20Component::Event::Transfer(Transfer { from, to, value }); assert!(event == expected); } diff --git a/packages/access/Scarb.toml b/packages/access/Scarb.toml new file mode 100644 index 000000000..cbb1b5421 --- /dev/null +++ b/packages/access/Scarb.toml @@ -0,0 +1,31 @@ +[package] +name = "openzeppelin_access" +version.workspace = true +edition.workspace = true +cairo-version.workspace = true +scarb-version.workspace = true +authors.workspace = true +description.workspace = true +documentation.workspace = true +readme.workspace = true +repository.workspace = true +license-file.workspace = true +keywords.workspace = true + +[tool] +fmt.workspace = true + +[dependencies] +starknet.workspace = true +openzeppelin_introspection = { path = "../introspection" } +openzeppelin_utils = { path = "../utils" } + +[dev-dependencies] +snforge_std.workspace = true + +[lib] + +[[target.starknet-contract]] +allowed-libfuncs-list.name = "experimental" +sierra = true +casm = false diff --git a/src/access/accesscontrol.cairo b/packages/access/src/accesscontrol.cairo similarity index 100% rename from src/access/accesscontrol.cairo rename to packages/access/src/accesscontrol.cairo diff --git a/src/access/accesscontrol/accesscontrol.cairo b/packages/access/src/accesscontrol/accesscontrol.cairo similarity index 97% rename from src/access/accesscontrol/accesscontrol.cairo rename to packages/access/src/accesscontrol/accesscontrol.cairo index 891b3a270..844f24f22 100644 --- a/src/access/accesscontrol/accesscontrol.cairo +++ b/packages/access/src/accesscontrol/accesscontrol.cairo @@ -7,10 +7,10 @@ /// Roles are referred to by their `felt252` identifier. #[starknet::component] pub mod AccessControlComponent { - use openzeppelin::access::accesscontrol::interface; - use openzeppelin::introspection::src5::SRC5Component::InternalImpl as SRC5InternalImpl; - use openzeppelin::introspection::src5::SRC5Component::SRC5Impl; - use openzeppelin::introspection::src5::SRC5Component; + use openzeppelin_access::accesscontrol::interface; + use openzeppelin_introspection::src5::SRC5Component::InternalImpl as SRC5InternalImpl; + use openzeppelin_introspection::src5::SRC5Component::SRC5Impl; + use openzeppelin_introspection::src5::SRC5Component; use starknet::ContractAddress; use starknet::get_caller_address; use starknet::storage::Map; diff --git a/src/access/accesscontrol/dual_accesscontrol.cairo b/packages/access/src/accesscontrol/dual_accesscontrol.cairo similarity index 94% rename from src/access/accesscontrol/dual_accesscontrol.cairo rename to packages/access/src/accesscontrol/dual_accesscontrol.cairo index 82b4f9256..e6fdcc645 100644 --- a/src/access/accesscontrol/dual_accesscontrol.cairo +++ b/packages/access/src/accesscontrol/dual_accesscontrol.cairo @@ -1,10 +1,10 @@ // SPDX-License-Identifier: MIT // OpenZeppelin Contracts for Cairo v0.15.0-rc.0 (access/accesscontrol/dual_accesscontrol.cairo) -use openzeppelin::utils::UnwrapAndCast; -use openzeppelin::utils::selectors; -use openzeppelin::utils::serde::SerializedAppend; -use openzeppelin::utils::try_selector_with_fallback; +use openzeppelin_utils::selectors; +use openzeppelin_utils::serde::SerializedAppend; +use openzeppelin_utils::try_selector_with_fallback; +use openzeppelin_utils::unwrap_and_cast::UnwrapAndCast; use starknet::ContractAddress; use starknet::SyscallResultTrait; use starknet::syscalls::call_contract_syscall; diff --git a/src/access/accesscontrol/interface.cairo b/packages/access/src/accesscontrol/interface.cairo similarity index 100% rename from src/access/accesscontrol/interface.cairo rename to packages/access/src/accesscontrol/interface.cairo diff --git a/src/access.cairo b/packages/access/src/lib.cairo similarity index 71% rename from src/access.cairo rename to packages/access/src/lib.cairo index e2a102dc1..b9ab604d4 100644 --- a/src/access.cairo +++ b/packages/access/src/lib.cairo @@ -1,2 +1,4 @@ pub mod accesscontrol; pub mod ownable; + +pub mod tests; diff --git a/src/access/ownable.cairo b/packages/access/src/ownable.cairo similarity index 100% rename from src/access/ownable.cairo rename to packages/access/src/ownable.cairo diff --git a/src/access/ownable/dual_ownable.cairo b/packages/access/src/ownable/dual_ownable.cairo similarity index 89% rename from src/access/ownable/dual_ownable.cairo rename to packages/access/src/ownable/dual_ownable.cairo index 1695e3e2d..9625460fb 100644 --- a/src/access/ownable/dual_ownable.cairo +++ b/packages/access/src/ownable/dual_ownable.cairo @@ -1,10 +1,10 @@ // SPDX-License-Identifier: MIT // OpenZeppelin Contracts for Cairo v0.15.0-rc.0 (access/ownable/dual_ownable.cairo) -use openzeppelin::utils::UnwrapAndCast; -use openzeppelin::utils::selectors; -use openzeppelin::utils::serde::SerializedAppend; -use openzeppelin::utils::try_selector_with_fallback; +use openzeppelin_utils::UnwrapAndCast; +use openzeppelin_utils::selectors; +use openzeppelin_utils::serde::SerializedAppend; +use openzeppelin_utils::try_selector_with_fallback; use starknet::ContractAddress; use starknet::SyscallResultTrait; use starknet::syscalls::call_contract_syscall; diff --git a/src/access/ownable/interface.cairo b/packages/access/src/ownable/interface.cairo similarity index 100% rename from src/access/ownable/interface.cairo rename to packages/access/src/ownable/interface.cairo diff --git a/src/access/ownable/ownable.cairo b/packages/access/src/ownable/ownable.cairo similarity index 99% rename from src/access/ownable/ownable.cairo rename to packages/access/src/ownable/ownable.cairo index 8443a23ff..db4b8b7f3 100644 --- a/src/access/ownable/ownable.cairo +++ b/packages/access/src/ownable/ownable.cairo @@ -16,8 +16,8 @@ #[starknet::component] pub mod OwnableComponent { use core::num::traits::Zero; - use openzeppelin::access::ownable::interface::IOwnableTwoStep; - use openzeppelin::access::ownable::interface; + use openzeppelin_access::ownable::interface::IOwnableTwoStep; + use openzeppelin_access::ownable::interface; use starknet::ContractAddress; use starknet::get_caller_address; diff --git a/src/tests/access.cairo b/packages/access/src/tests.cairo similarity index 54% rename from src/tests/access.cairo rename to packages/access/src/tests.cairo index cfa981899..8c3f28828 100644 --- a/src/tests/access.cairo +++ b/packages/access/src/tests.cairo @@ -1,7 +1,13 @@ -pub(crate) mod common; +pub mod common; +pub(crate) mod mocks; +#[cfg(test)] mod test_accesscontrol; +#[cfg(test)] mod test_dual_accesscontrol; +#[cfg(test)] mod test_dual_ownable; +#[cfg(test)] mod test_ownable; +#[cfg(test)] mod test_ownable_twostep; diff --git a/src/tests/access/common.cairo b/packages/access/src/tests/common.cairo similarity index 72% rename from src/tests/access/common.cairo rename to packages/access/src/tests/common.cairo index 6836a3437..bd04a48d0 100644 --- a/src/tests/access/common.cairo +++ b/packages/access/src/tests/common.cairo @@ -1,13 +1,12 @@ -use openzeppelin::access::ownable::OwnableComponent::OwnershipTransferred; -use openzeppelin::access::ownable::OwnableComponent; -use openzeppelin::tests::utils::EventSpyExt; -use openzeppelin::tests::utils; -use openzeppelin::utils::serde::SerializedAppend; +use openzeppelin_access::ownable::OwnableComponent::OwnershipTransferred; +use openzeppelin_access::ownable::OwnableComponent; +use openzeppelin_utils::serde::SerializedAppend; +use openzeppelin_utils::test_utils::EventSpyExt; use snforge_std::EventSpy; use starknet::ContractAddress; #[generate_trait] -pub(crate) impl OwnableSpyHelpersImpl of OwnableSpyHelpers { +pub impl OwnableSpyHelpersImpl of OwnableSpyHelpers { fn assert_only_event_ownership_transferred( ref self: EventSpy, contract: ContractAddress, diff --git a/packages/access/src/tests/mocks.cairo b/packages/access/src/tests/mocks.cairo new file mode 100644 index 000000000..f3eca4c97 --- /dev/null +++ b/packages/access/src/tests/mocks.cairo @@ -0,0 +1,3 @@ +pub(crate) mod accesscontrol_mocks; +pub(crate) mod non_implementing_mock; +pub(crate) mod ownable_mocks; diff --git a/src/tests/mocks/accesscontrol_mocks.cairo b/packages/access/src/tests/mocks/accesscontrol_mocks.cairo similarity index 91% rename from src/tests/mocks/accesscontrol_mocks.cairo rename to packages/access/src/tests/mocks/accesscontrol_mocks.cairo index d06e2c3b5..f9ddb0b38 100644 --- a/src/tests/mocks/accesscontrol_mocks.cairo +++ b/packages/access/src/tests/mocks/accesscontrol_mocks.cairo @@ -1,8 +1,8 @@ #[starknet::contract] pub(crate) mod DualCaseAccessControlMock { - use openzeppelin::access::accesscontrol::AccessControlComponent; - use openzeppelin::access::accesscontrol::DEFAULT_ADMIN_ROLE; - use openzeppelin::introspection::src5::SRC5Component; + use openzeppelin_access::accesscontrol::AccessControlComponent; + use openzeppelin_access::accesscontrol::DEFAULT_ADMIN_ROLE; + use openzeppelin_introspection::src5::SRC5Component; use starknet::ContractAddress; component!(path: AccessControlComponent, storage: accesscontrol, event: AccessControlEvent); @@ -40,9 +40,9 @@ pub(crate) mod DualCaseAccessControlMock { #[starknet::contract] pub(crate) mod SnakeAccessControlMock { - use openzeppelin::access::accesscontrol::AccessControlComponent; - use openzeppelin::access::accesscontrol::DEFAULT_ADMIN_ROLE; - use openzeppelin::introspection::src5::SRC5Component; + use openzeppelin_access::accesscontrol::AccessControlComponent; + use openzeppelin_access::accesscontrol::DEFAULT_ADMIN_ROLE; + use openzeppelin_introspection::src5::SRC5Component; use starknet::ContractAddress; component!(path: AccessControlComponent, storage: accesscontrol, event: AccessControlEvent); @@ -84,9 +84,9 @@ pub(crate) mod SnakeAccessControlMock { #[starknet::contract] pub(crate) mod CamelAccessControlMock { - use openzeppelin::access::accesscontrol::AccessControlComponent; - use openzeppelin::access::accesscontrol::DEFAULT_ADMIN_ROLE; - use openzeppelin::introspection::src5::SRC5Component; + use openzeppelin_access::accesscontrol::AccessControlComponent; + use openzeppelin_access::accesscontrol::DEFAULT_ADMIN_ROLE; + use openzeppelin_introspection::src5::SRC5Component; use starknet::ContractAddress; component!(path: AccessControlComponent, storage: accesscontrol, event: AccessControlEvent); diff --git a/src/tests/mocks/non_implementing_mock.cairo b/packages/access/src/tests/mocks/non_implementing_mock.cairo similarity index 100% rename from src/tests/mocks/non_implementing_mock.cairo rename to packages/access/src/tests/mocks/non_implementing_mock.cairo diff --git a/src/tests/mocks/ownable_mocks.cairo b/packages/access/src/tests/mocks/ownable_mocks.cairo similarity index 95% rename from src/tests/mocks/ownable_mocks.cairo rename to packages/access/src/tests/mocks/ownable_mocks.cairo index 45d48951f..1448f0cb0 100644 --- a/src/tests/mocks/ownable_mocks.cairo +++ b/packages/access/src/tests/mocks/ownable_mocks.cairo @@ -1,6 +1,6 @@ #[starknet::contract] pub(crate) mod DualCaseOwnableMock { - use openzeppelin::access::ownable::OwnableComponent; + use openzeppelin_access::ownable::OwnableComponent; use starknet::ContractAddress; component!(path: OwnableComponent, storage: ownable, event: OwnableEvent); @@ -30,7 +30,7 @@ pub(crate) mod DualCaseOwnableMock { #[starknet::contract] pub(crate) mod SnakeOwnableMock { - use openzeppelin::access::ownable::OwnableComponent; + use openzeppelin_access::ownable::OwnableComponent; use starknet::ContractAddress; component!(path: OwnableComponent, storage: ownable, event: OwnableEvent); @@ -60,7 +60,7 @@ pub(crate) mod SnakeOwnableMock { #[starknet::contract] pub(crate) mod CamelOwnableMock { - use openzeppelin::access::ownable::OwnableComponent; + use openzeppelin_access::ownable::OwnableComponent; use starknet::ContractAddress; component!(path: OwnableComponent, storage: ownable, event: OwnableEvent); @@ -158,7 +158,7 @@ pub(crate) mod CamelOwnablePanicMock { #[starknet::contract] pub(crate) mod DualCaseTwoStepOwnableMock { - use openzeppelin::access::ownable::OwnableComponent; + use openzeppelin_access::ownable::OwnableComponent; use starknet::ContractAddress; component!(path: OwnableComponent, storage: ownable, event: OwnableEvent); diff --git a/src/tests/access/test_accesscontrol.cairo b/packages/access/src/tests/test_accesscontrol.cairo similarity index 96% rename from src/tests/access/test_accesscontrol.cairo rename to packages/access/src/tests/test_accesscontrol.cairo index 809669e69..497dd20f6 100644 --- a/src/tests/access/test_accesscontrol.cairo +++ b/packages/access/src/tests/test_accesscontrol.cairo @@ -1,16 +1,16 @@ -use openzeppelin::access::accesscontrol::AccessControlComponent::{ +use openzeppelin_access::accesscontrol::AccessControlComponent::{ InternalImpl, RoleAdminChanged, RoleGranted, RoleRevoked }; -use openzeppelin::access::accesscontrol::interface::{ +use openzeppelin_access::accesscontrol::interface::{ IAccessControl, IAccessControlCamel, IACCESSCONTROL_ID }; -use openzeppelin::access::accesscontrol::{AccessControlComponent, DEFAULT_ADMIN_ROLE}; -use openzeppelin::introspection::interface::ISRC5; -use openzeppelin::tests::mocks::accesscontrol_mocks::DualCaseAccessControlMock; -use openzeppelin::tests::utils::constants::{ +use openzeppelin_access::accesscontrol::{AccessControlComponent, DEFAULT_ADMIN_ROLE}; +use openzeppelin_access::tests::mocks::accesscontrol_mocks::DualCaseAccessControlMock; +use openzeppelin_introspection::interface::ISRC5; +use openzeppelin_utils::test_utils::constants::{ ADMIN, AUTHORIZED, OTHER, OTHER_ADMIN, ROLE, OTHER_ROLE, ZERO }; -use openzeppelin::tests::utils::events::EventSpyExt; +use openzeppelin_utils::test_utils::events::EventSpyExt; use snforge_std::{EventSpy, spy_events, start_cheat_caller_address, test_address}; use starknet::ContractAddress; diff --git a/src/tests/access/test_dual_accesscontrol.cairo b/packages/access/src/tests/test_dual_accesscontrol.cairo similarity index 94% rename from src/tests/access/test_dual_accesscontrol.cairo rename to packages/access/src/tests/test_dual_accesscontrol.cairo index bd8f17781..e315b6e17 100644 --- a/src/tests/access/test_dual_accesscontrol.cairo +++ b/packages/access/src/tests/test_dual_accesscontrol.cairo @@ -1,15 +1,15 @@ -use openzeppelin::access::accesscontrol::DEFAULT_ADMIN_ROLE; -use openzeppelin::access::accesscontrol::dual_accesscontrol::DualCaseAccessControl; -use openzeppelin::access::accesscontrol::dual_accesscontrol::DualCaseAccessControlTrait; -use openzeppelin::access::accesscontrol::interface::{ +use openzeppelin_access::accesscontrol::DEFAULT_ADMIN_ROLE; +use openzeppelin_access::accesscontrol::dual_accesscontrol::DualCaseAccessControl; +use openzeppelin_access::accesscontrol::dual_accesscontrol::DualCaseAccessControlTrait; +use openzeppelin_access::accesscontrol::interface::{ IACCESSCONTROL_ID, IAccessControlCamelDispatcher, IAccessControlCamelDispatcherTrait }; -use openzeppelin::access::accesscontrol::interface::{ +use openzeppelin_access::accesscontrol::interface::{ IAccessControlDispatcher, IAccessControlDispatcherTrait }; -use openzeppelin::tests::utils::constants::{ADMIN, AUTHORIZED, ROLE}; -use openzeppelin::tests::utils; -use openzeppelin::utils::serde::SerializedAppend; +use openzeppelin_utils::serde::SerializedAppend; +use openzeppelin_utils::test_utils as utils; +use openzeppelin_utils::test_utils::constants::{ADMIN, AUTHORIZED, ROLE}; use snforge_std::start_cheat_caller_address; // diff --git a/src/tests/access/test_dual_ownable.cairo b/packages/access/src/tests/test_dual_ownable.cairo similarity index 94% rename from src/tests/access/test_dual_ownable.cairo rename to packages/access/src/tests/test_dual_ownable.cairo index 08a863498..792b600c8 100644 --- a/src/tests/access/test_dual_ownable.cairo +++ b/packages/access/src/tests/test_dual_ownable.cairo @@ -1,11 +1,11 @@ use core::num::traits::Zero; -use openzeppelin::access::ownable::dual_ownable::{DualCaseOwnable, DualCaseOwnableTrait}; -use openzeppelin::access::ownable::interface::{ +use openzeppelin_access::ownable::dual_ownable::{DualCaseOwnable, DualCaseOwnableTrait}; +use openzeppelin_access::ownable::interface::{ IOwnableDispatcher, IOwnableCamelOnlyDispatcher, IOwnableDispatcherTrait }; -use openzeppelin::tests::utils::constants::{OWNER, NEW_OWNER}; -use openzeppelin::tests::utils; -use openzeppelin::utils::serde::SerializedAppend; +use openzeppelin_utils::serde::SerializedAppend; +use openzeppelin_utils::test_utils as utils; +use openzeppelin_utils::test_utils::constants::{OWNER, NEW_OWNER}; use snforge_std::start_cheat_caller_address; // diff --git a/src/tests/access/test_ownable.cairo b/packages/access/src/tests/test_ownable.cairo similarity index 94% rename from src/tests/access/test_ownable.cairo rename to packages/access/src/tests/test_ownable.cairo index 8a2d8ac7d..7771e137f 100644 --- a/src/tests/access/test_ownable.cairo +++ b/packages/access/src/tests/test_ownable.cairo @@ -1,9 +1,9 @@ use core::num::traits::Zero; -use openzeppelin::access::ownable::OwnableComponent::InternalTrait; -use openzeppelin::access::ownable::OwnableComponent; -use openzeppelin::access::ownable::interface::{IOwnable, IOwnableCamelOnly}; -use openzeppelin::tests::mocks::ownable_mocks::DualCaseOwnableMock; -use openzeppelin::tests::utils::constants::{ZERO, OTHER, OWNER}; +use openzeppelin_access::ownable::OwnableComponent::InternalTrait; +use openzeppelin_access::ownable::OwnableComponent; +use openzeppelin_access::ownable::interface::{IOwnable, IOwnableCamelOnly}; +use openzeppelin_access::tests::mocks::ownable_mocks::DualCaseOwnableMock; +use openzeppelin_utils::test_utils::constants::{ZERO, OTHER, OWNER}; use snforge_std::{spy_events, test_address, start_cheat_caller_address}; use super::common::OwnableSpyHelpers; diff --git a/src/tests/access/test_ownable_twostep.cairo b/packages/access/src/tests/test_ownable_twostep.cairo similarity index 95% rename from src/tests/access/test_ownable_twostep.cairo rename to packages/access/src/tests/test_ownable_twostep.cairo index 60db61cc4..8a667862d 100644 --- a/src/tests/access/test_ownable_twostep.cairo +++ b/packages/access/src/tests/test_ownable_twostep.cairo @@ -1,11 +1,11 @@ use core::num::traits::Zero; -use openzeppelin::access::ownable::OwnableComponent::{InternalTrait, OwnershipTransferStarted}; -use openzeppelin::access::ownable::OwnableComponent; -use openzeppelin::access::ownable::interface::{IOwnableTwoStep, IOwnableTwoStepCamelOnly}; -use openzeppelin::tests::mocks::ownable_mocks::DualCaseTwoStepOwnableMock; -use openzeppelin::tests::utils::constants::{ZERO, OWNER, OTHER, NEW_OWNER}; -use openzeppelin::tests::utils::events::EventSpyExt; -use openzeppelin::utils::serde::SerializedAppend; +use openzeppelin_access::ownable::OwnableComponent::{InternalTrait, OwnershipTransferStarted}; +use openzeppelin_access::ownable::OwnableComponent; +use openzeppelin_access::ownable::interface::{IOwnableTwoStep, IOwnableTwoStepCamelOnly}; +use openzeppelin_access::tests::mocks::ownable_mocks::DualCaseTwoStepOwnableMock; +use openzeppelin_utils::serde::SerializedAppend; +use openzeppelin_utils::test_utils::constants::{ZERO, OWNER, OTHER, NEW_OWNER}; +use openzeppelin_utils::test_utils::events::EventSpyExt; use snforge_std::{EventSpy, spy_events, start_cheat_caller_address, test_address}; use starknet::ContractAddress; diff --git a/packages/account/Scarb.toml b/packages/account/Scarb.toml new file mode 100644 index 000000000..68775ceb4 --- /dev/null +++ b/packages/account/Scarb.toml @@ -0,0 +1,32 @@ +[package] +name = "openzeppelin_account" +version.workspace = true +edition.workspace = true +cairo-version.workspace = true +scarb-version.workspace = true +authors.workspace = true +description.workspace = true +documentation.workspace = true +readme.workspace = true +repository.workspace = true +license-file.workspace = true +keywords.workspace = true + +[tool] +fmt.workspace = true + +[dependencies] +starknet.workspace = true +openzeppelin_introspection = { path = "../introspection" } +openzeppelin_utils = { path = "../utils" } +openzeppelin_token = { path = "../token" } + +[dev-dependencies] +snforge_std.workspace = true + +[lib] + +[[target.starknet-contract]] +allowed-libfuncs-list.name = "experimental" +sierra = true +casm = false diff --git a/src/account/account.cairo b/packages/account/src/account.cairo similarity index 96% rename from src/account/account.cairo rename to packages/account/src/account.cairo index b63d756d4..2d1bf9c1c 100644 --- a/src/account/account.cairo +++ b/packages/account/src/account.cairo @@ -9,12 +9,12 @@ pub mod AccountComponent { use core::hash::{HashStateExTrait, HashStateTrait}; use core::num::traits::Zero; use core::poseidon::PoseidonTrait; - use openzeppelin::account::interface; - use openzeppelin::account::utils::{MIN_TRANSACTION_VERSION, QUERY_VERSION, QUERY_OFFSET}; - use openzeppelin::account::utils::{execute_calls, is_valid_stark_signature}; - use openzeppelin::introspection::src5::SRC5Component::InternalTrait as SRC5InternalTrait; - use openzeppelin::introspection::src5::SRC5Component::SRC5Impl; - use openzeppelin::introspection::src5::SRC5Component; + use openzeppelin_account::interface; + use openzeppelin_account::utils::{MIN_TRANSACTION_VERSION, QUERY_VERSION, QUERY_OFFSET}; + use openzeppelin_account::utils::{execute_calls, is_valid_stark_signature}; + use openzeppelin_introspection::src5::SRC5Component::InternalTrait as SRC5InternalTrait; + use openzeppelin_introspection::src5::SRC5Component::SRC5Impl; + use openzeppelin_introspection::src5::SRC5Component; use starknet::account::Call; use starknet::get_caller_address; use starknet::get_contract_address; diff --git a/src/account/dual_account.cairo b/packages/account/src/dual_account.cairo similarity index 92% rename from src/account/dual_account.cairo rename to packages/account/src/dual_account.cairo index dd9e4be34..cd3571e80 100644 --- a/src/account/dual_account.cairo +++ b/packages/account/src/dual_account.cairo @@ -1,10 +1,10 @@ // SPDX-License-Identifier: MIT // OpenZeppelin Contracts for Cairo v0.15.0-rc.0 (account/dual_account.cairo) -use openzeppelin::utils::UnwrapAndCast; -use openzeppelin::utils::selectors; -use openzeppelin::utils::serde::SerializedAppend; -use openzeppelin::utils::try_selector_with_fallback; +use openzeppelin_utils::UnwrapAndCast; +use openzeppelin_utils::selectors; +use openzeppelin_utils::serde::SerializedAppend; +use openzeppelin_utils::try_selector_with_fallback; use starknet::ContractAddress; use starknet::SyscallResultTrait; use starknet::syscalls::call_contract_syscall; diff --git a/src/account/dual_eth_account.cairo b/packages/account/src/dual_eth_account.cairo similarity index 90% rename from src/account/dual_eth_account.cairo rename to packages/account/src/dual_eth_account.cairo index 22cd39f9e..182797209 100644 --- a/src/account/dual_eth_account.cairo +++ b/packages/account/src/dual_eth_account.cairo @@ -1,11 +1,11 @@ // SPDX-License-Identifier: MIT // OpenZeppelin Contracts for Cairo v0.15.0-rc.0 (account/dual_eth_account.cairo) -use openzeppelin::account::interface::EthPublicKey; -use openzeppelin::utils::UnwrapAndCast; -use openzeppelin::utils::selectors; -use openzeppelin::utils::serde::SerializedAppend; -use openzeppelin::utils::try_selector_with_fallback; +use openzeppelin_account::interface::EthPublicKey; +use openzeppelin_utils::UnwrapAndCast; +use openzeppelin_utils::selectors; +use openzeppelin_utils::serde::SerializedAppend; +use openzeppelin_utils::try_selector_with_fallback; use starknet::ContractAddress; use starknet::SyscallResultTrait; use starknet::syscalls::call_contract_syscall; diff --git a/src/account/eth_account.cairo b/packages/account/src/eth_account.cairo similarity index 96% rename from src/account/eth_account.cairo rename to packages/account/src/eth_account.cairo index 61eb038af..1329c2f2b 100644 --- a/src/account/eth_account.cairo +++ b/packages/account/src/eth_account.cairo @@ -10,14 +10,14 @@ pub mod EthAccountComponent { use core::num::traits::Zero; use core::poseidon::{PoseidonTrait, poseidon_hash_span}; use core::starknet::secp256_trait::Secp256PointTrait; - use openzeppelin::account::interface::EthPublicKey; - use openzeppelin::account::interface; - use openzeppelin::account::utils::secp256k1::Secp256k1PointStorePacking; - use openzeppelin::account::utils::{MIN_TRANSACTION_VERSION, QUERY_VERSION, QUERY_OFFSET}; - use openzeppelin::account::utils::{execute_calls, is_valid_eth_signature}; - use openzeppelin::introspection::src5::SRC5Component::InternalTrait as SRC5InternalTrait; - use openzeppelin::introspection::src5::SRC5Component::SRC5Impl; - use openzeppelin::introspection::src5::SRC5Component; + use openzeppelin_account::interface::EthPublicKey; + use openzeppelin_account::interface; + use openzeppelin_account::utils::secp256k1::Secp256k1PointStorePacking; + use openzeppelin_account::utils::{MIN_TRANSACTION_VERSION, QUERY_VERSION, QUERY_OFFSET}; + use openzeppelin_account::utils::{execute_calls, is_valid_eth_signature}; + use openzeppelin_introspection::src5::SRC5Component::InternalTrait as SRC5InternalTrait; + use openzeppelin_introspection::src5::SRC5Component::SRC5Impl; + use openzeppelin_introspection::src5::SRC5Component; use starknet::SyscallResultTrait; use starknet::account::Call; use starknet::get_caller_address; diff --git a/src/account/interface.cairo b/packages/account/src/interface.cairo similarity index 100% rename from src/account/interface.cairo rename to packages/account/src/interface.cairo diff --git a/src/account.cairo b/packages/account/src/lib.cairo similarity index 92% rename from src/account.cairo rename to packages/account/src/lib.cairo index 0cc865d90..1504180fb 100644 --- a/src/account.cairo +++ b/packages/account/src/lib.cairo @@ -3,6 +3,8 @@ pub mod dual_account; pub mod dual_eth_account; pub mod eth_account; pub mod interface; + +pub mod tests; pub mod utils; pub use account::AccountComponent; diff --git a/packages/account/src/tests.cairo b/packages/account/src/tests.cairo new file mode 100644 index 000000000..f358a8153 --- /dev/null +++ b/packages/account/src/tests.cairo @@ -0,0 +1,8 @@ +pub mod ethereum; +pub(crate) mod mocks; +pub mod starknet; + +#[cfg(test)] +mod test_secp256k1; +#[cfg(test)] +mod test_signature; diff --git a/src/tests/account/ethereum.cairo b/packages/account/src/tests/ethereum.cairo similarity index 54% rename from src/tests/account/ethereum.cairo rename to packages/account/src/tests/ethereum.cairo index d6fcf488b..79548d497 100644 --- a/src/tests/account/ethereum.cairo +++ b/packages/account/src/tests/ethereum.cairo @@ -1,4 +1,6 @@ -pub(crate) mod common; +pub mod common; +#[cfg(test)] mod test_dual_eth_account; +#[cfg(test)] mod test_eth_account; diff --git a/src/tests/account/ethereum/common.cairo b/packages/account/src/tests/ethereum/common.cairo similarity index 69% rename from src/tests/account/ethereum/common.cairo rename to packages/account/src/tests/ethereum/common.cairo index 58f9a809f..40b214834 100644 --- a/src/tests/account/ethereum/common.cairo +++ b/packages/account/src/tests/ethereum/common.cairo @@ -2,30 +2,30 @@ use core::hash::{HashStateTrait, HashStateExTrait}; use core::poseidon::PoseidonTrait; use core::poseidon::poseidon_hash_span; use core::starknet::secp256_trait::Secp256PointTrait; -use openzeppelin::account::EthAccountComponent::{OwnerAdded, OwnerRemoved}; -use openzeppelin::account::EthAccountComponent; -use openzeppelin::account::interface::EthPublicKey; -use openzeppelin::account::utils::signature::EthSignature; -use openzeppelin::tests::utils::constants::TRANSACTION_HASH; -use openzeppelin::tests::utils::constants::{NAME, SYMBOL}; -use openzeppelin::tests::utils::events::EventSpyExt; -use openzeppelin::tests::utils::signing::{Secp256k1KeyPair, Secp256k1KeyPairExt}; -use openzeppelin::tests::utils; -use openzeppelin::token::erc20::interface::{IERC20Dispatcher, IERC20DispatcherTrait}; -use openzeppelin::utils::serde::SerializedAppend; +use openzeppelin_account::EthAccountComponent::{OwnerAdded, OwnerRemoved}; +use openzeppelin_account::EthAccountComponent; +use openzeppelin_account::interface::EthPublicKey; +use openzeppelin_account::utils::signature::EthSignature; +use openzeppelin_token::erc20::interface::{IERC20Dispatcher, IERC20DispatcherTrait}; +use openzeppelin_utils::serde::SerializedAppend; +use openzeppelin_utils::test_utils as utils; +use openzeppelin_utils::test_utils::constants::TRANSACTION_HASH; +use openzeppelin_utils::test_utils::constants::{NAME, SYMBOL}; +use openzeppelin_utils::test_utils::events::EventSpyExt; +use openzeppelin_utils::test_utils::signing::{Secp256k1KeyPair, Secp256k1KeyPairExt}; use snforge_std::EventSpy; use snforge_std::signature::secp256k1_curve::Secp256k1CurveSignerImpl; use starknet::{ContractAddress, SyscallResultTrait}; #[derive(Drop)] -pub(crate) struct SignedTransactionData { - pub(crate) private_key: u256, - pub(crate) public_key: EthPublicKey, - pub(crate) tx_hash: felt252, - pub(crate) signature: EthSignature +pub struct SignedTransactionData { + pub private_key: u256, + pub public_key: EthPublicKey, + pub tx_hash: felt252, + pub signature: EthSignature } -pub(crate) fn SIGNED_TX_DATA(key_pair: Secp256k1KeyPair) -> SignedTransactionData { +pub fn SIGNED_TX_DATA(key_pair: Secp256k1KeyPair) -> SignedTransactionData { let tx_hash = TRANSACTION_HASH; let (r, s) = key_pair.sign(tx_hash.into()).unwrap(); SignedTransactionData { @@ -36,7 +36,7 @@ pub(crate) fn SIGNED_TX_DATA(key_pair: Secp256k1KeyPair) -> SignedTransactionDat } } -pub(crate) fn get_accept_ownership_signature( +pub fn get_accept_ownership_signature( account_address: ContractAddress, current_owner: EthPublicKey, new_key_pair: Secp256k1KeyPair ) -> Span { let msg_hash: u256 = PoseidonTrait::new() @@ -50,7 +50,7 @@ pub(crate) fn get_accept_ownership_signature( new_key_pair.serialized_sign(msg_hash).span() } -pub(crate) fn deploy_erc20(recipient: ContractAddress, initial_supply: u256) -> IERC20Dispatcher { +pub fn deploy_erc20(recipient: ContractAddress, initial_supply: u256) -> IERC20Dispatcher { let mut calldata = array![]; calldata.append_serde(NAME()); @@ -64,7 +64,7 @@ pub(crate) fn deploy_erc20(recipient: ContractAddress, initial_supply: u256) -> #[generate_trait] -pub(crate) impl EthAccountSpyHelpersImpl of EthAccountSpyHelpers { +pub impl EthAccountSpyHelpersImpl of EthAccountSpyHelpers { fn assert_event_owner_removed( ref self: EventSpy, contract: ContractAddress, public_key: EthPublicKey ) { diff --git a/src/tests/account/ethereum/test_dual_eth_account.cairo b/packages/account/src/tests/ethereum/test_dual_eth_account.cairo similarity index 91% rename from src/tests/account/ethereum/test_dual_eth_account.cairo rename to packages/account/src/tests/ethereum/test_dual_eth_account.cairo index bde5c53f5..eafd219cc 100644 --- a/src/tests/account/ethereum/test_dual_eth_account.cairo +++ b/packages/account/src/tests/ethereum/test_dual_eth_account.cairo @@ -1,13 +1,13 @@ -use openzeppelin::account::dual_eth_account::{DualCaseEthAccountABI, DualCaseEthAccount}; -use openzeppelin::account::interface::{EthAccountABIDispatcherTrait, EthAccountABIDispatcher}; -use openzeppelin::account::utils::secp256k1::{DebugSecp256k1Point, Secp256k1PointPartialEq}; -use openzeppelin::account::utils::signature::EthSignature; -use openzeppelin::introspection::interface::ISRC5_ID; -use openzeppelin::tests::utils::constants::secp256k1::KEY_PAIR; -use openzeppelin::tests::utils::constants::{ETH_PUBKEY, NEW_ETH_PUBKEY, TRANSACTION_HASH}; -use openzeppelin::tests::utils::signing::Secp256k1KeyPairExt; -use openzeppelin::tests::utils; -use openzeppelin::utils::serde::SerializedAppend; +use openzeppelin_account::dual_eth_account::{DualCaseEthAccountABI, DualCaseEthAccount}; +use openzeppelin_account::interface::{EthAccountABIDispatcherTrait, EthAccountABIDispatcher}; +use openzeppelin_account::utils::secp256k1::{DebugSecp256k1Point, Secp256k1PointPartialEq}; +use openzeppelin_account::utils::signature::EthSignature; +use openzeppelin_introspection::interface::ISRC5_ID; +use openzeppelin_utils::serde::SerializedAppend; +use openzeppelin_utils::test_utils as utils; +use openzeppelin_utils::test_utils::constants::secp256k1::KEY_PAIR; +use openzeppelin_utils::test_utils::constants::{ETH_PUBKEY, NEW_ETH_PUBKEY, TRANSACTION_HASH}; +use openzeppelin_utils::test_utils::signing::Secp256k1KeyPairExt; use snforge_std::start_cheat_caller_address; use super::common::get_accept_ownership_signature; diff --git a/src/tests/account/ethereum/test_eth_account.cairo b/packages/account/src/tests/ethereum/test_eth_account.cairo similarity index 94% rename from src/tests/account/ethereum/test_eth_account.cairo rename to packages/account/src/tests/ethereum/test_eth_account.cairo index 4c1b50bff..4c9b097a5 100644 --- a/src/tests/account/ethereum/test_eth_account.cairo +++ b/packages/account/src/tests/ethereum/test_eth_account.cairo @@ -1,22 +1,22 @@ use core::starknet::SyscallResultTrait; -use openzeppelin::account::EthAccountComponent::{InternalTrait, SRC6CamelOnlyImpl}; -use openzeppelin::account::EthAccountComponent::{PublicKeyCamelImpl, PublicKeyImpl}; -use openzeppelin::account::EthAccountComponent; -use openzeppelin::account::interface::{EthAccountABIDispatcherTrait, EthAccountABIDispatcher}; -use openzeppelin::account::interface::{ISRC6, ISRC6_ID}; -use openzeppelin::account::utils::secp256k1::{DebugSecp256k1Point, Secp256k1PointPartialEq}; -use openzeppelin::account::utils::signature::EthSignature; -use openzeppelin::introspection::interface::{ISRC5, ISRC5_ID}; -use openzeppelin::tests::mocks::eth_account_mocks::DualCaseEthAccountMock; -use openzeppelin::tests::utils::constants::secp256k1::KEY_PAIR; -use openzeppelin::tests::utils::constants::{ +use openzeppelin_account::EthAccountComponent::{InternalTrait, SRC6CamelOnlyImpl}; +use openzeppelin_account::EthAccountComponent::{PublicKeyCamelImpl, PublicKeyImpl}; +use openzeppelin_account::EthAccountComponent; +use openzeppelin_account::interface::{EthAccountABIDispatcherTrait, EthAccountABIDispatcher}; +use openzeppelin_account::interface::{ISRC6, ISRC6_ID}; +use openzeppelin_account::tests::mocks::eth_account_mocks::DualCaseEthAccountMock; +use openzeppelin_account::utils::secp256k1::{DebugSecp256k1Point, Secp256k1PointPartialEq}; +use openzeppelin_account::utils::signature::EthSignature; +use openzeppelin_introspection::interface::{ISRC5, ISRC5_ID}; +use openzeppelin_token::erc20::interface::IERC20DispatcherTrait; +use openzeppelin_utils::selectors; +use openzeppelin_utils::serde::SerializedAppend; +use openzeppelin_utils::test_utils as utils; +use openzeppelin_utils::test_utils::constants::secp256k1::KEY_PAIR; +use openzeppelin_utils::test_utils::constants::{ ETH_PUBKEY, NEW_ETH_PUBKEY, SALT, ZERO, OTHER, RECIPIENT, CALLER, QUERY_VERSION, MIN_TRANSACTION_VERSION }; -use openzeppelin::tests::utils; -use openzeppelin::token::erc20::interface::IERC20DispatcherTrait; -use openzeppelin::utils::selectors; -use openzeppelin::utils::serde::SerializedAppend; use snforge_std::{ cheat_signature_global, cheat_transaction_version_global, cheat_transaction_hash_global, start_cheat_caller_address diff --git a/packages/account/src/tests/mocks.cairo b/packages/account/src/tests/mocks.cairo new file mode 100644 index 000000000..8b7ce956f --- /dev/null +++ b/packages/account/src/tests/mocks.cairo @@ -0,0 +1,4 @@ +pub(crate) mod account_mocks; +pub(crate) mod erc20_mocks; +pub(crate) mod eth_account_mocks; +pub(crate) mod non_implementing_mock; diff --git a/src/tests/mocks/account_mocks.cairo b/packages/account/src/tests/mocks/account_mocks.cairo similarity index 94% rename from src/tests/mocks/account_mocks.cairo rename to packages/account/src/tests/mocks/account_mocks.cairo index 9f82fb883..c2f7d9f57 100644 --- a/src/tests/mocks/account_mocks.cairo +++ b/packages/account/src/tests/mocks/account_mocks.cairo @@ -1,7 +1,7 @@ #[starknet::contract(account)] pub(crate) mod DualCaseAccountMock { - use openzeppelin::account::AccountComponent; - use openzeppelin::introspection::src5::SRC5Component; + use openzeppelin_account::AccountComponent; + use openzeppelin_introspection::src5::SRC5Component; component!(path: AccountComponent, storage: account, event: AccountEvent); component!(path: SRC5Component, storage: src5, event: SRC5Event); @@ -46,8 +46,8 @@ pub(crate) mod DualCaseAccountMock { #[starknet::contract(account)] pub(crate) mod SnakeAccountMock { - use openzeppelin::account::AccountComponent; - use openzeppelin::introspection::src5::SRC5Component; + use openzeppelin_account::AccountComponent; + use openzeppelin_introspection::src5::SRC5Component; component!(path: AccountComponent, storage: account, event: AccountEvent); component!(path: SRC5Component, storage: src5, event: SRC5Event); @@ -88,8 +88,8 @@ pub(crate) mod SnakeAccountMock { #[starknet::contract(account)] pub(crate) mod CamelAccountMock { - use openzeppelin::account::AccountComponent; - use openzeppelin::introspection::src5::SRC5Component; + use openzeppelin_account::AccountComponent; + use openzeppelin_introspection::src5::SRC5Component; use starknet::account::Call; component!(path: AccountComponent, storage: account, event: AccountEvent); diff --git a/packages/account/src/tests/mocks/erc20_mocks.cairo b/packages/account/src/tests/mocks/erc20_mocks.cairo new file mode 100644 index 000000000..8e24ff5f9 --- /dev/null +++ b/packages/account/src/tests/mocks/erc20_mocks.cairo @@ -0,0 +1,40 @@ +#[starknet::contract] +pub(crate) mod DualCaseERC20Mock { + use openzeppelin_token::erc20::{ERC20Component, ERC20HooksEmptyImpl}; + use starknet::ContractAddress; + + component!(path: ERC20Component, storage: erc20, event: ERC20Event); + + #[abi(embed_v0)] + impl ERC20Impl = ERC20Component::ERC20Impl; + #[abi(embed_v0)] + impl ERC20MetadataImpl = ERC20Component::ERC20MetadataImpl; + #[abi(embed_v0)] + impl ERC20CamelOnlyImpl = ERC20Component::ERC20CamelOnlyImpl; + impl InternalImpl = ERC20Component::InternalImpl; + + #[storage] + struct Storage { + #[substorage(v0)] + erc20: ERC20Component::Storage + } + + #[event] + #[derive(Drop, starknet::Event)] + enum Event { + #[flat] + ERC20Event: ERC20Component::Event + } + + #[constructor] + fn constructor( + ref self: ContractState, + name: ByteArray, + symbol: ByteArray, + initial_supply: u256, + recipient: ContractAddress + ) { + self.erc20.initializer(name, symbol); + self.erc20.mint(recipient, initial_supply); + } +} diff --git a/src/tests/mocks/eth_account_mocks.cairo b/packages/account/src/tests/mocks/eth_account_mocks.cairo similarity index 91% rename from src/tests/mocks/eth_account_mocks.cairo rename to packages/account/src/tests/mocks/eth_account_mocks.cairo index 24161d3ba..b230e524d 100644 --- a/src/tests/mocks/eth_account_mocks.cairo +++ b/packages/account/src/tests/mocks/eth_account_mocks.cairo @@ -1,8 +1,8 @@ #[starknet::contract(account)] pub(crate) mod DualCaseEthAccountMock { - use openzeppelin::account::EthAccountComponent; - use openzeppelin::account::interface::EthPublicKey; - use openzeppelin::introspection::src5::SRC5Component; + use openzeppelin_account::EthAccountComponent; + use openzeppelin_account::interface::EthPublicKey; + use openzeppelin_introspection::src5::SRC5Component; component!(path: EthAccountComponent, storage: eth_account, event: EthAccountEvent); component!(path: SRC5Component, storage: src5, event: SRC5Event); @@ -44,9 +44,9 @@ pub(crate) mod DualCaseEthAccountMock { #[starknet::contract(account)] pub(crate) mod SnakeEthAccountMock { - use openzeppelin::account::EthAccountComponent; - use openzeppelin::account::interface::EthPublicKey; - use openzeppelin::introspection::src5::SRC5Component; + use openzeppelin_account::EthAccountComponent; + use openzeppelin_account::interface::EthPublicKey; + use openzeppelin_introspection::src5::SRC5Component; component!(path: EthAccountComponent, storage: eth_account, event: EthAccountEvent); component!(path: SRC5Component, storage: src5, event: SRC5Event); @@ -84,9 +84,9 @@ pub(crate) mod SnakeEthAccountMock { #[starknet::contract(account)] pub(crate) mod CamelEthAccountMock { - use openzeppelin::account::EthAccountComponent; - use openzeppelin::account::interface::EthPublicKey; - use openzeppelin::introspection::src5::SRC5Component; + use openzeppelin_account::EthAccountComponent; + use openzeppelin_account::interface::EthPublicKey; + use openzeppelin_introspection::src5::SRC5Component; use starknet::account::Call; component!(path: EthAccountComponent, storage: eth_account, event: EthAccountEvent); @@ -147,7 +147,7 @@ pub(crate) mod CamelEthAccountMock { #[starknet::contract] pub(crate) mod SnakeEthAccountPanicMock { - use openzeppelin::account::interface::EthPublicKey; + use openzeppelin_account::interface::EthPublicKey; use starknet::SyscallResultTrait; use starknet::secp256_trait::Secp256Trait; @@ -188,7 +188,7 @@ pub(crate) mod SnakeEthAccountPanicMock { #[starknet::contract] pub(crate) mod CamelEthAccountPanicMock { - use openzeppelin::account::interface::EthPublicKey; + use openzeppelin_account::interface::EthPublicKey; use starknet::SyscallResultTrait; use starknet::secp256_trait::Secp256Trait; diff --git a/packages/account/src/tests/mocks/non_implementing_mock.cairo b/packages/account/src/tests/mocks/non_implementing_mock.cairo new file mode 100644 index 000000000..c1212dbdd --- /dev/null +++ b/packages/account/src/tests/mocks/non_implementing_mock.cairo @@ -0,0 +1,10 @@ +#[starknet::contract] +pub(crate) mod NonImplementingMock { + #[storage] + struct Storage {} + + #[external(v0)] + fn nope(self: @ContractState) -> bool { + false + } +} diff --git a/src/tests/account/starknet.cairo b/packages/account/src/tests/starknet.cairo similarity index 70% rename from src/tests/account/starknet.cairo rename to packages/account/src/tests/starknet.cairo index 8c3e80c69..1169c780f 100644 --- a/src/tests/account/starknet.cairo +++ b/packages/account/src/tests/starknet.cairo @@ -1,3 +1,6 @@ pub(crate) mod common; + +#[cfg(test)] mod test_account; +#[cfg(test)] mod test_dual_account; diff --git a/src/tests/account/starknet/common.cairo b/packages/account/src/tests/starknet/common.cairo similarity index 83% rename from src/tests/account/starknet/common.cairo rename to packages/account/src/tests/starknet/common.cairo index 26554ba33..cde377be5 100644 --- a/src/tests/account/starknet/common.cairo +++ b/packages/account/src/tests/starknet/common.cairo @@ -1,13 +1,13 @@ use core::hash::{HashStateTrait, HashStateExTrait}; use core::poseidon::PoseidonTrait; -use openzeppelin::account::AccountComponent::{OwnerAdded, OwnerRemoved}; -use openzeppelin::account::AccountComponent; -use openzeppelin::tests::utils::constants::{NAME, SYMBOL, TRANSACTION_HASH}; -use openzeppelin::tests::utils::events::EventSpyExt; -use openzeppelin::tests::utils::signing::StarkKeyPair; -use openzeppelin::tests::utils; -use openzeppelin::token::erc20::interface::IERC20Dispatcher; -use openzeppelin::utils::serde::SerializedAppend; +use openzeppelin_account::AccountComponent::{OwnerAdded, OwnerRemoved}; +use openzeppelin_account::AccountComponent; +use openzeppelin_token::erc20::interface::IERC20Dispatcher; +use openzeppelin_utils::serde::SerializedAppend; +use openzeppelin_utils::test_utils as utils; +use openzeppelin_utils::test_utils::constants::{NAME, SYMBOL, TRANSACTION_HASH}; +use openzeppelin_utils::test_utils::events::EventSpyExt; +use openzeppelin_utils::test_utils::signing::StarkKeyPair; use snforge_std::EventSpy; use snforge_std::signature::stark_curve::StarkCurveSignerImpl; use starknet::ContractAddress; diff --git a/src/tests/account/starknet/test_account.cairo b/packages/account/src/tests/starknet/test_account.cairo similarity index 94% rename from src/tests/account/starknet/test_account.cairo rename to packages/account/src/tests/starknet/test_account.cairo index 7bfa8e377..0d5892731 100644 --- a/src/tests/account/starknet/test_account.cairo +++ b/packages/account/src/tests/starknet/test_account.cairo @@ -1,21 +1,21 @@ use core::num::traits::Zero; use core::starknet::SyscallResultTrait; -use openzeppelin::account::AccountComponent::{InternalTrait, SRC6CamelOnlyImpl}; -use openzeppelin::account::AccountComponent::{PublicKeyCamelImpl, PublicKeyImpl}; -use openzeppelin::account::AccountComponent; -use openzeppelin::account::interface::{AccountABIDispatcherTrait, AccountABIDispatcher}; -use openzeppelin::account::interface::{ISRC6, ISRC6_ID}; -use openzeppelin::introspection::interface::{ISRC5, ISRC5_ID}; -use openzeppelin::tests::mocks::account_mocks::DualCaseAccountMock; -use openzeppelin::tests::utils::constants::stark::{KEY_PAIR, KEY_PAIR_2}; -use openzeppelin::tests::utils::constants::{ +use openzeppelin_account::AccountComponent::{InternalTrait, SRC6CamelOnlyImpl}; +use openzeppelin_account::AccountComponent::{PublicKeyCamelImpl, PublicKeyImpl}; +use openzeppelin_account::AccountComponent; +use openzeppelin_account::interface::{AccountABIDispatcherTrait, AccountABIDispatcher}; +use openzeppelin_account::interface::{ISRC6, ISRC6_ID}; +use openzeppelin_account::tests::mocks::account_mocks::DualCaseAccountMock; +use openzeppelin_introspection::interface::{ISRC5, ISRC5_ID}; +use openzeppelin_token::erc20::interface::IERC20DispatcherTrait; +use openzeppelin_utils::selectors; +use openzeppelin_utils::serde::SerializedAppend; +use openzeppelin_utils::test_utils as utils; +use openzeppelin_utils::test_utils::constants::stark::{KEY_PAIR, KEY_PAIR_2}; +use openzeppelin_utils::test_utils::constants::{ SALT, ZERO, OTHER, CALLER, RECIPIENT, QUERY_OFFSET, QUERY_VERSION, MIN_TRANSACTION_VERSION }; -use openzeppelin::tests::utils::signing::StarkKeyPair; -use openzeppelin::tests::utils; -use openzeppelin::token::erc20::interface::IERC20DispatcherTrait; -use openzeppelin::utils::selectors; -use openzeppelin::utils::serde::SerializedAppend; +use openzeppelin_utils::test_utils::signing::StarkKeyPair; use snforge_std::{ cheat_signature_global, cheat_transaction_version_global, cheat_transaction_hash_global }; diff --git a/src/tests/account/starknet/test_dual_account.cairo b/packages/account/src/tests/starknet/test_dual_account.cairo similarity index 92% rename from src/tests/account/starknet/test_dual_account.cairo rename to packages/account/src/tests/starknet/test_dual_account.cairo index ab0887896..9609514a8 100644 --- a/src/tests/account/starknet/test_dual_account.cairo +++ b/packages/account/src/tests/starknet/test_dual_account.cairo @@ -1,11 +1,11 @@ -use openzeppelin::account::dual_account::{DualCaseAccountABI, DualCaseAccount}; -use openzeppelin::account::interface::{AccountABIDispatcherTrait, AccountABIDispatcher}; -use openzeppelin::introspection::interface::ISRC5_ID; -use openzeppelin::tests::account::starknet::common::SIGNED_TX_DATA; -use openzeppelin::tests::utils::constants::TRANSACTION_HASH; -use openzeppelin::tests::utils::constants::stark::{KEY_PAIR, KEY_PAIR_2}; -use openzeppelin::tests::utils::signing::{StarkKeyPair, StarkKeyPairExt}; -use openzeppelin::tests::utils; +use openzeppelin_account::dual_account::{DualCaseAccountABI, DualCaseAccount}; +use openzeppelin_account::interface::{AccountABIDispatcherTrait, AccountABIDispatcher}; +use openzeppelin_account::tests::starknet::common::SIGNED_TX_DATA; +use openzeppelin_introspection::interface::ISRC5_ID; +use openzeppelin_utils::test_utils as utils; +use openzeppelin_utils::test_utils::constants::TRANSACTION_HASH; +use openzeppelin_utils::test_utils::constants::stark::{KEY_PAIR, KEY_PAIR_2}; +use openzeppelin_utils::test_utils::signing::{StarkKeyPair, StarkKeyPairExt}; use snforge_std::{declare, start_cheat_caller_address}; use super::common::get_accept_ownership_signature; diff --git a/src/tests/account/test_secp256k1.cairo b/packages/account/src/tests/test_secp256k1.cairo similarity index 98% rename from src/tests/account/test_secp256k1.cairo rename to packages/account/src/tests/test_secp256k1.cairo index 0fb43803c..5cb3e2235 100644 --- a/src/tests/account/test_secp256k1.cairo +++ b/packages/account/src/tests/test_secp256k1.cairo @@ -1,4 +1,4 @@ -use openzeppelin::account::utils::secp256k1::{ +use openzeppelin_account::utils::secp256k1::{ DebugSecp256k1Point, Secp256k1PointPartialEq, Secp256k1PointStorePacking as StorePacking }; use starknet::SyscallResultTrait; diff --git a/src/tests/account/test_signature.cairo b/packages/account/src/tests/test_signature.cairo similarity index 95% rename from src/tests/account/test_signature.cairo rename to packages/account/src/tests/test_signature.cairo index 548afb817..79f9368b5 100644 --- a/src/tests/account/test_signature.cairo +++ b/packages/account/src/tests/test_signature.cairo @@ -1,5 +1,5 @@ -use openzeppelin::account::utils::signature::{is_valid_stark_signature, is_valid_eth_signature}; -use openzeppelin::tests::utils::constants::{stark, secp256k1}; +use openzeppelin_account::utils::signature::{is_valid_stark_signature, is_valid_eth_signature}; +use openzeppelin_utils::test_utils::constants::{stark, secp256k1}; use starknet::secp256_trait::Secp256Trait; use starknet::secp256k1::Secp256k1Point; diff --git a/src/account/utils.cairo b/packages/account/src/utils.cairo similarity index 100% rename from src/account/utils.cairo rename to packages/account/src/utils.cairo diff --git a/src/account/utils/secp256k1.cairo b/packages/account/src/utils/secp256k1.cairo similarity index 93% rename from src/account/utils/secp256k1.cairo rename to packages/account/src/utils/secp256k1.cairo index fe4f00695..838a5e23f 100644 --- a/src/account/utils/secp256k1.cairo +++ b/packages/account/src/utils/secp256k1.cairo @@ -39,7 +39,7 @@ pub impl Secp256k1PointStorePacking of StorePacking { +pub impl Secp256k1PointPartialEq of PartialEq { #[inline(always)] fn eq(lhs: @Secp256k1Point, rhs: @Secp256k1Point) -> bool { (*lhs).get_coordinates().unwrap_syscall() == (*rhs).get_coordinates().unwrap_syscall() @@ -50,7 +50,7 @@ pub(crate) impl Secp256k1PointPartialEq of PartialEq { } } -pub(crate) impl DebugSecp256k1Point of core::fmt::Debug { +pub impl DebugSecp256k1Point of core::fmt::Debug { fn fmt(self: @Secp256k1Point, ref f: Formatter) -> Result<(), Error> { let (x, y) = (*self).get_coordinates().unwrap_syscall(); write!(f, "({x:?},{y:?})") diff --git a/src/account/utils/signature.cairo b/packages/account/src/utils/signature.cairo similarity index 96% rename from src/account/utils/signature.cairo rename to packages/account/src/utils/signature.cairo index f247df83f..922e04f91 100644 --- a/src/account/utils/signature.cairo +++ b/packages/account/src/utils/signature.cairo @@ -2,7 +2,7 @@ // OpenZeppelin Contracts for Cairo v0.15.0-rc.0 (account/utils/signature.cairo) use core::ecdsa::check_ecdsa_signature; -use openzeppelin::account::interface::EthPublicKey; +use openzeppelin_account::interface::EthPublicKey; use starknet::secp256_trait; #[derive(Copy, Drop, Serde)] diff --git a/packages/governance/Scarb.toml b/packages/governance/Scarb.toml new file mode 100644 index 000000000..d719a38ce --- /dev/null +++ b/packages/governance/Scarb.toml @@ -0,0 +1,32 @@ +[package] +name = "openzeppelin_governance" +version.workspace = true +edition.workspace = true +cairo-version.workspace = true +scarb-version.workspace = true +authors.workspace = true +description.workspace = true +documentation.workspace = true +readme.workspace = true +repository.workspace = true +license-file.workspace = true +keywords.workspace = true + +[tool] +fmt.workspace = true + +[dependencies] +starknet.workspace = true +openzeppelin_access = { path = "../access" } +openzeppelin_introspection = { path = "../introspection" } +openzeppelin_utils = { path = "../utils" } + +[dev-dependencies] +snforge_std.workspace = true + +[lib] + +[[target.starknet-contract]] +allowed-libfuncs-list.name = "experimental" +sierra = true +casm = false diff --git a/src/governance.cairo b/packages/governance/src/lib.cairo similarity index 73% rename from src/governance.cairo rename to packages/governance/src/lib.cairo index 01d740d38..852e24521 100644 --- a/src/governance.cairo +++ b/packages/governance/src/lib.cairo @@ -1,2 +1,4 @@ +mod tests; + pub mod timelock; pub mod utils; diff --git a/packages/governance/src/tests.cairo b/packages/governance/src/tests.cairo new file mode 100644 index 000000000..221670eec --- /dev/null +++ b/packages/governance/src/tests.cairo @@ -0,0 +1,6 @@ +pub(crate) mod mocks; + +#[cfg(test)] +mod test_timelock; +#[cfg(test)] +mod test_utils; diff --git a/packages/governance/src/tests/mocks.cairo b/packages/governance/src/tests/mocks.cairo new file mode 100644 index 000000000..6d38a6715 --- /dev/null +++ b/packages/governance/src/tests/mocks.cairo @@ -0,0 +1,2 @@ +pub(crate) mod non_implementing_mock; +pub(crate) mod timelock_mocks; diff --git a/packages/governance/src/tests/mocks/non_implementing_mock.cairo b/packages/governance/src/tests/mocks/non_implementing_mock.cairo new file mode 100644 index 000000000..c1212dbdd --- /dev/null +++ b/packages/governance/src/tests/mocks/non_implementing_mock.cairo @@ -0,0 +1,10 @@ +#[starknet::contract] +pub(crate) mod NonImplementingMock { + #[storage] + struct Storage {} + + #[external(v0)] + fn nope(self: @ContractState) -> bool { + false + } +} diff --git a/src/tests/mocks/timelock_mocks.cairo b/packages/governance/src/tests/mocks/timelock_mocks.cairo similarity index 94% rename from src/tests/mocks/timelock_mocks.cairo rename to packages/governance/src/tests/mocks/timelock_mocks.cairo index a60a9da19..810d88cac 100644 --- a/src/tests/mocks/timelock_mocks.cairo +++ b/packages/governance/src/tests/mocks/timelock_mocks.cairo @@ -1,8 +1,8 @@ #[starknet::contract] pub(crate) mod TimelockControllerMock { - use openzeppelin::access::accesscontrol::AccessControlComponent; - use openzeppelin::governance::timelock::TimelockControllerComponent; - use openzeppelin::introspection::src5::SRC5Component; + use openzeppelin_access::accesscontrol::AccessControlComponent; + use openzeppelin_governance::timelock::TimelockControllerComponent; + use openzeppelin_introspection::src5::SRC5Component; use starknet::ContractAddress; component!(path: AccessControlComponent, storage: access_control, event: AccessControlEvent); @@ -88,7 +88,7 @@ pub(crate) trait ITimelockAttacker { #[starknet::contract] pub(crate) mod TimelockAttackerMock { - use openzeppelin::governance::timelock::interface::{ + use openzeppelin_governance::timelock::interface::{ ITimelockDispatcher, ITimelockDispatcherTrait }; use starknet::ContractAddress; diff --git a/src/tests/governance/test_timelock.cairo b/packages/governance/src/tests/test_timelock.cairo similarity index 97% rename from src/tests/governance/test_timelock.cairo rename to packages/governance/src/tests/test_timelock.cairo index d3838ae21..6ba38fff4 100644 --- a/src/tests/governance/test_timelock.cairo +++ b/packages/governance/src/tests/test_timelock.cairo @@ -1,38 +1,40 @@ use core::hash::{HashStateTrait, HashStateExTrait}; use core::num::traits::Zero; use core::pedersen::PedersenTrait; -use openzeppelin::access::accesscontrol::AccessControlComponent::{ +use openzeppelin_access::accesscontrol::AccessControlComponent::{ AccessControlImpl, InternalImpl as AccessControlInternalImpl }; -use openzeppelin::access::accesscontrol::DEFAULT_ADMIN_ROLE; -use openzeppelin::access::accesscontrol::interface::IACCESSCONTROL_ID; -use openzeppelin::access::accesscontrol::interface::IAccessControl; -use openzeppelin::governance::timelock::OperationState; -use openzeppelin::governance::timelock::TimelockControllerComponent::{ +use openzeppelin_access::accesscontrol::DEFAULT_ADMIN_ROLE; +use openzeppelin_access::accesscontrol::interface::IACCESSCONTROL_ID; +use openzeppelin_access::accesscontrol::interface::IAccessControl; +use openzeppelin_governance::tests::mocks::timelock_mocks::MockContract; +use openzeppelin_governance::tests::mocks::timelock_mocks::{ + IMockContractDispatcher, IMockContractDispatcherTrait +}; +use openzeppelin_governance::tests::mocks::timelock_mocks::{ + ITimelockAttackerDispatcher, ITimelockAttackerDispatcherTrait +}; +use openzeppelin_governance::tests::mocks::timelock_mocks::{ + TimelockControllerMock, TimelockAttackerMock +}; +use openzeppelin_governance::timelock::OperationState; +use openzeppelin_governance::timelock::TimelockControllerComponent::{ CallScheduled, CallExecuted, CallSalt, CallCancelled, MinDelayChanged }; -use openzeppelin::governance::timelock::TimelockControllerComponent::{ +use openzeppelin_governance::timelock::TimelockControllerComponent::{ TimelockImpl, InternalImpl as TimelockInternalImpl }; -use openzeppelin::governance::timelock::TimelockControllerComponent; -use openzeppelin::governance::timelock::interface::{ +use openzeppelin_governance::timelock::TimelockControllerComponent; +use openzeppelin_governance::timelock::interface::{ TimelockABIDispatcher, TimelockABIDispatcherTrait }; -use openzeppelin::governance::timelock::{PROPOSER_ROLE, EXECUTOR_ROLE, CANCELLER_ROLE}; -use openzeppelin::introspection::interface::ISRC5_ID; -use openzeppelin::introspection::src5::SRC5Component::SRC5Impl; -use openzeppelin::tests::mocks::timelock_mocks::MockContract; -use openzeppelin::tests::mocks::timelock_mocks::{ - IMockContractDispatcher, IMockContractDispatcherTrait -}; -use openzeppelin::tests::mocks::timelock_mocks::{ - ITimelockAttackerDispatcher, ITimelockAttackerDispatcherTrait -}; -use openzeppelin::tests::mocks::timelock_mocks::{TimelockControllerMock, TimelockAttackerMock}; -use openzeppelin::tests::utils::constants::{ADMIN, ZERO, OTHER, SALT, FELT_VALUE as VALUE}; -use openzeppelin::tests::utils::events::EventSpyExt; -use openzeppelin::tests::utils; -use openzeppelin::utils::serde::SerializedAppend; +use openzeppelin_governance::timelock::{PROPOSER_ROLE, EXECUTOR_ROLE, CANCELLER_ROLE}; +use openzeppelin_introspection::interface::ISRC5_ID; +use openzeppelin_introspection::src5::SRC5Component::SRC5Impl; +use openzeppelin_utils::serde::SerializedAppend; +use openzeppelin_utils::test_utils as utils; +use openzeppelin_utils::test_utils::constants::{ADMIN, ZERO, OTHER, SALT, FELT_VALUE as VALUE}; +use openzeppelin_utils::test_utils::events::EventSpyExt; use snforge_std::EventSpy; use snforge_std::{ spy_events, test_address, start_cheat_caller_address, cheat_caller_address, diff --git a/src/tests/governance/test_utils.cairo b/packages/governance/src/tests/test_utils.cairo similarity index 98% rename from src/tests/governance/test_utils.cairo rename to packages/governance/src/tests/test_utils.cairo index 874fe2615..f66bafa33 100644 --- a/src/tests/governance/test_utils.cairo +++ b/packages/governance/src/tests/test_utils.cairo @@ -1,4 +1,4 @@ -use openzeppelin::governance::timelock::utils::call_impls::CallPartialEq; +use openzeppelin_governance::timelock::utils::call_impls::CallPartialEq; use starknet::account::Call; use starknet::contract_address_const; diff --git a/src/governance/timelock.cairo b/packages/governance/src/timelock.cairo similarity index 100% rename from src/governance/timelock.cairo rename to packages/governance/src/timelock.cairo diff --git a/src/governance/timelock/interface.cairo b/packages/governance/src/timelock/interface.cairo similarity index 98% rename from src/governance/timelock/interface.cairo rename to packages/governance/src/timelock/interface.cairo index 0c89d0c20..b228ed664 100644 --- a/src/governance/timelock/interface.cairo +++ b/packages/governance/src/timelock/interface.cairo @@ -1,7 +1,7 @@ // SPDX-License-Identifier: MIT // OpenZeppelin Contracts for Cairo v0.15.0-rc.0 (governance/timelock/interface.cairo) -use openzeppelin::governance::timelock::OperationState; +use openzeppelin_governance::timelock::OperationState; use starknet::ContractAddress; use starknet::account::Call; diff --git a/src/governance/timelock/timelock_controller.cairo b/packages/governance/src/timelock/timelock_controller.cairo similarity index 97% rename from src/governance/timelock/timelock_controller.cairo rename to packages/governance/src/timelock/timelock_controller.cairo index 494692025..40d269622 100644 --- a/src/governance/timelock/timelock_controller.cairo +++ b/packages/governance/src/timelock/timelock_controller.cairo @@ -17,18 +17,18 @@ pub mod TimelockControllerComponent { use core::hash::{HashStateTrait, HashStateExTrait}; use core::num::traits::Zero; use core::pedersen::PedersenTrait; - use openzeppelin::access::accesscontrol::AccessControlComponent::InternalTrait as AccessControlInternalTrait; - use openzeppelin::access::accesscontrol::AccessControlComponent::{ + use openzeppelin_access::accesscontrol::AccessControlComponent::InternalTrait as AccessControlInternalTrait; + use openzeppelin_access::accesscontrol::AccessControlComponent::{ AccessControlImpl, AccessControlCamelImpl }; - use openzeppelin::access::accesscontrol::AccessControlComponent; - use openzeppelin::access::accesscontrol::DEFAULT_ADMIN_ROLE; - use openzeppelin::governance::timelock::interface::{ITimelock, TimelockABI}; - use openzeppelin::governance::timelock::utils::call_impls::{ + use openzeppelin_access::accesscontrol::AccessControlComponent; + use openzeppelin_access::accesscontrol::DEFAULT_ADMIN_ROLE; + use openzeppelin_governance::timelock::interface::{ITimelock, TimelockABI}; + use openzeppelin_governance::timelock::utils::call_impls::{ HashCallImpl, HashCallsImpl, CallPartialEq }; - use openzeppelin::introspection::src5::SRC5Component::SRC5Impl; - use openzeppelin::introspection::src5::SRC5Component; + use openzeppelin_introspection::src5::SRC5Component::SRC5Impl; + use openzeppelin_introspection::src5::SRC5Component; use starknet::ContractAddress; use starknet::SyscallResultTrait; use starknet::account::Call; diff --git a/src/governance/timelock/utils.cairo b/packages/governance/src/timelock/utils.cairo similarity index 100% rename from src/governance/timelock/utils.cairo rename to packages/governance/src/timelock/utils.cairo diff --git a/src/governance/timelock/utils/call_impls.cairo b/packages/governance/src/timelock/utils/call_impls.cairo similarity index 83% rename from src/governance/timelock/utils/call_impls.cairo rename to packages/governance/src/timelock/utils/call_impls.cairo index 428259e57..5a46b6efe 100644 --- a/src/governance/timelock/utils/call_impls.cairo +++ b/packages/governance/src/timelock/utils/call_impls.cairo @@ -4,7 +4,7 @@ use core::hash::{HashStateTrait, HashStateExTrait, Hash}; use starknet::account::Call; -pub(crate) impl HashCallImpl, +Drop> of Hash { +pub impl HashCallImpl, +Drop> of Hash { fn update_state(mut state: S, value: Call) -> S { let Call { to, selector, calldata } = value; state = state.update_with(to).update_with(selector).update_with(calldata.len()); @@ -16,7 +16,7 @@ pub(crate) impl HashCallImpl, +Drop> of Hash { } } -pub(crate) impl HashCallsImpl, +Drop> of Hash, S> { +pub impl HashCallsImpl, +Drop> of Hash, S> { fn update_state(mut state: S, value: Span) -> S { state = state.update_with(value.len()); for call in value { @@ -27,7 +27,7 @@ pub(crate) impl HashCallsImpl, +Drop> of Hash { +pub impl CallPartialEq of PartialEq { #[inline(always)] fn eq(lhs: @Call, rhs: @Call) -> bool { let Call { to: l_to, selector: l_selector, calldata: l_calldata } = lhs; diff --git a/src/governance/utils.cairo b/packages/governance/src/utils.cairo similarity index 100% rename from src/governance/utils.cairo rename to packages/governance/src/utils.cairo diff --git a/src/governance/utils/interfaces.cairo b/packages/governance/src/utils/interfaces.cairo similarity index 100% rename from src/governance/utils/interfaces.cairo rename to packages/governance/src/utils/interfaces.cairo diff --git a/src/governance/utils/interfaces/votes.cairo b/packages/governance/src/utils/interfaces/votes.cairo similarity index 100% rename from src/governance/utils/interfaces/votes.cairo rename to packages/governance/src/utils/interfaces/votes.cairo diff --git a/packages/introspection/Scarb.toml b/packages/introspection/Scarb.toml new file mode 100644 index 000000000..1ccc1aae8 --- /dev/null +++ b/packages/introspection/Scarb.toml @@ -0,0 +1,30 @@ + +[package] +name = "openzeppelin_introspection" +version.workspace = true +edition.workspace = true +cairo-version.workspace = true +scarb-version.workspace = true +authors.workspace = true +description.workspace = true +documentation.workspace = true +readme.workspace = true +repository.workspace = true +license-file.workspace = true +keywords.workspace = true + +[tool] +fmt.workspace = true + +[dependencies] +starknet.workspace = true + +[dev-dependencies] +snforge_std.workspace = true + +[lib] + +[[target.starknet-contract]] +allowed-libfuncs-list.name = "experimental" +sierra = true +casm = false diff --git a/src/introspection/interface.cairo b/packages/introspection/src/interface.cairo similarity index 100% rename from src/introspection/interface.cairo rename to packages/introspection/src/interface.cairo diff --git a/src/introspection.cairo b/packages/introspection/src/lib.cairo similarity index 73% rename from src/introspection.cairo rename to packages/introspection/src/lib.cairo index 584b93016..6134bb225 100644 --- a/src/introspection.cairo +++ b/packages/introspection/src/lib.cairo @@ -1,2 +1,4 @@ pub mod interface; pub mod src5; + +mod tests; diff --git a/src/introspection/src5.cairo b/packages/introspection/src/src5.cairo similarity index 97% rename from src/introspection/src5.cairo rename to packages/introspection/src/src5.cairo index 530fb73b2..52b683fbc 100644 --- a/src/introspection/src5.cairo +++ b/packages/introspection/src/src5.cairo @@ -6,7 +6,7 @@ /// The SRC5 component allows contracts to expose the interfaces they implement. #[starknet::component] pub mod SRC5Component { - use openzeppelin::introspection::interface; + use openzeppelin_introspection::interface; use starknet::storage::Map; #[storage] diff --git a/packages/introspection/src/tests.cairo b/packages/introspection/src/tests.cairo new file mode 100644 index 000000000..72a21d551 --- /dev/null +++ b/packages/introspection/src/tests.cairo @@ -0,0 +1,4 @@ +pub(crate) mod mocks; + +#[cfg(test)] +mod test_src5; diff --git a/packages/introspection/src/tests/mocks.cairo b/packages/introspection/src/tests/mocks.cairo new file mode 100644 index 000000000..dc995e8e3 --- /dev/null +++ b/packages/introspection/src/tests/mocks.cairo @@ -0,0 +1 @@ +pub(crate) mod src5_mocks; diff --git a/src/tests/mocks/src5_mocks.cairo b/packages/introspection/src/tests/mocks/src5_mocks.cairo similarity index 88% rename from src/tests/mocks/src5_mocks.cairo rename to packages/introspection/src/tests/mocks/src5_mocks.cairo index f6d5f51b5..86e8c5167 100644 --- a/src/tests/mocks/src5_mocks.cairo +++ b/packages/introspection/src/tests/mocks/src5_mocks.cairo @@ -1,6 +1,6 @@ #[starknet::contract] pub(crate) mod SRC5Mock { - use openzeppelin::introspection::src5::SRC5Component; + use openzeppelin_introspection::src5::SRC5Component; component!(path: SRC5Component, storage: src5, event: SRC5Event); diff --git a/src/tests/introspection/test_src5.cairo b/packages/introspection/src/tests/test_src5.cairo similarity index 83% rename from src/tests/introspection/test_src5.cairo rename to packages/introspection/src/tests/test_src5.cairo index 7280845de..9fa6cf108 100644 --- a/src/tests/introspection/test_src5.cairo +++ b/packages/introspection/src/tests/test_src5.cairo @@ -1,7 +1,7 @@ -use openzeppelin::introspection::interface::{ISRC5_ID, ISRC5}; -use openzeppelin::introspection::src5::SRC5Component::InternalTrait; -use openzeppelin::introspection::src5::SRC5Component; -use openzeppelin::tests::mocks::src5_mocks::SRC5Mock; +use openzeppelin_introspection::interface::{ISRC5_ID, ISRC5}; +use openzeppelin_introspection::src5::SRC5Component::InternalTrait; +use openzeppelin_introspection::src5::SRC5Component; +use openzeppelin_introspection::tests::mocks::src5_mocks::SRC5Mock; const OTHER_ID: felt252 = 0x12345678; diff --git a/packages/presets/Scarb.toml b/packages/presets/Scarb.toml new file mode 100644 index 000000000..8319757ba --- /dev/null +++ b/packages/presets/Scarb.toml @@ -0,0 +1,35 @@ + +[package] +name = "openzeppelin_presets" +version.workspace = true +edition.workspace = true +cairo-version.workspace = true +scarb-version.workspace = true +authors.workspace = true +description.workspace = true +documentation.workspace = true +readme.workspace = true +repository.workspace = true +license-file.workspace = true +keywords.workspace = true + +[tool] +fmt.workspace = true + +[dependencies] +starknet.workspace = true +openzeppelin_access = { path = "../access" } +openzeppelin_account = { path = "../account" } +openzeppelin_introspection = { path = "../introspection" } +openzeppelin_token = { path = "../token" } +openzeppelin_upgrades = { path = "../upgrades" } + +[dev-dependencies] +snforge_std.workspace = true + +[lib] + +[[target.starknet-contract]] +allowed-libfuncs-list.name = "experimental" +sierra = true +casm = false diff --git a/src/presets/account.cairo b/packages/presets/src/account.cairo similarity index 83% rename from src/presets/account.cairo rename to packages/presets/src/account.cairo index 93cb2b5ef..3c5c10c8b 100644 --- a/src/presets/account.cairo +++ b/packages/presets/src/account.cairo @@ -6,11 +6,11 @@ /// OpenZeppelin's upgradeable account which can change its public key and declare, deploy, or call /// contracts. #[starknet::contract(account)] -pub(crate) mod AccountUpgradeable { - use openzeppelin::account::AccountComponent; - use openzeppelin::introspection::src5::SRC5Component; - use openzeppelin::upgrades::UpgradeableComponent; - use openzeppelin::upgrades::interface::IUpgradeable; +pub mod AccountUpgradeable { + use openzeppelin_account::AccountComponent; + use openzeppelin_introspection::src5::SRC5Component; + use openzeppelin_upgrades::UpgradeableComponent; + use openzeppelin_upgrades::interface::IUpgradeable; use starknet::ClassHash; component!(path: AccountComponent, storage: account, event: AccountEvent); @@ -48,7 +48,7 @@ pub(crate) mod AccountUpgradeable { } #[constructor] - pub(crate) fn constructor(ref self: ContractState, public_key: felt252) { + pub fn constructor(ref self: ContractState, public_key: felt252) { self.account.initializer(public_key); } diff --git a/src/presets/erc1155.cairo b/packages/presets/src/erc1155.cairo similarity index 90% rename from src/presets/erc1155.cairo rename to packages/presets/src/erc1155.cairo index b24bdf100..cc387852a 100644 --- a/src/presets/erc1155.cairo +++ b/packages/presets/src/erc1155.cairo @@ -9,12 +9,12 @@ /// For more complex or custom contracts, use Wizard for Cairo /// https://wizard.openzeppelin.com/cairo #[starknet::contract] -pub(crate) mod ERC1155Upgradeable { - use openzeppelin::access::ownable::OwnableComponent; - use openzeppelin::introspection::src5::SRC5Component; - use openzeppelin::token::erc1155::{ERC1155Component, ERC1155HooksEmptyImpl}; - use openzeppelin::upgrades::UpgradeableComponent; - use openzeppelin::upgrades::interface::IUpgradeable; +pub mod ERC1155Upgradeable { + use openzeppelin_access::ownable::OwnableComponent; + use openzeppelin_introspection::src5::SRC5Component; + use openzeppelin_token::erc1155::{ERC1155Component, ERC1155HooksEmptyImpl}; + use openzeppelin_upgrades::UpgradeableComponent; + use openzeppelin_upgrades::interface::IUpgradeable; use starknet::{ContractAddress, ClassHash}; component!(path: OwnableComponent, storage: ownable, event: OwnableEvent); diff --git a/src/presets/erc20.cairo b/packages/presets/src/erc20.cairo similarity index 90% rename from src/presets/erc20.cairo rename to packages/presets/src/erc20.cairo index 94506ba3e..8b213ee86 100644 --- a/src/presets/erc20.cairo +++ b/packages/presets/src/erc20.cairo @@ -10,11 +10,11 @@ /// For more complex or custom contracts, use Wizard for Cairo /// https://wizard.openzeppelin.com/cairo #[starknet::contract] -pub(crate) mod ERC20Upgradeable { - use openzeppelin::access::ownable::OwnableComponent; - use openzeppelin::token::erc20::{ERC20Component, ERC20HooksEmptyImpl}; - use openzeppelin::upgrades::UpgradeableComponent; - use openzeppelin::upgrades::interface::IUpgradeable; +pub mod ERC20Upgradeable { + use openzeppelin_access::ownable::OwnableComponent; + use openzeppelin_token::erc20::{ERC20Component, ERC20HooksEmptyImpl}; + use openzeppelin_upgrades::UpgradeableComponent; + use openzeppelin_upgrades::interface::IUpgradeable; use starknet::{ContractAddress, ClassHash}; component!(path: OwnableComponent, storage: ownable, event: OwnableEvent); diff --git a/src/presets/erc721.cairo b/packages/presets/src/erc721.cairo similarity index 90% rename from src/presets/erc721.cairo rename to packages/presets/src/erc721.cairo index 1359736f7..800b587e2 100644 --- a/src/presets/erc721.cairo +++ b/packages/presets/src/erc721.cairo @@ -9,12 +9,12 @@ /// For more complex or custom contracts, use Wizard for Cairo /// https://wizard.openzeppelin.com/cairo #[starknet::contract] -pub(crate) mod ERC721Upgradeable { - use openzeppelin::access::ownable::OwnableComponent; - use openzeppelin::introspection::src5::SRC5Component; - use openzeppelin::token::erc721::{ERC721Component, ERC721HooksEmptyImpl}; - use openzeppelin::upgrades::UpgradeableComponent; - use openzeppelin::upgrades::interface::IUpgradeable; +pub mod ERC721Upgradeable { + use openzeppelin_access::ownable::OwnableComponent; + use openzeppelin_introspection::src5::SRC5Component; + use openzeppelin_token::erc721::{ERC721Component, ERC721HooksEmptyImpl}; + use openzeppelin_upgrades::UpgradeableComponent; + use openzeppelin_upgrades::interface::IUpgradeable; use starknet::{ContractAddress, ClassHash}; component!(path: OwnableComponent, storage: ownable, event: OwnableEvent); diff --git a/src/presets/eth_account.cairo b/packages/presets/src/eth_account.cairo similarity index 87% rename from src/presets/eth_account.cairo rename to packages/presets/src/eth_account.cairo index 97bdbc8b4..b4cdf2080 100644 --- a/src/presets/eth_account.cairo +++ b/packages/presets/src/eth_account.cairo @@ -7,11 +7,11 @@ /// deploy, or call contracts, using Ethereum signing keys. #[starknet::contract(account)] pub(crate) mod EthAccountUpgradeable { - use openzeppelin::account::EthAccountComponent; - use openzeppelin::account::interface::EthPublicKey; - use openzeppelin::introspection::src5::SRC5Component; - use openzeppelin::upgrades::UpgradeableComponent; - use openzeppelin::upgrades::interface::IUpgradeable; + use openzeppelin_account::EthAccountComponent; + use openzeppelin_account::interface::EthPublicKey; + use openzeppelin_introspection::src5::SRC5Component; + use openzeppelin_upgrades::UpgradeableComponent; + use openzeppelin_upgrades::interface::IUpgradeable; use starknet::ClassHash; component!(path: EthAccountComponent, storage: eth_account, event: EthAccountEvent); diff --git a/src/presets/interfaces.cairo b/packages/presets/src/interfaces.cairo similarity index 100% rename from src/presets/interfaces.cairo rename to packages/presets/src/interfaces.cairo diff --git a/src/presets/interfaces/account.cairo b/packages/presets/src/interfaces/account.cairo similarity index 100% rename from src/presets/interfaces/account.cairo rename to packages/presets/src/interfaces/account.cairo diff --git a/src/presets/interfaces/erc1155.cairo b/packages/presets/src/interfaces/erc1155.cairo similarity index 100% rename from src/presets/interfaces/erc1155.cairo rename to packages/presets/src/interfaces/erc1155.cairo diff --git a/src/presets/interfaces/erc20.cairo b/packages/presets/src/interfaces/erc20.cairo similarity index 100% rename from src/presets/interfaces/erc20.cairo rename to packages/presets/src/interfaces/erc20.cairo diff --git a/src/presets/interfaces/erc721.cairo b/packages/presets/src/interfaces/erc721.cairo similarity index 100% rename from src/presets/interfaces/erc721.cairo rename to packages/presets/src/interfaces/erc721.cairo diff --git a/src/presets/interfaces/eth_account.cairo b/packages/presets/src/interfaces/eth_account.cairo similarity index 96% rename from src/presets/interfaces/eth_account.cairo rename to packages/presets/src/interfaces/eth_account.cairo index ab9af2f69..82a5aae18 100644 --- a/src/presets/interfaces/eth_account.cairo +++ b/packages/presets/src/interfaces/eth_account.cairo @@ -1,4 +1,4 @@ -use openzeppelin::account::interface::EthPublicKey; +use openzeppelin_account::interface::EthPublicKey; use starknet::account::Call; use starknet::{ContractAddress, ClassHash}; diff --git a/packages/presets/src/lib.cairo b/packages/presets/src/lib.cairo new file mode 100644 index 000000000..55240efd2 --- /dev/null +++ b/packages/presets/src/lib.cairo @@ -0,0 +1,16 @@ +pub mod account; +pub mod erc1155; +pub mod erc20; +pub mod erc721; +pub mod eth_account; +pub mod interfaces; + +mod tests; +pub mod universal_deployer; + +pub use account::AccountUpgradeable; +pub use erc1155::ERC1155Upgradeable; +pub use erc20::ERC20Upgradeable; +pub use erc721::ERC721Upgradeable; +pub use eth_account::EthAccountUpgradeable; +pub use universal_deployer::UniversalDeployer; diff --git a/src/tests/presets.cairo b/packages/presets/src/tests.cairo similarity index 51% rename from src/tests/presets.cairo rename to packages/presets/src/tests.cairo index 87e7cb2f4..27c970734 100644 --- a/src/tests/presets.cairo +++ b/packages/presets/src/tests.cairo @@ -1,6 +1,13 @@ -mod test_account; +mod mocks; + +// mod test_account; +#[cfg(test)] mod test_erc1155; +#[cfg(test)] mod test_erc20; +#[cfg(test)] mod test_erc721; +#[cfg(test)] mod test_eth_account; +#[cfg(test)] mod test_universal_deployer; diff --git a/src/tests/mocks.cairo b/packages/presets/src/tests/mocks.cairo similarity index 50% rename from src/tests/mocks.cairo rename to packages/presets/src/tests/mocks.cairo index daaf65baf..2037caeeb 100644 --- a/src/tests/mocks.cairo +++ b/packages/presets/src/tests/mocks.cairo @@ -1,18 +1,9 @@ -pub(crate) mod accesscontrol_mocks; pub(crate) mod account_mocks; pub(crate) mod erc1155_mocks; pub(crate) mod erc1155_receiver_mocks; pub(crate) mod erc20_mocks; -pub(crate) mod erc20_votes_mocks; pub(crate) mod erc721_mocks; pub(crate) mod erc721_receiver_mocks; pub(crate) mod eth_account_mocks; -pub(crate) mod initializable_mocks; pub(crate) mod non_implementing_mock; -pub(crate) mod nonces_mocks; -pub(crate) mod ownable_mocks; -pub(crate) mod pausable_mocks; -pub(crate) mod reentrancy_mocks; pub(crate) mod src5_mocks; -pub(crate) mod timelock_mocks; -pub(crate) mod upgrades_mocks; diff --git a/packages/presets/src/tests/mocks/account_mocks.cairo b/packages/presets/src/tests/mocks/account_mocks.cairo new file mode 100644 index 000000000..a6bc34626 --- /dev/null +++ b/packages/presets/src/tests/mocks/account_mocks.cairo @@ -0,0 +1,145 @@ +#[starknet::contract(account)] +pub(crate) mod DualCaseAccountMock { + use openzeppelin_account::AccountComponent; + use openzeppelin_introspection::src5::SRC5Component; + + component!(path: AccountComponent, storage: account, event: AccountEvent); + component!(path: SRC5Component, storage: src5, event: SRC5Event); + + // Account + #[abi(embed_v0)] + impl SRC6Impl = AccountComponent::SRC6Impl; + #[abi(embed_v0)] + impl SRC6CamelOnlyImpl = AccountComponent::SRC6CamelOnlyImpl; + #[abi(embed_v0)] + impl DeclarerImpl = AccountComponent::DeclarerImpl; + #[abi(embed_v0)] + impl DeployableImpl = AccountComponent::DeployableImpl; + impl AccountInternalImpl = AccountComponent::InternalImpl; + + // SCR5 + #[abi(embed_v0)] + impl SRC5Impl = SRC5Component::SRC5Impl; + + #[storage] + struct Storage { + #[substorage(v0)] + account: AccountComponent::Storage, + #[substorage(v0)] + src5: SRC5Component::Storage + } + + #[event] + #[derive(Drop, starknet::Event)] + enum Event { + #[flat] + AccountEvent: AccountComponent::Event, + #[flat] + SRC5Event: SRC5Component::Event + } + + #[constructor] + fn constructor(ref self: ContractState, public_key: felt252) { + self.account.initializer(public_key); + } +} + +#[starknet::contract(account)] +pub(crate) mod SnakeAccountMock { + use openzeppelin_account::AccountComponent; + use openzeppelin_introspection::src5::SRC5Component; + + component!(path: AccountComponent, storage: account, event: AccountEvent); + component!(path: SRC5Component, storage: src5, event: SRC5Event); + + // Account + #[abi(embed_v0)] + impl SRC6Impl = AccountComponent::SRC6Impl; + #[abi(embed_v0)] + impl PublicKeyImpl = AccountComponent::PublicKeyImpl; + impl AccountInternalImpl = AccountComponent::InternalImpl; + + // SCR5 + #[abi(embed_v0)] + impl SRC5Impl = SRC5Component::SRC5Impl; + + #[storage] + struct Storage { + #[substorage(v0)] + account: AccountComponent::Storage, + #[substorage(v0)] + src5: SRC5Component::Storage + } + + #[event] + #[derive(Drop, starknet::Event)] + enum Event { + #[flat] + AccountEvent: AccountComponent::Event, + #[flat] + SRC5Event: SRC5Component::Event + } + + #[constructor] + fn constructor(ref self: ContractState, public_key: felt252) { + self.account.initializer(public_key); + } +} + +#[starknet::contract(account)] +pub(crate) mod CamelAccountMock { + use openzeppelin_account::AccountComponent; + use openzeppelin_introspection::src5::SRC5Component; + use starknet::account::Call; + + component!(path: AccountComponent, storage: account, event: AccountEvent); + component!(path: SRC5Component, storage: src5, event: SRC5Event); + + // Account + #[abi(embed_v0)] + impl SRC6CamelOnlyImpl = AccountComponent::SRC6CamelOnlyImpl; + #[abi(embed_v0)] + impl PublicKeyCamelImpl = AccountComponent::PublicKeyCamelImpl; + impl SRC6Impl = AccountComponent::SRC6Impl; + impl AccountInternalImpl = AccountComponent::InternalImpl; + + // SCR5 + #[abi(embed_v0)] + impl SRC5Impl = SRC5Component::SRC5Impl; + + #[storage] + struct Storage { + #[substorage(v0)] + account: AccountComponent::Storage, + #[substorage(v0)] + src5: SRC5Component::Storage + } + + #[event] + #[derive(Drop, starknet::Event)] + enum Event { + #[flat] + AccountEvent: AccountComponent::Event, + #[flat] + SRC5Event: SRC5Component::Event + } + + #[constructor] + fn constructor(ref self: ContractState, publicKey: felt252) { + self.account.initializer(publicKey); + } + + #[abi(per_item)] + #[generate_trait] + impl ExternalImpl of ExternalTrait { + #[external(v0)] + fn __execute__(self: @ContractState, mut calls: Array) -> Array> { + self.account.__execute__(calls) + } + + #[external(v0)] + fn __validate__(self: @ContractState, mut calls: Array) -> felt252 { + self.account.__validate__(calls) + } + } +} diff --git a/packages/presets/src/tests/mocks/erc1155_mocks.cairo b/packages/presets/src/tests/mocks/erc1155_mocks.cairo new file mode 100644 index 000000000..3ddf1ee72 --- /dev/null +++ b/packages/presets/src/tests/mocks/erc1155_mocks.cairo @@ -0,0 +1,101 @@ +#[starknet::contract] +pub(crate) mod SnakeERC1155Mock { + use openzeppelin_introspection::src5::SRC5Component; + use openzeppelin_token::erc1155::{ERC1155Component, ERC1155HooksEmptyImpl}; + use starknet::ContractAddress; + + component!(path: ERC1155Component, storage: erc1155, event: ERC1155Event); + component!(path: SRC5Component, storage: src5, event: SRC5Event); + + // ERC1155 + #[abi(embed_v0)] + impl ERC1155Impl = ERC1155Component::ERC1155Impl; + #[abi(embed_v0)] + impl ERC1155MetadataURIImpl = + ERC1155Component::ERC1155MetadataURIImpl; + impl ERC1155InternalImpl = ERC1155Component::InternalImpl; + + // SRC5 + #[abi(embed_v0)] + impl SRC5Impl = SRC5Component::SRC5Impl; + + #[storage] + struct Storage { + #[substorage(v0)] + erc1155: ERC1155Component::Storage, + #[substorage(v0)] + src5: SRC5Component::Storage + } + + #[event] + #[derive(Drop, starknet::Event)] + enum Event { + #[flat] + ERC1155Event: ERC1155Component::Event, + #[flat] + SRC5Event: SRC5Component::Event + } + + #[constructor] + fn constructor( + ref self: ContractState, + base_uri: ByteArray, + recipient: ContractAddress, + token_id: u256, + value: u256 + ) { + self.erc1155.initializer(base_uri); + self.erc1155.mint_with_acceptance_check(recipient, token_id, value, array![].span()); + } +} + +#[starknet::contract] +pub(crate) mod CamelERC1155Mock { + use openzeppelin_introspection::src5::SRC5Component; + use openzeppelin_token::erc1155::{ERC1155Component, ERC1155HooksEmptyImpl}; + use starknet::ContractAddress; + + component!(path: ERC1155Component, storage: erc1155, event: ERC1155Event); + component!(path: SRC5Component, storage: src5, event: SRC5Event); + + // ERC1155 + #[abi(embed_v0)] + impl ERC1155Camel = ERC1155Component::ERC1155CamelImpl; + #[abi(embed_v0)] + impl ERC1155MetadataURIImpl = + ERC1155Component::ERC1155MetadataURIImpl; + impl ERC1155InternalImpl = ERC1155Component::InternalImpl; + + // SRC5 + #[abi(embed_v0)] + impl SRC5Impl = SRC5Component::SRC5Impl; + + #[storage] + struct Storage { + #[substorage(v0)] + erc1155: ERC1155Component::Storage, + #[substorage(v0)] + src5: SRC5Component::Storage + } + + #[event] + #[derive(Drop, starknet::Event)] + enum Event { + #[flat] + ERC1155Event: ERC1155Component::Event, + #[flat] + SRC5Event: SRC5Component::Event + } + + #[constructor] + fn constructor( + ref self: ContractState, + base_uri: ByteArray, + recipient: ContractAddress, + token_id: u256, + value: u256 + ) { + self.erc1155.initializer(base_uri); + self.erc1155.mint_with_acceptance_check(recipient, token_id, value, array![].span()); + } +} diff --git a/packages/presets/src/tests/mocks/erc1155_receiver_mocks.cairo b/packages/presets/src/tests/mocks/erc1155_receiver_mocks.cairo new file mode 100644 index 000000000..23bf2ff78 --- /dev/null +++ b/packages/presets/src/tests/mocks/erc1155_receiver_mocks.cairo @@ -0,0 +1,43 @@ +#[starknet::contract] +pub(crate) mod SnakeERC1155ReceiverMock { + use openzeppelin_introspection::src5::SRC5Component; + use openzeppelin_token::erc1155::ERC1155ReceiverComponent; + use starknet::ContractAddress; + + component!(path: SRC5Component, storage: src5, event: SRC5Event); + component!( + path: ERC1155ReceiverComponent, storage: erc1155_receiver, event: ERC1155ReceiverEvent + ); + + // ERC1155Receiver + #[abi(embed_v0)] + impl ERC1155ReceiverImpl = + ERC1155ReceiverComponent::ERC1155ReceiverImpl; + impl ERC1155ReceiverInternalImpl = ERC1155ReceiverComponent::InternalImpl; + + // SRC5 + #[abi(embed_v0)] + impl SRC5Impl = SRC5Component::SRC5Impl; + + #[storage] + struct Storage { + #[substorage(v0)] + erc1155_receiver: ERC1155ReceiverComponent::Storage, + #[substorage(v0)] + src5: SRC5Component::Storage + } + + #[event] + #[derive(Drop, starknet::Event)] + enum Event { + #[flat] + ERC1155ReceiverEvent: ERC1155ReceiverComponent::Event, + #[flat] + SRC5Event: SRC5Component::Event + } + + #[constructor] + fn constructor(ref self: ContractState) { + self.erc1155_receiver.initializer(); + } +} diff --git a/packages/presets/src/tests/mocks/erc20_mocks.cairo b/packages/presets/src/tests/mocks/erc20_mocks.cairo new file mode 100644 index 000000000..856ecc97d --- /dev/null +++ b/packages/presets/src/tests/mocks/erc20_mocks.cairo @@ -0,0 +1,79 @@ +#[starknet::contract] +pub(crate) mod DualCaseERC20Mock { + use openzeppelin_token::erc20::{ERC20Component, ERC20HooksEmptyImpl}; + use starknet::ContractAddress; + + component!(path: ERC20Component, storage: erc20, event: ERC20Event); + + #[abi(embed_v0)] + impl ERC20Impl = ERC20Component::ERC20Impl; + #[abi(embed_v0)] + impl ERC20MetadataImpl = ERC20Component::ERC20MetadataImpl; + #[abi(embed_v0)] + impl ERC20CamelOnlyImpl = ERC20Component::ERC20CamelOnlyImpl; + impl InternalImpl = ERC20Component::InternalImpl; + + #[storage] + struct Storage { + #[substorage(v0)] + erc20: ERC20Component::Storage + } + + #[event] + #[derive(Drop, starknet::Event)] + enum Event { + #[flat] + ERC20Event: ERC20Component::Event + } + + #[constructor] + fn constructor( + ref self: ContractState, + name: ByteArray, + symbol: ByteArray, + initial_supply: u256, + recipient: ContractAddress + ) { + self.erc20.initializer(name, symbol); + self.erc20.mint(recipient, initial_supply); + } +} + +#[starknet::contract] +pub(crate) mod SnakeERC20Mock { + use openzeppelin_token::erc20::{ERC20Component, ERC20HooksEmptyImpl}; + use starknet::ContractAddress; + + component!(path: ERC20Component, storage: erc20, event: ERC20Event); + + #[abi(embed_v0)] + impl ERC20Impl = ERC20Component::ERC20Impl; + #[abi(embed_v0)] + impl ERC20MetadataImpl = ERC20Component::ERC20MetadataImpl; + impl InternalImpl = ERC20Component::InternalImpl; + + #[storage] + struct Storage { + #[substorage(v0)] + erc20: ERC20Component::Storage + } + + #[event] + #[derive(Drop, starknet::Event)] + enum Event { + #[flat] + ERC20Event: ERC20Component::Event + } + + #[constructor] + fn constructor( + ref self: ContractState, + name: ByteArray, + symbol: ByteArray, + initial_supply: u256, + recipient: ContractAddress + ) { + self.erc20.initializer(name, symbol); + self.erc20.mint(recipient, initial_supply); + } +} diff --git a/packages/presets/src/tests/mocks/erc721_mocks.cairo b/packages/presets/src/tests/mocks/erc721_mocks.cairo new file mode 100644 index 000000000..3e84bbe93 --- /dev/null +++ b/packages/presets/src/tests/mocks/erc721_mocks.cairo @@ -0,0 +1,50 @@ +#[starknet::contract] +pub(crate) mod SnakeERC721Mock { + use openzeppelin_introspection::src5::SRC5Component; + use openzeppelin_token::erc721::{ERC721Component, ERC721HooksEmptyImpl}; + use starknet::ContractAddress; + + component!(path: ERC721Component, storage: erc721, event: ERC721Event); + component!(path: SRC5Component, storage: src5, event: SRC5Event); + + // ERC721 + #[abi(embed_v0)] + impl ERC721Impl = ERC721Component::ERC721Impl; + #[abi(embed_v0)] + impl ERC721MetadataImpl = ERC721Component::ERC721MetadataImpl; + impl ERC721InternalImpl = ERC721Component::InternalImpl; + + // SRC5 + #[abi(embed_v0)] + impl SRC5Impl = SRC5Component::SRC5Impl; + + #[storage] + struct Storage { + #[substorage(v0)] + erc721: ERC721Component::Storage, + #[substorage(v0)] + src5: SRC5Component::Storage + } + + #[event] + #[derive(Drop, starknet::Event)] + enum Event { + #[flat] + ERC721Event: ERC721Component::Event, + #[flat] + SRC5Event: SRC5Component::Event + } + + #[constructor] + fn constructor( + ref self: ContractState, + name: ByteArray, + symbol: ByteArray, + base_uri: ByteArray, + recipient: ContractAddress, + token_id: u256 + ) { + self.erc721.initializer(name, symbol, base_uri); + self.erc721.mint(recipient, token_id); + } +} diff --git a/packages/presets/src/tests/mocks/erc721_receiver_mocks.cairo b/packages/presets/src/tests/mocks/erc721_receiver_mocks.cairo new file mode 100644 index 000000000..fbf6e1b45 --- /dev/null +++ b/packages/presets/src/tests/mocks/erc721_receiver_mocks.cairo @@ -0,0 +1,119 @@ +use openzeppelin_utils::test_utils::constants::SUCCESS; + +#[starknet::contract] +pub(crate) mod SnakeERC721ReceiverMock { + use openzeppelin_introspection::src5::SRC5Component; + use openzeppelin_token::erc721::ERC721ReceiverComponent; + use starknet::ContractAddress; + + component!(path: ERC721ReceiverComponent, storage: erc721_receiver, event: ERC721ReceiverEvent); + component!(path: SRC5Component, storage: src5, event: SRC5Event); + + // ERC721Receiver + impl ERC721ReceiverImpl = ERC721ReceiverComponent::ERC721ReceiverImpl; + impl ERC721ReceiverInternalImpl = ERC721ReceiverComponent::InternalImpl; + + // SRC5 + #[abi(embed_v0)] + impl SRC5Impl = SRC5Component::SRC5Impl; + + #[storage] + struct Storage { + #[substorage(v0)] + erc721_receiver: ERC721ReceiverComponent::Storage, + #[substorage(v0)] + src5: SRC5Component::Storage + } + + #[event] + #[derive(Drop, starknet::Event)] + enum Event { + #[flat] + ERC721ReceiverEvent: ERC721ReceiverComponent::Event, + #[flat] + SRC5Event: SRC5Component::Event + } + + #[constructor] + fn constructor(ref self: ContractState) { + self.erc721_receiver.initializer(); + } + + #[abi(per_item)] + #[generate_trait] + impl ExternalImpl of ExternalTrait { + #[external(v0)] + fn on_erc721_received( + self: @ContractState, + operator: ContractAddress, + from: ContractAddress, + token_id: u256, + data: Span + ) -> felt252 { + if *data.at(0) == super::SUCCESS { + self.erc721_receiver.on_erc721_received(operator, from, token_id, data) + } else { + 0 + } + } + } +} + +#[starknet::contract] +pub(crate) mod CamelERC721ReceiverMock { + use openzeppelin_introspection::src5::SRC5Component; + use openzeppelin_token::erc721::ERC721ReceiverComponent; + use starknet::ContractAddress; + + component!(path: ERC721ReceiverComponent, storage: erc721_receiver, event: ERC721ReceiverEvent); + component!(path: SRC5Component, storage: src5, event: SRC5Event); + + // ERC721Receiver + impl ERC721ReceiverCamelImpl = ERC721ReceiverComponent::ERC721ReceiverCamelImpl; + impl ERC721ReceiverInternalImpl = ERC721ReceiverComponent::InternalImpl; + + // SRC5 + #[abi(embed_v0)] + impl SRC5Impl = SRC5Component::SRC5Impl; + + #[storage] + struct Storage { + #[substorage(v0)] + erc721_receiver: ERC721ReceiverComponent::Storage, + #[substorage(v0)] + src5: SRC5Component::Storage + } + + #[event] + #[derive(Drop, starknet::Event)] + enum Event { + #[flat] + ERC721ReceiverEvent: ERC721ReceiverComponent::Event, + #[flat] + SRC5Event: SRC5Component::Event + } + + #[constructor] + fn constructor(ref self: ContractState) { + self.erc721_receiver.initializer(); + } + + #[abi(per_item)] + #[generate_trait] + impl ExternalImpl of ExternalTrait { + #[external(v0)] + fn onERC721Received( + self: @ContractState, + operator: ContractAddress, + from: ContractAddress, + tokenId: u256, + data: Span + ) -> felt252 { + if *data.at(0) == super::SUCCESS { + self.erc721_receiver.onERC721Received(operator, from, tokenId, data) + } else { + 0 + } + } + } +} diff --git a/packages/presets/src/tests/mocks/eth_account_mocks.cairo b/packages/presets/src/tests/mocks/eth_account_mocks.cairo new file mode 100644 index 000000000..2dc299b06 --- /dev/null +++ b/packages/presets/src/tests/mocks/eth_account_mocks.cairo @@ -0,0 +1,39 @@ +#[starknet::contract(account)] +pub(crate) mod SnakeEthAccountMock { + use openzeppelin_account::EthAccountComponent; + use openzeppelin_account::interface::EthPublicKey; + use openzeppelin_introspection::src5::SRC5Component; + + component!(path: EthAccountComponent, storage: eth_account, event: EthAccountEvent); + component!(path: SRC5Component, storage: src5, event: SRC5Event); + + #[abi(embed_v0)] + impl SRC6Impl = EthAccountComponent::SRC6Impl; + #[abi(embed_v0)] + impl PublicKeyImpl = EthAccountComponent::PublicKeyImpl; + #[abi(embed_v0)] + impl SRC5Impl = SRC5Component::SRC5Impl; + impl EthAccountInternalImpl = EthAccountComponent::InternalImpl; + + #[storage] + struct Storage { + #[substorage(v0)] + eth_account: EthAccountComponent::Storage, + #[substorage(v0)] + src5: SRC5Component::Storage + } + + #[event] + #[derive(Drop, starknet::Event)] + enum Event { + #[flat] + EthAccountEvent: EthAccountComponent::Event, + #[flat] + SRC5Event: SRC5Component::Event + } + + #[constructor] + fn constructor(ref self: ContractState, public_key: EthPublicKey) { + self.eth_account.initializer(public_key); + } +} diff --git a/packages/presets/src/tests/mocks/non_implementing_mock.cairo b/packages/presets/src/tests/mocks/non_implementing_mock.cairo new file mode 100644 index 000000000..c1212dbdd --- /dev/null +++ b/packages/presets/src/tests/mocks/non_implementing_mock.cairo @@ -0,0 +1,10 @@ +#[starknet::contract] +pub(crate) mod NonImplementingMock { + #[storage] + struct Storage {} + + #[external(v0)] + fn nope(self: @ContractState) -> bool { + false + } +} diff --git a/packages/presets/src/tests/mocks/src5_mocks.cairo b/packages/presets/src/tests/mocks/src5_mocks.cairo new file mode 100644 index 000000000..86e8c5167 --- /dev/null +++ b/packages/presets/src/tests/mocks/src5_mocks.cairo @@ -0,0 +1,22 @@ +#[starknet::contract] +pub(crate) mod SRC5Mock { + use openzeppelin_introspection::src5::SRC5Component; + + component!(path: SRC5Component, storage: src5, event: SRC5Event); + + #[abi(embed_v0)] + impl SRC5Impl = SRC5Component::SRC5Impl; + + #[storage] + struct Storage { + #[substorage(v0)] + src5: SRC5Component::Storage + } + + #[event] + #[derive(Drop, starknet::Event)] + enum Event { + #[flat] + SRC5Event: SRC5Component::Event + } +} diff --git a/src/tests/presets/test_account.cairo b/packages/presets/src/tests/test_account.cairo similarity index 93% rename from src/tests/presets/test_account.cairo rename to packages/presets/src/tests/test_account.cairo index 3aaf59543..1305c3844 100644 --- a/src/tests/presets/test_account.cairo +++ b/packages/presets/src/tests/test_account.cairo @@ -1,32 +1,27 @@ use core::num::traits::Zero; -use openzeppelin::account::interface::ISRC6_ID; -use openzeppelin::introspection::interface::ISRC5_ID; -use openzeppelin::presets::AccountUpgradeable; -use openzeppelin::presets::interfaces::account::{ - AccountUpgradeableABISafeDispatcher, AccountUpgradeableABISafeDispatcherTrait +use openzeppelin_account::AccountComponent::{OwnerAdded, OwnerRemoved}; +use openzeppelin_account::interface::ISRC6_ID; +use openzeppelin_account::tests::starknet::common::{ + assert_only_event_owner_added, assert_event_owner_removed }; -use openzeppelin::presets::interfaces::{ - AccountUpgradeableABIDispatcher, AccountUpgradeableABIDispatcherTrait -}; -use openzeppelin::tests::account::starknet::common::{ - get_accept_ownership_signature, deploy_erc20, SIGNED_TX_DATA, +use openzeppelin_account::tests::starknet::common::{ + deploy_erc20, SIGNED_TX_DATA, SignedTransactionData }; -use openzeppelin::tests::account::starknet::common::{AccountSpyHelpers, SignedTransactionData}; -use openzeppelin::tests::upgrades::common::UpgradeableSpyHelpers; -use openzeppelin::tests::utils::constants::stark::{KEY_PAIR, KEY_PAIR_2}; -use openzeppelin::tests::utils::constants::{ - SALT, QUERY_OFFSET, QUERY_VERSION, MIN_TRANSACTION_VERSION +use openzeppelin_introspection::interface::ISRC5_ID; +use openzeppelin_presets::AccountUpgradeable; +use openzeppelin_presets::interfaces::{ + AccountUpgradeableABIDispatcher, AccountUpgradeableABIDispatcherTrait }; -use openzeppelin::tests::utils::constants::{ZERO, CALLER, RECIPIENT, OTHER, CLASS_HASH_ZERO}; -use openzeppelin::tests::utils::signing::{StarkKeyPair, StarkKeyPairExt}; -use openzeppelin::tests::utils; -use openzeppelin::token::erc20::interface::IERC20DispatcherTrait; -use openzeppelin::utils::selectors; -use openzeppelin::utils::serde::SerializedAppend; -use snforge_std::{ - cheat_signature_global, cheat_transaction_version_global, cheat_transaction_hash_global +use openzeppelin_presets::tests::mocks::account_mocks::SnakeAccountMock; +use openzeppelin_token::erc20::interface::{IERC20DispatcherTrait, IERC20Dispatcher}; +use openzeppelin_upgrades::tests::common::assert_only_event_upgraded; +use openzeppelin_utils::selectors; +use openzeppelin_utils::serde::SerializedAppend; +use openzeppelin_utils::test_utils::constants::{ + PUBKEY, NEW_PUBKEY, SALT, ZERO, CALLER, RECIPIENT, OTHER, QUERY_OFFSET, QUERY_VERSION, + MIN_TRANSACTION_VERSION, CLASS_HASH_ZERO }; -use snforge_std::{spy_events, test_address, start_cheat_caller_address}; +use openzeppelin_utils::test_utils; use starknet::account::Call; use starknet::{ContractAddress, ClassHash}; diff --git a/src/tests/presets/test_erc1155.cairo b/packages/presets/src/tests/test_erc1155.cairo similarity index 97% rename from src/tests/presets/test_erc1155.cairo rename to packages/presets/src/tests/test_erc1155.cairo index 62ff34fbb..b4f3060a6 100644 --- a/src/tests/presets/test_erc1155.cairo +++ b/packages/presets/src/tests/test_erc1155.cairo @@ -1,27 +1,26 @@ use core::num::traits::Zero; -use openzeppelin::introspection; -use openzeppelin::presets::interfaces::{ +use openzeppelin_access::tests::common::OwnableSpyHelpers; +use openzeppelin_presets::interfaces::{ ERC1155UpgradeableABIDispatcher, ERC1155UpgradeableABIDispatcherTrait }; -use openzeppelin::tests::access::common::OwnableSpyHelpers; -use openzeppelin::tests::token::erc1155::common::ERC1155SpyHelpers; -use openzeppelin::tests::token::erc1155::common::{ +use openzeppelin_token::erc1155::interface::{ + IERC1155CamelSafeDispatcher, IERC1155CamelSafeDispatcherTrait +}; +use openzeppelin_token::erc1155::interface::{IERC1155Dispatcher, IERC1155DispatcherTrait}; +use openzeppelin_token::erc1155; +use openzeppelin_token::tests::erc1155::common::ERC1155SpyHelpers; +use openzeppelin_token::tests::erc1155::common::{ setup_account, setup_receiver, setup_camel_receiver, deploy_another_account_at, setup_src5 }; -use openzeppelin::tests::token::erc1155::common::{get_ids_and_values, get_ids_and_split_values}; -use openzeppelin::tests::upgrades::common::UpgradeableSpyHelpers; -use openzeppelin::tests::utils::constants::{ +use openzeppelin_token::tests::erc1155::common::{get_ids_and_values, get_ids_and_split_values}; +use openzeppelin_upgrades::tests::common::UpgradeableSpyHelpers; +use openzeppelin_utils::serde::SerializedAppend; +use openzeppelin_utils::test_utils as utils; +use openzeppelin_utils::test_utils::constants::{ EMPTY_DATA, ZERO, OWNER, RECIPIENT, CLASS_HASH_ZERO, OPERATOR, OTHER, TOKEN_ID, TOKEN_ID_2, TOKEN_VALUE, TOKEN_VALUE_2 }; -use openzeppelin::tests::utils::events::EventSpyExt; -use openzeppelin::tests::utils; -use openzeppelin::token::erc1155::interface::{ - IERC1155CamelSafeDispatcher, IERC1155CamelSafeDispatcherTrait -}; -use openzeppelin::token::erc1155::interface::{IERC1155Dispatcher, IERC1155DispatcherTrait}; -use openzeppelin::token::erc1155; -use openzeppelin::utils::serde::SerializedAppend; +use openzeppelin_utils::test_utils::events::EventSpyExt; use snforge_std::{spy_events, EventSpy, start_cheat_caller_address}; use starknet::{ContractAddress, ClassHash}; @@ -78,7 +77,8 @@ fn test_constructor() { .supports_interface(erc1155::interface::IERC1155_METADATA_URI_ID); assert!(supports_ierc1155_metadata_uri); - let supports_isrc5 = dispatcher.supports_interface(introspection::interface::ISRC5_ID); + let supports_isrc5 = dispatcher + .supports_interface(openzeppelin_introspection::interface::ISRC5_ID); assert!(supports_isrc5); } diff --git a/src/tests/presets/test_erc20.cairo b/packages/presets/src/tests/test_erc20.cairo similarity index 94% rename from src/tests/presets/test_erc20.cairo rename to packages/presets/src/tests/test_erc20.cairo index 5630256d9..4b95a39c8 100644 --- a/src/tests/presets/test_erc20.cairo +++ b/packages/presets/src/tests/test_erc20.cairo @@ -1,22 +1,22 @@ -use core::integer::BoundedInt; +use core::num::traits::Bounded; use core::num::traits::Zero; -use openzeppelin::presets::interfaces::erc20::{ +use openzeppelin_access::tests::common::OwnableSpyHelpers; +use openzeppelin_presets::interfaces::erc20::{ ERC20UpgradeableABISafeDispatcher, ERC20UpgradeableABISafeDispatcherTrait }; -use openzeppelin::presets::interfaces::{ +use openzeppelin_presets::interfaces::{ ERC20UpgradeableABIDispatcher, ERC20UpgradeableABIDispatcherTrait }; -use openzeppelin::tests::access::common::OwnableSpyHelpers; -use openzeppelin::tests::token::erc20::common::ERC20SpyHelpers; -use openzeppelin::tests::upgrades::common::UpgradeableSpyHelpers; -use openzeppelin::tests::utils::common::IntoBase16String; -use openzeppelin::tests::utils::constants::{ +use openzeppelin_token::erc20::interface::{IERC20Dispatcher, IERC20DispatcherTrait}; +use openzeppelin_token::tests::erc20::common::ERC20SpyHelpers; +use openzeppelin_upgrades::tests::common::UpgradeableSpyHelpers; +use openzeppelin_utils::serde::SerializedAppend; +use openzeppelin_utils::test_utils as utils; +use openzeppelin_utils::test_utils::common::IntoBase16String; +use openzeppelin_utils::test_utils::constants::{ ZERO, OWNER, SPENDER, RECIPIENT, OTHER, NAME, SYMBOL, DECIMALS, SUPPLY, VALUE, CLASS_HASH_ZERO }; -use openzeppelin::tests::utils::events::EventSpyExt; -use openzeppelin::tests::utils; -use openzeppelin::token::erc20::interface::{IERC20Dispatcher, IERC20DispatcherTrait}; -use openzeppelin::utils::serde::SerializedAppend; +use openzeppelin_utils::test_utils::events::EventSpyExt; use snforge_std::{spy_events, EventSpy, start_cheat_caller_address}; use starknet::ClassHash; @@ -206,13 +206,13 @@ fn test_transfer_from_doesnt_consume_infinite_allowance() { let (_, mut dispatcher) = setup_dispatcher(); start_cheat_caller_address(dispatcher.contract_address, OWNER()); - dispatcher.approve(SPENDER(), BoundedInt::max()); + dispatcher.approve(SPENDER(), Bounded::MAX); start_cheat_caller_address(dispatcher.contract_address, SPENDER()); dispatcher.transfer_from(OWNER(), RECIPIENT(), VALUE); let allowance = dispatcher.allowance(OWNER(), SPENDER()); - assert_eq!(allowance, BoundedInt::max(), "Should not decrease"); + assert_eq!(allowance, Bounded::MAX, "Should not decrease"); } #[test] @@ -269,13 +269,13 @@ fn test_transferFrom() { fn test_transferFrom_doesnt_consume_infinite_allowance() { let (_, mut dispatcher) = setup_dispatcher(); start_cheat_caller_address(dispatcher.contract_address, OWNER()); - dispatcher.approve(SPENDER(), BoundedInt::max()); + dispatcher.approve(SPENDER(), Bounded::MAX); start_cheat_caller_address(dispatcher.contract_address, SPENDER()); dispatcher.transferFrom(OWNER(), RECIPIENT(), VALUE); let allowance = dispatcher.allowance(OWNER(), SPENDER()); - assert_eq!(allowance, BoundedInt::max(), "Should not decrease"); + assert_eq!(allowance, Bounded::MAX, "Should not decrease"); } #[test] diff --git a/src/tests/presets/test_erc721.cairo b/packages/presets/src/tests/test_erc721.cairo similarity index 97% rename from src/tests/presets/test_erc721.cairo rename to packages/presets/src/tests/test_erc721.cairo index a84bb7cce..45e067f4e 100644 --- a/src/tests/presets/test_erc721.cairo +++ b/packages/presets/src/tests/test_erc721.cairo @@ -1,27 +1,27 @@ use core::num::traits::Zero; -use openzeppelin::introspection::interface::ISRC5_ID; -use openzeppelin::presets::ERC721Upgradeable::InternalImpl; -use openzeppelin::presets::ERC721Upgradeable; -use openzeppelin::presets::interfaces::{ +use openzeppelin_access::tests::common::OwnableSpyHelpers; +use openzeppelin_introspection::interface::ISRC5_ID; +use openzeppelin_presets::ERC721Upgradeable::InternalImpl; +use openzeppelin_presets::ERC721Upgradeable; +use openzeppelin_presets::interfaces::{ ERC721UpgradeableABIDispatcher, ERC721UpgradeableABIDispatcherTrait }; -use openzeppelin::tests::access::common::OwnableSpyHelpers; -use openzeppelin::tests::token::erc721::common::ERC721SpyHelpers; -use openzeppelin::tests::upgrades::common::UpgradeableSpyHelpers; -use openzeppelin::tests::utils::common::IntoBase16String; -use openzeppelin::tests::utils::constants::{ +use openzeppelin_token::erc721::ERC721Component::ERC721Impl; +use openzeppelin_token::erc721::interface::{ + IERC721CamelOnlySafeDispatcher, IERC721CamelOnlySafeDispatcherTrait +}; +use openzeppelin_token::erc721::interface::{IERC721Dispatcher, IERC721DispatcherTrait}; +use openzeppelin_token::erc721::interface::{IERC721_ID, IERC721_METADATA_ID}; +use openzeppelin_token::tests::erc721::common::ERC721SpyHelpers; +use openzeppelin_upgrades::tests::common::UpgradeableSpyHelpers; +use openzeppelin_utils::serde::SerializedAppend; +use openzeppelin_utils::test_utils as utils; +use openzeppelin_utils::test_utils::common::IntoBase16String; +use openzeppelin_utils::test_utils::constants::{ ZERO, DATA, OWNER, SPENDER, RECIPIENT, OTHER, OPERATOR, CLASS_HASH_ZERO, PUBKEY, NAME, SYMBOL, BASE_URI }; -use openzeppelin::tests::utils::events::EventSpyExt; -use openzeppelin::tests::utils; -use openzeppelin::token::erc721::ERC721Component::ERC721Impl; -use openzeppelin::token::erc721::interface::{ - IERC721CamelOnlySafeDispatcher, IERC721CamelOnlySafeDispatcherTrait -}; -use openzeppelin::token::erc721::interface::{IERC721Dispatcher, IERC721DispatcherTrait}; -use openzeppelin::token::erc721::interface::{IERC721_ID, IERC721_METADATA_ID}; -use openzeppelin::utils::serde::SerializedAppend; +use openzeppelin_utils::test_utils::events::EventSpyExt; use snforge_std::{spy_events, EventSpy, start_cheat_caller_address}; use starknet::{ContractAddress, ClassHash}; diff --git a/src/tests/presets/test_eth_account.cairo b/packages/presets/src/tests/test_eth_account.cairo similarity index 95% rename from src/tests/presets/test_eth_account.cairo rename to packages/presets/src/tests/test_eth_account.cairo index 231e26c5b..a6ea18b77 100644 --- a/src/tests/presets/test_eth_account.cairo +++ b/packages/presets/src/tests/test_eth_account.cairo @@ -1,28 +1,28 @@ use core::num::traits::Zero; -use openzeppelin::account::interface::ISRC6_ID; -use openzeppelin::account::utils::secp256k1::{DebugSecp256k1Point, Secp256k1PointPartialEq}; -use openzeppelin::introspection::interface::ISRC5_ID; -use openzeppelin::presets::EthAccountUpgradeable; -use openzeppelin::presets::interfaces::eth_account::{ +use openzeppelin_account::interface::ISRC6_ID; +use openzeppelin_account::tests::ethereum::common::EthAccountSpyHelpers; +use openzeppelin_account::tests::ethereum::common::{ + deploy_erc20, SIGNED_TX_DATA, SignedTransactionData, get_accept_ownership_signature +}; +use openzeppelin_account::utils::secp256k1::{DebugSecp256k1Point, Secp256k1PointPartialEq}; +use openzeppelin_introspection::interface::ISRC5_ID; +use openzeppelin_presets::EthAccountUpgradeable; +use openzeppelin_presets::interfaces::eth_account::{ EthAccountUpgradeableABISafeDispatcher, EthAccountUpgradeableABISafeDispatcherTrait }; -use openzeppelin::presets::interfaces::{ +use openzeppelin_presets::interfaces::{ EthAccountUpgradeableABIDispatcher, EthAccountUpgradeableABIDispatcherTrait }; -use openzeppelin::tests::account::ethereum::common::EthAccountSpyHelpers; -use openzeppelin::tests::account::ethereum::common::{ - deploy_erc20, SIGNED_TX_DATA, SignedTransactionData, get_accept_ownership_signature -}; -use openzeppelin::tests::upgrades::common::UpgradeableSpyHelpers; -use openzeppelin::tests::utils::constants::secp256k1::KEY_PAIR; -use openzeppelin::tests::utils::constants::{ +use openzeppelin_token::erc20::interface::IERC20DispatcherTrait; +use openzeppelin_upgrades::tests::common::UpgradeableSpyHelpers; +use openzeppelin_utils::selectors; +use openzeppelin_utils::serde::SerializedAppend; +use openzeppelin_utils::test_utils as utils; +use openzeppelin_utils::test_utils::constants::secp256k1::KEY_PAIR; +use openzeppelin_utils::test_utils::constants::{ CLASS_HASH_ZERO, ETH_PUBKEY, NEW_ETH_PUBKEY, SALT, ZERO, RECIPIENT, QUERY_VERSION, MIN_TRANSACTION_VERSION }; -use openzeppelin::tests::utils; -use openzeppelin::token::erc20::interface::IERC20DispatcherTrait; -use openzeppelin::utils::selectors; -use openzeppelin::utils::serde::SerializedAppend; use snforge_std::{ cheat_signature_global, cheat_transaction_version_global, cheat_transaction_hash_global, start_cheat_caller_address diff --git a/src/tests/presets/test_universal_deployer.cairo b/packages/presets/src/tests/test_universal_deployer.cairo similarity index 86% rename from src/tests/presets/test_universal_deployer.cairo rename to packages/presets/src/tests/test_universal_deployer.cairo index e5874bcbc..d33bd8f75 100644 --- a/src/tests/presets/test_universal_deployer.cairo +++ b/packages/presets/src/tests/test_universal_deployer.cairo @@ -1,18 +1,17 @@ -use openzeppelin::presets::universal_deployer::UniversalDeployer::ContractDeployed; -use openzeppelin::presets::universal_deployer::UniversalDeployer; -use openzeppelin::tests::utils::constants::{NAME, SYMBOL, SUPPLY, SALT, CALLER, RECIPIENT}; -use openzeppelin::tests::utils::events::EventSpyExt; -use openzeppelin::tests::utils; -use openzeppelin::token::erc20::interface::{IERC20Dispatcher, IERC20DispatcherTrait}; -use openzeppelin::utils::deployments::{DeployerInfo, calculate_contract_address_from_udc}; -use openzeppelin::utils::interfaces::{ +use openzeppelin_presets::universal_deployer::UniversalDeployer::ContractDeployed; +use openzeppelin_presets::universal_deployer::UniversalDeployer; +use openzeppelin_token::erc20::interface::{IERC20Dispatcher, IERC20DispatcherTrait}; +use openzeppelin_utils::deployments::{DeployerInfo, calculate_contract_address_from_udc}; +use openzeppelin_utils::interfaces::{ IUniversalDeployerDispatcher, IUniversalDeployerDispatcherTrait }; -use openzeppelin::utils::serde::SerializedAppend; +use openzeppelin_utils::serde::SerializedAppend; +use openzeppelin_utils::test_utils as utils; +use openzeppelin_utils::test_utils::constants::{NAME, SYMBOL, SUPPLY, SALT, CALLER, RECIPIENT}; +use openzeppelin_utils::test_utils::events::EventSpyExt; use snforge_std::{EventSpy, spy_events, declare, start_cheat_caller_address}; use starknet::{ClassHash, ContractAddress}; - fn ERC20_CLASS_HASH() -> ClassHash { utils::declare_class("DualCaseERC20Mock").class_hash } diff --git a/src/presets/universal_deployer.cairo b/packages/presets/src/universal_deployer.cairo similarity index 95% rename from src/presets/universal_deployer.cairo rename to packages/presets/src/universal_deployer.cairo index 2777a6107..b12b997e2 100644 --- a/src/presets/universal_deployer.cairo +++ b/packages/presets/src/universal_deployer.cairo @@ -5,10 +5,10 @@ /// /// The Universal Deployer Contract is a standardized generic factory of Starknet contracts. #[starknet::contract] -pub(crate) mod UniversalDeployer { +pub mod UniversalDeployer { use core::hash::{HashStateTrait, HashStateExTrait}; use core::poseidon::PoseidonTrait; - use openzeppelin::utils::interfaces::IUniversalDeployer; + use openzeppelin_utils::interfaces::IUniversalDeployer; use starknet::ClassHash; use starknet::ContractAddress; use starknet::SyscallResultTrait; diff --git a/packages/security/Scarb.toml b/packages/security/Scarb.toml new file mode 100644 index 000000000..fb0a15b07 --- /dev/null +++ b/packages/security/Scarb.toml @@ -0,0 +1,31 @@ + +[package] +name = "openzeppelin_security" +version.workspace = true +edition.workspace = true +cairo-version.workspace = true +scarb-version.workspace = true +authors.workspace = true +description.workspace = true +documentation.workspace = true +readme.workspace = true +repository.workspace = true +license-file.workspace = true +keywords.workspace = true + +[tool] +fmt.workspace = true + +[dependencies] +starknet.workspace = true + +[dev-dependencies] +snforge_std.workspace = true +openzeppelin_utils = { path = "../utils" } + +[lib] + +[[target.starknet-contract]] +allowed-libfuncs-list.name = "experimental" +sierra = true +casm = false diff --git a/src/security/initializable.cairo b/packages/security/src/initializable.cairo similarity index 96% rename from src/security/initializable.cairo rename to packages/security/src/initializable.cairo index 11e7bdabb..5a2152401 100644 --- a/src/security/initializable.cairo +++ b/packages/security/src/initializable.cairo @@ -8,7 +8,7 @@ /// initial state in scenarios where a constructor cannot be used. #[starknet::component] pub mod InitializableComponent { - use openzeppelin::security::interface::IInitializable; + use openzeppelin_security::interface::IInitializable; #[storage] struct Storage { diff --git a/src/security/interface.cairo b/packages/security/src/interface.cairo similarity index 100% rename from src/security/interface.cairo rename to packages/security/src/interface.cairo diff --git a/src/security.cairo b/packages/security/src/lib.cairo similarity index 94% rename from src/security.cairo rename to packages/security/src/lib.cairo index 17ecc6dbe..f8ecbcedc 100644 --- a/src/security.cairo +++ b/packages/security/src/lib.cairo @@ -3,6 +3,8 @@ pub mod interface; pub mod pausable; pub mod reentrancyguard; +mod tests; + pub use initializable::InitializableComponent; pub use pausable::PausableComponent; pub use reentrancyguard::ReentrancyGuardComponent; diff --git a/src/security/pausable.cairo b/packages/security/src/pausable.cairo similarity index 98% rename from src/security/pausable.cairo rename to packages/security/src/pausable.cairo index 0be0d3a43..6b2c3a999 100644 --- a/src/security/pausable.cairo +++ b/packages/security/src/pausable.cairo @@ -8,7 +8,7 @@ /// or `assert_not_paused` will be affected by this mechanism. #[starknet::component] pub mod PausableComponent { - use openzeppelin::security::interface::IPausable; + use openzeppelin_security::interface::IPausable; use starknet::ContractAddress; use starknet::get_caller_address; diff --git a/src/security/reentrancyguard.cairo b/packages/security/src/reentrancyguard.cairo similarity index 100% rename from src/security/reentrancyguard.cairo rename to packages/security/src/reentrancyguard.cairo diff --git a/src/tests/security.cairo b/packages/security/src/tests.cairo similarity index 52% rename from src/tests/security.cairo rename to packages/security/src/tests.cairo index 35c30a0e8..0f674d192 100644 --- a/src/tests/security.cairo +++ b/packages/security/src/tests.cairo @@ -1,3 +1,8 @@ +pub(crate) mod mocks; + +#[cfg(test)] mod test_initializable; +#[cfg(test)] mod test_pausable; +#[cfg(test)] mod test_reentrancyguard; diff --git a/packages/security/src/tests/mocks.cairo b/packages/security/src/tests/mocks.cairo new file mode 100644 index 000000000..81134e172 --- /dev/null +++ b/packages/security/src/tests/mocks.cairo @@ -0,0 +1,3 @@ +pub(crate) mod initializable_mocks; +pub(crate) mod pausable_mocks; +pub(crate) mod reentrancy_mocks; diff --git a/src/tests/mocks/initializable_mocks.cairo b/packages/security/src/tests/mocks/initializable_mocks.cairo similarity index 88% rename from src/tests/mocks/initializable_mocks.cairo rename to packages/security/src/tests/mocks/initializable_mocks.cairo index 442d1e2b2..92841237d 100644 --- a/src/tests/mocks/initializable_mocks.cairo +++ b/packages/security/src/tests/mocks/initializable_mocks.cairo @@ -1,6 +1,6 @@ #[starknet::contract] pub(crate) mod InitializableMock { - use openzeppelin::security::initializable::InitializableComponent; + use openzeppelin_security::initializable::InitializableComponent; component!(path: InitializableComponent, storage: initializable, event: InitializableEvent); diff --git a/src/tests/mocks/pausable_mocks.cairo b/packages/security/src/tests/mocks/pausable_mocks.cairo similarity index 90% rename from src/tests/mocks/pausable_mocks.cairo rename to packages/security/src/tests/mocks/pausable_mocks.cairo index e737508f9..c37584a24 100644 --- a/src/tests/mocks/pausable_mocks.cairo +++ b/packages/security/src/tests/mocks/pausable_mocks.cairo @@ -1,6 +1,6 @@ #[starknet::contract] pub(crate) mod PausableMock { - use openzeppelin::security::pausable::PausableComponent; + use openzeppelin_security::pausable::PausableComponent; component!(path: PausableComponent, storage: pausable, event: PausableEvent); diff --git a/src/tests/mocks/reentrancy_mocks.cairo b/packages/security/src/tests/mocks/reentrancy_mocks.cairo similarity index 97% rename from src/tests/mocks/reentrancy_mocks.cairo rename to packages/security/src/tests/mocks/reentrancy_mocks.cairo index 44d545d9d..e7768e70f 100644 --- a/src/tests/mocks/reentrancy_mocks.cairo +++ b/packages/security/src/tests/mocks/reentrancy_mocks.cairo @@ -17,7 +17,7 @@ pub(crate) trait IReentrancyMock { #[starknet::contract] pub(crate) mod ReentrancyMock { - use openzeppelin::security::reentrancyguard::ReentrancyGuardComponent; + use openzeppelin_security::reentrancyguard::ReentrancyGuardComponent; use starknet::ContractAddress; use starknet::get_contract_address; use super::IAttackerDispatcher; diff --git a/src/tests/security/test_initializable.cairo b/packages/security/src/tests/test_initializable.cairo similarity index 72% rename from src/tests/security/test_initializable.cairo rename to packages/security/src/tests/test_initializable.cairo index 745b34518..bae478f6a 100644 --- a/src/tests/security/test_initializable.cairo +++ b/packages/security/src/tests/test_initializable.cairo @@ -1,6 +1,6 @@ -use openzeppelin::security::InitializableComponent::{InitializableImpl, InternalImpl}; -use openzeppelin::security::InitializableComponent; -use openzeppelin::tests::mocks::initializable_mocks::InitializableMock; +use openzeppelin_security::InitializableComponent::{InitializableImpl, InternalImpl}; +use openzeppelin_security::InitializableComponent; +use openzeppelin_security::tests::mocks::initializable_mocks::InitializableMock; type ComponentState = InitializableComponent::ComponentState; diff --git a/src/tests/security/test_pausable.cairo b/packages/security/src/tests/test_pausable.cairo similarity index 90% rename from src/tests/security/test_pausable.cairo rename to packages/security/src/tests/test_pausable.cairo index ea4ff3878..4189c34d8 100644 --- a/src/tests/security/test_pausable.cairo +++ b/packages/security/src/tests/test_pausable.cairo @@ -1,9 +1,9 @@ -use openzeppelin::security::PausableComponent::{InternalImpl, PausableImpl}; -use openzeppelin::security::PausableComponent::{Paused, Unpaused}; -use openzeppelin::security::PausableComponent; -use openzeppelin::tests::mocks::pausable_mocks::PausableMock; -use openzeppelin::tests::utils::constants::CALLER; -use openzeppelin::tests::utils::events::EventSpyExt; +use openzeppelin_security::PausableComponent::{InternalImpl, PausableImpl}; +use openzeppelin_security::PausableComponent::{Paused, Unpaused}; +use openzeppelin_security::PausableComponent; +use openzeppelin_security::tests::mocks::pausable_mocks::PausableMock; +use openzeppelin_utils::test_utils::constants::CALLER; +use openzeppelin_utils::test_utils::events::EventSpyExt; use snforge_std::EventSpy; use snforge_std::{spy_events, test_address, start_cheat_caller_address}; use starknet::ContractAddress; diff --git a/src/tests/security/test_reentrancyguard.cairo b/packages/security/src/tests/test_reentrancyguard.cairo similarity index 90% rename from src/tests/security/test_reentrancyguard.cairo rename to packages/security/src/tests/test_reentrancyguard.cairo index d6de45ef0..b3c647f5d 100644 --- a/src/tests/security/test_reentrancyguard.cairo +++ b/packages/security/src/tests/test_reentrancyguard.cairo @@ -1,9 +1,9 @@ -use openzeppelin::security::ReentrancyGuardComponent::InternalImpl; -use openzeppelin::security::ReentrancyGuardComponent; -use openzeppelin::tests::mocks::reentrancy_mocks::{ +use openzeppelin_security::ReentrancyGuardComponent::InternalImpl; +use openzeppelin_security::ReentrancyGuardComponent; +use openzeppelin_security::tests::mocks::reentrancy_mocks::{ ReentrancyMock, IReentrancyMockDispatcher, IReentrancyMockDispatcherTrait }; -use openzeppelin::tests::utils; +use openzeppelin_utils::test_utils as utils; type ComponentState = ReentrancyGuardComponent::ComponentState; diff --git a/packages/token/Scarb.toml b/packages/token/Scarb.toml new file mode 100644 index 000000000..93bdc6fd3 --- /dev/null +++ b/packages/token/Scarb.toml @@ -0,0 +1,33 @@ + +[package] +name = "openzeppelin_token" +version.workspace = true +edition.workspace = true +cairo-version.workspace = true +scarb-version.workspace = true +authors.workspace = true +description.workspace = true +documentation.workspace = true +readme.workspace = true +repository.workspace = true +license-file.workspace = true +keywords.workspace = true + +[tool] +fmt.workspace = true + +[dependencies] +starknet.workspace = true +openzeppelin_account = { path = "../account" } +openzeppelin_introspection = { path = "../introspection" } +openzeppelin_governance = { path = "../governance" } + +[dev-dependencies] +snforge_std.workspace = true + +[lib] + +[[target.starknet-contract]] +allowed-libfuncs-list.name = "experimental" +sierra = true +casm = false diff --git a/src/token/erc1155.cairo b/packages/token/src/erc1155.cairo similarity index 100% rename from src/token/erc1155.cairo rename to packages/token/src/erc1155.cairo diff --git a/src/token/erc1155/dual1155.cairo b/packages/token/src/erc1155/dual1155.cairo similarity index 96% rename from src/token/erc1155/dual1155.cairo rename to packages/token/src/erc1155/dual1155.cairo index a6644df67..d771d73b8 100644 --- a/src/token/erc1155/dual1155.cairo +++ b/packages/token/src/erc1155/dual1155.cairo @@ -1,10 +1,10 @@ // SPDX-License-Identifier: MIT // OpenZeppelin Contracts for Cairo v0.15.0-rc.0 (token/erc1155/dual1155.cairo) -use openzeppelin::utils::UnwrapAndCast; -use openzeppelin::utils::selectors; -use openzeppelin::utils::serde::SerializedAppend; -use openzeppelin::utils::try_selector_with_fallback; +use openzeppelin_utils::UnwrapAndCast; +use openzeppelin_utils::selectors; +use openzeppelin_utils::serde::SerializedAppend; +use openzeppelin_utils::try_selector_with_fallback; use starknet::ContractAddress; use starknet::SyscallResultTrait; use starknet::syscalls::call_contract_syscall; diff --git a/src/token/erc1155/dual1155_receiver.cairo b/packages/token/src/erc1155/dual1155_receiver.cairo similarity index 92% rename from src/token/erc1155/dual1155_receiver.cairo rename to packages/token/src/erc1155/dual1155_receiver.cairo index e53df5d3c..90184c079 100644 --- a/src/token/erc1155/dual1155_receiver.cairo +++ b/packages/token/src/erc1155/dual1155_receiver.cairo @@ -1,10 +1,10 @@ // SPDX-License-Identifier: MIT // OpenZeppelin Contracts for Cairo v0.15.0-rc.0 (token/erc1155/dual1155_receiver.cairo) -use openzeppelin::utils::UnwrapAndCast; -use openzeppelin::utils::selectors; -use openzeppelin::utils::serde::SerializedAppend; -use openzeppelin::utils::try_selector_with_fallback; +use openzeppelin_utils::UnwrapAndCast; +use openzeppelin_utils::selectors; +use openzeppelin_utils::serde::SerializedAppend; +use openzeppelin_utils::try_selector_with_fallback; use starknet::ContractAddress; #[derive(Copy, Drop)] diff --git a/src/token/erc1155/erc1155.cairo b/packages/token/src/erc1155/erc1155.cairo similarity index 97% rename from src/token/erc1155/erc1155.cairo rename to packages/token/src/erc1155/erc1155.cairo index f852af2a0..d81e0eda4 100644 --- a/src/token/erc1155/erc1155.cairo +++ b/packages/token/src/erc1155/erc1155.cairo @@ -10,15 +10,15 @@ use starknet::ContractAddress; #[starknet::component] pub mod ERC1155Component { use core::num::traits::Zero; - use openzeppelin::account; - use openzeppelin::introspection::interface::{ISRC5Dispatcher, ISRC5DispatcherTrait}; - use openzeppelin::introspection::src5::SRC5Component::InternalTrait as SRC5InternalTrait; - use openzeppelin::introspection::src5::SRC5Component::SRC5Impl; - use openzeppelin::introspection::src5::SRC5Component; - use openzeppelin::token::erc1155::dual1155_receiver::{ + use openzeppelin_account::interface::ISRC6_ID; + use openzeppelin_introspection::interface::{ISRC5Dispatcher, ISRC5DispatcherTrait}; + use openzeppelin_introspection::src5::SRC5Component::InternalTrait as SRC5InternalTrait; + use openzeppelin_introspection::src5::SRC5Component::SRC5Impl; + use openzeppelin_introspection::src5::SRC5Component; + use openzeppelin_token::erc1155::dual1155_receiver::{ DualCaseERC1155Receiver, DualCaseERC1155ReceiverTrait }; - use openzeppelin::token::erc1155::interface; + use openzeppelin_token::erc1155::interface; use starknet::ContractAddress; use starknet::get_caller_address; use starknet::storage::Map; @@ -140,7 +140,6 @@ pub mod ERC1155Component { self.ERC1155_balances.read((token_id, account)) } - /// Returns a list of balances derived from the `accounts` and `token_ids` pairs. /// /// Requirements: @@ -691,7 +690,7 @@ pub mod ERC1155Component { get_caller_address(), from, token_id, value, data ) == interface::IERC1155_RECEIVER_ID } else { - src5_dispatcher.supports_interface(account::interface::ISRC6_ID) + src5_dispatcher.supports_interface(ISRC6_ID) } } @@ -712,7 +711,7 @@ pub mod ERC1155Component { get_caller_address(), from, token_ids, values, data ) == interface::IERC1155_RECEIVER_ID } else { - src5_dispatcher.supports_interface(account::interface::ISRC6_ID) + src5_dispatcher.supports_interface(ISRC6_ID) } } } diff --git a/src/token/erc1155/erc1155_receiver.cairo b/packages/token/src/erc1155/erc1155_receiver.cairo similarity index 94% rename from src/token/erc1155/erc1155_receiver.cairo rename to packages/token/src/erc1155/erc1155_receiver.cairo index f9ac00b80..24765125f 100644 --- a/src/token/erc1155/erc1155_receiver.cairo +++ b/packages/token/src/erc1155/erc1155_receiver.cairo @@ -8,11 +8,11 @@ /// safe transfers. #[starknet::component] pub mod ERC1155ReceiverComponent { - use openzeppelin::introspection::src5::SRC5Component::InternalTrait as SRC5InternalTrait; - use openzeppelin::introspection::src5::SRC5Component::SRC5Impl; - use openzeppelin::introspection::src5::SRC5Component; - use openzeppelin::token::erc1155::interface::IERC1155_RECEIVER_ID; - use openzeppelin::token::erc1155::interface::{ + use openzeppelin_introspection::src5::SRC5Component::InternalTrait as SRC5InternalTrait; + use openzeppelin_introspection::src5::SRC5Component::SRC5Impl; + use openzeppelin_introspection::src5::SRC5Component; + use openzeppelin_token::erc1155::interface::IERC1155_RECEIVER_ID; + use openzeppelin_token::erc1155::interface::{ IERC1155Receiver, IERC1155ReceiverCamel, ERC1155ReceiverABI }; use starknet::ContractAddress; diff --git a/src/token/erc1155/interface.cairo b/packages/token/src/erc1155/interface.cairo similarity index 100% rename from src/token/erc1155/interface.cairo rename to packages/token/src/erc1155/interface.cairo diff --git a/src/token/erc20.cairo b/packages/token/src/erc20.cairo similarity index 100% rename from src/token/erc20.cairo rename to packages/token/src/erc20.cairo diff --git a/src/token/erc20/dual20.cairo b/packages/token/src/erc20/dual20.cairo similarity index 95% rename from src/token/erc20/dual20.cairo rename to packages/token/src/erc20/dual20.cairo index 9165574d0..d2a42d3ec 100644 --- a/src/token/erc20/dual20.cairo +++ b/packages/token/src/erc20/dual20.cairo @@ -1,10 +1,10 @@ // SPDX-License-Identifier: MIT // OpenZeppelin Contracts for Cairo v0.15.0-rc.0 (token/erc20/dual20.cairo) -use openzeppelin::utils::UnwrapAndCast; -use openzeppelin::utils::selectors; -use openzeppelin::utils::serde::SerializedAppend; -use openzeppelin::utils::try_selector_with_fallback; +use openzeppelin_utils::UnwrapAndCast; +use openzeppelin_utils::selectors; +use openzeppelin_utils::serde::SerializedAppend; +use openzeppelin_utils::try_selector_with_fallback; use starknet::ContractAddress; use starknet::SyscallResultTrait; use starknet::syscalls::call_contract_syscall; diff --git a/src/token/erc20/erc20.cairo b/packages/token/src/erc20/erc20.cairo similarity index 99% rename from src/token/erc20/erc20.cairo rename to packages/token/src/erc20/erc20.cairo index 6d8e0f3cf..005697b61 100644 --- a/src/token/erc20/erc20.cairo +++ b/packages/token/src/erc20/erc20.cairo @@ -14,9 +14,9 @@ use starknet::ContractAddress; /// for examples. #[starknet::component] pub mod ERC20Component { - use core::integer::BoundedInt; + use core::num::traits::Bounded; use core::num::traits::Zero; - use openzeppelin::token::erc20::interface; + use openzeppelin_token::erc20::interface; use starknet::ContractAddress; use starknet::get_caller_address; use starknet::storage::Map; @@ -427,7 +427,7 @@ pub mod ERC20Component { amount: u256 ) { let current_allowance = self.ERC20_allowances.read((owner, spender)); - if current_allowance != BoundedInt::max() { + if current_allowance != Bounded::MAX { assert(current_allowance >= amount, Errors::INSUFFICIENT_ALLOWANCE); self._approve(owner, spender, current_allowance - amount); } diff --git a/src/token/erc20/extensions.cairo b/packages/token/src/erc20/extensions.cairo similarity index 100% rename from src/token/erc20/extensions.cairo rename to packages/token/src/erc20/extensions.cairo diff --git a/src/token/erc20/extensions/erc20_votes.cairo b/packages/token/src/erc20/extensions/erc20_votes.cairo similarity index 95% rename from src/token/erc20/extensions/erc20_votes.cairo rename to packages/token/src/erc20/extensions/erc20_votes.cairo index 0a9d2f50b..4a6ff2a4e 100644 --- a/src/token/erc20/extensions/erc20_votes.cairo +++ b/packages/token/src/erc20/extensions/erc20_votes.cairo @@ -3,7 +3,7 @@ use core::hash::{Hash, HashStateTrait, HashStateExTrait}; use core::poseidon::PoseidonTrait; -use openzeppelin::utils::cryptography::snip12::{OffchainMessageHash, StructHash, SNIP12Metadata}; +use openzeppelin_utils::cryptography::snip12::{OffchainMessageHash, StructHash, SNIP12Metadata}; use starknet::ContractAddress; /// # ERC20Votes Component @@ -17,13 +17,13 @@ use starknet::ContractAddress; #[starknet::component] pub mod ERC20VotesComponent { use core::num::traits::Zero; - use openzeppelin::account::dual_account::{DualCaseAccount, DualCaseAccountABI}; - use openzeppelin::governance::utils::interfaces::IVotes; - use openzeppelin::token::erc20::ERC20Component; - use openzeppelin::token::erc20::interface::IERC20; - use openzeppelin::utils::nonces::NoncesComponent::InternalTrait as NoncesInternalTrait; - use openzeppelin::utils::nonces::NoncesComponent; - use openzeppelin::utils::structs::checkpoint::{Checkpoint, Trace, TraceTrait}; + use openzeppelin_account::dual_account::{DualCaseAccount, DualCaseAccountABI}; + use openzeppelin_governance::utils::interfaces::IVotes; + use openzeppelin_token::erc20::ERC20Component; + use openzeppelin_token::erc20::interface::IERC20; + use openzeppelin_utils::nonces::NoncesComponent::InternalTrait as NoncesInternalTrait; + use openzeppelin_utils::nonces::NoncesComponent; + use openzeppelin_utils::structs::checkpoint::{Checkpoint, Trace, TraceTrait}; use starknet::ContractAddress; use starknet::storage::Map; use super::{Delegation, OffchainMessageHash, SNIP12Metadata}; diff --git a/src/token/erc20/interface.cairo b/packages/token/src/erc20/interface.cairo similarity index 98% rename from src/token/erc20/interface.cairo rename to packages/token/src/erc20/interface.cairo index 74ed4c817..9f10bd9e3 100644 --- a/src/token/erc20/interface.cairo +++ b/packages/token/src/erc20/interface.cairo @@ -1,7 +1,7 @@ // SPDX-License-Identifier: MIT // OpenZeppelin Contracts for Cairo v0.15.0-rc.0 (token/erc20/interface.cairo) -use openzeppelin::utils::structs::checkpoint::Checkpoint; +use openzeppelin_utils::structs::checkpoint::Checkpoint; use starknet::ContractAddress; #[starknet::interface] diff --git a/src/token/erc721.cairo b/packages/token/src/erc721.cairo similarity index 100% rename from src/token/erc721.cairo rename to packages/token/src/erc721.cairo diff --git a/src/token/erc721/dual721.cairo b/packages/token/src/erc721/dual721.cairo similarity index 96% rename from src/token/erc721/dual721.cairo rename to packages/token/src/erc721/dual721.cairo index 7b57c787c..4b83a3d22 100644 --- a/src/token/erc721/dual721.cairo +++ b/packages/token/src/erc721/dual721.cairo @@ -1,10 +1,10 @@ // SPDX-License-Identifier: MIT // OpenZeppelin Contracts for Cairo v0.15.0-rc.0 (token/erc721/dual721.cairo) -use openzeppelin::utils::UnwrapAndCast; -use openzeppelin::utils::selectors; -use openzeppelin::utils::serde::SerializedAppend; -use openzeppelin::utils::try_selector_with_fallback; +use openzeppelin_utils::UnwrapAndCast; +use openzeppelin_utils::selectors; +use openzeppelin_utils::serde::SerializedAppend; +use openzeppelin_utils::try_selector_with_fallback; use starknet::ContractAddress; use starknet::SyscallResultTrait; use starknet::syscalls::call_contract_syscall; diff --git a/src/token/erc721/dual721_receiver.cairo b/packages/token/src/erc721/dual721_receiver.cairo similarity index 86% rename from src/token/erc721/dual721_receiver.cairo rename to packages/token/src/erc721/dual721_receiver.cairo index bc6e74242..dd41f1c58 100644 --- a/src/token/erc721/dual721_receiver.cairo +++ b/packages/token/src/erc721/dual721_receiver.cairo @@ -1,10 +1,10 @@ // SPDX-License-Identifier: MIT // OpenZeppelin Contracts for Cairo v0.15.0-rc.0 (token/erc721/dual721_receiver.cairo) -use openzeppelin::utils::UnwrapAndCast; -use openzeppelin::utils::selectors; -use openzeppelin::utils::serde::SerializedAppend; -use openzeppelin::utils::try_selector_with_fallback; +use openzeppelin_utils::UnwrapAndCast; +use openzeppelin_utils::selectors; +use openzeppelin_utils::serde::SerializedAppend; +use openzeppelin_utils::try_selector_with_fallback; use starknet::ContractAddress; #[derive(Copy, Drop)] diff --git a/src/token/erc721/erc721.cairo b/packages/token/src/erc721/erc721.cairo similarity index 98% rename from src/token/erc721/erc721.cairo rename to packages/token/src/erc721/erc721.cairo index 476ac76ee..6c5e43fca 100644 --- a/src/token/erc721/erc721.cairo +++ b/packages/token/src/erc721/erc721.cairo @@ -10,15 +10,14 @@ use starknet::ContractAddress; #[starknet::component] pub mod ERC721Component { use core::num::traits::Zero; - use openzeppelin::account; - use openzeppelin::introspection::interface::{ISRC5Dispatcher, ISRC5DispatcherTrait}; - use openzeppelin::introspection::src5::SRC5Component::InternalTrait as SRC5InternalTrait; - use openzeppelin::introspection::src5::SRC5Component::SRC5Impl; - use openzeppelin::introspection::src5::SRC5Component; - use openzeppelin::token::erc721::dual721_receiver::{ + use openzeppelin_introspection::interface::{ISRC5Dispatcher, ISRC5DispatcherTrait}; + use openzeppelin_introspection::src5::SRC5Component::InternalTrait as SRC5InternalTrait; + use openzeppelin_introspection::src5::SRC5Component::SRC5Impl; + use openzeppelin_introspection::src5::SRC5Component; + use openzeppelin_token::erc721::dual721_receiver::{ DualCaseERC721Receiver, DualCaseERC721ReceiverTrait }; - use openzeppelin::token::erc721::interface; + use openzeppelin_token::erc721::interface; use starknet::ContractAddress; use starknet::get_caller_address; use starknet::storage::Map; @@ -820,7 +819,7 @@ pub mod ERC721Component { get_caller_address(), from, token_id, data ) == interface::IERC721_RECEIVER_ID } else { - src5_dispatcher.supports_interface(account::interface::ISRC6_ID) + src5_dispatcher.supports_interface(openzeppelin_account::interface::ISRC6_ID) } } } diff --git a/src/token/erc721/erc721_receiver.cairo b/packages/token/src/erc721/erc721_receiver.cairo similarity index 89% rename from src/token/erc721/erc721_receiver.cairo rename to packages/token/src/erc721/erc721_receiver.cairo index 693f4d6fa..0f07753dc 100644 --- a/src/token/erc721/erc721_receiver.cairo +++ b/packages/token/src/erc721/erc721_receiver.cairo @@ -8,12 +8,12 @@ /// safe transfers. #[starknet::component] pub mod ERC721ReceiverComponent { - use openzeppelin::introspection::src5::SRC5Component::InternalTrait as SRC5InternalTrait; - use openzeppelin::introspection::src5::SRC5Component::SRC5Impl; - use openzeppelin::introspection::src5::SRC5Component; - use openzeppelin::token::erc721::interface::IERC721_RECEIVER_ID; - use openzeppelin::token::erc721::interface::{IERC721Receiver, IERC721ReceiverCamel}; - use openzeppelin::token::erc721::interface; + use openzeppelin_introspection::src5::SRC5Component::InternalTrait as SRC5InternalTrait; + use openzeppelin_introspection::src5::SRC5Component::SRC5Impl; + use openzeppelin_introspection::src5::SRC5Component; + use openzeppelin_token::erc721::interface::IERC721_RECEIVER_ID; + use openzeppelin_token::erc721::interface::{IERC721Receiver, IERC721ReceiverCamel}; + use openzeppelin_token::erc721::interface; use starknet::ContractAddress; #[storage] diff --git a/src/token/erc721/interface.cairo b/packages/token/src/erc721/interface.cairo similarity index 100% rename from src/token/erc721/interface.cairo rename to packages/token/src/erc721/interface.cairo diff --git a/src/token.cairo b/packages/token/src/lib.cairo similarity index 75% rename from src/token.cairo rename to packages/token/src/lib.cairo index afe47f7ac..2c0afce45 100644 --- a/src/token.cairo +++ b/packages/token/src/lib.cairo @@ -1,3 +1,5 @@ pub mod erc1155; pub mod erc20; pub mod erc721; + +pub mod tests; diff --git a/packages/token/src/tests.cairo b/packages/token/src/tests.cairo new file mode 100644 index 000000000..047d3ad2f --- /dev/null +++ b/packages/token/src/tests.cairo @@ -0,0 +1,5 @@ +pub mod erc1155; +pub mod erc20; +pub mod erc721; + +pub(crate) mod mocks; diff --git a/src/tests/token/erc1155.cairo b/packages/token/src/tests/erc1155.cairo similarity index 57% rename from src/tests/token/erc1155.cairo rename to packages/token/src/tests/erc1155.cairo index 888f16dc2..1cc8d702b 100644 --- a/src/tests/token/erc1155.cairo +++ b/packages/token/src/tests/erc1155.cairo @@ -1,6 +1,10 @@ -pub(crate) mod common; +pub mod common; +#[cfg(test)] mod test_dual1155; +#[cfg(test)] mod test_dual1155_receiver; +#[cfg(test)] mod test_erc1155; +#[cfg(test)] mod test_erc1155_receiver; diff --git a/src/tests/token/erc1155/common.cairo b/packages/token/src/tests/erc1155/common.cairo similarity index 80% rename from src/tests/token/erc1155/common.cairo rename to packages/token/src/tests/erc1155/common.cairo index 579b5931b..9a74c42bb 100644 --- a/src/tests/token/erc1155/common.cairo +++ b/packages/token/src/tests/erc1155/common.cairo @@ -1,52 +1,50 @@ -use openzeppelin::tests::utils::constants::{ +use openzeppelin_token::erc1155::ERC1155Component::{TransferBatch, ApprovalForAll, TransferSingle}; +use openzeppelin_token::erc1155::ERC1155Component; +use openzeppelin_utils::test_utils as utils; +use openzeppelin_utils::test_utils::constants::{ PUBKEY, TOKEN_ID, TOKEN_ID_2, TOKEN_VALUE, TOKEN_VALUE_2 }; -use openzeppelin::tests::utils::events::EventSpyExt; -use openzeppelin::tests::utils; -use openzeppelin::token::erc1155::ERC1155Component::{TransferBatch, ApprovalForAll, TransferSingle}; -use openzeppelin::token::erc1155::ERC1155Component; +use openzeppelin_utils::test_utils::events::EventSpyExt; use snforge_std::EventSpy; use starknet::ContractAddress; -pub(crate) fn setup_receiver() -> ContractAddress { +pub fn setup_receiver() -> ContractAddress { utils::declare_and_deploy("SnakeERC1155ReceiverMock", array![]) } -pub(crate) fn setup_camel_receiver() -> ContractAddress { +pub fn setup_camel_receiver() -> ContractAddress { utils::declare_and_deploy("CamelERC1155ReceiverMock", array![]) } -pub(crate) fn setup_account() -> ContractAddress { +pub fn setup_account() -> ContractAddress { let calldata = array![PUBKEY]; utils::declare_and_deploy("SnakeAccountMock", calldata) } -pub(crate) fn deploy_another_account_at( - existing: ContractAddress, target_address: ContractAddress -) { +pub fn deploy_another_account_at(existing: ContractAddress, target_address: ContractAddress) { let calldata = array![PUBKEY]; utils::deploy_another_at(existing, target_address, calldata); } -pub(crate) fn setup_src5() -> ContractAddress { +pub fn setup_src5() -> ContractAddress { utils::declare_and_deploy("SRC5Mock", array![]) } -pub(crate) fn get_ids_and_values() -> (Span, Span) { +pub fn get_ids_and_values() -> (Span, Span) { let ids = array![TOKEN_ID, TOKEN_ID_2].span(); let values = array![TOKEN_VALUE, TOKEN_VALUE_2].span(); (ids, values) } -pub(crate) fn get_ids_and_split_values(split: u256) -> (Span, Span) { +pub fn get_ids_and_split_values(split: u256) -> (Span, Span) { let ids = array![TOKEN_ID, TOKEN_ID].span(); let values = array![TOKEN_VALUE - split, split].span(); (ids, values) } #[generate_trait] -pub(crate) impl ERC1155SpyHelpersImpl of ERC1155SpyHelpers { +pub impl ERC1155SpyHelpersImpl of ERC1155SpyHelpers { fn assert_event_approval_for_all( ref self: EventSpy, contract: ContractAddress, diff --git a/src/tests/token/erc1155/test_dual1155.cairo b/packages/token/src/tests/erc1155/test_dual1155.cairo similarity index 96% rename from src/tests/token/erc1155/test_dual1155.cairo rename to packages/token/src/tests/erc1155/test_dual1155.cairo index 3248947b4..971134ce3 100644 --- a/src/tests/token/erc1155/test_dual1155.cairo +++ b/packages/token/src/tests/erc1155/test_dual1155.cairo @@ -1,15 +1,13 @@ use core::num::traits::Zero; -use openzeppelin::tests::utils::constants::{ +use openzeppelin_token::erc1155::dual1155::{DualCaseERC1155, DualCaseERC1155Trait}; +use openzeppelin_token::erc1155::interface::IERC1155_ID; +use openzeppelin_token::erc1155::interface::{IERC1155CamelDispatcher, IERC1155CamelDispatcherTrait}; +use openzeppelin_token::erc1155::interface::{IERC1155Dispatcher, IERC1155DispatcherTrait}; +use openzeppelin_utils::serde::SerializedAppend; +use openzeppelin_utils::test_utils as utils; +use openzeppelin_utils::test_utils::constants::{ EMPTY_DATA, OWNER, RECIPIENT, OPERATOR, TOKEN_ID, TOKEN_ID_2, TOKEN_VALUE }; -use openzeppelin::tests::utils; -use openzeppelin::token::erc1155::dual1155::{DualCaseERC1155, DualCaseERC1155Trait}; -use openzeppelin::token::erc1155::interface::IERC1155_ID; -use openzeppelin::token::erc1155::interface::{ - IERC1155CamelDispatcher, IERC1155CamelDispatcherTrait -}; -use openzeppelin::token::erc1155::interface::{IERC1155Dispatcher, IERC1155DispatcherTrait}; -use openzeppelin::utils::serde::SerializedAppend; use snforge_std::start_cheat_caller_address; use starknet::ContractAddress; diff --git a/src/tests/token/erc1155/test_dual1155_receiver.cairo b/packages/token/src/tests/erc1155/test_dual1155_receiver.cairo similarity index 93% rename from src/tests/token/erc1155/test_dual1155_receiver.cairo rename to packages/token/src/tests/erc1155/test_dual1155_receiver.cairo index f0e7c3a98..3c6e64c85 100644 --- a/src/tests/token/erc1155/test_dual1155_receiver.cairo +++ b/packages/token/src/tests/erc1155/test_dual1155_receiver.cairo @@ -1,15 +1,15 @@ -use openzeppelin::tests::utils::constants::{EMPTY_DATA, OPERATOR, OWNER, TOKEN_ID, TOKEN_VALUE}; -use openzeppelin::tests::utils; -use openzeppelin::token::erc1155::dual1155_receiver::{ +use openzeppelin_token::erc1155::dual1155_receiver::{ DualCaseERC1155Receiver, DualCaseERC1155ReceiverTrait }; -use openzeppelin::token::erc1155::interface::IERC1155_RECEIVER_ID; -use openzeppelin::token::erc1155::interface::{ +use openzeppelin_token::erc1155::interface::IERC1155_RECEIVER_ID; +use openzeppelin_token::erc1155::interface::{ IERC1155ReceiverCamelDispatcher, IERC1155ReceiverCamelDispatcherTrait }; -use openzeppelin::token::erc1155::interface::{ +use openzeppelin_token::erc1155::interface::{ IERC1155ReceiverDispatcher, IERC1155ReceiverDispatcherTrait }; +use openzeppelin_utils::test_utils as utils; +use openzeppelin_utils::test_utils::constants::{EMPTY_DATA, OPERATOR, OWNER, TOKEN_ID, TOKEN_VALUE}; // // Setup diff --git a/src/tests/token/erc1155/test_erc1155.cairo b/packages/token/src/tests/erc1155/test_erc1155.cairo similarity index 98% rename from src/tests/token/erc1155/test_erc1155.cairo rename to packages/token/src/tests/erc1155/test_erc1155.cairo index 110d93b68..6c3db0ebf 100644 --- a/src/tests/token/erc1155/test_erc1155.cairo +++ b/packages/token/src/tests/erc1155/test_erc1155.cairo @@ -1,15 +1,18 @@ use core::num::traits::Zero; -use openzeppelin::introspection::src5::SRC5Component::SRC5Impl; -use openzeppelin::introspection; -use openzeppelin::tests::mocks::erc1155_mocks::DualCaseERC1155Mock; -use openzeppelin::tests::utils::constants::{ +use openzeppelin_introspection::src5::SRC5Component::SRC5Impl; +use openzeppelin_token::erc1155::ERC1155Component::ERC1155CamelImpl; +use openzeppelin_token::erc1155::ERC1155Component::{ + ERC1155Impl, ERC1155MetadataURIImpl, InternalImpl +}; +use openzeppelin_token::erc1155::ERC1155Component::{TransferBatch, ApprovalForAll, TransferSingle}; +use openzeppelin_token::erc1155::ERC1155Component; +use openzeppelin_token::erc1155; +use openzeppelin_token::tests::mocks::erc1155_mocks::DualCaseERC1155Mock; +use openzeppelin_utils::serde::SerializedAppend; +use openzeppelin_utils::test_utils::constants::{ EMPTY_DATA, ZERO, OWNER, RECIPIENT, OPERATOR, OTHER, TOKEN_ID, TOKEN_ID_2, TOKEN_VALUE, TOKEN_VALUE_2 }; -use openzeppelin::token::erc1155::ERC1155Component::ERC1155CamelImpl; -use openzeppelin::token::erc1155::ERC1155Component::{ERC1155Impl, InternalImpl}; -use openzeppelin::token::erc1155::ERC1155Component; -use openzeppelin::token::erc1155; use snforge_std::{spy_events, test_address, start_cheat_caller_address}; use starknet::ContractAddress; @@ -65,7 +68,8 @@ fn test_initialize() { .supports_interface(erc1155::interface::IERC1155_METADATA_URI_ID); assert!(supports_ierc1155_metadata_uri); - let supports_isrc5 = mock_state.supports_interface(introspection::interface::ISRC5_ID); + let supports_isrc5 = mock_state + .supports_interface(openzeppelin_introspection::interface::ISRC5_ID); assert!(supports_isrc5); } diff --git a/src/tests/token/erc1155/test_erc1155_receiver.cairo b/packages/token/src/tests/erc1155/test_erc1155_receiver.cairo similarity index 82% rename from src/tests/token/erc1155/test_erc1155_receiver.cairo rename to packages/token/src/tests/erc1155/test_erc1155_receiver.cairo index 5d3456a52..c7cbb7c47 100644 --- a/src/tests/token/erc1155/test_erc1155_receiver.cairo +++ b/packages/token/src/tests/erc1155/test_erc1155_receiver.cairo @@ -1,11 +1,11 @@ -use openzeppelin::introspection::interface::ISRC5_ID; -use openzeppelin::introspection::src5::SRC5Component::SRC5Impl; -use openzeppelin::tests::mocks::erc1155_receiver_mocks::DualCaseERC1155ReceiverMock; -use openzeppelin::tests::utils::constants::{OWNER, OPERATOR, TOKEN_ID, TOKEN_VALUE, EMPTY_DATA}; -use openzeppelin::token::erc1155::ERC1155ReceiverComponent::{ +use openzeppelin_introspection::interface::ISRC5_ID; +use openzeppelin_introspection::src5::SRC5Component::SRC5Impl; +use openzeppelin_token::erc1155::ERC1155ReceiverComponent::{ ERC1155ReceiverImpl, ERC1155ReceiverCamelImpl, InternalImpl }; -use openzeppelin::token::erc1155::interface::IERC1155_RECEIVER_ID; +use openzeppelin_token::erc1155::interface::IERC1155_RECEIVER_ID; +use openzeppelin_token::tests::mocks::erc1155_receiver_mocks::DualCaseERC1155ReceiverMock; +use openzeppelin_utils::test_utils::constants::{OWNER, OPERATOR, TOKEN_ID, TOKEN_VALUE, EMPTY_DATA}; fn STATE() -> DualCaseERC1155ReceiverMock::ContractState { DualCaseERC1155ReceiverMock::contract_state_for_testing() diff --git a/src/tests/token/erc20.cairo b/packages/token/src/tests/erc20.cairo similarity index 50% rename from src/tests/token/erc20.cairo rename to packages/token/src/tests/erc20.cairo index 8d094274f..69da33c96 100644 --- a/src/tests/token/erc20.cairo +++ b/packages/token/src/tests/erc20.cairo @@ -1,5 +1,8 @@ -pub(crate) mod common; +pub mod common; +#[cfg(test)] mod test_dual20; +#[cfg(test)] mod test_erc20; +#[cfg(test)] mod test_erc20_votes; diff --git a/src/tests/token/erc20/common.cairo b/packages/token/src/tests/erc20/common.cairo similarity index 85% rename from src/tests/token/erc20/common.cairo rename to packages/token/src/tests/erc20/common.cairo index a50e5ff2e..f3a0d58bf 100644 --- a/src/tests/token/erc20/common.cairo +++ b/packages/token/src/tests/erc20/common.cairo @@ -1,11 +1,11 @@ -use openzeppelin::tests::utils::events::EventSpyExt; -use openzeppelin::token::erc20::ERC20Component::{Approval, Transfer}; -use openzeppelin::token::erc20::ERC20Component; +use openzeppelin_token::erc20::ERC20Component::{Approval, Transfer}; +use openzeppelin_token::erc20::ERC20Component; +use openzeppelin_utils::test_utils::events::EventSpyExt; use snforge_std::EventSpy; use starknet::ContractAddress; #[generate_trait] -pub(crate) impl ERC20SpyHelpersImpl of ERC20SpyHelpers { +pub impl ERC20SpyHelpersImpl of ERC20SpyHelpers { fn assert_event_approval( ref self: EventSpy, contract: ContractAddress, diff --git a/src/tests/token/erc20/test_dual20.cairo b/packages/token/src/tests/erc20/test_dual20.cairo similarity index 95% rename from src/tests/token/erc20/test_dual20.cairo rename to packages/token/src/tests/erc20/test_dual20.cairo index 8a24c3a9a..8edc96a23 100644 --- a/src/tests/token/erc20/test_dual20.cairo +++ b/packages/token/src/tests/erc20/test_dual20.cairo @@ -1,11 +1,11 @@ -use openzeppelin::tests::utils::constants::{ +use openzeppelin_token::erc20::dual20::{DualCaseERC20, DualCaseERC20Trait}; +use openzeppelin_token::erc20::interface::{IERC20CamelDispatcher, IERC20CamelDispatcherTrait}; +use openzeppelin_token::erc20::interface::{IERC20Dispatcher, IERC20DispatcherTrait}; +use openzeppelin_utils::serde::SerializedAppend; +use openzeppelin_utils::test_utils as utils; +use openzeppelin_utils::test_utils::constants::{ OWNER, RECIPIENT, SPENDER, OPERATOR, NAME, SYMBOL, DECIMALS, SUPPLY, VALUE }; -use openzeppelin::tests::utils; -use openzeppelin::token::erc20::dual20::{DualCaseERC20, DualCaseERC20Trait}; -use openzeppelin::token::erc20::interface::{IERC20CamelDispatcher, IERC20CamelDispatcherTrait}; -use openzeppelin::token::erc20::interface::{IERC20Dispatcher, IERC20DispatcherTrait}; -use openzeppelin::utils::serde::SerializedAppend; use snforge_std::{test_address, start_cheat_caller_address}; // diff --git a/src/tests/token/erc20/test_erc20.cairo b/packages/token/src/tests/erc20/test_erc20.cairo similarity index 93% rename from src/tests/token/erc20/test_erc20.cairo rename to packages/token/src/tests/erc20/test_erc20.cairo index c3315e8b7..4e1fb023d 100644 --- a/src/tests/token/erc20/test_erc20.cairo +++ b/packages/token/src/tests/erc20/test_erc20.cairo @@ -1,12 +1,13 @@ -use core::integer::BoundedInt; -use openzeppelin::tests::mocks::erc20_mocks::DualCaseERC20Mock; -use openzeppelin::tests::utils::constants::{ +use core::num::traits::Bounded; +use openzeppelin_token::erc20::ERC20Component::{Approval, Transfer}; +use openzeppelin_token::erc20::ERC20Component::{ERC20CamelOnlyImpl, ERC20Impl}; +use openzeppelin_token::erc20::ERC20Component::{ERC20MetadataImpl, InternalImpl}; +use openzeppelin_token::erc20::ERC20Component; +use openzeppelin_token::tests::mocks::erc20_mocks::DualCaseERC20Mock; +use openzeppelin_utils::serde::SerializedAppend; +use openzeppelin_utils::test_utils::constants::{ ZERO, OWNER, SPENDER, RECIPIENT, NAME, SYMBOL, DECIMALS, SUPPLY, VALUE }; -use openzeppelin::tests::utils; -use openzeppelin::token::erc20::ERC20Component::{ERC20CamelOnlyImpl, ERC20Impl}; -use openzeppelin::token::erc20::ERC20Component::{ERC20MetadataImpl, InternalImpl}; -use openzeppelin::token::erc20::ERC20Component; use snforge_std::{spy_events, test_address, start_cheat_caller_address}; use starknet::ContractAddress; @@ -263,13 +264,13 @@ fn test_transfer_from() { fn test_transfer_from_doesnt_consume_infinite_allowance() { let mut state = setup(); start_cheat_caller_address(test_address(), OWNER()); - state.approve(SPENDER(), BoundedInt::max()); + state.approve(SPENDER(), Bounded::MAX); start_cheat_caller_address(test_address(), SPENDER()); state.transfer_from(OWNER(), RECIPIENT(), VALUE); let allowance = state.allowance(OWNER(), SPENDER()); - assert_eq!(allowance, BoundedInt::max()); + assert_eq!(allowance, Bounded::MAX); } #[test] @@ -330,13 +331,13 @@ fn test_transferFrom() { fn test_transferFrom_doesnt_consume_infinite_allowance() { let mut state = setup(); start_cheat_caller_address(test_address(), OWNER()); - state.approve(SPENDER(), BoundedInt::max()); + state.approve(SPENDER(), Bounded::MAX); start_cheat_caller_address(test_address(), SPENDER()); state.transferFrom(OWNER(), RECIPIENT(), VALUE); let allowance = state.allowance(OWNER(), SPENDER()); - assert_eq!(allowance, BoundedInt::max()); + assert_eq!(allowance, Bounded::MAX); } #[test] @@ -392,13 +393,13 @@ fn test__spend_allowance_not_unlimited() { #[test] fn test__spend_allowance_unlimited() { let mut state = setup(); - state._approve(OWNER(), SPENDER(), BoundedInt::max()); + state._approve(OWNER(), SPENDER(), Bounded::MAX); - let max_minus_one: u256 = BoundedInt::max() - 1; + let max_minus_one: u256 = Bounded::MAX - 1; state._spend_allowance(OWNER(), SPENDER(), max_minus_one); let allowance = state.allowance(OWNER(), SPENDER()); - assert_eq!(allowance, BoundedInt::max()); + assert_eq!(allowance, Bounded::MAX); } // diff --git a/src/tests/token/erc20/test_erc20_votes.cairo b/packages/token/src/tests/erc20/test_erc20_votes.cairo similarity index 89% rename from src/tests/token/erc20/test_erc20_votes.cairo rename to packages/token/src/tests/erc20/test_erc20_votes.cairo index 21f0d8ba2..3a60cb2d7 100644 --- a/src/tests/token/erc20/test_erc20_votes.cairo +++ b/packages/token/src/tests/erc20/test_erc20_votes.cairo @@ -1,20 +1,20 @@ -use core::integer::BoundedInt; +use core::num::traits::Bounded; use core::num::traits::Zero; -use openzeppelin::tests::mocks::erc20_votes_mocks::DualCaseERC20VotesMock::SNIP12MetadataImpl; -use openzeppelin::tests::mocks::erc20_votes_mocks::DualCaseERC20VotesMock; -use openzeppelin::tests::utils::constants::{SUPPLY, ZERO, OWNER, RECIPIENT}; -use openzeppelin::tests::utils::events::EventSpyExt; -use openzeppelin::tests::utils; -use openzeppelin::token::erc20::ERC20Component::InternalImpl as ERC20Impl; -use openzeppelin::token::erc20::extensions::ERC20VotesComponent::{ +use openzeppelin_token::erc20::ERC20Component::InternalImpl as ERC20Impl; +use openzeppelin_token::erc20::extensions::ERC20VotesComponent::{ DelegateChanged, DelegateVotesChanged }; -use openzeppelin::token::erc20::extensions::ERC20VotesComponent::{ERC20VotesImpl, InternalImpl}; -use openzeppelin::token::erc20::extensions::ERC20VotesComponent; -use openzeppelin::token::erc20::extensions::erc20_votes::Delegation; -use openzeppelin::utils::cryptography::snip12::OffchainMessageHash; -use openzeppelin::utils::serde::SerializedAppend; -use openzeppelin::utils::structs::checkpoint::{Checkpoint, TraceTrait}; +use openzeppelin_token::erc20::extensions::ERC20VotesComponent::{ERC20VotesImpl, InternalImpl}; +use openzeppelin_token::erc20::extensions::ERC20VotesComponent; +use openzeppelin_token::erc20::extensions::erc20_votes::Delegation; +use openzeppelin_token::tests::mocks::erc20_votes_mocks::DualCaseERC20VotesMock::SNIP12MetadataImpl; +use openzeppelin_token::tests::mocks::erc20_votes_mocks::DualCaseERC20VotesMock; +use openzeppelin_utils::cryptography::snip12::OffchainMessageHash; +use openzeppelin_utils::serde::SerializedAppend; +use openzeppelin_utils::structs::checkpoint::{Checkpoint, TraceTrait}; +use openzeppelin_utils::test_utils as utils; +use openzeppelin_utils::test_utils::constants::{SUPPLY, ZERO, OWNER, RECIPIENT}; +use openzeppelin_utils::test_utils::events::EventSpyExt; use snforge_std::signature::KeyPairTrait; use snforge_std::signature::stark_curve::{StarkCurveKeyPairImpl, StarkCurveSignerImpl}; use snforge_std::{ @@ -101,9 +101,9 @@ fn test_get_past_votes() { trace.push('ts3', 0x333); // Big numbers (high different from 0x0) - let big1: u256 = BoundedInt::::max().into() + 0x444; - let big2: u256 = BoundedInt::::max().into() + 0x666; - let big3: u256 = BoundedInt::::max().into() + 0x888; + let big1: u256 = Bounded::::MAX.into() + 0x444; + let big2: u256 = Bounded::::MAX.into() + 0x666; + let big3: u256 = Bounded::::MAX.into() + 0x888; trace.push('ts4', big1); trace.push('ts6', big2); trace.push('ts8', big3); @@ -135,9 +135,9 @@ fn test_get_past_total_supply() { trace.push('ts3', 0x333); // Big numbers (high different from 0x0) - let big1: u256 = BoundedInt::::max().into() + 0x444; - let big2: u256 = BoundedInt::::max().into() + 0x666; - let big3: u256 = BoundedInt::::max().into() + 0x888; + let big1: u256 = Bounded::::MAX.into() + 0x444; + let big2: u256 = Bounded::::MAX.into() + 0x666; + let big3: u256 = Bounded::::MAX.into() + 0x888; trace.push('ts4', big1); trace.push('ts6', big2); trace.push('ts8', big3); diff --git a/src/tests/token/erc721.cairo b/packages/token/src/tests/erc721.cairo similarity index 56% rename from src/tests/token/erc721.cairo rename to packages/token/src/tests/erc721.cairo index d8b44e48b..27cc79035 100644 --- a/src/tests/token/erc721.cairo +++ b/packages/token/src/tests/erc721.cairo @@ -1,6 +1,10 @@ -pub(crate) mod common; +pub mod common; +#[cfg(test)] mod test_dual721; +#[cfg(test)] mod test_dual721_receiver; +#[cfg(test)] mod test_erc721; +#[cfg(test)] mod test_erc721_receiver; diff --git a/src/tests/token/erc721/common.cairo b/packages/token/src/tests/erc721/common.cairo similarity index 89% rename from src/tests/token/erc721/common.cairo rename to packages/token/src/tests/erc721/common.cairo index 97e94f886..f35fe41fb 100644 --- a/src/tests/token/erc721/common.cairo +++ b/packages/token/src/tests/erc721/common.cairo @@ -1,11 +1,11 @@ -use openzeppelin::tests::utils::events::EventSpyExt; -use openzeppelin::token::erc721::ERC721Component::{Approval, ApprovalForAll, Transfer}; -use openzeppelin::token::erc721::ERC721Component; +use openzeppelin_token::erc721::ERC721Component::{Approval, ApprovalForAll, Transfer}; +use openzeppelin_token::erc721::ERC721Component; +use openzeppelin_utils::test_utils::events::EventSpyExt; use snforge_std::EventSpy; use starknet::ContractAddress; #[generate_trait] -pub(crate) impl ERC721SpyHelpersImpl of ERC721SpyHelpers { +pub impl ERC721SpyHelpersImpl of ERC721SpyHelpers { fn assert_event_approval_for_all( ref self: EventSpy, contract: ContractAddress, diff --git a/src/tests/token/erc721/test_dual721.cairo b/packages/token/src/tests/erc721/test_dual721.cairo similarity index 97% rename from src/tests/token/erc721/test_dual721.cairo rename to packages/token/src/tests/erc721/test_dual721.cairo index b4b13cbb6..04dd336a8 100644 --- a/src/tests/token/erc721/test_dual721.cairo +++ b/packages/token/src/tests/erc721/test_dual721.cairo @@ -1,14 +1,14 @@ -use openzeppelin::tests::utils::constants::{ - DATA, OWNER, RECIPIENT, SPENDER, OPERATOR, NAME, SYMBOL, BASE_URI, TOKEN_ID -}; -use openzeppelin::tests::utils; -use openzeppelin::token::erc721::dual721::{DualCaseERC721, DualCaseERC721Trait}; -use openzeppelin::token::erc721::interface::IERC721_ID; -use openzeppelin::token::erc721::interface::{ +use openzeppelin_token::erc721::dual721::{DualCaseERC721, DualCaseERC721Trait}; +use openzeppelin_token::erc721::interface::IERC721_ID; +use openzeppelin_token::erc721::interface::{ IERC721CamelOnlyDispatcher, IERC721CamelOnlyDispatcherTrait }; -use openzeppelin::token::erc721::interface::{IERC721Dispatcher, IERC721DispatcherTrait}; -use openzeppelin::utils::serde::SerializedAppend; +use openzeppelin_token::erc721::interface::{IERC721Dispatcher, IERC721DispatcherTrait}; +use openzeppelin_utils::serde::SerializedAppend; +use openzeppelin_utils::test_utils as utils; +use openzeppelin_utils::test_utils::constants::{ + DATA, OWNER, RECIPIENT, SPENDER, OPERATOR, NAME, SYMBOL, BASE_URI, TOKEN_ID +}; use snforge_std::{test_address, start_cheat_caller_address}; use starknet::ContractAddress; diff --git a/src/tests/token/erc721/test_dual721_receiver.cairo b/packages/token/src/tests/erc721/test_dual721_receiver.cairo similarity index 82% rename from src/tests/token/erc721/test_dual721_receiver.cairo rename to packages/token/src/tests/erc721/test_dual721_receiver.cairo index 1a5ae99e4..a4be9f3a1 100644 --- a/src/tests/token/erc721/test_dual721_receiver.cairo +++ b/packages/token/src/tests/erc721/test_dual721_receiver.cairo @@ -1,15 +1,22 @@ -use openzeppelin::tests::utils::constants::{DATA, OPERATOR, OWNER, TOKEN_ID}; -use openzeppelin::tests::utils; -use openzeppelin::token::erc721::dual721_receiver::{ +use openzeppelin_token::erc721::dual721_receiver::{ DualCaseERC721Receiver, DualCaseERC721ReceiverTrait }; -use openzeppelin::token::erc721::interface::IERC721_RECEIVER_ID; -use openzeppelin::token::erc721::interface::{ +use openzeppelin_token::erc721::interface::IERC721_RECEIVER_ID; +use openzeppelin_token::erc721::interface::{ IERC721ReceiverCamelDispatcher, IERC721ReceiverCamelDispatcherTrait }; -use openzeppelin::token::erc721::interface::{ +use openzeppelin_token::erc721::interface::{ IERC721ReceiverDispatcher, IERC721ReceiverDispatcherTrait }; +use openzeppelin_token::tests::mocks::erc721_receiver_mocks::{ + CamelERC721ReceiverMock, CamelERC721ReceiverPanicMock +}; +use openzeppelin_token::tests::mocks::erc721_receiver_mocks::{ + SnakeERC721ReceiverMock, SnakeERC721ReceiverPanicMock +}; +use openzeppelin_token::tests::mocks::non_implementing_mock::NonImplementingMock; +use openzeppelin_utils::test_utils as utils; +use openzeppelin_utils::test_utils::constants::{DATA, OPERATOR, OWNER, TOKEN_ID}; // // Setup diff --git a/src/tests/token/erc721/test_erc721.cairo b/packages/token/src/tests/erc721/test_erc721.cairo similarity index 98% rename from src/tests/token/erc721/test_erc721.cairo rename to packages/token/src/tests/erc721/test_erc721.cairo index b7fb9c996..4ce77d621 100644 --- a/src/tests/token/erc721/test_erc721.cairo +++ b/packages/token/src/tests/erc721/test_erc721.cairo @@ -1,17 +1,16 @@ use core::num::traits::Zero; -use openzeppelin::introspection::src5::SRC5Component::SRC5Impl; -use openzeppelin::introspection; -use openzeppelin::tests::mocks::erc721_mocks::DualCaseERC721Mock; -use openzeppelin::tests::utils::constants::{ +use openzeppelin_introspection::src5::SRC5Component::SRC5Impl; +use openzeppelin_token::erc721::ERC721Component::{ERC721Impl, ERC721CamelOnlyImpl}; +use openzeppelin_token::erc721::ERC721Component::{ERC721MetadataImpl, InternalImpl}; +use openzeppelin_token::erc721::ERC721Component; +use openzeppelin_token::erc721; +use openzeppelin_token::tests::mocks::erc721_mocks::DualCaseERC721Mock; +use openzeppelin_utils::test_utils as utils; +use openzeppelin_utils::test_utils::constants::{ DATA, ZERO, OWNER, CALLER, RECIPIENT, SPENDER, OPERATOR, OTHER, NAME, SYMBOL, TOKEN_ID, TOKEN_ID_2, PUBKEY, BASE_URI, BASE_URI_2 }; -use openzeppelin::tests::utils::events::EventSpyExt; -use openzeppelin::tests::utils; -use openzeppelin::token::erc721::ERC721Component::{ERC721Impl, ERC721CamelOnlyImpl}; -use openzeppelin::token::erc721::ERC721Component::{ERC721MetadataImpl, InternalImpl}; -use openzeppelin::token::erc721::ERC721Component; -use openzeppelin::token::erc721; +use openzeppelin_utils::test_utils::events::EventSpyExt; use snforge_std::{spy_events, test_address, start_cheat_caller_address}; use starknet::ContractAddress; @@ -78,7 +77,8 @@ fn test_initializer() { .supports_interface(erc721::interface::IERC721_METADATA_ID); assert!(supports_ierc721_metadata); - let supports_isrc5 = mock_state.supports_interface(introspection::interface::ISRC5_ID); + let supports_isrc5 = mock_state + .supports_interface(openzeppelin_introspection::interface::ISRC5_ID); assert!(supports_isrc5); } @@ -845,10 +845,6 @@ fn test_safeTransferFrom_to_owner() { state.initializer(NAME(), SYMBOL(), BASE_URI()); state.mint(owner, token_id); - - assert_eq!(state.owner_of(token_id), owner); - assert_eq!(state.balance_of(owner), 1); - let mut spy = spy_events(); start_cheat_caller_address(contract_address, owner); @@ -982,15 +978,12 @@ fn test_safeTransferFrom_approved_camel() { let receiver = setup_camel_receiver(); let token_id = TOKEN_ID; let owner = OWNER(); + let mut spy = spy_events(); assert_state_before_transfer(owner, receiver, token_id); start_cheat_caller_address(contract_address, owner); state.approve(OPERATOR(), token_id); - - let mut spy = spy_events(); - - start_cheat_caller_address(contract_address, OPERATOR()); state.safeTransferFrom(owner, receiver, token_id, DATA(true)); spy.assert_only_event_transfer(contract_address, owner, receiver, token_id); @@ -1071,15 +1064,12 @@ fn test_safeTransferFrom_approved_for_all_camel() { let receiver = setup_camel_receiver(); let token_id = TOKEN_ID; let owner = OWNER(); + let mut spy = spy_events(); assert_state_before_transfer(owner, receiver, token_id); start_cheat_caller_address(contract_address, owner); state.set_approval_for_all(OPERATOR(), true); - - let mut spy = spy_events(); - - start_cheat_caller_address(contract_address, OPERATOR()); state.safeTransferFrom(owner, receiver, token_id, DATA(true)); spy.assert_only_event_transfer(contract_address, owner, receiver, token_id); diff --git a/src/tests/token/erc721/test_erc721_receiver.cairo b/packages/token/src/tests/erc721/test_erc721_receiver.cairo similarity index 72% rename from src/tests/token/erc721/test_erc721_receiver.cairo rename to packages/token/src/tests/erc721/test_erc721_receiver.cairo index a84e1c434..90fb42f3a 100644 --- a/src/tests/token/erc721/test_erc721_receiver.cairo +++ b/packages/token/src/tests/erc721/test_erc721_receiver.cairo @@ -1,11 +1,11 @@ -use openzeppelin::introspection::interface::ISRC5_ID; -use openzeppelin::introspection::src5::SRC5Component::SRC5Impl; -use openzeppelin::tests::mocks::erc721_receiver_mocks::DualCaseERC721ReceiverMock; -use openzeppelin::tests::utils::constants::{OWNER, OPERATOR, TOKEN_ID}; -use openzeppelin::token::erc721::ERC721ReceiverComponent::{ +use openzeppelin_introspection::interface::ISRC5_ID; +use openzeppelin_introspection::src5::SRC5Component::SRC5Impl; +use openzeppelin_token::erc721::ERC721ReceiverComponent::{ ERC721ReceiverImpl, ERC721ReceiverCamelImpl, InternalImpl }; -use openzeppelin::token::erc721::interface::IERC721_RECEIVER_ID; +use openzeppelin_token::erc721::interface::IERC721_RECEIVER_ID; +use openzeppelin_token::tests::mocks::erc721_receiver_mocks::DualCaseERC721ReceiverMock; +use openzeppelin_utils::test_utils::constants::{OWNER, OPERATOR, TOKEN_ID}; fn STATE() -> DualCaseERC721ReceiverMock::ContractState { DualCaseERC721ReceiverMock::contract_state_for_testing() diff --git a/packages/token/src/tests/mocks.cairo b/packages/token/src/tests/mocks.cairo new file mode 100644 index 000000000..db8bcba0d --- /dev/null +++ b/packages/token/src/tests/mocks.cairo @@ -0,0 +1,9 @@ +pub(crate) mod account_mocks; +pub(crate) mod erc1155_mocks; +pub(crate) mod erc1155_receiver_mocks; +pub(crate) mod erc20_mocks; +pub(crate) mod erc20_votes_mocks; +pub(crate) mod erc721_mocks; +pub(crate) mod erc721_receiver_mocks; +pub(crate) mod non_implementing_mock; +pub(crate) mod src5_mocks; diff --git a/packages/token/src/tests/mocks/account_mocks.cairo b/packages/token/src/tests/mocks/account_mocks.cairo new file mode 100644 index 000000000..a6bc34626 --- /dev/null +++ b/packages/token/src/tests/mocks/account_mocks.cairo @@ -0,0 +1,145 @@ +#[starknet::contract(account)] +pub(crate) mod DualCaseAccountMock { + use openzeppelin_account::AccountComponent; + use openzeppelin_introspection::src5::SRC5Component; + + component!(path: AccountComponent, storage: account, event: AccountEvent); + component!(path: SRC5Component, storage: src5, event: SRC5Event); + + // Account + #[abi(embed_v0)] + impl SRC6Impl = AccountComponent::SRC6Impl; + #[abi(embed_v0)] + impl SRC6CamelOnlyImpl = AccountComponent::SRC6CamelOnlyImpl; + #[abi(embed_v0)] + impl DeclarerImpl = AccountComponent::DeclarerImpl; + #[abi(embed_v0)] + impl DeployableImpl = AccountComponent::DeployableImpl; + impl AccountInternalImpl = AccountComponent::InternalImpl; + + // SCR5 + #[abi(embed_v0)] + impl SRC5Impl = SRC5Component::SRC5Impl; + + #[storage] + struct Storage { + #[substorage(v0)] + account: AccountComponent::Storage, + #[substorage(v0)] + src5: SRC5Component::Storage + } + + #[event] + #[derive(Drop, starknet::Event)] + enum Event { + #[flat] + AccountEvent: AccountComponent::Event, + #[flat] + SRC5Event: SRC5Component::Event + } + + #[constructor] + fn constructor(ref self: ContractState, public_key: felt252) { + self.account.initializer(public_key); + } +} + +#[starknet::contract(account)] +pub(crate) mod SnakeAccountMock { + use openzeppelin_account::AccountComponent; + use openzeppelin_introspection::src5::SRC5Component; + + component!(path: AccountComponent, storage: account, event: AccountEvent); + component!(path: SRC5Component, storage: src5, event: SRC5Event); + + // Account + #[abi(embed_v0)] + impl SRC6Impl = AccountComponent::SRC6Impl; + #[abi(embed_v0)] + impl PublicKeyImpl = AccountComponent::PublicKeyImpl; + impl AccountInternalImpl = AccountComponent::InternalImpl; + + // SCR5 + #[abi(embed_v0)] + impl SRC5Impl = SRC5Component::SRC5Impl; + + #[storage] + struct Storage { + #[substorage(v0)] + account: AccountComponent::Storage, + #[substorage(v0)] + src5: SRC5Component::Storage + } + + #[event] + #[derive(Drop, starknet::Event)] + enum Event { + #[flat] + AccountEvent: AccountComponent::Event, + #[flat] + SRC5Event: SRC5Component::Event + } + + #[constructor] + fn constructor(ref self: ContractState, public_key: felt252) { + self.account.initializer(public_key); + } +} + +#[starknet::contract(account)] +pub(crate) mod CamelAccountMock { + use openzeppelin_account::AccountComponent; + use openzeppelin_introspection::src5::SRC5Component; + use starknet::account::Call; + + component!(path: AccountComponent, storage: account, event: AccountEvent); + component!(path: SRC5Component, storage: src5, event: SRC5Event); + + // Account + #[abi(embed_v0)] + impl SRC6CamelOnlyImpl = AccountComponent::SRC6CamelOnlyImpl; + #[abi(embed_v0)] + impl PublicKeyCamelImpl = AccountComponent::PublicKeyCamelImpl; + impl SRC6Impl = AccountComponent::SRC6Impl; + impl AccountInternalImpl = AccountComponent::InternalImpl; + + // SCR5 + #[abi(embed_v0)] + impl SRC5Impl = SRC5Component::SRC5Impl; + + #[storage] + struct Storage { + #[substorage(v0)] + account: AccountComponent::Storage, + #[substorage(v0)] + src5: SRC5Component::Storage + } + + #[event] + #[derive(Drop, starknet::Event)] + enum Event { + #[flat] + AccountEvent: AccountComponent::Event, + #[flat] + SRC5Event: SRC5Component::Event + } + + #[constructor] + fn constructor(ref self: ContractState, publicKey: felt252) { + self.account.initializer(publicKey); + } + + #[abi(per_item)] + #[generate_trait] + impl ExternalImpl of ExternalTrait { + #[external(v0)] + fn __execute__(self: @ContractState, mut calls: Array) -> Array> { + self.account.__execute__(calls) + } + + #[external(v0)] + fn __validate__(self: @ContractState, mut calls: Array) -> felt252 { + self.account.__validate__(calls) + } + } +} diff --git a/src/tests/mocks/erc1155_mocks.cairo b/packages/token/src/tests/mocks/erc1155_mocks.cairo similarity index 95% rename from src/tests/mocks/erc1155_mocks.cairo rename to packages/token/src/tests/mocks/erc1155_mocks.cairo index 4ea256485..9d8d79181 100644 --- a/src/tests/mocks/erc1155_mocks.cairo +++ b/packages/token/src/tests/mocks/erc1155_mocks.cairo @@ -1,7 +1,7 @@ #[starknet::contract] pub(crate) mod DualCaseERC1155Mock { - use openzeppelin::introspection::src5::SRC5Component; - use openzeppelin::token::erc1155::{ERC1155Component, ERC1155HooksEmptyImpl}; + use openzeppelin_introspection::src5::SRC5Component; + use openzeppelin_token::erc1155::{ERC1155Component, ERC1155HooksEmptyImpl}; use starknet::ContractAddress; component!(path: ERC1155Component, storage: erc1155, event: ERC1155Event); @@ -53,8 +53,8 @@ pub(crate) mod DualCaseERC1155Mock { #[starknet::contract] pub(crate) mod SnakeERC1155Mock { - use openzeppelin::introspection::src5::SRC5Component; - use openzeppelin::token::erc1155::{ERC1155Component, ERC1155HooksEmptyImpl}; + use openzeppelin_introspection::src5::SRC5Component; + use openzeppelin_token::erc1155::{ERC1155Component, ERC1155HooksEmptyImpl}; use starknet::ContractAddress; component!(path: ERC1155Component, storage: erc1155, event: ERC1155Event); @@ -104,8 +104,8 @@ pub(crate) mod SnakeERC1155Mock { #[starknet::contract] pub(crate) mod CamelERC1155Mock { - use openzeppelin::introspection::src5::SRC5Component; - use openzeppelin::token::erc1155::{ERC1155Component, ERC1155HooksEmptyImpl}; + use openzeppelin_introspection::src5::SRC5Component; + use openzeppelin_token::erc1155::{ERC1155Component, ERC1155HooksEmptyImpl}; use starknet::ContractAddress; component!(path: ERC1155Component, storage: erc1155, event: ERC1155Event); diff --git a/src/tests/mocks/erc1155_receiver_mocks.cairo b/packages/token/src/tests/mocks/erc1155_receiver_mocks.cairo similarity index 92% rename from src/tests/mocks/erc1155_receiver_mocks.cairo rename to packages/token/src/tests/mocks/erc1155_receiver_mocks.cairo index 8df4a3963..34ec82649 100644 --- a/src/tests/mocks/erc1155_receiver_mocks.cairo +++ b/packages/token/src/tests/mocks/erc1155_receiver_mocks.cairo @@ -1,9 +1,9 @@ -use openzeppelin::tests::utils::constants::SUCCESS; +use openzeppelin_utils::test_utils::constants::SUCCESS; #[starknet::contract] pub(crate) mod DualCaseERC1155ReceiverMock { - use openzeppelin::introspection::src5::SRC5Component; - use openzeppelin::token::erc1155::ERC1155ReceiverComponent; + use openzeppelin_introspection::src5::SRC5Component; + use openzeppelin_token::erc1155::ERC1155ReceiverComponent; use starknet::ContractAddress; component!(path: SRC5Component, storage: src5, event: SRC5Event); @@ -42,8 +42,8 @@ pub(crate) mod DualCaseERC1155ReceiverMock { #[starknet::contract] pub(crate) mod SnakeERC1155ReceiverMock { - use openzeppelin::introspection::src5::SRC5Component; - use openzeppelin::token::erc1155::ERC1155ReceiverComponent; + use openzeppelin_introspection::src5::SRC5Component; + use openzeppelin_token::erc1155::ERC1155ReceiverComponent; use starknet::ContractAddress; component!(path: SRC5Component, storage: src5, event: SRC5Event); @@ -86,8 +86,8 @@ pub(crate) mod SnakeERC1155ReceiverMock { #[starknet::contract] pub(crate) mod CamelERC1155ReceiverMock { - use openzeppelin::introspection::src5::SRC5Component; - use openzeppelin::token::erc1155::ERC1155ReceiverComponent; + use openzeppelin_introspection::src5::SRC5Component; + use openzeppelin_token::erc1155::ERC1155ReceiverComponent; use starknet::ContractAddress; component!(path: SRC5Component, storage: src5, event: SRC5Event); diff --git a/src/tests/mocks/erc20_mocks.cairo b/packages/token/src/tests/mocks/erc20_mocks.cairo similarity index 96% rename from src/tests/mocks/erc20_mocks.cairo rename to packages/token/src/tests/mocks/erc20_mocks.cairo index 283cd7fdf..80a66d34f 100644 --- a/src/tests/mocks/erc20_mocks.cairo +++ b/packages/token/src/tests/mocks/erc20_mocks.cairo @@ -1,6 +1,6 @@ #[starknet::contract] pub(crate) mod DualCaseERC20Mock { - use openzeppelin::token::erc20::{ERC20Component, ERC20HooksEmptyImpl}; + use openzeppelin_token::erc20::{ERC20Component, ERC20HooksEmptyImpl}; use starknet::ContractAddress; component!(path: ERC20Component, storage: erc20, event: ERC20Event); @@ -41,7 +41,7 @@ pub(crate) mod DualCaseERC20Mock { #[starknet::contract] pub(crate) mod SnakeERC20Mock { - use openzeppelin::token::erc20::{ERC20Component, ERC20HooksEmptyImpl}; + use openzeppelin_token::erc20::{ERC20Component, ERC20HooksEmptyImpl}; use starknet::ContractAddress; component!(path: ERC20Component, storage: erc20, event: ERC20Event); @@ -80,7 +80,7 @@ pub(crate) mod SnakeERC20Mock { #[starknet::contract] pub(crate) mod CamelERC20Mock { - use openzeppelin::token::erc20::{ERC20Component, ERC20HooksEmptyImpl}; + use openzeppelin_token::erc20::{ERC20Component, ERC20HooksEmptyImpl}; use starknet::ContractAddress; component!(path: ERC20Component, storage: erc20, event: ERC20Event); diff --git a/src/tests/mocks/erc20_votes_mocks.cairo b/packages/token/src/tests/mocks/erc20_votes_mocks.cairo similarity index 88% rename from src/tests/mocks/erc20_votes_mocks.cairo rename to packages/token/src/tests/mocks/erc20_votes_mocks.cairo index fcc44b16a..a2a79ca18 100644 --- a/src/tests/mocks/erc20_votes_mocks.cairo +++ b/packages/token/src/tests/mocks/erc20_votes_mocks.cairo @@ -1,10 +1,10 @@ #[starknet::contract] pub(crate) mod DualCaseERC20VotesMock { - use openzeppelin::token::erc20::ERC20Component; - use openzeppelin::token::erc20::extensions::ERC20VotesComponent::InternalTrait as ERC20VotesInternalTrait; - use openzeppelin::token::erc20::extensions::ERC20VotesComponent; - use openzeppelin::utils::cryptography::nonces::NoncesComponent; - use openzeppelin::utils::cryptography::snip12::SNIP12Metadata; + use openzeppelin_token::erc20::ERC20Component; + use openzeppelin_token::erc20::extensions::ERC20VotesComponent::InternalTrait as ERC20VotesInternalTrait; + use openzeppelin_token::erc20::extensions::ERC20VotesComponent; + use openzeppelin_utils::cryptography::nonces::NoncesComponent; + use openzeppelin_utils::cryptography::snip12::SNIP12Metadata; use starknet::ContractAddress; component!(path: ERC20VotesComponent, storage: erc20_votes, event: ERC20VotesEvent); diff --git a/src/tests/mocks/erc721_mocks.cairo b/packages/token/src/tests/mocks/erc721_mocks.cairo similarity index 94% rename from src/tests/mocks/erc721_mocks.cairo rename to packages/token/src/tests/mocks/erc721_mocks.cairo index 770fd8312..05aaf81f2 100644 --- a/src/tests/mocks/erc721_mocks.cairo +++ b/packages/token/src/tests/mocks/erc721_mocks.cairo @@ -1,7 +1,7 @@ #[starknet::contract] pub(crate) mod DualCaseERC721Mock { - use openzeppelin::introspection::src5::SRC5Component; - use openzeppelin::token::erc721::{ERC721Component, ERC721HooksEmptyImpl}; + use openzeppelin_introspection::src5::SRC5Component; + use openzeppelin_token::erc721::{ERC721Component, ERC721HooksEmptyImpl}; use starknet::ContractAddress; component!(path: ERC721Component, storage: erc721, event: ERC721Event); @@ -56,8 +56,8 @@ pub(crate) mod DualCaseERC721Mock { #[starknet::contract] pub(crate) mod SnakeERC721Mock { - use openzeppelin::introspection::src5::SRC5Component; - use openzeppelin::token::erc721::{ERC721Component, ERC721HooksEmptyImpl}; + use openzeppelin_introspection::src5::SRC5Component; + use openzeppelin_token::erc721::{ERC721Component, ERC721HooksEmptyImpl}; use starknet::ContractAddress; component!(path: ERC721Component, storage: erc721, event: ERC721Event); @@ -107,9 +107,9 @@ pub(crate) mod SnakeERC721Mock { #[starknet::contract] pub(crate) mod CamelERC721Mock { - use openzeppelin::introspection::src5::SRC5Component; - use openzeppelin::token::erc721::ERC721Component::{ERC721Impl, ERC721MetadataImpl}; - use openzeppelin::token::erc721::{ERC721Component, ERC721HooksEmptyImpl}; + use openzeppelin_introspection::src5::SRC5Component; + use openzeppelin_token::erc721::ERC721Component::{ERC721Impl, ERC721MetadataImpl}; + use openzeppelin_token::erc721::{ERC721Component, ERC721HooksEmptyImpl}; use starknet::ContractAddress; component!(path: ERC721Component, storage: erc721, event: ERC721Event); diff --git a/src/tests/mocks/erc721_receiver_mocks.cairo b/packages/token/src/tests/mocks/erc721_receiver_mocks.cairo similarity index 93% rename from src/tests/mocks/erc721_receiver_mocks.cairo rename to packages/token/src/tests/mocks/erc721_receiver_mocks.cairo index 55ca3aebf..e321c0d58 100644 --- a/src/tests/mocks/erc721_receiver_mocks.cairo +++ b/packages/token/src/tests/mocks/erc721_receiver_mocks.cairo @@ -1,9 +1,9 @@ -use openzeppelin::tests::utils::constants::SUCCESS; +use openzeppelin_utils::test_utils::constants::SUCCESS; #[starknet::contract] pub(crate) mod DualCaseERC721ReceiverMock { - use openzeppelin::introspection::src5::SRC5Component; - use openzeppelin::token::erc721::ERC721ReceiverComponent; + use openzeppelin_introspection::src5::SRC5Component; + use openzeppelin_token::erc721::ERC721ReceiverComponent; use starknet::ContractAddress; component!(path: ERC721ReceiverComponent, storage: erc721_receiver, event: ERC721ReceiverEvent); @@ -72,8 +72,8 @@ pub(crate) mod DualCaseERC721ReceiverMock { #[starknet::contract] pub(crate) mod SnakeERC721ReceiverMock { - use openzeppelin::introspection::src5::SRC5Component; - use openzeppelin::token::erc721::ERC721ReceiverComponent; + use openzeppelin_introspection::src5::SRC5Component; + use openzeppelin_token::erc721::ERC721ReceiverComponent; use starknet::ContractAddress; component!(path: ERC721ReceiverComponent, storage: erc721_receiver, event: ERC721ReceiverEvent); @@ -131,8 +131,8 @@ pub(crate) mod SnakeERC721ReceiverMock { #[starknet::contract] pub(crate) mod CamelERC721ReceiverMock { - use openzeppelin::introspection::src5::SRC5Component; - use openzeppelin::token::erc721::ERC721ReceiverComponent; + use openzeppelin_introspection::src5::SRC5Component; + use openzeppelin_token::erc721::ERC721ReceiverComponent; use starknet::ContractAddress; component!(path: ERC721ReceiverComponent, storage: erc721_receiver, event: ERC721ReceiverEvent); diff --git a/packages/token/src/tests/mocks/non_implementing_mock.cairo b/packages/token/src/tests/mocks/non_implementing_mock.cairo new file mode 100644 index 000000000..c1212dbdd --- /dev/null +++ b/packages/token/src/tests/mocks/non_implementing_mock.cairo @@ -0,0 +1,10 @@ +#[starknet::contract] +pub(crate) mod NonImplementingMock { + #[storage] + struct Storage {} + + #[external(v0)] + fn nope(self: @ContractState) -> bool { + false + } +} diff --git a/packages/token/src/tests/mocks/src5_mocks.cairo b/packages/token/src/tests/mocks/src5_mocks.cairo new file mode 100644 index 000000000..86e8c5167 --- /dev/null +++ b/packages/token/src/tests/mocks/src5_mocks.cairo @@ -0,0 +1,22 @@ +#[starknet::contract] +pub(crate) mod SRC5Mock { + use openzeppelin_introspection::src5::SRC5Component; + + component!(path: SRC5Component, storage: src5, event: SRC5Event); + + #[abi(embed_v0)] + impl SRC5Impl = SRC5Component::SRC5Impl; + + #[storage] + struct Storage { + #[substorage(v0)] + src5: SRC5Component::Storage + } + + #[event] + #[derive(Drop, starknet::Event)] + enum Event { + #[flat] + SRC5Event: SRC5Component::Event + } +} diff --git a/packages/upgrades/Scarb.toml b/packages/upgrades/Scarb.toml new file mode 100644 index 000000000..8e751d426 --- /dev/null +++ b/packages/upgrades/Scarb.toml @@ -0,0 +1,31 @@ + +[package] +name = "openzeppelin_upgrades" +version.workspace = true +edition.workspace = true +cairo-version.workspace = true +scarb-version.workspace = true +authors.workspace = true +description.workspace = true +documentation.workspace = true +readme.workspace = true +repository.workspace = true +license-file.workspace = true +keywords.workspace = true + +[tool] +fmt.workspace = true + +[dependencies] +starknet.workspace = true +openzeppelin_utils = { path = "../utils" } + +[dev-dependencies] +snforge_std.workspace = true + +[lib] + +[[target.starknet-contract]] +allowed-libfuncs-list.name = "experimental" +sierra = true +casm = false diff --git a/src/upgrades/interface.cairo b/packages/upgrades/src/interface.cairo similarity index 100% rename from src/upgrades/interface.cairo rename to packages/upgrades/src/interface.cairo diff --git a/src/upgrades.cairo b/packages/upgrades/src/lib.cairo similarity index 84% rename from src/upgrades.cairo rename to packages/upgrades/src/lib.cairo index d85c912e6..1f6920e8c 100644 --- a/src/upgrades.cairo +++ b/packages/upgrades/src/lib.cairo @@ -1,4 +1,6 @@ pub mod interface; + +pub mod tests; pub mod upgradeable; pub use upgradeable::UpgradeableComponent; diff --git a/packages/upgrades/src/tests.cairo b/packages/upgrades/src/tests.cairo new file mode 100644 index 000000000..036225e91 --- /dev/null +++ b/packages/upgrades/src/tests.cairo @@ -0,0 +1,5 @@ +pub mod common; +pub(crate) mod mocks; + +#[cfg(test)] +mod test_upgradeable; diff --git a/src/tests/upgrades/common.cairo b/packages/upgrades/src/tests/common.cairo similarity index 72% rename from src/tests/upgrades/common.cairo rename to packages/upgrades/src/tests/common.cairo index 973f47c8b..e5fe93100 100644 --- a/src/tests/upgrades/common.cairo +++ b/packages/upgrades/src/tests/common.cairo @@ -1,11 +1,11 @@ -use openzeppelin::tests::utils::events::EventSpyExt; -use openzeppelin::upgrades::UpgradeableComponent::Upgraded; -use openzeppelin::upgrades::UpgradeableComponent; +use openzeppelin_upgrades::UpgradeableComponent::Upgraded; +use openzeppelin_upgrades::UpgradeableComponent; +use openzeppelin_utils::test_utils::events::EventSpyExt; use snforge_std::{EventSpy, EventSpyAssertionsTrait}; use starknet::{ContractAddress, ClassHash}; #[generate_trait] -pub(crate) impl UpgradeableSpyHelpersImpl of UpgradeableSpyHelpers { +pub impl UpgradeableSpyHelpersImpl of UpgradeableSpyHelpers { fn assert_event_upgraded(ref self: EventSpy, contract: ContractAddress, class_hash: ClassHash) { let expected = UpgradeableComponent::Event::Upgraded(Upgraded { class_hash }); self.assert_emitted_single(contract, expected); diff --git a/packages/upgrades/src/tests/mocks.cairo b/packages/upgrades/src/tests/mocks.cairo new file mode 100644 index 000000000..a287b9e8f --- /dev/null +++ b/packages/upgrades/src/tests/mocks.cairo @@ -0,0 +1 @@ +pub(crate) mod upgrades_mocks; diff --git a/src/tests/mocks/upgrades_mocks.cairo b/packages/upgrades/src/tests/mocks/upgrades_mocks.cairo similarity index 96% rename from src/tests/mocks/upgrades_mocks.cairo rename to packages/upgrades/src/tests/mocks/upgrades_mocks.cairo index 07a7ac620..266680d56 100644 --- a/src/tests/mocks/upgrades_mocks.cairo +++ b/packages/upgrades/src/tests/mocks/upgrades_mocks.cairo @@ -14,7 +14,7 @@ pub(crate) trait IUpgradesV1 { #[starknet::contract] pub(crate) mod UpgradesV1 { - use openzeppelin::upgrades::UpgradeableComponent; + use openzeppelin_upgrades::UpgradeableComponent; use starknet::ClassHash; component!(path: UpgradeableComponent, storage: upgradeable, event: UpgradeableEvent); @@ -64,7 +64,7 @@ pub(crate) trait IUpgradesV2 { #[starknet::contract] pub(crate) mod UpgradesV2 { - use openzeppelin::upgrades::UpgradeableComponent; + use openzeppelin_upgrades::UpgradeableComponent; use starknet::ClassHash; component!(path: UpgradeableComponent, storage: upgradeable, event: UpgradeableEvent); diff --git a/src/tests/upgrades/test_upgradeable.cairo b/packages/upgrades/src/tests/test_upgradeable.cairo similarity index 79% rename from src/tests/upgrades/test_upgradeable.cairo rename to packages/upgrades/src/tests/test_upgradeable.cairo index d55c41f74..c976ce1cc 100644 --- a/src/tests/upgrades/test_upgradeable.cairo +++ b/packages/upgrades/src/tests/test_upgradeable.cairo @@ -1,9 +1,13 @@ -use openzeppelin::tests::mocks::upgrades_mocks::{IUpgradesV1Dispatcher, IUpgradesV1DispatcherTrait}; -use openzeppelin::tests::mocks::upgrades_mocks::{IUpgradesV2Dispatcher, IUpgradesV2DispatcherTrait}; -use openzeppelin::tests::utils::constants::{CLASS_HASH_ZERO, ZERO, FELT_VALUE as VALUE}; -use openzeppelin::tests::utils::events::EventSpyExt; -use openzeppelin::tests::utils::{declare_class, deploy}; -use openzeppelin::upgrades::UpgradeableComponent; +use openzeppelin_upgrades::UpgradeableComponent; +use openzeppelin_upgrades::tests::mocks::upgrades_mocks::{ + IUpgradesV1Dispatcher, IUpgradesV1DispatcherTrait +}; +use openzeppelin_upgrades::tests::mocks::upgrades_mocks::{ + IUpgradesV2Dispatcher, IUpgradesV2DispatcherTrait +}; +use openzeppelin_utils::test_utils::constants::{CLASS_HASH_ZERO, ZERO, FELT_VALUE as VALUE}; +use openzeppelin_utils::test_utils::events::EventSpyExt; +use openzeppelin_utils::test_utils::{declare_class, deploy}; use snforge_std::{spy_events, ContractClass}; use super::common::UpgradeableSpyHelpers; diff --git a/src/upgrades/upgradeable.cairo b/packages/upgrades/src/upgradeable.cairo similarity index 100% rename from src/upgrades/upgradeable.cairo rename to packages/upgrades/src/upgradeable.cairo diff --git a/packages/utils/Scarb.toml b/packages/utils/Scarb.toml new file mode 100644 index 000000000..dbc349820 --- /dev/null +++ b/packages/utils/Scarb.toml @@ -0,0 +1,28 @@ + +[package] +name = "openzeppelin_utils" +version.workspace = true +edition.workspace = true +cairo-version.workspace = true +scarb-version.workspace = true +authors.workspace = true +description.workspace = true +documentation.workspace = true +readme.workspace = true +repository.workspace = true +license-file.workspace = true +keywords.workspace = true + +[tool] +fmt.workspace = true + +[dependencies] +starknet.workspace = true +snforge_std.workspace = true + +[lib] + +[[target.starknet-contract]] +allowed-libfuncs-list.name = "experimental" +sierra = true +casm = false diff --git a/src/utils/cryptography.cairo b/packages/utils/src/cryptography.cairo similarity index 100% rename from src/utils/cryptography.cairo rename to packages/utils/src/cryptography.cairo diff --git a/src/utils/cryptography/interface.cairo b/packages/utils/src/cryptography/interface.cairo similarity index 100% rename from src/utils/cryptography/interface.cairo rename to packages/utils/src/cryptography/interface.cairo diff --git a/src/utils/cryptography/nonces.cairo b/packages/utils/src/cryptography/nonces.cairo similarity index 97% rename from src/utils/cryptography/nonces.cairo rename to packages/utils/src/cryptography/nonces.cairo index 40089d76a..f27eb50cc 100644 --- a/src/utils/cryptography/nonces.cairo +++ b/packages/utils/src/cryptography/nonces.cairo @@ -3,7 +3,7 @@ #[starknet::component] pub mod NoncesComponent { - use openzeppelin::utils::interfaces::INonces; + use openzeppelin_utils::interfaces::INonces; use starknet::ContractAddress; use starknet::storage::Map; diff --git a/src/utils/cryptography/snip12.cairo b/packages/utils/src/cryptography/snip12.cairo similarity index 100% rename from src/utils/cryptography/snip12.cairo rename to packages/utils/src/cryptography/snip12.cairo diff --git a/src/utils/deployments.cairo b/packages/utils/src/deployments.cairo similarity index 95% rename from src/utils/deployments.cairo rename to packages/utils/src/deployments.cairo index 0ca55135c..bec5bed0a 100644 --- a/src/utils/deployments.cairo +++ b/packages/utils/src/deployments.cairo @@ -1,3 +1,6 @@ +// SPDX-License-Identifier: MIT +// OpenZeppelin Contracts for Cairo v0.15.0-rc.0 (utils/deployments.cairo) + pub mod interface; use core::hash::{HashStateTrait, HashStateExTrait}; @@ -5,7 +8,7 @@ use core::num::traits::Zero; use core::pedersen::PedersenTrait; use core::poseidon::PoseidonTrait; use interface::IUniversalDeployer; -use openzeppelin::utils::serde::SerializedAppend; +use openzeppelin_utils::serde::SerializedAppend; use starknet::ClassHash; use starknet::ContractAddress; diff --git a/src/utils/deployments/interface.cairo b/packages/utils/src/deployments/interface.cairo similarity index 100% rename from src/utils/deployments/interface.cairo rename to packages/utils/src/deployments/interface.cairo diff --git a/src/utils/interfaces.cairo b/packages/utils/src/interfaces.cairo similarity index 57% rename from src/utils/interfaces.cairo rename to packages/utils/src/interfaces.cairo index 4609526a0..90cfbc9ff 100644 --- a/src/utils/interfaces.cairo +++ b/packages/utils/src/interfaces.cairo @@ -1,6 +1,6 @@ -pub use openzeppelin::utils::cryptography::interface::{ +pub use openzeppelin_utils::cryptography::interface::{ INonces, INoncesDispatcher, INoncesDispatcherTrait }; -pub use openzeppelin::utils::deployments::interface::{ +pub use openzeppelin_utils::deployments::interface::{ IUniversalDeployer, IUniversalDeployerDispatcher, IUniversalDeployerDispatcherTrait }; diff --git a/src/utils.cairo b/packages/utils/src/lib.cairo similarity index 95% rename from src/utils.cairo rename to packages/utils/src/lib.cairo index 530d909b3..08cb871b9 100644 --- a/src/utils.cairo +++ b/packages/utils/src/lib.cairo @@ -8,6 +8,12 @@ pub mod math; pub mod selectors; pub mod serde; pub mod structs; + +pub mod test_utils; + +#[cfg(test)] +mod tests; + pub mod unwrap_and_cast; pub use cryptography::nonces; diff --git a/src/utils/math.cairo b/packages/utils/src/math.cairo similarity index 100% rename from src/utils/math.cairo rename to packages/utils/src/math.cairo diff --git a/src/utils/selectors.cairo b/packages/utils/src/selectors.cairo similarity index 100% rename from src/utils/selectors.cairo rename to packages/utils/src/selectors.cairo diff --git a/src/utils/serde.cairo b/packages/utils/src/serde.cairo similarity index 100% rename from src/utils/serde.cairo rename to packages/utils/src/serde.cairo diff --git a/src/utils/structs.cairo b/packages/utils/src/structs.cairo similarity index 100% rename from src/utils/structs.cairo rename to packages/utils/src/structs.cairo diff --git a/src/utils/structs/checkpoint.cairo b/packages/utils/src/structs/checkpoint.cairo similarity index 94% rename from src/utils/structs/checkpoint.cairo rename to packages/utils/src/structs/checkpoint.cairo index ec2ec0ab4..d18eb7d83 100644 --- a/src/utils/structs/checkpoint.cairo +++ b/packages/utils/src/structs/checkpoint.cairo @@ -2,7 +2,7 @@ // OpenZeppelin Contracts for Cairo v0.15.0-rc.0 (utils/structs/checkpoint.cairo) use core::num::traits::Sqrt; -use openzeppelin::utils::math; +use openzeppelin_utils::math; use starknet::storage_access::StorePacking; use super::storage_array::{StorageArray, StorageArrayTrait}; @@ -198,7 +198,7 @@ impl CheckpointStorePacking of StorePacking { #[cfg(test)] mod test { - use core::integer::BoundedInt; + use core::num::traits::Bounded; use super::Checkpoint; use super::CheckpointStorePacking; use super::_2_POW_184; @@ -208,15 +208,15 @@ mod test { #[test] fn test_pack_big_key_and_value() { - let key = BoundedInt::max(); - let value = BoundedInt::max(); + let key = Bounded::MAX; + let value = Bounded::MAX; let checkpoint = Checkpoint { key, value }; let (key_and_low, high) = CheckpointStorePacking::pack(checkpoint); let expected_key: u256 = (key_and_low.into() / _2_POW_184.into()) & KEY_MASK; let expected_low: u256 = key_and_low.into() & LOW_MASK; - let expected_high: felt252 = BoundedInt::::max().into(); + let expected_high: felt252 = Bounded::::MAX.into(); assert_eq!(key.into(), expected_key); assert_eq!(value.low.into(), expected_low); @@ -225,14 +225,13 @@ mod test { #[test] fn test_unpack_big_key_and_value() { - let key_and_low = BoundedInt::::max().into() * _2_POW_184 - + BoundedInt::::max().into(); - let high = BoundedInt::::max().into(); + let key_and_low = Bounded::::MAX.into() * _2_POW_184 + Bounded::::MAX.into(); + let high = Bounded::::MAX.into(); let checkpoint = CheckpointStorePacking::unpack((key_and_low, high)); - let expected_key: u64 = BoundedInt::max(); - let expected_value: u256 = BoundedInt::max(); + let expected_key: u64 = Bounded::MAX; + let expected_value: u256 = Bounded::MAX; assert_eq!(checkpoint.key, expected_key); assert_eq!(checkpoint.value, expected_value); diff --git a/src/utils/structs/storage_array.cairo b/packages/utils/src/structs/storage_array.cairo similarity index 100% rename from src/utils/structs/storage_array.cairo rename to packages/utils/src/structs/storage_array.cairo diff --git a/src/tests/utils.cairo b/packages/utils/src/test_utils.cairo similarity index 93% rename from src/tests/utils.cairo rename to packages/utils/src/test_utils.cairo index 597fa9659..c2b8b42f8 100644 --- a/src/tests/utils.cairo +++ b/packages/utils/src/test_utils.cairo @@ -1,5 +1,5 @@ pub mod common; -pub(crate) mod constants; +pub mod constants; pub mod deployment; pub mod events; pub mod signing; diff --git a/src/tests/utils/common.cairo b/packages/utils/src/test_utils/common.cairo similarity index 100% rename from src/tests/utils/common.cairo rename to packages/utils/src/test_utils/common.cairo diff --git a/packages/utils/src/test_utils/constants.cairo b/packages/utils/src/test_utils/constants.cairo new file mode 100644 index 000000000..b72c96c44 --- /dev/null +++ b/packages/utils/src/test_utils/constants.cairo @@ -0,0 +1,148 @@ +use starknet::ClassHash; +use starknet::ContractAddress; +use starknet::SyscallResultTrait; +use starknet::class_hash::class_hash_const; +use starknet::contract_address_const; +use starknet::secp256_trait::Secp256Trait; + +pub type EthPublicKey = starknet::secp256k1::Secp256k1Point; + +pub const DECIMALS: u8 = 18_u8; +pub const SUPPLY: u256 = 2000; +pub const VALUE: u256 = 300; +pub const FELT_VALUE: felt252 = 'FELT_VALUE'; +pub const ROLE: felt252 = 'ROLE'; +pub const OTHER_ROLE: felt252 = 'OTHER_ROLE'; +pub const TOKEN_ID: u256 = 21; +pub const TOKEN_ID_2: u256 = 121; +pub const TOKEN_VALUE: u256 = 42; +pub const TOKEN_VALUE_2: u256 = 142; +pub const PUBKEY: felt252 = 'PUBKEY'; +pub const NEW_PUBKEY: felt252 = 0x26da8d11938b76025862be14fdb8b28438827f73e75e86f7bfa38b196951fa7; +pub const DAPP_NAME: felt252 = 'DAPP_NAME'; +pub const DAPP_VERSION: felt252 = 'DAPP_VERSION'; +pub const SALT: felt252 = 'SALT'; +pub const SUCCESS: felt252 = 123123; +pub const FAILURE: felt252 = 456456; +pub const MIN_TRANSACTION_VERSION: felt252 = 1; +pub const TRANSACTION_HASH: felt252 = 'TRANSACTION_HASH'; +// 2**128 +pub const QUERY_OFFSET: felt252 = 0x100000000000000000000000000000000; +// QUERY_OFFSET + MIN_TRANSACTION_VERSION +pub const QUERY_VERSION: felt252 = 0x100000000000000000000000000000001; + +pub fn NAME() -> ByteArray { + "NAME" +} + +pub fn SYMBOL() -> ByteArray { + "SYMBOL" +} + +pub fn BASE_URI() -> ByteArray { + "https://api.example.com/v1/" +} + +pub fn BASE_URI_2() -> ByteArray { + "https://api.example.com/v2/" +} + +pub fn ETH_PUBKEY() -> EthPublicKey { + Secp256Trait::secp256_ec_get_point_from_x_syscall(3, false).unwrap_syscall().unwrap() +} + +pub fn NEW_ETH_PUBKEY() -> EthPublicKey { + Secp256Trait::secp256_ec_get_point_from_x_syscall(4, false).unwrap_syscall().unwrap() +} + +pub fn ADMIN() -> ContractAddress { + contract_address_const::<'ADMIN'>() +} + +pub fn AUTHORIZED() -> ContractAddress { + contract_address_const::<'AUTHORIZED'>() +} + +pub fn ZERO() -> ContractAddress { + contract_address_const::<0>() +} + +pub fn CLASS_HASH_ZERO() -> ClassHash { + class_hash_const::<0>() +} + +pub fn CALLER() -> ContractAddress { + contract_address_const::<'CALLER'>() +} + +pub fn OWNER() -> ContractAddress { + contract_address_const::<'OWNER'>() +} + +pub fn NEW_OWNER() -> ContractAddress { + contract_address_const::<'NEW_OWNER'>() +} + +pub fn OTHER() -> ContractAddress { + contract_address_const::<'OTHER'>() +} + +pub fn OTHER_ADMIN() -> ContractAddress { + contract_address_const::<'OTHER_ADMIN'>() +} + +pub fn SPENDER() -> ContractAddress { + contract_address_const::<'SPENDER'>() +} + +pub fn RECIPIENT() -> ContractAddress { + contract_address_const::<'RECIPIENT'>() +} + +pub fn OPERATOR() -> ContractAddress { + contract_address_const::<'OPERATOR'>() +} + +pub fn DATA(success: bool) -> Span { + let mut data = array![]; + if success { + data.append(SUCCESS); + } else { + data.append(FAILURE); + } + data.span() +} + +pub fn EMPTY_DATA() -> Span { + array![].span() +} + +// +// Signing keys +// + +pub mod secp256k1 { + use openzeppelin_utils::test_utils::signing::{Secp256k1KeyPair, get_secp256k1_keys_from}; + + pub fn KEY_PAIR() -> Secp256k1KeyPair { + let private_key = u256 { low: 'PRIVATE_LOW', high: 'PRIVATE_HIGH' }; + get_secp256k1_keys_from(private_key) + } + + pub fn KEY_PAIR_2() -> Secp256k1KeyPair { + let private_key = u256 { low: 'PRIVATE_LOW_2', high: 'PRIVATE_HIGH_2' }; + get_secp256k1_keys_from(private_key) + } +} + +pub mod stark { + use openzeppelin_utils::test_utils::signing::{StarkKeyPair, get_stark_keys_from}; + + pub fn KEY_PAIR() -> StarkKeyPair { + get_stark_keys_from('PRIVATE_KEY') + } + + pub fn KEY_PAIR_2() -> StarkKeyPair { + get_stark_keys_from('PRIVATE_KEY_2') + } +} diff --git a/src/tests/utils/deployment.cairo b/packages/utils/src/test_utils/deployment.cairo similarity index 89% rename from src/tests/utils/deployment.cairo rename to packages/utils/src/test_utils/deployment.cairo index 2b50ab15f..9e296b838 100644 --- a/src/tests/utils/deployment.cairo +++ b/packages/utils/src/test_utils/deployment.cairo @@ -1,6 +1,7 @@ use core::starknet::SyscallResultTrait; -use openzeppelin::tests::utils::panic_data_to_byte_array; -use snforge_std::{ContractClass, ContractClassTrait}; +use openzeppelin_utils::test_utils::panic_data_to_byte_array; +use snforge_std::{declare, get_class_hash, ContractClass, ContractClassTrait}; +use snforge_std::{start_cheat_caller_address, stop_cheat_caller_address}; use starknet::ContractAddress; pub fn deploy(contract_class: ContractClass, calldata: Array) -> ContractAddress { diff --git a/src/tests/utils/events.cairo b/packages/utils/src/test_utils/events.cairo similarity index 100% rename from src/tests/utils/events.cairo rename to packages/utils/src/test_utils/events.cairo diff --git a/src/tests/utils/signing.cairo b/packages/utils/src/test_utils/signing.cairo similarity index 100% rename from src/tests/utils/signing.cairo rename to packages/utils/src/test_utils/signing.cairo diff --git a/src/tests/cryptography.cairo b/packages/utils/src/tests.cairo similarity index 59% rename from src/tests/cryptography.cairo rename to packages/utils/src/tests.cairo index fedcc380c..37cf414d3 100644 --- a/src/tests/cryptography.cairo +++ b/packages/utils/src/tests.cairo @@ -1,2 +1,4 @@ +pub(crate) mod mocks; + mod test_nonces; mod test_snip12; diff --git a/packages/utils/src/tests/mocks.cairo b/packages/utils/src/tests/mocks.cairo new file mode 100644 index 000000000..7a238265a --- /dev/null +++ b/packages/utils/src/tests/mocks.cairo @@ -0,0 +1 @@ +pub(crate) mod nonces_mocks; diff --git a/src/tests/mocks/nonces_mocks.cairo b/packages/utils/src/tests/mocks/nonces_mocks.cairo similarity index 88% rename from src/tests/mocks/nonces_mocks.cairo rename to packages/utils/src/tests/mocks/nonces_mocks.cairo index 51472eb51..4c68d5f06 100644 --- a/src/tests/mocks/nonces_mocks.cairo +++ b/packages/utils/src/tests/mocks/nonces_mocks.cairo @@ -1,6 +1,6 @@ #[starknet::contract] pub(crate) mod NoncesMock { - use openzeppelin::utils::cryptography::nonces::NoncesComponent; + use openzeppelin_utils::cryptography::nonces::NoncesComponent; component!(path: NoncesComponent, storage: nonces, event: NoncesEvent); diff --git a/src/tests/cryptography/test_nonces.cairo b/packages/utils/src/tests/test_nonces.cairo similarity index 77% rename from src/tests/cryptography/test_nonces.cairo rename to packages/utils/src/tests/test_nonces.cairo index 8d46c5fcb..fb3d500d4 100644 --- a/src/tests/cryptography/test_nonces.cairo +++ b/packages/utils/src/tests/test_nonces.cairo @@ -1,9 +1,9 @@ use core::num::traits::Zero; -use openzeppelin::tests::mocks::nonces_mocks::NoncesMock; -use openzeppelin::tests::utils::constants::OWNER; -use openzeppelin::utils::cryptography::interface::INonces; -use openzeppelin::utils::cryptography::nonces::NoncesComponent::InternalTrait; -use openzeppelin::utils::cryptography::nonces::NoncesComponent; +use openzeppelin_utils::cryptography::interface::INonces; +use openzeppelin_utils::cryptography::nonces::NoncesComponent::InternalTrait; +use openzeppelin_utils::cryptography::nonces::NoncesComponent; +use openzeppelin_utils::test_utils::constants::OWNER; +use openzeppelin_utils::tests::mocks::nonces_mocks::NoncesMock; type ComponentState = NoncesComponent::ComponentState; diff --git a/src/tests/cryptography/test_snip12.cairo b/packages/utils/src/tests/test_snip12.cairo similarity index 94% rename from src/tests/cryptography/test_snip12.cairo rename to packages/utils/src/tests/test_snip12.cairo index 6ffa80df8..2511a8780 100644 --- a/src/tests/cryptography/test_snip12.cairo +++ b/packages/utils/src/tests/test_snip12.cairo @@ -1,9 +1,9 @@ use core::hash::{Hash, HashStateTrait, HashStateExTrait}; use core::poseidon::{PoseidonTrait, poseidon_hash_span}; -use openzeppelin::tests::utils::constants::{OWNER, RECIPIENT}; -use openzeppelin::utils::cryptography::snip12::{ +use openzeppelin_utils::cryptography::snip12::{ STARKNET_DOMAIN_TYPE_HASH, StarknetDomain, StructHash, OffchainMessageHashImpl, SNIP12Metadata }; +use openzeppelin_utils::test_utils::constants::{OWNER, RECIPIENT}; use snforge_std::{start_cheat_chain_id, test_address}; use starknet::ContractAddress; diff --git a/src/utils/unwrap_and_cast.cairo b/packages/utils/src/unwrap_and_cast.cairo similarity index 100% rename from src/utils/unwrap_and_cast.cairo rename to packages/utils/src/unwrap_and_cast.cairo diff --git a/src/lib.cairo b/src/lib.cairo index 78bf8b567..9c8fdf03a 100644 --- a/src/lib.cairo +++ b/src/lib.cairo @@ -1,10 +1,9 @@ -pub mod access; -pub mod account; -pub mod governance; -pub mod introspection; -pub mod presets; -pub mod security; -pub mod tests; -pub mod token; -pub mod upgrades; -pub mod utils; +pub use openzeppelin_access as access; +pub use openzeppelin_account as account; +pub use openzeppelin_governance as governance; +pub use openzeppelin_introspection as introspection; +pub use openzeppelin_presets as presets; +pub use openzeppelin_security as security; +pub use openzeppelin_token as token; +pub use openzeppelin_upgrades as upgrades; +pub use openzeppelin_utils as utils; diff --git a/src/presets.cairo b/src/presets.cairo deleted file mode 100644 index e7dd01ef0..000000000 --- a/src/presets.cairo +++ /dev/null @@ -1,14 +0,0 @@ -pub(crate) mod account; -pub(crate) mod erc1155; -pub(crate) mod erc20; -pub(crate) mod erc721; -pub(crate) mod eth_account; -pub mod interfaces; -pub(crate) mod universal_deployer; - -pub(crate) use account::AccountUpgradeable; -pub(crate) use erc1155::ERC1155Upgradeable; -pub(crate) use erc20::ERC20Upgradeable; -pub(crate) use erc721::ERC721Upgradeable; -pub(crate) use eth_account::EthAccountUpgradeable; -pub(crate) use universal_deployer::UniversalDeployer; diff --git a/src/tests.cairo b/src/tests.cairo deleted file mode 100644 index 6a1d8a06a..000000000 --- a/src/tests.cairo +++ /dev/null @@ -1,21 +0,0 @@ -#[cfg(test)] -mod access; -#[cfg(test)] -mod account; -#[cfg(test)] -mod cryptography; -#[cfg(test)] -mod governance; -#[cfg(test)] -mod introspection; -mod mocks; -#[cfg(test)] -mod presets; -#[cfg(test)] -mod security; -#[cfg(test)] -mod token; -#[cfg(test)] -mod upgrades; - -pub mod utils; diff --git a/src/tests/account.cairo b/src/tests/account.cairo deleted file mode 100644 index 2622d9aa5..000000000 --- a/src/tests/account.cairo +++ /dev/null @@ -1,5 +0,0 @@ -pub(crate) mod ethereum; -pub(crate) mod starknet; - -mod test_secp256k1; -mod test_signature; diff --git a/src/tests/governance.cairo b/src/tests/governance.cairo deleted file mode 100644 index 3aa8297b3..000000000 --- a/src/tests/governance.cairo +++ /dev/null @@ -1,2 +0,0 @@ -mod test_timelock; -mod test_utils; diff --git a/src/tests/introspection.cairo b/src/tests/introspection.cairo deleted file mode 100644 index 32094b462..000000000 --- a/src/tests/introspection.cairo +++ /dev/null @@ -1 +0,0 @@ -mod test_src5; diff --git a/src/tests/token.cairo b/src/tests/token.cairo deleted file mode 100644 index 04f631ea8..000000000 --- a/src/tests/token.cairo +++ /dev/null @@ -1,3 +0,0 @@ -pub(crate) mod erc1155; -pub(crate) mod erc20; -pub(crate) mod erc721; diff --git a/src/tests/upgrades.cairo b/src/tests/upgrades.cairo deleted file mode 100644 index 7b8b842ad..000000000 --- a/src/tests/upgrades.cairo +++ /dev/null @@ -1,3 +0,0 @@ -pub(crate) mod common; - -mod test_upgradeable; diff --git a/src/tests/utils/constants.cairo b/src/tests/utils/constants.cairo deleted file mode 100644 index 4d8df0911..000000000 --- a/src/tests/utils/constants.cairo +++ /dev/null @@ -1,148 +0,0 @@ -use openzeppelin::account::interface::EthPublicKey; -use starknet::ClassHash; -use starknet::ContractAddress; -use starknet::SyscallResultTrait; -use starknet::class_hash::class_hash_const; -use starknet::contract_address_const; -use starknet::secp256_trait::Secp256Trait; - -pub(crate) const DECIMALS: u8 = 18_u8; -pub(crate) const SUPPLY: u256 = 2000; -pub(crate) const VALUE: u256 = 300; -pub(crate) const FELT_VALUE: felt252 = 'FELT_VALUE'; -pub(crate) const ROLE: felt252 = 'ROLE'; -pub(crate) const OTHER_ROLE: felt252 = 'OTHER_ROLE'; -pub(crate) const TOKEN_ID: u256 = 21; -pub(crate) const TOKEN_ID_2: u256 = 121; -pub(crate) const TOKEN_VALUE: u256 = 42; -pub(crate) const TOKEN_VALUE_2: u256 = 142; -pub(crate) const PUBKEY: felt252 = 'PUBKEY'; -pub(crate) const NEW_PUBKEY: felt252 = - 0x26da8d11938b76025862be14fdb8b28438827f73e75e86f7bfa38b196951fa7; -pub(crate) const DAPP_NAME: felt252 = 'DAPP_NAME'; -pub(crate) const DAPP_VERSION: felt252 = 'DAPP_VERSION'; -pub(crate) const SALT: felt252 = 'SALT'; -pub(crate) const SUCCESS: felt252 = 123123; -pub(crate) const FAILURE: felt252 = 456456; -pub(crate) const MIN_TRANSACTION_VERSION: felt252 = 1; -pub(crate) const TRANSACTION_HASH: felt252 = 'TRANSACTION_HASH'; -// 2**128 -pub(crate) const QUERY_OFFSET: felt252 = 0x100000000000000000000000000000000; -// QUERY_OFFSET + MIN_TRANSACTION_VERSION -pub(crate) const QUERY_VERSION: felt252 = 0x100000000000000000000000000000001; - -pub(crate) fn NAME() -> ByteArray { - "NAME" -} - -pub(crate) fn SYMBOL() -> ByteArray { - "SYMBOL" -} - -pub(crate) fn BASE_URI() -> ByteArray { - "https://api.example.com/v1/" -} - -pub(crate) fn BASE_URI_2() -> ByteArray { - "https://api.example.com/v2/" -} - -pub(crate) fn ETH_PUBKEY() -> EthPublicKey { - Secp256Trait::secp256_ec_get_point_from_x_syscall(3, false).unwrap_syscall().unwrap() -} - -pub(crate) fn NEW_ETH_PUBKEY() -> EthPublicKey { - Secp256Trait::secp256_ec_get_point_from_x_syscall(4, false).unwrap_syscall().unwrap() -} - -pub(crate) fn ADMIN() -> ContractAddress { - contract_address_const::<'ADMIN'>() -} - -pub(crate) fn AUTHORIZED() -> ContractAddress { - contract_address_const::<'AUTHORIZED'>() -} - -pub(crate) fn ZERO() -> ContractAddress { - contract_address_const::<0>() -} - -pub(crate) fn CLASS_HASH_ZERO() -> ClassHash { - class_hash_const::<0>() -} - -pub(crate) fn CALLER() -> ContractAddress { - contract_address_const::<'CALLER'>() -} - -pub(crate) fn OWNER() -> ContractAddress { - contract_address_const::<'OWNER'>() -} - -pub(crate) fn NEW_OWNER() -> ContractAddress { - contract_address_const::<'NEW_OWNER'>() -} - -pub(crate) fn OTHER() -> ContractAddress { - contract_address_const::<'OTHER'>() -} - -pub(crate) fn OTHER_ADMIN() -> ContractAddress { - contract_address_const::<'OTHER_ADMIN'>() -} - -pub(crate) fn SPENDER() -> ContractAddress { - contract_address_const::<'SPENDER'>() -} - -pub(crate) fn RECIPIENT() -> ContractAddress { - contract_address_const::<'RECIPIENT'>() -} - -pub(crate) fn OPERATOR() -> ContractAddress { - contract_address_const::<'OPERATOR'>() -} - -pub(crate) fn DATA(success: bool) -> Span { - let mut data = array![]; - if success { - data.append(SUCCESS); - } else { - data.append(FAILURE); - } - data.span() -} - -pub(crate) fn EMPTY_DATA() -> Span { - array![].span() -} - -// -// Signing keys -// - -pub(crate) mod secp256k1 { - use openzeppelin::tests::utils::signing::{Secp256k1KeyPair, get_secp256k1_keys_from}; - - pub(crate) fn KEY_PAIR() -> Secp256k1KeyPair { - let private_key = u256 { low: 'PRIVATE_LOW', high: 'PRIVATE_HIGH' }; - get_secp256k1_keys_from(private_key) - } - - pub(crate) fn KEY_PAIR_2() -> Secp256k1KeyPair { - let private_key = u256 { low: 'PRIVATE_LOW_2', high: 'PRIVATE_HIGH_2' }; - get_secp256k1_keys_from(private_key) - } -} - -pub(crate) mod stark { - use openzeppelin::tests::utils::signing::{StarkKeyPair, get_stark_keys_from}; - - pub(crate) fn KEY_PAIR() -> StarkKeyPair { - get_stark_keys_from('PRIVATE_KEY') - } - - pub(crate) fn KEY_PAIR_2() -> StarkKeyPair { - get_stark_keys_from('PRIVATE_KEY_2') - } -}