Skip to content

Commit

Permalink
feat: add ecocredit params query (#555)
Browse files Browse the repository at this point in the history
* feat: add params query

* feat: add tests

* chore: review changes
  • Loading branch information
aleem1314 authored Sep 28, 2021
1 parent 862518a commit f7c2cb8
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 0 deletions.
29 changes: 29 additions & 0 deletions x/ecocredit/client/query.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
package client

import (
"fmt"
"strings"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/version"
"github.com/spf13/cobra"

"github.com/regen-network/regen-ledger/x/ecocredit"
Expand All @@ -27,6 +31,7 @@ func QueryCmd(name string) *cobra.Command {
QueryBalanceCmd(),
QuerySupplyCmd(),
QueryCreditTypesCmd(),
QueryParams(),
)
return cmd
}
Expand Down Expand Up @@ -194,3 +199,27 @@ func QueryCreditTypesCmd() *cobra.Command {
},
})
}

// QueryParams returns ecocredit module parameters.
func QueryParams() *cobra.Command {
return qflags(&cobra.Command{
Use: "params",
Short: "Query the current ecocredit module parameters",
Long: strings.TrimSpace(
fmt.Sprintf(`Query the current ecocredit module parameters
Examples:
$%s query %s params
$%s q %s params
`, version.AppName, ecocredit.ModuleName, version.AppName, ecocredit.ModuleName),
),
RunE: func(cmd *cobra.Command, args []string) error {
c, ctx, err := mkQueryClient(cmd)
if err != nil {
return err
}
res, err := c.Params(cmd.Context(), &ecocredit.QueryParamsRequest{})
return print(ctx, res, err)
},
})
}
22 changes: 22 additions & 0 deletions x/ecocredit/client/testsuite/grpc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package testsuite

import (
"fmt"

"github.com/regen-network/regen-ledger/x/ecocredit"

"github.com/cosmos/cosmos-sdk/types/rest"
)

func (s *IntegrationTestSuite) TestGRPCQueryParams() {
val := s.network.Validators[0]
require := s.Require()

resp, err := rest.GetRequest(fmt.Sprintf("%s/regen/ecocredit/v1alpha1/params", val.APIAddress))
require.NoError(err)

var params ecocredit.QueryParamsResponse
require.NoError(val.ClientCtx.Codec.UnmarshalJSON(resp, &params))

s.Require().Equal(ecocredit.DefaultParams(), *params.Params)
}
17 changes: 17 additions & 0 deletions x/ecocredit/client/testsuite/query.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package testsuite

import (
"encoding/json"
"fmt"

"github.com/cosmos/cosmos-sdk/client/flags"
Expand Down Expand Up @@ -470,3 +471,19 @@ func (s *IntegrationTestSuite) TestQueryCreditTypes() {
})
}
}

func (s *IntegrationTestSuite) TestQueryParams() {
val := s.network.Validators[0]
clientCtx := val.ClientCtx
clientCtx.OutputFormat = "JSON"
require := s.Require()

cmd := client.QueryParams()
out, err := cli.ExecTestCLICmd(clientCtx, cmd, []string{})
require.NoError(err)

var params ecocredit.QueryParamsResponse
json.Unmarshal(out.Bytes(), &params)

require.Equal(ecocredit.DefaultParams(), *params.Params)
}

0 comments on commit f7c2cb8

Please sign in to comment.