From d56934f396394041f8be13c58f23e17751c7c5c0 Mon Sep 17 00:00:00 2001 From: bexan Date: Mon, 19 Feb 2024 16:06:01 +0100 Subject: [PATCH 1/3] contract: ark_orderbook add is_broker_whitelisted fn --- .../ark_common/src/protocol/order_types.cairo | 6 +- .../ark_orderbook/src/order/order_v1.cairo | 7 ++ contracts/ark_orderbook/src/orderbook.cairo | 67 +++++++++++++++---- .../src/orderbook_event_mock.cairo | 3 + 4 files changed, 68 insertions(+), 15 deletions(-) diff --git a/contracts/ark_common/src/protocol/order_types.cairo b/contracts/ark_common/src/protocol/order_types.cairo index 8a6ca34cf..7bee5ea9a 100644 --- a/contracts/ark_common/src/protocol/order_types.cairo +++ b/contracts/ark_common/src/protocol/order_types.cairo @@ -49,7 +49,8 @@ enum OrderValidationError { EndDateTooFar, AdditionalDataTooLong, InvalidContent, - InvalidSalt + InvalidSalt, + InvalidBroker, } impl OrderValidationErrorIntoFelt252 of Into { @@ -62,6 +63,7 @@ impl OrderValidationErrorIntoFelt252 of Into { OrderValidationError::AdditionalDataTooLong => 'ADDITIONAL_DATA_TOO_LONG', OrderValidationError::InvalidContent => 'INVALID_CONTENT', OrderValidationError::InvalidSalt => 'INVALID_SALT', + OrderValidationError::InvalidBroker => 'INVALID_BROKER', } } } @@ -82,6 +84,8 @@ impl Felt252TryIntoOrderValidationError of TryInto, } @@ -103,6 +106,10 @@ impl OrderTraitOrderV1 of OrderTrait { return Result::Err(OrderValidationError::InvalidContent); } + if (is_broker_whitelisted(*self.broker_id, *self.broker_type) == 0) { + return Result::Err(OrderValidationError::InvalidBroker); + } + Result::Ok(()) } diff --git a/contracts/ark_orderbook/src/orderbook.cairo b/contracts/ark_orderbook/src/orderbook.cairo index 53e246276..9854ab904 100644 --- a/contracts/ark_orderbook/src/orderbook.cairo +++ b/contracts/ark_orderbook/src/orderbook.cairo @@ -1,8 +1,8 @@ //! # Orderbook Contract -//! +//! //! This module defines the structure and functionalities of an orderbook contract. It includes -//! trait definitions, error handling, contract storage, events, constructors, L1 handlers, external functions, -//! and internal functions. The primary functionalities include broker whitelisting, order management +//! trait definitions, error handling, contract storage, events, constructors, L1 handlers, external functions, +//! and internal functions. The primary functionalities include broker whitelisting, order management //! (creation, cancellation, fulfillment), and order queries. use ark_common::protocol::order_types::{FulfillInfo, OrderType, CancelInfo, OrderStatus}; @@ -13,12 +13,20 @@ use ark_orderbook::order::order_v1::OrderV1; #[starknet::interface] trait Orderbook { /// Whitelists a broker. - /// TODO: good first exercise to use a components for broker management. /// /// # Arguments /// /// * `broker_id` - ID of the broker. - fn whitelist_broker(ref self: T, broker_id: felt252); + /// * `broker_type` - Type of the broker (0: CREATOR, 1: FULFILLER). + fn whitelist_broker(ref self: T, broker_id: felt252, broker_type: felt252); + + /// Remove a broker from the whitelist. + /// + /// # Arguments + /// + /// * `broker_id` - ID of the broker. + /// * `broker_type` - Type of the broker (0: CREATOR, 1: FULFILLER). + fn unwhitelist_broker(ref self: T, broker_id: felt252, broker_type: felt252); /// Submits and places an order to the orderbook if the order is valid. /// @@ -74,7 +82,7 @@ trait Orderbook { /// * `order_hash` - The order hash of order. fn get_order_signer(self: @T, order_hash: felt252) -> felt252; - /// Retrieves the order hash using its token hash. + /// Retrieves the order hash using its token hash. /// /// # Arguments /// * `token_hash` - The token hash of the order. @@ -160,6 +168,12 @@ mod orderbook { /// Mapping of broker addresses to their whitelisted status. /// Represented as felt252, set to 1 if the broker is registered. brokers: LegacyMap, + /// Mapping of creator_brokers addresses to their whitelisted status. + /// Represented as felt252, set to 1 if the broker is registered. + creator_brokers: LegacyMap, + /// Mapping of fulfiller_brokers addresses to their whitelisted status. + /// Represented as felt252, set to 1 if the broker is registered. + fulfiller_brokers: LegacyMap, /// Mapping of token_hash to order_hash. token_listings: LegacyMap, /// Mapping of token_hash to auction details (order_hash and end_date, auction_offer_count). @@ -266,6 +280,17 @@ mod orderbook { self.emit(OrderExecuted { order_hash: info.order_hash, order_status: order_status }); } + /// Check if a broker is whitelisted + fn is_broker_whitelisted(ref self: ContractState, broker_id: felt252, broker_type: felt252) -> felt252 { + let mut is_whitelisted = 0; + if (broker_type == 0) { + is_whitelisted = self.creator_brokers.read(broker_id); + } else if (broker_type == 1) { + is_whitelisted = self.fulfiller_brokers.read(broker_id); + } + is_whitelisted + } + // ************************************************************************* // EXTERNAL FUNCTIONS // ************************************************************************* @@ -350,14 +375,27 @@ mod orderbook { } /// Whitelists a broker. - fn whitelist_broker(ref self: ContractState, broker_id: felt252) { - // TODO: check components with OZ when ready for ownable. - assert( - self.admin.read() == starknet::get_caller_address(), - orderbook_errors::BROKER_UNREGISTERED - ); + fn whitelist_broker(ref self: ContractState, broker_id: felt252, broker_type: felt252) { + assert(starknet::get_caller_address() == self.admin.read(), 'Unauthorized update'); self.brokers.write(broker_id, 1); + + if (broker_type == 0) { + self.creator_brokers.write(broker_id, 1); + } else if (broker_type == 1) { + self.fulfiller_brokers.write(broker_id, 1); + } + } + + fn unwhitelist_broker(ref self: ContractState, broker_id: felt252, broker_type: felt252) { + assert(starknet::get_caller_address() == self.admin.read(), 'Unauthorized update'); + self.brokers.write(broker_id, 0); + + if (broker_type == 0) { + self.creator_brokers.write(broker_id, 0); + } else if (broker_type == 1) { + self.fulfiller_brokers.write(broker_id, 0); + } } /// Submits and places an order to the orderbook if the order is valid. @@ -489,6 +527,7 @@ mod orderbook { // ************************************************************************* #[generate_trait] impl InternalFunctions of InternalFunctionsTrait { + /// Fulfill auction order /// /// # Arguments @@ -853,12 +892,12 @@ mod orderbook { let auction_is_pending = current_block_timestamp < auction_end_date; if auction_is_pending { - // If the auction is still pending, record the new offer by linking it to the + // If the auction is still pending, record the new offer by linking it to the // auction order hash in the 'auction_offers' mapping. self.auction_offers.write(order_hash, auction_order_hash); if auction_end_date - current_block_timestamp < EXTENSION_TIME_IN_SECONDS { - // Increment the number of offers for this auction and extend the auction + // Increment the number of offers for this auction and extend the auction // end date by the predefined extension time to allow for additional offers. self .auctions diff --git a/contracts/ark_orderbook/src/orderbook_event_mock.cairo b/contracts/ark_orderbook/src/orderbook_event_mock.cairo index 40e952903..d4ed7ac65 100644 --- a/contracts/ark_orderbook/src/orderbook_event_mock.cairo +++ b/contracts/ark_orderbook/src/orderbook_event_mock.cairo @@ -109,6 +109,7 @@ mod orderbook_event_mock { start_date: 5, end_date: 6, broker_id: 'broker', + broker_type: 0, additional_data: array![].span(), } } @@ -139,6 +140,7 @@ mod orderbook_event_mock { start_date: 5, end_date: 6, broker_id: 'broker', + broker_type: 1, additional_data: array![].span(), } } @@ -169,6 +171,7 @@ mod orderbook_event_mock { start_date: 2, end_date: 0, broker_id: 'broker', + broker_type: 0, additional_data: array![].span(), } } From 67be582840a01fdf6ad1d6d554b7319cb56206ba Mon Sep 17 00:00:00 2001 From: bexan Date: Mon, 19 Feb 2024 21:52:29 +0100 Subject: [PATCH 2/3] Contracts: ark_orderbook add whitelist broker --- contracts/ark_orderbook/README.md | 2 +- .../ark_orderbook/src/broker/database.cairo | 68 +++++++++++++++++++ contracts/ark_orderbook/src/lib.cairo | 4 ++ .../ark_orderbook/src/order/order_v1.cairo | 16 +++-- contracts/ark_orderbook/src/orderbook.cairo | 50 ++++---------- .../src/orderbook_event_mock.cairo | 3 - .../ark_orderbook/tests/common/setup.cairo | 13 +++- .../tests/integration/test_cancel_order.cairo | 5 +- .../test_create_auction_offers.cairo | 4 +- .../test_create_listing_order.cairo | 6 +- .../integration/test_fulfill_auction.cairo | 17 ++++- .../integration/test_fulfill_listing.cairo | 9 ++- .../integration/test_fulfill_offers.cairo | 8 ++- .../tests/unit/order/test_order_v1.cairo | 11 ++- 14 files changed, 157 insertions(+), 59 deletions(-) create mode 100644 contracts/ark_orderbook/src/broker/database.cairo diff --git a/contracts/ark_orderbook/README.md b/contracts/ark_orderbook/README.md index 41eb5512c..301866680 100644 --- a/contracts/ark_orderbook/README.md +++ b/contracts/ark_orderbook/README.md @@ -12,6 +12,6 @@ To build: # Testing -For testing, you must have [starknet forge](https://foundry-rs.github.io/starknet-foundry/getting-started/installation.html) installed (at least `0.6.0`). Then you can run: +For testing, you must have [starknet forge](https://foundry-rs.github.io/starknet-foundry/getting-started/installation.html) installed (at least `0.9.1`). Then you can run: `snforge` diff --git a/contracts/ark_orderbook/src/broker/database.cairo b/contracts/ark_orderbook/src/broker/database.cairo new file mode 100644 index 000000000..ea1d43649 --- /dev/null +++ b/contracts/ark_orderbook/src/broker/database.cairo @@ -0,0 +1,68 @@ +//! Orders database. +//! +//! The order database uses the `storage_read` and `storage_write` +//! syscalls directly to optimize how data are stored. +//! +//! The status is always stored independently of the seriliazed +//! broker. This allows a quick and cheap storage/retrieval of the status +//! without having to write/read the whole order. +//! +//! The only assumption for now is that, +//! a single order serialized buffer must not exceed +//! 256 felts. +//! +//! The storage layout is the following: +//! +//! 1. Compute the storage base address with [BROKER_DB_BASE_KEY, broker_id] +//! 2. At base address => The broker whitelisting status. +use starknet::SyscallResultTrait; + + +/// Must remain equal to 0 for now. +const ADDRESS_DOMAIN: u32 = 0; +/// A constant value used in the base key hash. +const BROKER_DB_BASE_KEY: felt252 = 'broker whitelist'; + + + +/// Reads whitelist status of broker. +/// +/// # Arguments +/// +/// * `broker_id` - ID of the broker. +fn broker_whitelist_read(broker_id: felt252) -> bool { + let key = array![BROKER_DB_BASE_KEY, broker_id]; + + let base = starknet::storage_base_address_from_felt252( + poseidon::poseidon_hash_span(key.span()) + ); + + // First offset is the status. + let whitelisted: felt252 = starknet::storage_read_syscall( + ADDRESS_DOMAIN, starknet::storage_address_from_base(base) + ).unwrap_syscall(); + + whitelisted == 1 +} + +/// Writes only the whitelisted brokers. +/// It can be whitelisted or blacklisted. +/// +/// # Arguments +/// +/// * `broker_id` - ID of the broker. +/// * `status` - 1 if whitelisted, 0 if not. +fn broker_whitelist_write(broker_id: felt252, status: felt252) -> bool { + + let key = array![BROKER_DB_BASE_KEY, broker_id]; + + let base = starknet::storage_base_address_from_felt252( + poseidon::poseidon_hash_span(key.span()) + ); + + starknet::storage_write_syscall( + ADDRESS_DOMAIN, starknet::storage_address_from_base(base), status + ); + + true +} diff --git a/contracts/ark_orderbook/src/lib.cairo b/contracts/ark_orderbook/src/lib.cairo index 2cb497f0d..2f0991621 100644 --- a/contracts/ark_orderbook/src/lib.cairo +++ b/contracts/ark_orderbook/src/lib.cairo @@ -3,5 +3,9 @@ mod order { mod order_v1; } +mod broker { + mod database; +} + mod orderbook; mod orderbook_event_mock; diff --git a/contracts/ark_orderbook/src/order/order_v1.cairo b/contracts/ark_orderbook/src/order/order_v1.cairo index 59dbc2d4b..60add3f86 100644 --- a/contracts/ark_orderbook/src/order/order_v1.cairo +++ b/contracts/ark_orderbook/src/order/order_v1.cairo @@ -2,7 +2,11 @@ use core::array::ArrayTrait; use core::traits::Into; use core::traits::TryInto; use core::option::OptionTrait; -use ark_orderbook::orderbook::is_broker_whitelisted; + +use ark_orderbook::broker::database::{ + broker_whitelist_read +}; + //! Order v1 supported by the Orderbook. //! use starknet::ContractAddress; @@ -10,7 +14,10 @@ use starknet::contract_address_to_felt252; use ark_common::protocol::order_types::{OrderTrait, OrderValidationError, OrderType, RouteType}; use ark_common::protocol::order_types::FulfillInfo; use poseidon::poseidon_hash_span; +use starknet::SyscallResultTrait; +/// Must remain equal to 0 for now. +const ADDRESS_DOMAIN: u32 = 0; const ORDER_VERSION_V1: felt252 = 'v1'; // Auction -> end_amount (reserve price) > start_amount (starting price). // Auction -> ERC721_ERC20. @@ -46,8 +53,6 @@ struct OrderV1 { end_date: u64, // Broker public identifier. broker_id: felt252, - // Broker type (0: creator, 1: fullfiller). - broker_type: felt252, // Additional data, limited to ??? felts. additional_data: Span, } @@ -106,7 +111,10 @@ impl OrderTraitOrderV1 of OrderTrait { return Result::Err(OrderValidationError::InvalidContent); } - if (is_broker_whitelisted(*self.broker_id, *self.broker_type) == 0) { + // check if the broker is whitelisted. + let whitelisted = broker_whitelist_read(*self.broker_id); + + if whitelisted == false { return Result::Err(OrderValidationError::InvalidBroker); } diff --git a/contracts/ark_orderbook/src/orderbook.cairo b/contracts/ark_orderbook/src/orderbook.cairo index 9854ab904..9c12c8753 100644 --- a/contracts/ark_orderbook/src/orderbook.cairo +++ b/contracts/ark_orderbook/src/orderbook.cairo @@ -17,16 +17,14 @@ trait Orderbook { /// # Arguments /// /// * `broker_id` - ID of the broker. - /// * `broker_type` - Type of the broker (0: CREATOR, 1: FULFILLER). - fn whitelist_broker(ref self: T, broker_id: felt252, broker_type: felt252); + fn whitelist_broker(ref self: T, broker_id: felt252); /// Remove a broker from the whitelist. /// /// # Arguments /// /// * `broker_id` - ID of the broker. - /// * `broker_type` - Type of the broker (0: CREATOR, 1: FULFILLER). - fn unwhitelist_broker(ref self: T, broker_id: felt252, broker_type: felt252); + fn unwhitelist_broker(ref self: T, broker_id: felt252); /// Submits and places an order to the orderbook if the order is valid. /// @@ -127,6 +125,7 @@ mod orderbook_errors { const ORDER_OPEN: felt252 = 'OB: order is not open'; const USE_FULFILL_AUCTION: felt252 = 'OB: must use fulfill auction'; const OFFER_NOT_STARTED: felt252 = 'OB: offer is not started'; + const INVALID_BROKER: felt252 = 'OB: broker is not whitelisted'; } /// StarkNet smart contract module for an order book. @@ -153,6 +152,10 @@ mod orderbook { order_read, order_status_read, order_write, order_status_write, order_type_read }; + use ark_orderbook::broker::database::{ + broker_whitelist_write + }; + const EXTENSION_TIME_IN_SECONDS: u64 = 600; const AUCTION_ACCEPTING_TIME_SECS: u64 = 172800; /// Storage struct for the Orderbook contract. @@ -168,12 +171,6 @@ mod orderbook { /// Mapping of broker addresses to their whitelisted status. /// Represented as felt252, set to 1 if the broker is registered. brokers: LegacyMap, - /// Mapping of creator_brokers addresses to their whitelisted status. - /// Represented as felt252, set to 1 if the broker is registered. - creator_brokers: LegacyMap, - /// Mapping of fulfiller_brokers addresses to their whitelisted status. - /// Represented as felt252, set to 1 if the broker is registered. - fulfiller_brokers: LegacyMap, /// Mapping of token_hash to order_hash. token_listings: LegacyMap, /// Mapping of token_hash to auction details (order_hash and end_date, auction_offer_count). @@ -280,17 +277,6 @@ mod orderbook { self.emit(OrderExecuted { order_hash: info.order_hash, order_status: order_status }); } - /// Check if a broker is whitelisted - fn is_broker_whitelisted(ref self: ContractState, broker_id: felt252, broker_type: felt252) -> felt252 { - let mut is_whitelisted = 0; - if (broker_type == 0) { - is_whitelisted = self.creator_brokers.read(broker_id); - } else if (broker_type == 1) { - is_whitelisted = self.fulfiller_brokers.read(broker_id); - } - is_whitelisted - } - // ************************************************************************* // EXTERNAL FUNCTIONS // ************************************************************************* @@ -375,27 +361,15 @@ mod orderbook { } /// Whitelists a broker. - fn whitelist_broker(ref self: ContractState, broker_id: felt252, broker_type: felt252) { + fn whitelist_broker(ref self: ContractState, broker_id: felt252) { assert(starknet::get_caller_address() == self.admin.read(), 'Unauthorized update'); - - self.brokers.write(broker_id, 1); - - if (broker_type == 0) { - self.creator_brokers.write(broker_id, 1); - } else if (broker_type == 1) { - self.fulfiller_brokers.write(broker_id, 1); - } + broker_whitelist_write(broker_id, 1); } - fn unwhitelist_broker(ref self: ContractState, broker_id: felt252, broker_type: felt252) { + /// Remove a broker from whitelist. + fn unwhitelist_broker(ref self: ContractState, broker_id: felt252) { assert(starknet::get_caller_address() == self.admin.read(), 'Unauthorized update'); - self.brokers.write(broker_id, 0); - - if (broker_type == 0) { - self.creator_brokers.write(broker_id, 0); - } else if (broker_type == 1) { - self.fulfiller_brokers.write(broker_id, 0); - } + broker_whitelist_write(broker_id, 0); } /// Submits and places an order to the orderbook if the order is valid. diff --git a/contracts/ark_orderbook/src/orderbook_event_mock.cairo b/contracts/ark_orderbook/src/orderbook_event_mock.cairo index d4ed7ac65..40e952903 100644 --- a/contracts/ark_orderbook/src/orderbook_event_mock.cairo +++ b/contracts/ark_orderbook/src/orderbook_event_mock.cairo @@ -109,7 +109,6 @@ mod orderbook_event_mock { start_date: 5, end_date: 6, broker_id: 'broker', - broker_type: 0, additional_data: array![].span(), } } @@ -140,7 +139,6 @@ mod orderbook_event_mock { start_date: 5, end_date: 6, broker_id: 'broker', - broker_type: 1, additional_data: array![].span(), } } @@ -171,7 +169,6 @@ mod orderbook_event_mock { start_date: 2, end_date: 0, broker_id: 'broker', - broker_type: 0, additional_data: array![].span(), } } diff --git a/contracts/ark_orderbook/tests/common/setup.cairo b/contracts/ark_orderbook/tests/common/setup.cairo index 312c97d1c..801e85900 100644 --- a/contracts/ark_orderbook/tests/common/setup.cairo +++ b/contracts/ark_orderbook/tests/common/setup.cairo @@ -4,10 +4,15 @@ use core::traits::Into; use ark_common::protocol::order_types::{RouteType, FulfillInfo, OrderTrait, OrderType, OrderStatus}; use ark_common::crypto::signer::{Signer, SignInfo}; use ark_orderbook::order::order_v1::OrderV1; +use ark_orderbook::orderbook::{OrderbookDispatcher, OrderbookDispatcherTrait}; + use snforge_std::signature::{ StarkCurveKeyPair, StarkCurveKeyPairTrait, Signer as SNSigner, Verifier }; +use snforge_std::{start_prank, stop_prank}; +use starknet::ContractAddress; + use super::super::common::signer::sign_mock; /// Utility function to setup orders for test environment. /// @@ -215,7 +220,7 @@ fn setup_listing_order(price: felt252) -> (OrderV1, felt252, felt252) { /// Utility function to setup a listing order for test environment. /// /// # Returns a tuple of the different orders data -/// +/// /// * order_listing /// * sign_info /// * order_hash @@ -366,3 +371,9 @@ fn get_offer_order() -> OrderV1 { additional_data: data_span, } } + +fn whitelist_creator_broker(contract_address: ContractAddress, broker_id: felt252, dispatcher: OrderbookDispatcher) { + start_prank(contract_address, 0x00E4769a4d2F7F69C70951A003eBA5c32707Cef3CdfB6B27cA63567f51cdd078.try_into().unwrap()); + dispatcher.whitelist_broker(broker_id); + stop_prank(contract_address); +} diff --git a/contracts/ark_orderbook/tests/integration/test_cancel_order.cairo b/contracts/ark_orderbook/tests/integration/test_cancel_order.cairo index 51f7281ab..e0d2fb473 100644 --- a/contracts/ark_orderbook/tests/integration/test_cancel_order.cairo +++ b/contracts/ark_orderbook/tests/integration/test_cancel_order.cairo @@ -14,7 +14,7 @@ use snforge_std::{ }; use super::super::common::setup::{ - setup_auction_order, setup_listing, sign_mock, setup_orders, setup_offer + setup_auction_order, setup_listing, sign_mock, setup_orders, setup_offer, whitelist_creator_broker }; #[test] @@ -34,6 +34,7 @@ fn test_cancel_auction() { let contract_address = contract.deploy(@contract_data).unwrap(); let dispatcher = OrderbookDispatcher { contract_address }; + whitelist_creator_broker(contract_address, auction_listing_order.broker_id, dispatcher); dispatcher.create_order(order: auction_listing_order, signer: signer); let cancel_info = CancelInfo { @@ -100,6 +101,7 @@ fn test_invalid_cancel_auction_order() { let contract_address = contract.deploy(@contract_data).unwrap(); let dispatcher = OrderbookDispatcher { contract_address }; + whitelist_creator_broker(contract_address, auction_listing_order.broker_id, dispatcher); dispatcher.create_order(order: auction_listing_order, signer: signer); let order_type = dispatcher.get_order_type(order_hash); @@ -138,6 +140,7 @@ fn test_cancel_auction_during_the_extended_time() { ]; let contract_address = contract.deploy(@contract_data).unwrap(); let dispatcher = OrderbookDispatcher { contract_address }; + whitelist_creator_broker(contract_address, auction_listing_order.broker_id, dispatcher); dispatcher.create_order(order: auction_listing_order, signer: auction_listing_signer); let order_type = dispatcher.get_order_type(order_hash); assert(order_type == OrderType::Auction.into(), 'order is not auction'); diff --git a/contracts/ark_orderbook/tests/integration/test_create_auction_offers.cairo b/contracts/ark_orderbook/tests/integration/test_create_auction_offers.cairo index 78b3b31f6..2ce38d6f3 100644 --- a/contracts/ark_orderbook/tests/integration/test_create_auction_offers.cairo +++ b/contracts/ark_orderbook/tests/integration/test_create_auction_offers.cairo @@ -11,7 +11,7 @@ use snforge_std::{ start_warp, declare, ContractClassTrait, spy_events, EventSpy, EventFetcher, EventAssertions, Event, SpyOn, test_address, signature::{StarkCurveKeyPair, StarkCurveKeyPairTrait, Verifier} }; -use super::super::common::setup::{setup_auction_order, sign_mock, setup_orders, setup_offer}; +use super::super::common::setup::{setup_auction_order, sign_mock, setup_orders, setup_offer, whitelist_creator_broker}; #[test] fn test_create_valid_auction_offer() { @@ -29,6 +29,7 @@ fn test_create_valid_auction_offer() { let contract_address = contract.deploy(@contract_data).unwrap(); let dispatcher = OrderbookDispatcher { contract_address }; + whitelist_creator_broker(contract_address, auction_listing_order.broker_id, dispatcher); dispatcher.create_order(order: auction_listing_order, signer: signer); let (auction_offer, signer, order_hash, token_hash) = setup_offer( @@ -53,6 +54,7 @@ fn test_accept_auction_after_expiration() { let contract_address = contract.deploy(@contract_data).unwrap(); let dispatcher = OrderbookDispatcher { contract_address }; + whitelist_creator_broker(contract_address, auction_listing_order.broker_id, dispatcher); dispatcher.create_order(order: auction_listing_order, signer: signer); let (auction_offer, signer, auction_offer_order_hash, token_hash) = setup_offer( diff --git a/contracts/ark_orderbook/tests/integration/test_create_listing_order.cairo b/contracts/ark_orderbook/tests/integration/test_create_listing_order.cairo index 6fe439468..453c1876c 100644 --- a/contracts/ark_orderbook/tests/integration/test_create_listing_order.cairo +++ b/contracts/ark_orderbook/tests/integration/test_create_listing_order.cairo @@ -8,7 +8,7 @@ use ark_orderbook::order::order_v1::OrderV1; use ark_orderbook::orderbook::{OrderbookDispatcher, OrderbookDispatcherTrait}; use starknet::deploy_syscall; use super::super::common::setup::{ - setup_auction_order, setup_listing, sign_mock, setup_orders, setup_offer + setup_auction_order, setup_listing, sign_mock, setup_orders, setup_offer, whitelist_creator_broker }; use snforge_std::{ start_warp, declare, ContractClassTrait, spy_events, EventSpy, EventFetcher, EventAssertions, @@ -30,6 +30,7 @@ fn test_create_existing_order() { ]; let contract_address = contract.deploy(@contract_data).unwrap(); let dispatcher = OrderbookDispatcher { contract_address }; + whitelist_creator_broker(contract_address, order_listing.broker_id, dispatcher); dispatcher.create_order(order: order_listing, signer: signer); dispatcher.create_order(order: order_listing, signer: signer); } @@ -48,6 +49,7 @@ fn test_create_listing_order() { ]; let contract_address = contract.deploy(@contract_data).unwrap(); let dispatcher = OrderbookDispatcher { contract_address }; + whitelist_creator_broker(contract_address, order_listing.broker_id, dispatcher); dispatcher.create_order(order: order_listing, signer: signer); let order = dispatcher.get_order(_order_hash); let order_status = dispatcher.get_order_status(_order_hash); @@ -103,8 +105,8 @@ fn test_auction_order_with_extended_time_order() { 0x00E4769a4d2F7F69C70951A003eBA5c32707Cef3CdfB6B27cA63567f51cdd078, chain_id ]; let contract_address = contract.deploy(@contract_data).unwrap(); - let dispatcher = OrderbookDispatcher { contract_address }; + whitelist_creator_broker(contract_address, auction_listing_order.broker_id, dispatcher); dispatcher.create_order(order: auction_listing_order, signer: auction_listing_signer); let order_type = dispatcher.get_order_type(order_hash); diff --git a/contracts/ark_orderbook/tests/integration/test_fulfill_auction.cairo b/contracts/ark_orderbook/tests/integration/test_fulfill_auction.cairo index b2e71e47f..867406212 100644 --- a/contracts/ark_orderbook/tests/integration/test_fulfill_auction.cairo +++ b/contracts/ark_orderbook/tests/integration/test_fulfill_auction.cairo @@ -13,7 +13,7 @@ use snforge_std::{ Event, SpyOn, test_address, signature::{StarkCurveKeyPair, StarkCurveKeyPairTrait, Verifier} }; use super::super::common::setup::{ - setup_auction_order, setup_listing, sign_mock, setup_orders, setup_offer + setup_auction_order, setup_listing, sign_mock, setup_orders, setup_offer, whitelist_creator_broker }; /// Test @@ -39,6 +39,7 @@ fn test_fulfill_auction() { let contract_address = contract.deploy(@contract_data).unwrap(); let dispatcher = OrderbookDispatcher { contract_address }; + whitelist_creator_broker(contract_address, auction_listing_order.broker_id, dispatcher); dispatcher.create_order(order: auction_listing_order, signer: auction_signer); let (auction_offer, related_order_signer, related_order_hash, related_order_token_hash) = @@ -61,7 +62,7 @@ fn test_fulfill_auction() { let offer_signer = sign_mock(fulfill_info_hash, auction_listing_order.offerer); let mut original_order_hash_signer = sign_mock(order_hash, auction_listing_order.offerer); let public_key = original_order_hash_signer.get_public_key(); - // sign original orderhash + // sign original orderhash // from signer send public key dispatcher.fulfill_order(fulfill_info, offer_signer); } @@ -87,6 +88,7 @@ fn test_fulfill_auction_with_classic_offer() { let (offer_order, offer_signer, offer_order_hash, offer_order_token_hash) = setup_offer( offer_start_date, offer_end_date, Option::None, Option::None ); + whitelist_creator_broker(contract_address, offer_order.broker_id, dispatcher); dispatcher.create_order(order: offer_order, signer: offer_signer); // Create an auction @@ -135,6 +137,8 @@ fn test_fulfill_auction_with_future_offer() { let (offer_order, offer_signer, offer_order_hash, offer_order_token_hash) = setup_offer( offer_start_date, offer_end_date, Option::None, Option::None ); + whitelist_creator_broker(contract_address, offer_order.broker_id, dispatcher); + dispatcher.create_order(order: offer_order, signer: offer_signer); // Create an auction @@ -182,6 +186,8 @@ fn test_fulfill_auction_with_expired_offer() { let (offer_order, offer_signer, offer_order_hash, offer_order_token_hash) = setup_offer( offer_start_date, offer_end_date, Option::None, Option::None ); + whitelist_creator_broker(contract_address, offer_order.broker_id, dispatcher); + dispatcher.create_order(order: offer_order, signer: offer_signer); // Create an auction @@ -229,6 +235,7 @@ fn test_fulfill_expired_auction() { let (offer_order, offer_signer, offer_order_hash, offer_order_token_hash) = setup_offer( offer_start_date, offer_end_date, Option::None, Option::None ); + whitelist_creator_broker(contract_address, offer_order.broker_id, dispatcher); dispatcher.create_order(order: offer_order, signer: offer_signer); // Create an auction @@ -276,6 +283,7 @@ fn test_fulfill_auction_with_offer_for_different_token() { let (mut offer_order, offer_signer, offer_order_hash, offer_order_token_hash) = setup_offer( offer_start_date, offer_end_date, Option::None, Option::Some(42) ); + whitelist_creator_broker(contract_address, offer_order.broker_id, dispatcher); dispatcher.create_order(order: offer_order, signer: offer_signer); // Create an auction @@ -323,6 +331,7 @@ fn test_fulfill_auction_with_non_existing_related_order_hash() { let (auction_listing_order, auction_signer, order_hash, token_hash) = setup_auction_order( start_date, end_date, 1, 10, Option::None ); + whitelist_creator_broker(contract_address, auction_listing_order.broker_id, dispatcher); dispatcher.create_order(order: auction_listing_order, signer: auction_signer); start_warp(contract_address, start_date + 3600); @@ -360,13 +369,15 @@ fn test_fulfill_auction_with_listing_order() { let (auction_listing_order, auction_signer, order_hash, token_hash) = setup_auction_order( start_date, end_date, 1, 10, Option::None ); + whitelist_creator_broker(contract_address, auction_listing_order.broker_id, dispatcher); dispatcher.create_order(order: auction_listing_order, signer: auction_signer); - //create a listing order + //create a listing order let (listing_order, listing_signer, listing_order_hash, listing_order_token_hash) = setup_listing( start_date, end_date, Option::Some(123) ); + whitelist_creator_broker(contract_address, listing_order.broker_id, dispatcher); dispatcher.create_order(order: listing_order, signer: listing_signer); start_warp(contract_address, start_date + 3600); diff --git a/contracts/ark_orderbook/tests/integration/test_fulfill_listing.cairo b/contracts/ark_orderbook/tests/integration/test_fulfill_listing.cairo index 6c815d8df..ae554e74d 100644 --- a/contracts/ark_orderbook/tests/integration/test_fulfill_listing.cairo +++ b/contracts/ark_orderbook/tests/integration/test_fulfill_listing.cairo @@ -12,7 +12,7 @@ use starknet::deploy_syscall; use snforge_std::start_warp; use super::super::common::signer::sign_mock; -use super::super::common::setup::{setup_listing, setup_listing_order_with_sign}; +use super::super::common::setup::{setup_listing, setup_listing_order_with_sign, whitelist_creator_broker}; // try to fulfill an order that doesn't exist #[should_panic(expected: ('OB: order not found',))] @@ -68,7 +68,7 @@ fn test_create_listing_order_and_fulfill() { ]; let contract_address = contract.deploy(@contract_data).unwrap(); let dispatcher = OrderbookDispatcher { contract_address }; - + whitelist_creator_broker(contract_address, order_listing.broker_id, dispatcher); dispatcher.create_order(order: order_listing, signer: signer); let order = dispatcher.get_order(order_hash); let fulfiller = 0x00E4769a4d2F7F69C70931A003eBA5c32707Cef3CdfB6B27cA63567f51cdd078 @@ -112,7 +112,7 @@ fn test_create_listing_order_and_fulfill_with_same_fulfiller() { ]; let contract_address = contract.deploy(@contract_data).unwrap(); let dispatcher = OrderbookDispatcher { contract_address }; - + whitelist_creator_broker(contract_address, order_listing.broker_id, dispatcher); dispatcher.create_order(order: order_listing, signer: signer); let order = dispatcher.get_order(order_hash); @@ -148,6 +148,8 @@ fn test_fulfill_already_fulfilled_order() { ]; let contract_address = contract.deploy(@contract_data).unwrap(); let dispatcher = OrderbookDispatcher { contract_address }; + whitelist_creator_broker(contract_address, order_listing.broker_id, dispatcher); + dispatcher.create_order(order: order_listing, signer: signer); let fulfiller = 0x00E4769a4d2F7F69C70931A003eBA5c32707Cef3CdfB6B27cA63567f51cdd078 .try_into() @@ -183,6 +185,7 @@ fn test_fulfill_expired_order() { ]; let contract_address = contract.deploy(@contract_data).unwrap(); let dispatcher = OrderbookDispatcher { contract_address }; + whitelist_creator_broker(contract_address, order_listing.broker_id, dispatcher); dispatcher.create_order(order: order_listing, signer: signer); start_warp(contract_address, order_listing.end_date + 10); diff --git a/contracts/ark_orderbook/tests/integration/test_fulfill_offers.cairo b/contracts/ark_orderbook/tests/integration/test_fulfill_offers.cairo index 133e26e9b..445f1ce69 100644 --- a/contracts/ark_orderbook/tests/integration/test_fulfill_offers.cairo +++ b/contracts/ark_orderbook/tests/integration/test_fulfill_offers.cairo @@ -15,7 +15,7 @@ use snforge_std::{ }; use super::super::common::signer::sign_mock; -use super::super::common::setup::{setup_orders, setup_listing_order_with_sign}; +use super::super::common::setup::{setup_orders, setup_listing_order_with_sign, whitelist_creator_broker}; // FIX with start date // #[test] @@ -70,6 +70,7 @@ fn test_fulfill_expired_offer() { let offer_order_hash = order_offer.compute_order_hash(); let offer_signer = sign_mock(offer_order_hash, order_offer.offerer); + whitelist_creator_broker(contract_address, order_offer.broker_id, dispatcher); dispatcher.create_order(order: order_offer, signer: offer_signer); start_warp(contract_address, order_listing.start_date + 2000); @@ -133,6 +134,7 @@ fn test_fulfill_classic_offer() { let listing_order_hash = order_listing.compute_order_hash(); let signer = sign_mock(listing_order_hash, order_listing.offerer); + whitelist_creator_broker(contract_address, order_listing.broker_id, dispatcher); dispatcher.create_order(order: order_listing, signer: signer); order_offer.start_date = order_listing.start_date; @@ -196,6 +198,7 @@ fn test_fulfill_collection_offer() { let offer_order_hash = order_offer.compute_order_hash(); let offer_signer = sign_mock(offer_order_hash, order_offer.offerer); + whitelist_creator_broker(contract_address, order_offer.broker_id, dispatcher); dispatcher.create_order(order: order_offer, signer: offer_signer); start_warp(contract_address, order_offer.start_date); @@ -258,6 +261,7 @@ fn test_fulfill_expired_collection_offer() { let offer_order_hash = order_offer.compute_order_hash(); let offer_signer = sign_mock(offer_order_hash, order_offer.offerer); + whitelist_creator_broker(contract_address, order_offer.broker_id, dispatcher); dispatcher.create_order(order: order_offer, signer: offer_signer); start_warp(contract_address, order_offer.end_date); @@ -295,6 +299,8 @@ fn test_double_fulfill_offer() { let listing_order_hash = order_listing.compute_order_hash(); let signer = sign_mock(listing_order_hash, order_listing.offerer); + whitelist_creator_broker(contract_address, order_listing.broker_id, dispatcher); + dispatcher.create_order(order: order_listing, signer: signer); order_offer.start_date = order_listing.start_date; diff --git a/contracts/ark_orderbook/tests/unit/order/test_order_v1.cairo b/contracts/ark_orderbook/tests/unit/order/test_order_v1.cairo index 274bc427a..e60939be7 100644 --- a/contracts/ark_orderbook/tests/unit/order/test_order_v1.cairo +++ b/contracts/ark_orderbook/tests/unit/order/test_order_v1.cairo @@ -4,10 +4,14 @@ use core::traits::Into; use core::traits::TryInto; use ark_orderbook::order::order_v1::OrderV1; use ark_orderbook::order::order_v1::OrderTraitOrderV1; +use ark_orderbook::orderbook::{orderbook, orderbook_errors, OrderbookDispatcher, OrderbookDispatcherTrait}; use ark_common::protocol::order_types::{OrderType, OrderTrait, RouteType}; use ark_common::crypto::signer::{SignInfo, Signer, SignerValidator}; use debug::PrintTrait; -use super::super::super::common::setup::setup_orders; +use super::super::super::common::setup::{setup_orders, whitelist_creator_broker}; +use snforge_std::{ + ContractClassTrait, declare +}; // ********************************************************* // validate_common_data @@ -17,6 +21,9 @@ use super::super::super::common::setup::setup_orders; fn test_validate_common_data_with_valid_order() { let (order_listing, _, _, _) = setup_orders(); let block_timestmap: u64 = 1699556828; + let mut state = orderbook::contract_state_for_testing(); + orderbook::ImplOrderbook::whitelist_broker(ref state, order_listing.broker_id); + let result = order_listing.validate_common_data(block_timestmap); assert(result.is_ok(), 'Invalid result'); } @@ -47,6 +54,8 @@ fn should_returns_invalid_order_with_zero_salt() { fn should_returns_invalid_order_with_no_token_id() { let (order_listing, _, _, _) = setup_orders(); let block_timestmap: u64 = 1699556828; + let mut state = orderbook::contract_state_for_testing(); + orderbook::ImplOrderbook::whitelist_broker(ref state, order_listing.broker_id); let mut invalid_order = order_listing.clone(); invalid_order.token_id = Option::None; From 96dd6c93185ddf4f8daa8ead429cceeff164d82c Mon Sep 17 00:00:00 2001 From: bexan Date: Tue, 20 Feb 2024 08:29:43 +0100 Subject: [PATCH 3/3] contracts ark_orderbook: add a not whitelisted test --- .../ark_orderbook/src/broker/database.cairo | 5 ++--- .../ark_orderbook/src/order/order_v1.cairo | 4 +--- contracts/ark_orderbook/src/orderbook.cairo | 5 +---- .../ark_orderbook/tests/common/setup.cairo | 9 ++++++-- .../tests/integration/test_cancel_order.cairo | 3 ++- .../test_create_auction_offers.cairo | 4 +++- .../test_create_listing_order.cairo | 21 ++++++++++++++++++- .../integration/test_fulfill_auction.cairo | 3 ++- .../integration/test_fulfill_listing.cairo | 4 +++- .../integration/test_fulfill_offers.cairo | 4 +++- .../tests/unit/order/test_order_v1.cairo | 8 +++---- 11 files changed, 48 insertions(+), 22 deletions(-) diff --git a/contracts/ark_orderbook/src/broker/database.cairo b/contracts/ark_orderbook/src/broker/database.cairo index ea1d43649..a7e498603 100644 --- a/contracts/ark_orderbook/src/broker/database.cairo +++ b/contracts/ark_orderbook/src/broker/database.cairo @@ -24,7 +24,6 @@ const ADDRESS_DOMAIN: u32 = 0; const BROKER_DB_BASE_KEY: felt252 = 'broker whitelist'; - /// Reads whitelist status of broker. /// /// # Arguments @@ -40,7 +39,8 @@ fn broker_whitelist_read(broker_id: felt252) -> bool { // First offset is the status. let whitelisted: felt252 = starknet::storage_read_syscall( ADDRESS_DOMAIN, starknet::storage_address_from_base(base) - ).unwrap_syscall(); + ) + .unwrap_syscall(); whitelisted == 1 } @@ -53,7 +53,6 @@ fn broker_whitelist_read(broker_id: felt252) -> bool { /// * `broker_id` - ID of the broker. /// * `status` - 1 if whitelisted, 0 if not. fn broker_whitelist_write(broker_id: felt252, status: felt252) -> bool { - let key = array![BROKER_DB_BASE_KEY, broker_id]; let base = starknet::storage_base_address_from_felt252( diff --git a/contracts/ark_orderbook/src/order/order_v1.cairo b/contracts/ark_orderbook/src/order/order_v1.cairo index 60add3f86..e6d95c39e 100644 --- a/contracts/ark_orderbook/src/order/order_v1.cairo +++ b/contracts/ark_orderbook/src/order/order_v1.cairo @@ -3,9 +3,7 @@ use core::traits::Into; use core::traits::TryInto; use core::option::OptionTrait; -use ark_orderbook::broker::database::{ - broker_whitelist_read -}; +use ark_orderbook::broker::database::{broker_whitelist_read}; //! Order v1 supported by the Orderbook. //! diff --git a/contracts/ark_orderbook/src/orderbook.cairo b/contracts/ark_orderbook/src/orderbook.cairo index 9c12c8753..aba2cd9b5 100644 --- a/contracts/ark_orderbook/src/orderbook.cairo +++ b/contracts/ark_orderbook/src/orderbook.cairo @@ -152,9 +152,7 @@ mod orderbook { order_read, order_status_read, order_write, order_status_write, order_type_read }; - use ark_orderbook::broker::database::{ - broker_whitelist_write - }; + use ark_orderbook::broker::database::{broker_whitelist_write}; const EXTENSION_TIME_IN_SECONDS: u64 = 600; const AUCTION_ACCEPTING_TIME_SECS: u64 = 172800; @@ -501,7 +499,6 @@ mod orderbook { // ************************************************************************* #[generate_trait] impl InternalFunctions of InternalFunctionsTrait { - /// Fulfill auction order /// /// # Arguments diff --git a/contracts/ark_orderbook/tests/common/setup.cairo b/contracts/ark_orderbook/tests/common/setup.cairo index 801e85900..5b779a87a 100644 --- a/contracts/ark_orderbook/tests/common/setup.cairo +++ b/contracts/ark_orderbook/tests/common/setup.cairo @@ -372,8 +372,13 @@ fn get_offer_order() -> OrderV1 { } } -fn whitelist_creator_broker(contract_address: ContractAddress, broker_id: felt252, dispatcher: OrderbookDispatcher) { - start_prank(contract_address, 0x00E4769a4d2F7F69C70951A003eBA5c32707Cef3CdfB6B27cA63567f51cdd078.try_into().unwrap()); +fn whitelist_creator_broker( + contract_address: ContractAddress, broker_id: felt252, dispatcher: OrderbookDispatcher +) { + start_prank( + contract_address, + 0x00E4769a4d2F7F69C70951A003eBA5c32707Cef3CdfB6B27cA63567f51cdd078.try_into().unwrap() + ); dispatcher.whitelist_broker(broker_id); stop_prank(contract_address); } diff --git a/contracts/ark_orderbook/tests/integration/test_cancel_order.cairo b/contracts/ark_orderbook/tests/integration/test_cancel_order.cairo index e0d2fb473..cfb7832c2 100644 --- a/contracts/ark_orderbook/tests/integration/test_cancel_order.cairo +++ b/contracts/ark_orderbook/tests/integration/test_cancel_order.cairo @@ -14,7 +14,8 @@ use snforge_std::{ }; use super::super::common::setup::{ - setup_auction_order, setup_listing, sign_mock, setup_orders, setup_offer, whitelist_creator_broker + setup_auction_order, setup_listing, sign_mock, setup_orders, setup_offer, + whitelist_creator_broker }; #[test] diff --git a/contracts/ark_orderbook/tests/integration/test_create_auction_offers.cairo b/contracts/ark_orderbook/tests/integration/test_create_auction_offers.cairo index 2ce38d6f3..427e0fb05 100644 --- a/contracts/ark_orderbook/tests/integration/test_create_auction_offers.cairo +++ b/contracts/ark_orderbook/tests/integration/test_create_auction_offers.cairo @@ -11,7 +11,9 @@ use snforge_std::{ start_warp, declare, ContractClassTrait, spy_events, EventSpy, EventFetcher, EventAssertions, Event, SpyOn, test_address, signature::{StarkCurveKeyPair, StarkCurveKeyPairTrait, Verifier} }; -use super::super::common::setup::{setup_auction_order, sign_mock, setup_orders, setup_offer, whitelist_creator_broker}; +use super::super::common::setup::{ + setup_auction_order, sign_mock, setup_orders, setup_offer, whitelist_creator_broker +}; #[test] fn test_create_valid_auction_offer() { diff --git a/contracts/ark_orderbook/tests/integration/test_create_listing_order.cairo b/contracts/ark_orderbook/tests/integration/test_create_listing_order.cairo index 453c1876c..2fdbde79e 100644 --- a/contracts/ark_orderbook/tests/integration/test_create_listing_order.cairo +++ b/contracts/ark_orderbook/tests/integration/test_create_listing_order.cairo @@ -8,7 +8,8 @@ use ark_orderbook::order::order_v1::OrderV1; use ark_orderbook::orderbook::{OrderbookDispatcher, OrderbookDispatcherTrait}; use starknet::deploy_syscall; use super::super::common::setup::{ - setup_auction_order, setup_listing, sign_mock, setup_orders, setup_offer, whitelist_creator_broker + setup_auction_order, setup_listing, sign_mock, setup_orders, setup_offer, + whitelist_creator_broker }; use snforge_std::{ start_warp, declare, ContractClassTrait, spy_events, EventSpy, EventFetcher, EventAssertions, @@ -35,6 +36,24 @@ fn test_create_existing_order() { dispatcher.create_order(order: order_listing, signer: signer); } +#[test] +#[should_panic(expected: ('INVALID_BROKER',))] +fn test_create_order_not_whitelisted() { + let start_date = 1699556828; + let end_date = start_date + (10 * 24 * 60 * 60); + let (order_listing, signer, _order_hash, token_hash) = setup_listing( + start_date, end_date, Option::Some(123) + ); + let contract = declare('orderbook'); + let chain_id = 0x534e5f4d41494e; + let contract_data = array![ + 0x00E4769a4d2F7F69C70951A003eBA5c32707Cef3CdfB6B27cA63567f51cdd078, chain_id + ]; + let contract_address = contract.deploy(@contract_data).unwrap(); + let dispatcher = OrderbookDispatcher { contract_address }; + dispatcher.create_order(order: order_listing, signer: signer); +} + #[test] fn test_create_listing_order() { let start_date = 1699556828; diff --git a/contracts/ark_orderbook/tests/integration/test_fulfill_auction.cairo b/contracts/ark_orderbook/tests/integration/test_fulfill_auction.cairo index 867406212..dca79c40d 100644 --- a/contracts/ark_orderbook/tests/integration/test_fulfill_auction.cairo +++ b/contracts/ark_orderbook/tests/integration/test_fulfill_auction.cairo @@ -13,7 +13,8 @@ use snforge_std::{ Event, SpyOn, test_address, signature::{StarkCurveKeyPair, StarkCurveKeyPairTrait, Verifier} }; use super::super::common::setup::{ - setup_auction_order, setup_listing, sign_mock, setup_orders, setup_offer, whitelist_creator_broker + setup_auction_order, setup_listing, sign_mock, setup_orders, setup_offer, + whitelist_creator_broker }; /// Test diff --git a/contracts/ark_orderbook/tests/integration/test_fulfill_listing.cairo b/contracts/ark_orderbook/tests/integration/test_fulfill_listing.cairo index ae554e74d..9ffad1519 100644 --- a/contracts/ark_orderbook/tests/integration/test_fulfill_listing.cairo +++ b/contracts/ark_orderbook/tests/integration/test_fulfill_listing.cairo @@ -12,7 +12,9 @@ use starknet::deploy_syscall; use snforge_std::start_warp; use super::super::common::signer::sign_mock; -use super::super::common::setup::{setup_listing, setup_listing_order_with_sign, whitelist_creator_broker}; +use super::super::common::setup::{ + setup_listing, setup_listing_order_with_sign, whitelist_creator_broker +}; // try to fulfill an order that doesn't exist #[should_panic(expected: ('OB: order not found',))] diff --git a/contracts/ark_orderbook/tests/integration/test_fulfill_offers.cairo b/contracts/ark_orderbook/tests/integration/test_fulfill_offers.cairo index 445f1ce69..989edb506 100644 --- a/contracts/ark_orderbook/tests/integration/test_fulfill_offers.cairo +++ b/contracts/ark_orderbook/tests/integration/test_fulfill_offers.cairo @@ -15,7 +15,9 @@ use snforge_std::{ }; use super::super::common::signer::sign_mock; -use super::super::common::setup::{setup_orders, setup_listing_order_with_sign, whitelist_creator_broker}; +use super::super::common::setup::{ + setup_orders, setup_listing_order_with_sign, whitelist_creator_broker +}; // FIX with start date // #[test] diff --git a/contracts/ark_orderbook/tests/unit/order/test_order_v1.cairo b/contracts/ark_orderbook/tests/unit/order/test_order_v1.cairo index e60939be7..414bf0597 100644 --- a/contracts/ark_orderbook/tests/unit/order/test_order_v1.cairo +++ b/contracts/ark_orderbook/tests/unit/order/test_order_v1.cairo @@ -4,14 +4,14 @@ use core::traits::Into; use core::traits::TryInto; use ark_orderbook::order::order_v1::OrderV1; use ark_orderbook::order::order_v1::OrderTraitOrderV1; -use ark_orderbook::orderbook::{orderbook, orderbook_errors, OrderbookDispatcher, OrderbookDispatcherTrait}; +use ark_orderbook::orderbook::{ + orderbook, orderbook_errors, OrderbookDispatcher, OrderbookDispatcherTrait +}; use ark_common::protocol::order_types::{OrderType, OrderTrait, RouteType}; use ark_common::crypto::signer::{SignInfo, Signer, SignerValidator}; use debug::PrintTrait; use super::super::super::common::setup::{setup_orders, whitelist_creator_broker}; -use snforge_std::{ - ContractClassTrait, declare -}; +use snforge_std::{ContractClassTrait, declare}; // ********************************************************* // validate_common_data