From dae8062270c6af38b484ac9442ae4112a478928b Mon Sep 17 00:00:00 2001 From: yann300 Date: Mon, 31 Dec 2018 17:03:43 +0100 Subject: [PATCH] makeMockCompiler use the default version + add comment --- .circleci/config.yml | 4 ++-- ci/makeMockCompiler.js | 30 +++++++++++++++++------------- src/app/tabs/compile-tab.js | 2 +- 3 files changed, 20 insertions(+), 16 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 7b424a4dde..b6eca0c917 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -26,10 +26,10 @@ jobs: - checkout - restore_cache: keys: - - dep-bundle-26-{{ checksum "package.json" }} + - dep-bundle-27-{{ checksum "package.json" }} - run: npm install - save_cache: - key: dep-bundle-26-{{ checksum "package.json" }} + key: dep-bundle-27-{{ checksum "package.json" }} paths: - ~/repo/node_modules - run: npm run lint && npm run test && npm run make-mock-compiler && npm run build diff --git a/ci/makeMockCompiler.js b/ci/makeMockCompiler.js index b8e3a6b4db..987f408d49 100644 --- a/ci/makeMockCompiler.js +++ b/ci/makeMockCompiler.js @@ -2,14 +2,18 @@ var fs = require('fs') var compiler = require('solc') - var compilerInput = require('remix-solidity').CompilerInput -var compilationResult = {} -gatherCompilationResults('./test-browser/tests/', compilationResult) -gatherCompilationResults('./test-browser/tests/units/', compilationResult) -replaceSolCompiler(compilationResult) +var defaultVersion = 'v0.5.1+commit.c8a2cb62' + +compiler.loadRemoteVersion(defaultVersion, (error, solcSnapshot) => { + if (error) console.log(error) + var compilationResult = {} + gatherCompilationResults('./test-browser/tests/', compilationResult, solcSnapshot) + gatherCompilationResults('./test-browser/tests/units/', compilationResult, solcSnapshot) + replaceSolCompiler(compilationResult, solcSnapshot) +}) -function gatherCompilationResults (dir, compilationResult, callback) { +function gatherCompilationResults (dir, compilationResult, solcSnapshot) { var filenames = fs.readdirSync(dir, 'utf8') filenames.map(function (item, i) { if (item.endsWith('.js')) { @@ -17,10 +21,10 @@ function gatherCompilationResults (dir, compilationResult, callback) { if ('@sources' in testDef) { var sources = testDef['@sources']() for (var files in sources) { - compile(sources[files], true, function (result) { + compile(solcSnapshot, sources[files], true, function (result) { compilationResult[result.key] = result }) - compile(sources[files], false, function (result) { + compile(solcSnapshot, sources[files], false, function (result) { compilationResult[result.key] = result }) } @@ -30,11 +34,11 @@ function gatherCompilationResults (dir, compilationResult, callback) { return compilationResult } -function compile (source, optimization, addCompilationResult) { +function compile (solcSnapshot, source, optimization, addCompilationResult) { var missingInputs = [] try { var input = compilerInput(source, {optimize: optimization}) - var result = compiler.compileStandardWrapper(input, function (path) { + var result = solcSnapshot.compileStandardWrapper(input, function (path) { missingInputs.push(path) }) input = input.replace(/(\t)|(\n)|(\\n)|( )/g, '') @@ -51,15 +55,15 @@ function compile (source, optimization, addCompilationResult) { addCompilationResult(ret) } -function replaceSolCompiler (results) { +function replaceSolCompiler (results, solcSnapshot) { fs.readFile('./test-browser/mockcompiler/compiler.js', 'utf8', function (error, data) { if (error) { console.log(error) process.exit(1) return } - console.log(compiler.version()) - data = data + '\n\nvar mockCompilerVersion = \'' + compiler.version() + '\'' + console.log(solcSnapshot.version()) + data = data + '\n\nvar mockCompilerVersion = \'' + solcSnapshot.version() + '\'' data = data + '\n\nvar mockData = ' + JSON.stringify(results) + ';\n' fs.writeFile('./soljson.js', data, 'utf8', function (error) { if (error) { diff --git a/src/app/tabs/compile-tab.js b/src/app/tabs/compile-tab.js index f6d5a61892..f5b9aa5365 100644 --- a/src/app/tabs/compile-tab.js +++ b/src/app/tabs/compile-tab.js @@ -66,7 +66,7 @@ module.exports = class CompileTab { timeout: 300, allversions: null, selectedVersion: null, - defaultVersion: 'soljson-v0.5.1+commit.c8a2cb62.js', + defaultVersion: 'soljson-v0.5.1+commit.c8a2cb62.js', // this default version is defined: in makeMockCompiler (for browser test) and in package.json (downloadsolc_root) for the builtin compiler baseurl: 'https://solc-bin.ethereum.org/bin' } self.data.optimize = self._components.queryParams.get().optimize