diff --git a/x/ccv/provider/keeper/grpc_query.go b/x/ccv/provider/keeper/grpc_query.go index e33b02b48d..4f2763e0b9 100644 --- a/x/ccv/provider/keeper/grpc_query.go +++ b/x/ccv/provider/keeper/grpc_query.go @@ -65,6 +65,11 @@ func (k Keeper) QueryConsumerChains(goCtx context.Context, req *types.QueryConsu // GetConsumerChain returns a Chain data structure with all the necessary fields func (k Keeper) GetConsumerChain(ctx sdk.Context, consumerId string) (types.Chain, error) { + chainID, err := k.GetConsumerChainId(ctx, consumerId) + if err != nil { + return types.Chain{}, fmt.Errorf("cannot find chainID for consumer (%s)", consumerId) + } + clientID, found := k.GetConsumerClientId(ctx, consumerId) if !found { return types.Chain{}, fmt.Errorf("cannot find clientID for consumer (%s)", consumerId) @@ -95,12 +100,12 @@ func (k Keeper) GetConsumerChain(ctx sdk.Context, consumerId string) (types.Chai strDenylist[i] = addr.String() } - allowInactiveVals := k.AllowsInactiveValidators(ctx, chainID) + allowInactiveVals := k.AllowsInactiveValidators(ctx, consumerId) - minStake, _ := k.GetMinStake(ctx, chainID) + minStake := k.GetMinStake(ctx, consumerId) return types.Chain{ - ChainId: consumerId, + ChainId: chainID, ClientId: clientID, Top_N: topN, MinPowerInTop_N: minPowerInTopN, diff --git a/x/ccv/provider/keeper/grpc_query_test.go b/x/ccv/provider/keeper/grpc_query_test.go index 7ab11ad325..a9670fafdd 100644 --- a/x/ccv/provider/keeper/grpc_query_test.go +++ b/x/ccv/provider/keeper/grpc_query_test.go @@ -379,6 +379,8 @@ func TestGetConsumerChain(t *testing.T) { pk, ctx, ctrl, mocks := testkeeper.GetProviderKeeperAndCtx(t, testkeeper.NewInMemKeeperParams(t)) defer ctrl.Finish() + consumerIDs := []string{"1", "23", "345", "6789"} + chainIDs := []string{"chain-1", "chain-2", "chain-3", "chain-4"} // mock the validator set @@ -433,23 +435,24 @@ func TestGetConsumerChain(t *testing.T) { } expectedGetAllOrder := []types.Chain{} - for i, chainID := range chainIDs { - clientID := fmt.Sprintf("client-%d", len(chainIDs)-i) + for i, consumerID := range consumerIDs { + pk.SetConsumerChainId(ctx, consumerID, chainIDs[i]) + clientID := fmt.Sprintf("client-%d", len(consumerID)-i) topN := topNs[i] - pk.SetConsumerClientId(ctx, chainID, clientID) - pk.SetConsumerPowerShapingParameters(ctx, chainID, types.PowerShapingParameters{ + pk.SetConsumerClientId(ctx, consumerID, clientID) + pk.SetConsumerPowerShapingParameters(ctx, consumerID, types.PowerShapingParameters{ Top_N: topN, ValidatorSetCap: validatorSetCaps[i], ValidatorsPowerCap: validatorPowerCaps[i], + AllowInactiveVals: allowInactiveVals[i], + MinStake: minStakes[i].Uint64(), }) - pk.SetMinimumPowerInTopN(ctx, chainID, expectedMinPowerInTopNs[i]) - pk.SetInactiveValidatorsAllowed(ctx, chainID, allowInactiveVals[i]) - pk.SetMinStake(ctx, chainID, minStakes[i].Uint64()) + pk.SetMinimumPowerInTopN(ctx, consumerID, expectedMinPowerInTopNs[i]) for _, addr := range allowlists[i] { - pk.SetAllowlist(ctx, chainID, addr) + pk.SetAllowlist(ctx, consumerID, addr) } for _, addr := range denylists[i] { - pk.SetDenylist(ctx, chainID, addr) + pk.SetDenylist(ctx, consumerID, addr) } strAllowlist := make([]string, len(allowlists[i])) for j, addr := range allowlists[i] { @@ -463,7 +466,7 @@ func TestGetConsumerChain(t *testing.T) { expectedGetAllOrder = append(expectedGetAllOrder, types.Chain{ - ChainId: chainID, + ChainId: chainIDs[i], ClientId: clientID, Top_N: topN, MinPowerInTop_N: expectedMinPowerInTopNs[i],