1
1
from ethereum import tester
2
- import pytest
3
2
serpent_contract = """
4
3
extern solidity: [sub2:_:i]
5
4
@@ -14,7 +13,7 @@ def sub1():
14
13
solidity_contract = """
15
14
contract serpent { function sub1() returns (int256 y) {} }
16
15
17
- contract foo {
16
+ contract zoo {
18
17
function main(address a) returns (int256 y) {
19
18
y = serpent(a).sub1() * 2;
20
19
}
@@ -26,69 +25,11 @@ def sub1():
26
25
"""
27
26
28
27
29
- @pytest .mark .xfail # pysol is currently broken
30
28
def test_interop ():
31
29
s = tester .state ()
32
30
c1 = s .abi_contract (serpent_contract )
33
- c2 = s .abi_contract (solidity_contract , language = 'solidity' )
34
- # assert c1.sub1() == 5
35
- # assert c2.sub2() == 7
36
- # assert c1.main(c2.address) == 14
37
- # assert c2.main(c1.address) == 10
38
-
39
-
40
- if __name__ == '__main__' :
41
-
42
- import subprocess
43
-
44
- one_solidity_contract = """
45
-
46
- contract foo {
47
- function main(address a) returns (address b) {
48
- b = a;
49
- return b;
50
- }
51
- function sub2() returns (int256 y) {
52
- y = 7;
53
- }
54
- }
55
-
56
- """
57
-
58
- class CompileError (Exception ):
59
- pass
60
-
61
- class solc_wrapper (object ):
62
-
63
- @classmethod
64
- def compile (cls , code ):
65
- p = subprocess .Popen (['solc' , '--binary' , 'stdout' ],
66
- stdin = subprocess .PIPE , stdout = subprocess .PIPE )
67
- stdoutdata , stderrdata = p .communicate (input = code )
68
- if p .returncode :
69
- raise CompileError ('compilation failed' )
70
-
71
- hex_code = stdoutdata .rsplit ('Binary: \n ' )[- 1 ].strip ()
72
- return hex_code .decode ('hex' )
73
-
74
- @classmethod
75
- def mk_full_signature (cls , code ):
76
- p = subprocess .Popen (['solc' , '--json-abi' , 'stdout' ],
77
- stdin = subprocess .PIPE , stdout = subprocess .PIPE )
78
- stdoutdata , stderrdata = p .communicate (input = code )
79
- if p .returncode :
80
- raise CompileError ('compilation failed' )
81
- jsonabi = stdoutdata .rsplit ('Contract JSON ABI\n ' )[- 1 ].strip ()
82
- return jsonabi
83
-
84
- tester .languages ['solidity' ] = solc_wrapper
85
-
86
- bytecode = solc_wrapper .compile (one_solidity_contract )
87
- jsonabi = solc_wrapper .mk_full_signature (one_solidity_contract )
88
-
89
- # test
90
- s = tester .state ()
91
- c2 = s .abi_contract (one_solidity_contract , language = 'solidity' )
92
- a = '\0 ' * 20
93
- assert c2 .main (a ).decode ('hex' ) == a
31
+ c2 = s .abi_contract (solidity_contract , language = 'solidity' ) # should be zoo
32
+ assert c1 .sub1 () == 5
94
33
assert c2 .sub2 () == 7
34
+ assert c1 .main (c2 .address ) == 14
35
+ assert c2 .main (c1 .address ) == 10
0 commit comments