Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Query lockup params #3098

Merged
merged 5 commits into from
Oct 24, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh wow, thanks!

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
}
7 changes: 7 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,10 @@ func (suite *KeeperTestSuite) TestLockedDenom() {
testTotalLockedDuration("2h", 0)
testTotalLockedDuration("1h", 10)
}

func (suite *KeeperTestSuite) TestParams() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add test cases for setting params and then querying it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah sure

suite.SetupTest()
res, err := suite.querier.Params(sdk.WrapSDKContext(suite.Ctx), &types.QueryParamsRequest{})
suite.Require().NoError(err)
suite.Require().Equal([]string(nil), res.Params.ForceUnlockAllowedAddresses)
}
515 changes: 424 additions & 91 deletions x/lockup/types/query.pb.go

Large diffs are not rendered by default.

65 changes: 65 additions & 0 deletions x/lockup/types/query.pb.gw.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.