From fc2a267daa35427360d802230678342f94ba3bbc Mon Sep 17 00:00:00 2001 From: garyghayrat Date: Mon, 5 Feb 2024 13:05:48 -0500 Subject: [PATCH] Use `vm.expectRevert("")` instead of `vm.expectRevert()` --- test/ERC6538Registry.t.sol | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/test/ERC6538Registry.t.sol b/test/ERC6538Registry.t.sol index 1ce50da..7608175 100644 --- a/test/ERC6538Registry.t.sol +++ b/test/ERC6538Registry.t.sol @@ -48,6 +48,13 @@ contract ERC6538RegistryTest is Test, Deploy { (uint8 v, bytes32 r, bytes32 s) = vm.sign(_registrantPrivateKey, _hash); _signature = abi.encodePacked(r, s, v); } + + function _notVmOrConsole(address _address) public pure { + // This function is used to avoid calling the VM or the console, which would return error + // messages. It is used in tests where we want assert a function reverts without a message. + vm.assume(_address != address(vm)); + vm.assume(_address != address(address(0x000000000000000000636F6e736F6c652e6c6f67))); + } } // Test harness to expose internal contract methods for test purpose only @@ -228,10 +235,11 @@ contract RegisterKeysOnBehalf is ERC6538RegistryTest { ) external { (address notRegistrant, uint256 notRegistrantPrivateKey) = makeAddrAndKey(seed); vm.assume(notRegistrant != registrant); + _notVmOrConsole(registrant); bytes memory signature = _generateRegistrationSignature(notRegistrantPrivateKey, schemeId, stealthMetaAddress, 0); - vm.expectRevert(); + vm.expectRevert(bytes("")); registry.registerKeysOnBehalf(registrant, schemeId, signature, stealthMetaAddress); } @@ -247,7 +255,7 @@ contract RegisterKeysOnBehalf is ERC6538RegistryTest { bytes memory signature = _generateRegistrationSignature(registrantPrivateKey, wrongSchemeId, stealthMetaAddress, 0); - vm.expectRevert(); + vm.expectRevert(bytes("")); registry.registerKeysOnBehalf(registrant, schemeId, signature, stealthMetaAddress); } @@ -263,7 +271,7 @@ contract RegisterKeysOnBehalf is ERC6538RegistryTest { bytes memory signature = _generateRegistrationSignature(registrantPrivateKey, schemeId, wrongStealthAMetaAddress, 0); - vm.expectRevert(); + vm.expectRevert(bytes("")); registry.registerKeysOnBehalf(registrant, schemeId, signature, stealthMetaAddress); } @@ -278,7 +286,7 @@ contract RegisterKeysOnBehalf is ERC6538RegistryTest { bytes memory signature = _generateRegistrationSignature(registrantPrivateKey, schemeId, stealthMetaAddress, nonce); - vm.expectRevert(); + vm.expectRevert(bytes("")); registry.registerKeysOnBehalf(registrant, schemeId, signature, stealthMetaAddress); } @@ -293,7 +301,7 @@ contract RegisterKeysOnBehalf is ERC6538RegistryTest { registry.registerKeysOnBehalf(registrant, schemeId, signature, stealthMetaAddress); - vm.expectRevert(); + vm.expectRevert(bytes("")); registry.registerKeysOnBehalf(registrant, schemeId, signature, stealthMetaAddress); } @@ -314,7 +322,8 @@ contract RegisterKeysOnBehalf is ERC6538RegistryTest { uint256 schemeId, bytes memory stealthMetaAddress ) external { - vm.expectRevert(); + _notVmOrConsole(registrant); + vm.expectRevert(bytes("")); registry.registerKeysOnBehalf(registrant, schemeId, "", stealthMetaAddress); } }