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.


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


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}();


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

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

2 Answers 2


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

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

While the selected answer by currenthandle should fix your issue, I would suggest programmatically using the error selector.

vm.expectRevert(MyContract.MaximumContributionExceeded.selector, 1, 2)

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.