custom compiler in progress

pull/5370/head
aniket-engg 4 years ago
parent f939d24731
commit 8f2c450ce7
  1. 35
      libs/remix-solidity/src/compiler/compiler.ts
  2. 2
      libs/remix-tests/package.json
  3. 9
      libs/remix-tests/src/compiler.ts
  4. 2
      libs/remix-tests/src/run.ts
  5. 14
      libs/remix-tests/tests/testRunner.cli.spec.ts

@ -163,6 +163,41 @@ export class Compiler {
}
}
/**
* @dev Load compiler using given version (used by remix-tests CLI)
* @param version compiler version
*/
loadRemoteVersion (version: string): void {
console.log('Loading remote solc version ' + version)
const compiler: any = require('solc')
compiler.loadRemoteVersion(version, (err, remoteCompiler) => {
if (err) {
console.error('Error in loading remote solc compiler: ', err)
} else {
this.state.compileJSON = (source: SourceWithTarget) => {
const missingInputs: string[] = []
const missingInputsCallback = (path: string) => {
missingInputs.push(path)
return { error: 'Deferred import' }
}
let result: CompilationResult = {}
try {
if(source && source.sources) {
const {optimize, runs, evmVersion, language} = this.state
const input = compilerInput(source.sources, {optimize, runs, evmVersion, language})
result = JSON.parse(remoteCompiler.compile(input, { import: missingInputsCallback }))
}
} catch (exception) {
result = { error: { formattedMessage: 'Uncaught JavaScript exception:\n' + exception, severity: 'error', mode: 'panic' } }
}
this.onCompilationFinished(result, missingInputs, source)
}
this.onCompilerLoaded(version)
}
})
}
/**
* @dev Load compiler using given URL (used by IDE)
* @param usingWorker if true, load compiler using worker

@ -37,7 +37,7 @@
"dependencies": {
"@remix-project/remix-lib": "^0.4.31",
"@remix-project/remix-simulator": "^0.1.9-beta.8",
"@remix-project/remix-solidity": "^0.3.32",
"@remix-project/remix-solidity": "file:../remix-solidity",
"ansi-gray": "^0.1.1",
"async": "^2.6.0",
"change-case": "^3.0.1",

@ -130,11 +130,10 @@ export function compileFileOrFiles(filename: string, isDirectory: boolean, opts:
evmVersion ? compiler.set('evmVersion', evmVersion) :
optimize ? compiler.set('optimize', optimize) :
runs ? compiler.set('runs', runs) :
currentCompilerUrl ? compiler.loadVersion('false', currentCompilerUrl) :
compiler.onInternalCompilerLoaded()
// compiler.event.register('compilerLoaded', this, function (version) {
next()
// });
currentCompilerUrl ? compiler.loadRemoteVersion(currentCompilerUrl) : compiler.onInternalCompilerLoaded()
compiler.event.register('compilerLoaded', this, function (version) {
next()
});
},
function doCompilation(next) {
// @ts-ignore

@ -89,7 +89,7 @@ commander
process.exit()
} else {
log.info(`Compiler version set to ${compVersion}. Latest version is ${latestRelease}`)
compilerConfig.currentCompilerUrl = baseURL + '/' + compString
compilerConfig.currentCompilerUrl = compString.replace('soljson-', '').replace('.js', '')
}
}

@ -50,5 +50,19 @@ Commands:
expect(res.stdout.toString().trim()).toMatch(/expected value to be ok to: true/)
expect(res.stdout.toString().trim()).toMatch(/returned: false/)
})
test('remix-tests running a test file with custom compiler version', () => {
const res = spawnSync(executablePath, ['--compiler', '0.7.4', resolve(__dirname + '/examples_0/assert_ok_test.sol')])
console.log('res.stdout.toString().trim()---------->', res.stdout.toString().trim())
// match initial lines
expect(res.stdout.toString().trim()).toMatch(/Loading remote solc version v0.7.4+commit.3f05b770/)
expect(res.stdout.toString().trim()).toMatch(/:: Running remix-tests - Unit testing for solidity ::/)
expect(res.stdout.toString().trim()).toMatch(/creation of library remix_tests.sol:Assert pending.../)
// match test result
expect(res.stdout.toString().trim()).toMatch(/Ok pass test/)
expect(res.stdout.toString().trim()).toMatch(/Ok fail test/)
// macth fail test details
expect(res.stdout.toString().trim()).toMatch(/error: okFailTest fails/)
})
})
})
Loading…
Cancel
Save