Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Checkpoint unfinished queries
Browse files Browse the repository at this point in the history
Daniel committed Nov 1, 2022
1 parent b6d2c8c commit 6ebc077
Showing 1 changed file with 26 additions and 15 deletions.
41 changes: 26 additions & 15 deletions x/ccv/provider/keeper/grpc_query_test.go
Original file line number Diff line number Diff line change
@@ -1,28 +1,41 @@
package keeper_test

import (
"strings"
"testing"

"github.com/golang/mock/gomock"
"github.com/stretchr/testify/require"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"

codectypes "github.com/cosmos/cosmos-sdk/codec/types"
cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
"github.com/cosmos/cosmos-sdk/testutil/testdata"
sdk "github.com/cosmos/cosmos-sdk/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
testkeeper "github.com/cosmos/interchain-security/testutil/keeper"
testutil "github.com/cosmos/interchain-security/testutil/sample"
keeper "github.com/cosmos/interchain-security/x/ccv/provider/keeper"
"github.com/cosmos/interchain-security/x/ccv/provider/types"
)


func TestGRPCQueryConsumerChainValidatorKeyMapping(t *testing.T) {

consumerTMProtoPublicKey := func() cryptotypes.PubKey {
_, cpk0 := testutil.GetTMCryptoPublicKeyFromSeed(0)
ret, err := cryptocodec.FromTmProtoPublicKey(cpk0)
require.NoError(t, err)
return ret
}

valAddress := func() sdk.ValAddress {
mockPV, _ := testutil.GetTMCryptoPublicKeyFromSeed(0)
tmPubKeyI, err := mockPV.GetPubKey()
require.NoError(t, err)
addr, err := sdk.ValAddressFromHex(tmPubKeyI.Address().String())
require.NoError(t, err)
return addr
}

consumerKey := consumerTMProtoPublicKey()
valAddr := valAddress()

testCases := []struct {
name string
// State-mutating setup specific to this test case
@@ -39,14 +52,14 @@ func TestGRPCQueryConsumerChainValidatorKeyMapping(t *testing.T) {

gomock.InOrder(
mocks.MockStakingKeeper.EXPECT().GetValidator(
ctx, valSdkAddr,
ctx, valAddr,
// Return a valid validator, found!
).Return(valSdkType, true).Times(1),
)
},
expError: false,
chainID: "chainid",
}
},
}

for _, tc := range testCases {
@@ -55,14 +68,12 @@ func TestGRPCQueryConsumerChainValidatorKeyMapping(t *testing.T) {

tc.setup(ctx, k, mocks)

msg, err := types.NewMsgDesignateConsensusKeyForConsumerChain(tc.chainID,
valSdkAddr, consumerTMProtoPublicKey(),
)

require.NoError(t, err)
req := types.QueryConsumerChainValidatorKeyMappingRequest{
ChainId: "chainid",
ProviderValidatorAddress: valAddr.String(),
}

// Try to handle the message
_, err = NewHandler(k)(ctx, msg)
res, err := k.QueryConsumerChainValidatorKeyMapping

if tc.expError {
require.Error(t, err, "invalid case did not return error")

0 comments on commit 6ebc077

Please sign in to comment.