Skip to content

Commit

Permalink
replacing fmt.Errorf (#1087)
Browse files Browse the repository at this point in the history
* replacing fmt.Errorf with errors.New

* fixing errors
  • Loading branch information
avkr003 authored Dec 31, 2024
1 parent dcd1cf4 commit 427ea25
Show file tree
Hide file tree
Showing 41 changed files with 109 additions and 113 deletions.
2 changes: 1 addition & 1 deletion app/ante/gov_expedited_ante.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func (g GovExpeditedProposalsDecorator) isWhitelisted(msgType string) bool {
func (g GovExpeditedProposalsDecorator) validateExpeditedGovProp(prop *govv1.MsgSubmitProposal) error {
//msgs := prop.GetMessages()
//if len(msgs) == 0 {
// return fmt.Errorf("unsupported expedited proposal type")
// return errors.New("unsupported expedited proposal type")
//}
//for _, message := range msgs {
// // in case of legacy content submitted using govv1.MsgSubmitProposal
Expand Down
5 changes: 3 additions & 2 deletions app/ante/gov_vote_ante.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package ante

import (
"cosmossdk.io/math"
"errors"
"fmt"

"cosmossdk.io/math"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/authz"
Expand Down Expand Up @@ -116,7 +117,7 @@ func (g GovVoteDecorator) ValidateVoteMsgs(ctx sdk.Context, msgs []sdk.Msg) erro
for _, v := range execMsg.Msgs {
var innerMsg sdk.Msg
if err := g.cdc.UnpackAny(v, &innerMsg); err != nil {
return fmt.Errorf("cannot unmarshal authz exec msgs")
return errors.New("cannot unmarshal authz exec msgs")
}
if err := validMsg(innerMsg); err != nil {
return err
Expand Down
12 changes: 6 additions & 6 deletions x/amm/keeper/denom_liquidity.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package keeper

import (
storetypes "cosmossdk.io/store/types"
"fmt"
"github.com/cosmos/cosmos-sdk/runtime"
"errors"

"cosmossdk.io/math"
"cosmossdk.io/store/prefix"
storetypes "cosmossdk.io/store/types"
"github.com/cosmos/cosmos-sdk/runtime"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/elys-network/elys/x/amm/types"
)
Expand Down Expand Up @@ -53,7 +53,7 @@ func (k Keeper) IncreaseDenomLiquidity(ctx sdk.Context, denom string, amount mat
store := prefix.NewStore(runtime.KVStoreAdapter(k.storeService.OpenKVStore(ctx)), types.KeyPrefix(types.DenomLiquidityKeyPrefix))
b := store.Get(types.DenomLiquidityKey(denom))
if b == nil {
return fmt.Errorf("denom not found")
return errors.New("denom not found")
}
var denomLiquidity types.DenomLiquidity
k.cdc.MustUnmarshal(b, &denomLiquidity)
Expand All @@ -68,12 +68,12 @@ func (k Keeper) DecreaseDenomLiquidity(ctx sdk.Context, denom string, amount mat
store := prefix.NewStore(runtime.KVStoreAdapter(k.storeService.OpenKVStore(ctx)), types.KeyPrefix(types.DenomLiquidityKeyPrefix))
b := store.Get(types.DenomLiquidityKey(denom))
if b == nil {
return fmt.Errorf("denom not found")
return errors.New("denom not found")
}
var denomLiquidity types.DenomLiquidity
k.cdc.MustUnmarshal(b, &denomLiquidity)
if denomLiquidity.Liquidity.LT(amount) {
return fmt.Errorf("not enough liquidity")
return errors.New("not enough liquidity")
}
denomLiquidity.Liquidity = denomLiquidity.Liquidity.Sub(amount)
newB := k.cdc.MustMarshal(&denomLiquidity)
Expand Down
3 changes: 2 additions & 1 deletion x/amm/keeper/msg_server_create_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package keeper

import (
"context"
"errors"
"fmt"
"strconv"
"strings"
Expand All @@ -22,7 +23,7 @@ func (k msgServer) CreatePool(goCtx context.Context, msg *types.MsgCreatePool) (
params := k.GetParams(ctx)

if !params.IsCreatorAllowed(msg.Sender) {
return nil, fmt.Errorf("sender is not allowed to create pool")
return nil, errors.New("sender is not allowed to create pool")
}

sender := sdk.MustAccAddressFromBech32(msg.Sender)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package keeper_test

import (
"fmt"

"errors"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"

sdkmath "cosmossdk.io/math"
Expand Down Expand Up @@ -126,7 +125,7 @@ func (suite *AmmKeeperTestSuite) TestGetExternalLiquidityRatio() {
},
},
expectedResult: nil,
expectedError: fmt.Errorf("asset profile not found for denom"),
expectedError: errors.New("asset profile not found for denom"),
},
{
name: "division by zero",
Expand Down
6 changes: 2 additions & 4 deletions x/amm/types/calc_exit_pool.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package types

import (
"errors"
"fmt"

errorsmod "cosmossdk.io/errors"
sdkmath "cosmossdk.io/math"
"errors"
sdk "github.com/cosmos/cosmos-sdk/types"
)

Expand Down Expand Up @@ -129,7 +127,7 @@ func CalcExitPool(
}
for _, asset := range newAssetPools {
if asset.Token.Amount.IsNegative() {
return sdk.Coins{}, sdkmath.LegacyZeroDec(), fmt.Errorf("out amount exceeds liquidity balance")
return sdk.Coins{}, sdkmath.LegacyZeroDec(), errors.New("out amount exceeds liquidity balance")
}
}

Expand Down
4 changes: 2 additions & 2 deletions x/amm/types/message_create_pool_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package types_test

import (
"fmt"
"errors"
"testing"

sdkmath "cosmossdk.io/math"
Expand Down Expand Up @@ -96,7 +96,7 @@ func TestMsgCreatePool_ValidateBasic(t *testing.T) {
},
},
},
err: fmt.Errorf("invalid pool asset"),
err: errors.New("invalid pool asset"),
},
{
name: "valid address",
Expand Down
4 changes: 2 additions & 2 deletions x/amm/types/message_exit_pool_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package types_test

import (
"fmt"
"errors"
"testing"

"cosmossdk.io/math"
Expand Down Expand Up @@ -40,7 +40,7 @@ func TestMsgExitPool_ValidateBasic(t *testing.T) {
ShareAmountIn: math.NewInt(100),
MinAmountsOut: sdk.Coins{sdk.Coin{Denom: "uusdc", Amount: math.NewInt(-100)}},
},
err: fmt.Errorf("negative coin amount"),
err: errors.New("negative coin amount"),
},
{
name: "ShareAmount is Nil",
Expand Down
4 changes: 2 additions & 2 deletions x/amm/types/message_join_pool_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package types_test

import (
"fmt"
"errors"
"testing"

"cosmossdk.io/math"
Expand Down Expand Up @@ -38,7 +38,7 @@ func TestMsgJoinPool_ValidateBasic(t *testing.T) {
ShareAmountOut: math.NewInt(100),
MaxAmountsIn: sdk.Coins{sdk.Coin{Denom: "uusdc", Amount: math.NewInt(-100)}},
},
err: fmt.Errorf("negative coin amount"),
err: errors.New("negative coin amount"),
},
{
name: "ShareAmount is Nil",
Expand Down
8 changes: 4 additions & 4 deletions x/amm/types/message_swap_by_denom_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package types

import (
"fmt"
"errors"
"testing"

sdkmath "cosmossdk.io/math"
Expand Down Expand Up @@ -43,7 +43,7 @@ func TestMsgSwapByDenom_ValidateBasic(t *testing.T) {
DenomIn: ptypes.ATOM,
DenomOut: ptypes.BaseCurrency,
},
err: fmt.Errorf("negative coin amount"),
err: errors.New("negative coin amount"),
},
{
name: "Invalid DenomIn",
Expand All @@ -53,7 +53,7 @@ func TestMsgSwapByDenom_ValidateBasic(t *testing.T) {
DenomIn: "invalid denom in",
DenomOut: ptypes.BaseCurrency,
},
err: fmt.Errorf("invalid denom"),
err: errors.New("invalid denom"),
},
{
name: "Invalid Denomout",
Expand All @@ -63,7 +63,7 @@ func TestMsgSwapByDenom_ValidateBasic(t *testing.T) {
DenomIn: ptypes.ATOM,
DenomOut: "invalid denom out",
},
err: fmt.Errorf("invalid denom"),
err: errors.New("invalid denom"),
},
}
for _, tt := range tests {
Expand Down
4 changes: 2 additions & 2 deletions x/amm/types/message_swap_exact_amount_in.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package types
import (
errorsmod "cosmossdk.io/errors"
sdkmath "cosmossdk.io/math"
"fmt"
"errors"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
)
Expand Down Expand Up @@ -52,7 +52,7 @@ func (msg *MsgSwapExactAmountIn) ValidateBasic() error {
return err
}
if msg.TokenIn.IsZero() {
return fmt.Errorf("token in is zero")
return errors.New("token in is zero")
}
return nil
}
8 changes: 4 additions & 4 deletions x/amm/types/message_swap_exact_amount_in_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package types_test

import (
"fmt"
"errors"
"testing"

"cosmossdk.io/math"
Expand Down Expand Up @@ -57,7 +57,7 @@ func TestMsgSwapExactAmountIn_ValidateBasic(t *testing.T) {
TokenOutMinAmount: math.NewInt(1),
Recipient: sample.AccAddress(),
},
err: fmt.Errorf("invalid denom"),
err: errors.New("invalid denom"),
},
{
name: "Invalid TokenIn",
Expand All @@ -68,7 +68,7 @@ func TestMsgSwapExactAmountIn_ValidateBasic(t *testing.T) {
TokenOutMinAmount: math.NewInt(1),
Recipient: sample.AccAddress(),
},
err: fmt.Errorf("negative coin amount"),
err: errors.New("negative coin amount"),
},
{
name: "Invalid TokenIn amount",
Expand All @@ -79,7 +79,7 @@ func TestMsgSwapExactAmountIn_ValidateBasic(t *testing.T) {
TokenOutMinAmount: math.NewInt(1),
Recipient: sample.AccAddress(),
},
err: fmt.Errorf("token in is zero"),
err: errors.New("token in is zero"),
},
}
for _, tt := range tests {
Expand Down
4 changes: 2 additions & 2 deletions x/amm/types/message_swap_exact_amount_out.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package types
import (
errorsmod "cosmossdk.io/errors"
sdkmath "cosmossdk.io/math"
"fmt"
"errors"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
)
Expand Down Expand Up @@ -52,7 +52,7 @@ func (msg *MsgSwapExactAmountOut) ValidateBasic() error {
return err
}
if msg.TokenOut.IsZero() {
return fmt.Errorf("token in is zero")
return errors.New("token in is zero")
}
return nil
}
8 changes: 4 additions & 4 deletions x/amm/types/message_swap_exact_amount_out_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package types_test

import (
"fmt"
"errors"
"testing"

"cosmossdk.io/math"
Expand Down Expand Up @@ -57,7 +57,7 @@ func TestMsgSwapExactAmountOut_ValidateBasic(t *testing.T) {
TokenInMaxAmount: math.NewInt(1),
Recipient: sample.AccAddress(),
},
err: fmt.Errorf("invalid denom"),
err: errors.New("invalid denom"),
},
{
name: "Invalid tokenOut",
Expand All @@ -68,7 +68,7 @@ func TestMsgSwapExactAmountOut_ValidateBasic(t *testing.T) {
TokenInMaxAmount: math.NewInt(1),
Recipient: sample.AccAddress(),
},
err: fmt.Errorf("negative coin amount"),
err: errors.New("negative coin amount"),
},
{
name: "Invalid tokenOut amount",
Expand All @@ -79,7 +79,7 @@ func TestMsgSwapExactAmountOut_ValidateBasic(t *testing.T) {
TokenInMaxAmount: math.NewInt(1),
Recipient: sample.AccAddress(),
},
err: fmt.Errorf("token in is zero"),
err: errors.New("token in is zero"),
},
}
for _, tt := range tests {
Expand Down
3 changes: 1 addition & 2 deletions x/amm/types/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package types
import (
"cosmossdk.io/math"
"errors"
"fmt"
sdk "github.com/cosmos/cosmos-sdk/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
Expand Down Expand Up @@ -39,7 +38,7 @@ func (p Params) Validate() error {
return errors.New("pool creation fee must not be empty")
}
if p.PoolCreationFee.IsNegative() {
return fmt.Errorf("pool creation fee must be positive")
return errors.New("pool creation fee must be positive")
}

for _, asset := range p.BaseAssets {
Expand Down
3 changes: 2 additions & 1 deletion x/amm/types/pool_asset.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ package types

import (
"cosmossdk.io/math"
"errors"
"fmt"
)

func (asset PoolAsset) Validate() error {
if !asset.Token.IsValid() {
return fmt.Errorf("invalid pool asset token")
return errors.New("invalid pool asset token")
}

if asset.Weight.IsNil() || asset.Weight.IsNegative() {
Expand Down
4 changes: 2 additions & 2 deletions x/amm/types/pool_params.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package types

import (
sdkmath "cosmossdk.io/math"
"fmt"
"errors"
sdk "github.com/cosmos/cosmos-sdk/types"
)

Expand All @@ -12,7 +12,7 @@ var (

func (params PoolParams) Validate() error {
if params.SwapFee.IsNil() {
return fmt.Errorf("swap_fee is nil")
return errors.New("swap_fee is nil")
}

if params.SwapFee.IsNegative() {
Expand Down
Loading

0 comments on commit 427ea25

Please sign in to comment.