Skip to content

Commit

Permalink
rusk: eliminated surcharge
Browse files Browse the repository at this point in the history
  • Loading branch information
miloszm committed May 20, 2024
1 parent 9864e77 commit dc091d8
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions rusk/tests/services/contract_pays_earns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.gas_spent
tx.economic_gas_spent
}

/// We call method 'pay' of a Charlie contract
Expand Down Expand Up @@ -165,8 +165,9 @@ pub async fn contract_pays() -> Result<()> {

info!("Original Root: {:?}", hex::encode(original_root));

let gas_spent = make_and_execute_transaction(&rusk, &wallet, "pay");
assert_eq!(gas_spent, 0, "Transaction should be free");
let economic_gas_spent =
make_and_execute_transaction(&rusk, &wallet, "pay");
assert_eq!(economic_gas_spent, 0, "Transaction should be free");

// Check the state's root is changed from the original one
let new_root = rusk.state_root();
Expand All @@ -185,7 +186,6 @@ pub async fn contract_pays() -> Result<()> {
#[tokio::test(flavor = "multi_thread")]
pub async fn contract_earns() -> Result<()> {
const CHARLIE_CHARGE: u64 = 20_000_000; // that much Charlie contract's method 'earn' is charging
const CHARGE_DISCOUNT: u64 = 10_000; // possible discount due to gas usage approximation

logger();

Expand All @@ -207,10 +207,10 @@ pub async fn contract_earns() -> Result<()> {

info!("Original Root: {:?}", hex::encode(original_root));

let gas_spent = make_and_execute_transaction(&rusk, &wallet, "earn");
assert!(
gas_spent >= (CHARLIE_CHARGE - CHARGE_DISCOUNT)
&& gas_spent <= CHARLIE_CHARGE,
let economic_gas_spent =
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"
);

Expand Down

0 comments on commit dc091d8

Please sign in to comment.