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): increase code coverage #730

Merged
merged 7 commits into from
Apr 21, 2022
Merged
Show file tree
Hide file tree
Changes from 6 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
2 changes: 1 addition & 1 deletion pkg/types/consensus_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func NewConsensusState(timestamp, nextValHash, rootHash string) ConsensusState {
return ConsensusState{
NextValidatorsHash: nextValHash,
Timestamp: timestamp,
Root: MerkelRool{
Root: MerkleRoot{
Hash: rootHash,
},
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/types/consensus_state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
func TestConsensusState_RootHash(t *testing.T) {
csf := types.ConsensusState{
NextValidatorsHash: "foo",
Root: types.MerkelRool{
Root: types.MerkleRoot{
Hash: "bar",
},
Timestamp: "foobar",
Expand Down
104 changes: 52 additions & 52 deletions pkg/types/ibc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions proto/types/ibc.proto
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import "gogoproto/gogo.proto";

option go_package = "github.com/tendermint/spn/pkg/types";

// MerkelRool represents a Merkel Root in ConsensusState
message MerkelRool {
// MerkleRoot represents a Merkle Root in ConsensusState
message MerkleRoot {
string hash = 1;
}

Expand All @@ -15,7 +15,7 @@ message MerkelRool {
message ConsensusState {
string nextValidatorsHash = 1;
string timestamp = 2;
MerkelRool root = 3 [(gogoproto.nullable) = false];
MerkleRoot root = 3 [(gogoproto.nullable) = false];
}


Expand Down
65 changes: 65 additions & 0 deletions x/monitoringc/keeper/grpc_verified_client_ids_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package keeper_test

import (
"testing"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/stretchr/testify/require"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"

testkeeper "github.com/tendermint/spn/testutil/keeper"
"github.com/tendermint/spn/testutil/nullify"
"github.com/tendermint/spn/x/monitoringc/types"
)

func TestVerifiedClientIds(t *testing.T) {
ctx, tk, _ := testkeeper.NewTestSetup(t)
wctx := sdk.WrapSDKContext(ctx)
items := createNVerifiedClientID(ctx, tk.MonitoringConsumerKeeper, 2)
for _, tc := range []struct {
desc string
request *types.QueryGetVerifiedClientIdsRequest
response *types.QueryGetVerifiedClientIdsResponse
err error
}{
{
desc: "first",
request: &types.QueryGetVerifiedClientIdsRequest{
LaunchID: items[0].LaunchID,
},
response: &types.QueryGetVerifiedClientIdsResponse{ClientIds: items[0].ClientIDs},
},
{
desc: "second",
request: &types.QueryGetVerifiedClientIdsRequest{
LaunchID: items[1].LaunchID,
},
response: &types.QueryGetVerifiedClientIdsResponse{ClientIds: items[1].ClientIDs},
},
{
desc: "key not found",
request: &types.QueryGetVerifiedClientIdsRequest{
LaunchID: 100000,
},
err: status.Error(codes.Internal, "launch id not found 100000"),
},
{
desc: "invalid request",
err: status.Error(codes.InvalidArgument, "invalid request"),
},
} {
t.Run(tc.desc, func(t *testing.T) {
response, err := tk.MonitoringConsumerKeeper.VerifiedClientIds(wctx, tc.request)
if tc.err != nil {
require.ErrorIs(t, err, tc.err)
} else {
require.NoError(t, err)
require.Equal(t,
nullify.Fill(tc.response),
nullify.Fill(response),
)
}
})
}
}
15 changes: 15 additions & 0 deletions x/monitoringc/keeper/handshake_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,4 +202,19 @@ func TestKeeper_RegisterProviderClientIDFromChannelID(t *testing.T) {
err := tk.MonitoringConsumerKeeper.RegisterProviderClientIDFromChannelID(ctx, "foo")
require.ErrorIs(t, err, types.ErrConnectionAlreadyEstablished)
})

t.Run("should fail if monitoring connection already enabled on chain", func(t *testing.T) {
ctx, tk, _ := testSetupWithFooClient(t)
tk.MonitoringConsumerKeeper.SetLaunchIDFromVerifiedClientID(ctx, types.LaunchIDFromVerifiedClientID{
LaunchID: 1,
ClientID: "foo",
})
chain := launchtypes.Chain{
LaunchID: 1,
MonitoringConnected: true,
}
tk.LaunchKeeper.SetChain(ctx, chain)
err := tk.MonitoringConsumerKeeper.RegisterProviderClientIDFromChannelID(ctx, "foo")
require.ErrorIs(t, err, launchtypes.ErrChainMonitoringConnected)
})
}
Loading