-
Notifications
You must be signed in to change notification settings - Fork 209
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into CNS-639-add-query-to-fetch-all-conflicts-tha…
…t-the-provider-is-reported
- Loading branch information
Showing
8 changed files
with
657 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package cli | ||
|
||
import ( | ||
"github.com/cosmos/cosmos-sdk/client" | ||
"github.com/cosmos/cosmos-sdk/client/flags" | ||
"github.com/lavanet/lava/x/conflict/types" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func CmdConsumerConflicts() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "consumer-conflicts <consumer>", | ||
Short: "Gets a consumer's active conflict list", | ||
Args: cobra.ExactArgs(1), | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
clientCtx := client.GetClientContextFromCmd(cmd) | ||
|
||
queryClient := types.NewQueryClient(clientCtx) | ||
|
||
params := &types.QueryConsumerConflictsRequest{ | ||
Consumer: args[0], | ||
} | ||
|
||
res, err := queryClient.ConsumerConflicts(cmd.Context(), params) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return clientCtx.PrintProto(res) | ||
}, | ||
} | ||
|
||
flags.AddQueryFlagsToCmd(cmd) | ||
|
||
return cmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package keeper | ||
|
||
import ( | ||
"context" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/lavanet/lava/x/conflict/types" | ||
"google.golang.org/grpc/codes" | ||
"google.golang.org/grpc/status" | ||
) | ||
|
||
func (k Keeper) ConsumerConflicts(c context.Context, req *types.QueryConsumerConflictsRequest) (*types.QueryConsumerConflictsResponse, error) { | ||
if req == nil { | ||
return nil, status.Error(codes.InvalidArgument, "invalid request") | ||
} | ||
|
||
var conflictIndices []string | ||
|
||
ctx := sdk.UnwrapSDKContext(c) | ||
conflicts := k.GetAllConflictVote(ctx) | ||
for _, conflict := range conflicts { | ||
if conflict.ClientAddress == req.Consumer { | ||
conflictIndices = append(conflictIndices, conflict.Index) | ||
} | ||
} | ||
|
||
return &types.QueryConsumerConflictsResponse{Conflicts: conflictIndices}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package keeper_test | ||
|
||
import ( | ||
"strconv" | ||
"testing" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
keepertest "github.com/lavanet/lava/testutil/keeper" | ||
"github.com/lavanet/lava/x/conflict/types" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
// Prevent strconv unused error | ||
var _ = strconv.IntSize | ||
|
||
func TestConsumerConflicts(t *testing.T) { | ||
keeper, ctx := keepertest.ConflictKeeper(t) | ||
wctx := sdk.WrapSDKContext(ctx) | ||
msgs := createNConflictVote(keeper, ctx, 10) | ||
for i, msg := range msgs { | ||
msg.ClientAddress = "client" + strconv.Itoa(i%2) | ||
keeper.SetConflictVote(ctx, msg) | ||
} | ||
|
||
for _, tc := range []struct { | ||
desc string | ||
client string | ||
expectedConflicts []string | ||
}{ | ||
{ | ||
desc: "client0 conflicts", | ||
client: "client0", | ||
expectedConflicts: []string{"0", "2", "4", "6", "8"}, | ||
}, | ||
{ | ||
desc: "client1 conflicts", | ||
client: "client1", | ||
expectedConflicts: []string{"1", "3", "5", "7", "9"}, | ||
}, | ||
{ | ||
desc: "invalid client", | ||
client: "dummy", | ||
expectedConflicts: []string{}, | ||
}, | ||
} { | ||
t.Run(tc.desc, func(t *testing.T) { | ||
res, err := keeper.ConsumerConflicts(wctx, &types.QueryConsumerConflictsRequest{Consumer: tc.client}) | ||
require.Nil(t, err) | ||
require.ElementsMatch(t, res.Conflicts, tc.expectedConflicts) | ||
}) | ||
} | ||
} |
Oops, something went wrong.