diff --git a/src/extensions/metadata/module.cairo b/src/extensions/metadata/module.cairo index 44ef557..2de5d13 100644 --- a/src/extensions/metadata/module.cairo +++ b/src/extensions/metadata/module.cairo @@ -9,7 +9,9 @@ mod ERC3525MetadataComponent { use openzeppelin::introspection::src5::SRC5Component; // Local deps - use cairo_erc_3525::extensions::metadata::interface::{IERC3525_METADATA_ID, IERC3525Metadata, IERC3525MetadataCamelOnly}; + use cairo_erc_3525::extensions::metadata::interface::{ + IERC3525_METADATA_ID, IERC3525Metadata, IERC3525MetadataCamelOnly + }; #[storage] struct Storage { diff --git a/src/extensions/slotapprovable/module.cairo b/src/extensions/slotapprovable/module.cairo index cc35d98..508fe78 100644 --- a/src/extensions/slotapprovable/module.cairo +++ b/src/extensions/slotapprovable/module.cairo @@ -73,7 +73,9 @@ mod ERC3525SlotApprovableComponent { // [Check] Caller is owner or approved for all let erc721_comp = get_dep_component!(@self, ERC721Comp); let is_approved_for_all = erc721_comp.is_approved_for_all(operator, owner); - assert(caller == owner || is_approved_for_all, ERC3525Component::Errors::CALLER_NOT_ALLOWED); + assert( + caller == owner || is_approved_for_all, ERC3525Component::Errors::CALLER_NOT_ALLOWED + ); // [Check] No self approval assert(caller != operator, Errors::SELF_APPROVAL); @@ -86,7 +88,10 @@ mod ERC3525SlotApprovableComponent { } fn is_approved_for_slot( - self: @ComponentState, owner: ContractAddress, slot: u256, operator: ContractAddress + self: @ComponentState, + owner: ContractAddress, + slot: u256, + operator: ContractAddress ) -> bool { self._erc3525_slot_approvals.read((owner, slot, operator)) } @@ -112,7 +117,10 @@ mod ERC3525SlotApprovableComponent { } fn isApprovedForSlot( - self: @ComponentState, owner: ContractAddress, slot: u256, operator: ContractAddress + self: @ComponentState, + owner: ContractAddress, + slot: u256, + operator: ContractAddress ) -> bool { self.is_approved_for_slot(owner, slot, operator) } @@ -139,7 +147,10 @@ mod ERC3525SlotApprovableComponent { } fn approve_value( - ref self: ComponentState, token_id: u256, operator: ContractAddress, value: u256 + ref self: ComponentState, + token_id: u256, + operator: ContractAddress, + value: u256 ) { // [Check] Caller and operator are not null addresses let caller = get_caller_address(); @@ -172,7 +183,8 @@ mod ERC3525SlotApprovableComponent { // [Check] Disambiguate function call: only one of `to_token_id` and `to` must be set assert( - to_token_id == 0.into() || to.is_zero(), ERC3525Component::Errors::INVALID_EXCLUSIVE_ARGS + to_token_id == 0.into() || to.is_zero(), + ERC3525Component::Errors::INVALID_EXCLUSIVE_ARGS ); // [Effect] Spend allowance if possible @@ -184,19 +196,13 @@ mod ERC3525SlotApprovableComponent { // Into felt252 works match token_id { // If token_id is zero, transfer value to address - 0 => erc3525_comp._transfer_value_to( - from_token_id, to, value - ), + 0 => erc3525_comp._transfer_value_to(from_token_id, to, value), // Otherwise, transfer value to token - _ => erc3525_comp._transfer_value_to_token( - from_token_id, to_token_id, value - ), + _ => erc3525_comp._transfer_value_to_token(from_token_id, to_token_id, value), } } else { // Into felt252 fails, so token_id is not zero - erc3525_comp._transfer_value_to_token( - from_token_id, to_token_id, value - ) + erc3525_comp._transfer_value_to_token(from_token_id, to_token_id, value) } } } @@ -217,14 +223,15 @@ mod ERC3525SlotApprovableComponent { } fn _spend_allowance( - ref self: ComponentState, spender: ContractAddress, token_id: u256, value: u256 + ref self: ComponentState, + spender: ContractAddress, + token_id: u256, + value: u256 ) { // [Compute] Spender allowance let is_approved = self._is_allowed(spender, token_id); let mut erc3525_comp = get_dep_component_mut!(ref self, ERC3525Comp); - let current_allowance = erc3525_comp.allowance( - token_id, spender - ); + let current_allowance = erc3525_comp.allowance(token_id, spender); let infinity: u256 = BoundedInt::max(); // [Effect] Update allowance if the rights are limited @@ -233,18 +240,16 @@ mod ERC3525SlotApprovableComponent { } assert(current_allowance >= value, ERC3525Component::Errors::INSUFFICIENT_ALLOWANCE); let new_allowance = current_allowance - value; - erc3525_comp._approve_value( - token_id, spender, new_allowance - ); + erc3525_comp._approve_value(token_id, spender, new_allowance); } - fn _is_allowed(self: @ComponentState, operator: ContractAddress, token_id: u256) -> bool { + fn _is_allowed( + self: @ComponentState, operator: ContractAddress, token_id: u256 + ) -> bool { // [Compute] Operator is owner or approved for all let erc721_comp = get_dep_component!(self, ERC721Comp); let owner = erc721_comp.owner_of(token_id); - let is_owner_or_approved = erc721_comp._is_approved_or_owner( - operator, token_id - ); + let is_owner_or_approved = erc721_comp._is_approved_or_owner(operator, token_id); // [Compute] Operator is approved for slot let erc3525_comp = get_dep_component!(self, ERC3525Comp); @@ -265,9 +270,13 @@ mod ERC3525SlotApprovableComponent { impl SRC5: SRC5Component::HasComponent, impl ERC721Comp: ERC721Component::HasComponent > of AssertTrait { - fn _assert_allowed(self: @ComponentState, operator: ContractAddress, token_id: u256) { + fn _assert_allowed( + self: @ComponentState, operator: ContractAddress, token_id: u256 + ) { // [Check] Operator is allowed - assert(self._is_allowed(operator, token_id), ERC3525Component::Errors::CALLER_NOT_ALLOWED); + assert( + self._is_allowed(operator, token_id), ERC3525Component::Errors::CALLER_NOT_ALLOWED + ); } } } diff --git a/src/extensions/slotenumerable/module.cairo b/src/extensions/slotenumerable/module.cairo index c62ee73..bd3a556 100644 --- a/src/extensions/slotenumerable/module.cairo +++ b/src/extensions/slotenumerable/module.cairo @@ -61,7 +61,9 @@ mod ERC3525SlotEnumerableComponent { fn token_supply_in_slot(self: @ComponentState, slot: u256) -> u256 { self._erc3525_slot_tokens_len.read(slot) } - fn token_in_slot_by_index(self: @ComponentState, slot: u256, index: u256) -> u256 { + fn token_in_slot_by_index( + self: @ComponentState, slot: u256, index: u256 + ) -> u256 { // [Check] Index is in range let supply = self._erc3525_slot_tokens_len.read(slot); assert(index < supply, Errors::INDEX_OUT_OF_BOUNDS); @@ -87,7 +89,9 @@ mod ERC3525SlotEnumerableComponent { fn tokenSupplyInSlot(self: @ComponentState, slot: u256) -> u256 { self.token_supply_in_slot(slot) } - fn tokenInSlotByIndex(self: @ComponentState, slot: u256, index: u256) -> u256 { + fn tokenInSlotByIndex( + self: @ComponentState, slot: u256, index: u256 + ) -> u256 { self.token_in_slot_by_index(slot, index) } } @@ -112,7 +116,9 @@ mod ERC3525SlotEnumerableComponent { self._erc3525_slot_enumerables.read(index) == slot && slot != 0 } - fn _token_exists(self: @ComponentState, slot: u256, token_id: u256) -> bool { + fn _token_exists( + self: @ComponentState, slot: u256, token_id: u256 + ) -> bool { let index = self._erc3525_slot_tokens_index.read((slot, token_id)); self._erc3525_slot_tokens.read((slot, index)) == token_id && token_id != 0 } @@ -148,7 +154,11 @@ mod ERC3525SlotEnumerableComponent { } fn _mint( - ref self: ComponentState, to: ContractAddress, token_id: u256, slot: u256, value: u256 + ref self: ComponentState, + to: ContractAddress, + token_id: u256, + slot: u256, + value: u256 ) { // [Effect] Mint let mut erc3525_comp = get_dep_component_mut!(ref self, ERC3525Comp); @@ -182,7 +192,9 @@ mod ERC3525SlotEnumerableComponent { self._erc3525_slot_enumerables_index.write(slot, index); } - fn _add_token_to_slot_enumeration(ref self: ComponentState, slot: u256, token_id: u256) { + fn _add_token_to_slot_enumeration( + ref self: ComponentState, slot: u256, token_id: u256 + ) { // [Effect] Store new token let index = self._erc3525_slot_tokens_len.read(slot); self._erc3525_slot_tokens_len.write(slot, index + 1); diff --git a/src/module.cairo b/src/module.cairo index 9d6dd57..6dec880 100644 --- a/src/module.cairo +++ b/src/module.cairo @@ -117,7 +117,10 @@ mod ERC3525Component { } fn approve_value( - ref self: ComponentState, token_id: u256, operator: ContractAddress, value: u256 + ref self: ComponentState, + token_id: u256, + operator: ContractAddress, + value: u256 ) { // [Check] Caller and operator are not null addresses let caller = get_caller_address(); @@ -128,16 +131,15 @@ mod ERC3525Component { let erc721_comp = get_dep_component!(@self, ERC721); let owner = erc721_comp.owner_of(token_id); assert(owner != operator, Errors::APPROVAL_TO_OWNER); - assert( - erc721_comp._is_approved_or_owner(caller, token_id), - Errors::CALLER_NOT_ALLOWED - ); + assert(erc721_comp._is_approved_or_owner(caller, token_id), Errors::CALLER_NOT_ALLOWED); // [Effect] Store approved value self._approve_value(token_id, operator, value); } - fn allowance(self: @ComponentState, token_id: u256, operator: ContractAddress) -> u256 { + fn allowance( + self: @ComponentState, token_id: u256, operator: ContractAddress + ) -> u256 { // [Check] let erc721_comp = get_dep_component!(self, ERC721); let owner = erc721_comp.owner_of(token_id); @@ -200,7 +202,10 @@ mod ERC3525Component { ERC3525::slot_of(self, tokenId) } fn approveValue( - ref self: ComponentState, tokenId: u256, operator: ContractAddress, value: u256 + ref self: ComponentState, + tokenId: u256, + operator: ContractAddress, + value: u256 ) { ERC3525::approve_value(ref self, tokenId, operator, value) } @@ -241,7 +246,10 @@ mod ERC3525Component { } fn _approve_value( - ref self: ComponentState, token_id: u256, operator: ContractAddress, value: u256 + ref self: ComponentState, + token_id: u256, + operator: ContractAddress, + value: u256 ) { // [Effect] Store approved value let erc721_comp = get_dep_component!(@self, ERC721); @@ -253,7 +261,10 @@ mod ERC3525Component { } fn _transfer_value_to( - ref self: ComponentState, from_token_id: u256, to: ContractAddress, value: u256 + ref self: ComponentState, + from_token_id: u256, + to: ContractAddress, + value: u256 ) -> u256 { // [Effect] Mint new token and transfer value let token_id = self._get_new_token_id(); @@ -264,7 +275,10 @@ mod ERC3525Component { } fn _transfer_value_to_token( - ref self: ComponentState, from_token_id: u256, to_token_id: u256, value: u256 + ref self: ComponentState, + from_token_id: u256, + to_token_id: u256, + value: u256 ) -> u256 { // [Effect] Transfer value self._transfer_value(from_token_id, to_token_id, value); @@ -272,16 +286,17 @@ mod ERC3525Component { } fn _spend_allowance( - ref self: ComponentState, spender: ContractAddress, token_id: u256, value: u256 + ref self: ComponentState, + spender: ContractAddress, + token_id: u256, + value: u256 ) { // [Compute] Spender allowance let erc721_comp = get_dep_component!(@self, ERC721); let owner = erc721_comp.owner_of(token_id); let current_allowance = self._erc3525_approved_values.read((owner, token_id, spender)); let infinity: u256 = BoundedInt::max(); - let is_approved = erc721_comp._is_approved_or_owner( - spender, token_id - ); + let is_approved = erc721_comp._is_approved_or_owner(spender, token_id); // [Effect] Update allowance if the rights are limited if current_allowance == infinity || is_approved { @@ -302,7 +317,11 @@ mod ERC3525Component { } fn _mint( - ref self: ComponentState, to: ContractAddress, token_id: u256, slot: u256, value: u256 + ref self: ComponentState, + to: ContractAddress, + token_id: u256, + slot: u256, + value: u256 ) { // [Check] Token id not already exists self._assert_not_minted(token_id); @@ -317,7 +336,12 @@ mod ERC3525Component { self._mint_value(token_id, value); } - fn _mint_token(ref self: ComponentState, to: ContractAddress, token_id: u256, slot: u256) { + fn _mint_token( + ref self: ComponentState, + to: ContractAddress, + token_id: u256, + slot: u256 + ) { // [Effect] Mint a new enumerable token if supported, standard token otherwise let mut erc721_comp = get_dep_component_mut!(ref self, ERC721); erc721_comp._mint(to, token_id); @@ -349,7 +373,10 @@ mod ERC3525Component { } fn _transfer_value( - ref self: ComponentState, from_token_id: u256, to_token_id: u256, value: u256 + ref self: ComponentState, + from_token_id: u256, + to_token_id: u256, + value: u256 ) { // [Check] Tokens exist and not null self._assert_minted(from_token_id); @@ -445,7 +472,9 @@ mod ERC3525Component { contract.supports_interface(ISRC6_ID) } - fn _split(ref self: ComponentState, token_id: u256, amounts: @Array) -> Array { + fn _split( + ref self: ComponentState, token_id: u256, amounts: @Array + ) -> Array { // [Check] Token exists self._assert_minted(token_id); diff --git a/src/presets/erc3525_mintable_burnable.cairo b/src/presets/erc3525_mintable_burnable.cairo index aedcebd..68eba03 100644 --- a/src/presets/erc3525_mintable_burnable.cairo +++ b/src/presets/erc3525_mintable_burnable.cairo @@ -36,7 +36,8 @@ mod ERC3525MintableBurnable { #[abi(embed_v0)] impl ERC3525Impl = ERC3525Component::ERC3525Impl; #[abi(embed_v0)] - impl ERC3525CamelOnlyImpl = ERC3525Component::ERC3525CamelOnlyImpl; + impl ERC3525CamelOnlyImpl = + ERC3525Component::ERC3525CamelOnlyImpl; impl ERC3525InternalImpl = ERC3525Component::InternalImpl; #[storage] diff --git a/src/presets/erc3525_mintable_burnable_metadata.cairo b/src/presets/erc3525_mintable_burnable_metadata.cairo index 62f0a8b..0fc1b4c 100644 --- a/src/presets/erc3525_mintable_burnable_metadata.cairo +++ b/src/presets/erc3525_mintable_burnable_metadata.cairo @@ -41,7 +41,9 @@ mod ERC3525MintableBurnableMetadata { component!(path: SRC5Component, storage: src5, event: SRC5Event); component!(path: ERC721Component, storage: erc721, event: ERC721Event); component!(path: ERC3525Component, storage: erc3525, event: ERC3525Event); - component!(path: ERC3525MetadataComponent, storage: erc3525_metadata, event: ERC3525MetadataEvent); + component!( + path: ERC3525MetadataComponent, storage: erc3525_metadata, event: ERC3525MetadataEvent + ); // Component implementations #[abi(embed_v0)] @@ -50,12 +52,15 @@ mod ERC3525MintableBurnableMetadata { #[abi(embed_v0)] impl ERC3525Impl = ERC3525Component::ERC3525Impl; #[abi(embed_v0)] - impl ERC3525CamelOnlyImpl = ERC3525Component::ERC3525CamelOnlyImpl; + impl ERC3525CamelOnlyImpl = + ERC3525Component::ERC3525CamelOnlyImpl; impl ERC3525InternalImpl = ERC3525Component::InternalImpl; #[abi(embed_v0)] - impl ERC3525MetadataImpl = ERC3525MetadataComponent::ERC3525MetadataImpl; + impl ERC3525MetadataImpl = + ERC3525MetadataComponent::ERC3525MetadataImpl; #[abi(embed_v0)] - impl ERC3525MetadataCamelOnlyImpl = ERC3525MetadataComponent::ERC3525MetadataCamelOnlyImpl; + impl ERC3525MetadataCamelOnlyImpl = + ERC3525MetadataComponent::ERC3525MetadataCamelOnlyImpl; impl ERC3525MetadataInternalImpl = ERC3525MetadataComponent::InternalImpl; #[storage] @@ -84,7 +89,13 @@ mod ERC3525MintableBurnableMetadata { } #[constructor] - fn constructor(ref self: ContractState, name: ByteArray, symbol: ByteArray, base_uri: ByteArray, value_decimals: u8) { + fn constructor( + ref self: ContractState, + name: ByteArray, + symbol: ByteArray, + base_uri: ByteArray, + value_decimals: u8 + ) { self.initializer(name, symbol, base_uri, value_decimals); } @@ -134,7 +145,11 @@ mod ERC3525MintableBurnableMetadata { #[generate_trait] impl InternalImpl of InternalTrait { fn initializer( - ref self: ContractState, name: ByteArray, symbol: ByteArray, base_uri: ByteArray, value_decimals: u8 + ref self: ContractState, + name: ByteArray, + symbol: ByteArray, + base_uri: ByteArray, + value_decimals: u8 ) { self.erc721.initializer(name, symbol, base_uri); self.erc3525.initializer(value_decimals); diff --git a/src/presets/erc3525_mintable_burnable_metadata_slot_approvable.cairo b/src/presets/erc3525_mintable_burnable_metadata_slot_approvable.cairo index b7becfb..fb5d16c 100644 --- a/src/presets/erc3525_mintable_burnable_metadata_slot_approvable.cairo +++ b/src/presets/erc3525_mintable_burnable_metadata_slot_approvable.cairo @@ -47,8 +47,14 @@ mod ERC3525MintableBurnableMSA { component!(path: SRC5Component, storage: src5, event: SRC5Event); component!(path: ERC721Component, storage: erc721, event: ERC721Event); component!(path: ERC3525Component, storage: erc3525, event: ERC3525Event); - component!(path: ERC3525MetadataComponent, storage: erc3525_metadata, event: ERC3525MetadataEvent); - component!(path: ERC3525SlotApprovableComponent, storage: erc3525_slot_approvable, event: ERC3525SlotApprovableEvent); + component!( + path: ERC3525MetadataComponent, storage: erc3525_metadata, event: ERC3525MetadataEvent + ); + component!( + path: ERC3525SlotApprovableComponent, + storage: erc3525_slot_approvable, + event: ERC3525SlotApprovableEvent + ); // Component implementations #[abi(embed_v0)] @@ -58,20 +64,27 @@ mod ERC3525MintableBurnableMSA { #[abi(embed_v0)] impl ERC721MetadataImpl = ERC721Component::ERC721MetadataImpl; #[abi(embed_v0)] - impl ERC721MetadataCamelOnlyImpl = ERC721Component::ERC721MetadataCamelOnlyImpl; + impl ERC721MetadataCamelOnlyImpl = + ERC721Component::ERC721MetadataCamelOnlyImpl; impl ERC721InternalImpl = ERC721Component::InternalImpl; impl ERC3525InternalImpl = ERC3525Component::InternalImpl; #[abi(embed_v0)] - impl ERC3525MetadataImpl = ERC3525MetadataComponent::ERC3525MetadataImpl; + impl ERC3525MetadataImpl = + ERC3525MetadataComponent::ERC3525MetadataImpl; impl ERC3525MetadataInternalImpl = ERC3525MetadataComponent::InternalImpl; #[abi(embed_v0)] - impl ERC3525MetadataCamelOnlyImpl = ERC3525MetadataComponent::ERC3525MetadataCamelOnlyImpl; + impl ERC3525MetadataCamelOnlyImpl = + ERC3525MetadataComponent::ERC3525MetadataCamelOnlyImpl; #[abi(embed_v0)] - impl ERC3525SlotApprovableImpl = ERC3525SlotApprovableComponent::ERC3525SlotApprovableImpl; - impl ERC3525SlotApprovableInternalImpl = ERC3525SlotApprovableComponent::InternalImpl; + impl ERC3525SlotApprovableImpl = + ERC3525SlotApprovableComponent::ERC3525SlotApprovableImpl; + impl ERC3525SlotApprovableInternalImpl = + ERC3525SlotApprovableComponent::InternalImpl; #[abi(embed_v0)] - impl ERC3525SlotApprovableCamelOnlyImpl = ERC3525SlotApprovableComponent::ERC3525SlotApprovableCamelOnlyImpl; - impl ERC3525SlotApprovableExternalImpl = ERC3525SlotApprovableComponent::ExternalImpl; + impl ERC3525SlotApprovableCamelOnlyImpl = + ERC3525SlotApprovableComponent::ERC3525SlotApprovableCamelOnlyImpl; + impl ERC3525SlotApprovableExternalImpl = + ERC3525SlotApprovableComponent::ExternalImpl; #[storage] @@ -104,7 +117,13 @@ mod ERC3525MintableBurnableMSA { } #[constructor] - fn constructor(ref self: ContractState, name: ByteArray, symbol: ByteArray, base_uri: ByteArray, value_decimals: u8) { + fn constructor( + ref self: ContractState, + name: ByteArray, + symbol: ByteArray, + base_uri: ByteArray, + value_decimals: u8 + ) { self.initializer(name, symbol, base_uri, value_decimals); } @@ -311,7 +330,11 @@ mod ERC3525MintableBurnableMSA { #[generate_trait] impl InternalImpl of InternalTrait { fn initializer( - ref self: ContractState, name: ByteArray, symbol: ByteArray, base_uri: ByteArray, value_decimals: u8 + ref self: ContractState, + name: ByteArray, + symbol: ByteArray, + base_uri: ByteArray, + value_decimals: u8 ) { self.erc721.initializer(name, symbol, base_uri); self.erc3525.initializer(value_decimals); diff --git a/src/presets/erc3525_mintable_burnable_metadata_slot_approvable_slot_enumerable.cairo b/src/presets/erc3525_mintable_burnable_metadata_slot_approvable_slot_enumerable.cairo index 1d9cc42..6abf52d 100644 --- a/src/presets/erc3525_mintable_burnable_metadata_slot_approvable_slot_enumerable.cairo +++ b/src/presets/erc3525_mintable_burnable_metadata_slot_approvable_slot_enumerable.cairo @@ -53,9 +53,19 @@ mod ERC3525MintableBurnableMSASE { component!(path: SRC5Component, storage: src5, event: SRC5Event); component!(path: ERC721Component, storage: erc721, event: ERC721Event); component!(path: ERC3525Component, storage: erc3525, event: ERC3525Event); - component!(path: ERC3525MetadataComponent, storage: erc3525_metadata, event: ERC3525MetadataEvent); - component!(path: ERC3525SlotApprovableComponent, storage: erc3525_slot_approvable, event: ERC3525SlotApprovableEvent); - component!(path: ERC3525SlotEnumerableComponent, storage: erc3525_slot_enumerable, event: ERC3525SlotEnumerableEvent); + component!( + path: ERC3525MetadataComponent, storage: erc3525_metadata, event: ERC3525MetadataEvent + ); + component!( + path: ERC3525SlotApprovableComponent, + storage: erc3525_slot_approvable, + event: ERC3525SlotApprovableEvent + ); + component!( + path: ERC3525SlotEnumerableComponent, + storage: erc3525_slot_enumerable, + event: ERC3525SlotEnumerableEvent + ); // Component implementations #[abi(embed_v0)] @@ -63,21 +73,30 @@ mod ERC3525MintableBurnableMSASE { impl ERC721InternalImpl = ERC721Component::InternalImpl; impl ERC3525InternalImpl = ERC3525Component::InternalImpl; #[abi(embed_v0)] - impl ERC3525MetadataImpl = ERC3525MetadataComponent::ERC3525MetadataImpl; + impl ERC3525MetadataImpl = + ERC3525MetadataComponent::ERC3525MetadataImpl; #[abi(embed_v0)] - impl ERC3525MetadataCamelOnlyImpl = ERC3525MetadataComponent::ERC3525MetadataCamelOnlyImpl; + impl ERC3525MetadataCamelOnlyImpl = + ERC3525MetadataComponent::ERC3525MetadataCamelOnlyImpl; impl ERC3525MetadataInternalImpl = ERC3525MetadataComponent::InternalImpl; #[abi(embed_v0)] - impl ERC3525SlotApprovableImpl = ERC3525SlotApprovableComponent::ERC3525SlotApprovableImpl; + impl ERC3525SlotApprovableImpl = + ERC3525SlotApprovableComponent::ERC3525SlotApprovableImpl; #[abi(embed_v0)] - impl ERC3525SlotApprovableCamelOnlyImpl = ERC3525SlotApprovableComponent::ERC3525SlotApprovableCamelOnlyImpl; - impl ERC3525SlotApprovableInternalImpl = ERC3525SlotApprovableComponent::InternalImpl; - impl ERC3525SlotApprovableExternalImpl = ERC3525SlotApprovableComponent::ExternalImpl; + impl ERC3525SlotApprovableCamelOnlyImpl = + ERC3525SlotApprovableComponent::ERC3525SlotApprovableCamelOnlyImpl; + impl ERC3525SlotApprovableInternalImpl = + ERC3525SlotApprovableComponent::InternalImpl; + impl ERC3525SlotApprovableExternalImpl = + ERC3525SlotApprovableComponent::ExternalImpl; #[abi(embed_v0)] - impl ERC3525SlotEnumerableImpl = ERC3525SlotEnumerableComponent::ERC3525SlotEnumerableImpl; + impl ERC3525SlotEnumerableImpl = + ERC3525SlotEnumerableComponent::ERC3525SlotEnumerableImpl; #[abi(embed_v0)] - impl ERC3525SlotEnumerableCamelOnlyImpl = ERC3525SlotEnumerableComponent::ERC3525SlotEnumerableCamelOnlyImpl; - impl ERC3525SlotEnumerableInternalImpl = ERC3525SlotEnumerableComponent::InternalImpl; + impl ERC3525SlotEnumerableCamelOnlyImpl = + ERC3525SlotEnumerableComponent::ERC3525SlotEnumerableCamelOnlyImpl; + impl ERC3525SlotEnumerableInternalImpl = + ERC3525SlotEnumerableComponent::InternalImpl; #[storage] struct Storage { @@ -114,7 +133,13 @@ mod ERC3525MintableBurnableMSASE { #[constructor] - fn constructor(ref self: ContractState, name: ByteArray, symbol: ByteArray, base_uri: ByteArray, value_decimals: u8) { + fn constructor( + ref self: ContractState, + name: ByteArray, + symbol: ByteArray, + base_uri: ByteArray, + value_decimals: u8 + ) { self.initializer(name, symbol, base_uri, value_decimals); } @@ -150,9 +175,9 @@ mod ERC3525MintableBurnableMSASE { value: u256 ) -> u256 { // Overwrite ERC3525 Impl with ERC3525 SlotApprovable Impl - let token_id = self.erc3525_slot_approvable.transfer_value_from( - from_token_id, to_token_id, to, value - ); + let token_id = self + .erc3525_slot_approvable + .transfer_value_from(from_token_id, to_token_id, to, value); self.erc3525_slot_enumerable._after_transfer_value_from(token_id); token_id } @@ -235,7 +260,11 @@ mod ERC3525MintableBurnableMSASE { #[generate_trait] impl InternalImpl of InternalTrait { fn initializer( - ref self: ContractState, name: ByteArray, symbol: ByteArray, base_uri: ByteArray, value_decimals: u8 + ref self: ContractState, + name: ByteArray, + symbol: ByteArray, + base_uri: ByteArray, + value_decimals: u8 ) { self.erc721.initializer(name, symbol, base_uri); self.erc3525.initializer(value_decimals); diff --git a/src/tests/integration/constants.cairo b/src/tests/integration/constants.cairo index 0c11f1d..09499e5 100644 --- a/src/tests/integration/constants.cairo +++ b/src/tests/integration/constants.cairo @@ -54,4 +54,4 @@ fn SYMBOL() -> ByteArray { fn BASE_URI() -> ByteArray { "BASE_URI" -} \ No newline at end of file +} diff --git a/src/tests/mocks/contracts.cairo b/src/tests/mocks/contracts.cairo index 237f9ed..cccee78 100644 --- a/src/tests/mocks/contracts.cairo +++ b/src/tests/mocks/contracts.cairo @@ -77,7 +77,9 @@ mod DualCaseERC3525MetadataMock { component!(path: ERC721Component, storage: erc721, event: ERC721Event); component!(path: SRC5Component, storage: src5, event: SRC5Event); component!(path: ERC3525Component, storage: erc3525, event: ERC3525Event); - component!(path: ERC3525MetadataComponent, storage: erc3525_metadata, event: ERC3525MetadataEvent); + component!( + path: ERC3525MetadataComponent, storage: erc3525_metadata, event: ERC3525MetadataEvent + ); // ERC721 #[abi(embed_v0)] @@ -103,9 +105,11 @@ mod DualCaseERC3525MetadataMock { // ERC3525Metadata #[abi(embed_v0)] - impl ERC3525MetadataImpl = ERC3525MetadataComponent::ERC3525MetadataImpl; + impl ERC3525MetadataImpl = + ERC3525MetadataComponent::ERC3525MetadataImpl; #[abi(embed_v0)] - impl ERC3525MetadataCamelOnlyImpl = ERC3525MetadataComponent::ERC3525MetadataCamelOnlyImpl; + impl ERC3525MetadataCamelOnlyImpl = + ERC3525MetadataComponent::ERC3525MetadataCamelOnlyImpl; impl ERC3525MetadataInternalImpl = ERC3525MetadataComponent::InternalImpl; #[storage] @@ -159,7 +163,11 @@ mod DualCaseERC3525SlotApprovableMock { component!(path: ERC721Component, storage: erc721, event: ERC721Event); component!(path: SRC5Component, storage: src5, event: SRC5Event); component!(path: ERC3525Component, storage: erc3525, event: ERC3525Event); - component!(path: ERC3525SlotApprovableComponent, storage: erc3525_slot_approvable, event: ERC3525SlotApprovableEvent); + component!( + path: ERC3525SlotApprovableComponent, + storage: erc3525_slot_approvable, + event: ERC3525SlotApprovableEvent + ); // ERC721 #[abi(embed_v0)] @@ -185,10 +193,13 @@ mod DualCaseERC3525SlotApprovableMock { // ERC3525SlotApprovable #[abi(embed_v0)] - impl ERC3525SlotApprovableImpl = ERC3525SlotApprovableComponent::ERC3525SlotApprovableImpl; + impl ERC3525SlotApprovableImpl = + ERC3525SlotApprovableComponent::ERC3525SlotApprovableImpl; #[abi(embed_v0)] - impl ERC3525SlotApprovableCamelOnlyImpl = ERC3525SlotApprovableComponent::ERC3525SlotApprovableCamelOnlyImpl; - impl ERC3525SlotApprovableInternalImpl = ERC3525SlotApprovableComponent::InternalImpl; + impl ERC3525SlotApprovableCamelOnlyImpl = + ERC3525SlotApprovableComponent::ERC3525SlotApprovableCamelOnlyImpl; + impl ERC3525SlotApprovableInternalImpl = + ERC3525SlotApprovableComponent::InternalImpl; #[storage] struct Storage { @@ -241,7 +252,11 @@ mod DualCaseERC3525SlotEnumerableMock { component!(path: ERC721Component, storage: erc721, event: ERC721Event); component!(path: SRC5Component, storage: src5, event: SRC5Event); component!(path: ERC3525Component, storage: erc3525, event: ERC3525Event); - component!(path: ERC3525SlotEnumerableComponent, storage: erc3525_slot_enumerable, event: ERC3525SlotEnumerableEvent); + component!( + path: ERC3525SlotEnumerableComponent, + storage: erc3525_slot_enumerable, + event: ERC3525SlotEnumerableEvent + ); // ERC721 #[abi(embed_v0)] @@ -267,10 +282,13 @@ mod DualCaseERC3525SlotEnumerableMock { // ERC3525SlotEnumerable #[abi(embed_v0)] - impl ERC3525SlotEnumerableImpl = ERC3525SlotEnumerableComponent::ERC3525SlotEnumerableImpl; + impl ERC3525SlotEnumerableImpl = + ERC3525SlotEnumerableComponent::ERC3525SlotEnumerableImpl; #[abi(embed_v0)] - impl ERC3525SlotEnumerableCamelOnlyImpl = ERC3525SlotEnumerableComponent::ERC3525SlotEnumerableCamelOnlyImpl; - impl ERC3525SlotEnumerableInternalImpl = ERC3525SlotEnumerableComponent::InternalImpl; + impl ERC3525SlotEnumerableCamelOnlyImpl = + ERC3525SlotEnumerableComponent::ERC3525SlotEnumerableCamelOnlyImpl; + impl ERC3525SlotEnumerableInternalImpl = + ERC3525SlotEnumerableComponent::InternalImpl; #[storage] struct Storage { diff --git a/src/tests/unit/constants.cairo b/src/tests/unit/constants.cairo index 0549235..9afb714 100644 --- a/src/tests/unit/constants.cairo +++ b/src/tests/unit/constants.cairo @@ -14,15 +14,24 @@ use cairo_erc_3525::extensions::metadata::module::ERC3525MetadataComponent; use cairo_erc_3525::extensions::slotapprovable::module::ERC3525SlotApprovableComponent; use cairo_erc_3525::extensions::slotenumerable::module::ERC3525SlotEnumerableComponent; use cairo_erc_3525::tests::mocks::contracts::{ - DualCaseERC3525Mock, DualCaseERC3525MetadataMock, DualCaseERC3525SlotApprovableMock, DualCaseERC3525SlotEnumerableMock + DualCaseERC3525Mock, DualCaseERC3525MetadataMock, DualCaseERC3525SlotApprovableMock, + DualCaseERC3525SlotEnumerableMock }; // Setup -pub type ERC3525ComponentState = ERC3525Component::ComponentState; -pub type ERC3525MetadataComponentState = ERC3525MetadataComponent::ComponentState; -pub type ERC3525SlotApprovableComponentState = ERC3525SlotApprovableComponent::ComponentState; -pub type ERC3525SlotEnumerableComponentState = ERC3525SlotEnumerableComponent::ComponentState; +pub type ERC3525ComponentState = + ERC3525Component::ComponentState; +pub type ERC3525MetadataComponentState = + ERC3525MetadataComponent::ComponentState; +pub type ERC3525SlotApprovableComponentState = + ERC3525SlotApprovableComponent::ComponentState< + DualCaseERC3525SlotApprovableMock::ContractState + >; +pub type ERC3525SlotEnumerableComponentState = + ERC3525SlotEnumerableComponent::ComponentState< + DualCaseERC3525SlotEnumerableMock::ContractState + >; // State diff --git a/src/tests/unit/test_approvals.cairo b/src/tests/unit/test_approvals.cairo index 5a0771c..bc59421 100644 --- a/src/tests/unit/test_approvals.cairo +++ b/src/tests/unit/test_approvals.cairo @@ -12,9 +12,8 @@ use openzeppelin::token::erc721::erc721::ERC721Component; use cairo_erc_3525::module::ERC3525Component::{ERC3525Impl, InternalImpl}; use cairo_erc_3525::module::ERC3525Component; use cairo_erc_3525::tests::unit::constants::{ - ERC3525ComponentState, - COMPONENT_STATE, CONTRACT_STATE, VALUE_DECIMALS, TOKEN_ID_1, INVALID_TOKEN, SLOT_1, VALUE, ZERO, OWNER, OPERATOR, SOMEONE, - ANYONE + ERC3525ComponentState, COMPONENT_STATE, CONTRACT_STATE, VALUE_DECIMALS, TOKEN_ID_1, + INVALID_TOKEN, SLOT_1, VALUE, ZERO, OWNER, OPERATOR, SOMEONE, ANYONE }; // Settings diff --git a/src/tests/unit/test_metadata.cairo b/src/tests/unit/test_metadata.cairo index 9ee2b59..44a0ab3 100644 --- a/src/tests/unit/test_metadata.cairo +++ b/src/tests/unit/test_metadata.cairo @@ -16,11 +16,13 @@ use openzeppelin::presets::Account; // Local imports use cairo_erc_3525::module::ERC3525Component; -use cairo_erc_3525::extensions::metadata::module::ERC3525MetadataComponent::{ ERC3525MetadataImpl, InternalImpl }; +use cairo_erc_3525::extensions::metadata::module::ERC3525MetadataComponent::{ + ERC3525MetadataImpl, InternalImpl +}; use cairo_erc_3525::extensions::metadata::module::ERC3525MetadataComponent; use cairo_erc_3525::tests::unit::constants::{ - ERC3525MetadataComponentState, - COMPONENT_STATE, COMPONENT_STATE_METADATA, VALUE_DECIMALS, SLOT_1, SLOT_2 + ERC3525MetadataComponentState, COMPONENT_STATE, COMPONENT_STATE_METADATA, VALUE_DECIMALS, + SLOT_1, SLOT_2 }; // Settings diff --git a/src/tests/unit/test_mint_burn.cairo b/src/tests/unit/test_mint_burn.cairo index d1ed75d..0f7b1af 100644 --- a/src/tests/unit/test_mint_burn.cairo +++ b/src/tests/unit/test_mint_burn.cairo @@ -9,17 +9,19 @@ use starknet::testing::set_caller_address; // External imports -use openzeppelin::token::erc721::erc721::ERC721Component::{ ERC721Impl, InternalImpl as ERC721InternalImpl }; +use openzeppelin::token::erc721::erc721::ERC721Component::{ + ERC721Impl, InternalImpl as ERC721InternalImpl +}; use openzeppelin::token::erc721::erc721::ERC721Component; // Local imports -use cairo_erc_3525::module::ERC3525Component::{ ERC3525Impl, InternalImpl }; +use cairo_erc_3525::module::ERC3525Component::{ERC3525Impl, InternalImpl}; use cairo_erc_3525::module::ERC3525Component; use cairo_erc_3525::tests::utils; use cairo_erc_3525::tests::unit::constants::{ - ERC3525ComponentState, - COMPONENT_STATE, CONTRACT_STATE, VALUE_DECIMALS, TOKEN_ID_1, SLOT_1, VALUE, ZERO, OWNER + ERC3525ComponentState, COMPONENT_STATE, CONTRACT_STATE, VALUE_DECIMALS, TOKEN_ID_1, SLOT_1, + VALUE, ZERO, OWNER }; // Settings @@ -58,11 +60,14 @@ fn test_mint() { }, _ => panic!("Wrong event type"), } - let event = starknet::testing::pop_log::(get_contract_address()).unwrap(); + let event = starknet::testing::pop_log::(get_contract_address()) + .unwrap(); assert(event.token_id == TOKEN_ID_1, 'Wrong event from_token_id'); assert(event.old_slot == 0, 'Wrong event old_slot'); assert(event.new_slot == SLOT_1, 'Wrong new_slot value'); - let event = starknet::testing::pop_log::(get_contract_address()) + let event = starknet::testing::pop_log::< + ERC3525Component::TransferValue + >(get_contract_address()) .unwrap(); assert(event.from_token_id == 0, 'Wrong event from_token_id'); assert(event.to_token_id == TOKEN_ID_1, 'Wrong event to_token_id'); @@ -134,9 +139,13 @@ fn test_burn() { state._burn(TOKEN_ID_1); // [Setup] mint Transfer, SlotChanged and TransferValue events - let _event = starknet::testing::pop_log::(get_contract_address()).unwrap(); - let _event = starknet::testing::pop_log::(get_contract_address()).unwrap(); - let _event = starknet::testing::pop_log::(get_contract_address()) + let _event = starknet::testing::pop_log::(get_contract_address()) + .unwrap(); + let _event = starknet::testing::pop_log::(get_contract_address()) + .unwrap(); + let _event = starknet::testing::pop_log::< + ERC3525Component::TransferValue + >(get_contract_address()) .unwrap(); // [Assert] Events @@ -149,12 +158,15 @@ fn test_burn() { }, _ => panic!("Wrong event type"), } - let event = starknet::testing::pop_log::(get_contract_address()) + let event = starknet::testing::pop_log::< + ERC3525Component::TransferValue + >(get_contract_address()) .unwrap(); assert(event.from_token_id == TOKEN_ID_1, 'Wrong event from_token_id'); assert(event.to_token_id == 0, 'Wrong event to_token_id'); assert(event.value == VALUE, 'Wrong event value'); - let event = starknet::testing::pop_log::(get_contract_address()).unwrap(); + let event = starknet::testing::pop_log::(get_contract_address()) + .unwrap(); assert(event.token_id == TOKEN_ID_1, 'Wrong event from_token_id'); assert(event.old_slot == SLOT_1, 'Wrong event old_slot'); assert(event.new_slot == 0, 'Wrong new_slot value'); @@ -173,13 +185,19 @@ fn test_burn_value() { state._burn_value(TOKEN_ID_1, VALUE); // [Setup] mint Transfer, SlotChanged and TransferValue events - let _event = starknet::testing::pop_log::(get_contract_address()).unwrap(); - let _event = starknet::testing::pop_log::(get_contract_address()).unwrap(); - let _event = starknet::testing::pop_log::(get_contract_address()) + let _event = starknet::testing::pop_log::(get_contract_address()) + .unwrap(); + let _event = starknet::testing::pop_log::(get_contract_address()) + .unwrap(); + let _event = starknet::testing::pop_log::< + ERC3525Component::TransferValue + >(get_contract_address()) .unwrap(); // [Assert] Events - let event = starknet::testing::pop_log::(get_contract_address()) + let event = starknet::testing::pop_log::< + ERC3525Component::TransferValue + >(get_contract_address()) .unwrap(); assert(event.from_token_id == TOKEN_ID_1, 'Wrong event from_token_id'); assert(event.to_token_id == 0, 'Wrong event to_token_id'); diff --git a/src/tests/unit/test_slot_approvable.cairo b/src/tests/unit/test_slot_approvable.cairo index 4ffd642..14aca31 100644 --- a/src/tests/unit/test_slot_approvable.cairo +++ b/src/tests/unit/test_slot_approvable.cairo @@ -12,11 +12,10 @@ use openzeppelin::token::erc721::erc721::ERC721Component; // Local imports -use cairo_erc_3525::module::ERC3525Component::{ InternalTrait, ERC3525Impl }; +use cairo_erc_3525::module::ERC3525Component::{InternalTrait, ERC3525Impl}; use cairo_erc_3525::module::ERC3525Component; use cairo_erc_3525::extensions::slotapprovable::module::ERC3525SlotApprovableComponent::{ - ERC3525SlotApprovableImpl, - InternalTrait as ERC3525SlotApprovableInternalTrait, + ERC3525SlotApprovableImpl, InternalTrait as ERC3525SlotApprovableInternalTrait, ExternalTrait as ERC3525SlotApprovableExternalTrait }; use cairo_erc_3525::extensions::slotapprovable::module::ERC3525SlotApprovableComponent; @@ -49,9 +48,7 @@ fn setup() -> ERC3525SlotApprovableComponentState { fn test_slot_approvable_owner_can_approve_slot() { let mut state = setup(); set_caller_address(OWNER()); - state.set_approval_for_slot( - OWNER(), SLOT_1, OPERATOR(), true - ); + state.set_approval_for_slot(OWNER(), SLOT_1, OPERATOR(), true); } #[test] @@ -61,13 +58,9 @@ fn test_slot_approvable_operator_can_approve_value() { let mut mock_state = CONTRACT_STATE(); set_caller_address(OWNER()); mock_state.erc3525._mint(OWNER(), TOKEN_ID_1, SLOT_1, VALUE); - state.set_approval_for_slot( - OWNER(), SLOT_1, OPERATOR(), true - ); + state.set_approval_for_slot(OWNER(), SLOT_1, OPERATOR(), true); set_caller_address(OPERATOR()); - state.approve_value( - TOKEN_ID_1, OPERATOR(), VALUE - ); + state.approve_value(TOKEN_ID_1, OPERATOR(), VALUE); } #[test] @@ -78,13 +71,9 @@ fn test_slot_approvable_operator_cannot_approve_any_token() { let mut mock_state = CONTRACT_STATE(); set_caller_address(OWNER()); mock_state.erc3525._mint(OWNER(), TOKEN_ID_1, SLOT_1, VALUE); - state.set_approval_for_slot( - OWNER(), SLOT_2, OPERATOR(), true - ); + state.set_approval_for_slot(OWNER(), SLOT_2, OPERATOR(), true); set_caller_address(OPERATOR()); - state.approve_value( - TOKEN_ID_1, OPERATOR(), VALUE - ); + state.approve_value(TOKEN_ID_1, OPERATOR(), VALUE); } #[test] @@ -96,13 +85,9 @@ fn test_slot_approvable_operator_cannot_transfer_anyones_value() { set_caller_address(OWNER()); mock_state.erc3525._mint(OWNER(), TOKEN_ID_1, SLOT_1, VALUE); mock_state.erc3525._mint(SOMEONE(), TOKEN_ID_2, SLOT_1, VALUE); - state.set_approval_for_slot( - OWNER(), SLOT_1, OPERATOR(), true - ); + state.set_approval_for_slot(OWNER(), SLOT_1, OPERATOR(), true); set_caller_address(OPERATOR()); - state.transfer_value_from( - TOKEN_ID_2, 0, OPERATOR(), VALUE - ); + state.transfer_value_from(TOKEN_ID_2, 0, OPERATOR(), VALUE); } #[test] @@ -114,13 +99,9 @@ fn test_slot_approvable_operator_transfer_value_revert_slot_mismatch() { set_caller_address(OWNER()); mock_state.erc3525._mint(OWNER(), TOKEN_ID_1, SLOT_1, VALUE); mock_state.erc3525._mint(SOMEONE(), TOKEN_ID_2, SLOT_2, VALUE); - state.set_approval_for_slot( - OWNER(), SLOT_1, OPERATOR(), true - ); + state.set_approval_for_slot(OWNER(), SLOT_1, OPERATOR(), true); set_caller_address(OPERATOR()); - state.transfer_value_from( - TOKEN_ID_1, TOKEN_ID_2, ZERO(), VALUE - ); + state.transfer_value_from(TOKEN_ID_1, TOKEN_ID_2, ZERO(), VALUE); } #[test] @@ -131,14 +112,8 @@ fn test_slot_approvable_revoked_slot_operator_cannot_approve() { let mut mock_state = CONTRACT_STATE(); set_caller_address(OWNER()); mock_state.erc3525._mint(OWNER(), TOKEN_ID_1, SLOT_1, VALUE); - state.set_approval_for_slot( - OWNER(), SLOT_1, OPERATOR(), true - ); - state.set_approval_for_slot( - OWNER(), SLOT_1, OPERATOR(), false - ); + state.set_approval_for_slot(OWNER(), SLOT_1, OPERATOR(), true); + state.set_approval_for_slot(OWNER(), SLOT_1, OPERATOR(), false); set_caller_address(OPERATOR()); - state.approve_value( - TOKEN_ID_1, OPERATOR(), VALUE - ); + state.approve_value(TOKEN_ID_1, OPERATOR(), VALUE); } diff --git a/src/tests/unit/test_slot_enumerable.cairo b/src/tests/unit/test_slot_enumerable.cairo index bddefbc..2e9d463 100644 --- a/src/tests/unit/test_slot_enumerable.cairo +++ b/src/tests/unit/test_slot_enumerable.cairo @@ -10,23 +10,23 @@ use starknet::testing::set_caller_address; // External imports -use openzeppelin::token::erc721::erc721::ERC721Component::{ ERC721Impl, InternalImpl as ERC721InternalImpl }; +use openzeppelin::token::erc721::erc721::ERC721Component::{ + ERC721Impl, InternalImpl as ERC721InternalImpl +}; use openzeppelin::token::erc721::erc721::ERC721Component; use openzeppelin::presets::Account; // Local imports -use cairo_erc_3525::module::ERC3525Component::{ ERC3525Impl, InternalImpl }; +use cairo_erc_3525::module::ERC3525Component::{ERC3525Impl, InternalImpl}; use cairo_erc_3525::module::ERC3525Component; use cairo_erc_3525::extensions::slotenumerable::module::ERC3525SlotEnumerableComponent::{ ERC3525SlotEnumerableImpl, InternalImpl as ERC3525SlotEnumerableInternalImpl }; use cairo_erc_3525::extensions::slotenumerable::module::ERC3525SlotEnumerableComponent; use cairo_erc_3525::tests::unit::constants::{ - ERC3525SlotEnumerableComponentState, - CONTRACT_STATE, COMPONENT_STATE_SLOT_ENUMERABLE, - VALUE_DECIMALS, TOKEN_ID_1, TOKEN_ID_2, SLOT_1, SLOT_2, VALUE, - ZERO, OWNER, SOMEONE + ERC3525SlotEnumerableComponentState, CONTRACT_STATE, COMPONENT_STATE_SLOT_ENUMERABLE, + VALUE_DECIMALS, TOKEN_ID_1, TOKEN_ID_2, SLOT_1, SLOT_2, VALUE, ZERO, OWNER, SOMEONE }; // Settings @@ -55,10 +55,8 @@ fn setup() -> (ERC3525SlotEnumerableComponentState, ContractAddress) { fn test_slot_enumerable_slot_count() { let (mut state, _) = setup(); set_caller_address(OWNER()); - state._mint(OWNER(), TOKEN_ID_1, SLOT_1, VALUE - ); - state._mint(OWNER(), TOKEN_ID_2, SLOT_2, 0 - ); + state._mint(OWNER(), TOKEN_ID_1, SLOT_1, VALUE); + state._mint(OWNER(), TOKEN_ID_2, SLOT_2, 0); let count = state.slot_count(); assert(count == 2, 'Wrong slot count'); } @@ -89,8 +87,7 @@ fn test_slot_enumerable_slot_by_index_revert_out_of_bounds() { #[should_panic(expected: ('ERC3525: index out of bounds',))] fn test_slot_enumerable_slot_by_index_revert_overflow() { let (mut state, _) = setup(); - state.slot_by_index(BoundedInt::max() - ); + state.slot_by_index(BoundedInt::max()); } #[test] @@ -98,15 +95,11 @@ fn test_slot_enumerable_slot_by_index_revert_overflow() { fn test_slot_enumerable_token_supply_in_slot() { let (mut state, _) = setup(); set_caller_address(OWNER()); - state._mint(OWNER(), TOKEN_ID_1, SLOT_1, VALUE - ); - state._mint(OWNER(), TOKEN_ID_2, SLOT_2, 0 - ); - let supply = state.token_supply_in_slot(SLOT_1 - ); + state._mint(OWNER(), TOKEN_ID_1, SLOT_1, VALUE); + state._mint(OWNER(), TOKEN_ID_2, SLOT_2, 0); + let supply = state.token_supply_in_slot(SLOT_1); assert(supply == 1, 'Wrong token supply'); - let supply = state.token_supply_in_slot(SLOT_2 - ); + let supply = state.token_supply_in_slot(SLOT_2); assert(supply == 1, 'Wrong token supply'); } @@ -114,8 +107,7 @@ fn test_slot_enumerable_token_supply_in_slot() { #[available_gas(20000000)] fn test_slot_enumerable_token_supply_in_slot_is_empty() { let (mut state, _) = setup(); - let supply = state.token_supply_in_slot(SLOT_1 - ); + let supply = state.token_supply_in_slot(SLOT_1); assert(supply == 0, 'Wrong token supply'); } @@ -125,13 +117,11 @@ fn test_slot_enumerable_token_supply_in_slot_after_transfer() { let (mut state, _) = setup(); let mut mock_state = CONTRACT_STATE(); set_caller_address(OWNER()); - state._mint(OWNER(), TOKEN_ID_1, SLOT_1, VALUE - ); + state._mint(OWNER(), TOKEN_ID_1, SLOT_1, VALUE); // ERC721 setup mock_state.erc721.transfer_from(OWNER(), SOMEONE(), TOKEN_ID_1); // [Assert] Token supply in slot - let supply = state.token_supply_in_slot(SLOT_1 - ); + let supply = state.token_supply_in_slot(SLOT_1); assert(supply == 1, 'Wrong token supply'); } @@ -143,13 +133,10 @@ fn test_slot_enumerable_token_supply_in_slot_after_transfer_to_address() { set_caller_address(OWNER()); state._mint(OWNER(), TOKEN_ID_1, SLOT_1, VALUE); // [Effect] Transfer value to address - let new_token_id = mock_state.erc3525.transfer_value_from( - TOKEN_ID_1, 0, receiver, VALUE - ); + let new_token_id = mock_state.erc3525.transfer_value_from(TOKEN_ID_1, 0, receiver, VALUE); state._after_transfer_value_from(new_token_id); // [Assert] Token supply in slot - let supply = state.token_supply_in_slot(SLOT_1 - ); + let supply = state.token_supply_in_slot(SLOT_1); assert(supply == 2, 'Wrong token supply'); } @@ -165,8 +152,7 @@ fn test_slot_enumerable_token_supply_in_slot_after_transfer_to_token() { mock_state.erc3525.transfer_value_from(TOKEN_ID_1, TOKEN_ID_2, ZERO(), VALUE); state._after_transfer_value_from(TOKEN_ID_2); // [Assert] Token supply in slot - let supply = state.token_supply_in_slot(SLOT_1 - ); + let supply = state.token_supply_in_slot(SLOT_1); assert(supply == 2, 'Wrong token supply'); } @@ -199,8 +185,7 @@ fn test_slot_enumerable_token_in_slot_by_index_revert_out_of_bounds() { fn test_slot_enumerable_token_in_slot_by_index_revert_overflow() { let (mut state, _) = setup(); // [Assert] Token in slot by index - state.token_in_slot_by_index(SLOT_1, BoundedInt::max() - ); + state.token_in_slot_by_index(SLOT_1, BoundedInt::max()); } #[test] @@ -213,8 +198,7 @@ fn test_slot_enumerable_token_in_slot_by_index_after_transfer() { // ERC721 setup mock_state.erc721.transfer_from(OWNER(), SOMEONE(), TOKEN_ID_1); // [Assert] Token in slot by index - let token_id = state.token_in_slot_by_index(SLOT_1, 0 - ); + let token_id = state.token_in_slot_by_index(SLOT_1, 0); assert(token_id == TOKEN_ID_1, 'Wrong token id'); } @@ -226,9 +210,7 @@ fn test_slot_enumerable_token_in_slot_by_index_after_transfer_to_address() { set_caller_address(OWNER()); state._mint(OWNER(), TOKEN_ID_1, SLOT_1, VALUE); // [Effect] Transfer value to address - let new_token_id = mock_state.erc3525.transfer_value_from( - TOKEN_ID_1, 0, receiver, VALUE - ); + let new_token_id = mock_state.erc3525.transfer_value_from(TOKEN_ID_1, 0, receiver, VALUE); state._after_transfer_value_from(new_token_id); // [Assert] Token in slot by index let token_id = state.token_in_slot_by_index(SLOT_1, 0); diff --git a/src/tests/unit/test_transfer_to_address.cairo b/src/tests/unit/test_transfer_to_address.cairo index 0c9a50d..4a0942f 100644 --- a/src/tests/unit/test_transfer_to_address.cairo +++ b/src/tests/unit/test_transfer_to_address.cairo @@ -10,17 +10,19 @@ use starknet::testing::set_caller_address; // External imports -use openzeppelin::token::erc721::erc721::ERC721Component::{ ERC721Impl, InternalImpl as ERC721InternalImpl }; +use openzeppelin::token::erc721::erc721::ERC721Component::{ + ERC721Impl, InternalImpl as ERC721InternalImpl +}; use openzeppelin::token::erc721::erc721::ERC721Component; use openzeppelin::presets::Account; // Local imports -use cairo_erc_3525::module::ERC3525Component::{ ERC3525Impl, InternalImpl }; +use cairo_erc_3525::module::ERC3525Component::{ERC3525Impl, InternalImpl}; use cairo_erc_3525::module::ERC3525Component; use cairo_erc_3525::tests::unit::constants::{ - ERC3525ComponentState, - COMPONENT_STATE, CONTRACT_STATE, VALUE_DECIMALS, TOKEN_ID_1, TOKEN_ID_2, SLOT_1, VALUE, ZERO, OWNER, OPERATOR + ERC3525ComponentState, COMPONENT_STATE, CONTRACT_STATE, VALUE_DECIMALS, TOKEN_ID_1, TOKEN_ID_2, + SLOT_1, VALUE, ZERO, OWNER, OPERATOR }; // Settings diff --git a/src/tests/unit/test_transfer_to_token.cairo b/src/tests/unit/test_transfer_to_token.cairo index c01496d..f950dfe 100644 --- a/src/tests/unit/test_transfer_to_token.cairo +++ b/src/tests/unit/test_transfer_to_token.cairo @@ -10,17 +10,19 @@ use starknet::testing::set_caller_address; // External imports -use openzeppelin::token::erc721::erc721::ERC721Component::{ ERC721Impl, InternalImpl as ERC721InternalImpl }; +use openzeppelin::token::erc721::erc721::ERC721Component::{ + ERC721Impl, InternalImpl as ERC721InternalImpl +}; use openzeppelin::token::erc721::erc721::ERC721Component; use openzeppelin::presets::Account; // Local imports -use cairo_erc_3525::module::ERC3525Component::{ ERC3525Impl, InternalImpl }; +use cairo_erc_3525::module::ERC3525Component::{ERC3525Impl, InternalImpl}; use cairo_erc_3525::module::ERC3525Component; use cairo_erc_3525::tests::unit::constants::{ - ERC3525ComponentState, - COMPONENT_STATE, CONTRACT_STATE, VALUE_DECIMALS, TOKEN_ID_1, TOKEN_ID_2, SLOT_1, VALUE, ZERO, OWNER, OPERATOR + ERC3525ComponentState, COMPONENT_STATE, CONTRACT_STATE, VALUE_DECIMALS, TOKEN_ID_1, TOKEN_ID_2, + SLOT_1, VALUE, ZERO, OWNER, OPERATOR }; // Settings diff --git a/src/tests/unit/test_views.cairo b/src/tests/unit/test_views.cairo index 2764cf1..bdb8d46 100644 --- a/src/tests/unit/test_views.cairo +++ b/src/tests/unit/test_views.cairo @@ -10,16 +10,18 @@ use starknet::testing::set_caller_address; // External imports -use openzeppelin::token::erc721::erc721::ERC721Component::{ ERC721Impl, InternalImpl as ERC721InternalImpl }; +use openzeppelin::token::erc721::erc721::ERC721Component::{ + ERC721Impl, InternalImpl as ERC721InternalImpl +}; use openzeppelin::token::erc721::erc721::ERC721Component; // Local imports -use cairo_erc_3525::module::ERC3525Component::{ ERC3525Impl, InternalImpl }; +use cairo_erc_3525::module::ERC3525Component::{ERC3525Impl, InternalImpl}; use cairo_erc_3525::module::ERC3525Component; use cairo_erc_3525::tests::unit::constants::{ - ERC3525ComponentState, - COMPONENT_STATE, CONTRACT_STATE, VALUE_DECIMALS, TOKEN_ID_1, TOKEN_ID_2, SLOT_1, SLOT_2, VALUE, OWNER + ERC3525ComponentState, COMPONENT_STATE, CONTRACT_STATE, VALUE_DECIMALS, TOKEN_ID_1, TOKEN_ID_2, + SLOT_1, SLOT_2, VALUE, OWNER }; // Settings