Skip to content

Commit bf9d463

Browse files
committed
Corectly handle Standard JSON with wrong file name splitting from 0.4.11-0.4.19 in tests
1 parent 8edc46c commit bf9d463

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

test/compiler.js

+42
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
const assert = require('assert');
12
const tape = require('tape');
23
const semver = require('semver');
34
const solc = require('../index.js');
@@ -9,6 +10,16 @@ var noRemoteVersions = (process.argv.indexOf('--no-remote-versions') >= 0);
910
function runTests (solc, versionText) {
1011
console.log(`Running tests with ${versionText} ${solc.version()}`);
1112

13+
function resplitFileNameOnFirstColon (fileName, contractName) {
14+
assert(!contractName.includes(':'));
15+
16+
let contractNameComponents = fileName.split(':');
17+
const truncatedFileName = contractNameComponents.shift();
18+
contractNameComponents.push(contractName);
19+
20+
return [truncatedFileName, contractNameComponents.join(':')];
21+
}
22+
1223
function getBytecode (output, fileName, contractName) {
1324
try {
1425
var outputContract;
@@ -29,6 +40,9 @@ function runTests (solc, versionText) {
2940
if (semver.lt(solc.semver(), '0.4.9')) {
3041
outputFile = output.contracts[''];
3142
} else {
43+
if (semver.gt(solc.semver(), '0.4.10') && semver.lt(solc.semver(), '0.4.20')) {
44+
[fileName, contractName] = resplitFileNameOnFirstColon(fileName, contractName);
45+
}
3246
outputFile = output.contracts[fileName];
3347
}
3448
return outputFile[contractName]['evm']['bytecode']['object'];
@@ -43,6 +57,9 @@ function runTests (solc, versionText) {
4357
if (semver.lt(solc.semver(), '0.4.9')) {
4458
outputFile = output.contracts[''];
4559
} else {
60+
if (semver.gt(solc.semver(), '0.4.10') && semver.gt(solc.semver(), '0.4.20')) {
61+
[fileName, contractName] = resplitFileNameOnFirstColon(fileName, contractName);
62+
}
4663
outputFile = output.contracts[fileName];
4764
}
4865
return outputFile[contractName]['evm']['gasEstimates'];
@@ -782,6 +799,31 @@ function runTests (solc, versionText) {
782799
st.ok(C.length > 0);
783800
st.end();
784801
});
802+
803+
t.test('compiling standard JSON (file names containing multiple semicolons)', function (st) {
804+
var input = {
805+
'language': 'Solidity',
806+
'settings': {
807+
'outputSelection': {
808+
'*': {
809+
'*': ['evm.bytecode']
810+
}
811+
}
812+
},
813+
'sources': {
814+
'a:b:c:d:e:f:G.sol': {
815+
'content': 'contract G {}'
816+
}
817+
}
818+
};
819+
820+
var output = JSON.parse(solc.compile(JSON.stringify(input)));
821+
st.ok(expectNoError(output));
822+
var G = getBytecodeStandard(output, 'a:b:c:d:e:f:G.sol', 'G');
823+
st.ok(typeof G === 'string');
824+
st.ok(G.length > 0);
825+
st.end();
826+
});
785827
});
786828
});
787829

0 commit comments

Comments
 (0)