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

R4R: Query Gov Params #2576

Merged
merged 18 commits into from
Nov 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion PENDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,17 @@ BREAKING CHANGES
FEATURES

* Gaia REST API (`gaiacli advanced rest-server`)
* [gov] [\#2479](https://github.com/cosmos/cosmos-sdk/issues/2479) Added governance parameter
query REST endpoints.

* Gaia CLI (`gaiacli`)
* [stake][cli] [\#2027] Add CLI query command for getting all delegations to a specific validator.
* [gov][cli] [\#2479](https://github.com/cosmos/cosmos-sdk/issues/2479) Added governance
parameter query commands.
* [stake][cli] [\#2027] Add CLI query command for getting all delegations to a specific validator.

* Gaia
* [x/gov] [#2479](https://github.com/cosmos/cosmos-sdk/issues/2479) Implemented querier
for getting governance parameters.

* SDK
* [simulator] \#2682 MsgEditValidator now looks at the validator's max rate, thus it now succeeds a significant portion of the time
Expand Down
47 changes: 42 additions & 5 deletions client/lcd/lcd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -735,26 +735,33 @@ func TestProposalsQuery(t *testing.T) {
cleanup, _, _, port := InitializeTestLCD(t, 1, []sdk.AccAddress{addrs[0], addrs[1]})
defer cleanup()

depositParam := getDepositParam(t, port)
halfMinDeposit := depositParam.MinDeposit.AmountOf(stakeTypes.DefaultBondDenom).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], 5)
resultTx := doSubmitProposal(t, port, seeds[0], names[0], passwords[0], addrs[0], halfMinDeposit)
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], 5)

resultTx = doSubmitProposal(t, port, seeds[0], names[0], passwords[0], addrs[0], halfMinDeposit)
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], 5)
resultTx = doSubmitProposal(t, port, seeds[1], names[1], passwords[1], addrs[1], halfMinDeposit)
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, 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
Expand Down Expand Up @@ -1246,6 +1253,36 @@ func getValidatorRedelegations(t *testing.T, port string, validatorAddr sdk.ValA

// ============= Governance Module ================

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)

var depositParams gov.DepositParams
err := cdc.UnmarshalJSON([]byte(body), &depositParams)
require.Nil(t, err)
return depositParams
}

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)

var votingParams gov.VotingParams
err := cdc.UnmarshalJSON([]byte(body), &votingParams)
require.Nil(t, err)
return votingParams
}

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)

var tallyParams gov.TallyParams
err := cdc.UnmarshalJSON([]byte(body), &tallyParams)
require.Nil(t, err)
return tallyParams
}

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)
Expand Down
79 changes: 78 additions & 1 deletion client/lcd/swagger-ui/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1451,7 +1451,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:
Expand All @@ -1478,6 +1478,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: <other_path> 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: <other_path> 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: <other_path> is not a valid query request path
404:
description: Found no voting parameters
500:
description: Internal Server Error

definitions:
CheckTxResult:
Expand Down
8 changes: 5 additions & 3 deletions client/lcd/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -16,6 +14,9 @@ import (
"strings"
"testing"

stakeTypes "github.com/cosmos/cosmos-sdk/x/stake/types"
"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"
Expand All @@ -25,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"
Expand Down
31 changes: 31 additions & 0 deletions cmd/gaia/cli_test/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,10 @@ func TestGaiaCLISubmitProposal(t *testing.T) {
tests.WaitForTMStart(port)
tests.WaitForNextNBlocksTM(2, port)

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))

fooAcc := executeGetAccount(t, fmt.Sprintf("gaiacli query account %s %v", fooAddr, flags))
Expand Down Expand Up @@ -784,6 +788,33 @@ func executeGetParams(t *testing.T, cmdStr string) stake.Params {
//___________________________________________________________________________________
// gov

func executeGetDepositParam(t *testing.T, cmdStr string) gov.DepositParams {
out, _ := tests.ExecuteT(t, cmdStr, "")
var depositParam gov.DepositParams
cdc := app.MakeCodec()
err := cdc.UnmarshalJSON([]byte(out), &depositParam)
require.NoError(t, err, "out %v\n, err %v", out, err)
return depositParam
}

func executeGetVotingParam(t *testing.T, cmdStr string) gov.VotingParams {
out, _ := tests.ExecuteT(t, cmdStr, "")
var votingParam gov.VotingParams
cdc := app.MakeCodec()
err := cdc.UnmarshalJSON([]byte(out), &votingParam)
require.NoError(t, err, "out %v\n, err %v", out, err)
return votingParam
}

func executeGetTallyingParam(t *testing.T, cmdStr string) gov.TallyParams {
out, _ := tests.ExecuteT(t, cmdStr, "")
var tallyingParam gov.TallyParams
cdc := app.MakeCodec()
err := cdc.UnmarshalJSON([]byte(out), &tallyingParam)
require.NoError(t, err, "out %v\n, err %v", out, err)
return tallyingParam
}

func executeGetProposal(t *testing.T, cmdStr string) gov.Proposal {
out, _ := tests.ExecuteT(t, cmdStr, "")
var proposal gov.Proposal
Expand Down
1 change: 1 addition & 0 deletions cmd/gaia/cmd/gaiacli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))...)

Expand Down
4 changes: 2 additions & 2 deletions docs/spec/governance/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand All @@ -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)**
Expand Down
Loading