简体   繁体   English

是什么导致 web3js 测试代码中的 MaxListenersExceededWarning 警告

[英]What is causing the MaxListenersExceededWarning warning in web3js test code

I've testing code for a contract in ethereum我已经测试了以太坊合约的代码

const assert = require("assert");
const ganache = require("ganache-cli");
const Web3 = require("web3");
const web3 = new Web3(ganache.provider());
const { abi, evm } = require("../compile");

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(abi)
    .deploy({
      data: evm.bytecode.object,
      arguments: ["Hi there!"]
    })
    .send({ from: accounts[0], gas: "1000000" });
});

describe("Inbox", () => {
  it("deploys a contract", () => {
    console.log(accounts);
    console.log(inbox);
    assert.ok(inbox.options.address);
  });
});

This is showing the following warning这显示以下警告

(node:52888) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 data listeners added. Use emitter.setMaxListeners() to increase limit

What is the probable reason for this and how to resolve it?造成这种情况的可能原因是什么以及如何解决?

Got the answer.得到了答案。 It's an issue in web3js with send function for version 1.这是 web3js 中的一个问题,版本 1 发送 function。

So either set max listeners using所以要么设置最大听众使用

web3.currentProvider.setMaxListeners(300);

Or upgrade to v2^ it's fixed there .或者升级到 v2^ 它已经固定在那里

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM