From 22b2926e70b373e1aafdca92a1c50439a240b36c Mon Sep 17 00:00:00 2001 From: ThanhNhann Date: Fri, 5 Jan 2024 17:11:17 +0700 Subject: [PATCH] update logic get data --- x/ccv/provider/keeper/grpc_query.go | 14 ++++++++------ x/ccv/provider/keeper/grpc_query_test.go | 9 +++++---- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/x/ccv/provider/keeper/grpc_query.go b/x/ccv/provider/keeper/grpc_query.go index 64f109b4a8..58f753ae17 100644 --- a/x/ccv/provider/keeper/grpc_query.go +++ b/x/ccv/provider/keeper/grpc_query.go @@ -196,14 +196,16 @@ func (k Keeper) QueryAllPairsValConAddrByConsumerChainID(goCtx context.Context, pairValConAddrs := []*types.PairValConAddrProviderAndConsumer{} ctx := sdk.UnwrapSDKContext(goCtx) - validatorConsumerAddrs := k.GetAllValidatorsByConsumerAddr(ctx, &req.ChainId) - for _, data := range validatorConsumerAddrs { - providerAddr := types.NewProviderConsAddress(data.ProviderAddr) - pubKey, _ := k.GetValidatorConsumerPubKey(ctx, req.ChainId, providerAddr) + validatorConsumerPubKeys := k.GetAllValidatorConsumerPubKeys(ctx, &req.ChainId) + for _, data := range validatorConsumerPubKeys { + consumerAddr, err := ccvtypes.TMCryptoPublicKeyToConsAddr(*data.ConsumerKey) + if err != nil { + return nil, err + } pairValConAddrs = append(pairValConAddrs, &types.PairValConAddrProviderAndConsumer{ ProviderAddress: string(data.ProviderAddr), - ConsumerAddress: string(data.ConsumerAddr), - ConsumerKey: &pubKey, + ConsumerAddress: string(consumerAddr), + ConsumerKey: data.ConsumerKey, }) } diff --git a/x/ccv/provider/keeper/grpc_query_test.go b/x/ccv/provider/keeper/grpc_query_test.go index 2e824a613e..3246e1fc35 100644 --- a/x/ccv/provider/keeper/grpc_query_test.go +++ b/x/ccv/provider/keeper/grpc_query_test.go @@ -8,19 +8,20 @@ import ( cryptotestutil "github.com/cosmos/interchain-security/v3/testutil/crypto" testkeeper "github.com/cosmos/interchain-security/v3/testutil/keeper" "github.com/cosmos/interchain-security/v3/x/ccv/provider/types" + ccvtypes "github.com/cosmos/interchain-security/v3/x/ccv/types" ) func TestQueryAllPairsValConAddrByConsumerChainID(t *testing.T) { chainID := consumer providerAddr := types.NewProviderConsAddress([]byte("providerAddr")) - consumerAddr := types.NewConsumerConsAddress([]byte("consumerAddr")) consumerKey := cryptotestutil.NewCryptoIdentityFromIntSeed(1).TMProtoCryptoPublicKey() + consumerAddr, err := ccvtypes.TMCryptoPublicKeyToConsAddr(consumerKey) + require.NoError(t, err) pk, ctx, ctrl, _ := testkeeper.GetProviderKeeperAndCtx(t, testkeeper.NewInMemKeeperParams(t)) defer ctrl.Finish() - pk.SetValidatorByConsumerAddr(ctx, chainID, consumerAddr, providerAddr) pk.SetValidatorConsumerPubKey(ctx, chainID, providerAddr, consumerKey) pk.SetKeyAssignmentReplacement(ctx, chainID, providerAddr, consumerKey, 100) @@ -30,7 +31,7 @@ func TestQueryAllPairsValConAddrByConsumerChainID(t *testing.T) { require.Equal(t, consumerPubKey, consumerKey) // Request is nil - _, err := pk.QueryAllPairsValConAddrByConsumerChainID(ctx, nil) + _, err = pk.QueryAllPairsValConAddrByConsumerChainID(ctx, nil) require.Error(t, err) // Request with chainId is empty @@ -48,7 +49,7 @@ func TestQueryAllPairsValConAddrByConsumerChainID(t *testing.T) { expectedResult := types.PairValConAddrProviderAndConsumer{ ProviderAddress: "providerAddr", - ConsumerAddress: "consumerAddr", + ConsumerAddress: string(consumerAddr), ConsumerKey: &consumerKey, } require.Equal(t, &consumerKey, response.PairValConAddr[0].ConsumerKey)