Skip to content

Commit

Permalink
refactor(tests): prague EIP-7692
Browse files Browse the repository at this point in the history
  • Loading branch information
marioevz committed Jun 4, 2024
1 parent 4ae0fec commit 625ca07
Showing 1 changed file with 67 additions and 70 deletions.
137 changes: 67 additions & 70 deletions tests/prague/eip7692_eof_v1/eip4200_relative_jumps/test_rjumpi.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@

from ethereum_test_tools import (
Account,
Alloc,
Environment,
EOFException,
EOFStateTestFiller,
EOFTestFiller,
StateTestFiller,
TestAddress,
Transaction,
)
from ethereum_test_tools.eof.v1 import Container, Section
Expand Down Expand Up @@ -40,38 +40,37 @@
)
def test_rjumpi_condition_forwards(
state_test: StateTestFiller,
pre: Alloc,
calldata: bytes,
):
"""Test RJUMPI contract switching based on external input"""
env = Environment()
sender = pre.fund_sender(10**18)
contract_address = pre.deploy_contract(
code=Container(
sections=[
Section.Code(
code=Op.PUSH1(0)
+ Op.CALLDATALOAD
+ Op.RJUMPI[6]
+ Op.SSTORE(slot_conditional_result, value_calldata_false)
+ Op.STOP
+ Op.SSTORE(slot_conditional_result, value_calldata_true)
+ Op.STOP,
code_outputs=NON_RETURNING_SECTION,
max_stack_height=2,
)
]
),
)
tx = Transaction(
nonce=1,
to=contract_address,
gas_limit=10_000_000,
data=calldata,
sender=sender,
)
pre = {
TestAddress: Account(balance=10**18, nonce=tx.nonce),
tx.to: Account(
code=Container(
sections=[
Section.Code(
code=Op.PUSH1(0)
+ Op.CALLDATALOAD
+ Op.RJUMPI[6]
+ Op.SSTORE(slot_conditional_result, value_calldata_false)
+ Op.STOP
+ Op.SSTORE(slot_conditional_result, value_calldata_true)
+ Op.STOP,
code_outputs=NON_RETURNING_SECTION,
max_stack_height=2,
)
]
),
nonce=1,
),
}
post = {
tx.to: Account(
contract_address: Account(
storage={
slot_conditional_result: value_calldata_false
if calldata == b"\0"
Expand All @@ -88,40 +87,39 @@ def test_rjumpi_condition_forwards(
)
def test_rjumpi_condition_backwards(
state_test: StateTestFiller,
pre: Alloc,
calldata: bytes,
):
"""Test RJUMPI contract switching based on external input"""
env = Environment()
sender = pre.fund_sender(10**18)
contract_address = pre.deploy_contract(
code=Container(
sections=[
Section.Code(
code=Op.PUSH1(1)
+ Op.RJUMPI[6]
+ Op.SSTORE(slot_conditional_result, value_calldata_true)
+ Op.STOP
+ Op.PUSH0
+ Op.CALLDATALOAD
+ Op.RJUMPI[-11]
+ Op.SSTORE(slot_conditional_result, value_calldata_false)
+ Op.STOP,
code_outputs=NON_RETURNING_SECTION,
max_stack_height=2,
)
]
)
)
tx = Transaction(
nonce=1,
to=contract_address,
gas_limit=10_000_000,
data=calldata,
sender=sender,
)
pre = {
TestAddress: Account(balance=10**18, nonce=tx.nonce),
tx.to: Account(
code=Container(
sections=[
Section.Code(
code=Op.PUSH1(1)
+ Op.RJUMPI[6]
+ Op.SSTORE(slot_conditional_result, value_calldata_true)
+ Op.STOP
+ Op.PUSH0
+ Op.CALLDATALOAD
+ Op.RJUMPI[-11]
+ Op.SSTORE(slot_conditional_result, value_calldata_false)
+ Op.STOP,
code_outputs=NON_RETURNING_SECTION,
max_stack_height=2,
)
]
),
nonce=1,
),
}
post = {
tx.to: Account(
contract_address: Account(
storage={
slot_conditional_result: value_calldata_false
if calldata == b"\0"
Expand All @@ -138,35 +136,34 @@ def test_rjumpi_condition_backwards(
)
def test_rjumpi_condition_zero(
state_test: StateTestFiller,
pre: Alloc,
calldata: bytes,
):
"""Test RJUMPI contract switching based on external input"""
env = Environment()
sender = pre.fund_sender(10**18)
contract_address = pre.deploy_contract(
code=Container(
sections=[
Section.Code(
code=Op.PUSH0
+ Op.CALLDATALOAD
+ Op.RJUMPI[0]
+ Op.SSTORE(slot_code_worked, value_code_worked)
+ Op.STOP,
code_outputs=NON_RETURNING_SECTION,
max_stack_height=2,
)
]
),
)
tx = Transaction(
nonce=1,
to=contract_address,
gas_limit=10_000_000,
data=calldata,
sender=sender,
)
pre = {
TestAddress: Account(balance=10**18, nonce=tx.nonce),
tx.to: Account(
code=Container(
sections=[
Section.Code(
code=Op.PUSH0
+ Op.CALLDATALOAD
+ Op.RJUMPI[0]
+ Op.SSTORE(slot_code_worked, value_code_worked)
+ Op.STOP,
code_outputs=NON_RETURNING_SECTION,
max_stack_height=2,
)
]
),
nonce=1,
),
}
post = {tx.to: Account(storage={slot_code_worked: value_code_worked})}
post = {contract_address: Account(storage={slot_code_worked: value_code_worked})}
state_test(env=env, tx=tx, pre=pre, post=post)


Expand Down

0 comments on commit 625ca07

Please sign in to comment.