Skip to content

Commit

Permalink
feat(rollapp): obsolete DRS versions query (#1445)
Browse files Browse the repository at this point in the history
  • Loading branch information
keruch authored Nov 8, 2024
1 parent 6a36f7b commit f621fb1
Show file tree
Hide file tree
Showing 6 changed files with 617 additions and 64 deletions.
11 changes: 11 additions & 0 deletions proto/dymensionxyz/dymension/rollapp/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ service Query {
rpc RegisteredDenoms(QueryRegisteredDenomsRequest) returns (QueryRegisteredDenomsResponse) {
option (google.api.http).get = "/dymensionxyz/dymension/rollapp/registered_denoms";
}

// Queries a list of obsolete DRS versions.
rpc ObsoleteDRSVersions(QueryObsoleteDRSVersionsRequest) returns (QueryObsoleteDRSVersionsResponse) {
option (google.api.http).get = "/dymensionxyz/dymension/rollapp/obsolete_drs_versions";
}
}

// QueryParamsRequest is request type for the Query/Params RPC method.
Expand Down Expand Up @@ -136,3 +141,9 @@ message QueryRegisteredDenomsRequest {
message QueryRegisteredDenomsResponse {
repeated string denoms = 1;
}

message QueryObsoleteDRSVersionsRequest {}

message QueryObsoleteDRSVersionsResponse {
repeated uint32 drs_versions = 1;
}
35 changes: 35 additions & 0 deletions x/rollapp/client/cli/query_obsolete_drs_versions.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package cli

import (
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/spf13/cobra"

"github.com/dymensionxyz/dymension/v3/x/rollapp/types"
)

func CmdQueryObsoleteDRSVersions() *cobra.Command {
cmd := &cobra.Command{
Use: "obsolete-drs-versions",
Short: "shows the list of obsolete DRS versions",
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}
queryClient := types.NewQueryClient(clientCtx)

res, err := queryClient.ObsoleteDRSVersions(cmd.Context(), &types.QueryObsoleteDRSVersionsRequest{})
if err != nil {
return err
}

return clientCtx.PrintProto(res)
},
}

flags.AddQueryFlagsToCmd(cmd)

return cmd
}
25 changes: 25 additions & 0 deletions x/rollapp/keeper/grpc_query_obsolete_drs_versions.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package keeper

import (
"context"

sdk "github.com/cosmos/cosmos-sdk/types"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"

"github.com/dymensionxyz/dymension/v3/x/rollapp/types"
)

func (k Keeper) ObsoleteDRSVersions(goCtx context.Context, req *types.QueryObsoleteDRSVersionsRequest) (*types.QueryObsoleteDRSVersionsResponse, error) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, "invalid request")
}
ctx := sdk.UnwrapSDKContext(goCtx)

versions, err := k.GetAllVulnerableDRSVersions(ctx)
if err != nil {
return nil, status.Error(codes.Internal, err.Error())
}

return &types.QueryObsoleteDRSVersionsResponse{DrsVersions: versions}, nil
}
27 changes: 27 additions & 0 deletions x/rollapp/keeper/grpc_query_obsolete_drs_versions_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package keeper_test

import (
"testing"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/stretchr/testify/require"

testkeeper "github.com/dymensionxyz/dymension/v3/testutil/keeper"
"github.com/dymensionxyz/dymension/v3/x/rollapp/types"
)

func TestObsoleteDRSVersionsQuery(t *testing.T) {
keeper, ctx := testkeeper.RollappKeeper(t)
wctx := sdk.WrapSDKContext(ctx)

const obsoleteDRSVersion uint32 = 1234567890
err := keeper.SetVulnerableDRSVersion(ctx, obsoleteDRSVersion)
require.NoError(t, err)

response, err := keeper.ObsoleteDRSVersions(wctx, &types.QueryObsoleteDRSVersionsRequest{})
require.NoError(t, err)

expected, err := keeper.GetAllVulnerableDRSVersions(ctx)
require.NoError(t, err)
require.EqualValues(t, expected, response.DrsVersions)
}
Loading

0 comments on commit f621fb1

Please sign in to comment.