From e25728ac88492755155eb1bc134d2917d491b065 Mon Sep 17 00:00:00 2001 From: cgewecke Date: Fri, 29 Nov 2019 17:30:01 -0800 Subject: [PATCH] Allow Truffle V4 style solc config (#449) --- plugins/resources/truffle.utils.js | 6 ++++++ test/units/truffle/standard.js | 25 ++++++++++++++++++++++++- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/plugins/resources/truffle.utils.js b/plugins/resources/truffle.utils.js index 80ac81a..9c00b59 100644 --- a/plugins/resources/truffle.utils.js +++ b/plugins/resources/truffle.utils.js @@ -200,6 +200,12 @@ function normalizeConfig(config){ delete config.mocha.reporterOptions; } + // Truffle V4 style solc settings are honored over V5 settings. Apparently it's common + // for both to be present in the same config (as an error). + if (typeof config.solc === "object" ){ + config.solc.optimizer = { enabled: false }; + } + return config; } diff --git a/test/units/truffle/standard.js b/test/units/truffle/standard.js index dd54b3a..436a457 100644 --- a/test/units/truffle/standard.js +++ b/test/units/truffle/standard.js @@ -216,13 +216,36 @@ describe('Truffle Plugin: standard use cases', function() { }); // This test errors if the reporter is not re-designated as 'spec' correctly - it('gracefully disables eth-gas-reporter', async function(){ + it('disables eth-gas-reporter', async function(){ truffleConfig.mocha = { reporter: 'eth-gas-reporter' }; mock.install('Simple', 'simple.js', solcoverConfig); await plugin(truffleConfig); }); + it('disables optimization when truffle-config uses V4 format', async function(){ + solcoverConfig = { + silent: process.env.SILENT ? true : false, + istanbulReporter: ['json-summary', 'text'] + }; + + truffleConfig.solc = { + optimizer: { enabled: true, runs: 200 } + }; + + mock.install('Simple', 'simple.js', solcoverConfig); + await plugin(truffleConfig); + + const expected = [ + { + file: mock.pathToContract(truffleConfig, 'Simple.sol'), + pct: 100 + } + ]; + + verify.lineCoverage(expected); + }); + // This test tightly coupled to the ganache version in production deps // "test-files" project solcoverjs includes `client: require('ganache-cli')` it('config: client', async function(){