Skip to content

Commit f5cf060

Browse files
committed
fix(tests): Test using incorrect keyword argument
fix(tests): Test using incorrect keyword argument
1 parent 203f1d6 commit f5cf060

File tree

2 files changed

+35
-16
lines changed

2 files changed

+35
-16
lines changed

tests/frontier/identity_precompile/test_identity_returndatasize.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ def test_identity_precompile_returndata(
4949
address=Constants.IDENTITY_PRECOMPILE_ADDRESS,
5050
args_offset=0,
5151
args_size=args_size,
52-
output_offset=0x10,
53-
output_size=output_size,
52+
ret_offset=0x10,
53+
ret_size=output_size,
5454
)
5555
)
5656
+ Op.SSTORE(storage.store_next(expected_returndatasize), Op.RETURNDATASIZE)

tests/frontier/precompiles/test_precompiles.py

Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,17 @@ def precompile_addresses(fork: Fork) -> Iterator[Tuple[Address, bool]]:
4444
"https://github.com/ethereum/tests/blob/v13.3/src/GeneralStateTestsFiller/stPreCompiledContracts/idPrecompsFiller.yml"
4545
],
4646
pr=["https://github.com/ethereum/execution-spec-tests/pull/1120"],
47+
coverage_missed_reason=(
48+
"Original test saves variables to memory, loads from storage, uses calldataload to get "
49+
"the precompile address to call, uses lt and gt to compare the gas differences, "
50+
"sends non-zero data and value with the transaction, uses conditional jumps to save "
51+
"different values to storage."
52+
),
4753
)
4854
@pytest.mark.valid_from("Berlin")
4955
@pytest.mark.parametrize_by_fork("address,precompile_exists", precompile_addresses)
5056
def test_precompiles(
51-
state_test: StateTestFiller, address: str, precompile_exists: bool, pre: Alloc
57+
state_test: StateTestFiller, address: Address, precompile_exists: bool, pre: Alloc
5258
):
5359
"""
5460
Tests the behavior of precompiled contracts in the Ethereum state test.
@@ -69,27 +75,40 @@ def test_precompiles(
6975
"""
7076
env = Environment()
7177

78+
# Empty account to serve as reference
79+
empty_account = pre.fund_eoa(amount=0)
80+
81+
# Memory
82+
args_offset = 0
83+
ret_offset = 32
84+
length = 32
85+
7286
account = pre.deploy_contract(
73-
Op.MSTORE(0, 0) # Pre-expand the memory so the gas costs are exactly the same
87+
Op.MSTORE(args_offset, 0xFF) # Pre-expand the memory and setup inputs for pre-compiles
88+
+ Op.MSTORE(ret_offset, 0xFF)
89+
+ Op.MSTORE8(args_offset, 0xFF)
90+
+ Op.MSTORE8(ret_offset, 0xFF)
91+
+ Op.POP(Op.BALANCE(empty_account)) # Warm the accounts
92+
+ Op.POP(Op.BALANCE(address))
7493
+ Op.GAS
7594
+ Op.CALL(
95+
gas=50_000,
7696
address=address,
77-
value=0,
78-
args_offset=0,
79-
args_size=32,
80-
output_offset=32,
81-
output_size=32,
97+
args_offset=args_offset,
98+
args_size=length,
99+
ret_offset=ret_offset,
100+
ret_size=length,
82101
)
83102
+ Op.POP
84103
+ Op.SUB(Op.SWAP1, Op.GAS)
85104
+ Op.GAS
86105
+ Op.CALL(
87-
address=pre.fund_eoa(amount=0),
88-
value=0,
89-
args_offset=0,
90-
args_size=32,
91-
output_offset=32,
92-
output_size=32,
106+
gas=50_000,
107+
address=empty_account,
108+
args_offset=args_offset,
109+
args_size=length,
110+
ret_offset=ret_offset,
111+
ret_size=length,
93112
)
94113
+ Op.POP
95114
+ Op.SUB(Op.SWAP1, Op.GAS)
@@ -109,6 +128,6 @@ def test_precompiles(
109128

110129
# A high gas cost will result from calling a precompile
111130
# Expect 0x00 when a precompile exists at the address, 0x01 otherwise
112-
post = {account: Account(storage={0: "0x00" if precompile_exists else "0x01"})}
131+
post = {account: Account(storage={0: 0 if precompile_exists else 1})}
113132

114133
state_test(env=env, pre=pre, post=post, tx=tx)

0 commit comments

Comments
 (0)