|
|
@ -19,26 +19,45 @@ function getOverridedSender (userdoc, signature: string, methodIdentifiers) { |
|
|
|
return fullName && accountIndex ? accountIndex[1] : null |
|
|
|
return fullName && accountIndex ? accountIndex[1] : null |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function getAvailableFunctions (fileAST, testContractName) { |
|
|
|
/** |
|
|
|
let contractAST: any[] = fileAST.nodes.filter(node => node.name === testContractName && node.nodeType === 'ContractDefinition') |
|
|
|
* @dev returns functions of a test contract file in same sequence they appear in file (using passed AST) |
|
|
|
let funcNodes: any[] = contractAST[0].nodes.filter(node => node.kind === 'function' && node.nodeType === "FunctionDefinition") |
|
|
|
* @param fileAST AST of test contract file source |
|
|
|
let funcList: string[] = funcNodes.map(node => node.name) |
|
|
|
* @param testContractName Name of test contract |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function getAvailableFunctions (fileAST: any, testContractName: string) { |
|
|
|
|
|
|
|
const contractAST: any[] = fileAST.nodes.filter(node => node.name === testContractName && node.nodeType === 'ContractDefinition') |
|
|
|
|
|
|
|
const funcNodes: any[] = contractAST[0].nodes.filter(node => node.kind === 'function' && node.nodeType === "FunctionDefinition") |
|
|
|
|
|
|
|
const funcList: string[] = funcNodes.map(node => node.name) |
|
|
|
return funcList; |
|
|
|
return funcList; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function getTestFunctionsInterface (jsonInterface, funcList: string[]) { |
|
|
|
/** |
|
|
|
let resutantInterface: any[] = [] |
|
|
|
* @dev returns ABI of passed method list from passed interface |
|
|
|
let specialFunctions = ['beforeAll', 'beforeEach', 'afterAll', 'afterEach'] |
|
|
|
* @param jsonInterface Json Interface |
|
|
|
|
|
|
|
* @param funcList Methods to extract the interface of |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function getTestFunctionsInterface (jsonInterface: any, funcList: string[]) { |
|
|
|
|
|
|
|
let functionsInterface: any[] = [] |
|
|
|
|
|
|
|
const specialFunctions = ['beforeAll', 'beforeEach', 'afterAll', 'afterEach'] |
|
|
|
for(const func of funcList){ |
|
|
|
for(const func of funcList){ |
|
|
|
if(!specialFunctions.includes(func)) |
|
|
|
if(!specialFunctions.includes(func)) |
|
|
|
resutantInterface.push(jsonInterface.find(node => node.type === 'function' && node.name === func)) |
|
|
|
functionsInterface.push(jsonInterface.find(node => node.type === 'function' && node.name === func)) |
|
|
|
} |
|
|
|
} |
|
|
|
return resutantInterface |
|
|
|
return functionsInterface |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function createRunList (jsonInterface, fileAST, testContractName): RunListInterface[] { |
|
|
|
/** |
|
|
|
let availableFunctions = getAvailableFunctions(fileAST, testContractName) |
|
|
|
* @dev Prepare a list of tests to run using test contract file ABI, AST & contract name |
|
|
|
let testFunctionsInterface = getTestFunctionsInterface(jsonInterface, availableFunctions) |
|
|
|
* @param jsonInterface File JSON interface |
|
|
|
|
|
|
|
* @param fileAST File AST |
|
|
|
|
|
|
|
* @param testContractName Test contract name |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function createRunList (jsonInterface: any, fileAST: any, testContractName: string): RunListInterface[] { |
|
|
|
|
|
|
|
const availableFunctions: string[] = getAvailableFunctions(fileAST, testContractName) |
|
|
|
|
|
|
|
const testFunctionsInterface: any[] = getTestFunctionsInterface(jsonInterface, availableFunctions) |
|
|
|
|
|
|
|
|
|
|
|
let runList: RunListInterface[] = [] |
|
|
|
let runList: RunListInterface[] = [] |
|
|
|
|
|
|
|
|
|
|
@ -46,7 +65,7 @@ function createRunList (jsonInterface, fileAST, testContractName): RunListInterf |
|
|
|
runList.push({ name: 'beforeAll', type: 'internal', constant: false }) |
|
|
|
runList.push({ name: 'beforeAll', type: 'internal', constant: false }) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
for (let func of testFunctionsInterface) { |
|
|
|
for (const func of testFunctionsInterface) { |
|
|
|
if (availableFunctions.indexOf('beforeEach') >= 0) { |
|
|
|
if (availableFunctions.indexOf('beforeEach') >= 0) { |
|
|
|
runList.push({ name: 'beforeEach', type: 'internal', constant: false }) |
|
|
|
runList.push({ name: 'beforeEach', type: 'internal', constant: false }) |
|
|
|
} |
|
|
|
} |
|
|
@ -64,11 +83,11 @@ function createRunList (jsonInterface, fileAST, testContractName): RunListInterf |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export function runTest (testName, testObject: any, contractDetails: any, fileAST: any, opts: any, testCallback: TestCbInterface, resultsCallback: ResultCbInterface) { |
|
|
|
export function runTest (testName, testObject: any, contractDetails: any, fileAST: any, opts: any, testCallback: TestCbInterface, resultsCallback: ResultCbInterface) { |
|
|
|
let runList = createRunList(testObject._jsonInterface, fileAST, testName) |
|
|
|
const runList: RunListInterface[] = createRunList(testObject._jsonInterface, fileAST, testName) |
|
|
|
let passingNum: number = 0 |
|
|
|
let passingNum: number = 0 |
|
|
|
let failureNum: number = 0 |
|
|
|
let failureNum: number = 0 |
|
|
|
let timePassed: number = 0 |
|
|
|
let timePassed: number = 0 |
|
|
|
let web3 = new Web3() |
|
|
|
const web3 = new Web3() |
|
|
|
|
|
|
|
|
|
|
|
const accts: TestResultInterface = { |
|
|
|
const accts: TestResultInterface = { |
|
|
|
type: 'accountList', |
|
|
|
type: 'accountList', |
|
|
@ -95,11 +114,11 @@ export function runTest (testName, testObject: any, contractDetails: any, fileAS |
|
|
|
let sendParams |
|
|
|
let sendParams |
|
|
|
if (sender) sendParams = { from: sender } |
|
|
|
if (sender) sendParams = { from: sender } |
|
|
|
|
|
|
|
|
|
|
|
let method = testObject.methods[func.name].apply(testObject.methods[func.name], []) |
|
|
|
const method = testObject.methods[func.name].apply(testObject.methods[func.name], []) |
|
|
|
let startTime = Date.now() |
|
|
|
const startTime = Date.now() |
|
|
|
if (func.constant) { |
|
|
|
if (func.constant) { |
|
|
|
method.call(sendParams).then((result) => { |
|
|
|
method.call(sendParams).then((result) => { |
|
|
|
let time = (Date.now() - startTime) / 1000.0 |
|
|
|
const time = (Date.now() - startTime) / 1000.0 |
|
|
|
if (result) { |
|
|
|
if (result) { |
|
|
|
const resp: TestResultInterface = { |
|
|
|
const resp: TestResultInterface = { |
|
|
|
type: 'testPass', |
|
|
|
type: 'testPass', |
|
|
@ -126,12 +145,12 @@ export function runTest (testName, testObject: any, contractDetails: any, fileAS |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
method.send(sendParams).on('receipt', (receipt) => { |
|
|
|
method.send(sendParams).on('receipt', (receipt) => { |
|
|
|
try { |
|
|
|
try { |
|
|
|
let time: number = (Date.now() - startTime) / 1000.0 |
|
|
|
const time: number = (Date.now() - startTime) / 1000.0 |
|
|
|
let topic = Web3.utils.sha3('AssertionEvent(bool,string)') |
|
|
|
const topic = Web3.utils.sha3('AssertionEvent(bool,string)') |
|
|
|
let testPassed: boolean = false |
|
|
|
let testPassed: boolean = false |
|
|
|
|
|
|
|
|
|
|
|
for (let i in receipt.events) { |
|
|
|
for (const i in receipt.events) { |
|
|
|
let event = receipt.events[i] |
|
|
|
const event = receipt.events[i] |
|
|
|
if (event.raw.topics.indexOf(topic) >= 0) { |
|
|
|
if (event.raw.topics.indexOf(topic) >= 0) { |
|
|
|
const testEvent = web3.eth.abi.decodeParameters(['bool', 'string'], event.raw.data) |
|
|
|
const testEvent = web3.eth.abi.decodeParameters(['bool', 'string'], event.raw.data) |
|
|
|
if (!testEvent[0]) { |
|
|
|
if (!testEvent[0]) { |
|
|
@ -168,7 +187,7 @@ export function runTest (testName, testObject: any, contractDetails: any, fileAS |
|
|
|
} |
|
|
|
} |
|
|
|
}).on('error', function (err: any) { |
|
|
|
}).on('error', function (err: any) { |
|
|
|
console.error(err) |
|
|
|
console.error(err) |
|
|
|
let time: number = (Date.now() - startTime) / 1000.0 |
|
|
|
const time: number = (Date.now() - startTime) / 1000.0 |
|
|
|
const resp: TestResultInterface = { |
|
|
|
const resp: TestResultInterface = { |
|
|
|
type: 'testFailure', |
|
|
|
type: 'testFailure', |
|
|
|
value: changeCase.sentenceCase(func.name), |
|
|
|
value: changeCase.sentenceCase(func.name), |
|
|
|