Merge branch 'develop' of github.com:cosmos/cosmos-sdk into develop
This commit is contained in:
commit
9c4345fc72
|
@ -418,12 +418,12 @@
|
||||||
revision = "e5840949ff4fff0c56f9b6a541e22b63581ea9df"
|
revision = "e5840949ff4fff0c56f9b6a541e22b63581ea9df"
|
||||||
|
|
||||||
[[projects]]
|
[[projects]]
|
||||||
digest = "1:10b3a599325740c84a7c81f3f3cb2e1fdb70b3ea01b7fa28495567a2519df431"
|
digest = "1:ad9c4c1a4e7875330b1f62906f2830f043a23edb5db997e3a5ac5d3e6eadf80a"
|
||||||
name = "github.com/tendermint/go-amino"
|
name = "github.com/tendermint/go-amino"
|
||||||
packages = ["."]
|
packages = ["."]
|
||||||
pruneopts = "UT"
|
pruneopts = "UT"
|
||||||
revision = "6dcc6ddc143e116455c94b25c1004c99e0d0ca12"
|
revision = "dc14acf9ef15f85828bfbc561ed9dd9d2a284885"
|
||||||
version = "v0.14.0"
|
version = "v0.14.1"
|
||||||
|
|
||||||
[[projects]]
|
[[projects]]
|
||||||
digest = "1:9f8c4c93658315a795ffd3e0c943d39f78067dd8382b8d7bcfaf6686b92f3978"
|
digest = "1:9f8c4c93658315a795ffd3e0c943d39f78067dd8382b8d7bcfaf6686b92f3978"
|
||||||
|
@ -434,7 +434,7 @@
|
||||||
version = "v0.11.1"
|
version = "v0.11.1"
|
||||||
|
|
||||||
[[projects]]
|
[[projects]]
|
||||||
digest = "1:5b1373b03f39e6f6061cd91f3829100527ebb5f94240c092bf9e5d314b153501"
|
digest = "1:ba2ba7d6a0853472bdb7a64c4f9c1d5f9cba0eb7aac0b024654104387bf5eb57"
|
||||||
name = "github.com/tendermint/tendermint"
|
name = "github.com/tendermint/tendermint"
|
||||||
packages = [
|
packages = [
|
||||||
"abci/client",
|
"abci/client",
|
||||||
|
@ -500,8 +500,8 @@
|
||||||
"version",
|
"version",
|
||||||
]
|
]
|
||||||
pruneopts = "UT"
|
pruneopts = "UT"
|
||||||
revision = "48ab899923c564bbf2fa2f1244c11cb930e28132"
|
revision = "80d0a362500fea2dd089258319075a54e5d40a2d"
|
||||||
version = "v0.26.1-rc3"
|
version = "v0.26.1"
|
||||||
|
|
||||||
[[projects]]
|
[[projects]]
|
||||||
digest = "1:7886f86064faff6f8d08a3eb0e8c773648ff5a2e27730831e2bfbf07467f6666"
|
digest = "1:7886f86064faff6f8d08a3eb0e8c773648ff5a2e27730831e2bfbf07467f6666"
|
||||||
|
|
|
@ -28,7 +28,7 @@
|
||||||
|
|
||||||
[[override]]
|
[[override]]
|
||||||
name = "github.com/tendermint/go-amino"
|
name = "github.com/tendermint/go-amino"
|
||||||
version = "v0.14.0"
|
version = "v0.14.1"
|
||||||
|
|
||||||
[[override]]
|
[[override]]
|
||||||
name = "github.com/tendermint/iavl"
|
name = "github.com/tendermint/iavl"
|
||||||
|
@ -36,7 +36,7 @@
|
||||||
|
|
||||||
[[override]]
|
[[override]]
|
||||||
name = "github.com/tendermint/tendermint"
|
name = "github.com/tendermint/tendermint"
|
||||||
version = "v0.26.1-rc3" # TODO replace w/ 0.26.1
|
version = "v0.26.1"
|
||||||
|
|
||||||
## deps without releases:
|
## deps without releases:
|
||||||
|
|
||||||
|
|
39
Makefile
39
Makefile
|
@ -1,11 +1,9 @@
|
||||||
PACKAGES_NOSIMULATION=$(shell go list ./... | grep -v '/simulation')
|
PACKAGES_NOSIMULATION=$(shell go list ./... | grep -v '/simulation')
|
||||||
PACKAGES_SIMTEST=$(shell go list ./... | grep '/simulation')
|
PACKAGES_SIMTEST=$(shell go list ./... | grep '/simulation')
|
||||||
VERSION := $(shell git describe --tags --long | sed 's/v\(.*\)/\1/')
|
VERSION := $(subst v,,$(shell git describe --tags --long))
|
||||||
BUILD_TAGS = netgo ledger
|
BUILD_TAGS = netgo
|
||||||
BUILD_FLAGS = -tags "${BUILD_TAGS}" -ldflags "-X github.com/cosmos/cosmos-sdk/version.Version=${VERSION}"
|
BUILD_FLAGS = -tags "${BUILD_TAGS}" -ldflags "-X github.com/cosmos/cosmos-sdk/version.Version=${VERSION}"
|
||||||
GCC := $(shell command -v gcc 2> /dev/null)
|
|
||||||
LEDGER_ENABLED ?= true
|
LEDGER_ENABLED ?= true
|
||||||
UNAME_S := $(shell uname -s)
|
|
||||||
GOTOOLS = \
|
GOTOOLS = \
|
||||||
github.com/golang/dep/cmd/dep \
|
github.com/golang/dep/cmd/dep \
|
||||||
github.com/alecthomas/gometalinter \
|
github.com/alecthomas/gometalinter \
|
||||||
|
@ -20,23 +18,30 @@ ci: get_tools get_vendor_deps install test_cover test_lint test
|
||||||
########################################
|
########################################
|
||||||
### Build/Install
|
### Build/Install
|
||||||
|
|
||||||
check-ledger:
|
|
||||||
ifeq ($(LEDGER_ENABLED),true)
|
ifeq ($(LEDGER_ENABLED),true)
|
||||||
ifeq ($(UNAME_S),OpenBSD)
|
ifeq ($(OS),Windows_NT)
|
||||||
$(info "OpenBSD detected, disabling ledger support (https://github.com/cosmos/cosmos-sdk/issues/1988)")
|
GCCEXE = $(shell where gcc.exe 2> NUL)
|
||||||
TMP_BUILD_TAGS := $(BUILD_TAGS)
|
ifeq ($(GCCEXE),)
|
||||||
BUILD_TAGS = $(filter-out ledger, $(TMP_BUILD_TAGS))
|
$(error gcc.exe not installed for ledger support, please install or set LEDGER_ENABLED=false)
|
||||||
else
|
else
|
||||||
ifndef GCC
|
BUILD_TAGS += ledger
|
||||||
$(error "gcc not installed for ledger support, please install or set LEDGER_ENABLED to false in the Makefile")
|
endif
|
||||||
|
else
|
||||||
|
UNAME_S = $(shell uname -s)
|
||||||
|
ifeq ($(UNAME_S),OpenBSD)
|
||||||
|
$(warning OpenBSD detected, disabling ledger support (https://github.com/cosmos/cosmos-sdk/issues/1988))
|
||||||
|
else
|
||||||
|
GCC = $(shell command -v gcc 2> /dev/null)
|
||||||
|
ifeq ($(GCC),)
|
||||||
|
$(error gcc not installed for ledger support, please install or set LEDGER_ENABLED=false)
|
||||||
|
else
|
||||||
|
BUILD_TAGS += ledger
|
||||||
|
endif
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
else
|
|
||||||
TMP_BUILD_TAGS := $(BUILD_TAGS)
|
|
||||||
BUILD_TAGS = $(filter-out ledger, $(TMP_BUILD_TAGS))
|
|
||||||
endif
|
endif
|
||||||
|
|
||||||
build: check-ledger update_gaia_lite_docs
|
build:
|
||||||
ifeq ($(OS),Windows_NT)
|
ifeq ($(OS),Windows_NT)
|
||||||
go build $(BUILD_FLAGS) -o build/gaiad.exe ./cmd/gaia/cmd/gaiad
|
go build $(BUILD_FLAGS) -o build/gaiad.exe ./cmd/gaia/cmd/gaiad
|
||||||
go build $(BUILD_FLAGS) -o build/gaiacli.exe ./cmd/gaia/cmd/gaiacli
|
go build $(BUILD_FLAGS) -o build/gaiacli.exe ./cmd/gaia/cmd/gaiacli
|
||||||
|
@ -101,7 +106,7 @@ check_tools:
|
||||||
|
|
||||||
update_tools:
|
update_tools:
|
||||||
@echo "--> Updating tools to correct version"
|
@echo "--> Updating tools to correct version"
|
||||||
./scripts/get_tools.sh
|
$(MAKE) -C scripts get_tools
|
||||||
|
|
||||||
update_dev_tools:
|
update_dev_tools:
|
||||||
@echo "--> Downloading linters (this may take awhile)"
|
@echo "--> Downloading linters (this may take awhile)"
|
||||||
|
@ -110,7 +115,7 @@ update_dev_tools:
|
||||||
|
|
||||||
get_tools:
|
get_tools:
|
||||||
@echo "--> Installing tools"
|
@echo "--> Installing tools"
|
||||||
./scripts/get_tools.sh
|
$(MAKE) -C scripts get_tools
|
||||||
|
|
||||||
get_dev_tools:
|
get_dev_tools:
|
||||||
@echo "--> Downloading linters (this may take awhile)"
|
@echo "--> Downloading linters (this may take awhile)"
|
||||||
|
|
16
PENDING.md
16
PENDING.md
|
@ -5,10 +5,14 @@ BREAKING CHANGES
|
||||||
* Gaia REST API (`gaiacli advanced rest-server`)
|
* Gaia REST API (`gaiacli advanced rest-server`)
|
||||||
|
|
||||||
* Gaia CLI (`gaiacli`)
|
* Gaia CLI (`gaiacli`)
|
||||||
|
* [cli] [\#2728](https://github.com/cosmos/cosmos-sdk/pull/2728) Seperate `tx` and `query` subcommands by module
|
||||||
|
* [cli] [\#2727](https://github.com/cosmos/cosmos-sdk/pull/2727) Fix unbonding command flow
|
||||||
|
* [cli] [\#2786](https://github.com/cosmos/cosmos-sdk/pull/2786) Fix redelegation command flow
|
||||||
|
|
||||||
* Gaia
|
* Gaia
|
||||||
|
|
||||||
* SDK
|
* SDK
|
||||||
|
* [\#2752](https://github.com/cosmos/cosmos-sdk/pull/2752) Don't hardcode bondable denom.
|
||||||
|
|
||||||
* Tendermint
|
* Tendermint
|
||||||
|
|
||||||
|
@ -16,12 +20,20 @@ BREAKING CHANGES
|
||||||
FEATURES
|
FEATURES
|
||||||
|
|
||||||
* Gaia REST API (`gaiacli advanced rest-server`)
|
* 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`)
|
* Gaia CLI (`gaiacli`)
|
||||||
|
* [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
|
* Gaia
|
||||||
|
* [x/gov] [#2479](https://github.com/cosmos/cosmos-sdk/issues/2479) Implemented querier
|
||||||
|
for getting governance parameters.
|
||||||
|
|
||||||
* SDK
|
* SDK
|
||||||
|
* [simulator] \#2682 MsgEditValidator now looks at the validator's max rate, thus it now succeeds a significant portion of the time
|
||||||
|
|
||||||
* Tendermint
|
* Tendermint
|
||||||
|
|
||||||
|
@ -34,11 +46,14 @@ IMPROVEMENTS
|
||||||
* [\#2749](https://github.com/cosmos/cosmos-sdk/pull/2749) Add --chain-id flag to gaiad testnet
|
* [\#2749](https://github.com/cosmos/cosmos-sdk/pull/2749) Add --chain-id flag to gaiad testnet
|
||||||
|
|
||||||
* Gaia
|
* Gaia
|
||||||
|
- #2773 Require moniker to be provided on `gaiad init`.
|
||||||
|
- #2672 [Makefile] Updated for better Windows compatibility and ledger support logic, get_tools was rewritten as a cross-compatible Makefile.
|
||||||
|
|
||||||
* SDK
|
* SDK
|
||||||
- [x/mock/simulation] [\#2720] major cleanup, introduction of helper objects, reorganization
|
- [x/mock/simulation] [\#2720] major cleanup, introduction of helper objects, reorganization
|
||||||
|
|
||||||
* Tendermint
|
* Tendermint
|
||||||
|
- #2796 Update to go-amino 0.14.1
|
||||||
|
|
||||||
|
|
||||||
BUG FIXES
|
BUG FIXES
|
||||||
|
@ -48,6 +63,7 @@ BUG FIXES
|
||||||
* Gaia CLI (`gaiacli`)
|
* Gaia CLI (`gaiacli`)
|
||||||
|
|
||||||
* Gaia
|
* Gaia
|
||||||
|
* [\#2723] Use `cosmosvalcons` Bech32 prefix in `tendermint show-address`
|
||||||
* [\#2742](https://github.com/cosmos/cosmos-sdk/issues/2742) Fix time format of TimeoutCommit override
|
* [\#2742](https://github.com/cosmos/cosmos-sdk/issues/2742) Fix time format of TimeoutCommit override
|
||||||
|
|
||||||
* SDK
|
* SDK
|
||||||
|
|
|
@ -3,20 +3,20 @@ package client
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
|
"os"
|
||||||
|
"path"
|
||||||
|
|
||||||
"github.com/cosmos/cosmos-sdk/types"
|
"github.com/cosmos/cosmos-sdk/types"
|
||||||
"github.com/mitchellh/go-homedir"
|
"github.com/mitchellh/go-homedir"
|
||||||
"github.com/pelletier/go-toml"
|
"github.com/pelletier/go-toml"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
|
||||||
"path"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type cliConfig struct {
|
type cliConfig struct {
|
||||||
Home string `toml:"home"`
|
Home string `toml:"home"`
|
||||||
ChainID string `toml:"chain_id"`
|
ChainID string `toml:"chain_id"`
|
||||||
TrustNode bool `toml:"trust_node"`
|
TrustNode bool `toml:"trust_node"`
|
||||||
Encoding string `toml:"encoding"`
|
|
||||||
Output string `toml:"output"`
|
Output string `toml:"output"`
|
||||||
Node string `toml:"node"`
|
Node string `toml:"node"`
|
||||||
Trace bool `toml:"trace"`
|
Trace bool `toml:"trace"`
|
||||||
|
@ -41,23 +41,24 @@ func runConfigCmd(cmd *cobra.Command, args []string) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
stdin := BufferStdin()
|
stdin := BufferStdin()
|
||||||
|
|
||||||
gaiaCLIHome, err := handleGaiaCLIHome(home, stdin)
|
gaiaCLIHome, err := handleGaiaCLIHome(home, stdin)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
node, err := handleNode(stdin)
|
node, err := handleNode(stdin)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
trustNode, err := handleTrustNode(stdin)
|
trustNode, err := handleTrustNode(stdin)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
encoding := "btc"
|
chainID, err := types.DefaultChainID()
|
||||||
output := "text"
|
|
||||||
var chainID string
|
|
||||||
chainID, err = types.DefaultChainID()
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("Couldn't populate ChainID, so using an empty one.")
|
fmt.Println("Couldn't populate ChainID, so using an empty one.")
|
||||||
}
|
}
|
||||||
|
@ -66,8 +67,7 @@ func runConfigCmd(cmd *cobra.Command, args []string) error {
|
||||||
Home: gaiaCLIHome,
|
Home: gaiaCLIHome,
|
||||||
ChainID: chainID,
|
ChainID: chainID,
|
||||||
TrustNode: trustNode,
|
TrustNode: trustNode,
|
||||||
Encoding: encoding,
|
Output: "text",
|
||||||
Output: output,
|
|
||||||
Node: node,
|
Node: node,
|
||||||
Trace: false,
|
Trace: false,
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,6 +31,7 @@ import (
|
||||||
"github.com/cosmos/cosmos-sdk/x/gov"
|
"github.com/cosmos/cosmos-sdk/x/gov"
|
||||||
"github.com/cosmos/cosmos-sdk/x/slashing"
|
"github.com/cosmos/cosmos-sdk/x/slashing"
|
||||||
"github.com/cosmos/cosmos-sdk/x/stake"
|
"github.com/cosmos/cosmos-sdk/x/stake"
|
||||||
|
stakeTypes "github.com/cosmos/cosmos-sdk/x/stake/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
@ -265,7 +266,7 @@ func TestCoinSend(t *testing.T) {
|
||||||
coins := acc.GetCoins()
|
coins := acc.GetCoins()
|
||||||
mycoins := coins[0]
|
mycoins := coins[0]
|
||||||
|
|
||||||
require.Equal(t, "steak", mycoins.Denom)
|
require.Equal(t, stakeTypes.DefaultBondDenom, mycoins.Denom)
|
||||||
require.Equal(t, initialBalance[0].Amount.SubRaw(1), mycoins.Amount)
|
require.Equal(t, initialBalance[0].Amount.SubRaw(1), mycoins.Amount)
|
||||||
|
|
||||||
// query receiver
|
// query receiver
|
||||||
|
@ -273,7 +274,7 @@ func TestCoinSend(t *testing.T) {
|
||||||
coins = acc.GetCoins()
|
coins = acc.GetCoins()
|
||||||
mycoins = coins[0]
|
mycoins = coins[0]
|
||||||
|
|
||||||
require.Equal(t, "steak", mycoins.Denom)
|
require.Equal(t, stakeTypes.DefaultBondDenom, mycoins.Denom)
|
||||||
require.Equal(t, int64(1), mycoins.Amount.Int64())
|
require.Equal(t, int64(1), mycoins.Amount.Int64())
|
||||||
|
|
||||||
// test failure with too little gas
|
// test failure with too little gas
|
||||||
|
@ -326,7 +327,7 @@ func DisabledTestIBCTransfer(t *testing.T) {
|
||||||
coins := acc.GetCoins()
|
coins := acc.GetCoins()
|
||||||
mycoins := coins[0]
|
mycoins := coins[0]
|
||||||
|
|
||||||
require.Equal(t, "steak", mycoins.Denom)
|
require.Equal(t, stakeTypes.DefaultBondDenom, mycoins.Denom)
|
||||||
require.Equal(t, initialBalance[0].Amount.SubRaw(1), mycoins.Amount)
|
require.Equal(t, initialBalance[0].Amount.SubRaw(1), mycoins.Amount)
|
||||||
|
|
||||||
// TODO: query ibc egress packet state
|
// TODO: query ibc egress packet state
|
||||||
|
@ -514,7 +515,7 @@ func TestValidatorQuery(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestBonding(t *testing.T) {
|
func TestBonding(t *testing.T) {
|
||||||
name, password, denom := "test", "1234567890", "steak"
|
name, password, denom := "test", "1234567890", stakeTypes.DefaultBondDenom
|
||||||
addr, seed := CreateAddr(t, name, password, GetKeyBase(t))
|
addr, seed := CreateAddr(t, name, password, GetKeyBase(t))
|
||||||
|
|
||||||
cleanup, valPubKeys, operAddrs, port := InitializeTestLCD(t, 2, []sdk.AccAddress{addr})
|
cleanup, valPubKeys, operAddrs, port := InitializeTestLCD(t, 2, []sdk.AccAddress{addr})
|
||||||
|
@ -538,7 +539,7 @@ func TestBonding(t *testing.T) {
|
||||||
|
|
||||||
require.Equal(t, int64(40), coins.AmountOf(denom).Int64())
|
require.Equal(t, int64(40), coins.AmountOf(denom).Int64())
|
||||||
|
|
||||||
// query validator
|
// query delegation
|
||||||
bond := getDelegation(t, port, addr, operAddrs[0])
|
bond := getDelegation(t, port, addr, operAddrs[0])
|
||||||
require.Equal(t, amt, bond.Shares)
|
require.Equal(t, amt, bond.Shares)
|
||||||
|
|
||||||
|
@ -546,6 +547,10 @@ func TestBonding(t *testing.T) {
|
||||||
require.Len(t, delegatorDels, 1)
|
require.Len(t, delegatorDels, 1)
|
||||||
require.Equal(t, amt, delegatorDels[0].Shares)
|
require.Equal(t, amt, delegatorDels[0].Shares)
|
||||||
|
|
||||||
|
// query all delegations to validator
|
||||||
|
bonds := getValidatorDelegations(t, port, operAddrs[0])
|
||||||
|
require.Len(t, bonds, 2)
|
||||||
|
|
||||||
bondedValidators := getDelegatorValidators(t, port, addr)
|
bondedValidators := getDelegatorValidators(t, port, addr)
|
||||||
require.Len(t, bondedValidators, 1)
|
require.Len(t, bondedValidators, 1)
|
||||||
require.Equal(t, operAddrs[0], bondedValidators[0].OperatorAddr)
|
require.Equal(t, operAddrs[0], bondedValidators[0].OperatorAddr)
|
||||||
|
@ -564,7 +569,7 @@ func TestBonding(t *testing.T) {
|
||||||
// sender should have not received any coins as the unbonding has only just begun
|
// sender should have not received any coins as the unbonding has only just begun
|
||||||
acc = getAccount(t, port, addr)
|
acc = getAccount(t, port, addr)
|
||||||
coins = acc.GetCoins()
|
coins = acc.GetCoins()
|
||||||
require.Equal(t, int64(40), coins.AmountOf("steak").Int64())
|
require.Equal(t, int64(40), coins.AmountOf(stakeTypes.DefaultBondDenom).Int64())
|
||||||
|
|
||||||
unbonding := getUndelegation(t, port, addr, operAddrs[0])
|
unbonding := getUndelegation(t, port, addr, operAddrs[0])
|
||||||
require.Equal(t, "30", unbonding.Balance.Amount.String())
|
require.Equal(t, "30", unbonding.Balance.Amount.String())
|
||||||
|
@ -663,11 +668,11 @@ func TestDeposit(t *testing.T) {
|
||||||
|
|
||||||
// query proposal
|
// query proposal
|
||||||
proposal = getProposal(t, port, proposalID)
|
proposal = getProposal(t, port, proposalID)
|
||||||
require.True(t, proposal.GetTotalDeposit().IsEqual(sdk.Coins{sdk.NewInt64Coin("steak", 10)}))
|
require.True(t, proposal.GetTotalDeposit().IsEqual(sdk.Coins{sdk.NewInt64Coin(stakeTypes.DefaultBondDenom, 10)}))
|
||||||
|
|
||||||
// query deposit
|
// query deposit
|
||||||
deposit := getDeposit(t, port, proposalID, addr)
|
deposit := getDeposit(t, port, proposalID, addr)
|
||||||
require.True(t, deposit.Amount.IsEqual(sdk.Coins{sdk.NewInt64Coin("steak", 10)}))
|
require.True(t, deposit.Amount.IsEqual(sdk.Coins{sdk.NewInt64Coin(stakeTypes.DefaultBondDenom, 10)}))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestVote(t *testing.T) {
|
func TestVote(t *testing.T) {
|
||||||
|
@ -730,26 +735,33 @@ func TestProposalsQuery(t *testing.T) {
|
||||||
cleanup, _, _, port := InitializeTestLCD(t, 1, []sdk.AccAddress{addrs[0], addrs[1]})
|
cleanup, _, _, port := InitializeTestLCD(t, 1, []sdk.AccAddress{addrs[0], addrs[1]})
|
||||||
defer cleanup()
|
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
|
// 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
|
var proposalID1 uint64
|
||||||
cdc.MustUnmarshalBinaryLengthPrefixed(resultTx.DeliverTx.GetData(), &proposalID1)
|
cdc.MustUnmarshalBinaryLengthPrefixed(resultTx.DeliverTx.GetData(), &proposalID1)
|
||||||
tests.WaitForHeight(resultTx.Height+1, port)
|
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
|
var proposalID2 uint64
|
||||||
cdc.MustUnmarshalBinaryLengthPrefixed(resultTx.DeliverTx.GetData(), &proposalID2)
|
cdc.MustUnmarshalBinaryLengthPrefixed(resultTx.DeliverTx.GetData(), &proposalID2)
|
||||||
tests.WaitForHeight(resultTx.Height+1, port)
|
tests.WaitForHeight(resultTx.Height+1, port)
|
||||||
|
|
||||||
// Addr2 proposes (and deposits) proposals #3
|
// 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
|
var proposalID3 uint64
|
||||||
cdc.MustUnmarshalBinaryLengthPrefixed(resultTx.DeliverTx.GetData(), &proposalID3)
|
cdc.MustUnmarshalBinaryLengthPrefixed(resultTx.DeliverTx.GetData(), &proposalID3)
|
||||||
tests.WaitForHeight(resultTx.Height+1, port)
|
tests.WaitForHeight(resultTx.Height+1, port)
|
||||||
|
|
||||||
// Addr2 deposits on proposals #2 & #3
|
// 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)
|
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)
|
tests.WaitForHeight(resultTx.Height+1, port)
|
||||||
|
|
||||||
// check deposits match proposal and individual deposits
|
// check deposits match proposal and individual deposits
|
||||||
|
@ -861,7 +873,7 @@ func doSendWithGas(t *testing.T, port, seed, name, password string, addr sdk.Acc
|
||||||
sequence := acc.GetSequence()
|
sequence := acc.GetSequence()
|
||||||
chainID := viper.GetString(client.FlagChainID)
|
chainID := viper.GetString(client.FlagChainID)
|
||||||
// send
|
// send
|
||||||
coinbz, err := cdc.MarshalJSON(sdk.NewInt64Coin("steak", 1))
|
coinbz, err := cdc.MarshalJSON(sdk.NewInt64Coin(stakeTypes.DefaultBondDenom, 1))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
@ -947,7 +959,7 @@ func doIBCTransfer(t *testing.T, port, seed, name, password string, addr sdk.Acc
|
||||||
"account_number":"%d",
|
"account_number":"%d",
|
||||||
"sequence":"%d"
|
"sequence":"%d"
|
||||||
}
|
}
|
||||||
}`, "steak", name, password, chainID, accnum, sequence))
|
}`, stakeTypes.DefaultBondDenom, name, password, chainID, accnum, sequence))
|
||||||
|
|
||||||
res, body := Request(t, port, "POST", fmt.Sprintf("/ibc/testchain/%s/send", receiveAddr), jsonStr)
|
res, body := Request(t, port, "POST", fmt.Sprintf("/ibc/testchain/%s/send", receiveAddr), jsonStr)
|
||||||
require.Equal(t, http.StatusOK, res.StatusCode, body)
|
require.Equal(t, http.StatusOK, res.StatusCode, body)
|
||||||
|
@ -1096,7 +1108,7 @@ func doDelegate(t *testing.T, port, seed, name, password string,
|
||||||
"account_number":"%d",
|
"account_number":"%d",
|
||||||
"sequence":"%d"
|
"sequence":"%d"
|
||||||
}
|
}
|
||||||
}`, delAddr, valAddr, "steak", amount, name, password, chainID, accnum, sequence))
|
}`, delAddr, valAddr, stakeTypes.DefaultBondDenom, amount, name, password, chainID, accnum, sequence))
|
||||||
|
|
||||||
res, body := Request(t, port, "POST", fmt.Sprintf("/stake/delegators/%s/delegations", delAddr), jsonStr)
|
res, body := Request(t, port, "POST", fmt.Sprintf("/stake/delegators/%s/delegations", delAddr), jsonStr)
|
||||||
require.Equal(t, http.StatusOK, res.StatusCode, body)
|
require.Equal(t, http.StatusOK, res.StatusCode, body)
|
||||||
|
@ -1206,6 +1218,17 @@ func getValidator(t *testing.T, port string, validatorAddr sdk.ValAddress) stake
|
||||||
return validator
|
return validator
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getValidatorDelegations(t *testing.T, port string, validatorAddr sdk.ValAddress) []stake.Delegation {
|
||||||
|
res, body := Request(t, port, "GET", fmt.Sprintf("/stake/validators/%s/delegations", validatorAddr.String()), nil)
|
||||||
|
require.Equal(t, http.StatusOK, res.StatusCode, body)
|
||||||
|
|
||||||
|
var delegations []stake.Delegation
|
||||||
|
err := cdc.UnmarshalJSON([]byte(body), &delegations)
|
||||||
|
require.Nil(t, err)
|
||||||
|
|
||||||
|
return delegations
|
||||||
|
}
|
||||||
|
|
||||||
func getValidatorUnbondingDelegations(t *testing.T, port string, validatorAddr sdk.ValAddress) []stake.UnbondingDelegation {
|
func getValidatorUnbondingDelegations(t *testing.T, port string, validatorAddr sdk.ValAddress) []stake.UnbondingDelegation {
|
||||||
res, body := Request(t, port, "GET", fmt.Sprintf("/stake/validators/%s/unbonding_delegations", validatorAddr.String()), nil)
|
res, body := Request(t, port, "GET", fmt.Sprintf("/stake/validators/%s/unbonding_delegations", validatorAddr.String()), nil)
|
||||||
require.Equal(t, http.StatusOK, res.StatusCode, body)
|
require.Equal(t, http.StatusOK, res.StatusCode, body)
|
||||||
|
@ -1230,6 +1253,36 @@ func getValidatorRedelegations(t *testing.T, port string, validatorAddr sdk.ValA
|
||||||
|
|
||||||
// ============= Governance Module ================
|
// ============= 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 {
|
func getProposal(t *testing.T, port string, proposalID uint64) gov.Proposal {
|
||||||
res, body := Request(t, port, "GET", fmt.Sprintf("/gov/proposals/%d", proposalID), nil)
|
res, body := Request(t, port, "GET", fmt.Sprintf("/gov/proposals/%d", proposalID), nil)
|
||||||
require.Equal(t, http.StatusOK, res.StatusCode, body)
|
require.Equal(t, http.StatusOK, res.StatusCode, body)
|
||||||
|
@ -1339,7 +1392,7 @@ func doSubmitProposal(t *testing.T, port, seed, name, password string, proposerA
|
||||||
"description": "test",
|
"description": "test",
|
||||||
"proposal_type": "Text",
|
"proposal_type": "Text",
|
||||||
"proposer": "%s",
|
"proposer": "%s",
|
||||||
"initial_deposit": [{ "denom": "steak", "amount": "%d" }],
|
"initial_deposit": [{ "denom": "%s", "amount": "%d" }],
|
||||||
"base_req": {
|
"base_req": {
|
||||||
"name": "%s",
|
"name": "%s",
|
||||||
"password": "%s",
|
"password": "%s",
|
||||||
|
@ -1347,7 +1400,7 @@ func doSubmitProposal(t *testing.T, port, seed, name, password string, proposerA
|
||||||
"account_number":"%d",
|
"account_number":"%d",
|
||||||
"sequence":"%d"
|
"sequence":"%d"
|
||||||
}
|
}
|
||||||
}`, proposerAddr, amount, name, password, chainID, accnum, sequence))
|
}`, proposerAddr, stakeTypes.DefaultBondDenom, amount, name, password, chainID, accnum, sequence))
|
||||||
res, body := Request(t, port, "POST", "/gov/proposals", jsonStr)
|
res, body := Request(t, port, "POST", "/gov/proposals", jsonStr)
|
||||||
require.Equal(t, http.StatusOK, res.StatusCode, body)
|
require.Equal(t, http.StatusOK, res.StatusCode, body)
|
||||||
|
|
||||||
|
@ -1369,7 +1422,7 @@ func doDeposit(t *testing.T, port, seed, name, password string, proposerAddr sdk
|
||||||
// deposit on proposal
|
// deposit on proposal
|
||||||
jsonStr := []byte(fmt.Sprintf(`{
|
jsonStr := []byte(fmt.Sprintf(`{
|
||||||
"depositer": "%s",
|
"depositer": "%s",
|
||||||
"amount": [{ "denom": "steak", "amount": "%d" }],
|
"amount": [{ "denom": "%s", "amount": "%d" }],
|
||||||
"base_req": {
|
"base_req": {
|
||||||
"name": "%s",
|
"name": "%s",
|
||||||
"password": "%s",
|
"password": "%s",
|
||||||
|
@ -1377,7 +1430,7 @@ func doDeposit(t *testing.T, port, seed, name, password string, proposerAddr sdk
|
||||||
"account_number":"%d",
|
"account_number":"%d",
|
||||||
"sequence": "%d"
|
"sequence": "%d"
|
||||||
}
|
}
|
||||||
}`, proposerAddr, amount, name, password, chainID, accnum, sequence))
|
}`, proposerAddr, stakeTypes.DefaultBondDenom, amount, name, password, chainID, accnum, sequence))
|
||||||
res, body := Request(t, port, "POST", fmt.Sprintf("/gov/proposals/%d/deposits", proposalID), jsonStr)
|
res, body := Request(t, port, "POST", fmt.Sprintf("/gov/proposals/%d/deposits", proposalID), jsonStr)
|
||||||
require.Equal(t, http.StatusOK, res.StatusCode, body)
|
require.Equal(t, http.StatusOK, res.StatusCode, body)
|
||||||
|
|
||||||
|
|
|
@ -950,6 +950,30 @@ paths:
|
||||||
description: Invalid validator address
|
description: Invalid validator address
|
||||||
500:
|
500:
|
||||||
description: Internal Server Error
|
description: Internal Server Error
|
||||||
|
/stake/validators/{validatorAddr}/delegations:
|
||||||
|
parameters:
|
||||||
|
- in: path
|
||||||
|
name: validatorAddr
|
||||||
|
description: Bech32 OperatorAddress of validator
|
||||||
|
required: true
|
||||||
|
type: string
|
||||||
|
get:
|
||||||
|
summary: Get all delegations from a validator
|
||||||
|
tags:
|
||||||
|
- ICS21
|
||||||
|
produces:
|
||||||
|
- application/json
|
||||||
|
responses:
|
||||||
|
200:
|
||||||
|
description: OK
|
||||||
|
schema:
|
||||||
|
type: array
|
||||||
|
items:
|
||||||
|
$ref: "#/definitions/Delegation"
|
||||||
|
400:
|
||||||
|
description: Invalid validator address
|
||||||
|
500:
|
||||||
|
description: Internal Server Error
|
||||||
/stake/validators/{validatorAddr}/unbonding_delegations:
|
/stake/validators/{validatorAddr}/unbonding_delegations:
|
||||||
parameters:
|
parameters:
|
||||||
- in: path
|
- in: path
|
||||||
|
@ -1427,7 +1451,7 @@ paths:
|
||||||
/gov/proposals/{proposalId}/votes/{voter}:
|
/gov/proposals/{proposalId}/votes/{voter}:
|
||||||
get:
|
get:
|
||||||
summary: Query vote
|
summary: Query vote
|
||||||
description: Query vote information by proposalId and voter address
|
description: Query vote information by proposal Id and voter address
|
||||||
produces:
|
produces:
|
||||||
- application/json
|
- application/json
|
||||||
tags:
|
tags:
|
||||||
|
@ -1454,6 +1478,83 @@ paths:
|
||||||
description: Found no vote
|
description: Found no vote
|
||||||
500:
|
500:
|
||||||
description: Internal Server Error
|
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:
|
definitions:
|
||||||
CheckTxResult:
|
CheckTxResult:
|
||||||
|
|
|
@ -4,8 +4,7 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/cosmos/cosmos-sdk/x/stake"
|
|
||||||
"github.com/tendermint/tendermint/crypto/secp256k1"
|
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
@ -15,6 +14,9 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"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"
|
||||||
"github.com/cosmos/cosmos-sdk/client/keys"
|
"github.com/cosmos/cosmos-sdk/client/keys"
|
||||||
gapp "github.com/cosmos/cosmos-sdk/cmd/gaia/app"
|
gapp "github.com/cosmos/cosmos-sdk/cmd/gaia/app"
|
||||||
|
@ -24,6 +26,7 @@ import (
|
||||||
"github.com/cosmos/cosmos-sdk/tests"
|
"github.com/cosmos/cosmos-sdk/tests"
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
"github.com/cosmos/cosmos-sdk/x/auth"
|
"github.com/cosmos/cosmos-sdk/x/auth"
|
||||||
|
"github.com/cosmos/cosmos-sdk/x/stake"
|
||||||
|
|
||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
@ -227,7 +230,7 @@ func InitializeTestLCD(
|
||||||
msg := stake.NewMsgCreateValidator(
|
msg := stake.NewMsgCreateValidator(
|
||||||
sdk.ValAddress(operAddr),
|
sdk.ValAddress(operAddr),
|
||||||
pubKey,
|
pubKey,
|
||||||
sdk.NewCoin("steak", sdk.NewInt(int64(delegation))),
|
sdk.NewCoin(stakeTypes.DefaultBondDenom, sdk.NewInt(int64(delegation))),
|
||||||
stake.Description{Moniker: fmt.Sprintf("validator-%d", i+1)},
|
stake.Description{Moniker: fmt.Sprintf("validator-%d", i+1)},
|
||||||
stake.NewCommissionMsg(sdk.ZeroDec(), sdk.ZeroDec(), sdk.ZeroDec()),
|
stake.NewCommissionMsg(sdk.ZeroDec(), sdk.ZeroDec(), sdk.ZeroDec()),
|
||||||
)
|
)
|
||||||
|
@ -245,7 +248,7 @@ func InitializeTestLCD(
|
||||||
valOperAddrs = append(valOperAddrs, sdk.ValAddress(operAddr))
|
valOperAddrs = append(valOperAddrs, sdk.ValAddress(operAddr))
|
||||||
|
|
||||||
accAuth := auth.NewBaseAccountWithAddress(sdk.AccAddress(operAddr))
|
accAuth := auth.NewBaseAccountWithAddress(sdk.AccAddress(operAddr))
|
||||||
accAuth.Coins = sdk.Coins{sdk.NewInt64Coin("steak", 150)}
|
accAuth.Coins = sdk.Coins{sdk.NewInt64Coin(stakeTypes.DefaultBondDenom, 150)}
|
||||||
accs = append(accs, gapp.NewGenesisAccount(&accAuth))
|
accs = append(accs, gapp.NewGenesisAccount(&accAuth))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -259,7 +262,7 @@ func InitializeTestLCD(
|
||||||
// add some tokens to init accounts
|
// add some tokens to init accounts
|
||||||
for _, addr := range initAddrs {
|
for _, addr := range initAddrs {
|
||||||
accAuth := auth.NewBaseAccountWithAddress(addr)
|
accAuth := auth.NewBaseAccountWithAddress(addr)
|
||||||
accAuth.Coins = sdk.Coins{sdk.NewInt64Coin("steak", 100)}
|
accAuth.Coins = sdk.Coins{sdk.NewInt64Coin(stakeTypes.DefaultBondDenom, 100)}
|
||||||
acc := gapp.NewGenesisAccount(&accAuth)
|
acc := gapp.NewGenesisAccount(&accAuth)
|
||||||
genesisState.Accounts = append(genesisState.Accounts, acc)
|
genesisState.Accounts = append(genesisState.Accounts, acc)
|
||||||
genesisState.StakeData.Pool.LooseTokens = genesisState.StakeData.Pool.LooseTokens.Add(sdk.NewDec(100))
|
genesisState.StakeData.Pool.LooseTokens = genesisState.StakeData.Pool.LooseTokens.Add(sdk.NewDec(100))
|
||||||
|
|
|
@ -22,15 +22,8 @@ func todoNotImplemented(_ *cobra.Command, _ []string) error {
|
||||||
return errors.New("todo: Command not yet implemented")
|
return errors.New("todo: Command not yet implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddCommands adds a number of rpc-related subcommands
|
// InitClientCommand initializes client commands
|
||||||
func AddCommands(cmd *cobra.Command) {
|
func InitClientCommand() *cobra.Command {
|
||||||
cmd.AddCommand(
|
|
||||||
initClientCommand(),
|
|
||||||
statusCommand(),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
func initClientCommand() *cobra.Command {
|
|
||||||
cmd := &cobra.Command{
|
cmd := &cobra.Command{
|
||||||
Use: "init",
|
Use: "init",
|
||||||
Short: "Initialize light client",
|
Short: "Initialize light client",
|
||||||
|
|
|
@ -14,7 +14,8 @@ import (
|
||||||
ctypes "github.com/tendermint/tendermint/rpc/core/types"
|
ctypes "github.com/tendermint/tendermint/rpc/core/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
func statusCommand() *cobra.Command {
|
// StatusCommand returns the status of the network
|
||||||
|
func StatusCommand() *cobra.Command {
|
||||||
cmd := &cobra.Command{
|
cmd := &cobra.Command{
|
||||||
Use: "status",
|
Use: "status",
|
||||||
Short: "Query remote node for status",
|
Short: "Query remote node for status",
|
||||||
|
|
|
@ -2,20 +2,11 @@ package tx
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
"github.com/spf13/cobra"
|
|
||||||
|
|
||||||
"github.com/cosmos/cosmos-sdk/client/context"
|
"github.com/cosmos/cosmos-sdk/client/context"
|
||||||
"github.com/cosmos/cosmos-sdk/codec"
|
"github.com/cosmos/cosmos-sdk/codec"
|
||||||
)
|
)
|
||||||
|
|
||||||
// AddCommands adds a number of tx-query related subcommands
|
|
||||||
func AddCommands(cmd *cobra.Command, cdc *codec.Codec) {
|
|
||||||
cmd.AddCommand(
|
|
||||||
SearchTxCmd(cdc),
|
|
||||||
QueryTxCmd(cdc),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
// register REST routes
|
// register REST routes
|
||||||
func RegisterRoutes(cliCtx context.CLIContext, r *mux.Router, cdc *codec.Codec) {
|
func RegisterRoutes(cliCtx context.CLIContext, r *mux.Router, cdc *codec.Codec) {
|
||||||
r.HandleFunc("/txs/{hash}", QueryTxRequestHandlerFn(cdc, cliCtx)).Methods("GET")
|
r.HandleFunc("/txs/{hash}", QueryTxRequestHandlerFn(cdc, cliCtx)).Methods("GET")
|
||||||
|
|
|
@ -19,6 +19,7 @@ import (
|
||||||
"github.com/cosmos/cosmos-sdk/x/mint"
|
"github.com/cosmos/cosmos-sdk/x/mint"
|
||||||
"github.com/cosmos/cosmos-sdk/x/slashing"
|
"github.com/cosmos/cosmos-sdk/x/slashing"
|
||||||
"github.com/cosmos/cosmos-sdk/x/stake"
|
"github.com/cosmos/cosmos-sdk/x/stake"
|
||||||
|
stakeTypes "github.com/cosmos/cosmos-sdk/x/stake/types"
|
||||||
tmtypes "github.com/tendermint/tendermint/types"
|
tmtypes "github.com/tendermint/tendermint/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -26,7 +27,7 @@ var (
|
||||||
// bonded tokens given to genesis validators/accounts
|
// bonded tokens given to genesis validators/accounts
|
||||||
freeFermionVal = int64(100)
|
freeFermionVal = int64(100)
|
||||||
freeFermionsAcc = sdk.NewInt(150)
|
freeFermionsAcc = sdk.NewInt(150)
|
||||||
bondDenom = "steak"
|
bondDenom = stakeTypes.DefaultBondDenom
|
||||||
)
|
)
|
||||||
|
|
||||||
// State to Unmarshal
|
// State to Unmarshal
|
||||||
|
@ -286,9 +287,11 @@ func CollectStdTxs(cdc *codec.Codec, moniker string, genTxsDir string, genDoc tm
|
||||||
|
|
||||||
func NewDefaultGenesisAccount(addr sdk.AccAddress) GenesisAccount {
|
func NewDefaultGenesisAccount(addr sdk.AccAddress) GenesisAccount {
|
||||||
accAuth := auth.NewBaseAccountWithAddress(addr)
|
accAuth := auth.NewBaseAccountWithAddress(addr)
|
||||||
accAuth.Coins = []sdk.Coin{
|
coins :=sdk.Coins{
|
||||||
{"fooToken", sdk.NewInt(1000)},
|
{"fooToken", sdk.NewInt(1000)},
|
||||||
{"steak", freeFermionsAcc},
|
{bondDenom, freeFermionsAcc},
|
||||||
}
|
}
|
||||||
|
coins.Sort()
|
||||||
|
accAuth.Coins = coins
|
||||||
return NewGenesisAccount(&accAuth)
|
return NewGenesisAccount(&accAuth)
|
||||||
}
|
}
|
||||||
|
|
|
@ -92,10 +92,8 @@ func TestGaiaAppGenState(t *testing.T) {
|
||||||
func makeMsg(name string, pk crypto.PubKey) auth.StdTx {
|
func makeMsg(name string, pk crypto.PubKey) auth.StdTx {
|
||||||
desc := stake.NewDescription(name, "", "", "")
|
desc := stake.NewDescription(name, "", "", "")
|
||||||
comm := stakeTypes.CommissionMsg{}
|
comm := stakeTypes.CommissionMsg{}
|
||||||
msg := stake.NewMsgCreateValidator(
|
msg := stake.NewMsgCreateValidator(sdk.ValAddress(pk.Address()), pk, sdk.NewInt64Coin(bondDenom,
|
||||||
sdk.ValAddress(pk.Address()), pk,
|
50), desc, comm)
|
||||||
sdk.NewInt64Coin(bondDenom, 50), desc, comm,
|
|
||||||
)
|
|
||||||
return auth.NewStdTx([]sdk.Msg{msg}, auth.StdFee{}, nil, "")
|
return auth.NewStdTx([]sdk.Msg{msg}, auth.StdFee{}, nil, "")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,6 +29,7 @@ import (
|
||||||
slashingsim "github.com/cosmos/cosmos-sdk/x/slashing/simulation"
|
slashingsim "github.com/cosmos/cosmos-sdk/x/slashing/simulation"
|
||||||
stake "github.com/cosmos/cosmos-sdk/x/stake"
|
stake "github.com/cosmos/cosmos-sdk/x/stake"
|
||||||
stakesim "github.com/cosmos/cosmos-sdk/x/stake/simulation"
|
stakesim "github.com/cosmos/cosmos-sdk/x/stake/simulation"
|
||||||
|
stakeTypes "github.com/cosmos/cosmos-sdk/x/stake/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -62,7 +63,7 @@ func appStateFn(r *rand.Rand, accs []simulation.Account) json.RawMessage {
|
||||||
|
|
||||||
// Randomly generate some genesis accounts
|
// Randomly generate some genesis accounts
|
||||||
for _, acc := range accs {
|
for _, acc := range accs {
|
||||||
coins := sdk.Coins{sdk.Coin{"steak", sdk.NewInt(amount)}}
|
coins := sdk.Coins{sdk.Coin{stakeTypes.DefaultBondDenom, sdk.NewInt(amount)}}
|
||||||
genesisAccounts = append(genesisAccounts, GenesisAccount{
|
genesisAccounts = append(genesisAccounts, GenesisAccount{
|
||||||
Address: acc.Address,
|
Address: acc.Address,
|
||||||
Coins: coins,
|
Coins: coins,
|
||||||
|
@ -73,7 +74,7 @@ func appStateFn(r *rand.Rand, accs []simulation.Account) json.RawMessage {
|
||||||
govGenesis := gov.GenesisState{
|
govGenesis := gov.GenesisState{
|
||||||
StartingProposalID: uint64(r.Intn(100)),
|
StartingProposalID: uint64(r.Intn(100)),
|
||||||
DepositParams: gov.DepositParams{
|
DepositParams: gov.DepositParams{
|
||||||
MinDeposit: sdk.Coins{sdk.NewInt64Coin("steak", int64(r.Intn(1e3)))},
|
MinDeposit: sdk.Coins{sdk.NewInt64Coin(stakeTypes.DefaultBondDenom, int64(r.Intn(1e3)))},
|
||||||
MaxDepositPeriod: time.Duration(r.Intn(2*172800)) * time.Second,
|
MaxDepositPeriod: time.Duration(r.Intn(2*172800)) * time.Second,
|
||||||
},
|
},
|
||||||
VotingParams: gov.VotingParams{
|
VotingParams: gov.VotingParams{
|
||||||
|
@ -91,7 +92,7 @@ func appStateFn(r *rand.Rand, accs []simulation.Account) json.RawMessage {
|
||||||
Params: stake.Params{
|
Params: stake.Params{
|
||||||
UnbondingTime: time.Duration(r.Intn(60*60*24*3*2)) * time.Second,
|
UnbondingTime: time.Duration(r.Intn(60*60*24*3*2)) * time.Second,
|
||||||
MaxValidators: uint16(r.Intn(250)),
|
MaxValidators: uint16(r.Intn(250)),
|
||||||
BondDenom: "steak",
|
BondDenom: stakeTypes.DefaultBondDenom,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
fmt.Printf("Selected randomly generated staking parameters: %+v\n", stakeGenesis)
|
fmt.Printf("Selected randomly generated staking parameters: %+v\n", stakeGenesis)
|
||||||
|
@ -113,7 +114,7 @@ func appStateFn(r *rand.Rand, accs []simulation.Account) json.RawMessage {
|
||||||
Inflation: sdk.NewDecWithPrec(int64(r.Intn(99)), 2),
|
Inflation: sdk.NewDecWithPrec(int64(r.Intn(99)), 2),
|
||||||
},
|
},
|
||||||
Params: mint.Params{
|
Params: mint.Params{
|
||||||
MintDenom: "steak",
|
MintDenom: stakeTypes.DefaultBondDenom,
|
||||||
InflationRateChange: sdk.NewDecWithPrec(int64(r.Intn(99)), 2),
|
InflationRateChange: sdk.NewDecWithPrec(int64(r.Intn(99)), 2),
|
||||||
InflationMax: sdk.NewDecWithPrec(20, 2),
|
InflationMax: sdk.NewDecWithPrec(20, 2),
|
||||||
InflationMin: sdk.NewDecWithPrec(7, 2),
|
InflationMin: sdk.NewDecWithPrec(7, 2),
|
||||||
|
|
|
@ -29,6 +29,7 @@ import (
|
||||||
"github.com/cosmos/cosmos-sdk/x/auth"
|
"github.com/cosmos/cosmos-sdk/x/auth"
|
||||||
"github.com/cosmos/cosmos-sdk/x/gov"
|
"github.com/cosmos/cosmos-sdk/x/gov"
|
||||||
"github.com/cosmos/cosmos-sdk/x/stake"
|
"github.com/cosmos/cosmos-sdk/x/stake"
|
||||||
|
stakeTypes "github.com/cosmos/cosmos-sdk/x/stake/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -55,10 +56,10 @@ func TestGaiaCLIMinimumFees(t *testing.T) {
|
||||||
barAddr, _ := executeGetAddrPK(t, fmt.Sprintf("gaiacli keys show bar --output=json --home=%s", gaiacliHome))
|
barAddr, _ := executeGetAddrPK(t, fmt.Sprintf("gaiacli keys show bar --output=json --home=%s", gaiacliHome))
|
||||||
|
|
||||||
fooAcc := executeGetAccount(t, fmt.Sprintf("gaiacli query account %s %v", fooAddr, flags))
|
fooAcc := executeGetAccount(t, fmt.Sprintf("gaiacli query account %s %v", fooAddr, flags))
|
||||||
require.Equal(t, int64(50), fooAcc.GetCoins().AmountOf("steak").Int64())
|
require.Equal(t, int64(50), fooAcc.GetCoins().AmountOf(stakeTypes.DefaultBondDenom).Int64())
|
||||||
|
|
||||||
success := executeWrite(t, fmt.Sprintf(
|
success := executeWrite(t, fmt.Sprintf(
|
||||||
"gaiacli tx send %v --amount=10steak --to=%s --from=foo", flags, barAddr), app.DefaultKeyPass)
|
"gaiacli tx send %v --amount=10%s --to=%s --from=foo", flags, stakeTypes.DefaultBondDenom, barAddr), app.DefaultKeyPass)
|
||||||
require.False(t, success)
|
require.False(t, success)
|
||||||
tests.WaitForNextNBlocksTM(2, port)
|
tests.WaitForNextNBlocksTM(2, port)
|
||||||
|
|
||||||
|
@ -121,40 +122,40 @@ func TestGaiaCLISend(t *testing.T) {
|
||||||
barAddr, _ := executeGetAddrPK(t, fmt.Sprintf("gaiacli keys show bar --output=json --home=%s", gaiacliHome))
|
barAddr, _ := executeGetAddrPK(t, fmt.Sprintf("gaiacli keys show bar --output=json --home=%s", gaiacliHome))
|
||||||
|
|
||||||
fooAcc := executeGetAccount(t, fmt.Sprintf("gaiacli query account %s %v", fooAddr, flags))
|
fooAcc := executeGetAccount(t, fmt.Sprintf("gaiacli query account %s %v", fooAddr, flags))
|
||||||
require.Equal(t, int64(50), fooAcc.GetCoins().AmountOf("steak").Int64())
|
require.Equal(t, int64(50), fooAcc.GetCoins().AmountOf(stakeTypes.DefaultBondDenom).Int64())
|
||||||
|
|
||||||
executeWrite(t, fmt.Sprintf("gaiacli tx send %v --amount=10steak --to=%s --from=foo", flags, barAddr), app.DefaultKeyPass)
|
executeWrite(t, fmt.Sprintf("gaiacli tx send %v --amount=10%s --to=%s --from=foo", flags, stakeTypes.DefaultBondDenom, barAddr), app.DefaultKeyPass)
|
||||||
tests.WaitForNextNBlocksTM(2, port)
|
tests.WaitForNextNBlocksTM(2, port)
|
||||||
|
|
||||||
barAcc := executeGetAccount(t, fmt.Sprintf("gaiacli query account %s %v", barAddr, flags))
|
barAcc := executeGetAccount(t, fmt.Sprintf("gaiacli query account %s %v", barAddr, flags))
|
||||||
require.Equal(t, int64(10), barAcc.GetCoins().AmountOf("steak").Int64())
|
require.Equal(t, int64(10), barAcc.GetCoins().AmountOf(stakeTypes.DefaultBondDenom).Int64())
|
||||||
fooAcc = executeGetAccount(t, fmt.Sprintf("gaiacli query account %s %v", fooAddr, flags))
|
fooAcc = executeGetAccount(t, fmt.Sprintf("gaiacli query account %s %v", fooAddr, flags))
|
||||||
require.Equal(t, int64(40), fooAcc.GetCoins().AmountOf("steak").Int64())
|
require.Equal(t, int64(40), fooAcc.GetCoins().AmountOf(stakeTypes.DefaultBondDenom).Int64())
|
||||||
|
|
||||||
// Test --dry-run
|
// Test --dry-run
|
||||||
success := executeWrite(t, fmt.Sprintf("gaiacli tx send %v --amount=10steak --to=%s --from=foo --dry-run", flags, barAddr), app.DefaultKeyPass)
|
success := executeWrite(t, fmt.Sprintf("gaiacli tx send %v --amount=10%s --to=%s --from=foo --dry-run", flags, stakeTypes.DefaultBondDenom, barAddr), app.DefaultKeyPass)
|
||||||
require.True(t, success)
|
require.True(t, success)
|
||||||
// Check state didn't change
|
// Check state didn't change
|
||||||
fooAcc = executeGetAccount(t, fmt.Sprintf("gaiacli query account %s %v", fooAddr, flags))
|
fooAcc = executeGetAccount(t, fmt.Sprintf("gaiacli query account %s %v", fooAddr, flags))
|
||||||
require.Equal(t, int64(40), fooAcc.GetCoins().AmountOf("steak").Int64())
|
require.Equal(t, int64(40), fooAcc.GetCoins().AmountOf(stakeTypes.DefaultBondDenom).Int64())
|
||||||
|
|
||||||
// test autosequencing
|
// test autosequencing
|
||||||
executeWrite(t, fmt.Sprintf("gaiacli tx send %v --amount=10steak --to=%s --from=foo", flags, barAddr), app.DefaultKeyPass)
|
executeWrite(t, fmt.Sprintf("gaiacli tx send %v --amount=10%s --to=%s --from=foo", flags, stakeTypes.DefaultBondDenom, barAddr), app.DefaultKeyPass)
|
||||||
tests.WaitForNextNBlocksTM(2, port)
|
tests.WaitForNextNBlocksTM(2, port)
|
||||||
|
|
||||||
barAcc = executeGetAccount(t, fmt.Sprintf("gaiacli query account %s %v", barAddr, flags))
|
barAcc = executeGetAccount(t, fmt.Sprintf("gaiacli query account %s %v", barAddr, flags))
|
||||||
require.Equal(t, int64(20), barAcc.GetCoins().AmountOf("steak").Int64())
|
require.Equal(t, int64(20), barAcc.GetCoins().AmountOf(stakeTypes.DefaultBondDenom).Int64())
|
||||||
fooAcc = executeGetAccount(t, fmt.Sprintf("gaiacli query account %s %v", fooAddr, flags))
|
fooAcc = executeGetAccount(t, fmt.Sprintf("gaiacli query account %s %v", fooAddr, flags))
|
||||||
require.Equal(t, int64(30), fooAcc.GetCoins().AmountOf("steak").Int64())
|
require.Equal(t, int64(30), fooAcc.GetCoins().AmountOf(stakeTypes.DefaultBondDenom).Int64())
|
||||||
|
|
||||||
// test memo
|
// test memo
|
||||||
executeWrite(t, fmt.Sprintf("gaiacli tx send %v --amount=10steak --to=%s --from=foo --memo 'testmemo'", flags, barAddr), app.DefaultKeyPass)
|
executeWrite(t, fmt.Sprintf("gaiacli tx send %v --amount=10%s --to=%s --from=foo --memo 'testmemo'", flags, stakeTypes.DefaultBondDenom, barAddr), app.DefaultKeyPass)
|
||||||
tests.WaitForNextNBlocksTM(2, port)
|
tests.WaitForNextNBlocksTM(2, port)
|
||||||
|
|
||||||
barAcc = executeGetAccount(t, fmt.Sprintf("gaiacli query account %s %v", barAddr, flags))
|
barAcc = executeGetAccount(t, fmt.Sprintf("gaiacli query account %s %v", barAddr, flags))
|
||||||
require.Equal(t, int64(30), barAcc.GetCoins().AmountOf("steak").Int64())
|
require.Equal(t, int64(30), barAcc.GetCoins().AmountOf(stakeTypes.DefaultBondDenom).Int64())
|
||||||
fooAcc = executeGetAccount(t, fmt.Sprintf("gaiacli query account %s %v", fooAddr, flags))
|
fooAcc = executeGetAccount(t, fmt.Sprintf("gaiacli query account %s %v", fooAddr, flags))
|
||||||
require.Equal(t, int64(20), fooAcc.GetCoins().AmountOf("steak").Int64())
|
require.Equal(t, int64(20), fooAcc.GetCoins().AmountOf(stakeTypes.DefaultBondDenom).Int64())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGaiaCLIGasAuto(t *testing.T) {
|
func TestGaiaCLIGasAuto(t *testing.T) {
|
||||||
|
@ -172,26 +173,26 @@ func TestGaiaCLIGasAuto(t *testing.T) {
|
||||||
barAddr, _ := executeGetAddrPK(t, fmt.Sprintf("gaiacli keys show bar --output=json --home=%s", gaiacliHome))
|
barAddr, _ := executeGetAddrPK(t, fmt.Sprintf("gaiacli keys show bar --output=json --home=%s", gaiacliHome))
|
||||||
|
|
||||||
fooAcc := executeGetAccount(t, fmt.Sprintf("gaiacli query account %s %v", fooAddr, flags))
|
fooAcc := executeGetAccount(t, fmt.Sprintf("gaiacli query account %s %v", fooAddr, flags))
|
||||||
require.Equal(t, int64(50), fooAcc.GetCoins().AmountOf("steak").Int64())
|
require.Equal(t, int64(50), fooAcc.GetCoins().AmountOf(stakeTypes.DefaultBondDenom).Int64())
|
||||||
|
|
||||||
// Test failure with auto gas disabled and very little gas set by hand
|
// Test failure with auto gas disabled and very little gas set by hand
|
||||||
success := executeWrite(t, fmt.Sprintf("gaiacli tx send %v --gas=10 --amount=10steak --to=%s --from=foo", flags, barAddr), app.DefaultKeyPass)
|
success := executeWrite(t, fmt.Sprintf("gaiacli tx send %v --gas=10 --amount=10%s --to=%s --from=foo", flags, stakeTypes.DefaultBondDenom, barAddr), app.DefaultKeyPass)
|
||||||
require.False(t, success)
|
require.False(t, success)
|
||||||
tests.WaitForNextNBlocksTM(2, port)
|
tests.WaitForNextNBlocksTM(2, port)
|
||||||
// Check state didn't change
|
// Check state didn't change
|
||||||
fooAcc = executeGetAccount(t, fmt.Sprintf("gaiacli query account %s %v", fooAddr, flags))
|
fooAcc = executeGetAccount(t, fmt.Sprintf("gaiacli query account %s %v", fooAddr, flags))
|
||||||
require.Equal(t, int64(50), fooAcc.GetCoins().AmountOf("steak").Int64())
|
require.Equal(t, int64(50), fooAcc.GetCoins().AmountOf(stakeTypes.DefaultBondDenom).Int64())
|
||||||
|
|
||||||
// Test failure with negative gas
|
// Test failure with negative gas
|
||||||
success = executeWrite(t, fmt.Sprintf("gaiacli tx send %v --gas=-100 --amount=10steak --to=%s --from=foo", flags, barAddr), app.DefaultKeyPass)
|
success = executeWrite(t, fmt.Sprintf("gaiacli tx send %v --gas=-100 --amount=10%s --to=%s --from=foo", flags, stakeTypes.DefaultBondDenom, barAddr), app.DefaultKeyPass)
|
||||||
require.False(t, success)
|
require.False(t, success)
|
||||||
|
|
||||||
// Test failure with 0 gas
|
// Test failure with 0 gas
|
||||||
success = executeWrite(t, fmt.Sprintf("gaiacli tx send %v --gas=0 --amount=10steak --to=%s --from=foo", flags, barAddr), app.DefaultKeyPass)
|
success = executeWrite(t, fmt.Sprintf("gaiacli tx send %v --gas=0 --amount=10%s --to=%s --from=foo", flags, stakeTypes.DefaultBondDenom, barAddr), app.DefaultKeyPass)
|
||||||
require.False(t, success)
|
require.False(t, success)
|
||||||
|
|
||||||
// Enable auto gas
|
// Enable auto gas
|
||||||
success, stdout, _ := executeWriteRetStdStreams(t, fmt.Sprintf("gaiacli tx send %v --json --gas=simulate --amount=10steak --to=%s --from=foo", flags, barAddr), app.DefaultKeyPass)
|
success, stdout, _ := executeWriteRetStdStreams(t, fmt.Sprintf("gaiacli tx send %v --json --gas=simulate --amount=10%s --to=%s --from=foo", flags, stakeTypes.DefaultBondDenom, barAddr), app.DefaultKeyPass)
|
||||||
require.True(t, success)
|
require.True(t, success)
|
||||||
// check that gas wanted == gas used
|
// check that gas wanted == gas used
|
||||||
cdc := app.MakeCodec()
|
cdc := app.MakeCodec()
|
||||||
|
@ -205,7 +206,7 @@ func TestGaiaCLIGasAuto(t *testing.T) {
|
||||||
tests.WaitForNextNBlocksTM(2, port)
|
tests.WaitForNextNBlocksTM(2, port)
|
||||||
// Check state has changed accordingly
|
// Check state has changed accordingly
|
||||||
fooAcc = executeGetAccount(t, fmt.Sprintf("gaiacli query account %s %v", fooAddr, flags))
|
fooAcc = executeGetAccount(t, fmt.Sprintf("gaiacli query account %s %v", fooAddr, flags))
|
||||||
require.Equal(t, int64(40), fooAcc.GetCoins().AmountOf("steak").Int64())
|
require.Equal(t, int64(40), fooAcc.GetCoins().AmountOf(stakeTypes.DefaultBondDenom).Int64())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGaiaCLICreateValidator(t *testing.T) {
|
func TestGaiaCLICreateValidator(t *testing.T) {
|
||||||
|
@ -223,23 +224,23 @@ func TestGaiaCLICreateValidator(t *testing.T) {
|
||||||
barAddr, barPubKey := executeGetAddrPK(t, fmt.Sprintf("gaiacli keys show bar --output=json --home=%s", gaiacliHome))
|
barAddr, barPubKey := executeGetAddrPK(t, fmt.Sprintf("gaiacli keys show bar --output=json --home=%s", gaiacliHome))
|
||||||
barCeshPubKey := sdk.MustBech32ifyConsPub(barPubKey)
|
barCeshPubKey := sdk.MustBech32ifyConsPub(barPubKey)
|
||||||
|
|
||||||
executeWrite(t, fmt.Sprintf("gaiacli tx send %v --amount=10steak --to=%s --from=foo", flags, barAddr), app.DefaultKeyPass)
|
executeWrite(t, fmt.Sprintf("gaiacli tx send %v --amount=10%s --to=%s --from=foo", flags, stakeTypes.DefaultBondDenom, barAddr), app.DefaultKeyPass)
|
||||||
tests.WaitForNextNBlocksTM(2, port)
|
tests.WaitForNextNBlocksTM(2, port)
|
||||||
|
|
||||||
barAcc := executeGetAccount(t, fmt.Sprintf("gaiacli query account %s %v", barAddr, flags))
|
barAcc := executeGetAccount(t, fmt.Sprintf("gaiacli query account %s %v", barAddr, flags))
|
||||||
require.Equal(t, int64(10), barAcc.GetCoins().AmountOf("steak").Int64())
|
require.Equal(t, int64(10), barAcc.GetCoins().AmountOf(stakeTypes.DefaultBondDenom).Int64())
|
||||||
fooAcc := executeGetAccount(t, fmt.Sprintf("gaiacli query account %s %v", fooAddr, flags))
|
fooAcc := executeGetAccount(t, fmt.Sprintf("gaiacli query account %s %v", fooAddr, flags))
|
||||||
require.Equal(t, int64(40), fooAcc.GetCoins().AmountOf("steak").Int64())
|
require.Equal(t, int64(40), fooAcc.GetCoins().AmountOf(stakeTypes.DefaultBondDenom).Int64())
|
||||||
|
|
||||||
defaultParams := stake.DefaultParams()
|
defaultParams := stake.DefaultParams()
|
||||||
initialPool := stake.InitialPool()
|
initialPool := stake.InitialPool()
|
||||||
initialPool.BondedTokens = initialPool.BondedTokens.Add(sdk.NewDec(100)) // Delegate tx on GaiaAppGenState
|
initialPool.BondedTokens = initialPool.BondedTokens.Add(sdk.NewDec(100)) // Delegate tx on GaiaAppGenState
|
||||||
|
|
||||||
// create validator
|
// create validator
|
||||||
cvStr := fmt.Sprintf("gaiacli tx create-validator %v", flags)
|
cvStr := fmt.Sprintf("gaiacli tx stake create-validator %v", flags)
|
||||||
cvStr += fmt.Sprintf(" --from=%s", "bar")
|
cvStr += fmt.Sprintf(" --from=%s", "bar")
|
||||||
cvStr += fmt.Sprintf(" --pubkey=%s", barCeshPubKey)
|
cvStr += fmt.Sprintf(" --pubkey=%s", barCeshPubKey)
|
||||||
cvStr += fmt.Sprintf(" --amount=%v", "2steak")
|
cvStr += fmt.Sprintf(" --amount=%v", fmt.Sprintf("2%s", stakeTypes.DefaultBondDenom))
|
||||||
cvStr += fmt.Sprintf(" --moniker=%v", "bar-vally")
|
cvStr += fmt.Sprintf(" --moniker=%v", "bar-vally")
|
||||||
cvStr += fmt.Sprintf(" --commission-rate=%v", "0.05")
|
cvStr += fmt.Sprintf(" --commission-rate=%v", "0.05")
|
||||||
cvStr += fmt.Sprintf(" --commission-max-rate=%v", "0.20")
|
cvStr += fmt.Sprintf(" --commission-max-rate=%v", "0.20")
|
||||||
|
@ -265,14 +266,18 @@ func TestGaiaCLICreateValidator(t *testing.T) {
|
||||||
tests.WaitForNextNBlocksTM(2, port)
|
tests.WaitForNextNBlocksTM(2, port)
|
||||||
|
|
||||||
barAcc = executeGetAccount(t, fmt.Sprintf("gaiacli query account %s %v", barAddr, flags))
|
barAcc = executeGetAccount(t, fmt.Sprintf("gaiacli query account %s %v", barAddr, flags))
|
||||||
require.Equal(t, int64(8), barAcc.GetCoins().AmountOf("steak").Int64(), "%v", barAcc)
|
require.Equal(t, int64(8), barAcc.GetCoins().AmountOf(stakeTypes.DefaultBondDenom).Int64(), "%v", barAcc)
|
||||||
|
|
||||||
validator := executeGetValidator(t, fmt.Sprintf("gaiacli query validator %s --output=json %v", sdk.ValAddress(barAddr), flags))
|
validator := executeGetValidator(t, fmt.Sprintf("gaiacli query stake validator %s --output=json %v", sdk.ValAddress(barAddr), flags))
|
||||||
require.Equal(t, validator.OperatorAddr, sdk.ValAddress(barAddr))
|
require.Equal(t, validator.OperatorAddr, sdk.ValAddress(barAddr))
|
||||||
require.True(sdk.DecEq(t, sdk.NewDec(2), validator.Tokens))
|
require.True(sdk.DecEq(t, sdk.NewDec(2), validator.Tokens))
|
||||||
|
|
||||||
|
validatorDelegations := executeGetValidatorDelegations(t, fmt.Sprintf("gaiacli query stake delegations-to %s --output=json %v", sdk.ValAddress(barAddr), flags))
|
||||||
|
require.Len(t, validatorDelegations, 1)
|
||||||
|
require.NotZero(t, validatorDelegations[0].Shares)
|
||||||
|
|
||||||
// unbond a single share
|
// unbond a single share
|
||||||
unbondStr := fmt.Sprintf("gaiacli tx unbond begin %v", flags)
|
unbondStr := fmt.Sprintf("gaiacli tx stake unbond begin %v", flags)
|
||||||
unbondStr += fmt.Sprintf(" --from=%s", "bar")
|
unbondStr += fmt.Sprintf(" --from=%s", "bar")
|
||||||
unbondStr += fmt.Sprintf(" --validator=%s", sdk.ValAddress(barAddr))
|
unbondStr += fmt.Sprintf(" --validator=%s", sdk.ValAddress(barAddr))
|
||||||
unbondStr += fmt.Sprintf(" --shares-amount=%v", "1")
|
unbondStr += fmt.Sprintf(" --shares-amount=%v", "1")
|
||||||
|
@ -283,21 +288,21 @@ func TestGaiaCLICreateValidator(t *testing.T) {
|
||||||
|
|
||||||
/* // this won't be what we expect because we've only started unbonding, haven't completed
|
/* // this won't be what we expect because we've only started unbonding, haven't completed
|
||||||
barAcc = executeGetAccount(t, fmt.Sprintf("gaiacli query account %v %v", barCech, flags))
|
barAcc = executeGetAccount(t, fmt.Sprintf("gaiacli query account %v %v", barCech, flags))
|
||||||
require.Equal(t, int64(9), barAcc.GetCoins().AmountOf("steak").Int64(), "%v", barAcc)
|
require.Equal(t, int64(9), barAcc.GetCoins().AmountOf(stakeTypes.DefaultBondDenom).Int64(), "%v", barAcc)
|
||||||
*/
|
*/
|
||||||
validator = executeGetValidator(t, fmt.Sprintf("gaiacli query validator %s --output=json %v", sdk.ValAddress(barAddr), flags))
|
validator = executeGetValidator(t, fmt.Sprintf("gaiacli query stake validator %s --output=json %v", sdk.ValAddress(barAddr), flags))
|
||||||
require.Equal(t, "1.0000000000", validator.Tokens.String())
|
require.Equal(t, "1.0000000000", validator.Tokens.String())
|
||||||
|
|
||||||
validatorUbds := executeGetValidatorUnbondingDelegations(t,
|
validatorUbds := executeGetValidatorUnbondingDelegations(t,
|
||||||
fmt.Sprintf("gaiacli query unbonding-delegations-from %s --output=json %v",
|
fmt.Sprintf("gaiacli query stake unbonding-delegations-from %s --output=json %v",
|
||||||
sdk.ValAddress(barAddr), flags))
|
sdk.ValAddress(barAddr), flags))
|
||||||
require.Len(t, validatorUbds, 1)
|
require.Len(t, validatorUbds, 1)
|
||||||
require.Equal(t, "1", validatorUbds[0].Balance.Amount.String())
|
require.Equal(t, "1", validatorUbds[0].Balance.Amount.String())
|
||||||
|
|
||||||
params := executeGetParams(t, fmt.Sprintf("gaiacli query parameters --output=json %v", flags))
|
params := executeGetParams(t, fmt.Sprintf("gaiacli query stake parameters --output=json %v", flags))
|
||||||
require.True(t, defaultParams.Equal(params))
|
require.True(t, defaultParams.Equal(params))
|
||||||
|
|
||||||
pool := executeGetPool(t, fmt.Sprintf("gaiacli query pool --output=json %v", flags))
|
pool := executeGetPool(t, fmt.Sprintf("gaiacli query stake pool --output=json %v", flags))
|
||||||
require.Equal(t, initialPool.BondedTokens, pool.BondedTokens)
|
require.Equal(t, initialPool.BondedTokens, pool.BondedTokens)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -312,18 +317,22 @@ func TestGaiaCLISubmitProposal(t *testing.T) {
|
||||||
tests.WaitForTMStart(port)
|
tests.WaitForTMStart(port)
|
||||||
tests.WaitForNextNBlocksTM(2, 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))
|
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))
|
fooAcc := executeGetAccount(t, fmt.Sprintf("gaiacli query account %s %v", fooAddr, flags))
|
||||||
require.Equal(t, int64(50), fooAcc.GetCoins().AmountOf("steak").Int64())
|
require.Equal(t, int64(50), fooAcc.GetCoins().AmountOf(stakeTypes.DefaultBondDenom).Int64())
|
||||||
|
|
||||||
proposalsQuery, _ := tests.ExecuteT(t, fmt.Sprintf("gaiacli query proposals %v", flags), "")
|
proposalsQuery, _ := tests.ExecuteT(t, fmt.Sprintf("gaiacli query gov proposals %v", flags), "")
|
||||||
require.Equal(t, "No matching proposals found", proposalsQuery)
|
require.Equal(t, "No matching proposals found", proposalsQuery)
|
||||||
|
|
||||||
// submit a test proposal
|
// submit a test proposal
|
||||||
spStr := fmt.Sprintf("gaiacli tx submit-proposal %v", flags)
|
spStr := fmt.Sprintf("gaiacli tx gov submit-proposal %v", flags)
|
||||||
spStr += fmt.Sprintf(" --from=%s", "foo")
|
spStr += fmt.Sprintf(" --from=%s", "foo")
|
||||||
spStr += fmt.Sprintf(" --deposit=%s", "5steak")
|
spStr += fmt.Sprintf(" --deposit=%s", fmt.Sprintf("5%s", stakeTypes.DefaultBondDenom))
|
||||||
spStr += fmt.Sprintf(" --type=%s", "Text")
|
spStr += fmt.Sprintf(" --type=%s", "Text")
|
||||||
spStr += fmt.Sprintf(" --title=%s", "Test")
|
spStr += fmt.Sprintf(" --title=%s", "Test")
|
||||||
spStr += fmt.Sprintf(" --description=%s", "test")
|
spStr += fmt.Sprintf(" --description=%s", "test")
|
||||||
|
@ -346,23 +355,23 @@ func TestGaiaCLISubmitProposal(t *testing.T) {
|
||||||
tests.WaitForNextNBlocksTM(2, port)
|
tests.WaitForNextNBlocksTM(2, port)
|
||||||
|
|
||||||
fooAcc = executeGetAccount(t, fmt.Sprintf("gaiacli query account %s %v", fooAddr, flags))
|
fooAcc = executeGetAccount(t, fmt.Sprintf("gaiacli query account %s %v", fooAddr, flags))
|
||||||
require.Equal(t, int64(45), fooAcc.GetCoins().AmountOf("steak").Int64())
|
require.Equal(t, int64(45), fooAcc.GetCoins().AmountOf(stakeTypes.DefaultBondDenom).Int64())
|
||||||
|
|
||||||
proposal1 := executeGetProposal(t, fmt.Sprintf("gaiacli query proposal --proposal-id=1 --output=json %v", flags))
|
proposal1 := executeGetProposal(t, fmt.Sprintf("gaiacli query gov proposal --proposal-id=1 --output=json %v", flags))
|
||||||
require.Equal(t, uint64(1), proposal1.GetProposalID())
|
require.Equal(t, uint64(1), proposal1.GetProposalID())
|
||||||
require.Equal(t, gov.StatusDepositPeriod, proposal1.GetStatus())
|
require.Equal(t, gov.StatusDepositPeriod, proposal1.GetStatus())
|
||||||
|
|
||||||
proposalsQuery, _ = tests.ExecuteT(t, fmt.Sprintf("gaiacli query proposals %v", flags), "")
|
proposalsQuery, _ = tests.ExecuteT(t, fmt.Sprintf("gaiacli query gov proposals %v", flags), "")
|
||||||
require.Equal(t, " 1 - Test", proposalsQuery)
|
require.Equal(t, " 1 - Test", proposalsQuery)
|
||||||
|
|
||||||
deposit := executeGetDeposit(t,
|
deposit := executeGetDeposit(t,
|
||||||
fmt.Sprintf("gaiacli query deposit --proposal-id=1 --depositer=%s --output=json %v",
|
fmt.Sprintf("gaiacli query gov deposit --proposal-id=1 --depositer=%s --output=json %v",
|
||||||
fooAddr, flags))
|
fooAddr, flags))
|
||||||
require.Equal(t, int64(5), deposit.Amount.AmountOf("steak").Int64())
|
require.Equal(t, int64(5), deposit.Amount.AmountOf(stakeTypes.DefaultBondDenom).Int64())
|
||||||
|
|
||||||
depositStr := fmt.Sprintf("gaiacli tx deposit %v", flags)
|
depositStr := fmt.Sprintf("gaiacli tx gov deposit %v", flags)
|
||||||
depositStr += fmt.Sprintf(" --from=%s", "foo")
|
depositStr += fmt.Sprintf(" --from=%s", "foo")
|
||||||
depositStr += fmt.Sprintf(" --deposit=%s", "10steak")
|
depositStr += fmt.Sprintf(" --deposit=%s", fmt.Sprintf("10%s", stakeTypes.DefaultBondDenom))
|
||||||
depositStr += fmt.Sprintf(" --proposal-id=%s", "1")
|
depositStr += fmt.Sprintf(" --proposal-id=%s", "1")
|
||||||
|
|
||||||
// Test generate only
|
// Test generate only
|
||||||
|
@ -380,22 +389,23 @@ func TestGaiaCLISubmitProposal(t *testing.T) {
|
||||||
|
|
||||||
// test query deposit
|
// test query deposit
|
||||||
deposits := executeGetDeposits(t,
|
deposits := executeGetDeposits(t,
|
||||||
fmt.Sprintf("gaiacli query deposits --proposal-id=1 --output=json %v", flags))
|
fmt.Sprintf("gaiacli query gov deposits --proposal-id=1 --output=json %v", flags))
|
||||||
require.Len(t, deposits, 1)
|
require.Len(t, deposits, 1)
|
||||||
require.Equal(t, int64(15), deposits[0].Amount.AmountOf("steak").Int64())
|
require.Equal(t, int64(15), deposits[0].Amount.AmountOf(stakeTypes.DefaultBondDenom).Int64())
|
||||||
|
|
||||||
deposit = executeGetDeposit(t,
|
deposit = executeGetDeposit(t,
|
||||||
fmt.Sprintf("gaiacli query deposit --proposal-id=1 --depositer=%s --output=json %v",
|
fmt.Sprintf("gaiacli query gov deposit --proposal-id=1 --depositer=%s --output=json %v",
|
||||||
fooAddr, flags))
|
fooAddr, flags))
|
||||||
require.Equal(t, int64(15), deposit.Amount.AmountOf("steak").Int64())
|
require.Equal(t, int64(15), deposit.Amount.AmountOf(stakeTypes.DefaultBondDenom).Int64())
|
||||||
|
|
||||||
fooAcc = executeGetAccount(t, fmt.Sprintf("gaiacli query account %s %v", fooAddr, flags))
|
fooAcc = executeGetAccount(t, fmt.Sprintf("gaiacli query account %s %v", fooAddr, flags))
|
||||||
require.Equal(t, int64(35), fooAcc.GetCoins().AmountOf("steak").Int64())
|
|
||||||
proposal1 = executeGetProposal(t, fmt.Sprintf("gaiacli query proposal --proposal-id=1 --output=json %v", flags))
|
require.Equal(t, int64(35), fooAcc.GetCoins().AmountOf(stakeTypes.DefaultBondDenom).Int64())
|
||||||
|
proposal1 = executeGetProposal(t, fmt.Sprintf("gaiacli query gov proposal --proposal-id=1 --output=json %v", flags))
|
||||||
require.Equal(t, uint64(1), proposal1.GetProposalID())
|
require.Equal(t, uint64(1), proposal1.GetProposalID())
|
||||||
require.Equal(t, gov.StatusVotingPeriod, proposal1.GetStatus())
|
require.Equal(t, gov.StatusVotingPeriod, proposal1.GetStatus())
|
||||||
|
|
||||||
voteStr := fmt.Sprintf("gaiacli tx vote %v", flags)
|
voteStr := fmt.Sprintf("gaiacli tx gov vote %v", flags)
|
||||||
voteStr += fmt.Sprintf(" --from=%s", "foo")
|
voteStr += fmt.Sprintf(" --from=%s", "foo")
|
||||||
voteStr += fmt.Sprintf(" --proposal-id=%s", "1")
|
voteStr += fmt.Sprintf(" --proposal-id=%s", "1")
|
||||||
voteStr += fmt.Sprintf(" --option=%s", "Yes")
|
voteStr += fmt.Sprintf(" --option=%s", "Yes")
|
||||||
|
@ -413,25 +423,25 @@ func TestGaiaCLISubmitProposal(t *testing.T) {
|
||||||
executeWrite(t, voteStr, app.DefaultKeyPass)
|
executeWrite(t, voteStr, app.DefaultKeyPass)
|
||||||
tests.WaitForNextNBlocksTM(2, port)
|
tests.WaitForNextNBlocksTM(2, port)
|
||||||
|
|
||||||
vote := executeGetVote(t, fmt.Sprintf("gaiacli query vote --proposal-id=1 --voter=%s --output=json %v", fooAddr, flags))
|
vote := executeGetVote(t, fmt.Sprintf("gaiacli query gov vote --proposal-id=1 --voter=%s --output=json %v", fooAddr, flags))
|
||||||
require.Equal(t, uint64(1), vote.ProposalID)
|
require.Equal(t, uint64(1), vote.ProposalID)
|
||||||
require.Equal(t, gov.OptionYes, vote.Option)
|
require.Equal(t, gov.OptionYes, vote.Option)
|
||||||
|
|
||||||
votes := executeGetVotes(t, fmt.Sprintf("gaiacli query votes --proposal-id=1 --output=json %v", flags))
|
votes := executeGetVotes(t, fmt.Sprintf("gaiacli query gov votes --proposal-id=1 --output=json %v", flags))
|
||||||
require.Len(t, votes, 1)
|
require.Len(t, votes, 1)
|
||||||
require.Equal(t, uint64(1), votes[0].ProposalID)
|
require.Equal(t, uint64(1), votes[0].ProposalID)
|
||||||
require.Equal(t, gov.OptionYes, votes[0].Option)
|
require.Equal(t, gov.OptionYes, votes[0].Option)
|
||||||
|
|
||||||
proposalsQuery, _ = tests.ExecuteT(t, fmt.Sprintf("gaiacli query proposals --status=DepositPeriod %v", flags), "")
|
proposalsQuery, _ = tests.ExecuteT(t, fmt.Sprintf("gaiacli query gov proposals --status=DepositPeriod %v", flags), "")
|
||||||
require.Equal(t, "No matching proposals found", proposalsQuery)
|
require.Equal(t, "No matching proposals found", proposalsQuery)
|
||||||
|
|
||||||
proposalsQuery, _ = tests.ExecuteT(t, fmt.Sprintf("gaiacli query proposals --status=VotingPeriod %v", flags), "")
|
proposalsQuery, _ = tests.ExecuteT(t, fmt.Sprintf("gaiacli query gov proposals --status=VotingPeriod %v", flags), "")
|
||||||
require.Equal(t, " 1 - Test", proposalsQuery)
|
require.Equal(t, " 1 - Test", proposalsQuery)
|
||||||
|
|
||||||
// submit a second test proposal
|
// submit a second test proposal
|
||||||
spStr = fmt.Sprintf("gaiacli tx submit-proposal %v", flags)
|
spStr = fmt.Sprintf("gaiacli tx gov submit-proposal %v", flags)
|
||||||
spStr += fmt.Sprintf(" --from=%s", "foo")
|
spStr += fmt.Sprintf(" --from=%s", "foo")
|
||||||
spStr += fmt.Sprintf(" --deposit=%s", "5steak")
|
spStr += fmt.Sprintf(" --deposit=%s", fmt.Sprintf("5%s", stakeTypes.DefaultBondDenom))
|
||||||
spStr += fmt.Sprintf(" --type=%s", "Text")
|
spStr += fmt.Sprintf(" --type=%s", "Text")
|
||||||
spStr += fmt.Sprintf(" --title=%s", "Apples")
|
spStr += fmt.Sprintf(" --title=%s", "Apples")
|
||||||
spStr += fmt.Sprintf(" --description=%s", "test")
|
spStr += fmt.Sprintf(" --description=%s", "test")
|
||||||
|
@ -439,7 +449,7 @@ func TestGaiaCLISubmitProposal(t *testing.T) {
|
||||||
executeWrite(t, spStr, app.DefaultKeyPass)
|
executeWrite(t, spStr, app.DefaultKeyPass)
|
||||||
tests.WaitForNextNBlocksTM(2, port)
|
tests.WaitForNextNBlocksTM(2, port)
|
||||||
|
|
||||||
proposalsQuery, _ = tests.ExecuteT(t, fmt.Sprintf("gaiacli query proposals --limit=1 %v", flags), "")
|
proposalsQuery, _ = tests.ExecuteT(t, fmt.Sprintf("gaiacli query gov proposals --limit=1 %v", flags), "")
|
||||||
require.Equal(t, " 2 - Apples", proposalsQuery)
|
require.Equal(t, " 2 - Apples", proposalsQuery)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -460,8 +470,8 @@ func TestGaiaCLISendGenerateSignAndBroadcast(t *testing.T) {
|
||||||
|
|
||||||
// Test generate sendTx with default gas
|
// Test generate sendTx with default gas
|
||||||
success, stdout, stderr := executeWriteRetStdStreams(t, fmt.Sprintf(
|
success, stdout, stderr := executeWriteRetStdStreams(t, fmt.Sprintf(
|
||||||
"gaiacli tx send %v --amount=10steak --to=%s --from=foo --generate-only",
|
"gaiacli tx send %v --amount=10%s --to=%s --from=foo --generate-only",
|
||||||
flags, barAddr), []string{}...)
|
flags, stakeTypes.DefaultBondDenom, barAddr), []string{}...)
|
||||||
require.True(t, success)
|
require.True(t, success)
|
||||||
require.Empty(t, stderr)
|
require.Empty(t, stderr)
|
||||||
msg := unmarshalStdTx(t, stdout)
|
msg := unmarshalStdTx(t, stdout)
|
||||||
|
@ -471,8 +481,8 @@ func TestGaiaCLISendGenerateSignAndBroadcast(t *testing.T) {
|
||||||
|
|
||||||
// Test generate sendTx with --gas=$amount
|
// Test generate sendTx with --gas=$amount
|
||||||
success, stdout, stderr = executeWriteRetStdStreams(t, fmt.Sprintf(
|
success, stdout, stderr = executeWriteRetStdStreams(t, fmt.Sprintf(
|
||||||
"gaiacli tx send %v --amount=10steak --to=%s --from=foo --gas=100 --generate-only",
|
"gaiacli tx send %v --amount=10%s --to=%s --from=foo --gas=100 --generate-only",
|
||||||
flags, barAddr), []string{}...)
|
flags, stakeTypes.DefaultBondDenom, barAddr), []string{}...)
|
||||||
require.True(t, success)
|
require.True(t, success)
|
||||||
require.Empty(t, stderr)
|
require.Empty(t, stderr)
|
||||||
msg = unmarshalStdTx(t, stdout)
|
msg = unmarshalStdTx(t, stdout)
|
||||||
|
@ -482,8 +492,8 @@ func TestGaiaCLISendGenerateSignAndBroadcast(t *testing.T) {
|
||||||
|
|
||||||
// Test generate sendTx, estimate gas
|
// Test generate sendTx, estimate gas
|
||||||
success, stdout, stderr = executeWriteRetStdStreams(t, fmt.Sprintf(
|
success, stdout, stderr = executeWriteRetStdStreams(t, fmt.Sprintf(
|
||||||
"gaiacli tx send %v --amount=10steak --to=%s --from=foo --gas=simulate --generate-only",
|
"gaiacli tx send %v --amount=10%s --to=%s --from=foo --gas=simulate --generate-only",
|
||||||
flags, barAddr), []string{}...)
|
flags, stakeTypes.DefaultBondDenom, barAddr), []string{}...)
|
||||||
require.True(t, success)
|
require.True(t, success)
|
||||||
require.NotEmpty(t, stderr)
|
require.NotEmpty(t, stderr)
|
||||||
msg = unmarshalStdTx(t, stdout)
|
msg = unmarshalStdTx(t, stdout)
|
||||||
|
@ -522,7 +532,7 @@ func TestGaiaCLISendGenerateSignAndBroadcast(t *testing.T) {
|
||||||
|
|
||||||
// Test broadcast
|
// Test broadcast
|
||||||
fooAcc := executeGetAccount(t, fmt.Sprintf("gaiacli query account %s %v", fooAddr, flags))
|
fooAcc := executeGetAccount(t, fmt.Sprintf("gaiacli query account %s %v", fooAddr, flags))
|
||||||
require.Equal(t, int64(50), fooAcc.GetCoins().AmountOf("steak").Int64())
|
require.Equal(t, int64(50), fooAcc.GetCoins().AmountOf(stakeTypes.DefaultBondDenom).Int64())
|
||||||
|
|
||||||
success, stdout, _ = executeWriteRetStdStreams(t, fmt.Sprintf(
|
success, stdout, _ = executeWriteRetStdStreams(t, fmt.Sprintf(
|
||||||
"gaiacli tx broadcast %v --json %v", flags, signedTxFile.Name()))
|
"gaiacli tx broadcast %v --json %v", flags, signedTxFile.Name()))
|
||||||
|
@ -536,9 +546,9 @@ func TestGaiaCLISendGenerateSignAndBroadcast(t *testing.T) {
|
||||||
tests.WaitForNextNBlocksTM(2, port)
|
tests.WaitForNextNBlocksTM(2, port)
|
||||||
|
|
||||||
barAcc := executeGetAccount(t, fmt.Sprintf("gaiacli query account %s %v", barAddr, flags))
|
barAcc := executeGetAccount(t, fmt.Sprintf("gaiacli query account %s %v", barAddr, flags))
|
||||||
require.Equal(t, int64(10), barAcc.GetCoins().AmountOf("steak").Int64())
|
require.Equal(t, int64(10), barAcc.GetCoins().AmountOf(stakeTypes.DefaultBondDenom).Int64())
|
||||||
fooAcc = executeGetAccount(t, fmt.Sprintf("gaiacli query account %s %v", fooAddr, flags))
|
fooAcc = executeGetAccount(t, fmt.Sprintf("gaiacli query account %s %v", fooAddr, flags))
|
||||||
require.Equal(t, int64(40), fooAcc.GetCoins().AmountOf("steak").Int64())
|
require.Equal(t, int64(40), fooAcc.GetCoins().AmountOf(stakeTypes.DefaultBondDenom).Int64())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGaiaCLIConfig(t *testing.T) {
|
func TestGaiaCLIConfig(t *testing.T) {
|
||||||
|
@ -552,7 +562,6 @@ func TestGaiaCLIConfig(t *testing.T) {
|
||||||
config, err := ioutil.ReadFile(path.Join(gaiacliHome, "config", "config.toml"))
|
config, err := ioutil.ReadFile(path.Join(gaiacliHome, "config", "config.toml"))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
expectedConfig := fmt.Sprintf(`chain_id = "%s"
|
expectedConfig := fmt.Sprintf(`chain_id = "%s"
|
||||||
encoding = "btc"
|
|
||||||
home = "%s"
|
home = "%s"
|
||||||
node = "%s"
|
node = "%s"
|
||||||
output = "text"
|
output = "text"
|
||||||
|
@ -571,7 +580,6 @@ trust_node = true
|
||||||
|
|
||||||
// ensure it works without an initialized gaiad state
|
// ensure it works without an initialized gaiad state
|
||||||
expectedConfig = fmt.Sprintf(`chain_id = ""
|
expectedConfig = fmt.Sprintf(`chain_id = ""
|
||||||
encoding = "btc"
|
|
||||||
home = "%s"
|
home = "%s"
|
||||||
node = "%s"
|
node = "%s"
|
||||||
output = "text"
|
output = "text"
|
||||||
|
@ -750,6 +758,15 @@ func executeGetValidatorRedelegations(t *testing.T, cmdStr string) []stake.Redel
|
||||||
return reds
|
return reds
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func executeGetValidatorDelegations(t *testing.T, cmdStr string) []stake.Delegation {
|
||||||
|
out, _ := tests.ExecuteT(t, cmdStr, "")
|
||||||
|
var delegations []stake.Delegation
|
||||||
|
cdc := app.MakeCodec()
|
||||||
|
err := cdc.UnmarshalJSON([]byte(out), &delegations)
|
||||||
|
require.NoError(t, err, "out %v\n, err %v", out, err)
|
||||||
|
return delegations
|
||||||
|
}
|
||||||
|
|
||||||
func executeGetPool(t *testing.T, cmdStr string) stake.Pool {
|
func executeGetPool(t *testing.T, cmdStr string) stake.Pool {
|
||||||
out, _ := tests.ExecuteT(t, cmdStr, "")
|
out, _ := tests.ExecuteT(t, cmdStr, "")
|
||||||
var pool stake.Pool
|
var pool stake.Pool
|
||||||
|
@ -771,6 +788,33 @@ func executeGetParams(t *testing.T, cmdStr string) stake.Params {
|
||||||
//___________________________________________________________________________________
|
//___________________________________________________________________________________
|
||||||
// gov
|
// 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 {
|
func executeGetProposal(t *testing.T, cmdStr string) gov.Proposal {
|
||||||
out, _ := tests.ExecuteT(t, cmdStr, "")
|
out, _ := tests.ExecuteT(t, cmdStr, "")
|
||||||
var proposal gov.Proposal
|
var proposal gov.Proposal
|
||||||
|
|
|
@ -13,18 +13,10 @@ import (
|
||||||
"github.com/cosmos/cosmos-sdk/client/keys"
|
"github.com/cosmos/cosmos-sdk/client/keys"
|
||||||
"github.com/cosmos/cosmos-sdk/client/lcd"
|
"github.com/cosmos/cosmos-sdk/client/lcd"
|
||||||
"github.com/cosmos/cosmos-sdk/client/rpc"
|
"github.com/cosmos/cosmos-sdk/client/rpc"
|
||||||
"github.com/cosmos/cosmos-sdk/client/tx"
|
|
||||||
"github.com/cosmos/cosmos-sdk/cmd/gaia/app"
|
"github.com/cosmos/cosmos-sdk/cmd/gaia/app"
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
"github.com/cosmos/cosmos-sdk/version"
|
"github.com/cosmos/cosmos-sdk/version"
|
||||||
|
|
||||||
authcmd "github.com/cosmos/cosmos-sdk/x/auth/client/cli"
|
|
||||||
bankcmd "github.com/cosmos/cosmos-sdk/x/bank/client/cli"
|
|
||||||
distrcmd "github.com/cosmos/cosmos-sdk/x/distribution/client/cli"
|
|
||||||
govcmd "github.com/cosmos/cosmos-sdk/x/gov/client/cli"
|
|
||||||
slashingcmd "github.com/cosmos/cosmos-sdk/x/slashing/client/cli"
|
|
||||||
stakecmd "github.com/cosmos/cosmos-sdk/x/stake/client/cli"
|
|
||||||
|
|
||||||
_ "github.com/cosmos/cosmos-sdk/client/lcd/statik"
|
_ "github.com/cosmos/cosmos-sdk/client/lcd/statik"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -40,7 +32,7 @@ const (
|
||||||
var (
|
var (
|
||||||
rootCmd = &cobra.Command{
|
rootCmd = &cobra.Command{
|
||||||
Use: "gaiacli",
|
Use: "gaiacli",
|
||||||
Short: "Gaia light-client",
|
Short: "Command line interface for interacting with gaiad",
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -57,90 +49,23 @@ func main() {
|
||||||
// TODO: setup keybase, viper object, etc. to be passed into
|
// TODO: setup keybase, viper object, etc. to be passed into
|
||||||
// the below functions and eliminate global vars, like we do
|
// the below functions and eliminate global vars, like we do
|
||||||
// with the cdc
|
// with the cdc
|
||||||
rootCmd.AddCommand(client.ConfigCmd())
|
|
||||||
|
|
||||||
// add standard rpc commands
|
// Construct Root Command
|
||||||
rpc.AddCommands(rootCmd)
|
|
||||||
|
|
||||||
//Add query commands
|
|
||||||
queryCmd := &cobra.Command{
|
|
||||||
Use: "query",
|
|
||||||
Aliases: []string{"q"},
|
|
||||||
Short: "Querying subcommands",
|
|
||||||
}
|
|
||||||
queryCmd.AddCommand(
|
|
||||||
rpc.BlockCommand(),
|
|
||||||
rpc.ValidatorCommand(),
|
|
||||||
)
|
|
||||||
tx.AddCommands(queryCmd, cdc)
|
|
||||||
queryCmd.AddCommand(client.LineBreak)
|
|
||||||
queryCmd.AddCommand(client.GetCommands(
|
|
||||||
authcmd.GetAccountCmd(storeAcc, cdc, authcmd.GetAccountDecoder(cdc)),
|
|
||||||
stakecmd.GetCmdQueryDelegation(storeStake, cdc),
|
|
||||||
stakecmd.GetCmdQueryDelegations(storeStake, cdc),
|
|
||||||
stakecmd.GetCmdQueryUnbondingDelegation(storeStake, cdc),
|
|
||||||
stakecmd.GetCmdQueryUnbondingDelegations(storeStake, cdc),
|
|
||||||
stakecmd.GetCmdQueryRedelegation(storeStake, cdc),
|
|
||||||
stakecmd.GetCmdQueryRedelegations(storeStake, cdc),
|
|
||||||
stakecmd.GetCmdQueryValidator(storeStake, cdc),
|
|
||||||
stakecmd.GetCmdQueryValidators(storeStake, cdc),
|
|
||||||
stakecmd.GetCmdQueryValidatorUnbondingDelegations(queryRouteStake, cdc),
|
|
||||||
stakecmd.GetCmdQueryValidatorRedelegations(queryRouteStake, cdc),
|
|
||||||
stakecmd.GetCmdQueryParams(storeStake, cdc),
|
|
||||||
stakecmd.GetCmdQueryPool(storeStake, cdc),
|
|
||||||
govcmd.GetCmdQueryProposal(storeGov, cdc),
|
|
||||||
govcmd.GetCmdQueryProposals(storeGov, cdc),
|
|
||||||
govcmd.GetCmdQueryVote(storeGov, cdc),
|
|
||||||
govcmd.GetCmdQueryVotes(storeGov, cdc),
|
|
||||||
govcmd.GetCmdQueryDeposit(storeGov, cdc),
|
|
||||||
govcmd.GetCmdQueryDeposits(storeGov, cdc),
|
|
||||||
slashingcmd.GetCmdQuerySigningInfo(storeSlashing, cdc),
|
|
||||||
)...)
|
|
||||||
|
|
||||||
//Add query commands
|
|
||||||
txCmd := &cobra.Command{
|
|
||||||
Use: "tx",
|
|
||||||
Short: "Transactions subcommands",
|
|
||||||
}
|
|
||||||
|
|
||||||
//Add auth and bank commands
|
|
||||||
txCmd.AddCommand(
|
|
||||||
client.PostCommands(
|
|
||||||
bankcmd.GetBroadcastCommand(cdc),
|
|
||||||
authcmd.GetSignCommand(cdc, authcmd.GetAccountDecoder(cdc)),
|
|
||||||
)...)
|
|
||||||
txCmd.AddCommand(client.LineBreak)
|
|
||||||
|
|
||||||
txCmd.AddCommand(
|
|
||||||
client.PostCommands(
|
|
||||||
stakecmd.GetCmdCreateValidator(cdc),
|
|
||||||
stakecmd.GetCmdEditValidator(cdc),
|
|
||||||
stakecmd.GetCmdDelegate(cdc),
|
|
||||||
stakecmd.GetCmdRedelegate(storeStake, cdc),
|
|
||||||
stakecmd.GetCmdUnbond(storeStake, cdc),
|
|
||||||
distrcmd.GetCmdWithdrawRewards(cdc),
|
|
||||||
distrcmd.GetCmdSetWithdrawAddr(cdc),
|
|
||||||
govcmd.GetCmdDeposit(cdc),
|
|
||||||
bankcmd.SendTxCmd(cdc),
|
|
||||||
govcmd.GetCmdSubmitProposal(cdc),
|
|
||||||
slashingcmd.GetCmdUnjail(cdc),
|
|
||||||
govcmd.GetCmdVote(cdc),
|
|
||||||
)...)
|
|
||||||
rootCmd.AddCommand(
|
rootCmd.AddCommand(
|
||||||
queryCmd,
|
rpc.InitClientCommand(),
|
||||||
txCmd,
|
rpc.StatusCommand(),
|
||||||
|
client.ConfigCmd(),
|
||||||
|
queryCmd(cdc),
|
||||||
|
txCmd(cdc),
|
||||||
|
client.LineBreak,
|
||||||
lcd.ServeCommand(cdc),
|
lcd.ServeCommand(cdc),
|
||||||
client.LineBreak,
|
client.LineBreak,
|
||||||
)
|
|
||||||
|
|
||||||
// add proxy, version and key info
|
|
||||||
rootCmd.AddCommand(
|
|
||||||
keys.Commands(),
|
keys.Commands(),
|
||||||
client.LineBreak,
|
client.LineBreak,
|
||||||
version.VersionCmd,
|
version.VersionCmd,
|
||||||
)
|
)
|
||||||
|
|
||||||
// prepare and add flags
|
// Add flags and prefix all env exposed with GA
|
||||||
executor := cli.PrepareMainCmd(rootCmd, "GA", app.DefaultCLIHome)
|
executor := cli.PrepareMainCmd(rootCmd, "GA", app.DefaultCLIHome)
|
||||||
err := initConfig(rootCmd)
|
err := initConfig(rootCmd)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -0,0 +1,83 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/cosmos/cosmos-sdk/client"
|
||||||
|
"github.com/cosmos/cosmos-sdk/client/rpc"
|
||||||
|
"github.com/cosmos/cosmos-sdk/client/tx"
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
|
authcmd "github.com/cosmos/cosmos-sdk/x/auth/client/cli"
|
||||||
|
govcmd "github.com/cosmos/cosmos-sdk/x/gov/client/cli"
|
||||||
|
slashingcmd "github.com/cosmos/cosmos-sdk/x/slashing/client/cli"
|
||||||
|
stakecmd "github.com/cosmos/cosmos-sdk/x/stake/client/cli"
|
||||||
|
amino "github.com/tendermint/go-amino"
|
||||||
|
)
|
||||||
|
|
||||||
|
func queryCmd(cdc *amino.Codec) *cobra.Command {
|
||||||
|
//Add query commands
|
||||||
|
queryCmd := &cobra.Command{
|
||||||
|
Use: "query",
|
||||||
|
Aliases: []string{"q"},
|
||||||
|
Short: "Querying subcommands",
|
||||||
|
}
|
||||||
|
|
||||||
|
// Group staking queries under a subcommand
|
||||||
|
stakeQueryCmd := &cobra.Command{
|
||||||
|
Use: "stake",
|
||||||
|
Short: "Querying commands for the staking module",
|
||||||
|
}
|
||||||
|
|
||||||
|
stakeQueryCmd.AddCommand(client.GetCommands(
|
||||||
|
stakecmd.GetCmdQueryDelegation(storeStake, cdc),
|
||||||
|
stakecmd.GetCmdQueryDelegations(storeStake, cdc),
|
||||||
|
stakecmd.GetCmdQueryUnbondingDelegation(storeStake, cdc),
|
||||||
|
stakecmd.GetCmdQueryUnbondingDelegations(storeStake, cdc),
|
||||||
|
stakecmd.GetCmdQueryRedelegation(storeStake, cdc),
|
||||||
|
stakecmd.GetCmdQueryRedelegations(storeStake, cdc),
|
||||||
|
stakecmd.GetCmdQueryValidator(storeStake, cdc),
|
||||||
|
stakecmd.GetCmdQueryValidators(storeStake, cdc),
|
||||||
|
stakecmd.GetCmdQueryValidatorDelegations(storeStake, cdc),
|
||||||
|
stakecmd.GetCmdQueryValidatorUnbondingDelegations(queryRouteStake, cdc),
|
||||||
|
stakecmd.GetCmdQueryValidatorRedelegations(queryRouteStake, cdc),
|
||||||
|
stakecmd.GetCmdQueryParams(storeStake, cdc),
|
||||||
|
stakecmd.GetCmdQueryPool(storeStake, cdc))...)
|
||||||
|
|
||||||
|
// Group gov queries under a subcommand
|
||||||
|
govQueryCmd := &cobra.Command{
|
||||||
|
Use: "gov",
|
||||||
|
Short: "Querying commands for the governance module",
|
||||||
|
}
|
||||||
|
|
||||||
|
govQueryCmd.AddCommand(client.GetCommands(
|
||||||
|
govcmd.GetCmdQueryProposal(storeGov, cdc),
|
||||||
|
govcmd.GetCmdQueryProposals(storeGov, cdc),
|
||||||
|
govcmd.GetCmdQueryVote(storeGov, cdc),
|
||||||
|
govcmd.GetCmdQueryVotes(storeGov, cdc),
|
||||||
|
govcmd.GetCmdQueryParams(storeGov, cdc),
|
||||||
|
govcmd.GetCmdQueryDeposit(storeGov, cdc),
|
||||||
|
govcmd.GetCmdQueryDeposits(storeGov, cdc))...)
|
||||||
|
|
||||||
|
// Group slashing queries under a subcommand
|
||||||
|
slashingQueryCmd := &cobra.Command{
|
||||||
|
Use: "slashing",
|
||||||
|
Short: "Querying commands for the slashing module",
|
||||||
|
}
|
||||||
|
|
||||||
|
slashingQueryCmd.AddCommand(client.GetCommands(
|
||||||
|
slashingcmd.GetCmdQuerySigningInfo(storeSlashing, cdc))...)
|
||||||
|
|
||||||
|
// Query commcmmand structure
|
||||||
|
queryCmd.AddCommand(
|
||||||
|
rpc.BlockCommand(),
|
||||||
|
rpc.ValidatorCommand(),
|
||||||
|
tx.SearchTxCmd(cdc),
|
||||||
|
tx.QueryTxCmd(cdc),
|
||||||
|
client.LineBreak,
|
||||||
|
client.GetCommands(authcmd.GetAccountCmd(storeAcc, cdc, authcmd.GetAccountDecoder(cdc)))[0],
|
||||||
|
stakeQueryCmd,
|
||||||
|
govQueryCmd,
|
||||||
|
slashingQueryCmd,
|
||||||
|
)
|
||||||
|
|
||||||
|
return queryCmd
|
||||||
|
}
|
|
@ -0,0 +1,83 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/cosmos/cosmos-sdk/client"
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
|
authcmd "github.com/cosmos/cosmos-sdk/x/auth/client/cli"
|
||||||
|
bankcmd "github.com/cosmos/cosmos-sdk/x/bank/client/cli"
|
||||||
|
distrcmd "github.com/cosmos/cosmos-sdk/x/distribution/client/cli"
|
||||||
|
govcmd "github.com/cosmos/cosmos-sdk/x/gov/client/cli"
|
||||||
|
slashingcmd "github.com/cosmos/cosmos-sdk/x/slashing/client/cli"
|
||||||
|
stakecmd "github.com/cosmos/cosmos-sdk/x/stake/client/cli"
|
||||||
|
amino "github.com/tendermint/go-amino"
|
||||||
|
)
|
||||||
|
|
||||||
|
func txCmd(cdc *amino.Codec) *cobra.Command {
|
||||||
|
//Add transaction generation commands
|
||||||
|
txCmd := &cobra.Command{
|
||||||
|
Use: "tx",
|
||||||
|
Short: "Transactions subcommands",
|
||||||
|
}
|
||||||
|
|
||||||
|
stakeTxCmd := &cobra.Command{
|
||||||
|
Use: "stake",
|
||||||
|
Short: "Staking transaction subcommands",
|
||||||
|
}
|
||||||
|
|
||||||
|
stakeTxCmd.AddCommand(client.PostCommands(
|
||||||
|
stakecmd.GetCmdCreateValidator(cdc),
|
||||||
|
stakecmd.GetCmdEditValidator(cdc),
|
||||||
|
stakecmd.GetCmdDelegate(cdc),
|
||||||
|
stakecmd.GetCmdRedelegate(storeStake, cdc),
|
||||||
|
stakecmd.GetCmdUnbond(storeStake, cdc),
|
||||||
|
)...)
|
||||||
|
|
||||||
|
distTxCmd := &cobra.Command{
|
||||||
|
Use: "dist",
|
||||||
|
Short: "Distribution transactions subcommands",
|
||||||
|
}
|
||||||
|
|
||||||
|
distTxCmd.AddCommand(client.PostCommands(
|
||||||
|
distrcmd.GetCmdWithdrawRewards(cdc),
|
||||||
|
distrcmd.GetCmdSetWithdrawAddr(cdc),
|
||||||
|
)...)
|
||||||
|
|
||||||
|
govTxCmd := &cobra.Command{
|
||||||
|
Use: "gov",
|
||||||
|
Short: "Governance transactions subcommands",
|
||||||
|
}
|
||||||
|
|
||||||
|
govTxCmd.AddCommand(client.PostCommands(
|
||||||
|
govcmd.GetCmdDeposit(cdc),
|
||||||
|
govcmd.GetCmdVote(cdc),
|
||||||
|
govcmd.GetCmdSubmitProposal(cdc),
|
||||||
|
)...)
|
||||||
|
|
||||||
|
slashingTxCmd := &cobra.Command{
|
||||||
|
Use: "slashing",
|
||||||
|
Short: "Slashing transactions subcommands",
|
||||||
|
}
|
||||||
|
|
||||||
|
slashingTxCmd.AddCommand(client.PostCommands(
|
||||||
|
slashingcmd.GetCmdUnjail(cdc),
|
||||||
|
)...)
|
||||||
|
|
||||||
|
txCmd.AddCommand(
|
||||||
|
//Add auth and bank commands
|
||||||
|
client.PostCommands(
|
||||||
|
bankcmd.SendTxCmd(cdc),
|
||||||
|
bankcmd.GetBroadcastCommand(cdc),
|
||||||
|
authcmd.GetSignCommand(cdc, authcmd.GetAccountDecoder(cdc)),
|
||||||
|
)...)
|
||||||
|
|
||||||
|
txCmd.AddCommand(
|
||||||
|
client.LineBreak,
|
||||||
|
stakeTxCmd,
|
||||||
|
distTxCmd,
|
||||||
|
govTxCmd,
|
||||||
|
slashingTxCmd,
|
||||||
|
)
|
||||||
|
|
||||||
|
return txCmd
|
||||||
|
}
|
|
@ -9,6 +9,7 @@ import (
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
authcmd "github.com/cosmos/cosmos-sdk/x/auth/client/cli"
|
authcmd "github.com/cosmos/cosmos-sdk/x/auth/client/cli"
|
||||||
"github.com/cosmos/cosmos-sdk/x/stake/client/cli"
|
"github.com/cosmos/cosmos-sdk/x/stake/client/cli"
|
||||||
|
stakeTypes "github.com/cosmos/cosmos-sdk/x/stake/types"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
cfg "github.com/tendermint/tendermint/config"
|
cfg "github.com/tendermint/tendermint/config"
|
||||||
|
@ -21,7 +22,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
defaultAmount = "100steak"
|
defaultAmount = "100" + stakeTypes.DefaultBondDenom
|
||||||
defaultCommissionRate = "0.1"
|
defaultCommissionRate = "0.1"
|
||||||
defaultCommissionMaxRate = "0.2"
|
defaultCommissionMaxRate = "0.2"
|
||||||
defaultCommissionMaxChangeRate = "0.01"
|
defaultCommissionMaxChangeRate = "0.01"
|
||||||
|
|
|
@ -51,25 +51,27 @@ func InitCmd(ctx *server.Context, cdc *codec.Codec, appInit server.AppInit) *cob
|
||||||
RunE: func(_ *cobra.Command, _ []string) error {
|
RunE: func(_ *cobra.Command, _ []string) error {
|
||||||
config := ctx.Config
|
config := ctx.Config
|
||||||
config.SetRoot(viper.GetString(cli.HomeFlag))
|
config.SetRoot(viper.GetString(cli.HomeFlag))
|
||||||
|
|
||||||
chainID := viper.GetString(client.FlagChainID)
|
chainID := viper.GetString(client.FlagChainID)
|
||||||
if chainID == "" {
|
if chainID == "" {
|
||||||
chainID = fmt.Sprintf("test-chain-%v", common.RandStr(6))
|
chainID = fmt.Sprintf("test-chain-%v", common.RandStr(6))
|
||||||
}
|
}
|
||||||
|
|
||||||
nodeID, _, err := InitializeNodeValidatorFiles(config)
|
nodeID, _, err := InitializeNodeValidatorFiles(config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if viper.GetString(flagMoniker) != "" {
|
|
||||||
config.Moniker = viper.GetString(flagMoniker)
|
config.Moniker = viper.GetString(flagMoniker)
|
||||||
}
|
|
||||||
|
|
||||||
var appState json.RawMessage
|
var appState json.RawMessage
|
||||||
genFile := config.GenesisFile()
|
genFile := config.GenesisFile()
|
||||||
|
|
||||||
if appState, err = initializeEmptyGenesis(cdc, genFile, chainID,
|
if appState, err = initializeEmptyGenesis(cdc, genFile, chainID,
|
||||||
viper.GetBool(flagOverwrite)); err != nil {
|
viper.GetBool(flagOverwrite)); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = ExportGenesisFile(genFile, chainID, nil, appState); err != nil {
|
if err = ExportGenesisFile(genFile, chainID, nil, appState); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -91,5 +93,7 @@ func InitCmd(ctx *server.Context, cdc *codec.Codec, appInit server.AppInit) *cob
|
||||||
cmd.Flags().BoolP(flagOverwrite, "o", false, "overwrite the genesis.json file")
|
cmd.Flags().BoolP(flagOverwrite, "o", false, "overwrite the genesis.json file")
|
||||||
cmd.Flags().String(client.FlagChainID, "", "genesis file chain-id, if left blank will be randomly created")
|
cmd.Flags().String(client.FlagChainID, "", "genesis file chain-id, if left blank will be randomly created")
|
||||||
cmd.Flags().String(flagMoniker, "", "set the validator's moniker")
|
cmd.Flags().String(flagMoniker, "", "set the validator's moniker")
|
||||||
|
cmd.MarkFlagRequired(flagMoniker)
|
||||||
|
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,15 +2,16 @@ package init
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"github.com/cosmos/cosmos-sdk/client"
|
|
||||||
"github.com/cosmos/cosmos-sdk/cmd/gaia/app"
|
|
||||||
"github.com/tendermint/tendermint/libs/cli"
|
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/cosmos/cosmos-sdk/client"
|
||||||
|
"github.com/cosmos/cosmos-sdk/cmd/gaia/app"
|
||||||
|
"github.com/tendermint/tendermint/libs/cli"
|
||||||
|
|
||||||
"github.com/cosmos/cosmos-sdk/server"
|
"github.com/cosmos/cosmos-sdk/server"
|
||||||
"github.com/cosmos/cosmos-sdk/server/mock"
|
"github.com/cosmos/cosmos-sdk/server/mock"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
@ -28,12 +29,16 @@ func TestInitCmd(t *testing.T) {
|
||||||
logger := log.NewNopLogger()
|
logger := log.NewNopLogger()
|
||||||
cfg, err := tcmd.ParseConfig()
|
cfg, err := tcmd.ParseConfig()
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
|
|
||||||
ctx := server.NewContext(cfg, logger)
|
ctx := server.NewContext(cfg, logger)
|
||||||
cdc := app.MakeCodec()
|
cdc := app.MakeCodec()
|
||||||
appInit := server.AppInit{
|
appInit := server.AppInit{
|
||||||
AppGenState: mock.AppGenState,
|
AppGenState: mock.AppGenState,
|
||||||
}
|
}
|
||||||
cmd := InitCmd(ctx, cdc, appInit)
|
cmd := InitCmd(ctx, cdc, appInit)
|
||||||
|
|
||||||
|
viper.Set(flagMoniker, "gaianode-test")
|
||||||
|
|
||||||
err = cmd.RunE(nil, nil)
|
err = cmd.RunE(nil, nil)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
}
|
}
|
||||||
|
@ -53,14 +58,19 @@ func setupClientHome(t *testing.T) func() {
|
||||||
func TestEmptyState(t *testing.T) {
|
func TestEmptyState(t *testing.T) {
|
||||||
defer server.SetupViper(t)()
|
defer server.SetupViper(t)()
|
||||||
defer setupClientHome(t)()
|
defer setupClientHome(t)()
|
||||||
|
|
||||||
logger := log.NewNopLogger()
|
logger := log.NewNopLogger()
|
||||||
cfg, err := tcmd.ParseConfig()
|
cfg, err := tcmd.ParseConfig()
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
|
|
||||||
ctx := server.NewContext(cfg, logger)
|
ctx := server.NewContext(cfg, logger)
|
||||||
cdc := app.MakeCodec()
|
cdc := app.MakeCodec()
|
||||||
appInit := server.AppInit{
|
appInit := server.AppInit{
|
||||||
AppGenState: mock.AppGenStateEmpty,
|
AppGenState: mock.AppGenStateEmpty,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
viper.Set(flagMoniker, "gaianode-test")
|
||||||
|
|
||||||
cmd := InitCmd(ctx, cdc, appInit)
|
cmd := InitCmd(ctx, cdc, appInit)
|
||||||
err = cmd.RunE(nil, nil)
|
err = cmd.RunE(nil, nil)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
@ -69,6 +79,7 @@ func TestEmptyState(t *testing.T) {
|
||||||
r, w, _ := os.Pipe()
|
r, w, _ := os.Pipe()
|
||||||
os.Stdout = w
|
os.Stdout = w
|
||||||
cmd = server.ExportCmd(ctx, cdc, nil)
|
cmd = server.ExportCmd(ctx, cdc, nil)
|
||||||
|
|
||||||
err = cmd.RunE(nil, nil)
|
err = cmd.RunE(nil, nil)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
|
|
@ -14,6 +14,7 @@ import (
|
||||||
"github.com/cosmos/cosmos-sdk/x/auth"
|
"github.com/cosmos/cosmos-sdk/x/auth"
|
||||||
authtx "github.com/cosmos/cosmos-sdk/x/auth/client/txbuilder"
|
authtx "github.com/cosmos/cosmos-sdk/x/auth/client/txbuilder"
|
||||||
"github.com/cosmos/cosmos-sdk/x/stake"
|
"github.com/cosmos/cosmos-sdk/x/stake"
|
||||||
|
stakeTypes "github.com/cosmos/cosmos-sdk/x/stake/types"
|
||||||
|
|
||||||
"github.com/cosmos/cosmos-sdk/server"
|
"github.com/cosmos/cosmos-sdk/server"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
@ -180,14 +181,14 @@ func initTestnet(config *cfg.Config, cdc *codec.Codec) error {
|
||||||
Address: addr,
|
Address: addr,
|
||||||
Coins: sdk.Coins{
|
Coins: sdk.Coins{
|
||||||
sdk.NewInt64Coin(fmt.Sprintf("%sToken", nodeDirName), 1000),
|
sdk.NewInt64Coin(fmt.Sprintf("%sToken", nodeDirName), 1000),
|
||||||
sdk.NewInt64Coin("steak", 150),
|
sdk.NewInt64Coin(stakeTypes.DefaultBondDenom, 150),
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
msg := stake.NewMsgCreateValidator(
|
msg := stake.NewMsgCreateValidator(
|
||||||
sdk.ValAddress(addr),
|
sdk.ValAddress(addr),
|
||||||
valPubKeys[i],
|
valPubKeys[i],
|
||||||
sdk.NewInt64Coin("steak", 100),
|
sdk.NewInt64Coin(stakeTypes.DefaultBondDenom, 100),
|
||||||
stake.NewDescription(nodeDirName, "", "", ""),
|
stake.NewDescription(nodeDirName, "", "", ""),
|
||||||
stake.NewCommissionMsg(sdk.ZeroDec(), sdk.ZeroDec(), sdk.ZeroDec()),
|
stake.NewCommissionMsg(sdk.ZeroDec(), sdk.ZeroDec(), sdk.ZeroDec()),
|
||||||
)
|
)
|
||||||
|
|
|
@ -341,6 +341,13 @@ Additionally, as you can get all the outgoing redelegations from a particular va
|
||||||
|
|
||||||
To get previous redelegation(s) status on past blocks, try adding the `--height` flag.
|
To get previous redelegation(s) status on past blocks, try adding the `--height` flag.
|
||||||
|
|
||||||
|
##### Query Delegations To Validator
|
||||||
|
|
||||||
|
You can also query all of the delegations to a particular validator:
|
||||||
|
```bash
|
||||||
|
gaiacli query delegations-to <account_cosmosval>
|
||||||
|
```
|
||||||
|
|
||||||
### Governance
|
### Governance
|
||||||
|
|
||||||
Governance is the process from which users in the Cosmos Hub can come to consensus on software upgrades, parameters of the mainnet or on custom text proposals. This is done through voting on proposals, which will be submitted by `Atom` holders on the mainnet.
|
Governance is the process from which users in the Cosmos Hub can come to consensus on software upgrades, parameters of the mainnet or on custom text proposals. This is done through voting on proposals, which will be submitted by `Atom` holders on the mainnet.
|
||||||
|
|
|
@ -24,7 +24,7 @@ The following specification uses *Atom* as the native staking token. The module
|
||||||
1. **[Design overview](overview.md)**
|
1. **[Design overview](overview.md)**
|
||||||
2. **Implementation**
|
2. **Implementation**
|
||||||
1. **[State](state.md)**
|
1. **[State](state.md)**
|
||||||
1. Procedures
|
1. Parameters
|
||||||
2. Proposals
|
2. Proposals
|
||||||
3. Proposal Processing Queue
|
3. Proposal Processing Queue
|
||||||
2. **[Transactions](transactions.md)**
|
2. **[Transactions](transactions.md)**
|
||||||
|
|
|
@ -2,36 +2,35 @@
|
||||||
|
|
||||||
## State
|
## 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
|
```go
|
||||||
type DepositProcedure struct {
|
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
|
MaxDepositPeriod time.Time // Maximum period for Atom holders to deposit on a proposal. Initial value: 2 months
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
```go
|
```go
|
||||||
type VotingProcedure struct {
|
type VotingParams struct {
|
||||||
VotingPeriod time.Time // Length of the voting period. Initial value: 2 weeks
|
VotingPeriod time.Time // Length of the voting period. Initial value: 2 weeks
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
```go
|
```go
|
||||||
type TallyingProcedure struct {
|
type TallyParams struct {
|
||||||
Threshold sdk.Dec // Minimum propotion of Yes votes for proposal to pass. Initial value: 0.5
|
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
|
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
|
GovernancePenalty sdk.Dec // Penalty if validator does not vote
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
Procedures are stored in a global `GlobalParams` KVStore.
|
Parameters are stored in a global `GlobalParams` KVStore.
|
||||||
|
|
||||||
Additionally, we introduce some basic types:
|
Additionally, we introduce some basic types:
|
||||||
|
|
||||||
|
@ -61,7 +60,7 @@ const (
|
||||||
ProposalStatusActive = 0x2 // MinDeposit is reachhed, participants can vote
|
ProposalStatusActive = 0x2 // MinDeposit is reachhed, participants can vote
|
||||||
ProposalStatusAccepted = 0x3 // Proposal has been accepted
|
ProposalStatusAccepted = 0x3 // Proposal has been accepted
|
||||||
ProposalStatusRejected = 0x4 // Proposal has been rejected
|
ProposalStatusRejected = 0x4 // Proposal has been rejected
|
||||||
ProposalStatusClosed. = 0x5 // Proposal never reached MinDeposit
|
ProposalStatusClosed = 0x5 // Proposal never reached MinDeposit
|
||||||
)
|
)
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -171,7 +170,7 @@ And the pseudocode for the `ProposalProcessingQueue`:
|
||||||
if (isVal)
|
if (isVal)
|
||||||
tmpValMap(voterAddress).Vote = vote
|
tmpValMap(voterAddress).Vote = vote
|
||||||
|
|
||||||
tallyingProcedure = load(GlobalParams, 'TallyingProcedure')
|
tallyingParam = load(GlobalParams, 'TallyingParam')
|
||||||
|
|
||||||
// Update tally if validator voted they voted
|
// Update tally if validator voted they voted
|
||||||
for each validator in validators
|
for each validator in validators
|
||||||
|
@ -182,7 +181,7 @@ And the pseudocode for the `ProposalProcessingQueue`:
|
||||||
|
|
||||||
// Check if proposal is accepted or rejected
|
// Check if proposal is accepted or rejected
|
||||||
totalNonAbstain := proposal.YesVotes + proposal.NoVotes + proposal.NoWithVetoVotes
|
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
|
// proposal was accepted at the end of the voting period
|
||||||
// refund deposits (non-voters already punished)
|
// refund deposits (non-voters already punished)
|
||||||
proposal.CurrentStatus = ProposalStatusAccepted
|
proposal.CurrentStatus = ProposalStatusAccepted
|
||||||
|
|
|
@ -46,7 +46,7 @@ upon receiving txGovSubmitProposal from sender do
|
||||||
|
|
||||||
sender.AtomBalance -= initialDeposit.Atoms
|
sender.AtomBalance -= initialDeposit.Atoms
|
||||||
|
|
||||||
depositProcedure = load(GlobalParams, 'DepositProcedure')
|
depositParam = load(GlobalParams, 'DepositParam')
|
||||||
|
|
||||||
proposalID = generate new proposalID
|
proposalID = generate new proposalID
|
||||||
proposal = NewProposal()
|
proposal = NewProposal()
|
||||||
|
@ -56,7 +56,7 @@ upon receiving txGovSubmitProposal from sender do
|
||||||
proposal.Type = txGovSubmitProposal.Type
|
proposal.Type = txGovSubmitProposal.Type
|
||||||
proposal.TotalDeposit = initialDeposit
|
proposal.TotalDeposit = initialDeposit
|
||||||
proposal.SubmitTime = <CurrentTime>
|
proposal.SubmitTime = <CurrentTime>
|
||||||
proposal.DepositEndTime = <CurrentTime>.Add(depositProcedure.MaxDepositPeriod)
|
proposal.DepositEndTime = <CurrentTime>.Add(depositParam.MaxDepositPeriod)
|
||||||
proposal.Deposits.append({initialDeposit, sender})
|
proposal.Deposits.append({initialDeposit, sender})
|
||||||
proposal.Submitter = sender
|
proposal.Submitter = sender
|
||||||
proposal.YesVotes = 0
|
proposal.YesVotes = 0
|
||||||
|
@ -72,7 +72,7 @@ upon receiving txGovSubmitProposal from sender do
|
||||||
### Deposit
|
### Deposit
|
||||||
|
|
||||||
Once a proposal is submitted, if
|
Once a proposal is submitted, if
|
||||||
`Proposal.TotalDeposit < ActiveProcedure.MinDeposit`, Atom holders can send
|
`Proposal.TotalDeposit < ActiveParam.MinDeposit`, Atom holders can send
|
||||||
`TxGovDeposit` transactions to increase the proposal's deposit.
|
`TxGovDeposit` transactions to increase the proposal's deposit.
|
||||||
|
|
||||||
```go
|
```go
|
||||||
|
@ -116,9 +116,9 @@ upon receiving txGovDeposit from sender do
|
||||||
|
|
||||||
throw
|
throw
|
||||||
|
|
||||||
depositProcedure = load(GlobalParams, 'DepositProcedure')
|
depositParam = load(GlobalParams, 'DepositParam')
|
||||||
|
|
||||||
if (CurrentBlock >= proposal.SubmitBlock + depositProcedure.MaxDepositPeriod)
|
if (CurrentBlock >= proposal.SubmitBlock + depositParam.MaxDepositPeriod)
|
||||||
proposal.CurrentStatus = ProposalStatusClosed
|
proposal.CurrentStatus = ProposalStatusClosed
|
||||||
|
|
||||||
else
|
else
|
||||||
|
@ -128,7 +128,7 @@ upon receiving txGovDeposit from sender do
|
||||||
proposal.Deposits.append({txGovVote.Deposit, sender})
|
proposal.Deposits.append({txGovVote.Deposit, sender})
|
||||||
proposal.TotalDeposit.Plus(txGovDeposit.Deposit)
|
proposal.TotalDeposit.Plus(txGovDeposit.Deposit)
|
||||||
|
|
||||||
if (proposal.TotalDeposit >= depositProcedure.MinDeposit)
|
if (proposal.TotalDeposit >= depositParam.MinDeposit)
|
||||||
// MinDeposit is reached, vote opens
|
// MinDeposit is reached, vote opens
|
||||||
|
|
||||||
proposal.VotingStartBlock = CurrentBlock
|
proposal.VotingStartBlock = CurrentBlock
|
||||||
|
@ -140,7 +140,7 @@ upon receiving txGovDeposit from sender do
|
||||||
|
|
||||||
### Vote
|
### Vote
|
||||||
|
|
||||||
Once `ActiveProcedure.MinDeposit` is reached, voting period starts. From there,
|
Once `ActiveParam.MinDeposit` is reached, voting period starts. From there,
|
||||||
bonded Atom holders are able to send `TxGovVote` transactions to cast their
|
bonded Atom holders are able to send `TxGovVote` transactions to cast their
|
||||||
vote on the proposal.
|
vote on the proposal.
|
||||||
|
|
||||||
|
|
|
@ -39,10 +39,14 @@ func main() {
|
||||||
// with the cdc.
|
// with the cdc.
|
||||||
|
|
||||||
// add standard rpc, and tx commands
|
// add standard rpc, and tx commands
|
||||||
rpc.AddCommands(rootCmd)
|
rootCmd.AddCommand(
|
||||||
rootCmd.AddCommand(client.LineBreak)
|
rpc.InitClientCommand(),
|
||||||
tx.AddCommands(rootCmd, cdc)
|
rpc.StatusCommand(),
|
||||||
rootCmd.AddCommand(client.LineBreak)
|
client.LineBreak,
|
||||||
|
tx.SearchTxCmd(cdc),
|
||||||
|
tx.QueryTxCmd(cdc),
|
||||||
|
client.LineBreak,
|
||||||
|
)
|
||||||
|
|
||||||
// add query/post commands (custom to binary)
|
// add query/post commands (custom to binary)
|
||||||
rootCmd.AddCommand(
|
rootCmd.AddCommand(
|
||||||
|
|
|
@ -3,10 +3,11 @@ package clitest
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/cosmos/cosmos-sdk/cmd/gaia/app"
|
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/cosmos/cosmos-sdk/cmd/gaia/app"
|
||||||
|
|
||||||
"github.com/cosmos/cosmos-sdk/server"
|
"github.com/cosmos/cosmos-sdk/server"
|
||||||
"github.com/cosmos/cosmos-sdk/tests"
|
"github.com/cosmos/cosmos-sdk/tests"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
|
@ -52,10 +52,15 @@ func main() {
|
||||||
// with the cdc
|
// with the cdc
|
||||||
|
|
||||||
// add standard rpc, and tx commands
|
// add standard rpc, and tx commands
|
||||||
rpc.AddCommands(rootCmd)
|
|
||||||
rootCmd.AddCommand(client.LineBreak)
|
rootCmd.AddCommand(
|
||||||
tx.AddCommands(rootCmd, cdc)
|
rpc.InitClientCommand(),
|
||||||
rootCmd.AddCommand(client.LineBreak)
|
rpc.StatusCommand(),
|
||||||
|
client.LineBreak,
|
||||||
|
tx.SearchTxCmd(cdc),
|
||||||
|
tx.QueryTxCmd(cdc),
|
||||||
|
client.LineBreak,
|
||||||
|
)
|
||||||
|
|
||||||
// add query/post commands (custom to binary)
|
// add query/post commands (custom to binary)
|
||||||
// start with commands common to basecoin
|
// start with commands common to basecoin
|
||||||
|
|
|
@ -8,7 +8,7 @@ import (
|
||||||
"github.com/cosmos/cosmos-sdk/x/bank"
|
"github.com/cosmos/cosmos-sdk/x/bank"
|
||||||
)
|
)
|
||||||
|
|
||||||
const stakingToken = "steak"
|
const stakingToken = "stake"
|
||||||
|
|
||||||
const moduleName = "simplestake"
|
const moduleName = "simplestake"
|
||||||
|
|
||||||
|
|
|
@ -75,10 +75,10 @@ func TestBonding(t *testing.T) {
|
||||||
_, _, err := stakeKeeper.unbondWithoutCoins(ctx, addr)
|
_, _, err := stakeKeeper.unbondWithoutCoins(ctx, addr)
|
||||||
require.Equal(t, err, ErrInvalidUnbond(DefaultCodespace))
|
require.Equal(t, err, ErrInvalidUnbond(DefaultCodespace))
|
||||||
|
|
||||||
_, err = stakeKeeper.bondWithoutCoins(ctx, addr, pubKey, sdk.NewInt64Coin("steak", 10))
|
_, err = stakeKeeper.bondWithoutCoins(ctx, addr, pubKey, sdk.NewInt64Coin("stake", 10))
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
|
|
||||||
power, err := stakeKeeper.bondWithoutCoins(ctx, addr, pubKey, sdk.NewInt64Coin("steak", 10))
|
power, err := stakeKeeper.bondWithoutCoins(ctx, addr, pubKey, sdk.NewInt64Coin("stake", 10))
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
require.Equal(t, int64(20), power)
|
require.Equal(t, int64(20), power)
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,54 @@
|
||||||
|
###
|
||||||
|
# Find OS and Go environment
|
||||||
|
# GO contains the Go binary
|
||||||
|
# FS contains the OS file separator
|
||||||
|
###
|
||||||
|
ifeq ($(OS),Windows_NT)
|
||||||
|
GO := $(shell where go.exe 2> NUL)
|
||||||
|
FS := \\
|
||||||
|
else
|
||||||
|
GO := $(shell command -v go 2> /dev/null)
|
||||||
|
FS := /
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifeq ($(GO),)
|
||||||
|
$(error could not find go. Is it in PATH? $(GO))
|
||||||
|
endif
|
||||||
|
|
||||||
|
GOPATH ?= $(shell $(GO) env GOPATH)
|
||||||
|
GITHUBDIR := $(GOPATH)$(FS)src$(FS)github.com
|
||||||
|
|
||||||
|
###
|
||||||
|
# Functions
|
||||||
|
###
|
||||||
|
|
||||||
|
go_get = $(if $(findstring Windows_NT,$(OS)),\
|
||||||
|
IF NOT EXIST $(GITHUBDIR)$(FS)$(1)$(FS) ( mkdir $(GITHUBDIR)$(FS)$(1) ) else (cd .) &\
|
||||||
|
IF NOT EXIST $(GITHUBDIR)$(FS)$(1)$(FS)$(2)$(FS) ( cd $(GITHUBDIR)$(FS)$(1) && git clone https://github.com/$(1)/$(2) ) else (cd .) &\
|
||||||
|
,\
|
||||||
|
mkdir -p $(GITHUBDIR)$(FS)$(1) &&\
|
||||||
|
(test ! -d $(GITHUBDIR)$(FS)$(1)$(FS)$(2) && cd $(GITHUBDIR)$(FS)$(1) && git clone https://github.com/$(1)/$(2)) || true &&\
|
||||||
|
)\
|
||||||
|
cd $(GITHUBDIR)$(FS)$(1)$(FS)$(2) && git fetch origin && git checkout -q $(3)
|
||||||
|
|
||||||
|
go_install = $(call go_get,$(1),$(2),$(3)) && cd $(GITHUBDIR)$(FS)$(1)$(FS)$(2) && $(GO) install
|
||||||
|
|
||||||
|
###
|
||||||
|
# get_tools
|
||||||
|
###
|
||||||
|
all: get_tools
|
||||||
|
get_tools: dep gometalinter statik
|
||||||
|
|
||||||
|
dep:
|
||||||
|
$(call go_get,golang,dep,22125cfaa6ddc71e145b1535d4b7ee9744fefff2)
|
||||||
|
cd $(GITHUBDIR)$(FS)golang$(FS)dep$(FS)cmd$(FS)dep && $(GO) install
|
||||||
|
|
||||||
|
#v2.0.11
|
||||||
|
gometalinter:
|
||||||
|
$(call go_install,alecthomas,gometalinter,17a7ffa42374937bfecabfb8d2efbd4db0c26741)
|
||||||
|
|
||||||
|
statik:
|
||||||
|
$(call go_install,rakyll,statik,v0.1.5)
|
||||||
|
|
||||||
|
.PHONY: all get_tools dep gometalinter statik
|
||||||
|
|
|
@ -1,49 +0,0 @@
|
||||||
#!/usr/bin/env bash
|
|
||||||
set -e
|
|
||||||
|
|
||||||
# This file downloads all of the binary dependencies we have, and checks out a
|
|
||||||
# specific git hash.
|
|
||||||
#
|
|
||||||
# repos it installs:
|
|
||||||
# github.com/golang/dep/cmd/dep
|
|
||||||
# gopkg.in/alecthomas/gometalinter.v2
|
|
||||||
# github.com/rakyll/statiik
|
|
||||||
|
|
||||||
## check if GOPATH is set
|
|
||||||
if [ -z ${GOPATH+x} ]; then
|
|
||||||
echo "please set GOPATH (https://github.com/golang/go/wiki/SettingGOPATH)"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
mkdir -p "$GOPATH/src/github.com"
|
|
||||||
cd "$GOPATH/src/github.com" || exit 1
|
|
||||||
|
|
||||||
installFromGithub() {
|
|
||||||
repo=$1
|
|
||||||
commit=$2
|
|
||||||
# optional
|
|
||||||
subdir=$3
|
|
||||||
echo "--> Installing $repo ($commit)..."
|
|
||||||
if [ ! -d "$repo" ]; then
|
|
||||||
mkdir -p "$repo"
|
|
||||||
git clone "https://github.com/$repo.git" "$repo"
|
|
||||||
fi
|
|
||||||
if [ ! -z ${subdir+x} ] && [ ! -d "$repo/$subdir" ]; then
|
|
||||||
echo "ERROR: no such directory $repo/$subdir"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
pushd "$repo" && \
|
|
||||||
git fetch origin && \
|
|
||||||
git checkout -q "$commit" && \
|
|
||||||
if [ ! -z ${subdir+x} ]; then cd "$subdir" || exit 1; fi && \
|
|
||||||
go install && \
|
|
||||||
if [ ! -z ${subdir+x} ]; then cd - || exit 1; fi && \
|
|
||||||
popd || exit 1
|
|
||||||
echo "--> Done"
|
|
||||||
echo ""
|
|
||||||
}
|
|
||||||
|
|
||||||
installFromGithub golang/dep 22125cfaa6ddc71e145b1535d4b7ee9744fefff2 cmd/dep
|
|
||||||
## gometalinter v2.0.11
|
|
||||||
installFromGithub alecthomas/gometalinter 17a7ffa42374937bfecabfb8d2efbd4db0c26741
|
|
||||||
installFromGithub rakyll/statik v0.1.5
|
|
|
@ -17,7 +17,7 @@ echo "Using temporary log directory: $tmpdir"
|
||||||
sim() {
|
sim() {
|
||||||
seed=$1
|
seed=$1
|
||||||
echo "Running full Gaia simulation with seed $seed. This may take awhile!"
|
echo "Running full Gaia simulation with seed $seed. This may take awhile!"
|
||||||
file="$tmpdir/gaia-simulation-seed-$seed-date-$(date -Iseconds -u).stdout"
|
file="$tmpdir/gaia-simulation-seed-$seed-date-$(date -u +"%Y-%m-%dT%H:%M:%S+00:00").stdout"
|
||||||
echo "Writing stdout to $file..."
|
echo "Writing stdout to $file..."
|
||||||
go test ./cmd/gaia/app -run TestFullGaiaSimulation -SimulationEnabled=true -SimulationNumBlocks=$blocks \
|
go test ./cmd/gaia/app -run TestFullGaiaSimulation -SimulationEnabled=true -SimulationNumBlocks=$blocks \
|
||||||
-SimulationVerbose=true -SimulationCommit=true -SimulationSeed=$seed -v -timeout 24h > $file
|
-SimulationVerbose=true -SimulationCommit=true -SimulationSeed=$seed -v -timeout 24h > $file
|
||||||
|
|
|
@ -63,17 +63,17 @@ func ShowValidatorCmd(ctx *Context) *cobra.Command {
|
||||||
func ShowAddressCmd(ctx *Context) *cobra.Command {
|
func ShowAddressCmd(ctx *Context) *cobra.Command {
|
||||||
cmd := &cobra.Command{
|
cmd := &cobra.Command{
|
||||||
Use: "show-address",
|
Use: "show-address",
|
||||||
Short: "Shows this node's tendermint validator address",
|
Short: "Shows this node's tendermint validator consensus address",
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
cfg := ctx.Config
|
cfg := ctx.Config
|
||||||
privValidator := pvm.LoadOrGenFilePV(cfg.PrivValidatorFile())
|
privValidator := pvm.LoadOrGenFilePV(cfg.PrivValidatorFile())
|
||||||
valAddr := (sdk.ValAddress)(privValidator.Address)
|
valConsAddr := (sdk.ConsAddress)(privValidator.Address)
|
||||||
|
|
||||||
if viper.GetBool(client.FlagJson) {
|
if viper.GetBool(client.FlagJson) {
|
||||||
return printlnJSON(valAddr)
|
return printlnJSON(valConsAddr)
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println(valAddr.String())
|
fmt.Println(valConsAddr.String())
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,8 +49,8 @@ func TestSameDenomAsCoin(t *testing.T) {
|
||||||
{NewInt64Coin("A", 1), NewInt64Coin("A", 1), true},
|
{NewInt64Coin("A", 1), NewInt64Coin("A", 1), true},
|
||||||
{NewInt64Coin("A", 1), NewInt64Coin("a", 1), false},
|
{NewInt64Coin("A", 1), NewInt64Coin("a", 1), false},
|
||||||
{NewInt64Coin("a", 1), NewInt64Coin("b", 1), false},
|
{NewInt64Coin("a", 1), NewInt64Coin("b", 1), false},
|
||||||
{NewInt64Coin("steak", 1), NewInt64Coin("steak", 10), true},
|
{NewInt64Coin("stake", 1), NewInt64Coin("stake", 10), true},
|
||||||
{NewInt64Coin("steak", -11), NewInt64Coin("steak", 10), true},
|
{NewInt64Coin("stake", -11), NewInt64Coin("stake", 10), true},
|
||||||
}
|
}
|
||||||
|
|
||||||
for tcIndex, tc := range cases {
|
for tcIndex, tc := range cases {
|
||||||
|
@ -107,8 +107,8 @@ func TestIsEqualCoin(t *testing.T) {
|
||||||
{NewInt64Coin("A", 1), NewInt64Coin("A", 1), true},
|
{NewInt64Coin("A", 1), NewInt64Coin("A", 1), true},
|
||||||
{NewInt64Coin("A", 1), NewInt64Coin("a", 1), false},
|
{NewInt64Coin("A", 1), NewInt64Coin("a", 1), false},
|
||||||
{NewInt64Coin("a", 1), NewInt64Coin("b", 1), false},
|
{NewInt64Coin("a", 1), NewInt64Coin("b", 1), false},
|
||||||
{NewInt64Coin("steak", 1), NewInt64Coin("steak", 10), false},
|
{NewInt64Coin("stake", 1), NewInt64Coin("stake", 10), false},
|
||||||
{NewInt64Coin("steak", -11), NewInt64Coin("steak", 10), false},
|
{NewInt64Coin("stake", -11), NewInt64Coin("stake", 10), false},
|
||||||
}
|
}
|
||||||
|
|
||||||
for tcIndex, tc := range cases {
|
for tcIndex, tc := range cases {
|
||||||
|
|
|
@ -21,8 +21,8 @@ func TestSortJSON(t *testing.T) {
|
||||||
want: "",
|
want: "",
|
||||||
wantErr: true},
|
wantErr: true},
|
||||||
// genesis.json
|
// genesis.json
|
||||||
{unsortedJSON: `{"consensus_params":{"block_size_params":{"max_bytes":22020096,"max_txs":100000,"max_gas":-1},"tx_size_params":{"max_bytes":10240,"max_gas":-1},"block_gossip_params":{"block_part_size_bytes":65536},"evidence_params":{"max_age":100000}},"validators":[{"pub_key":{"type":"AC26791624DE60","value":"c7UMMAbjFuc5GhGPy0E5q5tefy12p9Tq0imXqdrKXwo="},"power":100,"name":""}],"app_hash":"","genesis_time":"2018-05-11T15:52:25.424795506Z","chain_id":"test-chain-Q6VeoW","app_state":{"accounts":[{"address":"718C9C23F98C9642569742ADDD9F9AB9743FBD5D","coins":[{"denom":"Token","amount":1000},{"denom":"steak","amount":50}]}],"stake":{"pool":{"total_supply":50,"bonded_shares":"0","unbonded_shares":"0","bonded_pool":0,"unbonded_pool":0,"inflation_last_time":0,"inflation":"7/100"},"params":{"inflation_rate_change":"13/100","inflation_max":"1/5","inflation_min":"7/100","goal_bonded":"67/100","max_validators":100,"bond_denom":"steak"},"candidates":null,"bonds":null}}}`,
|
{unsortedJSON: `{"consensus_params":{"block_size_params":{"max_bytes":22020096,"max_txs":100000,"max_gas":-1},"tx_size_params":{"max_bytes":10240,"max_gas":-1},"block_gossip_params":{"block_part_size_bytes":65536},"evidence_params":{"max_age":100000}},"validators":[{"pub_key":{"type":"AC26791624DE60","value":"c7UMMAbjFuc5GhGPy0E5q5tefy12p9Tq0imXqdrKXwo="},"power":100,"name":""}],"app_hash":"","genesis_time":"2018-05-11T15:52:25.424795506Z","chain_id":"test-chain-Q6VeoW","app_state":{"accounts":[{"address":"718C9C23F98C9642569742ADDD9F9AB9743FBD5D","coins":[{"denom":"Token","amount":1000},{"denom":"stake","amount":50}]}],"stake":{"pool":{"total_supply":50,"bonded_shares":"0","unbonded_shares":"0","bonded_pool":0,"unbonded_pool":0,"inflation_last_time":0,"inflation":"7/100"},"params":{"inflation_rate_change":"13/100","inflation_max":"1/5","inflation_min":"7/100","goal_bonded":"67/100","max_validators":100,"bond_denom":"stake"},"candidates":null,"bonds":null}}}`,
|
||||||
want: `{"app_hash":"","app_state":{"accounts":[{"address":"718C9C23F98C9642569742ADDD9F9AB9743FBD5D","coins":[{"amount":1000,"denom":"Token"},{"amount":50,"denom":"steak"}]}],"stake":{"bonds":null,"candidates":null,"params":{"bond_denom":"steak","goal_bonded":"67/100","inflation_max":"1/5","inflation_min":"7/100","inflation_rate_change":"13/100","max_validators":100},"pool":{"bonded_pool":0,"bonded_shares":"0","inflation":"7/100","inflation_last_time":0,"total_supply":50,"unbonded_pool":0,"unbonded_shares":"0"}}},"chain_id":"test-chain-Q6VeoW","consensus_params":{"block_gossip_params":{"block_part_size_bytes":65536},"block_size_params":{"max_bytes":22020096,"max_gas":-1,"max_txs":100000},"evidence_params":{"max_age":100000},"tx_size_params":{"max_bytes":10240,"max_gas":-1}},"genesis_time":"2018-05-11T15:52:25.424795506Z","validators":[{"name":"","power":100,"pub_key":{"type":"AC26791624DE60","value":"c7UMMAbjFuc5GhGPy0E5q5tefy12p9Tq0imXqdrKXwo="}}]}`,
|
want: `{"app_hash":"","app_state":{"accounts":[{"address":"718C9C23F98C9642569742ADDD9F9AB9743FBD5D","coins":[{"amount":1000,"denom":"Token"},{"amount":50,"denom":"stake"}]}],"stake":{"bonds":null,"candidates":null,"params":{"bond_denom":"stake","goal_bonded":"67/100","inflation_max":"1/5","inflation_min":"7/100","inflation_rate_change":"13/100","max_validators":100},"pool":{"bonded_pool":0,"bonded_shares":"0","inflation":"7/100","inflation_last_time":0,"total_supply":50,"unbonded_pool":0,"unbonded_shares":"0"}}},"chain_id":"test-chain-Q6VeoW","consensus_params":{"block_gossip_params":{"block_part_size_bytes":65536},"block_size_params":{"max_bytes":22020096,"max_gas":-1,"max_txs":100000},"evidence_params":{"max_age":100000},"tx_size_params":{"max_bytes":10240,"max_gas":-1}},"genesis_time":"2018-05-11T15:52:25.424795506Z","validators":[{"name":"","power":100,"pub_key":{"type":"AC26791624DE60","value":"c7UMMAbjFuc5GhGPy0E5q5tefy12p9Tq0imXqdrKXwo="}}]}`,
|
||||||
wantErr: false},
|
wantErr: false},
|
||||||
// from the TXSpec:
|
// from the TXSpec:
|
||||||
{unsortedJSON: `{"chain_id":"test-chain-1","sequence":1,"fee_bytes":{"amount":[{"amount":5,"denom":"photon"}],"gas":10000},"msg_bytes":{"inputs":[{"address":"696E707574","coins":[{"amount":10,"denom":"atom"}]}],"outputs":[{"address":"6F7574707574","coins":[{"amount":10,"denom":"atom"}]}]},"alt_bytes":null}`,
|
{unsortedJSON: `{"chain_id":"test-chain-1","sequence":1,"fee_bytes":{"amount":[{"amount":5,"denom":"photon"}],"gas":10000},"msg_bytes":{"inputs":[{"address":"696E707574","coins":[{"amount":10,"denom":"atom"}]}],"outputs":[{"address":"6F7574707574","coins":[{"amount":10,"denom":"atom"}]}]},"alt_bytes":null}`,
|
||||||
|
|
|
@ -10,6 +10,7 @@ import (
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
"github.com/cosmos/cosmos-sdk/x/auth"
|
"github.com/cosmos/cosmos-sdk/x/auth"
|
||||||
"github.com/tendermint/tendermint/crypto/ed25519"
|
"github.com/tendermint/tendermint/crypto/ed25519"
|
||||||
|
stakeTypes "github.com/cosmos/cosmos-sdk/x/stake/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -46,7 +47,7 @@ func TestTxBuilderBuild(t *testing.T) {
|
||||||
SimulateGas: false,
|
SimulateGas: false,
|
||||||
ChainID: "test-chain",
|
ChainID: "test-chain",
|
||||||
Memo: "hello",
|
Memo: "hello",
|
||||||
Fee: "1steak",
|
Fee: "1" + stakeTypes.DefaultBondDenom,
|
||||||
},
|
},
|
||||||
defaultMsg,
|
defaultMsg,
|
||||||
StdSignMsg{
|
StdSignMsg{
|
||||||
|
@ -55,7 +56,7 @@ func TestTxBuilderBuild(t *testing.T) {
|
||||||
Sequence: 1,
|
Sequence: 1,
|
||||||
Memo: "hello",
|
Memo: "hello",
|
||||||
Msgs: defaultMsg,
|
Msgs: defaultMsg,
|
||||||
Fee: auth.NewStdFee(100, sdk.NewCoin("steak", sdk.NewInt(1))),
|
Fee: auth.NewStdFee(100, sdk.NewCoin(stakeTypes.DefaultBondDenom, sdk.NewInt(1))),
|
||||||
},
|
},
|
||||||
false,
|
false,
|
||||||
},
|
},
|
||||||
|
|
|
@ -15,41 +15,40 @@ const (
|
||||||
costAddCoins sdk.Gas = 10
|
costAddCoins sdk.Gas = 10
|
||||||
)
|
)
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// Keeper
|
||||||
|
|
||||||
|
var _ Keeper = (*BaseKeeper)(nil)
|
||||||
|
|
||||||
// Keeper defines a module interface that facilitates the transfer of coins
|
// Keeper defines a module interface that facilitates the transfer of coins
|
||||||
// between accounts.
|
// between accounts.
|
||||||
type Keeper interface {
|
type Keeper interface {
|
||||||
SendKeeper
|
SendKeeper
|
||||||
|
|
||||||
SetCoins(ctx sdk.Context, addr sdk.AccAddress, amt sdk.Coins) sdk.Error
|
SetCoins(ctx sdk.Context, addr sdk.AccAddress, amt sdk.Coins) sdk.Error
|
||||||
SubtractCoins(ctx sdk.Context, addr sdk.AccAddress, amt sdk.Coins) (sdk.Coins, sdk.Tags, sdk.Error)
|
SubtractCoins(ctx sdk.Context, addr sdk.AccAddress, amt sdk.Coins) (sdk.Coins, sdk.Tags, sdk.Error)
|
||||||
AddCoins(ctx sdk.Context, addr sdk.AccAddress, amt sdk.Coins) (sdk.Coins, sdk.Tags, sdk.Error)
|
AddCoins(ctx sdk.Context, addr sdk.AccAddress, amt sdk.Coins) (sdk.Coins, sdk.Tags, sdk.Error)
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ Keeper = (*BaseKeeper)(nil)
|
|
||||||
|
|
||||||
// BaseKeeper manages transfers between accounts. It implements the Keeper
|
// BaseKeeper manages transfers between accounts. It implements the Keeper
|
||||||
// interface.
|
// interface.
|
||||||
type BaseKeeper struct {
|
type BaseKeeper struct {
|
||||||
am auth.AccountKeeper
|
BaseSendKeeper
|
||||||
|
|
||||||
|
ak auth.AccountKeeper
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewBaseKeeper returns a new BaseKeeper
|
// NewBaseKeeper returns a new BaseKeeper
|
||||||
func NewBaseKeeper(am auth.AccountKeeper) BaseKeeper {
|
func NewBaseKeeper(ak auth.AccountKeeper) BaseKeeper {
|
||||||
return BaseKeeper{am: am}
|
return BaseKeeper{
|
||||||
}
|
BaseSendKeeper: NewBaseSendKeeper(ak),
|
||||||
|
ak: ak,
|
||||||
// GetCoins returns the coins at the addr.
|
}
|
||||||
func (keeper BaseKeeper) GetCoins(ctx sdk.Context, addr sdk.AccAddress) sdk.Coins {
|
|
||||||
return getCoins(ctx, keeper.am, addr)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetCoins sets the coins at the addr.
|
// SetCoins sets the coins at the addr.
|
||||||
func (keeper BaseKeeper) SetCoins(ctx sdk.Context, addr sdk.AccAddress, amt sdk.Coins) sdk.Error {
|
func (keeper BaseKeeper) SetCoins(ctx sdk.Context, addr sdk.AccAddress, amt sdk.Coins) sdk.Error {
|
||||||
return setCoins(ctx, keeper.am, addr, amt)
|
return setCoins(ctx, keeper.ak, addr, amt)
|
||||||
}
|
|
||||||
|
|
||||||
// HasCoins returns whether or not an account has at least amt coins.
|
|
||||||
func (keeper BaseKeeper) HasCoins(ctx sdk.Context, addr sdk.AccAddress, amt sdk.Coins) bool {
|
|
||||||
return hasCoins(ctx, keeper.am, addr, amt)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// SubtractCoins subtracts amt from the coins at the addr.
|
// SubtractCoins subtracts amt from the coins at the addr.
|
||||||
|
@ -57,7 +56,7 @@ func (keeper BaseKeeper) SubtractCoins(
|
||||||
ctx sdk.Context, addr sdk.AccAddress, amt sdk.Coins,
|
ctx sdk.Context, addr sdk.AccAddress, amt sdk.Coins,
|
||||||
) (sdk.Coins, sdk.Tags, sdk.Error) {
|
) (sdk.Coins, sdk.Tags, sdk.Error) {
|
||||||
|
|
||||||
return subtractCoins(ctx, keeper.am, addr, amt)
|
return subtractCoins(ctx, keeper.ak, addr, amt)
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddCoins adds amt to the coins at the addr.
|
// AddCoins adds amt to the coins at the addr.
|
||||||
|
@ -65,28 +64,17 @@ func (keeper BaseKeeper) AddCoins(
|
||||||
ctx sdk.Context, addr sdk.AccAddress, amt sdk.Coins,
|
ctx sdk.Context, addr sdk.AccAddress, amt sdk.Coins,
|
||||||
) (sdk.Coins, sdk.Tags, sdk.Error) {
|
) (sdk.Coins, sdk.Tags, sdk.Error) {
|
||||||
|
|
||||||
return addCoins(ctx, keeper.am, addr, amt)
|
return addCoins(ctx, keeper.ak, addr, amt)
|
||||||
}
|
}
|
||||||
|
|
||||||
// SendCoins moves coins from one account to another
|
//-----------------------------------------------------------------------------
|
||||||
func (keeper BaseKeeper) SendCoins(
|
// Send Keeper
|
||||||
ctx sdk.Context, fromAddr sdk.AccAddress, toAddr sdk.AccAddress, amt sdk.Coins,
|
|
||||||
) (sdk.Tags, sdk.Error) {
|
|
||||||
|
|
||||||
return sendCoins(ctx, keeper.am, fromAddr, toAddr, amt)
|
|
||||||
}
|
|
||||||
|
|
||||||
// InputOutputCoins handles a list of inputs and outputs
|
|
||||||
func (keeper BaseKeeper) InputOutputCoins(ctx sdk.Context, inputs []Input, outputs []Output) (sdk.Tags, sdk.Error) {
|
|
||||||
return inputOutputCoins(ctx, keeper.am, inputs, outputs)
|
|
||||||
}
|
|
||||||
|
|
||||||
//______________________________________________________________________________________________
|
|
||||||
|
|
||||||
// SendKeeper defines a module interface that facilitates the transfer of coins
|
// SendKeeper defines a module interface that facilitates the transfer of coins
|
||||||
// between accounts without the possibility of creating coins.
|
// between accounts without the possibility of creating coins.
|
||||||
type SendKeeper interface {
|
type SendKeeper interface {
|
||||||
ViewKeeper
|
ViewKeeper
|
||||||
|
|
||||||
SendCoins(ctx sdk.Context, fromAddr sdk.AccAddress, toAddr sdk.AccAddress, amt sdk.Coins) (sdk.Tags, sdk.Error)
|
SendCoins(ctx sdk.Context, fromAddr sdk.AccAddress, toAddr sdk.AccAddress, amt sdk.Coins) (sdk.Tags, sdk.Error)
|
||||||
InputOutputCoins(ctx sdk.Context, inputs []Input, outputs []Output) (sdk.Tags, sdk.Error)
|
InputOutputCoins(ctx sdk.Context, inputs []Input, outputs []Output) (sdk.Tags, sdk.Error)
|
||||||
}
|
}
|
||||||
|
@ -96,22 +84,17 @@ var _ SendKeeper = (*BaseSendKeeper)(nil)
|
||||||
// SendKeeper only allows transfers between accounts without the possibility of
|
// SendKeeper only allows transfers between accounts without the possibility of
|
||||||
// creating coins. It implements the SendKeeper interface.
|
// creating coins. It implements the SendKeeper interface.
|
||||||
type BaseSendKeeper struct {
|
type BaseSendKeeper struct {
|
||||||
am auth.AccountKeeper
|
BaseViewKeeper
|
||||||
|
|
||||||
|
ak auth.AccountKeeper
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewBaseSendKeeper returns a new BaseSendKeeper.
|
// NewBaseSendKeeper returns a new BaseSendKeeper.
|
||||||
func NewBaseSendKeeper(am auth.AccountKeeper) BaseSendKeeper {
|
func NewBaseSendKeeper(ak auth.AccountKeeper) BaseSendKeeper {
|
||||||
return BaseSendKeeper{am: am}
|
return BaseSendKeeper{
|
||||||
}
|
BaseViewKeeper: NewBaseViewKeeper(ak),
|
||||||
|
ak: ak,
|
||||||
// GetCoins returns the coins at the addr.
|
}
|
||||||
func (keeper BaseSendKeeper) GetCoins(ctx sdk.Context, addr sdk.AccAddress) sdk.Coins {
|
|
||||||
return getCoins(ctx, keeper.am, addr)
|
|
||||||
}
|
|
||||||
|
|
||||||
// HasCoins returns whether or not an account has at least amt coins.
|
|
||||||
func (keeper BaseSendKeeper) HasCoins(ctx sdk.Context, addr sdk.AccAddress, amt sdk.Coins) bool {
|
|
||||||
return hasCoins(ctx, keeper.am, addr, amt)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// SendCoins moves coins from one account to another
|
// SendCoins moves coins from one account to another
|
||||||
|
@ -119,7 +102,7 @@ func (keeper BaseSendKeeper) SendCoins(
|
||||||
ctx sdk.Context, fromAddr sdk.AccAddress, toAddr sdk.AccAddress, amt sdk.Coins,
|
ctx sdk.Context, fromAddr sdk.AccAddress, toAddr sdk.AccAddress, amt sdk.Coins,
|
||||||
) (sdk.Tags, sdk.Error) {
|
) (sdk.Tags, sdk.Error) {
|
||||||
|
|
||||||
return sendCoins(ctx, keeper.am, fromAddr, toAddr, amt)
|
return sendCoins(ctx, keeper.ak, fromAddr, toAddr, amt)
|
||||||
}
|
}
|
||||||
|
|
||||||
// InputOutputCoins handles a list of inputs and outputs
|
// InputOutputCoins handles a list of inputs and outputs
|
||||||
|
@ -127,10 +110,13 @@ func (keeper BaseSendKeeper) InputOutputCoins(
|
||||||
ctx sdk.Context, inputs []Input, outputs []Output,
|
ctx sdk.Context, inputs []Input, outputs []Output,
|
||||||
) (sdk.Tags, sdk.Error) {
|
) (sdk.Tags, sdk.Error) {
|
||||||
|
|
||||||
return inputOutputCoins(ctx, keeper.am, inputs, outputs)
|
return inputOutputCoins(ctx, keeper.ak, inputs, outputs)
|
||||||
}
|
}
|
||||||
|
|
||||||
//______________________________________________________________________________________________
|
//-----------------------------------------------------------------------------
|
||||||
|
// View Keeper
|
||||||
|
|
||||||
|
var _ ViewKeeper = (*BaseViewKeeper)(nil)
|
||||||
|
|
||||||
// ViewKeeper defines a module interface that facilitates read only access to
|
// ViewKeeper defines a module interface that facilitates read only access to
|
||||||
// account balances.
|
// account balances.
|
||||||
|
@ -139,29 +125,29 @@ type ViewKeeper interface {
|
||||||
HasCoins(ctx sdk.Context, addr sdk.AccAddress, amt sdk.Coins) bool
|
HasCoins(ctx sdk.Context, addr sdk.AccAddress, amt sdk.Coins) bool
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ ViewKeeper = (*BaseViewKeeper)(nil)
|
|
||||||
|
|
||||||
// BaseViewKeeper implements a read only keeper implementation of ViewKeeper.
|
// BaseViewKeeper implements a read only keeper implementation of ViewKeeper.
|
||||||
type BaseViewKeeper struct {
|
type BaseViewKeeper struct {
|
||||||
am auth.AccountKeeper
|
ak auth.AccountKeeper
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewBaseViewKeeper returns a new BaseViewKeeper.
|
// NewBaseViewKeeper returns a new BaseViewKeeper.
|
||||||
func NewBaseViewKeeper(am auth.AccountKeeper) BaseViewKeeper {
|
func NewBaseViewKeeper(ak auth.AccountKeeper) BaseViewKeeper {
|
||||||
return BaseViewKeeper{am: am}
|
return BaseViewKeeper{
|
||||||
|
ak: ak,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetCoins returns the coins at the addr.
|
// GetCoins returns the coins at the addr.
|
||||||
func (keeper BaseViewKeeper) GetCoins(ctx sdk.Context, addr sdk.AccAddress) sdk.Coins {
|
func (keeper BaseViewKeeper) GetCoins(ctx sdk.Context, addr sdk.AccAddress) sdk.Coins {
|
||||||
return getCoins(ctx, keeper.am, addr)
|
return getCoins(ctx, keeper.ak, addr)
|
||||||
}
|
}
|
||||||
|
|
||||||
// HasCoins returns whether or not an account has at least amt coins.
|
// HasCoins returns whether or not an account has at least amt coins.
|
||||||
func (keeper BaseViewKeeper) HasCoins(ctx sdk.Context, addr sdk.AccAddress, amt sdk.Coins) bool {
|
func (keeper BaseViewKeeper) HasCoins(ctx sdk.Context, addr sdk.AccAddress, amt sdk.Coins) bool {
|
||||||
return hasCoins(ctx, keeper.am, addr, amt)
|
return hasCoins(ctx, keeper.ak, addr, amt)
|
||||||
}
|
}
|
||||||
|
|
||||||
//______________________________________________________________________________________________
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
func getCoins(ctx sdk.Context, am auth.AccountKeeper, addr sdk.AccAddress) sdk.Coins {
|
func getCoins(ctx sdk.Context, am auth.AccountKeeper, addr sdk.AccAddress) sdk.Coins {
|
||||||
ctx.GasMeter().ConsumeGas(costGetCoins, "getCoins")
|
ctx.GasMeter().ConsumeGas(costGetCoins, "getCoins")
|
||||||
|
|
|
@ -249,6 +249,30 @@ func GetCmdVote(cdc *codec.Codec) *cobra.Command {
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetCmdQueryProposal implements the query proposal command.
|
||||||
|
func GetCmdQueryParams(queryRoute string, cdc *codec.Codec) *cobra.Command {
|
||||||
|
cmd := &cobra.Command{
|
||||||
|
Use: "param [param-type]",
|
||||||
|
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]
|
||||||
|
|
||||||
|
cliCtx := context.NewCLIContext().WithCodec(cdc)
|
||||||
|
|
||||||
|
res, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/params/%s", queryRoute, paramType), nil)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Println(string(res))
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
return cmd
|
||||||
|
}
|
||||||
|
|
||||||
// GetCmdQueryProposal implements the query proposal command.
|
// GetCmdQueryProposal implements the query proposal command.
|
||||||
func GetCmdQueryProposal(queryRoute string, cdc *codec.Codec) *cobra.Command {
|
func GetCmdQueryProposal(queryRoute string, cdc *codec.Codec) *cobra.Command {
|
||||||
cmd := &cobra.Command{
|
cmd := &cobra.Command{
|
||||||
|
|
|
@ -18,7 +18,8 @@ import (
|
||||||
// REST Variable names
|
// REST Variable names
|
||||||
// nolint
|
// nolint
|
||||||
const (
|
const (
|
||||||
RestProposalID = "proposalId"
|
RestParamsType = "type"
|
||||||
|
RestProposalID = "proposal-id"
|
||||||
RestDepositer = "depositer"
|
RestDepositer = "depositer"
|
||||||
RestVoter = "voter"
|
RestVoter = "voter"
|
||||||
RestProposalStatus = "status"
|
RestProposalStatus = "status"
|
||||||
|
@ -32,6 +33,11 @@ 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}/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/proposals/{%s}/votes", RestProposalID), voteHandlerFn(cdc, cliCtx)).Methods("POST")
|
||||||
|
|
||||||
|
r.HandleFunc(
|
||||||
|
fmt.Sprintf("/gov/parameters/{%s}", RestParamsType),
|
||||||
|
queryParamsHandlerFn(cdc, cliCtx),
|
||||||
|
).Methods("GET")
|
||||||
|
|
||||||
r.HandleFunc("/gov/proposals", queryProposalsWithParameterFn(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}", RestProposalID), queryProposalHandlerFn(cdc, cliCtx)).Methods("GET")
|
||||||
r.HandleFunc(fmt.Sprintf("/gov/proposals/{%s}/deposits", RestProposalID), queryDepositsHandlerFn(cdc, cliCtx)).Methods("GET")
|
r.HandleFunc(fmt.Sprintf("/gov/proposals/{%s}/deposits", RestProposalID), queryDepositsHandlerFn(cdc, cliCtx)).Methods("GET")
|
||||||
|
@ -177,6 +183,21 @@ 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)
|
||||||
|
paramType := vars[RestParamsType]
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
utils.PostProcessResponse(w, cdc, res, cliCtx.Indent)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func queryProposalHandlerFn(cdc *codec.Codec, cliCtx context.CLIContext) http.HandlerFunc {
|
func queryProposalHandlerFn(cdc *codec.Codec, cliCtx context.CLIContext) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
vars := mux.Vars(r)
|
vars := mux.Vars(r)
|
||||||
|
|
|
@ -7,6 +7,7 @@ import (
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
|
stakeTypes "github.com/cosmos/cosmos-sdk/x/stake/types"
|
||||||
abci "github.com/tendermint/tendermint/abci/types"
|
abci "github.com/tendermint/tendermint/abci/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -20,7 +21,7 @@ func TestTickExpiredDepositPeriod(t *testing.T) {
|
||||||
require.False(t, inactiveQueue.Valid())
|
require.False(t, inactiveQueue.Valid())
|
||||||
inactiveQueue.Close()
|
inactiveQueue.Close()
|
||||||
|
|
||||||
newProposalMsg := NewMsgSubmitProposal("Test", "test", ProposalTypeText, addrs[0], sdk.Coins{sdk.NewInt64Coin("steak", 5)})
|
newProposalMsg := NewMsgSubmitProposal("Test", "test", ProposalTypeText, addrs[0], sdk.Coins{sdk.NewInt64Coin(stakeTypes.DefaultBondDenom, 5)})
|
||||||
|
|
||||||
res := govHandler(ctx, newProposalMsg)
|
res := govHandler(ctx, newProposalMsg)
|
||||||
require.True(t, res.IsOK())
|
require.True(t, res.IsOK())
|
||||||
|
@ -62,7 +63,7 @@ func TestTickMultipleExpiredDepositPeriod(t *testing.T) {
|
||||||
require.False(t, inactiveQueue.Valid())
|
require.False(t, inactiveQueue.Valid())
|
||||||
inactiveQueue.Close()
|
inactiveQueue.Close()
|
||||||
|
|
||||||
newProposalMsg := NewMsgSubmitProposal("Test", "test", ProposalTypeText, addrs[0], sdk.Coins{sdk.NewInt64Coin("steak", 5)})
|
newProposalMsg := NewMsgSubmitProposal("Test", "test", ProposalTypeText, addrs[0], sdk.Coins{sdk.NewInt64Coin(stakeTypes.DefaultBondDenom, 5)})
|
||||||
|
|
||||||
res := govHandler(ctx, newProposalMsg)
|
res := govHandler(ctx, newProposalMsg)
|
||||||
require.True(t, res.IsOK())
|
require.True(t, res.IsOK())
|
||||||
|
@ -79,7 +80,7 @@ func TestTickMultipleExpiredDepositPeriod(t *testing.T) {
|
||||||
require.False(t, inactiveQueue.Valid())
|
require.False(t, inactiveQueue.Valid())
|
||||||
inactiveQueue.Close()
|
inactiveQueue.Close()
|
||||||
|
|
||||||
newProposalMsg2 := NewMsgSubmitProposal("Test2", "test2", ProposalTypeText, addrs[1], sdk.Coins{sdk.NewInt64Coin("steak", 5)})
|
newProposalMsg2 := NewMsgSubmitProposal("Test2", "test2", ProposalTypeText, addrs[1], sdk.Coins{sdk.NewInt64Coin(stakeTypes.DefaultBondDenom, 5)})
|
||||||
res = govHandler(ctx, newProposalMsg2)
|
res = govHandler(ctx, newProposalMsg2)
|
||||||
require.True(t, res.IsOK())
|
require.True(t, res.IsOK())
|
||||||
|
|
||||||
|
@ -121,7 +122,7 @@ func TestTickPassedDepositPeriod(t *testing.T) {
|
||||||
require.False(t, activeQueue.Valid())
|
require.False(t, activeQueue.Valid())
|
||||||
activeQueue.Close()
|
activeQueue.Close()
|
||||||
|
|
||||||
newProposalMsg := NewMsgSubmitProposal("Test", "test", ProposalTypeText, addrs[0], sdk.Coins{sdk.NewInt64Coin("steak", 5)})
|
newProposalMsg := NewMsgSubmitProposal("Test", "test", ProposalTypeText, addrs[0], sdk.Coins{sdk.NewInt64Coin(stakeTypes.DefaultBondDenom, 5)})
|
||||||
|
|
||||||
res := govHandler(ctx, newProposalMsg)
|
res := govHandler(ctx, newProposalMsg)
|
||||||
require.True(t, res.IsOK())
|
require.True(t, res.IsOK())
|
||||||
|
@ -140,7 +141,7 @@ func TestTickPassedDepositPeriod(t *testing.T) {
|
||||||
require.False(t, inactiveQueue.Valid())
|
require.False(t, inactiveQueue.Valid())
|
||||||
inactiveQueue.Close()
|
inactiveQueue.Close()
|
||||||
|
|
||||||
newDepositMsg := NewMsgDeposit(addrs[1], proposalID, sdk.Coins{sdk.NewInt64Coin("steak", 5)})
|
newDepositMsg := NewMsgDeposit(addrs[1], proposalID, sdk.Coins{sdk.NewInt64Coin(stakeTypes.DefaultBondDenom, 5)})
|
||||||
res = govHandler(ctx, newDepositMsg)
|
res = govHandler(ctx, newDepositMsg)
|
||||||
require.True(t, res.IsOK())
|
require.True(t, res.IsOK())
|
||||||
|
|
||||||
|
@ -163,7 +164,7 @@ func TestTickPassedVotingPeriod(t *testing.T) {
|
||||||
require.False(t, activeQueue.Valid())
|
require.False(t, activeQueue.Valid())
|
||||||
activeQueue.Close()
|
activeQueue.Close()
|
||||||
|
|
||||||
newProposalMsg := NewMsgSubmitProposal("Test", "test", ProposalTypeText, addrs[0], sdk.Coins{sdk.NewInt64Coin("steak", 5)})
|
newProposalMsg := NewMsgSubmitProposal("Test", "test", ProposalTypeText, addrs[0], sdk.Coins{sdk.NewInt64Coin(stakeTypes.DefaultBondDenom, 5)})
|
||||||
|
|
||||||
res := govHandler(ctx, newProposalMsg)
|
res := govHandler(ctx, newProposalMsg)
|
||||||
require.True(t, res.IsOK())
|
require.True(t, res.IsOK())
|
||||||
|
@ -174,7 +175,7 @@ func TestTickPassedVotingPeriod(t *testing.T) {
|
||||||
newHeader.Time = ctx.BlockHeader().Time.Add(time.Duration(1) * time.Second)
|
newHeader.Time = ctx.BlockHeader().Time.Add(time.Duration(1) * time.Second)
|
||||||
ctx = ctx.WithBlockHeader(newHeader)
|
ctx = ctx.WithBlockHeader(newHeader)
|
||||||
|
|
||||||
newDepositMsg := NewMsgDeposit(addrs[1], proposalID, sdk.Coins{sdk.NewInt64Coin("steak", 5)})
|
newDepositMsg := NewMsgDeposit(addrs[1], proposalID, sdk.Coins{sdk.NewInt64Coin(stakeTypes.DefaultBondDenom, 5)})
|
||||||
res = govHandler(ctx, newDepositMsg)
|
res = govHandler(ctx, newDepositMsg)
|
||||||
require.True(t, res.IsOK())
|
require.True(t, res.IsOK())
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
|
stakeTypes "github.com/cosmos/cosmos-sdk/x/stake/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
// GenesisState - all staking state that must be provided at genesis
|
// GenesisState - all staking state that must be provided at genesis
|
||||||
|
@ -43,7 +44,7 @@ func DefaultGenesisState() GenesisState {
|
||||||
return GenesisState{
|
return GenesisState{
|
||||||
StartingProposalID: 1,
|
StartingProposalID: 1,
|
||||||
DepositParams: DepositParams{
|
DepositParams: DepositParams{
|
||||||
MinDeposit: sdk.Coins{sdk.NewInt64Coin("steak", 10)},
|
MinDeposit: sdk.Coins{sdk.NewInt64Coin(stakeTypes.DefaultBondDenom, 10)},
|
||||||
MaxDepositPeriod: time.Duration(172800) * time.Second,
|
MaxDepositPeriod: time.Duration(172800) * time.Second,
|
||||||
},
|
},
|
||||||
VotingParams: VotingParams{
|
VotingParams: VotingParams{
|
||||||
|
|
|
@ -250,7 +250,7 @@ func (keeper Keeper) GetDepositParams(ctx sdk.Context) DepositParams {
|
||||||
return depositParams
|
return depositParams
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns the current Voting Procedure from the global param store
|
// Returns the current VotingParams from the global param store
|
||||||
// nolint: errcheck
|
// nolint: errcheck
|
||||||
func (keeper Keeper) GetVotingParams(ctx sdk.Context) VotingParams {
|
func (keeper Keeper) GetVotingParams(ctx sdk.Context) VotingParams {
|
||||||
var votingParams VotingParams
|
var votingParams VotingParams
|
||||||
|
@ -258,7 +258,7 @@ func (keeper Keeper) GetVotingParams(ctx sdk.Context) VotingParams {
|
||||||
return votingParams
|
return votingParams
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns the current Tallying Procedure from the global param store
|
// Returns the current TallyParam from the global param store
|
||||||
// nolint: errcheck
|
// nolint: errcheck
|
||||||
func (keeper Keeper) GetTallyParams(ctx sdk.Context) TallyParams {
|
func (keeper Keeper) GetTallyParams(ctx sdk.Context) TallyParams {
|
||||||
var tallyParams TallyParams
|
var tallyParams TallyParams
|
||||||
|
|
|
@ -9,6 +9,7 @@ import (
|
||||||
abci "github.com/tendermint/tendermint/abci/types"
|
abci "github.com/tendermint/tendermint/abci/types"
|
||||||
|
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
|
stakeTypes "github.com/cosmos/cosmos-sdk/x/stake/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestGetSetProposal(t *testing.T) {
|
func TestGetSetProposal(t *testing.T) {
|
||||||
|
@ -69,14 +70,14 @@ func TestDeposits(t *testing.T) {
|
||||||
proposal := keeper.NewTextProposal(ctx, "Test", "description", ProposalTypeText)
|
proposal := keeper.NewTextProposal(ctx, "Test", "description", ProposalTypeText)
|
||||||
proposalID := proposal.GetProposalID()
|
proposalID := proposal.GetProposalID()
|
||||||
|
|
||||||
fourSteak := sdk.Coins{sdk.NewInt64Coin("steak", 4)}
|
fourSteak := sdk.Coins{sdk.NewInt64Coin(stakeTypes.DefaultBondDenom, 4)}
|
||||||
fiveSteak := sdk.Coins{sdk.NewInt64Coin("steak", 5)}
|
fiveSteak := sdk.Coins{sdk.NewInt64Coin(stakeTypes.DefaultBondDenom, 5)}
|
||||||
|
|
||||||
addr0Initial := keeper.ck.GetCoins(ctx, addrs[0])
|
addr0Initial := keeper.ck.GetCoins(ctx, addrs[0])
|
||||||
addr1Initial := keeper.ck.GetCoins(ctx, addrs[1])
|
addr1Initial := keeper.ck.GetCoins(ctx, addrs[1])
|
||||||
|
|
||||||
// require.True(t, addr0Initial.IsEqual(sdk.Coins{sdk.NewInt64Coin("steak", 42)}))
|
// require.True(t, addr0Initial.IsEqual(sdk.Coins{sdk.NewInt64Coin(stakeTypes.DefaultBondDenom, 42)}))
|
||||||
require.Equal(t, sdk.Coins{sdk.NewInt64Coin("steak", 42)}, addr0Initial)
|
require.Equal(t, sdk.Coins{sdk.NewInt64Coin(stakeTypes.DefaultBondDenom, 42)}, addr0Initial)
|
||||||
|
|
||||||
require.True(t, proposal.GetTotalDeposit().IsEqual(sdk.Coins{}))
|
require.True(t, proposal.GetTotalDeposit().IsEqual(sdk.Coins{}))
|
||||||
|
|
||||||
|
|
|
@ -7,16 +7,21 @@ import (
|
||||||
|
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
"github.com/cosmos/cosmos-sdk/x/mock"
|
"github.com/cosmos/cosmos-sdk/x/mock"
|
||||||
|
stakeTypes "github.com/cosmos/cosmos-sdk/x/stake/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
coinsPos = sdk.Coins{sdk.NewInt64Coin("steak", 1000)}
|
coinsPos = sdk.Coins{sdk.NewInt64Coin(stakeTypes.DefaultBondDenom, 1000)}
|
||||||
coinsZero = sdk.Coins{}
|
coinsZero = sdk.Coins{}
|
||||||
coinsNeg = sdk.Coins{sdk.NewInt64Coin("steak", -10000)}
|
coinsNeg = sdk.Coins{sdk.NewInt64Coin(stakeTypes.DefaultBondDenom, -10000)}
|
||||||
coinsPosNotAtoms = sdk.Coins{sdk.NewInt64Coin("foo", 10000)}
|
coinsPosNotAtoms = sdk.Coins{sdk.NewInt64Coin("foo", 10000)}
|
||||||
coinsMulti = sdk.Coins{sdk.NewInt64Coin("foo", 10000), sdk.NewInt64Coin("steak", 1000)}
|
coinsMulti = sdk.Coins{sdk.NewInt64Coin(stakeTypes.DefaultBondDenom, 1000), sdk.NewInt64Coin("foo", 10000)}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
coinsMulti.Sort()
|
||||||
|
}
|
||||||
|
|
||||||
// test ValidateBasic for MsgCreateValidator
|
// test ValidateBasic for MsgCreateValidator
|
||||||
func TestMsgSubmitProposal(t *testing.T) {
|
func TestMsgSubmitProposal(t *testing.T) {
|
||||||
_, addrs, _, _ := mock.CreateGenAccounts(1, sdk.Coins{})
|
_, addrs, _, _ := mock.CreateGenAccounts(1, sdk.Coins{})
|
||||||
|
@ -42,9 +47,9 @@ func TestMsgSubmitProposal(t *testing.T) {
|
||||||
for i, tc := range tests {
|
for i, tc := range tests {
|
||||||
msg := NewMsgSubmitProposal(tc.title, tc.description, tc.proposalType, tc.proposerAddr, tc.initialDeposit)
|
msg := NewMsgSubmitProposal(tc.title, tc.description, tc.proposalType, tc.proposerAddr, tc.initialDeposit)
|
||||||
if tc.expectPass {
|
if tc.expectPass {
|
||||||
require.Nil(t, msg.ValidateBasic(), "test: %v", i)
|
require.NoError(t, msg.ValidateBasic(), "test: %v", i)
|
||||||
} else {
|
} else {
|
||||||
require.NotNil(t, msg.ValidateBasic(), "test: %v", i)
|
require.Error(t, msg.ValidateBasic(), "test: %v", i)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -68,9 +73,9 @@ func TestMsgDeposit(t *testing.T) {
|
||||||
for i, tc := range tests {
|
for i, tc := range tests {
|
||||||
msg := NewMsgDeposit(tc.depositerAddr, tc.proposalID, tc.depositAmount)
|
msg := NewMsgDeposit(tc.depositerAddr, tc.proposalID, tc.depositAmount)
|
||||||
if tc.expectPass {
|
if tc.expectPass {
|
||||||
require.Nil(t, msg.ValidateBasic(), "test: %v", i)
|
require.NoError(t, msg.ValidateBasic(), "test: %v", i)
|
||||||
} else {
|
} else {
|
||||||
require.NotNil(t, msg.ValidateBasic(), "test: %v", i)
|
require.Error(t, msg.ValidateBasic(), "test: %v", i)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,20 +6,20 @@ import (
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Procedure around Deposits for governance
|
// Param around Deposits for governance
|
||||||
type DepositParams struct {
|
type DepositParams struct {
|
||||||
MinDeposit sdk.Coins `json:"min_deposit"` // Minimum deposit for a proposal to enter voting period.
|
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
|
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 {
|
type TallyParams struct {
|
||||||
Threshold sdk.Dec `json:"threshold"` // Minimum propotion of Yes votes for proposal to pass. Initial value: 0.5
|
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
|
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
|
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 {
|
type VotingParams struct {
|
||||||
VotingPeriod time.Duration `json:"voting_period"` // Length of the voting period.
|
VotingPeriod time.Duration `json:"voting_period"` // Length of the voting period.
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
package gov
|
package gov
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
"github.com/cosmos/cosmos-sdk/codec"
|
"github.com/cosmos/cosmos-sdk/codec"
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
abci "github.com/tendermint/tendermint/abci/types"
|
abci "github.com/tendermint/tendermint/abci/types"
|
||||||
|
@ -8,6 +10,7 @@ import (
|
||||||
|
|
||||||
// query endpoints supported by the governance Querier
|
// query endpoints supported by the governance Querier
|
||||||
const (
|
const (
|
||||||
|
QueryParams = "params"
|
||||||
QueryProposals = "proposals"
|
QueryProposals = "proposals"
|
||||||
QueryProposal = "proposal"
|
QueryProposal = "proposal"
|
||||||
QueryDeposits = "deposits"
|
QueryDeposits = "deposits"
|
||||||
|
@ -15,11 +18,17 @@ const (
|
||||||
QueryVotes = "votes"
|
QueryVotes = "votes"
|
||||||
QueryVote = "vote"
|
QueryVote = "vote"
|
||||||
QueryTally = "tally"
|
QueryTally = "tally"
|
||||||
|
|
||||||
|
ParamDeposit = "deposit"
|
||||||
|
ParamVoting = "voting"
|
||||||
|
ParamTallying = "tallying"
|
||||||
)
|
)
|
||||||
|
|
||||||
func NewQuerier(keeper Keeper) sdk.Querier {
|
func NewQuerier(keeper Keeper) sdk.Querier {
|
||||||
return func(ctx sdk.Context, path []string, req abci.RequestQuery) (res []byte, err sdk.Error) {
|
return func(ctx sdk.Context, path []string, req abci.RequestQuery) (res []byte, err sdk.Error) {
|
||||||
switch path[0] {
|
switch path[0] {
|
||||||
|
case QueryParams:
|
||||||
|
return queryParams(ctx, path[1:], req, keeper)
|
||||||
case QueryProposals:
|
case QueryProposals:
|
||||||
return queryProposals(ctx, path[1:], req, keeper)
|
return queryProposals(ctx, path[1:], req, keeper)
|
||||||
case QueryProposal:
|
case QueryProposal:
|
||||||
|
@ -40,6 +49,31 @@ 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 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 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))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Params for query 'custom/gov/proposal'
|
// Params for query 'custom/gov/proposal'
|
||||||
type QueryProposalParams struct {
|
type QueryProposalParams struct {
|
||||||
ProposalID uint64
|
ProposalID uint64
|
|
@ -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()))
|
||||||
|
}
|
|
@ -11,10 +11,11 @@ import (
|
||||||
"github.com/cosmos/cosmos-sdk/x/gov"
|
"github.com/cosmos/cosmos-sdk/x/gov"
|
||||||
"github.com/cosmos/cosmos-sdk/x/mock/simulation"
|
"github.com/cosmos/cosmos-sdk/x/mock/simulation"
|
||||||
"github.com/cosmos/cosmos-sdk/x/stake"
|
"github.com/cosmos/cosmos-sdk/x/stake"
|
||||||
|
stakeTypes "github.com/cosmos/cosmos-sdk/x/stake/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
denom = "steak"
|
denom = stakeTypes.DefaultBondDenom
|
||||||
)
|
)
|
||||||
|
|
||||||
// SimulateSubmittingVotingAndSlashingForProposal simulates creating a msg Submit Proposal
|
// SimulateSubmittingVotingAndSlashingForProposal simulates creating a msg Submit Proposal
|
||||||
|
|
|
@ -11,6 +11,7 @@ import (
|
||||||
"github.com/tendermint/tendermint/crypto/ed25519"
|
"github.com/tendermint/tendermint/crypto/ed25519"
|
||||||
|
|
||||||
"github.com/cosmos/cosmos-sdk/x/stake"
|
"github.com/cosmos/cosmos-sdk/x/stake"
|
||||||
|
stakeTypes "github.com/cosmos/cosmos-sdk/x/stake/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -25,7 +26,7 @@ func createValidators(t *testing.T, stakeHandler sdk.Handler, ctx sdk.Context, a
|
||||||
|
|
||||||
for i := 0; i < len(addrs); i++ {
|
for i := 0; i < len(addrs); i++ {
|
||||||
valCreateMsg := stake.NewMsgCreateValidator(
|
valCreateMsg := stake.NewMsgCreateValidator(
|
||||||
addrs[i], pubkeys[i], sdk.NewInt64Coin("steak", coinAmt[i]), testDescription, testCommissionMsg,
|
addrs[i], pubkeys[i], sdk.NewInt64Coin(stakeTypes.DefaultBondDenom, coinAmt[i]), testDescription, testCommissionMsg,
|
||||||
)
|
)
|
||||||
|
|
||||||
res := stakeHandler(ctx, valCreateMsg)
|
res := stakeHandler(ctx, valCreateMsg)
|
||||||
|
@ -289,7 +290,7 @@ func TestTallyDelgatorOverride(t *testing.T) {
|
||||||
createValidators(t, stakeHandler, ctx, valAddrs, []int64{5, 6, 7})
|
createValidators(t, stakeHandler, ctx, valAddrs, []int64{5, 6, 7})
|
||||||
stake.EndBlocker(ctx, sk)
|
stake.EndBlocker(ctx, sk)
|
||||||
|
|
||||||
delegator1Msg := stake.NewMsgDelegate(addrs[3], sdk.ValAddress(addrs[2]), sdk.NewInt64Coin("steak", 30))
|
delegator1Msg := stake.NewMsgDelegate(addrs[3], sdk.ValAddress(addrs[2]), sdk.NewInt64Coin(stakeTypes.DefaultBondDenom, 30))
|
||||||
stakeHandler(ctx, delegator1Msg)
|
stakeHandler(ctx, delegator1Msg)
|
||||||
|
|
||||||
proposal := keeper.NewTextProposal(ctx, "Test", "description", ProposalTypeText)
|
proposal := keeper.NewTextProposal(ctx, "Test", "description", ProposalTypeText)
|
||||||
|
@ -326,7 +327,7 @@ func TestTallyDelgatorInherit(t *testing.T) {
|
||||||
createValidators(t, stakeHandler, ctx, valAddrs, []int64{5, 6, 7})
|
createValidators(t, stakeHandler, ctx, valAddrs, []int64{5, 6, 7})
|
||||||
stake.EndBlocker(ctx, sk)
|
stake.EndBlocker(ctx, sk)
|
||||||
|
|
||||||
delegator1Msg := stake.NewMsgDelegate(addrs[3], sdk.ValAddress(addrs[2]), sdk.NewInt64Coin("steak", 30))
|
delegator1Msg := stake.NewMsgDelegate(addrs[3], sdk.ValAddress(addrs[2]), sdk.NewInt64Coin(stakeTypes.DefaultBondDenom, 30))
|
||||||
stakeHandler(ctx, delegator1Msg)
|
stakeHandler(ctx, delegator1Msg)
|
||||||
|
|
||||||
proposal := keeper.NewTextProposal(ctx, "Test", "description", ProposalTypeText)
|
proposal := keeper.NewTextProposal(ctx, "Test", "description", ProposalTypeText)
|
||||||
|
@ -361,9 +362,9 @@ func TestTallyDelgatorMultipleOverride(t *testing.T) {
|
||||||
createValidators(t, stakeHandler, ctx, valAddrs, []int64{5, 6, 7})
|
createValidators(t, stakeHandler, ctx, valAddrs, []int64{5, 6, 7})
|
||||||
stake.EndBlocker(ctx, sk)
|
stake.EndBlocker(ctx, sk)
|
||||||
|
|
||||||
delegator1Msg := stake.NewMsgDelegate(addrs[3], sdk.ValAddress(addrs[2]), sdk.NewInt64Coin("steak", 10))
|
delegator1Msg := stake.NewMsgDelegate(addrs[3], sdk.ValAddress(addrs[2]), sdk.NewInt64Coin(stakeTypes.DefaultBondDenom, 10))
|
||||||
stakeHandler(ctx, delegator1Msg)
|
stakeHandler(ctx, delegator1Msg)
|
||||||
delegator1Msg2 := stake.NewMsgDelegate(addrs[3], sdk.ValAddress(addrs[1]), sdk.NewInt64Coin("steak", 10))
|
delegator1Msg2 := stake.NewMsgDelegate(addrs[3], sdk.ValAddress(addrs[1]), sdk.NewInt64Coin(stakeTypes.DefaultBondDenom, 10))
|
||||||
stakeHandler(ctx, delegator1Msg2)
|
stakeHandler(ctx, delegator1Msg2)
|
||||||
|
|
||||||
proposal := keeper.NewTextProposal(ctx, "Test", "description", ProposalTypeText)
|
proposal := keeper.NewTextProposal(ctx, "Test", "description", ProposalTypeText)
|
||||||
|
@ -393,24 +394,24 @@ func TestTallyDelgatorMultipleInherit(t *testing.T) {
|
||||||
stakeHandler := stake.NewHandler(sk)
|
stakeHandler := stake.NewHandler(sk)
|
||||||
|
|
||||||
val1CreateMsg := stake.NewMsgCreateValidator(
|
val1CreateMsg := stake.NewMsgCreateValidator(
|
||||||
sdk.ValAddress(addrs[0]), ed25519.GenPrivKey().PubKey(), sdk.NewInt64Coin("steak", 25), testDescription, testCommissionMsg,
|
sdk.ValAddress(addrs[0]), ed25519.GenPrivKey().PubKey(), sdk.NewInt64Coin(stakeTypes.DefaultBondDenom, 25), testDescription, testCommissionMsg,
|
||||||
)
|
)
|
||||||
stakeHandler(ctx, val1CreateMsg)
|
stakeHandler(ctx, val1CreateMsg)
|
||||||
|
|
||||||
val2CreateMsg := stake.NewMsgCreateValidator(
|
val2CreateMsg := stake.NewMsgCreateValidator(
|
||||||
sdk.ValAddress(addrs[1]), ed25519.GenPrivKey().PubKey(), sdk.NewInt64Coin("steak", 6), testDescription, testCommissionMsg,
|
sdk.ValAddress(addrs[1]), ed25519.GenPrivKey().PubKey(), sdk.NewInt64Coin(stakeTypes.DefaultBondDenom, 6), testDescription, testCommissionMsg,
|
||||||
)
|
)
|
||||||
stakeHandler(ctx, val2CreateMsg)
|
stakeHandler(ctx, val2CreateMsg)
|
||||||
|
|
||||||
val3CreateMsg := stake.NewMsgCreateValidator(
|
val3CreateMsg := stake.NewMsgCreateValidator(
|
||||||
sdk.ValAddress(addrs[2]), ed25519.GenPrivKey().PubKey(), sdk.NewInt64Coin("steak", 7), testDescription, testCommissionMsg,
|
sdk.ValAddress(addrs[2]), ed25519.GenPrivKey().PubKey(), sdk.NewInt64Coin(stakeTypes.DefaultBondDenom, 7), testDescription, testCommissionMsg,
|
||||||
)
|
)
|
||||||
stakeHandler(ctx, val3CreateMsg)
|
stakeHandler(ctx, val3CreateMsg)
|
||||||
|
|
||||||
delegator1Msg := stake.NewMsgDelegate(addrs[3], sdk.ValAddress(addrs[2]), sdk.NewInt64Coin("steak", 10))
|
delegator1Msg := stake.NewMsgDelegate(addrs[3], sdk.ValAddress(addrs[2]), sdk.NewInt64Coin(stakeTypes.DefaultBondDenom, 10))
|
||||||
stakeHandler(ctx, delegator1Msg)
|
stakeHandler(ctx, delegator1Msg)
|
||||||
|
|
||||||
delegator1Msg2 := stake.NewMsgDelegate(addrs[3], sdk.ValAddress(addrs[1]), sdk.NewInt64Coin("steak", 10))
|
delegator1Msg2 := stake.NewMsgDelegate(addrs[3], sdk.ValAddress(addrs[1]), sdk.NewInt64Coin(stakeTypes.DefaultBondDenom, 10))
|
||||||
stakeHandler(ctx, delegator1Msg2)
|
stakeHandler(ctx, delegator1Msg2)
|
||||||
|
|
||||||
stake.EndBlocker(ctx, sk)
|
stake.EndBlocker(ctx, sk)
|
||||||
|
@ -447,10 +448,10 @@ func TestTallyJailedValidator(t *testing.T) {
|
||||||
createValidators(t, stakeHandler, ctx, valAddrs, []int64{25, 6, 7})
|
createValidators(t, stakeHandler, ctx, valAddrs, []int64{25, 6, 7})
|
||||||
stake.EndBlocker(ctx, sk)
|
stake.EndBlocker(ctx, sk)
|
||||||
|
|
||||||
delegator1Msg := stake.NewMsgDelegate(addrs[3], sdk.ValAddress(addrs[2]), sdk.NewInt64Coin("steak", 10))
|
delegator1Msg := stake.NewMsgDelegate(addrs[3], sdk.ValAddress(addrs[2]), sdk.NewInt64Coin(stakeTypes.DefaultBondDenom, 10))
|
||||||
stakeHandler(ctx, delegator1Msg)
|
stakeHandler(ctx, delegator1Msg)
|
||||||
|
|
||||||
delegator1Msg2 := stake.NewMsgDelegate(addrs[3], sdk.ValAddress(addrs[1]), sdk.NewInt64Coin("steak", 10))
|
delegator1Msg2 := stake.NewMsgDelegate(addrs[3], sdk.ValAddress(addrs[1]), sdk.NewInt64Coin(stakeTypes.DefaultBondDenom, 10))
|
||||||
stakeHandler(ctx, delegator1Msg2)
|
stakeHandler(ctx, delegator1Msg2)
|
||||||
|
|
||||||
val2, found := sk.GetValidator(ctx, sdk.ValAddress(addrs[1]))
|
val2, found := sk.GetValidator(ctx, sdk.ValAddress(addrs[1]))
|
||||||
|
|
|
@ -17,6 +17,7 @@ import (
|
||||||
"github.com/cosmos/cosmos-sdk/x/bank"
|
"github.com/cosmos/cosmos-sdk/x/bank"
|
||||||
"github.com/cosmos/cosmos-sdk/x/mock"
|
"github.com/cosmos/cosmos-sdk/x/mock"
|
||||||
"github.com/cosmos/cosmos-sdk/x/stake"
|
"github.com/cosmos/cosmos-sdk/x/stake"
|
||||||
|
stakeTypes "github.com/cosmos/cosmos-sdk/x/stake/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
// initialize the mock application for this module
|
// initialize the mock application for this module
|
||||||
|
@ -38,13 +39,14 @@ func getMockApp(t *testing.T, numGenAccs int) (*mock.App, Keeper, stake.Keeper,
|
||||||
keeper := NewKeeper(mapp.Cdc, keyGov, pk, pk.Subspace("testgov"), ck, sk, DefaultCodespace)
|
keeper := NewKeeper(mapp.Cdc, keyGov, pk, pk.Subspace("testgov"), ck, sk, DefaultCodespace)
|
||||||
|
|
||||||
mapp.Router().AddRoute("gov", NewHandler(keeper))
|
mapp.Router().AddRoute("gov", NewHandler(keeper))
|
||||||
|
mapp.QueryRouter().AddRoute("gov", NewQuerier(keeper))
|
||||||
|
|
||||||
mapp.SetEndBlocker(getEndBlocker(keeper))
|
mapp.SetEndBlocker(getEndBlocker(keeper))
|
||||||
mapp.SetInitChainer(getInitChainer(mapp, keeper, sk))
|
mapp.SetInitChainer(getInitChainer(mapp, keeper, sk))
|
||||||
|
|
||||||
require.NoError(t, mapp.CompleteSetup(keyStake, tkeyStake, keyGov, keyGlobalParams, tkeyGlobalParams))
|
require.NoError(t, mapp.CompleteSetup(keyStake, tkeyStake, keyGov, keyGlobalParams, tkeyGlobalParams))
|
||||||
|
|
||||||
genAccs, addrs, pubKeys, privKeys := mock.CreateGenAccounts(numGenAccs, sdk.Coins{sdk.NewInt64Coin("steak", 42)})
|
genAccs, addrs, pubKeys, privKeys := mock.CreateGenAccounts(numGenAccs, sdk.Coins{sdk.NewInt64Coin(stakeTypes.DefaultBondDenom, 42)})
|
||||||
|
|
||||||
mock.SetGenesis(mapp, genAccs)
|
mock.SetGenesis(mapp, genAccs)
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@ package mint
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
stakeTypes "github.com/cosmos/cosmos-sdk/x/stake/types"
|
||||||
|
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
)
|
)
|
||||||
|
@ -18,7 +19,7 @@ type Params struct {
|
||||||
// default minting module parameters
|
// default minting module parameters
|
||||||
func DefaultParams() Params {
|
func DefaultParams() Params {
|
||||||
return Params{
|
return Params{
|
||||||
MintDenom: "steak",
|
MintDenom: stakeTypes.DefaultBondDenom,
|
||||||
InflationRateChange: sdk.NewDecWithPrec(13, 2),
|
InflationRateChange: sdk.NewDecWithPrec(13, 2),
|
||||||
InflationMax: sdk.NewDecWithPrec(20, 2),
|
InflationMax: sdk.NewDecWithPrec(20, 2),
|
||||||
InflationMin: sdk.NewDecWithPrec(7, 2),
|
InflationMin: sdk.NewDecWithPrec(7, 2),
|
||||||
|
|
|
@ -1,9 +1,11 @@
|
||||||
package mock
|
package mock
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"os"
|
"os"
|
||||||
|
"sort"
|
||||||
|
|
||||||
bam "github.com/cosmos/cosmos-sdk/baseapp"
|
bam "github.com/cosmos/cosmos-sdk/baseapp"
|
||||||
"github.com/cosmos/cosmos-sdk/codec"
|
"github.com/cosmos/cosmos-sdk/codec"
|
||||||
|
@ -109,23 +111,64 @@ func (app *App) InitChainer(ctx sdk.Context, _ abci.RequestInitChain) abci.Respo
|
||||||
return abci.ResponseInitChain{}
|
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
|
// CreateGenAccounts generates genesis accounts loaded with coins, and returns
|
||||||
// their addresses, pubkeys, and privkeys.
|
// their addresses, pubkeys, and privkeys.
|
||||||
func CreateGenAccounts(numAccs int, genCoins sdk.Coins) (genAccs []auth.Account, addrs []sdk.AccAddress, pubKeys []crypto.PubKey, privKeys []crypto.PrivKey) {
|
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++ {
|
for i := 0; i < numAccs; i++ {
|
||||||
privKey := ed25519.GenPrivKey()
|
privKey := ed25519.GenPrivKey()
|
||||||
pubKey := privKey.PubKey()
|
pubKey := privKey.PubKey()
|
||||||
addr := sdk.AccAddress(pubKey.Address())
|
addr := sdk.AccAddress(pubKey.Address())
|
||||||
|
|
||||||
genAcc := &auth.BaseAccount{
|
addrKeysSlice = append(addrKeysSlice, AddrKeys{
|
||||||
Address: addr,
|
Address: addr,
|
||||||
Coins: genCoins,
|
PubKey: pubKey,
|
||||||
|
PrivKey: privKey,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
genAccs = append(genAccs, genAcc)
|
sort.Sort(addrKeysSlice)
|
||||||
privKeys = append(privKeys, privKey)
|
|
||||||
pubKeys = append(pubKeys, pubKey)
|
for i := range addrKeysSlice {
|
||||||
addrs = append(addrs, addr)
|
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
|
return
|
||||||
|
|
|
@ -3,15 +3,17 @@ package slashing
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
abci "github.com/tendermint/tendermint/abci/types"
|
||||||
|
"github.com/tendermint/tendermint/crypto/ed25519"
|
||||||
|
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
"github.com/cosmos/cosmos-sdk/x/auth"
|
"github.com/cosmos/cosmos-sdk/x/auth"
|
||||||
"github.com/cosmos/cosmos-sdk/x/bank"
|
"github.com/cosmos/cosmos-sdk/x/bank"
|
||||||
"github.com/cosmos/cosmos-sdk/x/mock"
|
"github.com/cosmos/cosmos-sdk/x/mock"
|
||||||
"github.com/cosmos/cosmos-sdk/x/params"
|
"github.com/cosmos/cosmos-sdk/x/params"
|
||||||
"github.com/cosmos/cosmos-sdk/x/stake"
|
"github.com/cosmos/cosmos-sdk/x/stake"
|
||||||
"github.com/stretchr/testify/require"
|
stakeTypes "github.com/cosmos/cosmos-sdk/x/stake/types"
|
||||||
abci "github.com/tendermint/tendermint/abci/types"
|
|
||||||
"github.com/tendermint/tendermint/crypto/ed25519"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -93,8 +95,8 @@ func checkValidatorSigningInfo(t *testing.T, mapp *mock.App, keeper Keeper,
|
||||||
func TestSlashingMsgs(t *testing.T) {
|
func TestSlashingMsgs(t *testing.T) {
|
||||||
mapp, stakeKeeper, keeper := getMockApp(t)
|
mapp, stakeKeeper, keeper := getMockApp(t)
|
||||||
|
|
||||||
genCoin := sdk.NewInt64Coin("steak", 42)
|
genCoin := sdk.NewInt64Coin(stakeTypes.DefaultBondDenom, 42)
|
||||||
bondCoin := sdk.NewInt64Coin("steak", 10)
|
bondCoin := sdk.NewInt64Coin(stakeTypes.DefaultBondDenom, 10)
|
||||||
|
|
||||||
acc1 := &auth.BaseAccount{
|
acc1 := &auth.BaseAccount{
|
||||||
Address: addr1,
|
Address: addr1,
|
||||||
|
|
|
@ -21,6 +21,7 @@ import (
|
||||||
"github.com/cosmos/cosmos-sdk/x/bank"
|
"github.com/cosmos/cosmos-sdk/x/bank"
|
||||||
"github.com/cosmos/cosmos-sdk/x/params"
|
"github.com/cosmos/cosmos-sdk/x/params"
|
||||||
"github.com/cosmos/cosmos-sdk/x/stake"
|
"github.com/cosmos/cosmos-sdk/x/stake"
|
||||||
|
stakeTypes "github.com/cosmos/cosmos-sdk/x/stake/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
// TODO remove dependencies on staking (should only refer to validator set type from sdk)
|
// TODO remove dependencies on staking (should only refer to validator set type from sdk)
|
||||||
|
@ -120,7 +121,7 @@ func NewTestMsgCreateValidator(address sdk.ValAddress, pubKey crypto.PubKey, amt
|
||||||
DelegatorAddr: sdk.AccAddress(address),
|
DelegatorAddr: sdk.AccAddress(address),
|
||||||
ValidatorAddr: address,
|
ValidatorAddr: address,
|
||||||
PubKey: pubKey,
|
PubKey: pubKey,
|
||||||
Delegation: sdk.NewCoin("steak", amt),
|
Delegation: sdk.NewCoin(stakeTypes.DefaultBondDenom, amt),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -128,6 +129,6 @@ func newTestMsgDelegate(delAddr sdk.AccAddress, valAddr sdk.ValAddress, delAmoun
|
||||||
return stake.MsgDelegate{
|
return stake.MsgDelegate{
|
||||||
DelegatorAddr: delAddr,
|
DelegatorAddr: delAddr,
|
||||||
ValidatorAddr: valAddr,
|
ValidatorAddr: valAddr,
|
||||||
Delegation: sdk.NewCoin("steak", delAmount),
|
Delegation: sdk.NewCoin(stakeTypes.DefaultBondDenom, delAmount),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,13 +3,15 @@ package stake
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
abci "github.com/tendermint/tendermint/abci/types"
|
||||||
|
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
"github.com/cosmos/cosmos-sdk/x/auth"
|
"github.com/cosmos/cosmos-sdk/x/auth"
|
||||||
"github.com/cosmos/cosmos-sdk/x/bank"
|
"github.com/cosmos/cosmos-sdk/x/bank"
|
||||||
"github.com/cosmos/cosmos-sdk/x/mock"
|
"github.com/cosmos/cosmos-sdk/x/mock"
|
||||||
"github.com/cosmos/cosmos-sdk/x/params"
|
"github.com/cosmos/cosmos-sdk/x/params"
|
||||||
"github.com/stretchr/testify/require"
|
stakeTypes "github.com/cosmos/cosmos-sdk/x/stake/types"
|
||||||
abci "github.com/tendermint/tendermint/abci/types"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// getMockApp returns an initialized mock application for this module.
|
// getMockApp returns an initialized mock application for this module.
|
||||||
|
@ -100,8 +102,8 @@ func checkDelegation(
|
||||||
func TestStakeMsgs(t *testing.T) {
|
func TestStakeMsgs(t *testing.T) {
|
||||||
mApp, keeper := getMockApp(t)
|
mApp, keeper := getMockApp(t)
|
||||||
|
|
||||||
genCoin := sdk.NewInt64Coin("steak", 42)
|
genCoin := sdk.NewInt64Coin(stakeTypes.DefaultBondDenom, 42)
|
||||||
bondCoin := sdk.NewInt64Coin("steak", 10)
|
bondCoin := sdk.NewInt64Coin(stakeTypes.DefaultBondDenom, 10)
|
||||||
|
|
||||||
acc1 := &auth.BaseAccount{
|
acc1 := &auth.BaseAccount{
|
||||||
Address: addr1,
|
Address: addr1,
|
||||||
|
|
|
@ -127,9 +127,7 @@ func GetCmdQueryValidatorUnbondingDelegations(queryRoute string, cdc *codec.Code
|
||||||
}
|
}
|
||||||
|
|
||||||
cliCtx := context.NewCLIContext().WithCodec(cdc)
|
cliCtx := context.NewCLIContext().WithCodec(cdc)
|
||||||
params := stake.QueryValidatorParams{
|
params := stake.NewQueryValidatorParams(valAddr)
|
||||||
ValidatorAddr: valAddr,
|
|
||||||
}
|
|
||||||
|
|
||||||
bz, err := cdc.MarshalJSON(params)
|
bz, err := cdc.MarshalJSON(params)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -164,9 +162,7 @@ func GetCmdQueryValidatorRedelegations(queryRoute string, cdc *codec.Codec) *cob
|
||||||
}
|
}
|
||||||
|
|
||||||
cliCtx := context.NewCLIContext().WithCodec(cdc)
|
cliCtx := context.NewCLIContext().WithCodec(cdc)
|
||||||
params := stake.QueryValidatorParams{
|
params := stake.NewQueryValidatorParams(valAddr)
|
||||||
ValidatorAddr: valAddr,
|
|
||||||
}
|
|
||||||
|
|
||||||
bz, err := cdc.MarshalJSON(params)
|
bz, err := cdc.MarshalJSON(params)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -290,6 +286,41 @@ func GetCmdQueryDelegations(storeName string, cdc *codec.Codec) *cobra.Command {
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetCmdQueryValidatorDelegations implements the command to query all the
|
||||||
|
// delegations to a specific validator.
|
||||||
|
func GetCmdQueryValidatorDelegations(queryRoute string, cdc *codec.Codec) *cobra.Command {
|
||||||
|
cmd := &cobra.Command{
|
||||||
|
Use: "delegations-to [validator-addr]",
|
||||||
|
Short: "Query all delegations made to one validator",
|
||||||
|
Args: cobra.ExactArgs(1),
|
||||||
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
|
validatorAddr, err := sdk.ValAddressFromBech32(args[0])
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
params := stake.NewQueryValidatorParams(validatorAddr)
|
||||||
|
|
||||||
|
bz, err := cdc.MarshalJSON(params)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
cliCtx := context.NewCLIContext().WithCodec(cdc)
|
||||||
|
|
||||||
|
res, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/validatorDelegations", queryRoute), bz)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Println(string(res))
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
return cmd
|
||||||
|
}
|
||||||
|
|
||||||
// GetCmdQueryUnbondingDelegation implements the command to query a single
|
// GetCmdQueryUnbondingDelegation implements the command to query a single
|
||||||
// unbonding-delegation record.
|
// unbonding-delegation record.
|
||||||
func GetCmdQueryUnbondingDelegation(storeName string, cdc *codec.Codec) *cobra.Command {
|
func GetCmdQueryUnbondingDelegation(storeName string, cdc *codec.Codec) *cobra.Command {
|
||||||
|
|
|
@ -2,6 +2,7 @@ package cli
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/cosmos/cosmos-sdk/client"
|
"github.com/cosmos/cosmos-sdk/client"
|
||||||
"github.com/cosmos/cosmos-sdk/client/context"
|
"github.com/cosmos/cosmos-sdk/client/context"
|
||||||
"github.com/cosmos/cosmos-sdk/client/utils"
|
"github.com/cosmos/cosmos-sdk/client/utils"
|
||||||
|
@ -210,26 +211,11 @@ func GetCmdDelegate(cdc *codec.Codec) *cobra.Command {
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetCmdRedelegate implements the redelegate validator command.
|
// GetCmdRedelegate the begin redelegation command.
|
||||||
func GetCmdRedelegate(storeName string, cdc *codec.Codec) *cobra.Command {
|
func GetCmdRedelegate(storeName string, cdc *codec.Codec) *cobra.Command {
|
||||||
cmd := &cobra.Command{
|
cmd := &cobra.Command{
|
||||||
Use: "redelegate",
|
Use: "redelegate",
|
||||||
Short: "redelegate illiquid tokens from one validator to another",
|
Short: "redelegate illiquid tokens from one validator to another",
|
||||||
}
|
|
||||||
|
|
||||||
cmd.AddCommand(
|
|
||||||
client.PostCommands(
|
|
||||||
GetCmdBeginRedelegate(storeName, cdc),
|
|
||||||
)...)
|
|
||||||
|
|
||||||
return cmd
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetCmdBeginRedelegate the begin redelegation command.
|
|
||||||
func GetCmdBeginRedelegate(storeName string, cdc *codec.Codec) *cobra.Command {
|
|
||||||
cmd := &cobra.Command{
|
|
||||||
Use: "begin",
|
|
||||||
Short: "begin redelegation",
|
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
txBldr := authtxb.NewTxBuilderFromCLI().WithCodec(cdc)
|
txBldr := authtxb.NewTxBuilderFromCLI().WithCodec(cdc)
|
||||||
cliCtx := context.NewCLIContext().
|
cliCtx := context.NewCLIContext().
|
||||||
|
@ -284,22 +270,7 @@ func GetCmdBeginRedelegate(storeName string, cdc *codec.Codec) *cobra.Command {
|
||||||
func GetCmdUnbond(storeName string, cdc *codec.Codec) *cobra.Command {
|
func GetCmdUnbond(storeName string, cdc *codec.Codec) *cobra.Command {
|
||||||
cmd := &cobra.Command{
|
cmd := &cobra.Command{
|
||||||
Use: "unbond",
|
Use: "unbond",
|
||||||
Short: "begin or complete unbonding shares from a validator",
|
Short: "unbond shares from a validator",
|
||||||
}
|
|
||||||
|
|
||||||
cmd.AddCommand(
|
|
||||||
client.PostCommands(
|
|
||||||
GetCmdBeginUnbonding(storeName, cdc),
|
|
||||||
)...)
|
|
||||||
|
|
||||||
return cmd
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetCmdBeginUnbonding implements the begin unbonding validator command.
|
|
||||||
func GetCmdBeginUnbonding(storeName string, cdc *codec.Codec) *cobra.Command {
|
|
||||||
cmd := &cobra.Command{
|
|
||||||
Use: "begin",
|
|
||||||
Short: "begin unbonding",
|
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
txBldr := authtxb.NewTxBuilderFromCLI().WithCodec(cdc)
|
txBldr := authtxb.NewTxBuilderFromCLI().WithCodec(cdc)
|
||||||
cliCtx := context.NewCLIContext().
|
cliCtx := context.NewCLIContext().
|
||||||
|
|
|
@ -78,6 +78,12 @@ func registerQueryRoutes(cliCtx context.CLIContext, r *mux.Router, cdc *codec.Co
|
||||||
validatorHandlerFn(cliCtx, cdc),
|
validatorHandlerFn(cliCtx, cdc),
|
||||||
).Methods("GET")
|
).Methods("GET")
|
||||||
|
|
||||||
|
// Get all delegations to a validator
|
||||||
|
r.HandleFunc(
|
||||||
|
"/stake/validators/{validatorAddr}/delegations",
|
||||||
|
validatorDelegationsHandlerFn(cliCtx, cdc),
|
||||||
|
).Methods("GET")
|
||||||
|
|
||||||
// Get all unbonding delegations from a validator
|
// Get all unbonding delegations from a validator
|
||||||
r.HandleFunc(
|
r.HandleFunc(
|
||||||
"/stake/validators/{validatorAddr}/unbonding_delegations",
|
"/stake/validators/{validatorAddr}/unbonding_delegations",
|
||||||
|
@ -227,6 +233,11 @@ func validatorHandlerFn(cliCtx context.CLIContext, cdc *codec.Codec) http.Handle
|
||||||
return queryValidator(cliCtx, cdc, "custom/stake/validator")
|
return queryValidator(cliCtx, cdc, "custom/stake/validator")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// HTTP request handler to query all unbonding delegations from a validator
|
||||||
|
func validatorDelegationsHandlerFn(cliCtx context.CLIContext, cdc *codec.Codec) http.HandlerFunc {
|
||||||
|
return queryValidator(cliCtx, cdc, "custom/stake/validatorDelegations")
|
||||||
|
}
|
||||||
|
|
||||||
// HTTP request handler to query all unbonding delegations from a validator
|
// HTTP request handler to query all unbonding delegations from a validator
|
||||||
func validatorUnbondingDelegationsHandlerFn(cliCtx context.CLIContext, cdc *codec.Codec) http.HandlerFunc {
|
func validatorUnbondingDelegationsHandlerFn(cliCtx context.CLIContext, cdc *codec.Codec) http.HandlerFunc {
|
||||||
return queryValidator(cliCtx, cdc, "custom/stake/validatorUnbondingDelegations")
|
return queryValidator(cliCtx, cdc, "custom/stake/validatorUnbondingDelegations")
|
||||||
|
|
|
@ -62,10 +62,7 @@ func queryBonds(cliCtx context.CLIContext, cdc *codec.Codec, endpoint string) ht
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
params := stake.QueryBondsParams{
|
params := stake.NewQueryBondsParams(delegatorAddr, validatorAddr)
|
||||||
DelegatorAddr: delegatorAddr,
|
|
||||||
ValidatorAddr: validatorAddr,
|
|
||||||
}
|
|
||||||
|
|
||||||
bz, err := cdc.MarshalJSON(params)
|
bz, err := cdc.MarshalJSON(params)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -93,9 +90,7 @@ func queryDelegator(cliCtx context.CLIContext, cdc *codec.Codec, endpoint string
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
params := stake.QueryDelegatorParams{
|
params := stake.NewQueryDelegatorParams(delegatorAddr)
|
||||||
DelegatorAddr: delegatorAddr,
|
|
||||||
}
|
|
||||||
|
|
||||||
bz, err := cdc.MarshalJSON(params)
|
bz, err := cdc.MarshalJSON(params)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -123,9 +118,7 @@ func queryValidator(cliCtx context.CLIContext, cdc *codec.Codec, endpoint string
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
params := stake.QueryValidatorParams{
|
params := stake.NewQueryValidatorParams(validatorAddr)
|
||||||
ValidatorAddr: validatorAddr,
|
|
||||||
}
|
|
||||||
|
|
||||||
bz, err := cdc.MarshalJSON(params)
|
bz, err := cdc.MarshalJSON(params)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -37,6 +37,21 @@ func (k Keeper) GetAllDelegations(ctx sdk.Context) (delegations []types.Delegati
|
||||||
return delegations
|
return delegations
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// return all delegations to a specific validator. Useful for querier.
|
||||||
|
func (k Keeper) GetValidatorDelegations(ctx sdk.Context, valAddr sdk.ValAddress) (delegations []types.Delegation) {
|
||||||
|
store := ctx.KVStore(k.storeKey)
|
||||||
|
iterator := sdk.KVStorePrefixIterator(store, DelegationKey)
|
||||||
|
defer iterator.Close()
|
||||||
|
|
||||||
|
for ; iterator.Valid(); iterator.Next() {
|
||||||
|
delegation := types.MustUnmarshalDelegation(k.cdc, iterator.Key(), iterator.Value())
|
||||||
|
if delegation.GetValidatorAddr().Equals(valAddr) {
|
||||||
|
delegations = append(delegations, delegation)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return delegations
|
||||||
|
}
|
||||||
|
|
||||||
// return a given amount of all the delegations from a delegator
|
// return a given amount of all the delegations from a delegator
|
||||||
func (k Keeper) GetDelegatorDelegations(ctx sdk.Context, delegator sdk.AccAddress,
|
func (k Keeper) GetDelegatorDelegations(ctx sdk.Context, delegator sdk.AccAddress,
|
||||||
maxRetrieve uint16) (delegations []types.Delegation) {
|
maxRetrieve uint16) (delegations []types.Delegation) {
|
||||||
|
|
|
@ -105,6 +105,9 @@ func TestDelegation(t *testing.T) {
|
||||||
resVal, err = keeper.GetDelegatorValidator(ctx, addrDels[1], addrVals[i])
|
resVal, err = keeper.GetDelegatorValidator(ctx, addrDels[1], addrVals[i])
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
require.Equal(t, addrVals[i], resVal.GetOperator())
|
require.Equal(t, addrVals[i], resVal.GetOperator())
|
||||||
|
|
||||||
|
resDels := keeper.GetValidatorDelegations(ctx, addrVals[i])
|
||||||
|
require.Len(t, resDels, 2)
|
||||||
}
|
}
|
||||||
|
|
||||||
// delete a record
|
// delete a record
|
||||||
|
@ -139,7 +142,7 @@ func TestUnbondingDelegation(t *testing.T) {
|
||||||
ValidatorAddr: addrVals[0],
|
ValidatorAddr: addrVals[0],
|
||||||
CreationHeight: 0,
|
CreationHeight: 0,
|
||||||
MinTime: time.Unix(0, 0),
|
MinTime: time.Unix(0, 0),
|
||||||
Balance: sdk.NewInt64Coin("steak", 5),
|
Balance: sdk.NewInt64Coin(types.DefaultBondDenom, 5),
|
||||||
}
|
}
|
||||||
|
|
||||||
// set and retrieve a record
|
// set and retrieve a record
|
||||||
|
@ -149,7 +152,7 @@ func TestUnbondingDelegation(t *testing.T) {
|
||||||
require.True(t, ubd.Equal(resUnbond))
|
require.True(t, ubd.Equal(resUnbond))
|
||||||
|
|
||||||
// modify a records, save, and retrieve
|
// modify a records, save, and retrieve
|
||||||
ubd.Balance = sdk.NewInt64Coin("steak", 21)
|
ubd.Balance = sdk.NewInt64Coin(types.DefaultBondDenom, 21)
|
||||||
keeper.SetUnbondingDelegation(ctx, ubd)
|
keeper.SetUnbondingDelegation(ctx, ubd)
|
||||||
|
|
||||||
resUnbonds := keeper.GetUnbondingDelegations(ctx, addrDels[0], 5)
|
resUnbonds := keeper.GetUnbondingDelegations(ctx, addrDels[0], 5)
|
||||||
|
|
|
@ -15,6 +15,7 @@ const (
|
||||||
QueryDelegatorDelegations = "delegatorDelegations"
|
QueryDelegatorDelegations = "delegatorDelegations"
|
||||||
QueryDelegatorUnbondingDelegations = "delegatorUnbondingDelegations"
|
QueryDelegatorUnbondingDelegations = "delegatorUnbondingDelegations"
|
||||||
QueryDelegatorRedelegations = "delegatorRedelegations"
|
QueryDelegatorRedelegations = "delegatorRedelegations"
|
||||||
|
QueryValidatorDelegations = "validatorDelegations"
|
||||||
QueryValidatorUnbondingDelegations = "validatorUnbondingDelegations"
|
QueryValidatorUnbondingDelegations = "validatorUnbondingDelegations"
|
||||||
QueryValidatorRedelegations = "validatorRedelegations"
|
QueryValidatorRedelegations = "validatorRedelegations"
|
||||||
QueryDelegator = "delegator"
|
QueryDelegator = "delegator"
|
||||||
|
@ -34,6 +35,8 @@ func NewQuerier(k keep.Keeper, cdc *codec.Codec) sdk.Querier {
|
||||||
return queryValidators(ctx, cdc, k)
|
return queryValidators(ctx, cdc, k)
|
||||||
case QueryValidator:
|
case QueryValidator:
|
||||||
return queryValidator(ctx, cdc, req, k)
|
return queryValidator(ctx, cdc, req, k)
|
||||||
|
case QueryValidatorDelegations:
|
||||||
|
return queryValidatorDelegations(ctx, cdc, req, k)
|
||||||
case QueryValidatorUnbondingDelegations:
|
case QueryValidatorUnbondingDelegations:
|
||||||
return queryValidatorUnbondingDelegations(ctx, cdc, req, k)
|
return queryValidatorUnbondingDelegations(ctx, cdc, req, k)
|
||||||
case QueryValidatorRedelegations:
|
case QueryValidatorRedelegations:
|
||||||
|
@ -73,6 +76,7 @@ type QueryDelegatorParams struct {
|
||||||
|
|
||||||
// defines the params for the following queries:
|
// defines the params for the following queries:
|
||||||
// - 'custom/stake/validator'
|
// - 'custom/stake/validator'
|
||||||
|
// - 'custom/stake/validatorDelegations'
|
||||||
// - 'custom/stake/validatorUnbondingDelegations'
|
// - 'custom/stake/validatorUnbondingDelegations'
|
||||||
// - 'custom/stake/validatorRedelegations'
|
// - 'custom/stake/validatorRedelegations'
|
||||||
type QueryValidatorParams struct {
|
type QueryValidatorParams struct {
|
||||||
|
@ -88,6 +92,28 @@ type QueryBondsParams struct {
|
||||||
ValidatorAddr sdk.ValAddress
|
ValidatorAddr sdk.ValAddress
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// creates a new QueryDelegatorParams
|
||||||
|
func NewQueryDelegatorParams(delegatorAddr sdk.AccAddress) QueryDelegatorParams {
|
||||||
|
return QueryDelegatorParams{
|
||||||
|
DelegatorAddr: delegatorAddr,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// creates a new QueryValidatorParams
|
||||||
|
func NewQueryValidatorParams(validatorAddr sdk.ValAddress) QueryValidatorParams {
|
||||||
|
return QueryValidatorParams{
|
||||||
|
ValidatorAddr: validatorAddr,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// creates a new QueryBondsParams
|
||||||
|
func NewQueryBondsParams(delegatorAddr sdk.AccAddress, validatorAddr sdk.ValAddress) QueryBondsParams {
|
||||||
|
return QueryBondsParams{
|
||||||
|
DelegatorAddr: delegatorAddr,
|
||||||
|
ValidatorAddr: validatorAddr,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func queryValidators(ctx sdk.Context, cdc *codec.Codec, k keep.Keeper) (res []byte, err sdk.Error) {
|
func queryValidators(ctx sdk.Context, cdc *codec.Codec, k keep.Keeper) (res []byte, err sdk.Error) {
|
||||||
stakeParams := k.GetParams(ctx)
|
stakeParams := k.GetParams(ctx)
|
||||||
validators := k.GetValidators(ctx, stakeParams.MaxValidators)
|
validators := k.GetValidators(ctx, stakeParams.MaxValidators)
|
||||||
|
@ -119,6 +145,23 @@ func queryValidator(ctx sdk.Context, cdc *codec.Codec, req abci.RequestQuery, k
|
||||||
return res, nil
|
return res, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func queryValidatorDelegations(ctx sdk.Context, cdc *codec.Codec, req abci.RequestQuery, k keep.Keeper) (res []byte, err sdk.Error) {
|
||||||
|
var params QueryValidatorParams
|
||||||
|
|
||||||
|
errRes := cdc.UnmarshalJSON(req.Data, ¶ms)
|
||||||
|
if errRes != nil {
|
||||||
|
return []byte{}, sdk.ErrUnknownAddress("")
|
||||||
|
}
|
||||||
|
|
||||||
|
delegations := k.GetValidatorDelegations(ctx, params.ValidatorAddr)
|
||||||
|
|
||||||
|
res, errRes = codec.MarshalJSONIndent(cdc, delegations)
|
||||||
|
if errRes != nil {
|
||||||
|
return nil, sdk.ErrInternal(sdk.AppendMsgToErr("could not marshal result to JSON", errRes.Error()))
|
||||||
|
}
|
||||||
|
return res, nil
|
||||||
|
}
|
||||||
|
|
||||||
func queryValidatorUnbondingDelegations(ctx sdk.Context, cdc *codec.Codec, req abci.RequestQuery, k keep.Keeper) (res []byte, err sdk.Error) {
|
func queryValidatorUnbondingDelegations(ctx sdk.Context, cdc *codec.Codec, req abci.RequestQuery, k keep.Keeper) (res []byte, err sdk.Error) {
|
||||||
var params QueryValidatorParams
|
var params QueryValidatorParams
|
||||||
|
|
||||||
|
|
|
@ -17,25 +17,6 @@ var (
|
||||||
pk1, pk2 = keep.PKs[0], keep.PKs[1]
|
pk1, pk2 = keep.PKs[0], keep.PKs[1]
|
||||||
)
|
)
|
||||||
|
|
||||||
func newTestDelegatorQuery(delegatorAddr sdk.AccAddress) QueryDelegatorParams {
|
|
||||||
return QueryDelegatorParams{
|
|
||||||
DelegatorAddr: delegatorAddr,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func newTestValidatorQuery(validatorAddr sdk.ValAddress) QueryValidatorParams {
|
|
||||||
return QueryValidatorParams{
|
|
||||||
ValidatorAddr: validatorAddr,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func newTestBondQuery(delegatorAddr sdk.AccAddress, validatorAddr sdk.ValAddress) QueryBondsParams {
|
|
||||||
return QueryBondsParams{
|
|
||||||
DelegatorAddr: delegatorAddr,
|
|
||||||
ValidatorAddr: validatorAddr,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestNewQuerier(t *testing.T) {
|
func TestNewQuerier(t *testing.T) {
|
||||||
cdc := codec.New()
|
cdc := codec.New()
|
||||||
ctx, _, keeper := keep.CreateTestInput(t, false, 1000)
|
ctx, _, keeper := keep.CreateTestInput(t, false, 1000)
|
||||||
|
@ -72,7 +53,7 @@ func TestNewQuerier(t *testing.T) {
|
||||||
_, err = querier(ctx, []string{"parameters"}, query)
|
_, err = querier(ctx, []string{"parameters"}, query)
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
|
|
||||||
queryValParams := newTestValidatorQuery(addrVal1)
|
queryValParams := NewQueryValidatorParams(addrVal1)
|
||||||
bz, errRes := cdc.MarshalJSON(queryValParams)
|
bz, errRes := cdc.MarshalJSON(queryValParams)
|
||||||
require.Nil(t, errRes)
|
require.Nil(t, errRes)
|
||||||
|
|
||||||
|
@ -82,13 +63,16 @@ func TestNewQuerier(t *testing.T) {
|
||||||
_, err = querier(ctx, []string{"validator"}, query)
|
_, err = querier(ctx, []string{"validator"}, query)
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
|
|
||||||
|
_, err = querier(ctx, []string{"validatorDelegations"}, query)
|
||||||
|
require.Nil(t, err)
|
||||||
|
|
||||||
_, err = querier(ctx, []string{"validatorUnbondingDelegations"}, query)
|
_, err = querier(ctx, []string{"validatorUnbondingDelegations"}, query)
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
|
|
||||||
_, err = querier(ctx, []string{"validatorRedelegations"}, query)
|
_, err = querier(ctx, []string{"validatorRedelegations"}, query)
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
|
|
||||||
queryDelParams := newTestDelegatorQuery(addrAcc2)
|
queryDelParams := NewQueryDelegatorParams(addrAcc2)
|
||||||
bz, errRes = cdc.MarshalJSON(queryDelParams)
|
bz, errRes = cdc.MarshalJSON(queryDelParams)
|
||||||
require.Nil(t, errRes)
|
require.Nil(t, errRes)
|
||||||
|
|
||||||
|
@ -160,7 +144,7 @@ func TestQueryValidators(t *testing.T) {
|
||||||
require.ElementsMatch(t, queriedValidators, validatorsResp)
|
require.ElementsMatch(t, queriedValidators, validatorsResp)
|
||||||
|
|
||||||
// Query each validator
|
// Query each validator
|
||||||
queryParams := newTestValidatorQuery(addrVal1)
|
queryParams := NewQueryValidatorParams(addrVal1)
|
||||||
bz, errRes := cdc.MarshalJSON(queryParams)
|
bz, errRes := cdc.MarshalJSON(queryParams)
|
||||||
require.Nil(t, errRes)
|
require.Nil(t, errRes)
|
||||||
|
|
||||||
|
@ -189,13 +173,18 @@ func TestQueryDelegation(t *testing.T) {
|
||||||
pool := keeper.GetPool(ctx)
|
pool := keeper.GetPool(ctx)
|
||||||
keeper.SetValidatorByPowerIndex(ctx, val1, pool)
|
keeper.SetValidatorByPowerIndex(ctx, val1, pool)
|
||||||
|
|
||||||
keeper.Delegate(ctx, addrAcc2, sdk.NewCoin("steak", sdk.NewInt(20)), val1, true)
|
val2 := types.NewValidator(addrVal2, pk2, types.Description{})
|
||||||
|
keeper.SetValidator(ctx, val2)
|
||||||
|
pool = keeper.GetPool(ctx)
|
||||||
|
keeper.SetValidatorByPowerIndex(ctx, val2, pool)
|
||||||
|
|
||||||
|
keeper.Delegate(ctx, addrAcc2, sdk.NewCoin(types.DefaultBondDenom, sdk.NewInt(20)), val1, true)
|
||||||
|
|
||||||
// apply TM updates
|
// apply TM updates
|
||||||
keeper.ApplyAndReturnValidatorSetUpdates(ctx)
|
keeper.ApplyAndReturnValidatorSetUpdates(ctx)
|
||||||
|
|
||||||
// Query Delegator bonded validators
|
// Query Delegator bonded validators
|
||||||
queryParams := newTestDelegatorQuery(addrAcc2)
|
queryParams := NewQueryDelegatorParams(addrAcc2)
|
||||||
bz, errRes := cdc.MarshalJSON(queryParams)
|
bz, errRes := cdc.MarshalJSON(queryParams)
|
||||||
require.Nil(t, errRes)
|
require.Nil(t, errRes)
|
||||||
|
|
||||||
|
@ -223,7 +212,7 @@ func TestQueryDelegation(t *testing.T) {
|
||||||
require.NotNil(t, err)
|
require.NotNil(t, err)
|
||||||
|
|
||||||
// Query bonded validator
|
// Query bonded validator
|
||||||
queryBondParams := newTestBondQuery(addrAcc2, addrVal1)
|
queryBondParams := NewQueryBondsParams(addrAcc2, addrVal1)
|
||||||
bz, errRes = cdc.MarshalJSON(queryBondParams)
|
bz, errRes = cdc.MarshalJSON(queryBondParams)
|
||||||
require.Nil(t, errRes)
|
require.Nil(t, errRes)
|
||||||
|
|
||||||
|
@ -288,9 +277,32 @@ func TestQueryDelegation(t *testing.T) {
|
||||||
_, err = queryDelegation(ctx, cdc, query, keeper)
|
_, err = queryDelegation(ctx, cdc, query, keeper)
|
||||||
require.NotNil(t, err)
|
require.NotNil(t, err)
|
||||||
|
|
||||||
|
// Query validator delegations
|
||||||
|
|
||||||
|
bz, errRes = cdc.MarshalJSON(NewQueryValidatorParams(addrVal1))
|
||||||
|
require.Nil(t, errRes)
|
||||||
|
|
||||||
|
query = abci.RequestQuery{
|
||||||
|
Path: "custom/stake/validatorDelegations",
|
||||||
|
Data: bz,
|
||||||
|
}
|
||||||
|
|
||||||
|
res, err = queryValidatorDelegations(ctx, cdc, query, keeper)
|
||||||
|
require.Nil(t, err)
|
||||||
|
|
||||||
|
var delegationsRes []types.Delegation
|
||||||
|
errRes = cdc.UnmarshalJSON(res, &delegationsRes)
|
||||||
|
require.Nil(t, errRes)
|
||||||
|
|
||||||
|
require.Equal(t, delegationsRes[0], delegation)
|
||||||
|
|
||||||
// Query unbonging delegation
|
// Query unbonging delegation
|
||||||
keeper.BeginUnbonding(ctx, addrAcc2, val1.OperatorAddr, sdk.NewDec(10))
|
keeper.BeginUnbonding(ctx, addrAcc2, val1.OperatorAddr, sdk.NewDec(10))
|
||||||
|
|
||||||
|
queryBondParams = NewQueryBondsParams(addrAcc2, addrVal1)
|
||||||
|
bz, errRes = cdc.MarshalJSON(queryBondParams)
|
||||||
|
require.Nil(t, errRes)
|
||||||
|
|
||||||
query = abci.RequestQuery{
|
query = abci.RequestQuery{
|
||||||
Path: "/custom/stake/unbondingDelegation",
|
Path: "/custom/stake/unbondingDelegation",
|
||||||
Data: bz,
|
Data: bz,
|
||||||
|
@ -346,7 +358,7 @@ func TestQueryRedelegations(t *testing.T) {
|
||||||
keeper.SetValidator(ctx, val1)
|
keeper.SetValidator(ctx, val1)
|
||||||
keeper.SetValidator(ctx, val2)
|
keeper.SetValidator(ctx, val2)
|
||||||
|
|
||||||
keeper.Delegate(ctx, addrAcc2, sdk.NewCoin("steak", sdk.NewInt(100)), val1, true)
|
keeper.Delegate(ctx, addrAcc2, sdk.NewCoin(types.DefaultBondDenom, sdk.NewInt(100)), val1, true)
|
||||||
keeper.ApplyAndReturnValidatorSetUpdates(ctx)
|
keeper.ApplyAndReturnValidatorSetUpdates(ctx)
|
||||||
|
|
||||||
keeper.BeginRedelegation(ctx, addrAcc2, val1.GetOperator(), val2.GetOperator(), sdk.NewDec(20))
|
keeper.BeginRedelegation(ctx, addrAcc2, val1.GetOperator(), val2.GetOperator(), sdk.NewDec(20))
|
||||||
|
@ -356,7 +368,7 @@ func TestQueryRedelegations(t *testing.T) {
|
||||||
require.True(t, found)
|
require.True(t, found)
|
||||||
|
|
||||||
// delegator redelegations
|
// delegator redelegations
|
||||||
queryDelegatorParams := newTestDelegatorQuery(addrAcc2)
|
queryDelegatorParams := NewQueryDelegatorParams(addrAcc2)
|
||||||
bz, errRes := cdc.MarshalJSON(queryDelegatorParams)
|
bz, errRes := cdc.MarshalJSON(queryDelegatorParams)
|
||||||
require.Nil(t, errRes)
|
require.Nil(t, errRes)
|
||||||
|
|
||||||
|
@ -375,7 +387,7 @@ func TestQueryRedelegations(t *testing.T) {
|
||||||
require.Equal(t, redelegation, redsRes[0])
|
require.Equal(t, redelegation, redsRes[0])
|
||||||
|
|
||||||
// validator redelegations
|
// validator redelegations
|
||||||
queryValidatorParams := newTestValidatorQuery(val1.GetOperator())
|
queryValidatorParams := NewQueryValidatorParams(val1.GetOperator())
|
||||||
bz, errRes = cdc.MarshalJSON(queryValidatorParams)
|
bz, errRes = cdc.MarshalJSON(queryValidatorParams)
|
||||||
require.Nil(t, errRes)
|
require.Nil(t, errRes)
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,7 @@ import (
|
||||||
"github.com/cosmos/cosmos-sdk/x/mock/simulation"
|
"github.com/cosmos/cosmos-sdk/x/mock/simulation"
|
||||||
"github.com/cosmos/cosmos-sdk/x/stake"
|
"github.com/cosmos/cosmos-sdk/x/stake"
|
||||||
"github.com/cosmos/cosmos-sdk/x/stake/keeper"
|
"github.com/cosmos/cosmos-sdk/x/stake/keeper"
|
||||||
|
stakeTypes "github.com/cosmos/cosmos-sdk/x/stake/types"
|
||||||
abci "github.com/tendermint/tendermint/abci/types"
|
abci "github.com/tendermint/tendermint/abci/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -48,7 +49,7 @@ func SupplyInvariants(ck bank.Keeper, k stake.Keeper,
|
||||||
loose := sdk.ZeroDec()
|
loose := sdk.ZeroDec()
|
||||||
bonded := sdk.ZeroDec()
|
bonded := sdk.ZeroDec()
|
||||||
am.IterateAccounts(ctx, func(acc auth.Account) bool {
|
am.IterateAccounts(ctx, func(acc auth.Account) bool {
|
||||||
loose = loose.Add(sdk.NewDecFromInt(acc.GetCoins().AmountOf("steak")))
|
loose = loose.Add(sdk.NewDecFromInt(acc.GetCoins().AmountOf(stakeTypes.DefaultBondDenom)))
|
||||||
return false
|
return false
|
||||||
})
|
})
|
||||||
k.IterateUnbondingDelegations(ctx, func(_ int64, ubd stake.UnbondingDelegation) bool {
|
k.IterateUnbondingDelegations(ctx, func(_ int64, ubd stake.UnbondingDelegation) bool {
|
||||||
|
@ -70,19 +71,19 @@ func SupplyInvariants(ck bank.Keeper, k stake.Keeper,
|
||||||
feePool := d.GetFeePool(ctx)
|
feePool := d.GetFeePool(ctx)
|
||||||
|
|
||||||
// add outstanding fees
|
// add outstanding fees
|
||||||
loose = loose.Add(sdk.NewDecFromInt(f.GetCollectedFees(ctx).AmountOf("steak")))
|
loose = loose.Add(sdk.NewDecFromInt(f.GetCollectedFees(ctx).AmountOf(stakeTypes.DefaultBondDenom)))
|
||||||
|
|
||||||
// add community pool
|
// add community pool
|
||||||
loose = loose.Add(feePool.CommunityPool.AmountOf("steak"))
|
loose = loose.Add(feePool.CommunityPool.AmountOf(stakeTypes.DefaultBondDenom))
|
||||||
|
|
||||||
// add validator distribution pool
|
// add validator distribution pool
|
||||||
loose = loose.Add(feePool.ValPool.AmountOf("steak"))
|
loose = loose.Add(feePool.ValPool.AmountOf(stakeTypes.DefaultBondDenom))
|
||||||
|
|
||||||
// add validator distribution commission and yet-to-be-withdrawn-by-delegators
|
// add validator distribution commission and yet-to-be-withdrawn-by-delegators
|
||||||
d.IterateValidatorDistInfos(ctx,
|
d.IterateValidatorDistInfos(ctx,
|
||||||
func(_ int64, distInfo distribution.ValidatorDistInfo) (stop bool) {
|
func(_ int64, distInfo distribution.ValidatorDistInfo) (stop bool) {
|
||||||
loose = loose.Add(distInfo.DelPool.AmountOf("steak"))
|
loose = loose.Add(distInfo.DelPool.AmountOf(stakeTypes.DefaultBondDenom))
|
||||||
loose = loose.Add(distInfo.ValCommission.AmountOf("steak"))
|
loose = loose.Add(distInfo.ValCommission.AmountOf(stakeTypes.DefaultBondDenom))
|
||||||
return false
|
return false
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
|
@ -26,11 +26,11 @@ func SimulateMsgCreateValidator(m auth.AccountKeeper, k stake.Keeper) simulation
|
||||||
Moniker: simulation.RandStringOfLength(r, 10),
|
Moniker: simulation.RandStringOfLength(r, 10),
|
||||||
}
|
}
|
||||||
|
|
||||||
maxCommission := sdk.NewInt(10)
|
maxCommission := sdk.NewDecWithPrec(r.Int63n(1000), 3)
|
||||||
commission := stake.NewCommissionMsg(
|
commission := stake.NewCommissionMsg(
|
||||||
sdk.NewDecWithPrec(simulation.RandomAmount(r, maxCommission).Int64(), 1),
|
simulation.RandomDecAmount(r, maxCommission),
|
||||||
sdk.NewDecWithPrec(simulation.RandomAmount(r, maxCommission).Int64(), 1),
|
maxCommission,
|
||||||
sdk.NewDecWithPrec(simulation.RandomAmount(r, maxCommission).Int64(), 1),
|
simulation.RandomDecAmount(r, maxCommission),
|
||||||
)
|
)
|
||||||
|
|
||||||
acc := simulation.RandomAcc(r, accs)
|
acc := simulation.RandomAcc(r, accs)
|
||||||
|
@ -85,11 +85,10 @@ func SimulateMsgEditValidator(k stake.Keeper) simulation.Operation {
|
||||||
Details: simulation.RandStringOfLength(r, 10),
|
Details: simulation.RandStringOfLength(r, 10),
|
||||||
}
|
}
|
||||||
|
|
||||||
maxCommission := sdk.NewInt(10)
|
|
||||||
newCommissionRate := sdk.NewDecWithPrec(simulation.RandomAmount(r, maxCommission).Int64(), 1)
|
|
||||||
|
|
||||||
val := keeper.RandomValidator(r, k, ctx)
|
val := keeper.RandomValidator(r, k, ctx)
|
||||||
address := val.GetOperator()
|
address := val.GetOperator()
|
||||||
|
newCommissionRate := simulation.RandomDecAmount(r, val.Commission.MaxRate)
|
||||||
|
|
||||||
msg := stake.MsgEditValidator{
|
msg := stake.MsgEditValidator{
|
||||||
Description: description,
|
Description: description,
|
||||||
ValidatorAddr: address,
|
ValidatorAddr: address,
|
||||||
|
|
|
@ -85,6 +85,9 @@ var (
|
||||||
NewMsgBeginRedelegate = types.NewMsgBeginRedelegate
|
NewMsgBeginRedelegate = types.NewMsgBeginRedelegate
|
||||||
|
|
||||||
NewQuerier = querier.NewQuerier
|
NewQuerier = querier.NewQuerier
|
||||||
|
NewQueryDelegatorParams = querier.NewQueryDelegatorParams
|
||||||
|
NewQueryValidatorParams = querier.NewQueryValidatorParams
|
||||||
|
NewQueryBondsParams = querier.NewQueryBondsParams
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|
|
@ -28,7 +28,7 @@ var (
|
||||||
|
|
||||||
func NewTestMsgCreateValidator(address sdk.ValAddress, pubKey crypto.PubKey, amt int64) MsgCreateValidator {
|
func NewTestMsgCreateValidator(address sdk.ValAddress, pubKey crypto.PubKey, amt int64) MsgCreateValidator {
|
||||||
return types.NewMsgCreateValidator(
|
return types.NewMsgCreateValidator(
|
||||||
address, pubKey, sdk.NewCoin("steak", sdk.NewInt(amt)), Description{}, commissionMsg,
|
address, pubKey, sdk.NewCoin(types.DefaultBondDenom, sdk.NewInt(amt)), Description{}, commissionMsg,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,7 +38,7 @@ func NewTestMsgCreateValidatorWithCommission(address sdk.ValAddress, pubKey cryp
|
||||||
commission := NewCommissionMsg(commissionRate, sdk.OneDec(), sdk.ZeroDec())
|
commission := NewCommissionMsg(commissionRate, sdk.OneDec(), sdk.ZeroDec())
|
||||||
|
|
||||||
return types.NewMsgCreateValidator(
|
return types.NewMsgCreateValidator(
|
||||||
address, pubKey, sdk.NewCoin("steak", sdk.NewInt(amt)), Description{}, commission,
|
address, pubKey, sdk.NewCoin(types.DefaultBondDenom, sdk.NewInt(amt)), Description{}, commission,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,7 +46,7 @@ func NewTestMsgDelegate(delAddr sdk.AccAddress, valAddr sdk.ValAddress, amt int6
|
||||||
return MsgDelegate{
|
return MsgDelegate{
|
||||||
DelegatorAddr: delAddr,
|
DelegatorAddr: delAddr,
|
||||||
ValidatorAddr: valAddr,
|
ValidatorAddr: valAddr,
|
||||||
Delegation: sdk.NewCoin("steak", sdk.NewInt(amt)),
|
Delegation: sdk.NewCoin(types.DefaultBondDenom, sdk.NewInt(amt)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,6 +57,6 @@ func NewTestMsgCreateValidatorOnBehalfOf(delAddr sdk.AccAddress, valAddr sdk.Val
|
||||||
DelegatorAddr: delAddr,
|
DelegatorAddr: delAddr,
|
||||||
ValidatorAddr: valAddr,
|
ValidatorAddr: valAddr,
|
||||||
PubKey: valPubKey,
|
PubKey: valPubKey,
|
||||||
Delegation: sdk.NewCoin("steak", sdk.NewInt(amt)),
|
Delegation: sdk.NewCoin(types.DefaultBondDenom, sdk.NewInt(amt)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,7 @@ type (
|
||||||
// Commission defines a commission parameters for a given validator.
|
// Commission defines a commission parameters for a given validator.
|
||||||
Commission struct {
|
Commission struct {
|
||||||
Rate sdk.Dec `json:"rate"` // the commission rate charged to delegators
|
Rate sdk.Dec `json:"rate"` // the commission rate charged to delegators
|
||||||
MaxRate sdk.Dec `json:"max_rate"` // maximum commission rate which validator can ever charge
|
MaxRate sdk.Dec `json:"max_rate"` // maximum commission rate which this validator can ever charge
|
||||||
MaxChangeRate sdk.Dec `json:"max_change_rate"` // maximum daily increase of the validator commission
|
MaxChangeRate sdk.Dec `json:"max_change_rate"` // maximum daily increase of the validator commission
|
||||||
UpdateTime time.Time `json:"update_time"` // the last time the commission rate was changed
|
UpdateTime time.Time `json:"update_time"` // the last time the commission rate was changed
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,9 +10,9 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
coinPos = sdk.NewInt64Coin("steak", 1000)
|
coinPos = sdk.NewInt64Coin(DefaultBondDenom, 1000)
|
||||||
coinZero = sdk.NewInt64Coin("steak", 0)
|
coinZero = sdk.NewInt64Coin(DefaultBondDenom, 0)
|
||||||
coinNeg = sdk.NewInt64Coin("steak", -10000)
|
coinNeg = sdk.NewInt64Coin(DefaultBondDenom, -10000)
|
||||||
)
|
)
|
||||||
|
|
||||||
// test ValidateBasic for MsgCreateValidator
|
// test ValidateBasic for MsgCreateValidator
|
||||||
|
|
|
@ -19,6 +19,9 @@ const (
|
||||||
// if this is 1, the validator set at the end of a block will sign the block after the next.
|
// if this is 1, the validator set at the end of a block will sign the block after the next.
|
||||||
// Constant as this should not change without a hard fork.
|
// Constant as this should not change without a hard fork.
|
||||||
ValidatorUpdateDelay int64 = 1
|
ValidatorUpdateDelay int64 = 1
|
||||||
|
|
||||||
|
// Default bondable coin denomination
|
||||||
|
DefaultBondDenom = "STAKE"
|
||||||
)
|
)
|
||||||
|
|
||||||
// nolint - Keys for parameter access
|
// nolint - Keys for parameter access
|
||||||
|
@ -59,7 +62,7 @@ func DefaultParams() Params {
|
||||||
return Params{
|
return Params{
|
||||||
UnbondingTime: defaultUnbondingTime,
|
UnbondingTime: defaultUnbondingTime,
|
||||||
MaxValidators: 100,
|
MaxValidators: 100,
|
||||||
BondDenom: "steak",
|
BondDenom: DefaultBondDenom,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -69,7 +72,7 @@ func (p Params) HumanReadableString() string {
|
||||||
|
|
||||||
resp := "Params \n"
|
resp := "Params \n"
|
||||||
resp += fmt.Sprintf("Unbonding Time: %s\n", p.UnbondingTime)
|
resp += fmt.Sprintf("Unbonding Time: %s\n", p.UnbondingTime)
|
||||||
resp += fmt.Sprintf("Max Validators: %d: \n", p.MaxValidators)
|
resp += fmt.Sprintf("Max Validators: %d\n", p.MaxValidators)
|
||||||
resp += fmt.Sprintf("Bonded Coin Denomination: %s\n", p.BondDenom)
|
resp += fmt.Sprintf("Bonded Coin Denomination: %s\n", p.BondDenom)
|
||||||
return resp
|
return resp
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue