diff --git a/contracts/examples/digital-cash/scenarios/pay-fee-and-fund-esdt-multiple.scen.json b/contracts/examples/digital-cash/scenarios/pay-fee-and-fund-esdt-multiple.scen.json index 228c83f337..e9f57b8f4c 100644 --- a/contracts/examples/digital-cash/scenarios/pay-fee-and-fund-esdt-multiple.scen.json +++ b/contracts/examples/digital-cash/scenarios/pay-fee-and-fund-esdt-multiple.scen.json @@ -117,7 +117,7 @@ "storage": { "str:deposit|0xdb474a3a065d3f0c0a62ae680ef6435e48eb482899d2ae30ff7a3a4b0ef19c60": { "0-depositor_address": "address:acc3", - "1-funds": "u32:2|nested:str:CASHTOKEN-778899|u64:0|biguint:47|nested:str:CASHTOKEN-112233|u64:0|biguint:50", + "1-funds": "u32:2|nested:str:CASHTOKEN-778899|u64:0|biguint:44|nested:str:CASHTOKEN-112233|u64:0|biguint:50", "2-valability": "u64:100", "3-expiration_round": "u64:16", "4-fees": { @@ -125,7 +125,7 @@ "1-value": { "0-tokenIdentifier": "nested:str:CASHTOKEN-778899", "1-nonce": "u64:0", - "2-amount": "biguint:3" + "2-amount": "biguint:6" } } }, diff --git a/contracts/examples/digital-cash/src/pay_fee_and_fund.rs b/contracts/examples/digital-cash/src/pay_fee_and_fund.rs index 646627ddc5..6aeafb19cd 100644 --- a/contracts/examples/digital-cash/src/pay_fee_and_fund.rs +++ b/contracts/examples/digital-cash/src/pay_fee_and_fund.rs @@ -15,13 +15,18 @@ pub trait PayFeeAndFund: storage::StorageModule + helpers::HelpersModule { require!(!fee_value_mapper.is_empty(), "invalid fee toke provided"); fee_token.amount = fee_value_mapper.get(); + + let fee_with_first_token = fee_token.amount.clone() * payments.len() as u32; + let fee_without_first_token = fee_token.amount.clone() * (payments.len() as u32 - 1); + require!( - (provided_fee_token.amount >= fee_token.amount && payments.len() > 1) // case when we have more than 1 type of token transfered - || (provided_fee_token.amount > fee_token.amount && payments.len() == 1), // case when token transfered is the same with the fee token + (provided_fee_token.amount == fee_without_first_token || // case when first first token is the exact fee amount + provided_fee_token.amount > fee_with_first_token), // case when first token also covers part of the funds "payment not covering fees" ); - if provided_fee_token.amount > fee_token.amount { + if provided_fee_token.amount > fee_without_first_token { + fee_token.amount = fee_with_first_token; let extracted_fee = EgldOrEsdtTokenPayment::new( provided_fee_token.token_identifier, provided_fee_token.token_nonce, @@ -30,6 +35,7 @@ pub trait PayFeeAndFund: storage::StorageModule + helpers::HelpersModule { let _ = payments.set(0, extracted_fee); } else { payments.remove(0); + fee_token.amount = fee_without_first_token; } let caller_address = self.blockchain().get_caller();