55
66from ethereum .utils import encode_hex
77
8- from ethereum import tester
8+ from ethereum . tools import tester
99from 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
1213
1314SOLIDITY_AVAILABLE = get_solidity () is not None
1415CONTRACTS_DIR = path .join (path .dirname (__file__ ), 'contracts' )
1516
17+ skip_if_no_solidity = pytest .mark .skipif (
18+ not SOLIDITY_AVAILABLE ,
19+ reason = 'solc compiler not available' )
1620
1721def bytecode_is_generated (cinfo , cname ):
1822 return 'code' in cinfo [cname ] and len (cinfo [cname ]['code' ]) > 10
1923
2024
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
5026def test_library_from_code ():
5127 with open (path .join (CONTRACTS_DIR , 'seven_library.sol' )) as handler :
5228 library_code = handler .read ()
5329
5430 with open (path .join (CONTRACTS_DIR , 'seven_contract_without_import.sol' )) as handler :
5531 contract_code = handler .read ()
5632
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
5936
60- library = state .abi_contract (
61- library_code ,
62- path = None ,
37+ library = state .contract (
38+ sourcecode = library_code ,
6339 language = 'solidity' ,
6440 )
6541
6642 libraries = {
6743 'SevenLibrary' : encode_hex (library .address ),
6844 }
69- contract = state .abi_contract (
70- contract_code ,
71- path = None ,
45+ contract = state .contract (
46+ sourcecode = contract_code ,
7247 libraries = libraries ,
7348 language = 'solidity' ,
7449 )
7550
7651 # pylint: disable=no-member
77- assert library .seven () == 7
7852 assert contract .test () == 7
7953
8054
@@ -129,17 +103,16 @@ def test_symbols():
129103 ) == 'beef1111111111111111111111111111111111111111cafe'
130104
131105
132- @pytest .mark .skipif (not SOLIDITY_AVAILABLE ,
133- reason = 'solc compiler not available' )
106+ @skip_if_no_solidity
134107def test_interop ():
135108 serpent_contract = """
136- extern solidity: [sub2:[]:i]
109+ extern solidity: [sub2:[]:i]
137110
138- def main(a):
139- return(a.sub2() * 2)
111+ def main(a):
112+ return(a.sub2() * 2)
140113
141- def sub1():
142- return(5)
114+ def sub1():
115+ return(5)
143116 """
144117
145118 solidity_contract = """
@@ -158,9 +131,13 @@ def sub1():
158131 }
159132 """
160133
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 (
164141 solidity_contract ,
165142 language = 'solidity' ) # should be zoo
166143 solidity_address = utils .encode_hex (solidity_abi .address )
@@ -171,12 +148,11 @@ def sub1():
171148
172149 assert solidity_abi .sub2 () == 7
173150 assert solidity_abi .sub3 (utils .encode_hex (
174- solidity_abi .address )) == solidity_address
151+ solidity_abi .address )) == '0x' + solidity_address
175152 assert solidity_abi .main (serpent_abi .address ) == 10
176153
177154
178- @pytest .mark .skipif (not SOLIDITY_AVAILABLE ,
179- reason = 'solc compiler not available' )
155+ @skip_if_no_solidity
180156def test_constructor ():
181157 constructor_contract = """
182158 contract testme {
@@ -190,19 +166,19 @@ def test_constructor():
190166 }
191167 """
192168
193- state = tester .state ()
194- contract = state .abi_contract (
169+ state = tester .Chain ()
170+
171+ contract = state .contract (
195172 constructor_contract ,
196173 language = 'solidity' ,
197- constructor_parameters = (2 , ),
174+ args = (2 , ),
198175 )
199176
200177 # pylint: disable=no-member
201178 assert contract .getValue () == 2
202179
203180
204- @pytest .mark .skipif (not SOLIDITY_AVAILABLE ,
205- reason = 'solc compiler not available' )
181+ @skip_if_no_solidity
206182def test_solidity_compile_rich ():
207183 compile_rich_contract = """
208184 contract contract_add {
@@ -239,8 +215,7 @@ def test_solidity_compile_rich():
239215 } == {'subtract7' , 'subtract42' }
240216
241217
242- @pytest .mark .skipif (not SOLIDITY_AVAILABLE ,
243- reason = 'solc compiler not available' )
218+ @skip_if_no_solidity
244219def test_abi_contract ():
245220 one_contract = """
246221 contract foo {
@@ -253,17 +228,16 @@ def test_abi_contract():
253228 }
254229 """
255230
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' )
258233
259234 # pylint: disable=no-member
260235 assert contract .seven () == 7
261236 assert contract .mul2 (2 ) == 4
262237 assert contract .mul2 (- 2 ) == - 4
263238
264239
265- @pytest .mark .skipif (not SOLIDITY_AVAILABLE ,
266- reason = 'solc compiler not available' )
240+ @skip_if_no_solidity
267241def test_extra_args ():
268242 src = """
269243 contract foo {
0 commit comments