Skip to content

Some minor cleanups to the tests and wrapper #409

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions solcjs
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ function abort (msg) {

if (program.standardJson) {
var input = fs.readFileSync(process.stdin.fd).toString('utf8');
var output = solc.compileStandardWrapper(input);
var output = solc.compile(input);

try {
var inputJSON = smtchecker.handleSMTQueries(JSON.parse(input), JSON.parse(output), smtsolver.smtSolver);
if (inputJSON) {
output = solc.compileStandardWrapper(JSON.stringify(inputJSON));
output = solc.compile(JSON.stringify(inputJSON));
}
}
catch (e) {
Expand Down Expand Up @@ -80,7 +80,7 @@ for (var i = 0; i < files.length; i++) {
}
}

var output = JSON.parse(solc.compileStandardWrapper(JSON.stringify({
var output = JSON.parse(solc.compile(JSON.stringify({
language: 'Solidity',
settings: {
optimizer: {
Expand Down
11 changes: 4 additions & 7 deletions test/compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -563,31 +563,28 @@ function runTests (solc, versionText) {
t.test('compiling standard JSON (invalid JSON)', function (st) {
var output = JSON.parse(solc.compile('{invalid'));
// TODO: change wrapper to output matching error
st.ok(expectError(output, 'JSONError', 'Line 1, Column 2\n Missing \'}\' or object member name') || expectError(output, 'SOLCError', 'Invalid JSON supplied'));
st.ok(expectError(output, 'JSONError', 'Line 1, Column 2\n Missing \'}\' or object member name') || expectError(output, 'JSONError', 'Invalid JSON supplied:'));
st.end();
});

t.test('compiling standard JSON (invalid language)', function (st) {
var output = JSON.parse(solc.compile('{"language":"InvalidSolidity","sources":{"cont.sol":{"content":""}}}'));
// TODO: change wrapper to output matching error
st.ok(expectError(output, 'JSONError', 'supported as a language.') || expectError(output, 'SOLCError', 'Only Solidity sources are supported'));
st.ok(expectError(output, 'JSONError', 'supported as a language.') && expectError(output, 'JSONError', '"Solidity"'));
st.end();
});

t.test('compiling standard JSON (no sources)', function (st) {
var output = JSON.parse(solc.compile('{"language":"Solidity"}'));
// TODO: change wrapper to output matching error
st.ok(expectError(output, 'JSONError', 'No input sources specified.') || expectError(output, 'SOLCError', 'No input specified'));
st.ok(expectError(output, 'JSONError', 'No input sources specified.'));
st.end();
});

t.test('compiling standard JSON (multiple sources on old compiler)', function (st) {
var output = JSON.parse(solc.compile('{"language":"Solidity","sources":{"cont.sol":{"content":"import \\"lib.sol\\";"},"lib.sol":{"content":""}}}'));
console.log(output);
if (solc.features.multipleInputs) {
st.ok(expectNoError(output));
} else {
st.ok(expectError(output, 'SOLCError', 'Multiple sources provided, but compiler only supports single input') || expectError(output, 'Parser error', 'Parser error: Source not found.'));
st.ok(expectError(output, 'JSONError', 'Multiple sources provided, but compiler only supports single input.') || expectError(output, 'Parser error', 'Parser error: Source not found.'));
}
st.end();
});
Expand Down
12 changes: 6 additions & 6 deletions wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ function setupMethods (soljson) {
return JSON.stringify({
errors: [
{
'type': 'SOLCError',
'type': 'JSONError',
'component': 'solcjs',
'severity': 'error',
'message': message,
Expand All @@ -148,17 +148,17 @@ function setupMethods (soljson) {
}

if (input['language'] !== 'Solidity') {
return formatFatalError('Only Solidity sources are supported');
return formatFatalError('Only "Solidity" is supported as a language.');
}

// NOTE: this is deliberately `== null`
if (input['sources'] == null || input['sources'].length === 0) {
return formatFatalError('No input specified');
return formatFatalError('No input sources specified.');
}

// Bail out early
if ((input['sources'].length > 1) && (compileJSONMulti === null)) {
return formatFatalError('Multiple sources provided, but compiler only supports single input');
return formatFatalError('Multiple sources provided, but compiler only supports single input.');
}

function isOptimizerEnabled (input) {
Expand Down Expand Up @@ -192,14 +192,14 @@ function setupMethods (soljson) {
}
output = translate.translateJsonCompilerOutput(output, libraries);
if (output == null) {
return formatFatalError('Failed to process output');
return formatFatalError('Failed to process output.');
}
return JSON.stringify(output);
}

var sources = translateSources(input);
if (sources === null || Object.keys(sources).length === 0) {
return formatFatalError('Failed to process sources');
return formatFatalError('Failed to process sources.');
}

// Try linking if libraries were supplied
Expand Down