Skip to content

Commit

Permalink
Corectly handle Standard JSON with wrong file name splitting from 0.4…
Browse files Browse the repository at this point in the history
….11-0.4.19 in tests
  • Loading branch information
cameel committed Oct 12, 2021
1 parent 8edc46c commit bf9d463
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions test/compiler.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const assert = require('assert');
const tape = require('tape');
const semver = require('semver');
const solc = require('../index.js');
Expand All @@ -9,6 +10,16 @@ var noRemoteVersions = (process.argv.indexOf('--no-remote-versions') >= 0);
function runTests (solc, versionText) {
console.log(`Running tests with ${versionText} ${solc.version()}`);

function resplitFileNameOnFirstColon (fileName, contractName) {
assert(!contractName.includes(':'));

let contractNameComponents = fileName.split(':');
const truncatedFileName = contractNameComponents.shift();
contractNameComponents.push(contractName);

return [truncatedFileName, contractNameComponents.join(':')];
}

function getBytecode (output, fileName, contractName) {
try {
var outputContract;
Expand All @@ -29,6 +40,9 @@ function runTests (solc, versionText) {
if (semver.lt(solc.semver(), '0.4.9')) {
outputFile = output.contracts[''];
} else {
if (semver.gt(solc.semver(), '0.4.10') && semver.lt(solc.semver(), '0.4.20')) {
[fileName, contractName] = resplitFileNameOnFirstColon(fileName, contractName);
}
outputFile = output.contracts[fileName];
}
return outputFile[contractName]['evm']['bytecode']['object'];
Expand All @@ -43,6 +57,9 @@ function runTests (solc, versionText) {
if (semver.lt(solc.semver(), '0.4.9')) {
outputFile = output.contracts[''];
} else {
if (semver.gt(solc.semver(), '0.4.10') && semver.gt(solc.semver(), '0.4.20')) {
[fileName, contractName] = resplitFileNameOnFirstColon(fileName, contractName);
}
outputFile = output.contracts[fileName];
}
return outputFile[contractName]['evm']['gasEstimates'];
Expand Down Expand Up @@ -782,6 +799,31 @@ function runTests (solc, versionText) {
st.ok(C.length > 0);
st.end();
});

t.test('compiling standard JSON (file names containing multiple semicolons)', function (st) {
var input = {
'language': 'Solidity',
'settings': {
'outputSelection': {
'*': {
'*': ['evm.bytecode']
}
}
},
'sources': {
'a:b:c:d:e:f:G.sol': {
'content': 'contract G {}'
}
}
};

var output = JSON.parse(solc.compile(JSON.stringify(input)));
st.ok(expectNoError(output));
var G = getBytecodeStandard(output, 'a:b:c:d:e:f:G.sol', 'G');
st.ok(typeof G === 'string');
st.ok(G.length > 0);
st.end();
});
});
});

Expand Down

0 comments on commit bf9d463

Please sign in to comment.