diff --git a/apps/debugger/src/app/debugger-api.ts b/apps/debugger/src/app/debugger-api.ts index 73c49b32e9..2c95ff9071 100644 --- a/apps/debugger/src/app/debugger-api.ts +++ b/apps/debugger/src/app/debugger-api.ts @@ -123,7 +123,10 @@ export const DebuggerApiMixin = (Base) => class extends Base { debug (hash, web3?) { 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) } diff --git a/apps/remix-ide-e2e/src/tests/solidityUnittests.spec.ts b/apps/remix-ide-e2e/src/tests/solidityUnittests.spec.ts index e5b835e1eb..0f28b9212d 100644 --- a/apps/remix-ide-e2e/src/tests/solidityUnittests.spec.ts +++ b/apps/remix-ide-e2e/src/tests/solidityUnittests.spec.ts @@ -487,7 +487,7 @@ const sources = [ }, 'tests/deployError_test.sol': { content: ` - pragma solidity ^0.7.0; + pragma solidity ^0.8.0; contract failingDeploy { constructor() { @@ -498,7 +498,7 @@ const sources = [ }, 'tests/methodFailure_test.sol': { content: ` - pragma solidity ^0.7.0; + pragma solidity ^0.8.0; contract methodfailure { function add(uint a, uint b) public { diff --git a/apps/remix-ide/src/app/tabs/test-tab.js b/apps/remix-ide/src/app/tabs/test-tab.js index c3ae979a6b..e68e4f2755 100644 --- a/apps/remix-ide/src/app/tabs/test-tab.js +++ b/apps/remix-ide/src/app/tabs/test-tab.js @@ -527,17 +527,22 @@ module.exports = class TestTab extends ViewPlugin { usingWorker: canUseWorker(currentVersion), runs } + const deployCb = async (file, contractAddress) => { + const compilerData = await this.call('compilerArtefacts', 'getCompilerAbstract', file) + await this.call('compilerArtefacts', 'addResolvedContract', contractAddress, compilerData) + } this.testRunner.runTestSources( runningTests, compilerConfig, (result) => this.testCallback(result, runningTests), (_err, result, cb) => this.resultsCallback(_err, result, cb), + deployCb, (error, result) => { this.updateFinalResult(error, result, testFilePath) callback(error) }, (url, cb) => { return this.contentImport.resolveAndSave(url).then((result) => cb(null, result)).catch((error) => cb(error.message)) - } + }, {testFilePath} ) }).catch((error) => { if (error) return // eslint-disable-line diff --git a/libs/remix-core-plugin/src/lib/compiler-artefacts.ts b/libs/remix-core-plugin/src/lib/compiler-artefacts.ts index da22ffb39e..52e1c7730b 100644 --- a/libs/remix-core-plugin/src/lib/compiler-artefacts.ts +++ b/libs/remix-core-plugin/src/lib/compiler-artefacts.ts @@ -4,7 +4,7 @@ import { CompilerAbstract } from '@remix-project/remix-solidity' const profile = { name: 'compilerArtefacts', - methods: ['get', 'addResolvedContract'], + methods: ['get', 'addResolvedContract', 'getCompilerAbstract'], events: [], version: '0.0.1' } diff --git a/libs/remix-tests/src/compiler.ts b/libs/remix-tests/src/compiler.ts index e77fdcdcfc..e15bb656e4 100644 --- a/libs/remix-tests/src/compiler.ts +++ b/libs/remix-tests/src/compiler.ts @@ -171,8 +171,9 @@ export function compileFileOrFiles (filename: string, isDirectory: boolean, opts * @param cb Callback */ 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 filepath = opts.testFilePath || '' // Iterate over sources keys. Inject test libraries. Inject test library import statements. if (!('remix_tests.sol' in sources) && !('tests.sol' in sources)) { sources['tests.sol'] = { content: require('../sol/tests.sol.js') } diff --git a/libs/remix-tests/src/deployer.ts b/libs/remix-tests/src/deployer.ts index aeefac3faa..47305b4a48 100644 --- a/libs/remix-tests/src/deployer.ts +++ b/libs/remix-tests/src/deployer.ts @@ -11,7 +11,7 @@ import { compilationInterface } from './types' * @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 contracts = {} let accounts: string[] = [] @@ -70,7 +70,7 @@ export function deployAll (compileResult: compilationInterface, web3: Web3, with deployObject.send({ from: accounts[0], gas: gas - }).on('receipt', function (receipt) { + }).on('receipt', async function (receipt) { contractObject.options.address = receipt.contractAddress contractObject.options.from = accounts[0] contractObject.options.gas = 5000 * 1000 @@ -79,6 +79,7 @@ export function deployAll (compileResult: compilationInterface, web3: Web3, with contracts[contractName] = contractObject 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 }).on('error', function (err) { console.error(err) diff --git a/libs/remix-tests/src/runTestFiles.ts b/libs/remix-tests/src/runTestFiles.ts index b447452f22..d9ed0c2b6e 100644 --- a/libs/remix-tests/src/runTestFiles.ts +++ b/libs/remix-tests/src/runTestFiles.ts @@ -61,13 +61,13 @@ export function runTestFiles (filepath: string, isDirectory: boolean, web3: Web3 for (const filename in asts) { 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 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 // accept deployment params from UI 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 else next(null, compilationResult, contracts) }) diff --git a/libs/remix-tests/src/runTestSources.ts b/libs/remix-tests/src/runTestSources.ts index 4894b713eb..ecc35aa3f2 100644 --- a/libs/remix-tests/src/runTestSources.ts +++ b/libs/remix-tests/src/runTestSources.ts @@ -39,7 +39,7 @@ export class UnitTestRunner { * @param importFileCb Import file callback * @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 || {} const sourceASTs: any = {} const web3 = opts.web3 || await this.createWeb3Provider() @@ -53,19 +53,19 @@ export class UnitTestRunner { }) }, (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) { for (const filename in asts) { 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 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 // accept deployment params from UI 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 else next(null, compilationResult, contracts) }) diff --git a/libs/remix-tests/src/types.ts b/libs/remix-tests/src/types.ts index 3c87babb48..fb03e94887 100644 --- a/libs/remix-tests/src/types.ts +++ b/libs/remix-tests/src/types.ts @@ -49,6 +49,7 @@ export interface ResultCbInterface { export interface Options { accounts?: string[] | null, + testFilePath?: string web3?: any }