Skip to content

Commit

Permalink
fix: add new quantity to limit
Browse files Browse the repository at this point in the history
Refs: #45
  • Loading branch information
bucurdavid committed Apr 17, 2024
1 parent c5ccc2a commit cc9c615
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
7 changes: 6 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
10 changes: 5 additions & 5 deletions tests/rust_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
);
},
Expand All @@ -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(
Expand All @@ -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
Expand Down

0 comments on commit cc9c615

Please sign in to comment.