|
|
|
@ -6,6 +6,11 @@ import { Compiler as RemixCompiler } from '@remix-project/remix-solidity' |
|
|
|
|
import { SrcIfc, CompilerConfiguration, CompilationErrors } from './types' |
|
|
|
|
const logger = new Log() |
|
|
|
|
const log = logger.logger |
|
|
|
|
var accountsLibCode |
|
|
|
|
|
|
|
|
|
export function getAccountsLib () { |
|
|
|
|
return accountsLibCode |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function regexIndexOf (inputString: string, regex: RegExp, startpos = 0) { |
|
|
|
|
const indexOf = inputString.substring(startpos).search(regex) |
|
|
|
@ -18,10 +23,10 @@ function writeTestAccountsContract (accounts: string[]) { |
|
|
|
|
if (!accounts.length) body += ';' |
|
|
|
|
else { |
|
|
|
|
accounts.map((address, index) => { |
|
|
|
|
body += `\naccounts[${index}] = ${address};\n` |
|
|
|
|
body += `\n\t\taccounts[${index}] = ${address};\n` |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
return testAccountContract.replace('>accounts<', body) |
|
|
|
|
accountsLibCode = testAccountContract.replace('>accounts<', body) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
@ -87,10 +92,11 @@ const isBrowser = !(typeof (window) === 'undefined' || userAgent.indexOf(' elect |
|
|
|
|
export function compileFileOrFiles (filename: string, isDirectory: boolean, opts: any, compilerConfig: CompilerConfiguration, cb): void { |
|
|
|
|
let compiler: any |
|
|
|
|
const accounts: string[] = opts.accounts || [] |
|
|
|
|
writeTestAccountsContract(accounts) |
|
|
|
|
const sources: SrcIfc = { |
|
|
|
|
'tests.sol': { content: require('../sol/tests.sol') }, |
|
|
|
|
'remix_tests.sol': { content: require('../sol/tests.sol') }, |
|
|
|
|
'remix_accounts.sol': { content: writeTestAccountsContract(accounts) } |
|
|
|
|
'remix_accounts.sol': { content: getAccountsLib() } |
|
|
|
|
} |
|
|
|
|
const filepath: string = (isDirectory ? filename : path.dirname(filename)) |
|
|
|
|
try { |
|
|
|
@ -173,13 +179,8 @@ export function compileFileOrFiles (filename: string, isDirectory: boolean, opts |
|
|
|
|
export function compileContractSources (sources: SrcIfc, compilerConfig: CompilerConfiguration, importFileCb: any, opts: any, cb): void { |
|
|
|
|
let compiler |
|
|
|
|
const accounts: string[] = opts.accounts || [] |
|
|
|
|
writeTestAccountsContract(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') } |
|
|
|
|
// sources['remix_tests.sol'] = { content: require('../sol/tests.sol.js') }
|
|
|
|
|
sources['remix_accounts.sol'] = { content: writeTestAccountsContract(accounts) } |
|
|
|
|
} |
|
|
|
|
const testFileImportRegEx = /^(import)\s['"](remix_tests.sol|tests.sol)['"];/gm |
|
|
|
|
|
|
|
|
|
const includeTestLibs = '\nimport \'remix_tests.sol\';\n' |
|
|
|
|