diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index d1865ee43..c68479d59 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -34,8 +34,10 @@ jobs: with: starknet-foundry-version: ${{ env.FOUNDRY_VERSION }} - - name: Install cairo-coverage - run: curl -L https://raw.githubusercontent.com/software-mansion/cairo-coverage/main/scripts/install.sh | sh + # Issue with cairo-coverage. Re-add to CI once issues are fixed. + # + # - name: Install cairo-coverage + # run: curl -L https://raw.githubusercontent.com/software-mansion/cairo-coverage/main/scripts/install.sh | sh - name: Markdown lint uses: DavidAnson/markdownlint-cli2-action@eb5ca3ab411449c66620fe7f1b3c9e10547144b0 # v16 @@ -47,11 +49,16 @@ jobs: - name: Cairo lint run: scarb fmt --check --workspace - - name: Run tests and generate coverage report - run: snforge test --workspace --coverage + - name: Run tests + run: snforge test --workspace - - name: Upload coverage to Codecov - uses: codecov/codecov-action@v4 - with: - file: ./coverage.lcov - token: ${{ secrets.CODECOV_TOKEN }} + # Issue with cairo-coverage. Re-add to CI once issues are fixed. + # + # - name: Run tests and generate coverage report + # run: snforge test --workspace --coverage + # + # - name: Upload coverage to Codecov + # uses: codecov/codecov-action@v4 + # with: + # file: ./coverage.lcov + # token: ${{ secrets.CODECOV_TOKEN }} diff --git a/CHANGELOG.md b/CHANGELOG.md index 1c9cf83c6..69dfaa2fb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -30,6 +30,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed (Breaking) +- Bump snforge_std to v0.34.0 (#1239) +- Bump scarb to v2.9.1 (#1239) - The initializer in `OwnableComponent` now checks that `owner` is not the zero address (#1221) - Add `verifying_contract` member to the `Delegation` struct used in Votes `delegate_by_sig` (#1214) use crate::votes::VotesComponent::VotingUnitsTrait; diff --git a/Scarb.lock b/Scarb.lock index 3eaa94315..afe1436bd 100644 --- a/Scarb.lock +++ b/Scarb.lock @@ -51,6 +51,7 @@ dependencies = [ "openzeppelin_test_common", "openzeppelin_testing", "openzeppelin_token", + "openzeppelin_utils", "snforge_std", ] @@ -165,15 +166,15 @@ dependencies = [ [[package]] name = "snforge_scarb_plugin" -version = "0.33.0" +version = "0.34.0" source = "registry+https://scarbs.xyz/" -checksum = "sha256:b4dd6088372decd367652827091e0589bbf6bc550dfc3957baa3e9c61d6eb449" +checksum = "sha256:56f2b06ff2f0d8bbdfb7fb6c211fba7e4da6e5334ea70ba849af329a739faf11" [[package]] name = "snforge_std" -version = "0.33.0" +version = "0.34.0" source = "registry+https://scarbs.xyz/" -checksum = "sha256:f7dc3349f8a6ef4915c93df447a00bd5a53a31129fd0990a00afa0ad31d91b06" +checksum = "sha256:bd20964bde07e6fd0f7adb50d41216f05d66abd422ed82241030369333385876" dependencies = [ "snforge_scarb_plugin", ] diff --git a/Scarb.toml b/Scarb.toml index 84aa11e17..afcfd8369 100644 --- a/Scarb.toml +++ b/Scarb.toml @@ -20,12 +20,13 @@ name = "openzeppelin" readme = "README.md" version.workspace = true keywords.workspace = true +edition.workspace = true [workspace.package] version = "0.20.0-rc.0" edition = "2024_07" -cairo-version = "2.8.5" -scarb-version = "2.8.5" +cairo-version = "2.9.1" +scarb-version = "2.9.1" authors = ["OpenZeppelin Community "] description = "OpenZeppelin Contracts written in Cairo for Starknet, a decentralized ZK Rollup" documentation = "https://docs.openzeppelin.com/contracts-cairo" @@ -40,9 +41,9 @@ keywords = [ ] [workspace.dependencies] -assert_macros = "2.8.5" -starknet = "2.8.5" -snforge_std = "0.33.0" +assert_macros = "2.9.1" +starknet = "2.9.1" +snforge_std = "0.34.0" [dependencies] starknet.workspace = true diff --git a/docs/modules/ROOT/pages/index.adoc b/docs/modules/ROOT/pages/index.adoc index 7fdf5db1d..7be07d5f1 100644 --- a/docs/modules/ROOT/pages/index.adoc +++ b/docs/modules/ROOT/pages/index.adoc @@ -21,8 +21,8 @@ before proceeding, and run the following command to check that the installation ---- $ scarb --version -scarb 2.8.5 (3967bd4a6 2024-11-18) -cairo: 2.8.5 (https://crates.io/crates/cairo-lang-compiler/2.8.5) +scarb 2.9.1 (aba4f604a 2024-11-29) +cairo: 2.9.1 (https://crates.io/crates/cairo-lang-compiler/2.9.1) sierra: 1.6.0 ---- diff --git a/packages/access/src/accesscontrol/accesscontrol.cairo b/packages/access/src/accesscontrol/accesscontrol.cairo index 8966e9613..f956345ac 100644 --- a/packages/access/src/accesscontrol/accesscontrol.cairo +++ b/packages/access/src/accesscontrol/accesscontrol.cairo @@ -19,9 +19,9 @@ #[starknet::component] pub mod AccessControlComponent { use crate::accesscontrol::interface; + use openzeppelin_introspection::src5::SRC5Component; 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, StorageMapReadAccess, StorageMapWriteAccess}; @@ -48,7 +48,7 @@ pub mod AccessControlComponent { pub struct RoleGranted { pub role: felt252, pub account: ContractAddress, - pub sender: ContractAddress + pub sender: ContractAddress, } /// Emitted when `role` is revoked for `account`. @@ -60,7 +60,7 @@ pub mod AccessControlComponent { pub struct RoleRevoked { pub role: felt252, pub account: ContractAddress, - pub sender: ContractAddress + pub sender: ContractAddress, } /// Emitted when `new_admin_role` is set as `role`'s admin role, replacing `previous_admin_role` @@ -71,7 +71,7 @@ pub mod AccessControlComponent { pub struct RoleAdminChanged { pub role: felt252, pub previous_admin_role: felt252, - pub new_admin_role: felt252 + pub new_admin_role: felt252, } pub mod Errors { @@ -84,11 +84,11 @@ pub mod AccessControlComponent { TContractState, +HasComponent, +SRC5Component::HasComponent, - +Drop + +Drop, > of interface::IAccessControl> { /// Returns whether `account` has been granted `role`. fn has_role( - self: @ComponentState, role: felt252, account: ContractAddress + self: @ComponentState, role: felt252, account: ContractAddress, ) -> bool { self.AccessControl_role_member.read((role, account)) } @@ -106,7 +106,7 @@ pub mod AccessControlComponent { /// /// - The caller must have `role`'s admin role. fn grant_role( - ref self: ComponentState, role: felt252, account: ContractAddress + ref self: ComponentState, role: felt252, account: ContractAddress, ) { let admin = Self::get_role_admin(@self, role); self.assert_only_role(admin); @@ -121,7 +121,7 @@ pub mod AccessControlComponent { /// /// - The caller must have `role`'s admin role. fn revoke_role( - ref self: ComponentState, role: felt252, account: ContractAddress + ref self: ComponentState, role: felt252, account: ContractAddress, ) { let admin = Self::get_role_admin(@self, role); self.assert_only_role(admin); @@ -141,7 +141,7 @@ pub mod AccessControlComponent { /// /// - The caller must be `account`. fn renounce_role( - ref self: ComponentState, role: felt252, account: ContractAddress + ref self: ComponentState, role: felt252, account: ContractAddress, ) { let caller = get_caller_address(); assert(caller == account, Errors::INVALID_CALLER); @@ -155,10 +155,10 @@ pub mod AccessControlComponent { TContractState, +HasComponent, +SRC5Component::HasComponent, - +Drop + +Drop, > of interface::IAccessControlCamel> { fn hasRole( - self: @ComponentState, role: felt252, account: ContractAddress + self: @ComponentState, role: felt252, account: ContractAddress, ) -> bool { AccessControl::has_role(self, role, account) } @@ -168,19 +168,19 @@ pub mod AccessControlComponent { } fn grantRole( - ref self: ComponentState, role: felt252, account: ContractAddress + ref self: ComponentState, role: felt252, account: ContractAddress, ) { AccessControl::grant_role(ref self, role, account); } fn revokeRole( - ref self: ComponentState, role: felt252, account: ContractAddress + ref self: ComponentState, role: felt252, account: ContractAddress, ) { AccessControl::revoke_role(ref self, role, account); } fn renounceRole( - ref self: ComponentState, role: felt252, account: ContractAddress + ref self: ComponentState, role: felt252, account: ContractAddress, ) { AccessControl::renounce_role(ref self, role, account); } @@ -191,7 +191,7 @@ pub mod AccessControlComponent { TContractState, +HasComponent, impl SRC5: SRC5Component::HasComponent, - +Drop + +Drop, > of InternalTrait { /// Initializes the contract by registering the IAccessControl interface ID. fn initializer(ref self: ComponentState) { @@ -212,7 +212,7 @@ pub mod AccessControlComponent { /// /// Emits a `RoleAdminChanged` event. fn set_role_admin( - ref self: ComponentState, role: felt252, admin_role: felt252 + ref self: ComponentState, role: felt252, admin_role: felt252, ) { let previous_admin_role: felt252 = AccessControl::get_role_admin(@self, role); self.AccessControl_role_admin.write(role, admin_role); @@ -225,7 +225,7 @@ pub mod AccessControlComponent { /// /// May emit a `RoleGranted` event. fn _grant_role( - ref self: ComponentState, role: felt252, account: ContractAddress + ref self: ComponentState, role: felt252, account: ContractAddress, ) { if !AccessControl::has_role(@self, role, account) { let caller: ContractAddress = get_caller_address(); @@ -240,7 +240,7 @@ pub mod AccessControlComponent { /// /// May emit a `RoleRevoked` event. fn _revoke_role( - ref self: ComponentState, role: felt252, account: ContractAddress + ref self: ComponentState, role: felt252, account: ContractAddress, ) { if AccessControl::has_role(@self, role, account) { let caller: ContractAddress = get_caller_address(); @@ -255,11 +255,11 @@ pub mod AccessControlComponent { TContractState, +HasComponent, impl SRC5: SRC5Component::HasComponent, - +Drop + +Drop, > of interface::AccessControlABI> { // IAccessControl fn has_role( - self: @ComponentState, role: felt252, account: ContractAddress + self: @ComponentState, role: felt252, account: ContractAddress, ) -> bool { AccessControl::has_role(self, role, account) } @@ -269,26 +269,26 @@ pub mod AccessControlComponent { } fn grant_role( - ref self: ComponentState, role: felt252, account: ContractAddress + ref self: ComponentState, role: felt252, account: ContractAddress, ) { AccessControl::grant_role(ref self, role, account); } fn revoke_role( - ref self: ComponentState, role: felt252, account: ContractAddress + ref self: ComponentState, role: felt252, account: ContractAddress, ) { AccessControl::revoke_role(ref self, role, account); } fn renounce_role( - ref self: ComponentState, role: felt252, account: ContractAddress + ref self: ComponentState, role: felt252, account: ContractAddress, ) { AccessControl::renounce_role(ref self, role, account); } // IAccessControlCamel fn hasRole( - self: @ComponentState, role: felt252, account: ContractAddress + self: @ComponentState, role: felt252, account: ContractAddress, ) -> bool { AccessControlCamel::hasRole(self, role, account) } @@ -298,26 +298,26 @@ pub mod AccessControlComponent { } fn grantRole( - ref self: ComponentState, role: felt252, account: ContractAddress + ref self: ComponentState, role: felt252, account: ContractAddress, ) { AccessControlCamel::grantRole(ref self, role, account); } fn revokeRole( - ref self: ComponentState, role: felt252, account: ContractAddress + ref self: ComponentState, role: felt252, account: ContractAddress, ) { AccessControlCamel::revokeRole(ref self, role, account); } fn renounceRole( - ref self: ComponentState, role: felt252, account: ContractAddress + ref self: ComponentState, role: felt252, account: ContractAddress, ) { AccessControlCamel::renounceRole(ref self, role, account); } // ISRC5 fn supports_interface( - self: @ComponentState, interface_id: felt252 + self: @ComponentState, interface_id: felt252, ) -> bool { let src5 = get_dep_component!(self, SRC5); src5.supports_interface(interface_id) diff --git a/packages/access/src/ownable/ownable.cairo b/packages/access/src/ownable/ownable.cairo index c713cada4..9aeadac70 100644 --- a/packages/access/src/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 crate::ownable::interface::IOwnableTwoStep; use crate::ownable::interface; + use crate::ownable::interface::IOwnableTwoStep; use starknet::ContractAddress; use starknet::get_caller_address; use starknet::storage::{StoragePointerReadAccess, StoragePointerWriteAccess}; @@ -25,14 +25,14 @@ pub mod OwnableComponent { #[storage] pub struct Storage { pub Ownable_owner: ContractAddress, - pub Ownable_pending_owner: ContractAddress + pub Ownable_pending_owner: ContractAddress, } #[event] #[derive(Drop, PartialEq, starknet::Event)] pub enum Event { OwnershipTransferred: OwnershipTransferred, - OwnershipTransferStarted: OwnershipTransferStarted + OwnershipTransferStarted: OwnershipTransferStarted, } /// Emitted when `new_owner` is set as owner of the contract. @@ -64,7 +64,7 @@ pub mod OwnableComponent { #[embeddable_as(OwnableImpl)] impl Ownable< - TContractState, +HasComponent + TContractState, +HasComponent, > of interface::IOwnable> { /// Returns the address of the current owner. fn owner(self: @ComponentState) -> ContractAddress { @@ -80,7 +80,7 @@ pub mod OwnableComponent { /// /// Emits an `OwnershipTransferred` event. fn transfer_ownership( - ref self: ComponentState, new_owner: ContractAddress + ref self: ComponentState, new_owner: ContractAddress, ) { assert(!new_owner.is_zero(), Errors::ZERO_ADDRESS_OWNER); self.assert_only_owner(); @@ -104,7 +104,7 @@ pub mod OwnableComponent { /// Adds support for two step ownership transfer. #[embeddable_as(OwnableTwoStepImpl)] impl OwnableTwoStep< - TContractState, +HasComponent + TContractState, +HasComponent, > of interface::IOwnableTwoStep> { /// Returns the address of the current owner. fn owner(self: @ComponentState) -> ContractAddress { @@ -141,7 +141,7 @@ pub mod OwnableComponent { /// /// Emits an `OwnershipTransferStarted` event. fn transfer_ownership( - ref self: ComponentState, new_owner: ContractAddress + ref self: ComponentState, new_owner: ContractAddress, ) { self.assert_only_owner(); self._propose_owner(new_owner); @@ -164,7 +164,7 @@ pub mod OwnableComponent { /// Adds camelCase support for `IOwnable`. #[embeddable_as(OwnableCamelOnlyImpl)] impl OwnableCamelOnly< - TContractState, +HasComponent + TContractState, +HasComponent, > of interface::IOwnableCamelOnly> { fn transferOwnership(ref self: ComponentState, newOwner: ContractAddress) { Ownable::transfer_ownership(ref self, newOwner); @@ -178,7 +178,7 @@ pub mod OwnableComponent { /// Adds camelCase support for `IOwnableTwoStep`. #[embeddable_as(OwnableTwoStepCamelOnlyImpl)] impl OwnableTwoStepCamelOnly< - TContractState, +HasComponent + TContractState, +HasComponent, > of interface::IOwnableTwoStepCamelOnly> { fn pendingOwner(self: @ComponentState) -> ContractAddress { OwnableTwoStep::pending_owner(self) @@ -199,7 +199,7 @@ pub mod OwnableComponent { #[embeddable_as(OwnableMixinImpl)] impl OwnableMixin< - TContractState, +HasComponent, +Drop + TContractState, +HasComponent, +Drop, > of interface::OwnableABI> { // IOwnable fn owner(self: @ComponentState) -> ContractAddress { @@ -207,7 +207,7 @@ pub mod OwnableComponent { } fn transfer_ownership( - ref self: ComponentState, new_owner: ContractAddress + ref self: ComponentState, new_owner: ContractAddress, ) { Ownable::transfer_ownership(ref self, new_owner); } @@ -228,7 +228,7 @@ pub mod OwnableComponent { #[embeddable_as(OwnableTwoStepMixinImpl)] impl OwnableTwoStepMixin< - TContractState, +HasComponent, +Drop + TContractState, +HasComponent, +Drop, > of interface::OwnableTwoStepABI> { // IOwnableTwoStep fn owner(self: @ComponentState) -> ContractAddress { @@ -244,7 +244,7 @@ pub mod OwnableComponent { } fn transfer_ownership( - ref self: ComponentState, new_owner: ContractAddress + ref self: ComponentState, new_owner: ContractAddress, ) { OwnableTwoStep::transfer_ownership(ref self, new_owner); } @@ -273,7 +273,7 @@ pub mod OwnableComponent { #[generate_trait] pub impl InternalImpl< - TContractState, +HasComponent + TContractState, +HasComponent, > of InternalTrait { /// Sets the contract's initial owner. /// @@ -302,7 +302,7 @@ pub mod OwnableComponent { /// /// Emits an `OwnershipTransferred` event. fn _transfer_ownership( - ref self: ComponentState, new_owner: ContractAddress + ref self: ComponentState, new_owner: ContractAddress, ) { self.Ownable_pending_owner.write(Zero::zero()); diff --git a/packages/access/src/tests/test_accesscontrol.cairo b/packages/access/src/tests/test_accesscontrol.cairo index 3b09a01f7..24e427aee 100644 --- a/packages/access/src/tests/test_accesscontrol.cairo +++ b/packages/access/src/tests/test_accesscontrol.cairo @@ -1,12 +1,12 @@ use crate::accesscontrol::AccessControlComponent::{ - InternalImpl, RoleAdminChanged, RoleGranted, RoleRevoked + InternalImpl, RoleAdminChanged, RoleGranted, RoleRevoked, }; -use crate::accesscontrol::interface::{IAccessControl, IAccessControlCamel, IACCESSCONTROL_ID}; +use crate::accesscontrol::interface::{IACCESSCONTROL_ID, IAccessControl, IAccessControlCamel}; use crate::accesscontrol::{AccessControlComponent, DEFAULT_ADMIN_ROLE}; use openzeppelin_introspection::interface::ISRC5; use openzeppelin_test_common::mocks::access::DualCaseAccessControlMock; use openzeppelin_testing::constants::{ - ADMIN, AUTHORIZED, OTHER, OTHER_ADMIN, ROLE, OTHER_ROLE, ZERO + ADMIN, AUTHORIZED, OTHER, OTHER_ADMIN, OTHER_ROLE, ROLE, ZERO, }; use openzeppelin_testing::events::EventSpyExt; use snforge_std::{EventSpy, spy_events, start_cheat_caller_address, test_address}; @@ -382,7 +382,7 @@ fn test_set_role_admin() { spy .assert_only_event_role_admin_changed( - contract_address, ROLE, DEFAULT_ADMIN_ROLE, OTHER_ROLE + contract_address, ROLE, DEFAULT_ADMIN_ROLE, OTHER_ROLE, ); let current_admin_role = state.get_role_admin(ROLE); @@ -470,10 +470,10 @@ impl AccessControlSpyHelpersImpl of AccessControlSpyHelpers { contract: ContractAddress, role: felt252, account: ContractAddress, - sender: ContractAddress + sender: ContractAddress, ) { let expected = AccessControlComponent::Event::RoleRevoked( - RoleRevoked { role, account, sender } + RoleRevoked { role, account, sender }, ); self.assert_only_event(contract, expected); } @@ -483,10 +483,10 @@ impl AccessControlSpyHelpersImpl of AccessControlSpyHelpers { contract: ContractAddress, role: felt252, account: ContractAddress, - sender: ContractAddress + sender: ContractAddress, ) { let expected = AccessControlComponent::Event::RoleGranted( - RoleGranted { role, account, sender } + RoleGranted { role, account, sender }, ); self.assert_only_event(contract, expected); } @@ -496,10 +496,10 @@ impl AccessControlSpyHelpersImpl of AccessControlSpyHelpers { from_address: ContractAddress, role: felt252, previous_admin_role: felt252, - new_admin_role: felt252 + new_admin_role: felt252, ) { let expected = AccessControlComponent::Event::RoleAdminChanged( - RoleAdminChanged { role, previous_admin_role, new_admin_role } + RoleAdminChanged { role, previous_admin_role, new_admin_role }, ); self.assert_only_event(from_address, expected); } diff --git a/packages/access/src/tests/test_ownable.cairo b/packages/access/src/tests/test_ownable.cairo index 329823c81..a92124f07 100644 --- a/packages/access/src/tests/test_ownable.cairo +++ b/packages/access/src/tests/test_ownable.cairo @@ -1,11 +1,11 @@ use core::num::traits::Zero; -use crate::ownable::OwnableComponent::InternalTrait; use crate::ownable::OwnableComponent; +use crate::ownable::OwnableComponent::InternalTrait; use crate::ownable::interface::{IOwnable, IOwnableCamelOnly}; use openzeppelin_test_common::mocks::access::DualCaseOwnableMock; use openzeppelin_test_common::ownable::OwnableSpyHelpers; -use openzeppelin_testing::constants::{ZERO, OTHER, OWNER, RECIPIENT}; -use snforge_std::{spy_events, test_address, start_cheat_caller_address}; +use openzeppelin_testing::constants::{OTHER, OWNER, RECIPIENT, ZERO}; +use snforge_std::{spy_events, start_cheat_caller_address, test_address}; use starknet::storage::{StoragePointerReadAccess, StoragePointerWriteAccess}; // diff --git a/packages/access/src/tests/test_ownable_twostep.cairo b/packages/access/src/tests/test_ownable_twostep.cairo index b8ef090cd..96d651525 100644 --- a/packages/access/src/tests/test_ownable_twostep.cairo +++ b/packages/access/src/tests/test_ownable_twostep.cairo @@ -1,10 +1,10 @@ use core::num::traits::Zero; -use crate::ownable::OwnableComponent::{InternalTrait, OwnershipTransferStarted}; use crate::ownable::OwnableComponent; +use crate::ownable::OwnableComponent::{InternalTrait, OwnershipTransferStarted}; use crate::ownable::interface::{IOwnableTwoStep, IOwnableTwoStepCamelOnly}; use openzeppelin_test_common::mocks::access::DualCaseTwoStepOwnableMock; use openzeppelin_test_common::ownable::OwnableSpyHelpers; -use openzeppelin_testing::constants::{ZERO, OWNER, OTHER, NEW_OWNER}; +use openzeppelin_testing::constants::{NEW_OWNER, OTHER, OWNER, ZERO}; use openzeppelin_testing::events::EventSpyExt; use snforge_std::{EventSpy, spy_events, start_cheat_caller_address, test_address}; use starknet::ContractAddress; @@ -289,10 +289,10 @@ impl TwoStepSpyHelpersImpl of TwoStepSpyHelpers { ref self: EventSpy, from_address: ContractAddress, previous_owner: ContractAddress, - new_owner: ContractAddress + new_owner: ContractAddress, ) { let expected = OwnableComponent::Event::OwnershipTransferStarted( - OwnershipTransferStarted { previous_owner, new_owner } + OwnershipTransferStarted { previous_owner, new_owner }, ); self.assert_emitted_single(from_address, expected); } diff --git a/packages/account/src/account.cairo b/packages/account/src/account.cairo index d6872f61b..4caa4a22c 100644 --- a/packages/account/src/account.cairo +++ b/packages/account/src/account.cairo @@ -10,35 +10,35 @@ pub mod AccountComponent { use core::num::traits::Zero; use core::poseidon::PoseidonTrait; use crate::interface; - use crate::utils::{is_tx_version_valid, execute_calls, is_valid_stark_signature}; + use crate::utils::{execute_calls, is_tx_version_valid, is_valid_stark_signature}; + use openzeppelin_introspection::src5::SRC5Component; 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::storage::{StoragePointerReadAccess, StoragePointerWriteAccess}; #[storage] pub struct Storage { - pub Account_public_key: felt252 + pub Account_public_key: felt252, } #[event] #[derive(Drop, PartialEq, starknet::Event)] pub enum Event { OwnerAdded: OwnerAdded, - OwnerRemoved: OwnerRemoved + OwnerRemoved: OwnerRemoved, } #[derive(Drop, PartialEq, starknet::Event)] pub struct OwnerAdded { #[key] - pub new_owner_guid: felt252 + pub new_owner_guid: felt252, } #[derive(Drop, PartialEq, starknet::Event)] pub struct OwnerRemoved { #[key] - pub removed_owner_guid: felt252 + pub removed_owner_guid: felt252, } pub mod Errors { @@ -57,7 +57,7 @@ pub mod AccountComponent { TContractState, +HasComponent, +SRC5Component::HasComponent, - +Drop + +Drop, > of interface::ISRC6> { /// Executes a list of calls from the account. /// @@ -67,7 +67,7 @@ pub mod AccountComponent { /// - If the transaction is a simulation (version >= `QUERY_OFFSET`), it must be /// greater than or equal to `QUERY_OFFSET` + `MIN_TRANSACTION_VERSION`. fn __execute__( - self: @ComponentState, calls: Array + self: @ComponentState, calls: Array, ) -> Array> { // Avoid calls from other contracts // https://github.com/OpenZeppelin/cairo-contracts/issues/344 @@ -86,7 +86,7 @@ pub mod AccountComponent { /// Verifies that the given signature is valid for the given hash. fn is_valid_signature( - self: @ComponentState, hash: felt252, signature: Array + self: @ComponentState, hash: felt252, signature: Array, ) -> felt252 { if self._is_valid_signature(hash, signature.span()) { starknet::VALIDATED @@ -101,12 +101,12 @@ pub mod AccountComponent { TContractState, +HasComponent, +SRC5Component::HasComponent, - +Drop + +Drop, > of interface::IDeclarer> { /// Verifies the validity of the signature for the current transaction. /// This function is used by the protocol to verify `declare` transactions. fn __validate_declare__( - self: @ComponentState, class_hash: felt252 + self: @ComponentState, class_hash: felt252, ) -> felt252 { self.validate_transaction() } @@ -117,7 +117,7 @@ pub mod AccountComponent { TContractState, +HasComponent, +SRC5Component::HasComponent, - +Drop + +Drop, > of interface::IDeployable> { /// Verifies the validity of the signature for the current transaction. /// This function is used by the protocol to verify `deploy_account` transactions. @@ -125,7 +125,7 @@ pub mod AccountComponent { self: @ComponentState, class_hash: felt252, contract_address_salt: felt252, - public_key: felt252 + public_key: felt252, ) -> felt252 { self.validate_transaction() } @@ -136,7 +136,7 @@ pub mod AccountComponent { TContractState, +HasComponent, +SRC5Component::HasComponent, - +Drop + +Drop, > of interface::IPublicKey> { /// Returns the current public key of the account. fn get_public_key(self: @ComponentState) -> felt252 { @@ -154,7 +154,7 @@ pub mod AccountComponent { fn set_public_key( ref self: ComponentState, new_public_key: felt252, - signature: Span + signature: Span, ) { self.assert_only_self(); @@ -172,10 +172,10 @@ pub mod AccountComponent { TContractState, +HasComponent, +SRC5Component::HasComponent, - +Drop + +Drop, > of interface::ISRC6CamelOnly> { fn isValidSignature( - self: @ComponentState, hash: felt252, signature: Array + self: @ComponentState, hash: felt252, signature: Array, ) -> felt252 { SRC6::is_valid_signature(self, hash, signature) } @@ -187,7 +187,7 @@ pub mod AccountComponent { TContractState, +HasComponent, +SRC5Component::HasComponent, - +Drop + +Drop, > of interface::IPublicKeyCamel> { fn getPublicKey(self: @ComponentState) -> felt252 { self.Account_public_key.read() @@ -196,7 +196,7 @@ pub mod AccountComponent { fn setPublicKey( ref self: ComponentState, newPublicKey: felt252, - signature: Span + signature: Span, ) { PublicKey::set_public_key(ref self, newPublicKey, signature); } @@ -207,11 +207,11 @@ pub mod AccountComponent { TContractState, +HasComponent, impl SRC5: SRC5Component::HasComponent, - +Drop + +Drop, > of interface::AccountABI> { // ISRC6 fn __execute__( - self: @ComponentState, calls: Array + self: @ComponentState, calls: Array, ) -> Array> { SRC6::__execute__(self, calls) } @@ -221,21 +221,21 @@ pub mod AccountComponent { } fn is_valid_signature( - self: @ComponentState, hash: felt252, signature: Array + self: @ComponentState, hash: felt252, signature: Array, ) -> felt252 { SRC6::is_valid_signature(self, hash, signature) } // ISRC6CamelOnly fn isValidSignature( - self: @ComponentState, hash: felt252, signature: Array + self: @ComponentState, hash: felt252, signature: Array, ) -> felt252 { SRC6CamelOnly::isValidSignature(self, hash, signature) } // IDeclarer fn __validate_declare__( - self: @ComponentState, class_hash: felt252 + self: @ComponentState, class_hash: felt252, ) -> felt252 { Declarer::__validate_declare__(self, class_hash) } @@ -245,7 +245,7 @@ pub mod AccountComponent { self: @ComponentState, class_hash: felt252, contract_address_salt: felt252, - public_key: felt252 + public_key: felt252, ) -> felt252 { Deployable::__validate_deploy__(self, class_hash, contract_address_salt, public_key) } @@ -258,7 +258,7 @@ pub mod AccountComponent { fn set_public_key( ref self: ComponentState, new_public_key: felt252, - signature: Span + signature: Span, ) { PublicKey::set_public_key(ref self, new_public_key, signature); } @@ -271,14 +271,14 @@ pub mod AccountComponent { fn setPublicKey( ref self: ComponentState, newPublicKey: felt252, - signature: Span + signature: Span, ) { PublicKeyCamel::setPublicKey(ref self, newPublicKey, signature); } // ISRC5 fn supports_interface( - self: @ComponentState, interface_id: felt252 + self: @ComponentState, interface_id: felt252, ) -> bool { let src5 = get_dep_component!(self, SRC5); src5.supports_interface(interface_id) @@ -294,7 +294,7 @@ pub mod AccountComponent { TContractState, +HasComponent, impl SRC5: SRC5Component::HasComponent, - +Drop + +Drop, > of InternalTrait { /// Initializes the account with the given public key, and registers the ISRC6 interface ID. /// @@ -324,7 +324,7 @@ pub mod AccountComponent { self: @ComponentState, current_owner: felt252, new_owner: felt252, - signature: Span + signature: Span, ) { let message_hash = PoseidonTrait::new() .update_with('StarkNet Message') @@ -359,7 +359,7 @@ pub mod AccountComponent { /// Returns whether the given signature is valid for the given hash /// using the account's current public key. fn _is_valid_signature( - self: @ComponentState, hash: felt252, signature: Span + self: @ComponentState, hash: felt252, signature: Span, ) -> bool { let public_key = self.Account_public_key.read(); is_valid_stark_signature(hash, public_key, signature) diff --git a/packages/account/src/eth_account.cairo b/packages/account/src/eth_account.cairo index cc7ad7fd5..4b7ea638d 100644 --- a/packages/account/src/eth_account.cairo +++ b/packages/account/src/eth_account.cairo @@ -10,39 +10,39 @@ pub mod EthAccountComponent { use core::num::traits::Zero; use core::poseidon::{PoseidonTrait, poseidon_hash_span}; use core::starknet::secp256_trait::Secp256PointTrait; - use crate::interface::EthPublicKey; use crate::interface; + use crate::interface::EthPublicKey; use crate::utils::secp256_point::Secp256PointStorePacking; - use crate::utils::{is_tx_version_valid, execute_calls, is_valid_eth_signature}; + use crate::utils::{execute_calls, is_tx_version_valid, is_valid_eth_signature}; + use openzeppelin_introspection::src5::SRC5Component; 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::storage::{StoragePointerReadAccess, StoragePointerWriteAccess}; #[storage] pub struct Storage { - pub EthAccount_public_key: EthPublicKey + pub EthAccount_public_key: EthPublicKey, } #[event] #[derive(Drop, PartialEq, starknet::Event)] pub enum Event { OwnerAdded: OwnerAdded, - OwnerRemoved: OwnerRemoved + OwnerRemoved: OwnerRemoved, } #[derive(Drop, PartialEq, starknet::Event)] pub struct OwnerAdded { #[key] - pub new_owner_guid: felt252 + pub new_owner_guid: felt252, } #[derive(Drop, PartialEq, starknet::Event)] pub struct OwnerRemoved { #[key] - pub removed_owner_guid: felt252 + pub removed_owner_guid: felt252, } pub mod Errors { @@ -61,7 +61,7 @@ pub mod EthAccountComponent { TContractState, +HasComponent, +SRC5Component::HasComponent, - +Drop + +Drop, > of interface::ISRC6> { /// Executes a list of calls from the account. /// @@ -71,7 +71,7 @@ pub mod EthAccountComponent { /// - If the transaction is a simulation (version >= `QUERY_OFFSET`), it must be /// greater than or equal to `QUERY_OFFSET` + `MIN_TRANSACTION_VERSION`. fn __execute__( - self: @ComponentState, calls: Array + self: @ComponentState, calls: Array, ) -> Array> { // Avoid calls from other contracts // https://github.com/OpenZeppelin/cairo-contracts/issues/344 @@ -90,7 +90,7 @@ pub mod EthAccountComponent { /// Verifies that the given signature is valid for the given hash. fn is_valid_signature( - self: @ComponentState, hash: felt252, signature: Array + self: @ComponentState, hash: felt252, signature: Array, ) -> felt252 { if self._is_valid_signature(hash, signature.span()) { starknet::VALIDATED @@ -105,12 +105,12 @@ pub mod EthAccountComponent { TContractState, +HasComponent, +SRC5Component::HasComponent, - +Drop + +Drop, > of interface::IDeclarer> { /// Verifies the validity of the signature for the current transaction. /// This function is used by the protocol to verify `declare` transactions. fn __validate_declare__( - self: @ComponentState, class_hash: felt252 + self: @ComponentState, class_hash: felt252, ) -> felt252 { self.validate_transaction() } @@ -121,7 +121,7 @@ pub mod EthAccountComponent { TContractState, +HasComponent, +SRC5Component::HasComponent, - +Drop + +Drop, > of interface::IEthDeployable> { /// Verifies the validity of the signature for the current transaction. /// This function is used by the protocol to verify `deploy_account` transactions. @@ -129,7 +129,7 @@ pub mod EthAccountComponent { self: @ComponentState, class_hash: felt252, contract_address_salt: felt252, - public_key: EthPublicKey + public_key: EthPublicKey, ) -> felt252 { self.validate_transaction() } @@ -140,7 +140,7 @@ pub mod EthAccountComponent { TContractState, +HasComponent, +SRC5Component::HasComponent, - +Drop + +Drop, > of interface::IEthPublicKey> { /// Returns the current public key of the account. fn get_public_key(self: @ComponentState) -> EthPublicKey { @@ -158,7 +158,7 @@ pub mod EthAccountComponent { fn set_public_key( ref self: ComponentState, new_public_key: EthPublicKey, - signature: Span + signature: Span, ) { self.assert_only_self(); @@ -178,10 +178,10 @@ pub mod EthAccountComponent { TContractState, +HasComponent, +SRC5Component::HasComponent, - +Drop + +Drop, > of interface::ISRC6CamelOnly> { fn isValidSignature( - self: @ComponentState, hash: felt252, signature: Array + self: @ComponentState, hash: felt252, signature: Array, ) -> felt252 { SRC6::is_valid_signature(self, hash, signature) } @@ -193,7 +193,7 @@ pub mod EthAccountComponent { TContractState, +HasComponent, +SRC5Component::HasComponent, - +Drop + +Drop, > of interface::IEthPublicKeyCamel> { fn getPublicKey(self: @ComponentState) -> EthPublicKey { self.EthAccount_public_key.read() @@ -202,7 +202,7 @@ pub mod EthAccountComponent { fn setPublicKey( ref self: ComponentState, newPublicKey: EthPublicKey, - signature: Span + signature: Span, ) { PublicKey::set_public_key(ref self, newPublicKey, signature); } @@ -213,11 +213,11 @@ pub mod EthAccountComponent { TContractState, +HasComponent, impl SRC5: SRC5Component::HasComponent, - +Drop + +Drop, > of interface::EthAccountABI> { // ISRC6 fn __execute__( - self: @ComponentState, calls: Array + self: @ComponentState, calls: Array, ) -> Array> { SRC6::__execute__(self, calls) } @@ -227,21 +227,21 @@ pub mod EthAccountComponent { } fn is_valid_signature( - self: @ComponentState, hash: felt252, signature: Array + self: @ComponentState, hash: felt252, signature: Array, ) -> felt252 { SRC6::is_valid_signature(self, hash, signature) } // ISRC6CamelOnly fn isValidSignature( - self: @ComponentState, hash: felt252, signature: Array + self: @ComponentState, hash: felt252, signature: Array, ) -> felt252 { SRC6CamelOnly::isValidSignature(self, hash, signature) } // IDeclarer fn __validate_declare__( - self: @ComponentState, class_hash: felt252 + self: @ComponentState, class_hash: felt252, ) -> felt252 { Declarer::__validate_declare__(self, class_hash) } @@ -251,7 +251,7 @@ pub mod EthAccountComponent { self: @ComponentState, class_hash: felt252, contract_address_salt: felt252, - public_key: EthPublicKey + public_key: EthPublicKey, ) -> felt252 { Deployable::__validate_deploy__(self, class_hash, contract_address_salt, public_key) } @@ -264,7 +264,7 @@ pub mod EthAccountComponent { fn set_public_key( ref self: ComponentState, new_public_key: EthPublicKey, - signature: Span + signature: Span, ) { PublicKey::set_public_key(ref self, new_public_key, signature); } @@ -277,14 +277,14 @@ pub mod EthAccountComponent { fn setPublicKey( ref self: ComponentState, newPublicKey: EthPublicKey, - signature: Span + signature: Span, ) { PublicKeyCamel::setPublicKey(ref self, newPublicKey, signature); } // ISRC5 fn supports_interface( - self: @ComponentState, interface_id: felt252 + self: @ComponentState, interface_id: felt252, ) -> bool { let src5 = get_dep_component!(self, SRC5); src5.supports_interface(interface_id) @@ -300,7 +300,7 @@ pub mod EthAccountComponent { TContractState, +HasComponent, impl SRC5: SRC5Component::HasComponent, - +Drop + +Drop, > of InternalTrait { /// Initializes the account with the given public key, and registers the ISRC6 interface ID. /// @@ -330,7 +330,7 @@ pub mod EthAccountComponent { self: @ComponentState, current_owner: EthPublicKey, new_owner: EthPublicKey, - signature: Span + signature: Span, ) { let message_hash = PoseidonTrait::new() .update_with('StarkNet Message') @@ -366,7 +366,7 @@ pub mod EthAccountComponent { /// Returns whether the given signature is valid for the given hash /// using the account's current public key. fn _is_valid_signature( - self: @ComponentState, hash: felt252, signature: Span + self: @ComponentState, hash: felt252, signature: Span, ) -> bool { let public_key: EthPublicKey = self.EthAccount_public_key.read(); is_valid_eth_signature(hash, public_key, signature) diff --git a/packages/account/src/extensions/src9/interface.cairo b/packages/account/src/extensions/src9/interface.cairo index bd6379e13..9e95214a0 100644 --- a/packages/account/src/extensions/src9/interface.cairo +++ b/packages/account/src/extensions/src9/interface.cairo @@ -12,7 +12,7 @@ pub struct OutsideExecution { pub nonce: felt252, pub execute_after: u64, pub execute_before: u64, - pub calls: Span + pub calls: Span, } #[starknet::interface] diff --git a/packages/account/src/extensions/src9/snip12_utils.cairo b/packages/account/src/extensions/src9/snip12_utils.cairo index c4f41662c..fa0612021 100644 --- a/packages/account/src/extensions/src9/snip12_utils.cairo +++ b/packages/account/src/extensions/src9/snip12_utils.cairo @@ -1,7 +1,7 @@ // SPDX-License-Identifier: MIT // OpenZeppelin Contracts for Cairo v0.20.0-rc.0 (account/extensions/src9/snip12_utils.cairo) -use core::hash::{HashStateTrait, HashStateExTrait}; +use core::hash::{HashStateExTrait, HashStateTrait}; use core::poseidon::{PoseidonTrait, poseidon_hash_span}; use crate::extensions::src9::OutsideExecution; use openzeppelin_utils::cryptography::snip12::StructHash; diff --git a/packages/account/src/extensions/src9/src9.cairo b/packages/account/src/extensions/src9/src9.cairo index ac274df6a..711d87a5f 100644 --- a/packages/account/src/extensions/src9/src9.cairo +++ b/packages/account/src/extensions/src9/src9.cairo @@ -15,14 +15,14 @@ pub mod SRC9Component { use crate::extensions::src9::snip12_utils::OutsideExecutionStructHash; use crate::utils::execute_calls; use openzeppelin_account::interface::{ISRC6Dispatcher, ISRC6DispatcherTrait}; - use openzeppelin_introspection::src5::SRC5Component::InternalTrait as SRC5InternalTrait; use openzeppelin_introspection::src5::SRC5Component; + use openzeppelin_introspection::src5::SRC5Component::InternalTrait as SRC5InternalTrait; use openzeppelin_utils::cryptography::snip12::{OffchainMessageHash, SNIP12Metadata}; use starknet::storage::{Map, StorageMapReadAccess, StorageMapWriteAccess}; #[storage] pub struct Storage { - pub SRC9_nonces: Map + pub SRC9_nonces: Map, } pub mod Errors { @@ -52,7 +52,7 @@ pub mod SRC9Component { TContractState, +HasComponent, +SRC5Component::HasComponent, - +Drop + +Drop, > of interface::ISRC9_V2> { /// Allows anyone to submit a transaction on behalf of the account as long as they /// provide the relevant signatures. @@ -84,7 +84,7 @@ pub mod SRC9Component { if outside_execution.caller.into() != 'ANY_CALLER' { assert( starknet::get_caller_address() == outside_execution.caller, - Errors::INVALID_CALLER + Errors::INVALID_CALLER, ); } @@ -120,7 +120,7 @@ pub mod SRC9Component { /// Returns the status of a given nonce. `true` if the nonce is available to use. fn is_valid_outside_execution_nonce( - self: @ComponentState, nonce: felt252 + self: @ComponentState, nonce: felt252, ) -> bool { self.SRC9_nonces.read(nonce) == false } @@ -135,7 +135,7 @@ pub mod SRC9Component { TContractState, +HasComponent, impl SRC5: SRC5Component::HasComponent, - +Drop + +Drop, > of InternalTrait { /// Initializes the account by registering the ISRC9_V2 interface ID. fn initializer(ref self: ComponentState) { diff --git a/packages/account/src/interface.cairo b/packages/account/src/interface.cairo index 85ea5afec..bbacb095b 100644 --- a/packages/account/src/interface.cairo +++ b/packages/account/src/interface.cairo @@ -27,7 +27,7 @@ pub trait IDeclarer { #[starknet::interface] pub trait IDeployable { fn __validate_deploy__( - self: @TState, class_hash: felt252, contract_address_salt: felt252, public_key: felt252 + self: @TState, class_hash: felt252, contract_address_salt: felt252, public_key: felt252, ) -> felt252; } @@ -67,7 +67,7 @@ pub trait AccountABI { // IDeployable fn __validate_deploy__( - self: @TState, class_hash: felt252, contract_address_salt: felt252, public_key: felt252 + self: @TState, class_hash: felt252, contract_address_salt: felt252, public_key: felt252, ) -> felt252; // IPublicKey @@ -89,7 +89,10 @@ pub trait AccountABI { #[starknet::interface] pub trait IEthDeployable { fn __validate_deploy__( - self: @TState, class_hash: felt252, contract_address_salt: felt252, public_key: EthPublicKey + self: @TState, + class_hash: felt252, + contract_address_salt: felt252, + public_key: EthPublicKey, ) -> felt252; } @@ -125,7 +128,10 @@ pub trait EthAccountABI { // IEthDeployable fn __validate_deploy__( - self: @TState, class_hash: felt252, contract_address_salt: felt252, public_key: EthPublicKey + self: @TState, + class_hash: felt252, + contract_address_salt: felt252, + public_key: EthPublicKey, ) -> felt252; // IEthPublicKey diff --git a/packages/account/src/tests/extensions/test_snip12_utils.cairo b/packages/account/src/tests/extensions/test_snip12_utils.cairo index 1cf37af3a..68cf61afa 100644 --- a/packages/account/src/tests/extensions/test_snip12_utils.cairo +++ b/packages/account/src/tests/extensions/test_snip12_utils.cairo @@ -1,14 +1,14 @@ use crate::extensions::src9::interface::OutsideExecution; +use crate::extensions::src9::snip12_utils::{CALL_TYPE_HASH, OUTSIDE_EXECUTION_TYPE_HASH}; use crate::extensions::src9::snip12_utils::{CallStructHash, OutsideExecutionStructHash}; -use crate::extensions::src9::snip12_utils::{OUTSIDE_EXECUTION_TYPE_HASH, CALL_TYPE_HASH}; -use openzeppelin_testing::constants::{RECIPIENT, OWNER}; +use openzeppelin_testing::constants::{OWNER, RECIPIENT}; use snforge_std::start_cheat_chain_id_global; use starknet::account::Call; #[test] fn test_outside_execution_type_hash() { let expected = selector!( - "\"OutsideExecution\"(\"Caller\":\"ContractAddress\",\"Nonce\":\"felt\",\"Execute After\":\"u128\",\"Execute Before\":\"u128\",\"Calls\":\"Call*\")\"Call\"(\"To\":\"ContractAddress\",\"Selector\":\"selector\",\"Calldata\":\"felt*\")" + "\"OutsideExecution\"(\"Caller\":\"ContractAddress\",\"Nonce\":\"felt\",\"Execute After\":\"u128\",\"Execute Before\":\"u128\",\"Calls\":\"Call*\")\"Call\"(\"To\":\"ContractAddress\",\"Selector\":\"selector\",\"Calldata\":\"felt*\")", ); assert_eq!(OUTSIDE_EXECUTION_TYPE_HASH, expected); } @@ -16,7 +16,7 @@ fn test_outside_execution_type_hash() { #[test] fn test_call_type_hash() { let expected = selector!( - "\"Call\"(\"To\":\"ContractAddress\",\"Selector\":\"selector\",\"Calldata\":\"felt*\")" + "\"Call\"(\"To\":\"ContractAddress\",\"Selector\":\"selector\",\"Calldata\":\"felt*\")", ); assert_eq!(CALL_TYPE_HASH, expected); } @@ -58,7 +58,7 @@ fn test_outside_execution_struct_hash_generation() { let execute_before = 20; let calls = array![call].span(); let outside_execution = OutsideExecution { - caller, nonce, execute_after, execute_before, calls + caller, nonce, execute_after, execute_before, calls, }; let hash = outside_execution.hash_struct(); diff --git a/packages/account/src/tests/extensions/test_src9.cairo b/packages/account/src/tests/extensions/test_src9.cairo index 20fe1c9fc..aadea7319 100644 --- a/packages/account/src/tests/extensions/test_src9.cairo +++ b/packages/account/src/tests/extensions/test_src9.cairo @@ -1,17 +1,17 @@ -use crate::extensions::SRC9Component::{InternalImpl, OutsideExecutionV2Impl, SNIP12MetadataImpl}; use crate::extensions::SRC9Component; +use crate::extensions::SRC9Component::{InternalImpl, OutsideExecutionV2Impl, SNIP12MetadataImpl}; use crate::extensions::src9::interface::{ISRC9_V2Dispatcher, ISRC9_V2DispatcherTrait}; -use crate::extensions::src9::interface::{OutsideExecution, ISRC9_V2_ID}; +use crate::extensions::src9::interface::{ISRC9_V2_ID, OutsideExecution}; use crate::extensions::src9::snip12_utils::OutsideExecutionStructHash; use openzeppelin_introspection::interface::{ISRC5, ISRC5_ID}; use openzeppelin_test_common::mocks::src9::SRC9AccountMock; use openzeppelin_testing as utils; -use openzeppelin_testing::constants::{RECIPIENT, OWNER, OTHER, FELT_VALUE}; +use openzeppelin_testing::constants::{FELT_VALUE, OTHER, OWNER, RECIPIENT}; use openzeppelin_utils::cryptography::snip12::OffchainMessageHash; use snforge_std::signature::KeyPairTrait; use snforge_std::signature::stark_curve::{StarkCurveKeyPairImpl, StarkCurveSignerImpl}; -use snforge_std::{start_cheat_block_timestamp_global, test_address, load, CheatSpan}; -use snforge_std::{start_cheat_caller_address, cheat_caller_address}; +use snforge_std::{CheatSpan, load, start_cheat_block_timestamp_global, test_address}; +use snforge_std::{cheat_caller_address, start_cheat_caller_address}; use starknet::account::Call; use starknet::storage::StorageMapWriteAccess; use starknet::{ContractAddress, contract_address_const}; diff --git a/packages/account/src/tests/test_account.cairo b/packages/account/src/tests/test_account.cairo index dae79c71f..e5e03964e 100644 --- a/packages/account/src/tests/test_account.cairo +++ b/packages/account/src/tests/test_account.cairo @@ -1,8 +1,8 @@ use core::num::traits::Zero; +use crate::AccountComponent; use crate::AccountComponent::{InternalTrait, SRC6CamelOnlyImpl}; use crate::AccountComponent::{PublicKeyCamelImpl, PublicKeyImpl}; -use crate::AccountComponent; -use crate::interface::{AccountABIDispatcherTrait, AccountABIDispatcher}; +use crate::interface::{AccountABIDispatcher, AccountABIDispatcherTrait}; use crate::interface::{ISRC6, ISRC6_ID}; use openzeppelin_introspection::interface::{ISRC5, ISRC5_ID}; use openzeppelin_test_common::account::{AccountSpyHelpers, SignedTransactionData}; @@ -11,11 +11,11 @@ use openzeppelin_test_common::mocks::account::DualCaseAccountMock; use openzeppelin_test_common::mocks::simple::{ISimpleMockDispatcher, ISimpleMockDispatcherTrait}; use openzeppelin_testing as utils; use openzeppelin_testing::constants::stark::{KEY_PAIR, KEY_PAIR_2}; -use openzeppelin_testing::constants::{SALT, QUERY_OFFSET, QUERY_VERSION, MIN_TRANSACTION_VERSION}; -use openzeppelin_testing::constants::{ZERO, OTHER, CALLER}; +use openzeppelin_testing::constants::{CALLER, OTHER, ZERO}; +use openzeppelin_testing::constants::{MIN_TRANSACTION_VERSION, QUERY_OFFSET, QUERY_VERSION, SALT}; use openzeppelin_testing::signing::StarkKeyPair; use snforge_std::{spy_events, start_cheat_signature_global, start_cheat_transaction_hash_global}; -use snforge_std::{test_address, start_cheat_caller_address, start_cheat_transaction_version_global}; +use snforge_std::{start_cheat_caller_address, start_cheat_transaction_version_global, test_address}; use starknet::account::Call; // @@ -39,7 +39,7 @@ fn setup(key_pair: StarkKeyPair) -> ComponentState { } fn setup_dispatcher( - key_pair: StarkKeyPair, data: SignedTransactionData + key_pair: StarkKeyPair, data: SignedTransactionData, ) -> (AccountABIDispatcher, felt252) { let contract_class = utils::declare_class("DualCaseAccountMock"); @@ -200,7 +200,7 @@ fn test_execute_with_version(version: Option) { let amount = 200; let calldata = array![amount]; let call = Call { - to: contract_address, selector: selector!("increase_balance"), calldata: calldata.span() + to: contract_address, selector: selector!("increase_balance"), calldata: calldata.span(), }; let calls = array![call]; @@ -289,14 +289,14 @@ fn test_multicall() { let amount1 = 300; let calldata1 = array![amount1]; let call1 = Call { - to: contract_address, selector: selector!("increase_balance"), calldata: calldata1.span() + to: contract_address, selector: selector!("increase_balance"), calldata: calldata1.span(), }; // Craft 2nd call let amount2 = 500; let calldata2 = array![amount2]; let call2 = Call { - to: contract_address, selector: selector!("increase_balance"), calldata: calldata2.span() + to: contract_address, selector: selector!("increase_balance"), calldata: calldata2.span(), }; // Bundle calls and execute @@ -358,7 +358,7 @@ fn test_public_key_setter_and_getter() { // Set key let mut spy = spy_events(); let signature = get_accept_ownership_signature( - account_address, key_pair.public_key, new_key_pair + account_address, key_pair.public_key, new_key_pair, ); state.set_public_key(new_key_pair.public_key, signature); @@ -397,7 +397,7 @@ fn test_public_key_setter_and_getter_camel() { // Set key let mut spy = spy_events(); let signature = get_accept_ownership_signature( - account_address, key_pair.public_key, new_key_pair + account_address, key_pair.public_key, new_key_pair, ); state.setPublicKey(new_key_pair.public_key, signature); @@ -469,7 +469,7 @@ fn test_assert_valid_new_owner() { let new_key_pair = KEY_PAIR_2(); let signature = get_accept_ownership_signature( - account_address, key_pair.public_key, new_key_pair + account_address, key_pair.public_key, new_key_pair, ); state.assert_valid_new_owner(key_pair.public_key, new_key_pair.public_key, signature); diff --git a/packages/account/src/tests/test_eth_account.cairo b/packages/account/src/tests/test_eth_account.cairo index 49ae89e2a..2179f5fd8 100644 --- a/packages/account/src/tests/test_eth_account.cairo +++ b/packages/account/src/tests/test_eth_account.cairo @@ -1,25 +1,25 @@ +use crate::EthAccountComponent; use crate::EthAccountComponent::{InternalTrait, SRC6CamelOnlyImpl}; use crate::EthAccountComponent::{PublicKeyCamelImpl, PublicKeyImpl}; -use crate::EthAccountComponent; -use crate::interface::{EthAccountABIDispatcherTrait, EthAccountABIDispatcher}; +use crate::interface::{EthAccountABIDispatcher, EthAccountABIDispatcherTrait}; use crate::interface::{ISRC6, ISRC6_ID}; use crate::utils::secp256_point::{DebugSecp256Point, Secp256PointPartialEq}; use crate::utils::signature::Secp256Signature; use openzeppelin_introspection::interface::{ISRC5, ISRC5_ID}; use openzeppelin_test_common::eth_account::EthAccountSpyHelpers; use openzeppelin_test_common::eth_account::{ - SIGNED_TX_DATA, SignedTransactionData, get_accept_ownership_signature + SIGNED_TX_DATA, SignedTransactionData, get_accept_ownership_signature, }; use openzeppelin_test_common::mocks::account::DualCaseEthAccountMock; use openzeppelin_test_common::mocks::simple::{ISimpleMockDispatcher, ISimpleMockDispatcherTrait}; use openzeppelin_testing as utils; use openzeppelin_testing::constants::secp256k1::{KEY_PAIR, KEY_PAIR_2}; -use openzeppelin_testing::constants::{SALT, QUERY_VERSION, MIN_TRANSACTION_VERSION}; -use openzeppelin_testing::constants::{ZERO, OTHER, CALLER}; +use openzeppelin_testing::constants::{CALLER, OTHER, ZERO}; +use openzeppelin_testing::constants::{MIN_TRANSACTION_VERSION, QUERY_VERSION, SALT}; use openzeppelin_testing::signing::Secp256k1KeyPair; use openzeppelin_utils::serde::SerializedAppend; use snforge_std::{spy_events, start_cheat_signature_global, start_cheat_transaction_hash_global}; -use snforge_std::{test_address, start_cheat_caller_address, start_cheat_transaction_version_global}; +use snforge_std::{start_cheat_caller_address, start_cheat_transaction_version_global, test_address}; use starknet::account::Call; // @@ -43,7 +43,7 @@ fn setup(key_pair: Secp256k1KeyPair) -> ComponentState { } fn setup_dispatcher( - key_pair: Secp256k1KeyPair, data: SignedTransactionData + key_pair: Secp256k1KeyPair, data: SignedTransactionData, ) -> (EthAccountABIDispatcher, felt252) { let mut calldata = array![]; calldata.append_serde(key_pair.public_key); @@ -225,7 +225,7 @@ fn test_execute_with_version(version: Option) { let amount = 200; let calldata = array![amount]; let call = Call { - to: contract_address, selector: selector!("increase_balance"), calldata: calldata.span() + to: contract_address, selector: selector!("increase_balance"), calldata: calldata.span(), }; let calls = array![call]; @@ -298,14 +298,14 @@ fn test_multicall() { let amount1 = 300; let calldata1 = array![amount1]; let call1 = Call { - to: contract_address, selector: selector!("increase_balance"), calldata: calldata1.span() + to: contract_address, selector: selector!("increase_balance"), calldata: calldata1.span(), }; // Craft 2nd call let amount2 = 500; let calldata2 = array![amount2]; let call2 = Call { - to: contract_address, selector: selector!("increase_balance"), calldata: calldata2.span() + to: contract_address, selector: selector!("increase_balance"), calldata: calldata2.span(), }; // Bundle calls and execute @@ -386,7 +386,7 @@ fn test_public_key_setter_and_getter() { let mut spy = spy_events(); let new_key_pair = KEY_PAIR_2(); let signature = get_accept_ownership_signature( - contract_address, key_pair.public_key, new_key_pair + contract_address, key_pair.public_key, new_key_pair, ); state.set_public_key(new_key_pair.public_key, signature); @@ -407,7 +407,7 @@ fn test_public_key_setter_different_account() { let new_key_pair = KEY_PAIR_2(); let signature = get_accept_ownership_signature( - contract_address, key_pair.public_key, new_key_pair + contract_address, key_pair.public_key, new_key_pair, ); state.set_public_key(new_key_pair.public_key, signature); } @@ -430,7 +430,7 @@ fn test_public_key_setter_and_getter_camel() { let mut spy = spy_events(); let new_key_pair = KEY_PAIR_2(); let signature = get_accept_ownership_signature( - contract_address, key_pair.public_key, new_key_pair + contract_address, key_pair.public_key, new_key_pair, ); state.setPublicKey(new_key_pair.public_key, signature); @@ -451,7 +451,7 @@ fn test_public_key_setter_different_account_camel() { let new_key_pair = KEY_PAIR_2(); let signature = get_accept_ownership_signature( - contract_address, key_pair.public_key, new_key_pair + contract_address, key_pair.public_key, new_key_pair, ); state.setPublicKey(new_key_pair.public_key, signature); } @@ -505,7 +505,7 @@ fn test_assert_valid_new_owner() { let new_key_pair = KEY_PAIR_2(); let signature = get_accept_ownership_signature( - contract_address, key_pair.public_key, new_key_pair + contract_address, key_pair.public_key, new_key_pair, ); state.assert_valid_new_owner(key_pair.public_key, new_key_pair.public_key, signature); diff --git a/packages/account/src/tests/test_secp256_point.cairo b/packages/account/src/tests/test_secp256_point.cairo index 20ad7a217..5c9f082e5 100644 --- a/packages/account/src/tests/test_secp256_point.cairo +++ b/packages/account/src/tests/test_secp256_point.cairo @@ -1,8 +1,8 @@ use crate::utils::secp256_point::{ - DebugSecp256Point, Secp256PointPartialEq, Secp256PointStorePacking as StorePacking + DebugSecp256Point, Secp256PointPartialEq, Secp256PointStorePacking as StorePacking, }; use starknet::SyscallResultTrait; -use starknet::secp256_trait::{Secp256Trait, Secp256PointTrait}; +use starknet::secp256_trait::{Secp256PointTrait, Secp256Trait}; use starknet::secp256k1::Secp256k1Point; #[test] @@ -15,7 +15,7 @@ fn test_pack_big_secp256k1_points() { let xhigh_and_parity: u256 = xhigh_and_parity.into(); let x = u256 { - low: xlow.try_into().unwrap(), high: (xhigh_and_parity / 2).try_into().unwrap() + low: xlow.try_into().unwrap(), high: (xhigh_and_parity / 2).try_into().unwrap(), }; let parity = xhigh_and_parity % 2 == 1; @@ -27,7 +27,7 @@ fn test_pack_big_secp256k1_points() { let xhigh_and_parity: u256 = xhigh_and_parity.into(); let x = u256 { - low: xlow.try_into().unwrap(), high: (xhigh_and_parity / 2).try_into().unwrap() + low: xlow.try_into().unwrap(), high: (xhigh_and_parity / 2).try_into().unwrap(), }; let parity = xhigh_and_parity % 2 == 1; diff --git a/packages/account/src/tests/test_signature.cairo b/packages/account/src/tests/test_signature.cairo index 0d6e9d648..a9ac26b5a 100644 --- a/packages/account/src/tests/test_signature.cairo +++ b/packages/account/src/tests/test_signature.cairo @@ -1,11 +1,11 @@ use crate::interface::P256PublicKey; use crate::utils::signature::{ - is_valid_stark_signature, is_valid_eth_signature, is_valid_p256_signature + is_valid_eth_signature, is_valid_p256_signature, is_valid_stark_signature, }; use openzeppelin_account::utils::signature::Secp256Signature; use openzeppelin_test_common::account::SIGNED_TX_DATA as stark_signature_data; use openzeppelin_test_common::eth_account::SIGNED_TX_DATA as eth_signature_data; -use openzeppelin_testing::constants::{TRANSACTION_HASH, stark, secp256k1, secp256r1}; +use openzeppelin_testing::constants::{TRANSACTION_HASH, secp256k1, secp256r1, stark}; use openzeppelin_testing::signing::{Secp256r1KeyPair, Secp256r1SerializedSigning}; use snforge_std::signature::secp256r1_curve::Secp256r1CurveSignerImpl; use starknet::secp256_trait::Secp256Trait; @@ -59,7 +59,7 @@ fn test_is_valid_eth_signature_good_sig() { data.signature.serialize(ref serialized_good_signature); let is_valid = is_valid_eth_signature( - data.tx_hash, key_pair.public_key, serialized_good_signature.span() + data.tx_hash, key_pair.public_key, serialized_good_signature.span(), ); assert!(is_valid); } @@ -77,7 +77,7 @@ fn test_is_valid_eth_signature_bad_sig() { bad_signature.serialize(ref serialized_bad_signature); let is_invalid = !is_valid_eth_signature( - data.tx_hash, key_pair.public_key, serialized_bad_signature.span() + data.tx_hash, key_pair.public_key, serialized_bad_signature.span(), ); assert!(is_invalid); } @@ -107,7 +107,7 @@ fn test_eth_signature_r_out_of_range() { bad_signature.serialize(ref serialized_bad_signature); let is_invalid = !is_valid_eth_signature( - data.tx_hash, key_pair.public_key, serialized_bad_signature.span() + data.tx_hash, key_pair.public_key, serialized_bad_signature.span(), ); assert!(is_invalid); } @@ -127,7 +127,7 @@ fn test_eth_signature_s_out_of_range() { bad_signature.serialize(ref serialized_bad_signature); let is_invalid = !is_valid_eth_signature( - data.tx_hash, key_pair.public_key, serialized_bad_signature.span() + data.tx_hash, key_pair.public_key, serialized_bad_signature.span(), ); assert!(is_invalid); } @@ -141,7 +141,7 @@ pub struct SignedTransactionData { pub private_key: u256, pub public_key: P256PublicKey, pub tx_hash: felt252, - pub signature: Secp256Signature + pub signature: Secp256Signature, } fn p256_signature_data(key_pair: Secp256r1KeyPair) -> SignedTransactionData { @@ -151,7 +151,7 @@ fn p256_signature_data(key_pair: Secp256r1KeyPair) -> SignedTransactionData { private_key: key_pair.secret_key, public_key: key_pair.public_key, tx_hash, - signature: Secp256Signature { r, s } + signature: Secp256Signature { r, s }, } } @@ -164,7 +164,7 @@ fn test_is_valid_p256_signature_good_sig() { data.signature.serialize(ref serialized_good_signature); let is_valid = is_valid_p256_signature( - data.tx_hash, key_pair.public_key, serialized_good_signature.span() + data.tx_hash, key_pair.public_key, serialized_good_signature.span(), ); assert!(is_valid); } @@ -182,7 +182,7 @@ fn test_is_valid_p256_signature_bad_sig() { bad_signature.serialize(ref serialized_bad_signature); let is_invalid = !is_valid_p256_signature( - data.tx_hash, key_pair.public_key, serialized_bad_signature.span() + data.tx_hash, key_pair.public_key, serialized_bad_signature.span(), ); assert!(is_invalid); } @@ -212,7 +212,7 @@ fn test_p256_signature_r_out_of_range() { bad_signature.serialize(ref serialized_bad_signature); let is_invalid = !is_valid_p256_signature( - data.tx_hash, key_pair.public_key, serialized_bad_signature.span() + data.tx_hash, key_pair.public_key, serialized_bad_signature.span(), ); assert!(is_invalid); } @@ -232,7 +232,7 @@ fn test_p256_signature_s_out_of_range() { bad_signature.serialize(ref serialized_bad_signature); let is_invalid = !is_valid_p256_signature( - data.tx_hash, key_pair.public_key, serialized_bad_signature.span() + data.tx_hash, key_pair.public_key, serialized_bad_signature.span(), ); assert!(is_invalid); } diff --git a/packages/account/src/utils.cairo b/packages/account/src/utils.cairo index 0b59263ae..38833d00e 100644 --- a/packages/account/src/utils.cairo +++ b/packages/account/src/utils.cairo @@ -4,7 +4,7 @@ pub mod secp256_point; pub mod signature; -pub use signature::{is_valid_stark_signature, is_valid_eth_signature, is_valid_p256_signature}; +pub use signature::{is_valid_eth_signature, is_valid_p256_signature, is_valid_stark_signature}; use starknet::SyscallResultTrait; use starknet::account::Call; diff --git a/packages/account/src/utils/secp256_point.cairo b/packages/account/src/utils/secp256_point.cairo index 65fab78c4..0241f271e 100644 --- a/packages/account/src/utils/secp256_point.cairo +++ b/packages/account/src/utils/secp256_point.cairo @@ -1,9 +1,9 @@ // SPDX-License-Identifier: MIT // OpenZeppelin Contracts for Cairo v0.20.0-rc.0 (account/utils/secp256_point.cairo) -use core::fmt::{Formatter, Error}; +use core::fmt::{Error, Formatter}; use starknet::SyscallResultTrait; -use starknet::secp256_trait::{Secp256Trait, Secp256PointTrait}; +use starknet::secp256_trait::{Secp256PointTrait, Secp256Trait}; use starknet::storage_access::StorePacking; /// Packs a Secp256Point into a (felt252, felt252). @@ -14,7 +14,7 @@ use starknet::storage_access::StorePacking; /// - Second felt contains x.high and the parity bit, at the least significant bits (2 * x.high + /// parity). pub impl Secp256PointStorePacking< - Secp256Point, +Secp256Trait, +Secp256PointTrait + Secp256Point, +Secp256Trait, +Secp256PointTrait, > of StorePacking { fn pack(value: Secp256Point) -> (felt252, felt252) { let (x, y) = value.get_coordinates().unwrap_syscall(); @@ -43,7 +43,7 @@ pub impl Secp256PointStorePacking< } pub impl Secp256PointPartialEq< - Secp256Point, +Secp256PointTrait, +Copy + Secp256Point, +Secp256PointTrait, +Copy, > of PartialEq { #[inline(always)] fn eq(lhs: @Secp256Point, rhs: @Secp256Point) -> bool { @@ -56,7 +56,7 @@ pub impl Secp256PointPartialEq< } pub impl DebugSecp256Point< - Secp256Point, +Secp256PointTrait, +Copy + Secp256Point, +Secp256PointTrait, +Copy, > of core::fmt::Debug { fn fmt(self: @Secp256Point, ref f: Formatter) -> Result<(), Error> { let (x, y) = (*self).get_coordinates().unwrap_syscall(); diff --git a/packages/account/src/utils/signature.cairo b/packages/account/src/utils/signature.cairo index 4488dfc96..512078e5a 100644 --- a/packages/account/src/utils/signature.cairo +++ b/packages/account/src/utils/signature.cairo @@ -3,8 +3,8 @@ use core::ecdsa::check_ecdsa_signature; use crate::interface::{EthPublicKey, P256PublicKey}; -use starknet::secp256_trait::{Secp256Trait, Secp256PointTrait}; use starknet::secp256_trait; +use starknet::secp256_trait::{Secp256PointTrait, Secp256Trait}; /// A signature format compatible with the family of secp256 curves. #[derive(Copy, Drop, Serde)] @@ -19,7 +19,7 @@ pub struct Secp256Signature { /// it's not protected against signature malleability. /// See https://github.com/OpenZeppelin/cairo-contracts/issues/889. pub fn is_valid_stark_signature( - msg_hash: felt252, public_key: felt252, signature: Span + msg_hash: felt252, public_key: felt252, signature: Span, ) -> bool { let valid_length = signature.len() == 2; @@ -36,7 +36,7 @@ pub fn is_valid_stark_signature( /// it's not protected against signature malleability. /// See https://github.com/OpenZeppelin/cairo-contracts/issues/889. pub fn is_valid_eth_signature( - msg_hash: felt252, public_key: EthPublicKey, signature: Span + msg_hash: felt252, public_key: EthPublicKey, signature: Span, ) -> bool { is_valid_secp256_signature(msg_hash, public_key, signature) } @@ -47,16 +47,19 @@ pub fn is_valid_eth_signature( /// it's not protected against signature malleability. /// See https://github.com/OpenZeppelin/cairo-contracts/issues/889. pub fn is_valid_p256_signature( - msg_hash: felt252, public_key: P256PublicKey, signature: Span + msg_hash: felt252, public_key: P256PublicKey, signature: Span, ) -> bool { is_valid_secp256_signature(msg_hash, public_key, signature) } /// Verifies a Secp256 compatible signature for a valid point in the corresponding curve. fn is_valid_secp256_signature< - Secp256Point, +Secp256Trait, +Secp256PointTrait, +Drop + Secp256Point, + +Secp256Trait, + +Secp256PointTrait, + +Drop, >( - msg_hash: felt252, public_key: Secp256Point, signature: Span + msg_hash: felt252, public_key: Secp256Point, signature: Span, ) -> bool { let mut signature = signature; let signature: Secp256Signature = Serde::deserialize(ref signature) diff --git a/packages/finance/Scarb.toml b/packages/finance/Scarb.toml index 6b357bdce..70756a724 100644 --- a/packages/finance/Scarb.toml +++ b/packages/finance/Scarb.toml @@ -30,6 +30,7 @@ openzeppelin_token = { path = "../token" } snforge_std.workspace = true openzeppelin_testing = { path = "../testing" } openzeppelin_test_common = { path = "../test_common" } +openzeppelin_utils = { path = "../utils" } [lib] diff --git a/packages/finance/src/tests/common.cairo b/packages/finance/src/tests/common.cairo index bad9056f6..e6e93524f 100644 --- a/packages/finance/src/tests/common.cairo +++ b/packages/finance/src/tests/common.cairo @@ -8,7 +8,7 @@ use starknet::{ContractAddress, SyscallResultTrait}; #[derive(Copy, Drop)] pub(crate) enum VestingStrategy { Linear, - Steps: u64 + Steps: u64, } #[derive(Copy, Drop)] @@ -18,7 +18,7 @@ pub(crate) struct TestData { pub beneficiary: ContractAddress, pub start: u64, pub duration: u64, - pub cliff_duration: u64 + pub cliff_duration: u64, } fn deploy_vesting_mock(data: TestData) -> IVestingDispatcher { @@ -39,7 +39,7 @@ fn deploy_vesting_mock(data: TestData) -> IVestingDispatcher { calldata.append_serde(data.duration); calldata.append_serde(data.cliff_duration); utils::declare_and_deploy("StepsVestingMock", calldata) - } + }, }; IVestingDispatcher { contract_address } } @@ -65,7 +65,7 @@ pub(crate) fn set_transfer_to_fail(token: ContractAddress, should_fail: bool) { let mut calldata = array![]; calldata.append_serde(true); starknet::syscalls::call_contract_syscall( - token, selector!("set_transfer_should_fail"), calldata.span() + token, selector!("set_transfer_should_fail"), calldata.span(), ) .unwrap_syscall(); } diff --git a/packages/finance/src/tests/test_vesting_linear.cairo b/packages/finance/src/tests/test_vesting_linear.cairo index 60987ba36..3f7850edf 100644 --- a/packages/finance/src/tests/test_vesting_linear.cairo +++ b/packages/finance/src/tests/test_vesting_linear.cairo @@ -1,14 +1,14 @@ -use crate::tests::common::{VestingStrategy, TestData, setup, set_transfer_to_fail}; -use crate::vesting::VestingComponent::InternalImpl; +use crate::tests::common::{TestData, VestingStrategy, set_transfer_to_fail, setup}; use crate::vesting::VestingComponent; +use crate::vesting::VestingComponent::InternalImpl; use crate::vesting::interface::IVestingDispatcherTrait; use openzeppelin_access::ownable::interface::{IOwnableDispatcher, IOwnableDispatcherTrait}; use openzeppelin_test_common::mocks::vesting::LinearVestingMock; use openzeppelin_test_common::vesting::VestingSpyHelpers; -use openzeppelin_testing::constants::{OWNER, OTHER}; +use openzeppelin_testing::constants::{OTHER, OWNER}; use openzeppelin_testing::events::EventSpyExt; use openzeppelin_token::erc20::interface::{IERC20Dispatcher, IERC20DispatcherTrait}; -use snforge_std::{spy_events, start_cheat_caller_address, start_cheat_block_timestamp_global}; +use snforge_std::{spy_events, start_cheat_block_timestamp_global, start_cheat_caller_address}; // // Setup @@ -27,7 +27,7 @@ fn TEST_DATA() -> TestData { beneficiary: OWNER(), start: 30, duration: 100, - cliff_duration: 0 + cliff_duration: 0, } } diff --git a/packages/finance/src/tests/test_vesting_steps.cairo b/packages/finance/src/tests/test_vesting_steps.cairo index a1ec4cbfc..24941589e 100644 --- a/packages/finance/src/tests/test_vesting_steps.cairo +++ b/packages/finance/src/tests/test_vesting_steps.cairo @@ -1,13 +1,13 @@ -use crate::tests::common::{VestingStrategy, TestData, setup, set_transfer_to_fail}; -use crate::vesting::VestingComponent::InternalImpl; +use crate::tests::common::{TestData, VestingStrategy, set_transfer_to_fail, setup}; use crate::vesting::VestingComponent; +use crate::vesting::VestingComponent::InternalImpl; use crate::vesting::interface::IVestingDispatcherTrait; use openzeppelin_access::ownable::interface::{IOwnableDispatcher, IOwnableDispatcherTrait}; use openzeppelin_test_common::mocks::vesting::StepsVestingMock; use openzeppelin_test_common::vesting::VestingSpyHelpers; -use openzeppelin_testing::constants::{OWNER, OTHER}; +use openzeppelin_testing::constants::{OTHER, OWNER}; use openzeppelin_token::erc20::interface::{IERC20Dispatcher, IERC20DispatcherTrait}; -use snforge_std::{spy_events, start_cheat_caller_address, start_cheat_block_timestamp_global}; +use snforge_std::{spy_events, start_cheat_block_timestamp_global, start_cheat_caller_address}; // // Setup @@ -28,7 +28,7 @@ fn TEST_DATA() -> TestData { beneficiary: OWNER(), start: 30, duration: 100, - cliff_duration: 0 + cliff_duration: 0, } } diff --git a/packages/finance/src/vesting.cairo b/packages/finance/src/vesting.cairo index 1f05a8efe..b74d7f544 100644 --- a/packages/finance/src/vesting.cairo +++ b/packages/finance/src/vesting.cairo @@ -1,4 +1,4 @@ pub mod interface; pub mod vesting; -pub use vesting::{VestingComponent, LinearVestingSchedule}; +pub use vesting::{LinearVestingSchedule, VestingComponent}; diff --git a/packages/finance/src/vesting/vesting.cairo b/packages/finance/src/vesting/vesting.cairo index e1b7205ab..5364cd360 100644 --- a/packages/finance/src/vesting/vesting.cairo +++ b/packages/finance/src/vesting/vesting.cairo @@ -30,8 +30,8 @@ use starknet::ContractAddress; #[starknet::component] pub mod VestingComponent { use crate::vesting::interface; - use openzeppelin_access::ownable::OwnableComponent::OwnableImpl; use openzeppelin_access::ownable::OwnableComponent; + use openzeppelin_access::ownable::OwnableComponent::OwnableImpl; use openzeppelin_token::erc20::interface::{IERC20Dispatcher, IERC20DispatcherTrait}; use starknet::ContractAddress; use starknet::storage::{Map, StorageMapReadAccess, StorageMapWriteAccess}; @@ -42,13 +42,13 @@ pub mod VestingComponent { pub Vesting_start: u64, pub Vesting_duration: u64, pub Vesting_cliff: u64, - pub Vesting_released: Map + pub Vesting_released: Map, } #[event] #[derive(Drop, PartialEq, starknet::Event)] pub enum Event { - AmountReleased: AmountReleased + AmountReleased: AmountReleased, } /// Emitted when vested tokens are released to the beneficiary. @@ -88,7 +88,7 @@ pub mod VestingComponent { TContractState, +HasComponent, impl Ownable: OwnableComponent::HasComponent, - +VestingScheduleTrait + +VestingScheduleTrait, > of interface::IVesting> { /// Returns the timestamp marking the beginning of the vesting period. fn start(self: @ComponentState) -> u64 { @@ -129,7 +129,7 @@ pub mod VestingComponent { /// Returns the total vested amount of a specified `token` at a given `timestamp`. fn vested_amount( - self: @ComponentState, token: ContractAddress, timestamp: u64 + self: @ComponentState, token: ContractAddress, timestamp: u64, ) -> u256 { self.resolve_vested_amount(token, timestamp) } @@ -153,7 +153,7 @@ pub mod VestingComponent { let beneficiary = get_dep_component!(@self, Ownable).owner(); let token_dispatcher = IERC20Dispatcher { contract_address: token }; assert( - token_dispatcher.transfer(beneficiary, amount), Errors::TOKEN_TRANSFER_FAILED + token_dispatcher.transfer(beneficiary, amount), Errors::TOKEN_TRANSFER_FAILED, ); } amount @@ -164,7 +164,7 @@ pub mod VestingComponent { pub impl InternalImpl< TContractState, +HasComponent, - impl VestingSchedule: VestingScheduleTrait + impl VestingSchedule: VestingScheduleTrait, > of InternalTrait { /// Initializes the component by setting the vesting `start`, `duration` and /// `cliff_duration`. @@ -173,7 +173,10 @@ pub mod VestingComponent { /// /// - `cliff_duration` must be less than or equal to `duration`. fn initializer( - ref self: ComponentState, start: u64, duration: u64, cliff_duration: u64 + ref self: ComponentState, + start: u64, + duration: u64, + cliff_duration: u64, ) { self.Vesting_start.write(start); self.Vesting_duration.write(duration); @@ -185,7 +188,7 @@ pub mod VestingComponent { /// Returns the vested amount that's calculated using the `VestingScheduleTrait` /// implementation. fn resolve_vested_amount( - self: @ComponentState, token: ContractAddress, timestamp: u64 + self: @ComponentState, token: ContractAddress, timestamp: u64, ) -> u256 { let released_amount = self.Vesting_released.read(token); let token_dispatcher = IERC20Dispatcher { contract_address: token }; @@ -198,7 +201,7 @@ pub mod VestingComponent { timestamp, self.Vesting_start.read(), self.Vesting_duration.read(), - self.Vesting_cliff.read() + self.Vesting_cliff.read(), ); vested_amount } @@ -209,7 +212,7 @@ pub mod VestingComponent { /// It returns 0 before the cliff ends. After the cliff period, the vested amount returned /// is directly proportional to the time passed since the start of the vesting schedule. pub impl LinearVestingSchedule< - TContractState + TContractState, > of VestingComponent::VestingScheduleTrait { fn calculate_vested_amount( self: @VestingComponent::ComponentState, diff --git a/packages/governance/src/governor.cairo b/packages/governance/src/governor.cairo index 4d2442162..0f2980a70 100644 --- a/packages/governance/src/governor.cairo +++ b/packages/governance/src/governor.cairo @@ -4,5 +4,5 @@ pub mod interface; pub mod proposal_core; pub mod vote; -pub use governor::{GovernorComponent, DefaultConfig}; +pub use governor::{DefaultConfig, GovernorComponent}; pub use proposal_core::ProposalCore; diff --git a/packages/governance/src/governor/extensions/governor_core_execution.cairo b/packages/governance/src/governor/extensions/governor_core_execution.cairo index 87cf2b2cc..86d3cb74e 100644 --- a/packages/governance/src/governor/extensions/governor_core_execution.cairo +++ b/packages/governance/src/governor/extensions/governor_core_execution.cairo @@ -9,10 +9,10 @@ /// GovernorTimelockExecutionComponent. #[starknet::component] pub mod GovernorCoreExecutionComponent { + use crate::governor::GovernorComponent; use crate::governor::GovernorComponent::{ - InternalExtendedTrait, ComponentState as GovernorComponentState + ComponentState as GovernorComponentState, InternalExtendedTrait, }; - use crate::governor::GovernorComponent; use crate::governor::interface::ProposalState; use openzeppelin_introspection::src5::SRC5Component; use starknet::account::Call; @@ -33,7 +33,7 @@ pub mod GovernorCoreExecutionComponent { +GovernorComponent::GovernorVotesTrait, +SRC5Component::HasComponent, impl GovernorCoreExecution: HasComponent, - +Drop + +Drop, > of GovernorComponent::GovernorExecutionTrait { /// See `GovernorComponent::GovernorExecutionTrait::state`. /// @@ -41,7 +41,7 @@ pub mod GovernorCoreExecutionComponent { /// /// - The proposal must exist. fn state( - self: @GovernorComponentState, proposal_id: felt252 + self: @GovernorComponentState, proposal_id: felt252, ) -> ProposalState { self._state(proposal_id) } @@ -60,7 +60,7 @@ pub mod GovernorCoreExecutionComponent { ref self: GovernorComponentState, proposal_id: felt252, calls: Span, - description_hash: felt252 + description_hash: felt252, ) { for call in calls { let Call { to, selector, calldata } = *call; @@ -75,7 +75,7 @@ pub mod GovernorCoreExecutionComponent { ref self: GovernorComponentState, proposal_id: felt252, calls: Span, - description_hash: felt252 + description_hash: felt252, ) -> u64 { 0 } @@ -84,7 +84,7 @@ pub mod GovernorCoreExecutionComponent { /// /// In this implementation, it always returns false. fn proposal_needs_queuing( - self: @GovernorComponentState, proposal_id: felt252 + self: @GovernorComponentState, proposal_id: felt252, ) -> bool { false } @@ -93,7 +93,7 @@ pub mod GovernorCoreExecutionComponent { fn cancel_operations( ref self: GovernorComponentState, proposal_id: felt252, - description_hash: felt252 + description_hash: felt252, ) { self._cancel(proposal_id, description_hash); } diff --git a/packages/governance/src/governor/extensions/governor_counting_simple.cairo b/packages/governance/src/governor/extensions/governor_counting_simple.cairo index 0125b9213..e2832fe0a 100644 --- a/packages/governance/src/governor/extensions/governor_counting_simple.cairo +++ b/packages/governance/src/governor/extensions/governor_counting_simple.cairo @@ -7,13 +7,13 @@ /// Extension of GovernorComponent for simple vote counting with three options. #[starknet::component] pub mod GovernorCountingSimpleComponent { + use crate::governor::GovernorComponent; use crate::governor::GovernorComponent::{ - InternalTrait, ComponentState as GovernorComponentState + ComponentState as GovernorComponentState, InternalTrait, }; - use crate::governor::GovernorComponent; use openzeppelin_introspection::src5::SRC5Component; use starknet::ContractAddress; - use starknet::storage::{Map, StoragePathEntry, StorageMapReadAccess, StorageMapWriteAccess}; + use starknet::storage::{Map, StorageMapReadAccess, StorageMapWriteAccess, StoragePathEntry}; use starknet::storage::{StoragePointerReadAccess, StoragePointerWriteAccess}; type ProposalId = felt252; @@ -28,7 +28,7 @@ pub mod GovernorCountingSimpleComponent { pub enum VoteType { Against, For, - Abstain + Abstain, } impl U8TryIntoVoteType of TryInto { @@ -47,7 +47,7 @@ pub mod GovernorCountingSimpleComponent { match self { VoteType::Against => 0, VoteType::For => 1, - VoteType::Abstain => 2 + VoteType::Abstain => 2, } } } @@ -57,7 +57,7 @@ pub mod GovernorCountingSimpleComponent { pub against_votes: u256, pub for_votes: u256, pub abstain_votes: u256, - pub has_voted: Map + pub has_voted: Map, } pub mod Errors { @@ -75,7 +75,7 @@ pub mod GovernorCountingSimpleComponent { +GovernorComponent::GovernorQuorumTrait, +SRC5Component::HasComponent, impl GovernorCountingSimple: HasComponent, - +Drop + +Drop, > of GovernorComponent::GovernorCountingTrait { /// See `GovernorComponent::GovernorCountingTrait::counting_mode`. fn counting_mode(self: @GovernorComponentState) -> ByteArray { @@ -91,7 +91,7 @@ pub mod GovernorCountingSimpleComponent { account: ContractAddress, support: u8, total_weight: u256, - params: Span + params: Span, ) -> u256 { let mut contract = self.get_contract_mut(); let mut this_component = GovernorCountingSimple::get_component_mut(ref contract); @@ -114,7 +114,7 @@ pub mod GovernorCountingSimpleComponent { VoteType::Abstain => { let current_votes = proposal_votes.abstain_votes.read(); proposal_votes.abstain_votes.write(current_votes + total_weight); - } + }, } total_weight } @@ -123,7 +123,7 @@ pub mod GovernorCountingSimpleComponent { fn has_voted( self: @GovernorComponentState, proposal_id: felt252, - account: ContractAddress + account: ContractAddress, ) -> bool { let contract = self.get_contract(); let this_component = GovernorCountingSimple::get_component(contract); @@ -136,7 +136,7 @@ pub mod GovernorCountingSimpleComponent { /// /// In this implementation, both For and Abstain votes count toward quorum. fn quorum_reached( - self: @GovernorComponentState, proposal_id: felt252 + self: @GovernorComponentState, proposal_id: felt252, ) -> bool { let contract = self.get_contract(); let this_component = GovernorCountingSimple::get_component(contract); @@ -152,7 +152,7 @@ pub mod GovernorCountingSimpleComponent { /// /// In this module, the `for_votes` must be strictly over the `against_votes`. fn vote_succeeded( - self: @GovernorComponentState, proposal_id: felt252 + self: @GovernorComponentState, proposal_id: felt252, ) -> bool { let contract = self.get_contract(); let this_component = GovernorCountingSimple::get_component(contract); diff --git a/packages/governance/src/governor/extensions/governor_settings.cairo b/packages/governance/src/governor/extensions/governor_settings.cairo index 1b8611fa0..463108136 100644 --- a/packages/governance/src/governor/extensions/governor_settings.cairo +++ b/packages/governance/src/governor/extensions/governor_settings.cairo @@ -7,10 +7,10 @@ /// Extension of GovernorComponent for settings that are updatable through governance. #[starknet::component] pub mod GovernorSettingsComponent { + use crate::governor::GovernorComponent; use crate::governor::GovernorComponent::{ - InternalExtendedTrait, ComponentState as GovernorComponentState + ComponentState as GovernorComponentState, InternalExtendedTrait, }; - use crate::governor::GovernorComponent; use crate::governor::extensions::interface::IGovernorSettingsAdmin; use openzeppelin_introspection::src5::SRC5Component; use starknet::storage::{StoragePointerReadAccess, StoragePointerWriteAccess}; @@ -27,28 +27,28 @@ pub mod GovernorSettingsComponent { pub enum Event { VotingDelayUpdated: VotingDelayUpdated, VotingPeriodUpdated: VotingPeriodUpdated, - ProposalThresholdUpdated: ProposalThresholdUpdated + ProposalThresholdUpdated: ProposalThresholdUpdated, } /// Emitted when `Governor_voting_delay` is updated. #[derive(Drop, starknet::Event)] pub struct VotingDelayUpdated { pub old_voting_delay: u64, - pub new_voting_delay: u64 + pub new_voting_delay: u64, } /// Emitted when `Governor_voting_period` is updated. #[derive(Drop, starknet::Event)] pub struct VotingPeriodUpdated { pub old_voting_period: u64, - pub new_voting_period: u64 + pub new_voting_period: u64, } /// Emitted when `Governor_proposal_threshold` is updated. #[derive(Drop, starknet::Event)] pub struct ProposalThresholdUpdated { pub old_proposal_threshold: u256, - pub new_proposal_threshold: u256 + pub new_proposal_threshold: u256, } pub mod Errors { @@ -64,7 +64,7 @@ pub mod GovernorSettingsComponent { +GovernorComponent::HasComponent, +SRC5Component::HasComponent, impl GovernorSettings: HasComponent, - +Drop + +Drop, > of GovernorComponent::GovernorSettingsTrait { /// See `GovernorComponent::GovernorSettingsTrait::voting_delay`. fn voting_delay(self: @GovernorComponentState) -> u64 { @@ -104,7 +104,7 @@ pub mod GovernorSettingsComponent { +GovernorComponent::GovernorExecutionTrait, +GovernorComponent::GovernorVotesTrait, +SRC5Component::HasComponent, - +Drop + +Drop, > of IGovernorSettingsAdmin> { /// Sets the voting delay. /// @@ -148,7 +148,7 @@ pub mod GovernorSettingsComponent { /// /// May emit a `ProposalThresholdUpdated` event. fn set_proposal_threshold( - ref self: ComponentState, new_proposal_threshold: u256 + ref self: ComponentState, new_proposal_threshold: u256, ) { self.assert_only_governance(); self._set_proposal_threshold(new_proposal_threshold); @@ -168,7 +168,7 @@ pub mod GovernorSettingsComponent { +GovernorComponent::GovernorVotesTrait, +SRC5Component::HasComponent, impl Governor: GovernorComponent::HasComponent, - +Drop + +Drop, > of InternalTrait { /// Initializes the component by setting the default values. /// @@ -182,7 +182,7 @@ pub mod GovernorSettingsComponent { ref self: ComponentState, new_voting_delay: u64, new_voting_period: u64, - new_proposal_threshold: u256 + new_proposal_threshold: u256, ) { self._set_voting_delay(new_voting_delay); self._set_voting_period(new_voting_period); @@ -236,12 +236,12 @@ pub mod GovernorSettingsComponent { /// /// May emit a `ProposalThresholdUpdated` event. fn _set_proposal_threshold( - ref self: ComponentState, new_proposal_threshold: u256 + ref self: ComponentState, new_proposal_threshold: u256, ) { let old_proposal_threshold = self.Governor_proposal_threshold.read(); if old_proposal_threshold != new_proposal_threshold { let event = ProposalThresholdUpdated { - old_proposal_threshold, new_proposal_threshold + old_proposal_threshold, new_proposal_threshold, }; self.emit(event); self.Governor_proposal_threshold.write(new_proposal_threshold); diff --git a/packages/governance/src/governor/extensions/governor_timelock_execution.cairo b/packages/governance/src/governor/extensions/governor_timelock_execution.cairo index ca7e2345d..7eaffd3e7 100644 --- a/packages/governance/src/governor/extensions/governor_timelock_execution.cairo +++ b/packages/governance/src/governor/extensions/governor_timelock_execution.cairo @@ -23,13 +23,13 @@ #[starknet::component] pub mod GovernorTimelockExecutionComponent { use core::num::traits::Zero; + use crate::governor::GovernorComponent; use crate::governor::GovernorComponent::{ - InternalExtendedTrait, ComponentState as GovernorComponentState + ComponentState as GovernorComponentState, InternalExtendedTrait, }; - use crate::governor::GovernorComponent; use crate::governor::extensions::interface::ITimelocked; use crate::governor::interface::ProposalState; - use crate::timelock::interface::{OperationState, ITimelockDispatcher, ITimelockDispatcherTrait}; + use crate::timelock::interface::{ITimelockDispatcher, ITimelockDispatcherTrait, OperationState}; use openzeppelin_introspection::src5::SRC5Component; use starknet::ContractAddress; use starknet::account::Call; @@ -42,7 +42,7 @@ pub mod GovernorTimelockExecutionComponent { #[storage] pub struct Storage { pub Governor_timelock_controller: ContractAddress, - pub Governor_timelock_ids: Map + pub Governor_timelock_ids: Map, } #[event] @@ -55,7 +55,7 @@ pub mod GovernorTimelockExecutionComponent { #[derive(Drop, starknet::Event)] pub struct TimelockUpdated { pub old_timelock: ContractAddress, - pub new_timelock: ContractAddress + pub new_timelock: ContractAddress, } pub mod Errors { @@ -77,7 +77,7 @@ pub mod GovernorTimelockExecutionComponent { +GovernorComponent::GovernorVotesTrait, +SRC5Component::HasComponent, impl GovernorCoreExecution: HasComponent, - +Drop + +Drop, > of GovernorComponent::GovernorExecutionTrait { /// See `GovernorComponent::GovernorExecutionTrait::state`. /// @@ -85,7 +85,7 @@ pub mod GovernorTimelockExecutionComponent { /// /// - The proposal must exist. fn state( - self: @GovernorComponentState, proposal_id: felt252 + self: @GovernorComponentState, proposal_id: felt252, ) -> ProposalState { let current_state = self._state(proposal_id); @@ -132,7 +132,7 @@ pub mod GovernorTimelockExecutionComponent { ref self: GovernorComponentState, proposal_id: felt252, calls: Span, - description_hash: felt252 + description_hash: felt252, ) { let mut contract = self.get_contract_mut(); let mut this_component = GovernorCoreExecution::get_component_mut(ref contract); @@ -153,7 +153,7 @@ pub mod GovernorTimelockExecutionComponent { ref self: GovernorComponentState, proposal_id: felt252, calls: Span, - description_hash: felt252 + description_hash: felt252, ) -> u64 { let mut contract = self.get_contract_mut(); let mut this_component = GovernorCoreExecution::get_component_mut(ref contract); @@ -173,7 +173,7 @@ pub mod GovernorTimelockExecutionComponent { /// See `GovernorComponent::GovernorExecutionTrait::proposal_needs_queuing`. fn proposal_needs_queuing( - self: @GovernorComponentState, proposal_id: felt252 + self: @GovernorComponentState, proposal_id: felt252, ) -> bool { true } @@ -184,7 +184,7 @@ pub mod GovernorTimelockExecutionComponent { fn cancel_operations( ref self: GovernorComponentState, proposal_id: felt252, - description_hash: felt252 + description_hash: felt252, ) { self._cancel(proposal_id, description_hash); @@ -214,7 +214,7 @@ pub mod GovernorTimelockExecutionComponent { +GovernorComponent::GovernorVotesTrait, +SRC5Component::HasComponent, +GovernorComponent::HasComponent, - +Drop + +Drop, > of ITimelocked> { /// Returns the timelock controller address. fn timelock(self: @ComponentState) -> ContractAddress { @@ -223,7 +223,7 @@ pub mod GovernorTimelockExecutionComponent { /// Returns the timelock proposal id for a given proposal id. fn get_timelock_id( - self: @ComponentState, proposal_id: felt252 + self: @ComponentState, proposal_id: felt252, ) -> TimelockProposalId { self.Governor_timelock_ids.read(proposal_id) } @@ -236,7 +236,7 @@ pub mod GovernorTimelockExecutionComponent { /// /// Emits a `TimelockUpdated` event. fn update_timelock( - ref self: ComponentState, new_timelock: ContractAddress + ref self: ComponentState, new_timelock: ContractAddress, ) { self.assert_only_governance(); self._update_timelock(new_timelock); @@ -256,7 +256,7 @@ pub mod GovernorTimelockExecutionComponent { +GovernorComponent::GovernorVotesTrait, +SRC5Component::HasComponent, impl Governor: GovernorComponent::HasComponent, - +Drop + +Drop, > of InternalTrait { /// Initializes the component by setting the timelock contract address. /// @@ -264,7 +264,7 @@ pub mod GovernorTimelockExecutionComponent { /// /// - `timelock_controller` must not be zero. fn initializer( - ref self: ComponentState, timelock_controller: ContractAddress + ref self: ComponentState, timelock_controller: ContractAddress, ) { assert(timelock_controller.is_non_zero(), Errors::INVALID_TIMELOCK_CONTROLLER); self._update_timelock(timelock_controller); @@ -282,7 +282,7 @@ pub mod GovernorTimelockExecutionComponent { /// It is computed with the governor address itself to avoid collisions across /// governor instances using the same timelock. fn timelock_salt( - self: @ComponentState, description_hash: felt252 + self: @ComponentState, description_hash: felt252, ) -> felt252 { let description_hash: u256 = description_hash.into(); let this: felt252 = starknet::get_contract_address().into(); @@ -301,7 +301,7 @@ pub mod GovernorTimelockExecutionComponent { /// /// Emits a `TimelockUpdated` event. fn _update_timelock( - ref self: ComponentState, new_timelock: ContractAddress + ref self: ComponentState, new_timelock: ContractAddress, ) { let old_timelock = self.Governor_timelock_controller.read(); self.emit(TimelockUpdated { old_timelock, new_timelock }); diff --git a/packages/governance/src/governor/extensions/governor_votes.cairo b/packages/governance/src/governor/extensions/governor_votes.cairo index 3085d01a7..85ef0081f 100644 --- a/packages/governance/src/governor/extensions/governor_votes.cairo +++ b/packages/governance/src/governor/extensions/governor_votes.cairo @@ -9,8 +9,8 @@ #[starknet::component] pub mod GovernorVotesComponent { use core::num::traits::Zero; - use crate::governor::GovernorComponent::ComponentState as GovernorComponentState; use crate::governor::GovernorComponent; + use crate::governor::GovernorComponent::ComponentState as GovernorComponentState; use crate::governor::extensions::interface::IVotesToken; use crate::votes::interface::{IVotesDispatcher, IVotesDispatcherTrait}; use openzeppelin_introspection::src5::SRC5Component; @@ -19,7 +19,7 @@ pub mod GovernorVotesComponent { #[storage] pub struct Storage { - pub Governor_token: ContractAddress + pub Governor_token: ContractAddress, } pub mod Errors { @@ -35,7 +35,7 @@ pub mod GovernorVotesComponent { +GovernorComponent::HasComponent, +SRC5Component::HasComponent, impl GovernorVotes: HasComponent, - +Drop + +Drop, > of GovernorComponent::GovernorVotesTrait { /// See `GovernorComponent::GovernorVotesTrait::clock`. fn clock(self: @GovernorComponentState) -> u64 { @@ -54,7 +54,7 @@ pub mod GovernorVotesComponent { self: @GovernorComponentState, account: ContractAddress, timepoint: u64, - params: Span + params: Span, ) -> u256 { let contract = self.get_contract(); let this_component = GovernorVotes::get_component(contract); @@ -72,7 +72,7 @@ pub mod GovernorVotesComponent { #[embeddable_as(VotesTokenImpl)] impl VotesToken< - TContractState, +HasComponent, +Drop + TContractState, +HasComponent, +Drop, > of IVotesToken> { /// Returns the token that voting power is sourced from. fn token(self: @ComponentState) -> ContractAddress { @@ -90,7 +90,7 @@ pub mod GovernorVotesComponent { +HasComponent, +GovernorComponent::HasComponent, +GovernorComponent::GovernorVotesTrait, - +Drop + +Drop, > of InternalTrait { /// Initializes the component by setting the votes token. /// diff --git a/packages/governance/src/governor/extensions/governor_votes_quorum_fraction.cairo b/packages/governance/src/governor/extensions/governor_votes_quorum_fraction.cairo index b0f0213e2..d2c72ee66 100644 --- a/packages/governance/src/governor/extensions/governor_votes_quorum_fraction.cairo +++ b/packages/governance/src/governor/extensions/governor_votes_quorum_fraction.cairo @@ -9,8 +9,8 @@ #[starknet::component] pub mod GovernorVotesQuorumFractionComponent { use core::num::traits::Zero; - use crate::governor::GovernorComponent::ComponentState as GovernorComponentState; use crate::governor::GovernorComponent; + use crate::governor::GovernorComponent::ComponentState as GovernorComponentState; use crate::governor::extensions::interface::IQuorumFraction; use crate::votes::interface::{IVotesDispatcher, IVotesDispatcherTrait}; use openzeppelin_introspection::src5::SRC5Component; @@ -27,14 +27,14 @@ pub mod GovernorVotesQuorumFractionComponent { #[event] #[derive(Drop, starknet::Event)] pub enum Event { - QuorumNumeratorUpdated: QuorumNumeratorUpdated + QuorumNumeratorUpdated: QuorumNumeratorUpdated, } /// Emitted when the quorum numerator is updated. #[derive(Drop, starknet::Event)] pub struct QuorumNumeratorUpdated { pub old_quorum_numerator: u256, - pub new_quorum_numerator: u256 + pub new_quorum_numerator: u256, } pub mod Errors { @@ -51,7 +51,7 @@ pub mod GovernorVotesQuorumFractionComponent { +GovernorComponent::HasComponent, +SRC5Component::HasComponent, impl GovernorVotesQuorumFraction: HasComponent, - +Drop + +Drop, > of GovernorComponent::GovernorQuorumTrait { /// See `GovernorComponent::GovernorQuorumTrait::quorum`. /// @@ -77,7 +77,7 @@ pub mod GovernorVotesQuorumFractionComponent { +GovernorComponent::HasComponent, +SRC5Component::HasComponent, impl GovernorVotesQuorumFraction: HasComponent, - +Drop + +Drop, > of GovernorComponent::GovernorVotesTrait { /// See `GovernorComponent::GovernorVotesTrait::clock`. fn clock(self: @GovernorComponentState) -> u64 { @@ -96,7 +96,7 @@ pub mod GovernorVotesQuorumFractionComponent { self: @GovernorComponentState, account: ContractAddress, timepoint: u64, - params: Span + params: Span, ) -> u256 { let contract = self.get_contract(); let this_component = GovernorVotesQuorumFraction::get_component(contract); @@ -114,7 +114,7 @@ pub mod GovernorVotesQuorumFractionComponent { #[embeddable_as(QuorumFractionImpl)] impl QuorumFraction< - TContractState, +HasComponent, +Drop + TContractState, +HasComponent, +Drop, > of IQuorumFraction> { /// Returns the token that voting power is sourced from. fn token(self: @ComponentState) -> ContractAddress { @@ -159,7 +159,7 @@ pub mod GovernorVotesQuorumFractionComponent { +HasComponent, +GovernorComponent::GovernorVotesTrait, impl Governor: GovernorComponent::HasComponent, - +Drop + +Drop, > of InternalTrait { /// Initializes the component by setting the votes token and the /// initial quorum numerator value. @@ -173,7 +173,7 @@ pub mod GovernorVotesQuorumFractionComponent { fn initializer( ref self: ComponentState, votes_token: ContractAddress, - quorum_numerator: u256 + quorum_numerator: u256, ) { assert(votes_token.is_non_zero(), Errors::INVALID_TOKEN); @@ -192,7 +192,7 @@ pub mod GovernorVotesQuorumFractionComponent { /// /// May emit a `QuorumNumeratorUpdated` event. fn update_quorum_numerator( - ref self: ComponentState, new_quorum_numerator: u256 + ref self: ComponentState, new_quorum_numerator: u256, ) { let denominator = self.quorum_denominator(); diff --git a/packages/governance/src/governor/governor.cairo b/packages/governance/src/governor/governor.cairo index 77030daf4..ae2800437 100644 --- a/packages/governance/src/governor/governor.cairo +++ b/packages/governance/src/governor/governor.cairo @@ -6,16 +6,16 @@ /// Core of the governance system. #[starknet::component] pub mod GovernorComponent { - use core::hash::{HashStateTrait, HashStateExTrait}; + use core::hash::{HashStateExTrait, HashStateTrait}; use core::num::traits::Zero; use core::pedersen::PedersenTrait; use crate::governor::ProposalCore; - use crate::governor::interface::{ProposalState, IGovernor, IGOVERNOR_ID}; + use crate::governor::interface::{IGOVERNOR_ID, IGovernor, ProposalState}; use crate::governor::vote::{Vote, VoteWithReasonAndParams}; use crate::utils::call_impls::{HashCallImpl, HashCallsImpl}; use openzeppelin_account::interface::{ISRC6Dispatcher, ISRC6DispatcherTrait}; - use openzeppelin_introspection::src5::SRC5Component::InternalImpl as SRC5InternalImpl; use openzeppelin_introspection::src5::SRC5Component; + use openzeppelin_introspection::src5::SRC5Component::InternalImpl as SRC5InternalImpl; use openzeppelin_utils::bytearray::ByteArrayExtTrait; use openzeppelin_utils::cryptography::snip12::{OffchainMessageHash, SNIP12Metadata}; use starknet::account::Call; @@ -27,7 +27,7 @@ pub mod GovernorComponent { #[storage] pub struct Storage { pub Governor_proposals: Map, - pub Governor_nonces: Map + pub Governor_nonces: Map, } #[event] @@ -38,7 +38,7 @@ pub mod GovernorComponent { ProposalExecuted: ProposalExecuted, ProposalCanceled: ProposalCanceled, VoteCast: VoteCast, - VoteCastWithParams: VoteCastWithParams + VoteCastWithParams: VoteCastWithParams, } /// Emitted when `call` is scheduled as part of operation `id`. @@ -52,7 +52,7 @@ pub mod GovernorComponent { pub signatures: Span>, pub vote_start: u64, pub vote_end: u64, - pub description: ByteArray + pub description: ByteArray, } /// Emitted when a proposal is queued. @@ -60,21 +60,21 @@ pub mod GovernorComponent { pub struct ProposalQueued { #[key] pub proposal_id: felt252, - pub eta_seconds: u64 + pub eta_seconds: u64, } /// Emitted when a proposal is executed. #[derive(Drop, starknet::Event)] pub struct ProposalExecuted { #[key] - pub proposal_id: felt252 + pub proposal_id: felt252, } /// Emitted when a proposal is canceled. #[derive(Drop, starknet::Event)] pub struct ProposalCanceled { #[key] - pub proposal_id: felt252 + pub proposal_id: felt252, } /// Emitted when a vote is cast without params. @@ -85,7 +85,7 @@ pub mod GovernorComponent { pub proposal_id: felt252, pub support: u8, pub weight: u256, - pub reason: ByteArray + pub reason: ByteArray, } /// Emitted when a vote is cast with params. @@ -101,7 +101,7 @@ pub mod GovernorComponent { pub support: u8, pub weight: u256, pub reason: ByteArray, - pub params: Span + pub params: Span, } pub mod Errors { @@ -161,12 +161,12 @@ pub mod GovernorComponent { account: ContractAddress, support: u8, total_weight: u256, - params: Span + params: Span, ) -> u256; /// See `interface::IGovernor::has_voted`. fn has_voted( - self: @ComponentState, proposal_id: felt252, account: ContractAddress + self: @ComponentState, proposal_id: felt252, account: ContractAddress, ) -> bool; /// Returns whether amount of votes already cast passes the threshold limit. @@ -188,7 +188,7 @@ pub mod GovernorComponent { self: @ComponentState, account: ContractAddress, timepoint: u64, - params: Span + params: Span, ) -> u256; } @@ -216,7 +216,7 @@ pub mod GovernorComponent { ref self: ComponentState, proposal_id: felt252, calls: Span, - description_hash: felt252 + description_hash: felt252, ); /// Queuing mechanism. Can be used to modify the way queuing is @@ -231,12 +231,12 @@ pub mod GovernorComponent { ref self: ComponentState, proposal_id: felt252, calls: Span, - description_hash: felt252 + description_hash: felt252, ) -> u64; /// See `interface::IGovernor::proposal_needs_queuing`. fn proposal_needs_queuing( - self: @ComponentState, proposal_id: felt252 + self: @ComponentState, proposal_id: felt252, ) -> bool; /// Cancel mechanism. Can be used to modify the way canceling is @@ -244,7 +244,7 @@ pub mod GovernorComponent { fn cancel_operations( ref self: ComponentState, proposal_id: felt252, - description_hash: felt252 + description_hash: felt252, ); } @@ -306,7 +306,7 @@ pub mod GovernorComponent { /// Hashing function used to (re)build the proposal id from the proposal details. fn hash_proposal( - self: @ComponentState, calls: Span, description_hash: felt252 + self: @ComponentState, calls: Span, description_hash: felt252, ) -> felt252 { self._hash_proposal(calls, description_hash) } @@ -336,7 +336,7 @@ pub mod GovernorComponent { /// The account that created a proposal. fn proposal_proposer( - self: @ComponentState, proposal_id: felt252 + self: @ComponentState, proposal_id: felt252, ) -> ContractAddress { self._proposal_proposer(proposal_id) } @@ -350,7 +350,7 @@ pub mod GovernorComponent { /// Whether a proposal needs to be queued before execution. fn proposal_needs_queuing( - self: @ComponentState, proposal_id: felt252 + self: @ComponentState, proposal_id: felt252, ) -> bool { GovernorExecution::proposal_needs_queuing(self, proposal_id) } @@ -390,7 +390,7 @@ pub mod GovernorComponent { /// NOTE: this can be implemented in a number of ways, for example by reading the delegated /// balance from one (or multiple) `ERC20Votes` tokens. fn get_votes( - self: @ComponentState, account: ContractAddress, timepoint: u64 + self: @ComponentState, account: ContractAddress, timepoint: u64, ) -> u256 { self._get_votes(account, timepoint, Immutable::DEFAULT_PARAMS()) } @@ -401,14 +401,14 @@ pub mod GovernorComponent { self: @ComponentState, account: ContractAddress, timepoint: u64, - params: Span + params: Span, ) -> u256 { self._get_votes(account, timepoint, params) } /// Returns whether `account` has cast a vote on `proposal_id`. fn has_voted( - self: @ComponentState, proposal_id: felt252, account: ContractAddress + self: @ComponentState, proposal_id: felt252, account: ContractAddress, ) -> bool { GovernorCounting::has_voted(self, proposal_id, account) } @@ -435,14 +435,14 @@ pub mod GovernorComponent { /// /// Emits a `ProposalCreated` event. fn propose( - ref self: ComponentState, calls: Span, description: ByteArray + ref self: ComponentState, calls: Span, description: ByteArray, ) -> felt252 { let proposer = starknet::get_caller_address(); // Check description for restricted proposer assert( self.is_valid_description_for_proposer(proposer, @description), - Errors::RESTRICTED_PROPOSER + Errors::RESTRICTED_PROPOSER, ); // Check proposal threshold @@ -470,7 +470,7 @@ pub mod GovernorComponent { /// /// Emits a `ProposalQueued` event. fn queue( - ref self: ComponentState, calls: Span, description_hash: felt252 + ref self: ComponentState, calls: Span, description_hash: felt252, ) -> felt252 { let proposal_id = self._hash_proposal(calls, description_hash); self.validate_state(proposal_id, array![ProposalState::Succeeded].span()); @@ -502,12 +502,12 @@ pub mod GovernorComponent { /// /// Emits a `ProposalExecuted` event. fn execute( - ref self: ComponentState, calls: Span, description_hash: felt252 + ref self: ComponentState, calls: Span, description_hash: felt252, ) -> felt252 { let proposal_id = self._hash_proposal(calls, description_hash); self .validate_state( - proposal_id, array![ProposalState::Succeeded, ProposalState::Queued].span() + proposal_id, array![ProposalState::Succeeded, ProposalState::Queued].span(), ); // Mark proposal as executed to avoid reentrancy @@ -534,14 +534,14 @@ pub mod GovernorComponent { /// /// Emits a `ProposalCanceled` event. fn cancel( - ref self: ComponentState, calls: Span, description_hash: felt252 + ref self: ComponentState, calls: Span, description_hash: felt252, ) -> felt252 { let proposal_id = self._hash_proposal(calls, description_hash); self.validate_state(proposal_id, array![ProposalState::Pending].span()); assert( starknet::get_caller_address() == self.proposal_proposer(proposal_id), - Errors::PROPOSER_ONLY + Errors::PROPOSER_ONLY, ); self.cancel_operations(proposal_id, description_hash); @@ -558,7 +558,7 @@ pub mod GovernorComponent { /// /// Emits a `VoteCast` event. fn cast_vote( - ref self: ComponentState, proposal_id: felt252, support: u8 + ref self: ComponentState, proposal_id: felt252, support: u8, ) -> u256 { let voter = starknet::get_caller_address(); self._cast_vote(proposal_id, voter, support, "", Immutable::DEFAULT_PARAMS()) @@ -575,7 +575,7 @@ pub mod GovernorComponent { ref self: ComponentState, proposal_id: felt252, support: u8, - reason: ByteArray + reason: ByteArray, ) -> u256 { let voter = starknet::get_caller_address(); self._cast_vote(proposal_id, voter, support, reason, Immutable::DEFAULT_PARAMS()) @@ -595,7 +595,7 @@ pub mod GovernorComponent { proposal_id: felt252, support: u8, reason: ByteArray, - params: Span + params: Span, ) -> u256 { let voter = starknet::get_caller_address(); self._cast_vote(proposal_id, voter, support, reason, params) @@ -616,7 +616,7 @@ pub mod GovernorComponent { proposal_id: felt252, support: u8, voter: ContractAddress, - signature: Span + signature: Span, ) -> u256 { // 1. Get and increase current nonce let nonce = self.use_nonce(voter); @@ -659,7 +659,7 @@ pub mod GovernorComponent { voter: ContractAddress, reason: ByteArray, params: Span, - signature: Span + signature: Span, ) -> u256 { // 1. Get and increase current nonce let nonce = self.use_nonce(voter); @@ -668,7 +668,7 @@ pub mod GovernorComponent { let verifying_contract = starknet::get_contract_address(); let reason_hash = reason.hash(); let vote = VoteWithReasonAndParams { - verifying_contract, nonce, proposal_id, support, voter, reason_hash, params + verifying_contract, nonce, proposal_id, support, voter, reason_hash, params, }; let hash = vote.get_message_hash(voter); @@ -714,7 +714,7 @@ pub mod GovernorComponent { TContractState, +HasComponent, impl SRC5: SRC5Component::HasComponent, - +Drop + +Drop, > of InternalTrait { /// Initializes the contract by registering the supported interface id. fn initializer(ref self: ComponentState) { @@ -724,7 +724,7 @@ pub mod GovernorComponent { /// Returns the proposal object given its id. fn get_proposal( - self: @ComponentState, proposal_id: felt252 + self: @ComponentState, proposal_id: felt252, ) -> ProposalCore { self.Governor_proposals.read(proposal_id) } @@ -754,7 +754,7 @@ pub mod GovernorComponent { fn is_valid_description_for_proposer( self: @ComponentState, proposer: ContractAddress, - description: @ByteArray + description: @ByteArray, ) -> bool { let length = description.len(); @@ -778,7 +778,7 @@ pub mod GovernorComponent { /// Returns a hash of the proposal using the Pedersen hashing algorithm. fn _hash_proposal( - self: @ComponentState, calls: Span, description_hash: felt252 + self: @ComponentState, calls: Span, description_hash: felt252, ) -> felt252 { PedersenTrait::new(0).update_with(calls).update_with(description_hash).finalize() } @@ -799,7 +799,7 @@ pub mod GovernorComponent { /// The account that created a proposal. fn _proposal_proposer( - self: @ComponentState, proposal_id: felt252 + self: @ComponentState, proposal_id: felt252, ) -> ContractAddress { self.Governor_proposals.read(proposal_id).proposer } @@ -821,7 +821,7 @@ pub mod GovernorComponent { +GovernorExecutionTrait, impl GovernorSettings: GovernorSettingsTrait, impl GovernorVotes: GovernorVotesTrait, - +Drop + +Drop, > of InternalExtendedTrait { /// Asserts that the caller is the governance executor. /// @@ -839,7 +839,7 @@ pub mod GovernorComponent { fn validate_state( self: @ComponentState, proposal_id: felt252, - allowed_states: Span + allowed_states: Span, ) { let current_state = self.state(proposal_id); let mut found = false; @@ -867,7 +867,7 @@ pub mod GovernorComponent { self: @ComponentState, account: ContractAddress, timepoint: u64, - params: Span + params: Span, ) -> u256 { GovernorVotes::get_votes(self, account, timepoint, params) } @@ -924,12 +924,13 @@ pub mod GovernorComponent { ref self: ComponentState, calls: Span, description: @ByteArray, - proposer: ContractAddress + proposer: ContractAddress, ) -> felt252 { let proposal_id = self._hash_proposal(calls, description.hash()); assert( - self.Governor_proposals.read(proposal_id).vote_start == 0, Errors::EXISTENT_PROPOSAL + self.Governor_proposals.read(proposal_id).vote_start == 0, + Errors::EXISTENT_PROPOSAL, ); let snapshot = self.clock() + self.voting_delay(); @@ -941,7 +942,7 @@ pub mod GovernorComponent { vote_duration: duration, executed: false, canceled: false, - eta_seconds: 0 + eta_seconds: 0, }; self.Governor_proposals.write(proposal_id, proposal); @@ -954,8 +955,8 @@ pub mod GovernorComponent { signatures: array![].span(), vote_start: snapshot, vote_end: snapshot + duration, - description: description.clone() - } + description: description.clone(), + }, ); proposal_id @@ -968,14 +969,14 @@ pub mod GovernorComponent { fn _cancel( ref self: ComponentState, proposal_id: felt252, - description_hash: felt252 + description_hash: felt252, ) { let valid_states = array![ ProposalState::Pending, ProposalState::Active, ProposalState::Defeated, ProposalState::Succeeded, - ProposalState::Queued + ProposalState::Queued, ]; self.validate_state(proposal_id, valid_states.span()); @@ -991,7 +992,7 @@ pub mod GovernorComponent { account: ContractAddress, support: u8, total_weight: u256, - params: Span + params: Span, ) -> u256 { self.count_vote(proposal_id, account, support, total_weight, params) } @@ -1011,7 +1012,7 @@ pub mod GovernorComponent { voter: ContractAddress, support: u8, reason: ByteArray, - params: Span + params: Span, ) -> u256 { self.validate_state(proposal_id, array![ProposalState::Active].span()); @@ -1025,8 +1026,8 @@ pub mod GovernorComponent { self .emit( VoteCastWithParams { - voter, proposal_id, support, weight: voted_weight, reason, params - } + voter, proposal_id, support, weight: voted_weight, reason, params, + }, ); } diff --git a/packages/governance/src/governor/interface.cairo b/packages/governance/src/governor/interface.cairo index 8d8f5cfc7..e7a6af841 100644 --- a/packages/governance/src/governor/interface.cairo +++ b/packages/governance/src/governor/interface.cairo @@ -25,7 +25,7 @@ pub enum ProposalState { Defeated, Succeeded, Queued, - Executed + Executed, } #[starknet::interface] @@ -121,7 +121,7 @@ pub trait IGovernor { /// Voting power of an `account` at a specific `timepoint` given additional encoded parameters. fn get_votes_with_params( - self: @TState, account: ContractAddress, timepoint: u64, params: Span + self: @TState, account: ContractAddress, timepoint: u64, params: Span, ) -> u256; /// Returns whether `account` has cast a vote on `proposal_id`. @@ -169,7 +169,7 @@ pub trait IGovernor { /// Cast a vote with a `reason`. fn cast_vote_with_reason( - ref self: TState, proposal_id: felt252, support: u8, reason: ByteArray + ref self: TState, proposal_id: felt252, support: u8, reason: ByteArray, ) -> u256; /// Cast a vote with a `reason` and additional serialized `params`. @@ -178,7 +178,7 @@ pub trait IGovernor { proposal_id: felt252, support: u8, reason: ByteArray, - params: Span + params: Span, ) -> u256; /// Cast a vote using the `voter`'s signature. @@ -187,7 +187,7 @@ pub trait IGovernor { proposal_id: felt252, support: u8, voter: ContractAddress, - signature: Span + signature: Span, ) -> u256; /// Cast a vote with a `reason` and additional serialized `params` using the `voter`'s @@ -199,7 +199,7 @@ pub trait IGovernor { voter: ContractAddress, reason: ByteArray, params: Span, - signature: Span + signature: Span, ) -> u256; /// Returns the next unused nonce for an address. diff --git a/packages/governance/src/governor/proposal_core.cairo b/packages/governance/src/governor/proposal_core.cairo index 3e374939b..9b3f2cd2f 100644 --- a/packages/governance/src/governor/proposal_core.cairo +++ b/packages/governance/src/governor/proposal_core.cairo @@ -13,7 +13,7 @@ pub struct ProposalCore { pub vote_duration: u64, pub executed: bool, pub canceled: bool, - pub eta_seconds: u64 + pub eta_seconds: u64, } const _2_POW_184: felt252 = 0x10000000000000000000000000000000000000000000000; @@ -74,7 +74,7 @@ impl ProposalCoreStorePacking of StorePacking vote_duration: vote_duration.try_into().unwrap(), executed: executed > 0, canceled: canceled > 0, - eta_seconds: eta_seconds.try_into().unwrap() + eta_seconds: eta_seconds.try_into().unwrap(), } } } @@ -93,7 +93,7 @@ mod tests { vote_duration: 200, executed: false, canceled: true, - eta_seconds: 300 + eta_seconds: 300, }; let packed = ProposalCoreStorePacking::pack(proposal); let unpacked = ProposalCoreStorePacking::unpack(packed); @@ -108,7 +108,7 @@ mod tests { vote_duration: Bounded::MAX, executed: true, canceled: true, - eta_seconds: Bounded::MAX + eta_seconds: Bounded::MAX, }; let packed = ProposalCoreStorePacking::pack(proposal); let unpacked = ProposalCoreStorePacking::unpack(packed); diff --git a/packages/governance/src/governor/vote.cairo b/packages/governance/src/governor/vote.cairo index bf06151c0..74743f90e 100644 --- a/packages/governance/src/governor/vote.cairo +++ b/packages/governance/src/governor/vote.cairo @@ -1,9 +1,9 @@ // SPDX-License-Identifier: MIT // OpenZeppelin Contracts for Cairo v0.20.0-rc.0 (governance/governor/vote.cairo) -use core::hash::{HashStateTrait, HashStateExTrait}; +use core::hash::{HashStateExTrait, HashStateTrait}; use core::poseidon::PoseidonTrait; -use openzeppelin_utils::cryptography::snip12::{StructHash, SNIP12HashSpanImpl}; +use openzeppelin_utils::cryptography::snip12::{SNIP12HashSpanImpl, StructHash}; use starknet::ContractAddress; // sn_keccak( @@ -82,7 +82,7 @@ mod tests { #[test] fn test_vote_type_hash() { let expected = selector!( - "\"Vote\"(\"verifying_contract\":\"ContractAddress\",\"nonce\":\"felt\",\"proposal_id\":\"felt\",\"support\":\"u128\",\"voter\":\"ContractAddress\")" + "\"Vote\"(\"verifying_contract\":\"ContractAddress\",\"nonce\":\"felt\",\"proposal_id\":\"felt\",\"support\":\"u128\",\"voter\":\"ContractAddress\")", ); assert_eq!(VOTE_TYPE_HASH, expected); } @@ -90,7 +90,7 @@ mod tests { #[test] fn test_vote_with_reason_and_params_type_hash() { let expected = selector!( - "\"VoteWithReasonAndParams\"(\"verifying_contract\":\"ContractAddress\",\"nonce\":\"felt\",\"proposal_id\":\"felt\",\"support\":\"u128\",\"voter\":\"ContractAddress\",\"reason_hash\":\"felt\",\"params\":\"felt*\")" + "\"VoteWithReasonAndParams\"(\"verifying_contract\":\"ContractAddress\",\"nonce\":\"felt\",\"proposal_id\":\"felt\",\"support\":\"u128\",\"voter\":\"ContractAddress\",\"reason_hash\":\"felt\",\"params\":\"felt*\")", ); assert_eq!(VOTE_WITH_REASON_AND_PARAMS_TYPE_HASH, expected); } diff --git a/packages/governance/src/multisig/interface.cairo b/packages/governance/src/multisig/interface.cairo index de2cf81c8..471b6486c 100644 --- a/packages/governance/src/multisig/interface.cairo +++ b/packages/governance/src/multisig/interface.cairo @@ -12,7 +12,7 @@ pub enum TransactionState { NotFound, Pending, Confirmed, - Executed + Executed, } /// Interface of a contract providing the Multisig functionality. @@ -32,14 +32,14 @@ pub trait IMultisig { to: ContractAddress, selector: felt252, calldata: Span, - salt: felt252 + salt: felt252, ) -> TransactionID; fn hash_transaction_batch(self: @TState, calls: Span, salt: felt252) -> TransactionID; fn add_signers(ref self: TState, new_quorum: u32, signers_to_add: Span); fn remove_signers(ref self: TState, new_quorum: u32, signers_to_remove: Span); fn replace_signer( - ref self: TState, signer_to_remove: ContractAddress, signer_to_add: ContractAddress + ref self: TState, signer_to_remove: ContractAddress, signer_to_add: ContractAddress, ); fn change_quorum(ref self: TState, new_quorum: u32); fn submit_transaction( @@ -50,7 +50,7 @@ pub trait IMultisig { salt: felt252, ) -> TransactionID; fn submit_transaction_batch( - ref self: TState, calls: Span, salt: felt252 + ref self: TState, calls: Span, salt: felt252, ) -> TransactionID; fn confirm_transaction(ref self: TState, id: TransactionID); fn revoke_confirmation(ref self: TState, id: TransactionID); @@ -59,7 +59,7 @@ pub trait IMultisig { to: ContractAddress, selector: felt252, calldata: Span, - salt: felt252 + salt: felt252, ); fn execute_transaction_batch(ref self: TState, calls: Span, salt: felt252); } diff --git a/packages/governance/src/multisig/multisig.cairo b/packages/governance/src/multisig/multisig.cairo index f8f3566fd..9079cd109 100644 --- a/packages/governance/src/multisig/multisig.cairo +++ b/packages/governance/src/multisig/multisig.cairo @@ -15,14 +15,14 @@ /// governance. #[starknet::component] pub mod MultisigComponent { - use core::hash::{HashStateTrait, HashStateExTrait}; + use core::hash::{HashStateExTrait, HashStateTrait}; use core::num::traits::Zero; use core::panic_with_felt252; use core::pedersen::PedersenTrait; use crate::multisig::interface::{IMultisig, TransactionID, TransactionState}; use crate::multisig::storage_utils::{SignersInfo, SignersInfoStorePacking}; use crate::multisig::storage_utils::{TxInfo, TxInfoStorePacking}; - use crate::utils::call_impls::{HashCallImpl, HashCallsImpl, CallPartialEq}; + use crate::utils::call_impls::{CallPartialEq, HashCallImpl, HashCallsImpl}; use starknet::account::Call; use starknet::storage::{Map, StorageMapReadAccess, StorageMapWriteAccess}; use starknet::storage::{StoragePointerReadAccess, StoragePointerWriteAccess}; @@ -36,7 +36,7 @@ pub mod MultisigComponent { pub Multisig_signers_by_index: Map, pub Multisig_signers_indices: Map, pub Multisig_tx_info: Map, - pub Multisig_tx_confirmed_by: Map<(TransactionID, ContractAddress), bool> + pub Multisig_tx_confirmed_by: Map<(TransactionID, ContractAddress), bool>, } #[event] @@ -49,28 +49,28 @@ pub mod MultisigComponent { TransactionConfirmed: TransactionConfirmed, TransactionExecuted: TransactionExecuted, ConfirmationRevoked: ConfirmationRevoked, - CallSalt: CallSalt + CallSalt: CallSalt, } /// Emitted when a new `signer` is added. #[derive(Drop, starknet::Event)] pub struct SignerAdded { #[key] - pub signer: ContractAddress + pub signer: ContractAddress, } /// Emitted when a `signer` is removed. #[derive(Drop, starknet::Event)] pub struct SignerRemoved { #[key] - pub signer: ContractAddress + pub signer: ContractAddress, } /// Emitted when the `quorum` value is updated. #[derive(Drop, starknet::Event)] pub struct QuorumUpdated { pub old_quorum: u32, - pub new_quorum: u32 + pub new_quorum: u32, } /// Emitted when a new transaction is submitted by a `signer`. @@ -79,7 +79,7 @@ pub mod MultisigComponent { #[key] pub id: TransactionID, #[key] - pub signer: ContractAddress + pub signer: ContractAddress, } /// Emitted when a transaction is confirmed by a `signer`. @@ -88,7 +88,7 @@ pub mod MultisigComponent { #[key] pub id: TransactionID, #[key] - pub signer: ContractAddress + pub signer: ContractAddress, } /// Emitted when a `signer` revokes his confirmation. @@ -97,14 +97,14 @@ pub mod MultisigComponent { #[key] pub id: TransactionID, #[key] - pub signer: ContractAddress + pub signer: ContractAddress, } /// Emitted when a transaction is executed. #[derive(Drop, starknet::Event)] pub struct TransactionExecuted { #[key] - pub id: TransactionID + pub id: TransactionID, } /// Emitted when a new transaction is submitted with non-zero salt. @@ -112,7 +112,7 @@ pub mod MultisigComponent { pub struct CallSalt { #[key] pub id: felt252, - pub salt: felt252 + pub salt: felt252, } pub mod Errors { @@ -136,7 +136,7 @@ pub mod MultisigComponent { #[embeddable_as(MultisigImpl)] impl Multisig< - TContractState, +HasComponent, +Drop + TContractState, +HasComponent, +Drop, > of IMultisig> { /// Returns the current quorum value. The quorum is the minimum number /// of confirmations required to approve a transaction. @@ -167,7 +167,7 @@ pub mod MultisigComponent { TransactionState::NotFound => false, TransactionState::Pending => false, TransactionState::Confirmed => true, - TransactionState::Executed => true + TransactionState::Executed => true, } } @@ -180,7 +180,7 @@ pub mod MultisigComponent { /// confirmations toward meeting the quorum. For that, use `get_transaction_confirmations` /// instead. fn is_confirmed_by( - self: @ComponentState, id: TransactionID, signer: ContractAddress + self: @ComponentState, id: TransactionID, signer: ContractAddress, ) -> bool { self.Multisig_tx_confirmed_by.read((id, signer)) } @@ -199,7 +199,7 @@ pub mod MultisigComponent { /// executed. /// - `Executed`: The transaction has been executed. fn get_transaction_state( - self: @ComponentState, id: TransactionID + self: @ComponentState, id: TransactionID, ) -> TransactionState { self.resolve_tx_state(id) } @@ -207,7 +207,7 @@ pub mod MultisigComponent { /// Returns the number of confirmations from registered signers for the transaction with the /// specified `id`. fn get_transaction_confirmations( - self: @ComponentState, id: TransactionID + self: @ComponentState, id: TransactionID, ) -> u32 { let mut result = 0; let all_signers = self.get_signers(); @@ -236,7 +236,7 @@ pub mod MultisigComponent { fn add_signers( ref self: ComponentState, new_quorum: u32, - signers_to_add: Span + signers_to_add: Span, ) { self.assert_only_self(); self._add_signers(new_quorum, signers_to_add); @@ -254,7 +254,7 @@ pub mod MultisigComponent { fn remove_signers( ref self: ComponentState, new_quorum: u32, - signers_to_remove: Span + signers_to_remove: Span, ) { self.assert_only_self(); self._remove_signers(new_quorum, signers_to_remove); @@ -274,7 +274,7 @@ pub mod MultisigComponent { fn replace_signer( ref self: ComponentState, signer_to_remove: ContractAddress, - signer_to_add: ContractAddress + signer_to_add: ContractAddress, ) { self.assert_only_self(); self._replace_signer(signer_to_remove, signer_to_add); @@ -308,7 +308,7 @@ pub mod MultisigComponent { to: ContractAddress, selector: felt252, calldata: Span, - salt: felt252 + salt: felt252, ) -> TransactionID { let call = Call { to, selector, calldata }; self.submit_transaction_batch(array![call].span(), salt) @@ -324,7 +324,7 @@ pub mod MultisigComponent { /// Emits a `TransactionSubmitted` event. /// Emits a `CallSalt` event if `salt` is not zero. fn submit_transaction_batch( - ref self: ComponentState, calls: Span, salt: felt252 + ref self: ComponentState, calls: Span, salt: felt252, ) -> TransactionID { let caller = starknet::get_caller_address(); self.assert_one_of_signers(caller); @@ -332,7 +332,7 @@ pub mod MultisigComponent { assert(self.get_submitted_block(id).is_zero(), Errors::TX_ALREADY_EXISTS); let tx_info = TxInfo { - is_executed: false, submitted_block: starknet::get_block_number() + is_executed: false, submitted_block: starknet::get_block_number(), }; self.Multisig_tx_info.write(id, tx_info); if salt.is_non_zero() { @@ -394,7 +394,7 @@ pub mod MultisigComponent { to: ContractAddress, selector: felt252, calldata: Span, - salt: felt252 + salt: felt252, ) { let call = Call { to, selector, calldata }; self.execute_transaction_batch(array![call].span(), salt) @@ -409,7 +409,7 @@ pub mod MultisigComponent { /// /// Emits a `TransactionExecuted` event. fn execute_transaction_batch( - ref self: ComponentState, calls: Span, salt: felt252 + ref self: ComponentState, calls: Span, salt: felt252, ) { let id = self.hash_transaction_batch(calls, salt); match self.resolve_tx_state(id) { @@ -427,7 +427,7 @@ pub mod MultisigComponent { call_contract_syscall(to, selector, calldata).unwrap_syscall(); }; self.emit(TransactionExecuted { id }); - } + }, }; } @@ -437,7 +437,7 @@ pub mod MultisigComponent { to: ContractAddress, selector: felt252, calldata: Span, - salt: felt252 + salt: felt252, ) -> TransactionID { let call = Call { to, selector, calldata }; self.hash_transaction_batch(array![call].span(), salt) @@ -445,7 +445,7 @@ pub mod MultisigComponent { /// Returns the computed identifier of a transaction containing a batch of calls. fn hash_transaction_batch( - self: @ComponentState, calls: Span, salt: felt252 + self: @ComponentState, calls: Span, salt: felt252, ) -> TransactionID { PedersenTrait::new(0).update_with(calls).update_with(salt).finalize() } @@ -457,7 +457,7 @@ pub mod MultisigComponent { #[generate_trait] pub impl InternalImpl< - TContractState, +HasComponent, +Drop + TContractState, +HasComponent, +Drop, > of InternalTrait { /// Initializes the Multisig component with the initial `quorum` and `signers`. /// This function must be called during contract initialization to set up the initial state. @@ -469,7 +469,7 @@ pub mod MultisigComponent { /// Emits a `SignerAdded` event for each signer added. /// Emits a `QuorumUpdated` event if the quorum changes. fn initializer( - ref self: ComponentState, quorum: u32, signers: Span + ref self: ComponentState, quorum: u32, signers: Span, ) { self._add_signers(quorum, signers); } @@ -483,7 +483,7 @@ pub mod MultisigComponent { /// executed. /// - `Executed`: The transaction has been executed. fn resolve_tx_state( - self: @ComponentState, id: TransactionID + self: @ComponentState, id: TransactionID, ) -> TransactionState { let TxInfo { is_executed, submitted_block } = self.Multisig_tx_info.read(id); if submitted_block.is_zero() { @@ -542,7 +542,7 @@ pub mod MultisigComponent { fn _add_signers( ref self: ComponentState, new_quorum: u32, - signers_to_add: Span + signers_to_add: Span, ) { if !signers_to_add.is_empty() { let SignersInfo { quorum, mut signers_count } = self.Multisig_signers_info.read(); @@ -577,7 +577,7 @@ pub mod MultisigComponent { fn _remove_signers( ref self: ComponentState, new_quorum: u32, - signers_to_remove: Span + signers_to_remove: Span, ) { if !signers_to_remove.is_empty() { let SignersInfo { quorum, mut signers_count } = self.Multisig_signers_info.read(); @@ -620,7 +620,7 @@ pub mod MultisigComponent { fn _replace_signer( ref self: ComponentState, signer_to_remove: ContractAddress, - signer_to_add: ContractAddress + signer_to_add: ContractAddress, ) { assert(signer_to_add.is_non_zero(), Errors::ZERO_ADDRESS_SIGNER); assert(!self.is_signer(signer_to_add), Errors::ALREADY_A_SIGNER); @@ -645,9 +645,9 @@ pub mod MultisigComponent { /// /// Emits a `QuorumUpdated` event if the quorum changes. fn _change_quorum(ref self: ComponentState, new_quorum: u32) { - let SignersInfo { quorum: old_quorum, signers_count } = self - .Multisig_signers_info - .read(); + let SignersInfo { + quorum: old_quorum, signers_count, + } = self.Multisig_signers_info.read(); if new_quorum != old_quorum { assert(new_quorum.is_non_zero(), Errors::ZERO_QUORUM); assert(new_quorum <= signers_count, Errors::QUORUM_TOO_HIGH); diff --git a/packages/governance/src/multisig/storage_utils.cairo b/packages/governance/src/multisig/storage_utils.cairo index d82641f49..90af310d9 100644 --- a/packages/governance/src/multisig/storage_utils.cairo +++ b/packages/governance/src/multisig/storage_utils.cairo @@ -11,7 +11,7 @@ const _2_POW_32: NonZero = 0xffffffff; #[derive(Drop)] pub struct TxInfo { pub is_executed: bool, - pub submitted_block: u64 + pub submitted_block: u64, } /// Packs a `TxInfo` entity into a `u128` value. @@ -42,7 +42,7 @@ pub impl TxInfoStorePacking of StorePacking { #[derive(Drop)] pub struct SignersInfo { pub quorum: u32, - pub signers_count: u32 + pub signers_count: u32, } /// Packs a `SignersInfo` entity into a `u128` value. @@ -59,7 +59,7 @@ pub impl SignersInfoStorePacking of StorePacking { fn unpack(value: u128) -> SignersInfo { let (quorum, signers_count) = u128_safe_divmod(value, _2_POW_32); SignersInfo { - quorum: quorum.try_into().unwrap(), signers_count: signers_count.try_into().unwrap() + quorum: quorum.try_into().unwrap(), signers_count: signers_count.try_into().unwrap(), } } } diff --git a/packages/governance/src/tests/governor/common.cairo b/packages/governance/src/tests/governor/common.cairo index 4ebb68ef0..43d9df923 100644 --- a/packages/governance/src/tests/governor/common.cairo +++ b/packages/governance/src/tests/governor/common.cairo @@ -1,6 +1,6 @@ -use core::hash::{HashStateTrait, HashStateExTrait}; +use core::hash::{HashStateExTrait, HashStateTrait}; use core::pedersen::PedersenTrait; -use crate::governor::GovernorComponent::{InternalImpl, InternalExtendedImpl}; +use crate::governor::GovernorComponent::{InternalExtendedImpl, InternalImpl}; use crate::governor::interface::{IGovernor, ProposalState}; use crate::governor::{DefaultConfig, GovernorComponent, ProposalCore}; use crate::utils::call_impls::{HashCallImpl, HashCallsImpl}; @@ -11,7 +11,7 @@ use openzeppelin_utils::bytearray::ByteArrayExtTrait; use snforge_std::{start_cheat_block_timestamp_global, start_mock_call}; use starknet::ContractAddress; use starknet::account::Call; -use starknet::storage::{StoragePathEntry, StoragePointerWriteAccess, StorageMapWriteAccess}; +use starknet::storage::{StorageMapWriteAccess, StoragePathEntry, StoragePointerWriteAccess}; pub type ComponentState = GovernorComponent::ComponentState; pub type ComponentStateTimelocked = @@ -58,7 +58,7 @@ pub fn get_proposal_with_id(calls: Span, description: @ByteArray) -> (felt vote_duration, executed: false, canceled: false, - eta_seconds: 0 + eta_seconds: 0, }; (proposal_id, proposal) @@ -77,7 +77,7 @@ pub fn get_calls(to: ContractAddress, mock_syscalls: bool) -> Span { } pub fn get_state( - state: @ComponentState, id: felt252, external_state_version: bool + state: @ComponentState, id: felt252, external_state_version: bool, ) -> ProposalState { if external_state_version { state.state(id) @@ -87,7 +87,7 @@ pub fn get_state( } pub fn get_mock_state( - mock_state: @GovernorMock::ContractState, id: felt252, external_state_version: bool + mock_state: @GovernorMock::ContractState, id: felt252, external_state_version: bool, ) -> ProposalState { if external_state_version { mock_state.governor.state(id) @@ -97,7 +97,7 @@ pub fn get_mock_state( } pub fn set_executor( - ref mock_state: GovernorTimelockedMock::ContractState, executor: ContractAddress + ref mock_state: GovernorTimelockedMock::ContractState, executor: ContractAddress, ) { mock_state.governor_timelock_execution.Governor_timelock_controller.write(executor); } @@ -107,7 +107,7 @@ pub fn set_executor( // pub fn setup_pending_proposal( - ref state: ComponentState, external_state_version: bool + ref state: ComponentState, external_state_version: bool, ) -> (felt252, ProposalCore) { let (id, proposal) = get_proposal_info(); @@ -122,7 +122,7 @@ pub fn setup_pending_proposal( } pub fn setup_active_proposal( - ref state: ComponentState, external_state_version: bool + ref state: ComponentState, external_state_version: bool, ) -> (felt252, ProposalCore) { let (id, proposal) = get_proposal_info(); @@ -140,7 +140,7 @@ pub fn setup_active_proposal( } pub fn setup_queued_proposal( - ref mock_state: GovernorMock::ContractState, external_state_version: bool + ref mock_state: GovernorMock::ContractState, external_state_version: bool, ) -> (felt252, ProposalCore) { let (id, mut proposal) = get_proposal_info(); @@ -166,7 +166,7 @@ pub fn setup_queued_proposal( } pub fn setup_canceled_proposal( - ref state: ComponentState, external_state_version: bool + ref state: ComponentState, external_state_version: bool, ) -> (felt252, ProposalCore) { let (id, proposal) = get_proposal_info(); @@ -182,7 +182,7 @@ pub fn setup_canceled_proposal( } pub fn setup_defeated_proposal( - ref mock_state: GovernorMock::ContractState, external_state_version: bool + ref mock_state: GovernorMock::ContractState, external_state_version: bool, ) -> (felt252, ProposalCore) { let (id, proposal) = get_proposal_info(); @@ -204,7 +204,7 @@ pub fn setup_defeated_proposal( } pub fn setup_succeeded_proposal( - ref mock_state: GovernorMock::ContractState, external_state_version: bool + ref mock_state: GovernorMock::ContractState, external_state_version: bool, ) -> (felt252, ProposalCore) { let (id, proposal) = get_proposal_info(); @@ -230,7 +230,7 @@ pub fn setup_succeeded_proposal( } pub fn setup_executed_proposal( - ref state: ComponentState, external_state_version: bool + ref state: ComponentState, external_state_version: bool, ) -> (felt252, ProposalCore) { let (id, mut proposal) = get_proposal_info(); diff --git a/packages/governance/src/tests/governor/test_governor.cairo b/packages/governance/src/tests/governor/test_governor.cairo index 2cdbfa40a..f76183055 100644 --- a/packages/governance/src/tests/governor/test_governor.cairo +++ b/packages/governance/src/tests/governor/test_governor.cairo @@ -1,36 +1,37 @@ use core::num::traits::{Bounded, Zero}; -use crate::governor::GovernorComponent::{InternalImpl, InternalExtendedImpl}; -use crate::governor::interface::{IGovernor, IGOVERNOR_ID, ProposalState}; +use crate::governor::GovernorComponent::{InternalExtendedImpl, InternalImpl}; +use crate::governor::interface::{IGOVERNOR_ID, IGovernor, ProposalState}; use crate::governor::interface::{IGovernorDispatcher, IGovernorDispatcherTrait}; use crate::governor::vote::{Vote, VoteWithReasonAndParams}; use crate::governor::{DefaultConfig, GovernorComponent, ProposalCore}; +use crate::tests::governor::common::{COMPONENT_STATE, CONTRACT_STATE}; use crate::tests::governor::common::{ - hash_proposal, get_state, get_mock_state, get_proposal_info, get_calls + get_calls, get_mock_state, get_proposal_info, get_state, hash_proposal, }; use crate::tests::governor::common::{ - setup_pending_proposal, setup_active_proposal, setup_queued_proposal, setup_canceled_proposal, - setup_defeated_proposal, setup_succeeded_proposal, setup_executed_proposal + setup_active_proposal, setup_canceled_proposal, setup_defeated_proposal, + setup_executed_proposal, setup_pending_proposal, setup_queued_proposal, + setup_succeeded_proposal, }; -use crate::tests::governor::common::{COMPONENT_STATE, CONTRACT_STATE}; use openzeppelin_introspection::src5::SRC5Component::SRC5Impl; -use openzeppelin_test_common::mocks::governor::GovernorMock::SNIP12MetadataImpl; use openzeppelin_test_common::mocks::governor::GovernorMock; +use openzeppelin_test_common::mocks::governor::GovernorMock::SNIP12MetadataImpl; use openzeppelin_test_common::mocks::timelock::{ - IMockContractDispatcher, IMockContractDispatcherTrait + IMockContractDispatcher, IMockContractDispatcherTrait, }; use openzeppelin_testing as utils; -use openzeppelin_testing::constants::{ADMIN, OTHER, ZERO, VOTES_TOKEN}; +use openzeppelin_testing::constants::{ADMIN, OTHER, VOTES_TOKEN, ZERO}; use openzeppelin_testing::events::EventSpyExt; use openzeppelin_utils::bytearray::ByteArrayExtTrait; use openzeppelin_utils::cryptography::snip12::OffchainMessageHash; use snforge_std::signature::stark_curve::{StarkCurveKeyPairImpl, StarkCurveSignerImpl}; +use snforge_std::{EventSpy, spy_events, test_address}; use snforge_std::{ - start_cheat_caller_address, start_cheat_block_timestamp_global, start_cheat_chain_id_global, - start_mock_call + start_cheat_block_timestamp_global, start_cheat_caller_address, start_cheat_chain_id_global, + start_mock_call, }; -use snforge_std::{EventSpy, spy_events, test_address}; use starknet::account::Call; -use starknet::storage::{StoragePathEntry, StoragePointerWriteAccess, StorageMapWriteAccess}; +use starknet::storage::{StorageMapWriteAccess, StoragePathEntry, StoragePointerWriteAccess}; use starknet::{ContractAddress, contract_address_const}; // @@ -427,7 +428,7 @@ fn test_propose_external_version(external_state_version: bool) { array![].span(), vote_start, vote_end, - description_snap + description_snap, ); // 3. Check proposal @@ -438,7 +439,7 @@ fn test_propose_external_version(external_state_version: bool) { vote_duration: GovernorMock::VOTING_PERIOD, executed: false, canceled: false, - eta_seconds: 0 + eta_seconds: 0, }; assert_eq!(proposal, expected); @@ -512,7 +513,7 @@ fn test_execute() { let call = Call { to: target.contract_address, selector: selector!("set_number"), - calldata: array![new_number].span() + calldata: array![new_number].span(), }; let calls = array![call].span(); let description = "proposal description"; @@ -568,7 +569,7 @@ fn test_execute_panics() { let call = Call { to: target.contract_address, selector: selector!("failing_function"), - calldata: array![].span() + calldata: array![].span(), }; let calls = array![call].span(); let description = "proposal description"; @@ -1013,7 +1014,7 @@ fn test_cast_vote_with_reason_and_params_active() { spy .assert_only_event_vote_cast_with_params( - contract_address, OTHER(), id, 0, expected_weight, @reason, params + contract_address, OTHER(), id, 0, expected_weight, @reason, params, ); } @@ -1088,7 +1089,7 @@ fn test_cast_vote_with_reason_and_params_executed() { // fn prepare_governor_and_signature( - nonce: felt252 + nonce: felt252, ) -> (IGovernorDispatcher, felt252, felt252, felt252, u8, ContractAddress, u256) { let mut governor = deploy_governor(); let calls = get_calls(OTHER(), false); @@ -1133,7 +1134,7 @@ fn test_cast_vote_by_sig() { spy .assert_only_event_vote_cast( - governor.contract_address, voter, proposal_id, support, quorum, @"" + governor.contract_address, voter, proposal_id, support, quorum, @"", ); } @@ -1189,7 +1190,7 @@ fn test_cast_vote_by_sig_hash_generation() { // fn prepare_governor_and_signature_with_reason_and_params( - reason: @ByteArray, params: Span, nonce: felt252 + reason: @ByteArray, params: Span, nonce: felt252, ) -> (IGovernorDispatcher, felt252, felt252, felt252, u8, ContractAddress, u256) { let mut governor = deploy_governor(); let calls = get_calls(OTHER(), false); @@ -1219,7 +1220,7 @@ fn prepare_governor_and_signature_with_reason_and_params( // 5. Create and sign the vote message let vote = VoteWithReasonAndParams { - verifying_contract, nonce, proposal_id, support, voter, reason_hash, params + verifying_contract, nonce, proposal_id, support, voter, reason_hash, params, }; let msg_hash = vote.get_message_hash(voter); let (r, s) = key_pair.sign(msg_hash).unwrap(); @@ -1234,19 +1235,19 @@ fn test_cast_vote_with_reason_and_params_by_sig() { let (governor, r, s, proposal_id, support, voter, quorum) = prepare_governor_and_signature_with_reason_and_params( - @reason, params, 0 + @reason, params, 0, ); // Set up event spy and cast vote let mut spy = spy_events(); governor .cast_vote_with_reason_and_params_by_sig( - proposal_id, support, voter, reason.clone(), params, array![r, s].span() + proposal_id, support, voter, reason.clone(), params, array![r, s].span(), ); spy .assert_only_event_vote_cast_with_params( - governor.contract_address, voter, proposal_id, support, quorum, @reason, params + governor.contract_address, voter, proposal_id, support, quorum, @reason, params, ); } @@ -1257,19 +1258,19 @@ fn test_cast_vote_with_reason_and_params_by_sig_empty_params() { let (governor, r, s, proposal_id, support, voter, quorum) = prepare_governor_and_signature_with_reason_and_params( - @reason, params, 0 + @reason, params, 0, ); // Set up event spy and cast vote let mut spy = spy_events(); governor .cast_vote_with_reason_and_params_by_sig( - proposal_id, support, voter, reason.clone(), params, array![r, s].span() + proposal_id, support, voter, reason.clone(), params, array![r, s].span(), ); spy .assert_only_event_vote_cast( - governor.contract_address, voter, proposal_id, support, quorum, @reason + governor.contract_address, voter, proposal_id, support, quorum, @reason, ); } @@ -1281,13 +1282,13 @@ fn test_cast_vote_with_reason_and_params_by_sig_invalid_signature() { let (governor, r, s, proposal_id, support, voter, _) = prepare_governor_and_signature_with_reason_and_params( - @reason, params, 0 + @reason, params, 0, ); // Cast vote with invalid signature governor .cast_vote_with_reason_and_params_by_sig( - proposal_id, support, voter, reason.clone(), params, array![r + 1, s].span() + proposal_id, support, voter, reason.clone(), params, array![r + 1, s].span(), ); } @@ -1301,13 +1302,13 @@ fn test_cast_vote_with_reason_and_params_by_sig_invalid_msg_hash() { let invalid_nonce = 1; let (governor, r, s, proposal_id, support, voter, _) = prepare_governor_and_signature_with_reason_and_params( - @reason, params, invalid_nonce + @reason, params, invalid_nonce, ); // Cast vote with invalid msg hash governor .cast_vote_with_reason_and_params_by_sig( - proposal_id, support, voter, reason.clone(), params, array![r, s].span() + proposal_id, support, voter, reason.clone(), params, array![r, s].span(), ); } @@ -1323,7 +1324,7 @@ fn test_cast_vote_with_reason_and_params_by_sig_hash_generation() { let reason_hash = 'hash'; let params = array!['param'].span(); let vote = VoteWithReasonAndParams { - verifying_contract, nonce, proposal_id, support, voter, reason_hash, params + verifying_contract, nonce, proposal_id, support, voter, reason_hash, params, }; let hash = vote.get_message_hash(voter); @@ -1372,7 +1373,7 @@ fn test_relay() { let call = Call { to: target.contract_address, selector: selector!("set_number"), - calldata: array![new_number].span() + calldata: array![new_number].span(), }; let number = target.get_number(); @@ -1394,7 +1395,7 @@ fn test_relay_panics() { let call = Call { to: target.contract_address, selector: selector!("failing_function"), - calldata: array![].span() + calldata: array![].span(), }; start_cheat_caller_address(contract_address, contract_address); @@ -1626,7 +1627,7 @@ fn test_validate_state() { state.validate_state(id, valid_states.span()); let valid_states = array![ - ProposalState::Executed, ProposalState::Active, ProposalState::Pending + ProposalState::Executed, ProposalState::Active, ProposalState::Pending, ]; state.validate_state(id, valid_states.span()); } @@ -1888,7 +1889,7 @@ fn test__cast_vote_active_with_params() { spy .assert_event_vote_cast_with_params( - contract_address, OTHER(), id, 0, expected_weight, @"reason", params + contract_address, OTHER(), id, 0, expected_weight, @"reason", params, ); } @@ -1957,7 +1958,7 @@ pub(crate) impl GovernorSpyHelpersImpl of GovernorSpyHelpers { signatures: Span>, vote_start: u64, vote_end: u64, - description: @ByteArray + description: @ByteArray, ) { let expected = GovernorComponent::Event::ProposalCreated( GovernorComponent::ProposalCreated { @@ -1967,8 +1968,8 @@ pub(crate) impl GovernorSpyHelpersImpl of GovernorSpyHelpers { signatures, vote_start, vote_end, - description: description.clone() - } + description: description.clone(), + }, ); self.assert_emitted_single(contract, expected); } @@ -1982,7 +1983,7 @@ pub(crate) impl GovernorSpyHelpersImpl of GovernorSpyHelpers { signatures: Span>, vote_start: u64, vote_end: u64, - description: @ByteArray + description: @ByteArray, ) { self .assert_event_proposal_created( @@ -1993,7 +1994,7 @@ pub(crate) impl GovernorSpyHelpersImpl of GovernorSpyHelpers { signatures, vote_start, vote_end, - description + description, ); self.assert_no_events_left_from(contract); } @@ -2005,12 +2006,12 @@ pub(crate) impl GovernorSpyHelpersImpl of GovernorSpyHelpers { proposal_id: felt252, support: u8, weight: u256, - reason: @ByteArray + reason: @ByteArray, ) { let expected = GovernorComponent::Event::VoteCast( GovernorComponent::VoteCast { - voter, proposal_id, support, weight, reason: reason.clone() - } + voter, proposal_id, support, weight, reason: reason.clone(), + }, ); self.assert_emitted_single(contract, expected); } @@ -2022,7 +2023,7 @@ pub(crate) impl GovernorSpyHelpersImpl of GovernorSpyHelpers { proposal_id: felt252, support: u8, weight: u256, - reason: @ByteArray + reason: @ByteArray, ) { self.assert_event_vote_cast(contract, voter, proposal_id, support, weight, reason); self.assert_no_events_left_from(contract); @@ -2036,12 +2037,12 @@ pub(crate) impl GovernorSpyHelpersImpl of GovernorSpyHelpers { support: u8, weight: u256, reason: @ByteArray, - params: Span + params: Span, ) { let expected = GovernorComponent::Event::VoteCastWithParams( GovernorComponent::VoteCastWithParams { - voter, proposal_id, support, weight, reason: reason.clone(), params - } + voter, proposal_id, support, weight, reason: reason.clone(), params, + }, ); self.assert_emitted_single(contract, expected); } @@ -2054,58 +2055,58 @@ pub(crate) impl GovernorSpyHelpersImpl of GovernorSpyHelpers { support: u8, weight: u256, reason: @ByteArray, - params: Span + params: Span, ) { self .assert_event_vote_cast_with_params( - contract, voter, proposal_id, support, weight, reason, params + contract, voter, proposal_id, support, weight, reason, params, ); self.assert_no_events_left_from(contract); } fn assert_event_proposal_queued( - ref self: EventSpy, contract: ContractAddress, proposal_id: felt252, eta_seconds: u64 + ref self: EventSpy, contract: ContractAddress, proposal_id: felt252, eta_seconds: u64, ) { let expected = GovernorComponent::Event::ProposalQueued( - GovernorComponent::ProposalQueued { proposal_id, eta_seconds } + GovernorComponent::ProposalQueued { proposal_id, eta_seconds }, ); self.assert_emitted_single(contract, expected); } fn assert_only_event_proposal_queued( - ref self: EventSpy, contract: ContractAddress, proposal_id: felt252, eta_seconds: u64 + ref self: EventSpy, contract: ContractAddress, proposal_id: felt252, eta_seconds: u64, ) { self.assert_event_proposal_queued(contract, proposal_id, eta_seconds); self.assert_no_events_left_from(contract); } fn assert_event_proposal_executed( - ref self: EventSpy, contract: ContractAddress, proposal_id: felt252 + ref self: EventSpy, contract: ContractAddress, proposal_id: felt252, ) { let expected = GovernorComponent::Event::ProposalExecuted( - GovernorComponent::ProposalExecuted { proposal_id } + GovernorComponent::ProposalExecuted { proposal_id }, ); self.assert_emitted_single(contract, expected); } fn assert_only_event_proposal_executed( - ref self: EventSpy, contract: ContractAddress, proposal_id: felt252 + ref self: EventSpy, contract: ContractAddress, proposal_id: felt252, ) { self.assert_event_proposal_executed(contract, proposal_id); self.assert_no_events_left_from(contract); } fn assert_event_proposal_canceled( - ref self: EventSpy, contract: ContractAddress, proposal_id: felt252 + ref self: EventSpy, contract: ContractAddress, proposal_id: felt252, ) { let expected = GovernorComponent::Event::ProposalCanceled( - GovernorComponent::ProposalCanceled { proposal_id } + GovernorComponent::ProposalCanceled { proposal_id }, ); self.assert_emitted_single(contract, expected); } fn assert_only_event_proposal_canceled( - ref self: EventSpy, contract: ContractAddress, proposal_id: felt252 + ref self: EventSpy, contract: ContractAddress, proposal_id: felt252, ) { self.assert_event_proposal_canceled(contract, proposal_id); self.assert_no_events_left_from(contract); diff --git a/packages/governance/src/tests/governor/test_governor_core_execution.cairo b/packages/governance/src/tests/governor/test_governor_core_execution.cairo index 6b305dc8c..551e7e639 100644 --- a/packages/governance/src/tests/governor/test_governor_core_execution.cairo +++ b/packages/governance/src/tests/governor/test_governor_core_execution.cairo @@ -2,15 +2,16 @@ use crate::governor::DefaultConfig; use crate::governor::GovernorComponent::InternalImpl; use crate::governor::extensions::GovernorCoreExecutionComponent::GovernorExecution; use crate::governor::interface::{IGovernor, ProposalState}; +use crate::tests::governor::common::{COMPONENT_STATE, CONTRACT_STATE, get_calls, get_proposal_info}; use crate::tests::governor::common::{ - setup_pending_proposal, setup_active_proposal, setup_defeated_proposal, setup_queued_proposal, - setup_canceled_proposal, setup_succeeded_proposal, setup_executed_proposal + setup_active_proposal, setup_canceled_proposal, setup_defeated_proposal, + setup_executed_proposal, setup_pending_proposal, setup_queued_proposal, + setup_succeeded_proposal, }; -use crate::tests::governor::common::{get_proposal_info, get_calls, COMPONENT_STATE, CONTRACT_STATE}; use openzeppelin_test_common::mocks::governor::GovernorMock::SNIP12MetadataImpl; use openzeppelin_testing::constants::OTHER; use snforge_std::start_cheat_block_timestamp_global; -use starknet::storage::{StoragePathEntry, StoragePointerWriteAccess, StorageMapWriteAccess}; +use starknet::storage::{StorageMapWriteAccess, StoragePathEntry, StoragePointerWriteAccess}; // // state diff --git a/packages/governance/src/tests/governor/test_governor_counting_simple.cairo b/packages/governance/src/tests/governor/test_governor_counting_simple.cairo index 13a12a7dd..16e3e29fe 100644 --- a/packages/governance/src/tests/governor/test_governor_counting_simple.cairo +++ b/packages/governance/src/tests/governor/test_governor_counting_simple.cairo @@ -1,7 +1,7 @@ use core::num::traits::Bounded; use crate::governor::DefaultConfig; use crate::governor::GovernorComponent::InternalImpl; -use crate::governor::extensions::GovernorCountingSimpleComponent::{VoteType, GovernorCounting}; +use crate::governor::extensions::GovernorCountingSimpleComponent::{GovernorCounting, VoteType}; use crate::governor::interface::IGovernor; use crate::tests::governor::common::{COMPONENT_STATE, CONTRACT_STATE}; use openzeppelin_test_common::mocks::governor::GovernorMock::SNIP12MetadataImpl; @@ -84,7 +84,7 @@ fn test_count_vote_against() { assert_eq!(proposal_votes.against_votes.read(), 0); let weight = GovernorCounting::count_vote( - ref state, proposal_id, account, support, total_weight, params + ref state, proposal_id, account, support, total_weight, params, ); assert_eq!(weight, total_weight); @@ -111,7 +111,7 @@ fn test_count_vote_for() { assert_eq!(proposal_votes.for_votes.read(), 0); let weight = GovernorCounting::count_vote( - ref state, proposal_id, account, support, total_weight, params + ref state, proposal_id, account, support, total_weight, params, ); assert_eq!(weight, total_weight); @@ -138,7 +138,7 @@ fn test_count_vote_abstain() { assert_eq!(proposal_votes.abstain_votes.read(), 0); let weight = GovernorCounting::count_vote( - ref state, proposal_id, account, support, total_weight, params + ref state, proposal_id, account, support, total_weight, params, ); assert_eq!(weight, total_weight); diff --git a/packages/governance/src/tests/governor/test_governor_settings.cairo b/packages/governance/src/tests/governor/test_governor_settings.cairo index 309f8ec13..3d2735101 100644 --- a/packages/governance/src/tests/governor/test_governor_settings.cairo +++ b/packages/governance/src/tests/governor/test_governor_settings.cairo @@ -1,13 +1,13 @@ use crate::governor::DefaultConfig; use crate::governor::GovernorComponent::InternalImpl; +use crate::governor::extensions::GovernorSettingsComponent; use crate::governor::extensions::GovernorSettingsComponent::InternalImpl as GovernorSettingsInternalImpl; use crate::governor::extensions::GovernorSettingsComponent::{ - GovernorSettings, GovernorSettingsAdminImpl + GovernorSettings, GovernorSettingsAdminImpl, }; -use crate::governor::extensions::GovernorSettingsComponent; use crate::tests::governor::common::set_executor; use crate::tests::governor::common::{ - COMPONENT_STATE_TIMELOCKED as COMPONENT_STATE, CONTRACT_STATE_TIMELOCKED as CONTRACT_STATE + COMPONENT_STATE_TIMELOCKED as COMPONENT_STATE, CONTRACT_STATE_TIMELOCKED as CONTRACT_STATE, }; use openzeppelin_test_common::mocks::governor::GovernorTimelockedMock::SNIP12MetadataImpl; use openzeppelin_testing::constants::OTHER; @@ -395,16 +395,16 @@ fn test__set_proposal_threshold_no_change() { #[generate_trait] pub(crate) impl GovernorSettingsSpyHelpersImpl of GovernorSettingsSpyHelpers { fn assert_event_voting_delay_updated( - ref self: EventSpy, contract: ContractAddress, old_voting_delay: u64, new_voting_delay: u64 + ref self: EventSpy, contract: ContractAddress, old_voting_delay: u64, new_voting_delay: u64, ) { let expected = GovernorSettingsComponent::Event::VotingDelayUpdated( - GovernorSettingsComponent::VotingDelayUpdated { old_voting_delay, new_voting_delay } + GovernorSettingsComponent::VotingDelayUpdated { old_voting_delay, new_voting_delay }, ); self.assert_emitted_single(contract, expected); } fn assert_only_event_voting_delay_updated( - ref self: EventSpy, contract: ContractAddress, old_voting_delay: u64, new_voting_delay: u64 + ref self: EventSpy, contract: ContractAddress, old_voting_delay: u64, new_voting_delay: u64, ) { self.assert_event_voting_delay_updated(contract, old_voting_delay, new_voting_delay); self.assert_no_events_left_from(contract); @@ -414,10 +414,10 @@ pub(crate) impl GovernorSettingsSpyHelpersImpl of GovernorSettingsSpyHelpers { ref self: EventSpy, contract: ContractAddress, old_voting_period: u64, - new_voting_period: u64 + new_voting_period: u64, ) { let expected = GovernorSettingsComponent::Event::VotingPeriodUpdated( - GovernorSettingsComponent::VotingPeriodUpdated { old_voting_period, new_voting_period } + GovernorSettingsComponent::VotingPeriodUpdated { old_voting_period, new_voting_period }, ); self.assert_emitted_single(contract, expected); } @@ -426,7 +426,7 @@ pub(crate) impl GovernorSettingsSpyHelpersImpl of GovernorSettingsSpyHelpers { ref self: EventSpy, contract: ContractAddress, old_voting_period: u64, - new_voting_period: u64 + new_voting_period: u64, ) { self.assert_event_voting_period_updated(contract, old_voting_period, new_voting_period); self.assert_no_events_left_from(contract); @@ -436,12 +436,12 @@ pub(crate) impl GovernorSettingsSpyHelpersImpl of GovernorSettingsSpyHelpers { ref self: EventSpy, contract: ContractAddress, old_proposal_threshold: u256, - new_proposal_threshold: u256 + new_proposal_threshold: u256, ) { let expected = GovernorSettingsComponent::Event::ProposalThresholdUpdated( GovernorSettingsComponent::ProposalThresholdUpdated { - old_proposal_threshold, new_proposal_threshold - } + old_proposal_threshold, new_proposal_threshold, + }, ); self.assert_emitted_single(contract, expected); } @@ -450,11 +450,11 @@ pub(crate) impl GovernorSettingsSpyHelpersImpl of GovernorSettingsSpyHelpers { ref self: EventSpy, contract: ContractAddress, old_proposal_threshold: u256, - new_proposal_threshold: u256 + new_proposal_threshold: u256, ) { self .assert_event_proposal_threshold_updated( - contract, old_proposal_threshold, new_proposal_threshold + contract, old_proposal_threshold, new_proposal_threshold, ); self.assert_no_events_left_from(contract); } diff --git a/packages/governance/src/tests/governor/test_governor_timelock_execution.cairo b/packages/governance/src/tests/governor/test_governor_timelock_execution.cairo index b954e5e3c..5a64bc3cf 100644 --- a/packages/governance/src/tests/governor/test_governor_timelock_execution.cairo +++ b/packages/governance/src/tests/governor/test_governor_timelock_execution.cairo @@ -1,34 +1,34 @@ use crate::governor::DefaultConfig; -use crate::governor::GovernorComponent::{InternalImpl, InternalExtendedImpl}; -use crate::governor::extensions::GovernorTimelockExecutionComponent::GovernorExecution; +use crate::governor::GovernorComponent::{InternalExtendedImpl, InternalImpl}; use crate::governor::extensions::GovernorTimelockExecutionComponent; +use crate::governor::extensions::GovernorTimelockExecutionComponent::GovernorExecution; use crate::governor::extensions::interface::{ITimelockedDispatcher, ITimelockedDispatcherTrait}; use crate::governor::interface::ProposalState; use crate::governor::interface::{IGovernorDispatcher, IGovernorDispatcherTrait}; use crate::tests::governor::common::{ - COMPONENT_STATE_TIMELOCKED as COMPONENT_STATE, CONTRACT_STATE_TIMELOCKED as CONTRACT_STATE + COMPONENT_STATE_TIMELOCKED as COMPONENT_STATE, CONTRACT_STATE_TIMELOCKED as CONTRACT_STATE, }; -use crate::tests::governor::common::{set_executor, get_proposal_info, ComponentStateTimelocked}; +use crate::tests::governor::common::{ComponentStateTimelocked, get_proposal_info, set_executor}; use crate::tests::governor::test_governor::GovernorSpyHelpersImpl; use crate::tests::test_timelock::TimelockSpyHelpersImpl; -use crate::timelock::interface::{OperationState, ITimelockDispatcher}; +use crate::timelock::interface::{ITimelockDispatcher, OperationState}; use openzeppelin_test_common::mocks::governor::GovernorMock::SNIP12MetadataImpl; use openzeppelin_test_common::mocks::governor::{ - GovernorTimelockedMock, CancelOperationsDispatcher, CancelOperationsDispatcherTrait + CancelOperationsDispatcher, CancelOperationsDispatcherTrait, GovernorTimelockedMock, }; use openzeppelin_test_common::mocks::timelock::{ - IMockContractDispatcher, IMockContractDispatcherTrait + IMockContractDispatcher, IMockContractDispatcherTrait, }; use openzeppelin_testing as utils; -use openzeppelin_testing::constants::{TIMELOCK, VOTES_TOKEN, OTHER}; +use openzeppelin_testing::constants::{OTHER, TIMELOCK, VOTES_TOKEN}; use openzeppelin_testing::events::EventSpyExt; use openzeppelin_utils::bytearray::ByteArrayExtTrait; use openzeppelin_utils::serde::SerializedAppend; +use snforge_std::{EventSpy, spy_events, start_mock_call, store}; use snforge_std::{start_cheat_block_timestamp_global, start_cheat_caller_address}; -use snforge_std::{start_mock_call, spy_events, store, EventSpy}; use starknet::ContractAddress; use starknet::account::Call; -use starknet::storage::{StoragePathEntry, StoragePointerWriteAccess, StorageMapWriteAccess}; +use starknet::storage::{StorageMapWriteAccess, StoragePathEntry, StoragePointerWriteAccess}; const MIN_DELAY: u64 = 100; @@ -75,7 +75,7 @@ fn setup_dispatchers() -> (IGovernorDispatcher, ITimelockDispatcher, IMockContra store( governor.contract_address, selector!("Governor_timelock_controller"), - array![timelock.contract_address.into()].span() + array![timelock.contract_address.into()].span(), ); (governor, timelock, target) @@ -283,7 +283,7 @@ fn test_execute_operations() { let call = Call { to: target.contract_address, selector: selector!("set_number"), - calldata: array![new_number].span() + calldata: array![new_number].span(), }; let calls = array![call].span(); let description = "proposal description"; @@ -360,7 +360,7 @@ fn test_queue_operations() { let call = Call { to: target.contract_address, selector: selector!("set_number"), - calldata: array![new_number].span() + calldata: array![new_number].span(), }; let calls = array![call].span(); let description = "proposal description"; @@ -434,7 +434,7 @@ fn test_cancel_operations_queued() { let call = Call { to: target.contract_address, selector: selector!("set_number"), - calldata: array![new_number].span() + calldata: array![new_number].span(), }; let calls = array![call].span(); let description = "proposal description"; @@ -725,10 +725,10 @@ pub(crate) impl GovernorTimelockExecutionSpyHelpersImpl of GovernorTimelockExecu ref self: EventSpy, contract: ContractAddress, old_timelock: ContractAddress, - new_timelock: ContractAddress + new_timelock: ContractAddress, ) { let expected = GovernorTimelockExecutionComponent::Event::TimelockUpdated( - GovernorTimelockExecutionComponent::TimelockUpdated { old_timelock, new_timelock } + GovernorTimelockExecutionComponent::TimelockUpdated { old_timelock, new_timelock }, ); self.assert_emitted_single(contract, expected); } @@ -737,7 +737,7 @@ pub(crate) impl GovernorTimelockExecutionSpyHelpersImpl of GovernorTimelockExecu ref self: EventSpy, contract: ContractAddress, old_timelock: ContractAddress, - new_timelock: ContractAddress + new_timelock: ContractAddress, ) { self.assert_event_timelock_updated(contract, old_timelock, new_timelock); self.assert_no_events_left_from(contract); diff --git a/packages/governance/src/tests/governor/test_governor_votes.cairo b/packages/governance/src/tests/governor/test_governor_votes.cairo index 5746793e0..992525ed4 100644 --- a/packages/governance/src/tests/governor/test_governor_votes.cairo +++ b/packages/governance/src/tests/governor/test_governor_votes.cairo @@ -1,12 +1,12 @@ use crate::governor::DefaultConfig; use crate::governor::GovernorComponent::InternalImpl; use crate::governor::extensions::GovernorVotesComponent::{ - GovernorVotes, VotesTokenImpl, InternalTrait + GovernorVotes, InternalTrait, VotesTokenImpl, }; use crate::tests::governor::common::{COMPONENT_STATE, CONTRACT_STATE}; use openzeppelin_test_common::mocks::governor::GovernorMock::SNIP12MetadataImpl; -use openzeppelin_testing::constants::{VOTES_TOKEN, OTHER, ZERO}; -use snforge_std::{start_mock_call, start_cheat_block_timestamp_global}; +use openzeppelin_testing::constants::{OTHER, VOTES_TOKEN, ZERO}; +use snforge_std::{start_cheat_block_timestamp_global, start_mock_call}; use snforge_std::{store, test_address}; // diff --git a/packages/governance/src/tests/governor/test_governor_votes_quorum_fraction.cairo b/packages/governance/src/tests/governor/test_governor_votes_quorum_fraction.cairo index 8b3189a69..49d050058 100644 --- a/packages/governance/src/tests/governor/test_governor_votes_quorum_fraction.cairo +++ b/packages/governance/src/tests/governor/test_governor_votes_quorum_fraction.cairo @@ -1,16 +1,16 @@ use crate::governor::DefaultConfig; -use crate::governor::GovernorComponent::InternalImpl; use crate::governor::GovernorComponent; +use crate::governor::GovernorComponent::InternalImpl; +use crate::governor::extensions::GovernorVotesQuorumFractionComponent; use crate::governor::extensions::GovernorVotesQuorumFractionComponent::{ - GovernorQuorum, GovernorVotes, QuorumFractionImpl, InternalTrait + GovernorQuorum, GovernorVotes, InternalTrait, QuorumFractionImpl, }; -use crate::governor::extensions::GovernorVotesQuorumFractionComponent; -use openzeppelin_test_common::mocks::governor::GovernorQuorumFractionMock::SNIP12MetadataImpl; use openzeppelin_test_common::mocks::governor::GovernorQuorumFractionMock; -use openzeppelin_testing::constants::{VOTES_TOKEN, OTHER, ZERO}; +use openzeppelin_test_common::mocks::governor::GovernorQuorumFractionMock::SNIP12MetadataImpl; +use openzeppelin_testing::constants::{OTHER, VOTES_TOKEN, ZERO}; use openzeppelin_testing::events::EventSpyExt; -use snforge_std::{EventSpy, store, test_address, spy_events}; -use snforge_std::{start_mock_call, start_cheat_block_timestamp_global}; +use snforge_std::{EventSpy, spy_events, store, test_address}; +use snforge_std::{start_cheat_block_timestamp_global, start_mock_call}; use starknet::ContractAddress; pub type ComponentState = @@ -166,14 +166,14 @@ fn test_update_quorum_numerator() { mock_state.governor_votes.update_quorum_numerator(new_quorum_numerator_2); spy .assert_only_event_quorum_numerator_updated( - contract_address, new_quorum_numerator_1, new_quorum_numerator_2 + contract_address, new_quorum_numerator_1, new_quorum_numerator_2, ); start_cheat_block_timestamp_global(ts3); mock_state.governor_votes.update_quorum_numerator(new_quorum_numerator_3); spy .assert_only_event_quorum_numerator_updated( - contract_address, new_quorum_numerator_2, new_quorum_numerator_3 + contract_address, new_quorum_numerator_2, new_quorum_numerator_3, ); // 2. Check the current quorum numerator @@ -207,12 +207,12 @@ pub(crate) impl GovernorSettingsSpyHelpersImpl of GovernorSettingsSpyHelpers { ref self: EventSpy, contract: ContractAddress, old_quorum_numerator: u256, - new_quorum_numerator: u256 + new_quorum_numerator: u256, ) { let expected = GovernorVotesQuorumFractionComponent::Event::QuorumNumeratorUpdated( GovernorVotesQuorumFractionComponent::QuorumNumeratorUpdated { - old_quorum_numerator, new_quorum_numerator - } + old_quorum_numerator, new_quorum_numerator, + }, ); self.assert_emitted_single(contract, expected); } @@ -221,11 +221,11 @@ pub(crate) impl GovernorSettingsSpyHelpersImpl of GovernorSettingsSpyHelpers { ref self: EventSpy, contract: ContractAddress, old_quorum_numerator: u256, - new_quorum_numerator: u256 + new_quorum_numerator: u256, ) { self .assert_event_quorum_numerator_updated( - contract, old_quorum_numerator, new_quorum_numerator + contract, old_quorum_numerator, new_quorum_numerator, ); self.assert_no_events_left_from(contract); } diff --git a/packages/governance/src/tests/test_multisig.cairo b/packages/governance/src/tests/test_multisig.cairo index cfdee1788..90b3d0cdd 100644 --- a/packages/governance/src/tests/test_multisig.cairo +++ b/packages/governance/src/tests/test_multisig.cairo @@ -1,16 +1,16 @@ use core::num::traits::Zero; +use crate::multisig::MultisigComponent::{CallSalt, QuorumUpdated, SignerAdded, SignerRemoved}; use crate::multisig::MultisigComponent::{ConfirmationRevoked, TransactionExecuted}; -use crate::multisig::MultisigComponent::{MultisigImpl, InternalImpl, Event}; -use crate::multisig::MultisigComponent::{SignerAdded, SignerRemoved, QuorumUpdated, CallSalt}; -use crate::multisig::MultisigComponent::{TransactionSubmitted, TransactionConfirmed}; +use crate::multisig::MultisigComponent::{Event, InternalImpl, MultisigImpl}; +use crate::multisig::MultisigComponent::{TransactionConfirmed, TransactionSubmitted}; use crate::multisig::{MultisigComponent, TransactionID, TransactionState}; use openzeppelin_test_common::mocks::multisig::IMultisigTargetMockDispatcherTrait; -use openzeppelin_test_common::mocks::multisig::{MultisigWalletMock, IMultisigTargetMockDispatcher}; +use openzeppelin_test_common::mocks::multisig::{IMultisigTargetMockDispatcher, MultisigWalletMock}; use openzeppelin_testing as utils; -use openzeppelin_testing::constants::{ZERO, OTHER, ALICE, BOB, CHARLIE, SALT, BLOCK_NUMBER}; +use openzeppelin_testing::constants::{ALICE, BLOCK_NUMBER, BOB, CHARLIE, OTHER, SALT, ZERO}; use openzeppelin_testing::events::EventSpyExt; use snforge_std::{EventSpy, spy_events, test_address}; -use snforge_std::{start_cheat_caller_address, start_cheat_block_number_global}; +use snforge_std::{start_cheat_block_number_global, start_cheat_caller_address}; use starknet::account::Call; use starknet::{ContractAddress, contract_address_const}; @@ -135,7 +135,7 @@ fn test_submit_tx_batch() { let calls = array![ build_call(MockCall::AddNumber(42)), build_call(MockCall::AddNumber(18)), - build_call(MockCall::AddNumber(40)) + build_call(MockCall::AddNumber(40)), ] .span(); let salt = 0; @@ -162,7 +162,7 @@ fn test_submit_tx_batch_with_salt() { let calls = array![ build_call(MockCall::AddNumber(42)), build_call(MockCall::AddNumber(18)), - build_call(MockCall::AddNumber(40)) + build_call(MockCall::AddNumber(40)), ] .span(); let salt = SALT; @@ -190,7 +190,7 @@ fn test_submit_same_tx_batch_different_salt() { let calls = array![ build_call(MockCall::AddNumber(42)), build_call(MockCall::AddNumber(18)), - build_call(MockCall::AddNumber(40)) + build_call(MockCall::AddNumber(40)), ] .span(); let salt_1 = 0; @@ -235,7 +235,7 @@ fn test_cannot_submit_tx_batch_unauthorized() { let calls = array![ build_call(MockCall::AddNumber(42)), build_call(MockCall::AddNumber(18)), - build_call(MockCall::AddNumber(40)) + build_call(MockCall::AddNumber(40)), ] .span(); let signer = OTHER(); @@ -265,7 +265,7 @@ fn test_cannot_submit_tx_batch_twice() { let calls = array![ build_call(MockCall::AddNumber(42)), build_call(MockCall::AddNumber(18)), - build_call(MockCall::AddNumber(40)) + build_call(MockCall::AddNumber(40)), ] .span(); let signer = ALICE(); @@ -364,7 +364,7 @@ fn test_confirm_tx_batch() { let calls = array![ build_call(MockCall::AddNumber(42)), build_call(MockCall::AddNumber(18)), - build_call(MockCall::AddNumber(40)) + build_call(MockCall::AddNumber(40)), ] .span(); @@ -625,7 +625,7 @@ fn test_execute_tx_batch() { let calls = array![ build_call(MockCall::AddNumber(42)), build_call(MockCall::AddNumber(18)), - build_call(MockCall::AddNumber(40)) + build_call(MockCall::AddNumber(40)), ] .span(); let salt = 0; @@ -702,7 +702,7 @@ fn test_cannot_execute_batch_unauthorized() { let calls = array![ build_call(MockCall::AddNumber(42)), build_call(MockCall::AddNumber(18)), - build_call(MockCall::AddNumber(40)) + build_call(MockCall::AddNumber(40)), ] .span(); let salt = 0; @@ -845,7 +845,7 @@ fn test_tx_batch_hash_depends_on_salt() { let calls = array![ build_call(MockCall::AddNumber(42)), build_call(MockCall::AddNumber(18)), - build_call(MockCall::AddNumber(40)) + build_call(MockCall::AddNumber(40)), ] .span(); start_cheat_caller_address(test_address(), ALICE()); @@ -1387,7 +1387,7 @@ fn test_cannot_change_quorum_when_not_multisig_itself() { enum MockCall { AddNumber: felt252, FailingFn, - BadSelector + BadSelector, } fn build_call(call: MockCall) -> Call { @@ -1432,7 +1432,7 @@ fn assert_tx_state(id: TransactionID, expected_state: TransactionState) { assert!(is_confirmed); assert!(is_executed); assert!(tx_confirmations >= state.get_quorum()); - } + }, }; } @@ -1456,14 +1456,14 @@ impl MultisigSpyHelpersImpl of MultisigSpyHelpers { // fn assert_event_signer_added( - ref self: EventSpy, contract: ContractAddress, signer: ContractAddress + ref self: EventSpy, contract: ContractAddress, signer: ContractAddress, ) { let expected = Event::SignerAdded(SignerAdded { signer }); self.assert_emitted_single(contract, expected); } fn assert_only_event_signer_added( - ref self: EventSpy, contract: ContractAddress, signer: ContractAddress + ref self: EventSpy, contract: ContractAddress, signer: ContractAddress, ) { self.assert_event_signer_added(contract, signer); self.assert_no_events_left_from(contract); @@ -1474,14 +1474,14 @@ impl MultisigSpyHelpersImpl of MultisigSpyHelpers { // fn assert_event_signer_removed( - ref self: EventSpy, contract: ContractAddress, signer: ContractAddress + ref self: EventSpy, contract: ContractAddress, signer: ContractAddress, ) { let expected = Event::SignerRemoved(SignerRemoved { signer }); self.assert_emitted_single(contract, expected); } fn assert_only_event_signer_removed( - ref self: EventSpy, contract: ContractAddress, signer: ContractAddress + ref self: EventSpy, contract: ContractAddress, signer: ContractAddress, ) { self.assert_event_signer_removed(contract, signer); self.assert_no_events_left_from(contract); @@ -1492,14 +1492,14 @@ impl MultisigSpyHelpersImpl of MultisigSpyHelpers { // fn assert_event_quorum_updated( - ref self: EventSpy, contract: ContractAddress, old_quorum: u32, new_quorum: u32 + ref self: EventSpy, contract: ContractAddress, old_quorum: u32, new_quorum: u32, ) { let expected = Event::QuorumUpdated(QuorumUpdated { old_quorum, new_quorum }); self.assert_emitted_single(contract, expected); } fn assert_only_event_quorum_updated( - ref self: EventSpy, contract: ContractAddress, old_quorum: u32, new_quorum: u32 + ref self: EventSpy, contract: ContractAddress, old_quorum: u32, new_quorum: u32, ) { self.assert_event_quorum_updated(contract, old_quorum, new_quorum); self.assert_no_events_left_from(contract); @@ -1510,14 +1510,14 @@ impl MultisigSpyHelpersImpl of MultisigSpyHelpers { // fn assert_event_tx_submitted( - ref self: EventSpy, contract: ContractAddress, id: TransactionID, signer: ContractAddress + ref self: EventSpy, contract: ContractAddress, id: TransactionID, signer: ContractAddress, ) { let expected = Event::TransactionSubmitted(TransactionSubmitted { id, signer }); self.assert_emitted_single(contract, expected); } fn assert_only_event_tx_submitted( - ref self: EventSpy, contract: ContractAddress, id: TransactionID, signer: ContractAddress + ref self: EventSpy, contract: ContractAddress, id: TransactionID, signer: ContractAddress, ) { self.assert_event_tx_submitted(contract, id, signer); self.assert_no_events_left_from(contract); @@ -1528,14 +1528,14 @@ impl MultisigSpyHelpersImpl of MultisigSpyHelpers { // fn assert_event_tx_confirmed( - ref self: EventSpy, contract: ContractAddress, id: TransactionID, signer: ContractAddress + ref self: EventSpy, contract: ContractAddress, id: TransactionID, signer: ContractAddress, ) { let expected = Event::TransactionConfirmed(TransactionConfirmed { id, signer }); self.assert_emitted_single(contract, expected); } fn assert_only_event_tx_confirmed( - ref self: EventSpy, contract: ContractAddress, id: TransactionID, signer: ContractAddress + ref self: EventSpy, contract: ContractAddress, id: TransactionID, signer: ContractAddress, ) { self.assert_event_tx_confirmed(contract, id, signer); self.assert_no_events_left_from(contract); @@ -1546,14 +1546,14 @@ impl MultisigSpyHelpersImpl of MultisigSpyHelpers { // fn assert_event_confirmation_revoked( - ref self: EventSpy, contract: ContractAddress, id: TransactionID, signer: ContractAddress + ref self: EventSpy, contract: ContractAddress, id: TransactionID, signer: ContractAddress, ) { let expected = Event::ConfirmationRevoked(ConfirmationRevoked { id, signer }); self.assert_emitted_single(contract, expected); } fn assert_only_event_confirmation_revoked( - ref self: EventSpy, contract: ContractAddress, id: TransactionID, signer: ContractAddress + ref self: EventSpy, contract: ContractAddress, id: TransactionID, signer: ContractAddress, ) { self.assert_event_confirmation_revoked(contract, id, signer); self.assert_no_events_left_from(contract); @@ -1569,7 +1569,7 @@ impl MultisigSpyHelpersImpl of MultisigSpyHelpers { } fn assert_only_event_tx_executed( - ref self: EventSpy, contract: ContractAddress, id: TransactionID + ref self: EventSpy, contract: ContractAddress, id: TransactionID, ) { self.assert_event_tx_executed(contract, id); self.assert_no_events_left_from(contract); @@ -1580,7 +1580,7 @@ impl MultisigSpyHelpersImpl of MultisigSpyHelpers { // fn assert_event_call_salt( - ref self: EventSpy, contract: ContractAddress, id: TransactionID, salt: felt252 + ref self: EventSpy, contract: ContractAddress, id: TransactionID, salt: felt252, ) { let expected = Event::CallSalt(CallSalt { id, salt }); self.assert_emitted_single(contract, expected); diff --git a/packages/governance/src/tests/test_timelock.cairo b/packages/governance/src/tests/test_timelock.cairo index e38d8cf93..e1db0d8bd 100644 --- a/packages/governance/src/tests/test_timelock.cairo +++ b/packages/governance/src/tests/test_timelock.cairo @@ -1,17 +1,17 @@ -use core::hash::{HashStateTrait, HashStateExTrait}; +use core::hash::{HashStateExTrait, HashStateTrait}; use core::pedersen::PedersenTrait; use crate::timelock::OperationState; +use crate::timelock::TimelockControllerComponent; use crate::timelock::TimelockControllerComponent::{ - CallScheduled, CallExecuted, CallSalt, CallCancelled, MinDelayChanged + CallCancelled, CallExecuted, CallSalt, CallScheduled, MinDelayChanged, }; use crate::timelock::TimelockControllerComponent::{ - TimelockImpl, InternalImpl as TimelockInternalImpl + InternalImpl as TimelockInternalImpl, TimelockImpl, }; -use crate::timelock::TimelockControllerComponent; use crate::timelock::interface::{TimelockABIDispatcher, TimelockABIDispatcherTrait}; -use crate::timelock::{PROPOSER_ROLE, EXECUTOR_ROLE, CANCELLER_ROLE}; +use crate::timelock::{CANCELLER_ROLE, EXECUTOR_ROLE, PROPOSER_ROLE}; use openzeppelin_access::accesscontrol::AccessControlComponent::{ - AccessControlImpl, InternalImpl as AccessControlInternalImpl + AccessControlImpl, InternalImpl as AccessControlInternalImpl, }; use openzeppelin_access::accesscontrol::DEFAULT_ADMIN_ROLE; use openzeppelin_access::accesscontrol::interface::IACCESSCONTROL_ID; @@ -21,16 +21,16 @@ use openzeppelin_introspection::src5::SRC5Component::SRC5Impl; use openzeppelin_test_common::mocks::timelock::ITimelockAttackerDispatcher; use openzeppelin_test_common::mocks::timelock::TimelockControllerMock; use openzeppelin_test_common::mocks::timelock::{ - IMockContractDispatcher, IMockContractDispatcherTrait + IMockContractDispatcher, IMockContractDispatcherTrait, }; use openzeppelin_testing as utils; -use openzeppelin_testing::constants::{ADMIN, ZERO, OTHER, SALT, FELT_VALUE as VALUE}; +use openzeppelin_testing::constants::{ADMIN, FELT_VALUE as VALUE, OTHER, SALT, ZERO}; use openzeppelin_testing::events::EventSpyExt; use openzeppelin_utils::serde::SerializedAppend; use snforge_std::EventSpy; use snforge_std::{ - spy_events, test_address, start_cheat_caller_address, cheat_caller_address, - start_cheat_block_timestamp_global, CheatSpan + CheatSpan, cheat_caller_address, spy_events, start_cheat_block_timestamp_global, + start_cheat_caller_address, test_address, }; use starknet::ContractAddress; use starknet::account::Call; @@ -170,7 +170,7 @@ fn test_hash_operation() { let mut calldata = array![]; calldata.append_serde(VALUE); let mut call = Call { - to: target.contract_address, selector: selector!("set_number"), calldata: calldata.span() + to: target.contract_address, selector: selector!("set_number"), calldata: calldata.span(), }; // Hash operation @@ -199,7 +199,7 @@ fn test_hash_operation_batch() { let mut calldata = array![]; calldata.append_serde(VALUE); let mut call = Call { - to: target.contract_address, selector: selector!("set_number"), calldata: calldata.span() + to: target.contract_address, selector: selector!("set_number"), calldata: calldata.span(), }; let calls = array![call, call, call].span(); @@ -260,13 +260,13 @@ fn schedule_from_proposer(salt: felt252) { if salt != 0 { spy .assert_event_call_scheduled( - timelock.contract_address, target_id, event_index, call, predecessor, delay + timelock.contract_address, target_id, event_index, call, predecessor, delay, ); spy.assert_only_event_call_salt(timelock.contract_address, target_id, salt); } else { spy .assert_only_event_call_scheduled( - timelock.contract_address, target_id, event_index, call, predecessor, delay + timelock.contract_address, target_id, event_index, call, predecessor, delay, ); } } @@ -358,13 +358,13 @@ fn schedule_batch_from_proposer(salt: felt252) { if salt != 0 { spy .assert_events_call_scheduled_batch( - timelock.contract_address, target_id, calls, predecessor, delay + timelock.contract_address, target_id, calls, predecessor, delay, ); spy.assert_only_event_call_salt(timelock.contract_address, target_id, salt); } else { spy .assert_only_events_call_scheduled_batch( - timelock.contract_address, target_id, calls, predecessor, delay + timelock.contract_address, target_id, calls, predecessor, delay, ); } } @@ -462,7 +462,7 @@ fn test_execute_when_scheduled() { let event_index = 0; spy .assert_only_event_call_scheduled( - timelock.contract_address, target_id, event_index, call, predecessor, delay + timelock.contract_address, target_id, event_index, call, predecessor, delay, ); assert_operation_state(timelock, OperationState::Waiting, target_id); @@ -591,7 +591,7 @@ fn test_execute_reentrant_call() { let delay = MIN_DELAY; let reentrant_call = Call { - to: attacker.contract_address, selector: selector!("reenter"), calldata: array![].span() + to: attacker.contract_address, selector: selector!("reenter"), calldata: array![].span(), }; // Schedule @@ -671,7 +671,7 @@ fn test_execute_after_dependency() { assert_operation_state(timelock, OperationState::Waiting, target_id_1); spy .assert_only_event_call_scheduled( - timelock.contract_address, target_id_1, event_index, call_1, predecessor_1, delay + timelock.contract_address, target_id_1, event_index, call_1, predecessor_1, delay, ); // Schedule call 2 @@ -679,7 +679,7 @@ fn test_execute_after_dependency() { assert_operation_state(timelock, OperationState::Waiting, target_id_2); spy .assert_only_event_call_scheduled( - timelock.contract_address, target_id_2, event_index, call_2, predecessor_2, delay + timelock.contract_address, target_id_2, event_index, call_2, predecessor_2, delay, ); // Fast-forward @@ -698,7 +698,7 @@ fn test_execute_after_dependency() { assert_operation_state(timelock, OperationState::Done, target_id_2); spy .assert_only_event_call_executed( - timelock.contract_address, target_id_2, event_index, call_2 + timelock.contract_address, target_id_2, event_index, call_2, ); } @@ -739,7 +739,7 @@ fn test_execute_batch_when_scheduled() { assert_operation_state(timelock, OperationState::Waiting, target_id); spy .assert_only_events_call_scheduled_batch( - timelock.contract_address, target_id, calls, predecessor, delay + timelock.contract_address, target_id, calls, predecessor, delay, ); // Fast-forward @@ -818,7 +818,7 @@ fn test_execute_batch_reentrant_call() { let reentrant_call = Call { to: attacker.contract_address, selector: selector!("reenter_batch"), - calldata: array![].span() + calldata: array![].span(), }; let calls = array![reentrant_call].span(); @@ -919,7 +919,7 @@ fn test_execute_batch_after_dependency() { assert_operation_state(timelock, OperationState::Waiting, target_id_1); spy .assert_only_events_call_scheduled_batch( - timelock.contract_address, target_id_1, calls_1, predecessor_1, delay + timelock.contract_address, target_id_1, calls_1, predecessor_1, delay, ); // Schedule calls 2 @@ -928,7 +928,7 @@ fn test_execute_batch_after_dependency() { assert_operation_state(timelock, OperationState::Waiting, target_id_2); spy .assert_only_events_call_scheduled_batch( - timelock.contract_address, target_id_2, calls_2, predecessor_2, delay + timelock.contract_address, target_id_2, calls_2, predecessor_2, delay, ); // Fast-forward @@ -973,7 +973,7 @@ fn cancel_from_canceller(operation_state: OperationState) { assert_operation_state(timelock, OperationState::Waiting, target_id); spy .assert_only_event_call_scheduled( - timelock.contract_address, target_id, event_index, call, predecessor, delay + timelock.contract_address, target_id, event_index, call, predecessor, delay, ); if operation_state == OperationState::Ready { @@ -1086,7 +1086,7 @@ fn test_update_delay_scheduled() { let call = Call { to: timelock.contract_address, selector: selector!("update_delay"), - calldata: array![NEW_DELAY.into()].span() + calldata: array![NEW_DELAY.into()].span(), }; let target_id = timelock.hash_operation(call, predecessor, salt); @@ -1098,7 +1098,7 @@ fn test_update_delay_scheduled() { assert_operation_state(timelock, OperationState::Waiting, target_id); spy .assert_only_event_call_scheduled( - timelock.contract_address, target_id, event_index, call, predecessor, delay + timelock.contract_address, target_id, event_index, call, predecessor, delay, ); // Fast-forward @@ -1655,7 +1655,7 @@ fn assert_operation_state(timelock: TimelockABIDispatcher, exp_state: OperationS assert!(!is_pending); assert!(!is_ready); assert!(is_done); - } + }, }; } @@ -1676,10 +1676,10 @@ pub(crate) impl TimelockSpyHelpersImpl of TimelockSpyHelpers { index: felt252, call: Call, predecessor: felt252, - delay: u64 + delay: u64, ) { let expected = TimelockControllerComponent::Event::CallScheduled( - CallScheduled { id, index, call, predecessor, delay } + CallScheduled { id, index, call, predecessor, delay }, ); self.assert_emitted_single(contract, expected); } @@ -1691,7 +1691,7 @@ pub(crate) impl TimelockSpyHelpersImpl of TimelockSpyHelpers { index: felt252, call: Call, predecessor: felt252, - delay: u64 + delay: u64, ) { self.assert_event_call_scheduled(contract, id, index, call, predecessor, delay); self.assert_no_events_left_from(contract); @@ -1703,7 +1703,7 @@ pub(crate) impl TimelockSpyHelpersImpl of TimelockSpyHelpers { id: felt252, calls: Span, predecessor: felt252, - delay: u64 + delay: u64, ) { let mut i = 0; loop { @@ -1712,7 +1712,7 @@ pub(crate) impl TimelockSpyHelpersImpl of TimelockSpyHelpers { } self .assert_event_call_scheduled( - contract, id, i.into(), *calls.at(i), predecessor, delay + contract, id, i.into(), *calls.at(i), predecessor, delay, ); i += 1; }; @@ -1724,7 +1724,7 @@ pub(crate) impl TimelockSpyHelpersImpl of TimelockSpyHelpers { id: felt252, calls: Span, predecessor: felt252, - delay: u64 + delay: u64, ) { self.assert_events_call_scheduled_batch(contract, id, calls, predecessor, delay); self.assert_no_events_left_from(contract); @@ -1735,14 +1735,14 @@ pub(crate) impl TimelockSpyHelpersImpl of TimelockSpyHelpers { // fn assert_event_call_salt( - ref self: EventSpy, contract: ContractAddress, id: felt252, salt: felt252 + ref self: EventSpy, contract: ContractAddress, id: felt252, salt: felt252, ) { let expected = TimelockControllerComponent::Event::CallSalt(CallSalt { id, salt }); self.assert_emitted_single(contract, expected); } fn assert_only_event_call_salt( - ref self: EventSpy, contract: ContractAddress, id: felt252, salt: felt252 + ref self: EventSpy, contract: ContractAddress, id: felt252, salt: felt252, ) { self.assert_event_call_salt(contract, id, salt); self.assert_no_events_left_from(contract); @@ -1758,7 +1758,7 @@ pub(crate) impl TimelockSpyHelpersImpl of TimelockSpyHelpers { } fn assert_only_event_call_cancelled( - ref self: EventSpy, contract: ContractAddress, id: felt252 + ref self: EventSpy, contract: ContractAddress, id: felt252, ) { self.assert_event_call_cancelled(contract, id); self.assert_no_events_left_from(contract); @@ -1769,23 +1769,23 @@ pub(crate) impl TimelockSpyHelpersImpl of TimelockSpyHelpers { // fn assert_event_call_executed( - ref self: EventSpy, contract: ContractAddress, id: felt252, index: felt252, call: Call + ref self: EventSpy, contract: ContractAddress, id: felt252, index: felt252, call: Call, ) { let expected = TimelockControllerComponent::Event::CallExecuted( - CallExecuted { id, index, call } + CallExecuted { id, index, call }, ); self.assert_emitted_single(contract, expected); } fn assert_only_event_call_executed( - ref self: EventSpy, contract: ContractAddress, id: felt252, index: felt252, call: Call + ref self: EventSpy, contract: ContractAddress, id: felt252, index: felt252, call: Call, ) { self.assert_event_call_executed(contract, id, index, call); self.assert_no_events_left_from(contract); } fn assert_events_call_executed_batch( - ref self: EventSpy, contract: ContractAddress, id: felt252, calls: Span + ref self: EventSpy, contract: ContractAddress, id: felt252, calls: Span, ) { let mut i = 0; loop { @@ -1798,7 +1798,7 @@ pub(crate) impl TimelockSpyHelpersImpl of TimelockSpyHelpers { } fn assert_only_events_call_executed_batch( - ref self: EventSpy, contract: ContractAddress, id: felt252, calls: Span + ref self: EventSpy, contract: ContractAddress, id: felt252, calls: Span, ) { self.assert_events_call_executed_batch(contract, id, calls); self.assert_no_events_left_from(contract); @@ -1812,7 +1812,7 @@ pub(crate) impl TimelockSpyHelpersImpl of TimelockSpyHelpers { ref self: EventSpy, contract: ContractAddress, old_duration: u64, new_duration: u64, ) { let expected = TimelockControllerComponent::Event::MinDelayChanged( - MinDelayChanged { old_duration, new_duration } + MinDelayChanged { old_duration, new_duration }, ); self.assert_emitted_single(contract, expected); } diff --git a/packages/governance/src/tests/test_utils.cairo b/packages/governance/src/tests/test_utils.cairo index d1bf2b7c1..97b4dc77d 100644 --- a/packages/governance/src/tests/test_utils.cairo +++ b/packages/governance/src/tests/test_utils.cairo @@ -16,10 +16,10 @@ fn test_eq_calls_no_calldata() { #[test] fn test_eq_calls_with_calldata() { let call_1 = Call { - to: contract_address_const::<1>(), selector: 1, calldata: array![1, 2, 3].span() + to: contract_address_const::<1>(), selector: 1, calldata: array![1, 2, 3].span(), }; let call_2 = Call { - to: contract_address_const::<1>(), selector: 1, calldata: array![1, 2, 3].span() + to: contract_address_const::<1>(), selector: 1, calldata: array![1, 2, 3].span(), }; assert_eq!(call_1, call_2); } @@ -44,7 +44,7 @@ fn test_eq_calls_ne_selector() { #[should_panic] fn test_eq_calls_gt_calldata() { let call_1 = Call { - to: contract_address_const::<1>(), selector: 1, calldata: array![1].span() + to: contract_address_const::<1>(), selector: 1, calldata: array![1].span(), }; let call_2 = Call { to: contract_address_const::<1>(), selector: 2, calldata: array![].span() }; assert_eq!(call_1, call_2); @@ -54,10 +54,10 @@ fn test_eq_calls_gt_calldata() { #[should_panic] fn test_eq_calls_lt_calldata() { let call_1 = Call { - to: contract_address_const::<1>(), selector: 1, calldata: array![1].span() + to: contract_address_const::<1>(), selector: 1, calldata: array![1].span(), }; let call_2 = Call { - to: contract_address_const::<1>(), selector: 2, calldata: array![1, 2].span() + to: contract_address_const::<1>(), selector: 2, calldata: array![1, 2].span(), }; assert_eq!(call_1, call_2); } @@ -66,10 +66,10 @@ fn test_eq_calls_lt_calldata() { #[should_panic] fn test_eq_calls_ne_calldata() { let call_1 = Call { - to: contract_address_const::<1>(), selector: 1, calldata: array![1, 2].span() + to: contract_address_const::<1>(), selector: 1, calldata: array![1, 2].span(), }; let call_2 = Call { - to: contract_address_const::<1>(), selector: 2, calldata: array![2, 1].span() + to: contract_address_const::<1>(), selector: 2, calldata: array![2, 1].span(), }; assert_eq!(call_1, call_2); } @@ -81,10 +81,10 @@ fn test_eq_calls_ne_calldata() { #[test] fn test_ne_calls_to() { let call_1 = Call { - to: contract_address_const::<1>(), selector: 1, calldata: array![1, 2, 3].span() + to: contract_address_const::<1>(), selector: 1, calldata: array![1, 2, 3].span(), }; let call_2 = Call { - to: contract_address_const::<2>(), selector: 1, calldata: array![1, 2, 3].span() + to: contract_address_const::<2>(), selector: 1, calldata: array![1, 2, 3].span(), }; assert_ne!(call_1, call_2); } @@ -92,10 +92,10 @@ fn test_ne_calls_to() { #[test] fn test_ne_calls_selector() { let call_1 = Call { - to: contract_address_const::<1>(), selector: 1, calldata: array![1, 2, 3].span() + to: contract_address_const::<1>(), selector: 1, calldata: array![1, 2, 3].span(), }; let call_2 = Call { - to: contract_address_const::<1>(), selector: 2, calldata: array![1, 2, 3].span() + to: contract_address_const::<1>(), selector: 2, calldata: array![1, 2, 3].span(), }; assert_ne!(call_1, call_2); } @@ -103,10 +103,10 @@ fn test_ne_calls_selector() { #[test] fn test_ne_calls_gt_calldata() { let call_1 = Call { - to: contract_address_const::<1>(), selector: 1, calldata: array![1, 2, 3].span() + to: contract_address_const::<1>(), selector: 1, calldata: array![1, 2, 3].span(), }; let call_2 = Call { - to: contract_address_const::<1>(), selector: 1, calldata: array![1, 2].span() + to: contract_address_const::<1>(), selector: 1, calldata: array![1, 2].span(), }; assert_ne!(call_1, call_2); } @@ -114,10 +114,10 @@ fn test_ne_calls_gt_calldata() { #[test] fn test_ne_calls_lt_calldata() { let call_1 = Call { - to: contract_address_const::<1>(), selector: 1, calldata: array![1, 2].span() + to: contract_address_const::<1>(), selector: 1, calldata: array![1, 2].span(), }; let call_2 = Call { - to: contract_address_const::<1>(), selector: 1, calldata: array![1, 2, 3].span() + to: contract_address_const::<1>(), selector: 1, calldata: array![1, 2, 3].span(), }; assert_ne!(call_1, call_2); } @@ -125,10 +125,10 @@ fn test_ne_calls_lt_calldata() { #[test] fn test_ne_calls_eq_len_calldata() { let call_1 = Call { - to: contract_address_const::<1>(), selector: 1, calldata: array![1, 2, 3].span() + to: contract_address_const::<1>(), selector: 1, calldata: array![1, 2, 3].span(), }; let call_2 = Call { - to: contract_address_const::<1>(), selector: 1, calldata: array![3, 2, 1].span() + to: contract_address_const::<1>(), selector: 1, calldata: array![3, 2, 1].span(), }; assert_ne!(call_1, call_2); } @@ -137,10 +137,10 @@ fn test_ne_calls_eq_len_calldata() { #[should_panic] fn test_ne_calls_when_eq() { let call_1 = Call { - to: contract_address_const::<1>(), selector: 1, calldata: array![1, 2, 3].span() + to: contract_address_const::<1>(), selector: 1, calldata: array![1, 2, 3].span(), }; let call_2 = Call { - to: contract_address_const::<1>(), selector: 1, calldata: array![1, 2, 3].span() + to: contract_address_const::<1>(), selector: 1, calldata: array![1, 2, 3].span(), }; assert_ne!(call_1, call_2); } diff --git a/packages/governance/src/tests/test_votes.cairo b/packages/governance/src/tests/test_votes.cairo index 06374912f..ee919158d 100644 --- a/packages/governance/src/tests/test_votes.cairo +++ b/packages/governance/src/tests/test_votes.cairo @@ -1,27 +1,27 @@ use crate::votes::Delegation; -use crate::votes::VotesComponent::VotingUnitsTrait; -use crate::votes::VotesComponent::{DelegateChanged, DelegateVotesChanged, VotesImpl, InternalImpl}; use crate::votes::VotesComponent; +use crate::votes::VotesComponent::VotingUnitsTrait; +use crate::votes::VotesComponent::{DelegateChanged, DelegateVotesChanged, InternalImpl, VotesImpl}; use openzeppelin_test_common::mocks::votes::ERC721VotesMock::SNIP12MetadataImpl; -use openzeppelin_test_common::mocks::votes::{ERC721VotesMock, ERC20VotesMock}; +use openzeppelin_test_common::mocks::votes::{ERC20VotesMock, ERC721VotesMock}; use openzeppelin_testing as utils; -use openzeppelin_testing::constants::{SUPPLY, ZERO, DELEGATOR, DELEGATEE, OTHER, RECIPIENT}; +use openzeppelin_testing::constants::{DELEGATEE, DELEGATOR, OTHER, RECIPIENT, SUPPLY, ZERO}; use openzeppelin_testing::events::EventSpyExt; use openzeppelin_token::erc20::ERC20Component::InternalTrait; use openzeppelin_token::erc20::interface::IERC20; +use openzeppelin_token::erc721::ERC721Component::{ERC721CamelOnlyImpl, ERC721Impl}; use openzeppelin_token::erc721::ERC721Component::{ ERC721MetadataImpl, InternalImpl as ERC721InternalImpl, }; -use openzeppelin_token::erc721::ERC721Component::{ERC721Impl, ERC721CamelOnlyImpl}; use openzeppelin_token::erc721::interface::IERC721; use openzeppelin_utils::cryptography::snip12::OffchainMessageHash; use openzeppelin_utils::structs::checkpoint::TraceTrait; use snforge_std::signature::stark_curve::{StarkCurveKeyPairImpl, StarkCurveSignerImpl}; +use snforge_std::{EventSpy}; use snforge_std::{ - start_cheat_block_timestamp_global, start_cheat_caller_address, spy_events, test_address, - start_cheat_chain_id_global + spy_events, start_cheat_block_timestamp_global, start_cheat_caller_address, + start_cheat_chain_id_global, test_address, }; -use snforge_std::{EventSpy}; use starknet::storage::StoragePathEntry; use starknet::{ContractAddress, contract_address_const}; @@ -195,7 +195,7 @@ fn test_self_delegate() { spy.assert_event_delegate_changed(contract_address, DELEGATOR(), ZERO(), DELEGATOR()); spy .assert_only_event_delegate_votes_changed( - contract_address, DELEGATOR(), 0, ERC721_INITIAL_MINT + contract_address, DELEGATOR(), 0, ERC721_INITIAL_MINT, ); assert_eq!(state.get_votes(DELEGATOR()), ERC721_INITIAL_MINT); } @@ -211,7 +211,7 @@ fn test_delegate_to_delegatee_updates_votes() { spy.assert_event_delegate_changed(contract_address, DELEGATOR(), ZERO(), DELEGATEE()); spy .assert_only_event_delegate_votes_changed( - contract_address, DELEGATEE(), 0, ERC721_INITIAL_MINT + contract_address, DELEGATEE(), 0, ERC721_INITIAL_MINT, ); assert_eq!(state.get_votes(DELEGATEE()), ERC721_INITIAL_MINT); assert_eq!(state.get_votes(DELEGATOR()), 0); @@ -289,7 +289,7 @@ fn test_delegate_by_sig_hash_generation() { let nonce = 0; let expiry = 'ts2'; let delegator = contract_address_const::< - 0x70b0526a4bfbc9ca717c96aeb5a8afac85181f4585662273668928585a0d628 + 0x70b0526a4bfbc9ca717c96aeb5a8afac85181f4585662273668928585a0d628, >(); let verifying_contract = contract_address_const::<'VERIFIER'>(); let delegatee = RECIPIENT(); @@ -485,7 +485,7 @@ fn test_erc20_burn_updates_votes() { start_cheat_block_timestamp_global('ts2'); spy .assert_event_delegate_votes_changed( - contract_address, DELEGATOR(), SUPPLY, SUPPLY - burn_amount + contract_address, DELEGATOR(), SUPPLY, SUPPLY - burn_amount, ); assert_eq!(state.get_votes(DELEGATOR()), SUPPLY - burn_amount); assert_eq!(state.get_past_total_supply('ts1'), SUPPLY - burn_amount); @@ -504,17 +504,13 @@ fn test_erc721_burn_updates_votes() { // Set spy and burn some tokens let mut spy = spy_events(); let burn_amount = 3; - for i in 0 - ..burn_amount { - mock_state.erc721.burn(i); - spy - .assert_event_delegate_votes_changed( - contract_address, - DELEGATOR(), - ERC721_INITIAL_MINT - i, - ERC721_INITIAL_MINT - i - 1 - ); - }; + for i in 0..burn_amount { + mock_state.erc721.burn(i); + spy + .assert_event_delegate_votes_changed( + contract_address, DELEGATOR(), ERC721_INITIAL_MINT - i, ERC721_INITIAL_MINT - i - 1, + ); + }; // We need to move the timestamp forward to be able to call get_past_total_supply start_cheat_block_timestamp_global('ts2'); @@ -581,7 +577,7 @@ fn test_erc_20_voting_units_update_with_partial_balance_transfer() { spy .assert_event_delegate_votes_changed( - contract_address, DELEGATOR(), SUPPLY, SUPPLY - partial_amount + contract_address, DELEGATOR(), SUPPLY, SUPPLY - partial_amount, ); assert_eq!(state.get_votes(DELEGATOR()), SUPPLY - partial_amount); assert_eq!(state.get_votes(RECIPIENT()), 0); // RECIPIENT hasn't delegated yet @@ -613,7 +609,7 @@ fn test_erc721_voting_units_update_with_single_token_transfer() { spy .assert_event_delegate_votes_changed( - contract_address, DELEGATOR(), ERC721_INITIAL_MINT, ERC721_INITIAL_MINT - 1 + contract_address, DELEGATOR(), ERC721_INITIAL_MINT, ERC721_INITIAL_MINT - 1, ); assert_eq!(state.get_votes(DELEGATOR()), ERC721_INITIAL_MINT - 1); @@ -638,10 +634,10 @@ impl VotesSpyHelpersImpl of VotesSpyHelpers { contract: ContractAddress, delegator: ContractAddress, from_delegate: ContractAddress, - to_delegate: ContractAddress + to_delegate: ContractAddress, ) { let expected = VotesComponent::Event::DelegateChanged( - DelegateChanged { delegator, from_delegate, to_delegate } + DelegateChanged { delegator, from_delegate, to_delegate }, ); self.assert_emitted_single(contract, expected); } @@ -651,10 +647,10 @@ impl VotesSpyHelpersImpl of VotesSpyHelpers { contract: ContractAddress, delegate: ContractAddress, previous_votes: u256, - new_votes: u256 + new_votes: u256, ) { let expected = VotesComponent::Event::DelegateVotesChanged( - DelegateVotesChanged { delegate, previous_votes, new_votes } + DelegateVotesChanged { delegate, previous_votes, new_votes }, ); self.assert_emitted_single(contract, expected); } @@ -664,7 +660,7 @@ impl VotesSpyHelpersImpl of VotesSpyHelpers { contract: ContractAddress, delegator: ContractAddress, from_delegate: ContractAddress, - to_delegate: ContractAddress + to_delegate: ContractAddress, ) { self.assert_event_delegate_changed(contract, delegator, from_delegate, to_delegate); self.assert_no_events_left_from(contract); @@ -675,7 +671,7 @@ impl VotesSpyHelpersImpl of VotesSpyHelpers { contract: ContractAddress, delegate: ContractAddress, previous_votes: u256, - new_votes: u256 + new_votes: u256, ) { self.assert_event_delegate_votes_changed(contract, delegate, previous_votes, new_votes); self.assert_no_events_left_from(contract); diff --git a/packages/governance/src/timelock.cairo b/packages/governance/src/timelock.cairo index 7ce673051..473c9f647 100644 --- a/packages/governance/src/timelock.cairo +++ b/packages/governance/src/timelock.cairo @@ -2,7 +2,7 @@ pub mod interface; pub mod timelock_controller; pub use interface::OperationState; +pub use timelock_controller::TimelockControllerComponent; pub use timelock_controller::TimelockControllerComponent::{ - PROPOSER_ROLE, CANCELLER_ROLE, EXECUTOR_ROLE + CANCELLER_ROLE, EXECUTOR_ROLE, PROPOSER_ROLE, }; -pub use timelock_controller::TimelockControllerComponent; diff --git a/packages/governance/src/timelock/interface.cairo b/packages/governance/src/timelock/interface.cairo index d201c37f9..d2fb733e7 100644 --- a/packages/governance/src/timelock/interface.cairo +++ b/packages/governance/src/timelock/interface.cairo @@ -9,7 +9,7 @@ pub enum OperationState { Unset, Waiting, Ready, - Done + Done, } #[starknet::interface] @@ -23,11 +23,11 @@ pub trait ITimelock { fn get_min_delay(self: @TState) -> u64; fn hash_operation(self: @TState, call: Call, predecessor: felt252, salt: felt252) -> felt252; fn hash_operation_batch( - self: @TState, calls: Span, predecessor: felt252, salt: felt252 + self: @TState, calls: Span, predecessor: felt252, salt: felt252, ) -> felt252; fn schedule(ref self: TState, call: Call, predecessor: felt252, salt: felt252, delay: u64); fn schedule_batch( - ref self: TState, calls: Span, predecessor: felt252, salt: felt252, delay: u64 + ref self: TState, calls: Span, predecessor: felt252, salt: felt252, delay: u64, ); fn cancel(ref self: TState, id: felt252); fn execute(ref self: TState, call: Call, predecessor: felt252, salt: felt252); @@ -46,11 +46,11 @@ pub trait TimelockABI { fn get_min_delay(self: @TState) -> u64; fn hash_operation(self: @TState, call: Call, predecessor: felt252, salt: felt252) -> felt252; fn hash_operation_batch( - self: @TState, calls: Span, predecessor: felt252, salt: felt252 + self: @TState, calls: Span, predecessor: felt252, salt: felt252, ) -> felt252; fn schedule(ref self: TState, call: Call, predecessor: felt252, salt: felt252, delay: u64); fn schedule_batch( - ref self: TState, calls: Span, predecessor: felt252, salt: felt252, delay: u64 + ref self: TState, calls: Span, predecessor: felt252, salt: felt252, delay: u64, ); fn cancel(ref self: TState, id: felt252); fn execute(ref self: TState, call: Call, predecessor: felt252, salt: felt252); diff --git a/packages/governance/src/timelock/timelock_controller.cairo b/packages/governance/src/timelock/timelock_controller.cairo index 1820e0a7a..807abc89a 100644 --- a/packages/governance/src/timelock/timelock_controller.cairo +++ b/packages/governance/src/timelock/timelock_controller.cairo @@ -14,19 +14,19 @@ /// or a DAO as the sole proposer. #[starknet::component] pub mod TimelockControllerComponent { - use core::hash::{HashStateTrait, HashStateExTrait}; + use core::hash::{HashStateExTrait, HashStateTrait}; use core::num::traits::Zero; use core::pedersen::PedersenTrait; - use crate::timelock::interface::{OperationState, ITimelock, TimelockABI}; - use crate::utils::call_impls::{HashCallImpl, HashCallsImpl, CallPartialEq}; + use crate::timelock::interface::{ITimelock, OperationState, TimelockABI}; + use crate::utils::call_impls::{CallPartialEq, HashCallImpl, HashCallsImpl}; + use openzeppelin_access::accesscontrol::AccessControlComponent; use openzeppelin_access::accesscontrol::AccessControlComponent::InternalTrait as AccessControlInternalTrait; use openzeppelin_access::accesscontrol::AccessControlComponent::{ - AccessControlImpl, AccessControlCamelImpl + AccessControlCamelImpl, AccessControlImpl, }; - use openzeppelin_access::accesscontrol::AccessControlComponent; use openzeppelin_access::accesscontrol::DEFAULT_ADMIN_ROLE; - use openzeppelin_introspection::src5::SRC5Component::SRC5Impl; use openzeppelin_introspection::src5::SRC5Component; + use openzeppelin_introspection::src5::SRC5Component::SRC5Impl; use starknet::ContractAddress; use starknet::SyscallResultTrait; use starknet::account::Call; @@ -42,7 +42,7 @@ pub mod TimelockControllerComponent { #[storage] pub struct Storage { pub TimelockController_timestamps: Map, - pub TimelockController_min_delay: u64 + pub TimelockController_min_delay: u64, } #[event] @@ -52,7 +52,7 @@ pub mod TimelockControllerComponent { CallExecuted: CallExecuted, CallSalt: CallSalt, CallCancelled: CallCancelled, - MinDelayChanged: MinDelayChanged + MinDelayChanged: MinDelayChanged, } /// Emitted when `call` is scheduled as part of operation `id`. @@ -64,7 +64,7 @@ pub mod TimelockControllerComponent { pub index: felt252, pub call: Call, pub predecessor: felt252, - pub delay: u64 + pub delay: u64, } /// Emitted when `call` is performed as part of operation `id`. @@ -74,7 +74,7 @@ pub mod TimelockControllerComponent { pub id: felt252, #[key] pub index: felt252, - pub call: Call + pub call: Call, } /// Emitted when a new proposal is scheduled with non-zero salt. @@ -82,21 +82,21 @@ pub mod TimelockControllerComponent { pub struct CallSalt { #[key] pub id: felt252, - pub salt: felt252 + pub salt: felt252, } /// Emitted when operation `id` is cancelled. #[derive(Drop, PartialEq, starknet::Event)] pub struct CallCancelled { #[key] - pub id: felt252 + pub id: felt252, } /// Emitted when the minimum delay for future operations is modified. #[derive(Drop, PartialEq, starknet::Event)] pub struct MinDelayChanged { pub old_duration: u64, - pub new_duration: u64 + pub new_duration: u64, } pub mod Errors { @@ -119,7 +119,7 @@ pub mod TimelockControllerComponent { +HasComponent, +SRC5Component::HasComponent, +AccessControlComponent::HasComponent, - +Drop + +Drop, > of ITimelock> { /// Returns whether `id` corresponds to a registered operation. /// This includes the OperationStates: `Waiting`, `Ready`, and `Done`. @@ -154,7 +154,7 @@ pub mod TimelockControllerComponent { /// Returns the OperationState for `id`. fn get_operation_state( - self: @ComponentState, id: felt252 + self: @ComponentState, id: felt252, ) -> OperationState { let timestamp = Self::get_timestamp(self, id); if timestamp == 0 { @@ -176,7 +176,7 @@ pub mod TimelockControllerComponent { /// Returns the identifier of an operation containing a single transaction. fn hash_operation( - self: @ComponentState, call: Call, predecessor: felt252, salt: felt252 + self: @ComponentState, call: Call, predecessor: felt252, salt: felt252, ) -> felt252 { PedersenTrait::new(0) .update_with(call) @@ -190,7 +190,7 @@ pub mod TimelockControllerComponent { self: @ComponentState, calls: Span, predecessor: felt252, - salt: felt252 + salt: felt252, ) -> felt252 { PedersenTrait::new(0) .update_with(calls) @@ -214,7 +214,7 @@ pub mod TimelockControllerComponent { call: Call, predecessor: felt252, salt: felt252, - delay: u64 + delay: u64, ) { self.assert_only_role(PROPOSER_ROLE); @@ -242,7 +242,7 @@ pub mod TimelockControllerComponent { calls: Span, predecessor: felt252, salt: felt252, - delay: u64 + delay: u64, ) { self.assert_only_role(PROPOSER_ROLE); @@ -293,7 +293,7 @@ pub mod TimelockControllerComponent { ref self: ComponentState, call: Call, predecessor: felt252, - salt: felt252 + salt: felt252, ) { self.assert_only_role_or_open_role(EXECUTOR_ROLE); @@ -321,7 +321,7 @@ pub mod TimelockControllerComponent { ref self: ComponentState, calls: Span, predecessor: felt252, - salt: felt252 + salt: felt252, ) { self.assert_only_role_or_open_role(EXECUTOR_ROLE); @@ -363,7 +363,7 @@ pub mod TimelockControllerComponent { +HasComponent, impl SRC5: SRC5Component::HasComponent, impl AccessControl: AccessControlComponent::HasComponent, - +Drop + +Drop, > of TimelockABI> { fn is_operation(self: @ComponentState, id: felt252) -> bool { Timelock::is_operation(self, id) @@ -386,7 +386,7 @@ pub mod TimelockControllerComponent { } fn get_operation_state( - self: @ComponentState, id: felt252 + self: @ComponentState, id: felt252, ) -> OperationState { Timelock::get_operation_state(self, id) } @@ -396,7 +396,7 @@ pub mod TimelockControllerComponent { } fn hash_operation( - self: @ComponentState, call: Call, predecessor: felt252, salt: felt252 + self: @ComponentState, call: Call, predecessor: felt252, salt: felt252, ) -> felt252 { Timelock::hash_operation(self, call, predecessor, salt) } @@ -405,7 +405,7 @@ pub mod TimelockControllerComponent { self: @ComponentState, calls: Span, predecessor: felt252, - salt: felt252 + salt: felt252, ) -> felt252 { Timelock::hash_operation_batch(self, calls, predecessor, salt) } @@ -415,7 +415,7 @@ pub mod TimelockControllerComponent { call: Call, predecessor: felt252, salt: felt252, - delay: u64 + delay: u64, ) { Timelock::schedule(ref self, call, predecessor, salt, delay); } @@ -425,7 +425,7 @@ pub mod TimelockControllerComponent { calls: Span, predecessor: felt252, salt: felt252, - delay: u64 + delay: u64, ) { Timelock::schedule_batch(ref self, calls, predecessor, salt, delay); } @@ -438,7 +438,7 @@ pub mod TimelockControllerComponent { ref self: ComponentState, call: Call, predecessor: felt252, - salt: felt252 + salt: felt252, ) { Timelock::execute(ref self, call, predecessor, salt); } @@ -447,7 +447,7 @@ pub mod TimelockControllerComponent { ref self: ComponentState, calls: Span, predecessor: felt252, - salt: felt252 + salt: felt252, ) { Timelock::execute_batch(ref self, calls, predecessor, salt); } @@ -458,7 +458,7 @@ pub mod TimelockControllerComponent { // ISRC5 fn supports_interface( - self: @ComponentState, interface_id: felt252 + self: @ComponentState, interface_id: felt252, ) -> bool { let src5 = get_dep_component!(self, SRC5); src5.supports_interface(interface_id) @@ -466,7 +466,7 @@ pub mod TimelockControllerComponent { // IAccessControl fn has_role( - self: @ComponentState, role: felt252, account: ContractAddress + self: @ComponentState, role: felt252, account: ContractAddress, ) -> bool { let access_control = get_dep_component!(self, AccessControl); access_control.has_role(role, account) @@ -478,20 +478,20 @@ pub mod TimelockControllerComponent { } fn grant_role( - ref self: ComponentState, role: felt252, account: ContractAddress + ref self: ComponentState, role: felt252, account: ContractAddress, ) { let mut access_control = get_dep_component_mut!(ref self, AccessControl); access_control.grant_role(role, account); } fn revoke_role( - ref self: ComponentState, role: felt252, account: ContractAddress + ref self: ComponentState, role: felt252, account: ContractAddress, ) { let mut access_control = get_dep_component_mut!(ref self, AccessControl); access_control.revoke_role(role, account); } fn renounce_role( - ref self: ComponentState, role: felt252, account: ContractAddress + ref self: ComponentState, role: felt252, account: ContractAddress, ) { let mut access_control = get_dep_component_mut!(ref self, AccessControl); access_control.renounce_role(role, account); @@ -499,7 +499,7 @@ pub mod TimelockControllerComponent { // IAccessControlCamel fn hasRole( - self: @ComponentState, role: felt252, account: ContractAddress + self: @ComponentState, role: felt252, account: ContractAddress, ) -> bool { Self::has_role(self, role, account) } @@ -509,19 +509,19 @@ pub mod TimelockControllerComponent { } fn grantRole( - ref self: ComponentState, role: felt252, account: ContractAddress + ref self: ComponentState, role: felt252, account: ContractAddress, ) { Self::grant_role(ref self, role, account); } fn revokeRole( - ref self: ComponentState, role: felt252, account: ContractAddress + ref self: ComponentState, role: felt252, account: ContractAddress, ) { Self::revoke_role(ref self, role, account); } fn renounceRole( - ref self: ComponentState, role: felt252, account: ContractAddress + ref self: ComponentState, role: felt252, account: ContractAddress, ) { Self::renounce_role(ref self, role, account); } @@ -537,7 +537,7 @@ pub mod TimelockControllerComponent { +HasComponent, impl SRC5: SRC5Component::HasComponent, impl AccessControl: AccessControlComponent::HasComponent, - +Drop + +Drop, > of InternalTrait { /// Initializes the contract by registering support for SRC5 and AccessControl. /// @@ -566,7 +566,7 @@ pub mod TimelockControllerComponent { min_delay: u64, proposers: Span, executors: Span, - admin: ContractAddress + admin: ContractAddress, ) { // Register access control ID and self as default admin let mut access_component = get_dep_component_mut!(ref self, AccessControl); @@ -630,7 +630,7 @@ pub mod TimelockControllerComponent { assert(Timelock::is_operation_ready(self, id), Errors::EXPECTED_READY_OPERATION); assert( predecessor == 0 || Timelock::is_operation_done(self, predecessor), - Errors::UNEXECUTED_PREDECESSOR + Errors::UNEXECUTED_PREDECESSOR, ); } diff --git a/packages/governance/src/utils/call_impls.cairo b/packages/governance/src/utils/call_impls.cairo index d79f666da..73c441623 100644 --- a/packages/governance/src/utils/call_impls.cairo +++ b/packages/governance/src/utils/call_impls.cairo @@ -1,7 +1,7 @@ // SPDX-License-Identifier: MIT // OpenZeppelin Contracts for Cairo v0.20.0-rc.0 (governance/utils/call_impls.cairo) -use core::hash::{HashStateTrait, HashStateExTrait, Hash}; +use core::hash::{Hash, HashStateExTrait, HashStateTrait}; use starknet::account::Call; pub impl HashCallImpl, +Drop> of Hash { diff --git a/packages/governance/src/votes/delegation.cairo b/packages/governance/src/votes/delegation.cairo index e61c41bd3..48ad9fd0e 100644 --- a/packages/governance/src/votes/delegation.cairo +++ b/packages/governance/src/votes/delegation.cairo @@ -1,7 +1,7 @@ // SPDX-License-Identifier: MIT // OpenZeppelin Contracts for Cairo v0.20.0-rc.0 (governance/votes/delegation.cairo) -use core::hash::{HashStateTrait, HashStateExTrait}; +use core::hash::{HashStateExTrait, HashStateTrait}; use core::poseidon::PoseidonTrait; use openzeppelin_utils::cryptography::snip12::{StructHash}; use starknet::ContractAddress; @@ -20,7 +20,7 @@ pub struct Delegation { pub verifying_contract: ContractAddress, pub delegatee: ContractAddress, pub nonce: felt252, - pub expiry: u64 + pub expiry: u64, } impl StructHashImpl of StructHash { diff --git a/packages/governance/src/votes/interface.cairo b/packages/governance/src/votes/interface.cairo index 20b103d43..2fd7566c9 100644 --- a/packages/governance/src/votes/interface.cairo +++ b/packages/governance/src/votes/interface.cairo @@ -33,7 +33,7 @@ pub trait IVotes { delegatee: ContractAddress, nonce: felt252, expiry: u64, - signature: Span + signature: Span, ); } @@ -52,7 +52,7 @@ pub trait VotesABI { delegatee: ContractAddress, nonce: felt252, expiry: u64, - signature: Span + signature: Span, ); // Nonces diff --git a/packages/governance/src/votes/votes.cairo b/packages/governance/src/votes/votes.cairo index 590a47445..1471d4cd1 100644 --- a/packages/governance/src/votes/votes.cairo +++ b/packages/governance/src/votes/votes.cairo @@ -34,11 +34,11 @@ pub mod VotesComponent { use openzeppelin_token::erc721::ERC721Component; use openzeppelin_token::erc721::interface::IERC721; use openzeppelin_utils::cryptography::snip12::{OffchainMessageHash, SNIP12Metadata}; - use openzeppelin_utils::nonces::NoncesComponent::InternalTrait as NoncesInternalTrait; use openzeppelin_utils::nonces::NoncesComponent; + use openzeppelin_utils::nonces::NoncesComponent::InternalTrait as NoncesInternalTrait; use openzeppelin_utils::structs::checkpoint::{Checkpoint, Trace, TraceTrait}; use starknet::ContractAddress; - use starknet::storage::{Map, StoragePathEntry, StorageMapReadAccess, StorageMapWriteAccess}; + use starknet::storage::{Map, StorageMapReadAccess, StorageMapWriteAccess, StoragePathEntry}; #[storage] pub struct Storage { @@ -62,7 +62,7 @@ pub mod VotesComponent { #[key] pub from_delegate: ContractAddress, #[key] - pub to_delegate: ContractAddress + pub to_delegate: ContractAddress, } /// Emitted when `delegate` votes are updated from `previous_votes` to `new_votes`. @@ -71,7 +71,7 @@ pub mod VotesComponent { #[key] pub delegate: ContractAddress, pub previous_votes: u256, - pub new_votes: u256 + pub new_votes: u256, } pub mod Errors { @@ -106,7 +106,7 @@ pub mod VotesComponent { impl Nonces: NoncesComponent::HasComponent, +VotingUnitsTrait>, +SNIP12Metadata, - +Drop + +Drop, > of IVotes> { /// Returns the current amount of votes that `account` has. fn get_votes(self: @ComponentState, account: ContractAddress) -> u256 { @@ -119,7 +119,7 @@ pub mod VotesComponent { /// /// - `timepoint` must be in the past. fn get_past_votes( - self: @ComponentState, account: ContractAddress, timepoint: u64 + self: @ComponentState, account: ContractAddress, timepoint: u64, ) -> u256 { let current_timepoint = starknet::get_block_timestamp(); assert(timepoint < current_timepoint, Errors::FUTURE_LOOKUP); @@ -139,7 +139,7 @@ pub mod VotesComponent { /// Returns the delegate that `account` has chosen. fn delegates( - self: @ComponentState, account: ContractAddress + self: @ComponentState, account: ContractAddress, ) -> ContractAddress { self.Votes_delegatee.read(account) } @@ -171,7 +171,7 @@ pub mod VotesComponent { delegatee: ContractAddress, nonce: felt252, expiry: u64, - signature: Span + signature: Span, ) { assert(starknet::get_block_timestamp() <= expiry, Errors::EXPIRED_SIGNATURE); @@ -206,7 +206,7 @@ pub mod VotesComponent { TContractState, +HasComponent, impl ERC20: ERC20Component::HasComponent, - +ERC20Component::ERC20HooksTrait + +ERC20Component::ERC20HooksTrait, > of VotingUnitsTrait> { /// Returns the number of voting units for a given account. /// @@ -220,7 +220,7 @@ pub mod VotesComponent { /// Any deviation from this formula when transferring voting units (e.g. by using hooks) /// may compromise the internal vote accounting. fn get_voting_units( - self: @ComponentState, account: ContractAddress + self: @ComponentState, account: ContractAddress, ) -> u256 { let erc20_component = get_dep_component!(self, ERC20); erc20_component.balance_of(account) @@ -233,7 +233,7 @@ pub mod VotesComponent { +SRC5Component::HasComponent, impl ERC721: ERC721Component::HasComponent, +ERC721Component::ERC721HooksTrait, - +Drop + +Drop, > of VotingUnitsTrait> { /// Returns the number of voting units for a given account. /// @@ -248,7 +248,7 @@ pub mod VotesComponent { /// Any deviation from this formula when transferring voting units (e.g. by using hooks) /// may compromise the internal vote accounting. fn get_voting_units( - self: @ComponentState, account: ContractAddress + self: @ComponentState, account: ContractAddress, ) -> u256 { let erc721_component = get_dep_component!(self, ERC721); erc721_component.balance_of(account).into() @@ -262,7 +262,7 @@ pub mod VotesComponent { +VotingUnitsTrait>, +NoncesComponent::HasComponent, +SNIP12Metadata, - +Drop + +Drop, > of InternalTrait { /// Returns the current total supply of votes. fn get_total_supply(self: @ComponentState) -> u256 { @@ -276,7 +276,7 @@ pub mod VotesComponent { ref self: ComponentState, from: ContractAddress, to: ContractAddress, - amount: u256 + amount: u256, ) { let block_timestamp = starknet::get_block_timestamp(); if from != to && amount > 0 { @@ -310,7 +310,7 @@ pub mod VotesComponent { ref self: ComponentState, from: ContractAddress, to: ContractAddress, - amount: u256 + amount: u256, ) { let block_timestamp = starknet::get_block_timestamp(); if from.is_zero() { @@ -331,7 +331,7 @@ pub mod VotesComponent { /// Returns the `pos`-th checkpoint for `account`. fn checkpoints( - self: @ComponentState, account: ContractAddress, pos: u64 + self: @ComponentState, account: ContractAddress, pos: u64, ) -> Checkpoint { self.Votes_delegate_checkpoints.entry(account).at(pos) } @@ -343,13 +343,13 @@ pub mod VotesComponent { fn _delegate( ref self: ComponentState, account: ContractAddress, - delegatee: ContractAddress + delegatee: ContractAddress, ) { let from_delegate = self.delegates(account); self.Votes_delegatee.write(account, delegatee); self .emit( - DelegateChanged { delegator: account, from_delegate, to_delegate: delegatee } + DelegateChanged { delegator: account, from_delegate, to_delegate: delegatee }, ); self.move_delegate_votes(from_delegate, delegatee, self.get_voting_units(account)); } diff --git a/packages/introspection/src/src5.cairo b/packages/introspection/src/src5.cairo index 82029bba7..12b40c4f2 100644 --- a/packages/introspection/src/src5.cairo +++ b/packages/introspection/src/src5.cairo @@ -11,7 +11,7 @@ pub mod SRC5Component { #[storage] pub struct Storage { - pub SRC5_supported_interfaces: Map + pub SRC5_supported_interfaces: Map, } pub mod Errors { @@ -24,11 +24,11 @@ pub mod SRC5Component { #[embeddable_as(SRC5Impl)] impl SRC5< - TContractState, +HasComponent + TContractState, +HasComponent, > of interface::ISRC5> { /// Returns whether the contract implements the given interface. fn supports_interface( - self: @ComponentState, interface_id: felt252 + self: @ComponentState, interface_id: felt252, ) -> bool { if interface_id == interface::ISRC5_ID { return true; @@ -43,7 +43,7 @@ pub mod SRC5Component { #[generate_trait] pub impl InternalImpl< - TContractState, +HasComponent + TContractState, +HasComponent, > of InternalTrait { /// Registers the given interface as supported by the contract. fn register_interface(ref self: ComponentState, interface_id: felt252) { diff --git a/packages/introspection/src/tests/test_src5.cairo b/packages/introspection/src/tests/test_src5.cairo index 0473c8f31..d009b7593 100644 --- a/packages/introspection/src/tests/test_src5.cairo +++ b/packages/introspection/src/tests/test_src5.cairo @@ -1,6 +1,6 @@ -use crate::interface::{ISRC5_ID, ISRC5}; -use crate::src5::SRC5Component::InternalTrait; +use crate::interface::{ISRC5, ISRC5_ID}; use crate::src5::SRC5Component; +use crate::src5::SRC5Component::InternalTrait; use openzeppelin_test_common::mocks::src5::SRC5Mock; const OTHER_ID: felt252 = 0x12345678; diff --git a/packages/merkle_tree/src/merkle_proof.cairo b/packages/merkle_tree/src/merkle_proof.cairo index f87b81688..cb8f6f267 100644 --- a/packages/merkle_tree/src/merkle_proof.cairo +++ b/packages/merkle_tree/src/merkle_proof.cairo @@ -20,7 +20,7 @@ use crate::hashes::{CommutativeHasher, PedersenCHasher, PoseidonCHasher}; /// sibling hashes on the branch from the leaf to the root of the tree. Each /// pair of leaves and each pair of pre-images are assumed to be sorted. pub fn verify( - proof: Span, root: felt252, leaf: felt252 + proof: Span, root: felt252, leaf: felt252, ) -> bool { process_proof::(proof, leaf) == root } @@ -40,7 +40,7 @@ pub fn verify_poseidon(proof: Span, root: felt252, leaf: felt252) -> bo /// hash matches the root of the tree. When processing the proof, the pairs /// of leaves & pre-images are assumed to be sorted. pub fn process_proof( - proof: Span, leaf: felt252 + proof: Span, leaf: felt252, ) -> felt252 { let mut computed_hash = leaf; for hash in proof { @@ -59,7 +59,7 @@ pub fn process_proof( /// /// The `leaves` must be validated independently. See `process_multi_proof`. pub fn verify_multi_proof( - proof: Span, proof_flags: Span, root: felt252, leaves: Span + proof: Span, proof_flags: Span, root: felt252, leaves: Span, ) -> bool { process_multi_proof::(proof, proof_flags, leaves) == root } @@ -78,7 +78,7 @@ pub fn verify_multi_proof( /// considered a no-op, and therefore a valid multiproof (i.e. it returns `proof.at(0)`). Consider /// disallowing this case if you're not validating the leaves elsewhere. pub fn process_multi_proof( - proof: Span, proof_flags: Span, leaves: Span + proof: Span, proof_flags: Span, leaves: Span, ) -> felt252 { // This function rebuilds the root hash by traversing the tree up from the leaves. The root is // rebuilt by consuming and producing values on a queue. The queue starts with the `leaves` @@ -104,32 +104,31 @@ pub fn process_multi_proof( // otherwise we get the next hash. // 2. Depending on the flag, either another value from the "main queue" (merging branches) or an // element from the `proof` array. - for i in 0 - ..proof_flags_len { - let a = if leaf_pos < leaves_len { + for i in 0..proof_flags_len { + let a = if leaf_pos < leaves_len { + leaf_pos += 1; + leaves.at(leaf_pos - 1) + } else { + hash_pos += 1; + hashes.at(hash_pos - 1) + }; + + let b = if *proof_flags.at(i) { + if leaf_pos < leaves_len { leaf_pos += 1; leaves.at(leaf_pos - 1) } else { hash_pos += 1; hashes.at(hash_pos - 1) - }; - - let b = if *proof_flags.at(i) { - if leaf_pos < leaves_len { - leaf_pos += 1; - leaves.at(leaf_pos - 1) - } else { - hash_pos += 1; - hashes.at(hash_pos - 1) - } - } else { - proof_pos += 1; - proof.at(proof_pos - 1) - }; - - hashes.append(Hasher::commutative_hash(*a, *b)); + } + } else { + proof_pos += 1; + proof.at(proof_pos - 1) }; + hashes.append(Hasher::commutative_hash(*a, *b)); + }; + let root = if proof_flags_len > 0 { hashes.at(proof_flags_len - 1) } else if leaves_len > 0 { diff --git a/packages/merkle_tree/src/tests/merkle_proof/common.cairo b/packages/merkle_tree/src/tests/merkle_proof/common.cairo index d3dc09939..3d9016b8b 100644 --- a/packages/merkle_tree/src/tests/merkle_proof/common.cairo +++ b/packages/merkle_tree/src/tests/merkle_proof/common.cairo @@ -10,27 +10,28 @@ pub(crate) fn LEAVES() -> Span { [ Leaf { address: contract_address_const::< - 0x7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc8 + 0x7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc8, >(), - amount: 0xfc104e31d098d1ab488fc1acaeb0269 + amount: 0xfc104e31d098d1ab488fc1acaeb0269, }, Leaf { address: contract_address_const::< - 0x7ffffffffffffffffffffffffffffffffffffffffffffffffffffc66ca5c000 + 0x7ffffffffffffffffffffffffffffffffffffffffffffffffffffc66ca5c000, >(), - amount: 0xfc104e31d098d1ab488fc1acaeb0269 + amount: 0xfc104e31d098d1ab488fc1acaeb0269, }, Leaf { address: contract_address_const::< - 0x6a1f098854799debccf2d3c4059ff0f02dbfef6673dc1fcbfffffffffffffc8 + 0x6a1f098854799debccf2d3c4059ff0f02dbfef6673dc1fcbfffffffffffffc8, >(), - amount: 0xfc104e31d098d1ab488fc1acaeb0269 + amount: 0xfc104e31d098d1ab488fc1acaeb0269, }, Leaf { address: contract_address_const::< - 0xfa6541b7909bfb5e8585f1222fcf272eea352c7e0e8ed38c988bd1e2a85e82 + 0xfa6541b7909bfb5e8585f1222fcf272eea352c7e0e8ed38c988bd1e2a85e82, >(), - amount: 0xaa8565d732c2c9fa5f6c001d89d5c219 + amount: 0xaa8565d732c2c9fa5f6c001d89d5c219, }, - ].span() + ] + .span() } diff --git a/packages/merkle_tree/src/tests/merkle_proof/test_with_pedersen.cairo b/packages/merkle_tree/src/tests/merkle_proof/test_with_pedersen.cairo index f2598f402..139e977dc 100644 --- a/packages/merkle_tree/src/tests/merkle_proof/test_with_pedersen.cairo +++ b/packages/merkle_tree/src/tests/merkle_proof/test_with_pedersen.cairo @@ -1,24 +1,20 @@ -use core::hash::{HashStateTrait, HashStateExTrait}; +use core::hash::{HashStateExTrait, HashStateTrait}; use core::pedersen::{PedersenTrait, pedersen}; use crate::hashes::PedersenCHasher; use crate::merkle_proof::{ - process_proof, process_multi_proof, verify, verify_multi_proof, verify_pedersen + process_multi_proof, process_proof, verify, verify_multi_proof, verify_pedersen, }; -use super::common::{Leaf, LEAVES}; +use super::common::{LEAVES, Leaf}; // `ROOT`, `PROOF`, and `MULTI_PROOF` were computed using @ericnordelo/strk-merkle-tree const ROOT: felt252 = 0x02a40717603180fa52f40a55508cd360d301840f3e502665cf0132ef412911de; -const PROOF: [ - felt252 - ; 2] = [ +const PROOF: [felt252; 2] = [ 0x044fdc540a81d0189ed30b49d64136f9e8bd499c942ba170404ef0b9406e524c, - 0x02b0ee474cf2ab27501e54a661d17ac1dc162571c111fe2455d09fe23471099e + 0x02b0ee474cf2ab27501e54a661d17ac1dc162571c111fe2455d09fe23471099e, ]; -const MULTI_PROOF: [ - felt252 - ; 2] = [ +const MULTI_PROOF: [felt252; 2] = [ 0x044fdc540a81d0189ed30b49d64136f9e8bd499c942ba170404ef0b9406e524c, - 0x05fb6a626bb2c1e12fc2d6fa7f218ec06928ba5febf4d5677c2c5060827e383b + 0x05fb6a626bb2c1e12fc2d6fa7f218ec06928ba5febf4d5677c2c5060827e383b, ]; // @@ -50,8 +46,9 @@ fn test_invalid_merkle_proof() { let leaves = LEAVES(); let hash = leaf_hash(*leaves.at(0)); let invalid_proof = [ - 0x044fdc540a81d0189ed30b49d64136f9e8bd499c942ba170404ef0b9406e524c, 'invalid' - ].span(); + 0x044fdc540a81d0189ed30b49d64136f9e8bd499c942ba170404ef0b9406e524c, 'invalid', + ] + .span(); assert!(process_proof::(invalid_proof, hash) != ROOT); assert!(!verify::(invalid_proof, ROOT, hash)); @@ -78,15 +75,16 @@ fn test_invalid_merkle_multi_proof() { let leaves = LEAVES(); let leaves_to_prove = [leaf_hash(*leaves.at(0)), leaf_hash(*leaves.at(1))].span(); let invalid_proof = [ - 0x044fdc540a81d0189ed30b49d64136f9e8bd499c942ba170404ef0b9406e524c, 'invalid' - ].span(); + 0x044fdc540a81d0189ed30b49d64136f9e8bd499c942ba170404ef0b9406e524c, 'invalid', + ] + .span(); let proof_flags = [false, false, true].span(); assert!( - process_multi_proof::(invalid_proof, proof_flags, leaves_to_prove) != ROOT + process_multi_proof::(invalid_proof, proof_flags, leaves_to_prove) != ROOT, ); assert!( - !verify_multi_proof::(invalid_proof, proof_flags, ROOT, leaves_to_prove) + !verify_multi_proof::(invalid_proof, proof_flags, ROOT, leaves_to_prove), ); } @@ -132,8 +130,9 @@ fn test_verify_multi_proof_invalid_len_proof_flags_panics() { fn test_process_multi_proof_flags_extra_leaves_expected() { let leaves = LEAVES(); let leaves_to_prove = [ - leaf_hash(*leaves.at(0)), leaf_hash(*leaves.at(1)), leaf_hash(*leaves.at(2)) - ].span(); + leaf_hash(*leaves.at(0)), leaf_hash(*leaves.at(1)), leaf_hash(*leaves.at(2)), + ] + .span(); let proof = MULTI_PROOF.span(); // For each true one leaf is expected @@ -147,8 +146,9 @@ fn test_process_multi_proof_flags_extra_leaves_expected() { fn test_process_multi_proof_flags_extra_proofs_expected() { let leaves = LEAVES(); let leaves_to_prove = [ - leaf_hash(*leaves.at(0)), leaf_hash(*leaves.at(1)), leaf_hash(*leaves.at(2)) - ].span(); + leaf_hash(*leaves.at(0)), leaf_hash(*leaves.at(1)), leaf_hash(*leaves.at(2)), + ] + .span(); let proof = MULTI_PROOF.span(); // For each false one proof is expected @@ -162,8 +162,9 @@ fn test_process_multi_proof_flags_extra_proofs_expected() { fn test_verify_multi_proof_flags_extra_leaves_expected() { let leaves = LEAVES(); let leaves_to_prove = [ - leaf_hash(*leaves.at(0)), leaf_hash(*leaves.at(1)), leaf_hash(*leaves.at(2)) - ].span(); + leaf_hash(*leaves.at(0)), leaf_hash(*leaves.at(1)), leaf_hash(*leaves.at(2)), + ] + .span(); let proof = MULTI_PROOF.span(); // For each true one leaf is expected @@ -177,8 +178,9 @@ fn test_verify_multi_proof_flags_extra_leaves_expected() { fn test_verify_multi_proof_flags_extra_proofs_expected() { let leaves = LEAVES(); let leaves_to_prove = [ - leaf_hash(*leaves.at(0)), leaf_hash(*leaves.at(1)), leaf_hash(*leaves.at(2)) - ].span(); + leaf_hash(*leaves.at(0)), leaf_hash(*leaves.at(1)), leaf_hash(*leaves.at(2)), + ] + .span(); let proof = MULTI_PROOF.span(); // For each false one proof is expected diff --git a/packages/merkle_tree/src/tests/merkle_proof/test_with_poseidon.cairo b/packages/merkle_tree/src/tests/merkle_proof/test_with_poseidon.cairo index b7dce4442..a281c22a6 100644 --- a/packages/merkle_tree/src/tests/merkle_proof/test_with_poseidon.cairo +++ b/packages/merkle_tree/src/tests/merkle_proof/test_with_poseidon.cairo @@ -1,23 +1,19 @@ use core::poseidon::poseidon_hash_span; use crate::hashes::PoseidonCHasher; use crate::merkle_proof::{ - process_proof, process_multi_proof, verify, verify_multi_proof, verify_poseidon + process_multi_proof, process_proof, verify, verify_multi_proof, verify_poseidon, }; -use super::common::{Leaf, LEAVES}; +use super::common::{LEAVES, Leaf}; // `ROOT`, `PROOF`, and `MULTI_PROOF` were computed using @ericnordelo/strk-merkle-tree const ROOT: felt252 = 0x013f43fdca44b32f5334414b385b46aa1016d0172a1f066eab4cc93636426fcc; -const PROOF: [ - felt252 - ; 2] = [ +const PROOF: [felt252; 2] = [ 0x05b151ebb9201ce27c56a70f5d0571ccfb9d9d62f12b8ccab7801ba87ec21a2f, - 0x2b7d689bd2ff488fd06dfb8eb22f5cdaba1e5d9698d3fabff2f1801852dbb2 + 0x2b7d689bd2ff488fd06dfb8eb22f5cdaba1e5d9698d3fabff2f1801852dbb2, ]; -const MULTI_PROOF: [ - felt252 - ; 2] = [ +const MULTI_PROOF: [felt252; 2] = [ 0x044fdc540a81d0189ed30b49d64136f9e8bd499c942ba170404ef0b9406e524c, - 0x05fb6a626bb2c1e12fc2d6fa7f218ec06928ba5febf4d5677c2c5060827e383b + 0x05fb6a626bb2c1e12fc2d6fa7f218ec06928ba5febf4d5677c2c5060827e383b, ]; // @@ -49,8 +45,9 @@ fn test_invalid_merkle_proof() { let leaves = LEAVES(); let hash = leaf_hash(*leaves.at(0)); let invalid_proof = [ - 0x044fdc540a81d0189ed30b49d64136f9e8bd499c942ba170404ef0b9406e524c, 'invalid' - ].span(); + 0x044fdc540a81d0189ed30b49d64136f9e8bd499c942ba170404ef0b9406e524c, 'invalid', + ] + .span(); assert!(process_proof::(invalid_proof, hash) != ROOT); assert!(!verify::(invalid_proof, ROOT, hash)); @@ -77,15 +74,16 @@ fn test_invalid_merkle_multi_proof() { let leaves = LEAVES(); let leaves_to_prove = [leaf_hash(*leaves.at(0)), leaf_hash(*leaves.at(1))].span(); let invalid_proof = [ - 0x044fdc540a81d0189ed30b49d64136f9e8bd499c942ba170404ef0b9406e524c, 'invalid' - ].span(); + 0x044fdc540a81d0189ed30b49d64136f9e8bd499c942ba170404ef0b9406e524c, 'invalid', + ] + .span(); let proof_flags = [false, false, true].span(); assert!( - process_multi_proof::(invalid_proof, proof_flags, leaves_to_prove) != ROOT + process_multi_proof::(invalid_proof, proof_flags, leaves_to_prove) != ROOT, ); assert!( - !verify_multi_proof::(invalid_proof, proof_flags, ROOT, leaves_to_prove) + !verify_multi_proof::(invalid_proof, proof_flags, ROOT, leaves_to_prove), ); } @@ -131,8 +129,9 @@ fn test_verify_multi_proof_invalid_len_proof_flags_panics() { fn test_process_multi_proof_flags_extra_leaves_expected() { let leaves = LEAVES(); let leaves_to_prove = [ - leaf_hash(*leaves.at(0)), leaf_hash(*leaves.at(1)), leaf_hash(*leaves.at(2)) - ].span(); + leaf_hash(*leaves.at(0)), leaf_hash(*leaves.at(1)), leaf_hash(*leaves.at(2)), + ] + .span(); let proof = MULTI_PROOF.span(); // For each true one leaf is expected @@ -146,8 +145,9 @@ fn test_process_multi_proof_flags_extra_leaves_expected() { fn test_process_multi_proof_flags_extra_proofs_expected() { let leaves = LEAVES(); let leaves_to_prove = [ - leaf_hash(*leaves.at(0)), leaf_hash(*leaves.at(1)), leaf_hash(*leaves.at(2)) - ].span(); + leaf_hash(*leaves.at(0)), leaf_hash(*leaves.at(1)), leaf_hash(*leaves.at(2)), + ] + .span(); let proof = MULTI_PROOF.span(); // For each false one proof is expected @@ -161,8 +161,9 @@ fn test_process_multi_proof_flags_extra_proofs_expected() { fn test_verify_multi_proof_flags_extra_leaves_expected() { let leaves = LEAVES(); let leaves_to_prove = [ - leaf_hash(*leaves.at(0)), leaf_hash(*leaves.at(1)), leaf_hash(*leaves.at(2)) - ].span(); + leaf_hash(*leaves.at(0)), leaf_hash(*leaves.at(1)), leaf_hash(*leaves.at(2)), + ] + .span(); let proof = MULTI_PROOF.span(); // For each true one leaf is expected @@ -176,8 +177,9 @@ fn test_verify_multi_proof_flags_extra_leaves_expected() { fn test_verify_multi_proof_flags_extra_proofs_expected() { let leaves = LEAVES(); let leaves_to_prove = [ - leaf_hash(*leaves.at(0)), leaf_hash(*leaves.at(1)), leaf_hash(*leaves.at(2)) - ].span(); + leaf_hash(*leaves.at(0)), leaf_hash(*leaves.at(1)), leaf_hash(*leaves.at(2)), + ] + .span(); let proof = MULTI_PROOF.span(); // For each false one proof is expected @@ -192,6 +194,6 @@ fn test_verify_multi_proof_flags_extra_proofs_expected() { fn leaf_hash(leaf: Leaf) -> felt252 { poseidon_hash_span( - [poseidon_hash_span([leaf.address.into(), leaf.amount.into()].span())].span() + [poseidon_hash_span([leaf.address.into(), leaf.amount.into()].span())].span(), ) } diff --git a/packages/presets/src/account.cairo b/packages/presets/src/account.cairo index 94bcea17e..a98e2033f 100644 --- a/packages/presets/src/account.cairo +++ b/packages/presets/src/account.cairo @@ -43,7 +43,7 @@ pub mod AccountUpgradeable { #[substorage(v0)] pub src9: SRC9Component::Storage, #[substorage(v0)] - pub upgradeable: UpgradeableComponent::Storage + pub upgradeable: UpgradeableComponent::Storage, } #[event] @@ -56,7 +56,7 @@ pub mod AccountUpgradeable { #[flat] SRC9Event: SRC9Component::Event, #[flat] - UpgradeableEvent: UpgradeableComponent::Event + UpgradeableEvent: UpgradeableComponent::Event, } #[constructor] diff --git a/packages/presets/src/erc1155.cairo b/packages/presets/src/erc1155.cairo index 84ce18c4a..40dfd61d3 100644 --- a/packages/presets/src/erc1155.cairo +++ b/packages/presets/src/erc1155.cairo @@ -15,7 +15,7 @@ pub mod ERC1155Upgradeable { use openzeppelin_token::erc1155::{ERC1155Component, ERC1155HooksEmptyImpl}; use openzeppelin_upgrades::UpgradeableComponent; use openzeppelin_upgrades::interface::IUpgradeable; - use starknet::{ContractAddress, ClassHash}; + use starknet::{ClassHash, ContractAddress}; component!(path: OwnableComponent, storage: ownable, event: OwnableEvent); component!(path: ERC1155Component, storage: erc1155, event: ERC1155Event); @@ -44,7 +44,7 @@ pub mod ERC1155Upgradeable { #[substorage(v0)] pub src5: SRC5Component::Storage, #[substorage(v0)] - pub upgradeable: UpgradeableComponent::Storage + pub upgradeable: UpgradeableComponent::Storage, } #[event] @@ -57,7 +57,7 @@ pub mod ERC1155Upgradeable { #[flat] SRC5Event: SRC5Component::Event, #[flat] - UpgradeableEvent: UpgradeableComponent::Event + UpgradeableEvent: UpgradeableComponent::Event, } /// Assigns `owner` as the contract owner. @@ -76,7 +76,7 @@ pub mod ERC1155Upgradeable { recipient: ContractAddress, token_ids: Span, values: Span, - owner: ContractAddress + owner: ContractAddress, ) { self.ownable.initializer(owner); self.erc1155.initializer(base_uri); diff --git a/packages/presets/src/erc20.cairo b/packages/presets/src/erc20.cairo index 78665c0e8..a1bdedd7b 100644 --- a/packages/presets/src/erc20.cairo +++ b/packages/presets/src/erc20.cairo @@ -15,7 +15,7 @@ pub mod ERC20Upgradeable { use openzeppelin_token::erc20::{ERC20Component, ERC20HooksEmptyImpl}; use openzeppelin_upgrades::UpgradeableComponent; use openzeppelin_upgrades::interface::IUpgradeable; - use starknet::{ContractAddress, ClassHash}; + use starknet::{ClassHash, ContractAddress}; component!(path: OwnableComponent, storage: ownable, event: OwnableEvent); component!(path: ERC20Component, storage: erc20, event: ERC20Event); @@ -41,7 +41,7 @@ pub mod ERC20Upgradeable { #[substorage(v0)] pub erc20: ERC20Component::Storage, #[substorage(v0)] - pub upgradeable: UpgradeableComponent::Storage + pub upgradeable: UpgradeableComponent::Storage, } #[event] @@ -52,7 +52,7 @@ pub mod ERC20Upgradeable { #[flat] ERC20Event: ERC20Component::Event, #[flat] - UpgradeableEvent: UpgradeableComponent::Event + UpgradeableEvent: UpgradeableComponent::Event, } /// Assigns `owner` as the contract owner. @@ -65,7 +65,7 @@ pub mod ERC20Upgradeable { symbol: ByteArray, fixed_supply: u256, recipient: ContractAddress, - owner: ContractAddress + owner: ContractAddress, ) { self.ownable.initializer(owner); self.erc20.initializer(name, symbol); diff --git a/packages/presets/src/erc721.cairo b/packages/presets/src/erc721.cairo index d8f59bb27..52369ea71 100644 --- a/packages/presets/src/erc721.cairo +++ b/packages/presets/src/erc721.cairo @@ -15,7 +15,7 @@ pub mod ERC721Upgradeable { use openzeppelin_token::erc721::{ERC721Component, ERC721HooksEmptyImpl}; use openzeppelin_upgrades::UpgradeableComponent; use openzeppelin_upgrades::interface::IUpgradeable; - use starknet::{ContractAddress, ClassHash}; + use starknet::{ClassHash, ContractAddress}; component!(path: OwnableComponent, storage: ownable, event: OwnableEvent); component!(path: ERC721Component, storage: erc721, event: ERC721Event); @@ -44,7 +44,7 @@ pub mod ERC721Upgradeable { #[substorage(v0)] pub src5: SRC5Component::Storage, #[substorage(v0)] - pub upgradeable: UpgradeableComponent::Storage + pub upgradeable: UpgradeableComponent::Storage, } #[event] @@ -57,7 +57,7 @@ pub mod ERC721Upgradeable { #[flat] SRC5Event: SRC5Component::Event, #[flat] - UpgradeableEvent: UpgradeableComponent::Event + UpgradeableEvent: UpgradeableComponent::Event, } /// Assigns `owner` as the contract owner. @@ -72,7 +72,7 @@ pub mod ERC721Upgradeable { base_uri: ByteArray, recipient: ContractAddress, token_ids: Span, - owner: ContractAddress + owner: ContractAddress, ) { self.ownable.initializer(owner); self.erc721.initializer(name, symbol, base_uri); @@ -93,7 +93,7 @@ pub mod ERC721Upgradeable { pub(crate) impl InternalImpl of InternalTrait { /// Mints `token_ids` to `recipient`. fn mint_assets( - ref self: ContractState, recipient: ContractAddress, mut token_ids: Span + ref self: ContractState, recipient: ContractAddress, mut token_ids: Span, ) { loop { if token_ids.len() == 0 { diff --git a/packages/presets/src/eth_account.cairo b/packages/presets/src/eth_account.cairo index 1d9af2aa5..50d79301b 100644 --- a/packages/presets/src/eth_account.cairo +++ b/packages/presets/src/eth_account.cairo @@ -45,7 +45,7 @@ pub(crate) mod EthAccountUpgradeable { #[substorage(v0)] pub src9: SRC9Component::Storage, #[substorage(v0)] - pub upgradeable: UpgradeableComponent::Storage + pub upgradeable: UpgradeableComponent::Storage, } #[event] @@ -58,7 +58,7 @@ pub(crate) mod EthAccountUpgradeable { #[flat] SRC9Event: SRC9Component::Event, #[flat] - UpgradeableEvent: UpgradeableComponent::Event + UpgradeableEvent: UpgradeableComponent::Event, } #[constructor] diff --git a/packages/presets/src/interfaces/account.cairo b/packages/presets/src/interfaces/account.cairo index 37b834320..28113323f 100644 --- a/packages/presets/src/interfaces/account.cairo +++ b/packages/presets/src/interfaces/account.cairo @@ -23,7 +23,7 @@ pub trait AccountUpgradeableABI { // IDeployable fn __validate_deploy__( - self: @TState, class_hash: felt252, contract_address_salt: felt252, public_key: felt252 + self: @TState, class_hash: felt252, contract_address_salt: felt252, public_key: felt252, ) -> felt252; // IPublicKey diff --git a/packages/presets/src/interfaces/erc1155.cairo b/packages/presets/src/interfaces/erc1155.cairo index 7ca7ddbbd..821718c6a 100644 --- a/packages/presets/src/interfaces/erc1155.cairo +++ b/packages/presets/src/interfaces/erc1155.cairo @@ -1,11 +1,11 @@ -use starknet::{ContractAddress, ClassHash}; +use starknet::{ClassHash, ContractAddress}; #[starknet::interface] pub trait ERC1155UpgradeableABI { // IERC1155 fn balance_of(self: @TState, account: ContractAddress, token_id: u256) -> u256; fn balance_of_batch( - self: @TState, accounts: Span, token_ids: Span + self: @TState, accounts: Span, token_ids: Span, ) -> Span; fn safe_transfer_from( ref self: TState, @@ -13,7 +13,7 @@ pub trait ERC1155UpgradeableABI { to: ContractAddress, token_id: u256, value: u256, - data: Span + data: Span, ); fn safe_batch_transfer_from( ref self: TState, @@ -21,10 +21,10 @@ pub trait ERC1155UpgradeableABI { to: ContractAddress, token_ids: Span, values: Span, - data: Span + data: Span, ); fn is_approved_for_all( - self: @TState, owner: ContractAddress, operator: ContractAddress + self: @TState, owner: ContractAddress, operator: ContractAddress, ) -> bool; fn set_approval_for_all(ref self: TState, operator: ContractAddress, approved: bool); @@ -37,7 +37,7 @@ pub trait ERC1155UpgradeableABI { // IERC1155Camel fn balanceOf(self: @TState, account: ContractAddress, tokenId: u256) -> u256; fn balanceOfBatch( - self: @TState, accounts: Span, tokenIds: Span + self: @TState, accounts: Span, tokenIds: Span, ) -> Span; fn safeTransferFrom( ref self: TState, @@ -45,7 +45,7 @@ pub trait ERC1155UpgradeableABI { to: ContractAddress, tokenId: u256, value: u256, - data: Span + data: Span, ); fn safeBatchTransferFrom( ref self: TState, @@ -53,7 +53,7 @@ pub trait ERC1155UpgradeableABI { to: ContractAddress, tokenIds: Span, values: Span, - data: Span + data: Span, ); fn isApprovedForAll(self: @TState, owner: ContractAddress, operator: ContractAddress) -> bool; fn setApprovalForAll(ref self: TState, operator: ContractAddress, approved: bool); diff --git a/packages/presets/src/interfaces/erc20.cairo b/packages/presets/src/interfaces/erc20.cairo index 760bb8b31..34eae5d36 100644 --- a/packages/presets/src/interfaces/erc20.cairo +++ b/packages/presets/src/interfaces/erc20.cairo @@ -1,4 +1,4 @@ -use starknet::{ContractAddress, ClassHash}; +use starknet::{ClassHash, ContractAddress}; #[starknet::interface] pub trait ERC20UpgradeableABI { @@ -8,7 +8,7 @@ pub trait ERC20UpgradeableABI { fn allowance(self: @TState, owner: ContractAddress, spender: ContractAddress) -> u256; fn transfer(ref self: TState, recipient: ContractAddress, amount: u256) -> bool; fn transfer_from( - ref self: TState, sender: ContractAddress, recipient: ContractAddress, amount: u256 + ref self: TState, sender: ContractAddress, recipient: ContractAddress, amount: u256, ) -> bool; fn approve(ref self: TState, spender: ContractAddress, amount: u256) -> bool; @@ -21,7 +21,7 @@ pub trait ERC20UpgradeableABI { fn totalSupply(self: @TState) -> u256; fn balanceOf(self: @TState, account: ContractAddress) -> u256; fn transferFrom( - ref self: TState, sender: ContractAddress, recipient: ContractAddress, amount: u256 + ref self: TState, sender: ContractAddress, recipient: ContractAddress, amount: u256, ) -> bool; // IOwnable diff --git a/packages/presets/src/interfaces/erc721.cairo b/packages/presets/src/interfaces/erc721.cairo index b156ea2f8..8a39802ce 100644 --- a/packages/presets/src/interfaces/erc721.cairo +++ b/packages/presets/src/interfaces/erc721.cairo @@ -1,4 +1,4 @@ -use starknet::{ContractAddress, ClassHash}; +use starknet::{ClassHash, ContractAddress}; #[starknet::interface] pub trait ERC721UpgradeableABI { @@ -10,14 +10,14 @@ pub trait ERC721UpgradeableABI { from: ContractAddress, to: ContractAddress, token_id: u256, - data: Span + data: Span, ); fn transfer_from(ref self: TState, from: ContractAddress, to: ContractAddress, token_id: u256); fn approve(ref self: TState, to: ContractAddress, token_id: u256); fn set_approval_for_all(ref self: TState, operator: ContractAddress, approved: bool); fn get_approved(self: @TState, token_id: u256) -> ContractAddress; fn is_approved_for_all( - self: @TState, owner: ContractAddress, operator: ContractAddress + self: @TState, owner: ContractAddress, operator: ContractAddress, ) -> bool; // ISRC5 @@ -36,7 +36,7 @@ pub trait ERC721UpgradeableABI { from: ContractAddress, to: ContractAddress, tokenId: u256, - data: Span + data: Span, ); fn transferFrom(ref self: TState, from: ContractAddress, to: ContractAddress, tokenId: u256); fn setApprovalForAll(ref self: TState, operator: ContractAddress, approved: bool); diff --git a/packages/presets/src/interfaces/eth_account.cairo b/packages/presets/src/interfaces/eth_account.cairo index acdcf5575..883fe390d 100644 --- a/packages/presets/src/interfaces/eth_account.cairo +++ b/packages/presets/src/interfaces/eth_account.cairo @@ -24,7 +24,10 @@ pub trait EthAccountUpgradeableABI { // IEthDeployable fn __validate_deploy__( - self: @TState, class_hash: felt252, contract_address_salt: felt252, public_key: EthPublicKey + self: @TState, + class_hash: felt252, + contract_address_salt: felt252, + public_key: EthPublicKey, ) -> felt252; // IEthPublicKey diff --git a/packages/presets/src/tests/test_account.cairo b/packages/presets/src/tests/test_account.cairo index 3297641d4..f4dfcd497 100644 --- a/packages/presets/src/tests/test_account.cairo +++ b/packages/presets/src/tests/test_account.cairo @@ -1,25 +1,25 @@ use core::num::traits::Zero; use crate::AccountUpgradeable; use crate::interfaces::account::{ - AccountUpgradeableABISafeDispatcher, AccountUpgradeableABISafeDispatcherTrait + AccountUpgradeableABISafeDispatcher, AccountUpgradeableABISafeDispatcherTrait, }; use crate::interfaces::{AccountUpgradeableABIDispatcher, AccountUpgradeableABIDispatcherTrait}; use openzeppelin_account::account::AccountComponent::AccountMixinImpl; use openzeppelin_account::extensions::SRC9Component::{OutsideExecutionV2Impl, SNIP12MetadataImpl}; -use openzeppelin_account::extensions::src9::interface::{OutsideExecution, ISRC9_V2_ID}; +use openzeppelin_account::extensions::src9::interface::{ISRC9_V2_ID, OutsideExecution}; use openzeppelin_account::extensions::src9::snip12_utils::OutsideExecutionStructHash; use openzeppelin_account::interface::ISRC6_ID; use openzeppelin_introspection::interface::ISRC5_ID; use openzeppelin_test_common::account::{ - SIGNED_TX_DATA, get_accept_ownership_signature, SignedTransactionData, AccountSpyHelpers + AccountSpyHelpers, SIGNED_TX_DATA, SignedTransactionData, get_accept_ownership_signature, }; use openzeppelin_test_common::erc20::deploy_erc20; use openzeppelin_test_common::upgrades::UpgradeableSpyHelpers; use openzeppelin_testing as utils; use openzeppelin_testing::constants::stark::{KEY_PAIR, KEY_PAIR_2}; use openzeppelin_testing::constants::{ - SALT, ZERO, CALLER, RECIPIENT, OTHER, QUERY_OFFSET, QUERY_VERSION, MIN_TRANSACTION_VERSION, - CLASS_HASH_ZERO, FELT_VALUE + CALLER, CLASS_HASH_ZERO, FELT_VALUE, MIN_TRANSACTION_VERSION, OTHER, QUERY_OFFSET, + QUERY_VERSION, RECIPIENT, SALT, ZERO, }; use openzeppelin_testing::signing::SerializedSigning; use openzeppelin_testing::signing::StarkKeyPair; @@ -27,14 +27,14 @@ use openzeppelin_token::erc20::interface::IERC20DispatcherTrait; use openzeppelin_utils::cryptography::snip12::OffchainMessageHash; use openzeppelin_utils::serde::SerializedAppend; use snforge_std::{ - spy_events, test_address, load, CheatSpan, start_cheat_caller_address, cheat_caller_address + CheatSpan, cheat_caller_address, load, spy_events, start_cheat_caller_address, test_address, }; use snforge_std::{ - start_cheat_signature_global, start_cheat_transaction_version_global, - start_cheat_transaction_hash_global, start_cheat_block_timestamp_global + start_cheat_block_timestamp_global, start_cheat_signature_global, + start_cheat_transaction_hash_global, start_cheat_transaction_version_global, }; use starknet::account::Call; -use starknet::{contract_address_const, ContractAddress, ClassHash}; +use starknet::{ClassHash, ContractAddress, contract_address_const}; // // Setup @@ -53,7 +53,7 @@ fn setup_dispatcher(key_pair: StarkKeyPair) -> (ContractAddress, AccountUpgradea } fn setup_dispatcher_with_data( - key_pair: StarkKeyPair, data: SignedTransactionData + key_pair: StarkKeyPair, data: SignedTransactionData, ) -> (AccountUpgradeableABIDispatcher, felt252) { let account_class = utils::declare_class("AccountUpgradeable"); let calldata = array![key_pair.public_key]; @@ -111,7 +111,7 @@ fn test_public_key_setter_and_getter() { let new_key_pair = KEY_PAIR_2(); let signature = get_accept_ownership_signature( - account_address, key_pair.public_key, new_key_pair + account_address, key_pair.public_key, new_key_pair, ); start_cheat_caller_address(account_address, account_address); dispatcher.set_public_key(new_key_pair.public_key, signature); @@ -130,7 +130,7 @@ fn test_public_key_setter_and_getter_camel() { let new_key_pair = KEY_PAIR_2(); let signature = get_accept_ownership_signature( - account_address, key_pair.public_key, new_key_pair + account_address, key_pair.public_key, new_key_pair, ); start_cheat_caller_address(account_address, account_address); dispatcher.setPublicKey(new_key_pair.public_key, signature); @@ -149,7 +149,7 @@ fn test_set_public_key_different_account() { let new_key_pair = KEY_PAIR_2(); let signature = get_accept_ownership_signature( - account_address, key_pair.public_key, new_key_pair + account_address, key_pair.public_key, new_key_pair, ); dispatcher.set_public_key(new_key_pair.public_key, signature); } @@ -162,7 +162,7 @@ fn test_setPublicKey_different_account() { let new_key_pair = KEY_PAIR_2(); let signature = get_accept_ownership_signature( - account_address, key_pair.public_key, new_key_pair + account_address, key_pair.public_key, new_key_pair, ); dispatcher.setPublicKey(new_key_pair.public_key, signature); } @@ -364,7 +364,7 @@ fn test_execute_with_version(version: Option) { calldata.append_serde(amount); let call = Call { - to: erc20.contract_address, selector: selector!("transfer"), calldata: calldata.span() + to: erc20.contract_address, selector: selector!("transfer"), calldata: calldata.span(), }; let calls = array![call]; @@ -455,7 +455,7 @@ fn test_multicall() { calldata1.append_serde(recipient1); calldata1.append_serde(amount1); let call1 = Call { - to: erc20.contract_address, selector: selector!("transfer"), calldata: calldata1.span() + to: erc20.contract_address, selector: selector!("transfer"), calldata: calldata1.span(), }; // Craft 2nd call @@ -464,7 +464,7 @@ fn test_multicall() { calldata2.append_serde(recipient2); calldata2.append_serde(amount2); let call2 = Call { - to: erc20.contract_address, selector: selector!("transfer"), calldata: calldata2.span() + to: erc20.contract_address, selector: selector!("transfer"), calldata: calldata2.span(), }; // Bundle calls and execute @@ -568,7 +568,7 @@ fn test_state_persists_after_upgrade() { let new_key_pair = KEY_PAIR_2(); let accept_ownership_sig = get_accept_ownership_signature( - account_address, key_pair.public_key, new_key_pair + account_address, key_pair.public_key, new_key_pair, ); start_cheat_caller_address(account_address, account_address); v1_dispatcher.set_public_key(new_key_pair.public_key, accept_ownership_sig); diff --git a/packages/presets/src/tests/test_erc1155.cairo b/packages/presets/src/tests/test_erc1155.cairo index 0e83b0640..68ad496a8 100644 --- a/packages/presets/src/tests/test_erc1155.cairo +++ b/packages/presets/src/tests/test_erc1155.cairo @@ -2,25 +2,25 @@ use core::num::traits::Zero; use crate::interfaces::{ERC1155UpgradeableABIDispatcher, ERC1155UpgradeableABIDispatcherTrait}; use openzeppelin_test_common::erc1155::ERC1155SpyHelpers; use openzeppelin_test_common::erc1155::{ - setup_account, setup_receiver, deploy_another_account_at, setup_src5 + deploy_another_account_at, setup_account, setup_receiver, setup_src5, }; -use openzeppelin_test_common::erc1155::{get_ids_and_values, get_ids_and_split_values}; +use openzeppelin_test_common::erc1155::{get_ids_and_split_values, get_ids_and_values}; use openzeppelin_test_common::ownable::OwnableSpyHelpers; use openzeppelin_test_common::upgrades::UpgradeableSpyHelpers; use openzeppelin_testing as utils; use openzeppelin_testing::constants::{ - EMPTY_DATA, ZERO, OWNER, RECIPIENT, CLASS_HASH_ZERO, OPERATOR, OTHER, TOKEN_ID, TOKEN_ID_2, - TOKEN_VALUE, TOKEN_VALUE_2 + CLASS_HASH_ZERO, EMPTY_DATA, OPERATOR, OTHER, OWNER, RECIPIENT, TOKEN_ID, TOKEN_ID_2, + TOKEN_VALUE, TOKEN_VALUE_2, ZERO, }; use openzeppelin_testing::events::EventSpyExt; +use openzeppelin_token::erc1155; use openzeppelin_token::erc1155::interface::{ - IERC1155CamelSafeDispatcher, IERC1155CamelSafeDispatcherTrait + IERC1155CamelSafeDispatcher, IERC1155CamelSafeDispatcherTrait, }; use openzeppelin_token::erc1155::interface::{IERC1155Dispatcher, IERC1155DispatcherTrait}; -use openzeppelin_token::erc1155; use openzeppelin_utils::serde::SerializedAppend; -use snforge_std::{spy_events, EventSpy, start_cheat_caller_address}; -use starknet::{ContractAddress, ClassHash}; +use snforge_std::{EventSpy, spy_events, start_cheat_caller_address}; +use starknet::{ClassHash, ContractAddress}; fn V2_CLASS_HASH() -> ClassHash { utils::declare_class("SnakeERC1155Mock").class_hash @@ -232,7 +232,7 @@ fn test_safe_transfer_from_approved_operator() { dispatcher.safe_transfer_from(owner, recipient, TOKEN_ID, TOKEN_VALUE, EMPTY_DATA()); spy .assert_only_event_transfer_single( - contract, operator, owner, recipient, TOKEN_ID, TOKEN_VALUE + contract, operator, owner, recipient, TOKEN_ID, TOKEN_VALUE, ); assert_state_after_transfer_single(dispatcher, owner, recipient, TOKEN_ID); @@ -256,7 +256,7 @@ fn test_safeTransferFrom_approved_operator() { dispatcher.safeTransferFrom(owner, recipient, TOKEN_ID, TOKEN_VALUE, EMPTY_DATA()); spy .assert_only_event_transfer_single( - contract, operator, owner, recipient, TOKEN_ID, TOKEN_VALUE + contract, operator, owner, recipient, TOKEN_ID, TOKEN_VALUE, ); assert_state_after_transfer_single(dispatcher, owner, recipient, TOKEN_ID); @@ -806,7 +806,7 @@ fn assert_state_before_transfer_single( dispatcher: ERC1155UpgradeableABIDispatcher, sender: ContractAddress, recipient: ContractAddress, - token_id: u256 + token_id: u256, ) { assert_eq!(dispatcher.balance_of(sender, token_id), TOKEN_VALUE); assert!(dispatcher.balance_of(recipient, token_id).is_zero()); @@ -816,7 +816,7 @@ fn assert_state_after_transfer_single( dispatcher: ERC1155UpgradeableABIDispatcher, sender: ContractAddress, recipient: ContractAddress, - token_id: u256 + token_id: u256, ) { assert!(dispatcher.balance_of(sender, token_id).is_zero()); assert_eq!(dispatcher.balance_of(recipient, token_id), TOKEN_VALUE); @@ -827,7 +827,7 @@ fn assert_state_before_transfer_batch( sender: ContractAddress, recipient: ContractAddress, token_ids: Span, - values: Span + values: Span, ) { let mut index = 0; loop { @@ -848,7 +848,7 @@ fn assert_state_after_transfer_batch( sender: ContractAddress, recipient: ContractAddress, token_ids: Span, - values: Span + values: Span, ) { let mut index = 0; loop { diff --git a/packages/presets/src/tests/test_erc20.cairo b/packages/presets/src/tests/test_erc20.cairo index be41473d9..1af195eda 100644 --- a/packages/presets/src/tests/test_erc20.cairo +++ b/packages/presets/src/tests/test_erc20.cairo @@ -1,7 +1,7 @@ use core::num::traits::Bounded; use core::num::traits::Zero; use crate::interfaces::erc20::{ - ERC20UpgradeableABISafeDispatcher, ERC20UpgradeableABISafeDispatcherTrait + ERC20UpgradeableABISafeDispatcher, ERC20UpgradeableABISafeDispatcherTrait, }; use crate::interfaces::{ERC20UpgradeableABIDispatcher, ERC20UpgradeableABIDispatcherTrait}; use openzeppelin_test_common::erc20::ERC20SpyHelpers; @@ -10,12 +10,12 @@ use openzeppelin_test_common::upgrades::UpgradeableSpyHelpers; use openzeppelin_testing as utils; use openzeppelin_testing::common::IntoBase16String; use openzeppelin_testing::constants::{ - ZERO, OWNER, SPENDER, RECIPIENT, OTHER, NAME, SYMBOL, DECIMALS, SUPPLY, VALUE, CLASS_HASH_ZERO + CLASS_HASH_ZERO, DECIMALS, NAME, OTHER, OWNER, RECIPIENT, SPENDER, SUPPLY, SYMBOL, VALUE, ZERO, }; use openzeppelin_testing::events::EventSpyExt; use openzeppelin_token::erc20::interface::{IERC20Dispatcher, IERC20DispatcherTrait}; use openzeppelin_utils::serde::SerializedAppend; -use snforge_std::{spy_events, EventSpy, start_cheat_caller_address}; +use snforge_std::{EventSpy, spy_events, start_cheat_caller_address}; use starknet::ClassHash; fn V2_CLASS_HASH() -> ClassHash { @@ -444,7 +444,7 @@ fn test_v2_missing_camel_selector() { v1.upgrade(v2_class_hash); let safe_dispatcher = ERC20UpgradeableABISafeDispatcher { - contract_address: v1.contract_address + contract_address: v1.contract_address, }; let result = safe_dispatcher.totalSupply(); diff --git a/packages/presets/src/tests/test_erc721.cairo b/packages/presets/src/tests/test_erc721.cairo index c6b02aa65..25bbbb05a 100644 --- a/packages/presets/src/tests/test_erc721.cairo +++ b/packages/presets/src/tests/test_erc721.cairo @@ -1,6 +1,6 @@ use core::num::traits::Zero; -use crate::ERC721Upgradeable::InternalImpl; use crate::ERC721Upgradeable; +use crate::ERC721Upgradeable::InternalImpl; use crate::interfaces::{ERC721UpgradeableABIDispatcher, ERC721UpgradeableABIDispatcherTrait}; use openzeppelin_introspection::interface::ISRC5_ID; use openzeppelin_test_common::erc721::ERC721SpyHelpers; @@ -9,19 +9,19 @@ use openzeppelin_test_common::upgrades::UpgradeableSpyHelpers; use openzeppelin_testing as utils; use openzeppelin_testing::common::IntoBase16String; use openzeppelin_testing::constants::{ - ZERO, DATA, OWNER, SPENDER, RECIPIENT, OTHER, OPERATOR, CLASS_HASH_ZERO, PUBKEY, NAME, SYMBOL, - BASE_URI + BASE_URI, CLASS_HASH_ZERO, DATA, NAME, OPERATOR, OTHER, OWNER, PUBKEY, RECIPIENT, SPENDER, + SYMBOL, ZERO, }; use openzeppelin_testing::events::EventSpyExt; use openzeppelin_token::erc721::ERC721Component::ERC721Impl; use openzeppelin_token::erc721::interface::{ - IERC721CamelOnlySafeDispatcher, IERC721CamelOnlySafeDispatcherTrait + 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 snforge_std::{spy_events, EventSpy, start_cheat_caller_address}; -use starknet::{ContractAddress, ClassHash}; +use snforge_std::{EventSpy, spy_events, start_cheat_caller_address}; +use starknet::{ClassHash, ContractAddress}; // Token IDs @@ -906,7 +906,7 @@ fn assert_state_before_transfer( dispatcher: ERC721UpgradeableABIDispatcher, owner: ContractAddress, recipient: ContractAddress, - token_id: u256 + token_id: u256, ) { assert_eq!(dispatcher.owner_of(token_id), owner); assert_eq!(dispatcher.balance_of(owner), TOKENS_LEN); @@ -917,7 +917,7 @@ fn assert_state_after_transfer( dispatcher: ERC721UpgradeableABIDispatcher, owner: ContractAddress, recipient: ContractAddress, - token_id: u256 + token_id: u256, ) { let current_owner = dispatcher.owner_of(token_id); assert_eq!(current_owner, recipient); @@ -932,7 +932,7 @@ fn assert_state_transfer_to_self( dispatcher: ERC721UpgradeableABIDispatcher, target: ContractAddress, token_id: u256, - token_balance: u256 + token_balance: u256, ) { assert_eq!(dispatcher.owner_of(token_id), target); assert_eq!(dispatcher.balance_of(target), token_balance); diff --git a/packages/presets/src/tests/test_eth_account.cairo b/packages/presets/src/tests/test_eth_account.cairo index 4a7fae491..fb389e184 100644 --- a/packages/presets/src/tests/test_eth_account.cairo +++ b/packages/presets/src/tests/test_eth_account.cairo @@ -1,14 +1,14 @@ use core::num::traits::Zero; use crate::EthAccountUpgradeable; use crate::interfaces::eth_account::{ - EthAccountUpgradeableABISafeDispatcher, EthAccountUpgradeableABISafeDispatcherTrait + EthAccountUpgradeableABISafeDispatcher, EthAccountUpgradeableABISafeDispatcherTrait, }; use crate::interfaces::{ - EthAccountUpgradeableABIDispatcher, EthAccountUpgradeableABIDispatcherTrait + EthAccountUpgradeableABIDispatcher, EthAccountUpgradeableABIDispatcherTrait, }; use openzeppelin_account::eth_account::EthAccountComponent::EthAccountMixinImpl; use openzeppelin_account::extensions::SRC9Component::{OutsideExecutionV2Impl, SNIP12MetadataImpl}; -use openzeppelin_account::extensions::src9::interface::{OutsideExecution, ISRC9_V2_ID}; +use openzeppelin_account::extensions::src9::interface::{ISRC9_V2_ID, OutsideExecution}; use openzeppelin_account::extensions::src9::snip12_utils::OutsideExecutionStructHash; use openzeppelin_account::interface::ISRC6_ID; use openzeppelin_account::utils::secp256_point::{DebugSecp256Point, Secp256PointPartialEq}; @@ -16,30 +16,30 @@ use openzeppelin_introspection::interface::ISRC5_ID; use openzeppelin_test_common::erc20::deploy_erc20; use openzeppelin_test_common::eth_account::EthAccountSpyHelpers; use openzeppelin_test_common::eth_account::{ - SIGNED_TX_DATA, SignedTransactionData, get_accept_ownership_signature + SIGNED_TX_DATA, SignedTransactionData, get_accept_ownership_signature, }; use openzeppelin_test_common::upgrades::UpgradeableSpyHelpers; use openzeppelin_testing as utils; use openzeppelin_testing::constants::secp256k1::{KEY_PAIR, KEY_PAIR_2}; -use openzeppelin_testing::constants::{CLASS_HASH_ZERO, ZERO, RECIPIENT, CALLER, OTHER, FELT_VALUE}; -use openzeppelin_testing::constants::{SALT, QUERY_VERSION, MIN_TRANSACTION_VERSION}; +use openzeppelin_testing::constants::{CALLER, CLASS_HASH_ZERO, FELT_VALUE, OTHER, RECIPIENT, ZERO}; +use openzeppelin_testing::constants::{MIN_TRANSACTION_VERSION, QUERY_VERSION, SALT}; use openzeppelin_testing::signing::Secp256k1KeyPair; use openzeppelin_testing::signing::SerializedSigning; use openzeppelin_token::erc20::interface::IERC20DispatcherTrait; use openzeppelin_utils::cryptography::snip12::OffchainMessageHash; use openzeppelin_utils::serde::SerializedAppend; use snforge_std::{ - spy_events, test_address, load, CheatSpan, cheat_caller_address, start_cheat_caller_address + CheatSpan, cheat_caller_address, load, spy_events, start_cheat_caller_address, test_address, }; use snforge_std::{ - start_cheat_signature_global, start_cheat_transaction_version_global, - start_cheat_transaction_hash_global, start_cheat_block_timestamp_global + start_cheat_block_timestamp_global, start_cheat_signature_global, + start_cheat_transaction_hash_global, start_cheat_transaction_version_global, }; use starknet::SyscallResultTrait; use starknet::account::Call; use starknet::secp256_trait::Secp256Trait; use starknet::secp256k1::Secp256k1Point; -use starknet::{contract_address_const, ContractAddress, ClassHash}; +use starknet::{ClassHash, ContractAddress, contract_address_const}; fn declare_v2_class() -> ClassHash { utils::declare_class("SnakeEthAccountMock").class_hash @@ -50,7 +50,7 @@ fn declare_v2_class() -> ClassHash { // fn setup_dispatcher( - key_pair: Secp256k1KeyPair + key_pair: Secp256k1KeyPair, ) -> (ContractAddress, EthAccountUpgradeableABIDispatcher) { let mut calldata = array![]; calldata.append_serde(key_pair.public_key); @@ -62,7 +62,7 @@ fn setup_dispatcher( } fn setup_dispatcher_with_data( - key_pair: Secp256k1KeyPair, data: SignedTransactionData + key_pair: Secp256k1KeyPair, data: SignedTransactionData, ) -> (EthAccountUpgradeableABIDispatcher, felt252) { let mut calldata = array![]; calldata.append_serde(key_pair.public_key); @@ -124,7 +124,7 @@ fn test_public_key_setter_and_getter() { let new_key_pair = KEY_PAIR_2(); let signature = get_accept_ownership_signature( - contract_address, key_pair.public_key, new_key_pair + contract_address, key_pair.public_key, new_key_pair, ); start_cheat_caller_address(contract_address, contract_address); dispatcher.set_public_key(new_key_pair.public_key, signature); @@ -144,7 +144,7 @@ fn test_public_key_setter_and_getter_camel() { let new_key_pair = KEY_PAIR_2(); let signature = get_accept_ownership_signature( - contract_address, key_pair.public_key, new_key_pair + contract_address, key_pair.public_key, new_key_pair, ); start_cheat_caller_address(contract_address, contract_address); dispatcher.setPublicKey(new_key_pair.public_key, signature); @@ -294,7 +294,7 @@ fn test_validate_declare() { // value is already integrated in the tx hash. The class_hash argument in this // testing context is decoupled from the signature and has no effect on the test. let is_valid = account.__validate_declare__(class_hash); - assert_eq!(is_valid, starknet::VALIDATED,); + assert_eq!(is_valid, starknet::VALIDATED); } #[test] @@ -343,7 +343,7 @@ fn test_execute_with_version(version: Option) { calldata.append_serde(amount); let call = Call { - to: erc20.contract_address, selector: selector!("transfer"), calldata: calldata.span() + to: erc20.contract_address, selector: selector!("transfer"), calldata: calldata.span(), }; let calls = array![call]; @@ -413,7 +413,7 @@ fn test_multicall() { calldata1.append_serde(recipient1); calldata1.append_serde(amount1); let call1 = Call { - to: erc20.contract_address, selector: selector!("transfer"), calldata: calldata1.span() + to: erc20.contract_address, selector: selector!("transfer"), calldata: calldata1.span(), }; // Craft 2nd call @@ -422,7 +422,7 @@ fn test_multicall() { calldata2.append_serde(recipient2); calldata2.append_serde(amount2); let call2 = Call { - to: erc20.contract_address, selector: selector!("transfer"), calldata: calldata2.span() + to: erc20.contract_address, selector: selector!("transfer"), calldata: calldata2.span(), }; let calls = array![call1, call2]; @@ -522,7 +522,7 @@ fn test_state_persists_after_upgrade() { let new_key_pair = KEY_PAIR_2(); let signature = get_accept_ownership_signature( - contract_address, key_pair.public_key, new_key_pair + contract_address, key_pair.public_key, new_key_pair, ); dispatcher.set_public_key(new_key_pair.public_key, signature); @@ -680,7 +680,7 @@ fn test_execute_from_outside_v2_invalid_signature() { let msg_hash = outside_execution.get_message_hash(account_address); let signature = key_pair.serialized_sign(msg_hash.into()); let invalid_signature = array![ - *signature.at(0), *signature.at(1), *signature.at(2), *signature.at(3) + 1 + *signature.at(0), *signature.at(1), *signature.at(2), *signature.at(3) + 1, ]; dispatcher.execute_from_outside_v2(outside_execution, invalid_signature.span()); diff --git a/packages/presets/src/tests/test_universal_deployer.cairo b/packages/presets/src/tests/test_universal_deployer.cairo index cc75c6543..42fa9fd7f 100644 --- a/packages/presets/src/tests/test_universal_deployer.cairo +++ b/packages/presets/src/tests/test_universal_deployer.cairo @@ -1,12 +1,12 @@ -use crate::universal_deployer::UniversalDeployer::ContractDeployed; use crate::universal_deployer::UniversalDeployer; +use crate::universal_deployer::UniversalDeployer::ContractDeployed; use openzeppelin_testing as utils; -use openzeppelin_testing::constants::{NAME, SYMBOL, SUPPLY, SALT, CALLER, RECIPIENT}; +use openzeppelin_testing::constants::{CALLER, NAME, RECIPIENT, SALT, SUPPLY, SYMBOL}; use openzeppelin_testing::events::EventSpyExt; use openzeppelin_token::erc20::interface::{IERC20Dispatcher, IERC20DispatcherTrait}; use openzeppelin_utils::deployments::{DeployerInfo, calculate_contract_address_from_udc}; use openzeppelin_utils::interfaces::{ - IUniversalDeployerDispatcher, IUniversalDeployerDispatcherTrait + IUniversalDeployerDispatcher, IUniversalDeployerDispatcherTrait, }; use openzeppelin_utils::serde::SerializedAppend; use snforge_std::{EventSpy, spy_events, start_cheat_caller_address}; @@ -48,7 +48,7 @@ fn test_deploy_from_zero() { // Check address let expected_addr = calculate_contract_address_from_udc( - salt, erc20_class_hash, erc20_calldata, Option::None + salt, erc20_class_hash, erc20_calldata, Option::None, ); let deployed_addr = udc.deploy_contract(erc20_class_hash, salt, from_zero, erc20_calldata); assert_eq!(expected_addr, deployed_addr); @@ -63,7 +63,7 @@ fn test_deploy_from_zero() { from_zero, erc20_class_hash, erc20_calldata, - salt + salt, ); // Check deployment @@ -91,7 +91,7 @@ fn test_deploy_not_from_zero() { salt, erc20_class_hash, erc20_calldata, - Option::Some(DeployerInfo { caller_address: caller, udc_address: udc.contract_address }) + Option::Some(DeployerInfo { caller_address: caller, udc_address: udc.contract_address }), ); let deployed_addr = udc.deploy_contract(erc20_class_hash, salt, from_zero, erc20_calldata); assert_eq!(expected_addr, deployed_addr); @@ -106,7 +106,7 @@ fn test_deploy_not_from_zero() { from_zero, erc20_class_hash, erc20_calldata, - salt + salt, ); // Check deployment @@ -129,10 +129,10 @@ impl UniversalDeployerHelpersImpl of UniversalDeployerSpyHelpers { from_zero: bool, class_hash: ClassHash, calldata: Span, - salt: felt252 + salt: felt252, ) { let expected = UniversalDeployer::Event::ContractDeployed( - ContractDeployed { address, deployer, from_zero, class_hash, calldata, salt } + ContractDeployed { address, deployer, from_zero, class_hash, calldata, salt }, ); self.assert_only_event(contract, expected); } diff --git a/packages/presets/src/tests/test_vesting.cairo b/packages/presets/src/tests/test_vesting.cairo index ccaa0758f..8c46e027e 100644 --- a/packages/presets/src/tests/test_vesting.cairo +++ b/packages/presets/src/tests/test_vesting.cairo @@ -5,10 +5,10 @@ use openzeppelin_test_common::erc20::deploy_erc20; use openzeppelin_test_common::ownable::OwnableSpyHelpers; use openzeppelin_test_common::vesting::VestingSpyHelpers; use openzeppelin_testing as utils; -use openzeppelin_testing::constants::{OWNER, OTHER, ZERO}; +use openzeppelin_testing::constants::{OTHER, OWNER, ZERO}; use openzeppelin_token::erc20::interface::{IERC20Dispatcher, IERC20DispatcherTrait}; use openzeppelin_utils::serde::SerializedAppend; -use snforge_std::{spy_events, start_cheat_caller_address, start_cheat_block_timestamp_global}; +use snforge_std::{spy_events, start_cheat_block_timestamp_global, start_cheat_caller_address}; use starknet::ContractAddress; // @@ -21,12 +21,12 @@ struct TestData { beneficiary: ContractAddress, start: u64, duration: u64, - cliff_duration: u64 + cliff_duration: u64, } fn TEST_DATA() -> TestData { TestData { - total_allocation: 200, beneficiary: OWNER(), start: 30, duration: 100, cliff_duration: 0 + total_allocation: 200, beneficiary: OWNER(), start: 30, duration: 100, cliff_duration: 0, } } diff --git a/packages/presets/src/universal_deployer.cairo b/packages/presets/src/universal_deployer.cairo index beafd7a31..c00870d83 100644 --- a/packages/presets/src/universal_deployer.cairo +++ b/packages/presets/src/universal_deployer.cairo @@ -6,7 +6,7 @@ /// The Universal Deployer Contract is a standardized generic factory of Starknet contracts. #[starknet::contract] pub mod UniversalDeployer { - use core::hash::{HashStateTrait, HashStateExTrait}; + use core::hash::{HashStateExTrait, HashStateTrait}; use core::poseidon::PoseidonTrait; use openzeppelin_utils::interfaces::IUniversalDeployer; use starknet::ClassHash; @@ -20,7 +20,7 @@ pub mod UniversalDeployer { #[event] #[derive(Drop, PartialEq, starknet::Event)] pub(crate) enum Event { - ContractDeployed: ContractDeployed + ContractDeployed: ContractDeployed, } #[derive(Drop, PartialEq, starknet::Event)] @@ -40,7 +40,7 @@ pub mod UniversalDeployer { class_hash: ClassHash, salt: felt252, from_zero: bool, - calldata: Span + calldata: Span, ) -> ContractAddress { let deployer: ContractAddress = get_caller_address(); let mut _salt: felt252 = salt; @@ -49,13 +49,13 @@ pub mod UniversalDeployer { } let (address, _) = starknet::syscalls::deploy_syscall( - class_hash, _salt, calldata, from_zero + class_hash, _salt, calldata, from_zero, ) .unwrap_syscall(); self .emit( - ContractDeployed { address, deployer, from_zero, class_hash, calldata, salt } + ContractDeployed { address, deployer, from_zero, class_hash, calldata, salt }, ); return address; } diff --git a/packages/presets/src/vesting.cairo b/packages/presets/src/vesting.cairo index 12561cba5..1594dece2 100644 --- a/packages/presets/src/vesting.cairo +++ b/packages/presets/src/vesting.cairo @@ -4,7 +4,7 @@ #[starknet::contract] pub mod VestingWallet { use openzeppelin_access::ownable::OwnableComponent; - use openzeppelin_finance::vesting::{VestingComponent, LinearVestingSchedule}; + use openzeppelin_finance::vesting::{LinearVestingSchedule, VestingComponent}; use starknet::ContractAddress; component!(path: OwnableComponent, storage: ownable, event: OwnableEvent); @@ -25,7 +25,7 @@ pub mod VestingWallet { #[substorage(v0)] pub ownable: OwnableComponent::Storage, #[substorage(v0)] - pub vesting: VestingComponent::Storage + pub vesting: VestingComponent::Storage, } #[event] @@ -34,7 +34,7 @@ pub mod VestingWallet { #[flat] OwnableEvent: OwnableComponent::Event, #[flat] - VestingEvent: VestingComponent::Event + VestingEvent: VestingComponent::Event, } /// Initializes the vesting component by setting the vesting `start`, `duration` and @@ -50,7 +50,7 @@ pub mod VestingWallet { beneficiary: ContractAddress, start: u64, duration: u64, - cliff_duration: u64 + cliff_duration: u64, ) { self.ownable.initializer(beneficiary); self.vesting.initializer(start, duration, cliff_duration); diff --git a/packages/security/src/initializable.cairo b/packages/security/src/initializable.cairo index 8bb651f83..6a53e24d0 100644 --- a/packages/security/src/initializable.cairo +++ b/packages/security/src/initializable.cairo @@ -13,7 +13,7 @@ pub mod InitializableComponent { #[storage] pub struct Storage { - pub Initializable_initialized: bool + pub Initializable_initialized: bool, } pub mod Errors { @@ -22,7 +22,7 @@ pub mod InitializableComponent { #[embeddable_as(InitializableImpl)] impl Initializable< - TContractState, +HasComponent + TContractState, +HasComponent, > of IInitializable> { /// Returns whether the contract has been initialized. fn is_initialized(self: @ComponentState) -> bool { @@ -32,7 +32,7 @@ pub mod InitializableComponent { #[generate_trait] pub impl InternalImpl< - TContractState, +HasComponent + TContractState, +HasComponent, > of InternalTrait { /// Ensures the calling function can only be called once. /// diff --git a/packages/security/src/pausable.cairo b/packages/security/src/pausable.cairo index 2f921e6ac..d4fb3639f 100644 --- a/packages/security/src/pausable.cairo +++ b/packages/security/src/pausable.cairo @@ -16,7 +16,7 @@ pub mod PausableComponent { #[storage] pub struct Storage { - pub Pausable_paused: bool + pub Pausable_paused: bool, } #[event] @@ -29,13 +29,13 @@ pub mod PausableComponent { /// Emitted when the pause is triggered by `account`. #[derive(Drop, PartialEq, starknet::Event)] pub struct Paused { - pub account: ContractAddress + pub account: ContractAddress, } /// Emitted when the pause is lifted by `account`. #[derive(Drop, PartialEq, starknet::Event)] pub struct Unpaused { - pub account: ContractAddress + pub account: ContractAddress, } pub mod Errors { @@ -45,7 +45,7 @@ pub mod PausableComponent { #[embeddable_as(PausableImpl)] impl Pausable< - TContractState, +HasComponent + TContractState, +HasComponent, > of IPausable> { /// Returns true if the contract is paused, and false otherwise. fn is_paused(self: @ComponentState) -> bool { @@ -55,7 +55,7 @@ pub mod PausableComponent { #[generate_trait] pub impl InternalImpl< - TContractState, +HasComponent + TContractState, +HasComponent, > of InternalTrait { /// Makes a function only callable when the contract is not paused. fn assert_not_paused(self: @ComponentState) { diff --git a/packages/security/src/reentrancyguard.cairo b/packages/security/src/reentrancyguard.cairo index 02b6420bb..b91ee0eee 100644 --- a/packages/security/src/reentrancyguard.cairo +++ b/packages/security/src/reentrancyguard.cairo @@ -10,7 +10,7 @@ pub mod ReentrancyGuardComponent { use starknet::storage::{StoragePointerReadAccess, StoragePointerWriteAccess}; #[storage] pub struct Storage { - pub ReentrancyGuard_entered: bool + pub ReentrancyGuard_entered: bool, } pub mod Errors { @@ -19,7 +19,7 @@ pub mod ReentrancyGuardComponent { #[generate_trait] pub impl InternalImpl< - TContractState, +HasComponent + TContractState, +HasComponent, > of InternalTrait { /// Prevents a contract's function from calling itself or another protected function, /// directly or indirectly. diff --git a/packages/security/src/tests/test_initializable.cairo b/packages/security/src/tests/test_initializable.cairo index 6fbfada0a..02a0c76be 100644 --- a/packages/security/src/tests/test_initializable.cairo +++ b/packages/security/src/tests/test_initializable.cairo @@ -1,5 +1,5 @@ -use crate::InitializableComponent::{InitializableImpl, InternalImpl}; use crate::InitializableComponent; +use crate::InitializableComponent::{InitializableImpl, InternalImpl}; use openzeppelin_test_common::mocks::security::InitializableMock; type ComponentState = InitializableComponent::ComponentState; diff --git a/packages/security/src/tests/test_pausable.cairo b/packages/security/src/tests/test_pausable.cairo index 6ccbc921a..db22fa922 100644 --- a/packages/security/src/tests/test_pausable.cairo +++ b/packages/security/src/tests/test_pausable.cairo @@ -1,11 +1,11 @@ +use crate::PausableComponent; use crate::PausableComponent::{InternalImpl, PausableImpl}; use crate::PausableComponent::{Paused, Unpaused}; -use crate::PausableComponent; use openzeppelin_test_common::mocks::security::PausableMock; use openzeppelin_testing::constants::CALLER; use openzeppelin_testing::events::EventSpyExt; use snforge_std::EventSpy; -use snforge_std::{spy_events, test_address, start_cheat_caller_address}; +use snforge_std::{spy_events, start_cheat_caller_address, test_address}; use starknet::ContractAddress; type ComponentState = PausableComponent::ComponentState; @@ -125,7 +125,7 @@ fn test_unpause_when_unpaused() { #[generate_trait] impl PausableSpyHelpersImpl of PausableSpyHelpers { fn assert_event_paused( - ref self: EventSpy, contract: ContractAddress, account: ContractAddress + ref self: EventSpy, contract: ContractAddress, account: ContractAddress, ) { let expected = PausableComponent::Event::Paused(Paused { account }); self.assert_emitted_single(contract, expected); @@ -139,7 +139,7 @@ impl PausableSpyHelpersImpl of PausableSpyHelpers { } fn assert_event_unpaused( - ref self: EventSpy, contract: ContractAddress, account: ContractAddress + ref self: EventSpy, contract: ContractAddress, account: ContractAddress, ) { let expected = PausableComponent::Event::Unpaused(Unpaused { account }); self.assert_emitted_single(contract, expected); diff --git a/packages/security/src/tests/test_reentrancyguard.cairo b/packages/security/src/tests/test_reentrancyguard.cairo index 3263e77a4..dd57f366d 100644 --- a/packages/security/src/tests/test_reentrancyguard.cairo +++ b/packages/security/src/tests/test_reentrancyguard.cairo @@ -1,7 +1,7 @@ -use crate::ReentrancyGuardComponent::InternalImpl; use crate::ReentrancyGuardComponent; +use crate::ReentrancyGuardComponent::InternalImpl; use openzeppelin_test_common::mocks::security::{ - ReentrancyMock, IReentrancyMockDispatcher, IReentrancyMockDispatcherTrait + IReentrancyMockDispatcher, IReentrancyMockDispatcherTrait, ReentrancyMock, }; use openzeppelin_testing as utils; use starknet::storage::StoragePointerReadAccess; diff --git a/packages/test_common/src/account.cairo b/packages/test_common/src/account.cairo index 1456ae47f..b473d110f 100644 --- a/packages/test_common/src/account.cairo +++ b/packages/test_common/src/account.cairo @@ -1,7 +1,7 @@ -use core::hash::{HashStateTrait, HashStateExTrait}; +use core::hash::{HashStateExTrait, HashStateTrait}; use core::poseidon::PoseidonTrait; -use openzeppelin_account::AccountComponent::{OwnerAdded, OwnerRemoved}; use openzeppelin_account::AccountComponent; +use openzeppelin_account::AccountComponent::{OwnerAdded, OwnerRemoved}; use openzeppelin_testing::constants::TRANSACTION_HASH; use openzeppelin_testing::events::EventSpyExt; use openzeppelin_testing::signing::StarkKeyPair; @@ -13,7 +13,7 @@ use starknet::ContractAddress; pub struct SignedTransactionData { pub tx_hash: felt252, pub r: felt252, - pub s: felt252 + pub s: felt252, } pub fn SIGNED_TX_DATA(key_pair: StarkKeyPair) -> SignedTransactionData { @@ -23,7 +23,7 @@ pub fn SIGNED_TX_DATA(key_pair: StarkKeyPair) -> SignedTransactionData { } pub fn get_accept_ownership_signature( - account_address: ContractAddress, current_public_key: felt252, new_key_pair: StarkKeyPair + account_address: ContractAddress, current_public_key: felt252, new_key_pair: StarkKeyPair, ) -> Span { let msg_hash = PoseidonTrait::new() .update_with('StarkNet Message') @@ -38,21 +38,21 @@ pub fn get_accept_ownership_signature( #[generate_trait] pub impl AccountSpyHelpersImpl of AccountSpyHelpers { fn assert_event_owner_removed( - ref self: EventSpy, contract: ContractAddress, removed_owner_guid: felt252 + ref self: EventSpy, contract: ContractAddress, removed_owner_guid: felt252, ) { let expected = AccountComponent::Event::OwnerRemoved(OwnerRemoved { removed_owner_guid }); self.assert_emitted_single(contract, expected); } fn assert_event_owner_added( - ref self: EventSpy, contract: ContractAddress, new_owner_guid: felt252 + ref self: EventSpy, contract: ContractAddress, new_owner_guid: felt252, ) { let expected = AccountComponent::Event::OwnerAdded(OwnerAdded { new_owner_guid }); self.assert_emitted_single(contract, expected); } fn assert_only_event_owner_added( - ref self: EventSpy, contract: ContractAddress, new_owner_guid: felt252 + ref self: EventSpy, contract: ContractAddress, new_owner_guid: felt252, ) { self.assert_event_owner_added(contract, new_owner_guid); self.assert_no_events_left_from(contract); diff --git a/packages/test_common/src/erc1155.cairo b/packages/test_common/src/erc1155.cairo index 569c1c781..83d141c31 100644 --- a/packages/test_common/src/erc1155.cairo +++ b/packages/test_common/src/erc1155.cairo @@ -1,8 +1,8 @@ use openzeppelin_testing as utils; use openzeppelin_testing::constants::{PUBKEY, TOKEN_ID, TOKEN_ID_2, TOKEN_VALUE, TOKEN_VALUE_2}; use openzeppelin_testing::events::EventSpyExt; -use openzeppelin_token::erc1155::ERC1155Component::{TransferBatch, ApprovalForAll, TransferSingle}; use openzeppelin_token::erc1155::ERC1155Component; +use openzeppelin_token::erc1155::ERC1155Component::{ApprovalForAll, TransferBatch, TransferSingle}; use snforge_std::EventSpy; use starknet::ContractAddress; @@ -43,10 +43,10 @@ pub impl ERC1155SpyHelpersImpl of ERC1155SpyHelpers { contract: ContractAddress, owner: ContractAddress, operator: ContractAddress, - approved: bool + approved: bool, ) { let expected = ERC1155Component::Event::ApprovalForAll( - ApprovalForAll { owner, operator, approved } + ApprovalForAll { owner, operator, approved }, ); self.assert_emitted_single(contract, expected); } @@ -56,7 +56,7 @@ pub impl ERC1155SpyHelpersImpl of ERC1155SpyHelpers { contract: ContractAddress, owner: ContractAddress, operator: ContractAddress, - approved: bool + approved: bool, ) { self.assert_event_approval_for_all(contract, owner, operator, approved); self.assert_no_events_left_from(contract); @@ -69,10 +69,10 @@ pub impl ERC1155SpyHelpersImpl of ERC1155SpyHelpers { from: ContractAddress, to: ContractAddress, token_id: u256, - value: u256 + value: u256, ) { let expected = ERC1155Component::Event::TransferSingle( - TransferSingle { operator, from, to, id: token_id, value } + TransferSingle { operator, from, to, id: token_id, value }, ); self.assert_emitted_single(contract, expected); } @@ -84,7 +84,7 @@ pub impl ERC1155SpyHelpersImpl of ERC1155SpyHelpers { from: ContractAddress, to: ContractAddress, token_id: u256, - value: u256 + value: u256, ) { self.assert_event_transfer_single(contract, operator, from, to, token_id, value); self.assert_no_events_left_from(contract); @@ -97,10 +97,10 @@ pub impl ERC1155SpyHelpersImpl of ERC1155SpyHelpers { from: ContractAddress, to: ContractAddress, token_ids: Span, - values: Span + values: Span, ) { let expected = ERC1155Component::Event::TransferBatch( - TransferBatch { operator, from, to, ids: token_ids, values } + TransferBatch { operator, from, to, ids: token_ids, values }, ); self.assert_emitted_single(contract, expected); } @@ -112,7 +112,7 @@ pub impl ERC1155SpyHelpersImpl of ERC1155SpyHelpers { from: ContractAddress, to: ContractAddress, token_ids: Span, - values: Span + values: Span, ) { self.assert_event_transfer_batch(contract, operator, from, to, token_ids, values); self.assert_no_events_left_from(contract); diff --git a/packages/test_common/src/erc20.cairo b/packages/test_common/src/erc20.cairo index 1307dbcf5..c0e1d6e4d 100644 --- a/packages/test_common/src/erc20.cairo +++ b/packages/test_common/src/erc20.cairo @@ -1,8 +1,8 @@ use openzeppelin_testing as utils; use openzeppelin_testing::constants::{NAME, SYMBOL}; use openzeppelin_testing::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::interface::{IERC20Dispatcher}; use openzeppelin_utils::serde::SerializedAppend; use snforge_std::EventSpy; @@ -26,7 +26,7 @@ pub impl ERC20SpyHelpersImpl of ERC20SpyHelpers { contract: ContractAddress, owner: ContractAddress, spender: ContractAddress, - value: u256 + value: u256, ) { let expected = ERC20Component::Event::Approval(Approval { owner, spender, value }); self.assert_emitted_single(contract, expected); @@ -37,7 +37,7 @@ pub impl ERC20SpyHelpersImpl of ERC20SpyHelpers { contract: ContractAddress, owner: ContractAddress, spender: ContractAddress, - value: u256 + value: u256, ) { self.assert_event_approval(contract, owner, spender, value); self.assert_no_events_left_from(contract); @@ -48,7 +48,7 @@ pub impl ERC20SpyHelpersImpl of ERC20SpyHelpers { contract: ContractAddress, from: ContractAddress, to: ContractAddress, - value: u256 + value: u256, ) { let expected = ERC20Component::Event::Transfer(Transfer { from, to, value }); self.assert_emitted_single(contract, expected); @@ -59,7 +59,7 @@ pub impl ERC20SpyHelpersImpl of ERC20SpyHelpers { contract: ContractAddress, from: ContractAddress, to: ContractAddress, - value: u256 + value: u256, ) { self.assert_event_transfer(contract, from, to, value); self.assert_no_events_left_from(contract); diff --git a/packages/test_common/src/erc721.cairo b/packages/test_common/src/erc721.cairo index f73a67bab..a2409867b 100644 --- a/packages/test_common/src/erc721.cairo +++ b/packages/test_common/src/erc721.cairo @@ -1,6 +1,6 @@ use openzeppelin_testing::events::EventSpyExt; -use openzeppelin_token::erc721::ERC721Component::{Approval, ApprovalForAll, Transfer}; use openzeppelin_token::erc721::ERC721Component; +use openzeppelin_token::erc721::ERC721Component::{Approval, ApprovalForAll, Transfer}; use snforge_std::EventSpy; use starknet::ContractAddress; @@ -11,10 +11,10 @@ pub impl ERC721SpyHelpersImpl of ERC721SpyHelpers { contract: ContractAddress, owner: ContractAddress, operator: ContractAddress, - approved: bool + approved: bool, ) { let expected = ERC721Component::Event::ApprovalForAll( - ApprovalForAll { owner, operator, approved } + ApprovalForAll { owner, operator, approved }, ); self.assert_emitted_single(contract, expected); } @@ -24,7 +24,7 @@ pub impl ERC721SpyHelpersImpl of ERC721SpyHelpers { contract: ContractAddress, owner: ContractAddress, operator: ContractAddress, - approved: bool + approved: bool, ) { self.assert_event_approval_for_all(contract, owner, operator, approved); self.assert_no_events_left_from(contract); @@ -35,7 +35,7 @@ pub impl ERC721SpyHelpersImpl of ERC721SpyHelpers { contract: ContractAddress, owner: ContractAddress, approved: ContractAddress, - token_id: u256 + token_id: u256, ) { let expected = ERC721Component::Event::Approval(Approval { owner, approved, token_id }); self.assert_emitted_single(contract, expected); @@ -46,7 +46,7 @@ pub impl ERC721SpyHelpersImpl of ERC721SpyHelpers { contract: ContractAddress, owner: ContractAddress, approved: ContractAddress, - token_id: u256 + token_id: u256, ) { self.assert_event_approval(contract, owner, approved, token_id); self.assert_no_events_left_from(contract); @@ -57,7 +57,7 @@ pub impl ERC721SpyHelpersImpl of ERC721SpyHelpers { contract: ContractAddress, from: ContractAddress, to: ContractAddress, - token_id: u256 + token_id: u256, ) { let expected = ERC721Component::Event::Transfer(Transfer { from, to, token_id }); self.assert_emitted_single(contract, expected); @@ -68,7 +68,7 @@ pub impl ERC721SpyHelpersImpl of ERC721SpyHelpers { contract: ContractAddress, from: ContractAddress, to: ContractAddress, - token_id: u256 + token_id: u256, ) { self.assert_event_transfer(contract, from, to, token_id); self.assert_no_events_left_from(contract); diff --git a/packages/test_common/src/eth_account.cairo b/packages/test_common/src/eth_account.cairo index 377c06770..5aa8f015b 100644 --- a/packages/test_common/src/eth_account.cairo +++ b/packages/test_common/src/eth_account.cairo @@ -1,9 +1,9 @@ -use core::hash::{HashStateTrait, HashStateExTrait}; +use core::hash::{HashStateExTrait, HashStateTrait}; 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::EthAccountComponent::{OwnerAdded, OwnerRemoved}; use openzeppelin_account::interface::EthPublicKey; use openzeppelin_account::utils::signature::Secp256Signature; use openzeppelin_testing::constants::TRANSACTION_HASH; @@ -18,7 +18,7 @@ pub struct SignedTransactionData { pub private_key: u256, pub public_key: EthPublicKey, pub tx_hash: felt252, - pub signature: Secp256Signature + pub signature: Secp256Signature, } pub fn SIGNED_TX_DATA(key_pair: Secp256k1KeyPair) -> SignedTransactionData { @@ -28,12 +28,12 @@ pub fn SIGNED_TX_DATA(key_pair: Secp256k1KeyPair) -> SignedTransactionData { private_key: key_pair.secret_key, public_key: key_pair.public_key, tx_hash, - signature: Secp256Signature { r, s } + signature: Secp256Signature { r, s }, } } pub fn get_accept_ownership_signature( - account_address: ContractAddress, current_owner: EthPublicKey, new_key_pair: Secp256k1KeyPair + account_address: ContractAddress, current_owner: EthPublicKey, new_key_pair: Secp256k1KeyPair, ) -> Span { let msg_hash: u256 = PoseidonTrait::new() .update_with('StarkNet Message') @@ -49,17 +49,17 @@ pub fn get_accept_ownership_signature( #[generate_trait] pub impl EthAccountSpyHelpersImpl of EthAccountSpyHelpers { fn assert_event_owner_removed( - ref self: EventSpy, contract: ContractAddress, public_key: EthPublicKey + ref self: EventSpy, contract: ContractAddress, public_key: EthPublicKey, ) { let removed_owner_guid = get_guid_from_public_key(public_key); let expected = EthAccountComponent::Event::OwnerRemoved( - OwnerRemoved { removed_owner_guid } + OwnerRemoved { removed_owner_guid }, ); self.assert_emitted_single(contract, expected); } fn assert_event_owner_added( - ref self: EventSpy, contract: ContractAddress, public_key: EthPublicKey + ref self: EventSpy, contract: ContractAddress, public_key: EthPublicKey, ) { let new_owner_guid = get_guid_from_public_key(public_key); let expected = EthAccountComponent::Event::OwnerAdded(OwnerAdded { new_owner_guid }); @@ -67,7 +67,7 @@ pub impl EthAccountSpyHelpersImpl of EthAccountSpyHelpers { } fn assert_only_event_owner_added( - ref self: EventSpy, contract: ContractAddress, public_key: EthPublicKey + ref self: EventSpy, contract: ContractAddress, public_key: EthPublicKey, ) { self.assert_event_owner_added(contract, public_key); self.assert_no_events_left_from(contract); diff --git a/packages/test_common/src/mocks/access.cairo b/packages/test_common/src/mocks/access.cairo index ccca94518..d829c83da 100644 --- a/packages/test_common/src/mocks/access.cairo +++ b/packages/test_common/src/mocks/access.cairo @@ -19,7 +19,7 @@ pub mod DualCaseAccessControlMock { #[substorage(v0)] pub accesscontrol: AccessControlComponent::Storage, #[substorage(v0)] - pub src5: SRC5Component::Storage + pub src5: SRC5Component::Storage, } #[event] @@ -28,7 +28,7 @@ pub mod DualCaseAccessControlMock { #[flat] AccessControlEvent: AccessControlComponent::Event, #[flat] - SRC5Event: SRC5Component::Event + SRC5Event: SRC5Component::Event, } #[constructor] @@ -52,14 +52,14 @@ pub mod DualCaseOwnableMock { #[storage] pub struct Storage { #[substorage(v0)] - pub ownable: OwnableComponent::Storage + pub ownable: OwnableComponent::Storage, } #[event] #[derive(Drop, starknet::Event)] enum Event { #[flat] - OwnableEvent: OwnableComponent::Event + OwnableEvent: OwnableComponent::Event, } #[constructor] @@ -83,14 +83,14 @@ pub mod DualCaseTwoStepOwnableMock { #[storage] pub struct Storage { #[substorage(v0)] - ownable: OwnableComponent::Storage + ownable: OwnableComponent::Storage, } #[event] #[derive(Drop, starknet::Event)] enum Event { #[flat] - OwnableEvent: OwnableComponent::Event + OwnableEvent: OwnableComponent::Event, } #[constructor] diff --git a/packages/test_common/src/mocks/account.cairo b/packages/test_common/src/mocks/account.cairo index 69c6eaf02..208f5aacb 100644 --- a/packages/test_common/src/mocks/account.cairo +++ b/packages/test_common/src/mocks/account.cairo @@ -26,7 +26,7 @@ pub mod DualCaseAccountMock { #[substorage(v0)] pub account: AccountComponent::Storage, #[substorage(v0)] - pub src5: SRC5Component::Storage + pub src5: SRC5Component::Storage, } #[event] @@ -35,7 +35,7 @@ pub mod DualCaseAccountMock { #[flat] AccountEvent: AccountComponent::Event, #[flat] - SRC5Event: SRC5Component::Event + SRC5Event: SRC5Component::Event, } #[constructor] @@ -68,7 +68,7 @@ pub mod SnakeAccountMock { #[substorage(v0)] pub account: AccountComponent::Storage, #[substorage(v0)] - pub src5: SRC5Component::Storage + pub src5: SRC5Component::Storage, } #[event] @@ -77,7 +77,7 @@ pub mod SnakeAccountMock { #[flat] AccountEvent: AccountComponent::Event, #[flat] - SRC5Event: SRC5Component::Event + SRC5Event: SRC5Component::Event, } #[constructor] @@ -112,7 +112,7 @@ pub mod DualCaseEthAccountMock { #[substorage(v0)] pub eth_account: EthAccountComponent::Storage, #[substorage(v0)] - pub src5: SRC5Component::Storage + pub src5: SRC5Component::Storage, } #[event] @@ -121,7 +121,7 @@ pub mod DualCaseEthAccountMock { #[flat] EthAccountEvent: EthAccountComponent::Event, #[flat] - SRC5Event: SRC5Component::Event + SRC5Event: SRC5Component::Event, } #[constructor] @@ -152,7 +152,7 @@ pub mod SnakeEthAccountMock { #[substorage(v0)] pub eth_account: EthAccountComponent::Storage, #[substorage(v0)] - pub src5: SRC5Component::Storage + pub src5: SRC5Component::Storage, } #[event] @@ -161,7 +161,7 @@ pub mod SnakeEthAccountMock { #[flat] EthAccountEvent: EthAccountComponent::Event, #[flat] - SRC5Event: SRC5Component::Event + SRC5Event: SRC5Component::Event, } #[constructor] diff --git a/packages/test_common/src/mocks/erc1155.cairo b/packages/test_common/src/mocks/erc1155.cairo index 6c98dd7b2..f669299ad 100644 --- a/packages/test_common/src/mocks/erc1155.cairo +++ b/packages/test_common/src/mocks/erc1155.cairo @@ -26,7 +26,7 @@ pub mod DualCaseERC1155Mock { #[substorage(v0)] pub erc1155: ERC1155Component::Storage, #[substorage(v0)] - pub src5: SRC5Component::Storage + pub src5: SRC5Component::Storage, } #[event] @@ -35,7 +35,7 @@ pub mod DualCaseERC1155Mock { #[flat] ERC1155Event: ERC1155Component::Event, #[flat] - SRC5Event: SRC5Component::Event + SRC5Event: SRC5Component::Event, } #[constructor] @@ -44,7 +44,7 @@ pub mod DualCaseERC1155Mock { base_uri: ByteArray, recipient: ContractAddress, token_id: u256, - value: u256 + value: u256, ) { self.erc1155.initializer(base_uri); self.erc1155.mint_with_acceptance_check(recipient, token_id, value, array![].span()); @@ -77,7 +77,7 @@ pub mod SnakeERC1155Mock { #[substorage(v0)] pub erc1155: ERC1155Component::Storage, #[substorage(v0)] - pub src5: SRC5Component::Storage + pub src5: SRC5Component::Storage, } #[event] @@ -86,7 +86,7 @@ pub mod SnakeERC1155Mock { #[flat] ERC1155Event: ERC1155Component::Event, #[flat] - SRC5Event: SRC5Component::Event + SRC5Event: SRC5Component::Event, } #[constructor] @@ -95,7 +95,7 @@ pub mod SnakeERC1155Mock { base_uri: ByteArray, recipient: ContractAddress, token_id: u256, - value: u256 + value: u256, ) { self.erc1155.initializer(base_uri); self.erc1155.mint_with_acceptance_check(recipient, token_id, value, array![].span()); @@ -130,7 +130,7 @@ pub mod SnakeERC1155MockWithHooks { #[substorage(v0)] pub erc1155: ERC1155Component::Storage, #[substorage(v0)] - pub src5: SRC5Component::Storage + pub src5: SRC5Component::Storage, } #[event] @@ -141,7 +141,7 @@ pub mod SnakeERC1155MockWithHooks { #[flat] SRC5Event: SRC5Component::Event, BeforeUpdate: BeforeUpdate, - AfterUpdate: AfterUpdate + AfterUpdate: AfterUpdate, } /// Event used to test that `before_update` hook is called. @@ -150,7 +150,7 @@ pub mod SnakeERC1155MockWithHooks { pub from: ContractAddress, pub to: ContractAddress, pub token_ids: Span, - pub values: Span + pub values: Span, } /// Event used to test that `after_update` hook is called. @@ -159,7 +159,7 @@ pub mod SnakeERC1155MockWithHooks { pub from: ContractAddress, pub to: ContractAddress, pub token_ids: Span, - pub values: Span + pub values: Span, } #[constructor] @@ -168,7 +168,7 @@ pub mod SnakeERC1155MockWithHooks { base_uri: ByteArray, recipient: ContractAddress, token_id: u256, - value: u256 + value: u256, ) { self.erc1155.initializer(base_uri); self.erc1155.mint_with_acceptance_check(recipient, token_id, value, array![].span()); @@ -180,7 +180,7 @@ pub mod SnakeERC1155MockWithHooks { from: ContractAddress, to: ContractAddress, token_ids: Span, - values: Span + values: Span, ) { let mut contract_state = self.get_contract_mut(); contract_state.emit(BeforeUpdate { from, to, token_ids, values }); @@ -191,7 +191,7 @@ pub mod SnakeERC1155MockWithHooks { from: ContractAddress, to: ContractAddress, token_ids: Span, - values: Span + values: Span, ) { let mut contract_state = self.get_contract_mut(); contract_state.emit(AfterUpdate { from, to, token_ids, values }); @@ -206,7 +206,7 @@ pub mod DualCaseERC1155ReceiverMock { component!(path: SRC5Component, storage: src5, event: SRC5Event); component!( - path: ERC1155ReceiverComponent, storage: erc1155_receiver, event: ERC1155ReceiverEvent + path: ERC1155ReceiverComponent, storage: erc1155_receiver, event: ERC1155ReceiverEvent, ); // ERC1155Receiver Mixin @@ -220,7 +220,7 @@ pub mod DualCaseERC1155ReceiverMock { #[substorage(v0)] pub erc1155_receiver: ERC1155ReceiverComponent::Storage, #[substorage(v0)] - pub src5: SRC5Component::Storage + pub src5: SRC5Component::Storage, } #[event] @@ -229,7 +229,7 @@ pub mod DualCaseERC1155ReceiverMock { #[flat] ERC1155ReceiverEvent: ERC1155ReceiverComponent::Event, #[flat] - SRC5Event: SRC5Component::Event + SRC5Event: SRC5Component::Event, } #[constructor] diff --git a/packages/test_common/src/mocks/erc20.cairo b/packages/test_common/src/mocks/erc20.cairo index 818dc0917..de3c88e37 100644 --- a/packages/test_common/src/mocks/erc20.cairo +++ b/packages/test_common/src/mocks/erc20.cairo @@ -16,14 +16,14 @@ pub mod DualCaseERC20Mock { #[storage] pub struct Storage { #[substorage(v0)] - pub erc20: ERC20Component::Storage + pub erc20: ERC20Component::Storage, } #[event] #[derive(Drop, starknet::Event)] enum Event { #[flat] - ERC20Event: ERC20Component::Event + ERC20Event: ERC20Component::Event, } #[constructor] @@ -32,7 +32,7 @@ pub mod DualCaseERC20Mock { name: ByteArray, symbol: ByteArray, initial_supply: u256, - recipient: ContractAddress + recipient: ContractAddress, ) { self.erc20.initializer(name, symbol); self.erc20.mint(recipient, initial_supply); @@ -55,14 +55,14 @@ pub mod SnakeERC20Mock { #[storage] pub struct Storage { #[substorage(v0)] - pub erc20: ERC20Component::Storage + pub erc20: ERC20Component::Storage, } #[event] #[derive(Drop, starknet::Event)] enum Event { #[flat] - ERC20Event: ERC20Component::Event + ERC20Event: ERC20Component::Event, } #[constructor] @@ -71,7 +71,7 @@ pub mod SnakeERC20Mock { name: ByteArray, symbol: ByteArray, initial_supply: u256, - recipient: ContractAddress + recipient: ContractAddress, ) { self.erc20.initializer(name, symbol); self.erc20.mint(recipient, initial_supply); @@ -96,7 +96,7 @@ pub mod SnakeERC20MockWithHooks { #[storage] pub struct Storage { #[substorage(v0)] - pub erc20: ERC20Component::Storage + pub erc20: ERC20Component::Storage, } #[event] @@ -105,7 +105,7 @@ pub mod SnakeERC20MockWithHooks { #[flat] ERC20Event: ERC20Component::Event, BeforeUpdate: BeforeUpdate, - AfterUpdate: AfterUpdate + AfterUpdate: AfterUpdate, } /// Event used to test that `before_update` hook is called. @@ -113,7 +113,7 @@ pub mod SnakeERC20MockWithHooks { pub struct BeforeUpdate { pub from: ContractAddress, pub recipient: ContractAddress, - pub amount: u256 + pub amount: u256, } /// Event used to test that `after_update` hook is called. @@ -121,7 +121,7 @@ pub mod SnakeERC20MockWithHooks { pub struct AfterUpdate { pub from: ContractAddress, pub recipient: ContractAddress, - pub amount: u256 + pub amount: u256, } #[constructor] @@ -130,7 +130,7 @@ pub mod SnakeERC20MockWithHooks { name: ByteArray, symbol: ByteArray, initial_supply: u256, - recipient: ContractAddress + recipient: ContractAddress, ) { self.erc20.initializer(name, symbol); self.erc20.mint(recipient, initial_supply); @@ -141,7 +141,7 @@ pub mod SnakeERC20MockWithHooks { ref self: ERC20Component::ComponentState, from: ContractAddress, recipient: ContractAddress, - amount: u256 + amount: u256, ) { let mut contract_state = self.get_contract_mut(); contract_state.emit(BeforeUpdate { from, recipient, amount }); @@ -151,7 +151,7 @@ pub mod SnakeERC20MockWithHooks { ref self: ERC20Component::ComponentState, from: ContractAddress, recipient: ContractAddress, - amount: u256 + amount: u256, ) { let mut contract_state = self.get_contract_mut(); contract_state.emit(AfterUpdate { from, recipient, amount }); @@ -188,7 +188,7 @@ pub mod DualCaseERC20PermitMock { #[substorage(v0)] pub erc20: ERC20Component::Storage, #[substorage(v0)] - pub nonces: NoncesComponent::Storage + pub nonces: NoncesComponent::Storage, } #[event] @@ -197,7 +197,7 @@ pub mod DualCaseERC20PermitMock { #[flat] ERC20Event: ERC20Component::Event, #[flat] - NoncesEvent: NoncesComponent::Event + NoncesEvent: NoncesComponent::Event, } /// Required for hash computation. @@ -218,7 +218,7 @@ pub mod DualCaseERC20PermitMock { name: ByteArray, symbol: ByteArray, initial_supply: u256, - recipient: ContractAddress + recipient: ContractAddress, ) { self.erc20.initializer(name, symbol); self.erc20.mint(recipient, initial_supply); diff --git a/packages/test_common/src/mocks/erc2981.cairo b/packages/test_common/src/mocks/erc2981.cairo index 93b9c1285..90f848b95 100644 --- a/packages/test_common/src/mocks/erc2981.cairo +++ b/packages/test_common/src/mocks/erc2981.cairo @@ -1,7 +1,7 @@ #[starknet::contract] pub mod ERC2981Mock { use openzeppelin_introspection::src5::SRC5Component; - use openzeppelin_token::common::erc2981::{ERC2981Component, DefaultConfig}; + use openzeppelin_token::common::erc2981::{DefaultConfig, ERC2981Component}; use starknet::ContractAddress; component!(path: ERC2981Component, storage: erc2981, event: ERC2981Event); @@ -22,7 +22,7 @@ pub mod ERC2981Mock { #[substorage(v0)] pub erc2981: ERC2981Component::Storage, #[substorage(v0)] - pub src5: SRC5Component::Storage + pub src5: SRC5Component::Storage, } #[event] @@ -31,7 +31,7 @@ pub mod ERC2981Mock { #[flat] ERC2981Event: ERC2981Component::Event, #[flat] - SRC5Event: SRC5Component::Event + SRC5Event: SRC5Component::Event, } #[constructor] @@ -39,7 +39,7 @@ pub mod ERC2981Mock { ref self: ContractState, owner: ContractAddress, default_receiver: ContractAddress, - default_royalty_fraction: u128 + default_royalty_fraction: u128, ) { self.erc2981.initializer(default_receiver, default_royalty_fraction); } @@ -49,7 +49,7 @@ pub mod ERC2981Mock { pub mod ERC2981OwnableMock { use openzeppelin_access::ownable::OwnableComponent; use openzeppelin_introspection::src5::SRC5Component; - use openzeppelin_token::common::erc2981::{ERC2981Component, DefaultConfig}; + use openzeppelin_token::common::erc2981::{DefaultConfig, ERC2981Component}; use starknet::ContractAddress; component!(path: ERC2981Component, storage: erc2981, event: ERC2981Event); @@ -82,7 +82,7 @@ pub mod ERC2981OwnableMock { #[substorage(v0)] pub src5: SRC5Component::Storage, #[substorage(v0)] - pub ownable: OwnableComponent::Storage + pub ownable: OwnableComponent::Storage, } #[event] @@ -101,7 +101,7 @@ pub mod ERC2981OwnableMock { ref self: ContractState, owner: ContractAddress, default_receiver: ContractAddress, - default_royalty_fraction: u128 + default_royalty_fraction: u128, ) { self.erc2981.initializer(default_receiver, default_royalty_fraction); self.ownable.initializer(owner); @@ -114,7 +114,7 @@ pub mod ERC2981AccessControlMock { use openzeppelin_access::accesscontrol::{AccessControlComponent, DEFAULT_ADMIN_ROLE}; use openzeppelin_introspection::src5::SRC5Component; use openzeppelin_token::common::erc2981::ERC2981Component::ROYALTY_ADMIN_ROLE; - use openzeppelin_token::common::erc2981::{ERC2981Component, DefaultConfig}; + use openzeppelin_token::common::erc2981::{DefaultConfig, ERC2981Component}; use starknet::ContractAddress; component!(path: ERC2981Component, storage: erc2981, event: ERC2981Event); @@ -148,7 +148,7 @@ pub mod ERC2981AccessControlMock { #[substorage(v0)] pub src5: SRC5Component::Storage, #[substorage(v0)] - pub accesscontrol: AccessControlComponent::Storage + pub accesscontrol: AccessControlComponent::Storage, } #[event] @@ -167,7 +167,7 @@ pub mod ERC2981AccessControlMock { ref self: ContractState, owner: ContractAddress, default_receiver: ContractAddress, - default_royalty_fraction: u128 + default_royalty_fraction: u128, ) { self.erc2981.initializer(default_receiver, default_royalty_fraction); self.accesscontrol.initializer(); diff --git a/packages/test_common/src/mocks/erc721.cairo b/packages/test_common/src/mocks/erc721.cairo index 054b45258..0fa9b38e6 100644 --- a/packages/test_common/src/mocks/erc721.cairo +++ b/packages/test_common/src/mocks/erc721.cairo @@ -30,7 +30,7 @@ pub mod DualCaseERC721Mock { #[substorage(v0)] pub erc721: ERC721Component::Storage, #[substorage(v0)] - pub src5: SRC5Component::Storage + pub src5: SRC5Component::Storage, } #[event] @@ -39,7 +39,7 @@ pub mod DualCaseERC721Mock { #[flat] ERC721Event: ERC721Component::Event, #[flat] - SRC5Event: SRC5Component::Event + SRC5Event: SRC5Component::Event, } #[constructor] @@ -49,7 +49,7 @@ pub mod DualCaseERC721Mock { symbol: ByteArray, base_uri: ByteArray, recipient: ContractAddress, - token_id: u256 + token_id: u256, ) { self.erc721.initializer(name, symbol, base_uri); self.erc721.mint(recipient, token_id); @@ -81,7 +81,7 @@ pub mod SnakeERC721Mock { #[substorage(v0)] pub erc721: ERC721Component::Storage, #[substorage(v0)] - pub src5: SRC5Component::Storage + pub src5: SRC5Component::Storage, } #[event] @@ -90,7 +90,7 @@ pub mod SnakeERC721Mock { #[flat] ERC721Event: ERC721Component::Event, #[flat] - SRC5Event: SRC5Component::Event + SRC5Event: SRC5Component::Event, } #[constructor] @@ -100,7 +100,7 @@ pub mod SnakeERC721Mock { symbol: ByteArray, base_uri: ByteArray, recipient: ContractAddress, - token_id: u256 + token_id: u256, ) { self.erc721.initializer(name, symbol, base_uri); self.erc721.mint(recipient, token_id); @@ -134,7 +134,7 @@ pub mod SnakeERC721MockWithHooks { #[substorage(v0)] pub erc721: ERC721Component::Storage, #[substorage(v0)] - pub src5: SRC5Component::Storage + pub src5: SRC5Component::Storage, } #[event] @@ -145,7 +145,7 @@ pub mod SnakeERC721MockWithHooks { #[flat] SRC5Event: SRC5Component::Event, BeforeUpdate: BeforeUpdate, - AfterUpdate: AfterUpdate + AfterUpdate: AfterUpdate, } /// Event used to test that `before_update` hook is called. @@ -153,7 +153,7 @@ pub mod SnakeERC721MockWithHooks { pub struct BeforeUpdate { pub to: ContractAddress, pub token_id: u256, - pub auth: ContractAddress + pub auth: ContractAddress, } /// Event used to test that `after_update` hook is called. @@ -161,7 +161,7 @@ pub mod SnakeERC721MockWithHooks { pub struct AfterUpdate { pub to: ContractAddress, pub token_id: u256, - pub auth: ContractAddress + pub auth: ContractAddress, } #[constructor] @@ -171,7 +171,7 @@ pub mod SnakeERC721MockWithHooks { symbol: ByteArray, base_uri: ByteArray, recipient: ContractAddress, - token_id: u256 + token_id: u256, ) { self.erc721.initializer(name, symbol, base_uri); self.erc721.mint(recipient, token_id); @@ -182,7 +182,7 @@ pub mod SnakeERC721MockWithHooks { ref self: ERC721Component::ComponentState, to: ContractAddress, token_id: u256, - auth: ContractAddress + auth: ContractAddress, ) { let mut contract_state = self.get_contract_mut(); contract_state.emit(BeforeUpdate { to, token_id, auth }); @@ -192,7 +192,7 @@ pub mod SnakeERC721MockWithHooks { ref self: ERC721Component::ComponentState, to: ContractAddress, token_id: u256, - auth: ContractAddress + auth: ContractAddress, ) { let mut contract_state = self.get_contract_mut(); contract_state.emit(AfterUpdate { to, token_id, auth }); @@ -222,7 +222,7 @@ pub mod DualCaseERC721ReceiverMock { #[substorage(v0)] pub erc721_receiver: ERC721ReceiverComponent::Storage, #[substorage(v0)] - pub src5: SRC5Component::Storage + pub src5: SRC5Component::Storage, } #[event] @@ -231,7 +231,7 @@ pub mod DualCaseERC721ReceiverMock { #[flat] ERC721ReceiverEvent: ERC721ReceiverComponent::Event, #[flat] - SRC5Event: SRC5Component::Event + SRC5Event: SRC5Component::Event, } #[constructor] @@ -248,7 +248,7 @@ pub mod DualCaseERC721ReceiverMock { operator: ContractAddress, from: ContractAddress, token_id: u256, - data: Span + data: Span, ) -> felt252 { if *data.at(0) == super::SUCCESS { self.erc721_receiver.on_erc721_received(operator, from, token_id, data) @@ -263,7 +263,7 @@ pub mod DualCaseERC721ReceiverMock { operator: ContractAddress, from: ContractAddress, tokenId: u256, - data: Span + data: Span, ) -> felt252 { Self::on_erc721_received(self, operator, from, tokenId, data) } @@ -274,13 +274,13 @@ pub mod DualCaseERC721ReceiverMock { pub mod ERC721EnumerableMock { use openzeppelin_introspection::src5::SRC5Component; use openzeppelin_token::erc721::ERC721Component; - use openzeppelin_token::erc721::extensions::ERC721EnumerableComponent::InternalTrait; use openzeppelin_token::erc721::extensions::ERC721EnumerableComponent; + use openzeppelin_token::erc721::extensions::ERC721EnumerableComponent::InternalTrait; use starknet::ContractAddress; component!(path: ERC721Component, storage: erc721, event: ERC721Event); component!( - path: ERC721EnumerableComponent, storage: erc721_enumerable, event: ERC721EnumerableEvent + path: ERC721EnumerableComponent, storage: erc721_enumerable, event: ERC721EnumerableEvent, ); component!(path: SRC5Component, storage: src5, event: SRC5Event); @@ -306,7 +306,7 @@ pub mod ERC721EnumerableMock { #[substorage(v0)] pub erc721_enumerable: ERC721EnumerableComponent::Storage, #[substorage(v0)] - pub src5: SRC5Component::Storage + pub src5: SRC5Component::Storage, } #[event] @@ -317,7 +317,7 @@ pub mod ERC721EnumerableMock { #[flat] ERC721EnumerableEvent: ERC721EnumerableComponent::Event, #[flat] - SRC5Event: SRC5Component::Event + SRC5Event: SRC5Component::Event, } impl ERC721HooksImpl of ERC721Component::ERC721HooksTrait { @@ -325,7 +325,7 @@ pub mod ERC721EnumerableMock { ref self: ERC721Component::ComponentState, to: ContractAddress, token_id: u256, - auth: ContractAddress + auth: ContractAddress, ) { let mut contract_state = self.get_contract_mut(); contract_state.erc721_enumerable.before_update(to, token_id); @@ -348,7 +348,7 @@ pub mod ERC721EnumerableMock { symbol: ByteArray, base_uri: ByteArray, recipient: ContractAddress, - token_id: u256 + token_id: u256, ) { self.erc721.initializer(name, symbol, base_uri); self.erc721_enumerable.initializer(); diff --git a/packages/test_common/src/mocks/governor.cairo b/packages/test_common/src/mocks/governor.cairo index e87743a70..0458c9e9e 100644 --- a/packages/test_common/src/mocks/governor.cairo +++ b/packages/test_common/src/mocks/governor.cairo @@ -4,9 +4,9 @@ pub mod GovernorMock { use openzeppelin_governance::governor::GovernorComponent::InternalTrait as GovernorInternalTrait; use openzeppelin_governance::governor::extensions::GovernorVotesComponent::InternalTrait; use openzeppelin_governance::governor::extensions::{ - GovernorVotesComponent, GovernorCountingSimpleComponent, GovernorCoreExecutionComponent + GovernorCoreExecutionComponent, GovernorCountingSimpleComponent, GovernorVotesComponent, }; - use openzeppelin_governance::governor::{GovernorComponent, DefaultConfig}; + use openzeppelin_governance::governor::{DefaultConfig, GovernorComponent}; use openzeppelin_introspection::src5::SRC5Component; use openzeppelin_utils::cryptography::snip12::SNIP12Metadata; use starknet::ContractAddress; @@ -21,12 +21,12 @@ pub mod GovernorMock { component!( path: GovernorCountingSimpleComponent, storage: governor_counting_simple, - event: GovernorCountingSimpleEvent + event: GovernorCountingSimpleEvent, ); component!( path: GovernorCoreExecutionComponent, storage: governor_core_execution, - event: GovernorCoreExecutionEvent + event: GovernorCoreExecutionEvent, ); component!(path: SRC5Component, storage: src5, event: SRC5Event); @@ -136,10 +136,10 @@ pub mod GovernorQuorumFractionMock { use openzeppelin_governance::governor::GovernorComponent::InternalTrait as GovernorInternalTrait; use openzeppelin_governance::governor::extensions::GovernorVotesQuorumFractionComponent::InternalTrait; use openzeppelin_governance::governor::extensions::{ - GovernorVotesQuorumFractionComponent, GovernorCountingSimpleComponent, - GovernorCoreExecutionComponent, + GovernorCoreExecutionComponent, GovernorCountingSimpleComponent, + GovernorVotesQuorumFractionComponent, }; - use openzeppelin_governance::governor::{GovernorComponent, DefaultConfig}; + use openzeppelin_governance::governor::{DefaultConfig, GovernorComponent}; use openzeppelin_introspection::src5::SRC5Component; use openzeppelin_utils::cryptography::snip12::SNIP12Metadata; use starknet::ContractAddress; @@ -153,17 +153,17 @@ pub mod GovernorQuorumFractionMock { component!( path: GovernorVotesQuorumFractionComponent, storage: governor_votes, - event: GovernorVotesEvent + event: GovernorVotesEvent, ); component!( path: GovernorCountingSimpleComponent, storage: governor_counting_simple, - event: GovernorCountingSimpleEvent + event: GovernorCountingSimpleEvent, ); component!( path: GovernorCoreExecutionComponent, storage: governor_core_execution, - event: GovernorCoreExecutionEvent + event: GovernorCoreExecutionEvent, ); component!(path: SRC5Component, storage: src5, event: SRC5Event); @@ -266,10 +266,10 @@ pub mod GovernorTimelockedMock { use openzeppelin_governance::governor::extensions::GovernorTimelockExecutionComponent::InternalTrait as GovernorTimelockExecutionInternalTrait; use openzeppelin_governance::governor::extensions::GovernorVotesComponent::InternalTrait as GovernorVotesInternalTrait; use openzeppelin_governance::governor::extensions::{ - GovernorVotesComponent, GovernorSettingsComponent, GovernorCountingSimpleComponent, - GovernorTimelockExecutionComponent + GovernorCountingSimpleComponent, GovernorSettingsComponent, + GovernorTimelockExecutionComponent, GovernorVotesComponent, }; - use openzeppelin_governance::governor::{GovernorComponent, DefaultConfig}; + use openzeppelin_governance::governor::{DefaultConfig, GovernorComponent}; use openzeppelin_introspection::src5::SRC5Component; use openzeppelin_utils::cryptography::snip12::SNIP12Metadata; use starknet::ContractAddress; @@ -282,17 +282,17 @@ pub mod GovernorTimelockedMock { component!(path: GovernorComponent, storage: governor, event: GovernorEvent); component!(path: GovernorVotesComponent, storage: governor_votes, event: GovernorVotesEvent); component!( - path: GovernorSettingsComponent, storage: governor_settings, event: GovernorSettingsEvent + path: GovernorSettingsComponent, storage: governor_settings, event: GovernorSettingsEvent, ); component!( path: GovernorCountingSimpleComponent, storage: governor_counting_simple, - event: GovernorCountingSimpleEvent + event: GovernorCountingSimpleEvent, ); component!( path: GovernorTimelockExecutionComponent, storage: governor_timelock_execution, - event: GovernorTimelockExecutionEvent + event: GovernorTimelockExecutionEvent, ); component!(path: SRC5Component, storage: src5, event: SRC5Event); @@ -357,7 +357,7 @@ pub mod GovernorTimelockedMock { #[constructor] fn constructor( - ref self: ContractState, votes_token: ContractAddress, timelock_controller: ContractAddress + ref self: ContractState, votes_token: ContractAddress, timelock_controller: ContractAddress, ) { self.governor.initializer(); self.governor_votes.initializer(votes_token); @@ -395,7 +395,7 @@ pub mod GovernorTimelockedMock { impl ExternalImpl of ExternalTrait { #[external(v0)] fn cancel_operations( - ref self: ContractState, proposal_id: felt252, description_hash: felt252 + ref self: ContractState, proposal_id: felt252, description_hash: felt252, ) { self.governor.cancel_operations(proposal_id, description_hash); } diff --git a/packages/test_common/src/mocks/multisig.cairo b/packages/test_common/src/mocks/multisig.cairo index c7141a04b..38d1beb95 100644 --- a/packages/test_common/src/mocks/multisig.cairo +++ b/packages/test_common/src/mocks/multisig.cairo @@ -19,7 +19,7 @@ pub mod MultisigWalletMock { #[derive(Drop, starknet::Event)] enum Event { #[flat] - MultisigEvent: MultisigComponent::Event + MultisigEvent: MultisigComponent::Event, } #[constructor] diff --git a/packages/test_common/src/mocks/nonces.cairo b/packages/test_common/src/mocks/nonces.cairo index 92365d717..90331894a 100644 --- a/packages/test_common/src/mocks/nonces.cairo +++ b/packages/test_common/src/mocks/nonces.cairo @@ -11,13 +11,13 @@ pub mod NoncesMock { #[storage] pub struct Storage { #[substorage(v0)] - pub nonces: NoncesComponent::Storage + pub nonces: NoncesComponent::Storage, } #[event] #[derive(Drop, starknet::Event)] enum Event { #[flat] - NoncesEvent: NoncesComponent::Event + NoncesEvent: NoncesComponent::Event, } } diff --git a/packages/test_common/src/mocks/security.cairo b/packages/test_common/src/mocks/security.cairo index cac6c3acc..a1b3ed386 100644 --- a/packages/test_common/src/mocks/security.cairo +++ b/packages/test_common/src/mocks/security.cairo @@ -12,14 +12,14 @@ pub mod InitializableMock { #[storage] pub struct Storage { #[substorage(v0)] - pub initializable: InitializableComponent::Storage + pub initializable: InitializableComponent::Storage, } #[event] #[derive(Drop, starknet::Event)] enum Event { #[flat] - InitializableEvent: InitializableComponent::Event + InitializableEvent: InitializableComponent::Event, } } @@ -36,14 +36,14 @@ pub mod PausableMock { #[storage] pub struct Storage { #[substorage(v0)] - pub pausable: PausableComponent::Storage + pub pausable: PausableComponent::Storage, } #[event] #[derive(Drop, starknet::Event)] enum Event { #[flat] - PausableEvent: PausableComponent::Event + PausableEvent: PausableComponent::Event, } } @@ -74,7 +74,7 @@ pub mod ReentrancyMock { use super::IReentrancyGuardedDispatcherTrait; component!( - path: ReentrancyGuardComponent, storage: reentrancy_guard, event: ReentrancyGuardEvent + path: ReentrancyGuardComponent, storage: reentrancy_guard, event: ReentrancyGuardEvent, ); impl InternalImpl = ReentrancyGuardComponent::InternalImpl; @@ -83,14 +83,14 @@ pub mod ReentrancyMock { pub struct Storage { pub counter: felt252, #[substorage(v0)] - pub reentrancy_guard: ReentrancyGuardComponent::Storage + pub reentrancy_guard: ReentrancyGuardComponent::Storage, } #[event] #[derive(Drop, starknet::Event)] enum Event { #[flat] - ReentrancyGuardEvent: ReentrancyGuardComponent::Event + ReentrancyGuardEvent: ReentrancyGuardComponent::Event, } #[abi(embed_v0)] diff --git a/packages/test_common/src/mocks/src5.cairo b/packages/test_common/src/mocks/src5.cairo index 0d20d0a40..ae7347f66 100644 --- a/packages/test_common/src/mocks/src5.cairo +++ b/packages/test_common/src/mocks/src5.cairo @@ -10,13 +10,13 @@ pub mod SRC5Mock { #[storage] pub struct Storage { #[substorage(v0)] - pub src5: SRC5Component::Storage + pub src5: SRC5Component::Storage, } #[event] #[derive(Drop, starknet::Event)] enum Event { #[flat] - SRC5Event: SRC5Component::Event + SRC5Event: SRC5Component::Event, } } diff --git a/packages/test_common/src/mocks/src9.cairo b/packages/test_common/src/mocks/src9.cairo index a7a7bcafb..d28f5ca64 100644 --- a/packages/test_common/src/mocks/src9.cairo +++ b/packages/test_common/src/mocks/src9.cairo @@ -34,7 +34,7 @@ pub mod SRC9AccountMock { #[substorage(v0)] pub src9: SRC9Component::Storage, #[substorage(v0)] - pub src5: SRC5Component::Storage + pub src5: SRC5Component::Storage, } #[event] @@ -45,7 +45,7 @@ pub mod SRC9AccountMock { #[flat] SRC9Event: SRC9Component::Event, #[flat] - SRC5Event: SRC5Component::Event + SRC5Event: SRC5Component::Event, } #[constructor] diff --git a/packages/test_common/src/mocks/timelock.cairo b/packages/test_common/src/mocks/timelock.cairo index 974e7e2b8..0a59326a6 100644 --- a/packages/test_common/src/mocks/timelock.cairo +++ b/packages/test_common/src/mocks/timelock.cairo @@ -22,7 +22,7 @@ pub mod TimelockControllerMock { #[substorage(v0)] pub src5: SRC5Component::Storage, #[substorage(v0)] - pub timelock: TimelockControllerComponent::Storage + pub timelock: TimelockControllerComponent::Storage, } #[event] @@ -33,7 +33,7 @@ pub mod TimelockControllerMock { #[flat] SRC5Event: SRC5Component::Event, #[flat] - TimelockEvent: TimelockControllerComponent::Event + TimelockEvent: TimelockControllerComponent::Event, } #[constructor] @@ -42,7 +42,7 @@ pub mod TimelockControllerMock { min_delay: u64, proposers: Span, executors: Span, - admin: ContractAddress + admin: ContractAddress, ) { self.timelock.initializer(min_delay, proposers, executors, admin); } @@ -90,7 +90,7 @@ pub trait ITimelockAttacker { #[starknet::contract] pub mod TimelockAttackerMock { use openzeppelin_governance::timelock::interface::{ - ITimelockDispatcher, ITimelockDispatcherTrait + ITimelockDispatcher, ITimelockDispatcherTrait, }; use starknet::account::Call; use starknet::storage::{StoragePointerReadAccess, StoragePointerWriteAccess}; @@ -102,7 +102,7 @@ pub mod TimelockAttackerMock { #[storage] pub struct Storage { pub balance: felt252, - pub count: felt252 + pub count: felt252, } #[abi(embed_v0)] @@ -119,7 +119,7 @@ pub mod TimelockAttackerMock { self.count.write(current_count + 1); let reentrant_call = Call { - to: this, selector: selector!("reenter"), calldata: array![].span() + to: this, selector: selector!("reenter"), calldata: array![].span(), }; let timelock = ITimelockDispatcher { contract_address: sender }; @@ -139,7 +139,7 @@ pub mod TimelockAttackerMock { self.count.write(current_count + 1); let reentrant_call = Call { - to: this, selector: selector!("reenter_batch"), calldata: array![].span() + to: this, selector: selector!("reenter_batch"), calldata: array![].span(), }; let calls = array![reentrant_call].span(); diff --git a/packages/test_common/src/mocks/upgrades.cairo b/packages/test_common/src/mocks/upgrades.cairo index f743b703d..d5d54b577 100644 --- a/packages/test_common/src/mocks/upgrades.cairo +++ b/packages/test_common/src/mocks/upgrades.cairo @@ -4,7 +4,7 @@ use starknet::ClassHash; pub trait IUpgradesV1 { fn upgrade(ref self: TState, new_class_hash: ClassHash); fn upgrade_and_call( - ref self: TState, new_class_hash: ClassHash, selector: felt252, calldata: Span + ref self: TState, new_class_hash: ClassHash, selector: felt252, calldata: Span, ) -> Span; fn set_value(ref self: TState, val: felt252); fn get_value(self: @TState) -> felt252; @@ -25,14 +25,14 @@ pub mod UpgradesV1 { pub struct Storage { #[substorage(v0)] pub upgradeable: UpgradeableComponent::Storage, - pub value: felt252 + pub value: felt252, } #[event] #[derive(Drop, starknet::Event)] enum Event { #[flat] - UpgradeableEvent: UpgradeableComponent::Event + UpgradeableEvent: UpgradeableComponent::Event, } #[abi(embed_v0)] @@ -45,7 +45,7 @@ pub mod UpgradesV1 { ref self: ContractState, new_class_hash: ClassHash, selector: felt252, - calldata: Span + calldata: Span, ) -> Span { self.upgradeable.upgrade_and_call(new_class_hash, selector, calldata) } @@ -66,7 +66,7 @@ pub mod UpgradesV1 { pub trait IUpgradesV2 { fn upgrade(ref self: TState, new_class_hash: ClassHash); fn upgrade_and_call( - ref self: TState, new_class_hash: ClassHash, selector: felt252, calldata: Span + ref self: TState, new_class_hash: ClassHash, selector: felt252, calldata: Span, ) -> Span; fn set_value(ref self: TState, val: felt252); fn set_value2(ref self: TState, val: felt252); @@ -89,14 +89,14 @@ pub mod UpgradesV2 { #[substorage(v0)] pub upgradeable: UpgradeableComponent::Storage, pub value: felt252, - pub value2: felt252 + pub value2: felt252, } #[event] #[derive(Drop, starknet::Event)] enum Event { #[flat] - UpgradeableEvent: UpgradeableComponent::Event + UpgradeableEvent: UpgradeableComponent::Event, } #[abi(embed_v0)] @@ -109,7 +109,7 @@ pub mod UpgradesV2 { ref self: ContractState, new_class_hash: ClassHash, selector: felt252, - calldata: Span + calldata: Span, ) -> Span { self.upgradeable.upgrade_and_call(new_class_hash, selector, calldata) } diff --git a/packages/test_common/src/mocks/vesting.cairo b/packages/test_common/src/mocks/vesting.cairo index ae1489cfb..50100ad60 100644 --- a/packages/test_common/src/mocks/vesting.cairo +++ b/packages/test_common/src/mocks/vesting.cairo @@ -1,7 +1,7 @@ #[starknet::contract] pub mod LinearVestingMock { use openzeppelin_access::ownable::OwnableComponent; - use openzeppelin_finance::vesting::{VestingComponent, LinearVestingSchedule}; + use openzeppelin_finance::vesting::{LinearVestingSchedule, VestingComponent}; use starknet::ContractAddress; component!(path: OwnableComponent, storage: ownable, event: OwnableEvent); @@ -22,7 +22,7 @@ pub mod LinearVestingMock { #[substorage(v0)] ownable: OwnableComponent::Storage, #[substorage(v0)] - vesting: VestingComponent::Storage + vesting: VestingComponent::Storage, } #[event] @@ -31,7 +31,7 @@ pub mod LinearVestingMock { #[flat] OwnableEvent: OwnableComponent::Event, #[flat] - VestingEvent: VestingComponent::Event + VestingEvent: VestingComponent::Event, } #[constructor] @@ -50,8 +50,8 @@ pub mod LinearVestingMock { #[starknet::contract] pub mod StepsVestingMock { use openzeppelin_access::ownable::OwnableComponent; - use openzeppelin_finance::vesting::VestingComponent::VestingScheduleTrait; use openzeppelin_finance::vesting::VestingComponent; + use openzeppelin_finance::vesting::VestingComponent::VestingScheduleTrait; use starknet::ContractAddress; use starknet::storage::{StoragePointerReadAccess, StoragePointerWriteAccess}; @@ -74,7 +74,7 @@ pub mod StepsVestingMock { #[substorage(v0)] ownable: OwnableComponent::Storage, #[substorage(v0)] - vesting: VestingComponent::Storage + vesting: VestingComponent::Storage, } #[event] @@ -83,7 +83,7 @@ pub mod StepsVestingMock { #[flat] OwnableEvent: OwnableComponent::Event, #[flat] - VestingEvent: VestingComponent::Event + VestingEvent: VestingComponent::Event, } #[constructor] @@ -144,14 +144,14 @@ pub mod ERC20OptionalTransferPanicMock { struct Storage { transfer_should_fail: bool, #[substorage(v0)] - erc20: ERC20Component::Storage + erc20: ERC20Component::Storage, } #[event] #[derive(Drop, starknet::Event)] enum Event { #[flat] - ERC20Event: ERC20Component::Event + ERC20Event: ERC20Component::Event, } #[constructor] @@ -160,7 +160,7 @@ pub mod ERC20OptionalTransferPanicMock { name: ByteArray, symbol: ByteArray, initial_supply: u256, - recipient: ContractAddress + recipient: ContractAddress, ) { self.erc20.initializer(name, symbol); self.erc20.mint(recipient, initial_supply); @@ -177,7 +177,7 @@ pub mod ERC20OptionalTransferPanicMock { } fn allowance( - self: @ContractState, owner: ContractAddress, spender: ContractAddress + self: @ContractState, owner: ContractAddress, spender: ContractAddress, ) -> u256 { self.erc20.allowance(owner, spender) } @@ -194,7 +194,7 @@ pub mod ERC20OptionalTransferPanicMock { ref self: ContractState, sender: ContractAddress, recipient: ContractAddress, - amount: u256 + amount: u256, ) -> bool { if self.transfer_should_fail.read() { false diff --git a/packages/test_common/src/mocks/votes.cairo b/packages/test_common/src/mocks/votes.cairo index eefdce4df..9faf3b40d 100644 --- a/packages/test_common/src/mocks/votes.cairo +++ b/packages/test_common/src/mocks/votes.cairo @@ -31,7 +31,7 @@ pub mod ERC20VotesMock { #[substorage(v0)] pub erc20: ERC20Component::Storage, #[substorage(v0)] - pub nonces: NoncesComponent::Storage + pub nonces: NoncesComponent::Storage, } #[event] @@ -42,7 +42,7 @@ pub mod ERC20VotesMock { #[flat] ERC20Event: ERC20Component::Event, #[flat] - NoncesEvent: NoncesComponent::Event + NoncesEvent: NoncesComponent::Event, } /// Required for hash computation. @@ -60,7 +60,7 @@ pub mod ERC20VotesMock { ref self: ERC20Component::ComponentState, from: ContractAddress, recipient: ContractAddress, - amount: u256 + amount: u256, ) { let mut contract_state = self.get_contract_mut(); contract_state.erc20_votes.transfer_voting_units(from, recipient, amount); @@ -110,7 +110,7 @@ pub mod ERC721VotesMock { #[substorage(v0)] pub src5: SRC5Component::Storage, #[substorage(v0)] - pub nonces: NoncesComponent::Storage + pub nonces: NoncesComponent::Storage, } #[event] @@ -123,7 +123,7 @@ pub mod ERC721VotesMock { #[flat] SRC5Event: SRC5Component::Event, #[flat] - NoncesEvent: NoncesComponent::Event + NoncesEvent: NoncesComponent::Event, } /// Required for hash computation. @@ -143,7 +143,7 @@ pub mod ERC721VotesMock { ref self: ERC721Component::ComponentState, to: ContractAddress, token_id: u256, - auth: ContractAddress + auth: ContractAddress, ) { let mut contract_state = self.get_contract_mut(); diff --git a/packages/test_common/src/ownable.cairo b/packages/test_common/src/ownable.cairo index 8a5651693..b5e53ebbc 100644 --- a/packages/test_common/src/ownable.cairo +++ b/packages/test_common/src/ownable.cairo @@ -1,5 +1,5 @@ -use openzeppelin_access::ownable::OwnableComponent::OwnershipTransferred; use openzeppelin_access::ownable::OwnableComponent; +use openzeppelin_access::ownable::OwnableComponent::OwnershipTransferred; use openzeppelin_testing::EventSpyExt; use snforge_std::EventSpy; use starknet::ContractAddress; @@ -10,7 +10,7 @@ pub impl OwnableSpyHelpersImpl of OwnableSpyHelpers { ref self: EventSpy, contract: ContractAddress, previous_owner: ContractAddress, - new_owner: ContractAddress + new_owner: ContractAddress, ) { self.assert_event_ownership_transferred(contract, previous_owner, new_owner); self.assert_no_events_left_from(contract); @@ -20,10 +20,10 @@ pub impl OwnableSpyHelpersImpl of OwnableSpyHelpers { ref self: EventSpy, contract: ContractAddress, previous_owner: ContractAddress, - new_owner: ContractAddress + new_owner: ContractAddress, ) { let expected = OwnableComponent::Event::OwnershipTransferred( - OwnershipTransferred { previous_owner, new_owner } + OwnershipTransferred { previous_owner, new_owner }, ); self.assert_emitted_single(contract, expected); } diff --git a/packages/test_common/src/upgrades.cairo b/packages/test_common/src/upgrades.cairo index 4577cd3de..0e51a6806 100644 --- a/packages/test_common/src/upgrades.cairo +++ b/packages/test_common/src/upgrades.cairo @@ -1,8 +1,8 @@ use openzeppelin_testing::events::EventSpyExt; -use openzeppelin_upgrades::UpgradeableComponent::Upgraded; use openzeppelin_upgrades::UpgradeableComponent; +use openzeppelin_upgrades::UpgradeableComponent::Upgraded; use snforge_std::EventSpy; -use starknet::{ContractAddress, ClassHash}; +use starknet::{ClassHash, ContractAddress}; #[generate_trait] pub impl UpgradeableSpyHelpersImpl of UpgradeableSpyHelpers { @@ -12,7 +12,7 @@ pub impl UpgradeableSpyHelpersImpl of UpgradeableSpyHelpers { } fn assert_only_event_upgraded( - ref self: EventSpy, contract: ContractAddress, class_hash: ClassHash + ref self: EventSpy, contract: ContractAddress, class_hash: ClassHash, ) { self.assert_event_upgraded(contract, class_hash); self.assert_no_events_left_from(contract); diff --git a/packages/test_common/src/vesting.cairo b/packages/test_common/src/vesting.cairo index d6039c107..7596e13e2 100644 --- a/packages/test_common/src/vesting.cairo +++ b/packages/test_common/src/vesting.cairo @@ -1,5 +1,5 @@ -use openzeppelin_finance::vesting::VestingComponent::AmountReleased; use openzeppelin_finance::vesting::VestingComponent; +use openzeppelin_finance::vesting::VestingComponent::AmountReleased; use openzeppelin_testing::events::EventSpyExt; use snforge_std::EventSpy; use starknet::ContractAddress; @@ -7,7 +7,7 @@ use starknet::ContractAddress; #[generate_trait] pub impl VestingSpyHelpersImpl of VestingSpyHelpers { fn assert_only_event_amount_released( - ref self: EventSpy, contract: ContractAddress, token: ContractAddress, amount: u256 + ref self: EventSpy, contract: ContractAddress, token: ContractAddress, amount: u256, ) { let expected = VestingComponent::Event::AmountReleased(AmountReleased { token, amount }); self.assert_only_event(contract, expected); diff --git a/packages/testing/src/common.cairo b/packages/testing/src/common.cairo index 135a985de..c7ba1e28c 100644 --- a/packages/testing/src/common.cairo +++ b/packages/testing/src/common.cairo @@ -54,18 +54,18 @@ pub impl IntoBase16String> of IntoBase16StringTrait { /// Asserts that the syscall result of a call failed with an "Entrypoint not found" error, /// following the Starknet Foundry emitted error format. pub fn assert_entrypoint_not_found_error>( - result: SyscallResult, selector: felt252, contract_address: ContractAddress + result: SyscallResult, selector: felt252, contract_address: ContractAddress, ) { if let Result::Err(panic_data) = result { let expected_panic_message = format!( "Entry point selector {} not found in contract {}", selector.into_base_16_string_no_padding(), - contract_address.into_base_16_string_no_padding() + contract_address.into_base_16_string_no_padding(), ); let actual_panic_message = panic_data_to_byte_array(panic_data); assert!( actual_panic_message == expected_panic_message, - "Got unexpected panic message: {actual_panic_message}" + "Got unexpected panic message: {actual_panic_message}", ); } else { panic!("{selector} call was expected to fail, but succeeded"); diff --git a/packages/testing/src/deployment.cairo b/packages/testing/src/deployment.cairo index 46ef37eb0..eb8985c0e 100644 --- a/packages/testing/src/deployment.cairo +++ b/packages/testing/src/deployment.cairo @@ -12,7 +12,7 @@ pub fn declare_class(contract_name: ByteArray) -> ContractClass { DeclareResult::Success(contract_class) => contract_class, DeclareResult::AlreadyDeclared(contract_class) => contract_class, }, - Result::Err(panic_data) => panic!("{}", panic_data_to_byte_array(panic_data)) + Result::Err(panic_data) => panic!("{}", panic_data_to_byte_array(panic_data)), } } @@ -20,23 +20,23 @@ pub fn declare_class(contract_name: ByteArray) -> ContractClass { pub fn deploy(contract_class: ContractClass, calldata: Array) -> ContractAddress { match contract_class.deploy(@calldata) { Result::Ok((contract_address, _)) => contract_address, - Result::Err(panic_data) => panic!("{}", panic_data_to_byte_array(panic_data)) + Result::Err(panic_data) => panic!("{}", panic_data_to_byte_array(panic_data)), } } /// Deploys a contract at the given address and unwraps the result. pub fn deploy_at( - contract_class: ContractClass, target_address: ContractAddress, calldata: Array + contract_class: ContractClass, target_address: ContractAddress, calldata: Array, ) { match contract_class.deploy_at(@calldata, target_address) { Result::Ok(_) => (), - Result::Err(panic_data) => panic!("{}", panic_data_to_byte_array(panic_data)) + Result::Err(panic_data) => panic!("{}", panic_data_to_byte_array(panic_data)), }; } /// Deploys a contract using the class hash from another already-deployed contract. pub fn deploy_another_at( - existing: ContractAddress, target_address: ContractAddress, calldata: Array + existing: ContractAddress, target_address: ContractAddress, calldata: Array, ) { let class_hash = snforge_std::get_class_hash(existing); let contract_class = ContractClassTrait::new(class_hash); @@ -58,7 +58,7 @@ pub fn declare_and_deploy(contract_name: ByteArray, calldata: Array) -> /// already declared (the result of `snforge_std::declare` call is of type /// `DeclareResult::AlreadyDeclared`) pub fn declare_and_deploy_at( - contract_name: ByteArray, target_address: ContractAddress, calldata: Array + contract_name: ByteArray, target_address: ContractAddress, calldata: Array, ) { let contract_class = declare_class(contract_name); deploy_at(contract_class, target_address, calldata) diff --git a/packages/testing/src/events.cairo b/packages/testing/src/events.cairo index 944698d5c..260dec4cc 100644 --- a/packages/testing/src/events.cairo +++ b/packages/testing/src/events.cairo @@ -1,11 +1,11 @@ -use snforge_std::{EventSpyTrait, EventSpy, EventSpyAssertionsTrait}; +use snforge_std::{EventSpy, EventSpyAssertionsTrait, EventSpyTrait}; use starknet::ContractAddress; #[generate_trait] pub impl EventSpyExtImpl of EventSpyExt { /// Ensures that `from_address` has emitted only the `expected_event` and no additional events. fn assert_only_event, +Drop>( - ref self: EventSpy, from_address: ContractAddress, expected_event: T + ref self: EventSpy, from_address: ContractAddress, expected_event: T, ) { self.assert_emitted_single(from_address, expected_event); self.assert_no_events_left_from(from_address); @@ -16,7 +16,7 @@ pub impl EventSpyExtImpl of EventSpyExt { /// consumes the event in the first position of the offset. This means /// that events must be asserted in the order that they're emitted. fn assert_emitted_single, +Drop>( - ref self: EventSpy, from_address: ContractAddress, expected_event: T + ref self: EventSpy, from_address: ContractAddress, expected_event: T, ) { self.assert_emitted(@array![(from_address, expected_event)]); self._event_offset += 1; @@ -34,7 +34,7 @@ pub impl EventSpyExtImpl of EventSpyExt { let len = events.len(); assert!( len >= number_to_drop, - "Not enough events to drop. ${len} events, ${number_to_drop} to drop" + "Not enough events to drop. ${len} events, ${number_to_drop} to drop", ); self._event_offset += number_to_drop; } diff --git a/packages/testing/src/lib.cairo b/packages/testing/src/lib.cairo index c2b8b42f8..1b4c55c1a 100644 --- a/packages/testing/src/lib.cairo +++ b/packages/testing/src/lib.cairo @@ -5,11 +5,11 @@ pub mod events; pub mod signing; pub use common::{ - panic_data_to_byte_array, to_base_16_string, IntoBase16StringTrait, - assert_entrypoint_not_found_error + IntoBase16StringTrait, assert_entrypoint_not_found_error, panic_data_to_byte_array, + to_base_16_string, }; pub use deployment::{ - declare_class, declare_and_deploy, declare_and_deploy_at, deploy, deploy_at, deploy_another_at + declare_and_deploy, declare_and_deploy_at, declare_class, deploy, deploy_another_at, deploy_at, }; pub use events::EventSpyExt; diff --git a/packages/testing/src/signing.cairo b/packages/testing/src/signing.cairo index 18e56ab49..148637fee 100644 --- a/packages/testing/src/signing.cairo +++ b/packages/testing/src/signing.cairo @@ -1,7 +1,7 @@ use snforge_std::signature::KeyPair; -use snforge_std::signature::secp256k1_curve::{Secp256k1CurveSignerImpl, Secp256k1CurveKeyPairImpl}; -use snforge_std::signature::secp256r1_curve::{Secp256r1CurveSignerImpl, Secp256r1CurveKeyPairImpl}; -use snforge_std::signature::stark_curve::{StarkCurveSignerImpl, StarkCurveKeyPairImpl}; +use snforge_std::signature::secp256k1_curve::{Secp256k1CurveKeyPairImpl, Secp256k1CurveSignerImpl}; +use snforge_std::signature::secp256r1_curve::{Secp256r1CurveKeyPairImpl, Secp256r1CurveSignerImpl}; +use snforge_std::signature::stark_curve::{StarkCurveKeyPairImpl, StarkCurveSignerImpl}; use starknet::secp256k1::Secp256k1Point; use starknet::secp256r1::Secp256r1Point; diff --git a/packages/token/src/common/erc2981.cairo b/packages/token/src/common/erc2981.cairo index 208bb937e..3439dd62b 100644 --- a/packages/token/src/common/erc2981.cairo +++ b/packages/token/src/common/erc2981.cairo @@ -1,5 +1,5 @@ pub mod erc2981; pub mod interface; -pub use erc2981::{ERC2981Component, DefaultConfig}; +pub use erc2981::{DefaultConfig, ERC2981Component}; pub use interface::{IERC2981Dispatcher, IERC2981DispatcherTrait}; diff --git a/packages/token/src/common/erc2981/erc2981.cairo b/packages/token/src/common/erc2981/erc2981.cairo index f83357490..05650fb24 100644 --- a/packages/token/src/common/erc2981/erc2981.cairo +++ b/packages/token/src/common/erc2981/erc2981.cairo @@ -20,19 +20,19 @@ #[starknet::component] pub mod ERC2981Component { use core::num::traits::Zero; - use crate::common::erc2981::interface::IERC2981_ID; use crate::common::erc2981::interface; - use openzeppelin_access::accesscontrol::AccessControlComponent::InternalTrait as AccessControlInternalTrait; + use crate::common::erc2981::interface::IERC2981_ID; use openzeppelin_access::accesscontrol::AccessControlComponent; - use openzeppelin_access::ownable::OwnableComponent::InternalTrait as OwnableInternalTrait; + use openzeppelin_access::accesscontrol::AccessControlComponent::InternalTrait as AccessControlInternalTrait; use openzeppelin_access::ownable::OwnableComponent; + use openzeppelin_access::ownable::OwnableComponent::InternalTrait as OwnableInternalTrait; + use openzeppelin_introspection::src5::SRC5Component; use openzeppelin_introspection::src5::SRC5Component::InternalTrait as SRC5InternalTrait; use openzeppelin_introspection::src5::SRC5Component::SRC5Impl; - use openzeppelin_introspection::src5::SRC5Component; use starknet::ContractAddress; use starknet::storage::{ Map, StorageMapReadAccess, StorageMapWriteAccess, StoragePointerReadAccess, - StoragePointerWriteAccess + StoragePointerWriteAccess, }; /// Role for the admin responsible for managing royalty settings. @@ -98,7 +98,7 @@ pub mod ERC2981Component { /// - `t.0`: The receiver of the royalty payment. /// - `t.1`: The amount of royalty payment. fn royalty_info( - self: @ComponentState, token_id: u256, sale_price: u256 + self: @ComponentState, token_id: u256, sale_price: u256, ) -> (ContractAddress, u256) { let token_royalty_info = self.ERC2981_token_royalty_info.read(token_id); @@ -145,7 +145,7 @@ pub mod ERC2981Component { /// - `t.1`: The numerator of the royalty fraction. /// - `t.2`: The denominator of the royalty fraction. fn token_royalty( - self: @ComponentState, token_id: u256 + self: @ComponentState, token_id: u256, ) -> (ContractAddress, u128, u128) { self._token_royalty(token_id) } @@ -172,7 +172,9 @@ pub mod ERC2981Component { /// - `receiver` cannot be the zero address. /// - `fee_numerator` cannot be greater than the fee denominator. fn set_default_royalty( - ref self: ComponentState, receiver: ContractAddress, fee_numerator: u128 + ref self: ComponentState, + receiver: ContractAddress, + fee_numerator: u128, ) { get_dep_component!(@self, Ownable).assert_only_owner(); self._set_default_royalty(receiver, fee_numerator) @@ -200,7 +202,7 @@ pub mod ERC2981Component { ref self: ComponentState, token_id: u256, receiver: ContractAddress, - fee_numerator: u128 + fee_numerator: u128, ) { get_dep_component!(@self, Ownable).assert_only_owner(); self._set_token_royalty(token_id, receiver, fee_numerator) @@ -238,7 +240,9 @@ pub mod ERC2981Component { /// - `receiver` cannot be the zero address. /// - `fee_numerator` cannot be greater than the fee denominator. fn set_default_royalty( - ref self: ComponentState, receiver: ContractAddress, fee_numerator: u128 + ref self: ComponentState, + receiver: ContractAddress, + fee_numerator: u128, ) { get_dep_component!(@self, AccessControl).assert_only_role(ROYALTY_ADMIN_ROLE); self._set_default_royalty(receiver, fee_numerator) @@ -266,7 +270,7 @@ pub mod ERC2981Component { ref self: ComponentState, token_id: u256, receiver: ContractAddress, - fee_numerator: u128 + fee_numerator: u128, ) { get_dep_component!(@self, AccessControl).assert_only_role(ROYALTY_ADMIN_ROLE); self._set_token_royalty(token_id, receiver, fee_numerator) @@ -293,7 +297,7 @@ pub mod ERC2981Component { +HasComponent, impl Immutable: ImmutableConfig, impl SRC5: SRC5Component::HasComponent, - +Drop + +Drop, > of InternalTrait { /// Initializes the contract by setting the default royalty. /// @@ -307,7 +311,7 @@ pub mod ERC2981Component { fn initializer( ref self: ComponentState, default_receiver: ContractAddress, - default_royalty_fraction: u128 + default_royalty_fraction: u128, ) { Immutable::validate(); @@ -325,7 +329,7 @@ pub mod ERC2981Component { /// - `t.1`: The numerator of the royalty fraction. /// - `t.2`: The denominator of the royalty fraction. fn _default_royalty( - self: @ComponentState + self: @ComponentState, ) -> (ContractAddress, u128, u128) { let royalty_info = self.ERC2981_default_royalty_info.read(); (royalty_info.receiver, royalty_info.royalty_fraction, Immutable::FEE_DENOMINATOR) @@ -338,7 +342,9 @@ pub mod ERC2981Component { /// - `receiver` cannot be the zero address. /// - `fee_numerator` cannot be greater than the fee denominator. fn _set_default_royalty( - ref self: ComponentState, receiver: ContractAddress, fee_numerator: u128 + ref self: ComponentState, + receiver: ContractAddress, + fee_numerator: u128, ) { let fee_denominator = Immutable::FEE_DENOMINATOR; assert(fee_numerator <= fee_denominator, Errors::INVALID_ROYALTY); @@ -364,7 +370,7 @@ pub mod ERC2981Component { /// - `t.1`: The numerator of the royalty fraction. /// - `t.2`: The denominator of the royalty fraction. fn _token_royalty( - self: @ComponentState, token_id: u256 + self: @ComponentState, token_id: u256, ) -> (ContractAddress, u128, u128) { let token_royalty_info = self.ERC2981_token_royalty_info.read(token_id); @@ -389,7 +395,7 @@ pub mod ERC2981Component { ref self: ComponentState, token_id: u256, receiver: ContractAddress, - fee_numerator: u128 + fee_numerator: u128, ) { let fee_denominator = Immutable::FEE_DENOMINATOR; assert(fee_numerator <= fee_denominator, Errors::INVALID_ROYALTY); @@ -397,14 +403,14 @@ pub mod ERC2981Component { self .ERC2981_token_royalty_info - .write(token_id, RoyaltyInfo { receiver, royalty_fraction: fee_numerator },) + .write(token_id, RoyaltyInfo { receiver, royalty_fraction: fee_numerator }) } /// Resets royalty information for the token id back to unset. fn _reset_token_royalty(ref self: ComponentState, token_id: u256) { self .ERC2981_token_royalty_info - .write(token_id, RoyaltyInfo { receiver: Zero::zero(), royalty_fraction: 0 },) + .write(token_id, RoyaltyInfo { receiver: Zero::zero(), royalty_fraction: 0 }) } } } @@ -424,8 +430,8 @@ pub impl DefaultConfig of ERC2981Component::ImmutableConfig { mod tests { use openzeppelin_test_common::mocks::erc2981::ERC2981Mock; use starknet::contract_address_const; - use super::ERC2981Component::InternalImpl; use super::ERC2981Component; + use super::ERC2981Component::InternalImpl; type ComponentState = ERC2981Component::ComponentState; diff --git a/packages/token/src/common/erc2981/interface.cairo b/packages/token/src/common/erc2981/interface.cairo index 8aadd473b..ec1e5a4f3 100644 --- a/packages/token/src/common/erc2981/interface.cairo +++ b/packages/token/src/common/erc2981/interface.cairo @@ -49,7 +49,7 @@ pub trait IERC2981Admin { /// Sets the royalty information for a specific token id that takes precedence over the global /// default. fn set_token_royalty( - ref self: TState, token_id: u256, receiver: ContractAddress, fee_numerator: u128 + ref self: TState, token_id: u256, receiver: ContractAddress, fee_numerator: u128, ); /// Resets royalty information for the token id back to unset. @@ -70,7 +70,7 @@ pub trait IERC2981ABI { fn set_default_royalty(ref self: TState, receiver: ContractAddress, fee_numerator: u128); fn delete_default_royalty(ref self: TState); fn set_token_royalty( - ref self: TState, token_id: u256, receiver: ContractAddress, fee_numerator: u128 + ref self: TState, token_id: u256, receiver: ContractAddress, fee_numerator: u128, ); fn reset_token_royalty(ref self: TState, token_id: u256); } diff --git a/packages/token/src/erc1155/erc1155.cairo b/packages/token/src/erc1155/erc1155.cairo index 139e4ad20..4e9978760 100644 --- a/packages/token/src/erc1155/erc1155.cairo +++ b/packages/token/src/erc1155/erc1155.cairo @@ -8,13 +8,13 @@ #[starknet::component] pub mod ERC1155Component { use core::num::traits::Zero; - use crate::erc1155::interface::{IERC1155ReceiverDispatcher, IERC1155ReceiverDispatcherTrait}; use crate::erc1155::interface; + use crate::erc1155::interface::{IERC1155ReceiverDispatcher, IERC1155ReceiverDispatcherTrait}; use openzeppelin_account::interface::ISRC6_ID; use openzeppelin_introspection::interface::{ISRC5Dispatcher, ISRC5DispatcherTrait}; + use openzeppelin_introspection::src5::SRC5Component; use openzeppelin_introspection::src5::SRC5Component::InternalTrait as SRC5InternalTrait; use openzeppelin_introspection::src5::SRC5Component::SRC5Impl; - use openzeppelin_introspection::src5::SRC5Component; use starknet::storage::{Map, StorageMapReadAccess, StorageMapWriteAccess}; use starknet::storage::{StoragePointerReadAccess, StoragePointerWriteAccess}; use starknet::{ContractAddress, get_caller_address}; @@ -32,7 +32,7 @@ pub mod ERC1155Component { TransferSingle: TransferSingle, TransferBatch: TransferBatch, ApprovalForAll: ApprovalForAll, - URI: URI + URI: URI, } /// Emitted when `value` token is transferred from `from` to `to` for `id`. @@ -45,7 +45,7 @@ pub mod ERC1155Component { #[key] pub to: ContractAddress, pub id: u256, - pub value: u256 + pub value: u256, } /// Emitted when `values` are transferred from `from` to `to` for `ids`. @@ -69,7 +69,7 @@ pub mod ERC1155Component { pub owner: ContractAddress, #[key] pub operator: ContractAddress, - pub approved: bool + pub approved: bool, } /// Emitted when the URI for token type `id` changes to `value`, if it is a non-programmatic @@ -82,7 +82,7 @@ pub mod ERC1155Component { pub struct URI { pub value: ByteArray, #[key] - pub id: u256 + pub id: u256, } pub mod Errors { @@ -105,7 +105,7 @@ pub mod ERC1155Component { from: ContractAddress, to: ContractAddress, token_ids: Span, - values: Span + values: Span, ) {} fn after_update( @@ -113,7 +113,7 @@ pub mod ERC1155Component { from: ContractAddress, to: ContractAddress, token_ids: Span, - values: Span + values: Span, ) {} } @@ -127,11 +127,11 @@ pub mod ERC1155Component { +HasComponent, +SRC5Component::HasComponent, +ERC1155HooksTrait, - +Drop + +Drop, > of interface::IERC1155> { /// Returns the amount of `token_id` tokens owned by `account`. fn balance_of( - self: @ComponentState, account: ContractAddress, token_id: u256 + self: @ComponentState, account: ContractAddress, token_id: u256, ) -> u256 { self.ERC1155_balances.read((token_id, account)) } @@ -144,7 +144,7 @@ pub mod ERC1155Component { fn balance_of_batch( self: @ComponentState, accounts: Span, - token_ids: Span + token_ids: Span, ) -> Span { assert(accounts.len() == token_ids.len(), Errors::INVALID_ARRAY_LENGTH); @@ -187,7 +187,7 @@ pub mod ERC1155Component { to: ContractAddress, token_id: u256, value: u256, - data: Span + data: Span, ) { let token_ids = array![token_id].span(); let values = array![value].span(); @@ -219,7 +219,7 @@ pub mod ERC1155Component { to: starknet::ContractAddress, token_ids: Span, values: Span, - data: Span + data: Span, ) { assert(from.is_non_zero(), Errors::INVALID_SENDER); assert(to.is_non_zero(), Errors::INVALID_RECEIVER); @@ -241,7 +241,7 @@ pub mod ERC1155Component { /// /// Emits an `ApprovalForAll` event. fn set_approval_for_all( - ref self: ComponentState, operator: ContractAddress, approved: bool + ref self: ComponentState, operator: ContractAddress, approved: bool, ) { let owner = get_caller_address(); assert(owner != operator, Errors::SELF_APPROVAL); @@ -252,7 +252,9 @@ pub mod ERC1155Component { /// Queries if `operator` is an authorized operator for `owner`. fn is_approved_for_all( - self: @ComponentState, owner: ContractAddress, operator: ContractAddress + self: @ComponentState, + owner: ContractAddress, + operator: ContractAddress, ) -> bool { self.ERC1155_operator_approvals.read((owner, operator)) } @@ -264,7 +266,7 @@ pub mod ERC1155Component { +HasComponent, +SRC5Component::HasComponent, +ERC1155HooksTrait, - +Drop + +Drop, > of interface::IERC1155MetadataURI> { /// This implementation returns the same URI for *all* token types. It relies /// on the token type ID substitution mechanism defined in the EIP: @@ -284,10 +286,10 @@ pub mod ERC1155Component { +HasComponent, +SRC5Component::HasComponent, +ERC1155HooksTrait, - +Drop + +Drop, > of interface::IERC1155Camel> { fn balanceOf( - self: @ComponentState, account: ContractAddress, tokenId: u256 + self: @ComponentState, account: ContractAddress, tokenId: u256, ) -> u256 { ERC1155::balance_of(self, account, tokenId) } @@ -295,7 +297,7 @@ pub mod ERC1155Component { fn balanceOfBatch( self: @ComponentState, accounts: Span, - tokenIds: Span + tokenIds: Span, ) -> Span { ERC1155::balance_of_batch(self, accounts, tokenIds) } @@ -306,7 +308,7 @@ pub mod ERC1155Component { to: ContractAddress, tokenId: u256, value: u256, - data: Span + data: Span, ) { ERC1155::safe_transfer_from(ref self, from, to, tokenId, value, data) } @@ -317,19 +319,21 @@ pub mod ERC1155Component { to: ContractAddress, tokenIds: Span, values: Span, - data: Span + data: Span, ) { ERC1155::safe_batch_transfer_from(ref self, from, to, tokenIds, values, data) } fn setApprovalForAll( - ref self: ComponentState, operator: ContractAddress, approved: bool + ref self: ComponentState, operator: ContractAddress, approved: bool, ) { ERC1155::set_approval_for_all(ref self, operator, approved) } fn isApprovedForAll( - self: @ComponentState, owner: ContractAddress, operator: ContractAddress + self: @ComponentState, + owner: ContractAddress, + operator: ContractAddress, ) -> bool { ERC1155::is_approved_for_all(self, owner, operator) } @@ -341,11 +345,11 @@ pub mod ERC1155Component { +HasComponent, impl SRC5: SRC5Component::HasComponent, +ERC1155HooksTrait, - +Drop + +Drop, > of interface::ERC1155ABI> { // IERC1155 fn balance_of( - self: @ComponentState, account: ContractAddress, token_id: u256 + self: @ComponentState, account: ContractAddress, token_id: u256, ) -> u256 { ERC1155::balance_of(self, account, token_id) } @@ -353,7 +357,7 @@ pub mod ERC1155Component { fn balance_of_batch( self: @ComponentState, accounts: Span, - token_ids: Span + token_ids: Span, ) -> Span { ERC1155::balance_of_batch(self, accounts, token_ids) } @@ -364,7 +368,7 @@ pub mod ERC1155Component { to: ContractAddress, token_id: u256, value: u256, - data: Span + data: Span, ) { ERC1155::safe_transfer_from(ref self, from, to, token_id, value, data); } @@ -375,26 +379,28 @@ pub mod ERC1155Component { to: ContractAddress, token_ids: Span, values: Span, - data: Span + data: Span, ) { ERC1155::safe_batch_transfer_from(ref self, from, to, token_ids, values, data); } fn is_approved_for_all( - self: @ComponentState, owner: ContractAddress, operator: ContractAddress + self: @ComponentState, + owner: ContractAddress, + operator: ContractAddress, ) -> bool { ERC1155::is_approved_for_all(self, owner, operator) } fn set_approval_for_all( - ref self: ComponentState, operator: ContractAddress, approved: bool + ref self: ComponentState, operator: ContractAddress, approved: bool, ) { ERC1155::set_approval_for_all(ref self, operator, approved); } // ISRC5 fn supports_interface( - self: @ComponentState, interface_id: felt252 + self: @ComponentState, interface_id: felt252, ) -> bool { let src5 = get_dep_component!(self, SRC5); src5.supports_interface(interface_id) @@ -407,7 +413,7 @@ pub mod ERC1155Component { // IERC1155Camel fn balanceOf( - self: @ComponentState, account: ContractAddress, tokenId: u256 + self: @ComponentState, account: ContractAddress, tokenId: u256, ) -> u256 { ERC1155Camel::balanceOf(self, account, tokenId) } @@ -415,7 +421,7 @@ pub mod ERC1155Component { fn balanceOfBatch( self: @ComponentState, accounts: Span, - tokenIds: Span + tokenIds: Span, ) -> Span { ERC1155Camel::balanceOfBatch(self, accounts, tokenIds) } @@ -426,7 +432,7 @@ pub mod ERC1155Component { to: ContractAddress, tokenId: u256, value: u256, - data: Span + data: Span, ) { ERC1155Camel::safeTransferFrom(ref self, from, to, tokenId, value, data); } @@ -437,19 +443,21 @@ pub mod ERC1155Component { to: ContractAddress, tokenIds: Span, values: Span, - data: Span + data: Span, ) { ERC1155Camel::safeBatchTransferFrom(ref self, from, to, tokenIds, values, data); } fn isApprovedForAll( - self: @ComponentState, owner: ContractAddress, operator: ContractAddress + self: @ComponentState, + owner: ContractAddress, + operator: ContractAddress, ) -> bool { ERC1155Camel::isApprovedForAll(self, owner, operator) } fn setApprovalForAll( - ref self: ComponentState, operator: ContractAddress, approved: bool + ref self: ComponentState, operator: ContractAddress, approved: bool, ) { ERC1155Camel::setApprovalForAll(ref self, operator, approved); } @@ -465,7 +473,7 @@ pub mod ERC1155Component { +HasComponent, impl SRC5: SRC5Component::HasComponent, impl Hooks: ERC1155HooksTrait, - +Drop + +Drop, > of InternalTrait { /// Initializes the contract by setting the `base_uri` for all tokens, /// and registering the supported interfaces. @@ -493,7 +501,7 @@ pub mod ERC1155Component { to: ContractAddress, token_id: u256, value: u256, - data: Span + data: Span, ) { assert(to.is_non_zero(), Errors::INVALID_RECEIVER); @@ -518,7 +526,7 @@ pub mod ERC1155Component { to: ContractAddress, token_ids: Span, values: Span, - data: Span + data: Span, ) { assert(to.is_non_zero(), Errors::INVALID_RECEIVER); self.update_with_acceptance_check(Zero::zero(), to, token_ids, values, data); @@ -536,7 +544,7 @@ pub mod ERC1155Component { ref self: ComponentState, from: ContractAddress, token_id: u256, - value: u256 + value: u256, ) { assert(from.is_non_zero(), Errors::INVALID_SENDER); @@ -558,7 +566,7 @@ pub mod ERC1155Component { ref self: ComponentState, from: ContractAddress, token_ids: Span, - values: Span + values: Span, ) { assert(from.is_non_zero(), Errors::INVALID_SENDER); self.update(from, Zero::zero(), token_ids, values); @@ -581,7 +589,7 @@ pub mod ERC1155Component { to: ContractAddress, token_ids: Span, values: Span, - data: Span + data: Span, ) { self.update(from, to, token_ids, values); let accepted = if token_ids.len() == 1 { @@ -612,7 +620,7 @@ pub mod ERC1155Component { from: ContractAddress, to: ContractAddress, token_ids: Span, - values: Span + values: Span, ) { Hooks::before_update(ref self, from, to, token_ids, values); @@ -641,8 +649,8 @@ pub mod ERC1155Component { self .emit( TransferSingle { - operator, from, to, id: *token_ids.at(0), value: *values.at(0) - } + operator, from, to, id: *token_ids.at(0), value: *values.at(0), + }, ); } else { self.emit(TransferBatch { operator, from, to, ids: token_ids, values }); @@ -674,14 +682,18 @@ pub mod ERC1155Component { /// Checks if `to` accepts the token by implementing `IERC1155Receiver` /// or if it's an account contract (supporting ISRC6). fn _check_on_ERC1155_received( - from: ContractAddress, to: ContractAddress, token_id: u256, value: u256, data: Span + from: ContractAddress, + to: ContractAddress, + token_id: u256, + value: u256, + data: Span, ) -> bool { let src5_dispatcher = ISRC5Dispatcher { contract_address: to }; if src5_dispatcher.supports_interface(interface::IERC1155_RECEIVER_ID) { IERC1155ReceiverDispatcher { contract_address: to } .on_erc1155_received( - get_caller_address(), from, token_id, value, data + get_caller_address(), from, token_id, value, data, ) == interface::IERC1155_RECEIVER_ID } else { src5_dispatcher.supports_interface(ISRC6_ID) @@ -695,14 +707,14 @@ pub mod ERC1155Component { to: ContractAddress, token_ids: Span, values: Span, - data: Span + data: Span, ) -> bool { let src5_dispatcher = ISRC5Dispatcher { contract_address: to }; if src5_dispatcher.supports_interface(interface::IERC1155_RECEIVER_ID) { IERC1155ReceiverDispatcher { contract_address: to } .on_erc1155_batch_received( - get_caller_address(), from, token_ids, values, data + get_caller_address(), from, token_ids, values, data, ) == interface::IERC1155_RECEIVER_ID } else { src5_dispatcher.supports_interface(ISRC6_ID) @@ -712,5 +724,5 @@ pub mod ERC1155Component { /// An empty implementation of the ERC1155 hooks to be used in basic ERC1155 preset contracts. pub impl ERC1155HooksEmptyImpl< - TContractState + TContractState, > of ERC1155Component::ERC1155HooksTrait {} diff --git a/packages/token/src/erc1155/erc1155_receiver.cairo b/packages/token/src/erc1155/erc1155_receiver.cairo index 175281632..9ea7205dc 100644 --- a/packages/token/src/erc1155/erc1155_receiver.cairo +++ b/packages/token/src/erc1155/erc1155_receiver.cairo @@ -9,10 +9,10 @@ #[starknet::component] pub mod ERC1155ReceiverComponent { use crate::erc1155::interface::IERC1155_RECEIVER_ID; - use crate::erc1155::interface::{IERC1155Receiver, IERC1155ReceiverCamel, ERC1155ReceiverABI}; + use crate::erc1155::interface::{ERC1155ReceiverABI, IERC1155Receiver, IERC1155ReceiverCamel}; + use openzeppelin_introspection::src5::SRC5Component; use openzeppelin_introspection::src5::SRC5Component::InternalTrait as SRC5InternalTrait; use openzeppelin_introspection::src5::SRC5Component::SRC5Impl; - use openzeppelin_introspection::src5::SRC5Component; use starknet::ContractAddress; #[storage] @@ -23,7 +23,7 @@ pub mod ERC1155ReceiverComponent { TContractState, +HasComponent, +SRC5Component::HasComponent, - +Drop + +Drop, > of IERC1155Receiver> { /// Called whenever the implementing contract receives `value` through /// a safe transfer. This function must return `IERC1155_RECEIVER_ID` @@ -34,7 +34,7 @@ pub mod ERC1155ReceiverComponent { from: ContractAddress, token_id: u256, value: u256, - data: Span + data: Span, ) -> felt252 { IERC1155_RECEIVER_ID } @@ -48,7 +48,7 @@ pub mod ERC1155ReceiverComponent { from: ContractAddress, token_ids: Span, values: Span, - data: Span + data: Span, ) -> felt252 { IERC1155_RECEIVER_ID } @@ -60,7 +60,7 @@ pub mod ERC1155ReceiverComponent { TContractState, +HasComponent, +SRC5Component::HasComponent, - +Drop + +Drop, > of IERC1155ReceiverCamel> { fn onERC1155Received( self: @ComponentState, @@ -68,7 +68,7 @@ pub mod ERC1155ReceiverComponent { from: ContractAddress, tokenId: u256, value: u256, - data: Span + data: Span, ) -> felt252 { IERC1155_RECEIVER_ID } @@ -79,7 +79,7 @@ pub mod ERC1155ReceiverComponent { from: ContractAddress, tokenIds: Span, values: Span, - data: Span + data: Span, ) -> felt252 { IERC1155_RECEIVER_ID } @@ -90,7 +90,7 @@ pub mod ERC1155ReceiverComponent { TContractState, +HasComponent, impl SRC5: SRC5Component::HasComponent, - +Drop + +Drop, > of InternalTrait { /// Initializes the contract by registering the IERC1155Receiver interface ID. /// This should be used inside the contract's constructor. @@ -105,7 +105,7 @@ pub mod ERC1155ReceiverComponent { TContractState, +HasComponent, impl SRC5: SRC5Component::HasComponent, - +Drop + +Drop, > of ERC1155ReceiverABI> { // IERC1155 fn on_erc1155_received( @@ -114,7 +114,7 @@ pub mod ERC1155ReceiverComponent { from: ContractAddress, token_id: u256, value: u256, - data: Span + data: Span, ) -> felt252 { ERC1155Receiver::on_erc1155_received(self, operator, from, token_id, value, data) } @@ -125,10 +125,10 @@ pub mod ERC1155ReceiverComponent { from: ContractAddress, token_ids: Span, values: Span, - data: Span + data: Span, ) -> felt252 { ERC1155Receiver::on_erc1155_batch_received( - self, operator, from, token_ids, values, data + self, operator, from, token_ids, values, data, ) } @@ -139,7 +139,7 @@ pub mod ERC1155ReceiverComponent { from: ContractAddress, tokenId: u256, value: u256, - data: Span + data: Span, ) -> felt252 { ERC1155ReceiverCamel::onERC1155Received(self, operator, from, tokenId, value, data) } @@ -150,16 +150,16 @@ pub mod ERC1155ReceiverComponent { from: ContractAddress, tokenIds: Span, values: Span, - data: Span + data: Span, ) -> felt252 { ERC1155ReceiverCamel::onERC1155BatchReceived( - self, operator, from, tokenIds, values, data + self, operator, from, tokenIds, values, data, ) } // ISRC5 fn supports_interface( - self: @ComponentState, interface_id: felt252 + self: @ComponentState, interface_id: felt252, ) -> bool { let src5 = get_dep_component!(self, SRC5); src5.supports_interface(interface_id) diff --git a/packages/token/src/erc1155/interface.cairo b/packages/token/src/erc1155/interface.cairo index 8876e4556..ad8c1c72e 100644 --- a/packages/token/src/erc1155/interface.cairo +++ b/packages/token/src/erc1155/interface.cairo @@ -13,7 +13,7 @@ pub const IERC1155_RECEIVER_ID: felt252 = pub trait IERC1155 { fn balance_of(self: @TState, account: ContractAddress, token_id: u256) -> u256; fn balance_of_batch( - self: @TState, accounts: Span, token_ids: Span + self: @TState, accounts: Span, token_ids: Span, ) -> Span; fn safe_transfer_from( ref self: TState, @@ -21,7 +21,7 @@ pub trait IERC1155 { to: ContractAddress, token_id: u256, value: u256, - data: Span + data: Span, ); fn safe_batch_transfer_from( ref self: TState, @@ -29,10 +29,10 @@ pub trait IERC1155 { to: ContractAddress, token_ids: Span, values: Span, - data: Span + data: Span, ); fn is_approved_for_all( - self: @TState, owner: ContractAddress, operator: ContractAddress + self: @TState, owner: ContractAddress, operator: ContractAddress, ) -> bool; fn set_approval_for_all(ref self: TState, operator: ContractAddress, approved: bool); } @@ -46,7 +46,7 @@ pub trait IERC1155MetadataURI { pub trait IERC1155Camel { fn balanceOf(self: @TState, account: ContractAddress, tokenId: u256) -> u256; fn balanceOfBatch( - self: @TState, accounts: Span, tokenIds: Span + self: @TState, accounts: Span, tokenIds: Span, ) -> Span; fn safeTransferFrom( ref self: TState, @@ -54,7 +54,7 @@ pub trait IERC1155Camel { to: ContractAddress, tokenId: u256, value: u256, - data: Span + data: Span, ); fn safeBatchTransferFrom( ref self: TState, @@ -62,7 +62,7 @@ pub trait IERC1155Camel { to: ContractAddress, tokenIds: Span, values: Span, - data: Span + data: Span, ); fn isApprovedForAll(self: @TState, owner: ContractAddress, operator: ContractAddress) -> bool; fn setApprovalForAll(ref self: TState, operator: ContractAddress, approved: bool); @@ -77,7 +77,7 @@ pub trait ERC1155ABI { // IERC1155 fn balance_of(self: @TState, account: ContractAddress, token_id: u256) -> u256; fn balance_of_batch( - self: @TState, accounts: Span, token_ids: Span + self: @TState, accounts: Span, token_ids: Span, ) -> Span; fn safe_transfer_from( ref self: TState, @@ -85,7 +85,7 @@ pub trait ERC1155ABI { to: ContractAddress, token_id: u256, value: u256, - data: Span + data: Span, ); fn safe_batch_transfer_from( ref self: TState, @@ -93,10 +93,10 @@ pub trait ERC1155ABI { to: ContractAddress, token_ids: Span, values: Span, - data: Span + data: Span, ); fn is_approved_for_all( - self: @TState, owner: ContractAddress, operator: ContractAddress + self: @TState, owner: ContractAddress, operator: ContractAddress, ) -> bool; fn set_approval_for_all(ref self: TState, operator: ContractAddress, approved: bool); @@ -109,7 +109,7 @@ pub trait ERC1155ABI { // IERC1155Camel fn balanceOf(self: @TState, account: ContractAddress, tokenId: u256) -> u256; fn balanceOfBatch( - self: @TState, accounts: Span, tokenIds: Span + self: @TState, accounts: Span, tokenIds: Span, ) -> Span; fn safeTransferFrom( ref self: TState, @@ -117,7 +117,7 @@ pub trait ERC1155ABI { to: ContractAddress, tokenId: u256, value: u256, - data: Span + data: Span, ); fn safeBatchTransferFrom( ref self: TState, @@ -125,7 +125,7 @@ pub trait ERC1155ABI { to: ContractAddress, tokenIds: Span, values: Span, - data: Span + data: Span, ); fn isApprovedForAll(self: @TState, owner: ContractAddress, operator: ContractAddress) -> bool; fn setApprovalForAll(ref self: TState, operator: ContractAddress, approved: bool); @@ -143,7 +143,7 @@ pub trait IERC1155Receiver { from: ContractAddress, token_id: u256, value: u256, - data: Span + data: Span, ) -> felt252; fn on_erc1155_batch_received( self: @TState, @@ -151,7 +151,7 @@ pub trait IERC1155Receiver { from: ContractAddress, token_ids: Span, values: Span, - data: Span + data: Span, ) -> felt252; } @@ -163,7 +163,7 @@ pub trait IERC1155ReceiverCamel { from: ContractAddress, tokenId: u256, value: u256, - data: Span + data: Span, ) -> felt252; fn onERC1155BatchReceived( self: @TState, @@ -171,7 +171,7 @@ pub trait IERC1155ReceiverCamel { from: ContractAddress, tokenIds: Span, values: Span, - data: Span + data: Span, ) -> felt252; } @@ -184,7 +184,7 @@ pub trait ERC1155ReceiverABI { from: ContractAddress, token_id: u256, value: u256, - data: Span + data: Span, ) -> felt252; fn on_erc1155_batch_received( self: @TState, @@ -192,7 +192,7 @@ pub trait ERC1155ReceiverABI { from: ContractAddress, token_ids: Span, values: Span, - data: Span + data: Span, ) -> felt252; // IERC1155ReceiverCamel @@ -202,7 +202,7 @@ pub trait ERC1155ReceiverABI { from: ContractAddress, tokenId: u256, value: u256, - data: Span + data: Span, ) -> felt252; fn onERC1155BatchReceived( self: @TState, @@ -210,7 +210,7 @@ pub trait ERC1155ReceiverABI { from: ContractAddress, tokenIds: Span, values: Span, - data: Span + data: Span, ) -> felt252; // ISRC5 diff --git a/packages/token/src/erc20/erc20.cairo b/packages/token/src/erc20/erc20.cairo index ca13c50bb..b74e4d48c 100644 --- a/packages/token/src/erc20/erc20.cairo +++ b/packages/token/src/erc20/erc20.cairo @@ -18,10 +18,10 @@ pub mod ERC20Component { use openzeppelin_account::interface::{ISRC6Dispatcher, ISRC6DispatcherTrait}; use openzeppelin_utils::cryptography::interface::{INonces, ISNIP12Metadata}; use openzeppelin_utils::cryptography::snip12::{ - StructHash, OffchainMessageHash, SNIP12Metadata, StarknetDomain + OffchainMessageHash, SNIP12Metadata, StarknetDomain, StructHash, }; - use openzeppelin_utils::nonces::NoncesComponent::InternalTrait as NoncesInternalTrait; use openzeppelin_utils::nonces::NoncesComponent; + use openzeppelin_utils::nonces::NoncesComponent::InternalTrait as NoncesInternalTrait; use starknet::ContractAddress; use starknet::storage::{Map, StorageMapReadAccess, StorageMapWriteAccess}; use starknet::storage::{StoragePointerReadAccess, StoragePointerWriteAccess}; @@ -49,7 +49,7 @@ pub mod ERC20Component { pub from: ContractAddress, #[key] pub to: ContractAddress, - pub value: u256 + pub value: u256, } /// Emitted when the allowance of a `spender` for an `owner` is set by a call @@ -60,7 +60,7 @@ pub mod ERC20Component { pub owner: ContractAddress, #[key] pub spender: ContractAddress, - pub value: u256 + pub value: u256, } pub mod Errors { @@ -85,14 +85,14 @@ pub mod ERC20Component { ref self: ComponentState, from: ContractAddress, recipient: ContractAddress, - amount: u256 + amount: u256, ) {} fn after_update( ref self: ComponentState, from: ContractAddress, recipient: ContractAddress, - amount: u256 + amount: u256, ) {} } @@ -102,7 +102,7 @@ pub mod ERC20Component { #[embeddable_as(ERC20Impl)] impl ERC20< - TContractState, +HasComponent, +ERC20HooksTrait + TContractState, +HasComponent, +ERC20HooksTrait, > of interface::IERC20> { /// Returns the value of tokens in existence. fn total_supply(self: @ComponentState) -> u256 { @@ -119,7 +119,7 @@ pub mod ERC20Component { /// This is zero by default. /// This value changes when `approve` or `transfer_from` are called. fn allowance( - self: @ComponentState, owner: ContractAddress, spender: ContractAddress + self: @ComponentState, owner: ContractAddress, spender: ContractAddress, ) -> u256 { self.ERC20_allowances.read((owner, spender)) } @@ -133,7 +133,7 @@ pub mod ERC20Component { /// /// Emits a `Transfer` event. fn transfer( - ref self: ComponentState, recipient: ContractAddress, amount: u256 + ref self: ComponentState, recipient: ContractAddress, amount: u256, ) -> bool { let sender = starknet::get_caller_address(); self._transfer(sender, recipient, amount); @@ -155,7 +155,7 @@ pub mod ERC20Component { ref self: ComponentState, sender: ContractAddress, recipient: ContractAddress, - amount: u256 + amount: u256, ) -> bool { let caller = starknet::get_caller_address(); self._spend_allowance(sender, caller, amount); @@ -171,7 +171,7 @@ pub mod ERC20Component { /// /// Emits an `Approval` event. fn approve( - ref self: ComponentState, spender: ContractAddress, amount: u256 + ref self: ComponentState, spender: ContractAddress, amount: u256, ) -> bool { let caller = starknet::get_caller_address(); self._approve(caller, spender, amount); @@ -181,7 +181,7 @@ pub mod ERC20Component { #[embeddable_as(ERC20MetadataImpl)] impl ERC20Metadata< - TContractState, +HasComponent, +ERC20HooksTrait + TContractState, +HasComponent, +ERC20HooksTrait, > of interface::IERC20Metadata> { /// Returns the name of the token. fn name(self: @ComponentState) -> ByteArray { @@ -202,7 +202,7 @@ pub mod ERC20Component { /// Adds camelCase support for `IERC20`. #[embeddable_as(ERC20CamelOnlyImpl)] impl ERC20CamelOnly< - TContractState, +HasComponent, +ERC20HooksTrait + TContractState, +HasComponent, +ERC20HooksTrait, > of interface::IERC20CamelOnly> { fn totalSupply(self: @ComponentState) -> u256 { ERC20::total_supply(self) @@ -216,7 +216,7 @@ pub mod ERC20Component { ref self: ComponentState, sender: ContractAddress, recipient: ContractAddress, - amount: u256 + amount: u256, ) -> bool { ERC20::transfer_from(ref self, sender, recipient, amount) } @@ -224,7 +224,7 @@ pub mod ERC20Component { #[embeddable_as(ERC20MixinImpl)] impl ERC20Mixin< - TContractState, +HasComponent, +ERC20HooksTrait + TContractState, +HasComponent, +ERC20HooksTrait, > of interface::IERC20Mixin> { // IERC20 fn total_supply(self: @ComponentState) -> u256 { @@ -236,13 +236,13 @@ pub mod ERC20Component { } fn allowance( - self: @ComponentState, owner: ContractAddress, spender: ContractAddress + self: @ComponentState, owner: ContractAddress, spender: ContractAddress, ) -> u256 { ERC20::allowance(self, owner, spender) } fn transfer( - ref self: ComponentState, recipient: ContractAddress, amount: u256 + ref self: ComponentState, recipient: ContractAddress, amount: u256, ) -> bool { ERC20::transfer(ref self, recipient, amount) } @@ -251,13 +251,13 @@ pub mod ERC20Component { ref self: ComponentState, sender: ContractAddress, recipient: ContractAddress, - amount: u256 + amount: u256, ) -> bool { ERC20::transfer_from(ref self, sender, recipient, amount) } fn approve( - ref self: ComponentState, spender: ContractAddress, amount: u256 + ref self: ComponentState, spender: ContractAddress, amount: u256, ) -> bool { ERC20::approve(ref self, spender, amount) } @@ -288,7 +288,7 @@ pub mod ERC20Component { ref self: ComponentState, sender: ContractAddress, recipient: ContractAddress, - amount: u256 + amount: u256, ) -> bool { ERC20CamelOnly::transferFrom(ref self, sender, recipient, amount) } @@ -319,7 +319,7 @@ pub mod ERC20Component { +ERC20HooksTrait, impl Nonces: NoncesComponent::HasComponent, impl Metadata: SNIP12Metadata, - +Drop + +Drop, > of interface::IERC20Permit> { /// Sets `amount` as the allowance of `spender` over `owner`'s tokens after validating the /// signature. @@ -340,7 +340,7 @@ pub mod ERC20Component { spender: ContractAddress, amount: u256, deadline: u64, - signature: Span + signature: Span, ) { // 1. Ensure the deadline is not missed assert(starknet::get_block_timestamp() <= deadline, Errors::EXPIRED_PERMIT_SIGNATURE); @@ -351,7 +351,7 @@ pub mod ERC20Component { // 3. Make a call to the account to validate permit signature let permit = Permit { - token: starknet::get_contract_address(), spender, amount, nonce, deadline + token: starknet::get_contract_address(), spender, amount, nonce, deadline, }; let permit_hash = permit.get_message_hash(owner); let is_valid_sig_felt = ISRC6Dispatcher { contract_address: owner } @@ -379,7 +379,7 @@ pub mod ERC20Component { name: Metadata::name(), version: Metadata::version(), chain_id: starknet::get_tx_info().unbox().chain_id, - revision: 1 + revision: 1, }; domain.hash_struct() } @@ -387,7 +387,7 @@ pub mod ERC20Component { #[embeddable_as(SNIP12MetadataExternalImpl)] impl SNIP12MetadataExternal< - TContractState, +HasComponent, impl Metadata: SNIP12Metadata + TContractState, +HasComponent, impl Metadata: SNIP12Metadata, > of ISNIP12Metadata> { /// Returns the domain name and version used to generate the message hash for for permit /// signature. @@ -407,13 +407,13 @@ pub mod ERC20Component { #[generate_trait] pub impl InternalImpl< - TContractState, +HasComponent, impl Hooks: ERC20HooksTrait + TContractState, +HasComponent, impl Hooks: ERC20HooksTrait, > of InternalTrait { /// Initializes the contract by setting the token name and symbol. /// To prevent reinitialization, this should only be used inside of a contract's /// constructor. fn initializer( - ref self: ComponentState, name: ByteArray, symbol: ByteArray + ref self: ComponentState, name: ByteArray, symbol: ByteArray, ) { self.ERC20_name.write(name); self.ERC20_symbol.write(symbol); @@ -427,7 +427,7 @@ pub mod ERC20Component { /// /// Emits a `Transfer` event with `from` set to the zero address. fn mint( - ref self: ComponentState, recipient: ContractAddress, amount: u256 + ref self: ComponentState, recipient: ContractAddress, amount: u256, ) { assert(!recipient.is_zero(), Errors::MINT_TO_ZERO); self.update(Zero::zero(), recipient, amount); @@ -457,7 +457,7 @@ pub mod ERC20Component { ref self: ComponentState, from: ContractAddress, to: ContractAddress, - amount: u256 + amount: u256, ) { Hooks::before_update(ref self, from, to, amount); @@ -497,7 +497,7 @@ pub mod ERC20Component { ref self: ComponentState, sender: ContractAddress, recipient: ContractAddress, - amount: u256 + amount: u256, ) { assert(!sender.is_zero(), Errors::TRANSFER_FROM_ZERO); assert(!recipient.is_zero(), Errors::TRANSFER_TO_ZERO); @@ -517,7 +517,7 @@ pub mod ERC20Component { ref self: ComponentState, owner: ContractAddress, spender: ContractAddress, - amount: u256 + amount: u256, ) { assert(!owner.is_zero(), Errors::APPROVE_FROM_ZERO); assert(!spender.is_zero(), Errors::APPROVE_TO_ZERO); @@ -537,7 +537,7 @@ pub mod ERC20Component { ref self: ComponentState, owner: ContractAddress, spender: ContractAddress, - amount: u256 + amount: u256, ) { let current_allowance = self.ERC20_allowances.read((owner, spender)); if current_allowance != Bounded::MAX { diff --git a/packages/token/src/erc20/interface.cairo b/packages/token/src/erc20/interface.cairo index 065847c44..0d11749ec 100644 --- a/packages/token/src/erc20/interface.cairo +++ b/packages/token/src/erc20/interface.cairo @@ -10,7 +10,7 @@ pub trait IERC20 { fn allowance(self: @TState, owner: ContractAddress, spender: ContractAddress) -> u256; fn transfer(ref self: TState, recipient: ContractAddress, amount: u256) -> bool; fn transfer_from( - ref self: TState, sender: ContractAddress, recipient: ContractAddress, amount: u256 + ref self: TState, sender: ContractAddress, recipient: ContractAddress, amount: u256, ) -> bool; fn approve(ref self: TState, spender: ContractAddress, amount: u256) -> bool; } @@ -29,7 +29,7 @@ pub trait IERC20Camel { fn allowance(self: @TState, owner: ContractAddress, spender: ContractAddress) -> u256; fn transfer(ref self: TState, recipient: ContractAddress, amount: u256) -> bool; fn transferFrom( - ref self: TState, sender: ContractAddress, recipient: ContractAddress, amount: u256 + ref self: TState, sender: ContractAddress, recipient: ContractAddress, amount: u256, ) -> bool; fn approve(ref self: TState, spender: ContractAddress, amount: u256) -> bool; } @@ -39,7 +39,7 @@ pub trait IERC20CamelOnly { fn totalSupply(self: @TState) -> u256; fn balanceOf(self: @TState, account: ContractAddress) -> u256; fn transferFrom( - ref self: TState, sender: ContractAddress, recipient: ContractAddress, amount: u256 + ref self: TState, sender: ContractAddress, recipient: ContractAddress, amount: u256, ) -> bool; } @@ -51,7 +51,7 @@ pub trait IERC20Mixin { fn allowance(self: @TState, owner: ContractAddress, spender: ContractAddress) -> u256; fn transfer(ref self: TState, recipient: ContractAddress, amount: u256) -> bool; fn transfer_from( - ref self: TState, sender: ContractAddress, recipient: ContractAddress, amount: u256 + ref self: TState, sender: ContractAddress, recipient: ContractAddress, amount: u256, ) -> bool; fn approve(ref self: TState, spender: ContractAddress, amount: u256) -> bool; @@ -64,7 +64,7 @@ pub trait IERC20Mixin { fn totalSupply(self: @TState) -> u256; fn balanceOf(self: @TState, account: ContractAddress) -> u256; fn transferFrom( - ref self: TState, sender: ContractAddress, recipient: ContractAddress, amount: u256 + ref self: TState, sender: ContractAddress, recipient: ContractAddress, amount: u256, ) -> bool; } @@ -76,7 +76,7 @@ pub trait IERC20Permit { spender: ContractAddress, amount: u256, deadline: u64, - signature: Span + signature: Span, ); fn nonces(self: @TState, owner: ContractAddress) -> felt252; fn DOMAIN_SEPARATOR(self: @TState) -> felt252; @@ -90,7 +90,7 @@ pub trait ERC20ABI { fn allowance(self: @TState, owner: ContractAddress, spender: ContractAddress) -> u256; fn transfer(ref self: TState, recipient: ContractAddress, amount: u256) -> bool; fn transfer_from( - ref self: TState, sender: ContractAddress, recipient: ContractAddress, amount: u256 + ref self: TState, sender: ContractAddress, recipient: ContractAddress, amount: u256, ) -> bool; fn approve(ref self: TState, spender: ContractAddress, amount: u256) -> bool; @@ -103,7 +103,7 @@ pub trait ERC20ABI { fn totalSupply(self: @TState) -> u256; fn balanceOf(self: @TState, account: ContractAddress) -> u256; fn transferFrom( - ref self: TState, sender: ContractAddress, recipient: ContractAddress, amount: u256 + ref self: TState, sender: ContractAddress, recipient: ContractAddress, amount: u256, ) -> bool; // IERC20Permit @@ -113,7 +113,7 @@ pub trait ERC20ABI { spender: ContractAddress, amount: u256, deadline: u64, - signature: Span + signature: Span, ); fn nonces(self: @TState, owner: ContractAddress) -> felt252; fn DOMAIN_SEPARATOR(self: @TState) -> felt252; diff --git a/packages/token/src/erc20/snip12_utils/permit.cairo b/packages/token/src/erc20/snip12_utils/permit.cairo index 0c5fe0db8..b232d8edd 100644 --- a/packages/token/src/erc20/snip12_utils/permit.cairo +++ b/packages/token/src/erc20/snip12_utils/permit.cairo @@ -1,7 +1,7 @@ // SPDX-License-Identifier: MIT // OpenZeppelin Contracts for Cairo v0.20.0-rc.0 (token/erc20/snip12_utils/permit.cairo) -use core::hash::{HashStateTrait, HashStateExTrait}; +use core::hash::{HashStateExTrait, HashStateTrait}; use core::poseidon::PoseidonTrait; use openzeppelin_utils::cryptography::snip12::StructHash; use starknet::ContractAddress; diff --git a/packages/token/src/erc721/erc721.cairo b/packages/token/src/erc721/erc721.cairo index f24384a89..6549f179d 100644 --- a/packages/token/src/erc721/erc721.cairo +++ b/packages/token/src/erc721/erc721.cairo @@ -8,12 +8,12 @@ #[starknet::component] pub mod ERC721Component { use core::num::traits::Zero; - use crate::erc721::interface::{IERC721ReceiverDispatcher, IERC721ReceiverDispatcherTrait}; use crate::erc721::interface; + use crate::erc721::interface::{IERC721ReceiverDispatcher, IERC721ReceiverDispatcherTrait}; use openzeppelin_introspection::interface::{ISRC5Dispatcher, ISRC5DispatcherTrait}; + use openzeppelin_introspection::src5::SRC5Component; use openzeppelin_introspection::src5::SRC5Component::InternalTrait as SRC5InternalTrait; use openzeppelin_introspection::src5::SRC5Component::SRC5Impl; - use openzeppelin_introspection::src5::SRC5Component; use starknet::storage::{Map, StorageMapReadAccess, StorageMapWriteAccess}; use starknet::storage::{StoragePointerReadAccess, StoragePointerWriteAccess}; use starknet::{ContractAddress, get_caller_address}; @@ -26,7 +26,7 @@ pub mod ERC721Component { pub ERC721_balances: Map, pub ERC721_token_approvals: Map, pub ERC721_operator_approvals: Map<(ContractAddress, ContractAddress), bool>, - pub ERC721_base_uri: ByteArray + pub ERC721_base_uri: ByteArray, } #[event] @@ -45,7 +45,7 @@ pub mod ERC721Component { #[key] pub to: ContractAddress, #[key] - pub token_id: u256 + pub token_id: u256, } /// Emitted when `owner` enables `approved` to manage the `token_id` token. @@ -56,7 +56,7 @@ pub mod ERC721Component { #[key] pub approved: ContractAddress, #[key] - pub token_id: u256 + pub token_id: u256, } /// Emitted when `owner` enables or disables (`approved`) `operator` to manage @@ -67,7 +67,7 @@ pub mod ERC721Component { pub owner: ContractAddress, #[key] pub operator: ContractAddress, - pub approved: bool + pub approved: bool, } pub mod Errors { @@ -91,14 +91,14 @@ pub mod ERC721Component { ref self: ComponentState, to: ContractAddress, token_id: u256, - auth: ContractAddress + auth: ContractAddress, ) {} fn after_update( ref self: ComponentState, to: ContractAddress, token_id: u256, - auth: ContractAddress + auth: ContractAddress, ) {} } @@ -112,7 +112,7 @@ pub mod ERC721Component { +HasComponent, +SRC5Component::HasComponent, +ERC721HooksTrait, - +Drop + +Drop, > of interface::IERC721> { /// Returns the number of NFTs owned by `account`. fn balance_of(self: @ComponentState, account: ContractAddress) -> u256 { @@ -151,11 +151,11 @@ pub mod ERC721Component { from: ContractAddress, to: ContractAddress, token_id: u256, - data: Span + data: Span, ) { Self::transfer_from(ref self, from, to, token_id); assert( - _check_on_erc721_received(from, to, token_id, data), Errors::SAFE_TRANSFER_FAILED + _check_on_erc721_received(from, to, token_id, data), Errors::SAFE_TRANSFER_FAILED, ); } @@ -176,7 +176,7 @@ pub mod ERC721Component { ref self: ComponentState, from: ContractAddress, to: ContractAddress, - token_id: u256 + token_id: u256, ) { assert(!to.is_zero(), Errors::INVALID_RECEIVER); @@ -209,7 +209,7 @@ pub mod ERC721Component { /// /// Emits an `Approval` event. fn set_approval_for_all( - ref self: ComponentState, operator: ContractAddress, approved: bool + ref self: ComponentState, operator: ContractAddress, approved: bool, ) { self._set_approval_for_all(get_caller_address(), operator, approved) } @@ -226,7 +226,9 @@ pub mod ERC721Component { /// Query if `operator` is an authorized operator for `owner`. fn is_approved_for_all( - self: @ComponentState, owner: ContractAddress, operator: ContractAddress + self: @ComponentState, + owner: ContractAddress, + operator: ContractAddress, ) -> bool { self.ERC721_operator_approvals.read((owner, operator)) } @@ -238,7 +240,7 @@ pub mod ERC721Component { +HasComponent, +SRC5Component::HasComponent, +ERC721HooksTrait, - +Drop + +Drop, > of interface::IERC721Metadata> { /// Returns the NFT name. fn name(self: @ComponentState) -> ByteArray { @@ -274,7 +276,7 @@ pub mod ERC721Component { +HasComponent, +SRC5Component::HasComponent, +ERC721HooksTrait, - +Drop + +Drop, > of interface::IERC721CamelOnly> { fn balanceOf(self: @ComponentState, account: ContractAddress) -> u256 { ERC721::balance_of(self, account) @@ -289,7 +291,7 @@ pub mod ERC721Component { from: ContractAddress, to: ContractAddress, tokenId: u256, - data: Span + data: Span, ) { ERC721::safe_transfer_from(ref self, from, to, tokenId, data) } @@ -298,13 +300,13 @@ pub mod ERC721Component { ref self: ComponentState, from: ContractAddress, to: ContractAddress, - tokenId: u256 + tokenId: u256, ) { ERC721::transfer_from(ref self, from, to, tokenId) } fn setApprovalForAll( - ref self: ComponentState, operator: ContractAddress, approved: bool + ref self: ComponentState, operator: ContractAddress, approved: bool, ) { ERC721::set_approval_for_all(ref self, operator, approved) } @@ -314,7 +316,9 @@ pub mod ERC721Component { } fn isApprovedForAll( - self: @ComponentState, owner: ContractAddress, operator: ContractAddress + self: @ComponentState, + owner: ContractAddress, + operator: ContractAddress, ) -> bool { ERC721::is_approved_for_all(self, owner, operator) } @@ -327,7 +331,7 @@ pub mod ERC721Component { +HasComponent, +SRC5Component::HasComponent, +ERC721HooksTrait, - +Drop + +Drop, > of interface::IERC721MetadataCamelOnly> { fn tokenURI(self: @ComponentState, tokenId: u256) -> ByteArray { ERC721Metadata::token_uri(self, tokenId) @@ -340,7 +344,7 @@ pub mod ERC721Component { +HasComponent, impl SRC5: SRC5Component::HasComponent, +ERC721HooksTrait, - +Drop + +Drop, > of interface::ERC721ABI> { // IERC721 fn balance_of(self: @ComponentState, account: ContractAddress) -> u256 { @@ -356,7 +360,7 @@ pub mod ERC721Component { from: ContractAddress, to: ContractAddress, token_id: u256, - data: Span + data: Span, ) { ERC721::safe_transfer_from(ref self, from, to, token_id, data); } @@ -365,7 +369,7 @@ pub mod ERC721Component { ref self: ComponentState, from: ContractAddress, to: ContractAddress, - token_id: u256 + token_id: u256, ) { ERC721::transfer_from(ref self, from, to, token_id); } @@ -375,7 +379,7 @@ pub mod ERC721Component { } fn set_approval_for_all( - ref self: ComponentState, operator: ContractAddress, approved: bool + ref self: ComponentState, operator: ContractAddress, approved: bool, ) { ERC721::set_approval_for_all(ref self, operator, approved); } @@ -385,7 +389,9 @@ pub mod ERC721Component { } fn is_approved_for_all( - self: @ComponentState, owner: ContractAddress, operator: ContractAddress + self: @ComponentState, + owner: ContractAddress, + operator: ContractAddress, ) -> bool { ERC721::is_approved_for_all(self, owner, operator) } @@ -417,7 +423,7 @@ pub mod ERC721Component { from: ContractAddress, to: ContractAddress, tokenId: u256, - data: Span + data: Span, ) { ERC721CamelOnly::safeTransferFrom(ref self, from, to, tokenId, data); } @@ -426,13 +432,13 @@ pub mod ERC721Component { ref self: ComponentState, from: ContractAddress, to: ContractAddress, - tokenId: u256 + tokenId: u256, ) { ERC721CamelOnly::transferFrom(ref self, from, to, tokenId); } fn setApprovalForAll( - ref self: ComponentState, operator: ContractAddress, approved: bool + ref self: ComponentState, operator: ContractAddress, approved: bool, ) { ERC721CamelOnly::setApprovalForAll(ref self, operator, approved); } @@ -442,7 +448,9 @@ pub mod ERC721Component { } fn isApprovedForAll( - self: @ComponentState, owner: ContractAddress, operator: ContractAddress + self: @ComponentState, + owner: ContractAddress, + operator: ContractAddress, ) -> bool { ERC721CamelOnly::isApprovedForAll(self, owner, operator) } @@ -454,7 +462,7 @@ pub mod ERC721Component { // ISRC5 fn supports_interface( - self: @ComponentState, interface_id: felt252 + self: @ComponentState, interface_id: felt252, ) -> bool { let src5 = get_dep_component!(self, SRC5); src5.supports_interface(interface_id) @@ -471,7 +479,7 @@ pub mod ERC721Component { +HasComponent, impl SRC5: SRC5Component::HasComponent, impl Hooks: ERC721HooksTrait, - +Drop + +Drop, > of InternalTrait { /// Initializes the contract by setting the token name, symbol, and base URI. /// This should only be used inside the contract's constructor. @@ -479,7 +487,7 @@ pub mod ERC721Component { ref self: ComponentState, name: ByteArray, symbol: ByteArray, - base_uri: ByteArray + base_uri: ByteArray, ) { self.ERC721_name.write(name); self.ERC721_symbol.write(symbol); @@ -513,7 +521,7 @@ pub mod ERC721Component { ref self: ComponentState, from: ContractAddress, to: ContractAddress, - token_id: u256 + token_id: u256, ) { assert(!to.is_zero(), Errors::INVALID_RECEIVER); @@ -564,11 +572,11 @@ pub mod ERC721Component { from: ContractAddress, to: ContractAddress, token_id: u256, - data: Span + data: Span, ) { self.transfer(from, to, token_id); assert( - _check_on_erc721_received(from, to, token_id, data), Errors::SAFE_TRANSFER_FAILED + _check_on_erc721_received(from, to, token_id, data), Errors::SAFE_TRANSFER_FAILED, ); } @@ -589,12 +597,12 @@ pub mod ERC721Component { ref self: ComponentState, to: ContractAddress, token_id: u256, - data: Span + data: Span, ) { self.mint(to, token_id); assert( _check_on_erc721_received(Zero::zero(), to, token_id, data), - Errors::SAFE_MINT_FAILED + Errors::SAFE_MINT_FAILED, ); } @@ -630,7 +638,7 @@ pub mod ERC721Component { ref self: ComponentState, to: ContractAddress, token_id: u256, - auth: ContractAddress + auth: ContractAddress, ) -> ContractAddress { Hooks::before_update(ref self, to, token_id, auth); @@ -669,7 +677,7 @@ pub mod ERC721Component { /// /// - `token_id` exists. fn _require_owned( - self: @ComponentState, token_id: u256 + self: @ComponentState, token_id: u256, ) -> ContractAddress { let owner = self._owner_of(token_id); assert(!owner.is_zero(), Errors::INVALID_TOKEN_ID); @@ -687,7 +695,7 @@ pub mod ERC721Component { ref self: ComponentState, to: ContractAddress, token_id: u256, - auth: ContractAddress + auth: ContractAddress, ) { self._approve_with_optional_event(to, token_id, auth, true); } @@ -709,7 +717,7 @@ pub mod ERC721Component { to: ContractAddress, token_id: u256, auth: ContractAddress, - emit_event: bool + emit_event: bool, ) { if emit_event || !auth.is_zero() { let owner = self._require_owned(token_id); @@ -739,7 +747,7 @@ pub mod ERC721Component { ref self: ComponentState, owner: ContractAddress, operator: ContractAddress, - approved: bool + approved: bool, ) { assert(!operator.is_zero(), Errors::INVALID_OPERATOR); self.ERC721_operator_approvals.write((owner, operator), approved); @@ -769,7 +777,7 @@ pub mod ERC721Component { self: @ComponentState, owner: ContractAddress, spender: ContractAddress, - token_id: u256 + token_id: u256, ) -> bool { let is_approved_for_all = ERC721::is_approved_for_all(self, owner, spender); @@ -794,7 +802,7 @@ pub mod ERC721Component { self: @ComponentState, owner: ContractAddress, spender: ContractAddress, - token_id: u256 + token_id: u256, ) { // Non-existent token assert(!owner.is_zero(), Errors::INVALID_TOKEN_ID); @@ -805,14 +813,14 @@ pub mod ERC721Component { /// Checks if `to` either is an account contract or has registered support /// for the `IERC721Receiver` interface through SRC5. fn _check_on_erc721_received( - from: ContractAddress, to: ContractAddress, token_id: u256, data: Span + from: ContractAddress, to: ContractAddress, token_id: u256, data: Span, ) -> bool { let src5_dispatcher = ISRC5Dispatcher { contract_address: to }; if src5_dispatcher.supports_interface(interface::IERC721_RECEIVER_ID) { IERC721ReceiverDispatcher { contract_address: to } .on_erc721_received( - get_caller_address(), from, token_id, data + get_caller_address(), from, token_id, data, ) == interface::IERC721_RECEIVER_ID } else { src5_dispatcher.supports_interface(openzeppelin_account::interface::ISRC6_ID) @@ -822,5 +830,5 @@ pub mod ERC721Component { /// An empty implementation of the ERC721 hooks to be used in basic ERC721 preset contracts. pub impl ERC721HooksEmptyImpl< - TContractState + TContractState, > of ERC721Component::ERC721HooksTrait {} diff --git a/packages/token/src/erc721/erc721_receiver.cairo b/packages/token/src/erc721/erc721_receiver.cairo index afe04ad1d..dce210288 100644 --- a/packages/token/src/erc721/erc721_receiver.cairo +++ b/packages/token/src/erc721/erc721_receiver.cairo @@ -8,12 +8,12 @@ /// safe transfers. #[starknet::component] pub mod ERC721ReceiverComponent { + use crate::erc721::interface; use crate::erc721::interface::IERC721_RECEIVER_ID; use crate::erc721::interface::{IERC721Receiver, IERC721ReceiverCamel}; - use crate::erc721::interface; + use openzeppelin_introspection::src5::SRC5Component; use openzeppelin_introspection::src5::SRC5Component::InternalTrait as SRC5InternalTrait; use openzeppelin_introspection::src5::SRC5Component::SRC5Impl; - use openzeppelin_introspection::src5::SRC5Component; use starknet::ContractAddress; #[storage] @@ -24,7 +24,7 @@ pub mod ERC721ReceiverComponent { TContractState, +HasComponent, +SRC5Component::HasComponent, - +Drop + +Drop, > of IERC721Receiver> { /// Called whenever the implementing contract receives `token_id` through /// a safe transfer. This function must return `IERC721_RECEIVER_ID` @@ -34,7 +34,7 @@ pub mod ERC721ReceiverComponent { operator: ContractAddress, from: ContractAddress, token_id: u256, - data: Span + data: Span, ) -> felt252 { IERC721_RECEIVER_ID } @@ -46,14 +46,14 @@ pub mod ERC721ReceiverComponent { TContractState, +HasComponent, +SRC5Component::HasComponent, - +Drop + +Drop, > of IERC721ReceiverCamel> { fn onERC721Received( self: @ComponentState, operator: ContractAddress, from: ContractAddress, tokenId: u256, - data: Span + data: Span, ) -> felt252 { IERC721_RECEIVER_ID } @@ -64,7 +64,7 @@ pub mod ERC721ReceiverComponent { TContractState, +HasComponent, impl SRC5: SRC5Component::HasComponent, - +Drop + +Drop, > of InternalTrait { /// Initializes the contract by registering the IERC721Receiver interface ID. /// This should be used inside the contract's constructor. @@ -79,7 +79,7 @@ pub mod ERC721ReceiverComponent { TContractState, +HasComponent, impl SRC5: SRC5Component::HasComponent, - +Drop + +Drop, > of interface::ERC721ReceiverMixin> { // IERC721Receiver fn on_erc721_received( @@ -87,7 +87,7 @@ pub mod ERC721ReceiverComponent { operator: ContractAddress, from: ContractAddress, token_id: u256, - data: Span + data: Span, ) -> felt252 { ERC721Receiver::on_erc721_received(self, operator, from, token_id, data) } @@ -98,14 +98,14 @@ pub mod ERC721ReceiverComponent { operator: ContractAddress, from: ContractAddress, tokenId: u256, - data: Span + data: Span, ) -> felt252 { ERC721ReceiverCamel::onERC721Received(self, operator, from, tokenId, data) } // ISRC5 fn supports_interface( - self: @ComponentState, interface_id: felt252 + self: @ComponentState, interface_id: felt252, ) -> bool { let src5 = get_dep_component!(self, SRC5); src5.supports_interface(interface_id) diff --git a/packages/token/src/erc721/extensions/erc721_enumerable/erc721_enumerable.cairo b/packages/token/src/erc721/extensions/erc721_enumerable/erc721_enumerable.cairo index 91f09d003..424befa91 100644 --- a/packages/token/src/erc721/extensions/erc721_enumerable/erc721_enumerable.cairo +++ b/packages/token/src/erc721/extensions/erc721_enumerable/erc721_enumerable.cairo @@ -17,12 +17,12 @@ #[starknet::component] pub mod ERC721EnumerableComponent { use core::num::traits::Zero; + use crate::erc721::ERC721Component; use crate::erc721::ERC721Component::ERC721Impl; use crate::erc721::ERC721Component::InternalImpl as ERC721InternalImpl; - use crate::erc721::ERC721Component; use crate::erc721::extensions::erc721_enumerable::interface; - use openzeppelin_introspection::src5::SRC5Component::InternalTrait as SRC5InternalTrait; use openzeppelin_introspection::src5::SRC5Component; + use openzeppelin_introspection::src5::SRC5Component::InternalTrait as SRC5InternalTrait; use starknet::ContractAddress; use starknet::storage::{Map, StorageMapReadAccess, StorageMapWriteAccess}; use starknet::storage::{StoragePointerReadAccess, StoragePointerWriteAccess}; @@ -33,7 +33,7 @@ pub mod ERC721EnumerableComponent { pub ERC721Enumerable_owned_tokens_index: Map, pub ERC721Enumerable_all_tokens_len: u256, pub ERC721Enumerable_all_tokens: Map, - pub ERC721Enumerable_all_tokens_index: Map + pub ERC721Enumerable_all_tokens_index: Map, } pub mod Errors { @@ -47,7 +47,7 @@ pub mod ERC721EnumerableComponent { impl ERC721: ERC721Component::HasComponent, +ERC721Component::ERC721HooksTrait, +SRC5Component::HasComponent, - +Drop + +Drop, > of interface::IERC721Enumerable> { /// Returns the total amount of tokens stored by the contract. fn total_supply(self: @ComponentState) -> u256 { @@ -73,7 +73,7 @@ pub mod ERC721EnumerableComponent { /// - `index` is less than `owner`'s token balance. /// - `owner` is not the zero address. fn token_of_owner_by_index( - self: @ComponentState, owner: ContractAddress, index: u256 + self: @ComponentState, owner: ContractAddress, index: u256, ) -> u256 { let erc721_component = get_dep_component!(self, ERC721); assert(index < erc721_component.balance_of(owner), Errors::OUT_OF_BOUNDS_INDEX); @@ -92,7 +92,7 @@ pub mod ERC721EnumerableComponent { impl ERC721: ERC721Component::HasComponent, +ERC721Component::ERC721HooksTrait, impl SRC5: SRC5Component::HasComponent, - +Drop + +Drop, > of InternalTrait { /// Initializes the contract by declaring support for the `IERC721Enumerable` /// interface id. @@ -112,7 +112,7 @@ pub mod ERC721EnumerableComponent { /// This must be added to the implementing contract's `ERC721HooksTrait::before_update` /// hook. fn before_update( - ref self: ComponentState, to: ContractAddress, token_id: u256 + ref self: ComponentState, to: ContractAddress, token_id: u256, ) { let erc721_component = get_dep_component!(@self, ERC721); let previous_owner = erc721_component._owner_of(token_id); @@ -138,20 +138,19 @@ pub mod ERC721EnumerableComponent { /// /// - `owner` is not the zero address. fn all_tokens_of_owner( - self: @ComponentState, owner: ContractAddress + self: @ComponentState, owner: ContractAddress, ) -> Span { let mut result = array![]; let balance = get_dep_component!(self, ERC721).balance_of(owner); - for index in 0 - ..balance { - result.append(self.ERC721Enumerable_owned_tokens.read((owner, index))); - }; + for index in 0..balance { + result.append(self.ERC721Enumerable_owned_tokens.read((owner, index))); + }; result.span() } /// Adds token to this extension's ownership-tracking data structures. fn _add_token_to_owner_enumeration( - ref self: ComponentState, to: ContractAddress, token_id: u256 + ref self: ComponentState, to: ContractAddress, token_id: u256, ) { let mut erc721_component = get_dep_component_mut!(ref self, ERC721); let len = erc721_component.balance_of(to); @@ -161,7 +160,7 @@ pub mod ERC721EnumerableComponent { /// Adds token to this extension's token-tracking data structures. fn _add_token_to_all_tokens_enumeration( - ref self: ComponentState, token_id: u256 + ref self: ComponentState, token_id: u256, ) { let supply = self.total_supply(); self.ERC721Enumerable_all_tokens_index.write(token_id, supply); @@ -175,7 +174,7 @@ pub mod ERC721EnumerableComponent { /// swapping `token_id` and the index thereof with the last token id and the index /// thereof. fn _remove_token_from_owner_enumeration( - ref self: ComponentState, from: ContractAddress, token_id: u256 + ref self: ComponentState, from: ContractAddress, token_id: u256, ) { let erc721_component = get_dep_component!(@self, ERC721); let last_token_index = erc721_component.balance_of(from) - 1; @@ -204,7 +203,7 @@ pub mod ERC721EnumerableComponent { /// This has 0(1) time complexity but alters the indexed order by swapping /// `token_id` and the index thereof with the last token id and the index thereof. fn _remove_token_from_all_tokens_enumeration( - ref self: ComponentState, token_id: u256 + ref self: ComponentState, token_id: u256, ) { let last_token_index = self.total_supply() - 1; let this_token_index = self.ERC721Enumerable_all_tokens_index.read(token_id); diff --git a/packages/token/src/erc721/interface.cairo b/packages/token/src/erc721/interface.cairo index ab2787ebd..f28916bfe 100644 --- a/packages/token/src/erc721/interface.cairo +++ b/packages/token/src/erc721/interface.cairo @@ -18,14 +18,14 @@ pub trait IERC721 { from: ContractAddress, to: ContractAddress, token_id: u256, - data: Span + data: Span, ); fn transfer_from(ref self: TState, from: ContractAddress, to: ContractAddress, token_id: u256); fn approve(ref self: TState, to: ContractAddress, token_id: u256); fn set_approval_for_all(ref self: TState, operator: ContractAddress, approved: bool); fn get_approved(self: @TState, token_id: u256) -> ContractAddress; fn is_approved_for_all( - self: @TState, owner: ContractAddress, operator: ContractAddress + self: @TState, owner: ContractAddress, operator: ContractAddress, ) -> bool; } @@ -45,7 +45,7 @@ pub trait IERC721CamelOnly { from: ContractAddress, to: ContractAddress, tokenId: u256, - data: Span + data: Span, ); fn transferFrom(ref self: TState, from: ContractAddress, to: ContractAddress, tokenId: u256); fn setApprovalForAll(ref self: TState, operator: ContractAddress, approved: bool); @@ -72,14 +72,14 @@ pub trait ERC721ABI { from: ContractAddress, to: ContractAddress, token_id: u256, - data: Span + data: Span, ); fn transfer_from(ref self: TState, from: ContractAddress, to: ContractAddress, token_id: u256); fn approve(ref self: TState, to: ContractAddress, token_id: u256); fn set_approval_for_all(ref self: TState, operator: ContractAddress, approved: bool); fn get_approved(self: @TState, token_id: u256) -> ContractAddress; fn is_approved_for_all( - self: @TState, owner: ContractAddress, operator: ContractAddress + self: @TState, owner: ContractAddress, operator: ContractAddress, ) -> bool; // ISRC5 @@ -98,7 +98,7 @@ pub trait ERC721ABI { from: ContractAddress, to: ContractAddress, tokenId: u256, - data: Span + data: Span, ); fn transferFrom(ref self: TState, from: ContractAddress, to: ContractAddress, tokenId: u256); fn setApprovalForAll(ref self: TState, operator: ContractAddress, approved: bool); @@ -120,7 +120,7 @@ pub trait IERC721Receiver { operator: ContractAddress, from: ContractAddress, token_id: u256, - data: Span + data: Span, ) -> felt252; } @@ -131,7 +131,7 @@ pub trait IERC721ReceiverCamel { operator: ContractAddress, from: ContractAddress, tokenId: u256, - data: Span + data: Span, ) -> felt252; } @@ -143,7 +143,7 @@ pub trait ERC721ReceiverMixin { operator: ContractAddress, from: ContractAddress, token_id: u256, - data: Span + data: Span, ) -> felt252; // IERC721ReceiverCamel @@ -152,7 +152,7 @@ pub trait ERC721ReceiverMixin { operator: ContractAddress, from: ContractAddress, tokenId: u256, - data: Span + data: Span, ) -> felt252; // ISRC5 diff --git a/packages/token/src/tests/erc1155/test_erc1155.cairo b/packages/token/src/tests/erc1155/test_erc1155.cairo index 4e1bc6a3a..e58983bc4 100644 --- a/packages/token/src/tests/erc1155/test_erc1155.cairo +++ b/packages/token/src/tests/erc1155/test_erc1155.cairo @@ -1,23 +1,23 @@ use core::num::traits::Zero; +use crate::erc1155; +use crate::erc1155::ERC1155Component; use crate::erc1155::ERC1155Component::ERC1155CamelImpl; use crate::erc1155::ERC1155Component::{ERC1155Impl, ERC1155MetadataURIImpl, InternalImpl}; -use crate::erc1155::ERC1155Component; -use crate::erc1155; use openzeppelin_introspection::src5::SRC5Component::SRC5Impl; use openzeppelin_test_common::erc1155::{ - ERC1155SpyHelpers, get_ids_and_values, get_ids_and_split_values + ERC1155SpyHelpers, get_ids_and_split_values, get_ids_and_values, }; use openzeppelin_test_common::erc1155::{ - setup_account, deploy_another_account_at, setup_src5, setup_receiver + deploy_another_account_at, setup_account, setup_receiver, setup_src5, }; use openzeppelin_test_common::mocks::erc1155::{DualCaseERC1155Mock, SnakeERC1155MockWithHooks}; use openzeppelin_testing::constants::{ - EMPTY_DATA, ZERO, OWNER, RECIPIENT, OPERATOR, OTHER, TOKEN_ID, TOKEN_ID_2, TOKEN_VALUE, - TOKEN_VALUE_2 + EMPTY_DATA, OPERATOR, OTHER, OWNER, RECIPIENT, TOKEN_ID, TOKEN_ID_2, TOKEN_VALUE, TOKEN_VALUE_2, + ZERO, }; use openzeppelin_testing::events::EventSpyExt; -use snforge_std::{EventSpy, spy_events, test_address, start_cheat_caller_address}; +use snforge_std::{EventSpy, spy_events, start_cheat_caller_address, test_address}; use starknet::ContractAddress; use starknet::storage::StoragePointerReadAccess; @@ -172,7 +172,7 @@ fn test_safe_transfer_from_owner_to_receiver() { state.safe_transfer_from(owner, recipient, TOKEN_ID, TOKEN_VALUE, EMPTY_DATA()); spy .assert_only_event_transfer_single( - contract_address, owner, owner, recipient, TOKEN_ID, TOKEN_VALUE + contract_address, owner, owner, recipient, TOKEN_ID, TOKEN_VALUE, ); assert_state_after_transfer_single(owner, recipient, TOKEN_ID); @@ -191,7 +191,7 @@ fn test_safeTransferFrom_owner_to_receiver() { state.safeTransferFrom(owner, recipient, TOKEN_ID, TOKEN_VALUE, EMPTY_DATA()); spy .assert_only_event_transfer_single( - contract_address, owner, owner, recipient, TOKEN_ID, TOKEN_VALUE + contract_address, owner, owner, recipient, TOKEN_ID, TOKEN_VALUE, ); assert_state_after_transfer_single(owner, recipient, TOKEN_ID); @@ -211,7 +211,7 @@ fn test_safe_transfer_from_owner_to_account() { state.safe_transfer_from(owner, recipient, TOKEN_ID, TOKEN_VALUE, EMPTY_DATA()); spy .assert_only_event_transfer_single( - contract_address, owner, owner, recipient, TOKEN_ID, TOKEN_VALUE + contract_address, owner, owner, recipient, TOKEN_ID, TOKEN_VALUE, ); assert_state_after_transfer_single(owner, recipient, TOKEN_ID); @@ -231,7 +231,7 @@ fn test_safeTransferFrom_owner_to_account() { state.safeTransferFrom(owner, recipient, TOKEN_ID, TOKEN_VALUE, EMPTY_DATA()); spy .assert_only_event_transfer_single( - contract_address, owner, owner, recipient, TOKEN_ID, TOKEN_VALUE + contract_address, owner, owner, recipient, TOKEN_ID, TOKEN_VALUE, ); assert_state_after_transfer_single(owner, recipient, TOKEN_ID); @@ -256,7 +256,7 @@ fn test_safe_transfer_from_approved_operator() { state.safe_transfer_from(owner, recipient, TOKEN_ID, TOKEN_VALUE, EMPTY_DATA()); spy .assert_only_event_transfer_single( - contract_address, operator, owner, recipient, TOKEN_ID, TOKEN_VALUE + contract_address, operator, owner, recipient, TOKEN_ID, TOKEN_VALUE, ); assert_state_after_transfer_single(owner, recipient, TOKEN_ID); @@ -281,7 +281,7 @@ fn test_safeTransferFrom_approved_operator() { state.safeTransferFrom(owner, recipient, TOKEN_ID, TOKEN_VALUE, EMPTY_DATA()); spy .assert_only_event_transfer_single( - contract_address, operator, owner, recipient, TOKEN_ID, TOKEN_VALUE + contract_address, operator, owner, recipient, TOKEN_ID, TOKEN_VALUE, ); assert_state_after_transfer_single(owner, recipient, TOKEN_ID); @@ -397,7 +397,7 @@ fn test_safe_batch_transfer_from_owner_to_receiver() { state.safe_batch_transfer_from(owner, recipient, token_ids, values, EMPTY_DATA()); spy .assert_only_event_transfer_batch( - contract_address, owner, owner, recipient, token_ids, values + contract_address, owner, owner, recipient, token_ids, values, ); assert_state_after_transfer_batch(owner, recipient, token_ids, values); @@ -417,7 +417,7 @@ fn test_safeBatchTransferFrom_owner_to_receiver() { state.safeBatchTransferFrom(owner, recipient, token_ids, values, EMPTY_DATA()); spy .assert_only_event_transfer_batch( - contract_address, owner, owner, recipient, token_ids, values + contract_address, owner, owner, recipient, token_ids, values, ); assert_state_after_transfer_batch(owner, recipient, token_ids, values); @@ -438,7 +438,7 @@ fn test_safe_batch_transfer_from_owner_to_account() { state.safe_batch_transfer_from(owner, recipient, token_ids, values, EMPTY_DATA()); spy .assert_only_event_transfer_batch( - contract_address, owner, owner, recipient, token_ids, values + contract_address, owner, owner, recipient, token_ids, values, ); assert_state_after_transfer_batch(owner, recipient, token_ids, values); @@ -459,7 +459,7 @@ fn test_safeBatchTransferFrom_owner_to_account() { state.safeBatchTransferFrom(owner, recipient, token_ids, values, EMPTY_DATA()); spy .assert_only_event_transfer_batch( - contract_address, owner, owner, recipient, token_ids, values + contract_address, owner, owner, recipient, token_ids, values, ); assert_state_after_transfer_batch(owner, recipient, token_ids, values); @@ -486,7 +486,7 @@ fn test_safe_batch_transfer_from_approved_operator() { state.safe_batch_transfer_from(owner, recipient, token_ids, values, EMPTY_DATA()); spy .assert_only_event_transfer_batch( - contract_address, operator, owner, recipient, token_ids, values + contract_address, operator, owner, recipient, token_ids, values, ); assert_state_after_transfer_batch(owner, recipient, token_ids, values); @@ -512,7 +512,7 @@ fn test_safeBatchTransferFrom_approved_operator() { state.safeBatchTransferFrom(owner, recipient, token_ids, values, EMPTY_DATA()); spy .assert_only_event_transfer_batch( - contract_address, operator, owner, recipient, token_ids, values + contract_address, operator, owner, recipient, token_ids, values, ); assert_state_after_transfer_batch(owner, recipient, token_ids, values); @@ -731,7 +731,7 @@ fn test_update_single_from_non_zero_to_non_zero() { state.update(owner, recipient, token_ids, values); spy .assert_only_event_transfer_single( - contract_address, owner, owner, recipient, TOKEN_ID, TOKEN_VALUE + contract_address, owner, owner, recipient, TOKEN_ID, TOKEN_VALUE, ); assert_state_after_transfer_single(owner, recipient, TOKEN_ID); @@ -751,7 +751,7 @@ fn test_update_batch_from_non_zero_to_non_zero() { state.update(owner, recipient, token_ids, values); spy .assert_only_event_transfer_batch( - contract_address, owner, owner, recipient, token_ids, values + contract_address, owner, owner, recipient, token_ids, values, ); assert_state_after_transfer_batch(owner, recipient, token_ids, values); @@ -771,7 +771,7 @@ fn test_update_from_non_zero_to_zero() { state.update(owner, recipient, token_ids, values); spy .assert_only_event_transfer_batch( - contract_address, owner, owner, recipient, token_ids, values + contract_address, owner, owner, recipient, token_ids, values, ); assert_state_after_transfer_to_zero_batch(owner, recipient, token_ids); @@ -792,7 +792,7 @@ fn test_update_from_zero_to_non_zero() { state.update(sender, recipient, token_ids, values); spy .assert_only_event_transfer_batch( - contract_address, owner, sender, recipient, token_ids, values + contract_address, owner, sender, recipient, token_ids, values, ); assert_state_after_transfer_from_zero_batch(sender, recipient, token_ids, values); @@ -879,7 +879,7 @@ fn test_update_wac_single_from_non_zero_to_non_zero() { state.update_with_acceptance_check(owner, recipient, token_ids, values, EMPTY_DATA()); spy .assert_only_event_transfer_single( - contract_address, owner, owner, recipient, TOKEN_ID, TOKEN_VALUE + contract_address, owner, owner, recipient, TOKEN_ID, TOKEN_VALUE, ); assert_state_after_transfer_single(owner, recipient, TOKEN_ID); @@ -901,7 +901,7 @@ fn test_update_wac_single_from_non_zero_to_non_zero_account() { state.update_with_acceptance_check(owner, recipient, token_ids, values, EMPTY_DATA()); spy .assert_only_event_transfer_single( - contract_address, owner, owner, recipient, TOKEN_ID, TOKEN_VALUE + contract_address, owner, owner, recipient, TOKEN_ID, TOKEN_VALUE, ); assert_state_after_transfer_single(owner, recipient, TOKEN_ID); @@ -921,7 +921,7 @@ fn test_update_wac_batch_from_non_zero_to_non_zero() { state.update_with_acceptance_check(owner, recipient, token_ids, values, EMPTY_DATA()); spy .assert_only_event_transfer_batch( - contract_address, owner, owner, recipient, token_ids, values + contract_address, owner, owner, recipient, token_ids, values, ); assert_state_after_transfer_batch(owner, recipient, token_ids, values); @@ -942,7 +942,7 @@ fn test_update_wac_batch_from_non_zero_to_non_zero_account() { state.update_with_acceptance_check(owner, recipient, token_ids, values, EMPTY_DATA()); spy .assert_only_event_transfer_batch( - contract_address, owner, owner, recipient, token_ids, values + contract_address, owner, owner, recipient, token_ids, values, ); assert_state_after_transfer_batch(owner, recipient, token_ids, values); @@ -974,7 +974,7 @@ fn test_update_wac_from_zero_to_non_zero() { state.update_with_acceptance_check(sender, recipient, token_ids, values, EMPTY_DATA()); spy .assert_only_event_transfer_batch( - contract_address, owner, sender, recipient, token_ids, values + contract_address, owner, sender, recipient, token_ids, values, ); assert_state_after_transfer_from_zero_batch(sender, recipient, token_ids, values); @@ -996,7 +996,7 @@ fn test_update_wac_from_zero_to_non_zero_account() { state.update_with_acceptance_check(sender, recipient, token_ids, values, EMPTY_DATA()); spy .assert_only_event_transfer_batch( - contract_address, owner, sender, recipient, token_ids, values + contract_address, owner, sender, recipient, token_ids, values, ); assert_state_after_transfer_from_zero_batch(sender, recipient, token_ids, values); @@ -1077,7 +1077,7 @@ fn test_mint_wac_to_receiver() { state.mint_with_acceptance_check(recipient, TOKEN_ID, TOKEN_VALUE, EMPTY_DATA()); spy .assert_only_event_transfer_single( - contract_address, OTHER(), ZERO(), recipient, TOKEN_ID, TOKEN_VALUE + contract_address, OTHER(), ZERO(), recipient, TOKEN_ID, TOKEN_VALUE, ); let balance_of_recipient = state.balance_of(recipient, TOKEN_ID); @@ -1099,7 +1099,7 @@ fn test_mint_wac_to_account() { state.mint_with_acceptance_check(recipient, TOKEN_ID, TOKEN_VALUE, EMPTY_DATA()); spy .assert_only_event_transfer_single( - contract_address, OTHER(), ZERO(), recipient, TOKEN_ID, TOKEN_VALUE + contract_address, OTHER(), ZERO(), recipient, TOKEN_ID, TOKEN_VALUE, ); let balance_of_recipient = state.balance_of(recipient, TOKEN_ID); @@ -1146,7 +1146,7 @@ fn test_batch_mint_wac_to_receiver() { state.batch_mint_with_acceptance_check(recipient, token_ids, values, EMPTY_DATA()); spy .assert_only_event_transfer_batch( - contract_address, OTHER(), ZERO(), recipient, token_ids, values + contract_address, OTHER(), ZERO(), recipient, token_ids, values, ); let balance_of_recipient_token_1_after = state.balance_of(recipient, TOKEN_ID); @@ -1173,7 +1173,7 @@ fn test_batch_mint_wac_to_account() { state.batch_mint_with_acceptance_check(recipient, token_ids, values, EMPTY_DATA()); spy .assert_only_event_transfer_batch( - contract_address, OTHER(), ZERO(), recipient, token_ids, values + contract_address, OTHER(), ZERO(), recipient, token_ids, values, ); let balance_of_recipient_token_1_after = state.balance_of(recipient, TOKEN_ID); @@ -1220,7 +1220,7 @@ fn test_burn() { state.burn(owner, TOKEN_ID, TOKEN_VALUE); spy .assert_only_event_transfer_single( - contract_address, owner, owner, ZERO(), TOKEN_ID, TOKEN_VALUE + contract_address, owner, owner, ZERO(), TOKEN_ID, TOKEN_VALUE, ); let balance_of_owner = state.balance_of(owner, TOKEN_ID); @@ -1271,7 +1271,7 @@ fn test_batch_burn_from_zero() { // fn assert_state_before_transfer_single( - sender: ContractAddress, recipient: ContractAddress, token_id: u256 + sender: ContractAddress, recipient: ContractAddress, token_id: u256, ) { let state = COMPONENT_STATE(); assert_eq!(state.balance_of(sender, token_id), TOKEN_VALUE); @@ -1279,7 +1279,7 @@ fn assert_state_before_transfer_single( } fn assert_state_after_transfer_single( - sender: ContractAddress, recipient: ContractAddress, token_id: u256 + sender: ContractAddress, recipient: ContractAddress, token_id: u256, ) { let state = COMPONENT_STATE(); assert!(state.balance_of(sender, token_id).is_zero()); @@ -1287,7 +1287,7 @@ fn assert_state_after_transfer_single( } fn assert_state_before_transfer_batch( - sender: ContractAddress, recipient: ContractAddress, token_ids: Span, values: Span + sender: ContractAddress, recipient: ContractAddress, token_ids: Span, values: Span, ) { let state = COMPONENT_STATE(); let mut index = 0; @@ -1305,7 +1305,7 @@ fn assert_state_before_transfer_batch( } fn assert_state_before_transfer_from_zero_batch( - sender: ContractAddress, recipient: ContractAddress, token_ids: Span + sender: ContractAddress, recipient: ContractAddress, token_ids: Span, ) { let state = COMPONENT_STATE(); let mut index = 0; @@ -1323,7 +1323,7 @@ fn assert_state_before_transfer_from_zero_batch( } fn assert_state_after_transfer_batch( - sender: ContractAddress, recipient: ContractAddress, token_ids: Span, values: Span + sender: ContractAddress, recipient: ContractAddress, token_ids: Span, values: Span, ) { let state = COMPONENT_STATE(); let mut index = 0; @@ -1341,7 +1341,7 @@ fn assert_state_after_transfer_batch( } fn assert_state_after_transfer_to_zero_batch( - sender: ContractAddress, recipient: ContractAddress, token_ids: Span + sender: ContractAddress, recipient: ContractAddress, token_ids: Span, ) { let state = COMPONENT_STATE(); let mut index = 0; @@ -1359,7 +1359,7 @@ fn assert_state_after_transfer_to_zero_batch( } fn assert_state_after_transfer_from_zero_batch( - sender: ContractAddress, recipient: ContractAddress, token_ids: Span, values: Span + sender: ContractAddress, recipient: ContractAddress, token_ids: Span, values: Span, ) { let state = COMPONENT_STATE(); let mut index = 0; @@ -1384,10 +1384,10 @@ impl ERC1155HooksSpyHelpersImpl of ERC1155HooksSpyHelpers { from: ContractAddress, to: ContractAddress, token_ids: Span, - values: Span + values: Span, ) { let expected = SnakeERC1155MockWithHooks::Event::BeforeUpdate( - SnakeERC1155MockWithHooks::BeforeUpdate { from, to, token_ids, values } + SnakeERC1155MockWithHooks::BeforeUpdate { from, to, token_ids, values }, ); self.assert_emitted_single(contract, expected); } @@ -1398,10 +1398,10 @@ impl ERC1155HooksSpyHelpersImpl of ERC1155HooksSpyHelpers { from: ContractAddress, to: ContractAddress, token_ids: Span, - values: Span + values: Span, ) { let expected = SnakeERC1155MockWithHooks::Event::AfterUpdate( - SnakeERC1155MockWithHooks::AfterUpdate { from, to, token_ids, values } + SnakeERC1155MockWithHooks::AfterUpdate { from, to, token_ids, values }, ); self.assert_emitted_single(contract, expected); } diff --git a/packages/token/src/tests/erc1155/test_erc1155_receiver.cairo b/packages/token/src/tests/erc1155/test_erc1155_receiver.cairo index c3154f4ea..cc433b19d 100644 --- a/packages/token/src/tests/erc1155/test_erc1155_receiver.cairo +++ b/packages/token/src/tests/erc1155/test_erc1155_receiver.cairo @@ -1,11 +1,11 @@ use crate::erc1155::ERC1155ReceiverComponent::{ - ERC1155ReceiverImpl, ERC1155ReceiverCamelImpl, InternalImpl + ERC1155ReceiverCamelImpl, ERC1155ReceiverImpl, InternalImpl, }; use crate::erc1155::interface::IERC1155_RECEIVER_ID; use openzeppelin_introspection::interface::ISRC5_ID; use openzeppelin_introspection::src5::SRC5Component::SRC5Impl; use openzeppelin_test_common::mocks::erc1155::DualCaseERC1155ReceiverMock; -use openzeppelin_testing::constants::{OWNER, OPERATOR, TOKEN_ID, TOKEN_VALUE, EMPTY_DATA}; +use openzeppelin_testing::constants::{EMPTY_DATA, OPERATOR, OWNER, TOKEN_ID, TOKEN_VALUE}; fn STATE() -> DualCaseERC1155ReceiverMock::ContractState { DualCaseERC1155ReceiverMock::contract_state_for_testing() diff --git a/packages/token/src/tests/erc20/test_erc20.cairo b/packages/token/src/tests/erc20/test_erc20.cairo index 1d1deeb8a..314e1b2d0 100644 --- a/packages/token/src/tests/erc20/test_erc20.cairo +++ b/packages/token/src/tests/erc20/test_erc20.cairo @@ -1,14 +1,14 @@ use core::num::traits::Bounded; +use crate::erc20::ERC20Component; use crate::erc20::ERC20Component::{ERC20CamelOnlyImpl, ERC20Impl}; use crate::erc20::ERC20Component::{ERC20MetadataImpl, InternalImpl}; -use crate::erc20::ERC20Component; use openzeppelin_test_common::erc20::ERC20SpyHelpers; use openzeppelin_test_common::mocks::erc20::{DualCaseERC20Mock, SnakeERC20MockWithHooks}; use openzeppelin_testing::constants::{ - ZERO, OWNER, SPENDER, RECIPIENT, NAME, SYMBOL, DECIMALS, SUPPLY, VALUE + DECIMALS, NAME, OWNER, RECIPIENT, SPENDER, SUPPLY, SYMBOL, VALUE, ZERO, }; use openzeppelin_testing::events::EventSpyExt; -use snforge_std::{EventSpy, spy_events, test_address, start_cheat_caller_address}; +use snforge_std::{EventSpy, spy_events, start_cheat_caller_address, test_address}; use starknet::ContractAddress; // @@ -657,10 +657,10 @@ impl ERC20HooksSpyHelpersImpl of ERC20HooksSpyHelpers { contract: ContractAddress, from: ContractAddress, recipient: ContractAddress, - amount: u256 + amount: u256, ) { let expected = SnakeERC20MockWithHooks::Event::BeforeUpdate( - SnakeERC20MockWithHooks::BeforeUpdate { from, recipient, amount } + SnakeERC20MockWithHooks::BeforeUpdate { from, recipient, amount }, ); self.assert_emitted_single(contract, expected); } @@ -670,10 +670,10 @@ impl ERC20HooksSpyHelpersImpl of ERC20HooksSpyHelpers { contract: ContractAddress, from: ContractAddress, recipient: ContractAddress, - amount: u256 + amount: u256, ) { let expected = SnakeERC20MockWithHooks::Event::AfterUpdate( - SnakeERC20MockWithHooks::AfterUpdate { from, recipient, amount } + SnakeERC20MockWithHooks::AfterUpdate { from, recipient, amount }, ); self.assert_emitted_single(contract, expected); } diff --git a/packages/token/src/tests/erc20/test_erc20_permit.cairo b/packages/token/src/tests/erc20/test_erc20_permit.cairo index 0fdc9e236..d07417bcc 100644 --- a/packages/token/src/tests/erc20/test_erc20_permit.cairo +++ b/packages/token/src/tests/erc20/test_erc20_permit.cairo @@ -1,15 +1,15 @@ -use core::hash::{HashStateTrait, HashStateExTrait}; +use core::hash::{HashStateExTrait, HashStateTrait}; use core::poseidon::PoseidonTrait; +use crate::erc20::ERC20Component; use crate::erc20::ERC20Component::{ERC20MixinImpl, InternalImpl}; use crate::erc20::ERC20Component::{ERC20PermitImpl, SNIP12MetadataExternalImpl}; -use crate::erc20::ERC20Component; -use crate::erc20::snip12_utils::permit::{Permit, PERMIT_TYPE_HASH}; -use openzeppelin_test_common::mocks::erc20::DualCaseERC20PermitMock::SNIP12MetadataImpl; +use crate::erc20::snip12_utils::permit::{PERMIT_TYPE_HASH, Permit}; use openzeppelin_test_common::mocks::erc20::DualCaseERC20PermitMock; +use openzeppelin_test_common::mocks::erc20::DualCaseERC20PermitMock::SNIP12MetadataImpl; use openzeppelin_testing as utils; use openzeppelin_testing::constants; use openzeppelin_testing::signing::{StarkKeyPair, StarkSerializedSigning}; -use openzeppelin_utils::cryptography::snip12::{StructHash, StarknetDomain}; +use openzeppelin_utils::cryptography::snip12::{StarknetDomain, StructHash}; use snforge_std::signature::stark_curve::StarkCurveSignerImpl; use snforge_std::{start_cheat_block_timestamp, start_cheat_chain_id_global}; use snforge_std::{start_cheat_caller_address, test_address}; @@ -33,7 +33,7 @@ struct TestData { metadata_name: felt252, metadata_version: felt252, chain_id: felt252, - revision: felt252 + revision: felt252, } fn TEST_DATA() -> TestData { @@ -68,7 +68,7 @@ fn setup(data: TestData) -> ComponentState { start_cheat_chain_id_global(data.chain_id); utils::declare_and_deploy_at( - "DualCaseAccountMock", data.owner, array![data.key_pair.public_key] + "DualCaseAccountMock", data.owner, array![data.key_pair.public_key], ); let mut state = COMPONENT_STATE(); @@ -159,7 +159,7 @@ fn test_spend_half_permit() { fn test_subsequent_permits() { let mut data = TEST_DATA(); let (owner, spender, amount_1, deadline) = ( - data.owner, data.spender, data.amount, data.deadline + data.owner, data.spender, data.amount, data.deadline, ); let mut state = setup(data); @@ -226,7 +226,7 @@ fn test_domain_separator() { name: data.metadata_name, version: data.metadata_version, chain_id: data.chain_id, - revision: data.revision + revision: data.revision, }; let expected_domain_separator = sn_domain.hash_struct(); assert_eq!(state.DOMAIN_SEPARATOR(), expected_domain_separator); @@ -239,7 +239,7 @@ fn test_domain_separator() { #[test] fn test_permit_type_hash() { let expected_type_hash = selector!( - "\"Permit\"(\"token\":\"ContractAddress\",\"spender\":\"ContractAddress\",\"amount\":\"u256\",\"nonce\":\"felt\",\"deadline\":\"u128\")" + "\"Permit\"(\"token\":\"ContractAddress\",\"spender\":\"ContractAddress\",\"amount\":\"u256\",\"nonce\":\"felt\",\"deadline\":\"u128\")", ); assert_eq!(PERMIT_TYPE_HASH, expected_type_hash); } @@ -451,14 +451,14 @@ fn prepare_permit_signature(data: TestData, nonce: felt252) -> Span { name: data.metadata_name, version: data.metadata_version, chain_id: data.chain_id, - revision: data.revision + revision: data.revision, }; let permit = Permit { token: data.token_address, spender: data.spender, amount: data.amount, nonce, - deadline: data.deadline + deadline: data.deadline, }; let msg_hash = PoseidonTrait::new() .update_with('StarkNet Message') diff --git a/packages/token/src/tests/erc2981/test_erc2981_accesscontrol.cairo b/packages/token/src/tests/erc2981/test_erc2981_accesscontrol.cairo index b66c72d88..9dfe24517 100644 --- a/packages/token/src/tests/erc2981/test_erc2981_accesscontrol.cairo +++ b/packages/token/src/tests/erc2981/test_erc2981_accesscontrol.cairo @@ -1,10 +1,10 @@ +use crate::common::erc2981::ERC2981Component::{ERC2981AdminAccessControlImpl, ERC2981InfoImpl}; use crate::common::erc2981::ERC2981Component::{ERC2981Impl, InternalImpl, ROYALTY_ADMIN_ROLE}; -use crate::common::erc2981::ERC2981Component::{ERC2981InfoImpl, ERC2981AdminAccessControlImpl}; use crate::common::erc2981::{DefaultConfig, ERC2981Component}; use openzeppelin_access::accesscontrol::AccessControlComponent::InternalImpl as AccessControlInternalImpl; use openzeppelin_access::accesscontrol::{AccessControlComponent, DEFAULT_ADMIN_ROLE}; use openzeppelin_test_common::mocks::erc2981::ERC2981AccessControlMock; -use openzeppelin_testing::constants::{ADMIN, OTHER_ADMIN, OTHER_ROLE, OTHER, ZERO, RECIPIENT}; +use openzeppelin_testing::constants::{ADMIN, OTHER, OTHER_ADMIN, OTHER_ROLE, RECIPIENT, ZERO}; use snforge_std::{start_cheat_caller_address, test_address}; use starknet::{ContractAddress, contract_address_const}; diff --git a/packages/token/src/tests/erc2981/test_erc2981_internal.cairo b/packages/token/src/tests/erc2981/test_erc2981_internal.cairo index 7fd44e461..9aa25c95d 100644 --- a/packages/token/src/tests/erc2981/test_erc2981_internal.cairo +++ b/packages/token/src/tests/erc2981/test_erc2981_internal.cairo @@ -1,9 +1,9 @@ use crate::common::erc2981::ERC2981Component::{ERC2981Impl, InternalImpl}; use crate::common::erc2981::interface::IERC2981_ID; -use crate::common::erc2981::{ERC2981Component, DefaultConfig}; +use crate::common::erc2981::{DefaultConfig, ERC2981Component}; use openzeppelin_introspection::src5::SRC5Component::SRC5Impl; use openzeppelin_test_common::mocks::erc2981::ERC2981Mock; -use openzeppelin_testing::constants::{ZERO, RECIPIENT}; +use openzeppelin_testing::constants::{RECIPIENT, ZERO}; use starknet::{ContractAddress, contract_address_const}; type ComponentState = ERC2981Component::ComponentState; diff --git a/packages/token/src/tests/erc2981/test_erc2981_ownable.cairo b/packages/token/src/tests/erc2981/test_erc2981_ownable.cairo index e9c3e6842..67d5c0df8 100644 --- a/packages/token/src/tests/erc2981/test_erc2981_ownable.cairo +++ b/packages/token/src/tests/erc2981/test_erc2981_ownable.cairo @@ -1,10 +1,10 @@ +use crate::common::erc2981::ERC2981Component::{ERC2981AdminOwnableImpl, ERC2981InfoImpl}; use crate::common::erc2981::ERC2981Component::{ERC2981Impl, InternalImpl}; -use crate::common::erc2981::ERC2981Component::{ERC2981InfoImpl, ERC2981AdminOwnableImpl}; use crate::common::erc2981::{DefaultConfig, ERC2981Component}; -use openzeppelin_access::ownable::OwnableComponent::InternalImpl as OwnableInternalImpl; use openzeppelin_access::ownable::OwnableComponent; +use openzeppelin_access::ownable::OwnableComponent::InternalImpl as OwnableInternalImpl; use openzeppelin_test_common::mocks::erc2981::ERC2981OwnableMock; -use openzeppelin_testing::constants::{OWNER, OTHER, ZERO, RECIPIENT}; +use openzeppelin_testing::constants::{OTHER, OWNER, RECIPIENT, ZERO}; use snforge_std::{start_cheat_caller_address, test_address}; use starknet::{ContractAddress, contract_address_const}; diff --git a/packages/token/src/tests/erc721/test_erc721.cairo b/packages/token/src/tests/erc721/test_erc721.cairo index 51882720a..399cdb70f 100644 --- a/packages/token/src/tests/erc721/test_erc721.cairo +++ b/packages/token/src/tests/erc721/test_erc721.cairo @@ -1,18 +1,18 @@ use core::num::traits::Zero; -use crate::erc721::ERC721Component::{ERC721Impl, ERC721CamelOnlyImpl}; -use crate::erc721::ERC721Component::{ERC721MetadataImpl, InternalImpl}; -use crate::erc721::ERC721Component; use crate::erc721; +use crate::erc721::ERC721Component; +use crate::erc721::ERC721Component::{ERC721CamelOnlyImpl, ERC721Impl}; +use crate::erc721::ERC721Component::{ERC721MetadataImpl, InternalImpl}; use openzeppelin_introspection::src5::SRC5Component::SRC5Impl; use openzeppelin_test_common::erc721::ERC721SpyHelpers; use openzeppelin_test_common::mocks::erc721::{DualCaseERC721Mock, SnakeERC721MockWithHooks}; use openzeppelin_testing as utils; use openzeppelin_testing::constants::{ - DATA, ZERO, OWNER, CALLER, RECIPIENT, SPENDER, OPERATOR, OTHER, NAME, SYMBOL, TOKEN_ID, - TOKEN_ID_2, PUBKEY, BASE_URI, BASE_URI_2 + BASE_URI, BASE_URI_2, CALLER, DATA, NAME, OPERATOR, OTHER, OWNER, PUBKEY, RECIPIENT, SPENDER, + SYMBOL, TOKEN_ID, TOKEN_ID_2, ZERO, }; use openzeppelin_testing::events::EventSpyExt; -use snforge_std::{EventSpy, spy_events, test_address, start_cheat_caller_address}; +use snforge_std::{EventSpy, spy_events, start_cheat_caller_address, test_address}; use starknet::ContractAddress; use starknet::storage::StorageMapReadAccess; @@ -1426,7 +1426,7 @@ fn test_update_calls_after_update_hook() { // fn assert_state_before_transfer( - owner: ContractAddress, recipient: ContractAddress, token_id: u256 + owner: ContractAddress, recipient: ContractAddress, token_id: u256, ) { let state = COMPONENT_STATE(); assert_eq!(state.owner_of(token_id), owner); @@ -1461,10 +1461,10 @@ impl ERC721HooksSpyHelpersImpl of ERC721HooksSpyHelpers { contract: ContractAddress, to: ContractAddress, token_id: u256, - auth: ContractAddress + auth: ContractAddress, ) { let expected = SnakeERC721MockWithHooks::Event::BeforeUpdate( - SnakeERC721MockWithHooks::BeforeUpdate { to, token_id, auth } + SnakeERC721MockWithHooks::BeforeUpdate { to, token_id, auth }, ); self.assert_emitted_single(contract, expected); } @@ -1474,10 +1474,10 @@ impl ERC721HooksSpyHelpersImpl of ERC721HooksSpyHelpers { contract: ContractAddress, to: ContractAddress, token_id: u256, - auth: ContractAddress + auth: ContractAddress, ) { let expected = SnakeERC721MockWithHooks::Event::AfterUpdate( - SnakeERC721MockWithHooks::AfterUpdate { to, token_id, auth } + SnakeERC721MockWithHooks::AfterUpdate { to, token_id, auth }, ); self.assert_emitted_single(contract, expected); } diff --git a/packages/token/src/tests/erc721/test_erc721_enumerable.cairo b/packages/token/src/tests/erc721/test_erc721_enumerable.cairo index ad0a2f893..c3d119178 100644 --- a/packages/token/src/tests/erc721/test_erc721_enumerable.cairo +++ b/packages/token/src/tests/erc721/test_erc721_enumerable.cairo @@ -1,13 +1,13 @@ use crate::erc721::ERC721Component::{ERC721Impl, InternalImpl as ERC721InternalImpl}; +use crate::erc721::extensions::erc721_enumerable::ERC721EnumerableComponent; use crate::erc721::extensions::erc721_enumerable::ERC721EnumerableComponent::{ - ERC721EnumerableImpl, InternalImpl + ERC721EnumerableImpl, InternalImpl, }; -use crate::erc721::extensions::erc721_enumerable::ERC721EnumerableComponent; use crate::erc721::extensions::erc721_enumerable::interface::IERC721ENUMERABLE_ID; use openzeppelin_introspection::interface::ISRC5_ID; use openzeppelin_introspection::src5::SRC5Component::SRC5Impl; use openzeppelin_test_common::mocks::erc721::ERC721EnumerableMock; -use openzeppelin_testing::constants::{OWNER, RECIPIENT, OTHER, ZERO}; +use openzeppelin_testing::constants::{OTHER, OWNER, RECIPIENT, ZERO}; use starknet::ContractAddress; use starknet::storage::StorageMapReadAccess; diff --git a/packages/token/src/tests/erc721/test_erc721_receiver.cairo b/packages/token/src/tests/erc721/test_erc721_receiver.cairo index c24285744..f344a43cc 100644 --- a/packages/token/src/tests/erc721/test_erc721_receiver.cairo +++ b/packages/token/src/tests/erc721/test_erc721_receiver.cairo @@ -1,11 +1,11 @@ use crate::erc721::ERC721ReceiverComponent::{ - ERC721ReceiverImpl, ERC721ReceiverCamelImpl, InternalImpl + ERC721ReceiverCamelImpl, ERC721ReceiverImpl, InternalImpl, }; use crate::erc721::interface::IERC721_RECEIVER_ID; use openzeppelin_introspection::interface::ISRC5_ID; use openzeppelin_introspection::src5::SRC5Component::SRC5Impl; use openzeppelin_test_common::mocks::erc721::DualCaseERC721ReceiverMock; -use openzeppelin_testing::constants::{OWNER, OPERATOR, TOKEN_ID}; +use openzeppelin_testing::constants::{OPERATOR, OWNER, TOKEN_ID}; fn STATE() -> DualCaseERC721ReceiverMock::ContractState { DualCaseERC721ReceiverMock::contract_state_for_testing() diff --git a/packages/upgrades/src/interface.cairo b/packages/upgrades/src/interface.cairo index b79a2623d..d92e82b7f 100644 --- a/packages/upgrades/src/interface.cairo +++ b/packages/upgrades/src/interface.cairo @@ -11,6 +11,6 @@ pub trait IUpgradeable { #[starknet::interface] pub trait IUpgradeAndCall { fn upgrade_and_call( - ref self: TState, new_class_hash: ClassHash, selector: felt252, calldata: Span + ref self: TState, new_class_hash: ClassHash, selector: felt252, calldata: Span, ) -> Span; } diff --git a/packages/upgrades/src/tests/test_upgradeable.cairo b/packages/upgrades/src/tests/test_upgradeable.cairo index fa611cf24..194947867 100644 --- a/packages/upgrades/src/tests/test_upgradeable.cairo +++ b/packages/upgrades/src/tests/test_upgradeable.cairo @@ -6,7 +6,7 @@ use openzeppelin_test_common::upgrades::UpgradeableSpyHelpers; use openzeppelin_testing as utils; use openzeppelin_testing::constants::{CLASS_HASH_ZERO, FELT_VALUE as VALUE}; use openzeppelin_testing::{declare_class, deploy}; -use snforge_std::{spy_events, ContractClass}; +use snforge_std::{ContractClass, spy_events}; // // Setup @@ -82,7 +82,7 @@ fn test_remove_selector_fails_in_v2() { let safe_dispatcher = IUpgradesV1SafeDispatcher { contract_address: v1.contract_address }; let mut result = safe_dispatcher.remove_selector(); utils::assert_entrypoint_not_found_error( - result, selector!("remove_selector"), v1.contract_address + result, selector!("remove_selector"), v1.contract_address, ); } diff --git a/packages/upgrades/src/upgradeable.cairo b/packages/upgrades/src/upgradeable.cairo index b308ab352..42a9ef7eb 100644 --- a/packages/upgrades/src/upgradeable.cairo +++ b/packages/upgrades/src/upgradeable.cairo @@ -15,13 +15,13 @@ pub mod UpgradeableComponent { #[event] #[derive(Drop, PartialEq, starknet::Event)] pub enum Event { - Upgraded: Upgraded + Upgraded: Upgraded, } /// Emitted when the contract is upgraded. #[derive(Drop, PartialEq, starknet::Event)] pub struct Upgraded { - pub class_hash: ClassHash + pub class_hash: ClassHash, } pub mod Errors { @@ -34,7 +34,7 @@ pub mod UpgradeableComponent { #[generate_trait] pub impl InternalImpl< - TContractState, +HasComponent + TContractState, +HasComponent, > of InternalTrait { /// Replaces the contract's class hash with `new_class_hash`. /// @@ -63,7 +63,7 @@ pub mod UpgradeableComponent { ref self: ComponentState, new_class_hash: ClassHash, selector: felt252, - calldata: Span + calldata: Span, ) -> Span { self.upgrade(new_class_hash); let this = starknet::get_contract_address(); diff --git a/packages/utils/src/bytearray.cairo b/packages/utils/src/bytearray.cairo index bff3011a6..a0b7ef2dc 100644 --- a/packages/utils/src/bytearray.cairo +++ b/packages/utils/src/bytearray.cairo @@ -2,7 +2,7 @@ // OpenZeppelin Contracts for Cairo v0.20.0-rc.0 (utils/bytearray.cairo) use core::byte_array::ByteArrayTrait; -use core::hash::{HashStateTrait, HashStateExTrait}; +use core::hash::{HashStateExTrait, HashStateTrait}; use core::pedersen::PedersenTrait; use core::to_byte_array::FormatAsByteArray; @@ -28,7 +28,7 @@ pub fn read_n_bytes(data: @ByteArray, start: u32, n: u32) -> ByteArray { /// /// - `base` cannot be zero. pub fn to_byte_array, +Copy>( - value: @T, base: u8, padding: u16 + value: @T, base: u8, padding: u16, ) -> ByteArray { let value: felt252 = (*value).into(); let base: felt252 = base.into(); @@ -81,7 +81,7 @@ pub impl ByteArrayExtImpl of ByteArrayExtTrait { /// /// - `base` cannot be zero. fn to_byte_array, +Copy>( - self: @T, base: u8, padding: u16 + self: @T, base: u8, padding: u16, ) -> ByteArray { to_byte_array(self, base, padding) } diff --git a/packages/utils/src/cryptography/nonces.cairo b/packages/utils/src/cryptography/nonces.cairo index b4dc0a6bc..bae3cf532 100644 --- a/packages/utils/src/cryptography/nonces.cairo +++ b/packages/utils/src/cryptography/nonces.cairo @@ -14,7 +14,7 @@ pub mod NoncesComponent { #[storage] pub struct Storage { - pub Nonces_nonces: Map + pub Nonces_nonces: Map, } pub mod Errors { @@ -23,7 +23,7 @@ pub mod NoncesComponent { #[embeddable_as(NoncesImpl)] impl Nonces< - TContractState, +HasComponent + TContractState, +HasComponent, > of INonces> { /// Returns the next unused nonce for an address. fn nonces(self: @ComponentState, owner: ContractAddress) -> felt252 { @@ -33,7 +33,7 @@ pub mod NoncesComponent { #[generate_trait] pub impl InternalImpl< - TContractState, +HasComponent + TContractState, +HasComponent, > of InternalTrait { /// Consumes a nonce, returns the current value, and increments nonce. fn use_nonce(ref self: ComponentState, owner: ContractAddress) -> felt252 { @@ -47,7 +47,7 @@ pub mod NoncesComponent { /// Same as `use_nonce` but checking that `nonce` is the next valid one for `owner`. fn use_checked_nonce( - ref self: ComponentState, owner: ContractAddress, nonce: felt252 + ref self: ComponentState, owner: ContractAddress, nonce: felt252, ) -> felt252 { let current = self.use_nonce(owner); assert(nonce == current, Errors::INVALID_NONCE); diff --git a/packages/utils/src/cryptography/snip12.cairo b/packages/utils/src/cryptography/snip12.cairo index 84a95febd..cf2d72bfc 100644 --- a/packages/utils/src/cryptography/snip12.cairo +++ b/packages/utils/src/cryptography/snip12.cairo @@ -1,8 +1,8 @@ // SPDX-License-Identifier: MIT // OpenZeppelin Contracts for Cairo v0.20.0-rc.0 (utils/cryptography/snip12.cairo) -use core::hash::{HashStateTrait, HashStateExTrait, Hash}; -use core::poseidon::{PoseidonTrait, HashState}; +use core::hash::{Hash, HashStateExTrait, HashStateTrait}; +use core::poseidon::{HashState, PoseidonTrait}; use starknet::{ContractAddress, get_tx_info}; // selector!( @@ -60,14 +60,14 @@ pub trait SNIP12Metadata { /// - `signer` of the message. /// - Hashed struct of the message. pub(crate) impl OffchainMessageHashImpl< - T, +StructHash, impl metadata: SNIP12Metadata + T, +StructHash, impl metadata: SNIP12Metadata, > of OffchainMessageHash { fn get_message_hash(self: @T, signer: ContractAddress) -> felt252 { let domain = StarknetDomain { name: metadata::name(), version: metadata::version(), chain_id: get_tx_info().unbox().chain_id, - revision: 1 + revision: 1, }; let mut state = PoseidonTrait::new(); state = state.update_with('StarkNet Message'); diff --git a/packages/utils/src/deployments.cairo b/packages/utils/src/deployments.cairo index bd1ce64df..b2a2e005a 100644 --- a/packages/utils/src/deployments.cairo +++ b/packages/utils/src/deployments.cairo @@ -3,7 +3,7 @@ pub mod interface; -use core::hash::{HashStateTrait, HashStateExTrait}; +use core::hash::{HashStateExTrait, HashStateTrait}; use core::num::traits::Zero; use core::pedersen::PedersenTrait; use core::poseidon::PoseidonTrait; @@ -25,7 +25,7 @@ pub fn calculate_contract_address_from_deploy_syscall( salt: felt252, class_hash: ClassHash, constructor_calldata: Span, - deployer_address: ContractAddress + deployer_address: ContractAddress, ) -> ContractAddress { let constructor_calldata_hash = compute_hash_on_elements(constructor_calldata); @@ -58,7 +58,7 @@ fn compute_hash_on_elements(data: Span) -> felt252 { #[derive(Drop)] pub struct DeployerInfo { pub caller_address: ContractAddress, - pub udc_address: ContractAddress + pub udc_address: ContractAddress, } /// Returns the calculated contract address for contracts deployed through the UDC. @@ -68,7 +68,7 @@ pub fn calculate_contract_address_from_udc( salt: felt252, class_hash: ClassHash, constructor_calldata: Span, - deployer_info: Option + deployer_info: Option, ) -> ContractAddress { match deployer_info { Option::Some(deployer_info) => { @@ -78,11 +78,11 @@ pub fn calculate_contract_address_from_udc( .update_with(salt) .finalize(); calculate_contract_address_from_deploy_syscall( - hashed_salt, class_hash, constructor_calldata, deployer_info.udc_address + hashed_salt, class_hash, constructor_calldata, deployer_info.udc_address, ) }, Option::None => calculate_contract_address_from_deploy_syscall( - salt, class_hash, constructor_calldata, Zero::zero() + salt, class_hash, constructor_calldata, Zero::zero(), ), } } diff --git a/packages/utils/src/deployments/interface.cairo b/packages/utils/src/deployments/interface.cairo index dd60cf71b..76414356a 100644 --- a/packages/utils/src/deployments/interface.cairo +++ b/packages/utils/src/deployments/interface.cairo @@ -10,6 +10,6 @@ pub trait IUniversalDeployer { class_hash: ClassHash, salt: felt252, from_zero: bool, - calldata: Span + calldata: Span, ) -> ContractAddress; } diff --git a/packages/utils/src/interfaces.cairo b/packages/utils/src/interfaces.cairo index cbe1cca93..61b2ad9d5 100644 --- a/packages/utils/src/interfaces.cairo +++ b/packages/utils/src/interfaces.cairo @@ -1,4 +1,4 @@ pub use crate::cryptography::interface::{INonces, INoncesDispatcher, INoncesDispatcherTrait}; pub use crate::deployments::interface::{ - IUniversalDeployer, IUniversalDeployerDispatcher, IUniversalDeployerDispatcherTrait + IUniversalDeployer, IUniversalDeployerDispatcher, IUniversalDeployerDispatcherTrait, }; diff --git a/packages/utils/src/math.cairo b/packages/utils/src/math.cairo index a7a5aa89c..55a0713b3 100644 --- a/packages/utils/src/math.cairo +++ b/packages/utils/src/math.cairo @@ -1,7 +1,7 @@ // SPDX-License-Identifier: MIT // OpenZeppelin Contracts for Cairo v0.20.0-rc.0 (utils/math.cairo) -use core::traits::{Into, BitAnd, BitXor}; +use core::traits::{BitAnd, BitXor, Into}; /// Returns the average of two numbers. The result is rounded down. pub fn average< @@ -12,9 +12,9 @@ pub fn average< impl TDiv: Div, impl TBitAnd: BitAnd, impl TBitXor: BitXor, - impl TInto: Into + impl TInto: Into, >( - a: T, b: T + a: T, b: T, ) -> T { // (a + b) / 2 can overflow. (a & b) + (a ^ b) / 2_u8.into() diff --git a/packages/utils/src/structs.cairo b/packages/utils/src/structs.cairo index a42c00014..287a70edd 100644 --- a/packages/utils/src/structs.cairo +++ b/packages/utils/src/structs.cairo @@ -1,3 +1,3 @@ pub mod checkpoint; -pub use checkpoint::{Trace, Checkpoint}; +pub use checkpoint::{Checkpoint, Trace}; diff --git a/packages/utils/src/structs/checkpoint.cairo b/packages/utils/src/structs/checkpoint.cairo index 47881f3ea..824cfd540 100644 --- a/packages/utils/src/structs/checkpoint.cairo +++ b/packages/utils/src/structs/checkpoint.cairo @@ -3,7 +3,7 @@ use core::num::traits::Sqrt; use crate::math; -use starknet::storage::{StoragePath, StorageAsPath, Vec, VecTrait, Mutable, MutableVecTrait}; +use starknet::storage::{Mutable, MutableVecTrait, StorageAsPath, StoragePath, Vec, VecTrait}; use starknet::storage::{StoragePointerReadAccess, StoragePointerWriteAccess}; use starknet::storage_access::StorePacking; @@ -11,14 +11,14 @@ use starknet::storage_access::StorePacking; /// time, and later looking up past values by block timestamp. #[starknet::storage_node] pub struct Trace { - pub checkpoints: Vec + pub checkpoints: Vec, } /// Generic checkpoint representation. #[derive(Copy, Drop, Serde)] pub struct Checkpoint { pub key: u64, - pub value: u256 + pub value: u256, } #[generate_trait] @@ -140,7 +140,7 @@ impl CheckpointImpl of CheckpointTrait { /// the search key, or `high` if there is none. `low` and `high` define a section where to do /// the search, with inclusive `low` and exclusive `high`. fn _upper_binary_lookup( - self: StoragePath>, key: u64, low: u64, high: u64 + self: StoragePath>, key: u64, low: u64, high: u64, ) -> u64 { let mut _low = low; let mut _high = high; diff --git a/packages/utils/src/tests/test_nonces.cairo b/packages/utils/src/tests/test_nonces.cairo index fdc783035..051520c76 100644 --- a/packages/utils/src/tests/test_nonces.cairo +++ b/packages/utils/src/tests/test_nonces.cairo @@ -1,7 +1,7 @@ use core::num::traits::Zero; use crate::cryptography::interface::INonces; -use crate::cryptography::nonces::NoncesComponent::InternalTrait; use crate::cryptography::nonces::NoncesComponent; +use crate::cryptography::nonces::NoncesComponent::InternalTrait; use openzeppelin_test_common::mocks::nonces::NoncesMock; use openzeppelin_testing::constants::OWNER; diff --git a/packages/utils/src/tests/test_snip12.cairo b/packages/utils/src/tests/test_snip12.cairo index c9ba73238..2ed399e1b 100644 --- a/packages/utils/src/tests/test_snip12.cairo +++ b/packages/utils/src/tests/test_snip12.cairo @@ -1,7 +1,7 @@ -use core::hash::{HashStateTrait, HashStateExTrait}; +use core::hash::{HashStateExTrait, HashStateTrait}; use core::poseidon::{PoseidonTrait, poseidon_hash_span}; use crate::cryptography::snip12::{ - STARKNET_DOMAIN_TYPE_HASH, StarknetDomain, StructHash, OffchainMessageHashImpl, SNIP12Metadata + OffchainMessageHashImpl, SNIP12Metadata, STARKNET_DOMAIN_TYPE_HASH, StarknetDomain, StructHash, }; use openzeppelin_testing::constants::{OWNER, RECIPIENT}; use snforge_std::{start_cheat_chain_id, test_address}; @@ -15,7 +15,7 @@ struct Message { recipient: ContractAddress, amount: u256, nonce: felt252, - expiry: u64 + expiry: u64, } impl StructHashImpl of StructHash { @@ -37,7 +37,7 @@ impl SNIP12MetadataImpl of SNIP12Metadata { #[test] fn test_starknet_domain_type_hash() { let expected = selector!( - "\"StarknetDomain\"(\"name\":\"shortstring\",\"version\":\"shortstring\",\"chainId\":\"shortstring\",\"revision\":\"shortstring\")" + "\"StarknetDomain\"(\"name\":\"shortstring\",\"version\":\"shortstring\",\"chainId\":\"shortstring\",\"revision\":\"shortstring\")", ); assert_eq!(STARKNET_DOMAIN_TYPE_HASH, expected); } @@ -48,9 +48,13 @@ fn test_StructHashStarknetDomainImpl() { let expected = poseidon_hash_span( array![ - STARKNET_DOMAIN_TYPE_HASH, domain.name, domain.version, domain.chain_id, domain.revision + STARKNET_DOMAIN_TYPE_HASH, + domain.name, + domain.version, + domain.chain_id, + domain.revision, ] - .span() + .span(), ); assert_eq!(domain.hash_struct(), expected); } @@ -65,7 +69,7 @@ fn test_OffchainMessageHashImpl() { let expected = poseidon_hash_span( array!['StarkNet Message', domain.hash_struct(), OWNER().into(), message.hash_struct()] - .span() + .span(), ); assert_eq!(message.get_message_hash(OWNER()), expected); } diff --git a/sncast_scripts/src/declare_presets.cairo b/sncast_scripts/src/declare_presets.cairo index f10355ec2..28a2273af 100644 --- a/sncast_scripts/src/declare_presets.cairo +++ b/sncast_scripts/src/declare_presets.cairo @@ -1,5 +1,5 @@ use openzeppelin_testing::common::IntoBase16String; -use sncast_std::{declare, get_nonce, FeeSettings, EthFeeSettings}; +use sncast_std::{EthFeeSettings, FeeSettings, declare, get_nonce}; const MAX_FEE: felt252 = 99_999_999_999_999_999; @@ -10,7 +10,7 @@ fn main() { "ERC721Upgradeable", "ERC1155Upgradeable", "EthAccountUpgradeable", - "VestingWallet" + "VestingWallet", ]; let mut consumed_latest_nonce = false; @@ -35,13 +35,13 @@ fn declare_preset(contract: ByteArray, nonce: felt252) { let declare_result = declare( contract, FeeSettings::Eth(EthFeeSettings { max_fee: Option::Some(MAX_FEE) }), - Option::Some(nonce) + Option::Some(nonce), ); // Print output // Note that the tx hash will already display from the declaration match declare_result { Result::Ok(r) => println!("Class hash = {}", r.class_hash.into_base_16_string()), - Result::Err(r) => println!("{:?}", r) + Result::Err(r) => println!("{:?}", r), } }