@@ -47,6 +47,20 @@ tape('Version and license', function (t) {
47
47
} ) ;
48
48
49
49
tape ( 'Compilation' , function ( t ) {
50
+ t . test ( 'single files can be compiled' , function ( st ) {
51
+ if ( ! solc . supportsSingle ) {
52
+ st . skip ( 'Not supported by solc' ) ;
53
+ st . end ( ) ;
54
+ return ;
55
+ }
56
+ var output = solc . compile ( 'contract x { function g() public {} }' ) ;
57
+ st . ok ( 'contracts' in output ) ;
58
+ var bytecode = getBytecode ( output , '' , 'x' ) ;
59
+ st . ok ( bytecode ) ;
60
+ st . ok ( bytecode . length > 0 ) ;
61
+ st . end ( ) ;
62
+ } ) ;
63
+
50
64
t . test ( 'single files can be compiled (using lowlevel API)' , function ( st ) {
51
65
if ( typeof solc . lowlevel . compileSingle !== 'function' ) {
52
66
st . skip ( 'Low-level compileSingle interface not implemented by this compiler version.' ) ;
@@ -61,13 +75,13 @@ tape('Compilation', function (t) {
61
75
st . end ( ) ;
62
76
} ) ;
63
77
64
- t . test ( 'invalid source code fails properly (using lowlevel API) ' , function ( st ) {
65
- if ( typeof solc . lowlevel . compileSingle !== 'function' ) {
66
- st . skip ( 'Low-level compileSingle interface not implemented by this compiler version. ' ) ;
78
+ t . test ( 'invalid source code fails properly' , function ( st ) {
79
+ if ( ! solc . supportsSingle ) {
80
+ st . skip ( 'Not supported by solc ' ) ;
67
81
st . end ( ) ;
68
82
return ;
69
83
}
70
- var output = JSON . parse ( solc . lowlevel . compileSingle ( 'contract x { this is an invalid contract }' ) ) ;
84
+ var output = solc . compile ( 'contract x { this is an invalid contract }' ) ;
71
85
if ( semver . lt ( solc . semver ( ) , '0.1.4' ) ) {
72
86
st . ok ( output . error . indexOf ( 'Parser error: Expected identifier' ) !== - 1 ) ;
73
87
st . end ( ) ;
@@ -93,8 +107,34 @@ tape('Compilation', function (t) {
93
107
st . end ( ) ;
94
108
} ) ;
95
109
110
+ t . test ( 'multiple files can be compiled' , function ( st ) {
111
+ if ( semver . lt ( solc . semver ( ) , '0.1.6' ) ) {
112
+ st . skip ( 'Not supported by solc <0.1.6' ) ;
113
+ st . end ( ) ;
114
+ return ;
115
+ }
116
+
117
+ if ( ! solc . supportsMulti ) {
118
+ st . skip ( 'Not supported by solc' ) ;
119
+ st . end ( ) ;
120
+ return ;
121
+ }
122
+
123
+ var input = {
124
+ 'lib.sol' : 'library L { function f() public returns (uint) { return 7; } }' ,
125
+ 'cont.sol' : 'import "lib.sol"; contract x { function g() public { L.f(); } }'
126
+ } ;
127
+ var output = solc . compile ( { sources : input } ) ;
128
+ var x = getBytecode ( output , 'cont.sol' , 'x' ) ;
129
+ st . ok ( x ) ;
130
+ st . ok ( x . length > 0 ) ;
131
+ var L = getBytecode ( output , 'lib.sol' , 'L' ) ;
132
+ st . ok ( L ) ;
133
+ st . ok ( L . length > 0 ) ;
134
+ st . end ( ) ;
135
+ } ) ;
136
+
96
137
t . test ( 'multiple files can be compiled (using lowlevel API)' , function ( st ) {
97
- // Introduced in 0.1.6
98
138
if ( typeof solc . lowlevel . compileMulti !== 'function' ) {
99
139
st . skip ( 'Low-level compileMulti interface not implemented by this compiler version.' ) ;
100
140
st . end ( ) ;
@@ -115,8 +155,40 @@ tape('Compilation', function (t) {
115
155
st . end ( ) ;
116
156
} ) ;
117
157
158
+ t . test ( 'lazy-loading callback works' , function ( st ) {
159
+ if ( semver . lt ( solc . semver ( ) , '0.2.1' ) ) {
160
+ st . skip ( 'Not supported by solc <0.2.1' ) ;
161
+ st . end ( ) ;
162
+ return ;
163
+ }
164
+
165
+ if ( ! solc . supportsImportCallback ) {
166
+ st . skip ( 'Not supported by solc' ) ;
167
+ st . end ( ) ;
168
+ return ;
169
+ }
170
+
171
+ var input = {
172
+ 'cont.sol' : 'import "lib.sol"; contract x { function g() public { L.f(); } }'
173
+ } ;
174
+ function findImports ( path ) {
175
+ if ( path === 'lib.sol' ) {
176
+ return { contents : 'library L { function f() public returns (uint) { return 7; } }' } ;
177
+ } else {
178
+ return { error : 'File not found' } ;
179
+ }
180
+ }
181
+ var output = solc . compile ( { sources : input } , 0 , findImports ) ;
182
+ var x = getBytecode ( output , 'cont.sol' , 'x' ) ;
183
+ var L = getBytecode ( output , 'lib.sol' , 'L' ) ;
184
+ st . ok ( x ) ;
185
+ st . ok ( x . length > 0 ) ;
186
+ st . ok ( L ) ;
187
+ st . ok ( L . length > 0 ) ;
188
+ st . end ( ) ;
189
+ } ) ;
190
+
118
191
t . test ( 'lazy-loading callback works (using lowlevel API)' , function ( st ) {
119
- // Introduced in 0.2.1
120
192
if ( typeof solc . lowlevel . compileCallback !== 'function' ) {
121
193
st . skip ( 'Low-level compileCallback interface not implemented by this compiler version.' ) ;
122
194
st . end ( ) ;
@@ -143,10 +215,15 @@ tape('Compilation', function (t) {
143
215
st . end ( ) ;
144
216
} ) ;
145
217
146
- t . test ( 'lazy-loading callback works (with file not found) (using lowlevel API)' , function ( st ) {
147
- // Introduced in 0.2.1
148
- if ( typeof solc . lowlevel . compileCallback !== 'function' ) {
149
- st . skip ( 'Low-level compileCallback interface not implemented by this compiler version.' ) ;
218
+ t . test ( 'lazy-loading callback works (with file not found)' , function ( st ) {
219
+ if ( semver . lt ( solc . semver ( ) , '0.2.1' ) ) {
220
+ st . skip ( 'Not supported by solc <0.2.1' ) ;
221
+ st . end ( ) ;
222
+ return ;
223
+ }
224
+
225
+ if ( ! solc . supportsImportCallback ) {
226
+ st . skip ( 'Not supported by solc' ) ;
150
227
st . end ( ) ;
151
228
return ;
152
229
}
@@ -157,7 +234,7 @@ tape('Compilation', function (t) {
157
234
function findImports ( path ) {
158
235
return { error : 'File not found' } ;
159
236
}
160
- var output = JSON . parse ( solc . lowlevel . compileCallback ( JSON . stringify ( { sources : input } ) , 0 , findImports ) ) ;
237
+ var output = solc . compile ( { sources : input } , 0 , findImports ) ;
161
238
st . plan ( 3 ) ;
162
239
st . ok ( 'errors' in output ) ;
163
240
// Check if the ParserError exists, but allow others too
@@ -173,10 +250,15 @@ tape('Compilation', function (t) {
173
250
st . end ( ) ;
174
251
} ) ;
175
252
176
- t . test ( 'lazy-loading callback works (with exception) (using lowlevel API)' , function ( st ) {
177
- // Introduced in 0.2.1
178
- if ( typeof solc . lowlevel . compileCallback !== 'function' ) {
179
- st . skip ( 'Low-level compileCallback interface not implemented by this compiler version.' ) ;
253
+ t . test ( 'lazy-loading callback works (with exception)' , function ( st ) {
254
+ if ( semver . lt ( solc . semver ( ) , '0.2.1' ) ) {
255
+ st . skip ( 'Not supported by solc <0.2.1' ) ;
256
+ st . end ( ) ;
257
+ return ;
258
+ }
259
+
260
+ if ( ! solc . supportsImportCallback ) {
261
+ st . skip ( 'Not supported by solc' ) ;
180
262
st . end ( ) ;
181
263
return ;
182
264
}
@@ -188,15 +270,20 @@ tape('Compilation', function (t) {
188
270
throw new Error ( 'Could not implement this interface properly...' ) ;
189
271
}
190
272
st . throws ( function ( ) {
191
- solc . compileStandardWrapper ( JSON . stringify ( { sources : input } ) , 0 , findImports ) ;
273
+ solc . compile ( { sources : input } , 0 , findImports ) ;
192
274
} , / ^ E r r o r : C o u l d n o t i m p l e m e n t t h i s i n t e r f a c e p r o p e r l y .../ ) ;
193
275
st . end ( ) ;
194
276
} ) ;
195
277
196
278
t . test ( 'lazy-loading callback fails properly (with invalid callback)' , function ( st ) {
197
- // Introduced in 0.2.1
198
- if ( typeof solc . lowlevel . compileCallback !== 'function' ) {
199
- st . skip ( 'Low-level compileCallback interface not implemented by this compiler version.' ) ;
279
+ if ( semver . lt ( solc . semver ( ) , '0.2.1' ) ) {
280
+ st . skip ( 'Not supported by solc <0.2.1' ) ;
281
+ st . end ( ) ;
282
+ return ;
283
+ }
284
+
285
+ if ( ! solc . supportsImportCallback ) {
286
+ st . skip ( 'Not supported by solc' ) ;
200
287
st . end ( ) ;
201
288
return ;
202
289
}
@@ -205,7 +292,7 @@ tape('Compilation', function (t) {
205
292
'cont.sol' : 'import "lib.sol"; contract x { function g() public { L.f(); } }'
206
293
} ;
207
294
st . throws ( function ( ) {
208
- solc . compileStandardWrapper ( JSON . stringify ( { sources : input } ) , 0 , "this isn't a callback" ) ;
295
+ solc . compile ( { sources : input } , 0 , "this isn't a callback" ) ;
209
296
} , / I n v a l i d c a l l b a c k s p e c i f i e d ./ ) ;
210
297
st . end ( ) ;
211
298
} ) ;
@@ -226,7 +313,7 @@ tape('Compilation', function (t) {
226
313
var input = {
227
314
'cont.sol' : 'import "lib.sol"; contract x { function g() public { L.f(); } }'
228
315
} ;
229
- var output = JSON . parse ( solc . compileStandard ( { sources : input } , 0 ) ) ;
316
+ var output = solc . compile ( { sources : input } , 0 ) ;
230
317
st . plan ( 3 ) ;
231
318
st . ok ( 'errors' in output ) ;
232
319
// Check if the ParserError exists, but allow others too
@@ -499,7 +586,6 @@ tape('Loading Legacy Versions', function (t) {
499
586
return ;
500
587
}
501
588
if ( ! solcSnapshot . supportsSingle ) {
502
- st . plan ( 1 ) ;
503
589
st . skip ( 'Not supported by solc' ) ;
504
590
st . end ( ) ;
505
591
return ;
0 commit comments