@@ -35,3 +35,60 @@ def test_interop():
35
35
# assert c2.sub2() == 7
36
36
# assert c1.main(c2.address) == 14
37
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
94
+ assert c2 .sub2 () == 7
0 commit comments