@@ -47,20 +47,6 @@ 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
-
64
50
t . test ( 'single files can be compiled (using lowlevel API)' , function ( st ) {
65
51
if ( typeof solc . lowlevel . compileSingle !== 'function' ) {
66
52
st . skip ( 'Low-level compileSingle interface not implemented by this compiler version.' ) ;
@@ -75,13 +61,13 @@ tape('Compilation', function (t) {
75
61
st . end ( ) ;
76
62
} ) ;
77
63
78
- t . test ( 'invalid source code fails properly' , function ( st ) {
79
- if ( ! solc . supportsSingle ) {
80
- st . skip ( 'Not supported by solc ' ) ;
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. ' ) ;
81
67
st . end ( ) ;
82
68
return ;
83
69
}
84
- var output = solc . compile ( 'contract x { this is an invalid contract }' ) ;
70
+ var output = JSON . parse ( solc . lowlevel . compileSingle ( 'contract x { this is an invalid contract }' ) ) ;
85
71
if ( semver . lt ( solc . semver ( ) , '0.1.4' ) ) {
86
72
st . ok ( output . error . indexOf ( 'Parser error: Expected identifier' ) !== - 1 ) ;
87
73
st . end ( ) ;
@@ -107,34 +93,8 @@ tape('Compilation', function (t) {
107
93
st . end ( ) ;
108
94
} ) ;
109
95
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
-
137
96
t . test ( 'multiple files can be compiled (using lowlevel API)' , function ( st ) {
97
+ // Introduced in 0.1.6
138
98
if ( typeof solc . lowlevel . compileMulti !== 'function' ) {
139
99
st . skip ( 'Low-level compileMulti interface not implemented by this compiler version.' ) ;
140
100
st . end ( ) ;
@@ -155,40 +115,8 @@ tape('Compilation', function (t) {
155
115
st . end ( ) ;
156
116
} ) ;
157
117
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
-
191
118
t . test ( 'lazy-loading callback works (using lowlevel API)' , function ( st ) {
119
+ // Introduced in 0.2.1
192
120
if ( typeof solc . lowlevel . compileCallback !== 'function' ) {
193
121
st . skip ( 'Low-level compileCallback interface not implemented by this compiler version.' ) ;
194
122
st . end ( ) ;
@@ -215,15 +143,10 @@ tape('Compilation', function (t) {
215
143
st . end ( ) ;
216
144
} ) ;
217
145
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' ) ;
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.' ) ;
227
150
st . end ( ) ;
228
151
return ;
229
152
}
@@ -234,7 +157,7 @@ tape('Compilation', function (t) {
234
157
function findImports ( path ) {
235
158
return { error : 'File not found' } ;
236
159
}
237
- var output = solc . compile ( { sources : input } , 0 , findImports ) ;
160
+ var output = JSON . parse ( solc . lowlevel . compileCallback ( JSON . stringify ( { sources : input } ) , 0 , findImports ) ) ;
238
161
st . plan ( 3 ) ;
239
162
st . ok ( 'errors' in output ) ;
240
163
// Check if the ParserError exists, but allow others too
@@ -250,15 +173,10 @@ tape('Compilation', function (t) {
250
173
st . end ( ) ;
251
174
} ) ;
252
175
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' ) ;
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.' ) ;
262
180
st . end ( ) ;
263
181
return ;
264
182
}
@@ -270,20 +188,15 @@ tape('Compilation', function (t) {
270
188
throw new Error ( 'Could not implement this interface properly...' ) ;
271
189
}
272
190
st . throws ( function ( ) {
273
- solc . compile ( { sources : input } , 0 , findImports ) ;
191
+ solc . compileStandardWrapper ( JSON . stringify ( { sources : input } ) , 0 , findImports ) ;
274
192
} , / ^ 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 .../ ) ;
275
193
st . end ( ) ;
276
194
} ) ;
277
195
278
196
t . test ( 'lazy-loading callback fails properly (with invalid callback)' , function ( st ) {
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' ) ;
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.' ) ;
287
200
st . end ( ) ;
288
201
return ;
289
202
}
@@ -292,7 +205,7 @@ tape('Compilation', function (t) {
292
205
'cont.sol' : 'import "lib.sol"; contract x { function g() public { L.f(); } }'
293
206
} ;
294
207
st . throws ( function ( ) {
295
- solc . compile ( { sources : input } , 0 , "this isn't a callback" ) ;
208
+ solc . compileStandardWrapper ( JSON . stringify ( { sources : input } ) , 0 , "this isn't a callback" ) ;
296
209
} , / I n v a l i d c a l l b a c k s p e c i f i e d ./ ) ;
297
210
st . end ( ) ;
298
211
} ) ;
@@ -313,7 +226,7 @@ tape('Compilation', function (t) {
313
226
var input = {
314
227
'cont.sol' : 'import "lib.sol"; contract x { function g() public { L.f(); } }'
315
228
} ;
316
- var output = solc . compile ( { sources : input } , 0 ) ;
229
+ var output = JSON . parse ( solc . compileStandard ( { sources : input } , 0 ) ) ;
317
230
st . plan ( 3 ) ;
318
231
st . ok ( 'errors' in output ) ;
319
232
// Check if the ParserError exists, but allow others too
@@ -586,6 +499,7 @@ tape('Loading Legacy Versions', function (t) {
586
499
return ;
587
500
}
588
501
if ( ! solcSnapshot . supportsSingle ) {
502
+ st . plan ( 1 ) ;
589
503
st . skip ( 'Not supported by solc' ) ;
590
504
st . end ( ) ;
591
505
return ;
0 commit comments