I am trying to check for a custom error with expectRevert
in my Foundry test. Everything works however, after converting the following test to a fuzz test, it no longer works. How can I resolve this?
function test_fee_too_large(uint256 fee) public {
vm.assume(fee > 1 ether);
hoax(alice);
bytes4 selector = bytes4(keccak256("WrongInitiationFee(address)"));
vm.expectRevert(abi.encodeWithSelector(selector, alice));
emit log_named_uint("fee", fee);
dao.join{value: fee}();
}
Error:
Failing tests:
Encountered 1 failing test in test/join.t.sol:Join
[FAIL. Reason: Call reverted as expected, but without data Counterexample: calldata=0xd874ad920000000000000000000000000000000100000000000000000000000000000001, args=[340282366920938463463374607431768211457]] test_fee_too_large(uint256) (runs: 2, μ: 23105, ~: 23105)
However, it works as expected when I send a hardcoded value in as the value
to dao.join
function test_fee_too_large(uint256 fee) public {
vm.assume(fee > 1 ether);
hoax(alice);
bytes4 selector = bytes4(keccak256("WrongInitiationFee(address)"));
vm.expectRevert(abi.encodeWithSelector(selector, alice));
emit log_named_uint("fee", fee);
dao.join{value: 100 ether}();
}
error WrongInitiationFee(address caller);
join
function on contract:
function join() public payable {
if (members[msg.sender] == true) {
revert AlreadyMember(msg.sender);
}
// only work with exactly 1 ETH
if (msg.value != 1 ether) {
revert WrongInitiationFee(msg.sender);
}
members[msg.sender] = true;
memberCount++;
emit MemberJoined(msg.sender);
// console.log("New member joined: %s", members[msg.sender]);
}
bound(fee, 2 ether, 10 ether);
instead ofvm.assume(fee > 1 ether);
Same error...