Commit dbb71b17 authored by aniket-engg's avatar aniket-engg Committed by Aniket

hhlogs in unit testing plugin

parent 7a852929
...@@ -180,6 +180,7 @@ module.exports = class TestTab extends ViewPlugin { ...@@ -180,6 +180,7 @@ module.exports = class TestTab extends ViewPlugin {
} }
testCallback (result, runningTests) { testCallback (result, runningTests) {
console.log('result in testCallback', result)
this.testsOutput.hidden = false this.testsOutput.hidden = false
if (result.type === 'contract') { if (result.type === 'contract') {
this.testSuite = result.value this.testSuite = result.value
......
...@@ -5,7 +5,7 @@ import { deployAll } from './deployer' ...@@ -5,7 +5,7 @@ import { deployAll } from './deployer'
import { runTest } from './testRunner' import { runTest } from './testRunner'
import Web3 from 'web3' import Web3 from 'web3'
import { Provider } from '@remix-project/remix-simulator' import { Provider, extend } from '@remix-project/remix-simulator'
import { import {
FinalResult, SrcIfc, compilationInterface, ASTInterface, Options, FinalResult, SrcIfc, compilationInterface, ASTInterface, Options,
TestResultInterface, AstNode, CompilerConfiguration TestResultInterface, AstNode, CompilerConfiguration
...@@ -17,6 +17,7 @@ const createWeb3Provider = async function () { ...@@ -17,6 +17,7 @@ const createWeb3Provider = async function () {
const provider: any = new Provider() const provider: any = new Provider()
await provider.init() await provider.init()
web3.setProvider(provider) web3.setProvider(provider)
extend(web3)
return web3 return web3
} }
...@@ -102,7 +103,7 @@ export async function runTestSources (contractSources: SrcIfc, compilerConfig: C ...@@ -102,7 +103,7 @@ export async function runTestSources (contractSources: SrcIfc, compilerConfig: C
async.eachOfLimit(contractsToTest, 1, (contractName: string, index: string | number, cb: ErrorCallback) => { async.eachOfLimit(contractsToTest, 1, (contractName: string, index: string | number, cb: ErrorCallback) => {
const fileAST: AstNode = sourceASTs[contracts[contractName]['filename']] const fileAST: AstNode = sourceASTs[contracts[contractName]['filename']]
runTest(contractName, contracts[contractName], contractsToTestDetails[index], fileAST, { accounts }, _testCallback, (err, result) => { runTest(contractName, contracts[contractName], contractsToTestDetails[index], fileAST, { accounts, web3 }, _testCallback, (err, result) => {
if (err) { if (err) {
return cb(err) return cb(err)
} }
......
...@@ -217,7 +217,7 @@ export function runTest (testName: string, testObject: any, contractDetails: Com ...@@ -217,7 +217,7 @@ export function runTest (testName: string, testObject: any, contractDetails: Com
const isJSONInterfaceAvailable = testObject && testObject.options && testObject.options.jsonInterface const isJSONInterfaceAvailable = testObject && testObject.options && testObject.options.jsonInterface
if (!isJSONInterfaceAvailable) { return resultsCallback(new Error('Contract interface not available'), { passingNum, failureNum, timePassed }) } if (!isJSONInterfaceAvailable) { return resultsCallback(new Error('Contract interface not available'), { passingNum, failureNum, timePassed }) }
const runList: RunListInterface[] = createRunList(testObject.options.jsonInterface, fileAST, testName) const runList: RunListInterface[] = createRunList(testObject.options.jsonInterface, fileAST, testName)
const web3 = new Web3() const web3 = opts.web3 || new Web3()
const accts: TestResultInterface = { const accts: TestResultInterface = {
type: 'accountList', type: 'accountList',
value: opts.accounts value: opts.accounts
...@@ -284,6 +284,7 @@ export function runTest (testName: string, testObject: any, contractDetails: Com ...@@ -284,6 +284,7 @@ export function runTest (testName: string, testObject: any, contractDetails: Com
sendParams.gas = 10000000 * 8 sendParams.gas = 10000000 * 8
method.send(sendParams).on('receipt', (receipt) => { method.send(sendParams).on('receipt', (receipt) => {
try { try {
web3.eth.getHHLogsForTx(receipt.transactionHash).then((hhLogs) => {
const time: number = (Date.now() - startTime) / 1000.0 const time: number = (Date.now() - startTime) / 1000.0
const assertionEventHashes = assertionEvents.map(e => Web3.utils.sha3(e.name + '(' + e.params.join() + ')')) const assertionEventHashes = assertionEvents.map(e => Web3.utils.sha3(e.name + '(' + e.params.join() + ')'))
let testPassed = false let testPassed = false
...@@ -311,7 +312,8 @@ export function runTest (testName: string, testObject: any, contractDetails: Com ...@@ -311,7 +312,8 @@ export function runTest (testName: string, testObject: any, contractDetails: Com
assertMethod, assertMethod,
returned: testEvent[3], returned: testEvent[3],
expected: testEvent[4], expected: testEvent[4],
location location,
hhLogs
} }
testCallback(undefined, resp) testCallback(undefined, resp)
failureNum += 1 failureNum += 1
...@@ -329,7 +331,8 @@ export function runTest (testName: string, testObject: any, contractDetails: Com ...@@ -329,7 +331,8 @@ export function runTest (testName: string, testObject: any, contractDetails: Com
value: changeCase.sentenceCase(func.name), value: changeCase.sentenceCase(func.name),
filename: testObject.filename, filename: testObject.filename,
time: time, time: time,
context: testName context: testName,
hhLogs
} }
testCallback(undefined, resp) testCallback(undefined, resp)
passingNum += 1 passingNum += 1
...@@ -337,6 +340,7 @@ export function runTest (testName: string, testObject: any, contractDetails: Com ...@@ -337,6 +340,7 @@ export function runTest (testName: string, testObject: any, contractDetails: Com
} }
return next() return next()
})
} catch (err) { } catch (err) {
console.error(err) console.error(err)
return next(err) return next(err)
......
...@@ -36,6 +36,7 @@ export interface TestResultInterface { ...@@ -36,6 +36,7 @@ export interface TestResultInterface {
returned?: string | number returned?: string | number
expected?: string | number expected?: string | number
location?: string location?: string
hhLogs?: []
} }
export interface TestCbInterface { export interface TestCbInterface {
(error: Error | null | undefined, result: TestResultInterface) : void; (error: Error | null | undefined, result: TestResultInterface) : void;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment