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

问题描述 投票:1回答:1

我已经在以太坊中测试了合约的代码

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);
  });
});

这显示以下警告

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

可能的原因是什么以及如何解决?

node.js mocha ethereum solidity web3js
1个回答
1
投票

得到答案。这是web3js中具有版本1的发送功能的问题。

因此可以使用以下方式设置最大侦听器

web3.currentProvider.setMaxListeners(300);

或升级到v2 ^,它是固定的there

© www.soinside.com 2019 - 2024. All rights reserved.