当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript async.eachOfLimit函数代码示例

本文整理汇总了TypeScript中async.eachOfLimit函数的典型用法代码示例。如果您正苦于以下问题:TypeScript eachOfLimit函数的具体用法?TypeScript eachOfLimit怎么用?TypeScript eachOfLimit使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了eachOfLimit函数的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: runTests

        function runTests(contractsToTest, contractsToTestDetails, contracts, next: Function) {
            let totalPassing: number = 0
            let totalFailing: number = 0
            let totalTime: number = 0
            let errors: any[] = []

            const _testCallback = function (err: Error | null | undefined, result: TestResultInterface) {
                if(err) throw err;
                if (result.type === 'contract') {
                    signale.name(result.value.white)
                } else if (result.type === 'testPass') {
                    signale.result(result.value)
                } else if (result.type === 'testFailure') {
                    signale.result(result.value.red)
                    errors.push(result)
                }
            }
            const _resultsCallback = (_err: Error | null | undefined, result: ResultsInterface, cb) => {
                totalPassing += result.passingNum
                totalFailing += result.failureNum
                totalTime += result.timePassed
                cb()
            }

            async.eachOfLimit(contractsToTest, 1, (contractName: string, index, cb) => {
              try {
                runTest(contractName, contracts[contractName], contractsToTestDetails[index], { accounts }, _testCallback, (err, result) => {
                    if (err) {
                      console.log(err)
                        return cb(err)
                    }
                    _resultsCallback(null, result, cb)
                })
              } catch(e) {
                console.error(e)
              }
            }, function (err) {
                if (err) {
                    return next(err)
                }

                console.log('\n')
                if (totalPassing > 0) {
                    console.log(colors.green(totalPassing + ' passing ') + colors.grey('(' + totalTime + 's)'))
                }
                if (totalFailing > 0) {
                    console.log(colors.red(totalFailing + ' failing'))
                }
                console.log('')

                errors.forEach((error, index) => {
                    console.log('  ' + (index + 1) + ') ' + error.context + ' ' + error.value)
                    console.log('')
                    console.log(colors.red('\t error: ' + error.errMsg))
                })
                console.log('')

                next()
            })
        }
开发者ID:0mkara,项目名称:remix,代码行数:60,代码来源:runTestFiles.ts

示例2: deployContracts

        function deployContracts(contractsToDeploy: string[], next: Function) {
            const deployRunner = (deployObject, contractObject, contractName, filename, callback) => {
                deployObject.estimateGas().then((gasValue) => {
                    deployObject.send({
                        from: accounts[0],
                        gas: Math.ceil(gasValue * 1.2)
                    }).on('receipt', function (receipt) {
                        contractObject.options.address = receipt.contractAddress
                        contractObject.options.from = accounts[0]
                        contractObject.options.gas = 5000 * 1000
                        compiledObject[contractName].deployedAddress = receipt.contractAddress

                        contracts[contractName] = contractObject
                        contracts[contractName].filename = filename

                        callback(null, { result: { createdAddress: receipt.contractAddress } }) // TODO this will only work with JavaScriptV VM
                    }).on('error', function (err) {
                        console.error(err)
                        callback(err)
                    })
                })
            }

            async.eachOfLimit(contractsToDeploy, 1, function (contractName, index, nextEach) {
                let contract = compiledObject[contractName]
                let encodeDataFinalCallback = (error, contractDeployData) => {
                    if (error) return nextEach(error)
                    try {
                        let contractObject = new web3.eth.Contract(contract.abi)
                        let deployObject = contractObject.deploy({arguments: [], data: '0x' + contractDeployData.dataHex})
                        deployRunner(deployObject, contractObject, contractName, contract.filename, (error) => { nextEach(error) })
                    } catch (e) {
                        throw e
                    }
                }

                let encodeDataStepCallback = (msg) => { console.dir(msg) }

                let encodeDataDeployLibraryCallback = (libData, callback) => {
                    let abi = compiledObject[libData.data.contractName].abi
                    let code = compiledObject[libData.data.contractName].code
                    let libraryObject = new web3.eth.Contract(abi)
                    let deployObject = libraryObject.deploy({arguments: [], data: '0x' + code})
                    deployRunner(deployObject, libraryObject, libData.data.contractName, contract.filename, callback)
                }

                let funAbi = null // no need to set the abi for encoding the constructor
                let params = '' // we suppose that the test contract does not have any param in the constructor
                remixLib.execution.txFormat.encodeConstructorCallAndDeployLibraries(contractName, contract.raw, compileResult, params, funAbi, encodeDataFinalCallback, encodeDataStepCallback, encodeDataDeployLibraryCallback)
            }, function () {
                next(null, contracts)
            })
        }
开发者ID:0mkara,项目名称:remix,代码行数:53,代码来源:deployer.ts

示例3: runTests

        function runTests(contractsToTest, contractsToTestDetails, contracts, next) {
            let totalPassing = 0
            let totalFailing = 0
            let totalTime = 0
            let errors: any[] = []

            const _testCallback = function (err: Error | null | undefined, result: TestResultInterface) {
                if (result.type === 'testFailure') {
                    errors.push(result)
                }
                testCallback(result)
            }

            const _resultsCallback = function (_err, result, cb) {
                resultCallback(_err, result, () => {})
                totalPassing += result.passingNum
                totalFailing += result.failureNum
                totalTime += result.timePassed
                cb()
            }

            async.eachOfLimit(contractsToTest, 1, (contractName: string, index: string | number, cb: ErrorCallback) => {
                runTest(contractName, contracts[contractName], contractsToTestDetails[index], { accounts }, _testCallback, (err, result) => {
                    if (err) {
                        return cb(err)
                    }
                    _resultsCallback(null, result, cb)
                })
            }, function (err) {
                if (err) {
                    return next(err)
                }

                let finalResults: FinalResult = {
                    totalPassing: 0,
                    totalFailing: 0,
                    totalTime: 0,
                    errors: [],
                }

                finalResults.totalPassing = totalPassing || 0
                finalResults.totalFailing = totalFailing || 0
                finalResults.totalTime = totalTime || 0
                finalResults.errors = []

                errors.forEach((error, _index) => {
                    finalResults.errors.push({context: error.context, value: error.value, message: error.errMsg})
                })

                next(null, finalResults)
            })
        }
开发者ID:0mkara,项目名称:remix,代码行数:52,代码来源:runTestSources.ts

示例4: runTest

export function runTest (testName, testObject: any, contractDetails: any, opts: any, testCallback: TestCbInterface, resultsCallback: ResultCbInterface) {
    let runList = createRunList(testObject._jsonInterface)

    let passingNum: number = 0
    let failureNum: number = 0
    let timePassed: number = 0
    let web3 = new Web3()

    const userAgent = (typeof (navigator) !== 'undefined') && navigator.userAgent ? navigator.userAgent.toLowerCase() : '-'
    const isBrowser = !(typeof (window) === 'undefined' || userAgent.indexOf(' electron/') > -1)
    if (!isBrowser) {
        let signale = require('signale')
        signale.warn('DO NOT TRY TO ACCESS (IN YOUR SOLIDITY TEST) AN ACCOUNT GREATER THAN THE LENGTH OF THE FOLLOWING ARRAY (' + opts.accounts.length + ') :')
        signale.warn(opts.accounts)
        signale.warn('e.g: the following code won\'t work in the current context:')
        signale.warn('TestsAccounts.getAccount(' + opts.accounts.length + ')')
    }
    const resp: TestResultInterface = {
      type: 'contract',
      value: testName,
      filename: testObject.filename
    }
    testCallback(undefined, resp)
    async.eachOfLimit(runList, 1, function (func, index, next) {
        let sender
        if (func.signature) {
            sender = getOverridedSender(contractDetails.userdoc, func.signature, contractDetails.evm.methodIdentifiers)
            if (opts.accounts) {
                sender = opts.accounts[sender]
            }
        }
        let sendParams
        if (sender) sendParams = { from: sender }

        let method = testObject.methods[func.name].apply(testObject.methods[func.name], [])
        let startTime = Date.now()
        if (func.constant) {
            method.call(sendParams).then((result) => {
                let time = Math.ceil((Date.now() - startTime) / 1000.0)
                if (result) {
                    const resp: TestResultInterface = {
                      type: 'testPass',
                      value: changeCase.sentenceCase(func.name),
                      time: time,
                      context: testName
                    }
                    testCallback(undefined, resp)
                    passingNum += 1
                    timePassed += time
                } else {
                    const resp: TestResultInterface = {
                      type: 'testFailure',
                      value: changeCase.sentenceCase(func.name),
                      time: time,
                      errMsg: 'function returned false',
                      context: testName
                    }
                    testCallback(undefined, resp)
                    failureNum += 1
                }
                next()
            })
        } else {
            method.send(sendParams).on('receipt', (receipt) => {
                try {
                    let time: number = Math.ceil((Date.now() - startTime) / 1000.0)
                    let topic = Web3.utils.sha3('AssertionEvent(bool,string)')
                    let testPassed: boolean = false

                    for (let i in receipt.events) {
                        let event = receipt.events[i]
                        if (event.raw.topics.indexOf(topic) >= 0) {
                            const testEvent = web3.eth.abi.decodeParameters(['bool', 'string'], event.raw.data)
                            if (!testEvent[0]) {
                                const resp: TestResultInterface = {
                                  type: 'testFailure',
                                  value: changeCase.sentenceCase(func.name),
                                  time: time,
                                  errMsg: testEvent[1],
                                  context: testName
                                };
                                testCallback(undefined, resp)
                                failureNum += 1
                                return next()
                            }
                            testPassed = true
                        }
                    }

                    if (testPassed) {
                        const resp: TestResultInterface = {
                          type: 'testPass',
                          value: changeCase.sentenceCase(func.name),
                          time: time,
                          context: testName
                        }
                        testCallback(undefined, resp)
                        passingNum += 1
                    }

//.........这里部分代码省略.........
开发者ID:0mkara,项目名称:remix,代码行数:101,代码来源:testRunner.ts


注:本文中的async.eachOfLimit函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。