Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

316
Visualizações
Why is mocha test throwing "Error done() called multiple times in hook <"before each" ....>?

I am learning about smart contracts and blockchain development. I am currently trying to test the deployment of a simple contract using mocha but when running the test the following error is thrown :

Error: done() called multiple times in hook <"before each" hook for "deploys contract"> (of root suite) at createMultipleDoneError (/Users/nacholopez/Desktop/Inbox/node_modules/mocha/lib/errors.js:428:13) at multiple (/Users/nacholopez/Desktop/Inbox/node_modules/mocha/lib/runnable.js:290:24) at done (/Users/nacholopez/Desktop/Inbox/node_modules/mocha/lib/runnable.js:301:14) at /Users/nacholopez/Desktop/Inbox/node_modules/mocha/lib/runnable.js:371:11 at processTicksAndRejections (node:internal/process/task_queues:96:5) { code: 'ERR_MOCHA_MULTIPLE_DONE', valueType: 'undefined', value: undefined

Here is my compilation and testing code:

compile.js:

const path = require('path');
const fs = require('fs');
const solc = require('solc');
const Inboxpath = path.resolve(__dirname, 'contracts', 'Inbox.sol');
const source = fs.readFileSync(Inboxpath, 'utf8');

const input = {
    language: "Solidity",
    sources: {
        "Inbox.sol": {
            content: source,
        },
    },
    settings: {
        outputSelection: {
            "*": {
                "*": ["*"],
            },
        },
    },
};
const output = JSON.parse(solc.compile(JSON.stringify(input)));

module.exports = output.contracts["Inbox.sol"].Inbox;

Inbox.test.js :

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 () => {
    accounts = await web3.eth.getAccounts();
    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 contract', () => {
        console.log(inbox);
    });
});
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I ran into the same issue as well and I made the callback to the 'it' function 'async' and that fixed the issue for me.

it("deploys a contract", async () => {
        assert.ok(inbox.options.address);
    });
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda