Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(monitoringc): normalize tests #968

Merged
merged 5 commits into from
Oct 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions x/monitoringc/client/cli/query_launch_id_from_channel_id_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,29 +25,29 @@ func (suite *QueryTestSuite) TestShowLaunchIDFromChannelID() {
fmt.Sprintf("--%s=json", tmcli.OutputFlag),
}
for _, tc := range []struct {
desc string
name string
idChannelID string

args []string
err error
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,
}
Expand Down Expand Up @@ -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)
Expand All @@ -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 {
Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions x/monitoringc/client/cli/query_monitoring_history_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
10 changes: 5 additions & 5 deletions x/monitoringc/client/cli/query_provider_client_id_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand All @@ -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 {
Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions x/monitoringc/client/cli/query_verified_client_ids_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
26 changes: 14 additions & 12 deletions x/monitoringc/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
}
20 changes: 10 additions & 10 deletions x/monitoringc/keeper/grpc_launch_id_from_channel_id_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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))
Expand All @@ -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 {
Expand All @@ -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))
Expand All @@ -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"))
})
Expand Down
12 changes: 6 additions & 6 deletions x/monitoringc/keeper/grpc_monitoring_history_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
17 changes: 10 additions & 7 deletions x/monitoringc/keeper/grpc_params_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
}
Loading