feat(remix-tests): add optimization flag to CLI

Adds an optimize flag to the commander CLI config which generates a
CompilerConfiguration object and passes it down the line to the
compiler optionally.
pull/5370/head
Adasauce 4 years ago committed by aniket-engg
parent 9a828cab20
commit fe9fe766ab
  1. 6
      libs/remix-tests/src/compiler.ts
  2. 19
      libs/remix-tests/src/run.ts
  3. 7
      libs/remix-tests/src/runTestFiles.ts

@ -85,7 +85,7 @@ const isBrowser = !(typeof (window) === 'undefined' || userAgent.indexOf(' elect
* TODO: replace this with remix's own compiler code * TODO: replace this with remix's own compiler code
*/ */
export function compileFileOrFiles(filename: string, isDirectory: boolean, opts: any, cb): void { export function compileFileOrFiles(filename: string, isDirectory: boolean, opts: any, compilerConfig: CompilerConfiguration, cb): void {
let compiler: any let compiler: any
const accounts: string[] = opts.accounts || [] const accounts: string[] = opts.accounts || []
const sources: SrcIfc = { const sources: SrcIfc = {
@ -125,7 +125,11 @@ export function compileFileOrFiles(filename: string, isDirectory: boolean, opts:
} finally { } finally {
async.waterfall([ async.waterfall([
function loadCompiler(next) { function loadCompiler(next) {
const {currentCompilerUrl, evmVersion, optimize, usingWorker} = compilerConfig
compiler = new RemixCompiler() compiler = new RemixCompiler()
compiler.set('evmVersion', evmVersion)
compiler.set('optimize', optimize)
// compiler.loadVersion(usingWorker, currentCompilerUrl)
compiler.onInternalCompilerLoaded() compiler.onInternalCompilerLoaded()
// compiler.event.register('compilerLoaded', this, function (version) { // compiler.event.register('compilerLoaded', this, function (version) {
next() next()

@ -4,6 +4,7 @@ import path from 'path'
import { runTestFiles } from './runTestFiles' import { runTestFiles } from './runTestFiles'
import fs from './fileSystem' import fs from './fileSystem'
import { Provider } from '@remix-project/remix-simulator' import { Provider } from '@remix-project/remix-simulator'
import { CompilerConfiguration } from './types'
import Log from './logger' import Log from './logger'
const logger = new Log() const logger = new Log()
const log = logger.logger const log = logger.logger
@ -21,6 +22,15 @@ function mapVerbosity (v: number) {
} }
return levels[v] return levels[v]
} }
function mapOptimize (v: string) {
const optimize = {
'true': true,
'false': false
}
return optimize[v];
}
const version = require('../package.json').version const version = require('../package.json').version
commander.version(version) commander.version(version)
@ -36,6 +46,7 @@ commander.command('help').description('output usage information').action(functio
// get current version // get current version
commander commander
.option('-v, --verbose <level>', 'run with verbosity', mapVerbosity) .option('-v, --verbose <level>', 'run with verbosity', mapVerbosity)
.option('-o, --optimize <bool>', 'run compiler optimization', mapOptimize)
.action(async (testsPath) => { .action(async (testsPath) => {
// Check if path exists // Check if path exists
@ -67,7 +78,13 @@ commander
await provider.init() await provider.init()
web3.setProvider(provider) web3.setProvider(provider)
runTestFiles(path.resolve(testsPath), isDirectory, web3) const compilerConfig = {} as CompilerConfiguration
if (commander.optimize) {
compilerConfig.optimize = commander.optimize
log.info('compiler optimization set to ' + compilerConfig.optimize)
}
runTestFiles(path.resolve(testsPath), isDirectory, web3, compilerConfig)
}) })
if (!process.argv.slice(2).length) { if (!process.argv.slice(2).length) {

@ -1,7 +1,7 @@
import async from 'async' import async from 'async'
import fs from './fileSystem' import fs from './fileSystem'
import { runTest } from './testRunner' import { runTest } from './testRunner'
import { TestResultInterface, ResultsInterface, compilationInterface, ASTInterface, Options, AstNode } from './types' import { TestResultInterface, ResultsInterface, CompilerConfiguration, compilationInterface, ASTInterface, Options, AstNode } from './types'
import colors from 'colors' import colors from 'colors'
import Web3 from 'web3'; import Web3 from 'web3';
@ -18,8 +18,9 @@ import { deployAll } from './deployer'
*/ */
// eslint-disable-next-line @typescript-eslint/no-empty-function // eslint-disable-next-line @typescript-eslint/no-empty-function
export function runTestFiles(filepath: string, isDirectory: boolean, web3: Web3, finalCallback: any = () => {}, opts?: Options) { export function runTestFiles(filepath: string, isDirectory: boolean, web3: Web3, compilerConfig: CompilerConfiguration, finalCallback: any = () => {}, opts?: Options) {
opts = opts || {} opts = opts || {}
compilerConfig = compilerConfig || {} as CompilerConfiguration
const sourceASTs: any = {} const sourceASTs: any = {}
const { Signale } = require('signale') const { Signale } = require('signale')
// signale configuration // signale configuration
@ -53,7 +54,7 @@ export function runTestFiles(filepath: string, isDirectory: boolean, web3: Web3,
}) })
}, },
function compile(next) { function compile(next) {
compileFileOrFiles(filepath, isDirectory, { accounts }, next) compileFileOrFiles(filepath, isDirectory, { accounts }, compilerConfig, next)
}, },
function deployAllContracts (compilationResult: compilationInterface, asts: ASTInterface, next) { function deployAllContracts (compilationResult: compilationInterface, asts: ASTInterface, next) {
// Extract AST of test contract file source // Extract AST of test contract file source

Loading…
Cancel
Save