mocha.js - mocha : Timeout of 20000ms exceeded 单元测试错误

标签 mocha.js blockchain ethereum solidity ganache

当我尝试将合约发送到 Ganache 时出现超时错误。我的代码如下,

const assert = require('assert');
const ganache = require('ganache-cli');
const Web3 = require('web3');
const web3 = new Web3(ganache.provider());
const {interface,bytecode} = require('../compile');

let accounts;
let inbox;

beforeEach(async() => {
accounts = await web3.eth.getAccounts();
inbox = await new web3.eth.Contract(JSON.parse(interface))
  .deploy({data: bytecode,arguments:['Hi There !'] })
  .send({from: accounts[0], gas:'1000000'});
});

describe("inbox", () => {
it('deploys a contract', () => {
    console.log(inbox);
 })
})

当我注释掉发送方法(在下面提供)时,程序运行没有任何问题。但是,将其添加回来会引入超时错误。无论我为 mocha 超时分配多少时间,我仍然会遇到相同的错误。

.send({from: accounts[0], gas:'1000000'});

下面列出了关于超时的类似帖子, Error: Timeout of 2000ms exceeded. For async tests and hooks. Unit test with mocha and chai

Unit test error with mocha and chai Timeout of 2000ms exceeded. For async tests and hooks

Mocha testing with promises: Error: Timeout of 2000ms exceeded

Mocha exceeding 2000ms timeout when returning a promise

以上解决方案都不适合我(主要是关于增加超时时间)。此外,我按照另一个论坛中的建议降级了 web3 库。但是,它也没有用。

您可以在 a different forum 找到其他人发布的确切问题.显然,这个问题也没有得到任何可能的答案。

最佳答案

我安装了 truffle v5.0.24 并开始使用解决了所有问题的 truffle 控制台。

关于mocha.js - mocha : Timeout of 20000ms exceeded 单元测试错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56616396/

相关文章:

node.js - sinon-mongoose 不能与 sinon 9 一起使用

javascript - 如何使用WebdriverIO和Spectron使用Javascript应用模糊事件

mocha.js - 在 chai.expect 错误中格式化对象

node.js - 编写环回测试时如何传递输入参数

java - 如何将 Transaction State 转换为 ContractState 的一种类型 fooState?

blockchain - 警告 : SPDX license identifier not provided in source file

java - 使用 Hyperledger Fabric Java sdk 获取区 block 信息

cryptography - 带有 ed25519 曲线签名的 BIP44

go - 在 Go 中构建原始以太坊交易 - 合约函数调用

events - 发送交易和接收事件如何在以太坊区 block 链的后端工作