5
5
6
6
from ethereum .utils import encode_hex
7
7
8
- from ethereum import tester
8
+ from ethereum . tools import tester
9
9
from ethereum import utils
10
- from ethereum import _solidity
11
- from ethereum ._solidity import get_solidity
10
+ import ethereum .config as config
11
+ from ethereum .tools import _solidity
12
+ from ethereum .tools ._solidity import get_solidity
12
13
13
14
SOLIDITY_AVAILABLE = get_solidity () is not None
14
15
CONTRACTS_DIR = path .join (path .dirname (__file__ ), 'contracts' )
15
16
17
+ skip_if_no_solidity = pytest .mark .skipif (
18
+ not SOLIDITY_AVAILABLE ,
19
+ reason = 'solc compiler not available' )
16
20
17
21
def bytecode_is_generated (cinfo , cname ):
18
22
return 'code' in cinfo [cname ] and len (cinfo [cname ]['code' ]) > 10
19
23
20
24
21
- @pytest .mark .skipif (not SOLIDITY_AVAILABLE ,
22
- reason = 'solc compiler not available' )
23
- def test_library_from_file ():
24
- state = tester .state ()
25
- state .env .config ['HOMESTEAD_FORK_BLKNUM' ] = 0 # enable CALLCODE opcode
26
-
27
- library = state .abi_contract (
28
- None ,
29
- path = path .join (CONTRACTS_DIR , 'seven_library.sol' ),
30
- language = 'solidity' ,
31
- )
32
-
33
- libraries = {
34
- 'SevenLibrary' : encode_hex (library .address ),
35
- }
36
- contract = state .abi_contract (
37
- None ,
38
- path = path .join (CONTRACTS_DIR , 'seven_contract.sol' ),
39
- libraries = libraries ,
40
- language = 'solidity' ,
41
- )
42
-
43
- # pylint: disable=no-member
44
- assert library .seven () == 7
45
- assert contract .test () == 7
46
-
47
-
48
- @pytest .mark .skipif (not SOLIDITY_AVAILABLE ,
49
- reason = 'solc compiler not available' )
25
+ @skip_if_no_solidity
50
26
def test_library_from_code ():
51
27
with open (path .join (CONTRACTS_DIR , 'seven_library.sol' )) as handler :
52
28
library_code = handler .read ()
53
29
54
30
with open (path .join (CONTRACTS_DIR , 'seven_contract_without_import.sol' )) as handler :
55
31
contract_code = handler .read ()
56
32
57
- state = tester .state ()
58
- state .env .config ['HOMESTEAD_FORK_BLKNUM' ] = 0 # enable CALLCODE opcode
33
+ state = tester .Chain ()
34
+ env = config .Env ()
35
+ env .config ['HOMESTEAD_FORK_BLKNUM' ] = 0 # enable CALLCODE opcode
59
36
60
- library = state .abi_contract (
61
- library_code ,
62
- path = None ,
37
+ library = state .contract (
38
+ sourcecode = library_code ,
63
39
language = 'solidity' ,
64
40
)
65
41
66
42
libraries = {
67
43
'SevenLibrary' : encode_hex (library .address ),
68
44
}
69
- contract = state .abi_contract (
70
- contract_code ,
71
- path = None ,
45
+ contract = state .contract (
46
+ sourcecode = contract_code ,
72
47
libraries = libraries ,
73
48
language = 'solidity' ,
74
49
)
75
50
76
51
# pylint: disable=no-member
77
- assert library .seven () == 7
78
52
assert contract .test () == 7
79
53
80
54
@@ -129,17 +103,16 @@ def test_symbols():
129
103
) == 'beef1111111111111111111111111111111111111111cafe'
130
104
131
105
132
- @pytest .mark .skipif (not SOLIDITY_AVAILABLE ,
133
- reason = 'solc compiler not available' )
106
+ @skip_if_no_solidity
134
107
def test_interop ():
135
108
serpent_contract = """
136
- extern solidity: [sub2:[]:i]
109
+ extern solidity: [sub2:[]:i]
137
110
138
- def main(a):
139
- return(a.sub2() * 2)
111
+ def main(a):
112
+ return(a.sub2() * 2)
140
113
141
- def sub1():
142
- return(5)
114
+ def sub1():
115
+ return(5)
143
116
"""
144
117
145
118
solidity_contract = """
@@ -158,9 +131,13 @@ def sub1():
158
131
}
159
132
"""
160
133
161
- state = tester .state ()
162
- serpent_abi = state .abi_contract (serpent_contract )
163
- solidity_abi = state .abi_contract (
134
+ state = tester .Chain ()
135
+
136
+ serpent_abi = state .contract (
137
+ serpent_contract ,
138
+ language = 'serpent' )
139
+
140
+ solidity_abi = state .contract (
164
141
solidity_contract ,
165
142
language = 'solidity' ) # should be zoo
166
143
solidity_address = utils .encode_hex (solidity_abi .address )
@@ -171,12 +148,11 @@ def sub1():
171
148
172
149
assert solidity_abi .sub2 () == 7
173
150
assert solidity_abi .sub3 (utils .encode_hex (
174
- solidity_abi .address )) == solidity_address
151
+ solidity_abi .address )) == '0x' + solidity_address
175
152
assert solidity_abi .main (serpent_abi .address ) == 10
176
153
177
154
178
- @pytest .mark .skipif (not SOLIDITY_AVAILABLE ,
179
- reason = 'solc compiler not available' )
155
+ @skip_if_no_solidity
180
156
def test_constructor ():
181
157
constructor_contract = """
182
158
contract testme {
@@ -190,19 +166,19 @@ def test_constructor():
190
166
}
191
167
"""
192
168
193
- state = tester .state ()
194
- contract = state .abi_contract (
169
+ state = tester .Chain ()
170
+
171
+ contract = state .contract (
195
172
constructor_contract ,
196
173
language = 'solidity' ,
197
- constructor_parameters = (2 , ),
174
+ args = (2 , ),
198
175
)
199
176
200
177
# pylint: disable=no-member
201
178
assert contract .getValue () == 2
202
179
203
180
204
- @pytest .mark .skipif (not SOLIDITY_AVAILABLE ,
205
- reason = 'solc compiler not available' )
181
+ @skip_if_no_solidity
206
182
def test_solidity_compile_rich ():
207
183
compile_rich_contract = """
208
184
contract contract_add {
@@ -239,8 +215,7 @@ def test_solidity_compile_rich():
239
215
} == {'subtract7' , 'subtract42' }
240
216
241
217
242
- @pytest .mark .skipif (not SOLIDITY_AVAILABLE ,
243
- reason = 'solc compiler not available' )
218
+ @skip_if_no_solidity
244
219
def test_abi_contract ():
245
220
one_contract = """
246
221
contract foo {
@@ -253,17 +228,16 @@ def test_abi_contract():
253
228
}
254
229
"""
255
230
256
- state = tester .state ()
257
- contract = state .abi_contract (one_contract , language = 'solidity' )
231
+ state = tester .Chain ()
232
+ contract = state .contract (one_contract , language = 'solidity' )
258
233
259
234
# pylint: disable=no-member
260
235
assert contract .seven () == 7
261
236
assert contract .mul2 (2 ) == 4
262
237
assert contract .mul2 (- 2 ) == - 4
263
238
264
239
265
- @pytest .mark .skipif (not SOLIDITY_AVAILABLE ,
266
- reason = 'solc compiler not available' )
240
+ @skip_if_no_solidity
267
241
def test_extra_args ():
268
242
src = """
269
243
contract foo {
0 commit comments