This is the error code: enter image description here

Adoption.sol code: enter image description here

TestAdoption.sol code: enter image description here

I dont know how to solve this, it fails when i try to use this comand: "truffle test". Thanks.


5 Answers 5


npm uninstall -g truffle

npm install -g [email protected] (always got me back on track)

  • THIS solves my problem! Thank you very much! I also have similar "before hook", "after each" errors when using Truffle Test. Change the Truffle version to 5.1.10 solves the issues. Mar 16, 2022 at 5:41

delete everything inside your build folder in your truffle root project. and then repeat

truffle compile
truffle migrate
truffle test

hope this help


Which truffle version are you using? I had same issue and I was using v5.1.15, the latest version for now. And I try an old v5.1.10 and it works. It's due to a compilation OS-compatibility path issue. Here you can find an article about it: https://github.com/trufflesuite/truffle/issues/2834#issuecomment-588321875


uninstall and install truffle helped me!


Also, this issue occurs when used several test suites that use async test-helpers without await (for example, OpenZeppelin Test Helpers: expectEvent, expectRevert).

Consider example:


// SPDX-License-Identifier: MIT
pragma solidity ^0.8.3;

contract Test03 {
    address public owner;
    int32 public id;

    event ContractCreated();

    constructor() {
        owner = msg.sender;

        emit ContractCreated();

    function doSmth(int32 _id) public {
        require(id != 0, "id is zero");
        id= _id;


const { expectEvent, expectRevert } = require('@openzeppelin/test-helpers');

const TestContract = artifacts.require('Test03');

contract('Test03', function (accounts) {
    const [owner] = accounts;
    const txParams = { from: owner };

    beforeEach(async function () {
        this.testContract = await TestContract.new(txParams);

    describe('construction', function () {
        it('initial state', async function () {
            expect(await this.testContract.owner()).to.equal(owner);

            // !! DONT FORGET await before expectEvent-call <<------------------------------
            await expectEvent.inConstruction(this.testContract, 'ContractCreated');

    describe('doSmth', function () {
      it('fail when passed zero id', async function () {

        // !! DONT FORGET await before expectRevert-call <<------------------------------
        await expectRevert(
          this.testContract.doSmth(0, txParams),
          "id is zero");


  "devDependencies": {
    "@openzeppelin/test-helpers": "^0.5.10"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.