Skip to content

Commit e67cdd5

Browse files
committed
parametrize calldatasize
1 parent fc7a3bb commit e67cdd5

File tree

2 files changed

+42
-26
lines changed

2 files changed

+42
-26
lines changed

tests/frontier/opcodes/test_calldataload.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,5 @@ def test_calldataload(
8888
to=contract_address,
8989
)
9090

91-
post = {
92-
contract_address: Account(storage={0x00: expected_storage}),
93-
}
91+
post = {contract_address: Account(storage={0x00: expected_storage})}
9492
state_test(pre=pre, post=post, tx=tx)

tests/frontier/opcodes/test_calldatasize.py

Lines changed: 41 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -12,39 +12,57 @@
1212
"args_size",
1313
[0, 2, 16, 33, 257],
1414
)
15-
def test_calldataload(
15+
@pytest.mark.parametrize("calldata_source", ["contract", "tx"])
16+
def test_calldatasize(
1617
state_test: StateTestFiller,
1718
fork: Fork,
1819
args_size: int,
1920
pre: Alloc,
21+
calldata_source: str,
2022
):
2123
"""
2224
Test `CALLDATASIZE` opcode.
2325
26+
Tests two scenarios:
27+
- calldata_source is "contract": CALLDATASIZE reads from calldata passed by another contract
28+
- calldata_source is "tx": CALLDATASIZE reads directly from transaction calldata
29+
2430
Based on https://github.com/ethereum/tests/blob/81862e4848585a438d64f911a19b3825f0f4cd95/src/GeneralStateTestsFiller/VMTests/vmTests/calldatasizeFiller.yml
2531
"""
26-
address = pre.deploy_contract(Op.SSTORE(key=0x0, value=Op.CALLDATASIZE))
27-
28-
to = pre.deploy_contract(
29-
code=(
30-
Om.MSTORE(b"\x01" * args_size, 0x0)
31-
+ Op.CALL(
32-
gas=Op.SUB(Op.GAS(), 0x100),
33-
address=address,
34-
value=0x0,
35-
args_offset=0x0,
36-
args_size=args_size,
37-
ret_offset=0x0,
38-
ret_size=0x0,
32+
contract_address = pre.deploy_contract(Op.SSTORE(key=0x0, value=Op.CALLDATASIZE))
33+
calldata = b"\x01" * args_size
34+
35+
if calldata_source == "contract":
36+
to = pre.deploy_contract(
37+
code=(
38+
Om.MSTORE(calldata, 0x0)
39+
+ Op.CALL(
40+
gas=Op.SUB(Op.GAS(), 0x100),
41+
address=contract_address,
42+
value=0x0,
43+
args_offset=0x0,
44+
args_size=args_size,
45+
ret_offset=0x0,
46+
ret_size=0x0,
47+
)
3948
)
4049
)
41-
)
42-
43-
tx = Transaction(
44-
gas_limit=100_000,
45-
protected=fork >= Byzantium,
46-
sender=pre.fund_eoa(),
47-
to=to,
48-
)
49-
post = {address: Account(storage={0x00: args_size})}
50+
51+
tx = Transaction(
52+
gas_limit=100_000,
53+
protected=fork >= Byzantium,
54+
sender=pre.fund_eoa(),
55+
to=to,
56+
)
57+
58+
else:
59+
tx = Transaction(
60+
data=calldata,
61+
gas_limit=100_000,
62+
protected=fork >= Byzantium,
63+
sender=pre.fund_eoa(),
64+
to=contract_address,
65+
)
66+
67+
post = {contract_address: Account(storage={0x00: args_size})}
5068
state_test(pre=pre, post=post, tx=tx)

0 commit comments

Comments
 (0)