@pytest.mark.ported_from(
[
"https://github.com/ethereum/tests/blob/v13.3/src/GeneralStateTestsFiller/stEIP1559/intrinsicGen.js",
"https://github.com/ethereum/tests/blob/v13.3/src/GeneralStateTestsFiller/stEIP1559/intrinsicFiller.yml",
],
pr=["https://github.com/ethereum/execution-spec-tests/pull/1535"],
)
@pytest.mark.parametrize("data", tx_intrinsic_gas_data_vectors)
@pytest.mark.parametrize("access_list", tx_intrinsic_gas_access_list_vectors)
@pytest.mark.parametrize(
"below_intrinsic",
[
pytest.param(False),
pytest.param(True, marks=pytest.mark.exception_test),
],
)
@pytest.mark.with_all_tx_types(selector=lambda tx_type: tx_type in [1, 2])
@pytest.mark.slow()
def test_tx_intrinsic_gas(
state_test: StateTestFiller,
tx_type: int,
pre: Alloc,
fork: Fork,
data: Bytes,
access_list: List[AccessList],
below_intrinsic: bool,
) -> None:
"""Transaction intrinsic gas calculation on EIP2930."""
intrinsic_gas_cost_calculator = (
fork.transaction_intrinsic_cost_calculator()
)
intrinsic_gas_cost = intrinsic_gas_cost_calculator(
calldata=data, access_list=access_list
)
exception: List[TransactionException] | TransactionException | None = None
if below_intrinsic:
data_floor_gas_cost_calculator = (
fork.transaction_data_floor_cost_calculator()
)
data_floor_gas_cost = data_floor_gas_cost_calculator(data=data)
if data_floor_gas_cost > intrinsic_gas_cost:
exception = TransactionException.INTRINSIC_GAS_BELOW_FLOOR_GAS_COST
elif data_floor_gas_cost == intrinsic_gas_cost:
# Depending on the implementation, client might raise either
# exception.
exception = [
TransactionException.INTRINSIC_GAS_TOO_LOW,
TransactionException.INTRINSIC_GAS_BELOW_FLOOR_GAS_COST,
]
else:
exception = TransactionException.INTRINSIC_GAS_TOO_LOW
tx = Transaction(
ty=tx_type,
sender=pre.fund_eoa(),
to=pre.deploy_contract(code=Op.SSTORE(0, Op.ADD(1, 1))),
data=data,
access_list=access_list,
gas_limit=intrinsic_gas_cost + (-1 if below_intrinsic else 0),
error=exception,
protected=True,
)
state_test(env=Environment(), pre=pre, post={}, tx=tx)