@@ -55,6 +55,21 @@ tape('Compilation', function (t) {
55
55
st . ok ( bytecode . length > 0 ) ;
56
56
st . end ( ) ;
57
57
} ) ;
58
+
59
+ t . test ( 'single files can be compiled (using lowlevel API)' , function ( st ) {
60
+ if ( typeof solc . lowlevel . compileSingle !== 'function' ) {
61
+ st . skip ( 'Low-level compileSingle interface not implemented by this compiler version.' ) ;
62
+ st . end ( ) ;
63
+ return ;
64
+ }
65
+ var output = JSON . parse ( solc . lowlevel . compileSingle ( 'contract x { function g() public {} }' ) ) ;
66
+ st . ok ( 'contracts' in output ) ;
67
+ var bytecode = getBytecode ( output , '' , 'x' ) ;
68
+ st . ok ( bytecode ) ;
69
+ st . ok ( bytecode . length > 0 ) ;
70
+ st . end ( ) ;
71
+ } ) ;
72
+
58
73
t . test ( 'invalid source code fails properly' , function ( st ) {
59
74
var output = solc . compile ( 'contract x { this is an invalid contract }' ) ;
60
75
if ( semver . lt ( solc . semver ( ) , '0.1.4' ) ) {
@@ -103,6 +118,27 @@ tape('Compilation', function (t) {
103
118
st . end ( ) ;
104
119
} ) ;
105
120
121
+ t . test ( 'multiple files can be compiled (using lowlevel API)' , function ( st ) {
122
+ if ( typeof solc . lowlevel . compileMulti !== 'function' ) {
123
+ st . skip ( 'Low-level compileMulti interface not implemented by this compiler version.' ) ;
124
+ st . end ( ) ;
125
+ return ;
126
+ }
127
+
128
+ var input = {
129
+ 'lib.sol' : 'library L { function f() public returns (uint) { return 7; } }' ,
130
+ 'cont.sol' : 'import "lib.sol"; contract x { function g() public { L.f(); } }'
131
+ } ;
132
+ var output = JSON . parse ( solc . lowlevel . compileMulti ( JSON . stringify ( { sources : input } ) ) ) ;
133
+ var x = getBytecode ( output , 'cont.sol' , 'x' ) ;
134
+ st . ok ( x ) ;
135
+ st . ok ( x . length > 0 ) ;
136
+ var L = getBytecode ( output , 'lib.sol' , 'L' ) ;
137
+ st . ok ( L ) ;
138
+ st . ok ( L . length > 0 ) ;
139
+ st . end ( ) ;
140
+ } ) ;
141
+
106
142
t . test ( 'lazy-loading callback works' , function ( st ) {
107
143
if ( semver . lt ( solc . semver ( ) , '0.2.1' ) ) {
108
144
st . skip ( 'Not supported by solc <0.2.1' ) ;
@@ -130,6 +166,33 @@ tape('Compilation', function (t) {
130
166
st . end ( ) ;
131
167
} ) ;
132
168
169
+ t . test ( 'lazy-loading callback works (using lowlevel API)' , function ( st ) {
170
+ if ( typeof solc . lowlevel . compileCallback !== 'function' ) {
171
+ st . skip ( 'Low-level compileCallback interface not implemented by this compiler version.' ) ;
172
+ st . end ( ) ;
173
+ return ;
174
+ }
175
+
176
+ var input = {
177
+ 'cont.sol' : 'import "lib.sol"; contract x { function g() public { L.f(); } }'
178
+ } ;
179
+ function findImports ( path ) {
180
+ if ( path === 'lib.sol' ) {
181
+ return { contents : 'library L { function f() public returns (uint) { return 7; } }' } ;
182
+ } else {
183
+ return { error : 'File not found' } ;
184
+ }
185
+ }
186
+ var output = JSON . parse ( solc . lowlevel . compileCallback ( JSON . stringify ( { sources : input } ) , 0 , findImports ) ) ;
187
+ var x = getBytecode ( output , 'cont.sol' , 'x' ) ;
188
+ var L = getBytecode ( output , 'lib.sol' , 'L' ) ;
189
+ st . ok ( x ) ;
190
+ st . ok ( x . length > 0 ) ;
191
+ st . ok ( L ) ;
192
+ st . ok ( L . length > 0 ) ;
193
+ st . end ( ) ;
194
+ } ) ;
195
+
133
196
t . test ( 'lazy-loading callback works (with file not found)' , function ( st ) {
134
197
if ( semver . lt ( solc . semver ( ) , '0.2.1' ) ) {
135
198
st . skip ( 'Not supported by solc <0.2.1' ) ;
@@ -259,6 +322,7 @@ tape('Compilation', function (t) {
259
322
st . ok ( bytecodeExists ( output , 'lib.sol' , 'L' ) ) ;
260
323
st . end ( ) ;
261
324
} ) ;
325
+
262
326
t . test ( 'invalid source code fails properly with standard JSON' , function ( st ) {
263
327
if ( ! solc . supportsStandard ) {
264
328
st . skip ( 'Not supported by solc' ) ;
@@ -293,6 +357,7 @@ tape('Compilation', function (t) {
293
357
}
294
358
st . end ( ) ;
295
359
} ) ;
360
+
296
361
t . test ( 'compiling standard JSON (with callback)' , function ( st ) {
297
362
if ( ! solc . supportsStandard ) {
298
363
st . skip ( 'Not supported by solc' ) ;
@@ -337,6 +402,7 @@ tape('Compilation', function (t) {
337
402
st . ok ( bytecodeExists ( output , 'lib.sol' , 'L' ) ) ;
338
403
st . end ( ) ;
339
404
} ) ;
405
+
340
406
t . test ( 'compiling standard JSON (using wrapper)' , function ( st ) {
341
407
// Example needs support for compileJSONMulti
342
408
// FIXME: add test for wrapper without multiple files
@@ -418,6 +484,48 @@ tape('Compilation', function (t) {
418
484
st . ok ( L . length > 0 ) ;
419
485
st . end ( ) ;
420
486
} ) ;
487
+
488
+ t . test ( 'compiling standard JSON (using lowlevel API)' , function ( st ) {
489
+ if ( typeof solc . lowlevel . compileStandard !== 'function' ) {
490
+ st . skip ( 'Low-level compileStandard interface not implemented by this compiler version.' ) ;
491
+ st . end ( ) ;
492
+ return ;
493
+ }
494
+
495
+ var input = {
496
+ 'language' : 'Solidity' ,
497
+ 'settings' : {
498
+ 'libraries' : {
499
+ 'lib.sol' : {
500
+ 'L' : '0x4200000000000000000000000000000000000001'
501
+ }
502
+ } ,
503
+ 'outputSelection' : {
504
+ '*' : {
505
+ '*' : [ 'evm.bytecode' ]
506
+ }
507
+ }
508
+ } ,
509
+ 'sources' : {
510
+ 'lib.sol' : {
511
+ 'content' : 'library L { function f() public returns (uint) { return 7; } }'
512
+ } ,
513
+ 'cont.sol' : {
514
+ 'content' : 'import "lib.sol"; contract x { function g() public { L.f(); } }'
515
+ }
516
+ }
517
+ } ;
518
+
519
+ var output = JSON . parse ( solc . lowlevel . compileStandard ( JSON . stringify ( input ) ) ) ;
520
+ var x = getBytecodeStandard ( output , 'cont.sol' , 'x' ) ;
521
+ st . ok ( x ) ;
522
+ st . ok ( x . length > 0 ) ;
523
+ st . ok ( Object . keys ( linker . findLinkReferences ( x ) ) . length === 0 ) ;
524
+ var L = getBytecodeStandard ( output , 'lib.sol' , 'L' ) ;
525
+ st . ok ( L ) ;
526
+ st . ok ( L . length > 0 ) ;
527
+ st . end ( ) ;
528
+ } ) ;
421
529
} ) ;
422
530
423
531
tape ( 'Loading Legacy Versions' , function ( t ) {
0 commit comments