Skip to content

Conversation

jmakwana01
Copy link

PR: Fix fuzzing in PriceIsRightTest

Closes: #47 #46


What changed

  • Constrained fuzzing range with vm.assume(amount <= 10 ether)
  • Ensured the test contract always has enough ETH for any fuzz input (vm.deal(address(this), amount + 1 ether))
  • Kept the invariant check: 1 ether should succeed, everything else should revert

Why
The old fuzz test failed because Foundry would generate massive values for amount that couldn’t even be sent as msg.value.
This caused the revert to happen before reaching the contract, making the test misleading.

Now, fuzzing is limited to a realistic range, and the contract always has enough ETH to pay for the call.
This way the test actually checks the intended logic:

  • ✅ succeeds when exactly 1 ether is sent
  • ❌ reverts when anything else is sent

How to test
Run:

forge test

Expected:

  • All tests pass
  • Fuzzing explores 0–10 ether range

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant