Minor best practices edits in Hard module (#877)

* put err return inside conditional

* check error type instead of error msg string
This commit is contained in:
Denali Marsh 2021-03-15 16:15:19 +01:00 committed by GitHub
parent 20b3fa53e3
commit 72bfee6523
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 5 additions and 7 deletions

View File

@ -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
}

View File

@ -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))

View File

@ -91,7 +91,7 @@ func (suite *KeeperTestSuite) TestDeposit() {
},
errArgs{
expectPass: false,
contains: "insufficient funds",
contains: "insufficient funds: the requested deposit amount",
},
},
}