Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: replace deprecated Wrap and Wrapf #1278

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions x/dymns/client/cli/tx_update_resolve_address.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
"fmt"
"time"

"cosmossdk.io/errors"

errorsmod "cosmossdk.io/errors"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/client/tx"
Expand Down Expand Up @@ -43,14 +42,14 @@

subName, dymName, chainIdOrAlias, err := dymnskeeper.ParseDymNameAddress(dymNameAddress)
if err != nil {
return errors.Wrap(err, "failed to parse input Dym-Name-Address")
return errorsmod.Wrap(err, "failed to parse input Dym-Name-Address")

Check warning on line 45 in x/dymns/client/cli/tx_update_resolve_address.go

View check run for this annotation

Codecov / codecov/patch

x/dymns/client/cli/tx_update_resolve_address.go#L45

Added line #L45 was not covered by tests
}

respTranslateChainId, err := queryClient.TranslateAliasOrChainIdToChainId(cmd.Context(), &dymnstypes.QueryTranslateAliasOrChainIdToChainIdRequest{
AliasOrChainId: chainIdOrAlias,
})
if err != nil || respTranslateChainId.ChainId == "" {
return errors.Wrapf(err, "failed to translate alias to chain-id: %s", chainIdOrAlias)
return errorsmod.Wrapf(err, "failed to translate alias to chain-id: %s", chainIdOrAlias)

Check warning on line 52 in x/dymns/client/cli/tx_update_resolve_address.go

View check run for this annotation

Codecov / codecov/patch

x/dymns/client/cli/tx_update_resolve_address.go#L52

Added line #L52 was not covered by tests
}

chainId := respTranslateChainId.ChainId
Expand Down
25 changes: 13 additions & 12 deletions x/lockup/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import (
"context"

errorsmod "cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"google.golang.org/grpc/codes"
Expand Down Expand Up @@ -42,7 +43,7 @@
return nil, status.Error(codes.InvalidArgument, "empty request")
}
if len(req.Owner) == 0 {
return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "empty owner")
return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "empty owner")
}

ctx := sdk.UnwrapSDKContext(goCtx)
Expand All @@ -61,7 +62,7 @@
return nil, status.Error(codes.InvalidArgument, "empty request")
}
if len(req.Owner) == 0 {
return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "empty owner")
return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "empty owner")
}

ctx := sdk.UnwrapSDKContext(goCtx)
Expand All @@ -80,7 +81,7 @@
return nil, status.Error(codes.InvalidArgument, "empty request")
}
if len(req.Owner) == 0 {
return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "empty owner")
return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "empty owner")
}

ctx := sdk.UnwrapSDKContext(goCtx)
Expand All @@ -99,7 +100,7 @@
return nil, status.Error(codes.InvalidArgument, "empty request")
}
if len(req.Owner) == 0 {
return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "empty owner")
return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "empty owner")
}

ctx := sdk.UnwrapSDKContext(goCtx)
Expand All @@ -118,7 +119,7 @@
return nil, status.Error(codes.InvalidArgument, "empty request")
}
if len(req.Owner) == 0 {
return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "empty owner")
return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "empty owner")
}

ctx := sdk.UnwrapSDKContext(goCtx)
Expand All @@ -138,7 +139,7 @@
return nil, status.Error(codes.InvalidArgument, "empty request")
}
if len(req.Owner) == 0 {
return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "empty owner")
return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "empty owner")
}

ctx := sdk.UnwrapSDKContext(goCtx)
Expand Down Expand Up @@ -181,7 +182,7 @@
return nil, status.Error(codes.InvalidArgument, "empty request")
}
if len(req.Owner) == 0 {
return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "empty owner")
return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "empty owner")
}

ctx := sdk.UnwrapSDKContext(goCtx)
Expand All @@ -201,7 +202,7 @@
return nil, status.Error(codes.InvalidArgument, "empty request")
}
if len(req.Owner) == 0 {
return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "empty owner")
return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "empty owner")
}

ctx := sdk.UnwrapSDKContext(goCtx)
Expand All @@ -221,7 +222,7 @@
return nil, status.Error(codes.InvalidArgument, "empty request")
}
if len(req.Owner) == 0 {
return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "empty owner")
return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "empty owner")

Check warning on line 225 in x/lockup/keeper/grpc_query.go

View check run for this annotation

Codecov / codecov/patch

x/lockup/keeper/grpc_query.go#L225

Added line #L225 was not covered by tests
}

ctx := sdk.UnwrapSDKContext(goCtx)
Expand All @@ -242,7 +243,7 @@
return nil, status.Error(codes.InvalidArgument, "empty request")
}
if len(req.Owner) == 0 {
return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "empty owner")
return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "empty owner")
}

ctx := sdk.UnwrapSDKContext(goCtx)
Expand All @@ -262,7 +263,7 @@
return nil, status.Error(codes.InvalidArgument, "empty request")
}
if len(req.Owner) == 0 {
return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "empty owner")
return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "empty owner")
}

ctx := sdk.UnwrapSDKContext(goCtx)
Expand All @@ -281,7 +282,7 @@
return nil, status.Error(codes.InvalidArgument, "empty request")
}
if len(req.Denom) == 0 {
return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "empty denom")
return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "empty denom")

Check warning on line 285 in x/lockup/keeper/grpc_query.go

View check run for this annotation

Codecov / codecov/patch

x/lockup/keeper/grpc_query.go#L285

Added line #L285 was not covered by tests
}

ctx := sdk.UnwrapSDKContext(goCtx)
Expand Down
5 changes: 3 additions & 2 deletions x/lockup/keeper/lock.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"sort"
"time"

errorsmod "cosmossdk.io/errors"
"github.com/cosmos/cosmos-sdk/store/prefix"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
Expand Down Expand Up @@ -55,15 +56,15 @@ func (k Keeper) AddToExistingLock(ctx sdk.Context, owner sdk.AccAddress, coin sd

// if no lock exists for the given owner + denom + duration, return an error
if len(locks) < 1 {
return 0, sdkerrors.Wrapf(types.ErrLockupNotFound, "lock with denom %s before duration %s does not exist", coin.Denom, duration.String())
return 0, errorsmod.Wrapf(types.ErrLockupNotFound, "lock with denom %s before duration %s does not exist", coin.Denom, duration.String())
}

// if existing lock with same duration and denom exists, add to the existing lock
// there should only be a single lock with the same duration + token, thus we take the first lock
lock := locks[0]
_, err := k.AddTokensToLockByID(ctx, lock.ID, owner, coin)
if err != nil {
return 0, sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, err.Error())
return 0, errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, err.Error())
}

return lock.ID, nil
Expand Down
23 changes: 12 additions & 11 deletions x/lockup/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"context"
"fmt"

errorsmod "cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/osmosis-labs/osmosis/v15/osmoutils"
Expand Down Expand Up @@ -60,7 +61,7 @@
// if the owner + duration combination is new, create a new lock.
lock, err := server.keeper.CreateLock(ctx, owner, msg.Coins, msg.Duration)
if err != nil {
return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, err.Error())
return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, err.Error())
}

ctx.EventManager().EmitEvents(sdk.Events{
Expand All @@ -84,16 +85,16 @@

lock, err := server.keeper.GetLockByID(ctx, msg.ID)
if err != nil {
return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, err.Error())
return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, err.Error())

Check warning on line 88 in x/lockup/keeper/msg_server.go

View check run for this annotation

Codecov / codecov/patch

x/lockup/keeper/msg_server.go#L88

Added line #L88 was not covered by tests
}

if msg.Owner != lock.Owner {
return nil, sdkerrors.Wrap(types.ErrNotLockOwner, fmt.Sprintf("msg sender (%s) and lock owner (%s) does not match", msg.Owner, lock.Owner))
return nil, errorsmod.Wrap(types.ErrNotLockOwner, fmt.Sprintf("msg sender (%s) and lock owner (%s) does not match", msg.Owner, lock.Owner))

Check warning on line 92 in x/lockup/keeper/msg_server.go

View check run for this annotation

Codecov / codecov/patch

x/lockup/keeper/msg_server.go#L92

Added line #L92 was not covered by tests
}

unlockingLock, err := server.keeper.BeginUnlock(ctx, lock.ID, msg.Coins)
if err != nil {
return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, err.Error())
return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, err.Error())

Check warning on line 97 in x/lockup/keeper/msg_server.go

View check run for this annotation

Codecov / codecov/patch

x/lockup/keeper/msg_server.go#L97

Added line #L97 was not covered by tests
}

// N.B. begin unlock event is emitted downstream in the keeper method.
Expand All @@ -112,7 +113,7 @@

unlocks, err := server.keeper.BeginUnlockAllNotUnlockings(ctx, owner)
if err != nil {
return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, err.Error())
return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, err.Error())

Check warning on line 116 in x/lockup/keeper/msg_server.go

View check run for this annotation

Codecov / codecov/patch

x/lockup/keeper/msg_server.go#L116

Added line #L116 was not covered by tests
}

// Create the events for this message
Expand Down Expand Up @@ -156,12 +157,12 @@

err = server.keeper.ExtendLockup(ctx, msg.ID, owner, msg.Duration)
if err != nil {
return nil, sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, err.Error())
return nil, errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, err.Error())
}

lock, err := server.keeper.GetLockByID(ctx, msg.ID)
if err != nil {
return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, err.Error())
return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, err.Error())

Check warning on line 165 in x/lockup/keeper/msg_server.go

View check run for this annotation

Codecov / codecov/patch

x/lockup/keeper/msg_server.go#L165

Added line #L165 was not covered by tests
}

ctx.EventManager().EmitEvents(sdk.Events{
Expand All @@ -184,12 +185,12 @@

lock, err := server.keeper.GetLockByID(ctx, msg.ID)
if err != nil {
return &types.MsgForceUnlockResponse{Success: false}, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, err.Error())
return &types.MsgForceUnlockResponse{Success: false}, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, err.Error())

Check warning on line 188 in x/lockup/keeper/msg_server.go

View check run for this annotation

Codecov / codecov/patch

x/lockup/keeper/msg_server.go#L188

Added line #L188 was not covered by tests
}

// check if message sender matches lock owner
if lock.Owner != msg.Owner {
return &types.MsgForceUnlockResponse{Success: false}, sdkerrors.Wrapf(sdkerrors.ErrUnauthorized, "Sender (%s) does not match lock owner (%s)", msg.Owner, lock.Owner)
return &types.MsgForceUnlockResponse{Success: false}, errorsmod.Wrapf(sdkerrors.ErrUnauthorized, "Sender (%s) does not match lock owner (%s)", msg.Owner, lock.Owner)

Check warning on line 193 in x/lockup/keeper/msg_server.go

View check run for this annotation

Codecov / codecov/patch

x/lockup/keeper/msg_server.go#L193

Added line #L193 was not covered by tests
}

// check for chain parameter that the address is allowed to force unlock
Expand All @@ -203,15 +204,15 @@
}
}
if !found {
return &types.MsgForceUnlockResponse{Success: false}, sdkerrors.Wrapf(sdkerrors.ErrUnauthorized, "Sender (%s) not allowed to force unlock", lock.Owner)
return &types.MsgForceUnlockResponse{Success: false}, errorsmod.Wrapf(sdkerrors.ErrUnauthorized, "Sender (%s) not allowed to force unlock", lock.Owner)

Check warning on line 207 in x/lockup/keeper/msg_server.go

View check run for this annotation

Codecov / codecov/patch

x/lockup/keeper/msg_server.go#L207

Added line #L207 was not covered by tests
}

// force unlock given lock
// This also supports the case of force unlocking lock as a whole when msg.Coins
// provided is empty.
err = server.keeper.PartialForceUnlock(ctx, *lock, msg.Coins)
if err != nil {
return &types.MsgForceUnlockResponse{Success: false}, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, err.Error())
return &types.MsgForceUnlockResponse{Success: false}, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, err.Error())
}

return &types.MsgForceUnlockResponse{Success: true}, nil
Expand Down
4 changes: 2 additions & 2 deletions x/lockup/keeper/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"fmt"
"time"

errorsmod "cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/gogoproto/proto"

"github.com/dymensionxyz/dymension/v3/x/lockup/types"
Expand Down Expand Up @@ -226,7 +226,7 @@ func (k Keeper) GetLockByID(ctx sdk.Context, lockID uint64) (*types.PeriodLock,
store := ctx.KVStore(k.storeKey)
lockKey := lockStoreKey(lockID)
if !store.Has(lockKey) {
return nil, sdkerrors.Wrap(types.ErrLockupNotFound, fmt.Sprintf("lock with ID %d does not exist", lockID))
return nil, errorsmod.Wrap(types.ErrLockupNotFound, fmt.Sprintf("lock with ID %d does not exist", lockID))
}
bz := store.Get(lockKey)
err := proto.Unmarshal(bz, &lock)
Expand Down
15 changes: 8 additions & 7 deletions x/lockup/types/msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"fmt"
"time"

errorsmod "cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
)
Expand Down Expand Up @@ -32,7 +33,7 @@
func (m MsgLockTokens) ValidateBasic() error {
_, err := sdk.AccAddressFromBech32(m.Owner)
if err != nil {
return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "Invalid owner address (%s)", err)
return errorsmod.Wrapf(sdkerrors.ErrInvalidAddress, "Invalid owner address (%s)", err)
}

if m.Duration <= 0 {
Expand Down Expand Up @@ -74,7 +75,7 @@
func (m MsgBeginUnlockingAll) ValidateBasic() error {
_, err := sdk.AccAddressFromBech32(m.Owner)
if err != nil {
return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "Invalid owner address (%s)", err)
return errorsmod.Wrapf(sdkerrors.ErrInvalidAddress, "Invalid owner address (%s)", err)
}
return nil
}
Expand Down Expand Up @@ -104,7 +105,7 @@
func (m MsgBeginUnlocking) ValidateBasic() error {
_, err := sdk.AccAddressFromBech32(m.Owner)
if err != nil {
return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "Invalid owner address (%s)", err)
return errorsmod.Wrapf(sdkerrors.ErrInvalidAddress, "Invalid owner address (%s)", err)
}

if m.ID == 0 {
Expand Down Expand Up @@ -146,7 +147,7 @@
func (m MsgExtendLockup) ValidateBasic() error {
_, err := sdk.AccAddressFromBech32(m.Owner)
if err != nil {
return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "Invalid owner address (%s)", err)
return errorsmod.Wrapf(sdkerrors.ErrInvalidAddress, "Invalid owner address (%s)", err)
}
if m.ID == 0 {
return fmt.Errorf("id is empty")
Expand Down Expand Up @@ -182,15 +183,15 @@
func (m MsgForceUnlock) ValidateBasic() error {
_, err := sdk.AccAddressFromBech32(m.Owner)
if err != nil {
return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "Invalid owner address (%s)", err)
return errorsmod.Wrapf(sdkerrors.ErrInvalidAddress, "Invalid owner address (%s)", err)

Check warning on line 186 in x/lockup/types/msgs.go

View check run for this annotation

Codecov / codecov/patch

x/lockup/types/msgs.go#L186

Added line #L186 was not covered by tests
}

if m.ID <= 0 {
return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "lock id should be bigger than 1 (%s)", err)
return errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, "lock id should be bigger than 1 (%s)", err)

Check warning on line 190 in x/lockup/types/msgs.go

View check run for this annotation

Codecov / codecov/patch

x/lockup/types/msgs.go#L190

Added line #L190 was not covered by tests
}

if !m.Coins.IsValid() {
return sdkerrors.Wrap(sdkerrors.ErrInvalidCoins, m.Coins.String())
return errorsmod.Wrap(sdkerrors.ErrInvalidCoins, m.Coins.String())

Check warning on line 194 in x/lockup/types/msgs.go

View check run for this annotation

Codecov / codecov/patch

x/lockup/types/msgs.go#L194

Added line #L194 was not covered by tests
}
return nil
}
Expand Down
6 changes: 3 additions & 3 deletions x/sequencer/keeper/rotation.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"sort"
"time"

"cosmossdk.io/errors"
errorsmod "cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/dymensionxyz/dymension/v3/x/sequencer/types"
"github.com/dymensionxyz/gerr-cosmos/gerrc"
Expand Down Expand Up @@ -111,11 +111,11 @@
func (k Keeper) CompleteRotation(ctx sdk.Context, rollappId string) error {
proposer, ok := k.GetProposer(ctx, rollappId)
if !ok {
return errors.Wrapf(gerrc.ErrInternal, "proposer not set for rollapp %s", rollappId)
return errorsmod.Wrapf(gerrc.ErrInternal, "proposer not set for rollapp %s", rollappId)

Check warning on line 114 in x/sequencer/keeper/rotation.go

View check run for this annotation

Codecov / codecov/patch

x/sequencer/keeper/rotation.go#L114

Added line #L114 was not covered by tests
}
nextProposer, ok := k.GetNextProposer(ctx, rollappId)
if !ok {
return errors.Wrapf(gerrc.ErrInternal, "next proposer not set for rollapp %s", rollappId)
return errorsmod.Wrapf(gerrc.ErrInternal, "next proposer not set for rollapp %s", rollappId)

Check warning on line 118 in x/sequencer/keeper/rotation.go

View check run for this annotation

Codecov / codecov/patch

x/sequencer/keeper/rotation.go#L118

Added line #L118 was not covered by tests
}

// start unbonding the current proposer
Expand Down
Loading