forked from celestiaorg/celestia-app
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add payment module params (celestiaorg#893)
Adds `minSquareSize` and `maxSquareSize` as params to the payment module. Defines relevant stores and queries Relevant changes in `proto/payment/*` `x/payment/keeper*` `x/payment/types/*` - [x] closes celestiaorg#183 Note: The constants that currently define min/max square size have not been deprecated, will do so in another PR
- Loading branch information
1 parent
3294eee
commit 6b5b33f
Showing
23 changed files
with
1,417 additions
and
37 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
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 |
---|---|---|
@@ -1,7 +1,12 @@ | ||
syntax = "proto3"; | ||
package blob; | ||
|
||
import "gogoproto/gogo.proto"; | ||
import "blob/params.proto"; | ||
|
||
option go_package = "github.com/celestiaorg/celestia-app/x/blob/types"; | ||
|
||
// GenesisState defines the capability module's genesis state. | ||
message GenesisState {} | ||
message GenesisState { | ||
Params params = 1 [(gogoproto.nullable) = false]; | ||
} |
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,14 @@ | ||
syntax = "proto3"; | ||
package blob; | ||
|
||
import "gogoproto/gogo.proto"; | ||
|
||
option go_package = "github.com/celestiaorg/celestia-app/x/blob/types"; | ||
|
||
// Params defines the parameters for the module. | ||
message Params { | ||
option (gogoproto.goproto_stringer) = false; | ||
|
||
uint32 min_square_size = 1 [(gogoproto.moretags) = "yaml:\"min_square_size\""]; | ||
uint32 max_square_size = 2 [(gogoproto.moretags) = "yaml:\"max_square_size\""]; | ||
} |
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 |
---|---|---|
@@ -1,12 +1,25 @@ | ||
syntax = "proto3"; | ||
package blob; | ||
|
||
import "gogoproto/gogo.proto"; | ||
import "google/api/annotations.proto"; | ||
import "cosmos/base/query/v1beta1/pagination.proto"; | ||
import "blob/params.proto"; | ||
|
||
option go_package = "github.com/celestiaorg/celestia-app/x/blob/types"; | ||
|
||
// Query defines the gRPC querier service. | ||
// Query defines the gRPC query service. | ||
service Query { | ||
// Params queries the parameters of the module. | ||
rpc Params(QueryParamsRequest) returns (QueryParamsResponse) { | ||
option (google.api.http).get = "/blob/params"; | ||
} | ||
} | ||
|
||
// QueryParamsRequest is the request type for the Query/Params RPC method. | ||
message QueryParamsRequest {} | ||
|
||
// QueryParamsResponse is the response type for the Query/Params RPC method. | ||
message QueryParamsResponse { | ||
Params params = 1 [(gogoproto.nullable) = false]; | ||
} |
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,53 @@ | ||
package keeper | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/celestiaorg/celestia-app/testutil" | ||
"github.com/celestiaorg/celestia-app/x/blob/keeper" | ||
"github.com/celestiaorg/celestia-app/x/blob/types" | ||
"github.com/cosmos/cosmos-sdk/codec" | ||
codectypes "github.com/cosmos/cosmos-sdk/codec/types" | ||
"github.com/cosmos/cosmos-sdk/store" | ||
storetypes "github.com/cosmos/cosmos-sdk/store/types" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
typesparams "github.com/cosmos/cosmos-sdk/x/params/types" | ||
"github.com/stretchr/testify/require" | ||
"github.com/tendermint/tendermint/libs/log" | ||
tmproto "github.com/tendermint/tendermint/proto/tendermint/types" | ||
tmdb "github.com/tendermint/tm-db" | ||
) | ||
|
||
func BlobKeeper(t testing.TB) (*keeper.Keeper, sdk.Context) { | ||
storeKey := sdk.NewKVStoreKey(types.StoreKey) | ||
memStoreKey := storetypes.NewMemoryStoreKey(types.MemStoreKey) | ||
|
||
db := tmdb.NewMemDB() | ||
stateStore := store.NewCommitMultiStore(db) | ||
stateStore.MountStoreWithDB(storeKey, storetypes.StoreTypeIAVL, db) | ||
stateStore.MountStoreWithDB(memStoreKey, storetypes.StoreTypeMemory, nil) | ||
require.NoError(t, stateStore.LoadLatestVersion()) | ||
|
||
registry := codectypes.NewInterfaceRegistry() | ||
cdc := codec.NewProtoCodec(registry) | ||
|
||
paramsSubspace := typesparams.NewSubspace(cdc, | ||
testutil.MakeTestCodec(), | ||
storeKey, | ||
memStoreKey, | ||
"Blob", | ||
) | ||
k := keeper.NewKeeper( | ||
cdc, | ||
storeKey, | ||
memStoreKey, | ||
paramsSubspace, | ||
) | ||
|
||
ctx := sdk.NewContext(stateStore, tmproto.Header{}, false, log.NewNopLogger()) | ||
|
||
// Initialize params | ||
k.SetParams(ctx, types.DefaultParams()) | ||
|
||
return k, ctx | ||
} |
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,34 @@ | ||
package cli | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/celestiaorg/celestia-app/x/blob/types" | ||
"github.com/cosmos/cosmos-sdk/client" | ||
"github.com/cosmos/cosmos-sdk/client/flags" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func CmdQueryParams() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "params", | ||
Short: "shows the parameters of the module", | ||
Args: cobra.NoArgs, | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
clientCtx := client.GetClientContextFromCmd(cmd) | ||
|
||
queryClient := types.NewQueryClient(clientCtx) | ||
|
||
res, err := queryClient.Params(context.Background(), &types.QueryParamsRequest{}) | ||
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
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,22 @@ | ||
package blob_test | ||
|
||
import ( | ||
"testing" | ||
|
||
keepertest "github.com/celestiaorg/celestia-app/testutil/keeper" | ||
"github.com/celestiaorg/celestia-app/x/blob" | ||
"github.com/celestiaorg/celestia-app/x/blob/types" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestGenesis(t *testing.T) { | ||
genesisState := types.GenesisState{ | ||
Params: types.DefaultParams(), | ||
} | ||
|
||
k, ctx := keepertest.BlobKeeper(t) | ||
blob.InitGenesis(ctx, *k, genesisState) | ||
got := blob.ExportGenesis(ctx, *k) | ||
require.NotNil(t, got) | ||
require.Equal(t, types.DefaultParams(), got.Params) | ||
} |
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,7 @@ | ||
package keeper | ||
|
||
import ( | ||
"github.com/celestiaorg/celestia-app/x/blob/types" | ||
) | ||
|
||
var _ types.QueryServer = Keeper{} |
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,19 @@ | ||
package keeper | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/celestiaorg/celestia-app/x/blob/types" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"google.golang.org/grpc/codes" | ||
"google.golang.org/grpc/status" | ||
) | ||
|
||
func (k Keeper) Params(c context.Context, req *types.QueryParamsRequest) (*types.QueryParamsResponse, error) { | ||
if req == nil { | ||
return nil, status.Error(codes.InvalidArgument, "invalid request") | ||
} | ||
ctx := sdk.UnwrapSDKContext(c) | ||
|
||
return &types.QueryParamsResponse{Params: k.GetParams(ctx)}, 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,21 @@ | ||
package keeper_test | ||
|
||
import ( | ||
"testing" | ||
|
||
testkeeper "github.com/celestiaorg/celestia-app/testutil/keeper" | ||
"github.com/celestiaorg/celestia-app/x/blob/types" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestParamsQuery(t *testing.T) { | ||
keeper, ctx := testkeeper.BlobKeeper(t) | ||
wctx := sdk.WrapSDKContext(ctx) | ||
params := types.DefaultParams() | ||
keeper.SetParams(ctx, params) | ||
|
||
response, err := keeper.Params(wctx, &types.QueryParamsRequest{}) | ||
require.NoError(t, err) | ||
require.Equal(t, &types.QueryParamsResponse{Params: params}, response) | ||
} |
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,31 @@ | ||
package keeper | ||
|
||
import ( | ||
"github.com/celestiaorg/celestia-app/x/blob/types" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
) | ||
|
||
// GetParams gets all parameters as types.Params | ||
func (k Keeper) GetParams(ctx sdk.Context) types.Params { | ||
return types.NewParams( | ||
k.MinSquareSize(ctx), | ||
k.MaxSquareSize(ctx), | ||
) | ||
} | ||
|
||
// SetParams sets the params | ||
func (k Keeper) SetParams(ctx sdk.Context, params types.Params) { | ||
k.paramStore.SetParamSet(ctx, ¶ms) | ||
} | ||
|
||
// MinSquareSize returns the MinSquareSize param | ||
func (k Keeper) MinSquareSize(ctx sdk.Context) (res uint32) { | ||
k.paramStore.Get(ctx, types.KeyMinSquareSize, &res) | ||
return | ||
} | ||
|
||
// MaxSquareSize returns the MaxSquareSize param | ||
func (k Keeper) MaxSquareSize(ctx sdk.Context) (res uint32) { | ||
k.paramStore.Get(ctx, types.KeyMaxSquareSize, &res) | ||
return | ||
} |
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,20 @@ | ||
package keeper_test | ||
|
||
import ( | ||
"testing" | ||
|
||
testkeeper "github.com/celestiaorg/celestia-app/testutil/keeper" | ||
"github.com/celestiaorg/celestia-app/x/blob/types" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestGetParams(t *testing.T) { | ||
k, ctx := testkeeper.BlobKeeper(t) | ||
params := types.DefaultParams() | ||
|
||
k.SetParams(ctx, params) | ||
|
||
require.EqualValues(t, params, k.GetParams(ctx)) | ||
require.EqualValues(t, params.MinSquareSize, k.MinSquareSize(ctx)) | ||
require.EqualValues(t, params.MaxSquareSize, k.MaxSquareSize(ctx)) | ||
} |
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
Oops, something went wrong.