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

refactor(mint)!: migrate state management to collections #16329

Merged
merged 11 commits into from
May 30, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
remove SetParams
  • Loading branch information
unknown unknown committed May 29, 2023
commit 374952a0266d0a4838bd87a4f7ccc881b14d924f
2 changes: 1 addition & 1 deletion x/mint/keeper/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
func (keeper Keeper) InitGenesis(ctx sdk.Context, ak types.AccountKeeper, data *types.GenesisState) {
keeper.SetMinter(ctx, data.Minter)

if err := keeper.SetParams(ctx, data.Params); err != nil {
if err := keeper.Params.Set(ctx, data.Params); err != nil {
panic(err)
}

Expand Down
2 changes: 1 addition & 1 deletion x/mint/keeper/grpc_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func (suite *MintTestSuite) SetupTest() {
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)

err := suite.mintKeeper.SetParams(suite.ctx, types.DefaultParams())
err := suite.mintKeeper.Params.Set(suite.ctx, types.DefaultParams())
suite.Require().NoError(err)
suite.mintKeeper.SetMinter(suite.ctx, types.DefaultInitialMinter())

Expand Down
5 changes: 0 additions & 5 deletions x/mint/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,6 @@ func (k Keeper) SetMinter(ctx context.Context, minter types.Minter) error {
return store.Set(types.MinterKey, bz)
}

// SetParams sets the x/mint module parameters.
func (k Keeper) SetParams(ctx context.Context, params types.Params) error {
return k.Params.Set(ctx, params)
}

// StakingTokenSupply implements an alias call to the underlying staking keeper's
// StakingTokenSupply to be used in BeginBlocker.
func (k Keeper) StakingTokenSupply(ctx context.Context) math.Int {
Expand Down
55 changes: 1 addition & 54 deletions x/mint/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,66 +65,13 @@ func (s *IntegrationTestSuite) SetupTest() {
s.Require().Equal(testCtx.Ctx.Logger().With("module", "x/"+types.ModuleName),
s.mintKeeper.Logger(testCtx.Ctx))

err := s.mintKeeper.SetParams(s.ctx, types.DefaultParams())
err := s.mintKeeper.Params.Set(s.ctx, types.DefaultParams())
s.Require().NoError(err)
s.mintKeeper.SetMinter(s.ctx, types.DefaultInitialMinter())

s.msgServer = keeper.NewMsgServerImpl(s.mintKeeper)
}

func (s *IntegrationTestSuite) TestParams() {
testCases := []struct {
name string
input types.Params
expectErr bool
}{
{
name: "set invalid params (⚠️ not validated in keeper)",
input: types.Params{
MintDenom: sdk.DefaultBondDenom,
InflationRateChange: math.LegacyNewDecWithPrec(-13, 2),
InflationMax: math.LegacyNewDecWithPrec(20, 2),
InflationMin: math.LegacyNewDecWithPrec(7, 2),
GoalBonded: math.LegacyNewDecWithPrec(67, 2),
BlocksPerYear: uint64(60 * 60 * 8766 / 5),
},
expectErr: false,
},
{
name: "set full valid params",
input: types.Params{
MintDenom: sdk.DefaultBondDenom,
InflationRateChange: math.LegacyNewDecWithPrec(8, 2),
InflationMax: math.LegacyNewDecWithPrec(20, 2),
InflationMin: math.LegacyNewDecWithPrec(2, 2),
GoalBonded: math.LegacyNewDecWithPrec(37, 2),
BlocksPerYear: uint64(60 * 60 * 8766 / 5),
},
expectErr: false,
},
}

for _, tc := range testCases {
tc := tc

s.Run(tc.name, func() {
expected, err := s.mintKeeper.Params.Get(s.ctx)
s.Require().NoError(err)
err = s.mintKeeper.SetParams(s.ctx, tc.input)
if tc.expectErr {
s.Require().Error(err)
} else {
expected = tc.input
s.Require().NoError(err)
}

p, err := s.mintKeeper.Params.Get(s.ctx)
s.Require().NoError(err)
s.Require().Equal(expected, p)
})
}
}

func (s *IntegrationTestSuite) TestAliasFunctions() {
stakingTokenSupply := math.NewIntFromUint64(100000000000)
s.stakingKeeper.EXPECT().StakingTokenSupply(s.ctx).Return(stakingTokenSupply)
Expand Down
2 changes: 1 addition & 1 deletion x/mint/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func (ms msgServer) UpdateParams(goCtx context.Context, msg *types.MsgUpdatePara
}

ctx := sdk.UnwrapSDKContext(goCtx)
if err := ms.SetParams(ctx, msg.Params); err != nil {
if err := ms.Params.Set(ctx, msg.Params); err != nil {
return nil, err
}

Expand Down
2 changes: 1 addition & 1 deletion x/slashing/simulation/operations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func (suite *SimTestSuite) SetupTest() {
suite.Require().NoError(banktestutil.FundAccount(suite.ctx, suite.bankKeeper, account.Address, initCoins))
}

suite.mintKeeper.SetParams(suite.ctx, minttypes.DefaultParams())
suite.Require().NoError(suite.mintKeeper.Params.Set(suite.ctx, minttypes.DefaultParams()))
suite.mintKeeper.SetMinter(suite.ctx, minttypes.DefaultInitialMinter())
}

Expand Down
2 changes: 1 addition & 1 deletion x/staking/simulation/operations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func (s *SimTestSuite) SetupTest() {
require.NoError(s.T(), err)

ctx := app.BaseApp.NewContext(false, cmtproto.Header{})
mintKeeper.SetParams(ctx, minttypes.DefaultParams())
s.Require().NoError(mintKeeper.Params.Set(ctx, minttypes.DefaultParams()))
mintKeeper.SetMinter(ctx, minttypes.DefaultInitialMinter())

initAmt := stakingKeeper.TokensFromConsensusPower(ctx, 200)
Expand Down