Skip to content

Commit

Permalink
sdk 46, wasmd 31, token factory
Browse files Browse the repository at this point in the history
  • Loading branch information
faddat committed Mar 20, 2023
1 parent be9298e commit f5072b9
Show file tree
Hide file tree
Showing 58 changed files with 488 additions and 470 deletions.
11 changes: 6 additions & 5 deletions app/ante.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package app

import (
errorsmod "cosmossdk.io/errors"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
Expand All @@ -24,19 +25,19 @@ type HandlerOptions struct {

func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) {
if options.AccountKeeper == nil {
return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "account keeper is required for AnteHandler")
return nil, errorsmod.Wrap(sdkerrors.ErrLogic, "account keeper is required for AnteHandler")
}
if options.BankKeeper == nil {
return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "bank keeper is required for AnteHandler")
return nil, errorsmod.Wrap(sdkerrors.ErrLogic, "bank keeper is required for AnteHandler")
}
if options.SignModeHandler == nil {
return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "sign mode handler is required for ante builder")
return nil, errorsmod.Wrap(sdkerrors.ErrLogic, "sign mode handler is required for ante builder")
}
if options.WasmConfig == nil {
return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "wasm config is required for ante builder")
return nil, errorsmod.Wrap(sdkerrors.ErrLogic, "wasm config is required for ante builder")
}
if options.TXCounterStoreKey == nil {
return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "tx counter key is required for ante builder")
return nil, errorsmod.Wrap(sdkerrors.ErrLogic, "tx counter key is required for ante builder")
}

sigGasConsumer := options.SigGasConsumer
Expand Down
1 change: 0 additions & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,6 @@ func NewWasmApp(
scopedWasmKeeper,
app.TransferKeeper,
app.MsgServiceRouter(),
app.GRPCQueryRouter(),
wasmDir,
wasmConfig,
availableCapabilities,
Expand Down
4 changes: 2 additions & 2 deletions app/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func TestWasmdExport(t *testing.T) {
Coins: sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, amount)),
}

genesisState := SetupGenesisValSet(t, valSet, []authtypes.GenesisAccount{acc}, nil, gapp, balance)
genesisState := SetupGenesisValSet(t, valSet, []authtypes.GenesisAccount{acc}, gapp, balance)
stateBytes, err := json.MarshalIndent(genesisState, "", " ")
require.NoError(t, err)

Expand Down Expand Up @@ -119,7 +119,7 @@ func TestGetEnabledProposals(t *testing.T) {
}
}

func SetupGenesisValSet(t *testing.T, valSet *tmtypes.ValidatorSet, genAccs []authtypes.GenesisAccount, opts []wasm.Option, app *WasmApp, balances ...banktypes.Balance) GenesisState {
func SetupGenesisValSet(t *testing.T, valSet *tmtypes.ValidatorSet, genAccs []authtypes.GenesisAccount, app *WasmApp, balances ...banktypes.Balance) GenesisState {
genesisState := NewDefaultGenesisState()
// set genesis accounts
authGenesis := authtypes.NewGenesisState(authtypes.DefaultParams(), genAccs)
Expand Down
3 changes: 2 additions & 1 deletion tests/e2e/grants_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"testing"

errorsmod "cosmossdk.io/errors"
"github.com/CosmWasm/wasmd/x/wasm/ibctesting"
"github.com/CosmWasm/wasmd/x/wasm/types"
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
Expand Down Expand Up @@ -46,7 +47,7 @@ func TestGrants(t *testing.T) {
filter types.ContractAuthzFilterX
transferAmount sdk.Coin
senderKey cryptotypes.PrivKey
expErr *sdkerrors.Error
expErr *errorsmod.Error
}{
"in limits and filter": {
limit: types.NewMaxFundsLimit(myAmount),
Expand Down
2 changes: 1 addition & 1 deletion x/tokenfactory/bindings/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func CreateTestInput() (*app.WasmApp, sdk.Context) {
return osmosis, ctx
}

func FundAccount(t *testing.T, ctx sdk.Context, osmosis *app.WasmApp, acct sdk.AccAddress) {
func FundAccount(_ *testing.T, _ sdk.Context, _ *app.WasmApp, _ sdk.AccAddress) {
// TODO:
// err := simapp.FundAccount(osmosis.BankKeeper, ctx, acct, sdk.NewCoins(
// sdk.NewCoin("uosmo", sdk.NewInt(10000000000)),
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
4 changes: 2 additions & 2 deletions x/tokenfactory/keeper/createdenom.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func (k Keeper) CreateDenom(ctx sdk.Context, creatorAddr string, subdenom string
return "", err
}

err = k.chargeForCreateDenom(ctx, creatorAddr, subdenom)
err = k.chargeForCreateDenom(ctx, creatorAddr)
if err != nil {
return "", err
}
Expand Down Expand Up @@ -70,7 +70,7 @@ func (k Keeper) validateCreateDenom(ctx sdk.Context, creatorAddr string, subdeno
return denom, nil
}

func (k Keeper) chargeForCreateDenom(ctx sdk.Context, creatorAddr string, subdenom string) (err error) { //nolint:unparam
func (k Keeper) chargeForCreateDenom(ctx sdk.Context, creatorAddr string) (err error) {
// Send creation fee to community pool
creationFee := k.GetParams(ctx).DenomCreationFee
accAddr, err := sdk.AccAddressFromBech32(creatorAddr)
Expand Down
2 changes: 1 addition & 1 deletion x/tokenfactory/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

var _ types.QueryServer = Keeper{}

func (k Keeper) Params(ctx context.Context, req *types.QueryParamsRequest) (*types.QueryParamsResponse, error) {
func (k Keeper) Params(ctx context.Context, _ *types.QueryParamsRequest) (*types.QueryParamsResponse, error) {
sdkCtx := sdk.UnwrapSDKContext(ctx)
params := k.GetParams(sdkCtx)

Expand Down
13 changes: 4 additions & 9 deletions x/tokenfactory/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
cdctypes "github.com/cosmos/cosmos-sdk/codec/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
"github.com/gorilla/mux"
"github.com/grpc-ecosystem/grpc-gateway/runtime"
"github.com/spf13/cobra"
abci "github.com/tendermint/tendermint/abci/types"
Expand Down Expand Up @@ -68,7 +67,7 @@ func (AppModuleBasic) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage {
}

// ValidateGenesis performs genesis state validation for the x/tokenfactory module.
func (AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, config client.TxEncodingConfig, bz json.RawMessage) error {
func (AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, _ client.TxEncodingConfig, bz json.RawMessage) error {
var genState types.GenesisState
if err := cdc.UnmarshalJSON(bz, &genState); err != nil {
return fmt.Errorf("failed to unmarshal %s genesis state: %w", types.ModuleName, err)
Expand All @@ -77,10 +76,6 @@ func (AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, config client.TxEncod
return genState.Validate()
}

// RegisterRESTRoutes registers the capability module's REST service handlers.
func (AppModuleBasic) RegisterRESTRoutes(clientCtx client.Context, rtr *mux.Router) {
}

// RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the module.
func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *runtime.ServeMux) {
types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx)) //nolint:errcheck
Expand Down Expand Up @@ -136,7 +131,7 @@ func (am AppModule) Route() sdk.Route {
func (AppModule) QuerierRoute() string { return types.QuerierRoute }

// LegacyQuerierHandler returns the x/tokenfactory module's Querier.
func (am AppModule) LegacyQuerierHandler(legacyQuerierCdc *codec.LegacyAmino) sdk.Querier {
func (am AppModule) LegacyQuerierHandler(_ *codec.LegacyAmino) sdk.Querier {
return nil
}

Expand Down Expand Up @@ -210,7 +205,7 @@ func (AppModule) GenerateGenesisState(simState *module.SimulationState) {
}

// GenerateGenesisState creates a randomized GenState of the bank module.
func (am AppModule) ProposalContents(simState module.SimulationState) []simtypes.WeightedProposalContent {
func (am AppModule) ProposalContents(_ module.SimulationState) []simtypes.WeightedProposalContent {
return nil
}

Expand All @@ -220,7 +215,7 @@ func (am AppModule) RandomizedParams(r *rand.Rand) []simtypes.ParamChange {
}

// RegisterStoreDecoder registers a decoder for supply module's types
func (am AppModule) RegisterStoreDecoder(sdr sdk.StoreDecoderRegistry) {
func (am AppModule) RegisterStoreDecoder(_ sdk.StoreDecoderRegistry) {
}

// WeightedOperations returns the all the gov module operations with their respective weights.
Expand Down
2 changes: 1 addition & 1 deletion x/tokenfactory/simulation/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/cosmos/cosmos-sdk/x/simulation"
)

func ParamChanges(r *rand.Rand) []simtypes.ParamChange {
func ParamChanges(_ *rand.Rand) []simtypes.ParamChange {
return []simtypes.ParamChange{
simulation.NewSimParamChange(
types.ModuleName,
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
Loading

0 comments on commit f5072b9

Please sign in to comment.