Skip to content

Commit fc7a3bb

Browse files
committed
add tx direct test variant
1 parent 76ce50e commit fc7a3bb

File tree

1 file changed

+38
-21
lines changed

1 file changed

+38
-21
lines changed

tests/frontier/opcodes/test_calldataload.py

Lines changed: 38 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -33,45 +33,62 @@
3333
"34_bytes",
3434
],
3535
)
36+
@pytest.mark.parametrize("calldata_source", ["contract", "tx"])
3637
def test_calldataload(
3738
state_test: StateTestFiller,
3839
calldata: bytes,
3940
calldata_offset: int,
4041
fork: Fork,
4142
pre: Alloc,
4243
expected_storage: Account,
44+
calldata_source: str,
4345
):
4446
"""
4547
Test `CALLDATALOAD` opcode.
4648
49+
Tests two scenarios:
50+
- calldata_source is "contract": CALLDATALOAD reads from calldata passed by another contract
51+
- calldata_source is "tx": CALLDATALOAD reads directly from transaction calldata
52+
4753
Based on https://github.com/ethereum/tests/blob/ae4791077e8fcf716136e70fe8392f1a1f1495fb/src/GeneralStateTestsFiller/VMTests/vmTests/calldatacopyFiller.yml
4854
"""
49-
address_a = pre.deploy_contract(
55+
contract_address = pre.deploy_contract(
5056
Op.SSTORE(0, Op.CALLDATALOAD(offset=calldata_offset)) + Op.STOP,
5157
)
5258

53-
to = pre.deploy_contract(
54-
Om.MSTORE(calldata, 0x0)
55-
+ Op.CALL(
56-
gas=Op.SUB(Op.GAS(), 0x100),
57-
address=address_a,
58-
value=0x0,
59-
args_offset=0x0,
60-
args_size=len(calldata),
61-
ret_offset=0x0,
62-
ret_size=0x0,
59+
if calldata_source == "contract":
60+
to = pre.deploy_contract(
61+
Om.MSTORE(calldata, 0x0)
62+
+ Op.CALL(
63+
gas=Op.SUB(Op.GAS(), 0x100),
64+
address=contract_address,
65+
value=0x0,
66+
args_offset=0x0,
67+
args_size=len(calldata),
68+
ret_offset=0x0,
69+
ret_size=0x0,
70+
)
71+
+ Op.STOP
72+
)
73+
74+
tx = Transaction(
75+
data=calldata,
76+
gas_limit=100_000,
77+
protected=fork >= Byzantium,
78+
sender=pre.fund_eoa(),
79+
to=to,
80+
)
81+
82+
else:
83+
tx = Transaction(
84+
data=calldata,
85+
gas_limit=100_000,
86+
protected=fork >= Byzantium,
87+
sender=pre.fund_eoa(),
88+
to=contract_address,
6389
)
64-
+ Op.STOP
65-
)
6690

67-
tx = Transaction(
68-
data=calldata,
69-
gas_limit=100_000,
70-
protected=fork >= Byzantium,
71-
sender=pre.fund_eoa(),
72-
to=to,
73-
)
7491
post = {
75-
address_a: Account(storage={0x00: expected_storage}),
92+
contract_address: Account(storage={0x00: expected_storage}),
7693
}
7794
state_test(pre=pre, post=post, tx=tx)

0 commit comments

Comments
 (0)