Unverified Commit df9102ed authored by Hieu Vu's avatar Hieu Vu Committed by GitHub
Browse files

Query lockup params (#3098)

* change proto

* add grpc & cli query

* test

* set params in genesis

* add test case: setParams & query
parent 0aa0263c
Showing with 590 additions and 91 deletions
+590 -91
......@@ -7,6 +7,7 @@ import "google/api/annotations.proto";
import "google/protobuf/timestamp.proto";
import "google/protobuf/duration.proto";
import "osmosis/lockup/lock.proto";
import "osmosis/lockup/params.proto";
option go_package = "github.com/osmosis-labs/osmosis/v12/x/lockup/types";
......@@ -118,6 +119,10 @@ service Query {
option (google.api.http).get =
"/osmosis/lockup/v1beta1/account_locked_longer_duration_denom/{owner}";
}
// Params returns lockup params.
rpc Params(QueryParamsRequest) returns (QueryParamsResponse) {
option (google.api.http).get = "/osmosis/lockup/v1beta1/params";
}
}
message ModuleBalanceRequest {};
......@@ -287,3 +292,8 @@ message AccountLockedLongerDurationDenomRequest {
message AccountLockedLongerDurationDenomResponse {
repeated PeriodLock locks = 1 [ (gogoproto.nullable) = false ];
};
message QueryParamsRequest {}
message QueryParamsResponse {
Params params = 1 [ (gogoproto.nullable) = false ];
}
......@@ -735,6 +735,38 @@ func (s IntegrationTestSuite) TestCmdAccountLockedLongerDurationDenom() {
}
}
// TestGetCmdParams tests module params CLI query commands
func (s IntegrationTestSuite) TestGetCmdParams() {
val := s.network.Validators[0]
testCases := []struct {
name string
args []string
}{
{
"query module params",
[]string{
fmt.Sprintf("--%s=json", tmcli.OutputFlag),
},
},
}
for _, tc := range testCases {
tc := tc
s.Run(tc.name, func() {
cmd := cli.GetCmdParams()
clientCtx := val.ClientCtx
out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, tc.args)
s.Require().NoError(err)
var result types.QueryParamsResponse
s.Require().NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), &result))
})
}
}
func TestIntegrationTestSuite(t *testing.T) {
suite.Run(t, new(IntegrationTestSuite))
}
......@@ -48,6 +48,7 @@ func GetQueryCmd() *cobra.Command {
GetCmdOutputLocksJson(),
GetCmdSyntheticLockupsByLockupID(),
GetCmdAccountLockedDuration(),
GetCmdParams(),
)
return cmd
......@@ -799,3 +800,39 @@ $ %s query lockup output-all-locks <max lock ID>
return cmd
}
// GetCmdParams returns module params.
func GetCmdParams() *cobra.Command {
cmd := &cobra.Command{
Use: "params",
Short: "Query module params",
Long: strings.TrimSpace(
fmt.Sprintf(`Query module params.
Example:
$ %s query lockup params
`,
version.AppName,
),
),
Args: cobra.ExactArgs(0),
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.Params(cmd.Context(), &types.QueryParamsRequest{})
if err != nil {
return err
}
return clientCtx.PrintProto(res)
},
}
flags.AddQueryFlagsToCmd(cmd)
return cmd
}
......@@ -9,6 +9,7 @@ import (
// InitGenesis initializes the capability module's state from a provided genesis
// state.
func (k Keeper) InitGenesis(ctx sdk.Context, genState types.GenesisState) {
k.SetParams(ctx, types.DefaultParams())
k.SetLastLockID(ctx, genState.LastLockId)
if err := k.InitializeAllLocks(ctx, genState.Locks); err != nil {
return
......
......@@ -285,3 +285,9 @@ func (q Querier) LockedDenom(goCtx context.Context, req *types.LockedDenomReques
ctx := sdk.UnwrapSDKContext(goCtx)
return &types.LockedDenomResponse{Amount: q.Keeper.GetLockedDenom(ctx, req.Denom, req.Duration)}, nil
}
// Params returns module params
func (q Querier) Params(goCtx context.Context, req *types.QueryParamsRequest) (*types.QueryParamsResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)
return &types.QueryParamsResponse{Params: q.Keeper.GetParams(ctx)}, nil
}
......@@ -513,3 +513,18 @@ func (suite *KeeperTestSuite) TestLockedDenom() {
testTotalLockedDuration("2h", 0)
testTotalLockedDuration("1h", 10)
}
func (suite *KeeperTestSuite) TestParams() {
suite.SetupTest()
// Query default params
res, err := suite.querier.Params(sdk.WrapSDKContext(suite.Ctx), &types.QueryParamsRequest{})
suite.Require().NoError(err)
suite.Require().Equal([]string(nil), res.Params.ForceUnlockAllowedAddresses)
// Set new params & query
suite.App.LockupKeeper.SetParams(suite.Ctx, types.NewParams([]string{suite.TestAccs[0].String()}))
res, err = suite.querier.Params(sdk.WrapSDKContext(suite.Ctx), &types.QueryParamsRequest{})
suite.Require().NoError(err)
suite.Require().Equal([]string{suite.TestAccs[0].String()}, res.Params.ForceUnlockAllowedAddresses)
}
This diff is collapsed.
......@@ -951,6 +951,24 @@ func local_request_Query_AccountLockedLongerDurationDenom_0(ctx context.Context,
}
func request_Query_Params_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
var protoReq QueryParamsRequest
var metadata runtime.ServerMetadata
msg, err := client.Params(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
return msg, metadata, err
}
func local_request_Query_Params_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
var protoReq QueryParamsRequest
var metadata runtime.ServerMetadata
msg, err := server.Params(ctx, &protoReq)
return msg, metadata, err
}
// RegisterQueryHandlerServer registers the http handlers for service Query to "mux".
// UnaryRPC :call QueryServer directly.
// StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906.
......@@ -1325,6 +1343,29 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv
})
mux.Handle("GET", pattern_Query_Params_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
ctx, cancel := context.WithCancel(req.Context())
defer cancel()
var stream runtime.ServerTransportStream
ctx = grpc.NewContextWithServerTransportStream(ctx, &stream)
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req)
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
resp, md, err := local_request_Query_Params_0(rctx, inboundMarshaler, server, req, pathParams)
md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer())
ctx = runtime.NewServerMetadataContext(ctx, md)
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
forward_Query_Params_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
})
return nil
}
......@@ -1686,6 +1727,26 @@ func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, clie
})
mux.Handle("GET", pattern_Query_Params_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
ctx, cancel := context.WithCancel(req.Context())
defer cancel()
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
rctx, err := runtime.AnnotateContext(ctx, mux, req)
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
resp, md, err := request_Query_Params_0(rctx, inboundMarshaler, client, req, pathParams)
ctx = runtime.NewServerMetadataContext(ctx, md)
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
forward_Query_Params_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
})
return nil
}
......@@ -1721,6 +1782,8 @@ var (
pattern_Query_AccountLockedLongerDurationNotUnlockingOnly_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 1, 0, 4, 1, 5, 4}, []string{"osmosis", "lockup", "v1beta1", "account_locked_longer_duration_not_unlocking_only", "owner"}, "", runtime.AssumeColonVerbOpt(false)))
pattern_Query_AccountLockedLongerDurationDenom_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 1, 0, 4, 1, 5, 4}, []string{"osmosis", "lockup", "v1beta1", "account_locked_longer_duration_denom", "owner"}, "", runtime.AssumeColonVerbOpt(false)))
pattern_Query_Params_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"osmosis", "lockup", "v1beta1", "params"}, "", runtime.AssumeColonVerbOpt(false)))
)
var (
......@@ -1755,4 +1818,6 @@ var (
forward_Query_AccountLockedLongerDurationNotUnlockingOnly_0 = runtime.ForwardResponseMessage
forward_Query_AccountLockedLongerDurationDenom_0 = runtime.ForwardResponseMessage
forward_Query_Params_0 = runtime.ForwardResponseMessage
)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment