diff --git a/x/monitoringc/client/cli/query_launch_id_from_channel_id_test.go b/x/monitoringc/client/cli/query_launch_id_from_channel_id_test.go index 73d102ebb..6f7efd3ec 100644 --- a/x/monitoringc/client/cli/query_launch_id_from_channel_id_test.go +++ b/x/monitoringc/client/cli/query_launch_id_from_channel_id_test.go @@ -25,7 +25,7 @@ func (suite *QueryTestSuite) TestShowLaunchIDFromChannelID() { fmt.Sprintf("--%s=json", tmcli.OutputFlag), } for _, tc := range []struct { - desc string + name string idChannelID string args []string @@ -33,21 +33,21 @@ func (suite *QueryTestSuite) TestShowLaunchIDFromChannelID() { obj types.LaunchIDFromChannelID }{ { - desc: "found", + name: "should allow valid query", idChannelID: objs[0].ChannelID, args: common, obj: objs[0], }, { - desc: "not found", + name: "should fail if not found", idChannelID: strconv.Itoa(100000), args: common, err: status.Error(codes.NotFound, "not found"), }, } { - suite.T().Run(tc.desc, func(t *testing.T) { + suite.T().Run(tc.name, func(t *testing.T) { args := []string{ tc.idChannelID, } @@ -90,7 +90,7 @@ func (suite *QueryTestSuite) TestListLaunchIDFromChannelID() { } return args } - suite.T().Run("by offset", func(t *testing.T) { + suite.T().Run("should paginate by offset", func(t *testing.T) { step := 2 for i := 0; i < len(objs); i += step { args := request(nil, uint64(i), uint64(step), false) @@ -105,7 +105,7 @@ func (suite *QueryTestSuite) TestListLaunchIDFromChannelID() { ) } }) - suite.T().Run("by key", func(t *testing.T) { + suite.T().Run("should paginate by key", func(t *testing.T) { step := 2 var next []byte for i := 0; i < len(objs); i += step { @@ -122,7 +122,7 @@ func (suite *QueryTestSuite) TestListLaunchIDFromChannelID() { next = resp.Pagination.NextKey } }) - suite.T().Run("total", func(t *testing.T) { + suite.T().Run("should paginate all", func(t *testing.T) { args := request(nil, 0, uint64(len(objs)), true) out, err := clitestutil.ExecTestCLICmd(ctx, cli.CmdListLaunchIDFromChannelID(), args) require.NoError(t, err) diff --git a/x/monitoringc/client/cli/query_monitoring_history_test.go b/x/monitoringc/client/cli/query_monitoring_history_test.go index 1e0ae5668..c0043f7de 100644 --- a/x/monitoringc/client/cli/query_monitoring_history_test.go +++ b/x/monitoringc/client/cli/query_monitoring_history_test.go @@ -32,14 +32,14 @@ func (suite *QueryTestSuite) TestShowMonitoringHistory() { obj types.MonitoringHistory }{ { - desc: "found", + desc: "should allow valid query", idLaunchID: objs[0].LaunchID, args: common, obj: objs[0], }, { - desc: "not found", + desc: "should fail if not found", idLaunchID: 100000, args: common, diff --git a/x/monitoringc/client/cli/query_provider_client_id_test.go b/x/monitoringc/client/cli/query_provider_client_id_test.go index e31845152..4d1e588fa 100644 --- a/x/monitoringc/client/cli/query_provider_client_id_test.go +++ b/x/monitoringc/client/cli/query_provider_client_id_test.go @@ -33,14 +33,14 @@ func (suite *QueryTestSuite) TestShowProviderClientID() { obj types.ProviderClientID }{ { - desc: "found", + desc: "should allow valid query", idLaunchID: objs[0].LaunchID, args: common, obj: objs[0], }, { - desc: "not found", + desc: "should fail if not found", idLaunchID: 100000, args: common, @@ -90,7 +90,7 @@ func (suite *QueryTestSuite) TestListProviderClientID() { } return args } - suite.T().Run("by offset", func(t *testing.T) { + suite.T().Run("should paginate by offset", func(t *testing.T) { step := 2 for i := 0; i < len(objs); i += step { args := request(nil, uint64(i), uint64(step), false) @@ -105,7 +105,7 @@ func (suite *QueryTestSuite) TestListProviderClientID() { ) } }) - suite.T().Run("by key", func(t *testing.T) { + suite.T().Run("should paginate by key", func(t *testing.T) { step := 2 var next []byte for i := 0; i < len(objs); i += step { @@ -122,7 +122,7 @@ func (suite *QueryTestSuite) TestListProviderClientID() { next = resp.Pagination.NextKey } }) - suite.T().Run("total", func(t *testing.T) { + suite.T().Run("should paginate all", func(t *testing.T) { args := request(nil, 0, uint64(len(objs)), true) out, err := clitestutil.ExecTestCLICmd(ctx, cli.CmdListProviderClientID(), args) require.NoError(t, err) diff --git a/x/monitoringc/client/cli/query_verified_client_ids_test.go b/x/monitoringc/client/cli/query_verified_client_ids_test.go index fd776259a..cab7f50de 100644 --- a/x/monitoringc/client/cli/query_verified_client_ids_test.go +++ b/x/monitoringc/client/cli/query_verified_client_ids_test.go @@ -32,14 +32,14 @@ func (suite *QueryTestSuite) TestShowVerifiedClientIds() { obj types.VerifiedClientID }{ { - desc: "found", + desc: "should allow valid query", idLaunchID: objs[0].LaunchID, args: common, obj: objs[0], }, { - desc: "not found", + desc: "should fail if not found", idLaunchID: 100000, args: common, diff --git a/x/monitoringc/genesis_test.go b/x/monitoringc/genesis_test.go index 5904982cd..2489f2097 100644 --- a/x/monitoringc/genesis_test.go +++ b/x/monitoringc/genesis_test.go @@ -61,19 +61,21 @@ func TestGenesis(t *testing.T) { } ctx, tk, _ := testkeeper.NewTestSetup(t) - monitoringc.InitGenesis(ctx, *tk.MonitoringConsumerKeeper, genesisState) - got := monitoringc.ExportGenesis(ctx, *tk.MonitoringConsumerKeeper) - require.NotNil(t, got) + t.Run("should allow import and export of genesis", func(t *testing.T) { + monitoringc.InitGenesis(ctx, *tk.MonitoringConsumerKeeper, genesisState) + got := monitoringc.ExportGenesis(ctx, *tk.MonitoringConsumerKeeper) + require.NotNil(t, got) - nullify.Fill(&genesisState) - nullify.Fill(got) + nullify.Fill(&genesisState) + nullify.Fill(got) - require.Equal(t, genesisState.PortId, got.PortId) + require.Equal(t, genesisState.PortId, got.PortId) - require.ElementsMatch(t, genesisState.VerifiedClientIDs, got.VerifiedClientIDs) - require.ElementsMatch(t, genesisState.ProviderClientIDs, got.ProviderClientIDs) - require.ElementsMatch(t, genesisState.LaunchIDsFromVerifiedClientID, got.LaunchIDsFromVerifiedClientID) - require.ElementsMatch(t, genesisState.LaunchIDsFromChannelID, got.LaunchIDsFromChannelID) - require.ElementsMatch(t, genesisState.MonitoringHistories, got.MonitoringHistories) - // this line is used by starport scaffolding # genesis/test/assert + require.ElementsMatch(t, genesisState.VerifiedClientIDs, got.VerifiedClientIDs) + require.ElementsMatch(t, genesisState.ProviderClientIDs, got.ProviderClientIDs) + require.ElementsMatch(t, genesisState.LaunchIDsFromVerifiedClientID, got.LaunchIDsFromVerifiedClientID) + require.ElementsMatch(t, genesisState.LaunchIDsFromChannelID, got.LaunchIDsFromChannelID) + require.ElementsMatch(t, genesisState.MonitoringHistories, got.MonitoringHistories) + // this line is used by starport scaffolding # genesis/test/assert + }) } diff --git a/x/monitoringc/keeper/grpc_launch_id_from_channel_id_test.go b/x/monitoringc/keeper/grpc_launch_id_from_channel_id_test.go index bee3ad4da..d82a40f1f 100644 --- a/x/monitoringc/keeper/grpc_launch_id_from_channel_id_test.go +++ b/x/monitoringc/keeper/grpc_launch_id_from_channel_id_test.go @@ -20,38 +20,38 @@ func TestLaunchIDFromChannelIDQuerySingle(t *testing.T) { wctx := sdk.WrapSDKContext(ctx) items := createNLaunchIDFromChannelID(ctx, tk.MonitoringConsumerKeeper, 2) for _, tc := range []struct { - desc string + name string request *types.QueryGetLaunchIDFromChannelIDRequest response *types.QueryGetLaunchIDFromChannelIDResponse err error }{ { - desc: "first", + name: "should allow valid first query", request: &types.QueryGetLaunchIDFromChannelIDRequest{ ChannelID: items[0].ChannelID, }, response: &types.QueryGetLaunchIDFromChannelIDResponse{LaunchIDFromChannelID: items[0]}, }, { - desc: "second", + name: "should allow valid second query", request: &types.QueryGetLaunchIDFromChannelIDRequest{ ChannelID: items[1].ChannelID, }, response: &types.QueryGetLaunchIDFromChannelIDResponse{LaunchIDFromChannelID: items[1]}, }, { - desc: "key not found", + name: "should return key not found", request: &types.QueryGetLaunchIDFromChannelIDRequest{ ChannelID: strconv.Itoa(100000), }, err: status.Error(codes.NotFound, "not found"), }, { - desc: "invalid request", + name: "should return invalid request", err: status.Error(codes.InvalidArgument, "invalid request"), }, } { - t.Run(tc.desc, func(t *testing.T) { + t.Run(tc.name, func(t *testing.T) { response, err := tk.MonitoringConsumerKeeper.LaunchIDFromChannelID(wctx, tc.request) if tc.err != nil { require.ErrorIs(t, err, tc.err) @@ -81,7 +81,7 @@ func TestLaunchIDFromChannelIDQueryPaginated(t *testing.T) { }, } } - t.Run("by offset", func(t *testing.T) { + t.Run("should paginate by offset", func(t *testing.T) { step := 2 for i := 0; i < len(items); i += step { resp, err := tk.MonitoringConsumerKeeper.LaunchIDFromChannelIDAll(wctx, request(nil, uint64(i), uint64(step), false)) @@ -93,7 +93,7 @@ func TestLaunchIDFromChannelIDQueryPaginated(t *testing.T) { ) } }) - t.Run("by key", func(t *testing.T) { + t.Run("should paginate by key", func(t *testing.T) { step := 2 var next []byte for i := 0; i < len(items); i += step { @@ -107,7 +107,7 @@ func TestLaunchIDFromChannelIDQueryPaginated(t *testing.T) { next = resp.Pagination.NextKey } }) - t.Run("total", func(t *testing.T) { + t.Run("should paginate all", func(t *testing.T) { resp, err := tk.MonitoringConsumerKeeper.LaunchIDFromChannelIDAll(wctx, request(nil, 0, 0, true)) require.NoError(t, err) require.Equal(t, len(items), int(resp.Pagination.Total)) @@ -116,7 +116,7 @@ func TestLaunchIDFromChannelIDQueryPaginated(t *testing.T) { nullify.Fill(resp.LaunchIDFromChannelID), ) }) - t.Run("InvalidRequest", func(t *testing.T) { + t.Run("should return InvalidRequest", func(t *testing.T) { _, err := tk.MonitoringConsumerKeeper.LaunchIDFromChannelIDAll(wctx, nil) require.ErrorIs(t, err, status.Error(codes.InvalidArgument, "invalid request")) }) diff --git a/x/monitoringc/keeper/grpc_monitoring_history_test.go b/x/monitoringc/keeper/grpc_monitoring_history_test.go index a11ebfbca..b2aa80481 100644 --- a/x/monitoringc/keeper/grpc_monitoring_history_test.go +++ b/x/monitoringc/keeper/grpc_monitoring_history_test.go @@ -18,38 +18,38 @@ func TestMonitoringHistoryQuerySingle(t *testing.T) { wctx := sdk.WrapSDKContext(ctx) items := createNMonitoringHistory(ctx, tk.MonitoringConsumerKeeper, 2) for _, tc := range []struct { - desc string + name string request *types.QueryGetMonitoringHistoryRequest response *types.QueryGetMonitoringHistoryResponse err error }{ { - desc: "first", + name: "should allow valid first query", request: &types.QueryGetMonitoringHistoryRequest{ LaunchID: items[0].LaunchID, }, response: &types.QueryGetMonitoringHistoryResponse{MonitoringHistory: items[0]}, }, { - desc: "second", + name: "should allow valid second query", request: &types.QueryGetMonitoringHistoryRequest{ LaunchID: items[1].LaunchID, }, response: &types.QueryGetMonitoringHistoryResponse{MonitoringHistory: items[1]}, }, { - desc: "key not found", + name: "should return key not found", request: &types.QueryGetMonitoringHistoryRequest{ LaunchID: 100000, }, err: status.Error(codes.NotFound, "not found"), }, { - desc: "invalid request", + name: "should return invalid request", err: status.Error(codes.InvalidArgument, "invalid request"), }, } { - t.Run(tc.desc, func(t *testing.T) { + t.Run(tc.name, func(t *testing.T) { response, err := tk.MonitoringConsumerKeeper.MonitoringHistory(wctx, tc.request) if tc.err != nil { require.ErrorIs(t, err, tc.err) diff --git a/x/monitoringc/keeper/grpc_params_test.go b/x/monitoringc/keeper/grpc_params_test.go index 11a04f190..b4a5a4c21 100644 --- a/x/monitoringc/keeper/grpc_params_test.go +++ b/x/monitoringc/keeper/grpc_params_test.go @@ -13,13 +13,16 @@ import ( func TestParamsQuery(t *testing.T) { ctx, tk, _ := testkeeper.NewTestSetup(t) wctx := sdk.WrapSDKContext(ctx) - params := types.DefaultParams() - tk.MonitoringConsumerKeeper.SetParams(ctx, params) - response, err := tk.MonitoringConsumerKeeper.Params(wctx, &types.QueryParamsRequest{}) - require.NoError(t, err) - require.Equal(t, &types.QueryParamsResponse{Params: params}, response) + t.Run("should allow params query", func(t *testing.T) { + params := types.DefaultParams() + tk.MonitoringConsumerKeeper.SetParams(ctx, params) - _, err = tk.MonitoringConsumerKeeper.Params(wctx, nil) - require.Error(t, err) + response, err := tk.MonitoringConsumerKeeper.Params(wctx, &types.QueryParamsRequest{}) + require.NoError(t, err) + require.Equal(t, &types.QueryParamsResponse{Params: params}, response) + + _, err = tk.MonitoringConsumerKeeper.Params(wctx, nil) + require.Error(t, err) + }) } diff --git a/x/monitoringc/keeper/grpc_provider_client_id_test.go b/x/monitoringc/keeper/grpc_provider_client_id_test.go index 6812a671a..a9671355f 100644 --- a/x/monitoringc/keeper/grpc_provider_client_id_test.go +++ b/x/monitoringc/keeper/grpc_provider_client_id_test.go @@ -19,38 +19,38 @@ func TestProviderClientIDQuerySingle(t *testing.T) { wctx := sdk.WrapSDKContext(ctx) items := createNProviderClientID(ctx, tk.MonitoringConsumerKeeper, 2) for _, tc := range []struct { - desc string + name string request *types.QueryGetProviderClientIDRequest response *types.QueryGetProviderClientIDResponse err error }{ { - desc: "first", + name: "should allow valid first query", request: &types.QueryGetProviderClientIDRequest{ LaunchID: items[0].LaunchID, }, response: &types.QueryGetProviderClientIDResponse{ProviderClientID: items[0]}, }, { - desc: "second", + name: "should allow valid second query", request: &types.QueryGetProviderClientIDRequest{ LaunchID: items[1].LaunchID, }, response: &types.QueryGetProviderClientIDResponse{ProviderClientID: items[1]}, }, { - desc: "key not found", + name: "should return key not found", request: &types.QueryGetProviderClientIDRequest{ LaunchID: 100000, }, err: status.Error(codes.NotFound, "not found"), }, { - desc: "invalid request", + name: "should return invalid request", err: status.Error(codes.InvalidArgument, "invalid request"), }, } { - t.Run(tc.desc, func(t *testing.T) { + t.Run(tc.name, func(t *testing.T) { response, err := tk.MonitoringConsumerKeeper.ProviderClientID(wctx, tc.request) if tc.err != nil { require.ErrorIs(t, err, tc.err) @@ -80,7 +80,7 @@ func TestProviderClientIDQueryPaginated(t *testing.T) { }, } } - t.Run("by offset", func(t *testing.T) { + t.Run("should paginate by offset", func(t *testing.T) { step := 2 for i := 0; i < len(items); i += step { resp, err := tk.MonitoringConsumerKeeper.ProviderClientIDAll(wctx, request(nil, uint64(i), uint64(step), false)) @@ -92,7 +92,7 @@ func TestProviderClientIDQueryPaginated(t *testing.T) { ) } }) - t.Run("by key", func(t *testing.T) { + t.Run("should paginate by key", func(t *testing.T) { step := 2 var next []byte for i := 0; i < len(items); i += step { @@ -106,7 +106,7 @@ func TestProviderClientIDQueryPaginated(t *testing.T) { next = resp.Pagination.NextKey } }) - t.Run("total", func(t *testing.T) { + t.Run("should paginate all", func(t *testing.T) { resp, err := tk.MonitoringConsumerKeeper.ProviderClientIDAll(wctx, request(nil, 0, 0, true)) require.NoError(t, err) require.Equal(t, len(items), int(resp.Pagination.Total)) @@ -115,7 +115,7 @@ func TestProviderClientIDQueryPaginated(t *testing.T) { nullify.Fill(resp.ProviderClientID), ) }) - t.Run("InvalidRequest", func(t *testing.T) { + t.Run("should return InvalidRequest", func(t *testing.T) { _, err := tk.MonitoringConsumerKeeper.ProviderClientIDAll(wctx, nil) require.ErrorIs(t, err, status.Error(codes.InvalidArgument, "invalid request")) }) diff --git a/x/monitoringc/keeper/grpc_verified_client_ids_test.go b/x/monitoringc/keeper/grpc_verified_client_ids_test.go index 0191e7616..bbf265dc7 100644 --- a/x/monitoringc/keeper/grpc_verified_client_ids_test.go +++ b/x/monitoringc/keeper/grpc_verified_client_ids_test.go @@ -18,38 +18,38 @@ func TestVerifiedClientIds(t *testing.T) { wctx := sdk.WrapSDKContext(ctx) items := createNVerifiedClientID(ctx, tk.MonitoringConsumerKeeper, 2) for _, tc := range []struct { - desc string + name string request *types.QueryGetVerifiedClientIdsRequest response *types.QueryGetVerifiedClientIdsResponse err error }{ { - desc: "first", + name: "should allow valid first query", request: &types.QueryGetVerifiedClientIdsRequest{ LaunchID: items[0].LaunchID, }, response: &types.QueryGetVerifiedClientIdsResponse{ClientIds: items[0].ClientIDs}, }, { - desc: "second", + name: "should allow valid second query", request: &types.QueryGetVerifiedClientIdsRequest{ LaunchID: items[1].LaunchID, }, response: &types.QueryGetVerifiedClientIdsResponse{ClientIds: items[1].ClientIDs}, }, { - desc: "key not found", + name: "should return key not found", request: &types.QueryGetVerifiedClientIdsRequest{ LaunchID: 100000, }, err: status.Error(codes.NotFound, "launch id not found 100000"), }, { - desc: "invalid request", + name: "should return invalid request", err: status.Error(codes.InvalidArgument, "invalid request"), }, } { - t.Run(tc.desc, func(t *testing.T) { + t.Run(tc.name, func(t *testing.T) { response, err := tk.MonitoringConsumerKeeper.VerifiedClientIds(wctx, tc.request) if tc.err != nil { require.ErrorIs(t, err, tc.err) diff --git a/x/monitoringc/keeper/invariants_test.go b/x/monitoringc/keeper/invariants_test.go index 7f97b95d2..c067e8811 100644 --- a/x/monitoringc/keeper/invariants_test.go +++ b/x/monitoringc/keeper/invariants_test.go @@ -14,7 +14,7 @@ import ( func TestMissingVerifiedClientIDInvariant(t *testing.T) { ctx, tk, _ := testkeeper.NewTestSetup(t) - t.Run("valid case", func(t *testing.T) { + t.Run("should allow valid case", func(t *testing.T) { n := sample.Uint64(r) launchID := sample.Uint64(r) for i := uint64(0); i < n; i++ { @@ -29,7 +29,7 @@ func TestMissingVerifiedClientIDInvariant(t *testing.T) { require.False(t, broken, msg) }) - t.Run("invalid case", func(t *testing.T) { + t.Run("should prevent invalid case", func(t *testing.T) { n := sample.Uint64(r) launchID := sample.Uint64(r) for i := uint64(0); i < n; i++ { diff --git a/x/monitoringc/keeper/launch_id_from_channel_id_test.go b/x/monitoringc/keeper/launch_id_from_channel_id_test.go index 78901e2f3..3c7bc0be6 100644 --- a/x/monitoringc/keeper/launch_id_from_channel_id_test.go +++ b/x/monitoringc/keeper/launch_id_from_channel_id_test.go @@ -24,24 +24,30 @@ func createNLaunchIDFromChannelID(ctx sdk.Context, keeper *keeper.Keeper, n int) func TestLaunchIDFromChannelIDGet(t *testing.T) { ctx, tk, _ := testkeeper.NewTestSetup(t) - items := createNLaunchIDFromChannelID(ctx, tk.MonitoringConsumerKeeper, 10) - for _, item := range items { - rst, found := tk.MonitoringConsumerKeeper.GetLaunchIDFromChannelID(ctx, - item.ChannelID, - ) - require.True(t, found) - require.Equal(t, - nullify.Fill(&item), - nullify.Fill(&rst), - ) - } + + t.Run("should allow get", func(t *testing.T) { + items := createNLaunchIDFromChannelID(ctx, tk.MonitoringConsumerKeeper, 10) + for _, item := range items { + rst, found := tk.MonitoringConsumerKeeper.GetLaunchIDFromChannelID(ctx, + item.ChannelID, + ) + require.True(t, found) + require.Equal(t, + nullify.Fill(&item), + nullify.Fill(&rst), + ) + } + }) } func TestLaunchIDFromChannelIDGetAll(t *testing.T) { ctx, tk, _ := testkeeper.NewTestSetup(t) - items := createNLaunchIDFromChannelID(ctx, tk.MonitoringConsumerKeeper, 10) - require.ElementsMatch(t, - nullify.Fill(items), - nullify.Fill(tk.MonitoringConsumerKeeper.GetAllLaunchIDFromChannelID(ctx)), - ) + + t.Run("should allow get all", func(t *testing.T) { + items := createNLaunchIDFromChannelID(ctx, tk.MonitoringConsumerKeeper, 10) + require.ElementsMatch(t, + nullify.Fill(items), + nullify.Fill(tk.MonitoringConsumerKeeper.GetAllLaunchIDFromChannelID(ctx)), + ) + }) } diff --git a/x/monitoringc/keeper/launch_id_from_verified_client_id_test.go b/x/monitoringc/keeper/launch_id_from_verified_client_id_test.go index ba6b46354..6877d9f1b 100644 --- a/x/monitoringc/keeper/launch_id_from_verified_client_id_test.go +++ b/x/monitoringc/keeper/launch_id_from_verified_client_id_test.go @@ -24,24 +24,30 @@ func createNLaunchIDFromVerifiedClientID(keeper *keeper.Keeper, ctx sdk.Context, func TestLaunchIDFromVerifiedClientIDGet(t *testing.T) { ctx, tk, _ := testkeeper.NewTestSetup(t) - items := createNLaunchIDFromVerifiedClientID(tk.MonitoringConsumerKeeper, ctx, 10) - for _, item := range items { - rst, found := tk.MonitoringConsumerKeeper.GetLaunchIDFromVerifiedClientID(ctx, - item.ClientID, - ) - require.True(t, found) - require.Equal(t, - nullify.Fill(&item), - nullify.Fill(&rst), - ) - } + + t.Run("should allow get", func(t *testing.T) { + items := createNLaunchIDFromVerifiedClientID(tk.MonitoringConsumerKeeper, ctx, 10) + for _, item := range items { + rst, found := tk.MonitoringConsumerKeeper.GetLaunchIDFromVerifiedClientID(ctx, + item.ClientID, + ) + require.True(t, found) + require.Equal(t, + nullify.Fill(&item), + nullify.Fill(&rst), + ) + } + }) } func TestLaunchIDFromVerifiedClientIDGetAll(t *testing.T) { ctx, tk, _ := testkeeper.NewTestSetup(t) - items := createNLaunchIDFromVerifiedClientID(tk.MonitoringConsumerKeeper, ctx, 10) - require.ElementsMatch(t, - nullify.Fill(items), - nullify.Fill(tk.MonitoringConsumerKeeper.GetAllLaunchIDFromVerifiedClientID(ctx)), - ) + + t.Run("should allow get all", func(t *testing.T) { + items := createNLaunchIDFromVerifiedClientID(tk.MonitoringConsumerKeeper, ctx, 10) + require.ElementsMatch(t, + nullify.Fill(items), + nullify.Fill(tk.MonitoringConsumerKeeper.GetAllLaunchIDFromVerifiedClientID(ctx)), + ) + }) } diff --git a/x/monitoringc/keeper/monitoring_history_test.go b/x/monitoringc/keeper/monitoring_history_test.go index c71342e64..fc4f8e7e2 100644 --- a/x/monitoringc/keeper/monitoring_history_test.go +++ b/x/monitoringc/keeper/monitoring_history_test.go @@ -23,24 +23,30 @@ func createNMonitoringHistory(ctx sdk.Context, keeper *keeper.Keeper, n int) []t func TestMonitoringHistoryGet(t *testing.T) { ctx, tk, _ := testkeeper.NewTestSetup(t) - items := createNMonitoringHistory(ctx, tk.MonitoringConsumerKeeper, 10) - for _, item := range items { - rst, found := tk.MonitoringConsumerKeeper.GetMonitoringHistory(ctx, - item.LaunchID, - ) - require.True(t, found) - require.Equal(t, - nullify.Fill(&item), - nullify.Fill(&rst), - ) - } + + t.Run("should allow get", func(t *testing.T) { + items := createNMonitoringHistory(ctx, tk.MonitoringConsumerKeeper, 10) + for _, item := range items { + rst, found := tk.MonitoringConsumerKeeper.GetMonitoringHistory(ctx, + item.LaunchID, + ) + require.True(t, found) + require.Equal(t, + nullify.Fill(&item), + nullify.Fill(&rst), + ) + } + }) } func TestMonitoringHistoryGetAll(t *testing.T) { ctx, tk, _ := testkeeper.NewTestSetup(t) - items := createNMonitoringHistory(ctx, tk.MonitoringConsumerKeeper, 10) - require.ElementsMatch(t, - nullify.Fill(items), - nullify.Fill(tk.MonitoringConsumerKeeper.GetAllMonitoringHistory(ctx)), - ) + + t.Run("should allow get all", func(t *testing.T) { + items := createNMonitoringHistory(ctx, tk.MonitoringConsumerKeeper, 10) + require.ElementsMatch(t, + nullify.Fill(items), + nullify.Fill(tk.MonitoringConsumerKeeper.GetAllMonitoringHistory(ctx)), + ) + }) } diff --git a/x/monitoringc/keeper/monitoring_packet_test.go b/x/monitoringc/keeper/monitoring_packet_test.go index 6db94acfc..b065a653d 100644 --- a/x/monitoringc/keeper/monitoring_packet_test.go +++ b/x/monitoringc/keeper/monitoring_packet_test.go @@ -3,11 +3,12 @@ package keeper_test import ( "testing" + tc "github.com/tendermint/spn/testutil/constructor" + channeltypes "github.com/cosmos/ibc-go/v5/modules/core/04-channel/types" "github.com/stretchr/testify/require" spntypes "github.com/tendermint/spn/pkg/types" - tc "github.com/tendermint/spn/testutil/constructor" testkeeper "github.com/tendermint/spn/testutil/keeper" "github.com/tendermint/spn/testutil/sample" "github.com/tendermint/spn/x/monitoringc/types" @@ -38,16 +39,18 @@ func Test_OnRecvMonitoringPacket(t *testing.T) { LaunchID: chain.LaunchID, }) - tk.RewardKeeper.SetRewardPool(ctx, rewardtypes.RewardPool{ - LaunchID: chain.LaunchID, - Provider: sample.Address(r), - InitialCoins: coins, - RemainingCoins: coins, - LastRewardHeight: 1, - Closed: false, + t.Run("should allow set reward pool", func(t *testing.T) { + tk.RewardKeeper.SetRewardPool(ctx, rewardtypes.RewardPool{ + LaunchID: chain.LaunchID, + Provider: sample.Address(r), + InitialCoins: coins, + RemainingCoins: coins, + LastRewardHeight: 1, + Closed: false, + }) + err := tk.BankKeeper.MintCoins(ctx, rewardtypes.ModuleName, coins) + require.NoError(t, err) }) - err := tk.BankKeeper.MintCoins(ctx, rewardtypes.ModuleName, coins) - require.NoError(t, err) // set validator profiles tk.ProfileKeeper.SetValidator(ctx, profiletypes.Validator{ @@ -74,7 +77,21 @@ func Test_OnRecvMonitoringPacket(t *testing.T) { valid bool }{ { - name: "invalid data", + name: "should successfully distribute rewards", + packet: channeltypes.Packet{ + DestinationChannel: validChannel, + }, + data: spntypes.MonitoringPacket{ + BlockHeight: 10, + SignatureCounts: tc.SignatureCounts(10, + tc.SignatureCount(t, valOpAddrFoo, "0.5"), + tc.SignatureCount(t, valOpAddrBar, "0.5"), + ), + }, + valid: true, + }, + { + name: "should prevent invalid data", packet: channeltypes.Packet{}, data: spntypes.MonitoringPacket{ BlockHeight: 0, @@ -85,7 +102,7 @@ func Test_OnRecvMonitoringPacket(t *testing.T) { valid: false, }, { - name: "no launch ID associated to channel ID", + name: "should prevent no launch ID associated to channel ID", packet: channeltypes.Packet{ DestinationChannel: "invalid", }, @@ -110,20 +127,6 @@ func Test_OnRecvMonitoringPacket(t *testing.T) { }, valid: false, }, - { - name: "should successfully distribute rewards", - packet: channeltypes.Packet{ - DestinationChannel: validChannel, - }, - data: spntypes.MonitoringPacket{ - BlockHeight: 10, - SignatureCounts: tc.SignatureCounts(10, - tc.SignatureCount(t, valOpAddrFoo, "0.5"), - tc.SignatureCount(t, valOpAddrBar, "0.5"), - ), - }, - valid: true, - }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { @@ -139,21 +142,27 @@ func Test_OnRecvMonitoringPacket(t *testing.T) { func Test_OnAcknowledgementMonitoringPacket(t *testing.T) { ctx, tk, _ := testkeeper.NewTestSetup(t) - err := tk.MonitoringConsumerKeeper.OnAcknowledgementMonitoringPacket( - ctx, - channeltypes.Packet{}, - spntypes.MonitoringPacket{}, - channeltypes.Acknowledgement{}, - ) - require.EqualError(t, err, "not implemented") + + t.Run("should return not implemented", func(t *testing.T) { + err := tk.MonitoringConsumerKeeper.OnAcknowledgementMonitoringPacket( + ctx, + channeltypes.Packet{}, + spntypes.MonitoringPacket{}, + channeltypes.Acknowledgement{}, + ) + require.EqualError(t, err, "not implemented") + }) } func Test_OnTimeoutMonitoringPacket(t *testing.T) { ctx, tk, _ := testkeeper.NewTestSetup(t) - err := tk.MonitoringConsumerKeeper.OnTimeoutMonitoringPacket( - ctx, - channeltypes.Packet{}, - spntypes.MonitoringPacket{}, - ) - require.EqualError(t, err, "not implemented") + + t.Run("should return not implemented", func(t *testing.T) { + err := tk.MonitoringConsumerKeeper.OnTimeoutMonitoringPacket( + ctx, + channeltypes.Packet{}, + spntypes.MonitoringPacket{}, + ) + require.EqualError(t, err, "not implemented") + }) } diff --git a/x/monitoringc/keeper/params_test.go b/x/monitoringc/keeper/params_test.go index 92e6b9c65..ff4397e51 100644 --- a/x/monitoringc/keeper/params_test.go +++ b/x/monitoringc/keeper/params_test.go @@ -12,11 +12,13 @@ import ( func TestGetParams(t *testing.T) { ctx, tk, _ := testkeeper.NewTestSetup(t) - params := types.DefaultParams() - tk.MonitoringConsumerKeeper.SetParams(ctx, params) - require.EqualValues(t, params, tk.MonitoringConsumerKeeper.GetParams(ctx)) + t.Run("should allow get", func(t *testing.T) { + params := types.DefaultParams() + tk.MonitoringConsumerKeeper.SetParams(ctx, params) + require.EqualValues(t, params, tk.MonitoringConsumerKeeper.GetParams(ctx)) - params = types.NewParams() - tk.MonitoringConsumerKeeper.SetParams(ctx, params) - require.EqualValues(t, params, tk.MonitoringConsumerKeeper.GetParams(ctx)) + params = types.NewParams() + tk.MonitoringConsumerKeeper.SetParams(ctx, params) + require.EqualValues(t, params, tk.MonitoringConsumerKeeper.GetParams(ctx)) + }) } diff --git a/x/monitoringc/keeper/provider_client_id_test.go b/x/monitoringc/keeper/provider_client_id_test.go index c0f50d39c..2bc2c0b00 100644 --- a/x/monitoringc/keeper/provider_client_id_test.go +++ b/x/monitoringc/keeper/provider_client_id_test.go @@ -23,24 +23,30 @@ func createNProviderClientID(ctx sdk.Context, keeper *keeper.Keeper, n int) []ty func TestProviderClientIDGet(t *testing.T) { ctx, tk, _ := testkeeper.NewTestSetup(t) - items := createNProviderClientID(ctx, tk.MonitoringConsumerKeeper, 10) - for _, item := range items { - rst, found := tk.MonitoringConsumerKeeper.GetProviderClientID(ctx, - item.LaunchID, - ) - require.True(t, found) - require.Equal(t, - nullify.Fill(&item), - nullify.Fill(&rst), - ) - } + + t.Run("should allow get", func(t *testing.T) { + items := createNProviderClientID(ctx, tk.MonitoringConsumerKeeper, 10) + for _, item := range items { + rst, found := tk.MonitoringConsumerKeeper.GetProviderClientID(ctx, + item.LaunchID, + ) + require.True(t, found) + require.Equal(t, + nullify.Fill(&item), + nullify.Fill(&rst), + ) + } + }) } func TestProviderClientIDGetAll(t *testing.T) { ctx, tk, _ := testkeeper.NewTestSetup(t) - items := createNProviderClientID(ctx, tk.MonitoringConsumerKeeper, 10) - require.ElementsMatch(t, - nullify.Fill(items), - nullify.Fill(tk.MonitoringConsumerKeeper.GetAllProviderClientID(ctx)), - ) + + t.Run("should allow get all", func(t *testing.T) { + items := createNProviderClientID(ctx, tk.MonitoringConsumerKeeper, 10) + require.ElementsMatch(t, + nullify.Fill(items), + nullify.Fill(tk.MonitoringConsumerKeeper.GetAllProviderClientID(ctx)), + ) + }) } diff --git a/x/monitoringc/keeper/verified_client_id_test.go b/x/monitoringc/keeper/verified_client_id_test.go index a43efc075..5faa65d46 100644 --- a/x/monitoringc/keeper/verified_client_id_test.go +++ b/x/monitoringc/keeper/verified_client_id_test.go @@ -25,20 +25,23 @@ func createNVerifiedClientID(ctx sdk.Context, keeper *keeper.Keeper, n int) []ty func TestVerifiedClientIDGet(t *testing.T) { ctx, tk, _ := testkeeper.NewTestSetup(t) - items := createNVerifiedClientID(ctx, tk.MonitoringConsumerKeeper, 10) - for _, item := range items { - rst, found := tk.MonitoringConsumerKeeper.GetVerifiedClientID(ctx, item.LaunchID) - require.True(t, found) - require.Equal(t, - nullify.Fill(&item), - nullify.Fill(&rst), - ) - } + + t.Run("should allow get", func(t *testing.T) { + items := createNVerifiedClientID(ctx, tk.MonitoringConsumerKeeper, 10) + for _, item := range items { + rst, found := tk.MonitoringConsumerKeeper.GetVerifiedClientID(ctx, item.LaunchID) + require.True(t, found) + require.Equal(t, + nullify.Fill(&item), + nullify.Fill(&rst), + ) + } + }) } func TestVerifiedClientIDClear(t *testing.T) { ctx, tk, _ := testkeeper.NewTestSetup(t) - t.Run("successfully clear entries", func(t *testing.T) { + t.Run("should successfully clear entries", func(t *testing.T) { items := createNVerifiedClientID(ctx, tk.MonitoringConsumerKeeper, 1) launchID := items[0].LaunchID clientID := items[0].ClientIDs[0] @@ -65,16 +68,19 @@ func TestVerifiedClientIDClear(t *testing.T) { func TestVerifiedClientIDGetAll(t *testing.T) { ctx, tk, _ := testkeeper.NewTestSetup(t) - items := createNVerifiedClientID(ctx, tk.MonitoringConsumerKeeper, 10) - require.ElementsMatch(t, - nullify.Fill(items), - nullify.Fill(tk.MonitoringConsumerKeeper.GetAllVerifiedClientID(ctx)), - ) + + t.Run("should allow get all", func(t *testing.T) { + items := createNVerifiedClientID(ctx, tk.MonitoringConsumerKeeper, 10) + require.ElementsMatch(t, + nullify.Fill(items), + nullify.Fill(tk.MonitoringConsumerKeeper.GetAllVerifiedClientID(ctx)), + ) + }) } func TestAddVerifiedClientID(t *testing.T) { ctx, tk, _ := testkeeper.NewTestSetup(t) - t.Run("update a verified client id", func(t *testing.T) { + t.Run("should update a verified client id", func(t *testing.T) { var ( launchID = uint64(1) newClientID = "2" @@ -91,7 +97,7 @@ func TestAddVerifiedClientID(t *testing.T) { require.Equal(t, verifiedClientID, got) }) - t.Run("update a duplicated verified client id", func(t *testing.T) { + t.Run("should update a duplicated verified client id", func(t *testing.T) { var ( launchID = uint64(2) newClientID = "2" @@ -107,7 +113,7 @@ func TestAddVerifiedClientID(t *testing.T) { require.Equal(t, verifiedClientID, got) }) - t.Run("update a non exiting verified client id", func(t *testing.T) { + t.Run("should update a non exiting verified client id", func(t *testing.T) { verifiedClientID := types.VerifiedClientID{ LaunchID: 3, ClientIDs: []string{"1"}, diff --git a/x/monitoringc/types/genesis_test.go b/x/monitoringc/types/genesis_test.go index 2599979f9..bef9ffd59 100644 --- a/x/monitoringc/types/genesis_test.go +++ b/x/monitoringc/types/genesis_test.go @@ -10,17 +10,17 @@ import ( func TestGenesisState_Validate(t *testing.T) { for _, tc := range []struct { - desc string + name string genState *types.GenesisState valid bool }{ { - desc: "default is valid", + name: "should allow valid default genesis", genState: types.DefaultGenesis(), valid: true, }, { - desc: "valid genesis state", + name: "should allow valid genesis state", genState: &types.GenesisState{ PortId: types.PortID, VerifiedClientIDs: []types.VerifiedClientID{ @@ -52,14 +52,14 @@ func TestGenesisState_Validate(t *testing.T) { valid: true, }, { - desc: "invalid portID", + name: "should prevent invalid portID", genState: &types.GenesisState{ PortId: "", }, valid: false, }, { - desc: "duplicated verifiedClientID", + name: "should prevent duplicated verifiedClientID", genState: &types.GenesisState{ PortId: types.PortID, VerifiedClientIDs: []types.VerifiedClientID{ @@ -76,7 +76,7 @@ func TestGenesisState_Validate(t *testing.T) { valid: false, }, { - desc: "duplicated clientID", + name: "should prevent duplicated clientID", genState: &types.GenesisState{ PortId: types.PortID, VerifiedClientIDs: []types.VerifiedClientID{ @@ -89,7 +89,7 @@ func TestGenesisState_Validate(t *testing.T) { valid: false, }, { - desc: "duplicated providerClientID", + name: "should prevent duplicated providerClientID", genState: &types.GenesisState{ PortId: types.PortID, VerifiedClientIDs: []types.VerifiedClientID{ @@ -112,7 +112,7 @@ func TestGenesisState_Validate(t *testing.T) { valid: false, }, { - desc: "duplicated launchIDFromVerifiedClientID", + name: "should prevent duplicated launchIDFromVerifiedClientID", genState: &types.GenesisState{ PortId: types.PortID, VerifiedClientIDs: []types.VerifiedClientID{ @@ -135,7 +135,7 @@ func TestGenesisState_Validate(t *testing.T) { valid: false, }, { - desc: "provider client id without valid client id", + name: "should prevent provider client id without valid client id", genState: &types.GenesisState{ PortId: types.PortID, VerifiedClientIDs: []types.VerifiedClientID{ @@ -155,7 +155,7 @@ func TestGenesisState_Validate(t *testing.T) { valid: false, }, { - desc: "launch id from verified client id without valid client id", + name: "should prevent launch id from verified client id without valid client id", genState: &types.GenesisState{ PortId: types.PortID, VerifiedClientIDs: []types.VerifiedClientID{ @@ -175,7 +175,7 @@ func TestGenesisState_Validate(t *testing.T) { valid: false, }, { - desc: "duplicated launchIDFromChannelID", + name: "should prevent duplicated launchIDFromChannelID", genState: &types.GenesisState{ PortId: types.PortID, LaunchIDsFromChannelID: []types.LaunchIDFromChannelID{ @@ -190,7 +190,7 @@ func TestGenesisState_Validate(t *testing.T) { valid: false, }, { - desc: "duplicated monitoringHistory", + name: "should prevent duplicated monitoringHistory", genState: &types.GenesisState{ PortId: types.PortID, MonitoringHistories: []types.MonitoringHistory{ @@ -206,7 +206,7 @@ func TestGenesisState_Validate(t *testing.T) { }, // this line is used by starport scaffolding # types/genesis/testcase } { - t.Run(tc.desc, func(t *testing.T) { + t.Run(tc.name, func(t *testing.T) { err := tc.genState.Validate() if tc.valid { require.NoError(t, err) diff --git a/x/monitoringc/types/msg_create_client_test.go b/x/monitoringc/types/msg_create_client_test.go index d59c4fcc7..55cbbb90b 100644 --- a/x/monitoringc/types/msg_create_client_test.go +++ b/x/monitoringc/types/msg_create_client_test.go @@ -18,7 +18,7 @@ func TestMsgCreateClient_ValidateBasic(t *testing.T) { err error }{ { - name: "valid message", + name: "should validate valid message", msg: types.MsgCreateClient{ Creator: sample.Address(r), LaunchID: 0, @@ -29,7 +29,7 @@ func TestMsgCreateClient_ValidateBasic(t *testing.T) { }, }, { - name: "invalid address", + name: "should prevent invalid address", msg: types.MsgCreateClient{ Creator: "invalid_address", LaunchID: 0, @@ -41,7 +41,7 @@ func TestMsgCreateClient_ValidateBasic(t *testing.T) { err: sdkerrortypes.ErrInvalidAddress, }, { - name: "invalid consensus state", + name: "should prevent invalid consensus state", msg: types.MsgCreateClient{ Creator: sample.Address(r), LaunchID: 0, @@ -57,7 +57,7 @@ func TestMsgCreateClient_ValidateBasic(t *testing.T) { err: types.ErrInvalidConsensusState, }, { - name: "invalid validator set", + name: "should prevent invalid validator set", msg: types.MsgCreateClient{ Creator: sample.Address(r), LaunchID: 0, @@ -75,7 +75,7 @@ func TestMsgCreateClient_ValidateBasic(t *testing.T) { err: types.ErrInvalidValidatorSet, }, { - name: "validator set not matching consensus state", + name: "should prevent validator set not matching consensus state", msg: types.MsgCreateClient{ Creator: sample.Address(r), LaunchID: 0,