@@ -47,21 +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 . features . legacySingleInput ) {
52
- st . skip ( 'Not supported by solc' ) ;
53
- st . end ( ) ;
54
- return ;
55
- }
56
-
57
- var output = solc . compile ( 'contract x { function g() public {} }' ) ;
58
- st . ok ( 'contracts' in output ) ;
59
- var bytecode = getBytecode ( output , '' , 'x' ) ;
60
- st . ok ( bytecode ) ;
61
- st . ok ( bytecode . length > 0 ) ;
62
- st . end ( ) ;
63
- } ) ;
64
-
65
50
t . test ( 'single files can be compiled (using lowlevel API)' , function ( st ) {
66
51
if ( typeof solc . lowlevel . compileSingle !== 'function' ) {
67
52
st . skip ( 'Low-level compileSingle interface not implemented by this compiler version.' ) ;
@@ -77,14 +62,14 @@ tape('Compilation', function (t) {
77
62
st . end ( ) ;
78
63
} ) ;
79
64
80
- t . test ( 'invalid source code fails properly' , function ( st ) {
81
- if ( ! solc . features . legacySingleInput ) {
82
- st . skip ( 'Not supported by solc ' ) ;
65
+ t . test ( 'invalid source code fails properly (using lowlevel API) ' , function ( st ) {
66
+ if ( typeof solc . lowlevel . compileSingle !== 'function' ) {
67
+ st . skip ( 'Low-level compileSingle interface not implemented by this compiler version. ' ) ;
83
68
st . end ( ) ;
84
69
return ;
85
70
}
86
71
87
- var output = solc . compile ( 'contract x { this is an invalid contract }' ) ;
72
+ var output = JSON . parse ( solc . lowlevel . compileSingle ( 'contract x { this is an invalid contract }' ) ) ;
88
73
if ( semver . lt ( solc . semver ( ) , '0.1.4' ) ) {
89
74
st . ok ( output . error . indexOf ( 'Parser error: Expected identifier' ) !== - 1 ) ;
90
75
st . end ( ) ;
@@ -110,29 +95,8 @@ tape('Compilation', function (t) {
110
95
st . end ( ) ;
111
96
} ) ;
112
97
113
- t . test ( 'multiple files can be compiled' , function ( st ) {
114
- // <0.1.6 doesn't have this
115
- if ( ! solc . features . multipleInputs ) {
116
- st . skip ( 'Not supported by solc' ) ;
117
- st . end ( ) ;
118
- return ;
119
- }
120
-
121
- var input = {
122
- 'lib.sol' : 'library L { function f() public returns (uint) { return 7; } }' ,
123
- 'cont.sol' : 'import "lib.sol"; contract x { function g() public { L.f(); } }'
124
- } ;
125
- var output = solc . compile ( { sources : input } ) ;
126
- var x = getBytecode ( output , 'cont.sol' , 'x' ) ;
127
- st . ok ( x ) ;
128
- st . ok ( x . length > 0 ) ;
129
- var L = getBytecode ( output , 'lib.sol' , 'L' ) ;
130
- st . ok ( L ) ;
131
- st . ok ( L . length > 0 ) ;
132
- st . end ( ) ;
133
- } ) ;
134
-
135
98
t . test ( 'multiple files can be compiled (using lowlevel API)' , function ( st ) {
99
+ // Introduced in 0.1.6
136
100
if ( typeof solc . lowlevel . compileMulti !== 'function' ) {
137
101
st . skip ( 'Low-level compileMulti interface not implemented by this compiler version.' ) ;
138
102
st . end ( ) ;
@@ -153,35 +117,8 @@ tape('Compilation', function (t) {
153
117
st . end ( ) ;
154
118
} ) ;
155
119
156
- t . test ( 'lazy-loading callback works' , function ( st ) {
157
- // <0.2.1 doesn't have this
158
- if ( ! solc . features . importCallback ) {
159
- st . skip ( 'Not supported by solc' ) ;
160
- st . end ( ) ;
161
- return ;
162
- }
163
-
164
- var input = {
165
- 'cont.sol' : 'import "lib.sol"; contract x { function g() public { L.f(); } }'
166
- } ;
167
- function findImports ( path ) {
168
- if ( path === 'lib.sol' ) {
169
- return { contents : 'library L { function f() public returns (uint) { return 7; } }' } ;
170
- } else {
171
- return { error : 'File not found' } ;
172
- }
173
- }
174
- var output = solc . compile ( { sources : input } , 0 , findImports ) ;
175
- var x = getBytecode ( output , 'cont.sol' , 'x' ) ;
176
- var L = getBytecode ( output , 'lib.sol' , 'L' ) ;
177
- st . ok ( x ) ;
178
- st . ok ( x . length > 0 ) ;
179
- st . ok ( L ) ;
180
- st . ok ( L . length > 0 ) ;
181
- st . end ( ) ;
182
- } ) ;
183
-
184
120
t . test ( 'lazy-loading callback works (using lowlevel API)' , function ( st ) {
121
+ // Introduced in 0.2.1
185
122
if ( typeof solc . lowlevel . compileCallback !== 'function' ) {
186
123
st . skip ( 'Low-level compileCallback interface not implemented by this compiler version.' ) ;
187
124
st . end ( ) ;
@@ -208,10 +145,10 @@ tape('Compilation', function (t) {
208
145
st . end ( ) ;
209
146
} ) ;
210
147
211
- t . test ( 'lazy-loading callback works (with file not found)' , function ( st ) {
148
+ t . test ( 'lazy-loading callback works (with file not found) (using lowlevel API) ' , function ( st ) {
212
149
// <0.2.1 doesn't have this
213
- if ( ! solc . features . importCallback ) {
214
- st . skip ( 'Not supported by solc ' ) ;
150
+ if ( typeof solc . lowlevel . compileCallback !== 'function' ) {
151
+ st . skip ( 'Low-level compileCallback interface not implemented by this compiler version. ' ) ;
215
152
st . end ( ) ;
216
153
return ;
217
154
}
@@ -222,7 +159,7 @@ tape('Compilation', function (t) {
222
159
function findImports ( path ) {
223
160
return { error : 'File not found' } ;
224
161
}
225
- var output = solc . compile ( { sources : input } , 0 , findImports ) ;
162
+ var output = JSON . parse ( solc . lowlevel . compileCallback ( JSON . stringify ( { sources : input } ) , 0 , findImports ) ) ;
226
163
st . plan ( 3 ) ;
227
164
st . ok ( 'errors' in output ) ;
228
165
// Check if the ParserError exists, but allow others too
@@ -238,10 +175,10 @@ tape('Compilation', function (t) {
238
175
st . end ( ) ;
239
176
} ) ;
240
177
241
- t . test ( 'lazy-loading callback works (with exception)' , function ( st ) {
178
+ t . test ( 'lazy-loading callback works (with exception) (using lowlevel API) ' , function ( st ) {
242
179
// <0.2.1 doesn't have this
243
- if ( ! solc . features . importCallback ) {
244
- st . skip ( 'Not supported by solc ' ) ;
180
+ if ( typeof solc . lowlevel . compileCallback !== 'function' ) {
181
+ st . skip ( 'Low-level compileCallback interface not implemented by this compiler version. ' ) ;
245
182
st . end ( ) ;
246
183
return ;
247
184
}
@@ -253,15 +190,15 @@ tape('Compilation', function (t) {
253
190
throw new Error ( 'Could not implement this interface properly...' ) ;
254
191
}
255
192
st . throws ( function ( ) {
256
- solc . compile ( { sources : input } , 0 , findImports ) ;
193
+ solc . lowlevel . compileCallback ( JSON . stringify ( { sources : input } ) , 0 , findImports ) ;
257
194
} , / ^ 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 .../ ) ;
258
195
st . end ( ) ;
259
196
} ) ;
260
197
261
- t . test ( 'lazy-loading callback fails properly (with invalid callback)' , function ( st ) {
198
+ t . test ( 'lazy-loading callback fails properly (with invalid callback) (using lowlevel API) ' , function ( st ) {
262
199
// <0.2.1 doesn't have this
263
- if ( ! solc . features . importCallback ) {
264
- st . skip ( 'Not supported by solc ' ) ;
200
+ if ( typeof solc . lowlevel . compileCallback !== 'function' ) {
201
+ st . skip ( 'Low-level compileCallback interface not implemented by this compiler version. ' ) ;
265
202
st . end ( ) ;
266
203
return ;
267
204
}
@@ -270,32 +207,32 @@ tape('Compilation', function (t) {
270
207
'cont.sol' : 'import "lib.sol"; contract x { function g() public { L.f(); } }'
271
208
} ;
272
209
st . throws ( function ( ) {
273
- solc . compile ( { sources : input } , 0 , "this isn't a callback" ) ;
210
+ solc . lowlevel . compileCallback ( JSON . stringify ( { sources : input } ) , 0 , "this isn't a callback" ) ;
274
211
} , / I n v a l i d c a l l b a c k s p e c i f i e d ./ ) ;
275
212
st . end ( ) ;
276
213
} ) ;
277
214
278
- t . test ( 'file import without lazy-loading callback fails properly' , function ( st ) {
215
+ t . test ( 'file import without lazy-loading callback fails properly (using lowlevel API) ' , function ( st ) {
279
216
// <0.2.1 doesn't have this
280
- if ( ! solc . features . importCallback ) {
281
- st . skip ( 'Not supported by solc ' ) ;
217
+ if ( typeof solc . lowlevel . compileCallback !== 'function' ) {
218
+ st . skip ( 'Low-level compileCallback interface not implemented by this compiler version. ' ) ;
282
219
st . end ( ) ;
283
220
return ;
284
221
}
285
222
286
223
var input = {
287
224
'cont.sol' : 'import "lib.sol"; contract x { function g() public { L.f(); } }'
288
225
} ;
289
- var output = solc . compile ( { sources : input } , 0 ) ;
226
+ var output = JSON . parse ( solc . lowlevel . compileCallback ( JSON . stringify ( { sources : input } ) ) ) ;
290
227
st . plan ( 3 ) ;
291
228
st . ok ( 'errors' in output ) ;
292
229
// Check if the ParserError exists, but allow others too
293
230
st . ok ( output . errors . length >= 1 ) ;
294
231
for ( var error in output . errors ) {
295
232
// Error should be something like:
296
- // cont.sol:1:1: ParserError: Source "lib.sol" not found: File not supplied initially.
297
- // cont.sol:1:1: Error: Source "lib.sol" not found: File not supplied initially.
298
- if ( output . errors [ error ] . indexOf ( 'Error' ) !== - 1 && output . errors [ error ] . indexOf ( 'File not supplied initially. ' ) !== - 1 ) {
233
+ // cont.sol:1:1: ParserError: Source "lib.sol" not found: File import callback not supported
234
+ // cont.sol:1:1: Error: Source "lib.sol" not found: File import callback not supported
235
+ if ( output . errors [ error ] . indexOf ( 'Error' ) !== - 1 && output . errors [ error ] . indexOf ( 'File import callback not supported ' ) !== - 1 ) {
299
236
st . ok ( true ) ;
300
237
}
301
238
}
0 commit comments