Skip to content

Commit

Permalink
style: improve error message
Browse files Browse the repository at this point in the history
  • Loading branch information
MathisGD committed Aug 10, 2023
1 parent 165541d commit 091f320
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 13 deletions.
8 changes: 4 additions & 4 deletions src/Blue.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/libraries/Errors.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down
21 changes: 21 additions & 0 deletions src/libraries/ErrorsLib.sol
Original file line number Diff line number Diff line change
@@ -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";
}
16 changes: 8 additions & 8 deletions test/forge/Blue.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down

0 comments on commit 091f320

Please sign in to comment.