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
631
632
633 | @pytest.mark.parametrize(
"exceed_tx_gas_limit,correct_intrinsic_cost_in_transaction_gas_limit",
[
pytest.param(True, False, marks=pytest.mark.exception_test),
pytest.param(True, True, marks=pytest.mark.exception_test),
pytest.param(False, True),
],
)
@pytest.mark.valid_from("Osaka")
def test_tx_gas_limit_cap_access_list_with_diff_addr(
state_test: StateTestFiller,
pre: Alloc,
fork: Fork,
exceed_tx_gas_limit: bool,
correct_intrinsic_cost_in_transaction_gas_limit: bool,
) -> None:
"""
Test the transaction gas limit cap behavior for access list with different
addresses.
"""
intrinsic_cost = fork.transaction_intrinsic_cost_calculator()
tx_gas_limit_cap = fork.transaction_gas_limit_cap()
assert tx_gas_limit_cap is not None, (
"Fork does not have a transaction gas limit cap"
)
def make_access_list(account_count: int) -> List[AccessList]:
return [
AccessList(
address=Address(i + 1),
storage_keys=[Hash(i)],
)
for i in range(account_count)
]
def intrinsic_cost_for_num_accounts(account_count: int) -> int:
return intrinsic_cost(access_list=make_access_list(account_count))
account_num = max_count_with_intrinsic_cost_at_most(
intrinsic_cost_for_num_accounts, tx_gas_limit_cap
) + int(exceed_tx_gas_limit)
access_list = make_access_list(account_num)
correct_intrinsic_cost = intrinsic_cost(access_list=access_list)
if exceed_tx_gas_limit:
assert correct_intrinsic_cost > tx_gas_limit_cap, (
"Correct intrinsic cost should exceed the tx gas limit cap"
)
else:
assert correct_intrinsic_cost <= tx_gas_limit_cap, (
"Correct intrinsic cost should be less than or "
"equal to the tx gas limit cap"
)
tx_gas_limit = (
correct_intrinsic_cost
if correct_intrinsic_cost_in_transaction_gas_limit
else tx_gas_limit_cap
)
tx = Transaction(
to=pre.fund_eoa(),
gas_limit=tx_gas_limit,
sender=pre.fund_eoa(),
access_list=access_list,
error=TransactionException.GAS_LIMIT_EXCEEDS_MAXIMUM
if correct_intrinsic_cost_in_transaction_gas_limit
and exceed_tx_gas_limit
else TransactionException.INTRINSIC_GAS_TOO_LOW
if exceed_tx_gas_limit
else None,
)
state_test(
pre=pre,
post={},
tx=tx,
)
|