Skip to content

Commit

Permalink
new(tests): Add EIP-7702 folder, first test
Browse files Browse the repository at this point in the history
  • Loading branch information
marioevz committed Jun 12, 2024
1 parent e818c50 commit 7786e62
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 0 deletions.
3 changes: 3 additions & 0 deletions tests/prague/eip7702_eoa_code_tx/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
"""
Cross-client EIP-7702 Tests
"""
29 changes: 29 additions & 0 deletions tests/prague/eip7702_eoa_code_tx/spec.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
"""
Defines EIP-7702 specification constants and functions.
"""
from dataclasses import dataclass


@dataclass(frozen=True)
class ReferenceSpec:
"""
Defines the reference spec version and git path.
"""

git_path: str
version: str


ref_spec_7702 = ReferenceSpec("EIPS/eip-7702.md", "7357ff1f3f176aada6d350d6e42a292a3dec27f4")


@dataclass(frozen=True)
class Spec:
"""
Parameters from the EIP-7702 specifications as defined at
https://eips.ethereum.org/EIPS/eip-7702
"""

SET_CODE_TX_TYPE = 0x04
MAGIC = 0x05
PER_AUTH_BASE_COST = 2500
55 changes: 55 additions & 0 deletions tests/prague/eip7702_eoa_code_tx/test_eoa_code_txs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
"""
abstract: Tests use of set-code transactions from [EIP-7702: Set EOA account code for one transaction](https://eips.ethereum.org/EIPS/eip-7702)
Tests use of set-code transactions from [EIP-7702: Set EOA account code for one transaction](https://eips.ethereum.org/EIPS/eip-7702).
""" # noqa: E501

import pytest

from ethereum_test_tools import Alloc, AuthorizationTuple, Environment
from ethereum_test_tools import Opcodes as Op
from ethereum_test_tools import StateTestFiller, Transaction

from .spec import ref_spec_7702

REFERENCE_SPEC_GIT_PATH = ref_spec_7702.git_path
REFERENCE_SPEC_VERSION = ref_spec_7702.version

pytestmark = [
pytest.mark.valid_from("Prague"),
]


def test_set_code_to_self_destruct(
state_test: StateTestFiller,
pre: Alloc,
):
"""
Test the executing self-destruct opcode in a set-code transaction.
"""
set_code_to_address = pre.deploy_contract(Op.SELFDESTRUCT(Op.ADDRESS))

signer = pre.fund_eoa(0)

sender = pre.fund_eoa(10**18)

tx = Transaction(
gas_limit=1_000_000,
to=sender,
value=0,
authorization_tuples=[
AuthorizationTuple(
chain_id=1,
address=set_code_to_address,
nonce=0,
signer=signer,
),
],
sender=sender,
)

state_test(
env=Environment(),
pre=pre,
tx=tx,
post={},
)

0 comments on commit 7786e62

Please sign in to comment.