Skip to content

test_transaction_gas()

Documentation for tests/amsterdam/eip2780_reduce_intrinsic_tx_gas/test_eip_mainnet.py::test_transaction_gas@26332146.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/amsterdam/eip2780_reduce_intrinsic_tx_gas/test_eip_mainnet.py::test_transaction_gas --fork Amsterdam

Gas for a non-create transaction, per recipient type and value.

Source code in tests/amsterdam/eip2780_reduce_intrinsic_tx_gas/test_eip_mainnet.py
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
@EIPChecklist.GasCostChanges.Test.GasUpdatesMeasurement()
@pytest.mark.parametrize("recipient_type", RECIPIENT_TYPES_NON_CREATE)
@pytest.mark.parametrize(
    "value",
    [
        pytest.param(0, id="zero_value"),
        pytest.param(1, id="non-zero_value"),
    ],
)
def test_transaction_gas(
    state_test: StateTestFiller,
    pre: Alloc,
    fork: Fork,
    recipient_type: RecipientType,
    value: int,
) -> None:
    """Gas for a non-create transaction, per recipient type and value."""
    sender = pre.fund_eoa()
    target = setup_target(pre, recipient_type, sender)

    intrinsic_gas = fork.transaction_intrinsic_cost_calculator()(
        sends_value=bool(value),
        recipient_type=recipient_type,
        return_cost_deducted_prior_execution=True,
    )
    top_frame_gas = fork.transaction_top_frame_gas_calculator()(
        sends_value=bool(value),
        recipient_type=recipient_type,
    )
    top_frame_state_gas = fork.transaction_top_frame_state_gas(
        sends_value=bool(value),
        recipient_type=recipient_type,
    )
    gas_used = intrinsic_gas + top_frame_gas + top_frame_state_gas

    tx = Transaction(
        to=target,
        value=value,
        gas_limit=gas_used,
        sender=sender,
        expected_receipt=TransactionReceipt(cumulative_gas_used=gas_used),
    )

    post: dict[Address, Account | None] = {sender: Account(nonce=1)}
    if recipient_type != RecipientType.SELF:
        target_initial_balance = (
            EOA_INITIAL_BALANCE if recipient_type == RecipientType.EOA else 0
        )
        if recipient_type == RecipientType.EMPTY_ACCOUNT and value == 0:
            post[target] = None
        else:
            post[target] = Account(balance=target_initial_balance + value)

    state_test(pre=pre, post=post, tx=tx)

Parametrized Test Cases

This test generates 10 parametrized test cases across 1 fork.