Test for truffleAssert.reverts


As you can see from the image, I am getting error with “truffleAssert.reverts”. It should already revert but it is not getting tick from the test. If someone can help me, I would be appreciated.

Hi @jieunpro

It is just that the error message is not matching with the message in the contract test.
Try like this

await truffleAssert.reverts(
        dex.withdraw(byteValue,500), "Insufficient Balance" // Match the message with the contract revert message
      );

Let us know if it works. :slightly_smiling_face:

It worked! To make it clear, there is a require statement in my original withdraw function and the error message in this require statement is “Insufficient Balance”. If I want to write a test for this function specifically, do I need to match the error statements? Was that the problem?

Yes, that is correct.
And if you look closely at the error message that is exactly what it says.

Thank you so much for your answer. What about this one? I wrote it exactly like from the video. And it says depositEth is not a function. And also I think so because I couldn’t find that function in the files. If it is a silly question, sorry for that I am beginner.

Hi @jieunpro

Code looks correct. Can you check if the function name depositEth is matching with the name in contract? or Maybe check if there is a typo in function name.

The problem is there is no any function loke that. I could not see it on the videos, where should i write that function? Which contract should i locate it?

Hi @jieunpro

Answered in your latest post

Please check it and let us know if it works.