@@ -72,6 +72,61 @@ tape('Compilation', function (t) {
72
72
st . ok ( output . contracts [ 'lib.sol:L' ] . bytecode . length > 0 ) ;
73
73
st . end ( ) ;
74
74
} ) ;
75
+
76
+ t . test ( 'lazy-loading callback works (with file not found)' , function ( st ) {
77
+ var input = {
78
+ 'cont.sol' : 'import "lib.sol"; contract x { function g() { L.f(); } }'
79
+ } ;
80
+ function findImports ( path ) {
81
+ return { error : 'File not found' } ;
82
+ }
83
+ var output = solc . compile ( { sources : input } , 0 , findImports ) ;
84
+ st . plan ( 3 ) ;
85
+ st . ok ( 'errors' in output ) ;
86
+ // Check if the ParserError exists, but allow others too
87
+ st . ok ( output . errors . length >= 1 ) ;
88
+ for ( var error in output . errors ) {
89
+ // Error should be something like:
90
+ // cont.sol:1:1: ParserError: Source "lib.sol" not found: File not found
91
+ if ( output . errors [ error ] . indexOf ( 'ParserError' ) !== - 1 && output . errors [ error ] . indexOf ( 'File not found' ) !== - 1 ) {
92
+ st . ok ( true ) ;
93
+ }
94
+ }
95
+ st . end ( ) ;
96
+ } ) ;
97
+
98
+ t . test ( 'lazy-loading callback works (with exception)' , function ( st ) {
99
+ var input = {
100
+ 'cont.sol' : 'import "lib.sol"; contract x { function g() { L.f(); } }'
101
+ } ;
102
+ function findImports ( path ) {
103
+ throw new Error ( 'Could not implement this interface properly...' ) ;
104
+ }
105
+ st . throws ( function ( ) {
106
+ solc . compile ( { sources : input } , 0 , findImports ) ;
107
+ } , / ^ 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 .../ ) ;
108
+ st . end ( ) ;
109
+ } ) ;
110
+
111
+ t . test ( 'file import without lazy-loading callback fails properly' , function ( st ) {
112
+ var input = {
113
+ 'cont.sol' : 'import "lib.sol"; contract x { function g() { L.f(); } }'
114
+ } ;
115
+ var output = solc . compile ( { sources : input } , 0 ) ;
116
+ st . plan ( 3 ) ;
117
+ st . ok ( 'errors' in output ) ;
118
+ // Check if the ParserError exists, but allow others too
119
+ st . ok ( output . errors . length >= 1 ) ;
120
+ for ( var error in output . errors ) {
121
+ // Error should be something like:
122
+ // cont.sol:1:1: ParserError: Source "lib.sol" not found: File not supplied initially.
123
+ if ( output . errors [ error ] . indexOf ( 'ParserError' ) !== - 1 && output . errors [ error ] . indexOf ( 'File not supplied initially.' ) !== - 1 ) {
124
+ st . ok ( true ) ;
125
+ }
126
+ }
127
+ st . end ( ) ;
128
+ } ) ;
129
+
75
130
t . test ( 'compiling standard JSON' , function ( st ) {
76
131
if ( ! solc . supportsStandard ) {
77
132
st . skip ( 'Not supported by solc' ) ;
0 commit comments