2

I am attempting to expectRevert on a custom error with MULTIPLE parameters by following the example in the office Foundry. I am able to get it to work with a single parameter. But as soon as I add a second parameter to the custom error I get an error in the forge test runner.

https://book.getfoundry.sh/cheatcodes/expect-revert

Does anyone know what could be causing this issue? Any direction would be greatly appreciated.

Contract

error MaximumContributionExceeded(uint256 isIndividual, uint256 temp);
...
revert MaximumContributionExceeded({isIndividual: 1, temp: 2});

Test (Foundry Test Contract)

bytes4 selector = bytes4(keccak256("MaximumContributionExceeded(uint256, uint256)"));
vm.expectRevert(abi.encodeWithSelector(selector, 1, 2));
ico.contribute{value: 1501 ether}();

Error

[FAIL. Reason: Error != expected error: 0xd38ddc2300000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002 != 0x1d3d86b7] 

Full code https://gist.github.com/bd9b4964bc96e88cb6da5a2d59e5672c

1 Answer 1

3

I had to remove the space between uint256 and uint256 on this line: bytes4 selector = bytes4(keccak256("MaximumContributionExceeded(uint256,uint256)"));

1
  • Very nice! Thanks
    – Russo
    Nov 1 at 3:58

Your Answer

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

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