I am using Hardhat
and chai
for my testing and attempting to trigger an error that gets reverted to make sure my contract is acting properly. Note: I'm running on a forked hardhat chain of mainnet.
I define the error like so:
error FundMe__WithdrawProceedsGreaterThanBalance(uint256 amount, uint256 balance);
and revert it with
function withdrawFunds(uint256 amount) public {
if (amount > s_funders[msg.sender].amount) {
revert FundMe__WithdrawFundsGreaterThanBalance(
amount,
s_funders[msg.sender].amount
);
}
Then in my test I purposefully trigger it:
await expect(fundMe.withdrawFundsFromPool(higherFundAmount)
).to.be.revertedWith(
"FundMe__WithdrawFundsGreaterThanBalance"
)
Here is where it goes wrong, instead of passing that test, it fails with an error:
AssertionError: Expected transaction to be reverted with FundMe__WithdrawFundsGreaterThanBalance, but other exception was thrown: ProviderError: Error: Transaction reverted without a reason string
It's so strange because if I change the solidity code to revert a string like `revert ("Test failure") and change the test code to expect that string to be reverted, it works. I'm thinking this issue might have to do with some sort of versioning issue, with hardhat, chai, and waffle but I haven't been able to figure it out. I believe these are the versions that matter so I'll paste them here:
"@nomiclabs/hardhat-ethers": "npm:hardhat-deploy-ethers",
"@nomiclabs/hardhat-etherscan": "^3.1.0",
"@nomiclabs/hardhat-waffle": "^2.0.3",
"chai": "^4.3.6",
Not really sure what to do. I've tried other solutions I've seen people like adding hardhat-chai-matchers
but nothing works