Skip to content

Commit

Permalink
fix coinbase balance (#636)
Browse files Browse the repository at this point in the history
  • Loading branch information
greged93 authored Jan 16, 2024
1 parent 79ed71c commit 2b5d7b9
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions crates/ef-testing/src/models/case.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,7 @@ impl BlockchainTestCase {
.and_then(|transaction| transaction.gas_price)
.map(|gas_price| gas_price.0)
.unwrap_or_default();
let transaction_cost = if coinbase.0 != sender_address {
gas_price
} else {
base_fee_per_gas
} * gas_used;
let transaction_cost = gas_price * gas_used;

let post_state = match self.post.clone() {
RootOrState::Root(_) => {
Expand All @@ -150,6 +146,7 @@ impl BlockchainTestCase {
diff.push(storage_diff);
}
}

// Nonce
let actual = sequencer.nonce_at(address)?;
if actual != expected_state.nonce.0 {
Expand All @@ -159,6 +156,7 @@ impl BlockchainTestCase {
);
diff.push(nonce_diff);
}

// Bytecode
let actual = sequencer.code_at(address)?;
if actual != expected_state.code {
Expand All @@ -168,12 +166,17 @@ impl BlockchainTestCase {
);
diff.push(bytecode_diff);
}

// Balance
let mut actual = sequencer.balance_at(address)?;
// Subtract transaction cost to sender balance
if address.0 == sender_address {
actual -= transaction_cost;
}
// Add priority fee to coinbase balance
if *address == coinbase {
actual += (gas_price - base_fee_per_gas) * gas_used;
}
if actual != expected_state.balance.0 {
let balance_diff = format!(
"balance mismatch for {:#20x}: expected {:#32x}, got {:#32x}",
Expand Down

0 comments on commit 2b5d7b9

Please sign in to comment.