Skip to content

Commit

Permalink
update logic get data
Browse files Browse the repository at this point in the history
  • Loading branch information
ThanhNhann committed Jan 5, 2024
1 parent 77d3805 commit 22b2926
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
14 changes: 8 additions & 6 deletions x/ccv/provider/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})
}

Expand Down
9 changes: 5 additions & 4 deletions x/ccv/provider/keeper/grpc_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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
Expand All @@ -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)
Expand Down

0 comments on commit 22b2926

Please sign in to comment.