diff --git a/rusk/src/lib/chain/rusk.rs b/rusk/src/lib/chain/rusk.rs index 8281bfb177..ad0957c3df 100644 --- a/rusk/src/lib/chain/rusk.rs +++ b/rusk/src/lib/chain/rusk.rs @@ -23,13 +23,11 @@ use phoenix_core::transaction::StakeData; use phoenix_core::Transaction as PhoenixTransaction; use rusk_abi::dusk::Dusk; use rusk_abi::{ - CallReceipt, ContractError, ContractId, EconomicMode, - Error as PiecrustError, Event, Session, STAKE_CONTRACT, TRANSFER_CONTRACT, - VM, + CallReceipt, ContractError, ContractId, Error as PiecrustError, Event, + Session, STAKE_CONTRACT, TRANSFER_CONTRACT, VM, }; use rusk_profile::to_rusk_state_id_path; use tokio::sync::broadcast; -use EconomicMode::{Allowance, Charge}; use super::{coinbase_value, emission_amount, Rusk, RuskTip}; use crate::http::ContractEvent; @@ -149,15 +147,10 @@ impl Rusk { block_gas_left -= gas_spent; let gas_price = unspent_tx.inner.fee.gas_price; dusk_spent += gas_spent * gas_price; - let economic_gas_spent = match receipt.economic_mode { - Allowance(allowance) if allowance > 0 => 0, - Charge(charge) if charge > 0 => charge, - _ => gas_spent, - }; spent_txs.push(SpentTransaction { inner: unspent_tx, gas_spent, - economic_gas_spent, + economic_mode: receipt.economic_mode, block_height, err, }); @@ -443,16 +436,10 @@ fn accept( .checked_sub(gas_spent) .ok_or(Error::OutOfGas)?; - let economic_gas_spent = match receipt.economic_mode { - Allowance(allowance) if allowance > 0 => 0, - Charge(charge) if charge > 0 => charge, - _ => gas_spent, - }; - spent_txs.push(SpentTransaction { inner: unspent_tx.clone(), gas_spent, - economic_gas_spent, + economic_mode: receipt.economic_mode, block_height, // We're currently ignoring the result of successful calls err: receipt.data.err().map(|e| format!("{e}")), diff --git a/rusk/tests/services/contract_pays_earns.rs b/rusk/tests/services/contract_pays_earns.rs index 23ca49a785..903888537b 100644 --- a/rusk/tests/services/contract_pays_earns.rs +++ b/rusk/tests/services/contract_pays_earns.rs @@ -14,7 +14,7 @@ use dusk_wallet_core::{self as wallet}; use rand::prelude::*; use rand::rngs::StdRng; use rusk::{Result, Rusk}; -use rusk_abi::{ContractData, ContractId, TRANSFER_CONTRACT}; +use rusk_abi::{ContractData, ContractId, EconomicMode, TRANSFER_CONTRACT}; use rusk_recovery_tools::state; use tempfile::tempdir; use tokio::sync::broadcast; @@ -85,7 +85,7 @@ fn make_and_execute_transaction( rusk: &Rusk, wallet: &wallet::Wallet, method: impl AsRef, -) -> u64 { +) -> EconomicMode { // We will refund the transaction to ourselves. let refund = wallet .public_key(SENDER_INDEX) @@ -137,7 +137,7 @@ fn make_and_execute_transaction( .expect("There should be one spent transactions"); assert!(tx.err.is_none(), "Transaction should succeed"); - tx.economic_gas_spent + tx.economic_mode } /// We call method 'pay' of a Charlie contract @@ -165,9 +165,14 @@ pub async fn contract_pays() -> Result<()> { info!("Original Root: {:?}", hex::encode(original_root)); - let economic_gas_spent = - make_and_execute_transaction(&rusk, &wallet, "pay"); - assert_eq!(economic_gas_spent, 0, "Transaction should be free"); + let economic_mode = make_and_execute_transaction(&rusk, &wallet, "pay"); + assert!( + match economic_mode { + EconomicMode::Allowance(allowance) if allowance > 0 => true, + _ => false, + }, + "Transaction should be free" + ); // Check the state's root is changed from the original one let new_root = rusk.state_root(); @@ -207,11 +212,11 @@ pub async fn contract_earns() -> Result<()> { info!("Original Root: {:?}", hex::encode(original_root)); - let economic_gas_spent = - make_and_execute_transaction(&rusk, &wallet, "earn"); + let economic_mode = make_and_execute_transaction(&rusk, &wallet, "earn"); assert_eq!( - economic_gas_spent, CHARLIE_CHARGE, - "Transaction should cost as much as contract is charging minus discount" + economic_mode, + EconomicMode::Charge(CHARLIE_CHARGE), + "Transaction should cost as much as contract is charging" ); // Check the state's root is changed from the original one