Skip to content

Commit

Permalink
refactor(tests/prague): use ethereum_test_addresses
Browse files Browse the repository at this point in the history
  • Loading branch information
marioevz committed Sep 27, 2024
1 parent 47a3646 commit 5ee7a97
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 22 deletions.
20 changes: 11 additions & 9 deletions tests/prague/eip2537_bls_12_381_precompiles/spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
from dataclasses import dataclass
from typing import Callable, List, Sized, SupportsBytes, Tuple

from ethereum_test_addresses import Precompile

from .helpers import current_python_script_directory


Expand Down Expand Up @@ -122,15 +124,15 @@ class Spec:
"""

# Addresses
G1ADD = 0x0B
G1MUL = 0x0C
G1MSM = 0x0D
G2ADD = 0x0E
G2MUL = 0x0F
G2MSM = 0x10
PAIRING = 0x11
MAP_FP_TO_G1 = 0x12
MAP_FP2_TO_G2 = 0x13
G1ADD = Precompile.BLS_12_381_G1_ADD
G1MUL = Precompile.BLS_12_381_G1_MUL
G1MSM = Precompile.BLS_12_381_G1_MULTIEXP
G2ADD = Precompile.BLS_12_381_G2_ADD
G2MUL = Precompile.BLS_12_381_G2_MUL
G2MSM = Precompile.BLS_12_381_G2_MULTIEXP
PAIRING = Precompile.BLS_12_381_PAIRING
MAP_FP_TO_G1 = Precompile.BLS_12_381_MAP_FP_TO_G1
MAP_FP2_TO_G2 = Precompile.BLS_12_381_MAP_FP2_TO_G2

# Gas constants
G1ADD_GAS = 500
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

from dataclasses import dataclass

from ethereum_test_addresses import SystemContract


@dataclass(frozen=True)
class ReferenceSpec:
Expand All @@ -26,6 +28,6 @@ class Spec:
"""

FORK_TIMESTAMP = 15_000
HISTORY_STORAGE_ADDRESS = 0x0AAE40965E6800CD9B1F4B05FF21581047E3F91E
HISTORY_STORAGE_ADDRESS = SystemContract.BLOCK_HISTORY_CONTRACT
HISTORY_SERVE_WINDOW = 8192
BLOCKHASH_OLD_WINDOW = 256
4 changes: 3 additions & 1 deletion tests/prague/eip6110_deposits/spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
"""
from dataclasses import dataclass

from ethereum_test_addresses import SystemContract


@dataclass(frozen=True)
class ReferenceSpec:
Expand All @@ -24,4 +26,4 @@ class Spec:
https://eips.ethereum.org/EIPS/eip-6110
"""

DEPOSIT_CONTRACT_ADDRESS = 0x00000000219AB540356CBB839CBE05303D7705FA
DEPOSIT_CONTRACT_ADDRESS = SystemContract.BEACON_DEPOSIT_CONTRACT
6 changes: 4 additions & 2 deletions tests/prague/eip7002_el_triggerable_withdrawals/spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

from dataclasses import dataclass

from ethereum_test_addresses import SYSTEM_ADDRESS, SystemContract


@dataclass(frozen=True)
class ReferenceSpec:
Expand All @@ -30,8 +32,8 @@ class Spec:
out.
"""

WITHDRAWAL_REQUEST_PREDEPLOY_ADDRESS = 0x0000B595F2A73542E60B811C3EB8A231CA3CAAAA
SYSTEM_ADDRESS = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE
WITHDRAWAL_REQUEST_PREDEPLOY_ADDRESS = SystemContract.WITHDRAWAL_REQUESTS_CONTRACT
SYSTEM_ADDRESS = SYSTEM_ADDRESS

EXCESS_WITHDRAWAL_REQUESTS_STORAGE_SLOT = 0
WITHDRAWAL_REQUEST_COUNT_STORAGE_SLOT = 1
Expand Down
6 changes: 4 additions & 2 deletions tests/prague/eip7251_consolidations/spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

from dataclasses import dataclass

from ethereum_test_addresses import SYSTEM_ADDRESS, SystemContract


@dataclass(frozen=True)
class ReferenceSpec:
Expand All @@ -26,8 +28,8 @@ class Spec:
https://eips.ethereum.org/EIPS/eip-7251#execution-layer
"""

CONSOLIDATION_REQUEST_PREDEPLOY_ADDRESS = 0x000b0cbbCb4A622b212A4c8BF81A3614ceaAbBBB
SYSTEM_ADDRESS = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE
CONSOLIDATION_REQUEST_PREDEPLOY_ADDRESS = SystemContract.CONSOLIDATION_REQUESTS_CONTRACT
SYSTEM_ADDRESS = SYSTEM_ADDRESS

EXCESS_CONSOLIDATION_REQUESTS_STORAGE_SLOT = 0
CONSOLIDATION_REQUEST_COUNT_STORAGE_SLOT = 1
Expand Down
15 changes: 8 additions & 7 deletions tests/prague/eip7702_set_code_tx/test_set_code_txs.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import pytest
from ethereum.crypto.hash import keccak256

from ethereum_test_addresses import SystemContract
from ethereum_test_tools import (
AccessList,
Account,
Expand Down Expand Up @@ -2440,23 +2441,23 @@ def test_set_code_to_system_contract(

# Setup the initial storage of the account to mimic the system contract if required
match system_contract:
case Address(0x00000000219AB540356CBB839CBE05303D7705FA): # EIP-6110
case SystemContract.BEACON_DEPOSIT_CONTRACT: # EIP-6110
# Deposit contract needs specific storage values, so we set them on the account
auth_signer = pre.fund_eoa(
auth_account_start_balance, storage=deposit_contract_initial_storage()
)
case Address(0x000F3DF6D732807EF1319FB7B8BB8522D0BEAC02): # EIP-4788
case SystemContract.BEACON_ROOT_HISTORY_CONTRACT: # EIP-4788
auth_signer = pre.fund_eoa(auth_account_start_balance, storage=Storage({1: 1}))
case _:
# Pre-fund without storage
auth_signer = pre.fund_eoa(auth_account_start_balance)

# Fabricate the payload for the system contract
match system_contract:
case Address(0x000F3DF6D732807EF1319FB7B8BB8522D0BEAC02): # EIP-4788
case SystemContract.BEACON_ROOT_HISTORY_CONTRACT: # EIP-4788
caller_payload = Hash(1)
caller_code_storage[call_return_data_size_slot] = 32
case Address(0x00000000219AB540356CBB839CBE05303D7705FA): # EIP-6110
case SystemContract.BEACON_DEPOSIT_CONTRACT: # EIP-6110
# Fabricate a valid deposit request to the set-code account
deposit_request = DepositRequest(
pubkey=0x01,
Expand All @@ -2467,7 +2468,7 @@ def test_set_code_to_system_contract(
)
caller_payload = deposit_request.calldata
call_value = deposit_request.value
case Address(0x0000B595F2A73542E60B811C3EB8A231CA3CAAAA): # EIP-7002
case SystemContract.WITHDRAWAL_REQUESTS_CONTRACT: # EIP-7002
# Fabricate a valid withdrawal request to the set-code account
withdrawal_request = WithdrawalRequest(
source_address=0x01,
Expand All @@ -2477,7 +2478,7 @@ def test_set_code_to_system_contract(
)
caller_payload = withdrawal_request.calldata
call_value = withdrawal_request.value
case Address(0x000B0CBBCB4A622B212A4C8BF81A3614CEAABBBB): # EIP-7251
case SystemContract.CONSOLIDATION_REQUESTS_CONTRACT: # EIP-7251
# Fabricate a valid consolidation request to the set-code account
consolidation_request = ConsolidationRequest(
source_address=0x01,
Expand All @@ -2487,7 +2488,7 @@ def test_set_code_to_system_contract(
)
caller_payload = consolidation_request.calldata
call_value = consolidation_request.value
case Address(0x0AAE40965E6800CD9B1F4B05FF21581047E3F91E): # EIP-2935
case SystemContract.BLOCK_HISTORY_CONTRACT: # EIP-2935
caller_payload = Hash(0)
caller_code_storage[call_return_data_size_slot] = 32
case _:
Expand Down

0 comments on commit 5ee7a97

Please sign in to comment.