Skip to content

Commit e293535

Browse files
raxhvlfselmo
authored andcommitted
✨ feat(test): test_bal_block_rewards
1 parent 4d7c9e5 commit e293535

File tree

2 files changed

+67
-0
lines changed

2 files changed

+67
-0
lines changed

tests/amsterdam/eip7928_block_level_access_lists/test_block_access_lists.py

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -653,3 +653,69 @@ def test_bal_delegated_storage_reads(
653653
)
654654

655655
blockchain_test(pre=pre, blocks=[block], post={})
656+
657+
658+
def test_bal_block_rewards(
659+
pre: Alloc,
660+
blockchain_test: BlockchainTestFiller,
661+
fork,
662+
):
663+
"""Ensure BAL captures fee recipient balance changes from block rewards."""
664+
alice_initial_balance = 1_000_000
665+
alice = pre.fund_eoa(amount=alice_initial_balance)
666+
bob = pre.fund_eoa(amount=0)
667+
charlie = pre.fund_eoa(amount=0) # fee recipient
668+
669+
intrinsic_gas_calculator = fork.transaction_intrinsic_cost_calculator()
670+
intrinsic_gas_cost = intrinsic_gas_calculator(
671+
calldata=b"",
672+
contract_creation=False,
673+
access_list=[],
674+
)
675+
tx_gas_limit = intrinsic_gas_cost + 1000 # add a small buffer
676+
gas_price = 0xA
677+
base_fee_per_gas = 0x2 # Set base fee for EIP-1559
678+
679+
tx = Transaction(
680+
sender=alice,
681+
to=bob,
682+
value=100,
683+
gas_limit=tx_gas_limit,
684+
gas_price=gas_price,
685+
)
686+
687+
# EIP-1559 fee calculation:
688+
# - Total gas cost
689+
total_gas_cost = intrinsic_gas_cost * gas_price
690+
# - Tip portion
691+
tip_to_charlie = intrinsic_gas_cost * (gas_price - base_fee_per_gas)
692+
693+
alice_final_balance = alice_initial_balance - 100 - total_gas_cost
694+
695+
block = Block(
696+
txs=[tx],
697+
fee_recipient=charlie, # Set Charlie as the fee recipient
698+
base_fee_per_gas=base_fee_per_gas, # Set base fee for EIP-1559
699+
expected_block_access_list=BlockAccessListExpectation(
700+
account_expectations={
701+
alice: BalAccountExpectation(
702+
nonce_changes=[BalNonceChange(tx_index=1, post_nonce=1)],
703+
balance_changes=[
704+
BalBalanceChange(tx_index=1, post_balance=alice_final_balance)
705+
],
706+
),
707+
bob: BalAccountExpectation(
708+
balance_changes=[BalBalanceChange(tx_index=1, post_balance=100)],
709+
),
710+
charlie: BalAccountExpectation(
711+
balance_changes=[BalBalanceChange(tx_index=1, post_balance=tip_to_charlie)],
712+
),
713+
}
714+
),
715+
)
716+
717+
blockchain_test(
718+
pre=pre,
719+
blocks=[block],
720+
post={},
721+
)

tests/amsterdam/eip7928_block_level_access_lists/test_cases.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
| `test_bal_callcode_with_value_transfer` | Ensure BAL captures balance changes from `CALLCODE` opcode with value transfer | Alice calls `Oracle` contract (200 wei balance) which uses `CALLCODE` opcode to execute `TargetContract`'s code with 100 wei value transfer to Bob (0 wei balance). | BAL MUST include Alice (nonce changes), `Oracle` (balance change to 100 wei), Bob (balance change to 100 wei), and `TargetContract` (empty changes). | ✅ Completed |
1515
| `test_bal_delegated_storage_writes` | Ensure BAL captures delegated storage writes via `DELEGATECALL` and `CALLCODE` | Alice calls `Oracle` contract which uses `DELEGATECALL`/`CALLCODE` to `TargetContract` that writes `0x42` to slot `0x01`. | BAL MUST include Alice (nonce changes), `Oracle` (storage changes for slot `0x01` = `0x42`), and `TargetContract` (empty changes). | ✅ Completed |
1616
| `test_bal_delegated_storage_reads` | Ensure BAL captures delegated storage reads via `DELEGATECALL` and `CALLCODE` | Alice calls `Oracle` contract (with slot `0x01` = `0x42`) which uses `DELEGATECALL`/`CALLCODE` to `TargetContract` that reads from slot `0x01`. | BAL MUST include Alice (nonce changes), `Oracle` (storage reads for slot `0x01`), and `TargetContract` (empty changes). | ✅ Completed |
17+
| `test_bal_block_rewards` | BAL tracks fee recipient balance changes from block rewards | Alice sends 100 wei to Bob with Charlie as fee recipient | BAL MUST include fee recipient Charlie with `balance_changes` reflecting transaction fees collected from the block. | ✅ Completed |
1718
| `test_bal_2930_slot_listed_but_untouched` | Ensure 2930 access list alone doesn’t appear in BAL | Include `(KV, S=0x01)` in tx’s EIP-2930 access list; tx executes code that does **no** `SLOAD`/`SSTORE` to `S` (e.g., pure arithmetic/log). | BAL **MUST NOT** contain any entry for `(KV, S)` — neither reads nor writes — because the slot wasn’t touched. | 🟡 Planned |
1819
| `test_bal_2930_slot_listed_and_modified` | Ensure BAL records writes only because the slot is touched | Same access list as above, but tx executes `SSTORE` to `S`. | BAL **MUST** include `storage_changes` for `(KV, S)` (and no separate read record for that slot if implementation deduplicates). Presence in the access list is irrelevant; inclusion is due to the actual write. | 🟡 Planned |
1920
| `test_bal_7702_delegated_create` | BAL tracks EIP-7702 delegation indicator write and contract creation | Alice sends a type-4 (7702) tx authorizing herself to delegate to `Deployer` code which executes `CREATE` | BAL MUST include for **Alice**: `code_changes` (delegation indicator), `nonce_changes` (increment from 7702 processing), and `balance_changes` (post-gas). For **Child**: `code_changes` (runtime bytecode) and `nonce_changes = 1`. | 🟡 Planned |

0 commit comments

Comments
 (0)