From 091f3209265087656ab31e4e518826e39b6d5236 Mon Sep 17 00:00:00 2001 From: MathisGD Date: Thu, 10 Aug 2023 12:16:29 +0200 Subject: [PATCH] style: improve error message --- src/Blue.sol | 8 ++++---- src/libraries/Errors.sol | 2 +- src/libraries/ErrorsLib.sol | 21 +++++++++++++++++++++ test/forge/Blue.t.sol | 16 ++++++++-------- 4 files changed, 34 insertions(+), 13 deletions(-) create mode 100644 src/libraries/ErrorsLib.sol diff --git a/src/Blue.sol b/src/Blue.sol index d57494faf..9099e62d1 100644 --- a/src/Blue.sol +++ b/src/Blue.sol @@ -149,7 +149,7 @@ contract Blue is IBlue { { Id id = market.id(); require(lastUpdate[id] != 0, Errors.MARKET_NOT_CREATED); - require(UtilsLib.exactlyOneZero(amount, shares), Errors.NOT_EXACTLY_ONE_ZERO); + require(UtilsLib.exactlyOneZero(amount, shares), Errors.INCONSISTENT_INPUT); require(onBehalf != address(0), Errors.ZERO_ADDRESS); _accrueInterests(market, id); @@ -173,7 +173,7 @@ contract Blue is IBlue { { Id id = market.id(); require(lastUpdate[id] != 0, Errors.MARKET_NOT_CREATED); - require(UtilsLib.exactlyOneZero(amount, shares), Errors.NOT_EXACTLY_ONE_ZERO); + require(UtilsLib.exactlyOneZero(amount, shares), Errors.INCONSISTENT_INPUT); // No need to verify that onBehalf != address(0) thanks to the authorization check. require(receiver != address(0), Errors.ZERO_ADDRESS); require(_isSenderAuthorized(onBehalf), Errors.UNAUTHORIZED); @@ -201,7 +201,7 @@ contract Blue is IBlue { { Id id = market.id(); require(lastUpdate[id] != 0, Errors.MARKET_NOT_CREATED); - require(UtilsLib.exactlyOneZero(amount, shares), Errors.NOT_EXACTLY_ONE_ZERO); + require(UtilsLib.exactlyOneZero(amount, shares), Errors.INCONSISTENT_INPUT); // No need to verify that onBehalf != address(0) thanks to the authorization check. require(receiver != address(0), Errors.ZERO_ADDRESS); require(_isSenderAuthorized(onBehalf), Errors.UNAUTHORIZED); @@ -228,7 +228,7 @@ contract Blue is IBlue { { Id id = market.id(); require(lastUpdate[id] != 0, Errors.MARKET_NOT_CREATED); - require(UtilsLib.exactlyOneZero(amount, shares), Errors.NOT_EXACTLY_ONE_ZERO); + require(UtilsLib.exactlyOneZero(amount, shares), Errors.INCONSISTENT_INPUT); require(onBehalf != address(0), Errors.ZERO_ADDRESS); _accrueInterests(market, id); diff --git a/src/libraries/Errors.sol b/src/libraries/Errors.sol index 5b7570822..b7ac25c7b 100644 --- a/src/libraries/Errors.sol +++ b/src/libraries/Errors.sol @@ -18,7 +18,7 @@ library Errors { string internal constant ZERO_AMOUNT = "zero amount"; - string internal constant NOT_EXACTLY_ONE_ZERO = "not exactly one zero"; + string internal constant INCONSISTENT_INPUT = "inconsistent input"; string internal constant ZERO_ADDRESS = "zero address"; diff --git a/src/libraries/ErrorsLib.sol b/src/libraries/ErrorsLib.sol new file mode 100644 index 000000000..9883f584f --- /dev/null +++ b/src/libraries/ErrorsLib.sol @@ -0,0 +1,21 @@ +// SPDX-License-Identifier: UNLICENSED +pragma solidity ^0.8.0; + +library ErrorsLib { + string constant NOT_OWNER = "not owner"; + string constant LLTV_TOO_HIGH = "LLTV too high"; + string constant MAX_FEE_EXCEEDED = "MAX_FEE exceeded"; + string constant IRM_NOT_ENABLED = "IRM not enabled"; + string constant LLTV_NOT_ENABLED = "LLTV not enabled"; + string constant MARKET_CREATED = "market created"; + string constant MARKET_NOT_CREATED = "market not created"; + string constant INCONSISTENT_INPUT = "not exactly one zero"; + string constant ZERO_AMOUNT = "zero amount"; + string constant ZERO_ADDRESS = "zero address"; + string constant UNAUTHORIZED = "unauthorized"; + string constant INSUFFICIENT_COLLATERAL = "insufficient collateral"; + string constant INSUFFICIENT_LIQUIDITY = "insufficient liquidity"; + string constant HEALTHY_POSITION = "position is healthy"; + string constant INVALID_SIGNATURE = "invalid signature"; + string constant SIGNATURE_EXPIRED = "signature expired"; +} diff --git a/test/forge/Blue.t.sol b/test/forge/Blue.t.sol index 931b0aa76..8745ed857 100644 --- a/test/forge/Blue.t.sol +++ b/test/forge/Blue.t.sol @@ -750,24 +750,24 @@ contract BlueTest is } function testInputZero() public { - vm.expectRevert(bytes(Errors.NOT_EXACTLY_ONE_ZERO)); + vm.expectRevert(bytes(Errors.INCONSISTENT_INPUT)); blue.supply(market, 0, 0, address(this), hex""); - vm.expectRevert(bytes(Errors.NOT_EXACTLY_ONE_ZERO)); + vm.expectRevert(bytes(Errors.INCONSISTENT_INPUT)); blue.supply(market, 1, 1, address(this), hex""); - vm.expectRevert(bytes(Errors.NOT_EXACTLY_ONE_ZERO)); + vm.expectRevert(bytes(Errors.INCONSISTENT_INPUT)); blue.withdraw(market, 0, 0, address(this), address(this)); - vm.expectRevert(bytes(Errors.NOT_EXACTLY_ONE_ZERO)); + vm.expectRevert(bytes(Errors.INCONSISTENT_INPUT)); blue.withdraw(market, 1, 1, address(this), address(this)); - vm.expectRevert(bytes(Errors.NOT_EXACTLY_ONE_ZERO)); + vm.expectRevert(bytes(Errors.INCONSISTENT_INPUT)); blue.borrow(market, 0, 0, address(this), address(this)); - vm.expectRevert(bytes(Errors.NOT_EXACTLY_ONE_ZERO)); + vm.expectRevert(bytes(Errors.INCONSISTENT_INPUT)); blue.borrow(market, 1, 1, address(this), address(this)); - vm.expectRevert(bytes(Errors.NOT_EXACTLY_ONE_ZERO)); + vm.expectRevert(bytes(Errors.INCONSISTENT_INPUT)); blue.repay(market, 0, 0, address(this), hex""); - vm.expectRevert(bytes(Errors.NOT_EXACTLY_ONE_ZERO)); + vm.expectRevert(bytes(Errors.INCONSISTENT_INPUT)); blue.repay(market, 1, 1, address(this), hex""); vm.expectRevert(bytes(Errors.ZERO_AMOUNT));