diff --git a/contracts/auctions/src/contract.rs b/contracts/auctions/src/contract.rs index 54b4435..6ce070c 100644 --- a/contracts/auctions/src/contract.rs +++ b/contracts/auctions/src/contract.rs @@ -23,6 +23,7 @@ impl MarketplaceContract { env: Env, admin: Address, auction_token: Address, + auction_creation_fee: u128, ) -> Result<(), ContractError> { admin.require_auth(); @@ -32,7 +33,13 @@ impl MarketplaceContract { } save_admin_old(&env, &admin); - save_auction_token(&env, auction_token); + + let config = Config { + auction_token, + auction_creation_fee, + }; + + save_config(&env, config); set_initialized(&env); @@ -62,7 +69,28 @@ impl MarketplaceContract { validate_input_params(&env, &input_values[..])?; - let auction_token = get_auction_token(&env)?; + let config = get_config(&env)?; + let auction_token = config.auction_token; + let auction_creation_fee = config.auction_creation_fee as i128; + + let token_client = token::Client::new(&env, &auction_token); + + if token_client.balance(&seller) < auction_creation_fee { + log!( + &env, + "Auction: Create Auctoin: Not enough balance to cover the auction creation fee. ", + "Required: ", + auction_creation_fee + ); + return Err(ContractError::AuctionCreationFeeNotCovered); + } + + token_client.transfer( + &seller, + &env.current_contract_address(), + &auction_creation_fee, + ); + let nft_client = collection::Client::new(&env, &item_info.collection_addr); let item_balance = nft_client.balance_of(&seller, &item_info.item_id); diff --git a/contracts/auctions/src/error.rs b/contracts/auctions/src/error.rs index 53ec611..d44a046 100644 --- a/contracts/auctions/src/error.rs +++ b/contracts/auctions/src/error.rs @@ -21,5 +21,6 @@ pub enum ContractError { InvalidBidder = 14, AdminNotFound = 15, NoBidFound = 16, - AuctionTokenNotFound = 17, + ConfigNotFound = 17, + AuctionCreationFeeNotCovered = 18, } diff --git a/contracts/auctions/src/storage.rs b/contracts/auctions/src/storage.rs index ce65a8a..3ee83b2 100644 --- a/contracts/auctions/src/storage.rs +++ b/contracts/auctions/src/storage.rs @@ -23,7 +23,7 @@ pub enum DataKey { AuctionId, AllAuctions, HighestBid(u64), - AuctionToken, + Config, } #[derive(Clone, Debug, PartialEq)] @@ -64,6 +64,13 @@ pub enum AuctionStatus { Paused, } +#[derive(Clone, Debug)] +#[contracttype] +pub struct Config { + pub auction_token: Address, + pub auction_creation_fee: u128, +} + pub fn generate_auction_id(env: &Env) -> Result { let id = env .storage() @@ -274,35 +281,27 @@ pub fn set_highest_bid( Ok(()) } -pub fn save_auction_token(env: &Env, auction_token: Address) { +pub fn save_config(env: &Env, config: Config) { + env.storage().persistent().set(&DataKey::Config, &config); env.storage() .persistent() - .set(&DataKey::AuctionToken, &auction_token); - - env.storage() - .persistent() - .extend_ttl(&DataKey::AuctionToken, LIFETIME_THRESHOLD, BUMP_AMOUNT); + .extend_ttl(&DataKey::Config, LIFETIME_THRESHOLD, BUMP_AMOUNT); } -pub fn get_auction_token(env: &Env) -> Result { - let auction_token = env +pub fn get_config(env: &Env) -> Result { + let config = env .storage() .persistent() - .get(&DataKey::AuctionToken) - .ok_or(ContractError::AuctionTokenNotFound)?; + .get(&DataKey::Config) + .ok_or(ContractError::ConfigNotFound); - env.storage() - .persistent() - .has(&DataKey::AuctionToken) - .then(|| { - env.storage().persistent().extend_ttl( - &DataKey::AuctionToken, - LIFETIME_THRESHOLD, - BUMP_AMOUNT, - ); - }); + env.storage().persistent().has(&DataKey::Config).then(|| { + env.storage() + .persistent() + .extend_ttl(&DataKey::Config, LIFETIME_THRESHOLD, BUMP_AMOUNT) + }); - Ok(auction_token) + Ok(config)? } #[cfg(test)] diff --git a/contracts/auctions/src/test/bids.rs b/contracts/auctions/src/test/bids.rs index e4193c1..9b51af7 100644 --- a/contracts/auctions/src/test/bids.rs +++ b/contracts/auctions/src/test/bids.rs @@ -10,7 +10,6 @@ use crate::{ test::setup::{ deploy_token_contract, generate_marketplace_and_collection_client, DAY, FOUR_HOURS, WEEKLY, }, - token, }; use super::setup::create_and_initialize_collection; @@ -26,6 +25,7 @@ fn should_place_a_bid() { let bidder_c = Address::generate(&env); let token_client = deploy_token_contract(&env, &Address::generate(&env)); + token_client.mint(&seller, &10); let (mp_client, nft_collection_client) = generate_marketplace_and_collection_client( &env, &seller, @@ -55,7 +55,7 @@ fn should_place_a_bid() { bidder: bidder_a.clone() } ); - assert_eq!(token_client.balance(&mp_client.address), 10i128); + assert_eq!(token_client.balance(&mp_client.address), 20i128); assert_eq!(token_client.balance(&bidder_a), 0i128); mp_client.place_bid(&1, &bidder_b, &20); @@ -66,7 +66,7 @@ fn should_place_a_bid() { bidder: bidder_b.clone() } ); - assert_eq!(token_client.balance(&mp_client.address), 20i128); + assert_eq!(token_client.balance(&mp_client.address), 30i128); assert_eq!(token_client.balance(&bidder_a), 10i128); assert_eq!(token_client.balance(&bidder_b), 0i128); @@ -75,7 +75,7 @@ fn should_place_a_bid() { mp_client.try_place_bid(&1, &bidder_a, &15), Err(Ok(ContractError::BidNotEnough)) ); - assert_eq!(token_client.balance(&mp_client.address), 20i128); + assert_eq!(token_client.balance(&mp_client.address), 30i128); assert_eq!(token_client.balance(&bidder_a), 10i128); assert_eq!(token_client.balance(&bidder_b), 0i128); @@ -95,7 +95,7 @@ fn should_place_a_bid() { bidder: bidder_c.clone() } ); - assert_eq!(token_client.balance(&mp_client.address), 40i128); + assert_eq!(token_client.balance(&mp_client.address), 50i128); assert_eq!(token_client.balance(&bidder_a), 10i128); assert_eq!(token_client.balance(&bidder_b), 20i128); assert_eq!(token_client.balance(&bidder_c), 0i128); @@ -109,7 +109,9 @@ fn fail_to_place_bid_when_auction_inactive() { let seller = Address::generate(&env); let bidder_a = Address::generate(&env); - let token_client = token::Client::new(&env, &Address::generate(&env)); + let token_client = deploy_token_contract(&env, &Address::generate(&env)); + token_client.mint(&seller, &10); + let (mp_client, nft_collection_client) = generate_marketplace_and_collection_client( &env, &seller, @@ -148,7 +150,7 @@ fn seller_tries_to_place_a_bid_should_fail() { let seller = Address::generate(&env); let token_client = deploy_token_contract(&env, &Address::generate(&env)); - token_client.mint(&seller, &1); + token_client.mint(&seller, &11); let (mp_client, collection_client) = generate_marketplace_and_collection_client( &env, &seller, @@ -189,6 +191,7 @@ fn buy_now_should_fail_when_auction_not_active() { let token_client = deploy_token_contract(&env, &admin); + token_client.mint(&seller, &10); token_client.mint(&fomo_buyer, &50); let (mp_client, collections_client) = generate_marketplace_and_collection_client( @@ -231,6 +234,7 @@ fn buy_now_should_fail_when_no_buy_now_price_has_been_set() { let token_client = deploy_token_contract(&env, &admin); + token_client.mint(&seller, &10); token_client.mint(&fomo_buyer, &50); let (mp_client, collections_client) = generate_marketplace_and_collection_client( @@ -272,6 +276,7 @@ fn buy_now() { let fomo_buyer = Address::generate(&env); let token_client = deploy_token_contract(&env, &admin); + token_client.mint(&seller, &10); token_client.mint(&fomo_buyer, &100); token_client.mint(&bidder_a, &100); @@ -303,14 +308,14 @@ fn buy_now() { env.ledger().with_mut(|li| li.timestamp = FOUR_HOURS); mp_client.place_bid(&1, &bidder_a, &5); assert_eq!(token_client.balance(&bidder_a), 95); - assert_eq!(token_client.balance(&mp_client.address), 5); + assert_eq!(token_client.balance(&mp_client.address), 15); // 8 hours in and we have a second highest bid env.ledger().with_mut(|li| li.timestamp = FOUR_HOURS * 2); mp_client.place_bid(&1, &bidder_b, &10); assert_eq!(token_client.balance(&bidder_a), 100); assert_eq!(token_client.balance(&bidder_b), 90); - assert_eq!(token_client.balance(&mp_client.address), 10); + assert_eq!(token_client.balance(&mp_client.address), 20); // 16 hours in and we have a third highest bid env.ledger().with_mut(|li| li.timestamp = FOUR_HOURS * 4); @@ -318,7 +323,7 @@ fn buy_now() { assert_eq!(token_client.balance(&bidder_a), 100); assert_eq!(token_client.balance(&bidder_b), 100); assert_eq!(token_client.balance(&fomo_buyer), 75); - assert_eq!(token_client.balance(&mp_client.address), 25); + assert_eq!(token_client.balance(&mp_client.address), 35); // 24 hours in and we have a 4th highest bid env.ledger().with_mut(|li| li.timestamp = FOUR_HOURS * 6); @@ -326,7 +331,7 @@ fn buy_now() { assert_eq!(token_client.balance(&bidder_a), 100); assert_eq!(token_client.balance(&bidder_b), 70); assert_eq!(token_client.balance(&fomo_buyer), 100); - assert_eq!(token_client.balance(&mp_client.address), 30); + assert_eq!(token_client.balance(&mp_client.address), 40); // 36 hours in and we have a 5th highest bid, which is over the buy now price env.ledger().with_mut(|li| li.timestamp = FOUR_HOURS * 9); @@ -334,7 +339,7 @@ fn buy_now() { assert_eq!(token_client.balance(&bidder_a), 40); assert_eq!(token_client.balance(&bidder_b), 100); assert_eq!(token_client.balance(&fomo_buyer), 100); - assert_eq!(token_client.balance(&mp_client.address), 60); + assert_eq!(token_client.balance(&mp_client.address), 70); // 40 hours in and the fomo buyer sees the previous user mistake and buys now env.ledger().with_mut(|li| li.timestamp = FOUR_HOURS * 10); @@ -342,7 +347,8 @@ fn buy_now() { assert_eq!(token_client.balance(&bidder_a), 100); assert_eq!(token_client.balance(&bidder_b), 100); assert_eq!(token_client.balance(&fomo_buyer), 50); - assert_eq!(token_client.balance(&mp_client.address), 0); + // mp_client has the fees from the auction creation + assert_eq!(token_client.balance(&mp_client.address), 10); assert_eq!(token_client.balance(&seller), 50); assert_eq!( @@ -371,6 +377,7 @@ fn pause_changes_status_and_second_attempt_fails_to_pause() { let seller = Address::generate(&env); let token_client = deploy_token_contract(&env, &admin); + token_client.mint(&seller, &10); let (mp_client, collections_client) = generate_marketplace_and_collection_client( &env, @@ -423,6 +430,7 @@ fn pause_after_enddate_should_fail() { let seller = Address::generate(&env); let token_client = deploy_token_contract(&env, &admin); + token_client.mint(&seller, &10); let (mp_client, collections_client) = generate_marketplace_and_collection_client( &env, @@ -463,6 +471,7 @@ fn unpause_changes_status_and_second_attempt_fails_to_unpause() { let bidder = Address::generate(&env); let token_client = deploy_token_contract(&env, &admin); + token_client.mint(&seller, &10); token_client.mint(&bidder, &100); let (mp_client, collections_client) = generate_marketplace_and_collection_client( @@ -516,7 +525,7 @@ fn unpause_changes_status_and_second_attempt_fails_to_unpause() { mp_client.place_bid(&1, &bidder, &100); assert_eq!(token_client.balance(&bidder), 0); - assert_eq!(token_client.balance(&mp_client.address), 100); + assert_eq!(token_client.balance(&mp_client.address), 110); assert_eq!( mp_client.get_highest_bid(&1), HighestBid { bid: 100, bidder } @@ -551,6 +560,10 @@ fn multiple_auction_by_multiple_sellers() { let token_client = deploy_token_contract(&env, &admin); + token_client.mint(&seller_a, &20); + token_client.mint(&seller_b, &10); + token_client.mint(&seller_c, &10); + token_client.mint(&bidder_a, &1_000); token_client.mint(&bidder_b, &1_000); token_client.mint(&bidder_c, &1_000); @@ -558,7 +571,7 @@ fn multiple_auction_by_multiple_sellers() { let mp_client = MarketplaceContractClient::new(&env, &env.register_contract(None, MarketplaceContract {})); - mp_client.initialize(&admin, &token_client.address); + mp_client.initialize(&admin, &token_client.address, &10); // ============ Collections client setup ============ let collection_a_client = @@ -689,7 +702,7 @@ fn multiple_auction_by_multiple_sellers() { assert_eq!(token_client.balance(&bidder_a), 900); assert_eq!(token_client.balance(&bidder_b), 900); assert_eq!(token_client.balance(&bidder_c), 974); - assert_eq!(token_client.balance(&mp_client.address), 226); + assert_eq!(token_client.balance(&mp_client.address), 266); // within day #2 // here auction #4 has ended @@ -701,7 +714,7 @@ fn multiple_auction_by_multiple_sellers() { ); mp_client.finalize_auction(&4); - assert_eq!(token_client.balance(&mp_client.address), 126); + assert_eq!(token_client.balance(&mp_client.address), 166); assert_eq!(token_client.balance(&bidder_a), 900); assert_eq!(token_client.balance(&bidder_b), 900); assert_eq!(token_client.balance(&bidder_c), 974); @@ -725,7 +738,7 @@ fn multiple_auction_by_multiple_sellers() { // `bidder_c`places a bit for 75 he now has 925 in total assert_eq!(token_client.balance(&bidder_c), 925); // total of the assets locked in the contract - assert_eq!(token_client.balance(&mp_client.address), 225); + assert_eq!(token_client.balance(&mp_client.address), 265); // day #4 env.ledger().with_mut(|li| li.timestamp = DAY * 4); @@ -849,7 +862,8 @@ fn multiple_auction_by_multiple_sellers() { assert_eq!(token_client.balance(&bidder_c), 1_000); // make sure that we don't hold any tokens, as we are just intermediary - assert_eq!(token_client.balance(&mp_client.address), 0); + // market place has kept all the fees for creating the auctions + assert_eq!(token_client.balance(&mp_client.address), 40); // let's check the item info // auction #1 sold item #1 from `collection_a` and the winner is `bidder_a` @@ -872,6 +886,7 @@ fn buy_now_should_fail_when_status_is_different_from_active() { let bidder = Address::generate(&env); let token = deploy_token_contract(&env, &admin); + token.mint(&seller, &10); token.mint(&bidder, &10); let (mp_client, collection) = @@ -912,6 +927,7 @@ fn buy_now_should_work_when_no_previous_bid() { let token_client = deploy_token_contract(&env, &admin); + token_client.mint(&seller, &10); token_client.mint(&fomo_buyer, &100); let (mp_client, collections_client) = generate_marketplace_and_collection_client( @@ -941,7 +957,7 @@ fn buy_now_should_work_when_no_previous_bid() { mp_client.buy_now(&1, &fomo_buyer); assert_eq!(token_client.balance(&fomo_buyer), 50); - assert_eq!(token_client.balance(&mp_client.address), 0); + assert_eq!(token_client.balance(&mp_client.address), 10); assert_eq!(token_client.balance(&seller), 50); } @@ -958,6 +974,7 @@ fn buy_now_should_refund_previous_buyer() { let token_client = deploy_token_contract(&env, &admin); + token_client.mint(&seller, &10); token_client.mint(&fomo_buyer, &100); token_client.mint(&bidder, &100); @@ -987,7 +1004,7 @@ fn buy_now_should_refund_previous_buyer() { mp_client.place_bid(&1, &bidder, &40); assert_eq!(token_client.balance(&bidder), 60); - assert_eq!(token_client.balance(&mp_client.address), 40); + assert_eq!(token_client.balance(&mp_client.address), 50); env.ledger().with_mut(|li| li.timestamp = FOUR_HOURS * 2); @@ -995,6 +1012,6 @@ fn buy_now_should_refund_previous_buyer() { assert_eq!(token_client.balance(&fomo_buyer), 50); assert_eq!(token_client.balance(&bidder), 100); - assert_eq!(token_client.balance(&mp_client.address), 0); + assert_eq!(token_client.balance(&mp_client.address), 10); assert_eq!(token_client.balance(&seller), 50); } diff --git a/contracts/auctions/src/test/finalize_auction.rs b/contracts/auctions/src/test/finalize_auction.rs index ed5411c..86b0be0 100644 --- a/contracts/auctions/src/test/finalize_auction.rs +++ b/contracts/auctions/src/test/finalize_auction.rs @@ -9,7 +9,6 @@ use crate::{ test::setup::{ deploy_token_contract, generate_marketplace_and_collection_client, DAY, FOUR_HOURS, WEEKLY, }, - token, }; #[test] @@ -27,6 +26,8 @@ fn finalize_auction() { let token_client = deploy_token_contract(&env, &admin); + token_client.mint(&seller, &10); + token_client.mint(&bidder_a, &100); token_client.mint(&bidder_b, &100); token_client.mint(&bidder_c, &100); @@ -54,7 +55,7 @@ fn finalize_auction() { env.ledger().with_mut(|li| li.timestamp = FOUR_HOURS); mp_client.place_bid(&1, &bidder_a, &5); assert_eq!(token_client.balance(&bidder_a), 95); - assert_eq!(token_client.balance(&mp_client.address), 5); + assert_eq!(token_client.balance(&mp_client.address), 15); // another 4 hours pass by and `bidder_b` places a higher bid env.ledger().with_mut(|li| { @@ -63,7 +64,7 @@ fn finalize_auction() { mp_client.place_bid(&1, &bidder_b, &10); assert_eq!(token_client.balance(&bidder_a), 100); assert_eq!(token_client.balance(&bidder_b), 90); - assert_eq!(token_client.balance(&mp_client.address), 10); + assert_eq!(token_client.balance(&mp_client.address), 20); // 12 hours in total pass by and `bidder_c` places a higher bid env.ledger().with_mut(|li| { @@ -73,7 +74,7 @@ fn finalize_auction() { assert_eq!(token_client.balance(&bidder_a), 100); assert_eq!(token_client.balance(&bidder_b), 100); assert_eq!(token_client.balance(&bidder_c), 50); - assert_eq!(token_client.balance(&mp_client.address), 50); + assert_eq!(token_client.balance(&mp_client.address), 60); // 13 hours in total pass by and `bidder_b` tries to place a bid, but that's not enough env.ledger().with_mut(|li| { @@ -83,7 +84,7 @@ fn finalize_auction() { assert_eq!(token_client.balance(&bidder_a), 100); assert_eq!(token_client.balance(&bidder_b), 100); assert_eq!(token_client.balance(&bidder_c), 50); - assert_eq!(token_client.balance(&mp_client.address), 50); + assert_eq!(token_client.balance(&mp_client.address), 60); // 16 hours in total pass by and `bidder_a` places the highest bid env.ledger().with_mut(|li| { @@ -93,7 +94,7 @@ fn finalize_auction() { assert_eq!(token_client.balance(&bidder_a), 25); assert_eq!(token_client.balance(&bidder_b), 100); assert_eq!(token_client.balance(&bidder_c), 100); - assert_eq!(token_client.balance(&mp_client.address), 75); + assert_eq!(token_client.balance(&mp_client.address), 85); // we wrap it up and the winner is `bidder_a` with a highest bid of 75 env.ledger().with_mut(|li| li.timestamp = WEEKLY + DAY); @@ -103,7 +104,8 @@ fn finalize_auction() { assert_eq!(token_client.balance(&bidder_a), 25); assert_eq!(token_client.balance(&bidder_b), 100); assert_eq!(token_client.balance(&bidder_c), 100); - assert_eq!(token_client.balance(&mp_client.address), 0); + // market place has the initial auction creation fee + assert_eq!(token_client.balance(&mp_client.address), 10); // check if `bidder_a` has 1 NFT of the item assert_eq!(collections_client.balance_of(&bidder_a, &1), 1); @@ -121,6 +123,8 @@ fn fail_to_finalyze_auction_when_endtime_not_reached() { let bidder = Address::generate(&env); let token_client = deploy_token_contract(&env, &Address::generate(&env)); + token_client.mint(&seller, &10); + let (mp_client, nft_collection_client) = generate_marketplace_and_collection_client( &env, &seller, @@ -143,7 +147,7 @@ fn fail_to_finalyze_auction_when_endtime_not_reached() { mp_client.place_bid(&1, &bidder, &50); - assert_eq!(token_client.balance(&mp_client.address), 50i128); + assert_eq!(token_client.balance(&mp_client.address), 60i128); assert_eq!(token_client.balance(&bidder), 0i128); env.ledger().with_mut(|li| li.timestamp = DAY); @@ -153,9 +157,10 @@ fn fail_to_finalyze_auction_when_endtime_not_reached() { ); // auction is not yet over, so the bid is still in place - assert_eq!(token_client.balance(&mp_client.address), 50i128); + assert_eq!(token_client.balance(&mp_client.address), 60i128); assert_eq!(token_client.balance(&bidder), 0i128); } + #[test] fn finalize_auction_when_minimal_price_not_reached_should_refund_last_bidder() { let env = Env::default(); @@ -166,6 +171,8 @@ fn finalize_auction_when_minimal_price_not_reached_should_refund_last_bidder() { let bidder_a = Address::generate(&env); let token_client = deploy_token_contract(&env, &Address::generate(&env)); + token_client.mint(&seller, &10); + let (mp_client, nft_collection_client) = generate_marketplace_and_collection_client( &env, &seller, @@ -189,7 +196,7 @@ fn finalize_auction_when_minimal_price_not_reached_should_refund_last_bidder() { env.ledger().with_mut(|li| li.timestamp = DAY); mp_client.place_bid(&1, &bidder_a, &5); - assert_eq!(token_client.balance(&mp_client.address), 5i128); + assert_eq!(token_client.balance(&mp_client.address), 15i128); assert_eq!(token_client.balance(&bidder_a), 0i128); // we try to finalize the auction 2 weeks later @@ -209,7 +216,7 @@ fn finalize_auction_when_minimal_price_not_reached_should_refund_last_bidder() { auction_token: token_client.address.clone() } ); - assert_eq!(token_client.balance(&mp_client.address), 0i128); + assert_eq!(token_client.balance(&mp_client.address), 10i128); assert_eq!(token_client.balance(&bidder_a), 5i128); } @@ -220,7 +227,9 @@ fn fail_to_finalyze_auction_when_not_correct_state() { env.budget().reset_unlimited(); let seller = Address::generate(&env); - let token_client = token::Client::new(&env, &Address::generate(&env)); + let token_client = deploy_token_contract(&env, &Address::generate(&env)); + token_client.mint(&seller, &10); + let (mp_client, nft_collection_client) = generate_marketplace_and_collection_client( &env, &seller, @@ -256,7 +265,9 @@ fn get_active_auctions_should_list_correct_number_of_active_auctions() { let seller = Address::generate(&env); - let token_client = token::Client::new(&env, &Address::generate(&env)); + let token_client = deploy_token_contract(&env, &Address::generate(&env)); + token_client.mint(&seller, &30); + let (mp_client, nft_collection_client) = generate_marketplace_and_collection_client( &env, &seller, diff --git a/contracts/auctions/src/test/initialization.rs b/contracts/auctions/src/test/initialization.rs index 2c17fe5..dcf60d6 100644 --- a/contracts/auctions/src/test/initialization.rs +++ b/contracts/auctions/src/test/initialization.rs @@ -24,7 +24,7 @@ fn initialize_and_update_admin_should_work() { let mp_client = MarketplaceContractClient::new(&env, &env.register_contract(None, MarketplaceContract {})); - mp_client.initialize(&admin, &token_client.address); + mp_client.initialize(&admin, &token_client.address, &10); mp_client.update_admin(&new_admin); } @@ -36,6 +36,8 @@ fn mp_should_create_auction() { let seller = Address::generate(&env); let token_client = deploy_token_contract(&env, &Address::generate(&env)); + token_client.mint(&seller, &10); + let (mp_client, nft_collection_client) = generate_marketplace_and_collection_client( &env, &seller, @@ -80,6 +82,8 @@ fn initialize_twice_should_fail() { let seller = Address::generate(&env); let token_client = deploy_token_contract(&env, &admin); + token_client.mint(&seller, &10); + let (mp_client, _) = generate_marketplace_and_collection_client( &env, &seller, @@ -89,7 +93,7 @@ fn initialize_twice_should_fail() { ); assert_eq!( - mp_client.try_initialize(&admin, &token_client.address), + mp_client.try_initialize(&admin, &token_client.address, &10), Err(Ok(ContractError::AlreadyInitialized)) ); } @@ -102,6 +106,8 @@ fn mp_should_fail_to_create_auction_where_not_enought_balance_of_the_item() { let seller = Address::generate(&env); let token_client = deploy_token_contract(&env, &Address::generate(&env)); + token_client.mint(&seller, &10); + // we don't want to use the collection from the setup method, as this will automatically // mint an item for the auction. let (mp_client, _) = generate_marketplace_and_collection_client( @@ -143,6 +149,7 @@ fn mp_should_be_able_create_multiple_auctions_and_query_them_with_pagination() { let seller = Address::generate(&env); let token_client = deploy_token_contract(&env, &Address::generate(&env)); + token_client.mint(&seller, &250); let (mp_client, collection_client) = generate_marketplace_and_collection_client( &env, @@ -241,6 +248,33 @@ fn get_auction_by_seller_should_return_an_err_when_id_not_found() { ) } +#[test] +fn should_fail_to_create_auction_when_seller_cannot_cover_the_fees() { + let env = Env::default(); + env.mock_all_auths(); + + let seller = Address::generate(&env); + + let token = deploy_token_contract(&env, &Address::generate(&env)); + + let (mp_client, collection) = + generate_marketplace_and_collection_client(&env, &seller, &token.address, None, None); + + collection.mint(&seller, &seller, &1, &1); + + let item_info = ItemInfo { + collection_addr: collection.address, + item_id: 1, + minimum_price: None, + buy_now_price: None, + }; + + assert_eq!( + mp_client.try_create_auction(&item_info, &seller, &WEEKLY), + Err(Ok(ContractError::AuctionCreationFeeNotCovered)) + ); +} + #[test] fn mp_should_not_create_auction_with_item_info_with_zero_amount() { let env = Env::default(); @@ -270,3 +304,4 @@ fn mp_should_not_create_auction_with_item_info_with_zero_amount() { Err(Ok(ContractError::InvalidInputs)) ); } + diff --git a/contracts/auctions/src/test/setup.rs b/contracts/auctions/src/test/setup.rs index a12a978..9666abd 100644 --- a/contracts/auctions/src/test/setup.rs +++ b/contracts/auctions/src/test/setup.rs @@ -43,7 +43,7 @@ pub fn generate_marketplace_and_collection_client<'a>( ) -> (MarketplaceContractClient<'a>, collection::Client<'a>) { let mp_client = MarketplaceContractClient::new(env, &env.register(MarketplaceContract, ())); - mp_client.initialize(admin, auction_token); + mp_client.initialize(admin, auction_token, &10); let alt_name = String::from_str(env, "Stellar kitties"); let alt_symbol = String::from_str(env, "STK");