首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >以太网坚固性合约- web3.eth.Contract send()方法的Mocha超时

以太网坚固性合约- web3.eth.Contract send()方法的Mocha超时
EN

Stack Overflow用户
提问于 2019-04-10 01:44:47
回答 1查看 346关注 0票数 1

我目前正在学习可靠,并试图建立一个简单的合同。我还在尝试使用Mocha框架在部署之前测试智能合约。测试代码如下:

代码语言:javascript
运行
复制
const assert = require("assert");
const ganache = require("ganache-cli");
const Web3 = require("web3");
const { interface, bytecode } = require("../compile");

const provider = ganache.provider();
const web3 = new Web3(provider);

let accounts;
let inbox;

beforeEach(async () => {
  // Get a list of all accounts
  accounts = await web3.eth.getAccounts();

  // Use one of those accounts to deploy the contract
  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);
  });
});

测试失败并超时:

代码语言:javascript
运行
复制
> mocha

  Inbox
    1) "before each" hook for "deploys a contract"


  0 passing (2s)
  1 failing

  1) "before each" hook for "deploys a contract":
     Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves.

我注意到,如果我注释掉send()参数,测试就会通过:

代码语言:javascript
运行
复制
// .send({
//   from: accounts[0],
//   gas: "1000000"
// });

所以问题一定出在使用这种方法上。不确定是否为异步问题。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-04-11 13:38:38

我通过将web3降级为1.0.0-beta.37解决了这个问题。看起来1.0.0-beta.51版本有buggy。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55598440

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档