Skip to content

Commit

Permalink
tests/beacon_root: Change naming from precompile -> contract. (#285)
Browse files Browse the repository at this point in the history
  • Loading branch information
spencer-tb authored Sep 1, 2023
1 parent 1c4dfd1 commit 74dcd93
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 33 deletions.
4 changes: 2 additions & 2 deletions tests/cancun/eip4788_beacon_root/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ def expected_storage(
valid_input: bool,
) -> Storage:
"""
Derives the expected storage for a given beacon root precompile call
Derives the expected storage for a given beacon root contract call
dependent on:
- success or failure of the call
- validity of the timestamp input used within the call
"""
# By default assume the call is unsuccessful and all keys are zero
storage = Storage({k: 0 for k in range(4)})
if valid_call and valid_input:
# beacon root precompile call is successful
# beacon root contract call is successful
storage[0] = 1
storage[1] = beacon_root
storage[2] = 32
Expand Down
38 changes: 19 additions & 19 deletions tests/cancun/eip4788_beacon_root/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,15 @@ def caller_address() -> str: # noqa: D103


@pytest.fixture
def precompile_call_account(call_type: Op, call_value: int, call_gas: int) -> Account:
def contract_call_account(call_type: Op, call_value: int, call_gas: int) -> Account:
"""
Code to call the beacon root precompile.
Code to call the beacon root contract.
"""
args_start, args_length, return_start, return_length = 0x20, Op.CALLDATASIZE, 0x00, 0x20
precompile_call_code = Op.CALLDATACOPY(args_start, 0x00, args_length)
contract_call_code = Op.CALLDATACOPY(args_start, 0x00, args_length)
if call_type == Op.CALL or call_type == Op.CALLCODE:
precompile_call_code += Op.SSTORE(
0x00, # store the result of the precompile call in storage[0]
contract_call_code += Op.SSTORE(
0x00, # store the result of the contract call in storage[0]
call_type(
call_gas,
BEACON_ROOT_CONTRACT_ADDRESS,
Expand All @@ -98,7 +98,7 @@ def precompile_call_account(call_type: Op, call_value: int, call_gas: int) -> Ac
)
elif call_type == Op.DELEGATECALL or call_type == Op.STATICCALL:
# delegatecall and staticcall use one less argument
precompile_call_code += Op.SSTORE(
contract_call_code += Op.SSTORE(
0x00,
call_type(
call_gas,
Expand All @@ -109,12 +109,12 @@ def precompile_call_account(call_type: Op, call_value: int, call_gas: int) -> Ac
return_length,
),
)
precompile_call_code += (
Op.SSTORE( # Save the return value of the precompile call
contract_call_code += (
Op.SSTORE( # Save the return value of the contract call
0x01,
Op.MLOAD(return_start),
)
+ Op.SSTORE( # Save the length of the return value of the precompile call
+ Op.SSTORE( # Save the length of the return value of the contract call
0x02,
Op.RETURNDATASIZE,
)
Expand All @@ -130,23 +130,23 @@ def precompile_call_account(call_type: Op, call_value: int, call_gas: int) -> Ac
)
return Account(
nonce=0,
code=precompile_call_code,
code=contract_call_code,
balance=0x10**10,
)


@pytest.fixture
def valid_call() -> bool:
"""
Validity of beacon root precompile call: defaults to True.
Validity of beacon root contract call: defaults to True.
"""
return True


@pytest.fixture
def valid_input() -> bool:
"""
Validity of timestamp input to precompile call: defaults to True.
Validity of timestamp input to contract call: defaults to True.
"""
return True

Expand All @@ -161,20 +161,20 @@ def system_address_balance() -> int:

@pytest.fixture
def pre(
precompile_call_account: Account,
contract_call_account: Account,
system_address_balance: int,
caller_address: str,
) -> Dict:
"""
Prepares the pre state of all test cases, by setting the balance of the
source account of all test transactions, and the precompile caller account.
source account of all test transactions, and the contract caller account.
"""
return {
TestAddress: Account(
nonce=0,
balance=0x10**10,
),
caller_address: precompile_call_account,
caller_address: contract_call_account,
SYSTEM_ADDRESS: Account(
nonce=0,
balance=system_address_balance,
Expand All @@ -198,7 +198,7 @@ def auto_access_list() -> bool:
@pytest.fixture
def access_list(auto_access_list: bool, timestamp: int) -> List[AccessList]:
"""
Access list included in the transaction to call the beacon root precompile.
Access list included in the transaction to call the beacon root contract.
"""
if auto_access_list:
return [
Expand All @@ -216,7 +216,7 @@ def access_list(auto_access_list: bool, timestamp: int) -> List[AccessList]:
@pytest.fixture
def tx_data(timestamp: int) -> bytes:
"""
Data included in the transaction to call the beacon root precompile.
Data included in the transaction to call the beacon root contract.
"""
return to_hash_bytes(timestamp)

Expand All @@ -240,7 +240,7 @@ def tx(
call_beacon_root_contract: bool,
) -> Transaction:
"""
Prepares transaction to call the beacon root precompile caller account.
Prepares transaction to call the beacon root contract caller account.
"""
to = BEACON_ROOT_CONTRACT_ADDRESS if call_beacon_root_contract else tx_to_address
kwargs: Dict = {
Expand Down Expand Up @@ -280,7 +280,7 @@ def post(
call_beacon_root_contract: bool,
) -> Dict:
"""
Prepares the expected post state for a single precompile call based upon the success or
Prepares the expected post state for a single contract call based upon the success or
failure of the call, and the validity of the timestamp input.
"""
storage = Storage()
Expand Down
21 changes: 10 additions & 11 deletions tests/cancun/eip4788_beacon_root/test_beacon_root_contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,15 @@
],
)
@pytest.mark.valid_from("Cancun")
def test_beacon_root_precompile_calls(
def test_beacon_root_contract_calls(
state_test: StateTestFiller,
env: Environment,
pre: Dict,
tx: Transaction,
post: Dict,
):
"""
Tests the beacon root precompile call using various call contexts:
Tests the beacon root contract call using various call contexts:
- `CALL`
- `DELEGATECALL`
- `CALLCODE`
Expand All @@ -77,7 +77,7 @@ def test_beacon_root_precompile_calls(
- extra gas (valid call)
- insufficient gas (invalid call)
The expected result is that the precompile call will be executed if the gas amount is met
The expected result is that the contract call will be executed if the gas amount is met
and return the correct`parent_beacon_block_root`. Otherwise the call will be invalid, and not
be executed. This is highlighted within storage by storing the return value of each call
context.
Expand Down Expand Up @@ -114,17 +114,17 @@ def test_beacon_root_precompile_calls(
],
)
@pytest.mark.valid_from("Cancun")
def test_beacon_root_precompile_timestamps(
def test_beacon_root_contract_timestamps(
state_test: StateTestFiller,
env: Environment,
pre: Dict,
tx: Transaction,
post: Dict,
):
"""
Tests the beacon root precompile call across for various valid and invalid timestamps.
Tests the beacon root contract call across for various valid and invalid timestamps.
The expected result is that the precompile call will return the correct
The expected result is that the contract call will return the correct
`parent_beacon_block_root` for a valid input timestamp and return the zero'd 32 bytes value
for an invalid input timestamp.
"""
Expand Down Expand Up @@ -157,7 +157,7 @@ def test_calldata_lengths(
post: Dict,
):
"""
Tests the beacon root precompile call using multiple invalid input lengths.
Tests the beacon root contract call using multiple invalid input lengths.
"""
state_test(
env=env,
Expand Down Expand Up @@ -187,9 +187,9 @@ def test_beacon_root_equal_to_timestamp(
post: Dict,
):
"""
Tests the beacon root precompile call where the beacon root is equal to the timestamp.
Tests the beacon root contract call where the beacon root is equal to the timestamp.
The expected result is that the precompile call will return the `parent_beacon_block_root`,
The expected result is that the contract call will return the `parent_beacon_block_root`,
as all timestamps used are valid.
"""
state_test(
Expand All @@ -212,8 +212,7 @@ def test_tx_to_beacon_root_contract(
post: Dict,
):
"""
Tests the beacon root precompile call using a transaction to the precompile contract, using
different transaction types and data lengths.
Tests the beacon root contract using a transaction with different types and data lengths.
"""
state_test(
env=env,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def test_multi_block_beacon_root_timestamp_calls(
):
"""
Tests multiple blocks where each block writes a timestamp to storage and contains one
transaction that calls the beacon root precompile multiple times.
transaction that calls the beacon root contract multiple times.
The blocks might overwrite the historical roots buffer, or not, depending on the `timestamps`,
and whether they increment in multiples of `HISTORICAL_ROOTS_MODULUS` or not.
Expand Down

0 comments on commit 74dcd93

Please sign in to comment.