From 7b7a0e411125831132e1087064a5b9adcd58ddd7 Mon Sep 17 00:00:00 2001 From: aniket-engg Date: Tue, 19 Nov 2019 17:48:37 +0530 Subject: [PATCH] suggested changes --- remix-tests/src/runTestSources.ts | 3 +-- remix-tests/src/testRunner.ts | 14 ++++++++------ remix-tests/src/types.ts | 1 + 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/remix-tests/src/runTestSources.ts b/remix-tests/src/runTestSources.ts index 7c3b4fbf7e..f5394e57f8 100644 --- a/remix-tests/src/runTestSources.ts +++ b/remix-tests/src/runTestSources.ts @@ -4,11 +4,10 @@ require('colors') import { compileContractSources } from './compiler' import { deployAll } from './deployer' import { runTest } from './testRunner' -import { TestResultInterface, AstNode } from './types' import Web3 = require('web3') import { Provider } from 'remix-simulator' -import { FinalResult, SrcIfc, compilationInterface, ASTInterface, Options } from './types' +import { FinalResult, SrcIfc, compilationInterface, ASTInterface, Options, TestResultInterface, AstNode } from './types' const createWeb3Provider = async function () { let web3 = new Web3() diff --git a/remix-tests/src/testRunner.ts b/remix-tests/src/testRunner.ts index 5bb06b4e28..e32c421ade 100644 --- a/remix-tests/src/testRunner.ts +++ b/remix-tests/src/testRunner.ts @@ -4,7 +4,7 @@ import Web3 = require('web3') import { RunListInterface, TestCbInterface, TestResultInterface, ResultCbInterface, CompiledContract, AstNode, Options, FunctionDescription, UserDocumentation } from './types' -function getFunctionFullName (signature: string, methodIdentifiers: any) { +function getFunctionFullName (signature: string, methodIdentifiers: Record ) { for (const method in methodIdentifiers) { if (signature.replace('0x', '') === methodIdentifiers[method].replace('0x', '')) { return method @@ -13,7 +13,7 @@ function getFunctionFullName (signature: string, methodIdentifiers: any) { return null } -function getOverridedSender (userdoc: UserDocumentation, signature: string, methodIdentifiers: any) { +function getOverridedSender (userdoc: UserDocumentation, signature: string, methodIdentifiers: Record ) { let fullName: any = getFunctionFullName(signature, methodIdentifiers) let match: RegExp = /sender: account-+(\d)/g let accountIndex: any = userdoc.methods[fullName] ? match.exec(userdoc.methods[fullName].notice) : null @@ -27,11 +27,13 @@ function getOverridedSender (userdoc: UserDocumentation, signature: string, meth */ function getAvailableFunctions (fileAST: AstNode, testContractName: string) { - var funcList: string[] = [] + let funcList: string[] = [] if(fileAST.nodes && fileAST.nodes.length > 0) { - 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") - funcList = funcNodes.map(node => node.name) + const contractAST: AstNode[] = fileAST.nodes.filter(node => node.name === testContractName && node.nodeType === 'ContractDefinition') + if(contractAST.length > 0 && contractAST[0].nodes) { + const funcNodes: AstNode[] = contractAST[0].nodes.filter(node => node.kind === 'function' && node.nodeType === "FunctionDefinition") + funcList = funcNodes.map(node => node.name) + } } return funcList; } diff --git a/remix-tests/src/types.ts b/remix-tests/src/types.ts index e0c04f14ce..0af2f50244 100644 --- a/remix-tests/src/types.ts +++ b/remix-tests/src/types.ts @@ -163,6 +163,7 @@ export interface FunctionDescription { payable?: boolean /** true if function is either pure or view, false otherwise. Default is false */ constant?: boolean + signature?: string } export interface EventDescription {