Skip to content

Commit

Permalink
Remove SetParams and its test case
Browse files Browse the repository at this point in the history
  • Loading branch information
sergio-mena committed May 10, 2024
1 parent bb13d0b commit 02a5e96
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 129 deletions.
18 changes: 0 additions & 18 deletions x/consensus/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,21 +99,3 @@ func (k Keeper) UpdateParams(ctx context.Context, msg *types.MsgUpdateParams) (*

return &types.MsgUpdateParamsResponse{}, nil
}

// SetParams sets the consensus parameters on init of a chain. This is a consensus message. It can only be called by the consensus server
// This is used in the consensus message handler set in module.go.
func (k Keeper) SetParams(ctx context.Context, req *types.ConsensusMsgParams) (*types.ConsensusMsgParamsResponse, error) {
consensusParams, err := req.ToProtoConsensusParams()
if err != nil {
return nil, err
}
if err := cmttypes.ConsensusParamsFromProto(consensusParams).ValidateBasic(); err != nil {
return nil, err
}

if err := k.ParamsStore.Set(ctx, consensusParams); err != nil {
return nil, err
}

return &types.ConsensusMsgParamsResponse{}, nil
}
111 changes: 0 additions & 111 deletions x/consensus/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -603,114 +603,3 @@ func (s *KeeperTestSuite) TestUpdateParams() {
})
}
}

// TODO(sergio-mena) Is this test really needed? (everything is already tested above)
func (s *KeeperTestSuite) TestSetParams() {
defaultConsensusParams := cmttypes.DefaultConsensusParams().ToProto()
testCases := []struct {
name string
input *types.ConsensusMsgParams
expErr bool
expErrMsg string
}{
{
name: "valid params",
input: &types.ConsensusMsgParams{
Version: &cmtproto.VersionParams{App: 1},
Block: defaultConsensusParams.Block,
Validator: defaultConsensusParams.Validator,
Evidence: defaultConsensusParams.Evidence,
Feature: defaultConsensusParams.Feature,
},
expErr: false,
expErrMsg: "",
},
{
name: "invalid params",
input: &types.ConsensusMsgParams{
Version: &cmtproto.VersionParams{App: 1},
Block: &cmtproto.BlockParams{MaxGas: -10, MaxBytes: -10},
Validator: defaultConsensusParams.Validator,
Evidence: defaultConsensusParams.Evidence,
Feature: defaultConsensusParams.Feature,
},
expErr: true,
expErrMsg: "block.MaxBytes must be -1 or greater than 0. Got -10",
},
{
name: "nil version params",
input: &types.ConsensusMsgParams{
Abci: defaultConsensusParams.Abci,
Version: nil,
Block: defaultConsensusParams.Block,
Validator: defaultConsensusParams.Validator,
Evidence: defaultConsensusParams.Evidence,
Feature: defaultConsensusParams.Feature,
},
expErr: true,
expErrMsg: "all parameters must be present",
},
{
name: "nil evidence params",
input: &types.ConsensusMsgParams{
Abci: defaultConsensusParams.Abci,
Version: &cmtproto.VersionParams{App: 1},
Block: defaultConsensusParams.Block,
Validator: defaultConsensusParams.Validator,
Evidence: nil,
Feature: defaultConsensusParams.Feature,
},
expErr: true,
expErrMsg: "all parameters must be present",
},
{
name: "nil block params",
input: &types.ConsensusMsgParams{
Abci: defaultConsensusParams.Abci,
Version: &cmtproto.VersionParams{App: 1},
Block: nil,
Validator: defaultConsensusParams.Validator,
Evidence: defaultConsensusParams.Evidence,
Feature: defaultConsensusParams.Feature,
},
expErr: true,
expErrMsg: "all parameters must be present",
},
{
name: "nil validator params",
input: &types.ConsensusMsgParams{
Abci: defaultConsensusParams.Abci,
Version: &cmtproto.VersionParams{App: 1},
Block: defaultConsensusParams.Block,
Validator: nil,
Evidence: defaultConsensusParams.Evidence,
Feature: defaultConsensusParams.Feature,
},
expErr: true,
expErrMsg: "all parameters must be present",
},
}

for _, tc := range testCases {
tc := tc
s.Run(tc.name, func() {
s.SetupTest(false)
_, err := s.consensusParamsKeeper.SetParams(s.ctx, tc.input)
if tc.expErr {
s.Require().Error(err)
s.Require().Contains(err.Error(), tc.expErrMsg)
} else {
s.Require().NoError(err)

res, err := s.consensusParamsKeeper.Params(s.ctx, &types.QueryParamsRequest{})
s.Require().NoError(err)

s.Require().Equal(tc.input.Abci, res.Params.Abci)
s.Require().Equal(tc.input.Block, res.Params.Block)
s.Require().Equal(tc.input.Evidence, res.Params.Evidence)
s.Require().Equal(tc.input.Validator, res.Params.Validator)
s.Require().Equal(tc.input.Version, res.Params.Version)
}
})
}
}

0 comments on commit 02a5e96

Please sign in to comment.