• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript async.eachOfLimit函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript async.eachSeries函数代码示例发布时间:2022-05-25
下一篇:
TypeScript async.eachLimit函数代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap