The set of PUSH* opcodes pushes data onto the stack.
In this test, we ensure that the set of PUSH* opcodes writes a portion of
an excerpt from the Ethereum yellow paper to storage.
Source code in tests/frontier/opcodes/test_push.py
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
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 | @pytest.mark.ported_from(
[
"https://github.com/ethereum/tests/blob/v13.3/src/GeneralStateTestsFiller/VMTests/vmTests/pushFiller.yml",
],
pr=["https://github.com/ethereum/execution-spec-tests/pull/975"],
)
@pytest.mark.parametrize(
"push_opcode",
# Dynamically parametrize PUSH opcodes
[getattr(Op, f"PUSH{i}") for i in range(1, 33)],
ids=lambda op: str(op),
)
@pytest.mark.valid_from("Frontier")
def test_push(
state_test: StateTestFiller, fork: Fork, pre: Alloc, push_opcode: Op
) -> None:
"""
The set of `PUSH*` opcodes pushes data onto the stack.
In this test, we ensure that the set of `PUSH*` opcodes writes a portion of
an excerpt from the Ethereum yellow paper to storage.
"""
# Input used to test the `PUSH*` opcode.
excerpt = get_input_for_push_opcode(push_opcode)
env = Environment()
"""
** Bytecode explanation **
+---------------------------------------------------+
| Bytecode | Stack | Storage |
|---------------------------------------------------|
| PUSH* excerpt | excerpt | |
| PUSH1 0 | 0 excerpt | |
| SSTORE | | [0]: excerpt |
+---------------------------------------------------+
"""
contract_code = push_opcode(excerpt) + Op.PUSH1(0) + Op.SSTORE
contract = pre.deploy_contract(contract_code)
tx = Transaction(
sender=pre.fund_eoa(),
to=contract,
gas_limit=500_000,
protected=fork.supports_protected_txs(),
)
post = {}
post[contract] = Account(
storage={0: int.from_bytes(excerpt, byteorder="big")}
)
state_test(env=env, pre=pre, post=post, tx=tx)
|