Skip to content

Commit

Permalink
address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
winsvega committed Aug 28, 2024
1 parent 54c8dd6 commit 43ba0f3
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions tests/frontier/opcodes/test_all_opcodes.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""
Call every possible opcode to see if it is recognized by the evm
If opcode is undefined the subcall will fail
Call every possible opcode and test that the subcall is successful
if the opcode is supported by the fork supports and fails otherwise.
"""

from typing import Dict
Expand All @@ -23,8 +23,6 @@

REFERENCE_SPEC_GIT_PATH = "N/A"
REFERENCE_SPEC_VERSION = "N/A"
all_opcodes = set(Op)
undefined_opcodes = set(UndefinedOpcodes)


def prepare_stack(opcode: Opcode) -> Bytecode:
Expand All @@ -49,19 +47,23 @@ def prepare_suffix(opcode: Opcode) -> Bytecode:

@pytest.mark.valid_from("Frontier")
def test_all_opcodes(state_test: StateTestFiller, pre: Alloc, fork: Fork):
"""Check if the opcode supported on given fork"""
"""
Test each possible opcode on the fork with a single contract that
calls each opcode in succession. Check that each subcall passes
if the opcode is supported and fails otherwise.
"""
code_worked = 1000

code_contract: Dict[Opcode, Address] = {}
for opcode in sorted(all_opcodes | undefined_opcodes):
for opcode in sorted(set(Op) | set(UndefinedOpcodes)):
code_contract[opcode] = pre.deploy_contract(
balance=10,
code=prepare_stack(opcode) + opcode + prepare_suffix(opcode),
storage={},
)

# EVM code to make the call and store the result
caller = pre.deploy_contract(
contract_address = pre.deploy_contract(
code=sum(
Op.SSTORE(
Op.PUSH1(opcode.int()),
Expand All @@ -74,15 +76,15 @@ def test_all_opcodes(state_test: StateTestFiller, pre: Alloc, fork: Fork):
)

post = {
caller: Account(
contract_address: Account(
storage={**{opcode.int(): 1 for opcode in fork.valid_opcodes()}, code_worked: 1}
),
}

tx = Transaction(
sender=pre.fund_eoa(),
gas_limit=500_000_000,
to=caller,
to=contract_address,
data=b"",
value=0,
protected=False,
Expand Down

0 comments on commit 43ba0f3

Please sign in to comment.