Skip to content

Commit 04ff205

Browse files
authored
Merge pull request #294 from ethereum/rework-test-cases
Update tests to not use obsolete compile API
2 parents a567be8 + 2d39c0c commit 04ff205

File tree

1 file changed

+25
-88
lines changed

1 file changed

+25
-88
lines changed

test/package.js

Lines changed: 25 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -47,21 +47,6 @@ tape('Version and license', function (t) {
4747
});
4848

4949
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-
6550
t.test('single files can be compiled (using lowlevel API)', function (st) {
6651
if (typeof solc.lowlevel.compileSingle !== 'function') {
6752
st.skip('Low-level compileSingle interface not implemented by this compiler version.');
@@ -77,14 +62,14 @@ tape('Compilation', function (t) {
7762
st.end();
7863
});
7964

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.');
8368
st.end();
8469
return;
8570
}
8671

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 }'));
8873
if (semver.lt(solc.semver(), '0.1.4')) {
8974
st.ok(output.error.indexOf('Parser error: Expected identifier') !== -1);
9075
st.end();
@@ -110,29 +95,8 @@ tape('Compilation', function (t) {
11095
st.end();
11196
});
11297

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-
13598
t.test('multiple files can be compiled (using lowlevel API)', function (st) {
99+
// Introduced in 0.1.6
136100
if (typeof solc.lowlevel.compileMulti !== 'function') {
137101
st.skip('Low-level compileMulti interface not implemented by this compiler version.');
138102
st.end();
@@ -153,35 +117,8 @@ tape('Compilation', function (t) {
153117
st.end();
154118
});
155119

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-
184120
t.test('lazy-loading callback works (using lowlevel API)', function (st) {
121+
// Introduced in 0.2.1
185122
if (typeof solc.lowlevel.compileCallback !== 'function') {
186123
st.skip('Low-level compileCallback interface not implemented by this compiler version.');
187124
st.end();
@@ -208,10 +145,10 @@ tape('Compilation', function (t) {
208145
st.end();
209146
});
210147

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) {
212149
// <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.');
215152
st.end();
216153
return;
217154
}
@@ -222,7 +159,7 @@ tape('Compilation', function (t) {
222159
function findImports (path) {
223160
return { error: 'File not found' };
224161
}
225-
var output = solc.compile({sources: input}, 0, findImports);
162+
var output = JSON.parse(solc.lowlevel.compileCallback(JSON.stringify({sources: input}), 0, findImports));
226163
st.plan(3);
227164
st.ok('errors' in output);
228165
// Check if the ParserError exists, but allow others too
@@ -238,10 +175,10 @@ tape('Compilation', function (t) {
238175
st.end();
239176
});
240177

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) {
242179
// <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.');
245182
st.end();
246183
return;
247184
}
@@ -253,15 +190,15 @@ tape('Compilation', function (t) {
253190
throw new Error('Could not implement this interface properly...');
254191
}
255192
st.throws(function () {
256-
solc.compile({sources: input}, 0, findImports);
193+
solc.lowlevel.compileCallback(JSON.stringify({sources: input}), 0, findImports);
257194
}, /^Error: Could not implement this interface properly.../);
258195
st.end();
259196
});
260197

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) {
262199
// <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.');
265202
st.end();
266203
return;
267204
}
@@ -270,32 +207,32 @@ tape('Compilation', function (t) {
270207
'cont.sol': 'import "lib.sol"; contract x { function g() public { L.f(); } }'
271208
};
272209
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");
274211
}, /Invalid callback specified./);
275212
st.end();
276213
});
277214

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) {
279216
// <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.');
282219
st.end();
283220
return;
284221
}
285222

286223
var input = {
287224
'cont.sol': 'import "lib.sol"; contract x { function g() public { L.f(); } }'
288225
};
289-
var output = solc.compile({sources: input}, 0);
226+
var output = JSON.parse(solc.lowlevel.compileCallback(JSON.stringify({sources: input})));
290227
st.plan(3);
291228
st.ok('errors' in output);
292229
// Check if the ParserError exists, but allow others too
293230
st.ok(output.errors.length >= 1);
294231
for (var error in output.errors) {
295232
// 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) {
299236
st.ok(true);
300237
}
301238
}

0 commit comments

Comments
 (0)