0

I am looking to get some tips and advice for my smart contract testing as I am a bit stuck. I am currently using Foundry to test my smart contract for my NFT Marketplace project however since I am relatively new to testing, I am a bit confused on an error that I am getting and how to handle it. I am getting an assertion error however it is not telling me where it is failing specifically(only telling me the function that is failing. At least I believe). How do you guys figure out what the specific error is? Any tips? Here is my code and my test. Thank you guys in advance! And sorry in advance if its a really silly mistake on my part haha. I welcome constructive criticism so be honest! Thank you:)

enter image description here

enter image description here

enter image description here

Edit: I deleted the parameter for the testBuyListing function and now I get this error.

enter image description here

1 Answer 1

0

You have assertGt(_buyerBalance,0) and this forge test will fuzz values of _buyerBalance for you. The error says that when _buyerBalance = 0, the assertion fails.

That makes sense because you are asserting _buyerBalance > 0 and an input of 0 is not > 0. Try assertGe(_buyerBalance,0) if you really intend to allow _buyerBalance >= 0.

4
  • AHHHH! I kind of figured this was the case or had an idea it was the case I should say. I need to get a good hold of fuzzing as I am not used to it. However, I tried to change assertionGt to assertionGe and the error still shows. It shows for both of my function testings. So indirectly, it did what is was supposed to do? So when you fuzz test, you are supposed to get an error?
    – EGstacking
    Jan 8 at 18:30
  • I also updated my code and now I am getting a new assertion error once I deleted my parameters for the buyListing function(whihc I now understand how fuzzing works).
    – EGstacking
    Jan 8 at 18:59
  • you need to do this: stackoverflow.com/help/minimal-reproducible-example and then it will be easier to identify and fix the issue.
    – Bob Baxley
    Jan 8 at 21:31
  • I will definetly check that out thank you! Also, how would a participant or caller of a smart contract be represented in the contract itseslf? Would it be msg.sender(as in the person who is CALLING said contract)? And how would the deployer of the smart contratc be represented( as in would the deployer of the smart contract be represented as owner or msg.owner)?
    – EGstacking
    Jan 9 at 18:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.