|
|
|
@ -2,6 +2,26 @@ import async from 'async' |
|
|
|
|
import * as changeCase from 'change-case' |
|
|
|
|
import Web3 from 'web3' |
|
|
|
|
|
|
|
|
|
interface CbReturnInterface { |
|
|
|
|
type: string, |
|
|
|
|
value: any, |
|
|
|
|
time?: number, |
|
|
|
|
context?: string, |
|
|
|
|
errMsg?: string |
|
|
|
|
filename?: string |
|
|
|
|
} |
|
|
|
|
export interface ResultsInterface { |
|
|
|
|
passingNum: number, |
|
|
|
|
failureNum: number, |
|
|
|
|
timePassed: number |
|
|
|
|
} |
|
|
|
|
export interface TestCbInterface { |
|
|
|
|
(error: Error | null | undefined, result?: CbReturnInterface) : void; |
|
|
|
|
} |
|
|
|
|
export interface ResultCbInterface { |
|
|
|
|
(error: Error | null | undefined, result: ResultsInterface) : void; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function getFunctionFullName (signature, methodIdentifiers) { |
|
|
|
|
for (var method in methodIdentifiers) { |
|
|
|
|
if (signature.replace('0x', '') === methodIdentifiers[method].replace('0x', '')) { |
|
|
|
@ -53,12 +73,12 @@ function createRunList (jsonInterface) { |
|
|
|
|
return runList |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
export default function runTest (testName, testObject: any, contractDetails: any, opts: any, testCallback: Function, resultsCallback: Function) { |
|
|
|
|
export default function runTest (testName, testObject: any, contractDetails: any, opts: any, testCallback: TestCbInterface, resultsCallback: ResultCbInterface) { |
|
|
|
|
let runList = createRunList(testObject._jsonInterface) |
|
|
|
|
|
|
|
|
|
let passingNum = 0 |
|
|
|
|
let failureNum = 0 |
|
|
|
|
let timePassed = 0 |
|
|
|
|
let passingNum: number = 0 |
|
|
|
|
let failureNum: number = 0 |
|
|
|
|
let timePassed: number = 0 |
|
|
|
|
let web3 = new Web3() |
|
|
|
|
|
|
|
|
|
var userAgent = (typeof (navigator) !== 'undefined') && navigator.userAgent ? navigator.userAgent.toLowerCase() : '-' |
|
|
|
@ -70,8 +90,12 @@ export default function runTest (testName, testObject: any, contractDetails: any |
|
|
|
|
signale.warn('e.g: the following code won\'t work in the current context:') |
|
|
|
|
signale.warn('TestsAccounts.getAccount(' + opts.accounts.length + ')') |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
testCallback({type: 'contract', value: testName, filename: testObject.filename}) |
|
|
|
|
const resp: CbReturnInterface = { |
|
|
|
|
type: 'contract', |
|
|
|
|
value: testName, |
|
|
|
|
filename: testObject.filename |
|
|
|
|
} |
|
|
|
|
testCallback(undefined, resp) |
|
|
|
|
async.eachOfLimit(runList, 1, function (func, index, next) { |
|
|
|
|
let sender |
|
|
|
|
if (func.signature) { |
|
|
|
@ -89,29 +113,48 @@ export default function runTest (testName, testObject: any, contractDetails: any |
|
|
|
|
method.call(sendParams).then((result) => { |
|
|
|
|
let time = Math.ceil((Date.now() - startTime) / 1000.0) |
|
|
|
|
if (result) { |
|
|
|
|
testCallback({type: 'testPass', value: changeCase.sentenceCase(func.name), time: time, context: testName}) |
|
|
|
|
const resp: CbReturnInterface = { |
|
|
|
|
type: 'testPass', |
|
|
|
|
value: changeCase.sentenceCase(func.name), |
|
|
|
|
time: time, |
|
|
|
|
context: testName |
|
|
|
|
} |
|
|
|
|
testCallback(undefined, resp) |
|
|
|
|
passingNum += 1 |
|
|
|
|
timePassed += time |
|
|
|
|
} else { |
|
|
|
|
testCallback({type: 'testFailure', value: changeCase.sentenceCase(func.name), time: time, errMsg: 'function returned false', context: testName}) |
|
|
|
|
const resp: CbReturnInterface = { |
|
|
|
|
type: 'testFailure', |
|
|
|
|
value: changeCase.sentenceCase(func.name), |
|
|
|
|
time: time, |
|
|
|
|
errMsg: 'function returned false', |
|
|
|
|
context: testName |
|
|
|
|
} |
|
|
|
|
testCallback(undefined, resp) |
|
|
|
|
failureNum += 1 |
|
|
|
|
} |
|
|
|
|
next() |
|
|
|
|
}) |
|
|
|
|
} else { |
|
|
|
|
method.send(sendParams).on('receipt', function (receipt) { |
|
|
|
|
method.send(sendParams).on('receipt', (receipt) => { |
|
|
|
|
try { |
|
|
|
|
let time = Math.ceil((Date.now() - startTime) / 1000.0) |
|
|
|
|
let time: number = Math.ceil((Date.now() - startTime) / 1000.0) |
|
|
|
|
let topic = Web3.utils.sha3('AssertionEvent(bool,string)') |
|
|
|
|
|
|
|
|
|
let testPassed = false |
|
|
|
|
let testPassed: boolean = false |
|
|
|
|
|
|
|
|
|
for (let i in receipt.events) { |
|
|
|
|
let event = receipt.events[i] |
|
|
|
|
if (event.raw.topics.indexOf(topic) >= 0) { |
|
|
|
|
var testEvent = web3.eth.abi.decodeParameters(['bool', 'string'], event.raw.data) |
|
|
|
|
if (!testEvent[0]) { |
|
|
|
|
testCallback({type: 'testFailure', value: changeCase.sentenceCase(func.name), time: time, errMsg: testEvent[1], context: testName}) |
|
|
|
|
const resp: CbReturnInterface = { |
|
|
|
|
type: 'testFailure', |
|
|
|
|
value: changeCase.sentenceCase(func.name), |
|
|
|
|
time: time, |
|
|
|
|
errMsg: testEvent[1], |
|
|
|
|
context: testName |
|
|
|
|
}; |
|
|
|
|
testCallback(undefined, resp) |
|
|
|
|
failureNum += 1 |
|
|
|
|
return next() |
|
|
|
|
} |
|
|
|
@ -120,7 +163,13 @@ export default function runTest (testName, testObject: any, contractDetails: any |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (testPassed) { |
|
|
|
|
testCallback({type: 'testPass', value: changeCase.sentenceCase(func.name), time: time, context: testName}) |
|
|
|
|
const resp: CbReturnInterface = { |
|
|
|
|
type: 'testPass', |
|
|
|
|
value: changeCase.sentenceCase(func.name), |
|
|
|
|
time: time, |
|
|
|
|
context: testName |
|
|
|
|
} |
|
|
|
|
testCallback(undefined, resp) |
|
|
|
|
passingNum += 1 |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -130,7 +179,7 @@ export default function runTest (testName, testObject: any, contractDetails: any |
|
|
|
|
console.dir(err) |
|
|
|
|
return next(err) |
|
|
|
|
} |
|
|
|
|
}).on('error', function (err) { |
|
|
|
|
}).on('error', function (err: Error | null | undefined) { |
|
|
|
|
console.error(err) |
|
|
|
|
next(err) |
|
|
|
|
}) |
|
|
|
|