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

fix: fix the params query for oracle and crosschain module #99

Merged
merged 2 commits into from
Feb 8, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
59 changes: 59 additions & 0 deletions x/oracle/client/cli/query.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package cli

import (
"strings"

"github.com/spf13/cobra"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/x/oracle/types"
)

// GetQueryCmd returns the transaction commands for this module
func GetQueryCmd() *cobra.Command {
cmd := &cobra.Command{
Use: types.ModuleName,
Short: "Querying commands for the oracle module",
DisableFlagParsing: true,
SuggestionsMinimumDistance: 2,
RunE: client.ValidateCmd,
}

cmd.AddCommand(
QueryParamsCmd(),
)

return cmd
}

// QueryParamsCmd returns the command handler for evidence parameter querying.
func QueryParamsCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "params",
Short: "Query the current oracle parameters",
Args: cobra.NoArgs,
Long: strings.TrimSpace(`Query the current oracle parameters:

$ <appd> query oracle params
`),
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.Params)
},
}

flags.AddQueryFlagsToCmd(cmd)

return cmd
}
14 changes: 14 additions & 0 deletions x/oracle/keeper/grpc_query_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package keeper_test

import (
gocontext "context"

"github.com/cosmos/cosmos-sdk/x/oracle/types"
)

func (suite *TestSuite) TestQueryParams() {
res, err := suite.queryClient.Params(gocontext.Background(), &types.QueryParamsRequest{})
suite.Require().NoError(err)
suite.Require().NotNil(res)
suite.Require().Equal(suite.app.OracleKeeper.GetParams(suite.ctx), res.GetParams())
}
11 changes: 10 additions & 1 deletion x/oracle/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"testing"
"time"

"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/prysmaticlabs/prysm/crypto/bls"
"github.com/prysmaticlabs/prysm/crypto/bls/blst"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -35,7 +36,8 @@ type TestSuite struct {
app *simapp.SimApp
ctx sdk.Context

msgServer types.MsgServer
msgServer types.MsgServer
queryClient types.QueryClient
}

func (s *TestSuite) SetupTest() {
Expand All @@ -51,13 +53,20 @@ func (s *TestSuite) SetupTest() {
s.app.CrossChainKeeper.SetSrcChainID(sdk.ChainID(1))
s.app.CrossChainKeeper.SetDestChainID(sdk.ChainID(56))

s.app.OracleKeeper.SetParams(s.ctx, types.DefaultParams())

coins := sdk.NewCoins(sdk.NewCoin("stake", sdk.NewInt(100000)))
err := s.app.BankKeeper.MintCoins(ctx, minttypes.ModuleName, coins)
s.NoError(err)
err = app.BankKeeper.SendCoinsFromModuleToModule(ctx, minttypes.ModuleName, crosschaintypes.ModuleName, coins)
s.NoError(err)

queryHelper := baseapp.NewQueryServerTestHelper(ctx, app.InterfaceRegistry())
types.RegisterQueryServer(queryHelper, app.OracleKeeper)
queryClient := types.NewQueryClient(queryHelper)

s.msgServer = keeper.NewMsgServerImpl(s.app.OracleKeeper)
s.queryClient = queryClient
}

func TestTestSuite(t *testing.T) {
Expand Down
6 changes: 3 additions & 3 deletions x/oracle/types/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ func ParamKeyTable() paramtypes.KeyTable {
// ParamSetPairs implements params.ParamSet
func (p *Params) ParamSetPairs() paramtypes.ParamSetPairs {
return paramtypes.ParamSetPairs{
paramtypes.NewParamSetPair(KeyParamRelayerTimeout, p.RelayerTimeout, validateRelayerTimeout),
paramtypes.NewParamSetPair(KeyParamRelayerBackoffTime, p.RelayerBackoffTime, validateRelayerBackoffTime),
paramtypes.NewParamSetPair(KeyParamRelayerRewardShare, p.RelayerRewardShare, validateRelayerRewardShare),
paramtypes.NewParamSetPair(KeyParamRelayerTimeout, &p.RelayerTimeout, validateRelayerTimeout),
paramtypes.NewParamSetPair(KeyParamRelayerBackoffTime, &p.RelayerBackoffTime, validateRelayerBackoffTime),
paramtypes.NewParamSetPair(KeyParamRelayerRewardShare, &p.RelayerRewardShare, validateRelayerRewardShare),
}
}

Expand Down