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

expose queries for minimums #281

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
20 changes: 20 additions & 0 deletions client/docs/static/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -51010,6 +51010,26 @@
},
"description": "QueryParamsResponse is the response type for the Query/Params RPC method."
},
"xion.v1.QueryPlatformMinimumResponse": {
"type": "object",
"properties": {
"minimums": {
"type": "array",
"items": {
"type": "object",
"properties": {
"denom": {
"type": "string"
},
"amount": {
"type": "string"
}
},
"description": "Coin defines a token with a denomination and an amount.\n\nNOTE: The amount field is an Int which implements the custom method\nsignatures required by gogoproto."
}
}
}
},
"xion.v1.QueryPlatformPercentageResponse": {
"type": "object",
"properties": {
Expand Down
20 changes: 20 additions & 0 deletions client/docs/static/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -48372,6 +48372,26 @@
},
"description": "QueryParamsResponse is the response type for the Query/Params RPC method."
},
"xion.v1.QueryPlatformMinimumResponse": {
"type": "object",
"properties": {
"minimums": {
"type": "array",
"items": {
"type": "object",
"properties": {
"denom": {
"type": "string"
},
"amount": {
"type": "string"
}
},
"description": "Coin defines a token with a denomination and an amount.\n\nNOTE: The amount field is an Int which implements the custom method\nsignatures required by gogoproto."
}
}
}
},
"xion.v1.QueryPlatformPercentageResponse": {
"type": "object",
"properties": {
Expand Down
18 changes: 16 additions & 2 deletions integration_tests/send_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@ func TestXionSendPlatformFee(t *testing.T) {
config := types.GetConfig()
config.SetBech32PrefixForAccount("xion", "xionpub")

// query to make sure minimums are empty

minimums, err := ExecQuery(t, ctx, xion.GetNode(), "xion", "platform-minimum")
require.NoError(t, err)
t.Log(minimums)
require.Equal(t, []interface{}{}, minimums["minimums"])

setPlatformMinimumsMsg := xiontypes.MsgSetPlatformMinimum{
Authority: authtypes.NewModuleAddress("gov").String(),
Minimums: types.Coins{types.Coin{Amount: math.NewInt(10), Denom: "uxion"}},
Expand All @@ -78,8 +85,8 @@ func TestXionSendPlatformFee(t *testing.T) {
Messages: []json.RawMessage{msg},
Metadata: "",
Deposit: "100uxion",
Title: "Set platform percentage to 5%",
Summary: "Ups the platform fee to 5% for the integration test",
Title: "Set platform minimum to 100uxion",
Summary: "Ups the platform minimum to 100uxion for the integration test",
}
paramChangeTx, err := xion.SubmitProposal(ctx, xionUser.KeyName(), prop)
require.NoError(t, err)
Expand Down Expand Up @@ -117,6 +124,13 @@ func TestXionSendPlatformFee(t *testing.T) {
return false
}, time.Second*11, time.Second, "failed to reach status PASSED after 11s")

// check that the value has been set

minimums, err = ExecQuery(t, ctx, xion.GetNode(), "xion", "platform-minimum")
require.NoError(t, err)
coins := minimums["minimums"].([]interface{})
require.Equal(t, 1, len(coins))

_, err = xion.GetNode().ExecTx(ctx,
xionUser.KeyName(),
"xion", "send", xionUser.KeyName(),
Expand Down
16 changes: 0 additions & 16 deletions integration_tests/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ import (
"github.com/go-webauthn/webauthn/webauthn"

sdk "github.com/cosmos/cosmos-sdk/types"
paramsutils "github.com/cosmos/cosmos-sdk/x/params/client/utils"
"github.com/docker/docker/client"
"github.com/icza/dyno"
"github.com/strangelove-ventures/interchaintest/v8"
Expand Down Expand Up @@ -210,21 +209,6 @@ func RawJSONMsgMigrateContract(sender string, codeID string) []byte {
return rawMsg
}

func ParamChangeProposal(t *testing.T, subspace, key, value, title, description, deposit string) paramsutils.ParamChangeProposalJSON {
changes := paramsutils.ParamChangeJSON{
Subspace: subspace,
Key: key,
Value: json.RawMessage(fmt.Sprintf(`"%s"`, value)),
}
proposal := paramsutils.ParamChangeProposalJSON{
Title: title,
Description: description,
Deposit: deposit,
Changes: []paramsutils.ParamChangeJSON{changes},
}
return proposal
}

func BuildXionChain(t *testing.T, gas string, modifyGenesis func(ibc.ChainConfig, []byte) ([]byte, error)) TestData {
ctx := context.Background()

Expand Down
14 changes: 14 additions & 0 deletions proto/xion/v1/query.proto
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
syntax = "proto3";
package xion.v1;

import "gogoproto/gogo.proto";
import "cosmos/base/v1beta1/coin.proto";


option go_package = "github.com/burnt-labs/xion/x/xion/types";

service Query {
rpc WebAuthNVerifyRegister(QueryWebAuthNVerifyRegisterRequest) returns (QueryWebAuthNVerifyRegisterResponse) {}
rpc WebAuthNVerifyAuthenticate(QueryWebAuthNVerifyAuthenticateRequest) returns (QueryWebAuthNVerifyAuthenticateResponse) {}
rpc PlatformPercentage(QueryPlatformPercentageRequest) returns (QueryPlatformPercentageResponse) {}
rpc PlatformMinimum(QueryPlatformMinimumRequest) returns (QueryPlatformMinimumResponse) {}
}

message QueryWebAuthNVerifyRegisterRequest {
Expand Down Expand Up @@ -34,4 +39,13 @@ message QueryPlatformPercentageRequest {}

message QueryPlatformPercentageResponse {
uint64 platform_percentage = 1;
}

message QueryPlatformMinimumRequest {}

message QueryPlatformMinimumResponse {
repeated cosmos.base.v1beta1.Coin minimums = 3 [
(gogoproto.nullable) = false,
(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins"
];
}
3 changes: 2 additions & 1 deletion x/xion/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ func GetQueryCmd() *cobra.Command {

cmd.AddCommand(CmdWebAuthNVerifyRegister())
cmd.AddCommand(CmdWebAuthNVerifyAuthenticate())
cmd.AddCommand(CmdPlatformFee())
cmd.AddCommand(CmdPlatformPercentage())
cmd.AddCommand(CmdPlatformMinimum())

// this line is used by starport scaffolding # 1

Expand Down
34 changes: 31 additions & 3 deletions x/xion/client/cli/query_platform_fee.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import (
"github.com/burnt-labs/xion/x/xion/types"
)

func CmdPlatformFee() *cobra.Command {
func CmdPlatformPercentage() *cobra.Command {
cmd := &cobra.Command{
Use: "platform-fee",
Short: "Get Platform Fee",
Use: "platform-percentage",
Short: "Get Platform Percentage",
RunE: func(cmd *cobra.Command, _ []string) error {
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
Expand All @@ -36,3 +36,31 @@ func CmdPlatformFee() *cobra.Command {

return cmd
}

func CmdPlatformMinimum() *cobra.Command {
cmd := &cobra.Command{
Use: "platform-minimum",
Short: "Get Platform Minimum",
RunE: func(cmd *cobra.Command, _ []string) error {
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}

queryClient := types.NewQueryClient(clientCtx)

params := &types.QueryPlatformMinimumRequest{}

res, err := queryClient.PlatformMinimum(cmd.Context(), params)
if err != nil {
return err
}

return clientCtx.PrintProto(res)
},
}

flags.AddQueryFlagsToCmd(cmd)

return cmd
}
20 changes: 20 additions & 0 deletions x/xion/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
"github.com/go-webauthn/webauthn/protocol"
"github.com/go-webauthn/webauthn/webauthn"

sdktypes "github.com/cosmos/cosmos-sdk/types"

"github.com/burnt-labs/xion/x/xion/types"
)

Expand Down Expand Up @@ -62,3 +64,21 @@ func (k Keeper) WebAuthNVerifyAuthenticate(_ context.Context, request *types.Que

return &types.QueryWebAuthNVerifyAuthenticateResponse{}, nil
}

// PlatformPercentage implements types.QueryServer.
func (k Keeper) PlatformPercentage(ctx context.Context, _ *types.QueryPlatformPercentageRequest) (*types.QueryPlatformPercentageResponse, error) {
sdkCtx := sdktypes.UnwrapSDKContext(ctx)
percentage := k.GetPlatformPercentage(sdkCtx).Uint64()
return &types.QueryPlatformPercentageResponse{PlatformPercentage: percentage}, nil
}

// PlatformMinimum implements types.QueryServer.
func (k Keeper) PlatformMinimum(ctx context.Context, _ *types.QueryPlatformMinimumRequest) (*types.QueryPlatformMinimumResponse, error) {
sdkCtx := sdktypes.UnwrapSDKContext(ctx)
coins, err := k.GetPlatformMinimums(sdkCtx)
if err != nil {
return nil, err
}

return &types.QueryPlatformMinimumResponse{Minimums: coins}, nil
}
8 changes: 0 additions & 8 deletions x/xion/keeper/keeper.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package keeper

import (
"context"
"encoding/json"

wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"
Expand Down Expand Up @@ -97,10 +96,3 @@ func (k Keeper) OverwritePlatformMinimum(ctx sdktypes.Context, coins sdktypes.Co
func (k Keeper) GetAuthority() string {
return k.authority
}

// PlatformPercentage implements types.QueryServer.
func (k Keeper) PlatformPercentage(ctx context.Context, _ *types.QueryPlatformPercentageRequest) (*types.QueryPlatformPercentageResponse, error) {
sdkCtx := sdktypes.UnwrapSDKContext(ctx)
percentage := k.GetPlatformPercentage(sdkCtx).Uint64()
return &types.QueryPlatformPercentageResponse{PlatformPercentage: percentage}, nil
}
Loading
Loading