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