From c75cbc5e0eb69f15a47393d7d2d54568a2b7428f Mon Sep 17 00:00:00 2001 From: Rootul P Date: Mon, 14 Aug 2023 10:25:20 -0400 Subject: [PATCH] chore!: remove x/mint amino codec (#2258) Closes https://github.com/celestiaorg/celestia-app/issues/2069 TBH I'm not sure if this is breaking b/c idk if anything uses the legacy querier or Amino codec. If possible, would be nice to backport to v1.x. --- x/mint/keeper/querier.go | 64 --------------------- x/mint/keeper/querier_test.go | 104 ---------------------------------- x/mint/module.go | 7 ++- x/mint/types/codec.go | 13 ----- 4 files changed, 4 insertions(+), 184 deletions(-) delete mode 100644 x/mint/keeper/querier.go delete mode 100644 x/mint/keeper/querier_test.go delete mode 100644 x/mint/types/codec.go diff --git a/x/mint/keeper/querier.go b/x/mint/keeper/querier.go deleted file mode 100644 index 4e6888b7ea..0000000000 --- a/x/mint/keeper/querier.go +++ /dev/null @@ -1,64 +0,0 @@ -package keeper - -import ( - abci "github.com/tendermint/tendermint/abci/types" - - "github.com/celestiaorg/celestia-app/x/mint/types" - "github.com/cosmos/cosmos-sdk/codec" - sdk "github.com/cosmos/cosmos-sdk/types" - - "cosmossdk.io/errors" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" -) - -// NewQuerier returns a minting Querier handler. -func NewQuerier(k Keeper, legacyQuerierCdc *codec.LegacyAmino) sdk.Querier { - return func(ctx sdk.Context, path []string, _ abci.RequestQuery) ([]byte, error) { - switch path[0] { - case types.QueryInflationRate: - return queryInflationRate(ctx, k, legacyQuerierCdc) - - case types.QueryAnnualProvisions: - return queryAnnualProvisions(ctx, k, legacyQuerierCdc) - - case types.QueryGenesisTime: - return queryGenesisTime(ctx, k, legacyQuerierCdc) - - default: - return nil, errors.Wrapf(sdkerrors.ErrUnknownRequest, "unknown query path: %s", path[0]) - } - } -} - -func queryInflationRate(ctx sdk.Context, k Keeper, legacyQuerierCdc *codec.LegacyAmino) ([]byte, error) { - minter := k.GetMinter(ctx) - - res, err := codec.MarshalJSONIndent(legacyQuerierCdc, minter.InflationRate) - if err != nil { - return nil, errors.Wrap(sdkerrors.ErrJSONMarshal, err.Error()) - } - - return res, nil -} - -func queryAnnualProvisions(ctx sdk.Context, k Keeper, legacyQuerierCdc *codec.LegacyAmino) ([]byte, error) { - minter := k.GetMinter(ctx) - - res, err := codec.MarshalJSONIndent(legacyQuerierCdc, minter.AnnualProvisions) - if err != nil { - return nil, errors.Wrap(sdkerrors.ErrJSONMarshal, err.Error()) - } - - return res, nil -} - -func queryGenesisTime(ctx sdk.Context, k Keeper, legacyQuerierCdc *codec.LegacyAmino) ([]byte, error) { - genesisTime := k.GetGenesisTime(ctx).GenesisTime - - res, err := codec.MarshalJSONIndent(legacyQuerierCdc, genesisTime) - if err != nil { - return nil, errors.Wrap(sdkerrors.ErrJSONMarshal, err.Error()) - } - - return res, nil -} diff --git a/x/mint/keeper/querier_test.go b/x/mint/keeper/querier_test.go deleted file mode 100644 index 7e7562db63..0000000000 --- a/x/mint/keeper/querier_test.go +++ /dev/null @@ -1,104 +0,0 @@ -package keeper_test - -import ( - "testing" - "time" - - "github.com/stretchr/testify/require" - "github.com/stretchr/testify/suite" - abci "github.com/tendermint/tendermint/abci/types" - tmproto "github.com/tendermint/tendermint/proto/tendermint/types" - - "github.com/celestiaorg/celestia-app/app" - testutil "github.com/celestiaorg/celestia-app/test/util" - keep "github.com/celestiaorg/celestia-app/x/mint/keeper" - "github.com/celestiaorg/celestia-app/x/mint/types" - "github.com/cosmos/cosmos-sdk/codec" - sdk "github.com/cosmos/cosmos-sdk/types" -) - -type MintKeeperTestSuite struct { - suite.Suite - - app *app.App - ctx sdk.Context - legacyQuerierCdc *codec.AminoCodec -} - -func (suite *MintKeeperTestSuite) SetupTest() { - testApp, _ := testutil.SetupTestAppWithGenesisValSet(app.DefaultConsensusParams()) - ctx := testApp.NewContext(true, tmproto.Header{}) - - legacyQuerierCdc := codec.NewAminoCodec(testApp.LegacyAmino()) - - suite.app = testApp - suite.ctx = ctx - suite.legacyQuerierCdc = legacyQuerierCdc -} - -func (suite *MintKeeperTestSuite) TestNewQuerier(t *testing.T) { - app, ctx, legacyQuerierCdc := suite.app, suite.ctx, suite.legacyQuerierCdc - querier := keep.NewQuerier(app.MintKeeper, legacyQuerierCdc.LegacyAmino) - - query := abci.RequestQuery{ - Path: "", - Data: []byte{}, - } - - _, err := querier(ctx, []string{types.QueryInflationRate}, query) - require.NoError(t, err) - - _, err = querier(ctx, []string{types.QueryAnnualProvisions}, query) - require.NoError(t, err) - - _, err = querier(ctx, []string{types.QueryGenesisTime}, query) - require.NoError(t, err) - - _, err = querier(ctx, []string{"foo"}, query) - require.Error(t, err) -} - -func (suite *MintKeeperTestSuite) TestQueryInflationRate(t *testing.T) { - app, ctx, legacyQuerierCdc := suite.app, suite.ctx, suite.legacyQuerierCdc - querier := keep.NewQuerier(app.MintKeeper, legacyQuerierCdc.LegacyAmino) - - var inflation sdk.Dec - - res, sdkErr := querier(ctx, []string{types.QueryInflationRate}, abci.RequestQuery{}) - require.NoError(t, sdkErr) - - err := app.LegacyAmino().UnmarshalJSON(res, &inflation) - require.NoError(t, err) - - require.Equal(t, app.MintKeeper.GetMinter(ctx).InflationRate, inflation) -} - -func (suite *MintKeeperTestSuite) TestQueryAnnualProvisions(t *testing.T) { - app, ctx, legacyQuerierCdc := suite.app, suite.ctx, suite.legacyQuerierCdc - querier := keep.NewQuerier(app.MintKeeper, legacyQuerierCdc.LegacyAmino) - - var annualProvisions sdk.Dec - - res, sdkErr := querier(ctx, []string{types.QueryAnnualProvisions}, abci.RequestQuery{}) - require.NoError(t, sdkErr) - - err := app.LegacyAmino().UnmarshalJSON(res, &annualProvisions) - require.NoError(t, err) - - require.Equal(t, app.MintKeeper.GetMinter(ctx).AnnualProvisions, annualProvisions) -} - -func (suite *MintKeeperTestSuite) TestQueryGenesisTime(t *testing.T) { - app, ctx, legacyQuerierCdc := suite.app, suite.ctx, suite.legacyQuerierCdc - querier := keep.NewQuerier(app.MintKeeper, legacyQuerierCdc.LegacyAmino) - - var genesisTime *time.Time - - res, sdkErr := querier(ctx, []string{types.QueryGenesisTime}, abci.RequestQuery{}) - require.NoError(t, sdkErr) - - err := app.LegacyAmino().UnmarshalJSON(res, &genesisTime) - require.NoError(t, err) - - require.Equal(t, app.MintKeeper.GetGenesisTime(ctx).GenesisTime, genesisTime) -} diff --git a/x/mint/module.go b/x/mint/module.go index c2ff8b1c05..5aa4fa779b 100644 --- a/x/mint/module.go +++ b/x/mint/module.go @@ -109,9 +109,10 @@ func (AppModule) QuerierRoute() string { return types.QuerierRoute } -// LegacyQuerierHandler returns the mint module sdk.Querier. -func (am AppModule) LegacyQuerierHandler(legacyQuerierCdc *codec.LegacyAmino) sdk.Querier { - return keeper.NewQuerier(am.keeper, legacyQuerierCdc) +// LegacyQuerierHandler returns nil because this module doesn't support the +// legacy querier or Amino codec. +func (am AppModule) LegacyQuerierHandler(_ *codec.LegacyAmino) sdk.Querier { + return nil } // RegisterServices registers a gRPC query service to respond to the diff --git a/x/mint/types/codec.go b/x/mint/types/codec.go deleted file mode 100644 index a7067d90c2..0000000000 --- a/x/mint/types/codec.go +++ /dev/null @@ -1,13 +0,0 @@ -package types - -import ( - "github.com/cosmos/cosmos-sdk/codec" - cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" -) - -var amino = codec.NewLegacyAmino() - -func init() { - cryptocodec.RegisterCrypto(amino) - amino.Seal() -}