Skip to content

test_gas_costs()

Documentation for tests/byzantium/eip196_ec_add_mul/test_gas.py::test_gas_costs@7b8124a7.

Generate fixtures for these test cases for Osaka with:

fill -v tests/byzantium/eip196_ec_add_mul/test_gas.py::test_gas_costs --fork Osaka

Tests the constant gas behavior of ecadd/ecmul precompiled contracts.

Source code in tests/byzantium/eip196_ec_add_mul/test_gas.py
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
@pytest.mark.valid_from("Byzantium")
@pytest.mark.parametrize(
    "address",
    [
        pytest.param(Spec.ECADD, id="ecadd"),
        pytest.param(Spec.ECMUL, id="ecmul"),
    ],
)
@pytest.mark.parametrize("enough_gas", [True, False])
def test_gas_costs(
    state_test: StateTestFiller,
    pre: Alloc,
    fork: Fork,
    address: Address,
    enough_gas: bool,
) -> None:
    """
    Tests the constant gas behavior of `ecadd/ecmul` precompiled contracts.
    """
    gas_costs = fork.gas_costs()
    gas = (
        gas_costs.G_PRECOMPILE_ECADD
        if address == Spec.ECADD
        else gas_costs.G_PRECOMPILE_ECMUL
    )
    if not enough_gas:
        gas -= 1

    account = pre.deploy_contract(
        code=Op.SSTORE(0, Op.CALL(gas=gas, address=address)),
        storage={0: 0xDEADBEEF},
    )

    tx = Transaction(
        to=account,
        sender=pre.fund_eoa(),
        gas_limit=100_0000,
        protected=fork.supports_protected_txs(),
    )

    post = {account: Account(storage={0: 1 if enough_gas else 0})}

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

Parametrized Test Cases

This test generates 4 parametrized test cases across 11 forks.