Lesson 14: testing randomIpfs.test.ts, revertedWith is not working as expected.
#1075
-
|
So while testing AssertionError: Expected transaction to be reverted with reason 'NeedMoreETHSent', but it reverted with a custom errorI am not sure what custom error I am getting instead of the set error in my code in function requestNft() public payable returns (uint256 requestId) {
if (msg.value < i_mintFee) {
revert NeedMoreETHSent(); // I was expecting this
}
requestId = i_vrfCoordinator.requestRandomWords(
i_gasLane,
i_subscriptionId,
REQUEST_CONFIRMATIONS,
i_callbackGasLimit,
NUM_WORDS
);
s_requesIdToSender[requestId] = msg.sender;
emit NftRequested(requestId, msg.sender);
}I have defined My test code. I am sending less mint fee so that it revert with error describe("requestNft", () => {
it("Reverts if send ETH is less", async () => {
//const mintFee = await randomIpfsNft.getMintFee();
const lessmintFee = ethers.utils.parseEther("0.001");
await expect(
randomIpfsNft.requestNft({ value: lessmintFee })
).to.be.revertedWith("NeedMoreETHSent");
});
});What could be the custom error? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 19 replies
-
|
I do not know what the problem here is, so I could be wrong, but try: Increase |
Beta Was this translation helpful? Give feedback.
-
|
@ali-thegilfoyle @Krakxn @PatrickAlphaC So I saw another supported method it("Reverts if send ETH is less", async () => {
const lessmintFee = ethers.utils.parseEther("0.001");
await expect(
randomIpfsNft.requestNft({
value: lessmintFee.toString(),
})
).to.be.revertedWithCustomError(
randomIpfsNft,
"NeedMoreETHSent"
);
});I wonder why the |
Beta Was this translation helpful? Give feedback.
@ali-thegilfoyle @Krakxn @PatrickAlphaC
So I saw another supported method
revertedWithCustomErrorand its working.I wonder why the
revertedWithis not working? Due to changes inchai? Not sure.