-
Notifications
You must be signed in to change notification settings - Fork 341
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(rollapp): obsolete DRS versions query (#1445)
- Loading branch information
Showing
6 changed files
with
617 additions
and
64 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
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 | ||
} |
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,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 | ||
} |
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,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) | ||
} |
Oops, something went wrong.