-
Notifications
You must be signed in to change notification settings - Fork 122
/
Copy pathtest_calldatasize.py
50 lines (43 loc) · 1.33 KB
/
test_calldatasize.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
"""test `CALLDATASIZE` opcode."""
import pytest
from ethereum_test_forks import Byzantium, Fork
from ethereum_test_tools import Account, Alloc, StateTestFiller, Transaction
from ethereum_test_tools import Macros as Om
from ethereum_test_tools.vm.opcode import Opcodes as Op
@pytest.mark.parametrize(
"args_size",
[0, 2, 16, 33, 257],
)
def test_calldataload(
state_test: StateTestFiller,
fork: Fork,
args_size: int,
pre: Alloc,
):
"""
Test `CALLDATASIZE` opcode.
Based on https://github.com/ethereum/tests/blob/81862e4848585a438d64f911a19b3825f0f4cd95/src/GeneralStateTestsFiller/VMTests/vmTests/calldatasizeFiller.yml
"""
address = pre.deploy_contract(Op.SSTORE(key=0x0, value=Op.CALLDATASIZE))
to = pre.deploy_contract(
code=(
Om.MSTORE(b"\x01" * args_size, 0x0)
+ Op.CALL(
gas=Op.SUB(Op.GAS(), 0x100),
address=address,
value=0x0,
args_offset=0x0,
args_size=args_size,
ret_offset=0x0,
ret_size=0x0,
)
)
)
tx = Transaction(
gas_limit=100_000,
protected=fork >= Byzantium,
sender=pre.fund_eoa(),
to=to,
)
post = {address: Account(storage={0x00: args_size})}
state_test(pre=pre, post=post, tx=tx)