Skip to content

Commit d1492f0

Browse files
committed
py-evm-issue-1466: Added test cases for EIP170
1 parent 1af151a commit d1492f0

File tree

3 files changed

+99
-1
lines changed

3 files changed

+99
-1
lines changed

eth/vm/forks/spurious_dragon/constants.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@
1010

1111

1212
# https://github.com/ethereum/EIPs/issues/170
13-
EIP170_CODE_SIZE_LIMIT = 24577
13+
EIP170_CODE_SIZE_LIMIT = 24576 # 2**14 + 2**13

tests/core/vm/fixtures/spurious_dragon_computation_test_code_size_limitation.json

+5
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
import json
2+
import os
3+
import pytest
4+
5+
from eth_utils import (
6+
to_canonical_address,
7+
decode_hex,
8+
)
9+
10+
from eth.vm.message import (
11+
Message,
12+
)
13+
from eth.vm.forks.spurious_dragon.computation import (
14+
SpuriousDragonComputation,
15+
)
16+
from eth.vm.forks.spurious_dragon.constants import (
17+
EIP170_CODE_SIZE_LIMIT,
18+
)
19+
from eth.vm.transaction_context import (
20+
BaseTransactionContext,
21+
)
22+
23+
CANONICAL_ADDRESS_A = to_canonical_address("0x0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6")
24+
CANONICAL_ADDRESS_B = to_canonical_address("0xcd1722f3947def4cf144679da39c4c32bdc35681")
25+
26+
27+
def contract_code_json():
28+
filepath = os.path.join(os.path.dirname(__file__),
29+
'fixtures/spurious_dragon_computation_test_code_size_limitation.json')
30+
with open(filepath) as f:
31+
return json.load(f)
32+
33+
34+
@pytest.fixture
35+
def state(chain_with_block_validation):
36+
state = chain_with_block_validation.get_vm().state
37+
state.set_balance(CANONICAL_ADDRESS_A, 1000)
38+
return state
39+
40+
41+
@pytest.fixture
42+
def transaction_context():
43+
tx_context = BaseTransactionContext(
44+
gas_price=0,
45+
origin=CANONICAL_ADDRESS_A,
46+
)
47+
return tx_context
48+
49+
50+
def _create_message(code):
51+
message = Message(
52+
to=CANONICAL_ADDRESS_B,
53+
sender=CANONICAL_ADDRESS_A,
54+
value=0,
55+
data=b'',
56+
code=code,
57+
gas=5000000,
58+
)
59+
return message
60+
61+
62+
@pytest.mark.parametrize(
63+
'message, code_size, is_error',
64+
(
65+
(
66+
# CODE_SIZE == 24575
67+
_create_message(decode_hex(contract_code_json()['code_1'])),
68+
EIP170_CODE_SIZE_LIMIT - 1,
69+
False,
70+
),
71+
(
72+
# CODE_SIZE == 24576
73+
_create_message(decode_hex(contract_code_json()['code_2'])),
74+
0,
75+
True,
76+
),
77+
(
78+
# CODE_SIZE == 24577
79+
_create_message(decode_hex(contract_code_json()['code_3'])),
80+
0,
81+
True,
82+
)
83+
)
84+
)
85+
def test_code_size_limit_eip_170(state, message, transaction_context, code_size, is_error):
86+
computation = SpuriousDragonComputation(
87+
state=state,
88+
message=message,
89+
transaction_context=transaction_context,
90+
).apply_create_message(state, message, transaction_context)
91+
92+
assert len(computation.output) == code_size
93+
assert computation.is_error == is_error

0 commit comments

Comments
 (0)