From 6ebc077acf3774a4789dbd30827054a98e960181 Mon Sep 17 00:00:00 2001 From: Daniel Date: Tue, 1 Nov 2022 13:52:33 +0000 Subject: [PATCH] Checkpoint unfinished queries --- x/ccv/provider/keeper/grpc_query_test.go | 41 +++++++++++++++--------- 1 file changed, 26 insertions(+), 15 deletions(-) diff --git a/x/ccv/provider/keeper/grpc_query_test.go b/x/ccv/provider/keeper/grpc_query_test.go index 2c04859cee..2e5ff4a184 100644 --- a/x/ccv/provider/keeper/grpc_query_test.go +++ b/x/ccv/provider/keeper/grpc_query_test.go @@ -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")