From befeed8e3ac51a04395a38cd7011729a1d91897c Mon Sep 17 00:00:00 2001 From: adu Date: Mon, 23 Sep 2024 17:17:13 +0800 Subject: [PATCH] refactor: optimize errors --- docs/native_deposit_workflow.wsd | 2 +- src/core/ExocoreGateway.sol | 2 +- src/libraries/Errors.sol | 12 ++---------- src/storage/BootstrapStorage.sol | 2 +- src/storage/ClientChainGatewayStorage.sol | 2 +- test/foundry/unit/ClientChainGateway.t.sol | 4 ++-- test/mocks/ExocoreGatewayMock.sol | 2 +- 7 files changed, 9 insertions(+), 17 deletions(-) diff --git a/docs/native_deposit_workflow.wsd b/docs/native_deposit_workflow.wsd index 56cecbe8..cd84a56a 100644 --- a/docs/native_deposit_workflow.wsd +++ b/docs/native_deposit_workflow.wsd @@ -71,7 +71,7 @@ start :Get the capsule associated with the message sender; if (capsule == address(0)) then (yes) - :Revert with CapsuleNotExist error; + :Revert with CapsuleDoesNotExist error; stop endif diff --git a/src/core/ExocoreGateway.sol b/src/core/ExocoreGateway.sol index 398f9fab..d93c8992 100644 --- a/src/core/ExocoreGateway.sol +++ b/src/core/ExocoreGateway.sol @@ -312,7 +312,7 @@ contract ExocoreGateway is (bool success, bytes memory responseOrReason) = address(this).call(abi.encodePacked(selector_, abi.encode(_origin.srcEid, _origin.nonce, act, payload))); if (!success) { - revert Errors.RequestExecuteFailed(act, _origin.nonce, responseOrReason); + revert Errors.RequestOrResponseExecuteFailed(act, _origin.nonce, responseOrReason); } // decode to get the response, and send it back if it is not empty diff --git a/src/libraries/Errors.sol b/src/libraries/Errors.sol index d065806b..beef06e5 100644 --- a/src/libraries/Errors.sol +++ b/src/libraries/Errors.sol @@ -124,7 +124,7 @@ library Errors { error BootstrapValidatorNameLengthZero(); /// @dev Indicates an operation failed because the specified vault does not exist. - error VaultNotExist(); + error VaultDoesNotExist(); /// @dev Indicates that an operation which is not yet supported is requested. error NotYetSupported(); @@ -157,7 +157,7 @@ library Errors { /// @dev ClientChainGateway: token addition must happen via Exocore error ClientChainGatewayTokenAdditionViaExocore(); /// @notice Error thrown when the ExoCapsule does not exist. - error CapsuleNotExist(); + error CapsuleDoesNotExist(); ////////////////////////////////////// // ClientGatewayLzReceiver Errors // @@ -235,12 +235,6 @@ library Errors { /// @dev thrown when dissociateOperatorFromEVMStaker failed error DissociateOperatorFailed(uint32 clientChainId, address staker); - /// @notice Thrown when the execution of a request fails - /// @param act The action that failed. - /// @param nonce The LayerZero nonce. - /// @param reason The reason for the failure. - error RequestExecuteFailed(Action act, uint64 nonce, bytes reason); - /// @notice Thrown when the execution of a precompile call fails. /// @param selector_ The function selector of the precompile call. /// @param reason The reason for the failure. @@ -275,8 +269,6 @@ library Errors { /// @notice Thrown when the whitelist tokens list is too long. error WhitelistTokensListTooLong(); - error MismatchMessageHanlder(); - //////////////////////////////////////// // NativeRestakingController Errors // //////////////////////////////////////// diff --git a/src/storage/BootstrapStorage.sol b/src/storage/BootstrapStorage.sol index b67c10c7..d147603e 100644 --- a/src/storage/BootstrapStorage.sol +++ b/src/storage/BootstrapStorage.sol @@ -321,7 +321,7 @@ contract BootstrapStorage is GatewayStorage { function _getVault(address token) internal view returns (IVault) { IVault vault = tokenToVault[token]; if (address(vault) == address(0)) { - revert Errors.VaultNotExist(); + revert Errors.VaultDoesNotExist(); } return vault; } diff --git a/src/storage/ClientChainGatewayStorage.sol b/src/storage/ClientChainGatewayStorage.sol index e6c78b14..33c835f6 100644 --- a/src/storage/ClientChainGatewayStorage.sol +++ b/src/storage/ClientChainGatewayStorage.sol @@ -113,7 +113,7 @@ contract ClientChainGatewayStorage is BootstrapStorage { function _getCapsule(address owner) internal view returns (IExoCapsule) { IExoCapsule capsule = ownerToCapsule[owner]; if (address(capsule) == address(0)) { - revert Errors.CapsuleNotExist(); + revert Errors.CapsuleDoesNotExist(); } return capsule; } diff --git a/test/foundry/unit/ClientChainGateway.t.sol b/test/foundry/unit/ClientChainGateway.t.sol index c3e5c872..8bf7d3b7 100644 --- a/test/foundry/unit/ClientChainGateway.t.sol +++ b/test/foundry/unit/ClientChainGateway.t.sol @@ -332,7 +332,7 @@ contract WithdrawNonBeaconChainETHFromCapsule is SetUp { address payable userWithoutCapsule = payable(address(0x123)); vm.prank(userWithoutCapsule); - vm.expectRevert(Errors.CapsuleNotExist.selector); + vm.expectRevert(Errors.CapsuleDoesNotExist.selector); clientGateway.withdrawNonBeaconChainETHFromCapsule(userWithoutCapsule, withdrawAmount); } @@ -394,7 +394,7 @@ contract WithdrawalPrincipalFromExocore is SetUp { function test_revert_withdrawVirtualStakedETH() public { // Try to withdraw VIRTUAL_STAKED_ETH vm.prank(user); - vm.expectRevert(Errors.VaultNotExist.selector); + vm.expectRevert(Errors.VaultDoesNotExist.selector); clientGateway.withdrawPrincipalFromExocore(VIRTUAL_STAKED_ETH_ADDRESS, WITHDRAWAL_AMOUNT); } diff --git a/test/mocks/ExocoreGatewayMock.sol b/test/mocks/ExocoreGatewayMock.sol index 4572eea4..c75f323b 100644 --- a/test/mocks/ExocoreGatewayMock.sol +++ b/test/mocks/ExocoreGatewayMock.sol @@ -329,7 +329,7 @@ contract ExocoreGatewayMock is (bool success, bytes memory responseOrReason) = address(this).call(abi.encodePacked(selector_, abi.encode(_origin.srcEid, _origin.nonce, act, payload))); if (!success) { - revert Errors.RequestExecuteFailed(act, _origin.nonce, responseOrReason); + revert Errors.RequestOrResponseExecuteFailed(act, _origin.nonce, responseOrReason); } emit MessageExecuted(act, _origin.nonce);