PatrickAlphaC / hardhat-fund-me-fcc

82 stars 184 forks source link

New change on the function of revertedWith #42

Closed nicolasCinzer closed 2 years ago

nicolasCinzer commented 2 years ago

Hi to the best Blockchain Community in the internet! Im currently doing the testing of withdraw function, and with the version of patrick, today (17/7/2022) the expect function will return this error:

AssertionError: Expected transaction to be reverted with reason 'FundMe__NotOwner', but it reverted with a custom error

So apparently, chai made some changes and now we have to use revertedWithCustomError()! The first parameter should be the contract interface where the custom error is triggered and the second parameter should be the name of but in string type.

Thanks for this amazing course @PatrickAlphaC !!!

talha-rafique commented 2 years ago

which version of chai are you using ? as i have the "chai": "^4.2.0", "@nomicfoundation/hardhat-chai-matchers": "^1.0.0",

but I'm facing NEW error Error: Invalid Chai property: revertedWithCustomError

so what i did, i used await expect(fundMe.fund()).to.be.reverted and it worked for me. reason behind that in the fundMe.sol contract there is require() fun of solidity require(msg.value.getConversionRate(priceFeed) >= MINIMUM_USD, "my fundme solidity Custom ERROR"); which also through exception while testing because we were sending less Eth.

when i was using revertedWith('') in my testing that was conflicting with another exception that was from the require fun of solidity.

but other exception was thrown: Error: VM Exception while processing transaction: reverted with reason string 'my fundme solidity Custom ERROR'

Final words. it worked await expect(fundMe.fund()).to.be.reverted its not a fun, its just a property

talha-rafique commented 2 years ago

ahh, i got the issue why revertedWith() fun was not working....

the issue was that, there was also another exception error from solidity code. if you check your code.... require(msg.value.getConversionRate(priceFeed) >= MINIMUM_USD, "You need to spend more ETH!"); remember ?? in funMe contract !!!

so in that case if an exception can also come from solidity, then the expectation error string SHOULD BE the SAME on both sides. means while writing in ether test, the custom error should be same. i.e: await expect(fundMe.fund()).to.be.revertedWith( "You need to spend more ETH!" )

same error string in both solidity and in JS revertedWith()

that means, there is no need for this pull request.

PatrickAlphaC commented 2 years ago

Glad you like the course!

Hmmm... Yeah it looks like it makes sense to not have the PR, what do you think @nicolasCinzer

nicolasCinzer commented 2 years ago

Glad you like the course!

Hmmm... Yeah it looks like it makes sense to not have the PR, what do you think @nicolasCinzer

Oh i forgot about this PR, nah doesnt make sense, i dont know how do that work for me, currently doing the hardhat raffle and that function doesnt work. So we can close this PR!