From 3e4ae9310208b8e8bc073a7d8f3744631fc10ba4 Mon Sep 17 00:00:00 2001 From: Milosz Muszynski Date: Mon, 20 May 2024 15:21:38 +0200 Subject: [PATCH] transfer-contract: charge and allowance in gas points --- contracts/transfer/src/state.rs | 22 +++++++++++----------- contracts/transfer/tests/scenario3.rs | 2 +- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/contracts/transfer/src/state.rs b/contracts/transfer/src/state.rs index 3d78dd180b..a14d1e5d26 100644 --- a/contracts/transfer/src/state.rs +++ b/contracts/transfer/src/state.rs @@ -267,12 +267,12 @@ impl TransferState { &mut self, contract_id: &ContractId, charge: u64, - ges_spent: u64, + gas_spent: u64, gas_price: u64, ) -> u64 { - let cost = ges_spent * gas_price; + let cost = gas_spent * gas_price; if charge > cost { - let earning = charge - cost; + let earning = charge * gas_price - cost; self.add_balance(*contract_id, earning); rusk_abi::emit( "earning", @@ -288,11 +288,11 @@ impl TransferState { "earning", EconomicEvent { module: contract_id.to_bytes(), - value: charge, + value: charge * gas_price, result: EconomicResult::ChargeNotSufficient, }, ); - ges_spent + gas_spent } } @@ -307,20 +307,20 @@ impl TransferState { &mut self, contract_id: &ContractId, allowance: u64, - ges_spent: u64, + gas_spent: u64, gas_price: u64, ) -> u64 { - let spent = ges_spent * gas_price; - if allowance < spent { + let spent = gas_spent * gas_price; + if allowance * gas_price < spent { rusk_abi::emit( "sponsoring", EconomicEvent { module: contract_id.to_bytes(), - value: allowance, + value: allowance * gas_price, result: EconomicResult::AllowanceNotSufficient, }, ); - spent + gas_spent } else { let contract_balance = self.balance(contract_id); if spent > contract_balance { @@ -332,7 +332,7 @@ impl TransferState { result: EconomicResult::BalanceNotSufficient, }, ); - spent + gas_spent } else { self.sub_balance(contract_id, spent).expect( "Subtracting callee contract balance should succeed", diff --git a/contracts/transfer/tests/scenario3.rs b/contracts/transfer/tests/scenario3.rs index 2649b523dc..bb58aa8e6d 100644 --- a/contracts/transfer/tests/scenario3.rs +++ b/contracts/transfer/tests/scenario3.rs @@ -562,7 +562,7 @@ fn contract_earns_fee() { assert_eq!( execution_result.economic_mode, EconomicMode::Charge( - balance_delta + execution_result.gas_spent * GAS_PRICE + balance_delta / GAS_PRICE + execution_result.gas_spent ) ); }