From 8edc46cd64f21ecd5afc328c0585a00f871c8bdb Mon Sep 17 00:00:00 2001 From: cameel Date: Tue, 12 Oct 2021 21:36:43 +0200 Subject: [PATCH 1/2] Don't assume that file names do not contain colons when translating compiler output from 0.4.10 --- test/compiler.js | 26 ++++++++++++++++++++++++++ translate.js | 2 +- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/test/compiler.js b/test/compiler.js index 2e5a78b5..263408d9 100644 --- a/test/compiler.js +++ b/test/compiler.js @@ -757,6 +757,31 @@ function runTests (solc, versionText) { } st.end(); }); + + t.test('compiling standard JSON (file names containing symbols)', function (st) { + var input = { + 'language': 'Solidity', + 'settings': { + 'outputSelection': { + '*': { + '*': ['evm.bytecode'] + } + } + }, + 'sources': { + '!@#$%^&*()_+-=[]{}\\|"\';:~`<>,.?/': { + 'content': 'contract C {}' + } + } + }; + + var output = JSON.parse(solc.compile(JSON.stringify(input))); + st.ok(expectNoError(output)); + var C = getBytecodeStandard(output, '!@#$%^&*()_+-=[]{}\\|"\';:~`<>,.?/', 'C'); + st.ok(typeof C === 'string'); + st.ok(C.length > 0); + st.end(); + }); }); }); @@ -810,6 +835,7 @@ if (!noRemoteVersions) { 'v0.2.1+commit.91a6b35', 'v0.3.6+commit.3fc68da', 'v0.4.0+commit.acd334c9', + 'v0.4.10+commit.f0d539ae', 'v0.4.11+commit.68ef5810', 'v0.4.12+commit.194ff033', 'v0.4.26+commit.4563c3fc' diff --git a/translate.js b/translate.js index 5c4c76eb..4a9d0e3d 100644 --- a/translate.js +++ b/translate.js @@ -78,7 +78,7 @@ function translateJsonCompilerOutput (output, libraries) { ret['contracts'] = {}; for (var contract in output['contracts']) { // Split name first, can be `contract`, `:contract` or `filename:contract` - var tmp = contract.match(/^(([^:]*):)?([^:]+)$/); + var tmp = contract.match(/^((.*):)?([^:]+)$/); if (tmp.length !== 4) { // Force abort return null; From 7c78d4cbe5a4cefeb841ab99ff247bab0238e00d Mon Sep 17 00:00:00 2001 From: cameel Date: Tue, 12 Oct 2021 21:45:43 +0200 Subject: [PATCH 2/2] Corectly handle Standard JSON with wrong file name splitting from 0.4.11-0.4.19 in tests --- test/compiler.js | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/test/compiler.js b/test/compiler.js index 263408d9..62a8cdf8 100644 --- a/test/compiler.js +++ b/test/compiler.js @@ -1,3 +1,4 @@ +const assert = require('assert'); const tape = require('tape'); const semver = require('semver'); const solc = require('../index.js'); @@ -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; @@ -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']; @@ -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']; @@ -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(); + }); }); }); @@ -835,9 +877,12 @@ if (!noRemoteVersions) { 'v0.2.1+commit.91a6b35', 'v0.3.6+commit.3fc68da', 'v0.4.0+commit.acd334c9', + 'v0.4.9+commit.364da425', 'v0.4.10+commit.f0d539ae', 'v0.4.11+commit.68ef5810', 'v0.4.12+commit.194ff033', + 'v0.4.19+commit.c4cbbb05', + 'v0.4.20+commit.3155dd80', 'v0.4.26+commit.4563c3fc' ]; for (var version in versions) {