Skip to content

Commit

Permalink
lint fix
Browse files Browse the repository at this point in the history
  • Loading branch information
srene committed Dec 3, 2024
1 parent da5ebcb commit 3f4722f
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 95 deletions.
3 changes: 2 additions & 1 deletion app/apptesting/apptesting.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
tmtypes "github.com/tendermint/tendermint/proto/tendermint/types"
dbm "github.com/tendermint/tm-db"

sdkmath "cosmossdk.io/math"
minttypes "github.com/cosmos/cosmos-sdk/x/mint/types"
"github.com/dymensionxyz/rollapp-wasm/app"
)
Expand Down Expand Up @@ -177,7 +178,7 @@ func (s *KeeperTestHelper) EndBlock() {
}

// AllocateRewardsToValidator allocates reward tokens to a distribution module then allocates rewards to the validator address.
func (s *KeeperTestHelper) AllocateRewardsToValidator(valAddr sdk.ValAddress, rewardAmt sdk.Int) {
func (s *KeeperTestHelper) AllocateRewardsToValidator(valAddr sdk.ValAddress, rewardAmt sdkmath.Int) {
validator, found := s.App.StakingKeeper.GetValidator(s.Ctx, valAddr)
s.Require().True(found)

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ require (
cosmossdk.io/collections v0.4.0
cosmossdk.io/core v0.12.0
cosmossdk.io/errors v1.0.1
cosmossdk.io/math v1.4.0
github.com/CosmWasm/wasmd v0.33.0
github.com/CosmWasm/wasmvm v1.3.0
github.com/bcdevtools/block-explorer-rpc-cosmos v1.2.3
Expand Down Expand Up @@ -46,7 +47,6 @@ require (
cloud.google.com/go/storage v1.38.0 // indirect
cosmossdk.io/api v0.7.0 // indirect
cosmossdk.io/depinject v1.0.0-alpha.4 // indirect
cosmossdk.io/math v1.4.0 // indirect
filippo.io/edwards25519 v1.0.0-rc.1 // indirect
github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect
github.com/99designs/keyring v1.2.1 // indirect
Expand Down
35 changes: 18 additions & 17 deletions x/tokenfactory/bindings/message_plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package bindings
import (
"encoding/json"

errorsmod "cosmossdk.io/errors"
wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper"
wasmvmtypes "github.com/CosmWasm/wasmvm/types"
sdk "github.com/cosmos/cosmos-sdk/types"
Expand Down Expand Up @@ -41,10 +42,10 @@ func (m *CustomMessenger) DispatchMsg(ctx sdk.Context, contractAddr sdk.AccAddre
// leave everything else for the wrapped version
var contractMsg bindingstypes.TokenFactoryMsg
if err := json.Unmarshal(msg.Custom, &contractMsg); err != nil {
return nil, nil, sdkerrors.Wrap(err, "token factory msg")
return nil, nil, errorsmod.Wrap(err, "token factory msg")
}
if contractMsg.Token == nil {
return nil, nil, sdkerrors.Wrap(sdkerrors.ErrUnknownRequest, "nil token field")
return nil, nil, errorsmod.Wrap(sdkerrors.ErrUnknownRequest, "nil token field")
}
tokenMsg := contractMsg.Token

Expand All @@ -71,7 +72,7 @@ func (m *CustomMessenger) DispatchMsg(ctx sdk.Context, contractAddr sdk.AccAddre
func (m *CustomMessenger) createDenom(ctx sdk.Context, contractAddr sdk.AccAddress, createDenom *bindingstypes.CreateDenom) ([]sdk.Event, [][]byte, error) {
bz, err := PerformCreateDenom(m.tokenFactory, m.bank, ctx, contractAddr, createDenom)
if err != nil {
return nil, nil, sdkerrors.Wrap(err, "perform create denom")
return nil, nil, errorsmod.Wrap(err, "perform create denom")
}
// TODO: double check how this is all encoded to the contract
return nil, [][]byte{bz}, nil
Expand All @@ -88,7 +89,7 @@ func PerformCreateDenom(f *tokenfactorykeeper.Keeper, b *bankkeeper.BaseKeeper,
msgCreateDenom := tokenfactorytypes.NewMsgCreateDenom(contractAddr.String(), createDenom.Subdenom)

if err := msgCreateDenom.ValidateBasic(); err != nil {
return nil, sdkerrors.Wrap(err, "failed validating MsgCreateDenom")
return nil, errorsmod.Wrap(err, "failed validating MsgCreateDenom")
}

// Create denom
Expand All @@ -97,14 +98,14 @@ func PerformCreateDenom(f *tokenfactorykeeper.Keeper, b *bankkeeper.BaseKeeper,
msgCreateDenom,
)
if err != nil {
return nil, sdkerrors.Wrap(err, "creating denom")
return nil, errorsmod.Wrap(err, "creating denom")
}

if createDenom.Metadata != nil {
newDenom := resp.NewTokenDenom
err := PerformSetMetadata(f, b, ctx, contractAddr, newDenom, *createDenom.Metadata)
if err != nil {
return nil, sdkerrors.Wrap(err, "setting metadata")
return nil, errorsmod.Wrap(err, "setting metadata")
}
}

Expand All @@ -115,7 +116,7 @@ func PerformCreateDenom(f *tokenfactorykeeper.Keeper, b *bankkeeper.BaseKeeper,
func (m *CustomMessenger) mintTokens(ctx sdk.Context, contractAddr sdk.AccAddress, mint *bindingstypes.MintTokens) ([]sdk.Event, [][]byte, error) {
err := PerformMint(m.tokenFactory, m.bank, ctx, contractAddr, mint)
if err != nil {
return nil, nil, sdkerrors.Wrap(err, "perform mint")
return nil, nil, errorsmod.Wrap(err, "perform mint")
}
return nil, nil, nil
}
Expand All @@ -140,11 +141,11 @@ func PerformMint(f *tokenfactorykeeper.Keeper, b *bankkeeper.BaseKeeper, ctx sdk
msgServer := tokenfactorykeeper.NewMsgServerImpl(*f)
_, err = msgServer.Mint(sdk.WrapSDKContext(ctx), sdkMsg)
if err != nil {
return sdkerrors.Wrap(err, "minting coins from message")
return errorsmod.Wrap(err, "minting coins from message")
}
err = b.SendCoins(ctx, contractAddr, rcpt, sdk.NewCoins(coin))
if err != nil {
return sdkerrors.Wrap(err, "sending newly minted coins from message")
return errorsmod.Wrap(err, "sending newly minted coins from message")
}
return nil
}
Expand All @@ -153,7 +154,7 @@ func PerformMint(f *tokenfactorykeeper.Keeper, b *bankkeeper.BaseKeeper, ctx sdk
func (m *CustomMessenger) changeAdmin(ctx sdk.Context, contractAddr sdk.AccAddress, changeAdmin *bindingstypes.ChangeAdmin) ([]sdk.Event, [][]byte, error) {
err := ChangeAdmin(m.tokenFactory, ctx, contractAddr, changeAdmin)
if err != nil {
return nil, nil, sdkerrors.Wrap(err, "failed to change admin")
return nil, nil, errorsmod.Wrap(err, "failed to change admin")
}
return nil, nil, nil
}
Expand All @@ -176,7 +177,7 @@ func ChangeAdmin(f *tokenfactorykeeper.Keeper, ctx sdk.Context, contractAddr sdk
msgServer := tokenfactorykeeper.NewMsgServerImpl(*f)
_, err = msgServer.ChangeAdmin(sdk.WrapSDKContext(ctx), changeAdminMsg)
if err != nil {
return sdkerrors.Wrap(err, "failed changing admin from message")
return errorsmod.Wrap(err, "failed changing admin from message")
}
return nil
}
Expand All @@ -185,7 +186,7 @@ func ChangeAdmin(f *tokenfactorykeeper.Keeper, ctx sdk.Context, contractAddr sdk
func (m *CustomMessenger) burnTokens(ctx sdk.Context, contractAddr sdk.AccAddress, burn *bindingstypes.BurnTokens) ([]sdk.Event, [][]byte, error) {
err := PerformBurn(m.tokenFactory, ctx, contractAddr, burn)
if err != nil {
return nil, nil, sdkerrors.Wrap(err, "perform burn")
return nil, nil, errorsmod.Wrap(err, "perform burn")
}
return nil, nil, nil
}
Expand All @@ -209,7 +210,7 @@ func PerformBurn(f *tokenfactorykeeper.Keeper, ctx sdk.Context, contractAddr sdk
msgServer := tokenfactorykeeper.NewMsgServerImpl(*f)
_, err := msgServer.Burn(sdk.WrapSDKContext(ctx), sdkMsg)
if err != nil {
return sdkerrors.Wrap(err, "burning coins from message")
return errorsmod.Wrap(err, "burning coins from message")
}
return nil
}
Expand All @@ -218,7 +219,7 @@ func PerformBurn(f *tokenfactorykeeper.Keeper, ctx sdk.Context, contractAddr sdk
func (m *CustomMessenger) setMetadata(ctx sdk.Context, contractAddr sdk.AccAddress, setMetadata *bindingstypes.SetMetadata) ([]sdk.Event, [][]byte, error) {
err := PerformSetMetadata(m.tokenFactory, m.bank, ctx, contractAddr, setMetadata.Denom, setMetadata.Metadata)
if err != nil {
return nil, nil, sdkerrors.Wrap(err, "perform create denom")
return nil, nil, errorsmod.Wrap(err, "perform create denom")
}
return nil, nil, nil
}
Expand Down Expand Up @@ -261,7 +262,7 @@ func GetFullDenom(contract string, subDenom string) (string, error) {
}
fullDenom, err := tokenfactorytypes.GetTokenDenom(contract, subDenom)
if err != nil {
return "", sdkerrors.Wrap(err, "validate sub-denom")
return "", errorsmod.Wrap(err, "validate sub-denom")
}

return fullDenom, nil
Expand All @@ -271,11 +272,11 @@ func GetFullDenom(contract string, subDenom string) (string, error) {
func parseAddress(addr string) (sdk.AccAddress, error) {
parsed, err := sdk.AccAddressFromBech32(addr)
if err != nil {
return nil, sdkerrors.Wrap(err, "address from bech32")
return nil, errorsmod.Wrap(err, "address from bech32")
}
err = sdk.VerifyAddressFormat(parsed)
if err != nil {
return nil, sdkerrors.Wrap(err, "verify address format")
return nil, errorsmod.Wrap(err, "verify address format")
}
return parsed, nil
}
Expand Down
9 changes: 5 additions & 4 deletions x/tokenfactory/bindings/query_plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/json"
"fmt"

errorsmod "cosmossdk.io/errors"
wasmvmtypes "github.com/CosmWasm/wasmvm/types"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
Expand All @@ -16,10 +17,10 @@ func CustomQuerier(qp *QueryPlugin) func(ctx sdk.Context, request json.RawMessag
return func(ctx sdk.Context, request json.RawMessage) ([]byte, error) {
var contractQuery bindingstypes.TokenFactoryQuery
if err := json.Unmarshal(request, &contractQuery); err != nil {
return nil, sdkerrors.Wrap(err, "osmosis query")
return nil, errorsmod.Wrap(err, "osmosis query")
}
if contractQuery.Token == nil {
return nil, sdkerrors.Wrap(sdkerrors.ErrUnknownRequest, "nil token field")
return nil, errorsmod.Wrap(sdkerrors.ErrUnknownRequest, "nil token field")
}
tokenQuery := contractQuery.Token

Expand All @@ -30,7 +31,7 @@ func CustomQuerier(qp *QueryPlugin) func(ctx sdk.Context, request json.RawMessag

fullDenom, err := GetFullDenom(creator, subdenom)
if err != nil {
return nil, sdkerrors.Wrap(err, "osmo full denom query")
return nil, errorsmod.Wrap(err, "osmo full denom query")
}

res := bindingstypes.FullDenomResponse{
Expand All @@ -39,7 +40,7 @@ func CustomQuerier(qp *QueryPlugin) func(ctx sdk.Context, request json.RawMessag

bz, err := json.Marshal(res)
if err != nil {
return nil, sdkerrors.Wrap(err, "failed to marshal FullDenomResponse")
return nil, errorsmod.Wrap(err, "failed to marshal FullDenomResponse")
}

return bz, nil
Expand Down
2 changes: 1 addition & 1 deletion x/tokenfactory/bindings/types/msg.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package types

import sdk "github.com/cosmos/cosmos-sdk/types"
import sdk "cosmossdk.io/math"

type TokenFactoryMsg struct {
Token *TokenMsg `json:"token,omitempty"`
Expand Down
8 changes: 4 additions & 4 deletions x/tokenfactory/types/denoms.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package types
import (
"strings"

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

const (
Expand Down Expand Up @@ -46,17 +46,17 @@ func DeconstructDenom(denom string) (creator string, subdenom string, err error)

strParts := strings.Split(denom, "/")
if len(strParts) < 3 {
return "", "", sdkerrors.Wrapf(ErrInvalidDenom, "not enough parts of denom %s", denom)
return "", "", errorsmod.Wrapf(ErrInvalidDenom, "not enough parts of denom %s", denom)
}

if strParts[0] != ModuleDenomPrefix {
return "", "", sdkerrors.Wrapf(ErrInvalidDenom, "denom prefix is incorrect. Is: %s. Should be: %s", strParts[0], ModuleDenomPrefix)
return "", "", errorsmod.Wrapf(ErrInvalidDenom, "denom prefix is incorrect. Is: %s. Should be: %s", strParts[0], ModuleDenomPrefix)
}

creator = strParts[1]
creatorAddr, err := sdk.AccAddressFromBech32(creator)
if err != nil {
return "", "", sdkerrors.Wrapf(ErrInvalidDenom, "Invalid creator address (%s)", err)
return "", "", errorsmod.Wrapf(ErrInvalidDenom, "Invalid creator address (%s)", err)
}

// Handle the case where a denom has a slash in its subdenom. For example,
Expand Down
20 changes: 10 additions & 10 deletions x/tokenfactory/types/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@ package types
import (
fmt "fmt"

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

// x/tokenfactory module sentinel errors
var (
ErrDenomExists = sdkerrors.Register(ModuleName, 2, "attempting to create a denom that already exists (has bank metadata)")
ErrUnauthorized = sdkerrors.Register(ModuleName, 3, "unauthorized account")
ErrInvalidDenom = sdkerrors.Register(ModuleName, 4, "invalid denom")
ErrInvalidCreator = sdkerrors.Register(ModuleName, 5, "invalid creator")
ErrInvalidAuthorityMetadata = sdkerrors.Register(ModuleName, 6, "invalid authority metadata")
ErrInvalidGenesis = sdkerrors.Register(ModuleName, 7, "invalid genesis")
ErrSubdenomTooLong = sdkerrors.Register(ModuleName, 8, fmt.Sprintf("subdenom too long, max length is %d bytes", MaxSubdenomLength))
ErrCreatorTooLong = sdkerrors.Register(ModuleName, 9, fmt.Sprintf("creator too long, max length is %d bytes", MaxCreatorLength))
ErrDenomDoesNotExist = sdkerrors.Register(ModuleName, 10, "denom does not exist")
ErrDenomExists = errorsmod.Register(ModuleName, 2, "attempting to create a denom that already exists (has bank metadata)")
ErrUnauthorized = errorsmod.Register(ModuleName, 3, "unauthorized account")
ErrInvalidDenom = errorsmod.Register(ModuleName, 4, "invalid denom")
ErrInvalidCreator = errorsmod.Register(ModuleName, 5, "invalid creator")
ErrInvalidAuthorityMetadata = errorsmod.Register(ModuleName, 6, "invalid authority metadata")
ErrInvalidGenesis = errorsmod.Register(ModuleName, 7, "invalid genesis")
ErrSubdenomTooLong = errorsmod.Register(ModuleName, 8, fmt.Sprintf("subdenom too long, max length is %d bytes", MaxSubdenomLength))
ErrCreatorTooLong = errorsmod.Register(ModuleName, 9, fmt.Sprintf("creator too long, max length is %d bytes", MaxCreatorLength))
ErrDenomDoesNotExist = errorsmod.Register(ModuleName, 10, "denom does not exist")
)
6 changes: 3 additions & 3 deletions x/tokenfactory/types/genesis.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package types

import (
errorsmod "cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
)

// this line is used by starport scaffolding # genesis/types/import
Expand Down Expand Up @@ -30,7 +30,7 @@ func (gs GenesisState) Validate() error {

for _, denom := range gs.GetFactoryDenoms() {
if seenDenoms[denom.GetDenom()] {
return sdkerrors.Wrapf(ErrInvalidGenesis, "duplicate denom: %s", denom.GetDenom())
return errorsmod.Wrapf(ErrInvalidGenesis, "duplicate denom: %s", denom.GetDenom())
}
seenDenoms[denom.GetDenom()] = true

Expand All @@ -42,7 +42,7 @@ func (gs GenesisState) Validate() error {
if denom.AuthorityMetadata.Admin != "" {
_, err = sdk.AccAddressFromBech32(denom.AuthorityMetadata.Admin)
if err != nil {
return sdkerrors.Wrapf(ErrInvalidAuthorityMetadata, "Invalid admin address (%s)", err)
return errorsmod.Wrapf(ErrInvalidAuthorityMetadata, "Invalid admin address (%s)", err)
}
}
}
Expand Down
Loading

0 comments on commit 3f4722f

Please sign in to comment.