From cc9c61583ad8bf8aed38a11fd6193742b3f79519 Mon Sep 17 00:00:00 2001 From: Bucur David Date: Wed, 17 Apr 2024 14:31:09 +0300 Subject: [PATCH] fix: add new quantity to limit Refs: #45 --- src/lib.rs | 7 ++++++- tests/rust_tests.rs | 10 +++++----- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 48c9101..3abb8be 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -383,13 +383,18 @@ pub trait DataMarket: let mut offer = self.try_get_offer(offer_id); - let address_limit = self.max_quantity_per_address(&offer.owner, offer_id).get(); + let mut address_limit = self.max_quantity_per_address(&caller, offer_id).get(); if offer.max_quantity > BigUint::zero() { require!( &quantity + &address_limit <= offer.max_quantity, ERR_MAX_QUANTITY_EXCEEDED ); + + address_limit += &quantity; + + self.max_quantity_per_address(&caller, offer_id) + .set(&address_limit); } let payment = self.call_value().egld_or_single_esdt(); diff --git a/tests/rust_tests.rs b/tests/rust_tests.rs index 7450366..cc156cc 100644 --- a/tests/rust_tests.rs +++ b/tests/rust_tests.rs @@ -2714,14 +2714,14 @@ fn accept_offer_test() { &setup.contract_wrapper, SFT_TICKER, 1, - &rust_biguint!(2u64), + &rust_biguint!(3u64), |sc| { sc.add_offer( managed_token_id_wrapped!(TOKEN_ID), 0u64, managed_biguint!(100), managed_biguint!(0), - managed_biguint!(2u64), + managed_biguint!(3u64), OptionalValue::Some(managed_biguint!(1)), ); }, @@ -2737,10 +2737,10 @@ fn accept_offer_test() { &(&rust_biguint!(100) + ((&rust_biguint!(100) * rust_biguint!(150u64)) / rust_biguint!(10000u64))), // buyer needs to send with % fee included |sc| { - sc.accept_offer(5u64, managed_biguint!(2u64)); + sc.accept_offer(5u64, managed_biguint!(1u64)); }, ) - .assert_user_error("Max quantity exceeded"); + .assert_ok(); b_wrapper .execute_esdt_transfer( @@ -2754,7 +2754,7 @@ fn accept_offer_test() { sc.accept_offer(5u64, managed_biguint!(1u64)); }, ) - .assert_ok() + .assert_user_error("Max quantity exceeded"); } #[test] // Tests whether the user gets the royaties tokens but not in the claims contract