Skip to content

Commit

Permalink
Query lockup params (#3098)
Browse files Browse the repository at this point in the history
* change proto

* add grpc & cli query

* test

* set params in genesis

* add test case: setParams & query
  • Loading branch information
hieuvubk authored Oct 24, 2022
1 parent 0aa0263 commit df9102e
Show file tree
Hide file tree
Showing 8 changed files with 590 additions and 91 deletions.
10 changes: 10 additions & 0 deletions proto/osmosis/lockup/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -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 {};
Expand Down Expand Up @@ -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 ];
}
32 changes: 32 additions & 0 deletions x/lockup/client/cli/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
37 changes: 37 additions & 0 deletions x/lockup/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ func GetQueryCmd() *cobra.Command {
GetCmdOutputLocksJson(),
GetCmdSyntheticLockupsByLockupID(),
GetCmdAccountLockedDuration(),
GetCmdParams(),
)

return cmd
Expand Down Expand Up @@ -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
}
1 change: 1 addition & 0 deletions x/lockup/keeper/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions x/lockup/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
15 changes: 15 additions & 0 deletions x/lockup/keeper/grpc_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Loading

0 comments on commit df9102e

Please sign in to comment.