test_slotnum_gas_cost()
Documentation for tests/amsterdam/eip7843_slotnum/test_slotnum.py::test_slotnum_gas_cost@b314d18e.
Generate fixtures for these test cases for Amsterdam with:
fill -v tests/amsterdam/eip7843_slotnum/test_slotnum.py::test_slotnum_gas_cost --fork Amsterdam
Test that SLOTNUM opcode costs exactly 2 gas (G_BASE).
Source code in tests/amsterdam/eip7843_slotnum/test_slotnum.py
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112 | @pytest.mark.parametrize(
"gas_delta,call_succeeds",
[
pytest.param(0, True, id="enough_gas"),
pytest.param(-1, False, id="out_of_gas"),
],
)
def test_slotnum_gas_cost(
state_test: StateTestFiller,
pre: Alloc,
fork: Fork,
gas_delta: int,
call_succeeds: bool,
) -> None:
"""
Test that SLOTNUM opcode costs exactly 2 gas (G_BASE).
"""
slotnum_gas = Op.SLOTNUM.gas_cost(fork)
call_gas = slotnum_gas + gas_delta
# Callee just executes SLOTNUM
callee_code = Op.SLOTNUM + Op.STOP
callee_address = pre.deterministic_deploy_contract(deploy_code=callee_code)
# Caller calls the callee with limited gas and stores result
caller_code = Op.SSTORE(0, Op.CALL(gas=call_gas, address=callee_address))
caller_address = pre.deploy_contract(caller_code)
tx = Transaction(
sender=pre.fund_eoa(),
to=caller_address,
)
post = {
caller_address: Account(
storage={0: 1 if call_succeeds else 0},
),
}
state_test(
env=Environment(slot_number=12345),
pre=pre,
tx=tx,
post=post,
)
|
Parametrized Test Cases
This test generates 2 parametrized test cases across 1 fork.