From b310fc3d2d497ef4656cd038e935c48e3c8f1dd1 Mon Sep 17 00:00:00 2001 From: Cool Developer Date: Tue, 9 Aug 2022 14:22:13 -0400 Subject: [PATCH 1/4] move integration tests --- tests/e2e/slashing/client/testutil/cli_test.go | 5 ++--- .../e2e}/slashing/client/testutil/grpc.go | 2 +- .../e2e}/slashing/client/testutil/suite.go | 16 ++++++++-------- .../integration}/slashing/keeper/common_test.go | 0 .../integration}/slashing/keeper/genesis_test.go | 0 .../slashing/keeper/grpc_query_test.go | 0 .../integration}/slashing/keeper/keeper_test.go | 0 .../slashing/keeper/msg_server_test.go | 0 .../integration}/slashing/keeper/params_test.go | 0 .../slashing/keeper/signing_info_test.go | 0 10 files changed, 11 insertions(+), 12 deletions(-) rename {x => tests/e2e}/slashing/client/testutil/grpc.go (97%) rename {x => tests/e2e}/slashing/client/testutil/suite.go (91%) rename {x => tests/integration}/slashing/keeper/common_test.go (100%) rename {x => tests/integration}/slashing/keeper/genesis_test.go (100%) rename {x => tests/integration}/slashing/keeper/grpc_query_test.go (100%) rename {x => tests/integration}/slashing/keeper/keeper_test.go (100%) rename {x => tests/integration}/slashing/keeper/msg_server_test.go (100%) rename {x => tests/integration}/slashing/keeper/params_test.go (100%) rename {x => tests/integration}/slashing/keeper/signing_info_test.go (100%) diff --git a/tests/e2e/slashing/client/testutil/cli_test.go b/tests/e2e/slashing/client/testutil/cli_test.go index 3fe7a357e141..7d84c365f20c 100644 --- a/tests/e2e/slashing/client/testutil/cli_test.go +++ b/tests/e2e/slashing/client/testutil/cli_test.go @@ -8,13 +8,12 @@ import ( "github.com/cosmos/cosmos-sdk/simapp" "github.com/cosmos/cosmos-sdk/testutil/network" - clienttestutil "github.com/cosmos/cosmos-sdk/x/slashing/client/testutil" "github.com/stretchr/testify/suite" ) -func TestIntegrationTestSuite(t *testing.T) { +func TestEndToEndTestSuite(t *testing.T) { cfg := network.DefaultConfig(simapp.NewTestNetworkFixture) cfg.NumValidators = 1 - suite.Run(t, clienttestutil.NewIntegrationTestSuite(cfg)) + suite.Run(t, NewEndToEndTestSuite(cfg)) } diff --git a/x/slashing/client/testutil/grpc.go b/tests/e2e/slashing/client/testutil/grpc.go similarity index 97% rename from x/slashing/client/testutil/grpc.go rename to tests/e2e/slashing/client/testutil/grpc.go index fc41baf953aa..fe70df8182a0 100644 --- a/x/slashing/client/testutil/grpc.go +++ b/tests/e2e/slashing/client/testutil/grpc.go @@ -13,7 +13,7 @@ import ( "github.com/cosmos/cosmos-sdk/x/slashing/types" ) -func (s *IntegrationTestSuite) TestGRPCQueries() { +func (s *EndToEndTestSuite) TestGRPCQueries() { val := s.network.Validators[0] baseURL := val.APIAddress diff --git a/x/slashing/client/testutil/suite.go b/tests/e2e/slashing/client/testutil/suite.go similarity index 91% rename from x/slashing/client/testutil/suite.go rename to tests/e2e/slashing/client/testutil/suite.go index 06bcdca70110..2623eb03dba8 100644 --- a/x/slashing/client/testutil/suite.go +++ b/tests/e2e/slashing/client/testutil/suite.go @@ -15,20 +15,20 @@ import ( "github.com/cosmos/cosmos-sdk/x/slashing/client/cli" ) -type IntegrationTestSuite struct { +type EndToEndTestSuite struct { suite.Suite cfg network.Config network *network.Network } -func NewIntegrationTestSuite(cfg network.Config) *IntegrationTestSuite { - return &IntegrationTestSuite{cfg: cfg} +func NewEndToEndTestSuite(cfg network.Config) *EndToEndTestSuite { + return &EndToEndTestSuite{cfg: cfg} } // SetupSuite executes bootstrapping logic before all the tests, i.e. once before // the entire suite, start executing. -func (s *IntegrationTestSuite) SetupSuite() { +func (s *EndToEndTestSuite) SetupSuite() { s.T().Log("setting up integration test suite") var err error @@ -41,12 +41,12 @@ func (s *IntegrationTestSuite) SetupSuite() { // TearDownSuite performs cleanup logic after all the tests, i.e. once after the // entire suite, has finished executing. -func (s *IntegrationTestSuite) TearDownSuite() { +func (s *EndToEndTestSuite) TearDownSuite() { s.T().Log("tearing down integration test suite") s.network.Cleanup() } -func (s *IntegrationTestSuite) TestGetCmdQuerySigningInfo() { +func (s *EndToEndTestSuite) TestGetCmdQuerySigningInfo() { val := s.network.Validators[0] pubKeyBz, err := s.cfg.Codec.MarshalInterfaceJSON(val.PubKey) s.Require().NoError(err) @@ -104,7 +104,7 @@ tombstoned: false`, sdk.ConsAddress(val.PubKey.Address())), } } -func (s *IntegrationTestSuite) TestGetCmdQueryParams() { +func (s *EndToEndTestSuite) TestGetCmdQueryParams() { val := s.network.Validators[0] testCases := []struct { @@ -142,7 +142,7 @@ slash_fraction_downtime: "0.010000000000000000"`, } } -func (s *IntegrationTestSuite) TestNewUnjailTxCmd() { +func (s *EndToEndTestSuite) TestNewUnjailTxCmd() { val := s.network.Validators[0] testCases := []struct { name string diff --git a/x/slashing/keeper/common_test.go b/tests/integration/slashing/keeper/common_test.go similarity index 100% rename from x/slashing/keeper/common_test.go rename to tests/integration/slashing/keeper/common_test.go diff --git a/x/slashing/keeper/genesis_test.go b/tests/integration/slashing/keeper/genesis_test.go similarity index 100% rename from x/slashing/keeper/genesis_test.go rename to tests/integration/slashing/keeper/genesis_test.go diff --git a/x/slashing/keeper/grpc_query_test.go b/tests/integration/slashing/keeper/grpc_query_test.go similarity index 100% rename from x/slashing/keeper/grpc_query_test.go rename to tests/integration/slashing/keeper/grpc_query_test.go diff --git a/x/slashing/keeper/keeper_test.go b/tests/integration/slashing/keeper/keeper_test.go similarity index 100% rename from x/slashing/keeper/keeper_test.go rename to tests/integration/slashing/keeper/keeper_test.go diff --git a/x/slashing/keeper/msg_server_test.go b/tests/integration/slashing/keeper/msg_server_test.go similarity index 100% rename from x/slashing/keeper/msg_server_test.go rename to tests/integration/slashing/keeper/msg_server_test.go diff --git a/x/slashing/keeper/params_test.go b/tests/integration/slashing/keeper/params_test.go similarity index 100% rename from x/slashing/keeper/params_test.go rename to tests/integration/slashing/keeper/params_test.go diff --git a/x/slashing/keeper/signing_info_test.go b/tests/integration/slashing/keeper/signing_info_test.go similarity index 100% rename from x/slashing/keeper/signing_info_test.go rename to tests/integration/slashing/keeper/signing_info_test.go From 37f4838a30b921adaf979f6cbe8ac9edcc064361 Mon Sep 17 00:00:00 2001 From: Cool Developer Date: Tue, 16 Aug 2022 16:12:33 -0400 Subject: [PATCH 2/4] add unit testing --- scripts/mockgen.sh | 1 + .../slashing/keeper/common_test.go | 6 - .../slashing/keeper/genesis_test.go | 74 --- .../slashing/keeper/grpc_query_test.go | 60 --- .../slashing/keeper/keeper_test.go | 32 +- .../slashing/keeper/signing_info_test.go | 88 ---- x/slashing/keeper/genesis_test.go | 57 +++ x/slashing/keeper/grpc_query_test.go | 91 ++++ x/slashing/keeper/keeper_test.go | 82 ++++ .../slashing/keeper/msg_server_test.go | 59 ++- .../slashing/keeper/params_test.go | 25 +- x/slashing/keeper/signing_info_test.go | 93 ++++ x/slashing/testutil/expected_keepers_mocks.go | 425 ++++++++++++++++++ 13 files changed, 818 insertions(+), 275 deletions(-) delete mode 100644 tests/integration/slashing/keeper/common_test.go delete mode 100644 tests/integration/slashing/keeper/genesis_test.go delete mode 100644 tests/integration/slashing/keeper/grpc_query_test.go delete mode 100644 tests/integration/slashing/keeper/signing_info_test.go create mode 100644 x/slashing/keeper/genesis_test.go create mode 100644 x/slashing/keeper/grpc_query_test.go create mode 100644 x/slashing/keeper/keeper_test.go rename {tests/integration => x}/slashing/keeper/msg_server_test.go (72%) rename {tests/integration => x}/slashing/keeper/params_test.go (88%) create mode 100644 x/slashing/keeper/signing_info_test.go create mode 100644 x/slashing/testutil/expected_keepers_mocks.go diff --git a/scripts/mockgen.sh b/scripts/mockgen.sh index 2c0fcc42e848..399312632929 100755 --- a/scripts/mockgen.sh +++ b/scripts/mockgen.sh @@ -19,3 +19,4 @@ $mockgen_cmd -source=x/auth/types/expected_keepers.go -package testutil -destina $mockgen_cmd -source=x/auth/ante/expected_keepers.go -package testutil -destination x/auth/ante/testutil/expected_keepers_mocks.go $mockgen_cmd -source=x/bank/types/expected_keepers.go -package testutil -destination x/bank/testutil/expected_keepers_mocks.go $mockgen_cmd -source=x/evidence/types/expected_keepers.go -package testutil -destination x/evidence/testutil/expected_keepers_mocks.go +$mockgen_cmd -source=x/slashing/types/expected_keepers.go -package testutil -destination x/slashing/testutil/expected_keepers_mocks.go diff --git a/tests/integration/slashing/keeper/common_test.go b/tests/integration/slashing/keeper/common_test.go deleted file mode 100644 index 4e4be93b91e8..000000000000 --- a/tests/integration/slashing/keeper/common_test.go +++ /dev/null @@ -1,6 +0,0 @@ -package keeper_test - -import sdk "github.com/cosmos/cosmos-sdk/types" - -// The default power validators are initialized to have within tests -var InitTokens = sdk.TokensFromConsensusPower(200, sdk.DefaultPowerReduction) diff --git a/tests/integration/slashing/keeper/genesis_test.go b/tests/integration/slashing/keeper/genesis_test.go deleted file mode 100644 index f4dc734dd515..000000000000 --- a/tests/integration/slashing/keeper/genesis_test.go +++ /dev/null @@ -1,74 +0,0 @@ -package keeper_test - -import ( - "testing" - "time" - - "github.com/stretchr/testify/require" - tmproto "github.com/tendermint/tendermint/proto/tendermint/types" - - simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" - sdk "github.com/cosmos/cosmos-sdk/types" - bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" - slashingkeeper "github.com/cosmos/cosmos-sdk/x/slashing/keeper" - "github.com/cosmos/cosmos-sdk/x/slashing/testslashing" - "github.com/cosmos/cosmos-sdk/x/slashing/testutil" - "github.com/cosmos/cosmos-sdk/x/slashing/types" - stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" -) - -func TestExportAndInitGenesis(t *testing.T) { - var slashingKeeper slashingkeeper.Keeper - var stakingKeeper *stakingkeeper.Keeper - var bankKeeper bankkeeper.Keeper - - app, err := simtestutil.Setup( - testutil.AppConfig, - &slashingKeeper, - &stakingKeeper, - &bankKeeper, - ) - require.NoError(t, err) - - ctx := app.BaseApp.NewContext(false, tmproto.Header{}) - - slashingKeeper.SetParams(ctx, testslashing.TestParams()) - - addrDels := simtestutil.AddTestAddrsIncremental(bankKeeper, stakingKeeper, ctx, 2, stakingKeeper.TokensFromConsensusPower(ctx, 200)) - - info1 := types.NewValidatorSigningInfo(sdk.ConsAddress(addrDels[0]), int64(4), int64(3), - time.Now().UTC().Add(100000000000), false, int64(10)) - info2 := types.NewValidatorSigningInfo(sdk.ConsAddress(addrDels[1]), int64(5), int64(4), - time.Now().UTC().Add(10000000000), false, int64(10)) - - slashingKeeper.SetValidatorSigningInfo(ctx, sdk.ConsAddress(addrDels[0]), info1) - slashingKeeper.SetValidatorSigningInfo(ctx, sdk.ConsAddress(addrDels[1]), info2) - genesisState := slashingKeeper.ExportGenesis(ctx) - - require.Equal(t, genesisState.Params, testslashing.TestParams()) - require.Len(t, genesisState.SigningInfos, 2) - require.Equal(t, genesisState.SigningInfos[0].ValidatorSigningInfo, info1) - - // Tombstone validators after genesis shouldn't effect genesis state - slashingKeeper.Tombstone(ctx, sdk.ConsAddress(addrDels[0])) - slashingKeeper.Tombstone(ctx, sdk.ConsAddress(addrDels[1])) - - ok := slashingKeeper.IsTombstoned(ctx, sdk.ConsAddress(addrDels[0])) - require.True(t, ok) - - newInfo1, ok := slashingKeeper.GetValidatorSigningInfo(ctx, sdk.ConsAddress(addrDels[0])) - require.NotEqual(t, info1, newInfo1) - // Initialise genesis with genesis state before tombstone - - slashingKeeper.InitGenesis(ctx, stakingKeeper, genesisState) - - // Validator isTombstoned should return false as GenesisState is initialised - ok = slashingKeeper.IsTombstoned(ctx, sdk.ConsAddress(addrDels[0])) - require.False(t, ok) - - newInfo1, ok = slashingKeeper.GetValidatorSigningInfo(ctx, sdk.ConsAddress(addrDels[0])) - newInfo2, ok := slashingKeeper.GetValidatorSigningInfo(ctx, sdk.ConsAddress(addrDels[1])) - require.True(t, ok) - require.Equal(t, info1, newInfo1) - require.Equal(t, info2, newInfo2) -} diff --git a/tests/integration/slashing/keeper/grpc_query_test.go b/tests/integration/slashing/keeper/grpc_query_test.go deleted file mode 100644 index 98cc4a2763f5..000000000000 --- a/tests/integration/slashing/keeper/grpc_query_test.go +++ /dev/null @@ -1,60 +0,0 @@ -package keeper_test - -import ( - gocontext "context" - - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/types/query" - "github.com/cosmos/cosmos-sdk/x/slashing/testslashing" - "github.com/cosmos/cosmos-sdk/x/slashing/types" -) - -func (suite *KeeperTestSuite) TestGRPCQueryParams() { - queryClient := suite.queryClient - paramsResp, err := queryClient.Params(gocontext.Background(), &types.QueryParamsRequest{}) - - suite.NoError(err) - suite.Equal(testslashing.TestParams(), paramsResp.Params) -} - -func (suite *KeeperTestSuite) TestGRPCSigningInfo() { - queryClient := suite.queryClient - - infoResp, err := queryClient.SigningInfo(gocontext.Background(), &types.QuerySigningInfoRequest{ConsAddress: ""}) - suite.Error(err) - suite.Nil(infoResp) - - consAddr := sdk.ConsAddress(suite.addrDels[0]) - info, found := suite.slashingKeeper.GetValidatorSigningInfo(suite.ctx, consAddr) - suite.True(found) - - infoResp, err = queryClient.SigningInfo(gocontext.Background(), - &types.QuerySigningInfoRequest{ConsAddress: consAddr.String()}) - suite.NoError(err) - suite.Equal(info, infoResp.ValSigningInfo) -} - -func (suite *KeeperTestSuite) TestGRPCSigningInfos() { - queryClient := suite.queryClient - - var signingInfos []types.ValidatorSigningInfo - - suite.slashingKeeper.IterateValidatorSigningInfos(suite.ctx, func(consAddr sdk.ConsAddress, info types.ValidatorSigningInfo) (stop bool) { - signingInfos = append(signingInfos, info) - return false - }) - - // verify all values are returned without pagination - infoResp, err := queryClient.SigningInfos(gocontext.Background(), - &types.QuerySigningInfosRequest{Pagination: nil}) - suite.NoError(err) - suite.Equal(signingInfos, infoResp.Info) - - infoResp, err = queryClient.SigningInfos(gocontext.Background(), - &types.QuerySigningInfosRequest{Pagination: &query.PageRequest{Limit: 1, CountTotal: true}}) - suite.NoError(err) - suite.Len(infoResp.Info, 1) - suite.Equal(signingInfos[0], infoResp.Info[0]) - suite.NotNil(infoResp.Pagination.NextKey) - suite.Equal(uint64(2), infoResp.Pagination.Total) -} diff --git a/tests/integration/slashing/keeper/keeper_test.go b/tests/integration/slashing/keeper/keeper_test.go index 622510dd690e..bbd703818aa4 100644 --- a/tests/integration/slashing/keeper/keeper_test.go +++ b/tests/integration/slashing/keeper/keeper_test.go @@ -8,24 +8,28 @@ import ( tmproto "github.com/tendermint/tendermint/proto/tendermint/types" "github.com/cosmos/cosmos-sdk/baseapp" - codectypes "github.com/cosmos/cosmos-sdk/codec/types" simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" sdk "github.com/cosmos/cosmos-sdk/types" - authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper" - authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" - bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" - banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" - slashingkeeper "github.com/cosmos/cosmos-sdk/x/slashing/keeper" "github.com/cosmos/cosmos-sdk/x/slashing/testslashing" "github.com/cosmos/cosmos-sdk/x/slashing/testutil" - "github.com/cosmos/cosmos-sdk/x/slashing/types" - slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types" "github.com/cosmos/cosmos-sdk/x/staking" - stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" "github.com/cosmos/cosmos-sdk/x/staking/teststaking" + + authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper" + bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" + slashingkeeper "github.com/cosmos/cosmos-sdk/x/slashing/keeper" + stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" + + codectypes "github.com/cosmos/cosmos-sdk/codec/types" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" + banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" + slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" ) +// The default power validators are initialized to have within tests +var InitTokens = sdk.TokensFromConsensusPower(200, sdk.DefaultPowerReduction) + type KeeperTestSuite struct { suite.Suite @@ -37,7 +41,7 @@ type KeeperTestSuite struct { interfaceRegistry codectypes.InterfaceRegistry addrDels []sdk.AccAddress queryClient slashingtypes.QueryClient - msgServer types.MsgServer + msgServer slashingtypes.MsgServer } func (s *KeeperTestSuite) SetupTest() { @@ -59,17 +63,17 @@ func (s *KeeperTestSuite) SetupTest() { addrDels := simtestutil.AddTestAddrsIncremental(s.bankKeeper, s.stakingKeeper, ctx, 5, s.stakingKeeper.TokensFromConsensusPower(ctx, 200)) - info1 := types.NewValidatorSigningInfo(sdk.ConsAddress(addrDels[0]), int64(4), int64(3), + info1 := slashingtypes.NewValidatorSigningInfo(sdk.ConsAddress(addrDels[0]), int64(4), int64(3), time.Unix(2, 0), false, int64(10)) - info2 := types.NewValidatorSigningInfo(sdk.ConsAddress(addrDels[1]), int64(5), int64(4), + info2 := slashingtypes.NewValidatorSigningInfo(sdk.ConsAddress(addrDels[1]), int64(5), int64(4), time.Unix(2, 0), false, int64(10)) s.slashingKeeper.SetValidatorSigningInfo(ctx, sdk.ConsAddress(addrDels[0]), info1) s.slashingKeeper.SetValidatorSigningInfo(ctx, sdk.ConsAddress(addrDels[1]), info2) queryHelper := baseapp.NewQueryServerTestHelper(ctx, s.interfaceRegistry) - types.RegisterQueryServer(queryHelper, s.slashingKeeper) - queryClient := types.NewQueryClient(queryHelper) + slashingtypes.RegisterQueryServer(queryHelper, s.slashingKeeper) + queryClient := slashingtypes.NewQueryClient(queryHelper) s.queryClient = queryClient s.addrDels = addrDels diff --git a/tests/integration/slashing/keeper/signing_info_test.go b/tests/integration/slashing/keeper/signing_info_test.go deleted file mode 100644 index 67c34467ec11..000000000000 --- a/tests/integration/slashing/keeper/signing_info_test.go +++ /dev/null @@ -1,88 +0,0 @@ -package keeper_test - -import ( - "time" - - simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/slashing/types" -) - -func (suite *KeeperTestSuite) TestGetSetValidatorSigningInfo() { - ctx := suite.ctx - - addrDels := suite.addrDels - info, found := suite.slashingKeeper.GetValidatorSigningInfo(ctx, sdk.ConsAddress(addrDels[2])) - suite.Require().False(found) - newInfo := types.NewValidatorSigningInfo( - sdk.ConsAddress(addrDels[2]), - int64(4), - int64(3), - time.Unix(2, 0), - false, - int64(10), - ) - suite.slashingKeeper.SetValidatorSigningInfo(ctx, sdk.ConsAddress(addrDels[2]), newInfo) - info, found = suite.slashingKeeper.GetValidatorSigningInfo(ctx, sdk.ConsAddress(addrDels[2])) - suite.Require().True(found) - suite.Require().Equal(info.StartHeight, int64(4)) - suite.Require().Equal(info.IndexOffset, int64(3)) - suite.Require().Equal(info.JailedUntil, time.Unix(2, 0).UTC()) - suite.Require().Equal(info.MissedBlocksCounter, int64(10)) -} - -func (suite *KeeperTestSuite) TestGetSetValidatorMissedBlockBitArray() { - ctx := suite.ctx - addrDels := simtestutil.AddTestAddrsIncremental(suite.bankKeeper, suite.stakingKeeper, ctx, 1, suite.stakingKeeper.TokensFromConsensusPower(ctx, 200)) - - missed := suite.slashingKeeper.GetValidatorMissedBlockBitArray(ctx, sdk.ConsAddress(addrDels[0]), 0) - suite.Require().False(missed) // treat empty key as not missed - suite.slashingKeeper.SetValidatorMissedBlockBitArray(ctx, sdk.ConsAddress(addrDels[0]), 0, true) - missed = suite.slashingKeeper.GetValidatorMissedBlockBitArray(ctx, sdk.ConsAddress(addrDels[0]), 0) - suite.Require().True(missed) // now should be missed -} - -func (suite *KeeperTestSuite) TestTombstoned() { - ctx := suite.ctx - addrDels := suite.addrDels - - suite.Require().Panics(func() { suite.slashingKeeper.Tombstone(ctx, sdk.ConsAddress(addrDels[4])) }) - suite.Require().False(suite.slashingKeeper.IsTombstoned(ctx, sdk.ConsAddress(addrDels[4]))) - - newInfo := types.NewValidatorSigningInfo( - sdk.ConsAddress(addrDels[4]), - int64(4), - int64(3), - time.Unix(2, 0), - false, - int64(10), - ) - suite.slashingKeeper.SetValidatorSigningInfo(ctx, sdk.ConsAddress(addrDels[4]), newInfo) - - suite.Require().False(suite.slashingKeeper.IsTombstoned(ctx, sdk.ConsAddress(addrDels[4]))) - suite.slashingKeeper.Tombstone(ctx, sdk.ConsAddress(addrDels[4])) - suite.Require().True(suite.slashingKeeper.IsTombstoned(ctx, sdk.ConsAddress(addrDels[4]))) - suite.Require().Panics(func() { suite.slashingKeeper.Tombstone(ctx, sdk.ConsAddress(addrDels[4])) }) -} - -func (suite *KeeperTestSuite) TestJailUntil() { - ctx := suite.ctx - addrDels := suite.addrDels - - suite.Require().Panics(func() { suite.slashingKeeper.JailUntil(ctx, sdk.ConsAddress(addrDels[3]), time.Now()) }) - - newInfo := types.NewValidatorSigningInfo( - sdk.ConsAddress(addrDels[3]), - int64(4), - int64(3), - time.Unix(2, 0), - false, - int64(10), - ) - suite.slashingKeeper.SetValidatorSigningInfo(ctx, sdk.ConsAddress(addrDels[3]), newInfo) - suite.slashingKeeper.JailUntil(ctx, sdk.ConsAddress(addrDels[3]), time.Unix(253402300799, 0).UTC()) - - info, ok := suite.slashingKeeper.GetValidatorSigningInfo(ctx, sdk.ConsAddress(addrDels[3])) - suite.Require().True(ok) - suite.Require().Equal(time.Unix(253402300799, 0).UTC(), info.JailedUntil) -} diff --git a/x/slashing/keeper/genesis_test.go b/x/slashing/keeper/genesis_test.go new file mode 100644 index 000000000000..2b882c1bba45 --- /dev/null +++ b/x/slashing/keeper/genesis_test.go @@ -0,0 +1,57 @@ +package keeper_test + +import ( + "time" + + "github.com/golang/mock/gomock" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/x/slashing/testslashing" + "github.com/cosmos/cosmos-sdk/x/slashing/types" +) + +func (s *KeeperTestSuite) TestExportAndInitGenesis() { + ctx, keeper := s.ctx, s.slashingKeeper + require := s.Require() + + keeper.SetParams(ctx, testslashing.TestParams()) + + consAddr1 := sdk.ConsAddress(sdk.AccAddress([]byte("addr1_______________"))) + consAddr2 := sdk.ConsAddress(sdk.AccAddress([]byte("addr2_______________"))) + + info1 := types.NewValidatorSigningInfo(consAddr1, int64(4), int64(3), + time.Now().UTC().Add(100000000000), false, int64(10)) + info2 := types.NewValidatorSigningInfo(consAddr2, int64(5), int64(4), + time.Now().UTC().Add(10000000000), false, int64(10)) + + keeper.SetValidatorSigningInfo(ctx, consAddr1, info1) + keeper.SetValidatorSigningInfo(ctx, consAddr2, info2) + genesisState := keeper.ExportGenesis(ctx) + + require.Equal(genesisState.Params, testslashing.TestParams()) + require.Len(genesisState.SigningInfos, 2) + require.Equal(genesisState.SigningInfos[0].ValidatorSigningInfo, info1) + + // Tombstone validators after genesis shouldn't effect genesis state + keeper.Tombstone(ctx, consAddr1) + keeper.Tombstone(ctx, consAddr2) + + ok := keeper.IsTombstoned(ctx, consAddr1) + require.True(ok) + + newInfo1, _ := keeper.GetValidatorSigningInfo(ctx, consAddr1) + require.NotEqual(info1, newInfo1) + + // Initialise genesis with genesis state before tombstone + s.stakingKeeper.EXPECT().IterateValidators(ctx, gomock.Any()).Return() + keeper.InitGenesis(ctx, s.stakingKeeper, genesisState) + + // Validator isTombstoned should return false as GenesisState is initialised + ok = keeper.IsTombstoned(ctx, consAddr1) + require.False(ok) + + newInfo1, _ = keeper.GetValidatorSigningInfo(ctx, consAddr1) + newInfo2, _ := keeper.GetValidatorSigningInfo(ctx, consAddr2) + require.Equal(info1, newInfo1) + require.Equal(info2, newInfo2) +} diff --git a/x/slashing/keeper/grpc_query_test.go b/x/slashing/keeper/grpc_query_test.go new file mode 100644 index 000000000000..0c314610b8d4 --- /dev/null +++ b/x/slashing/keeper/grpc_query_test.go @@ -0,0 +1,91 @@ +package keeper_test + +import ( + gocontext "context" + "time" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/query" + "github.com/cosmos/cosmos-sdk/x/slashing/testslashing" + "github.com/cosmos/cosmos-sdk/x/slashing/types" + slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types" +) + +func (s *KeeperTestSuite) TestGRPCQueryParams() { + queryClient := s.queryClient + require := s.Require() + + paramsResp, err := queryClient.Params(gocontext.Background(), &types.QueryParamsRequest{}) + + require.NoError(err) + require.Equal(testslashing.TestParams(), paramsResp.Params) +} + +func (s *KeeperTestSuite) TestGRPCSigningInfo() { + queryClient, ctx, keeper := s.queryClient, s.ctx, s.slashingKeeper + require := s.Require() + + infoResp, err := queryClient.SigningInfo(gocontext.Background(), &types.QuerySigningInfoRequest{ConsAddress: ""}) + require.Error(err) + require.Nil(infoResp) + + signingInfo := slashingtypes.NewValidatorSigningInfo( + consAddr, + 0, + int64(0), + time.Unix(2, 0), + false, + int64(0), + ) + + keeper.SetValidatorSigningInfo(ctx, consAddr, signingInfo) + info, found := keeper.GetValidatorSigningInfo(ctx, consAddr) + require.True(found) + + infoResp, err = queryClient.SigningInfo(gocontext.Background(), + &types.QuerySigningInfoRequest{ConsAddress: consAddr.String()}) + require.NoError(err) + require.Equal(info, infoResp.ValSigningInfo) +} + +func (s *KeeperTestSuite) TestGRPCSigningInfos() { + queryClient, ctx, keeper := s.queryClient, s.ctx, s.slashingKeeper + require := s.Require() + + // set two validator signing information + consAddr1 := sdk.ConsAddress(sdk.AccAddress([]byte("addr1_______________"))) + consAddr2 := sdk.ConsAddress(sdk.AccAddress([]byte("addr2_______________"))) + signingInfo := slashingtypes.NewValidatorSigningInfo( + consAddr1, + 0, + int64(0), + time.Unix(2, 0), + false, + int64(0), + ) + + keeper.SetValidatorSigningInfo(ctx, consAddr1, signingInfo) + signingInfo.Address = string(consAddr2) + keeper.SetValidatorSigningInfo(ctx, consAddr2, signingInfo) + + var signingInfos []types.ValidatorSigningInfo + + keeper.IterateValidatorSigningInfos(ctx, func(consAddr sdk.ConsAddress, info types.ValidatorSigningInfo) (stop bool) { + signingInfos = append(signingInfos, info) + return false + }) + + // verify all values are returned without pagination + infoResp, err := queryClient.SigningInfos(gocontext.Background(), + &types.QuerySigningInfosRequest{Pagination: nil}) + require.NoError(err) + require.Equal(signingInfos, infoResp.Info) + + infoResp, err = queryClient.SigningInfos(gocontext.Background(), + &types.QuerySigningInfosRequest{Pagination: &query.PageRequest{Limit: 1, CountTotal: true}}) + require.NoError(err) + require.Len(infoResp.Info, 1) + require.Equal(signingInfos[0], infoResp.Info[0]) + require.NotNil(infoResp.Pagination.NextKey) + require.Equal(uint64(2), infoResp.Pagination.Total) +} diff --git a/x/slashing/keeper/keeper_test.go b/x/slashing/keeper/keeper_test.go new file mode 100644 index 000000000000..9285ce92eb52 --- /dev/null +++ b/x/slashing/keeper/keeper_test.go @@ -0,0 +1,82 @@ +package keeper_test + +import ( + "testing" + + "github.com/golang/mock/gomock" + "github.com/stretchr/testify/suite" + "github.com/tendermint/tendermint/crypto" + + tmtime "github.com/tendermint/tendermint/libs/time" + tmproto "github.com/tendermint/tendermint/proto/tendermint/types" + + "github.com/cosmos/cosmos-sdk/baseapp" + "github.com/cosmos/cosmos-sdk/testutil" + "github.com/cosmos/cosmos-sdk/testutil/testdata" + sdk "github.com/cosmos/cosmos-sdk/types" + moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" + "github.com/cosmos/cosmos-sdk/x/slashing/testslashing" + slashingtestutil "github.com/cosmos/cosmos-sdk/x/slashing/testutil" + + slashingkeeper "github.com/cosmos/cosmos-sdk/x/slashing/keeper" + + govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" + slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types" +) + +var consAddr = sdk.ConsAddress(sdk.AccAddress([]byte("addr1_______________"))) + +type KeeperTestSuite struct { + suite.Suite + + ctx sdk.Context + stakingKeeper *slashingtestutil.MockStakingKeeper + slashingKeeper slashingkeeper.Keeper + queryClient slashingtypes.QueryClient + msgServer slashingtypes.MsgServer +} + +func (s *KeeperTestSuite) SetupTest() { + key := sdk.NewKVStoreKey(slashingtypes.StoreKey) + testCtx := testutil.DefaultContextWithDB(s.T(), key, sdk.NewTransientStoreKey("transient_test")) + ctx := testCtx.Ctx.WithBlockHeader(tmproto.Header{Time: tmtime.Now()}) + encCfg := moduletestutil.MakeTestEncodingConfig() + + // gomock initializations + ctrl := gomock.NewController(s.T()) + s.stakingKeeper = slashingtestutil.NewMockStakingKeeper(ctrl) + + s.ctx = ctx + s.slashingKeeper = slashingkeeper.NewKeeper( + encCfg.Codec, + encCfg.Amino, + key, + s.stakingKeeper, + sdk.AccAddress(crypto.AddressHash([]byte(govtypes.ModuleName))).String(), + ) + // set test params + s.slashingKeeper.SetParams(ctx, testslashing.TestParams()) + + slashingtypes.RegisterInterfaces(encCfg.InterfaceRegistry) + queryHelper := baseapp.NewQueryServerTestHelper(ctx, encCfg.InterfaceRegistry) + slashingtypes.RegisterQueryServer(queryHelper, s.slashingKeeper) + + s.queryClient = slashingtypes.NewQueryClient(queryHelper) + s.msgServer = slashingkeeper.NewMsgServerImpl(s.slashingKeeper) +} + +func (s *KeeperTestSuite) TestPubkey() { + ctx, keeper := s.ctx, s.slashingKeeper + require := s.Require() + + _, pubKey, addr := testdata.KeyTestPubAddr() + require.NoError(keeper.AddPubkey(ctx, pubKey)) + + expectedPubKey, err := keeper.GetPubkey(ctx, addr.Bytes()) + require.NoError(err) + require.Equal(pubKey, expectedPubKey) +} + +func TestKeeperTestSuite(t *testing.T) { + suite.Run(t, new(KeeperTestSuite)) +} diff --git a/tests/integration/slashing/keeper/msg_server_test.go b/x/slashing/keeper/msg_server_test.go similarity index 72% rename from tests/integration/slashing/keeper/msg_server_test.go rename to x/slashing/keeper/msg_server_test.go index 926bd8c3832f..ad41a7cc7823 100644 --- a/tests/integration/slashing/keeper/msg_server_test.go +++ b/x/slashing/keeper/msg_server_test.go @@ -4,31 +4,34 @@ import ( "time" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/slashing/types" + slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types" + "github.com/golang/mock/gomock" ) func (s *KeeperTestSuite) TestUpdateParams() { + require := s.Require() + minSignedPerWindow, err := sdk.NewDecFromStr("0.60") - s.Require().NoError(err) + require.NoError(err) slashFractionDoubleSign, err := sdk.NewDecFromStr("0.022") - s.Require().NoError(err) + require.NoError(err) slashFractionDowntime, err := sdk.NewDecFromStr("0.0089") - s.Require().NoError(err) + require.NoError(err) invalidVal, err := sdk.NewDecFromStr("-1") - s.Require().NoError(err) + require.NoError(err) testCases := []struct { name string - request *types.MsgUpdateParams + request *slashingtypes.MsgUpdateParams expectErr bool expErrMsg string }{ { name: "set invalid authority", - request: &types.MsgUpdateParams{ + request: &slashingtypes.MsgUpdateParams{ Authority: "foo", }, expectErr: true, @@ -36,9 +39,9 @@ func (s *KeeperTestSuite) TestUpdateParams() { }, { name: "set invalid signed blocks window", - request: &types.MsgUpdateParams{ + request: &slashingtypes.MsgUpdateParams{ Authority: s.slashingKeeper.GetAuthority(), - Params: types.Params{ + Params: slashingtypes.Params{ SignedBlocksWindow: 0, MinSignedPerWindow: minSignedPerWindow, DowntimeJailDuration: time.Duration(34800000000000), @@ -51,9 +54,9 @@ func (s *KeeperTestSuite) TestUpdateParams() { }, { name: "set invalid min signed per window", - request: &types.MsgUpdateParams{ + request: &slashingtypes.MsgUpdateParams{ Authority: s.slashingKeeper.GetAuthority(), - Params: types.Params{ + Params: slashingtypes.Params{ SignedBlocksWindow: int64(750), MinSignedPerWindow: invalidVal, DowntimeJailDuration: time.Duration(34800000000000), @@ -66,9 +69,9 @@ func (s *KeeperTestSuite) TestUpdateParams() { }, { name: "set invalid downtime jail duration", - request: &types.MsgUpdateParams{ + request: &slashingtypes.MsgUpdateParams{ Authority: s.slashingKeeper.GetAuthority(), - Params: types.Params{ + Params: slashingtypes.Params{ SignedBlocksWindow: int64(750), MinSignedPerWindow: minSignedPerWindow, DowntimeJailDuration: time.Duration(0), @@ -81,9 +84,9 @@ func (s *KeeperTestSuite) TestUpdateParams() { }, { name: "set invalid slash fraction double sign", - request: &types.MsgUpdateParams{ + request: &slashingtypes.MsgUpdateParams{ Authority: s.slashingKeeper.GetAuthority(), - Params: types.Params{ + Params: slashingtypes.Params{ SignedBlocksWindow: int64(750), MinSignedPerWindow: minSignedPerWindow, DowntimeJailDuration: time.Duration(10), @@ -96,9 +99,9 @@ func (s *KeeperTestSuite) TestUpdateParams() { }, { name: "set invalid slash fraction downtime", - request: &types.MsgUpdateParams{ + request: &slashingtypes.MsgUpdateParams{ Authority: s.slashingKeeper.GetAuthority(), - Params: types.Params{ + Params: slashingtypes.Params{ SignedBlocksWindow: int64(750), MinSignedPerWindow: minSignedPerWindow, DowntimeJailDuration: time.Duration(10), @@ -111,9 +114,9 @@ func (s *KeeperTestSuite) TestUpdateParams() { }, { name: "set full valid params", - request: &types.MsgUpdateParams{ + request: &slashingtypes.MsgUpdateParams{ Authority: s.slashingKeeper.GetAuthority(), - Params: types.Params{ + Params: slashingtypes.Params{ SignedBlocksWindow: int64(750), MinSignedPerWindow: minSignedPerWindow, DowntimeJailDuration: time.Duration(34800000000000), @@ -130,11 +133,23 @@ func (s *KeeperTestSuite) TestUpdateParams() { s.Run(tc.name, func() { _, err := s.msgServer.UpdateParams(s.ctx, tc.request) if tc.expectErr { - s.Require().Error(err) - s.Require().Contains(err.Error(), tc.expErrMsg) + require.Error(err) + require.Contains(err.Error(), tc.expErrMsg) } else { - s.Require().NoError(err) + require.NoError(err) } }) } } + +func (s *KeeperTestSuite) TestUnjail() { + addr := sdk.AccAddress([]byte("val1_______________")) + request := &slashingtypes.MsgUnjail{ + ValidatorAddr: sdk.ValAddress(addr).String(), + } + + s.stakingKeeper.EXPECT().Validator(gomock.Any(), gomock.Any()).Return(nil) + _, err := s.msgServer.Unjail(s.ctx, request) + s.Require().Error(err) + s.Require().Equal(err, slashingtypes.ErrNoValidatorForAddress) +} diff --git a/tests/integration/slashing/keeper/params_test.go b/x/slashing/keeper/params_test.go similarity index 88% rename from tests/integration/slashing/keeper/params_test.go rename to x/slashing/keeper/params_test.go index 94faa023e0b1..1f1d4a7dd7ba 100644 --- a/tests/integration/slashing/keeper/params_test.go +++ b/x/slashing/keeper/params_test.go @@ -8,17 +8,20 @@ import ( ) func (s *KeeperTestSuite) TestParams() { + ctx, keeper := s.ctx, s.slashingKeeper + require := s.Require() + minSignedPerWindow, err := sdk.NewDecFromStr("0.60") - s.Require().NoError(err) + require.NoError(err) slashFractionDoubleSign, err := sdk.NewDecFromStr("0.022") - s.Require().NoError(err) + require.NoError(err) slashFractionDowntime, err := sdk.NewDecFromStr("0.0089") - s.Require().NoError(err) + require.NoError(err) invalidVal, err := sdk.NewDecFromStr("-1") - s.Require().NoError(err) + require.NoError(err) testCases := []struct { name string @@ -101,19 +104,19 @@ func (s *KeeperTestSuite) TestParams() { for _, tc := range testCases { tc := tc s.Run(tc.name, func() { - expected := s.slashingKeeper.GetParams(s.ctx) - err := s.slashingKeeper.SetParams(s.ctx, tc.input) + expected := keeper.GetParams(ctx) + err := keeper.SetParams(ctx, tc.input) if tc.expectErr { - s.Require().Error(err) - s.Require().Contains(err.Error(), tc.expErrMsg) + require.Error(err) + require.Contains(err.Error(), tc.expErrMsg) } else { expected = tc.input - s.Require().NoError(err) + require.NoError(err) } - params := s.slashingKeeper.GetParams(s.ctx) - s.Require().Equal(expected, params) + params := keeper.GetParams(ctx) + require.Equal(expected, params) }) } } diff --git a/x/slashing/keeper/signing_info_test.go b/x/slashing/keeper/signing_info_test.go new file mode 100644 index 000000000000..cfef7104b825 --- /dev/null +++ b/x/slashing/keeper/signing_info_test.go @@ -0,0 +1,93 @@ +package keeper_test + +import ( + "time" + + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/cosmos/cosmos-sdk/x/slashing/testslashing" + slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types" +) + +func (s *KeeperTestSuite) TestValidatorSigningInfo() { + ctx, keeper := s.ctx, s.slashingKeeper + require := s.Require() + + signingInfo := slashingtypes.NewValidatorSigningInfo( + consAddr, + ctx.BlockHeight(), + int64(3), + time.Unix(2, 0), + false, + int64(10), + ) + + // set the validator signing information + keeper.SetValidatorSigningInfo(ctx, consAddr, signingInfo) + + require.True(keeper.HasValidatorSigningInfo(ctx, consAddr)) + info, found := keeper.GetValidatorSigningInfo(ctx, consAddr) + require.True(found) + require.Equal(info.StartHeight, ctx.BlockHeight()) + require.Equal(info.IndexOffset, int64(3)) + require.Equal(info.JailedUntil, time.Unix(2, 0).UTC()) + require.Equal(info.MissedBlocksCounter, int64(10)) + + var signingInfos []slashingtypes.ValidatorSigningInfo + + keeper.IterateValidatorSigningInfos(ctx, func(consAddr sdk.ConsAddress, info slashingtypes.ValidatorSigningInfo) (stop bool) { + signingInfos = append(signingInfos, info) + return false + }) + + require.Equal(signingInfos[0].Address, signingInfo.Address) + + // test Tombstone + keeper.Tombstone(ctx, consAddr) + require.True(keeper.IsTombstoned(ctx, consAddr)) + + // test JailUntil + jailTime := time.Now().Add(time.Hour).UTC() + keeper.JailUntil(ctx, consAddr, jailTime) + sInfo, _ := keeper.GetValidatorSigningInfo(ctx, consAddr) + require.Equal(sInfo.JailedUntil, jailTime) +} + +func (s *KeeperTestSuite) TestValidatorMissedBlockBitArray() { + ctx, keeper := s.ctx, s.slashingKeeper + require := s.Require() + + params := testslashing.TestParams() + params.SignedBlocksWindow = 100 + require.NoError(keeper.SetParams(ctx, params)) + + testCases := []struct { + name string + index int64 + missed bool + }{ + { + name: "missed block with false", + index: 50, + missed: false, + }, + { + name: "missed block with true", + index: 51, + missed: true, + }, + } + for ind, tc := range testCases { + tc := tc + s.Run(tc.name, func() { + keeper.SetValidatorMissedBlockBitArray(ctx, consAddr, tc.index, tc.missed) + missed := keeper.GetValidatorMissedBlockBitArray(ctx, consAddr, tc.index) + + require.Equal(missed, tc.missed) + missedBlocks := keeper.GetValidatorMissedBlocks(ctx, consAddr) + require.Equal(len(missedBlocks), ind+1) + require.Equal(missedBlocks[ind].Index, tc.index) + require.Equal(missedBlocks[ind].Missed, tc.missed) + }) + } +} diff --git a/x/slashing/testutil/expected_keepers_mocks.go b/x/slashing/testutil/expected_keepers_mocks.go new file mode 100644 index 000000000000..05eec6974153 --- /dev/null +++ b/x/slashing/testutil/expected_keepers_mocks.go @@ -0,0 +1,425 @@ +// Code generated by MockGen. DO NOT EDIT. +// Source: x/slashing/types/expected_keepers.go + +// Package testutil is a generated GoMock package. +package testutil + +import ( + reflect "reflect" + + math "cosmossdk.io/math" + types "github.com/cosmos/cosmos-sdk/types" + types0 "github.com/cosmos/cosmos-sdk/x/auth/types" + types1 "github.com/cosmos/cosmos-sdk/x/params/types" + types2 "github.com/cosmos/cosmos-sdk/x/staking/types" + gomock "github.com/golang/mock/gomock" +) + +// MockAccountKeeper is a mock of AccountKeeper interface. +type MockAccountKeeper struct { + ctrl *gomock.Controller + recorder *MockAccountKeeperMockRecorder +} + +// MockAccountKeeperMockRecorder is the mock recorder for MockAccountKeeper. +type MockAccountKeeperMockRecorder struct { + mock *MockAccountKeeper +} + +// NewMockAccountKeeper creates a new mock instance. +func NewMockAccountKeeper(ctrl *gomock.Controller) *MockAccountKeeper { + mock := &MockAccountKeeper{ctrl: ctrl} + mock.recorder = &MockAccountKeeperMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockAccountKeeper) EXPECT() *MockAccountKeeperMockRecorder { + return m.recorder +} + +// GetAccount mocks base method. +func (m *MockAccountKeeper) GetAccount(ctx types.Context, addr types.AccAddress) types0.AccountI { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetAccount", ctx, addr) + ret0, _ := ret[0].(types0.AccountI) + return ret0 +} + +// GetAccount indicates an expected call of GetAccount. +func (mr *MockAccountKeeperMockRecorder) GetAccount(ctx, addr interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetAccount", reflect.TypeOf((*MockAccountKeeper)(nil).GetAccount), ctx, addr) +} + +// IterateAccounts mocks base method. +func (m *MockAccountKeeper) IterateAccounts(ctx types.Context, process func(types0.AccountI) bool) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "IterateAccounts", ctx, process) +} + +// IterateAccounts indicates an expected call of IterateAccounts. +func (mr *MockAccountKeeperMockRecorder) IterateAccounts(ctx, process interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IterateAccounts", reflect.TypeOf((*MockAccountKeeper)(nil).IterateAccounts), ctx, process) +} + +// MockBankKeeper is a mock of BankKeeper interface. +type MockBankKeeper struct { + ctrl *gomock.Controller + recorder *MockBankKeeperMockRecorder +} + +// MockBankKeeperMockRecorder is the mock recorder for MockBankKeeper. +type MockBankKeeperMockRecorder struct { + mock *MockBankKeeper +} + +// NewMockBankKeeper creates a new mock instance. +func NewMockBankKeeper(ctrl *gomock.Controller) *MockBankKeeper { + mock := &MockBankKeeper{ctrl: ctrl} + mock.recorder = &MockBankKeeperMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockBankKeeper) EXPECT() *MockBankKeeperMockRecorder { + return m.recorder +} + +// GetAllBalances mocks base method. +func (m *MockBankKeeper) GetAllBalances(ctx types.Context, addr types.AccAddress) types.Coins { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetAllBalances", ctx, addr) + ret0, _ := ret[0].(types.Coins) + return ret0 +} + +// GetAllBalances indicates an expected call of GetAllBalances. +func (mr *MockBankKeeperMockRecorder) GetAllBalances(ctx, addr interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetAllBalances", reflect.TypeOf((*MockBankKeeper)(nil).GetAllBalances), ctx, addr) +} + +// GetBalance mocks base method. +func (m *MockBankKeeper) GetBalance(ctx types.Context, addr types.AccAddress, denom string) types.Coin { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetBalance", ctx, addr, denom) + ret0, _ := ret[0].(types.Coin) + return ret0 +} + +// GetBalance indicates an expected call of GetBalance. +func (mr *MockBankKeeperMockRecorder) GetBalance(ctx, addr, denom interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetBalance", reflect.TypeOf((*MockBankKeeper)(nil).GetBalance), ctx, addr, denom) +} + +// LockedCoins mocks base method. +func (m *MockBankKeeper) LockedCoins(ctx types.Context, addr types.AccAddress) types.Coins { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "LockedCoins", ctx, addr) + ret0, _ := ret[0].(types.Coins) + return ret0 +} + +// LockedCoins indicates an expected call of LockedCoins. +func (mr *MockBankKeeperMockRecorder) LockedCoins(ctx, addr interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "LockedCoins", reflect.TypeOf((*MockBankKeeper)(nil).LockedCoins), ctx, addr) +} + +// SpendableCoins mocks base method. +func (m *MockBankKeeper) SpendableCoins(ctx types.Context, addr types.AccAddress) types.Coins { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "SpendableCoins", ctx, addr) + ret0, _ := ret[0].(types.Coins) + return ret0 +} + +// SpendableCoins indicates an expected call of SpendableCoins. +func (mr *MockBankKeeperMockRecorder) SpendableCoins(ctx, addr interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SpendableCoins", reflect.TypeOf((*MockBankKeeper)(nil).SpendableCoins), ctx, addr) +} + +// MockParamSubspace is a mock of ParamSubspace interface. +type MockParamSubspace struct { + ctrl *gomock.Controller + recorder *MockParamSubspaceMockRecorder +} + +// MockParamSubspaceMockRecorder is the mock recorder for MockParamSubspace. +type MockParamSubspaceMockRecorder struct { + mock *MockParamSubspace +} + +// NewMockParamSubspace creates a new mock instance. +func NewMockParamSubspace(ctrl *gomock.Controller) *MockParamSubspace { + mock := &MockParamSubspace{ctrl: ctrl} + mock.recorder = &MockParamSubspaceMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockParamSubspace) EXPECT() *MockParamSubspaceMockRecorder { + return m.recorder +} + +// Get mocks base method. +func (m *MockParamSubspace) Get(ctx types.Context, key []byte, ptr interface{}) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "Get", ctx, key, ptr) +} + +// Get indicates an expected call of Get. +func (mr *MockParamSubspaceMockRecorder) Get(ctx, key, ptr interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Get", reflect.TypeOf((*MockParamSubspace)(nil).Get), ctx, key, ptr) +} + +// GetParamSet mocks base method. +func (m *MockParamSubspace) GetParamSet(ctx types.Context, ps types1.ParamSet) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "GetParamSet", ctx, ps) +} + +// GetParamSet indicates an expected call of GetParamSet. +func (mr *MockParamSubspaceMockRecorder) GetParamSet(ctx, ps interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetParamSet", reflect.TypeOf((*MockParamSubspace)(nil).GetParamSet), ctx, ps) +} + +// HasKeyTable mocks base method. +func (m *MockParamSubspace) HasKeyTable() bool { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "HasKeyTable") + ret0, _ := ret[0].(bool) + return ret0 +} + +// HasKeyTable indicates an expected call of HasKeyTable. +func (mr *MockParamSubspaceMockRecorder) HasKeyTable() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "HasKeyTable", reflect.TypeOf((*MockParamSubspace)(nil).HasKeyTable)) +} + +// SetParamSet mocks base method. +func (m *MockParamSubspace) SetParamSet(ctx types.Context, ps types1.ParamSet) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "SetParamSet", ctx, ps) +} + +// SetParamSet indicates an expected call of SetParamSet. +func (mr *MockParamSubspaceMockRecorder) SetParamSet(ctx, ps interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetParamSet", reflect.TypeOf((*MockParamSubspace)(nil).SetParamSet), ctx, ps) +} + +// WithKeyTable mocks base method. +func (m *MockParamSubspace) WithKeyTable(table types1.KeyTable) types1.Subspace { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "WithKeyTable", table) + ret0, _ := ret[0].(types1.Subspace) + return ret0 +} + +// WithKeyTable indicates an expected call of WithKeyTable. +func (mr *MockParamSubspaceMockRecorder) WithKeyTable(table interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "WithKeyTable", reflect.TypeOf((*MockParamSubspace)(nil).WithKeyTable), table) +} + +// MockStakingKeeper is a mock of StakingKeeper interface. +type MockStakingKeeper struct { + ctrl *gomock.Controller + recorder *MockStakingKeeperMockRecorder +} + +// MockStakingKeeperMockRecorder is the mock recorder for MockStakingKeeper. +type MockStakingKeeperMockRecorder struct { + mock *MockStakingKeeper +} + +// NewMockStakingKeeper creates a new mock instance. +func NewMockStakingKeeper(ctrl *gomock.Controller) *MockStakingKeeper { + mock := &MockStakingKeeper{ctrl: ctrl} + mock.recorder = &MockStakingKeeperMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockStakingKeeper) EXPECT() *MockStakingKeeperMockRecorder { + return m.recorder +} + +// Delegation mocks base method. +func (m *MockStakingKeeper) Delegation(arg0 types.Context, arg1 types.AccAddress, arg2 types.ValAddress) types2.DelegationI { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Delegation", arg0, arg1, arg2) + ret0, _ := ret[0].(types2.DelegationI) + return ret0 +} + +// Delegation indicates an expected call of Delegation. +func (mr *MockStakingKeeperMockRecorder) Delegation(arg0, arg1, arg2 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Delegation", reflect.TypeOf((*MockStakingKeeper)(nil).Delegation), arg0, arg1, arg2) +} + +// IterateValidators mocks base method. +func (m *MockStakingKeeper) IterateValidators(arg0 types.Context, arg1 func(int64, types2.ValidatorI) bool) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "IterateValidators", arg0, arg1) +} + +// IterateValidators indicates an expected call of IterateValidators. +func (mr *MockStakingKeeperMockRecorder) IterateValidators(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IterateValidators", reflect.TypeOf((*MockStakingKeeper)(nil).IterateValidators), arg0, arg1) +} + +// Jail mocks base method. +func (m *MockStakingKeeper) Jail(arg0 types.Context, arg1 types.ConsAddress) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "Jail", arg0, arg1) +} + +// Jail indicates an expected call of Jail. +func (mr *MockStakingKeeperMockRecorder) Jail(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Jail", reflect.TypeOf((*MockStakingKeeper)(nil).Jail), arg0, arg1) +} + +// MaxValidators mocks base method. +func (m *MockStakingKeeper) MaxValidators(arg0 types.Context) uint32 { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "MaxValidators", arg0) + ret0, _ := ret[0].(uint32) + return ret0 +} + +// MaxValidators indicates an expected call of MaxValidators. +func (mr *MockStakingKeeperMockRecorder) MaxValidators(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "MaxValidators", reflect.TypeOf((*MockStakingKeeper)(nil).MaxValidators), arg0) +} + +// Slash mocks base method. +func (m *MockStakingKeeper) Slash(arg0 types.Context, arg1 types.ConsAddress, arg2, arg3 int64, arg4 types.Dec) math.Int { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Slash", arg0, arg1, arg2, arg3, arg4) + ret0, _ := ret[0].(math.Int) + return ret0 +} + +// Slash indicates an expected call of Slash. +func (mr *MockStakingKeeperMockRecorder) Slash(arg0, arg1, arg2, arg3, arg4 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Slash", reflect.TypeOf((*MockStakingKeeper)(nil).Slash), arg0, arg1, arg2, arg3, arg4) +} + +// Unjail mocks base method. +func (m *MockStakingKeeper) Unjail(arg0 types.Context, arg1 types.ConsAddress) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "Unjail", arg0, arg1) +} + +// Unjail indicates an expected call of Unjail. +func (mr *MockStakingKeeperMockRecorder) Unjail(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Unjail", reflect.TypeOf((*MockStakingKeeper)(nil).Unjail), arg0, arg1) +} + +// Validator mocks base method. +func (m *MockStakingKeeper) Validator(arg0 types.Context, arg1 types.ValAddress) types2.ValidatorI { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Validator", arg0, arg1) + ret0, _ := ret[0].(types2.ValidatorI) + return ret0 +} + +// Validator indicates an expected call of Validator. +func (mr *MockStakingKeeperMockRecorder) Validator(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Validator", reflect.TypeOf((*MockStakingKeeper)(nil).Validator), arg0, arg1) +} + +// ValidatorByConsAddr mocks base method. +func (m *MockStakingKeeper) ValidatorByConsAddr(arg0 types.Context, arg1 types.ConsAddress) types2.ValidatorI { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ValidatorByConsAddr", arg0, arg1) + ret0, _ := ret[0].(types2.ValidatorI) + return ret0 +} + +// ValidatorByConsAddr indicates an expected call of ValidatorByConsAddr. +func (mr *MockStakingKeeperMockRecorder) ValidatorByConsAddr(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ValidatorByConsAddr", reflect.TypeOf((*MockStakingKeeper)(nil).ValidatorByConsAddr), arg0, arg1) +} + +// MockStakingHooks is a mock of StakingHooks interface. +type MockStakingHooks struct { + ctrl *gomock.Controller + recorder *MockStakingHooksMockRecorder +} + +// MockStakingHooksMockRecorder is the mock recorder for MockStakingHooks. +type MockStakingHooksMockRecorder struct { + mock *MockStakingHooks +} + +// NewMockStakingHooks creates a new mock instance. +func NewMockStakingHooks(ctrl *gomock.Controller) *MockStakingHooks { + mock := &MockStakingHooks{ctrl: ctrl} + mock.recorder = &MockStakingHooksMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockStakingHooks) EXPECT() *MockStakingHooksMockRecorder { + return m.recorder +} + +// AfterValidatorBonded mocks base method. +func (m *MockStakingHooks) AfterValidatorBonded(ctx types.Context, consAddr types.ConsAddress, valAddr types.ValAddress) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "AfterValidatorBonded", ctx, consAddr, valAddr) + ret0, _ := ret[0].(error) + return ret0 +} + +// AfterValidatorBonded indicates an expected call of AfterValidatorBonded. +func (mr *MockStakingHooksMockRecorder) AfterValidatorBonded(ctx, consAddr, valAddr interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AfterValidatorBonded", reflect.TypeOf((*MockStakingHooks)(nil).AfterValidatorBonded), ctx, consAddr, valAddr) +} + +// AfterValidatorCreated mocks base method. +func (m *MockStakingHooks) AfterValidatorCreated(ctx types.Context, valAddr types.ValAddress) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "AfterValidatorCreated", ctx, valAddr) + ret0, _ := ret[0].(error) + return ret0 +} + +// AfterValidatorCreated indicates an expected call of AfterValidatorCreated. +func (mr *MockStakingHooksMockRecorder) AfterValidatorCreated(ctx, valAddr interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AfterValidatorCreated", reflect.TypeOf((*MockStakingHooks)(nil).AfterValidatorCreated), ctx, valAddr) +} + +// AfterValidatorRemoved mocks base method. +func (m *MockStakingHooks) AfterValidatorRemoved(ctx types.Context, consAddr types.ConsAddress, valAddr types.ValAddress) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "AfterValidatorRemoved", ctx, consAddr, valAddr) + ret0, _ := ret[0].(error) + return ret0 +} + +// AfterValidatorRemoved indicates an expected call of AfterValidatorRemoved. +func (mr *MockStakingHooksMockRecorder) AfterValidatorRemoved(ctx, consAddr, valAddr interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AfterValidatorRemoved", reflect.TypeOf((*MockStakingHooks)(nil).AfterValidatorRemoved), ctx, consAddr, valAddr) +} From 69c49c6e30a8172dccf0cd5ab57dd186459bde1c Mon Sep 17 00:00:00 2001 From: Cool Developer Date: Tue, 16 Aug 2022 16:17:13 -0400 Subject: [PATCH 3/4] refactor module import --- x/slashing/keeper/grpc_query_test.go | 15 +++++++-------- x/slashing/keeper/msg_server_test.go | 3 ++- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/x/slashing/keeper/grpc_query_test.go b/x/slashing/keeper/grpc_query_test.go index 0c314610b8d4..d11d4c9dbb01 100644 --- a/x/slashing/keeper/grpc_query_test.go +++ b/x/slashing/keeper/grpc_query_test.go @@ -7,7 +7,6 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/query" "github.com/cosmos/cosmos-sdk/x/slashing/testslashing" - "github.com/cosmos/cosmos-sdk/x/slashing/types" slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types" ) @@ -15,7 +14,7 @@ func (s *KeeperTestSuite) TestGRPCQueryParams() { queryClient := s.queryClient require := s.Require() - paramsResp, err := queryClient.Params(gocontext.Background(), &types.QueryParamsRequest{}) + paramsResp, err := queryClient.Params(gocontext.Background(), &slashingtypes.QueryParamsRequest{}) require.NoError(err) require.Equal(testslashing.TestParams(), paramsResp.Params) @@ -25,7 +24,7 @@ func (s *KeeperTestSuite) TestGRPCSigningInfo() { queryClient, ctx, keeper := s.queryClient, s.ctx, s.slashingKeeper require := s.Require() - infoResp, err := queryClient.SigningInfo(gocontext.Background(), &types.QuerySigningInfoRequest{ConsAddress: ""}) + infoResp, err := queryClient.SigningInfo(gocontext.Background(), &slashingtypes.QuerySigningInfoRequest{ConsAddress: ""}) require.Error(err) require.Nil(infoResp) @@ -43,7 +42,7 @@ func (s *KeeperTestSuite) TestGRPCSigningInfo() { require.True(found) infoResp, err = queryClient.SigningInfo(gocontext.Background(), - &types.QuerySigningInfoRequest{ConsAddress: consAddr.String()}) + &slashingtypes.QuerySigningInfoRequest{ConsAddress: consAddr.String()}) require.NoError(err) require.Equal(info, infoResp.ValSigningInfo) } @@ -68,21 +67,21 @@ func (s *KeeperTestSuite) TestGRPCSigningInfos() { signingInfo.Address = string(consAddr2) keeper.SetValidatorSigningInfo(ctx, consAddr2, signingInfo) - var signingInfos []types.ValidatorSigningInfo + var signingInfos []slashingtypes.ValidatorSigningInfo - keeper.IterateValidatorSigningInfos(ctx, func(consAddr sdk.ConsAddress, info types.ValidatorSigningInfo) (stop bool) { + keeper.IterateValidatorSigningInfos(ctx, func(consAddr sdk.ConsAddress, info slashingtypes.ValidatorSigningInfo) (stop bool) { signingInfos = append(signingInfos, info) return false }) // verify all values are returned without pagination infoResp, err := queryClient.SigningInfos(gocontext.Background(), - &types.QuerySigningInfosRequest{Pagination: nil}) + &slashingtypes.QuerySigningInfosRequest{Pagination: nil}) require.NoError(err) require.Equal(signingInfos, infoResp.Info) infoResp, err = queryClient.SigningInfos(gocontext.Background(), - &types.QuerySigningInfosRequest{Pagination: &query.PageRequest{Limit: 1, CountTotal: true}}) + &slashingtypes.QuerySigningInfosRequest{Pagination: &query.PageRequest{Limit: 1, CountTotal: true}}) require.NoError(err) require.Len(infoResp.Info, 1) require.Equal(signingInfos[0], infoResp.Info[0]) diff --git a/x/slashing/keeper/msg_server_test.go b/x/slashing/keeper/msg_server_test.go index ad41a7cc7823..025504b922f8 100644 --- a/x/slashing/keeper/msg_server_test.go +++ b/x/slashing/keeper/msg_server_test.go @@ -3,9 +3,10 @@ package keeper_test import ( "time" + "github.com/golang/mock/gomock" + sdk "github.com/cosmos/cosmos-sdk/types" slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types" - "github.com/golang/mock/gomock" ) func (s *KeeperTestSuite) TestUpdateParams() { From e2d2608559688b08f056f354d38b2c75a7ab53a4 Mon Sep 17 00:00:00 2001 From: Cool Developer Date: Tue, 16 Aug 2022 17:19:29 -0400 Subject: [PATCH 4/4] add hooks test --- x/slashing/keeper/hooks_test.go | 43 ++++++++++++++++++++++++++++++++ x/slashing/keeper/params_test.go | 7 +++++- 2 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 x/slashing/keeper/hooks_test.go diff --git a/x/slashing/keeper/hooks_test.go b/x/slashing/keeper/hooks_test.go new file mode 100644 index 000000000000..d07b050632f4 --- /dev/null +++ b/x/slashing/keeper/hooks_test.go @@ -0,0 +1,43 @@ +package keeper_test + +import ( + "github.com/cosmos/cosmos-sdk/testutil/testdata" + sdk "github.com/cosmos/cosmos-sdk/types" + stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" +) + +func (s *KeeperTestSuite) TestAfterValidatorBonded() { + ctx, keeper := s.ctx, s.slashingKeeper + require := s.Require() + + valAddr := sdk.ValAddress(consAddr.Bytes()) + keeper.AfterValidatorBonded(ctx, consAddr, valAddr) + + _, ok := keeper.GetValidatorSigningInfo(ctx, consAddr) + require.True(ok) +} + +func (s *KeeperTestSuite) TestAfterValidatorCreatedOrRemoved() { + ctx, keeper := s.ctx, s.slashingKeeper + require := s.Require() + + _, pubKey, addr := testdata.KeyTestPubAddr() + valAddr := sdk.ValAddress(addr) + + validator, err := stakingtypes.NewValidator(sdk.ValAddress(addr), pubKey, stakingtypes.Description{}) + require.NoError(err) + + s.stakingKeeper.EXPECT().Validator(ctx, valAddr).Return(validator) + err = keeper.AfterValidatorCreated(ctx, valAddr) + require.NoError(err) + + ePubKey, err := keeper.GetPubkey(ctx, addr.Bytes()) + require.NoError(err) + require.Equal(ePubKey, pubKey) + + err = keeper.AfterValidatorRemoved(ctx, sdk.ConsAddress(addr)) + require.NoError(err) + + _, err = keeper.GetPubkey(ctx, addr.Bytes()) + require.Error(err) +} diff --git a/x/slashing/keeper/params_test.go b/x/slashing/keeper/params_test.go index 1f1d4a7dd7ba..bcf96ef136c0 100644 --- a/x/slashing/keeper/params_test.go +++ b/x/slashing/keeper/params_test.go @@ -116,7 +116,12 @@ func (s *KeeperTestSuite) TestParams() { } params := keeper.GetParams(ctx) - require.Equal(expected, params) + require.Equal(params, expected) + require.Equal(keeper.SignedBlocksWindow(ctx), expected.SignedBlocksWindow) + require.Equal(keeper.MinSignedPerWindow(ctx), expected.MinSignedPerWindow.MulInt64(expected.SignedBlocksWindow).RoundInt64()) + require.Equal(keeper.DowntimeJailDuration(ctx), expected.DowntimeJailDuration) + require.Equal(keeper.SlashFractionDoubleSign(ctx), expected.SlashFractionDoubleSign) + require.Equal(keeper.SlashFractionDowntime(ctx), expected.SlashFractionDowntime) }) } }