535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630 | def test_bal_block_rewards(
pre: Alloc,
blockchain_test: BlockchainTestFiller,
fork: Fork,
) -> None:
"""Ensure BAL captures fee recipient balance changes from block rewards."""
bob = pre.fund_eoa(amount=0)
charlie = pre.fund_eoa(amount=0) # fee recipient
intrinsic_gas_calculator = fork.transaction_intrinsic_cost_calculator()
intrinsic_gas = intrinsic_gas_calculator(
calldata=b"",
contract_creation=False,
access_list=[],
recipient_type=RecipientType.EMPTY_ACCOUNT,
sends_value=True,
)
top_frame_state_gas = fork.transaction_top_frame_state_gas(
sends_value=True,
recipient_type=RecipientType.EMPTY_ACCOUNT,
)
expected_gas_used = intrinsic_gas + top_frame_state_gas
tx_gas_limit = expected_gas_used + 1000 # add a small buffer
gas_price = 0xA
tx_value = 100
extra_balance = 1000
alice_initial_balance = (
(tx_gas_limit * gas_price) + tx_value + extra_balance
)
alice = pre.fund_eoa(amount=alice_initial_balance)
tx = Transaction(
sender=alice,
to=bob,
value=tx_value,
gas_limit=tx_gas_limit,
gas_price=gas_price,
)
# EIP-1559 fee calculation:
# - Total gas cost
total_gas_cost = expected_gas_used * gas_price
# - Tip portion
genesis_env = Environment(base_fee_per_gas=0x7)
base_fee_per_gas = fork.base_fee_per_gas_calculator()(
parent_base_fee_per_gas=int(genesis_env.base_fee_per_gas or 0),
parent_gas_used=0,
parent_gas_limit=genesis_env.gas_limit,
)
tip_to_charlie = (gas_price - base_fee_per_gas) * expected_gas_used
alice_final_balance = alice_initial_balance - tx_value - total_gas_cost
block = Block(
txs=[tx],
fee_recipient=charlie, # Set Charlie as the fee recipient
header_verify=Header(base_fee_per_gas=base_fee_per_gas),
expected_block_access_list=BlockAccessListExpectation(
account_expectations={
alice: BalAccountExpectation(
nonce_changes=[
BalNonceChange(block_access_index=1, post_nonce=1)
],
balance_changes=[
BalBalanceChange(
block_access_index=1,
post_balance=alice_final_balance,
)
],
),
bob: BalAccountExpectation(
balance_changes=[
BalBalanceChange(
block_access_index=1, post_balance=100
)
],
),
charlie: BalAccountExpectation(
balance_changes=[
BalBalanceChange(
block_access_index=1, post_balance=tip_to_charlie
)
],
),
}
),
)
blockchain_test(
pre=pre,
blocks=[block],
post={},
genesis_environment=genesis_env,
)
|