From 13d61547dbd77f406306e78fcf09f353092b2e47 Mon Sep 17 00:00:00 2001 From: Patrice Tisserand Date: Mon, 14 Oct 2024 11:53:41 +0200 Subject: [PATCH] starknet: scarb fmt --- apps/blockchain/starknet/Scarb.toml | 3 + apps/blockchain/starknet/src/bridge.cairo | 30 ++-- .../starknet/src/byte_array_extra.cairo | 14 +- apps/blockchain/starknet/src/interfaces.cairo | 2 +- apps/blockchain/starknet/src/lib.cairo | 6 +- apps/blockchain/starknet/src/request.cairo | 75 ++++------ .../starknet/src/tests/bridge_t.cairo | 46 +++--- apps/blockchain/starknet/src/token.cairo | 2 +- .../src/token/collection_manager.cairo | 51 +++---- .../src/token/erc721_bridgeable.cairo | 132 +++++++++--------- 10 files changed, 167 insertions(+), 194 deletions(-) diff --git a/apps/blockchain/starknet/Scarb.toml b/apps/blockchain/starknet/Scarb.toml index 0d00037b..dca3cb61 100644 --- a/apps/blockchain/starknet/Scarb.toml +++ b/apps/blockchain/starknet/Scarb.toml @@ -18,3 +18,6 @@ casm = true [tool.sncast.katana] account = "katana_account" url = "http://127.0.0.1:5050" + +[tool.fmt] +sort-module-level-items = true \ No newline at end of file diff --git a/apps/blockchain/starknet/src/bridge.cairo b/apps/blockchain/starknet/src/bridge.cairo index 6ece571d..6f6eaeb4 100644 --- a/apps/blockchain/starknet/src/bridge.cairo +++ b/apps/blockchain/starknet/src/bridge.cairo @@ -1,26 +1,17 @@ #[starknet::contract] mod bridge { - use core::byte_array::ByteArrayTrait; use array::{ArrayTrait, SpanTrait}; - use traits::{Into, TryInto}; - use zeroable::Zeroable; - use serde::Serde; - use option::OptionTrait; - use debug::PrintTrait; + use core::byte_array::ByteArrayTrait; use core::starknet::SyscallResultTrait; - - use starknet::{ClassHash, ContractAddress, EthAddress}; - use starknet::contract_address::ContractAddressZeroable; - use starknet::eth_address::EthAddressZeroable; + use debug::PrintTrait; use openzeppelin::access::ownable::OwnableComponent; use openzeppelin::access::ownable::interface::{IOwnableDispatcher, IOwnableDispatcherTrait}; + use option::OptionTrait; - use starklane::interfaces::{ - IStarklane, IUpgradeable, IUpgradeableDispatcher, IUpgradeableDispatcherTrait, - IStarklaneCollectionAdmin - }; + use poseidon::poseidon_hash_span; + use serde::Serde; // events use starklane::interfaces::{ DepositRequestInitiated, WithdrawRequestCompleted, CollectionDeployedFromL1, @@ -28,6 +19,11 @@ mod bridge { BridgeL1AddressUpdated, ERC721ClassHashUpdated, L1L2CollectionMappingUpdated }; + use starklane::interfaces::{ + IStarklane, IUpgradeable, IUpgradeableDispatcher, IUpgradeableDispatcherTrait, + IStarklaneCollectionAdmin + }; + use starklane::request::{ Request, compute_request_header_v1, compute_request_hash, collection_type_from_header, }; @@ -40,8 +36,12 @@ mod bridge { CollectionType, deploy_erc721_bridgeable, verify_collection_address, erc721_metadata, }, }; + use starknet::contract_address::ContractAddressZeroable; + use starknet::eth_address::EthAddressZeroable; - use poseidon::poseidon_hash_span; + use starknet::{ClassHash, ContractAddress, EthAddress}; + use traits::{Into, TryInto}; + use zeroable::Zeroable; component!(path: OwnableComponent, storage: ownable, event: OwnableEvent); diff --git a/apps/blockchain/starknet/src/byte_array_extra.cairo b/apps/blockchain/starknet/src/byte_array_extra.cairo index b69c78ce..7e3dc5f6 100644 --- a/apps/blockchain/starknet/src/byte_array_extra.cairo +++ b/apps/blockchain/starknet/src/byte_array_extra.cairo @@ -33,7 +33,6 @@ impl SpanFeltTryIntoByteArray of TryInto, ByteArray> { } - #[cfg(test)] mod tests { use core::serde::Serde; @@ -90,9 +89,14 @@ mod tests { let mut a = ArrayTrait::new(); orig.serialize(ref a); assert_eq!(*a[0], 1, "Wrong data len"); - assert_eq!(*a[1], 0x546869732070616c696e64726f6d65206973206e6f7420617320676f6f642c, "Wrong data[0]"); - assert_eq!(*a[2], 0x20627574206174206c656173742069742773206c6f6e6720656e6f756768, "Wrong pending word"); + assert_eq!( + *a[1], 0x546869732070616c696e64726f6d65206973206e6f7420617320676f6f642c, "Wrong data[0]" + ); + assert_eq!( + *a[2], + 0x20627574206174206c656173742069742773206c6f6e6720656e6f756768, + "Wrong pending word" + ); assert_eq!(*a[3], 30, "Wrong pending word len"); } - -} \ No newline at end of file +} diff --git a/apps/blockchain/starknet/src/interfaces.cairo b/apps/blockchain/starknet/src/interfaces.cairo index 1cd3f4bd..c0be71a0 100644 --- a/apps/blockchain/starknet/src/interfaces.cairo +++ b/apps/blockchain/starknet/src/interfaces.cairo @@ -1,6 +1,6 @@ use array::{SpanTrait}; -use starknet::{ClassHash, ContractAddress, EthAddress}; use starklane::request::Request; +use starknet::{ClassHash, ContractAddress, EthAddress}; #[starknet::interface] trait IStarklane { diff --git a/apps/blockchain/starknet/src/lib.cairo b/apps/blockchain/starknet/src/lib.cairo index f4f2e0ff..3c552810 100644 --- a/apps/blockchain/starknet/src/lib.cairo +++ b/apps/blockchain/starknet/src/lib.cairo @@ -1,8 +1,8 @@ -mod request; -mod interfaces; mod bridge; -mod token; mod byte_array_extra; +mod interfaces; +mod request; mod tests; +mod token; diff --git a/apps/blockchain/starknet/src/request.cairo b/apps/blockchain/starknet/src/request.cairo index 67976f81..6040ec39 100644 --- a/apps/blockchain/starknet/src/request.cairo +++ b/apps/blockchain/starknet/src/request.cairo @@ -1,14 +1,14 @@ +use array::{ArrayTrait, SpanTrait}; +use keccak::{keccak_u256s_be_inputs, keccak_u256s_le_inputs}; +use option::OptionTrait; +use poseidon::poseidon_hash_span; ///! Request to bridge tokens. use serde::Serde; -use traits::{Into, TryInto}; -use option::OptionTrait; -use array::{ArrayTrait, SpanTrait}; -use starknet::{ContractAddress, EthAddress}; -use poseidon::poseidon_hash_span; -use keccak::{keccak_u256s_be_inputs, keccak_u256s_le_inputs}; use starklane::token::collection_manager::CollectionType; +use starknet::{ContractAddress, EthAddress}; +use traits::{Into, TryInto}; // Byte 1 of the header. const HEADER_V1: u256 = 0x01; @@ -30,37 +30,30 @@ struct Request { header: felt252, // Unique hash of the request. hash: u256, - // Address of the collection on Ethereum. collection_l1: EthAddress, // Address of the collection on Starknet. collection_l2: ContractAddress, - // Owner on Ethereum (for all the tokens in the request). owner_l1: EthAddress, // Owners on Starknet (for all the tokens in the request). owner_l2: ContractAddress, - // Collection name (ERC1155: not used). name: ByteArray, // Collection symbol (ERC1155: not used). symbol: ByteArray, // Base URI for the collection. base_uri: ByteArray, - // Tokens to be bridged. ids: Span, - // Amounts for each token // ERC721: not used. // ERC1155: if empty, the amount is 1 for each token id, else length must match `ids`. values: Span, - // URIs for each individual token // ERC721: must be empty if `base_uri` is provided, else length must match `ids`. // ERC1155: not used. uris: Span, - // New owners on starknet. This allows a batch migration of the tokens to // different owners. // Must be empty if `owner_l2` is not 0. Otherwise, length must match `ids`. @@ -110,9 +103,7 @@ fn collection_type_from_header(header: felt252) -> CollectionType { /// * `use_deposit_burn_auto` - Enables burn auto in the header. /// * `use_withdraw_auto` - Enables withdraw auto in the header. fn compute_request_header_v1( - ctype: CollectionType, - use_deposit_burn_auto: bool, - use_withdraw_auto: bool, + ctype: CollectionType, use_deposit_burn_auto: bool, use_withdraw_auto: bool, ) -> felt252 { let mut header: u256 = HEADER_V1; @@ -144,10 +135,7 @@ fn compute_request_header_v1( /// * `to_l1_address` - New owner on Ethereum (L1). /// * `token_ids` - List of token ids to be transferred. fn compute_request_hash( - salt: felt252, - collection: ContractAddress, - to_l1_address: EthAddress, - token_ids: Span, + salt: felt252, collection: ContractAddress, to_l1_address: EthAddress, token_ids: Span, ) -> u256 { let c_felt: felt252 = collection.into(); let mut buf: Array = array![salt.into(), c_felt.into(), to_l1_address.address.into()]; @@ -169,14 +157,10 @@ fn compute_request_hash( let hash = keccak_u256s_be_inputs(span); // Ensure keccak endianness compatibility. - u256 { - low: integer::u128_byte_reverse(hash.high), - high: integer::u128_byte_reverse(hash.low) - } + u256 { low: integer::u128_byte_reverse(hash.high), high: integer::u128_byte_reverse(hash.low) } } - // **** TESTS **** /// We have to use a contract as the syscall is not supported directly in tests. #[starknet::interface] @@ -192,14 +176,12 @@ trait IContractRequest { #[starknet::contract] mod contract_req_test { - use super::{compute_request_hash, IContractRequest}; use array::{ArrayTrait, SpanTrait}; use starknet::{ContractAddress, EthAddress}; + use super::{compute_request_hash, IContractRequest}; #[storage] - struct Storage { - - } + struct Storage {} #[abi(embed_v0)] impl ContractTestImpl of IContractRequest { @@ -217,24 +199,23 @@ mod contract_req_test { #[cfg(test)] mod tests { - use debug::PrintTrait; - use serde::Serde; use array::{ArrayTrait, SpanTrait}; + use debug::PrintTrait; use integer::{U8IntoFelt252, U32IntoFelt252, Felt252TryIntoU32}; - use traits::{Into, TryInto}; use option::OptionTrait; use result::ResultTrait; + use serde::Serde; + + use snforge_std::{declare, ContractClassTrait}; + + use starklane::token::collection_manager::CollectionType; use starknet::{ContractAddress, EthAddress}; use super::{ - Request, WITHDRAW_AUTO, DEPOSIT_AUTO_BURN, ERC721_TYPE, ERC1155_TYPE, - can_use_withdraw_auto, collection_type_from_header, - compute_request_header_v1, compute_request_hash, + Request, WITHDRAW_AUTO, DEPOSIT_AUTO_BURN, ERC721_TYPE, ERC1155_TYPE, can_use_withdraw_auto, + collection_type_from_header, compute_request_header_v1, compute_request_hash, contract_req_test, IContractRequestDispatcher, IContractRequestDispatcherTrait, }; - - use starklane::token::collection_manager::CollectionType; - - use snforge_std::{declare, ContractClassTrait}; + use traits::{Into, TryInto}; #[test] fn can_use_withdraw_auto_test() { @@ -252,7 +233,7 @@ mod tests { } #[test] - #[should_panic(expected: ('Invalid collection type', ))] + #[should_panic(expected: ('Invalid collection type',))] fn collection_type_from_header_test_fail() { let h: felt252 = 0; assert(collection_type_from_header(h) == CollectionType::ERC721, 'Invalid ERC721 CT'); @@ -280,15 +261,13 @@ mod tests { let contract_address = contract.deploy(@array![]).unwrap(); let disp = IContractRequestDispatcher { contract_address }; - let hash = disp.compute_request_hash_from_contract( - salt, - collection, - to_l1_address, - ids.span() - ); + let hash = disp + .compute_request_hash_from_contract(salt, collection, to_l1_address, ids.span()); - assert(hash == 0xbb7ca67ee263bd2bb68dc88b530300222a3700bceca4e537079047fff89a0402_u256, - 'Invalid req hash'); + assert( + hash == 0xbb7ca67ee263bd2bb68dc88b530300222a3700bceca4e537079047fff89a0402_u256, + 'Invalid req hash' + ); } /// Should deserialize from buffer. diff --git a/apps/blockchain/starknet/src/tests/bridge_t.cairo b/apps/blockchain/starknet/src/tests/bridge_t.cairo index 4549db0f..9e939cce 100644 --- a/apps/blockchain/starknet/src/tests/bridge_t.cairo +++ b/apps/blockchain/starknet/src/tests/bridge_t.cairo @@ -1,31 +1,25 @@ #[cfg(test)] mod tests { - use snforge_std::{ - cheatcodes::{events::EventFetcher, events::EventAssertions, l1_handler::L1HandlerTrait}, - event_name_hash, - }; + use array::{ArrayTrait, SpanTrait}; use core::traits::TryInto; - use array::{ArrayTrait, SpanTrait}; - use traits::Into; - use result::ResultTrait; - use option::OptionTrait; - use serde::Serde; - use zeroable::Zeroable; use openzeppelin::access::ownable::interface::{ IOwnableTwoStepDispatcher, IOwnableTwoStepDispatcherTrait }; + use option::OptionTrait; + use result::ResultTrait; + use serde::Serde; + use snforge_std::{ + cheatcodes::{events::EventFetcher, events::EventAssertions, l1_handler::L1HandlerTrait}, + event_name_hash, + }; - use starknet::{ContractAddress, ClassHash, EthAddress, class_hash_const}; - use starklane::{ - request::{Request, compute_request_hash}, - interfaces::{ - IStarklaneDispatcher, IStarklaneDispatcherTrait, IUpgradeableDispatcher, - IUpgradeableDispatcherTrait, IStarklaneCollectionAdminDispatcher, - IStarklaneCollectionAdminDispatcherTrait, - }, + use snforge_std::{ + declare, ContractClass, ContractClassTrait, start_prank, stop_prank, CheatTarget, L1Handler, + get_class_hash, spy_events, SpyOn, load, map_entry_address, }; + use starklane::bridge::bridge; use starklane::token::{ interfaces::{ IERC721Dispatcher, IERC721DispatcherTrait, IERC721BridgeableDispatcher, @@ -33,13 +27,19 @@ mod tests { IERC721MintableDispatcherTrait, }, }; - use starklane::bridge::bridge; - - use snforge_std::{ - declare, ContractClass, ContractClassTrait, start_prank, stop_prank, CheatTarget, L1Handler, - get_class_hash, spy_events, SpyOn, load, map_entry_address, + use starklane::{ + request::{Request, compute_request_hash}, + interfaces::{ + IStarklaneDispatcher, IStarklaneDispatcherTrait, IUpgradeableDispatcher, + IUpgradeableDispatcherTrait, IStarklaneCollectionAdminDispatcher, + IStarklaneCollectionAdminDispatcherTrait, + }, }; + use starknet::{ContractAddress, ClassHash, EthAddress, class_hash_const}; + use traits::Into; + use zeroable::Zeroable; + #[derive(Drop)] struct BridgeDeployedConfig { admin: ContractAddress, diff --git a/apps/blockchain/starknet/src/token.cairo b/apps/blockchain/starknet/src/token.cairo index 5256c272..1f2deedc 100644 --- a/apps/blockchain/starknet/src/token.cairo +++ b/apps/blockchain/starknet/src/token.cairo @@ -1,3 +1,3 @@ -mod interfaces; mod collection_manager; mod erc721_bridgeable; +mod interfaces; diff --git a/apps/blockchain/starknet/src/token/collection_manager.cairo b/apps/blockchain/starknet/src/token/collection_manager.cairo index 0d605b02..00cd1b79 100644 --- a/apps/blockchain/starknet/src/token/collection_manager.cairo +++ b/apps/blockchain/starknet/src/token/collection_manager.cairo @@ -1,14 +1,14 @@ -use serde::Serde; -use traits::Into; use array::{ArrayTrait, SpanTrait}; -use result::ResultTrait; use option::OptionTrait; -use zeroable::Zeroable; -use starknet::{ContractAddress, ClassHash, EthAddress}; +use result::ResultTrait; +use serde::Serde; +use starklane::byte_array_extra::SpanFeltTryIntoByteArray; use starknet::contract_address::ContractAddressZeroable; use starknet::eth_address::EthAddressZeroable; +use starknet::{ContractAddress, ClassHash, EthAddress}; use super::interfaces::{IERC721Dispatcher, IERC721DispatcherTrait}; -use starklane::byte_array_extra::SpanFeltTryIntoByteArray; +use traits::Into; +use zeroable::Zeroable; #[derive(Drop, PartialEq)] enum CollectionType { @@ -31,8 +31,7 @@ struct ERC721Metadata { /// * `erc721` - Dispatcher of ERC721 contract. /// * `token_ids` - An optional list of token to extract individual URI. fn erc721_metadata( - contract_address: ContractAddress, - token_ids: Option> + contract_address: ContractAddress, token_ids: Option> ) -> Option { let erc721 = IERC721Dispatcher { contract_address }; @@ -48,9 +47,9 @@ fn erc721_metadata( let token_id = *ids[i]; let token_uri = match token_uri_from_contract_call(erc721.contract_address, token_id) { - Option::Some(uri) => uri, - Option::None => "", - }; + Option::Some(uri) => uri, + Option::None => "", + }; out_uris.append(token_uri); @@ -59,18 +58,11 @@ fn erc721_metadata( out_uris.span() }, - Option::None => { - array![].span() - } + Option::None => { array![].span() } }; Option::Some( - ERC721Metadata { - name: erc721.name(), - symbol: erc721.symbol(), - base_uri: "", - uris - } + ERC721Metadata { name: erc721.name(), symbol: erc721.symbol(), base_uri: "", uris } ) } @@ -87,8 +79,7 @@ fn erc721_metadata( /// * `collection_address` - Collection address of the collection. /// * `token_id` - Token id. fn token_uri_from_contract_call( - collection_address: ContractAddress, - token_id: u256, + collection_address: ContractAddress, token_id: u256, ) -> Option { // TODO: add the interface detection when the standard is out. @@ -104,20 +95,14 @@ fn token_uri_from_contract_call( // len: 0 -> empty // len: 1 -> 'old' string // len > 1 -> ByteArray - match starknet::call_contract_syscall( - collection_address, - token_uri_selector, - calldata, - ) { + match starknet::call_contract_syscall(collection_address, token_uri_selector, calldata,) { Result::Ok(span) => span.try_into(), Result::Err(_e) => { match starknet::call_contract_syscall( collection_address, tokenURI_selector, calldata, ) { Result::Ok(span) => span.try_into(), - Result::Err(_e) => { - Option::None - } + Result::Err(_e) => { Option::None } } } } @@ -168,12 +153,8 @@ fn deploy_erc721_bridgeable( /// * `l1_bridge` - Contract address on L1 in the bridge storage. /// * `l2_bridge` - Contract address on L2 in the bridge storage. fn verify_collection_address( - l1_req: EthAddress, - l2_req: ContractAddress, - l1_bridge: EthAddress, - l2_bridge: ContractAddress, + l1_req: EthAddress, l2_req: ContractAddress, l1_bridge: EthAddress, l2_bridge: ContractAddress, ) -> ContractAddress { - // L1 address must always be set as we receive the request from L1. if l1_req.is_zero() { panic!("L1 address cannot be 0"); diff --git a/apps/blockchain/starknet/src/token/erc721_bridgeable.cairo b/apps/blockchain/starknet/src/token/erc721_bridgeable.cairo index b518b611..f44f669d 100644 --- a/apps/blockchain/starknet/src/token/erc721_bridgeable.cairo +++ b/apps/blockchain/starknet/src/token/erc721_bridgeable.cairo @@ -3,14 +3,14 @@ #[starknet::contract] mod erc721_bridgeable { - use starknet::{ContractAddress, ClassHash}; + use openzeppelin::access::ownable::OwnableComponent; use openzeppelin::introspection::src5::SRC5Component; use openzeppelin::token::erc721::ERC721Component; - use openzeppelin::access::ownable::OwnableComponent; + use starklane::interfaces::IUpgradeable; use starklane::token::interfaces::{IERC721Bridgeable, IERC721Mintable, IERC721Uri}; - use starklane::interfaces::IUpgradeable; + use starknet::{ContractAddress, ClassHash}; component!(path: ERC721Component, storage: erc721, event: ERC721Event); component!(path: SRC5Component, storage: src5, event: SRC5Event); @@ -21,7 +21,7 @@ mod erc721_bridgeable { impl ERC721Impl = ERC721Component::ERC721Impl; #[abi(embed_v0)] impl ERC721CamelOnly = ERC721Component::ERC721CamelOnlyImpl; - + impl ERC721InternalImpl = ERC721Component::InternalImpl; // SRC5 @@ -29,7 +29,8 @@ mod erc721_bridgeable { impl SRC5Impl = SRC5Component::SRC5Impl; #[abi(embed_v0)] - impl OwnableTwoStepMixinImpl = OwnableComponent::OwnableTwoStepMixinImpl; + impl OwnableTwoStepMixinImpl = + OwnableComponent::OwnableTwoStepMixinImpl; impl OwnableInternalImpl = OwnableComponent::InternalImpl; @@ -79,8 +80,7 @@ mod erc721_bridgeable { impl ERC721BridgeableImpl of IERC721Bridgeable { fn mint_from_bridge(ref self: ContractState, to: ContractAddress, token_id: u256) { assert( - starknet::get_caller_address() == self.bridge.read(), - 'ERC721: only bridge can mint' + starknet::get_caller_address() == self.bridge.read(), 'ERC721: only bridge can mint' ); self.erc721._mint(to, token_id); @@ -93,14 +93,18 @@ mod erc721_bridgeable { } - fn mint_from_bridge_uri(ref self: ContractState, to: ContractAddress, token_id: u256, token_uri: ByteArray) { + fn mint_from_bridge_uri( + ref self: ContractState, to: ContractAddress, token_id: u256, token_uri: ByteArray + ) { IERC721Bridgeable::mint_from_bridge(ref self, to, token_id); self.token_uris.write(token_id, token_uri); } } #[abi(embed_v0)] - impl ERC721BridgeableMetadataImpl of ERC721Component::interface::IERC721Metadata { + impl ERC721BridgeableMetadataImpl of ERC721Component::interface::IERC721Metadata< + ContractState + > { fn name(self: @ContractState) -> ByteArray { self.erc721.name() } @@ -120,7 +124,9 @@ mod erc721_bridgeable { } #[abi(embed_v0)] - impl ERC721BridgeableMetadataCamelOnlyImpl of ERC721Component::interface::IERC721MetadataCamelOnly { + impl ERC721BridgeableMetadataCamelOnlyImpl of ERC721Component::interface::IERC721MetadataCamelOnly< + ContractState + > { fn tokenURI(self: @ContractState, tokenId: u256) -> ByteArray { self.token_uri(tokenId) } @@ -148,15 +154,17 @@ mod erc721_bridgeable { fn mint_range(ref self: ContractState, to: ContractAddress, start: u256, end: u256) { let mut token_id = start; loop { - if token_id == end { - break (); - } + if token_id == end { + break (); + } self.mint(to, token_id); token_id += 1_u256; } } - fn mint_uri(ref self: ContractState, to: ContractAddress, token_id: u256, token_uri: ByteArray) { + fn mint_uri( + ref self: ContractState, to: ContractAddress, token_id: u256, token_uri: ByteArray + ) { self.mint(to, token_id); self.token_uris.write(token_id, token_uri); } @@ -183,33 +191,32 @@ mod erc721_bridgeable { #[cfg(test)] mod tests { - use super::erc721_bridgeable; + use array::{ArrayTrait, SpanTrait}; + use core::result::ResultTrait; + + use debug::PrintTrait; use openzeppelin::access::ownable::interface::{ IOwnableTwoStepDispatcher, IOwnableTwoStepDispatcherTrait }; + use option::OptionTrait; + use serde::Serde; + + + use snforge_std::{declare, ContractClassTrait, start_prank, stop_prank, CheatTarget}; + use starklane::token::collection_manager; use starklane::token::interfaces::{ - IERC721BridgeableDispatcher, IERC721BridgeableDispatcherTrait, - IERC721Dispatcher, IERC721DispatcherTrait, - IERC721MintableDispatcher, IERC721MintableDispatcherTrait, + IERC721BridgeableDispatcher, IERC721BridgeableDispatcherTrait, IERC721Dispatcher, + IERC721DispatcherTrait, IERC721MintableDispatcher, IERC721MintableDispatcherTrait, IERC721UriDispatcher, IERC721UriDispatcherTrait, }; - use starklane::token::collection_manager; - - use debug::PrintTrait; - use serde::Serde; - use array::{ArrayTrait, SpanTrait}; - use zeroable::Zeroable; - use option::OptionTrait; - use core::result::ResultTrait; - use traits::{TryInto, Into}; - use starknet::contract_address::Felt252TryIntoContractAddress; use starknet::class_hash::Felt252TryIntoClassHash; + use starknet::contract_address::Felt252TryIntoContractAddress; use starknet::{ContractAddress, ClassHash}; - - - use snforge_std::{declare, ContractClassTrait, start_prank, stop_prank, CheatTarget}; + use super::erc721_bridgeable; + use traits::{TryInto, Into}; + use zeroable::Zeroable; /// Deploy a ERC721Bridgeable instance, reusable in tests. fn deploy_erc721b( @@ -248,7 +255,8 @@ mod tests { "DUO", "https://my.base.uri", bridge_addr_mock(), - collection_owner_addr_mock()) + collection_owner_addr_mock() + ) } /// Should have correct constructor valules. @@ -272,11 +280,12 @@ mod tests { let TOKEN_ID = 244; let contract_address = deploy_everai_collection(); - let erc721 = IERC721Dispatcher { contract_address }; - + let erc721 = IERC721Dispatcher { contract_address }; + let new_uri = "https:..."; start_prank(CheatTarget::One(contract_address), COLLECTION_OWNER); - IERC721MintableDispatcher { contract_address }.mint_uri(NEW_DUO_OWNER, TOKEN_ID, new_uri.clone()); + IERC721MintableDispatcher { contract_address } + .mint_uri(NEW_DUO_OWNER, TOKEN_ID, new_uri.clone()); stop_prank(CheatTarget::One(contract_address)); let fetched_uri = erc721.token_uri(TOKEN_ID); @@ -287,7 +296,7 @@ mod tests { #[test] fn mint_from_bridge() { let BRIDGE = bridge_addr_mock(); - + let NEW_DUO_OWNER = starknet::contract_address_const::<128>(); let contract_address = deploy_everai_collection(); @@ -304,7 +313,7 @@ mod tests { } - /// Should burn token from bridge call. + /// Should burn token from bridge call. #[test] fn test_burn_token() { let BRIDGE = bridge_addr_mock(); @@ -330,16 +339,14 @@ mod tests { stop_prank(CheatTarget::One(contract_address)); // balance_of - + let balance = erc721.balance_of(DUO_OWNER); assert(balance == 0, 'token was not burn'); - - } - /// Should panic, only owner can burn + /// Should panic, only owner can burn #[test] - #[should_panic(expected: ('ERC721: only owner can burn', ))] + #[should_panic(expected: ('ERC721: only owner can burn',))] fn should_panic_test_burn_token() { let BRIDGE = bridge_addr_mock(); @@ -361,13 +368,11 @@ mod tests { // Burn the token by wrong owner start_prank(CheatTarget::One(contract_address), BRIDGE); erc721b.burn(42_u256); - - } /// Should not mint token if not bridge. #[test] - #[should_panic(expected: ('ERC721: only bridge can mint', ))] + #[should_panic(expected: ('ERC721: only bridge can mint',))] fn should_panic_mint_from_bridge_fail() { let NEW_DUO_OWNER = starknet::contract_address_const::<128>(); @@ -417,7 +422,9 @@ mod tests { erc721.mint_uri(NEW_DUO_OWNER, TOKEN_ID, new_uri.clone()); stop_prank(CheatTarget::One(contract_address)); - let fetched_uri = collection_manager::token_uri_from_contract_call(contract_address, TOKEN_ID) + let fetched_uri = collection_manager::token_uri_from_contract_call( + contract_address, TOKEN_ID + ) .expect('token mint failed'); assert_eq!(fetched_uri, new_uri, "bad uri"); } @@ -459,7 +466,7 @@ mod tests { stop_prank(CheatTarget::One(contract_address)); assert_eq!(ownable.owner(), COLLECTION_OWNER, "bad owner"); assert_eq!(ownable.pending_owner(), ALICE, "bad pending owner"); - + start_prank(CheatTarget::One(contract_address), COLLECTION_OWNER); ownable.transfer_ownership(BOB); stop_prank(CheatTarget::One(contract_address)); @@ -497,7 +504,7 @@ mod tests { let new_uri = "https://this.is.a.test.com"; let contract_address = deploy_everai_collection(); - let contract = IERC721UriDispatcher { contract_address}; + let contract = IERC721UriDispatcher { contract_address }; assert_eq!(contract.base_uri(), "https://my.base.uri"); start_prank(CheatTarget::One(contract_address), COLLECTION_OWNER); contract.set_base_uri(new_uri.clone()); @@ -517,7 +524,7 @@ mod tests { assert_eq!(ownable.owner(), COLLECTION_OWNER, "bad owner"); start_prank(CheatTarget::One(contract_address), ALICE); - IERC721UriDispatcher { contract_address}.set_base_uri("https://this.is.a.test.com"); + IERC721UriDispatcher { contract_address }.set_base_uri("https://this.is.a.test.com"); stop_prank(CheatTarget::One(contract_address)); } @@ -530,14 +537,14 @@ mod tests { let token_id = 42_u256; start_prank(CheatTarget::One(contract_address), COLLECTION_OWNER); - IERC721MintableDispatcher { contract_address}.mint(ALICE, token_id); + IERC721MintableDispatcher { contract_address }.mint(ALICE, token_id); stop_prank(CheatTarget::One(contract_address)); - assert!(IERC721Dispatcher {contract_address}.token_uri(token_id) != new_uri.clone()); + assert!(IERC721Dispatcher { contract_address }.token_uri(token_id) != new_uri.clone()); start_prank(CheatTarget::One(contract_address), COLLECTION_OWNER); - IERC721UriDispatcher { contract_address}.set_token_uri(token_id, new_uri.clone()); + IERC721UriDispatcher { contract_address }.set_token_uri(token_id, new_uri.clone()); stop_prank(CheatTarget::One(contract_address)); - assert_eq!(IERC721Dispatcher {contract_address}.token_uri(token_id), new_uri); + assert_eq!(IERC721Dispatcher { contract_address }.token_uri(token_id), new_uri); } #[test] @@ -551,14 +558,14 @@ mod tests { let invalid_token_id = 68_u256; start_prank(CheatTarget::One(contract_address), COLLECTION_OWNER); - IERC721MintableDispatcher { contract_address}.mint(ALICE, token_id); + IERC721MintableDispatcher { contract_address }.mint(ALICE, token_id); stop_prank(CheatTarget::One(contract_address)); - assert!(IERC721Dispatcher {contract_address}.token_uri(token_id) != new_uri.clone()); + assert!(IERC721Dispatcher { contract_address }.token_uri(token_id) != new_uri.clone()); start_prank(CheatTarget::One(contract_address), COLLECTION_OWNER); - IERC721UriDispatcher { contract_address}.set_token_uri(invalid_token_id, new_uri.clone()); + IERC721UriDispatcher { contract_address }.set_token_uri(invalid_token_id, new_uri.clone()); stop_prank(CheatTarget::One(contract_address)); - assert_eq!(IERC721Dispatcher {contract_address}.token_uri(token_id), new_uri); + assert_eq!(IERC721Dispatcher { contract_address }.token_uri(token_id), new_uri); } #[test] @@ -571,14 +578,13 @@ mod tests { let token_id = 42_u256; start_prank(CheatTarget::One(contract_address), COLLECTION_OWNER); - IERC721MintableDispatcher { contract_address}.mint(ALICE, token_id); + IERC721MintableDispatcher { contract_address }.mint(ALICE, token_id); stop_prank(CheatTarget::One(contract_address)); - assert!(IERC721Dispatcher {contract_address}.token_uri(token_id) != new_uri.clone()); + assert!(IERC721Dispatcher { contract_address }.token_uri(token_id) != new_uri.clone()); start_prank(CheatTarget::One(contract_address), ALICE); - IERC721UriDispatcher { contract_address}.set_token_uri(token_id, new_uri.clone()); + IERC721UriDispatcher { contract_address }.set_token_uri(token_id, new_uri.clone()); stop_prank(CheatTarget::One(contract_address)); - assert_eq!(IERC721Dispatcher {contract_address}.token_uri(token_id), new_uri); + assert_eq!(IERC721Dispatcher { contract_address }.token_uri(token_id), new_uri); } - -} \ No newline at end of file +}