Solidity – Handling Custom Errors with Multiple Errors in Foundry expectRevert

custom-errorserrorforgefoundrysolidity

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

Best Answer

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

Related Topic