TrueFiEng / Waffle

Library for writing and testing smart contracts.
https://getwaffle.io
MIT License
961 stars 162 forks source link

4.0.1 sometimes reports an empty error message #761

Closed TrejGun closed 2 years ago

TrejGun commented 2 years ago

Describe the bug The new version sometimes reports an empty error message I was not able to narrow down the conditions but was able to compile a simple test

To Reproduce

// SPDX-License-Identifier: UNLICENSED

pragma solidity ^0.8.9;

contract Test {
  uint256 _x;

  constructor() {}

  function testMe1() public view returns (uint256) {
    require(false, "Error");
    return _x;
  }

  function testMe2(uint256 x) public {
    require(false, "Error");
    _x = x;
  }
}
import { expect, use } from "chai";
import { solidity } from "ethereum-waffle";
import { ethers } from "hardhat";

import { Test } from "../typechain-types";

use(solidity);

describe("Test", function () {
  let testInstance: Test;

  beforeEach(async function () {
    [this.owner, this.receiver] = await ethers.getSigners();

    const testFactory = await ethers.getContractFactory("Test");
    testInstance = await testFactory.deploy();
  });

  it("testMe1", async function () {
    const tx = testInstance.testMe1();
    await expect(tx).to.be.revertedWith("Error");
  });

  it("testMe2", async function () {
    const tx = testInstance.testMe2(1);
    await expect(tx).to.be.revertedWith("Error");
  });
});

Software versions

Additional context

Screen Shot 2022-07-23 at 11 32 43
rzadp commented 2 years ago

Looks like it does not properly extract the error message for a view function - we might have not covered this - I'll take a look at that.

rzadp commented 2 years ago

Hmm no, it seems to be working fine in our tests. @TrejGun What is your installed version of @nomiclabs/hardhat-ethers?

TrejGun commented 2 years ago

@rzadp 2.1.0

rzadp commented 2 years ago

@TrejGun I was able to reproduce the issue (outside of our repository). I will continue to look into it.

rzadp commented 2 years ago

@TrejGun Is your installed version of hardhat higher than 2.9.3? My investigation shows that this problem happens then. You can try downgrading hardhat to 2.9.3 to make it work, or wait for a fix on our side - looks like it should not be difficult.

TrejGun commented 2 years ago

@rzadp thanks for the quick response indeed my hardhat is 2.10.1 I will wait for the fix and run my tests again to report to you

rzadp commented 2 years ago

@TrejGun Please give Waffle 4.0.2 a try.

TrejGun commented 2 years ago

@rzadp thanks, works like a charm

irux commented 2 years ago

@TrejGun did you make it work with hardhat 2.1.0? I downgraded to hardhat 2.9.3 and still didn't work :/ here my dependencies:

    "@nomiclabs/hardhat-ethers": "2.1.0",
    "@nomiclabs/hardhat-etherscan": "^3.0.0",
    "@nomiclabs/hardhat-waffle": "^2.0.3",
    "@typechain/ethers-v5": "^10.1.0",
    "@typechain/hardhat": "^6.1.0",
    "@types/chai": "^4.3.0",
    "@types/mocha": "^9.0.0",
    "@types/node": "^16.4.13",
    "@typescript-eslint/eslint-plugin": "^4.29.1",
    "@typescript-eslint/parser": "^4.29.1",
    "chai": "^4.3.4",
    "dotenv": "^10.0.0",
    "eslint": "^7.29.0",
    "eslint-config-prettier": "^8.3.0",
    "eslint-config-standard": "^16.0.3",
    "eslint-plugin-import": "^2.23.4",
    "eslint-plugin-node": "^11.1.0",
    "eslint-plugin-prettier": "^3.4.0",
    "eslint-plugin-promise": "^5.1.0",
    "ethereum-waffle": "^4.0.4",
    "ethers": "5.6.9",
    "hardhat": "^2.9.3",
    "hardhat-contract-sizer": "^2.4.0",
    "hardhat-deploy": "^0.9.29",
    "hardhat-gas-reporter": "^1.0.7",
    "prettier": "^2.7.1",
    "prettier-plugin-solidity": "^1.0.0-dev.23",
    "sol-merger": "^4.0.0",
    "solhint": "^3.3.6",
    "solidity-coverage": "^0.7.17",
    "ts-node": "^10.4.0",
    "typechain": "^8.1.0",
    "typescript": "^4.5.4"
irux commented 2 years ago

@TrejGun @rzadp I was looking more deeply into the code and I found the error. When I get the error string, the reason is inside simple quotes but the regex is searchig for double quotes here: https://github.com/TrueFiEng/Waffle/blob/master/waffle-chai/src/matchers/revertedWith.ts#L89 If I change the regex to single quotes, it reads the message and it is not anymore empty. I can imagine it is regarding the operating system, but it is only a quick guess :)

TrejGun commented 2 years ago

I'm on mac