mirror of
https://github.com/0glabs/0g-chain.git
synced 2024-12-26 00:05:18 +00:00
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:
parent
20b3fa53e3
commit
72bfee6523
@ -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
|
||||
}
|
||||
|
||||
|
@ -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))
|
||||
|
@ -91,7 +91,7 @@ func (suite *KeeperTestSuite) TestDeposit() {
|
||||
},
|
||||
errArgs{
|
||||
expectPass: false,
|
||||
contains: "insufficient funds",
|
||||
contains: "insufficient funds: the requested deposit amount",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user