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