diff --git a/x/hard/keeper/borrow.go b/x/hard/keeper/borrow.go index 833cf966..62cd6136 100644 --- a/x/hard/keeper/borrow.go +++ b/x/hard/keeper/borrow.go @@ -1,7 +1,7 @@ package keeper import ( - "strings" + "errors" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" @@ -44,7 +44,7 @@ func (k Keeper) Borrow(ctx sdk.Context, borrower sdk.AccAddress, coins sdk.Coins // Sends coins from Hard module account to user err = k.supplyKeeper.SendCoinsFromModuleToAccount(ctx, types.ModuleAccountName, borrower, coins) if err != nil { - if strings.Contains(err.Error(), "insufficient account funds") { + if errors.Is(err, sdkerrors.ErrInsufficientFunds) { modAccCoins := k.supplyKeeper.GetModuleAccount(ctx, types.ModuleAccountName).GetCoins() for _, coin := range coins { _, isNegative := modAccCoins.SafeSub(sdk.NewCoins(coin)) @@ -56,8 +56,6 @@ func (k Keeper) Borrow(ctx sdk.Context, borrower sdk.AccAddress, coins sdk.Coins } } } - } - if err != nil { return err } diff --git a/x/hard/keeper/deposit.go b/x/hard/keeper/deposit.go index 9df0127c..4187a31e 100644 --- a/x/hard/keeper/deposit.go +++ b/x/hard/keeper/deposit.go @@ -1,7 +1,7 @@ package keeper import ( - "strings" + "errors" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" @@ -44,7 +44,7 @@ func (k Keeper) Deposit(ctx sdk.Context, depositor sdk.AccAddress, coins sdk.Coi err = k.supplyKeeper.SendCoinsFromAccountToModule(ctx, depositor, types.ModuleAccountName, coins) if err != nil { - if strings.Contains(err.Error(), "insufficient account funds") { + if errors.Is(err, sdkerrors.ErrInsufficientFunds) { accCoins := k.accountKeeper.GetAccount(ctx, depositor).SpendableCoins(ctx.BlockTime()) for _, coin := range coins { _, isNegative := accCoins.SafeSub(sdk.NewCoins(coin)) diff --git a/x/hard/keeper/deposit_test.go b/x/hard/keeper/deposit_test.go index a6152b8d..309b2d1e 100644 --- a/x/hard/keeper/deposit_test.go +++ b/x/hard/keeper/deposit_test.go @@ -91,7 +91,7 @@ func (suite *KeeperTestSuite) TestDeposit() { }, errArgs{ expectPass: false, - contains: "insufficient funds", + contains: "insufficient funds: the requested deposit amount", }, }, }