From f8575a5851fbb17b92c3a8f576269f92da6da4c3 Mon Sep 17 00:00:00 2001 From: Sunny Aggarwal Date: Tue, 23 Oct 2018 16:29:56 -0700 Subject: [PATCH 01/16] gov query procedures --- PENDING.md | 3 +++ client/lcd/lcd_test.go | 45 +++++++++++++++++++++++++++++++---- cmd/gaia/cli_test/cli_test.go | 31 ++++++++++++++++++++++++ cmd/gaia/cmd/gaiacli/main.go | 1 + x/gov/client/cli/tx.go | 24 +++++++++++++++++++ x/gov/client/rest/rest.go | 22 +++++++++++++++++ x/gov/queryable.go | 30 +++++++++++++++++++++++ 7 files changed, 151 insertions(+), 5 deletions(-) diff --git a/PENDING.md b/PENDING.md index 84a08a5abe26..1446da972af1 100644 --- a/PENDING.md +++ b/PENDING.md @@ -17,14 +17,17 @@ BREAKING CHANGES FEATURES * Gaia REST API (`gaiacli advanced rest-server`) + * [gov] [\#2479](https://github.com/cosmos/cosmos-sdk/issues/2479) Added query governance procedures rest endpoints * Gaia CLI (`gaiacli`) * [cli] [\#2569](https://github.com/cosmos/cosmos-sdk/pull/2569) Add commands to query validator unbondings and redelegations * [cli] [\#2569](https://github.com/cosmos/cosmos-sdk/pull/2569) Add commands to query validator unbondings and redelegations * [cli] [\#2524](https://github.com/cosmos/cosmos-sdk/issues/2524) Add support offline mode to `gaiacli tx sign`. Lookups are not performed if the flag `--offline` is on. * [cli] [\#2558](https://github.com/cosmos/cosmos-sdk/issues/2558) Rename --print-sigs to --validate-signatures. It now performs a complete set of sanity checks and reports to the user. Also added --print-signature-only to print the signature only, not the whole transaction. + * [gov][cli] [\#2479](https://github.com/cosmos/cosmos-sdk/issues/2479) Add query governance procedures commands * Gaia + * [x/gov] [#2479](https://github.com/cosmos/cosmos-sdk/issues/2479) Added querier for getting Procedures * SDK * (#1336) Mechanism for SDK Users to configure their own Bech32 prefixes instead of using the default cosmos prefixes. diff --git a/client/lcd/lcd_test.go b/client/lcd/lcd_test.go index cb25721e891d..86ac5069d53e 100644 --- a/client/lcd/lcd_test.go +++ b/client/lcd/lcd_test.go @@ -730,26 +730,31 @@ func TestProposalsQuery(t *testing.T) { cleanup, _, _, port := InitializeTestLCD(t, 1, []sdk.AccAddress{addrs[0], addrs[1]}) defer cleanup() + depositProcedure := getDepositProcedure(t, port) + halfMinDeposit := depositProcedure.MinDeposit.AmountOf("steak").Int64() / 2 + getVotingProcedure(t, port) + getTallyingProcedure(t, port) + // Addr1 proposes (and deposits) proposals #1 and #2 - resultTx := doSubmitProposal(t, port, seeds[0], names[0], passwords[0], addrs[0], 5) + resultTx := doSubmitProposal(t, port, seeds[0], names[0], passwords[0], addrs[0], halfMinDeposit) var proposalID1 int64 cdc.UnmarshalBinaryBare(resultTx.DeliverTx.GetData(), &proposalID1) tests.WaitForHeight(resultTx.Height+1, port) - resultTx = doSubmitProposal(t, port, seeds[0], names[0], passwords[0], addrs[0], 5) + resultTx = doSubmitProposal(t, port, seeds[0], names[0], passwords[0], addrs[0], halfMinDeposit) var proposalID2 int64 cdc.UnmarshalBinaryBare(resultTx.DeliverTx.GetData(), &proposalID2) tests.WaitForHeight(resultTx.Height+1, port) // Addr2 proposes (and deposits) proposals #3 - resultTx = doSubmitProposal(t, port, seeds[1], names[1], passwords[1], addrs[1], 5) + resultTx = doSubmitProposal(t, port, seeds[1], names[1], passwords[1], addrs[1], halfMinDeposit) var proposalID3 int64 cdc.UnmarshalBinaryBare(resultTx.DeliverTx.GetData(), &proposalID3) tests.WaitForHeight(resultTx.Height+1, port) // Addr2 deposits on proposals #2 & #3 - resultTx = doDeposit(t, port, seeds[1], names[1], passwords[1], addrs[1], proposalID2, 5) + resultTx = doDeposit(t, port, seeds[1], names[1], passwords[1], addrs[1], proposalID2, halfMinDeposit) tests.WaitForHeight(resultTx.Height+1, port) - resultTx = doDeposit(t, port, seeds[1], names[1], passwords[1], addrs[1], proposalID3, 5) + resultTx = doDeposit(t, port, seeds[1], names[1], passwords[1], addrs[1], proposalID3, halfMinDeposit) tests.WaitForHeight(resultTx.Height+1, port) // check deposits match proposal and individual deposits @@ -1230,6 +1235,36 @@ func getValidatorRedelegations(t *testing.T, port string, validatorAddr sdk.ValA // ============= Governance Module ================ +func getDepositProcedure(t *testing.T, port string) gov.DepositProcedure { + res, body := Request(t, port, "GET", "/gov/procedure/deposit", nil) + require.Equal(t, http.StatusOK, res.StatusCode, body) + + var depositProcedure gov.DepositProcedure + err := cdc.UnmarshalJSON([]byte(body), &depositProcedure) + require.Nil(t, err) + return depositProcedure +} + +func getVotingProcedure(t *testing.T, port string) gov.VotingProcedure { + res, body := Request(t, port, "GET", "/gov/procedure/voting", nil) + require.Equal(t, http.StatusOK, res.StatusCode, body) + + var votingProcedure gov.VotingProcedure + err := cdc.UnmarshalJSON([]byte(body), &votingProcedure) + require.Nil(t, err) + return votingProcedure +} + +func getTallyingProcedure(t *testing.T, port string) gov.TallyingProcedure { + res, body := Request(t, port, "GET", "/gov/procedure/tallying", nil) + require.Equal(t, http.StatusOK, res.StatusCode, body) + + var tallyingProcedure gov.TallyingProcedure + err := cdc.UnmarshalJSON([]byte(body), &tallyingProcedure) + require.Nil(t, err) + return tallyingProcedure +} + func getProposal(t *testing.T, port string, proposalID int64) gov.Proposal { res, body := Request(t, port, "GET", fmt.Sprintf("/gov/proposals/%d", proposalID), nil) require.Equal(t, http.StatusOK, res.StatusCode, body) diff --git a/cmd/gaia/cli_test/cli_test.go b/cmd/gaia/cli_test/cli_test.go index b4791bf126b0..cd847d784ad2 100644 --- a/cmd/gaia/cli_test/cli_test.go +++ b/cmd/gaia/cli_test/cli_test.go @@ -309,6 +309,10 @@ func TestGaiaCLISubmitProposal(t *testing.T) { tests.WaitForTMStart(port) tests.WaitForNextNBlocksTM(2, port) + executeGetDepositProcedure(t, fmt.Sprintf("gaiacli query procedure deposit %v", flags)) + executeGetVotingProcedure(t, fmt.Sprintf("gaiacli query procedure voting %v", flags)) + executeGetTallyingProcedure(t, fmt.Sprintf("gaiacli query procedure tallying %v", flags)) + fooAddr, _ := executeGetAddrPK(t, fmt.Sprintf("gaiacli keys show foo --output=json --home=%s", gaiacliHome)) fooAcc := executeGetAccount(t, fmt.Sprintf("gaiacli query account %s %v", fooAddr, flags)) @@ -741,6 +745,33 @@ func executeGetParams(t *testing.T, cmdStr string) stake.Params { //___________________________________________________________________________________ // gov +func executeGetDepositProcedure(t *testing.T, cmdStr string) gov.DepositProcedure { + out, _ := tests.ExecuteT(t, cmdStr, "") + var depositProcedure gov.DepositProcedure + cdc := app.MakeCodec() + err := cdc.UnmarshalJSON([]byte(out), &depositProcedure) + require.NoError(t, err, "out %v\n, err %v", out, err) + return depositProcedure +} + +func executeGetVotingProcedure(t *testing.T, cmdStr string) gov.VotingProcedure { + out, _ := tests.ExecuteT(t, cmdStr, "") + var votingProcedure gov.VotingProcedure + cdc := app.MakeCodec() + err := cdc.UnmarshalJSON([]byte(out), &votingProcedure) + require.NoError(t, err, "out %v\n, err %v", out, err) + return votingProcedure +} + +func executeGetTallyingProcedure(t *testing.T, cmdStr string) gov.TallyingProcedure { + out, _ := tests.ExecuteT(t, cmdStr, "") + var tallyingProcedure gov.TallyingProcedure + cdc := app.MakeCodec() + err := cdc.UnmarshalJSON([]byte(out), &tallyingProcedure) + require.NoError(t, err, "out %v\n, err %v", out, err) + return tallyingProcedure +} + func executeGetProposal(t *testing.T, cmdStr string) gov.Proposal { out, _ := tests.ExecuteT(t, cmdStr, "") var proposal gov.Proposal diff --git a/cmd/gaia/cmd/gaiacli/main.go b/cmd/gaia/cmd/gaiacli/main.go index 212a67021404..3252c6658447 100644 --- a/cmd/gaia/cmd/gaiacli/main.go +++ b/cmd/gaia/cmd/gaiacli/main.go @@ -88,6 +88,7 @@ func main() { stakecmd.GetCmdQueryValidatorRedelegations(queryRouteStake, cdc), stakecmd.GetCmdQueryParams(storeStake, cdc), stakecmd.GetCmdQueryPool(storeStake, cdc), + govcmd.GetCmdQueryProcedure(storeGov, cdc), govcmd.GetCmdQueryProposal(storeGov, cdc), govcmd.GetCmdQueryProposals(storeGov, cdc), govcmd.GetCmdQueryVote(storeGov, cdc), diff --git a/x/gov/client/cli/tx.go b/x/gov/client/cli/tx.go index 4b23002bd74f..1f1c3c343524 100644 --- a/x/gov/client/cli/tx.go +++ b/x/gov/client/cli/tx.go @@ -249,6 +249,30 @@ func GetCmdVote(cdc *codec.Codec) *cobra.Command { return cmd } +// GetCmdQueryProposal implements the query proposal command. +func GetCmdQueryProcedure(queryRoute string, cdc *codec.Codec) *cobra.Command { + cmd := &cobra.Command{ + Use: "procedure [procedure-type]", + Short: "Query the procedure parameters of a certain part of the governance process", + Args: cobra.ExactArgs(1), + RunE: func(cmd *cobra.Command, args []string) error { + procedureType := args[0] + + cliCtx := context.NewCLIContext().WithCodec(cdc) + + res, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/procedure/%s", queryRoute, procedureType), nil) + if err != nil { + return err + } + + fmt.Println(string(res)) + return nil + }, + } + + return cmd +} + // GetCmdQueryProposal implements the query proposal command. func GetCmdQueryProposal(queryRoute string, cdc *codec.Codec) *cobra.Command { cmd := &cobra.Command{ diff --git a/x/gov/client/rest/rest.go b/x/gov/client/rest/rest.go index 374f5cc2ac56..6d240543adc9 100644 --- a/x/gov/client/rest/rest.go +++ b/x/gov/client/rest/rest.go @@ -18,7 +18,12 @@ import ( // REST Variable names // nolint const ( +<<<<<<< HEAD RestProposalID = "proposalId" +======= + RestProcedureType = "procedure-type" + RestProposalID = "proposal-id" +>>>>>>> gov query procedures RestDepositer = "depositer" RestVoter = "voter" RestProposalStatus = "status" @@ -32,6 +37,8 @@ func RegisterRoutes(cliCtx context.CLIContext, r *mux.Router, cdc *codec.Codec) r.HandleFunc(fmt.Sprintf("/gov/proposals/{%s}/deposits", RestProposalID), depositHandlerFn(cdc, cliCtx)).Methods("POST") r.HandleFunc(fmt.Sprintf("/gov/proposals/{%s}/votes", RestProposalID), voteHandlerFn(cdc, cliCtx)).Methods("POST") + r.HandleFunc(fmt.Sprintf("/gov/procedure/{%s}", RestProcedureType), queryProcedureHandlerFn(cdc, cliCtx)).Methods("GET") + r.HandleFunc("/gov/proposals", queryProposalsWithParameterFn(cdc, cliCtx)).Methods("GET") r.HandleFunc(fmt.Sprintf("/gov/proposals/{%s}", RestProposalID), queryProposalHandlerFn(cdc, cliCtx)).Methods("GET") r.HandleFunc(fmt.Sprintf("/gov/proposals/{%s}/deposits", RestProposalID), queryDepositsHandlerFn(cdc, cliCtx)).Methods("GET") @@ -177,6 +184,21 @@ func voteHandlerFn(cdc *codec.Codec, cliCtx context.CLIContext) http.HandlerFunc } } +func queryProcedureHandlerFn(cdc *codec.Codec, cliCtx context.CLIContext) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + vars := mux.Vars(r) + procedureType := vars[RestProcedureType] + + res, err := cliCtx.QueryWithData(fmt.Sprintf("custom/gov/procedure/%s", procedureType), nil) + if err != nil { + utils.WriteErrorResponse(w, http.StatusNotFound, err.Error()) + return + } + + utils.PostProcessResponse(w, cdc, res, cliCtx.Indent) + } +} + func queryProposalHandlerFn(cdc *codec.Codec, cliCtx context.CLIContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) diff --git a/x/gov/queryable.go b/x/gov/queryable.go index 93469a5ac299..44e8a36b7029 100644 --- a/x/gov/queryable.go +++ b/x/gov/queryable.go @@ -1,6 +1,8 @@ package gov import ( + "fmt" + "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" abci "github.com/tendermint/tendermint/abci/types" @@ -8,6 +10,7 @@ import ( // query endpoints supported by the governance Querier const ( + QueryProcedure = "procedure" QueryProposals = "proposals" QueryProposal = "proposal" QueryDeposits = "deposits" @@ -20,6 +23,8 @@ const ( func NewQuerier(keeper Keeper) sdk.Querier { return func(ctx sdk.Context, path []string, req abci.RequestQuery) (res []byte, err sdk.Error) { switch path[0] { + case QueryProcedure: + return queryProcedure(ctx, path[1:], req, keeper) case QueryProposals: return queryProposals(ctx, path[1:], req, keeper) case QueryProposal: @@ -40,6 +45,31 @@ func NewQuerier(keeper Keeper) sdk.Querier { } } +func queryProcedure(ctx sdk.Context, path []string, req abci.RequestQuery, keeper Keeper) (res []byte, err sdk.Error) { + switch path[0] { + case "deposit": + bz, err2 := codec.MarshalJSONIndent(keeper.cdc, keeper.GetDepositProcedure(ctx)) + if err2 != nil { + return nil, sdk.ErrInternal(sdk.AppendMsgToErr("could not marshal result to JSON", err2.Error())) + } + return bz, nil + case "voting": + bz, err2 := codec.MarshalJSONIndent(keeper.cdc, keeper.GetVotingProcedure(ctx)) + if err2 != nil { + return nil, sdk.ErrInternal(sdk.AppendMsgToErr("could not marshal result to JSON", err2.Error())) + } + return bz, nil + case "tallying": + bz, err2 := codec.MarshalJSONIndent(keeper.cdc, keeper.GetTallyingProcedure(ctx)) + if err2 != nil { + return nil, sdk.ErrInternal(sdk.AppendMsgToErr("could not marshal result to JSON", err2.Error())) + } + return bz, nil + } + + return res, sdk.ErrUnknownRequest(fmt.Sprintf("%s is not a valid query request path", req.Path)) +} + // Params for query 'custom/gov/proposal' type QueryProposalParams struct { ProposalID int64 From 1bdc4edc11fce43977bedb13308f00f4a6e75a39 Mon Sep 17 00:00:00 2001 From: Sunny Aggarwal Date: Mon, 29 Oct 2018 22:59:23 -0700 Subject: [PATCH 02/16] addressed comments --- client/lcd/lcd_test.go | 6 +++--- x/gov/client/rest/rest.go | 4 ++-- x/gov/queryable.go | 32 ++++++++++++++++++-------------- 3 files changed, 23 insertions(+), 19 deletions(-) diff --git a/client/lcd/lcd_test.go b/client/lcd/lcd_test.go index 86ac5069d53e..7abe6a0c48dc 100644 --- a/client/lcd/lcd_test.go +++ b/client/lcd/lcd_test.go @@ -1236,7 +1236,7 @@ func getValidatorRedelegations(t *testing.T, port string, validatorAddr sdk.ValA // ============= Governance Module ================ func getDepositProcedure(t *testing.T, port string) gov.DepositProcedure { - res, body := Request(t, port, "GET", "/gov/procedure/deposit", nil) + res, body := Request(t, port, "GET", "/gov/procedures/deposit", nil) require.Equal(t, http.StatusOK, res.StatusCode, body) var depositProcedure gov.DepositProcedure @@ -1246,7 +1246,7 @@ func getDepositProcedure(t *testing.T, port string) gov.DepositProcedure { } func getVotingProcedure(t *testing.T, port string) gov.VotingProcedure { - res, body := Request(t, port, "GET", "/gov/procedure/voting", nil) + res, body := Request(t, port, "GET", "/gov/procedures/voting", nil) require.Equal(t, http.StatusOK, res.StatusCode, body) var votingProcedure gov.VotingProcedure @@ -1256,7 +1256,7 @@ func getVotingProcedure(t *testing.T, port string) gov.VotingProcedure { } func getTallyingProcedure(t *testing.T, port string) gov.TallyingProcedure { - res, body := Request(t, port, "GET", "/gov/procedure/tallying", nil) + res, body := Request(t, port, "GET", "/gov/procedures/tallying", nil) require.Equal(t, http.StatusOK, res.StatusCode, body) var tallyingProcedure gov.TallyingProcedure diff --git a/x/gov/client/rest/rest.go b/x/gov/client/rest/rest.go index 6d240543adc9..ab281a4d9b95 100644 --- a/x/gov/client/rest/rest.go +++ b/x/gov/client/rest/rest.go @@ -37,7 +37,7 @@ func RegisterRoutes(cliCtx context.CLIContext, r *mux.Router, cdc *codec.Codec) r.HandleFunc(fmt.Sprintf("/gov/proposals/{%s}/deposits", RestProposalID), depositHandlerFn(cdc, cliCtx)).Methods("POST") r.HandleFunc(fmt.Sprintf("/gov/proposals/{%s}/votes", RestProposalID), voteHandlerFn(cdc, cliCtx)).Methods("POST") - r.HandleFunc(fmt.Sprintf("/gov/procedure/{%s}", RestProcedureType), queryProcedureHandlerFn(cdc, cliCtx)).Methods("GET") + r.HandleFunc(fmt.Sprintf("/gov/procedures/{%s}", RestProcedureType), queryProcedureHandlerFn(cdc, cliCtx)).Methods("GET") r.HandleFunc("/gov/proposals", queryProposalsWithParameterFn(cdc, cliCtx)).Methods("GET") r.HandleFunc(fmt.Sprintf("/gov/proposals/{%s}", RestProposalID), queryProposalHandlerFn(cdc, cliCtx)).Methods("GET") @@ -189,7 +189,7 @@ func queryProcedureHandlerFn(cdc *codec.Codec, cliCtx context.CLIContext) http.H vars := mux.Vars(r) procedureType := vars[RestProcedureType] - res, err := cliCtx.QueryWithData(fmt.Sprintf("custom/gov/procedure/%s", procedureType), nil) + res, err := cliCtx.QueryWithData(fmt.Sprintf("custom/gov/procedures/%s", procedureType), nil) if err != nil { utils.WriteErrorResponse(w, http.StatusNotFound, err.Error()) return diff --git a/x/gov/queryable.go b/x/gov/queryable.go index 44e8a36b7029..4ef99bd97224 100644 --- a/x/gov/queryable.go +++ b/x/gov/queryable.go @@ -10,21 +10,25 @@ import ( // query endpoints supported by the governance Querier const ( - QueryProcedure = "procedure" - QueryProposals = "proposals" - QueryProposal = "proposal" - QueryDeposits = "deposits" - QueryDeposit = "deposit" - QueryVotes = "votes" - QueryVote = "vote" - QueryTally = "tally" + QueryProcedures = "procedures" + QueryProposals = "proposals" + QueryProposal = "proposal" + QueryDeposits = "deposits" + QueryDeposit = "deposit" + QueryVotes = "votes" + QueryVote = "vote" + QueryTally = "tally" + + ProcedureDeposit = "deposit" + ProcedureVoting = "voting" + ProcedureTallying = "tallying" ) func NewQuerier(keeper Keeper) sdk.Querier { return func(ctx sdk.Context, path []string, req abci.RequestQuery) (res []byte, err sdk.Error) { switch path[0] { - case QueryProcedure: - return queryProcedure(ctx, path[1:], req, keeper) + case QueryProcedures: + return queryProcedures(ctx, path[1:], req, keeper) case QueryProposals: return queryProposals(ctx, path[1:], req, keeper) case QueryProposal: @@ -45,21 +49,21 @@ func NewQuerier(keeper Keeper) sdk.Querier { } } -func queryProcedure(ctx sdk.Context, path []string, req abci.RequestQuery, keeper Keeper) (res []byte, err sdk.Error) { +func queryProcedures(ctx sdk.Context, path []string, req abci.RequestQuery, keeper Keeper) (res []byte, err sdk.Error) { switch path[0] { - case "deposit": + case ProcedureDeposit: bz, err2 := codec.MarshalJSONIndent(keeper.cdc, keeper.GetDepositProcedure(ctx)) if err2 != nil { return nil, sdk.ErrInternal(sdk.AppendMsgToErr("could not marshal result to JSON", err2.Error())) } return bz, nil - case "voting": + case ProcedureVoting: bz, err2 := codec.MarshalJSONIndent(keeper.cdc, keeper.GetVotingProcedure(ctx)) if err2 != nil { return nil, sdk.ErrInternal(sdk.AppendMsgToErr("could not marshal result to JSON", err2.Error())) } return bz, nil - case "tallying": + case ProcedureTallying: bz, err2 := codec.MarshalJSONIndent(keeper.cdc, keeper.GetTallyingProcedure(ctx)) if err2 != nil { return nil, sdk.ErrInternal(sdk.AppendMsgToErr("could not marshal result to JSON", err2.Error())) From ed33bcb340b9e5e8a7c290bfdad0851ca89c7c39 Mon Sep 17 00:00:00 2001 From: Sunny Aggarwal Date: Sun, 4 Nov 2018 15:39:18 -0800 Subject: [PATCH 03/16] fixed diff commit --- x/gov/client/cli/tx.go | 2 +- x/gov/client/rest/rest.go | 4 ---- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/x/gov/client/cli/tx.go b/x/gov/client/cli/tx.go index 1f1c3c343524..897628d06b68 100644 --- a/x/gov/client/cli/tx.go +++ b/x/gov/client/cli/tx.go @@ -253,7 +253,7 @@ func GetCmdVote(cdc *codec.Codec) *cobra.Command { func GetCmdQueryProcedure(queryRoute string, cdc *codec.Codec) *cobra.Command { cmd := &cobra.Command{ Use: "procedure [procedure-type]", - Short: "Query the procedure parameters of a certain part of the governance process", + Short: "Query the procedure parameters of the governance process", Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { procedureType := args[0] diff --git a/x/gov/client/rest/rest.go b/x/gov/client/rest/rest.go index ab281a4d9b95..e697b0aafe48 100644 --- a/x/gov/client/rest/rest.go +++ b/x/gov/client/rest/rest.go @@ -18,12 +18,8 @@ import ( // REST Variable names // nolint const ( -<<<<<<< HEAD - RestProposalID = "proposalId" -======= RestProcedureType = "procedure-type" RestProposalID = "proposal-id" ->>>>>>> gov query procedures RestDepositer = "depositer" RestVoter = "voter" RestProposalStatus = "status" From 79fe2ed1e2cf8645f57ee6e88e6cedfe0ea25417 Mon Sep 17 00:00:00 2001 From: Aleksandr Bezobchuk Date: Mon, 12 Nov 2018 10:11:12 -0500 Subject: [PATCH 04/16] Fix dup pending logs --- PENDING.md | 4 ---- 1 file changed, 4 deletions(-) diff --git a/PENDING.md b/PENDING.md index 26d931ab3f25..4c7b30d731b6 100644 --- a/PENDING.md +++ b/PENDING.md @@ -20,10 +20,6 @@ FEATURES query REST endpoints. * Gaia CLI (`gaiacli`) - * [cli] [\#2569](https://github.com/cosmos/cosmos-sdk/pull/2569) Add commands to query validator unbondings and redelegations - * [cli] [\#2569](https://github.com/cosmos/cosmos-sdk/pull/2569) Add commands to query validator unbondings and redelegations - * [cli] [\#2524](https://github.com/cosmos/cosmos-sdk/issues/2524) Add support offline mode to `gaiacli tx sign`. Lookups are not performed if the flag `--offline` is on. - * [cli] [\#2558](https://github.com/cosmos/cosmos-sdk/issues/2558) Rename --print-sigs to --validate-signatures. It now performs a complete set of sanity checks and reports to the user. Also added --print-signature-only to print the signature only, not the whole transaction. * [gov][cli] [\#2479](https://github.com/cosmos/cosmos-sdk/issues/2479) Add governance parameter query commands. From cc3c32c07a12ca80db6059ca2fd320716b7ab6db Mon Sep 17 00:00:00 2001 From: Aleksandr Bezobchuk Date: Mon, 12 Nov 2018 10:12:20 -0500 Subject: [PATCH 05/16] Cleanup pending log entries again --- PENDING.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/PENDING.md b/PENDING.md index 4c7b30d731b6..a7c085a5e5a2 100644 --- a/PENDING.md +++ b/PENDING.md @@ -20,12 +20,12 @@ FEATURES query REST endpoints. * Gaia CLI (`gaiacli`) - * [gov][cli] [\#2479](https://github.com/cosmos/cosmos-sdk/issues/2479) Add governance + * [gov][cli] [\#2479](https://github.com/cosmos/cosmos-sdk/issues/2479) Added governance parameter query commands. * Gaia - * [x/gov] [#2479](https://github.com/cosmos/cosmos-sdk/issues/2479) Added querier for getting - governance parameters. + * [x/gov] [#2479](https://github.com/cosmos/cosmos-sdk/issues/2479) Implemented querier + for getting governance parameters. * SDK From 3e5aac4f50052f78015ca410820341892cbfb48a Mon Sep 17 00:00:00 2001 From: Aleksandr Bezobchuk Date: Mon, 12 Nov 2018 10:41:59 -0500 Subject: [PATCH 06/16] Fix test coverage and remove legacy procedures --- client/lcd/lcd_test.go | 46 ++++++++++++++++++++------------------- x/gov/client/rest/rest.go | 6 ++--- x/gov/queryable.go | 30 +++++++++++++------------ 3 files changed, 43 insertions(+), 39 deletions(-) diff --git a/client/lcd/lcd_test.go b/client/lcd/lcd_test.go index a122237b716b..3b5d24503623 100644 --- a/client/lcd/lcd_test.go +++ b/client/lcd/lcd_test.go @@ -737,23 +737,25 @@ func TestProposalsQuery(t *testing.T) { // Addr1 proposes (and deposits) proposals #1 and #2 resultTx := doSubmitProposal(t, port, seeds[0], names[0], passwords[0], addrs[0], halfMinDeposit) - var proposalID1 int64 - cdc.UnmarshalBinaryBare(resultTx.DeliverTx.GetData(), &proposalID1) + var proposalID1 uint64 + cdc.MustUnmarshalBinaryLengthPrefixed(resultTx.DeliverTx.GetData(), &proposalID1) tests.WaitForHeight(resultTx.Height+1, port) + resultTx = doSubmitProposal(t, port, seeds[0], names[0], passwords[0], addrs[0], halfMinDeposit) - var proposalID2 int64 - cdc.UnmarshalBinaryBare(resultTx.DeliverTx.GetData(), &proposalID2) + var proposalID2 uint64 + cdc.MustUnmarshalBinaryLengthPrefixed(resultTx.DeliverTx.GetData(), &proposalID2) tests.WaitForHeight(resultTx.Height+1, port) // Addr2 proposes (and deposits) proposals #3 resultTx = doSubmitProposal(t, port, seeds[1], names[1], passwords[1], addrs[1], halfMinDeposit) - var proposalID3 int64 - cdc.UnmarshalBinaryBare(resultTx.DeliverTx.GetData(), &proposalID3) + var proposalID3 uint64 + cdc.MustUnmarshalBinaryLengthPrefixed(resultTx.DeliverTx.GetData(), &proposalID3) tests.WaitForHeight(resultTx.Height+1, port) // Addr2 deposits on proposals #2 & #3 resultTx = doDeposit(t, port, seeds[1], names[1], passwords[1], addrs[1], proposalID2, halfMinDeposit) tests.WaitForHeight(resultTx.Height+1, port) + resultTx = doDeposit(t, port, seeds[1], names[1], passwords[1], addrs[1], proposalID3, halfMinDeposit) tests.WaitForHeight(resultTx.Height+1, port) @@ -1235,37 +1237,37 @@ func getValidatorRedelegations(t *testing.T, port string, validatorAddr sdk.ValA // ============= Governance Module ================ -func getDepositProcedure(t *testing.T, port string) gov.DepositProcedure { - res, body := Request(t, port, "GET", "/gov/procedures/deposit", nil) +func getDepositProcedure(t *testing.T, port string) gov.DepositParams { + res, body := Request(t, port, "GET", "/gov/params/deposit", nil) require.Equal(t, http.StatusOK, res.StatusCode, body) - var depositProcedure gov.DepositProcedure - err := cdc.UnmarshalJSON([]byte(body), &depositProcedure) + var depositParams gov.DepositParams + err := cdc.UnmarshalJSON([]byte(body), &depositParams) require.Nil(t, err) - return depositProcedure + return depositParams } -func getVotingProcedure(t *testing.T, port string) gov.VotingProcedure { - res, body := Request(t, port, "GET", "/gov/procedures/voting", nil) +func getVotingProcedure(t *testing.T, port string) gov.VotingParams { + res, body := Request(t, port, "GET", "/gov/params/voting", nil) require.Equal(t, http.StatusOK, res.StatusCode, body) - var votingProcedure gov.VotingProcedure - err := cdc.UnmarshalJSON([]byte(body), &votingProcedure) + var votingParams gov.VotingParams + err := cdc.UnmarshalJSON([]byte(body), &votingParams) require.Nil(t, err) - return votingProcedure + return votingParams } -func getTallyingProcedure(t *testing.T, port string) gov.TallyingProcedure { - res, body := Request(t, port, "GET", "/gov/procedures/tallying", nil) +func getTallyingProcedure(t *testing.T, port string) gov.TallyParams { + res, body := Request(t, port, "GET", "/gov/params/tallying", nil) require.Equal(t, http.StatusOK, res.StatusCode, body) - var tallyingProcedure gov.TallyingProcedure - err := cdc.UnmarshalJSON([]byte(body), &tallyingProcedure) + var tallyParams gov.TallyParams + err := cdc.UnmarshalJSON([]byte(body), &tallyParams) require.Nil(t, err) - return tallyingProcedure + return tallyParams } -func getProposal(t *testing.T, port string, proposalID int64) gov.Proposal { +func getProposal(t *testing.T, port string, proposalID uint64) gov.Proposal { res, body := Request(t, port, "GET", fmt.Sprintf("/gov/proposals/%d", proposalID), nil) require.Equal(t, http.StatusOK, res.StatusCode, body) var proposal gov.Proposal diff --git a/x/gov/client/rest/rest.go b/x/gov/client/rest/rest.go index dbf949714352..481b5848b264 100644 --- a/x/gov/client/rest/rest.go +++ b/x/gov/client/rest/rest.go @@ -33,7 +33,7 @@ func RegisterRoutes(cliCtx context.CLIContext, r *mux.Router, cdc *codec.Codec) r.HandleFunc(fmt.Sprintf("/gov/proposals/{%s}/deposits", RestProposalID), depositHandlerFn(cdc, cliCtx)).Methods("POST") r.HandleFunc(fmt.Sprintf("/gov/proposals/{%s}/votes", RestProposalID), voteHandlerFn(cdc, cliCtx)).Methods("POST") - r.HandleFunc(fmt.Sprintf("/gov/procedures/{%s}", RestProcedureType), queryProcedureHandlerFn(cdc, cliCtx)).Methods("GET") + r.HandleFunc(fmt.Sprintf("/gov/params/{%s}", RestProcedureType), queryParamsHandlerFn(cdc, cliCtx)).Methods("GET") r.HandleFunc("/gov/proposals", queryProposalsWithParameterFn(cdc, cliCtx)).Methods("GET") r.HandleFunc(fmt.Sprintf("/gov/proposals/{%s}", RestProposalID), queryProposalHandlerFn(cdc, cliCtx)).Methods("GET") @@ -180,12 +180,12 @@ func voteHandlerFn(cdc *codec.Codec, cliCtx context.CLIContext) http.HandlerFunc } } -func queryProcedureHandlerFn(cdc *codec.Codec, cliCtx context.CLIContext) http.HandlerFunc { +func queryParamsHandlerFn(cdc *codec.Codec, cliCtx context.CLIContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) procedureType := vars[RestProcedureType] - res, err := cliCtx.QueryWithData(fmt.Sprintf("custom/gov/procedures/%s", procedureType), nil) + res, err := cliCtx.QueryWithData(fmt.Sprintf("custom/gov/%s/%s", gov.QueryParams, procedureType), nil) if err != nil { utils.WriteErrorResponse(w, http.StatusNotFound, err.Error()) return diff --git a/x/gov/queryable.go b/x/gov/queryable.go index c82c48e3a87a..467a9a319ea9 100644 --- a/x/gov/queryable.go +++ b/x/gov/queryable.go @@ -10,14 +10,14 @@ import ( // query endpoints supported by the governance Querier const ( - QueryProcedures = "procedures" - QueryProposals = "proposals" - QueryProposal = "proposal" - QueryDeposits = "deposits" - QueryDeposit = "deposit" - QueryVotes = "votes" - QueryVote = "vote" - QueryTally = "tally" + QueryParams = "params" + QueryProposals = "proposals" + QueryProposal = "proposal" + QueryDeposits = "deposits" + QueryDeposit = "deposit" + QueryVotes = "votes" + QueryVote = "vote" + QueryTally = "tally" ProcedureDeposit = "deposit" ProcedureVoting = "voting" @@ -27,8 +27,8 @@ const ( func NewQuerier(keeper Keeper) sdk.Querier { return func(ctx sdk.Context, path []string, req abci.RequestQuery) (res []byte, err sdk.Error) { switch path[0] { - case QueryProcedures: - return queryProcedures(ctx, path[1:], req, keeper) + case QueryParams: + return queryParams(ctx, path[1:], req, keeper) case QueryProposals: return queryProposals(ctx, path[1:], req, keeper) case QueryProposal: @@ -49,22 +49,24 @@ func NewQuerier(keeper Keeper) sdk.Querier { } } -func queryProcedures(ctx sdk.Context, path []string, req abci.RequestQuery, keeper Keeper) (res []byte, err sdk.Error) { +func queryParams(ctx sdk.Context, path []string, req abci.RequestQuery, keeper Keeper) (res []byte, err sdk.Error) { switch path[0] { case ProcedureDeposit: - bz, err2 := codec.MarshalJSONIndent(keeper.cdc, keeper.GetDepositProcedure(ctx)) + bz, err2 := codec.MarshalJSONIndent(keeper.cdc, keeper.GetDepositParams(ctx)) if err2 != nil { return nil, sdk.ErrInternal(sdk.AppendMsgToErr("could not marshal result to JSON", err2.Error())) } return bz, nil + case ProcedureVoting: - bz, err2 := codec.MarshalJSONIndent(keeper.cdc, keeper.GetVotingProcedure(ctx)) + bz, err2 := codec.MarshalJSONIndent(keeper.cdc, keeper.GetVotingParams(ctx)) if err2 != nil { return nil, sdk.ErrInternal(sdk.AppendMsgToErr("could not marshal result to JSON", err2.Error())) } return bz, nil + case ProcedureTallying: - bz, err2 := codec.MarshalJSONIndent(keeper.cdc, keeper.GetTallyingProcedure(ctx)) + bz, err2 := codec.MarshalJSONIndent(keeper.cdc, keeper.GetTallyParams(ctx)) if err2 != nil { return nil, sdk.ErrInternal(sdk.AppendMsgToErr("could not marshal result to JSON", err2.Error())) } From 32befb20d1c7b267c07740690bbdc23872a22dd4 Mon Sep 17 00:00:00 2001 From: Aleksandr Bezobchuk Date: Mon, 12 Nov 2018 10:52:32 -0500 Subject: [PATCH 07/16] Update gov docs by updating to use params --- docs/spec/governance/state.md | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/docs/spec/governance/state.md b/docs/spec/governance/state.md index ca130bd4c374..5c76fbe56467 100644 --- a/docs/spec/governance/state.md +++ b/docs/spec/governance/state.md @@ -9,25 +9,24 @@ be one active procedure at any given time. If governance wants to change a procedure, either to modify a value or add/remove a parameter, a new procedure has to be created and the previous one rendered inactive. - ```go -type DepositProcedure struct { - MinDeposit sdk.Coins // Minimum deposit for a proposal to enter voting period. - MaxDepositPeriod time.Time // Maximum period for Atom holders to deposit on a proposal. Initial value: 2 months +type DepositParams struct { + MinDeposit sdk.Coins // Minimum deposit for a proposal to enter voting period. + MaxDepositPeriod time.Time // Maximum period for Atom holders to deposit on a proposal. Initial value: 2 months } ``` ```go -type VotingProcedure struct { - VotingPeriod time.Time // Length of the voting period. Initial value: 2 weeks +type VotingParams struct { + VotingPeriod time.Time // Length of the voting period. Initial value: 2 weeks } ``` ```go -type TallyingProcedure struct { - Threshold sdk.Dec // Minimum propotion of Yes votes for proposal to pass. Initial value: 0.5 - Veto sdk.Dec // Minimum proportion of Veto votes to Total votes ratio for proposal to be vetoed. Initial value: 1/3 - GovernancePenalty sdk.Dec // Penalty if validator does not vote +type TallyParams struct { + Threshold sdk.Dec // Minimum proportion of Yes votes for proposal to pass. Initial value: 0.5 + Veto sdk.Dec // Minimum proportion of Veto votes to Total votes ratio for proposal to be vetoed. Initial value: 1/3 + GovernancePenalty sdk.Dec // Penalty if validator does not vote } ``` From cb517fcd2f896874cde8f9b6b11034dc94f35f66 Mon Sep 17 00:00:00 2001 From: Aleksandr Bezobchuk Date: Mon, 12 Nov 2018 10:52:39 -0500 Subject: [PATCH 08/16] Fix CLI tests --- cmd/gaia/cli_test/cli_test.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/cmd/gaia/cli_test/cli_test.go b/cmd/gaia/cli_test/cli_test.go index 309637f0fb71..d2261fd7bfc6 100644 --- a/cmd/gaia/cli_test/cli_test.go +++ b/cmd/gaia/cli_test/cli_test.go @@ -775,27 +775,27 @@ func executeGetParams(t *testing.T, cmdStr string) stake.Params { //___________________________________________________________________________________ // gov -func executeGetDepositProcedure(t *testing.T, cmdStr string) gov.DepositProcedure { +func executeGetDepositProcedure(t *testing.T, cmdStr string) gov.DepositParams { out, _ := tests.ExecuteT(t, cmdStr, "") - var depositProcedure gov.DepositProcedure + var depositProcedure gov.DepositParams cdc := app.MakeCodec() err := cdc.UnmarshalJSON([]byte(out), &depositProcedure) require.NoError(t, err, "out %v\n, err %v", out, err) return depositProcedure } -func executeGetVotingProcedure(t *testing.T, cmdStr string) gov.VotingProcedure { +func executeGetVotingProcedure(t *testing.T, cmdStr string) gov.VotingParams { out, _ := tests.ExecuteT(t, cmdStr, "") - var votingProcedure gov.VotingProcedure + var votingProcedure gov.VotingParams cdc := app.MakeCodec() err := cdc.UnmarshalJSON([]byte(out), &votingProcedure) require.NoError(t, err, "out %v\n, err %v", out, err) return votingProcedure } -func executeGetTallyingProcedure(t *testing.T, cmdStr string) gov.TallyingProcedure { +func executeGetTallyingProcedure(t *testing.T, cmdStr string) gov.TallyParams { out, _ := tests.ExecuteT(t, cmdStr, "") - var tallyingProcedure gov.TallyingProcedure + var tallyingProcedure gov.TallyParams cdc := app.MakeCodec() err := cdc.UnmarshalJSON([]byte(out), &tallyingProcedure) require.NoError(t, err, "out %v\n, err %v", out, err) From 8c48b0ea5c39856f8032c6efa2c36082b715c066 Mon Sep 17 00:00:00 2001 From: Aleksandr Bezobchuk Date: Mon, 12 Nov 2018 11:28:37 -0500 Subject: [PATCH 09/16] Update docs and REST endpoints --- client/lcd/lcd_test.go | 6 +++--- docs/spec/governance/state.md | 12 ++++++------ x/gov/client/rest/rest.go | 9 ++++++--- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/client/lcd/lcd_test.go b/client/lcd/lcd_test.go index 3b5d24503623..dcf3cfb36c24 100644 --- a/client/lcd/lcd_test.go +++ b/client/lcd/lcd_test.go @@ -1238,7 +1238,7 @@ func getValidatorRedelegations(t *testing.T, port string, validatorAddr sdk.ValA // ============= Governance Module ================ func getDepositProcedure(t *testing.T, port string) gov.DepositParams { - res, body := Request(t, port, "GET", "/gov/params/deposit", nil) + res, body := Request(t, port, "GET", "/gov/parameters/deposit", nil) require.Equal(t, http.StatusOK, res.StatusCode, body) var depositParams gov.DepositParams @@ -1248,7 +1248,7 @@ func getDepositProcedure(t *testing.T, port string) gov.DepositParams { } func getVotingProcedure(t *testing.T, port string) gov.VotingParams { - res, body := Request(t, port, "GET", "/gov/params/voting", nil) + res, body := Request(t, port, "GET", "/gov/parameters/voting", nil) require.Equal(t, http.StatusOK, res.StatusCode, body) var votingParams gov.VotingParams @@ -1258,7 +1258,7 @@ func getVotingProcedure(t *testing.T, port string) gov.VotingParams { } func getTallyingProcedure(t *testing.T, port string) gov.TallyParams { - res, body := Request(t, port, "GET", "/gov/params/tallying", nil) + res, body := Request(t, port, "GET", "/gov/parameters/tallying", nil) require.Equal(t, http.StatusOK, res.StatusCode, body) var tallyParams gov.TallyParams diff --git a/docs/spec/governance/state.md b/docs/spec/governance/state.md index 5c76fbe56467..6ecaefab9ef0 100644 --- a/docs/spec/governance/state.md +++ b/docs/spec/governance/state.md @@ -2,12 +2,12 @@ ## State -### Procedures and base types +### Parameters and base types -`Procedures` define the rule according to which votes are run. There can only -be one active procedure at any given time. If governance wants to change a -procedure, either to modify a value or add/remove a parameter, a new procedure -has to be created and the previous one rendered inactive. +`Parameters` define the rules according to which votes are run. There can only +be one active parameter set at any given time. If governance wants to change a +parameter set, either to modify a value or add/remove a parameter field, a new +parameter set has to be created and the previous one rendered inactive. ```go type DepositParams struct { @@ -30,7 +30,7 @@ type TallyParams struct { } ``` -Procedures are stored in a global `GlobalParams` KVStore. +Parameters are stored in a global `GlobalParams` KVStore. Additionally, we introduce some basic types: diff --git a/x/gov/client/rest/rest.go b/x/gov/client/rest/rest.go index 481b5848b264..ee019ace3914 100644 --- a/x/gov/client/rest/rest.go +++ b/x/gov/client/rest/rest.go @@ -18,7 +18,7 @@ import ( // REST Variable names // nolint const ( - RestProcedureType = "procedure-type" + RestParamsType = "type" RestProposalID = "proposal-id" RestDepositer = "depositer" RestVoter = "voter" @@ -33,7 +33,10 @@ func RegisterRoutes(cliCtx context.CLIContext, r *mux.Router, cdc *codec.Codec) r.HandleFunc(fmt.Sprintf("/gov/proposals/{%s}/deposits", RestProposalID), depositHandlerFn(cdc, cliCtx)).Methods("POST") r.HandleFunc(fmt.Sprintf("/gov/proposals/{%s}/votes", RestProposalID), voteHandlerFn(cdc, cliCtx)).Methods("POST") - r.HandleFunc(fmt.Sprintf("/gov/params/{%s}", RestProcedureType), queryParamsHandlerFn(cdc, cliCtx)).Methods("GET") + r.HandleFunc( + fmt.Sprintf("/gov/parameters/{%s}", RestParamsType), + queryParamsHandlerFn(cdc, cliCtx), + ).Methods("GET") r.HandleFunc("/gov/proposals", queryProposalsWithParameterFn(cdc, cliCtx)).Methods("GET") r.HandleFunc(fmt.Sprintf("/gov/proposals/{%s}", RestProposalID), queryProposalHandlerFn(cdc, cliCtx)).Methods("GET") @@ -183,7 +186,7 @@ func voteHandlerFn(cdc *codec.Codec, cliCtx context.CLIContext) http.HandlerFunc func queryParamsHandlerFn(cdc *codec.Codec, cliCtx context.CLIContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) - procedureType := vars[RestProcedureType] + procedureType := vars[RestParamsType] res, err := cliCtx.QueryWithData(fmt.Sprintf("custom/gov/%s/%s", gov.QueryParams, procedureType), nil) if err != nil { From 22ad59e5631203347747434be3ef801c7b03092d Mon Sep 17 00:00:00 2001 From: Federico Kunze Date: Mon, 12 Nov 2018 20:30:38 +0100 Subject: [PATCH 10/16] procedure --> param --- client/lcd/lcd_test.go | 14 ++--- cmd/gaia/cmd/gaiacli/main.go | 2 +- docs/spec/governance/README.md | 4 +- docs/spec/governance/state.md | 22 ++++---- docs/spec/governance/transactions.md | 76 ++++++++++++++-------------- x/gov/client/cli/tx.go | 2 +- x/gov/keeper.go | 4 +- x/gov/params.go | 6 +-- x/gov/queryable.go | 12 ++--- 9 files changed, 71 insertions(+), 71 deletions(-) diff --git a/client/lcd/lcd_test.go b/client/lcd/lcd_test.go index dcf3cfb36c24..79442b0c16d3 100644 --- a/client/lcd/lcd_test.go +++ b/client/lcd/lcd_test.go @@ -730,10 +730,10 @@ func TestProposalsQuery(t *testing.T) { cleanup, _, _, port := InitializeTestLCD(t, 1, []sdk.AccAddress{addrs[0], addrs[1]}) defer cleanup() - depositProcedure := getDepositProcedure(t, port) - halfMinDeposit := depositProcedure.MinDeposit.AmountOf("steak").Int64() / 2 - getVotingProcedure(t, port) - getTallyingProcedure(t, port) + depositParam := getDepositParam(t, port) + halfMinDeposit := depositParam.MinDeposit.AmountOf("steak").Int64() / 2 + getVotingParam(t, port) + getTallyingParam(t, port) // Addr1 proposes (and deposits) proposals #1 and #2 resultTx := doSubmitProposal(t, port, seeds[0], names[0], passwords[0], addrs[0], halfMinDeposit) @@ -1237,7 +1237,7 @@ func getValidatorRedelegations(t *testing.T, port string, validatorAddr sdk.ValA // ============= Governance Module ================ -func getDepositProcedure(t *testing.T, port string) gov.DepositParams { +func getDepositParam(t *testing.T, port string) gov.DepositParams { res, body := Request(t, port, "GET", "/gov/parameters/deposit", nil) require.Equal(t, http.StatusOK, res.StatusCode, body) @@ -1247,7 +1247,7 @@ func getDepositProcedure(t *testing.T, port string) gov.DepositParams { return depositParams } -func getVotingProcedure(t *testing.T, port string) gov.VotingParams { +func getVotingParam(t *testing.T, port string) gov.VotingParams { res, body := Request(t, port, "GET", "/gov/parameters/voting", nil) require.Equal(t, http.StatusOK, res.StatusCode, body) @@ -1257,7 +1257,7 @@ func getVotingProcedure(t *testing.T, port string) gov.VotingParams { return votingParams } -func getTallyingProcedure(t *testing.T, port string) gov.TallyParams { +func getTallyingParam(t *testing.T, port string) gov.TallyParams { res, body := Request(t, port, "GET", "/gov/parameters/tallying", nil) require.Equal(t, http.StatusOK, res.StatusCode, body) diff --git a/cmd/gaia/cmd/gaiacli/main.go b/cmd/gaia/cmd/gaiacli/main.go index 3252c6658447..13e633b7d0b8 100644 --- a/cmd/gaia/cmd/gaiacli/main.go +++ b/cmd/gaia/cmd/gaiacli/main.go @@ -88,7 +88,7 @@ func main() { stakecmd.GetCmdQueryValidatorRedelegations(queryRouteStake, cdc), stakecmd.GetCmdQueryParams(storeStake, cdc), stakecmd.GetCmdQueryPool(storeStake, cdc), - govcmd.GetCmdQueryProcedure(storeGov, cdc), + govcmd.GetCmdQueryParam(storeGov, cdc), govcmd.GetCmdQueryProposal(storeGov, cdc), govcmd.GetCmdQueryProposals(storeGov, cdc), govcmd.GetCmdQueryVote(storeGov, cdc), diff --git a/docs/spec/governance/README.md b/docs/spec/governance/README.md index 0ddbc7cfdcff..6cc1edb50845 100644 --- a/docs/spec/governance/README.md +++ b/docs/spec/governance/README.md @@ -2,7 +2,7 @@ ## Abstract -This paper specifies the Governance module of the Cosmos-SDK, which was first described in the [Cosmos Whitepaper](https://cosmos.network/about/whitepaper) in June 2016. +This paper specifies the Governance module of the Cosmos-SDK, which was first described in the [Cosmos Whitepaper](https://cosmos.network/about/whitepaper) in June 2016. The module enables Cosmos-SDK based blockchain to support an on-chain governance system. In this system, holders of the native staking token of the chain can vote on proposals on a 1 token 1 vote basis. Next is a list of features the module currently supports: @@ -24,7 +24,7 @@ The following specification uses *Atom* as the native staking token. The module 1. **[Design overview](overview.md)** 2. **Implementation** 1. **[State](state.md)** - 1. Procedures + 1. Parameters 2. Proposals 3. Proposal Processing Queue 2. **[Transactions](transactions.md)** diff --git a/docs/spec/governance/state.md b/docs/spec/governance/state.md index 6ecaefab9ef0..f2a1467a97bd 100644 --- a/docs/spec/governance/state.md +++ b/docs/spec/governance/state.md @@ -11,7 +11,7 @@ parameter set has to be created and the previous one rendered inactive. ```go type DepositParams struct { - MinDeposit sdk.Coins // Minimum deposit for a proposal to enter voting period. + MinDeposit sdk.Coins // Minimum deposit for a proposal to enter voting period. MaxDepositPeriod time.Time // Maximum period for Atom holders to deposit on a proposal. Initial value: 2 months } ``` @@ -60,7 +60,7 @@ const ( ProposalStatusActive = 0x2 // MinDeposit is reachhed, participants can vote ProposalStatusAccepted = 0x3 // Proposal has been accepted ProposalStatusRejected = 0x4 // Proposal has been rejected - ProposalStatusClosed. = 0x5 // Proposal never reached MinDeposit + ProposalStatusClosed. = 0x5 // Proposal never reached MinDeposit ) ``` @@ -75,7 +75,7 @@ const ( ### ValidatorGovInfo -This type is used in a temp map when tallying +This type is used in a temp map when tallying ```go type ValidatorGovInfo struct { @@ -86,7 +86,7 @@ This type is used in a temp map when tallying ### Proposals -`Proposals` are an item to be voted on. +`Proposals` are an item to be voted on. ```go type Proposal struct { @@ -98,7 +98,7 @@ type Proposal struct { SubmitTime time.Time // Time of the block where TxGovSubmitProposal was included DepositEndTime time.Time // Time that the DepositPeriod of a proposal would expire Submitter sdk.AccAddress // Address of the submitter - + VotingStartTime time.Time // Time of the block where MinDeposit was reached. time.Time{} if MinDeposit is not reached VotingEndTime time.Time // Time of the block that the VotingPeriod for a proposal will end. CurrentStatus ProposalStatus // Current status of the proposal @@ -134,7 +134,7 @@ For pseudocode purposes, here are the two function we will use to read or write ### Proposal Processing Queue **Store:** -* `ProposalProcessingQueue`: A queue `queue[proposalID]` containing all the +* `ProposalProcessingQueue`: A queue `queue[proposalID]` containing all the `ProposalIDs` of proposals that reached `MinDeposit`. Each `EndBlock`, all the proposals that have reached the end of their voting period are processed. To process a finished proposal, the application tallies the votes, compute the votes of @@ -144,8 +144,8 @@ For pseudocode purposes, here are the two function we will use to read or write And the pseudocode for the `ProposalProcessingQueue`: ```go - in EndBlock do - + in EndBlock do + for finishedProposalID in GetAllFinishedProposalIDs(block.Time) proposal = load(Governance, ) // proposal is a const key @@ -170,7 +170,7 @@ And the pseudocode for the `ProposalProcessingQueue`: if (isVal) tmpValMap(voterAddress).Vote = vote - tallyingProcedure = load(GlobalParams, 'TallyingProcedure') + tallyingParam = load(GlobalParams, 'TallyingParam') // Update tally if validator voted they voted for each validator in validators @@ -181,14 +181,14 @@ And the pseudocode for the `ProposalProcessingQueue`: // Check if proposal is accepted or rejected totalNonAbstain := proposal.YesVotes + proposal.NoVotes + proposal.NoWithVetoVotes - if (proposal.Votes.YesVotes/totalNonAbstain > tallyingProcedure.Threshold AND proposal.Votes.NoWithVetoVotes/totalNonAbstain < tallyingProcedure.Veto) + if (proposal.Votes.YesVotes/totalNonAbstain > tallyingParam.Threshold AND proposal.Votes.NoWithVetoVotes/totalNonAbstain < tallyingParam.Veto) // proposal was accepted at the end of the voting period // refund deposits (non-voters already punished) proposal.CurrentStatus = ProposalStatusAccepted for each (amount, depositer) in proposal.Deposits depositer.AtomBalance += amount - else + else // proposal was rejected proposal.CurrentStatus = ProposalStatusRejected diff --git a/docs/spec/governance/transactions.md b/docs/spec/governance/transactions.md index f3636facda75..68966bcfc45c 100644 --- a/docs/spec/governance/transactions.md +++ b/docs/spec/governance/transactions.md @@ -4,7 +4,7 @@ ### Proposal Submission -Proposals can be submitted by any Atom holder via a `TxGovSubmitProposal` +Proposals can be submitted by any Atom holder via a `TxGovSubmitProposal` transaction. ```go @@ -24,7 +24,7 @@ type TxGovSubmitProposal struct { * If `MinDeposit` is reached: * Push `proposalID` in `ProposalProcessingQueue` -A `TxGovSubmitProposal` transaction can be handled according to the following +A `TxGovSubmitProposal` transaction can be handled according to the following pseudocode. ```go @@ -32,31 +32,31 @@ pseudocode. // Check if TxGovSubmitProposal is valid. If it is, create proposal // upon receiving txGovSubmitProposal from sender do - - if !correctlyFormatted(txGovSubmitProposal) + + if !correctlyFormatted(txGovSubmitProposal) // check if proposal is correctly formatted. Includes fee payment. throw - - initialDeposit = txGovSubmitProposal.InitialDeposit - if (initialDeposit.Atoms <= 0) OR (sender.AtomBalance < initialDeposit.Atoms) + + initialDeposit = txGovSubmitProposal.InitialDeposit + if (initialDeposit.Atoms <= 0) OR (sender.AtomBalance < initialDeposit.Atoms) // InitialDeposit is negative or null OR sender has insufficient funds throw if (txGovSubmitProposal.Type != ProposalTypePlainText) OR (txGovSubmitProposal.Type != ProposalTypeSoftwareUpgrade) - + sender.AtomBalance -= initialDeposit.Atoms - depositProcedure = load(GlobalParams, 'DepositProcedure') - + depositParam = load(GlobalParams, 'DepositParam') + proposalID = generate new proposalID proposal = NewProposal() - + proposal.Title = txGovSubmitProposal.Title proposal.Description = txGovSubmitProposal.Description proposal.Type = txGovSubmitProposal.Type proposal.TotalDeposit = initialDeposit proposal.SubmitTime = - proposal.DepositEndTime = .Add(depositProcedure.MaxDepositPeriod) + proposal.DepositEndTime = .Add(depositParam.MaxDepositPeriod) proposal.Deposits.append({initialDeposit, sender}) proposal.Submitter = sender proposal.YesVotes = 0 @@ -64,15 +64,15 @@ upon receiving txGovSubmitProposal from sender do proposal.NoWithVetoVotes = 0 proposal.AbstainVotes = 0 proposal.CurrentStatus = ProposalStatusOpen - + store(Proposals, , proposal) // Store proposal in Proposals mapping return proposalID ``` ### Deposit -Once a proposal is submitted, if -`Proposal.TotalDeposit < ActiveProcedure.MinDeposit`, Atom holders can send +Once a proposal is submitted, if +`Proposal.TotalDeposit < ActiveParam.MinDeposit`, Atom holders can send `TxGovDeposit` transactions to increase the proposal's deposit. ```go @@ -89,7 +89,7 @@ type TxGovDeposit struct { * If `MinDeposit` is reached: * Push `proposalID` in `ProposalProcessingQueueEnd` -A `TxGovDeposit` transaction has to go through a number of checks to be valid. +A `TxGovDeposit` transaction has to go through a number of checks to be valid. These checks are outlined in the following pseudocode. ```go @@ -98,27 +98,27 @@ These checks are outlined in the following pseudocode. upon receiving txGovDeposit from sender do // check if proposal is correctly formatted. Includes fee payment. - - if !correctlyFormatted(txGovDeposit) + + if !correctlyFormatted(txGovDeposit) throw - + proposal = load(Proposals, ) // proposal is a const key, proposalID is variable - if (proposal == nil) + if (proposal == nil) // There is no proposal for this proposalID throw - + if (txGovDeposit.Deposit.Atoms <= 0) ORĀ (sender.AtomBalance < txGovDeposit.Deposit.Atoms) OR (proposal.CurrentStatus != ProposalStatusOpen) - // deposit is negative or null + // deposit is negative or null // OR sender has insufficient funds // OR proposal is not open for deposit anymore throw - depositProcedure = load(GlobalParams, 'DepositProcedure') + depositParam = load(GlobalParams, 'DepositParam') - if (CurrentBlock >= proposal.SubmitBlock + depositProcedure.MaxDepositPeriod) + if (CurrentBlock >= proposal.SubmitBlock + depositParam.MaxDepositPeriod) proposal.CurrentStatus = ProposalStatusClosed else @@ -127,21 +127,21 @@ upon receiving txGovDeposit from sender do proposal.Deposits.append({txGovVote.Deposit, sender}) proposal.TotalDeposit.Plus(txGovDeposit.Deposit) - - if (proposal.TotalDeposit >= depositProcedure.MinDeposit) + + if (proposal.TotalDeposit >= depositParam.MinDeposit) // MinDeposit is reached, vote opens - + proposal.VotingStartBlock = CurrentBlock proposal.CurrentStatus = ProposalStatusActive - ProposalProcessingQueue.push(txGovDeposit.ProposalID) + ProposalProcessingQueue.push(txGovDeposit.ProposalID) store(Proposals, , proposal) ``` ### Vote -Once `ActiveProcedure.MinDeposit` is reached, voting period starts. From there, -bonded Atom holders are able to send `TxGovVote` transactions to cast their +Once `ActiveParam.MinDeposit` is reached, voting period starts. From there, +bonded Atom holders are able to send `TxGovVote` transactions to cast their vote on the proposal. ```go @@ -157,25 +157,25 @@ vote on the proposal. *Note: Gas cost for this message has to take into account the future tallying of the vote in EndBlocker* -Next is a pseudocode proposal of the way `TxGovVote` transactions are +Next is a pseudocode proposal of the way `TxGovVote` transactions are handled: ```go // PSEUDOCODE // // Check if TxGovVote is valid. If it is, count vote// - + upon receiving txGovVote from sender do - // check if proposal is correctly formatted. Includes fee payment. - - if !correctlyFormatted(txGovDeposit) + // check if proposal is correctly formatted. Includes fee payment. + + if !correctlyFormatted(txGovDeposit) throw - + proposal = load(Proposals, ) - if (proposal == nil) + if (proposal == nil) // There is no proposal for this proposalID throw - + if (proposal.CurrentStatus == ProposalStatusActive) diff --git a/x/gov/client/cli/tx.go b/x/gov/client/cli/tx.go index 1f619885ec2c..383dd1678e08 100644 --- a/x/gov/client/cli/tx.go +++ b/x/gov/client/cli/tx.go @@ -250,7 +250,7 @@ func GetCmdVote(cdc *codec.Codec) *cobra.Command { } // GetCmdQueryProposal implements the query proposal command. -func GetCmdQueryProcedure(queryRoute string, cdc *codec.Codec) *cobra.Command { +func GetCmdQueryParam(queryRoute string, cdc *codec.Codec) *cobra.Command { cmd := &cobra.Command{ Use: "procedure [procedure-type]", Short: "Query the procedure parameters of the governance process", diff --git a/x/gov/keeper.go b/x/gov/keeper.go index 862db82744ac..4f370ef531e6 100644 --- a/x/gov/keeper.go +++ b/x/gov/keeper.go @@ -250,7 +250,7 @@ func (keeper Keeper) GetDepositParams(ctx sdk.Context) DepositParams { return depositParams } -// Returns the current Voting Procedure from the global param store +// Returns the current VotingParams from the global param store // nolint: errcheck func (keeper Keeper) GetVotingParams(ctx sdk.Context) VotingParams { var votingParams VotingParams @@ -258,7 +258,7 @@ func (keeper Keeper) GetVotingParams(ctx sdk.Context) VotingParams { return votingParams } -// Returns the current Tallying Procedure from the global param store +// Returns the current TallyParam from the global param store // nolint: errcheck func (keeper Keeper) GetTallyParams(ctx sdk.Context) TallyParams { var tallyParams TallyParams diff --git a/x/gov/params.go b/x/gov/params.go index 4d8126d14137..b9e1efa87805 100644 --- a/x/gov/params.go +++ b/x/gov/params.go @@ -6,20 +6,20 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" ) -// Procedure around Deposits for governance +// Param around Deposits for governance type DepositParams struct { MinDeposit sdk.Coins `json:"min_deposit"` // Minimum deposit for a proposal to enter voting period. MaxDepositPeriod time.Duration `json:"max_deposit_period"` // Maximum period for Atom holders to deposit on a proposal. Initial value: 2 months } -// Procedure around Tallying votes in governance +// Param around Tallying votes in governance type TallyParams struct { Threshold sdk.Dec `json:"threshold"` // Minimum propotion of Yes votes for proposal to pass. Initial value: 0.5 Veto sdk.Dec `json:"veto"` // Minimum value of Veto votes to Total votes ratio for proposal to be vetoed. Initial value: 1/3 GovernancePenalty sdk.Dec `json:"governance_penalty"` // Penalty if validator does not vote } -// Procedure around Voting in governance +// Param around Voting in governance type VotingParams struct { VotingPeriod time.Duration `json:"voting_period"` // Length of the voting period. } diff --git a/x/gov/queryable.go b/x/gov/queryable.go index 467a9a319ea9..987821515aea 100644 --- a/x/gov/queryable.go +++ b/x/gov/queryable.go @@ -19,9 +19,9 @@ const ( QueryVote = "vote" QueryTally = "tally" - ProcedureDeposit = "deposit" - ProcedureVoting = "voting" - ProcedureTallying = "tallying" + ParamDeposit = "deposit" + ParamVoting = "voting" + ParamTallying = "tallying" ) func NewQuerier(keeper Keeper) sdk.Querier { @@ -51,21 +51,21 @@ func NewQuerier(keeper Keeper) sdk.Querier { func queryParams(ctx sdk.Context, path []string, req abci.RequestQuery, keeper Keeper) (res []byte, err sdk.Error) { switch path[0] { - case ProcedureDeposit: + case ParamDeposit: bz, err2 := codec.MarshalJSONIndent(keeper.cdc, keeper.GetDepositParams(ctx)) if err2 != nil { return nil, sdk.ErrInternal(sdk.AppendMsgToErr("could not marshal result to JSON", err2.Error())) } return bz, nil - case ProcedureVoting: + case ParamVoting: bz, err2 := codec.MarshalJSONIndent(keeper.cdc, keeper.GetVotingParams(ctx)) if err2 != nil { return nil, sdk.ErrInternal(sdk.AppendMsgToErr("could not marshal result to JSON", err2.Error())) } return bz, nil - case ProcedureTallying: + case ParamTallying: bz, err2 := codec.MarshalJSONIndent(keeper.cdc, keeper.GetTallyParams(ctx)) if err2 != nil { return nil, sdk.ErrInternal(sdk.AppendMsgToErr("could not marshal result to JSON", err2.Error())) From 899b9585af5eb8377df7870c28409f69775c34bb Mon Sep 17 00:00:00 2001 From: Federico Kunze Date: Mon, 12 Nov 2018 20:34:13 +0100 Subject: [PATCH 11/16] missing renaming in cli test --- cmd/gaia/cli_test/cli_test.go | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/cmd/gaia/cli_test/cli_test.go b/cmd/gaia/cli_test/cli_test.go index d2261fd7bfc6..907b3d7458a2 100644 --- a/cmd/gaia/cli_test/cli_test.go +++ b/cmd/gaia/cli_test/cli_test.go @@ -312,9 +312,9 @@ func TestGaiaCLISubmitProposal(t *testing.T) { tests.WaitForTMStart(port) tests.WaitForNextNBlocksTM(2, port) - executeGetDepositProcedure(t, fmt.Sprintf("gaiacli query procedure deposit %v", flags)) - executeGetVotingProcedure(t, fmt.Sprintf("gaiacli query procedure voting %v", flags)) - executeGetTallyingProcedure(t, fmt.Sprintf("gaiacli query procedure tallying %v", flags)) + executeGetDepositParam(t, fmt.Sprintf("gaiacli query procedure deposit %v", flags)) + executeGetVotingParam(t, fmt.Sprintf("gaiacli query procedure voting %v", flags)) + executeGetTallyingParam(t, fmt.Sprintf("gaiacli query procedure tallying %v", flags)) fooAddr, _ := executeGetAddrPK(t, fmt.Sprintf("gaiacli keys show foo --output=json --home=%s", gaiacliHome)) @@ -775,31 +775,31 @@ func executeGetParams(t *testing.T, cmdStr string) stake.Params { //___________________________________________________________________________________ // gov -func executeGetDepositProcedure(t *testing.T, cmdStr string) gov.DepositParams { +func executeGetDepositParam(t *testing.T, cmdStr string) gov.DepositParams { out, _ := tests.ExecuteT(t, cmdStr, "") - var depositProcedure gov.DepositParams + var depositParam gov.DepositParams cdc := app.MakeCodec() - err := cdc.UnmarshalJSON([]byte(out), &depositProcedure) + err := cdc.UnmarshalJSON([]byte(out), &depositParam) require.NoError(t, err, "out %v\n, err %v", out, err) - return depositProcedure + return depositParam } -func executeGetVotingProcedure(t *testing.T, cmdStr string) gov.VotingParams { +func executeGetVotingParam(t *testing.T, cmdStr string) gov.VotingParams { out, _ := tests.ExecuteT(t, cmdStr, "") - var votingProcedure gov.VotingParams + var votingParam gov.VotingParams cdc := app.MakeCodec() - err := cdc.UnmarshalJSON([]byte(out), &votingProcedure) + err := cdc.UnmarshalJSON([]byte(out), &votingParam) require.NoError(t, err, "out %v\n, err %v", out, err) - return votingProcedure + return votingParam } -func executeGetTallyingProcedure(t *testing.T, cmdStr string) gov.TallyParams { +func executeGetTallyingParam(t *testing.T, cmdStr string) gov.TallyParams { out, _ := tests.ExecuteT(t, cmdStr, "") - var tallyingProcedure gov.TallyParams + var tallyingParam gov.TallyParams cdc := app.MakeCodec() - err := cdc.UnmarshalJSON([]byte(out), &tallyingProcedure) + err := cdc.UnmarshalJSON([]byte(out), &tallyingParam) require.NoError(t, err, "out %v\n, err %v", out, err) - return tallyingProcedure + return tallyingParam } func executeGetProposal(t *testing.T, cmdStr string) gov.Proposal { From c00a43dba62ebbbb8ed6fe25e2da30d62ca76d72 Mon Sep 17 00:00:00 2001 From: Federico Kunze Date: Mon, 12 Nov 2018 20:50:49 +0100 Subject: [PATCH 12/16] more renaming --- cmd/gaia/cli_test/cli_test.go | 6 +++--- cmd/gaia/cmd/gaiacli/main.go | 2 +- x/gov/client/cli/tx.go | 10 +++++----- x/gov/client/rest/rest.go | 4 ++-- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/cmd/gaia/cli_test/cli_test.go b/cmd/gaia/cli_test/cli_test.go index 907b3d7458a2..304f1bad907f 100644 --- a/cmd/gaia/cli_test/cli_test.go +++ b/cmd/gaia/cli_test/cli_test.go @@ -312,9 +312,9 @@ func TestGaiaCLISubmitProposal(t *testing.T) { tests.WaitForTMStart(port) tests.WaitForNextNBlocksTM(2, port) - executeGetDepositParam(t, fmt.Sprintf("gaiacli query procedure deposit %v", flags)) - executeGetVotingParam(t, fmt.Sprintf("gaiacli query procedure voting %v", flags)) - executeGetTallyingParam(t, fmt.Sprintf("gaiacli query procedure tallying %v", flags)) + executeGetDepositParam(t, fmt.Sprintf("gaiacli query param deposit %v", flags)) + executeGetVotingParam(t, fmt.Sprintf("gaiacli query param voting %v", flags)) + executeGetTallyingParam(t, fmt.Sprintf("gaiacli query param tallying %v", flags)) fooAddr, _ := executeGetAddrPK(t, fmt.Sprintf("gaiacli keys show foo --output=json --home=%s", gaiacliHome)) diff --git a/cmd/gaia/cmd/gaiacli/main.go b/cmd/gaia/cmd/gaiacli/main.go index 13e633b7d0b8..feafe8ff1f1c 100644 --- a/cmd/gaia/cmd/gaiacli/main.go +++ b/cmd/gaia/cmd/gaiacli/main.go @@ -88,7 +88,7 @@ func main() { stakecmd.GetCmdQueryValidatorRedelegations(queryRouteStake, cdc), stakecmd.GetCmdQueryParams(storeStake, cdc), stakecmd.GetCmdQueryPool(storeStake, cdc), - govcmd.GetCmdQueryParam(storeGov, cdc), + govcmd.GetCmdQueryParams(storeGov, cdc), govcmd.GetCmdQueryProposal(storeGov, cdc), govcmd.GetCmdQueryProposals(storeGov, cdc), govcmd.GetCmdQueryVote(storeGov, cdc), diff --git a/x/gov/client/cli/tx.go b/x/gov/client/cli/tx.go index 383dd1678e08..5601b10e7975 100644 --- a/x/gov/client/cli/tx.go +++ b/x/gov/client/cli/tx.go @@ -250,17 +250,17 @@ func GetCmdVote(cdc *codec.Codec) *cobra.Command { } // GetCmdQueryProposal implements the query proposal command. -func GetCmdQueryParam(queryRoute string, cdc *codec.Codec) *cobra.Command { +func GetCmdQueryParams(queryRoute string, cdc *codec.Codec) *cobra.Command { cmd := &cobra.Command{ - Use: "procedure [procedure-type]", - Short: "Query the procedure parameters of the governance process", + Use: "param [param-type]", + Short: "Query the parameters of the governance process", Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { - procedureType := args[0] + paramType := args[0] cliCtx := context.NewCLIContext().WithCodec(cdc) - res, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/procedure/%s", queryRoute, procedureType), nil) + res, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/params/%s", queryRoute, paramType), nil) if err != nil { return err } diff --git a/x/gov/client/rest/rest.go b/x/gov/client/rest/rest.go index ee019ace3914..930a39b025c7 100644 --- a/x/gov/client/rest/rest.go +++ b/x/gov/client/rest/rest.go @@ -186,9 +186,9 @@ func voteHandlerFn(cdc *codec.Codec, cliCtx context.CLIContext) http.HandlerFunc func queryParamsHandlerFn(cdc *codec.Codec, cliCtx context.CLIContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) - procedureType := vars[RestParamsType] + paramType := vars[RestParamsType] - res, err := cliCtx.QueryWithData(fmt.Sprintf("custom/gov/%s/%s", gov.QueryParams, procedureType), nil) + res, err := cliCtx.QueryWithData(fmt.Sprintf("custom/gov/%s/%s", gov.QueryParams, paramType), nil) if err != nil { utils.WriteErrorResponse(w, http.StatusNotFound, err.Error()) return From e206b555f70bae1dfa2a69c2ddb0bb85c8a91a8d Mon Sep 17 00:00:00 2001 From: Federico Kunze Date: Mon, 12 Nov 2018 21:26:10 +0100 Subject: [PATCH 13/16] swagger and move return value to default --- client/lcd/swagger-ui/swagger.yaml | 79 +++++++++++++++++++++++++++++- x/gov/queryable.go | 6 +-- 2 files changed, 80 insertions(+), 5 deletions(-) diff --git a/client/lcd/swagger-ui/swagger.yaml b/client/lcd/swagger-ui/swagger.yaml index 86b6ec6813fa..8e9da25f01ee 100644 --- a/client/lcd/swagger-ui/swagger.yaml +++ b/client/lcd/swagger-ui/swagger.yaml @@ -1427,7 +1427,7 @@ paths: /gov/proposals/{proposalId}/votes/{voter}: get: summary: Query vote - description: Query vote information by proposalId and voter address + description: Query vote information by proposal Id and voter address produces: - application/json tags: @@ -1454,6 +1454,83 @@ paths: description: Found no vote 500: description: Internal Server Error + /gov/parameters/deposit: + get: + summary: Query governance deposit parameters + description: Query governance deposit parameters. The max_deposit_period units are in nanoseconds. + produces: + - application/json + tags: + - ICS22 + responses: + 200: + description: OK + schema: + type: object + properties: + min_deposit: + type: array + items: + $ref: "#/definitions/Coin" + max_deposit_period: + type: string + example: "86400000000000" + 400: + description: is not a valid query request path + 404: + description: Found no deposit parameters + 500: + description: Internal Server Error + /gov/parameters/tallying: + get: + summary: Query governance tally parameters + description: Query governance tally parameters + produces: + - application/json + tags: + - ICS22 + responses: + 200: + description: OK + schema: + properties: + threshold: + type: string + example: "0.5000000000" + veto: + type: string + example: "0.3340000000" + governance_penalty: + type: string + example: "0.0100000000" + 400: + description: is not a valid query request path + 404: + description: Found no tally parameters + 500: + description: Internal Server Error + /gov/parameters/voting: + get: + summary: Query governance voting parameters + description: Query governance voting parameters. The voting_period units are in nanoseconds. + produces: + - application/json + tags: + - ICS22 + responses: + 200: + description: OK + schema: + properties: + voting_period: + type: string + example: "86400000000000" + 400: + description: is not a valid query request path + 404: + description: Found no voting parameters + 500: + description: Internal Server Error definitions: CheckTxResult: diff --git a/x/gov/queryable.go b/x/gov/queryable.go index 987821515aea..171ab469d551 100644 --- a/x/gov/queryable.go +++ b/x/gov/queryable.go @@ -57,23 +57,21 @@ func queryParams(ctx sdk.Context, path []string, req abci.RequestQuery, keeper K return nil, sdk.ErrInternal(sdk.AppendMsgToErr("could not marshal result to JSON", err2.Error())) } return bz, nil - case ParamVoting: bz, err2 := codec.MarshalJSONIndent(keeper.cdc, keeper.GetVotingParams(ctx)) if err2 != nil { return nil, sdk.ErrInternal(sdk.AppendMsgToErr("could not marshal result to JSON", err2.Error())) } return bz, nil - case ParamTallying: bz, err2 := codec.MarshalJSONIndent(keeper.cdc, keeper.GetTallyParams(ctx)) if err2 != nil { return nil, sdk.ErrInternal(sdk.AppendMsgToErr("could not marshal result to JSON", err2.Error())) } return bz, nil + default: + return res, sdk.ErrUnknownRequest(fmt.Sprintf("%s is not a valid query request path", req.Path)) } - - return res, sdk.ErrUnknownRequest(fmt.Sprintf("%s is not a valid query request path", req.Path)) } // Params for query 'custom/gov/proposal' From c2480903872f648d544803441c251633615b26a0 Mon Sep 17 00:00:00 2001 From: Federico Kunze Date: Mon, 12 Nov 2018 21:30:19 +0100 Subject: [PATCH 14/16] delete dot --- docs/spec/governance/state.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/spec/governance/state.md b/docs/spec/governance/state.md index f2a1467a97bd..3858ba06b69f 100644 --- a/docs/spec/governance/state.md +++ b/docs/spec/governance/state.md @@ -60,7 +60,7 @@ const ( ProposalStatusActive = 0x2 // MinDeposit is reachhed, participants can vote ProposalStatusAccepted = 0x3 // Proposal has been accepted ProposalStatusRejected = 0x4 // Proposal has been rejected - ProposalStatusClosed. = 0x5 // Proposal never reached MinDeposit + ProposalStatusClosed = 0x5 // Proposal never reached MinDeposit ) ``` From 816531b494dc9ef16f792047c30cf41ad18961dc Mon Sep 17 00:00:00 2001 From: Sunny Aggarwal Date: Tue, 13 Nov 2018 14:39:53 -0800 Subject: [PATCH 15/16] added gov querier tests --- client/lcd/test_helpers.go | 5 +- x/gov/{queryable.go => querier.go} | 0 x/gov/querier_test.go | 306 +++++++++++++++++++++++++++++ x/gov/test_common.go | 1 + x/mock/app.go | 57 +++++- 5 files changed, 360 insertions(+), 9 deletions(-) rename x/gov/{queryable.go => querier.go} (100%) create mode 100644 x/gov/querier_test.go diff --git a/client/lcd/test_helpers.go b/client/lcd/test_helpers.go index 39c76865cc0a..5089b3188ba4 100644 --- a/client/lcd/test_helpers.go +++ b/client/lcd/test_helpers.go @@ -4,8 +4,6 @@ import ( "bytes" "encoding/json" "fmt" - "github.com/cosmos/cosmos-sdk/x/stake" - "github.com/tendermint/tendermint/crypto/secp256k1" "io/ioutil" "net" "net/http" @@ -15,6 +13,9 @@ import ( "strings" "testing" + "github.com/cosmos/cosmos-sdk/x/stake" + "github.com/tendermint/tendermint/crypto/secp256k1" + "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/keys" gapp "github.com/cosmos/cosmos-sdk/cmd/gaia/app" diff --git a/x/gov/queryable.go b/x/gov/querier.go similarity index 100% rename from x/gov/queryable.go rename to x/gov/querier.go diff --git a/x/gov/querier_test.go b/x/gov/querier_test.go new file mode 100644 index 000000000000..eee58d2ac192 --- /dev/null +++ b/x/gov/querier_test.go @@ -0,0 +1,306 @@ +package gov + +import ( + "strings" + "testing" + + "github.com/cosmos/cosmos-sdk/codec" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/stretchr/testify/require" + abci "github.com/tendermint/tendermint/abci/types" +) + +func getQueriedParams(t *testing.T, ctx sdk.Context, cdc *codec.Codec, querier sdk.Querier) (DepositParams, VotingParams, TallyParams) { + query := abci.RequestQuery{ + Path: strings.Join([]string{"custom", "gov", QueryParams, ParamDeposit}, "/"), + Data: []byte{}, + } + + bz, err := querier(ctx, []string{QueryParams, ParamDeposit}, query) + require.Nil(t, err) + require.NotNil(t, bz) + + var depositParams DepositParams + err2 := cdc.UnmarshalJSON(bz, &depositParams) + require.Nil(t, err2) + + query = abci.RequestQuery{ + Path: strings.Join([]string{"custom", "gov", QueryParams, ParamVoting}, "/"), + Data: []byte{}, + } + + bz, err = querier(ctx, []string{QueryParams, ParamVoting}, query) + require.Nil(t, err) + require.NotNil(t, bz) + + var votingParams VotingParams + err2 = cdc.UnmarshalJSON(bz, &votingParams) + require.Nil(t, err2) + + query = abci.RequestQuery{ + Path: strings.Join([]string{"custom", "gov", QueryParams, ParamTallying}, "/"), + Data: []byte{}, + } + + bz, err = querier(ctx, []string{QueryParams, ParamTallying}, query) + require.Nil(t, err) + require.NotNil(t, bz) + + var tallyParams TallyParams + err2 = cdc.UnmarshalJSON(bz, &tallyParams) + require.Nil(t, err2) + + return depositParams, votingParams, tallyParams +} + +func getQueriedProposal(t *testing.T, ctx sdk.Context, cdc *codec.Codec, querier sdk.Querier, proposalID uint64) Proposal { + query := abci.RequestQuery{ + Path: strings.Join([]string{"custom", "gov", QueryProposal}, "/"), + Data: cdc.MustMarshalJSON(QueryProposalParams{ + ProposalID: proposalID, + }), + } + + bz, err := querier(ctx, []string{QueryProposal}, query) + require.Nil(t, err) + require.NotNil(t, bz) + + var proposal Proposal + err2 := cdc.UnmarshalJSON(bz, proposal) + require.Nil(t, err2) + return proposal +} + +func getQueriedProposals(t *testing.T, ctx sdk.Context, cdc *codec.Codec, querier sdk.Querier, depositer, voter sdk.AccAddress, status ProposalStatus, limit uint64) []Proposal { + query := abci.RequestQuery{ + Path: strings.Join([]string{"custom", "gov", QueryProposals}, "/"), + Data: cdc.MustMarshalJSON(QueryProposalsParams{ + Voter: voter, + Depositer: depositer, + ProposalStatus: status, + Limit: limit, + }), + } + + bz, err := querier(ctx, []string{QueryProposal}, query) + require.Nil(t, err) + require.NotNil(t, bz) + + var proposals []Proposal + err2 := cdc.UnmarshalJSON(bz, proposals) + require.Nil(t, err2) + return proposals +} + +func getQueriedDeposit(t *testing.T, ctx sdk.Context, cdc *codec.Codec, querier sdk.Querier, proposalID uint64, depositer sdk.AccAddress) Deposit { + query := abci.RequestQuery{ + Path: strings.Join([]string{"custom", "gov", QueryDeposit}, "/"), + Data: cdc.MustMarshalJSON(QueryDepositParams{ + ProposalID: proposalID, + Depositer: depositer, + }), + } + + bz, err := querier(ctx, []string{QueryDeposits}, query) + require.Nil(t, err) + require.NotNil(t, bz) + + var deposit Deposit + err2 := cdc.UnmarshalJSON(bz, deposit) + require.Nil(t, err2) + return deposit +} + +func getQueriedDeposits(t *testing.T, ctx sdk.Context, cdc *codec.Codec, querier sdk.Querier, proposalID uint64) []Deposit { + query := abci.RequestQuery{ + Path: strings.Join([]string{"custom", "gov", QueryDeposits}, "/"), + Data: cdc.MustMarshalJSON(QueryDepositsParams{ + ProposalID: proposalID, + }), + } + + bz, err := querier(ctx, []string{QueryDeposits}, query) + require.Nil(t, err) + require.NotNil(t, bz) + + var deposits []Deposit + err2 := cdc.UnmarshalJSON(bz, &deposits) + require.Nil(t, err2) + return deposits +} + +func getQueriedVote(t *testing.T, ctx sdk.Context, cdc *codec.Codec, querier sdk.Querier, proposalID uint64, voter sdk.AccAddress) Vote { + query := abci.RequestQuery{ + Path: strings.Join([]string{"custom", "gov", QueryVote}, "/"), + Data: cdc.MustMarshalJSON(QueryVoteParams{ + ProposalID: proposalID, + Voter: voter, + }), + } + + bz, err := querier(ctx, []string{QueryVote}, query) + require.Nil(t, err) + require.NotNil(t, bz) + + var vote Vote + err2 := cdc.UnmarshalJSON(bz, &vote) + require.Nil(t, err2) + return vote +} + +func getQueriedVotes(t *testing.T, ctx sdk.Context, cdc *codec.Codec, querier sdk.Querier, proposalID uint64) []Vote { + query := abci.RequestQuery{ + Path: strings.Join([]string{"custom", "gov", QueryVote}, "/"), + Data: cdc.MustMarshalJSON(QueryVotesParams{ + ProposalID: proposalID, + }), + } + + bz, err := querier(ctx, []string{QueryVotes}, query) + require.Nil(t, err) + require.NotNil(t, bz) + + var votes []Vote + err2 := cdc.UnmarshalJSON(bz, &votes) + require.Nil(t, err2) + return votes +} + +func getQueriedTally(t *testing.T, ctx sdk.Context, cdc *codec.Codec, querier sdk.Querier, proposalID uint64) TallyResult { + query := abci.RequestQuery{ + Path: strings.Join([]string{"custom", "gov", QueryTally}, "/"), + Data: cdc.MustMarshalJSON(QueryTallyParams{ + ProposalID: proposalID, + }), + } + + bz, err := querier(ctx, []string{QueryTally}, query) + require.Nil(t, err) + require.NotNil(t, bz) + + var tally TallyResult + err2 := cdc.UnmarshalJSON(bz, &tally) + require.Nil(t, err2) + return tally +} + +func testQueryParams(t *testing.T) { + cdc := codec.New() + mapp, keeper, _, _, _, _ := getMockApp(t, 1000) + querier := NewQuerier(keeper) + ctx := mapp.NewContext(false, abci.Header{}) + + getQueriedParams(t, ctx, cdc, querier) +} + +func testQueries(t *testing.T) { + cdc := codec.New() + mapp, keeper, _, addrs, _, _ := getMockApp(t, 1000) + querier := NewQuerier(keeper) + handler := NewHandler(keeper) + ctx := mapp.NewContext(false, abci.Header{}) + + depositParams, _, _ := getQueriedParams(t, ctx, cdc, querier) + + // addrs[0] proposes (and deposits) proposals #1 and #2 + res := handler(ctx, NewMsgSubmitProposal("title", "description", ProposalTypeText, addrs[0], sdk.Coins{sdk.NewInt64Coin("dummycoin", 1)})) + var proposalID1 uint64 + cdc.MustUnmarshalBinaryLengthPrefixed(res.Data, &proposalID1) + + res = handler(ctx, NewMsgSubmitProposal("title", "description", ProposalTypeText, addrs[0], sdk.Coins{sdk.NewInt64Coin("dummycoin", 1)})) + var proposalID2 uint64 + cdc.MustUnmarshalBinaryLengthPrefixed(res.Data, &proposalID2) + + // addrs[1] proposes (and deposits) proposals #3 + res = handler(ctx, NewMsgSubmitProposal("title", "description", ProposalTypeText, addrs[1], sdk.Coins{sdk.NewInt64Coin("dummycoin", 1)})) + var proposalID3 uint64 + cdc.MustUnmarshalBinaryLengthPrefixed(res.Data, &proposalID3) + + // addrs[1] deposits on proposals #2 & #3 + res = handler(ctx, NewMsgDeposit(addrs[1], proposalID2, depositParams.MinDeposit)) + res = handler(ctx, NewMsgDeposit(addrs[1], proposalID3, depositParams.MinDeposit)) + + // check deposits on proposal1 match individual deposits + deposits := getQueriedDeposits(t, ctx, cdc, querier, proposalID1) + require.Len(t, deposits, 1) + deposit := getQueriedDeposit(t, ctx, cdc, querier, proposalID1, addrs[0]) + require.Equal(t, deposit, deposits[0]) + + // check deposits on proposal2 match individual deposits + deposits = getQueriedDeposits(t, ctx, cdc, querier, proposalID2) + require.Len(t, deposits, 2) + deposit = getQueriedDeposit(t, ctx, cdc, querier, proposalID2, addrs[0]) + require.True(t, deposit.Equals(deposits[0])) + deposit = getQueriedDeposit(t, ctx, cdc, querier, proposalID2, addrs[1]) + require.True(t, deposit.Equals(deposits[1])) + + // check deposits on proposal3 match individual deposits + deposits = getQueriedDeposits(t, ctx, cdc, querier, proposalID3) + require.Len(t, deposits, 1) + deposit = getQueriedDeposit(t, ctx, cdc, querier, proposalID3, addrs[1]) + require.Equal(t, deposit, deposits[0]) + + // Only proposal #1 should be in Deposit Period + proposals := getQueriedProposals(t, ctx, cdc, querier, nil, nil, StatusDepositPeriod, 0) + require.Len(t, proposals, 1) + require.Equal(t, proposalID1, proposals[0].GetProposalID()) + // Only proposals #2 and #3 should be in Voting Period + proposals = getQueriedProposals(t, ctx, cdc, querier, nil, nil, StatusVotingPeriod, 0) + require.Len(t, proposals, 2) + require.Equal(t, proposalID2, proposals[0].GetProposalID()) + require.Equal(t, proposalID3, proposals[1].GetProposalID()) + + // Addrs[0] votes on proposals #2 & #3 + handler(ctx, NewMsgVote(addrs[0], proposalID2, OptionYes)) + handler(ctx, NewMsgVote(addrs[0], proposalID3, OptionYes)) + + // Addrs[1] votes on proposal #3 + handler(ctx, NewMsgVote(addrs[1], proposalID3, OptionYes)) + + // Test query voted by addrs[0] + proposals = getQueriedProposals(t, ctx, cdc, querier, nil, addrs[0], StatusNil, 0) + require.Equal(t, proposalID2, (proposals[0]).GetProposalID()) + require.Equal(t, proposalID3, (proposals[1]).GetProposalID()) + + // Test query votes on Proposal 2 + votes := getQueriedVotes(t, ctx, cdc, querier, proposalID2) + require.Len(t, votes, 1) + require.Equal(t, addrs[0], votes[0].Voter) + vote := getQueriedVote(t, ctx, cdc, querier, proposalID2, addrs[0]) + require.Equal(t, vote, votes[0]) + + // Test query votes on Proposal 3 + votes = getQueriedVotes(t, ctx, cdc, querier, proposalID3) + require.Len(t, votes, 2) + require.True(t, addrs[0].String() == votes[0].Voter.String()) + require.True(t, addrs[1].String() == votes[0].Voter.String()) + + // Test proposals queries with filters + + // Test query all proposals + proposals = getQueriedProposals(t, ctx, cdc, querier, nil, nil, StatusNil, 0) + require.Equal(t, proposalID1, (proposals[0]).GetProposalID()) + require.Equal(t, proposalID2, (proposals[1]).GetProposalID()) + require.Equal(t, proposalID3, (proposals[2]).GetProposalID()) + + // Test query voted by addrs[1] + proposals = getQueriedProposals(t, ctx, cdc, querier, nil, addrs[1], StatusNil, 0) + require.Equal(t, proposalID3, (proposals[0]).GetProposalID()) + + // Test query deposited by addrs[0] + proposals = getQueriedProposals(t, ctx, cdc, querier, addrs[0], nil, StatusNil, 0) + require.Equal(t, proposalID1, (proposals[0]).GetProposalID()) + + // Test query deposited by addr2 + proposals = getQueriedProposals(t, ctx, cdc, querier, addrs[1], nil, StatusNil, 0) + require.Equal(t, proposalID2, (proposals[0]).GetProposalID()) + require.Equal(t, proposalID3, (proposals[1]).GetProposalID()) + + // Test query voted AND deposited by addr1 + proposals = getQueriedProposals(t, ctx, cdc, querier, addrs[0], addrs[0], StatusNil, 0) + require.Equal(t, proposalID2, (proposals[0]).GetProposalID()) + + // Test Tally Query + tally := getQueriedTally(t, ctx, cdc, querier, proposalID2) + require.True(t, !tally.Equals(EmptyTallyResult())) +} diff --git a/x/gov/test_common.go b/x/gov/test_common.go index 82ae30358b53..38bf49ad04a2 100644 --- a/x/gov/test_common.go +++ b/x/gov/test_common.go @@ -38,6 +38,7 @@ func getMockApp(t *testing.T, numGenAccs int) (*mock.App, Keeper, stake.Keeper, keeper := NewKeeper(mapp.Cdc, keyGov, pk, pk.Subspace("testgov"), ck, sk, DefaultCodespace) mapp.Router().AddRoute("gov", NewHandler(keeper)) + mapp.QueryRouter().AddRoute("gov", NewQuerier(keeper)) mapp.SetEndBlocker(getEndBlocker(keeper)) mapp.SetInitChainer(getInitChainer(mapp, keeper, sk)) diff --git a/x/mock/app.go b/x/mock/app.go index 627434a513d9..0b7b0ae16bf0 100644 --- a/x/mock/app.go +++ b/x/mock/app.go @@ -1,9 +1,11 @@ package mock import ( + "bytes" "fmt" "math/rand" "os" + "sort" bam "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/codec" @@ -109,23 +111,64 @@ func (app *App) InitChainer(ctx sdk.Context, _ abci.RequestInitChain) abci.Respo return abci.ResponseInitChain{} } +// Type that combines an Address with the privKey and pubKey to that address +type AddrKeys struct { + Address sdk.AccAddress + PubKey crypto.PubKey + PrivKey crypto.PrivKey +} + +// implement `Interface` in sort package. +type AddrKeysSlice []AddrKeys + +func (b AddrKeysSlice) Len() int { + return len(b) +} + +// Sorts lexographically by Address +func (b AddrKeysSlice) Less(i, j int) bool { + // bytes package already implements Comparable for []byte. + switch bytes.Compare(b[i].Address.Bytes(), b[j].Address.Bytes()) { + case -1: + return true + case 0, 1: + return false + default: + panic("not fail-able with `bytes.Comparable` bounded [-1, 1].") + } +} + +func (b AddrKeysSlice) Swap(i, j int) { + b[j], b[i] = b[i], b[j] +} + // CreateGenAccounts generates genesis accounts loaded with coins, and returns // their addresses, pubkeys, and privkeys. func CreateGenAccounts(numAccs int, genCoins sdk.Coins) (genAccs []auth.Account, addrs []sdk.AccAddress, pubKeys []crypto.PubKey, privKeys []crypto.PrivKey) { + addrKeysSlice := AddrKeysSlice{} + for i := 0; i < numAccs; i++ { privKey := ed25519.GenPrivKey() pubKey := privKey.PubKey() addr := sdk.AccAddress(pubKey.Address()) - genAcc := &auth.BaseAccount{ + addrKeysSlice = append(addrKeysSlice, AddrKeys{ Address: addr, - Coins: genCoins, - } + PubKey: pubKey, + PrivKey: privKey, + }) + } - genAccs = append(genAccs, genAcc) - privKeys = append(privKeys, privKey) - pubKeys = append(pubKeys, pubKey) - addrs = append(addrs, addr) + sort.Sort(addrKeysSlice) + + for i := range addrKeysSlice { + addrs = append(addrs, addrKeysSlice[i].Address) + pubKeys = append(pubKeys, addrKeysSlice[i].PubKey) + privKeys = append(privKeys, addrKeysSlice[i].PrivKey) + genAccs = append(genAccs, &auth.BaseAccount{ + Address: addrKeysSlice[i].Address, + Coins: genCoins, + }) } return From f94ae504a7030417cf5bf8676ca35aa681162b0a Mon Sep 17 00:00:00 2001 From: Jack Zampolin Date: Tue, 13 Nov 2018 15:35:30 -0800 Subject: [PATCH 16/16] Fix hard coded stake and a bit more help text to command --- client/lcd/lcd_test.go | 2 +- client/lcd/test_helpers.go | 7 +++---- cmd/gaia/cli_test/cli_test.go | 6 +++--- cmd/gaia/cmd/gaiacli/query.go | 1 + examples/democoin/cli_test/cli_test.go | 3 ++- x/gov/client/cli/tx.go | 2 +- 6 files changed, 11 insertions(+), 10 deletions(-) diff --git a/client/lcd/lcd_test.go b/client/lcd/lcd_test.go index 555f9cb1f109..1be908e98bdb 100644 --- a/client/lcd/lcd_test.go +++ b/client/lcd/lcd_test.go @@ -736,7 +736,7 @@ func TestProposalsQuery(t *testing.T) { defer cleanup() depositParam := getDepositParam(t, port) - halfMinDeposit := depositParam.MinDeposit.AmountOf("steak").Int64() / 2 + halfMinDeposit := depositParam.MinDeposit.AmountOf(stakeTypes.DefaultBondDenom).Int64() / 2 getVotingParam(t, port) getTallyingParam(t, port) diff --git a/client/lcd/test_helpers.go b/client/lcd/test_helpers.go index 8c6cce07e3b9..774fd4d6adb0 100644 --- a/client/lcd/test_helpers.go +++ b/client/lcd/test_helpers.go @@ -4,9 +4,7 @@ import ( "bytes" "encoding/json" "fmt" - "github.com/cosmos/cosmos-sdk/x/stake" - stakeTypes "github.com/cosmos/cosmos-sdk/x/stake/types" - "github.com/tendermint/tendermint/crypto/secp256k1" + "io/ioutil" "net" "net/http" @@ -16,7 +14,7 @@ import ( "strings" "testing" - "github.com/cosmos/cosmos-sdk/x/stake" + stakeTypes "github.com/cosmos/cosmos-sdk/x/stake/types" "github.com/tendermint/tendermint/crypto/secp256k1" "github.com/cosmos/cosmos-sdk/client" @@ -28,6 +26,7 @@ import ( "github.com/cosmos/cosmos-sdk/tests" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/auth" + "github.com/cosmos/cosmos-sdk/x/stake" "github.com/spf13/viper" "github.com/stretchr/testify/require" diff --git a/cmd/gaia/cli_test/cli_test.go b/cmd/gaia/cli_test/cli_test.go index 5a8c22bc6add..874c2a29a486 100644 --- a/cmd/gaia/cli_test/cli_test.go +++ b/cmd/gaia/cli_test/cli_test.go @@ -317,9 +317,9 @@ func TestGaiaCLISubmitProposal(t *testing.T) { tests.WaitForTMStart(port) tests.WaitForNextNBlocksTM(2, port) - executeGetDepositParam(t, fmt.Sprintf("gaiacli query param deposit %v", flags)) - executeGetVotingParam(t, fmt.Sprintf("gaiacli query param voting %v", flags)) - executeGetTallyingParam(t, fmt.Sprintf("gaiacli query param tallying %v", flags)) + executeGetDepositParam(t, fmt.Sprintf("gaiacli query gov param deposit %v", flags)) + executeGetVotingParam(t, fmt.Sprintf("gaiacli query gov param voting %v", flags)) + executeGetTallyingParam(t, fmt.Sprintf("gaiacli query gov param tallying %v", flags)) fooAddr, _ := executeGetAddrPK(t, fmt.Sprintf("gaiacli keys show foo --output=json --home=%s", gaiacliHome)) diff --git a/cmd/gaia/cmd/gaiacli/query.go b/cmd/gaia/cmd/gaiacli/query.go index 9ba3bca4677a..3a806d36c262 100644 --- a/cmd/gaia/cmd/gaiacli/query.go +++ b/cmd/gaia/cmd/gaiacli/query.go @@ -53,6 +53,7 @@ func queryCmd(cdc *amino.Codec) *cobra.Command { govcmd.GetCmdQueryProposals(storeGov, cdc), govcmd.GetCmdQueryVote(storeGov, cdc), govcmd.GetCmdQueryVotes(storeGov, cdc), + govcmd.GetCmdQueryParams(storeGov, cdc), govcmd.GetCmdQueryDeposit(storeGov, cdc), govcmd.GetCmdQueryDeposits(storeGov, cdc))...) diff --git a/examples/democoin/cli_test/cli_test.go b/examples/democoin/cli_test/cli_test.go index 8df97c987e82..9a3cba0df7e5 100644 --- a/examples/democoin/cli_test/cli_test.go +++ b/examples/democoin/cli_test/cli_test.go @@ -3,10 +3,11 @@ package clitest import ( "encoding/json" "fmt" - "github.com/cosmos/cosmos-sdk/cmd/gaia/app" "os" "testing" + "github.com/cosmos/cosmos-sdk/cmd/gaia/app" + "github.com/cosmos/cosmos-sdk/server" "github.com/cosmos/cosmos-sdk/tests" "github.com/stretchr/testify/require" diff --git a/x/gov/client/cli/tx.go b/x/gov/client/cli/tx.go index 5601b10e7975..fc25f5ec4fbf 100644 --- a/x/gov/client/cli/tx.go +++ b/x/gov/client/cli/tx.go @@ -253,7 +253,7 @@ func GetCmdVote(cdc *codec.Codec) *cobra.Command { func GetCmdQueryParams(queryRoute string, cdc *codec.Codec) *cobra.Command { cmd := &cobra.Command{ Use: "param [param-type]", - Short: "Query the parameters of the governance process", + Short: "Query the parameters (voting|tallying|deposit) of the governance process", Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { paramType := args[0]