more types added

pull/5370/head
aniket-engg 5 years ago committed by Aniket
parent 297d038b1c
commit 5bcc01ea8c
  1. 6
      remix-tests/src/runTestFiles.ts
  2. 10
      remix-tests/src/runTestSources.ts
  3. 28
      remix-tests/src/testRunner.ts
  4. 5
      remix-tests/src/types.ts

@ -1,7 +1,7 @@
import async from 'async'
import fs from './fileSystem'
import { runTest } from './testRunner'
import { TestResultInterface, ResultsInterface, compilationInterface, ASTInterface } from './types'
import { TestResultInterface, ResultsInterface, compilationInterface, ASTInterface, Options, AstNode } from './types'
import colors from 'colors'
import Web3 = require('web3')
@ -16,7 +16,7 @@ import { deployAll } from './deployer'
* @param opts Options
*/
export function runTestFiles(filepath: string, isDirectory: boolean, web3: Web3, opts?: object) {
export function runTestFiles(filepath: string, isDirectory: boolean, web3: Web3, opts?: Options) {
opts = opts || {}
const sourceASTs: any = {}
const { Signale } = require('signale')
@ -117,7 +117,7 @@ export function runTestFiles(filepath: string, isDirectory: boolean, web3: Web3,
async.eachOfLimit(contractsToTest, 1, (contractName: string, index, cb) => {
try {
const fileAST = sourceASTs[contracts[contractName]['filename']]
const fileAST: AstNode = sourceASTs[contracts[contractName]['filename']]
runTest(contractName, contracts[contractName], contractsToTestDetails[index], fileAST, { accounts }, _testCallback, (err, result) => {
if (err) {
console.log(err)

@ -4,11 +4,11 @@ require('colors')
import { compileContractSources } from './compiler'
import { deployAll } from './deployer'
import { runTest } from './testRunner'
import { TestResultInterface } from './types'
import { TestResultInterface, AstNode } from './types'
import Web3 = require('web3')
import { Provider } from 'remix-simulator'
import { FinalResult, SrcIfc, compilationInterface, ASTInterface } from './types'
import { FinalResult, SrcIfc, compilationInterface, ASTInterface, Options } from './types'
const createWeb3Provider = async function () {
let web3 = new Web3()
@ -29,11 +29,11 @@ const createWeb3Provider = async function () {
* @param importFileCb Import file callback
* @param opts Options
*/
export async function runTestSources(contractSources: SrcIfc, versionUrl: string, usingWorker: boolean, testCallback: Function, resultCallback: Function, finalCallback: any, importFileCb: Function, opts: any) {
export async function runTestSources(contractSources: SrcIfc, versionUrl: string, usingWorker: boolean, testCallback: Function, resultCallback: Function, finalCallback: any, importFileCb: Function, opts: Options) {
opts = opts || {}
const sourceASTs: any = {}
let web3 = opts.web3 || await createWeb3Provider()
let accounts = opts.accounts || null
let accounts: string[] | null = opts.accounts || null
async.waterfall([
function getAccountList (next) {
if (accounts) return next()
@ -95,7 +95,7 @@ export async function runTestSources(contractSources: SrcIfc, versionUrl: string
}
async.eachOfLimit(contractsToTest, 1, (contractName: string, index: string | number, cb: ErrorCallback) => {
const fileAST = sourceASTs[contracts[contractName]['filename']]
const fileAST: AstNode = sourceASTs[contracts[contractName]['filename']]
runTest(contractName, contracts[contractName], contractsToTestDetails[index], fileAST, { accounts }, _testCallback, (err, result) => {
if (err) {
return cb(err)

@ -1,9 +1,10 @@
import async from 'async'
import * as changeCase from 'change-case'
import Web3 = require('web3')
import { RunListInterface, TestCbInterface, TestResultInterface, ResultCbInterface } from './types'
import { RunListInterface, TestCbInterface, TestResultInterface, ResultCbInterface,
CompiledContract, AstNode, Options, FunctionDescription, UserDocumentation } from './types'
function getFunctionFullName (signature: string, methodIdentifiers) {
function getFunctionFullName (signature: string, methodIdentifiers: any) {
for (const method in methodIdentifiers) {
if (signature.replace('0x', '') === methodIdentifiers[method].replace('0x', '')) {
return method
@ -12,10 +13,10 @@ function getFunctionFullName (signature: string, methodIdentifiers) {
return null
}
function getOverridedSender (userdoc, signature: string, methodIdentifiers) {
function getOverridedSender (userdoc: UserDocumentation, signature: string, methodIdentifiers: any) {
let fullName: any = getFunctionFullName(signature, methodIdentifiers)
let match = /sender: account-+(\d)/g
let accountIndex = userdoc.methods[fullName] ? match.exec(userdoc.methods[fullName].notice) : null
let match: RegExp = /sender: account-+(\d)/g
let accountIndex: any = userdoc.methods[fullName] ? match.exec(userdoc.methods[fullName].notice) : null
return fullName && accountIndex ? accountIndex[1] : null
}
@ -25,10 +26,13 @@ function getOverridedSender (userdoc, signature: string, methodIdentifiers) {
* @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)
function getAvailableFunctions (fileAST: AstNode, testContractName: string) {
var 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)
}
return funcList;
}
@ -38,7 +42,7 @@ function getAvailableFunctions (fileAST: any, testContractName: string) {
* @param funcList Methods to extract the interface of
*/
function getTestFunctionsInterface (jsonInterface: any, funcList: string[]) {
function getTestFunctionsInterface (jsonInterface: FunctionDescription[], funcList: string[]) {
const functionsInterface: any[] = []
const specialFunctions = ['beforeAll', 'beforeEach', 'afterAll', 'afterEach']
for(const func of funcList){
@ -57,7 +61,7 @@ function getTestFunctionsInterface (jsonInterface: any, funcList: string[]) {
* @param testContractName Test contract name
*/
function createRunList (jsonInterface: any, fileAST: any, testContractName: string): RunListInterface[] {
function createRunList (jsonInterface: FunctionDescription[], fileAST: AstNode, testContractName: string): RunListInterface[] {
const availableFunctions: string[] = getAvailableFunctions(fileAST, testContractName)
const testFunctionsInterface: any[] = getTestFunctionsInterface(jsonInterface, availableFunctions)
@ -84,7 +88,7 @@ function createRunList (jsonInterface: any, fileAST: any, testContractName: stri
return runList
}
export function runTest (testName, testObject: any, contractDetails: any, fileAST: any, opts: any, testCallback: TestCbInterface, resultsCallback: ResultCbInterface) {
export function runTest (testName: string, testObject: any, contractDetails: CompiledContract, fileAST: AstNode, opts: Options, testCallback: TestCbInterface, resultsCallback: ResultCbInterface) {
const runList: RunListInterface[] = createRunList(testObject._jsonInterface, fileAST, testName)
let passingNum: number = 0
let failureNum: number = 0

@ -38,6 +38,11 @@ export interface ResultCbInterface {
(error: Error | null | undefined, result: ResultsInterface) : void;
}
export interface Options {
accounts?: string[] | null,
web3?: any
}
/** sources object with name of the file and content **/
////////////

Loading…
Cancel
Save