Merge pull request #3517 from ethereum/fix_tests_accounts

Fix generating unit-tests accounts  lib
pull/5370/head
yann300 2 years ago committed by GitHub
commit 19e8cc066a
  1. 6
      apps/remix-ide/src/app/tabs/test-tab.js
  2. 1
      libs/remix-tests/sol/tests_accounts.sol.ts
  3. 11
      libs/remix-tests/src/compiler.ts
  4. 5
      libs/remix-ui/solidity-unit-testing/src/lib/solidity-unit-testing.tsx

@ -110,6 +110,8 @@ module.exports = class TestTab extends ViewPlugin {
*/ */
async testFromSource (content, path = 'browser/unit_test.sol') { async testFromSource (content, path = 'browser/unit_test.sol') {
const web3 = await this.call('blockchain', 'web3VM') const web3 = await this.call('blockchain', 'web3VM')
await this.testRunner.init(web3)
await this.createTestLibs()
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
const runningTest = {} const runningTest = {}
runningTest[path] = { content } runningTest[path] = { content }
@ -127,9 +129,7 @@ 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
})
}) })
} }

@ -5,7 +5,6 @@ pragma solidity >=0.4.22 <0.9.0;
library TestsAccounts { library TestsAccounts {
function getAccount(uint index) pure public returns (address) { function getAccount(uint index) pure public returns (address) {
>accounts< >accounts<
return accounts[index];
} }
} }
` `

@ -16,13 +16,16 @@ function regexIndexOf (inputString: string, regex: RegExp, startpos = 0) {
export function writeTestAccountsContract (accounts: string[]) { export function writeTestAccountsContract (accounts: string[]) {
const testAccountContract = require('../sol/tests_accounts.sol') // eslint-disable-line const testAccountContract = require('../sol/tests_accounts.sol') // eslint-disable-line
let body = `address[${accounts.length}] memory accounts;` let body = ''
if (!accounts.length) body += ';' if (accounts.length) {
else { body = `address[${accounts.length}] memory accounts;`
accounts.map((address, index) => { accounts.map((address, index) => {
body += `\n\t\taccounts[${index}] = ${address};\n` body += `\n\t\taccounts[${index}] = ${address};\n`
}) })
} body += `return accounts[index];`
} else {
body = `return address(0);`
}
return testAccountContract.replace('>accounts<', body) return testAccountContract.replace('>accounts<', body)
} }

@ -557,6 +557,9 @@ export const SolidityUnitTesting = (props: Record<string, any>) => { // eslint-d
const compilerData = await testTab.call('compilerArtefacts', 'getCompilerAbstract', file) const compilerData = await testTab.call('compilerArtefacts', 'getCompilerAbstract', file)
await testTab.call('compilerArtefacts', 'addResolvedContract', contractAddress, compilerData) await testTab.call('compilerArtefacts', 'addResolvedContract', contractAddress, compilerData)
} }
await testTab.testRunner.init(await testTab.call('blockchain', 'web3VM'))
await testTab.createTestLibs()
testTab.testRunner.runTestSources( testTab.testRunner.runTestSources(
runningTests, runningTests,
compilerConfig, compilerConfig,
@ -568,7 +571,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, web3: await testTab.call('blockchain', 'web3VM') } }, { testFilePath: testFilePath }
) )
}).catch((error: Error) => { }).catch((error: Error) => {
console.log(error) console.log(error)

Loading…
Cancel
Save