Skip to content

Commit 94c781b

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

File tree

3 files changed

+92
-1
lines changed

3 files changed

+92
-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,86 @@
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.transaction_context import (
17+
BaseTransactionContext,
18+
)
19+
20+
CANONICAL_ADDRESS_A = to_canonical_address("0x0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6")
21+
CANONICAL_ADDRESS_B = to_canonical_address("0xcd1722f3947def4cf144679da39c4c32bdc35681")
22+
23+
24+
def contract_code_json():
25+
filepath = os.path.join(os.path.dirname(__file__),
26+
'fixtures/spurious_dragon_computation_test_code_size_limitation.json')
27+
with open(filepath) as f:
28+
return json.load(f)
29+
30+
31+
@pytest.fixture
32+
def state(chain_with_block_validation):
33+
state = chain_with_block_validation.get_vm().state
34+
state.set_balance(CANONICAL_ADDRESS_A, 1000)
35+
return state
36+
37+
38+
@pytest.fixture
39+
def transaction_context():
40+
tx_context = BaseTransactionContext(
41+
gas_price=0,
42+
origin=CANONICAL_ADDRESS_A,
43+
)
44+
return tx_context
45+
46+
47+
def _create_message(code):
48+
message = Message(
49+
to=CANONICAL_ADDRESS_B,
50+
sender=CANONICAL_ADDRESS_A,
51+
value=0,
52+
data=b'',
53+
code=code,
54+
gas=5000000,
55+
)
56+
return message
57+
58+
59+
@pytest.mark.parametrize(
60+
'message, expected',
61+
(
62+
(
63+
# CODE_SIZE == 24575
64+
_create_message(decode_hex(contract_code_json()['code_1'])),
65+
False,
66+
),
67+
(
68+
# CODE_SIZE == 24576
69+
_create_message(decode_hex(contract_code_json()['code_2'])),
70+
True,
71+
),
72+
(
73+
# CODE_SIZE == 24577
74+
_create_message(decode_hex(contract_code_json()['code_3'])),
75+
True,
76+
),
77+
),
78+
)
79+
def test_code_size_limit_eip_170(state, message, transaction_context, expected):
80+
computation = SpuriousDragonComputation(
81+
state=state,
82+
message=message,
83+
transaction_context=transaction_context,
84+
)
85+
assert computation.apply_create_message(
86+
state, message, transaction_context).is_error == expected

0 commit comments

Comments
 (0)