use current VM for testing instead of instanciating a new one

pull/3262/head^2
yann300 2 years ago committed by Aniket
parent f58bab81bf
commit 5fc107b67f
  1. 1
      apps/remix-ide-e2e/src/commands/checkVariableDebug.ts
  2. 4
      apps/remix-ide/src/app/tabs/test-tab.js
  3. 6
      apps/remix-ide/src/blockchain/blockchain.js
  4. 5
      libs/remix-tests/src/runTestSources.ts
  5. 4
      libs/remix-ui/solidity-unit-testing/src/lib/solidity-unit-testing.tsx

@ -29,6 +29,7 @@ function checkDebug(browser: NightwatchBrowser, id: string, debugValue: Nightwat
}, [id], (result) => { }, [id], (result) => {
if (result.value) { if (result.value) {
try { try {
console.log('checkDebug', result.value)
resultOfElement = JSON.parse(<string>result.value) resultOfElement = JSON.parse(<string>result.value)
isEqual = deepequal(debugValue, resultOfElement) isEqual = deepequal(debugValue, resultOfElement)
} catch (e) { } catch (e) {

@ -109,7 +109,7 @@ module.exports = class TestTab extends ViewPlugin {
Test is not associated with the UI Test is not associated with the UI
*/ */
testFromSource (content, path = 'browser/unit_test.sol') { testFromSource (content, path = 'browser/unit_test.sol') {
return new Promise((resolve, reject) => { return new Promise(async (resolve, reject) => {
const runningTest = {} const runningTest = {}
runningTest[path] = { content } runningTest[path] = { content }
const { currentVersion, evmVersion, optimize, runs } = this.compileTab.getCurrentCompilerConfig() const { currentVersion, evmVersion, optimize, runs } = this.compileTab.getCurrentCompilerConfig()
@ -126,6 +126,8 @@ module.exports = class TestTab extends ViewPlugin {
resolve(result) resolve(result)
}, (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))
}, {
web3: await this.call('blockchain', 'web3VM')
}) })
}) })
} }

@ -22,7 +22,7 @@ const profile = {
name: 'blockchain', name: 'blockchain',
displayName: 'Blockchain', displayName: 'Blockchain',
description: 'Blockchain - Logic', description: 'Blockchain - Logic',
methods: ['getCode', 'getTransactionReceipt', 'addProvider', 'removeProvider'], methods: ['getCode', 'getTransactionReceipt', 'addProvider', 'removeProvider', 'getCurrentFork', 'web3VM'],
version: packageJson.version version: packageJson.version
} }
@ -401,6 +401,10 @@ export class Blockchain extends Plugin {
this.getCurrentProvider().signMessage(message, account, passphrase, cb) this.getCurrentProvider().signMessage(message, account, passphrase, cb)
} }
web3VM () {
return this.providers.vm.web3
}
web3 () { web3 () {
// @todo(https://github.com/ethereum/remix-project/issues/431) // @todo(https://github.com/ethereum/remix-project/issues/431)
const isVM = this.getProvider() === 'vm' const isVM = this.getProvider() === 'vm'

@ -30,10 +30,7 @@ export class UnitTestRunner {
} }
async createWeb3Provider (optWeb3) { async createWeb3Provider (optWeb3) {
const web3 = optWeb3 || new Web3() const web3 = optWeb3
const provider: any = new Provider()
await provider.init()
web3.setProvider(provider)
extend(web3) extend(web3)
return web3 return web3
} }

@ -537,7 +537,7 @@ export const SolidityUnitTesting = (props: Record<string, any>) => { // eslint-d
updateFinalResult(null, null, testFilePath) updateFinalResult(null, null, testFilePath)
return return
} }
testTab.fileManager.readFile(testFilePath).then((content: string) => { testTab.fileManager.readFile(testFilePath).then(async (content: string) => {
const runningTests: Record<string, Record<string, string>> = {} const runningTests: Record<string, Record<string, string>> = {}
runningTests[testFilePath] = { content } runningTests[testFilePath] = { content }
filesContent[testFilePath] = { content } filesContent[testFilePath] = { content }
@ -565,7 +565,7 @@ export const SolidityUnitTesting = (props: Record<string, any>) => { // eslint-d
callback(error) callback(error)
}, (url: string, cb: any) => { // eslint-disable-line @typescript-eslint/no-explicit-any }, (url: string, cb: any) => { // eslint-disable-line @typescript-eslint/no-explicit-any
return testTab.contentImport.resolveAndSave(url).then((result: any) => cb(null, result)).catch((error: Error) => cb(error.message)) // eslint-disable-line @typescript-eslint/no-explicit-any return testTab.contentImport.resolveAndSave(url).then((result: any) => cb(null, result)).catch((error: Error) => cb(error.message)) // eslint-disable-line @typescript-eslint/no-explicit-any
}, { testFilePath } }, { testFilePath: testFilePath, web3: await testTab.call('blockchain', 'web3VM') }
) )
}).catch((error: Error) => { }).catch((error: Error) => {
console.log(error) console.log(error)

Loading…
Cancel
Save