artifacts saved on deployment from SUT

pull/5370/head
Aniket-Engg 3 years ago committed by Aniket
parent b4e9edf650
commit 8d4b8456c2
  1. 5
      apps/debugger/src/app/debugger-api.ts
  2. 4
      apps/remix-ide-e2e/src/tests/solidityUnittests.spec.ts
  3. 7
      apps/remix-ide/src/app/tabs/test-tab.js
  4. 2
      libs/remix-core-plugin/src/lib/compiler-artefacts.ts
  5. 3
      libs/remix-tests/src/compiler.ts
  6. 5
      libs/remix-tests/src/deployer.ts
  7. 4
      libs/remix-tests/src/runTestFiles.ts
  8. 8
      libs/remix-tests/src/runTestSources.ts
  9. 1
      libs/remix-tests/src/types.ts

@ -123,7 +123,10 @@ export const DebuggerApiMixin = (Base) => class extends Base {
debug (hash, web3?) { debug (hash, web3?) {
this.debugHash = hash this.debugHash = hash
if (web3) remixDebug.init.extendWeb3(web3) if (web3) {
this._web3 = web3
remixDebug.init.extendWeb3(web3)
}
if (this.onDebugRequestedListener) this.onDebugRequestedListener(hash, web3) if (this.onDebugRequestedListener) this.onDebugRequestedListener(hash, web3)
} }

@ -487,7 +487,7 @@ const sources = [
}, },
'tests/deployError_test.sol': { 'tests/deployError_test.sol': {
content: ` content: `
pragma solidity ^0.7.0; pragma solidity ^0.8.0;
contract failingDeploy { contract failingDeploy {
constructor() { constructor() {
@ -498,7 +498,7 @@ const sources = [
}, },
'tests/methodFailure_test.sol': { 'tests/methodFailure_test.sol': {
content: ` content: `
pragma solidity ^0.7.0; pragma solidity ^0.8.0;
contract methodfailure { contract methodfailure {
function add(uint a, uint b) public { function add(uint a, uint b) public {

@ -527,17 +527,22 @@ module.exports = class TestTab extends ViewPlugin {
usingWorker: canUseWorker(currentVersion), usingWorker: canUseWorker(currentVersion),
runs runs
} }
const deployCb = async (file, contractAddress) => {
const compilerData = await this.call('compilerArtefacts', 'getCompilerAbstract', file)
await this.call('compilerArtefacts', 'addResolvedContract', contractAddress, compilerData)
}
this.testRunner.runTestSources( this.testRunner.runTestSources(
runningTests, runningTests,
compilerConfig, compilerConfig,
(result) => this.testCallback(result, runningTests), (result) => this.testCallback(result, runningTests),
(_err, result, cb) => this.resultsCallback(_err, result, cb), (_err, result, cb) => this.resultsCallback(_err, result, cb),
deployCb,
(error, result) => { (error, result) => {
this.updateFinalResult(error, result, testFilePath) this.updateFinalResult(error, result, testFilePath)
callback(error) callback(error)
}, (url, cb) => { }, (url, cb) => {
return this.contentImport.resolveAndSave(url).then((result) => cb(null, result)).catch((error) => cb(error.message)) return this.contentImport.resolveAndSave(url).then((result) => cb(null, result)).catch((error) => cb(error.message))
} }, {testFilePath}
) )
}).catch((error) => { }).catch((error) => {
if (error) return // eslint-disable-line if (error) return // eslint-disable-line

@ -4,7 +4,7 @@ import { CompilerAbstract } from '@remix-project/remix-solidity'
const profile = { const profile = {
name: 'compilerArtefacts', name: 'compilerArtefacts',
methods: ['get', 'addResolvedContract'], methods: ['get', 'addResolvedContract', 'getCompilerAbstract'],
events: [], events: [],
version: '0.0.1' version: '0.0.1'
} }

@ -171,8 +171,9 @@ export function compileFileOrFiles (filename: string, isDirectory: boolean, opts
* @param cb Callback * @param cb Callback
*/ */
export function compileContractSources (sources: SrcIfc, compilerConfig: CompilerConfiguration, importFileCb: any, opts: any, cb): void { export function compileContractSources (sources: SrcIfc, compilerConfig: CompilerConfiguration, importFileCb: any, opts: any, cb): void {
let compiler, filepath: string let compiler
const accounts: string[] = opts.accounts || [] const accounts: string[] = opts.accounts || []
const filepath = opts.testFilePath || ''
// Iterate over sources keys. Inject test libraries. Inject test library import statements. // Iterate over sources keys. Inject test libraries. Inject test library import statements.
if (!('remix_tests.sol' in sources) && !('tests.sol' in sources)) { if (!('remix_tests.sol' in sources) && !('tests.sol' in sources)) {
sources['tests.sol'] = { content: require('../sol/tests.sol.js') } sources['tests.sol'] = { content: require('../sol/tests.sol.js') }

@ -11,7 +11,7 @@ import { compilationInterface } from './types'
* @param callback Callback * @param callback Callback
*/ */
export function deployAll (compileResult: compilationInterface, web3: Web3, withDoubleGas: boolean, callback) { export function deployAll (compileResult: compilationInterface, web3: Web3, withDoubleGas: boolean, deployCb, callback) {
const compiledObject = {} const compiledObject = {}
const contracts = {} const contracts = {}
let accounts: string[] = [] let accounts: string[] = []
@ -70,7 +70,7 @@ export function deployAll (compileResult: compilationInterface, web3: Web3, with
deployObject.send({ deployObject.send({
from: accounts[0], from: accounts[0],
gas: gas gas: gas
}).on('receipt', function (receipt) { }).on('receipt', async function (receipt) {
contractObject.options.address = receipt.contractAddress contractObject.options.address = receipt.contractAddress
contractObject.options.from = accounts[0] contractObject.options.from = accounts[0]
contractObject.options.gas = 5000 * 1000 contractObject.options.gas = 5000 * 1000
@ -79,6 +79,7 @@ export function deployAll (compileResult: compilationInterface, web3: Web3, with
contracts[contractName] = contractObject contracts[contractName] = contractObject
contracts[contractName].filename = filename contracts[contractName].filename = filename
if(deployCb) await deployCb(filename, receipt.contractAddress)
callback(null, { receipt: { contractAddress: receipt.contractAddress } }) // TODO this will only work with JavaScriptV VM callback(null, { receipt: { contractAddress: receipt.contractAddress } }) // TODO this will only work with JavaScriptV VM
}).on('error', function (err) { }).on('error', function (err) {
console.error(err) console.error(err)

@ -61,13 +61,13 @@ export function runTestFiles (filepath: string, isDirectory: boolean, web3: Web3
for (const filename in asts) { for (const filename in asts) {
if (filename.endsWith('_test.sol')) { sourceASTs[filename] = asts[filename].ast } if (filename.endsWith('_test.sol')) { sourceASTs[filename] = asts[filename].ast }
} }
deployAll(compilationResult, web3, false, (err, contracts) => { deployAll(compilationResult, web3, false, null, (err, contracts) => {
if (err) { if (err) {
// If contract deployment fails because of 'Out of Gas' error, try again with double gas // If contract deployment fails because of 'Out of Gas' error, try again with double gas
// This is temporary, should be removed when remix-tests will have a dedicated UI to // This is temporary, should be removed when remix-tests will have a dedicated UI to
// accept deployment params from UI // accept deployment params from UI
if (err.message.includes('The contract code couldn\'t be stored, please check your gas limit')) { if (err.message.includes('The contract code couldn\'t be stored, please check your gas limit')) {
deployAll(compilationResult, web3, true, (error, contracts) => { deployAll(compilationResult, web3, true, null, (error, contracts) => {
if (error) next([{ message: 'contract deployment failed after trying twice: ' + error.message, severity: 'error' }]) // IDE expects errors in array if (error) next([{ message: 'contract deployment failed after trying twice: ' + error.message, severity: 'error' }]) // IDE expects errors in array
else next(null, compilationResult, contracts) else next(null, compilationResult, contracts)
}) })

@ -39,7 +39,7 @@ export class UnitTestRunner {
* @param importFileCb Import file callback * @param importFileCb Import file callback
* @param opts Options * @param opts Options
*/ */
async runTestSources (contractSources: SrcIfc, compilerConfig: CompilerConfiguration, testCallback, resultCallback, finalCallback: any, importFileCb, opts: Options) { async runTestSources (contractSources: SrcIfc, compilerConfig: CompilerConfiguration, testCallback, resultCallback, deployCb:any, finalCallback: any, importFileCb, opts: Options) {
opts = opts || {} opts = opts || {}
const sourceASTs: any = {} const sourceASTs: any = {}
const web3 = opts.web3 || await this.createWeb3Provider() const web3 = opts.web3 || await this.createWeb3Provider()
@ -53,19 +53,19 @@ export class UnitTestRunner {
}) })
}, },
(next) => { (next) => {
compileContractSources(contractSources, compilerConfig, importFileCb, { accounts, event: this.event }, next) compileContractSources(contractSources, compilerConfig, importFileCb, { accounts, testFilePath: opts.testFilePath, event: this.event }, next)
}, },
function deployAllContracts (compilationResult: compilationInterface, asts: ASTInterface, next) { function deployAllContracts (compilationResult: compilationInterface, asts: ASTInterface, next) {
for (const filename in asts) { for (const filename in asts) {
if (filename.endsWith('_test.sol')) { sourceASTs[filename] = asts[filename].ast } if (filename.endsWith('_test.sol')) { sourceASTs[filename] = asts[filename].ast }
} }
deployAll(compilationResult, web3, false, (err, contracts) => { deployAll(compilationResult, web3, false, deployCb, (err, contracts) => {
if (err) { if (err) {
// If contract deployment fails because of 'Out of Gas' error, try again with double gas // If contract deployment fails because of 'Out of Gas' error, try again with double gas
// This is temporary, should be removed when remix-tests will have a dedicated UI to // This is temporary, should be removed when remix-tests will have a dedicated UI to
// accept deployment params from UI // accept deployment params from UI
if (err.message.includes('The contract code couldn\'t be stored, please check your gas limit')) { if (err.message.includes('The contract code couldn\'t be stored, please check your gas limit')) {
deployAll(compilationResult, web3, true, (error, contracts) => { deployAll(compilationResult, web3, true, deployCb, (error, contracts) => {
if (error) next([{ message: 'contract deployment failed after trying twice: ' + error.message, severity: 'error' }]) // IDE expects errors in array if (error) next([{ message: 'contract deployment failed after trying twice: ' + error.message, severity: 'error' }]) // IDE expects errors in array
else next(null, compilationResult, contracts) else next(null, compilationResult, contracts)
}) })

@ -49,6 +49,7 @@ export interface ResultCbInterface {
export interface Options { export interface Options {
accounts?: string[] | null, accounts?: string[] | null,
testFilePath?: string
web3?: any web3?: any
} }

Loading…
Cancel
Save