From ca65d66a6bbd962cbf86d67c30f78bbb5049bd72 Mon Sep 17 00:00:00 2001 From: yann300 Date: Thu, 30 Nov 2017 09:49:44 +0100 Subject: [PATCH] refactor compilerInput && update change on legacy features --- remix-lib/index.js | 4 ++- remix-lib/src/helpers/compilerHelper.js | 26 +++++++++++++++++++ remix-lib/test/sourceMappingDecoder.js | 23 +--------------- .../staticAnalysisIntegration-test.js | 25 ++---------------- remix-solidity/test/decoder/decodeInfo.js | 24 ++--------------- remix-solidity/test/decoder/localDecoder.js | 23 +--------------- 6 files changed, 35 insertions(+), 90 deletions(-) create mode 100644 remix-lib/src/helpers/compilerHelper.js diff --git a/remix-lib/index.js b/remix-lib/index.js index b49f5867d1..d76ec5a1c9 100644 --- a/remix-lib/index.js +++ b/remix-lib/index.js @@ -2,6 +2,7 @@ var EventManager = require('./src/eventManager') var traceHelper = require('./src/helpers/traceHelper') var uiHelper = require('./src/helpers/uiHelper') +var compilerHelper = require('./src/helpers/compilerHelper') var SourceMappingDecoder = require('./src/sourceMappingDecoder') var SourceLocationTracker = require('./src/sourceLocationTracker') var init = require('./src/init') @@ -26,7 +27,8 @@ function modules () { EventManager: EventManager, helpers: { trace: traceHelper, - ui: uiHelper + ui: uiHelper, + compiler: compilerHelper }, vm: { Web3Providers: Web3Providers, diff --git a/remix-lib/src/helpers/compilerHelper.js b/remix-lib/src/helpers/compilerHelper.js new file mode 100644 index 0000000000..2e99e9afc1 --- /dev/null +++ b/remix-lib/src/helpers/compilerHelper.js @@ -0,0 +1,26 @@ +module.exports = { + compilerInput: compilerInput +} + +function compilerInput (contracts) { + return JSON.stringify({ + language: 'Solidity', + sources: { + 'test.sol': { + content: contracts + } + }, + settings: { + optimizer: { + enabled: false, + runs: 500 + } + }, + outputSelection: { + '*': { + '': [ 'legacyAST' ], + '*': [ 'abi', 'metadata', 'evm.legacyAssembly', 'evm.bytecode', 'evm.deployedBytecode', 'evm.methodIdentifiers', 'evm.gasEstimates' ] + } + } + }) +} diff --git a/remix-lib/test/sourceMappingDecoder.js b/remix-lib/test/sourceMappingDecoder.js index 52ea53d14a..1a6513e384 100644 --- a/remix-lib/test/sourceMappingDecoder.js +++ b/remix-lib/test/sourceMappingDecoder.js @@ -3,6 +3,7 @@ var tape = require('tape') var sourceMapping = require('./resources/sourceMapping') var SourceMappingDecoder = require('../src/sourceMappingDecoder') var compiler = require('solc') +var compilerInput = require('../src/helpers/compilerHelper').compilerInput tape('SourceMappingDecoder', function (t) { t.test('SourceMappingDecoder.findNodeAtInstructionIndex', function (st) { @@ -116,25 +117,3 @@ var contracts = `contract test { } } ` - -function compilerInput (contracts) { - return JSON.stringify({ - language: 'Solidity', - sources: { - 'test.sol': { - content: contracts - } - }, - settings: { - optimizer: { - enabled: false, - runs: 500 - } - }, - outputSelection: { - '*': { - '*': [ 'metadata', 'evm.bytecode', 'abi', 'legacyAST', 'metadata', 'evm.assembly', 'evm.methodIdentifiers', 'evm.gasEstimates' ] - } - } - }) -} diff --git a/remix-solidity/test/analysis/staticAnalysisIntegration-test.js b/remix-solidity/test/analysis/staticAnalysisIntegration-test.js index 273876f4b5..9acf740910 100644 --- a/remix-solidity/test/analysis/staticAnalysisIntegration-test.js +++ b/remix-solidity/test/analysis/staticAnalysisIntegration-test.js @@ -1,7 +1,8 @@ var test = require('tape') +var remixLib = require('remix-lib') var StatRunner = require('../../src/analysis/staticAnalysisRunner') -// const util = require('util') +var compilerInput = remixLib.helpers.compiler.compilerInput var solc = require('solc/wrapper') var compiler = solc(require('../../soljson')) @@ -450,25 +451,3 @@ function runModuleOnFiles (module, t, cb) { }) }) } - -function compilerInput (contracts) { - return JSON.stringify({ - language: 'Solidity', - sources: { - 'test.sol': { - content: contracts - } - }, - settings: { - optimizer: { - enabled: false, - runs: 500 - } - }, - outputSelection: { - '*': { - '*': [ 'metadata', 'evm.bytecode', 'abi', 'legacyAST', 'metadata', 'evm.assembly', 'evm.methodIdentifiers', 'evm.gasEstimates' ] - } - } - }) -} diff --git a/remix-solidity/test/decoder/decodeInfo.js b/remix-solidity/test/decoder/decodeInfo.js index 474981d6a8..3a23f0346a 100644 --- a/remix-solidity/test/decoder/decodeInfo.js +++ b/remix-solidity/test/decoder/decodeInfo.js @@ -6,6 +6,8 @@ var decodeInfo = require('../../src/decoder/decodeInfo') var stateDecoder = require('../../src/decoder/stateDecoder') var contracts = require('./contracts/miscContracts') var simplecontracts = require('./contracts/simpleContract') +var remixLib = require('remix-lib') +var compilerInput = remixLib.helpers.compiler.compilerInput tape('solidity', function (t) { t.test('astHelper, decodeInfo', function (st) { @@ -92,25 +94,3 @@ function checkDecodeInfo (st, decodeInfo, storageSlots, storageBytes, typeName) st.equal(decodeInfo.storageBytes, storageBytes) st.equal(decodeInfo.typeName, typeName) } - -function compilerInput (contracts) { - return JSON.stringify({ - language: 'Solidity', - sources: { - 'test.sol': { - content: contracts - } - }, - settings: { - optimizer: { - enabled: false, - runs: 500 - } - }, - outputSelection: { - '*': { - '*': [ 'metadata', 'evm.bytecode', 'abi', 'legacyAST', 'metadata', 'evm.assembly', 'evm.methodIdentifiers', 'evm.gasEstimates' ] - } - } - }) -} diff --git a/remix-solidity/test/decoder/localDecoder.js b/remix-solidity/test/decoder/localDecoder.js index af9c0500ea..5c9fe73ed6 100644 --- a/remix-solidity/test/decoder/localDecoder.js +++ b/remix-solidity/test/decoder/localDecoder.js @@ -13,6 +13,7 @@ var intLocalTest = require('./localsTests/int') var miscLocalTest = require('./localsTests/misc') var misc2LocalTest = require('./localsTests/misc2') var structArrayLocalTest = require('./localsTests/structArray') +var compilerInput = remixLib.helpers.compiler.compilerInput tape('solidity', function (t) { t.test('local decoder', function (st) { @@ -64,25 +65,3 @@ function test (st, vm, privateKey) { }) }) } - -function compilerInput (contracts) { - return JSON.stringify({ - language: 'Solidity', - sources: { - 'test.sol': { - content: contracts - } - }, - settings: { - optimizer: { - enabled: false, - runs: 500 - } - }, - outputSelection: { - '*': { - '*': [ 'metadata', 'evm.bytecode', 'abi', 'legacyAST', 'metadata', 'evm.assembly', 'evm.methodIdentifiers', 'evm.gasEstimates' ] - } - } - }) -}