CLI/Tests: Remove Fixtures (#6799)
* remove fixtures * setup tests * update x/mint * cli: update x/staking commands * tests: convert x/staking CLI tests * tests: fix x/auth CLI tests * cli updates * fix buiild * fix build * Update x/gov/client/cli/cli_test.go Co-authored-by: Amaury Martiny <amaury.martiny@protonmail.com> * remove GenerateOrBroadcastTx * move TestCLIQueryConn Co-authored-by: Federico Kunze <31522760+fedekunze@users.noreply.github.com> Co-authored-by: Amaury Martiny <amaury.martiny@protonmail.com>
This commit is contained in:
parent
6e7ce48b31
commit
0ccc48d2a3
|
@ -188,24 +188,3 @@ jobs:
|
||||||
with:
|
with:
|
||||||
file: ./coverage.txt
|
file: ./coverage.txt
|
||||||
if: "env.GIT_DIFF != ''"
|
if: "env.GIT_DIFF != ''"
|
||||||
|
|
||||||
integration-tests:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
timeout-minutes: 10
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v2
|
|
||||||
- uses: technote-space/get-diff-action@v1
|
|
||||||
id: git_diff
|
|
||||||
with:
|
|
||||||
SUFFIX_FILTER: |
|
|
||||||
.go
|
|
||||||
.mod
|
|
||||||
.sum
|
|
||||||
- name: build-simd
|
|
||||||
run: |
|
|
||||||
make build-simd
|
|
||||||
if: "env.GIT_DIFF != ''"
|
|
||||||
- name: cli-test
|
|
||||||
run: |
|
|
||||||
make test-integration
|
|
||||||
if: "env.GIT_DIFF != ''"
|
|
||||||
|
|
6
Makefile
6
Makefile
|
@ -188,9 +188,6 @@ test-unit:
|
||||||
test-race:
|
test-race:
|
||||||
@VERSION=$(VERSION) go test -mod=readonly -race $(PACKAGES_NOSIMULATION)
|
@VERSION=$(VERSION) go test -mod=readonly -race $(PACKAGES_NOSIMULATION)
|
||||||
|
|
||||||
test-integration: build-simd
|
|
||||||
BUILDDIR=$(BUILDDIR) go test -mod=readonly -p 4 -tags='ledger test_ledger_mock cli_test' -run ^TestCLI `go list ./.../cli/...`
|
|
||||||
|
|
||||||
.PHONY: test test-all test-ledger-mock test-ledger test-unit test-race
|
.PHONY: test test-all test-ledger-mock test-ledger test-unit test-race
|
||||||
|
|
||||||
test-sim-nondeterminism:
|
test-sim-nondeterminism:
|
||||||
|
@ -239,8 +236,7 @@ test-sim-after-import \
|
||||||
test-sim-custom-genesis-multi-seed \
|
test-sim-custom-genesis-multi-seed \
|
||||||
test-sim-multi-seed-short \
|
test-sim-multi-seed-short \
|
||||||
test-sim-multi-seed-long \
|
test-sim-multi-seed-long \
|
||||||
test-sim-benchmark-invariants \
|
test-sim-benchmark-invariants
|
||||||
test-integration
|
|
||||||
|
|
||||||
SIM_NUM_BLOCKS ?= 500
|
SIM_NUM_BLOCKS ?= 500
|
||||||
SIM_BLOCK_SIZE ?= 200
|
SIM_BLOCK_SIZE ?= 200
|
||||||
|
|
|
@ -2,20 +2,20 @@ package client_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"context"
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/cosmos/cosmos-sdk/codec"
|
|
||||||
"github.com/cosmos/cosmos-sdk/codec/types"
|
|
||||||
"github.com/cosmos/cosmos-sdk/testutil/testdata"
|
|
||||||
|
|
||||||
"github.com/cosmos/cosmos-sdk/crypto/keyring"
|
|
||||||
|
|
||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
"github.com/cosmos/cosmos-sdk/client"
|
"github.com/cosmos/cosmos-sdk/client"
|
||||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||||
|
"github.com/cosmos/cosmos-sdk/codec"
|
||||||
|
"github.com/cosmos/cosmos-sdk/codec/types"
|
||||||
|
"github.com/cosmos/cosmos-sdk/crypto/keyring"
|
||||||
|
"github.com/cosmos/cosmos-sdk/testutil/network"
|
||||||
|
"github.com/cosmos/cosmos-sdk/testutil/testdata"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestMain(m *testing.M) {
|
func TestMain(m *testing.M) {
|
||||||
|
@ -100,3 +100,16 @@ value:
|
||||||
x: "10"
|
x: "10"
|
||||||
`, string(buf.Bytes()))
|
`, string(buf.Bytes()))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestCLIQueryConn(t *testing.T) {
|
||||||
|
cfg := network.DefaultConfig()
|
||||||
|
cfg.NumValidators = 1
|
||||||
|
|
||||||
|
n := network.New(t, cfg)
|
||||||
|
defer n.Cleanup()
|
||||||
|
|
||||||
|
testClient := testdata.NewTestServiceClient(n.Validators[0].ClientCtx)
|
||||||
|
res, err := testClient.Echo(context.Background(), &testdata.EchoRequest{Message: "hello"})
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Equal(t, "hello", res.Message)
|
||||||
|
}
|
||||||
|
|
|
@ -1,10 +1,7 @@
|
||||||
package tx
|
package tx
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io"
|
|
||||||
|
|
||||||
"github.com/spf13/pflag"
|
"github.com/spf13/pflag"
|
||||||
"github.com/spf13/viper"
|
|
||||||
|
|
||||||
"github.com/cosmos/cosmos-sdk/client"
|
"github.com/cosmos/cosmos-sdk/client"
|
||||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||||
|
@ -78,47 +75,6 @@ func NewFactoryCLI(clientCtx client.Context, flagSet *pflag.FlagSet) Factory {
|
||||||
return f
|
return f
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Remove in favor of NewFactoryCLI
|
|
||||||
func NewFactoryFromDeprecated(input io.Reader) Factory {
|
|
||||||
kb, err := keyring.New(
|
|
||||||
sdk.KeyringServiceName(),
|
|
||||||
viper.GetString(flags.FlagKeyringBackend),
|
|
||||||
viper.GetString(flags.FlagHome),
|
|
||||||
input,
|
|
||||||
)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
signModeStr := viper.GetString(flags.FlagSignMode)
|
|
||||||
signMode := signing.SignMode_SIGN_MODE_UNSPECIFIED
|
|
||||||
switch signModeStr {
|
|
||||||
case signModeDirect:
|
|
||||||
signMode = signing.SignMode_SIGN_MODE_DIRECT
|
|
||||||
case signModeAminoJSON:
|
|
||||||
signMode = signing.SignMode_SIGN_MODE_LEGACY_AMINO_JSON
|
|
||||||
}
|
|
||||||
|
|
||||||
gasSetting, _ := flags.ParseGasSetting(viper.GetString(flags.FlagGas))
|
|
||||||
|
|
||||||
f := Factory{
|
|
||||||
keybase: kb,
|
|
||||||
chainID: viper.GetString(flags.FlagChainID),
|
|
||||||
accountNumber: viper.GetUint64(flags.FlagAccountNumber),
|
|
||||||
sequence: viper.GetUint64(flags.FlagSequence),
|
|
||||||
gas: gasSetting.Gas,
|
|
||||||
simulateAndExecute: gasSetting.Simulate,
|
|
||||||
gasAdjustment: viper.GetFloat64(flags.FlagGasAdjustment),
|
|
||||||
memo: viper.GetString(flags.FlagMemo),
|
|
||||||
signMode: signMode,
|
|
||||||
}
|
|
||||||
|
|
||||||
f = f.WithFees(viper.GetString(flags.FlagFees))
|
|
||||||
f = f.WithGasPrices(viper.GetString(flags.FlagGasPrices))
|
|
||||||
|
|
||||||
return f
|
|
||||||
}
|
|
||||||
|
|
||||||
func (f Factory) AccountNumber() uint64 { return f.accountNumber }
|
func (f Factory) AccountNumber() uint64 { return f.accountNumber }
|
||||||
func (f Factory) Sequence() uint64 { return f.sequence }
|
func (f Factory) Sequence() uint64 { return f.sequence }
|
||||||
func (f Factory) Gas() uint64 { return f.gas }
|
func (f Factory) Gas() uint64 { return f.gas }
|
||||||
|
|
|
@ -29,15 +29,6 @@ func GenerateOrBroadcastTxCLI(clientCtx client.Context, flagSet *pflag.FlagSet,
|
||||||
return GenerateOrBroadcastTxWithFactory(clientCtx, txf, msgs...)
|
return GenerateOrBroadcastTxWithFactory(clientCtx, txf, msgs...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GenerateOrBroadcastTx will either generate and print and unsigned transaction
|
|
||||||
// or sign it and broadcast it returning an error upon failure.
|
|
||||||
//
|
|
||||||
// TODO: Remove in favor of GenerateOrBroadcastTxCLI
|
|
||||||
func GenerateOrBroadcastTx(clientCtx client.Context, msgs ...sdk.Msg) error {
|
|
||||||
txf := NewFactoryFromDeprecated(clientCtx.Input).WithTxConfig(clientCtx.TxConfig).WithAccountRetriever(clientCtx.AccountRetriever)
|
|
||||||
return GenerateOrBroadcastTxWithFactory(clientCtx, txf, msgs...)
|
|
||||||
}
|
|
||||||
|
|
||||||
// GenerateOrBroadcastTxWithFactory will either generate and print and unsigned transaction
|
// GenerateOrBroadcastTxWithFactory will either generate and print and unsigned transaction
|
||||||
// or sign it and broadcast it returning an error upon failure.
|
// or sign it and broadcast it returning an error upon failure.
|
||||||
func GenerateOrBroadcastTxWithFactory(clientCtx client.Context, txf Factory, msgs ...sdk.Msg) error {
|
func GenerateOrBroadcastTxWithFactory(clientCtx client.Context, txf Factory, msgs ...sdk.Msg) error {
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
PKGS=$(go list ./... | grep -v '/simapp' | grep -v '/cli_test')
|
PKGS=$(go list ./... | grep -v '/simapp')
|
||||||
|
|
||||||
set -e
|
set -e
|
||||||
echo "mode: atomic" > coverage.txt
|
echo "mode: atomic" > coverage.txt
|
||||||
|
|
|
@ -1,13 +0,0 @@
|
||||||
package cli
|
|
||||||
|
|
||||||
const (
|
|
||||||
Denom = "stake"
|
|
||||||
KeyFoo = "foo"
|
|
||||||
KeyBar = "bar"
|
|
||||||
FooDenom = "footoken"
|
|
||||||
FeeDenom = "feetoken"
|
|
||||||
Fee2Denom = "fee2token"
|
|
||||||
KeyBaz = "baz"
|
|
||||||
KeyVesting = "vesting"
|
|
||||||
KeyFooBarBaz = "foobarbaz"
|
|
||||||
)
|
|
|
@ -1,3 +0,0 @@
|
||||||
package cli
|
|
||||||
|
|
||||||
// package tests runs integration tests which make use of CLI commands.
|
|
|
@ -1,49 +0,0 @@
|
||||||
package cli
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"testing"
|
|
||||||
|
|
||||||
"github.com/stretchr/testify/require"
|
|
||||||
|
|
||||||
"github.com/cosmos/cosmos-sdk/tests"
|
|
||||||
)
|
|
||||||
|
|
||||||
func ExecuteWriteCheckErr(t *testing.T, cmdStr string, writes ...string) {
|
|
||||||
require.True(t, ExecuteWrite(t, cmdStr, writes...))
|
|
||||||
}
|
|
||||||
|
|
||||||
func ExecuteWrite(t *testing.T, cmdStr string, writes ...string) (exitSuccess bool) {
|
|
||||||
exitSuccess, _, _ = ExecuteWriteRetStdStreams(t, cmdStr, writes...)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func ExecuteWriteRetStdStreams(t *testing.T, cmdStr string, writes ...string) (bool, string, string) {
|
|
||||||
proc := tests.GoExecuteT(t, cmdStr)
|
|
||||||
|
|
||||||
// Enables use of interactive commands
|
|
||||||
for _, write := range writes {
|
|
||||||
_, err := proc.StdinPipe.Write([]byte(write + "\n"))
|
|
||||||
require.NoError(t, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Read both stdout and stderr from the process
|
|
||||||
stdout, stderr, err := proc.ReadAll()
|
|
||||||
if err != nil {
|
|
||||||
fmt.Println("Err on proc.ReadAll()", err, cmdStr)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Log output.
|
|
||||||
if len(stdout) > 0 {
|
|
||||||
t.Log("Stdout:", string(stdout))
|
|
||||||
}
|
|
||||||
if len(stderr) > 0 {
|
|
||||||
t.Log("Stderr:", string(stderr))
|
|
||||||
}
|
|
||||||
|
|
||||||
// Wait for process to exit
|
|
||||||
proc.Wait()
|
|
||||||
|
|
||||||
// Return succes, stdout, stderr
|
|
||||||
return proc.ExitState.Success(), string(stdout), string(stderr)
|
|
||||||
}
|
|
|
@ -1,81 +0,0 @@
|
||||||
package cli
|
|
||||||
|
|
||||||
import (
|
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
|
||||||
"path/filepath"
|
|
||||||
"testing"
|
|
||||||
|
|
||||||
"github.com/stretchr/testify/require"
|
|
||||||
|
|
||||||
tmtypes "github.com/tendermint/tendermint/types"
|
|
||||||
|
|
||||||
"github.com/cosmos/cosmos-sdk/codec"
|
|
||||||
"github.com/cosmos/cosmos-sdk/server"
|
|
||||||
"github.com/cosmos/cosmos-sdk/simapp"
|
|
||||||
"github.com/cosmos/cosmos-sdk/simapp/params"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Fixtures is used to setup the testing environment
|
|
||||||
type Fixtures struct {
|
|
||||||
BuildDir string
|
|
||||||
RootDir string
|
|
||||||
SimdBinary string
|
|
||||||
ChainID string
|
|
||||||
RPCAddr string
|
|
||||||
Port string
|
|
||||||
SimdHome string
|
|
||||||
SimcliHome string
|
|
||||||
P2PAddr string
|
|
||||||
Cdc *codec.Codec
|
|
||||||
EncodingConfig params.EncodingConfig
|
|
||||||
T *testing.T
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewFixtures creates a new instance of Fixtures with many vars set
|
|
||||||
func NewFixtures(t *testing.T) *Fixtures {
|
|
||||||
tmpDir, err := ioutil.TempDir("", "sdk_integration_"+t.Name()+"_")
|
|
||||||
require.NoError(t, err)
|
|
||||||
|
|
||||||
servAddr, port, err := server.FreeTCPAddr()
|
|
||||||
require.NoError(t, err)
|
|
||||||
|
|
||||||
p2pAddr, _, err := server.FreeTCPAddr()
|
|
||||||
require.NoError(t, err)
|
|
||||||
|
|
||||||
buildDir := os.Getenv("BUILDDIR")
|
|
||||||
if buildDir == "" {
|
|
||||||
t.Skip("builddir is empty, skipping")
|
|
||||||
}
|
|
||||||
|
|
||||||
encodingConfig := simapp.MakeEncodingConfig()
|
|
||||||
|
|
||||||
return &Fixtures{
|
|
||||||
T: t,
|
|
||||||
BuildDir: buildDir,
|
|
||||||
RootDir: tmpDir,
|
|
||||||
SimdBinary: filepath.Join(buildDir, "simd"),
|
|
||||||
SimdHome: filepath.Join(tmpDir, ".simd"),
|
|
||||||
SimcliHome: filepath.Join(tmpDir, ".simcli"),
|
|
||||||
RPCAddr: servAddr,
|
|
||||||
P2PAddr: p2pAddr,
|
|
||||||
Cdc: encodingConfig.Amino,
|
|
||||||
EncodingConfig: encodingConfig,
|
|
||||||
Port: port,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// GenesisFile returns the path of the genesis file
|
|
||||||
func (f Fixtures) GenesisFile() string {
|
|
||||||
return filepath.Join(f.SimdHome, "config", "genesis.json")
|
|
||||||
}
|
|
||||||
|
|
||||||
// GenesisFile returns the application's genesis state
|
|
||||||
func (f Fixtures) GenesisState() simapp.GenesisState {
|
|
||||||
genDoc, err := tmtypes.GenesisDocFromFile(f.GenesisFile())
|
|
||||||
require.NoError(f.T, err)
|
|
||||||
|
|
||||||
var appState simapp.GenesisState
|
|
||||||
require.NoError(f.T, f.Cdc.UnmarshalJSON(genDoc.AppState, &appState))
|
|
||||||
return appState
|
|
||||||
}
|
|
|
@ -1,24 +0,0 @@
|
||||||
package cli
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"testing"
|
|
||||||
|
|
||||||
"github.com/stretchr/testify/require"
|
|
||||||
|
|
||||||
"github.com/cosmos/cosmos-sdk/testutil/network"
|
|
||||||
"github.com/cosmos/cosmos-sdk/testutil/testdata"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestCLIQueryConn(t *testing.T) {
|
|
||||||
cfg := network.DefaultConfig()
|
|
||||||
cfg.NumValidators = 1
|
|
||||||
|
|
||||||
n := network.New(t, cfg)
|
|
||||||
defer n.Cleanup()
|
|
||||||
|
|
||||||
testClient := testdata.NewTestServiceClient(n.Validators[0].ClientCtx)
|
|
||||||
res, err := testClient.Echo(context.Background(), &testdata.EchoRequest{Message: "hello"})
|
|
||||||
require.NoError(t, err)
|
|
||||||
require.Equal(t, "hello", res.Message)
|
|
||||||
}
|
|
|
@ -1,198 +0,0 @@
|
||||||
package cli
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
"path/filepath"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/stretchr/testify/require"
|
|
||||||
|
|
||||||
clientkeys "github.com/cosmos/cosmos-sdk/client/keys"
|
|
||||||
"github.com/cosmos/cosmos-sdk/codec"
|
|
||||||
"github.com/cosmos/cosmos-sdk/crypto/keyring"
|
|
||||||
"github.com/cosmos/cosmos-sdk/tests"
|
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
||||||
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
TotalCoins = sdk.NewCoins(
|
|
||||||
sdk.NewCoin(Fee2Denom, sdk.TokensFromConsensusPower(2000000)),
|
|
||||||
sdk.NewCoin(FeeDenom, sdk.TokensFromConsensusPower(2000000)),
|
|
||||||
sdk.NewCoin(FooDenom, sdk.TokensFromConsensusPower(2000)),
|
|
||||||
sdk.NewCoin(Denom, sdk.TokensFromConsensusPower(300).Add(sdk.NewInt(12))), // add coins from inflation
|
|
||||||
)
|
|
||||||
|
|
||||||
StartCoins = sdk.NewCoins(
|
|
||||||
sdk.NewCoin(Fee2Denom, sdk.TokensFromConsensusPower(1000000)),
|
|
||||||
sdk.NewCoin(FeeDenom, sdk.TokensFromConsensusPower(1000000)),
|
|
||||||
sdk.NewCoin(FooDenom, sdk.TokensFromConsensusPower(1000)),
|
|
||||||
sdk.NewCoin(Denom, sdk.TokensFromConsensusPower(150)),
|
|
||||||
)
|
|
||||||
|
|
||||||
VestingCoins = sdk.NewCoins(
|
|
||||||
sdk.NewCoin(FeeDenom, sdk.TokensFromConsensusPower(500000)),
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
//___________________________________________________________________________________
|
|
||||||
// simd
|
|
||||||
|
|
||||||
// UnsafeResetAll is simd unsafe-reset-all
|
|
||||||
func (f *Fixtures) UnsafeResetAll(flags ...string) {
|
|
||||||
cmd := fmt.Sprintf("%s --home=%s unsafe-reset-all", f.SimdBinary, f.SimdHome)
|
|
||||||
ExecuteWrite(f.T, AddFlags(cmd, flags))
|
|
||||||
err := os.RemoveAll(filepath.Join(f.SimdHome, "config", "gentx"))
|
|
||||||
require.NoError(f.T, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// SDInit is simd init
|
|
||||||
// NOTE: SDInit sets the ChainID for the Fixtures instance
|
|
||||||
func (f *Fixtures) SDInit(moniker string, flags ...string) {
|
|
||||||
cmd := fmt.Sprintf("%s init --overwrite --home=%s %s", f.SimdBinary, f.SimdHome, moniker)
|
|
||||||
_, stderr := tests.ExecuteT(f.T, AddFlags(cmd, flags), clientkeys.DefaultKeyPass)
|
|
||||||
|
|
||||||
var chainID string
|
|
||||||
var initRes map[string]json.RawMessage
|
|
||||||
|
|
||||||
err := json.Unmarshal([]byte(stderr), &initRes)
|
|
||||||
require.NoError(f.T, err)
|
|
||||||
|
|
||||||
err = json.Unmarshal(initRes["chain_id"], &chainID)
|
|
||||||
require.NoError(f.T, err)
|
|
||||||
|
|
||||||
f.ChainID = chainID
|
|
||||||
}
|
|
||||||
|
|
||||||
// AddGenesisAccount is simd add-genesis-account
|
|
||||||
func (f *Fixtures) AddGenesisAccount(address sdk.AccAddress, coins sdk.Coins, flags ...string) {
|
|
||||||
cmd := fmt.Sprintf("%s add-genesis-account %s %s --home=%s --keyring-backend=test", f.SimdBinary, address, coins, f.SimdHome)
|
|
||||||
ExecuteWriteCheckErr(f.T, AddFlags(cmd, flags))
|
|
||||||
}
|
|
||||||
|
|
||||||
// GenTx is simd gentx
|
|
||||||
func (f *Fixtures) GenTx(name string, flags ...string) {
|
|
||||||
cmd := fmt.Sprintf("%s gentx --name=%s --home=%s --keyring-backend=test --chain-id=%s", f.SimdBinary, name, f.SimdHome, f.ChainID)
|
|
||||||
ExecuteWriteCheckErr(f.T, AddFlags(cmd, flags))
|
|
||||||
}
|
|
||||||
|
|
||||||
// CollectGenTxs is simd collect-gentxs
|
|
||||||
func (f *Fixtures) CollectGenTxs(flags ...string) {
|
|
||||||
cmd := fmt.Sprintf("%s collect-gentxs --home=%s", f.SimdBinary, f.SimdHome)
|
|
||||||
ExecuteWriteCheckErr(f.T, AddFlags(cmd, flags))
|
|
||||||
}
|
|
||||||
|
|
||||||
// SDStart runs simd start with the appropriate flags and returns a process
|
|
||||||
func (f *Fixtures) SDStart(flags ...string) *tests.Process {
|
|
||||||
cmd := fmt.Sprintf("%s start --home=%s --rpc.laddr=%v --p2p.laddr=%v", f.SimdBinary, f.SimdHome, f.RPCAddr, f.P2PAddr)
|
|
||||||
proc := tests.GoExecuteTWithStdout(f.T, AddFlags(cmd, flags))
|
|
||||||
tests.WaitForTMStart(f.Port)
|
|
||||||
tests.WaitForNextNBlocksTM(1, f.Port)
|
|
||||||
return proc
|
|
||||||
}
|
|
||||||
|
|
||||||
// SDTendermint returns the results of simd tendermint [query]
|
|
||||||
func (f *Fixtures) SDTendermint(query string) string {
|
|
||||||
cmd := fmt.Sprintf("%s tendermint %s --home=%s", f.SimdBinary, query, f.SimdHome)
|
|
||||||
success, stdout, stderr := ExecuteWriteRetStdStreams(f.T, cmd)
|
|
||||||
require.Empty(f.T, stderr)
|
|
||||||
require.True(f.T, success)
|
|
||||||
return strings.TrimSpace(stdout)
|
|
||||||
}
|
|
||||||
|
|
||||||
// ValidateGenesis runs simd validate-genesis
|
|
||||||
func (f *Fixtures) ValidateGenesis() {
|
|
||||||
cmd := fmt.Sprintf("%s validate-genesis --home=%s", f.SimdBinary, f.SimdHome)
|
|
||||||
ExecuteWriteCheckErr(f.T, cmd)
|
|
||||||
}
|
|
||||||
|
|
||||||
//___________________________________________________________________________________
|
|
||||||
// simcli keys
|
|
||||||
|
|
||||||
// KeysDelete is simcli keys delete
|
|
||||||
func (f *Fixtures) KeysDelete(name string, flags ...string) {
|
|
||||||
cmd := fmt.Sprintf("%s keys delete --keyring-backend=test --home=%s %s", f.SimdBinary,
|
|
||||||
f.SimcliHome, name)
|
|
||||||
ExecuteWrite(f.T, AddFlags(cmd, append(append(flags, "-y"), "-f")))
|
|
||||||
}
|
|
||||||
|
|
||||||
// KeysAdd is simcli keys add
|
|
||||||
func (f *Fixtures) KeysAdd(name string, flags ...string) {
|
|
||||||
cmd := fmt.Sprintf("%s keys add --keyring-backend=test --home=%s %s", f.SimdBinary,
|
|
||||||
f.SimcliHome, name)
|
|
||||||
ExecuteWriteCheckErr(f.T, AddFlags(cmd, flags))
|
|
||||||
}
|
|
||||||
|
|
||||||
// KeysAddRecover prepares simcli keys add --recover
|
|
||||||
func (f *Fixtures) KeysAddRecover(name, mnemonic string, flags ...string) (exitSuccess bool, stdout, stderr string) {
|
|
||||||
cmd := fmt.Sprintf("%s keys add --keyring-backend=test --home=%s --recover %s",
|
|
||||||
f.SimdBinary, f.SimcliHome, name)
|
|
||||||
return ExecuteWriteRetStdStreams(f.T, AddFlags(cmd, flags), mnemonic)
|
|
||||||
}
|
|
||||||
|
|
||||||
// KeysAddRecoverHDPath prepares simcli keys add --recover --account --index
|
|
||||||
func (f *Fixtures) KeysAddRecoverHDPath(name, mnemonic string, account uint32, index uint32, flags ...string) {
|
|
||||||
cmd := fmt.Sprintf("%s keys add --keyring-backend=test --home=%s --recover %s --account %d"+
|
|
||||||
" --index %d", f.SimdBinary, f.SimcliHome, name, account, index)
|
|
||||||
ExecuteWriteCheckErr(f.T, AddFlags(cmd, flags), mnemonic)
|
|
||||||
}
|
|
||||||
|
|
||||||
// KeysShow is simcli keys show
|
|
||||||
func (f *Fixtures) KeysShow(name string, flags ...string) keyring.KeyOutput {
|
|
||||||
cmd := fmt.Sprintf("%s keys show --keyring-backend=test --home=%s %s --output=json", f.SimdBinary, f.SimcliHome, name)
|
|
||||||
out, _ := tests.ExecuteT(f.T, AddFlags(cmd, flags), "")
|
|
||||||
var ko keyring.KeyOutput
|
|
||||||
err := clientkeys.UnmarshalJSON([]byte(out), &ko)
|
|
||||||
require.NoError(f.T, err)
|
|
||||||
return ko
|
|
||||||
}
|
|
||||||
|
|
||||||
// KeyAddress returns the SDK account address from the key
|
|
||||||
func (f *Fixtures) KeyAddress(name string) sdk.AccAddress {
|
|
||||||
ko := f.KeysShow(name)
|
|
||||||
accAddr, err := sdk.AccAddressFromBech32(ko.Address)
|
|
||||||
require.NoError(f.T, err)
|
|
||||||
return accAddr
|
|
||||||
}
|
|
||||||
|
|
||||||
//___________________________________________________________________________________
|
|
||||||
// simcli query txs
|
|
||||||
|
|
||||||
// QueryTxs is simcli query txs
|
|
||||||
func (f *Fixtures) QueryTxs(page, limit int, events ...string) *sdk.SearchTxsResult {
|
|
||||||
cmd := fmt.Sprintf("%s query txs --page=%d --limit=%d --events='%s' %v",
|
|
||||||
f.SimdBinary, page, limit, buildEventsQueryString(events), f.Flags())
|
|
||||||
out, _ := tests.ExecuteT(f.T, cmd, "")
|
|
||||||
var result sdk.SearchTxsResult
|
|
||||||
|
|
||||||
err := f.Cdc.UnmarshalJSON([]byte(out), &result)
|
|
||||||
require.NoError(f.T, err, "out %v\n, err %v", out, err)
|
|
||||||
return &result
|
|
||||||
}
|
|
||||||
|
|
||||||
//utils
|
|
||||||
|
|
||||||
func AddFlags(cmd string, flags []string) string {
|
|
||||||
for _, f := range flags {
|
|
||||||
cmd += " " + f
|
|
||||||
}
|
|
||||||
return strings.TrimSpace(cmd)
|
|
||||||
}
|
|
||||||
|
|
||||||
func UnmarshalStdTx(t require.TestingT, c codec.JSONMarshaler, s string) (stdTx authtypes.StdTx) {
|
|
||||||
require.Nil(t, c.UnmarshalJSON([]byte(s), &stdTx))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func buildEventsQueryString(events []string) string {
|
|
||||||
return strings.Join(events, "&")
|
|
||||||
}
|
|
||||||
|
|
||||||
func MarshalStdTx(t require.TestingT, c *codec.Codec, stdTx authtypes.StdTx) []byte {
|
|
||||||
bz, err := c.MarshalBinaryBare(stdTx)
|
|
||||||
require.NoError(t, err)
|
|
||||||
|
|
||||||
return bz
|
|
||||||
}
|
|
|
@ -1,60 +0,0 @@
|
||||||
package cli
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
"testing"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/stretchr/testify/require"
|
|
||||||
)
|
|
||||||
|
|
||||||
// InitFixtures is called at the beginning of a test and initializes a chain
|
|
||||||
// with 1 validator.
|
|
||||||
func InitFixtures(t *testing.T) (f *Fixtures) {
|
|
||||||
f = NewFixtures(t)
|
|
||||||
|
|
||||||
// reset test state
|
|
||||||
f.UnsafeResetAll()
|
|
||||||
|
|
||||||
// ensure keystore has foo and bar keys
|
|
||||||
f.KeysDelete(KeyFoo)
|
|
||||||
f.KeysDelete(KeyBar)
|
|
||||||
f.KeysDelete(KeyBar)
|
|
||||||
f.KeysDelete(KeyFooBarBaz)
|
|
||||||
f.KeysAdd(KeyFoo)
|
|
||||||
f.KeysAdd(KeyBar)
|
|
||||||
f.KeysAdd(KeyBaz)
|
|
||||||
f.KeysAdd(KeyVesting)
|
|
||||||
f.KeysAdd(KeyFooBarBaz, "--multisig-threshold=2", fmt.Sprintf("--multisig=%s,%s,%s", KeyFoo, KeyBar, KeyBaz))
|
|
||||||
|
|
||||||
// NOTE: SDInit sets the ChainID
|
|
||||||
f.SDInit(KeyFoo)
|
|
||||||
|
|
||||||
// start an account with tokens
|
|
||||||
f.AddGenesisAccount(f.KeyAddress(KeyFoo), StartCoins)
|
|
||||||
f.AddGenesisAccount(
|
|
||||||
f.KeyAddress(KeyVesting), StartCoins,
|
|
||||||
fmt.Sprintf("--vesting-amount=%s", VestingCoins),
|
|
||||||
fmt.Sprintf("--vesting-start-time=%d", time.Now().UTC().UnixNano()),
|
|
||||||
fmt.Sprintf("--vesting-end-time=%d", time.Now().Add(60*time.Second).UTC().UnixNano()),
|
|
||||||
)
|
|
||||||
|
|
||||||
f.GenTx(KeyFoo)
|
|
||||||
f.CollectGenTxs()
|
|
||||||
|
|
||||||
return f
|
|
||||||
}
|
|
||||||
|
|
||||||
// Cleanup is meant to be run at the end of a test to clean up an remaining test state
|
|
||||||
func (f *Fixtures) Cleanup(dirs ...string) {
|
|
||||||
clean := append(dirs, f.RootDir)
|
|
||||||
for _, d := range clean {
|
|
||||||
require.NoError(f.T, os.RemoveAll(d))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Flags returns the flags necessary for making most CLI calls
|
|
||||||
func (f *Fixtures) Flags() string {
|
|
||||||
return fmt.Sprintf("--home=%s --node=%s --chain-id=%s --output=json", f.SimcliHome, f.RPCAddr, f.ChainID)
|
|
||||||
}
|
|
|
@ -1,77 +0,0 @@
|
||||||
// +build cli_test
|
|
||||||
|
|
||||||
package cli_test
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"testing"
|
|
||||||
|
|
||||||
"github.com/stretchr/testify/require"
|
|
||||||
|
|
||||||
"github.com/cosmos/cosmos-sdk/tests/cli"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestCLIKeysAddMultisig(t *testing.T) {
|
|
||||||
t.SkipNow() // TODO: Bring back once viper is refactored.
|
|
||||||
t.Parallel()
|
|
||||||
f := cli.InitFixtures(t)
|
|
||||||
|
|
||||||
// key names order does not matter
|
|
||||||
f.KeysAdd("msig1", "--multisig-threshold=2",
|
|
||||||
fmt.Sprintf("--multisig=%s,%s", cli.KeyBar, cli.KeyBaz))
|
|
||||||
ke1Address1 := f.KeysShow("msig1").Address
|
|
||||||
f.KeysDelete("msig1")
|
|
||||||
|
|
||||||
f.KeysAdd("msig2", "--multisig-threshold=2",
|
|
||||||
fmt.Sprintf("--multisig=%s,%s", cli.KeyBaz, cli.KeyBar))
|
|
||||||
require.Equal(t, ke1Address1, f.KeysShow("msig2").Address)
|
|
||||||
f.KeysDelete("msig2")
|
|
||||||
|
|
||||||
f.KeysAdd("msig3", "--multisig-threshold=2",
|
|
||||||
fmt.Sprintf("--multisig=%s,%s", cli.KeyBar, cli.KeyBaz),
|
|
||||||
"--nosort")
|
|
||||||
f.KeysAdd("msig4", "--multisig-threshold=2",
|
|
||||||
fmt.Sprintf("--multisig=%s,%s", cli.KeyBaz, cli.KeyBar),
|
|
||||||
"--nosort")
|
|
||||||
require.NotEqual(t, f.KeysShow("msig3").Address, f.KeysShow("msig4").Address)
|
|
||||||
|
|
||||||
// Cleanup testing directories
|
|
||||||
f.Cleanup()
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestCLIKeysAddRecover(t *testing.T) {
|
|
||||||
t.SkipNow() // TODO: Bring back once viper is refactored.
|
|
||||||
t.Parallel()
|
|
||||||
f := cli.InitFixtures(t)
|
|
||||||
|
|
||||||
exitSuccess, _, _ := f.KeysAddRecover("empty-mnemonic", "")
|
|
||||||
require.False(t, exitSuccess)
|
|
||||||
|
|
||||||
exitSuccess, _, _ = f.KeysAddRecover("test-recover", "dentist task convince chimney quality leave banana trade firm crawl eternal easily")
|
|
||||||
require.True(t, exitSuccess)
|
|
||||||
require.Equal(t, "cosmos1qcfdf69js922qrdr4yaww3ax7gjml6pdds46f4", f.KeyAddress("test-recover").String())
|
|
||||||
|
|
||||||
// Cleanup testing directories
|
|
||||||
f.Cleanup()
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestCLIKeysAddRecoverHDPath(t *testing.T) {
|
|
||||||
t.SkipNow() // TODO: Bring back once viper is refactored.
|
|
||||||
t.Parallel()
|
|
||||||
f := cli.InitFixtures(t)
|
|
||||||
|
|
||||||
f.KeysAddRecoverHDPath("test-recoverHD1", "dentist task convince chimney quality leave banana trade firm crawl eternal easily", 0, 0)
|
|
||||||
require.Equal(t, "cosmos1qcfdf69js922qrdr4yaww3ax7gjml6pdds46f4", f.KeyAddress("test-recoverHD1").String())
|
|
||||||
|
|
||||||
f.KeysAddRecoverHDPath("test-recoverH2", "dentist task convince chimney quality leave banana trade firm crawl eternal easily", 1, 5)
|
|
||||||
require.Equal(t, "cosmos1pdfav2cjhry9k79nu6r8kgknnjtq6a7rykmafy", f.KeyAddress("test-recoverH2").String())
|
|
||||||
|
|
||||||
f.KeysAddRecoverHDPath("test-recoverH3", "dentist task convince chimney quality leave banana trade firm crawl eternal easily", 1, 17)
|
|
||||||
require.Equal(t, "cosmos1909k354n6wl8ujzu6kmh49w4d02ax7qvlkv4sn", f.KeyAddress("test-recoverH3").String())
|
|
||||||
|
|
||||||
f.KeysAddRecoverHDPath("test-recoverH4", "dentist task convince chimney quality leave banana trade firm crawl eternal easily", 2, 17)
|
|
||||||
require.Equal(t, "cosmos1v9plmhvyhgxk3th9ydacm7j4z357s3nhtwsjat", f.KeyAddress("test-recoverH4").String())
|
|
||||||
|
|
||||||
// Cleanup testing directories
|
|
||||||
f.Cleanup()
|
|
||||||
}
|
|
|
@ -1,127 +0,0 @@
|
||||||
// +build cli_test
|
|
||||||
|
|
||||||
package cli_test
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"io/ioutil"
|
|
||||||
"path/filepath"
|
|
||||||
"testing"
|
|
||||||
|
|
||||||
"github.com/stretchr/testify/require"
|
|
||||||
tmtypes "github.com/tendermint/tendermint/types"
|
|
||||||
|
|
||||||
"github.com/cosmos/cosmos-sdk/tests/cli"
|
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
||||||
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
|
|
||||||
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestCLISimdCollectGentxs(t *testing.T) {
|
|
||||||
t.SkipNow() // TODO: Bring back once viper is refactored.
|
|
||||||
t.Parallel()
|
|
||||||
var customMaxBytes, customMaxGas int64 = 99999999, 1234567
|
|
||||||
f := cli.NewFixtures(t)
|
|
||||||
|
|
||||||
// Initialise temporary directories
|
|
||||||
gentxDir, err := ioutil.TempDir("", "")
|
|
||||||
gentxDoc := filepath.Join(gentxDir, "gentx.json")
|
|
||||||
require.NoError(t, err)
|
|
||||||
|
|
||||||
// Reset testing path
|
|
||||||
f.UnsafeResetAll()
|
|
||||||
|
|
||||||
// Initialize keys
|
|
||||||
f.KeysAdd(cli.KeyFoo)
|
|
||||||
|
|
||||||
// Run init
|
|
||||||
f.SDInit(cli.KeyFoo)
|
|
||||||
|
|
||||||
// Customise genesis.json
|
|
||||||
|
|
||||||
genFile := f.GenesisFile()
|
|
||||||
genDoc, err := tmtypes.GenesisDocFromFile(genFile)
|
|
||||||
require.NoError(t, err)
|
|
||||||
genDoc.ConsensusParams.Block.MaxBytes = customMaxBytes
|
|
||||||
genDoc.ConsensusParams.Block.MaxGas = customMaxGas
|
|
||||||
genDoc.SaveAs(genFile)
|
|
||||||
|
|
||||||
// Add account to genesis.json
|
|
||||||
f.AddGenesisAccount(f.KeyAddress(cli.KeyFoo), cli.StartCoins)
|
|
||||||
|
|
||||||
// Write gentx file
|
|
||||||
f.GenTx(cli.KeyFoo, fmt.Sprintf("--output-document=%s", gentxDoc))
|
|
||||||
|
|
||||||
// Collect gentxs from a custom directory
|
|
||||||
f.CollectGenTxs(fmt.Sprintf("--gentx-dir=%s", gentxDir))
|
|
||||||
|
|
||||||
genDoc, err = tmtypes.GenesisDocFromFile(genFile)
|
|
||||||
require.NoError(t, err)
|
|
||||||
require.Equal(t, genDoc.ConsensusParams.Block.MaxBytes, customMaxBytes)
|
|
||||||
require.Equal(t, genDoc.ConsensusParams.Block.MaxGas, customMaxGas)
|
|
||||||
|
|
||||||
f.Cleanup(gentxDir)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestCLISimdAddGenesisAccount(t *testing.T) {
|
|
||||||
t.Parallel()
|
|
||||||
f := cli.NewFixtures(t)
|
|
||||||
|
|
||||||
// Reset testing path
|
|
||||||
f.UnsafeResetAll()
|
|
||||||
|
|
||||||
// Initialize keys
|
|
||||||
f.KeysDelete(cli.KeyFoo)
|
|
||||||
f.KeysDelete(cli.KeyBar)
|
|
||||||
f.KeysDelete(cli.KeyBaz)
|
|
||||||
f.KeysAdd(cli.KeyFoo)
|
|
||||||
f.KeysAdd(cli.KeyBar)
|
|
||||||
f.KeysAdd(cli.KeyBaz)
|
|
||||||
|
|
||||||
// Run init
|
|
||||||
f.SDInit(cli.KeyFoo)
|
|
||||||
|
|
||||||
// Add account to genesis.json
|
|
||||||
bazCoins := sdk.Coins{
|
|
||||||
sdk.NewInt64Coin("acoin", 1000000),
|
|
||||||
sdk.NewInt64Coin("bcoin", 1000000),
|
|
||||||
}
|
|
||||||
|
|
||||||
f.AddGenesisAccount(f.KeyAddress(cli.KeyFoo), cli.StartCoins)
|
|
||||||
f.AddGenesisAccount(f.KeyAddress(cli.KeyBar), bazCoins)
|
|
||||||
|
|
||||||
genesisState := f.GenesisState()
|
|
||||||
|
|
||||||
appCodec := f.EncodingConfig.Marshaler
|
|
||||||
|
|
||||||
accounts := authtypes.GetGenesisStateFromAppState(appCodec, genesisState).Accounts
|
|
||||||
balances := banktypes.GetGenesisStateFromAppState(f.Cdc, genesisState).Balances
|
|
||||||
balancesSet := make(map[string]sdk.Coins)
|
|
||||||
|
|
||||||
for _, b := range balances {
|
|
||||||
balancesSet[b.GetAddress().String()] = b.Coins
|
|
||||||
}
|
|
||||||
|
|
||||||
require.Equal(t, accounts[0].GetAddress(), f.KeyAddress(cli.KeyFoo))
|
|
||||||
require.Equal(t, accounts[1].GetAddress(), f.KeyAddress(cli.KeyBar))
|
|
||||||
require.True(t, balancesSet[accounts[0].GetAddress().String()].IsEqual(cli.StartCoins))
|
|
||||||
require.True(t, balancesSet[accounts[1].GetAddress().String()].IsEqual(bazCoins))
|
|
||||||
|
|
||||||
// Cleanup testing directories
|
|
||||||
f.Cleanup()
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestCLIValidateGenesis(t *testing.T) {
|
|
||||||
t.SkipNow()
|
|
||||||
t.Parallel()
|
|
||||||
f := cli.InitFixtures(t)
|
|
||||||
|
|
||||||
// start simd server
|
|
||||||
proc := f.SDStart()
|
|
||||||
t.Cleanup(func() { proc.Stop(false) })
|
|
||||||
|
|
||||||
f.ValidateGenesis()
|
|
||||||
|
|
||||||
// Cleanup testing directories
|
|
||||||
f.Cleanup()
|
|
||||||
}
|
|
114
tests/gobash.go
114
tests/gobash.go
|
@ -1,114 +0,0 @@
|
||||||
package tests
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"io"
|
|
||||||
"io/ioutil"
|
|
||||||
"strings"
|
|
||||||
"testing"
|
|
||||||
|
|
||||||
"github.com/stretchr/testify/require"
|
|
||||||
)
|
|
||||||
|
|
||||||
// ExecuteT executes the command, pipes any input to STDIN and return STDOUT,
|
|
||||||
// logging STDOUT/STDERR to t.
|
|
||||||
func ExecuteT(t *testing.T, cmd, input string) (stdout, stderr string) {
|
|
||||||
t.Log("Running", cmd)
|
|
||||||
|
|
||||||
// split cmd to name and args
|
|
||||||
split := strings.Split(cmd, " ")
|
|
||||||
require.True(t, len(split) > 0, "no command provided")
|
|
||||||
name, args := split[0], []string(nil)
|
|
||||||
if len(split) > 1 {
|
|
||||||
args = split[1:]
|
|
||||||
}
|
|
||||||
|
|
||||||
proc, err := StartProcess("", name, args)
|
|
||||||
require.NoError(t, err)
|
|
||||||
|
|
||||||
// if input is provided, pass it to STDIN and close the pipe
|
|
||||||
if input != "" {
|
|
||||||
_, err = io.WriteString(proc.StdinPipe, input)
|
|
||||||
require.NoError(t, err)
|
|
||||||
proc.StdinPipe.Close()
|
|
||||||
}
|
|
||||||
|
|
||||||
outbz, errbz, err := proc.ReadAll()
|
|
||||||
if err != nil {
|
|
||||||
fmt.Println("Err on proc.ReadAll()", err, args)
|
|
||||||
}
|
|
||||||
|
|
||||||
proc.Wait()
|
|
||||||
|
|
||||||
if len(outbz) > 0 {
|
|
||||||
t.Log("Stdout:", string(outbz))
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(errbz) > 0 {
|
|
||||||
t.Log("Stderr:", string(errbz))
|
|
||||||
}
|
|
||||||
|
|
||||||
stdout = strings.Trim(string(outbz), "\n")
|
|
||||||
stderr = strings.Trim(string(errbz), "\n")
|
|
||||||
|
|
||||||
return stdout, stderr
|
|
||||||
}
|
|
||||||
|
|
||||||
// Execute the command, launch goroutines to log stdout/err to t.
|
|
||||||
// Caller should wait for .Wait() or .Stop() to terminate.
|
|
||||||
func GoExecuteT(t *testing.T, cmd string) (proc *Process) {
|
|
||||||
t.Log("Running", cmd)
|
|
||||||
|
|
||||||
// Split cmd to name and args.
|
|
||||||
split := strings.Split(cmd, " ")
|
|
||||||
require.True(t, len(split) > 0, "no command provided")
|
|
||||||
name, args := split[0], []string(nil)
|
|
||||||
if len(split) > 1 {
|
|
||||||
args = split[1:]
|
|
||||||
}
|
|
||||||
|
|
||||||
// Start process.
|
|
||||||
proc, err := StartProcess("", name, args)
|
|
||||||
require.NoError(t, err)
|
|
||||||
return proc
|
|
||||||
}
|
|
||||||
|
|
||||||
// Same as GoExecuteT but spawns a go routine to ReadAll off stdout.
|
|
||||||
func GoExecuteTWithStdout(t *testing.T, cmd string) (proc *Process) {
|
|
||||||
t.Log("Running", cmd)
|
|
||||||
|
|
||||||
// Split cmd to name and args.
|
|
||||||
split := strings.Split(cmd, " ")
|
|
||||||
require.True(t, len(split) > 0, "no command provided")
|
|
||||||
name, args := split[0], []string(nil)
|
|
||||||
if len(split) > 1 {
|
|
||||||
args = split[1:]
|
|
||||||
}
|
|
||||||
|
|
||||||
// Start process.
|
|
||||||
proc, err := CreateProcess("", name, args)
|
|
||||||
require.NoError(t, err)
|
|
||||||
|
|
||||||
// Without this, the test halts ?!
|
|
||||||
// (theory: because stdout and/or err aren't connected to anything the process halts)
|
|
||||||
go func(proc *Process) {
|
|
||||||
_, err := ioutil.ReadAll(proc.StdoutPipe)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Println("-------------ERR-----------------------", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}(proc)
|
|
||||||
|
|
||||||
go func(proc *Process) {
|
|
||||||
_, err := ioutil.ReadAll(proc.StderrPipe)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Println("-------------ERR-----------------------", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}(proc)
|
|
||||||
|
|
||||||
err = proc.Cmd.Start()
|
|
||||||
require.NoError(t, err)
|
|
||||||
proc.Pid = proc.Cmd.Process.Pid
|
|
||||||
return proc
|
|
||||||
}
|
|
117
tests/process.go
117
tests/process.go
|
@ -1,117 +0,0 @@
|
||||||
package tests
|
|
||||||
|
|
||||||
import (
|
|
||||||
"io"
|
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
|
||||||
"os/exec"
|
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
// execution process
|
|
||||||
type Process struct {
|
|
||||||
ExecPath string
|
|
||||||
Args []string
|
|
||||||
Pid int
|
|
||||||
StartTime time.Time
|
|
||||||
EndTime time.Time
|
|
||||||
Cmd *exec.Cmd `json:"-"`
|
|
||||||
ExitState *os.ProcessState `json:"-"`
|
|
||||||
StdinPipe io.WriteCloser `json:"-"`
|
|
||||||
StdoutPipe io.ReadCloser `json:"-"`
|
|
||||||
StderrPipe io.ReadCloser `json:"-"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// dir: The working directory. If "", os.Getwd() is used.
|
|
||||||
// name: Command name
|
|
||||||
// args: Args to command. (should not include name)
|
|
||||||
func StartProcess(dir string, name string, args []string) (*Process, error) {
|
|
||||||
proc, err := CreateProcess(dir, name, args)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
// cmd start
|
|
||||||
if err := proc.Cmd.Start(); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
proc.Pid = proc.Cmd.Process.Pid
|
|
||||||
|
|
||||||
return proc, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Same as StartProcess but doesn't start the process
|
|
||||||
func CreateProcess(dir string, name string, args []string) (*Process, error) {
|
|
||||||
var cmd = exec.Command(name, args...) // is not yet started.
|
|
||||||
// cmd dir
|
|
||||||
if dir == "" {
|
|
||||||
pwd, err := os.Getwd()
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
cmd.Dir = pwd
|
|
||||||
} else {
|
|
||||||
cmd.Dir = dir
|
|
||||||
}
|
|
||||||
// cmd stdin
|
|
||||||
stdin, err := cmd.StdinPipe()
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
stdout, err := cmd.StdoutPipe()
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
stderr, err := cmd.StderrPipe()
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
proc := &Process{
|
|
||||||
ExecPath: name,
|
|
||||||
Args: args,
|
|
||||||
StartTime: time.Now(),
|
|
||||||
Cmd: cmd,
|
|
||||||
ExitState: nil,
|
|
||||||
StdinPipe: stdin,
|
|
||||||
StdoutPipe: stdout,
|
|
||||||
StderrPipe: stderr,
|
|
||||||
}
|
|
||||||
return proc, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// stop the process
|
|
||||||
func (proc *Process) Stop(kill bool) error {
|
|
||||||
if kill {
|
|
||||||
// fmt.Printf("Killing process %v\n", proc.Cmd.Process)
|
|
||||||
return proc.Cmd.Process.Kill()
|
|
||||||
}
|
|
||||||
return proc.Cmd.Process.Signal(os.Interrupt)
|
|
||||||
}
|
|
||||||
|
|
||||||
// wait for the process
|
|
||||||
func (proc *Process) Wait() {
|
|
||||||
err := proc.Cmd.Wait()
|
|
||||||
if err != nil {
|
|
||||||
// fmt.Printf("Process exit: %v\n", err)
|
|
||||||
if exitError, ok := err.(*exec.ExitError); ok {
|
|
||||||
proc.ExitState = exitError.ProcessState
|
|
||||||
}
|
|
||||||
}
|
|
||||||
proc.ExitState = proc.Cmd.ProcessState
|
|
||||||
proc.EndTime = time.Now() // TODO make this goroutine-safe
|
|
||||||
}
|
|
||||||
|
|
||||||
// ReadAll calls ioutil.ReadAll on the StdoutPipe and StderrPipe.
|
|
||||||
func (proc *Process) ReadAll() (stdout []byte, stderr []byte, err error) {
|
|
||||||
outbz, err := ioutil.ReadAll(proc.StdoutPipe)
|
|
||||||
if err != nil {
|
|
||||||
return nil, nil, err
|
|
||||||
}
|
|
||||||
errbz, err := ioutil.ReadAll(proc.StderrPipe)
|
|
||||||
if err != nil {
|
|
||||||
return nil, nil, err
|
|
||||||
}
|
|
||||||
return outbz, errbz, nil
|
|
||||||
}
|
|
120
tests/util.go
120
tests/util.go
|
@ -1,120 +0,0 @@
|
||||||
package tests
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"net/http"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
rpchttp "github.com/tendermint/tendermint/rpc/client/http"
|
|
||||||
ctypes "github.com/tendermint/tendermint/rpc/core/types"
|
|
||||||
|
|
||||||
"github.com/cosmos/cosmos-sdk/codec"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Wait for N tendermint blocks to pass using the Tendermint RPC
|
|
||||||
// on localhost
|
|
||||||
func WaitForNextNBlocksTM(n int64, port string) {
|
|
||||||
// get the latest block and wait for n more
|
|
||||||
url := fmt.Sprintf("http://localhost:%v", port)
|
|
||||||
cl, err := rpchttp.New(url, "/websocket")
|
|
||||||
if err != nil {
|
|
||||||
panic(fmt.Sprintf("failed to create Tendermint HTTP client: %s", err))
|
|
||||||
}
|
|
||||||
|
|
||||||
var height int64
|
|
||||||
|
|
||||||
resBlock, err := cl.Block(nil)
|
|
||||||
if err != nil || resBlock.Block == nil {
|
|
||||||
// wait for the first block to exist
|
|
||||||
WaitForHeightTM(1, port)
|
|
||||||
height = 1 + n
|
|
||||||
} else {
|
|
||||||
height = resBlock.Block.Height + n
|
|
||||||
}
|
|
||||||
|
|
||||||
waitForHeightTM(height, url)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Wait for the given height from the Tendermint RPC
|
|
||||||
// on localhost
|
|
||||||
func WaitForHeightTM(height int64, port string) {
|
|
||||||
url := fmt.Sprintf("http://localhost:%v", port)
|
|
||||||
waitForHeightTM(height, url)
|
|
||||||
}
|
|
||||||
|
|
||||||
func waitForHeightTM(height int64, url string) {
|
|
||||||
cl, err := rpchttp.New(url, "/websocket")
|
|
||||||
if err != nil {
|
|
||||||
panic(fmt.Sprintf("failed to create Tendermint HTTP client: %s", err))
|
|
||||||
}
|
|
||||||
|
|
||||||
for {
|
|
||||||
// get url, try a few times
|
|
||||||
var resBlock *ctypes.ResultBlock
|
|
||||||
var err error
|
|
||||||
INNER:
|
|
||||||
for i := 0; i < 5; i++ {
|
|
||||||
resBlock, err = cl.Block(nil)
|
|
||||||
if err == nil {
|
|
||||||
break INNER
|
|
||||||
}
|
|
||||||
time.Sleep(time.Millisecond * 200)
|
|
||||||
}
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if resBlock.Block != nil && resBlock.Block.Height >= height {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
time.Sleep(time.Millisecond * 100)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// wait for tendermint to start by querying tendermint
|
|
||||||
func WaitForTMStart(port string) {
|
|
||||||
url := fmt.Sprintf("http://localhost:%v/block", port)
|
|
||||||
WaitForStart(url)
|
|
||||||
}
|
|
||||||
|
|
||||||
// WaitForStart waits for the node to start by pinging the url
|
|
||||||
// every 100ms for 10s until it returns 200. If it takes longer than 5s,
|
|
||||||
// it panics.
|
|
||||||
func WaitForStart(url string) {
|
|
||||||
var err error
|
|
||||||
|
|
||||||
// ping the status endpoint a few times a second
|
|
||||||
// for a few seconds until we get a good response.
|
|
||||||
// otherwise something probably went wrong
|
|
||||||
for i := 0; i < 100; i++ {
|
|
||||||
time.Sleep(time.Millisecond * 100)
|
|
||||||
|
|
||||||
var res *http.Response
|
|
||||||
res, err = http.Get(url) // nolint:gosec
|
|
||||||
if err != nil || res == nil {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
// body, _ := ioutil.ReadAll(res.Body)
|
|
||||||
// fmt.Println("BODY", string(body))
|
|
||||||
err = res.Body.Close()
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if res.StatusCode == http.StatusOK {
|
|
||||||
// good!
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// still haven't started up?! panic!
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
var cdc = codec.New()
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
ctypes.RegisterAmino(cdc.Amino)
|
|
||||||
}
|
|
||||||
|
|
||||||
//DONTCOVER
|
|
|
@ -334,13 +334,6 @@ func New(t *testing.T, cfg Config) *Network {
|
||||||
return network
|
return network
|
||||||
}
|
}
|
||||||
|
|
||||||
// WaitForHeight performs a blocking check where it waits for a block to be
|
|
||||||
// committed after a given block. If that height is not reached within a timeout,
|
|
||||||
// an error is returned. Regardless, the latest height queried is returned.
|
|
||||||
func (n *Network) WaitForHeight(h int64) (int64, error) {
|
|
||||||
return n.WaitForHeightWithTimeout(h, 10*time.Second)
|
|
||||||
}
|
|
||||||
|
|
||||||
// LatestHeight returns the latest height of the network or an error if the
|
// LatestHeight returns the latest height of the network or an error if the
|
||||||
// query fails or no validators exist.
|
// query fails or no validators exist.
|
||||||
func (n *Network) LatestHeight() (int64, error) {
|
func (n *Network) LatestHeight() (int64, error) {
|
||||||
|
@ -356,6 +349,13 @@ func (n *Network) LatestHeight() (int64, error) {
|
||||||
return status.SyncInfo.LatestBlockHeight, nil
|
return status.SyncInfo.LatestBlockHeight, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// WaitForHeight performs a blocking check where it waits for a block to be
|
||||||
|
// committed after a given block. If that height is not reached within a timeout,
|
||||||
|
// an error is returned. Regardless, the latest height queried is returned.
|
||||||
|
func (n *Network) WaitForHeight(h int64) (int64, error) {
|
||||||
|
return n.WaitForHeightWithTimeout(h, 10*time.Second)
|
||||||
|
}
|
||||||
|
|
||||||
// WaitForHeightWithTimeout is the same as WaitForHeight except the caller can
|
// WaitForHeightWithTimeout is the same as WaitForHeight except the caller can
|
||||||
// provide a custom timeout.
|
// provide a custom timeout.
|
||||||
func (n *Network) WaitForHeightWithTimeout(h int64, t time.Duration) (int64, error) {
|
func (n *Network) WaitForHeightWithTimeout(h int64, t time.Duration) (int64, error) {
|
||||||
|
@ -386,6 +386,22 @@ func (n *Network) WaitForHeightWithTimeout(h int64, t time.Duration) (int64, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// WaitForNextBlock waits for the next block to be committed, returning an error
|
||||||
|
// upon failure.
|
||||||
|
func (n *Network) WaitForNextBlock() error {
|
||||||
|
lastBlock, err := n.LatestHeight()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = n.WaitForHeight(lastBlock + 1)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
// Cleanup removes the root testing (temporary) directory and stops both the
|
// Cleanup removes the root testing (temporary) directory and stops both the
|
||||||
// Tendermint and API services. It allows other callers to create and start
|
// Tendermint and API services. It allows other callers to create and start
|
||||||
// test networks. This method must be called when a test is finished, typically
|
// test networks. This method must be called when a test is finished, typically
|
||||||
|
|
|
@ -7,7 +7,6 @@ import (
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
"github.com/stretchr/testify/suite"
|
"github.com/stretchr/testify/suite"
|
||||||
|
@ -15,18 +14,19 @@ import (
|
||||||
|
|
||||||
"github.com/cosmos/cosmos-sdk/client"
|
"github.com/cosmos/cosmos-sdk/client"
|
||||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||||
|
"github.com/cosmos/cosmos-sdk/codec"
|
||||||
codec2 "github.com/cosmos/cosmos-sdk/codec"
|
codec2 "github.com/cosmos/cosmos-sdk/codec"
|
||||||
"github.com/cosmos/cosmos-sdk/crypto/hd"
|
"github.com/cosmos/cosmos-sdk/crypto/hd"
|
||||||
"github.com/cosmos/cosmos-sdk/crypto/keyring"
|
"github.com/cosmos/cosmos-sdk/crypto/keyring"
|
||||||
"github.com/cosmos/cosmos-sdk/crypto/types/multisig"
|
"github.com/cosmos/cosmos-sdk/crypto/types/multisig"
|
||||||
simappparams "github.com/cosmos/cosmos-sdk/simapp/params"
|
simappparams "github.com/cosmos/cosmos-sdk/simapp/params"
|
||||||
"github.com/cosmos/cosmos-sdk/tests/cli"
|
|
||||||
"github.com/cosmos/cosmos-sdk/testutil"
|
"github.com/cosmos/cosmos-sdk/testutil"
|
||||||
"github.com/cosmos/cosmos-sdk/testutil/network"
|
"github.com/cosmos/cosmos-sdk/testutil/network"
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
cli2 "github.com/cosmos/cosmos-sdk/x/auth/client/cli"
|
authcli "github.com/cosmos/cosmos-sdk/x/auth/client/cli"
|
||||||
authtest "github.com/cosmos/cosmos-sdk/x/auth/client/testutil"
|
authtest "github.com/cosmos/cosmos-sdk/x/auth/client/testutil"
|
||||||
"github.com/cosmos/cosmos-sdk/x/auth/types"
|
"github.com/cosmos/cosmos-sdk/x/auth/types"
|
||||||
|
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
|
||||||
bankcli "github.com/cosmos/cosmos-sdk/x/bank/client/testutil"
|
bankcli "github.com/cosmos/cosmos-sdk/x/bank/client/testutil"
|
||||||
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
|
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
|
||||||
)
|
)
|
||||||
|
@ -176,7 +176,7 @@ func (s *IntegrationTestSuite) TestCLISendGenerateSignAndBroadcast() {
|
||||||
)
|
)
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
|
|
||||||
normalGeneratedStdTx := cli.UnmarshalStdTx(s.T(), val1.ClientCtx.JSONMarshaler, normalGeneratedTx.String())
|
normalGeneratedStdTx := unmarshalStdTx(s.T(), val1.ClientCtx.JSONMarshaler, normalGeneratedTx.String())
|
||||||
s.Require().Equal(normalGeneratedStdTx.Fee.Gas, uint64(flags.DefaultGasLimit))
|
s.Require().Equal(normalGeneratedStdTx.Fee.Gas, uint64(flags.DefaultGasLimit))
|
||||||
s.Require().Equal(len(normalGeneratedStdTx.Msgs), 1)
|
s.Require().Equal(len(normalGeneratedStdTx.Msgs), 1)
|
||||||
s.Require().Equal(0, len(normalGeneratedStdTx.GetSignatures()))
|
s.Require().Equal(0, len(normalGeneratedStdTx.GetSignatures()))
|
||||||
|
@ -197,7 +197,7 @@ func (s *IntegrationTestSuite) TestCLISendGenerateSignAndBroadcast() {
|
||||||
)
|
)
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
|
|
||||||
limitedGasStdTx := cli.UnmarshalStdTx(s.T(), val1.ClientCtx.JSONMarshaler, limitedGasGeneratedTx.String())
|
limitedGasStdTx := unmarshalStdTx(s.T(), val1.ClientCtx.JSONMarshaler, limitedGasGeneratedTx.String())
|
||||||
s.Require().Equal(limitedGasStdTx.Fee.Gas, uint64(100))
|
s.Require().Equal(limitedGasStdTx.Fee.Gas, uint64(100))
|
||||||
s.Require().Equal(len(limitedGasStdTx.Msgs), 1)
|
s.Require().Equal(len(limitedGasStdTx.Msgs), 1)
|
||||||
s.Require().Equal(0, len(limitedGasStdTx.GetSignatures()))
|
s.Require().Equal(0, len(limitedGasStdTx.GetSignatures()))
|
||||||
|
@ -218,7 +218,7 @@ func (s *IntegrationTestSuite) TestCLISendGenerateSignAndBroadcast() {
|
||||||
)
|
)
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
|
|
||||||
finalStdTx := cli.UnmarshalStdTx(s.T(), val1.ClientCtx.JSONMarshaler, finalGeneratedTx.String())
|
finalStdTx := unmarshalStdTx(s.T(), val1.ClientCtx.JSONMarshaler, finalGeneratedTx.String())
|
||||||
s.Require().Equal(uint64(flags.DefaultGasLimit), finalStdTx.Fee.Gas)
|
s.Require().Equal(uint64(flags.DefaultGasLimit), finalStdTx.Fee.Gas)
|
||||||
s.Require().Equal(len(finalStdTx.Msgs), 1)
|
s.Require().Equal(len(finalStdTx.Msgs), 1)
|
||||||
|
|
||||||
|
@ -246,7 +246,7 @@ func (s *IntegrationTestSuite) TestCLISendGenerateSignAndBroadcast() {
|
||||||
signedTx, err := authtest.TxSignExec(val1.ClientCtx, val1.Address, unsignedTxFile.Name())
|
signedTx, err := authtest.TxSignExec(val1.ClientCtx, val1.Address, unsignedTxFile.Name())
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
|
|
||||||
signedFinalTx := cli.UnmarshalStdTx(s.T(), val1.ClientCtx.JSONMarshaler, signedTx.String())
|
signedFinalTx := unmarshalStdTx(s.T(), val1.ClientCtx.JSONMarshaler, signedTx.String())
|
||||||
s.Require().Equal(len(signedFinalTx.Msgs), 1)
|
s.Require().Equal(len(signedFinalTx.Msgs), 1)
|
||||||
s.Require().Equal(1, len(signedFinalTx.GetSignatures()))
|
s.Require().Equal(1, len(signedFinalTx.GetSignatures()))
|
||||||
s.Require().Equal(val1.Address.String(), signedFinalTx.GetSigners()[0].String())
|
s.Require().Equal(val1.Address.String(), signedFinalTx.GetSigners()[0].String())
|
||||||
|
@ -268,7 +268,7 @@ func (s *IntegrationTestSuite) TestCLISendGenerateSignAndBroadcast() {
|
||||||
var coins sdk.Coins
|
var coins sdk.Coins
|
||||||
err = val1.ClientCtx.JSONMarshaler.UnmarshalJSON(resp.Bytes(), &coins)
|
err = val1.ClientCtx.JSONMarshaler.UnmarshalJSON(resp.Bytes(), &coins)
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
s.Require().Equal(startTokens, coins.AmountOf(cli.Denom))
|
s.Require().Equal(startTokens, coins.AmountOf(s.cfg.BondDenom))
|
||||||
|
|
||||||
// Test broadcast
|
// Test broadcast
|
||||||
|
|
||||||
|
@ -276,16 +276,14 @@ func (s *IntegrationTestSuite) TestCLISendGenerateSignAndBroadcast() {
|
||||||
res, err = authtest.TxBroadcastExec(val1.ClientCtx, signedTxFile.Name(), "--offline")
|
res, err = authtest.TxBroadcastExec(val1.ClientCtx, signedTxFile.Name(), "--offline")
|
||||||
s.Require().EqualError(err, "cannot broadcast tx during offline mode")
|
s.Require().EqualError(err, "cannot broadcast tx during offline mode")
|
||||||
|
|
||||||
err = waitForNextBlock(s.network)
|
s.Require().NoError(s.network.WaitForNextBlock())
|
||||||
s.Require().NoError(err)
|
|
||||||
|
|
||||||
// Broadcast correct transaction.
|
// Broadcast correct transaction.
|
||||||
val1.ClientCtx.BroadcastMode = flags.BroadcastBlock
|
val1.ClientCtx.BroadcastMode = flags.BroadcastBlock
|
||||||
res, err = authtest.TxBroadcastExec(val1.ClientCtx, signedTxFile.Name())
|
res, err = authtest.TxBroadcastExec(val1.ClientCtx, signedTxFile.Name())
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
|
|
||||||
err = waitForNextBlock(s.network)
|
s.Require().NoError(s.network.WaitForNextBlock())
|
||||||
s.Require().NoError(err)
|
|
||||||
|
|
||||||
// Ensure destiny account state
|
// Ensure destiny account state
|
||||||
resp, err = bankcli.QueryBalancesExec(val1.ClientCtx, account.GetAddress())
|
resp, err = bankcli.QueryBalancesExec(val1.ClientCtx, account.GetAddress())
|
||||||
|
@ -293,7 +291,7 @@ func (s *IntegrationTestSuite) TestCLISendGenerateSignAndBroadcast() {
|
||||||
|
|
||||||
err = val1.ClientCtx.JSONMarshaler.UnmarshalJSON(resp.Bytes(), &coins)
|
err = val1.ClientCtx.JSONMarshaler.UnmarshalJSON(resp.Bytes(), &coins)
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
s.Require().Equal(sendTokens, coins.AmountOf(cli.Denom))
|
s.Require().Equal(sendTokens, coins.AmountOf(s.cfg.BondDenom))
|
||||||
|
|
||||||
// Ensure origin account state
|
// Ensure origin account state
|
||||||
resp, err = bankcli.QueryBalancesExec(val1.ClientCtx, val1.Address)
|
resp, err = bankcli.QueryBalancesExec(val1.ClientCtx, val1.Address)
|
||||||
|
@ -301,7 +299,7 @@ func (s *IntegrationTestSuite) TestCLISendGenerateSignAndBroadcast() {
|
||||||
|
|
||||||
err = val1.ClientCtx.JSONMarshaler.UnmarshalJSON(resp.Bytes(), &coins)
|
err = val1.ClientCtx.JSONMarshaler.UnmarshalJSON(resp.Bytes(), &coins)
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
s.Require().Equal(sdk.NewInt(389999990), coins.AmountOf(cli.Denom))
|
s.Require().Equal(sdk.NewInt(389999990), coins.AmountOf(s.cfg.BondDenom))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *IntegrationTestSuite) TestCLIMultisignInsufficientCosigners() {
|
func (s *IntegrationTestSuite) TestCLIMultisignInsufficientCosigners() {
|
||||||
|
@ -330,7 +328,7 @@ func (s *IntegrationTestSuite) TestCLIMultisignInsufficientCosigners() {
|
||||||
val1.Address,
|
val1.Address,
|
||||||
multisigInfo.GetAddress(),
|
multisigInfo.GetAddress(),
|
||||||
sdk.NewCoins(
|
sdk.NewCoins(
|
||||||
sdk.NewInt64Coin(cli.Denom, 10),
|
sdk.NewInt64Coin(s.cfg.BondDenom, 10),
|
||||||
),
|
),
|
||||||
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
|
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
|
||||||
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock),
|
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock),
|
||||||
|
@ -339,8 +337,7 @@ func (s *IntegrationTestSuite) TestCLIMultisignInsufficientCosigners() {
|
||||||
)
|
)
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
|
|
||||||
err = waitForNextBlock(s.network)
|
s.Require().NoError(s.network.WaitForNextBlock())
|
||||||
s.Require().NoError(err)
|
|
||||||
|
|
||||||
// Generate multisig transaction.
|
// Generate multisig transaction.
|
||||||
multiGeneratedTx, err := bankcli.MsgSendExec(
|
multiGeneratedTx, err := bankcli.MsgSendExec(
|
||||||
|
@ -348,7 +345,7 @@ func (s *IntegrationTestSuite) TestCLIMultisignInsufficientCosigners() {
|
||||||
multisigInfo.GetAddress(),
|
multisigInfo.GetAddress(),
|
||||||
val1.Address,
|
val1.Address,
|
||||||
sdk.NewCoins(
|
sdk.NewCoins(
|
||||||
sdk.NewInt64Coin(cli.Denom, 5),
|
sdk.NewInt64Coin(s.cfg.BondDenom, 5),
|
||||||
),
|
),
|
||||||
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
|
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
|
||||||
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock),
|
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock),
|
||||||
|
@ -415,7 +412,7 @@ func (s *IntegrationTestSuite) TestCLIEncode() {
|
||||||
decodedTx, err := authtest.TxDecodeExec(val1.ClientCtx, trimmedBase64)
|
decodedTx, err := authtest.TxDecodeExec(val1.ClientCtx, trimmedBase64)
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
|
|
||||||
theTx := cli.UnmarshalStdTx(s.T(), val1.ClientCtx.JSONMarshaler, decodedTx.String())
|
theTx := unmarshalStdTx(s.T(), val1.ClientCtx.JSONMarshaler, decodedTx.String())
|
||||||
s.Require().Equal("deadbeef", theTx.Memo)
|
s.Require().Equal("deadbeef", theTx.Memo)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -440,7 +437,7 @@ func (s *IntegrationTestSuite) TestCLIMultisignSortSignatures() {
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
|
|
||||||
// Send coins from validator to multisig.
|
// Send coins from validator to multisig.
|
||||||
sendTokens := sdk.NewInt64Coin(cli.Denom, 10)
|
sendTokens := sdk.NewInt64Coin(s.cfg.BondDenom, 10)
|
||||||
_, err = bankcli.MsgSendExec(
|
_, err = bankcli.MsgSendExec(
|
||||||
val1.ClientCtx,
|
val1.ClientCtx,
|
||||||
val1.Address,
|
val1.Address,
|
||||||
|
@ -455,8 +452,7 @@ func (s *IntegrationTestSuite) TestCLIMultisignSortSignatures() {
|
||||||
)
|
)
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
|
|
||||||
err = waitForNextBlock(s.network)
|
s.Require().NoError(s.network.WaitForNextBlock())
|
||||||
s.Require().NoError(err)
|
|
||||||
|
|
||||||
resp, err := bankcli.QueryBalancesExec(val1.ClientCtx, multisigInfo.GetAddress())
|
resp, err := bankcli.QueryBalancesExec(val1.ClientCtx, multisigInfo.GetAddress())
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
|
@ -464,7 +460,7 @@ func (s *IntegrationTestSuite) TestCLIMultisignSortSignatures() {
|
||||||
var coins sdk.Coins
|
var coins sdk.Coins
|
||||||
err = val1.ClientCtx.JSONMarshaler.UnmarshalJSON(resp.Bytes(), &coins)
|
err = val1.ClientCtx.JSONMarshaler.UnmarshalJSON(resp.Bytes(), &coins)
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
s.Require().Equal(sendTokens.Amount, coins.AmountOf(cli.Denom))
|
s.Require().Equal(sendTokens.Amount, coins.AmountOf(s.cfg.BondDenom))
|
||||||
|
|
||||||
// Generate multisig transaction.
|
// Generate multisig transaction.
|
||||||
multiGeneratedTx, err := bankcli.MsgSendExec(
|
multiGeneratedTx, err := bankcli.MsgSendExec(
|
||||||
|
@ -472,7 +468,7 @@ func (s *IntegrationTestSuite) TestCLIMultisignSortSignatures() {
|
||||||
multisigInfo.GetAddress(),
|
multisigInfo.GetAddress(),
|
||||||
val1.Address,
|
val1.Address,
|
||||||
sdk.NewCoins(
|
sdk.NewCoins(
|
||||||
sdk.NewInt64Coin(cli.Denom, 5),
|
sdk.NewInt64Coin(s.cfg.BondDenom, 5),
|
||||||
),
|
),
|
||||||
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
|
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
|
||||||
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock),
|
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock),
|
||||||
|
@ -514,8 +510,7 @@ func (s *IntegrationTestSuite) TestCLIMultisignSortSignatures() {
|
||||||
_, err = authtest.TxBroadcastExec(val1.ClientCtx, signedTxFile.Name())
|
_, err = authtest.TxBroadcastExec(val1.ClientCtx, signedTxFile.Name())
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
|
|
||||||
err = waitForNextBlock(s.network)
|
s.Require().NoError(s.network.WaitForNextBlock())
|
||||||
s.Require().NoError(err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *IntegrationTestSuite) TestCLIMultisign() {
|
func (s *IntegrationTestSuite) TestCLIMultisign() {
|
||||||
|
@ -539,7 +534,7 @@ func (s *IntegrationTestSuite) TestCLIMultisign() {
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
|
|
||||||
// Send coins from validator to multisig.
|
// Send coins from validator to multisig.
|
||||||
sendTokens := sdk.NewInt64Coin(cli.Denom, 10)
|
sendTokens := sdk.NewInt64Coin(s.cfg.BondDenom, 10)
|
||||||
_, err = bankcli.MsgSendExec(
|
_, err = bankcli.MsgSendExec(
|
||||||
val1.ClientCtx,
|
val1.ClientCtx,
|
||||||
val1.Address,
|
val1.Address,
|
||||||
|
@ -553,8 +548,7 @@ func (s *IntegrationTestSuite) TestCLIMultisign() {
|
||||||
fmt.Sprintf("--gas=%d", flags.DefaultGasLimit),
|
fmt.Sprintf("--gas=%d", flags.DefaultGasLimit),
|
||||||
)
|
)
|
||||||
|
|
||||||
err = waitForNextBlock(s.network)
|
s.Require().NoError(s.network.WaitForNextBlock())
|
||||||
s.Require().NoError(err)
|
|
||||||
|
|
||||||
resp, err := bankcli.QueryBalancesExec(val1.ClientCtx, multisigInfo.GetAddress())
|
resp, err := bankcli.QueryBalancesExec(val1.ClientCtx, multisigInfo.GetAddress())
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
|
@ -562,7 +556,7 @@ func (s *IntegrationTestSuite) TestCLIMultisign() {
|
||||||
var coins sdk.Coins
|
var coins sdk.Coins
|
||||||
err = val1.ClientCtx.JSONMarshaler.UnmarshalJSON(resp.Bytes(), &coins)
|
err = val1.ClientCtx.JSONMarshaler.UnmarshalJSON(resp.Bytes(), &coins)
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
s.Require().Equal(sendTokens.Amount, coins.AmountOf(cli.Denom))
|
s.Require().Equal(sendTokens.Amount, coins.AmountOf(s.cfg.BondDenom))
|
||||||
|
|
||||||
// Generate multisig transaction.
|
// Generate multisig transaction.
|
||||||
multiGeneratedTx, err := bankcli.MsgSendExec(
|
multiGeneratedTx, err := bankcli.MsgSendExec(
|
||||||
|
@ -570,7 +564,7 @@ func (s *IntegrationTestSuite) TestCLIMultisign() {
|
||||||
multisigInfo.GetAddress(),
|
multisigInfo.GetAddress(),
|
||||||
val1.Address,
|
val1.Address,
|
||||||
sdk.NewCoins(
|
sdk.NewCoins(
|
||||||
sdk.NewInt64Coin(cli.Denom, 5),
|
sdk.NewInt64Coin(s.cfg.BondDenom, 5),
|
||||||
),
|
),
|
||||||
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
|
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
|
||||||
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock),
|
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock),
|
||||||
|
@ -618,15 +612,14 @@ func (s *IntegrationTestSuite) TestCLIMultisign() {
|
||||||
_, err = authtest.TxBroadcastExec(val1.ClientCtx, signedTxFile.Name())
|
_, err = authtest.TxBroadcastExec(val1.ClientCtx, signedTxFile.Name())
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
|
|
||||||
err = waitForNextBlock(s.network)
|
s.Require().NoError(s.network.WaitForNextBlock())
|
||||||
s.Require().NoError(err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGetBroadcastCommand_OfflineFlag(t *testing.T) {
|
func TestGetBroadcastCommand_OfflineFlag(t *testing.T) {
|
||||||
clientCtx := client.Context{}.WithOffline(true)
|
clientCtx := client.Context{}.WithOffline(true)
|
||||||
clientCtx = clientCtx.WithTxConfig(simappparams.MakeEncodingConfig().TxConfig)
|
clientCtx = clientCtx.WithTxConfig(simappparams.MakeEncodingConfig().TxConfig)
|
||||||
|
|
||||||
cmd := cli2.GetBroadcastCommand()
|
cmd := authcli.GetBroadcastCommand()
|
||||||
_ = testutil.ApplyMockIODiscardOutErr(cmd)
|
_ = testutil.ApplyMockIODiscardOutErr(cmd)
|
||||||
cmd.SetArgs([]string{fmt.Sprintf("--%s=true", flags.FlagOffline), ""})
|
cmd.SetArgs([]string{fmt.Sprintf("--%s=true", flags.FlagOffline), ""})
|
||||||
|
|
||||||
|
@ -640,7 +633,7 @@ func TestGetBroadcastCommand_WithoutOfflineFlag(t *testing.T) {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
ctx = context.WithValue(ctx, client.ClientContextKey, &clientCtx)
|
ctx = context.WithValue(ctx, client.ClientContextKey, &clientCtx)
|
||||||
|
|
||||||
cmd := cli2.GetBroadcastCommand()
|
cmd := authcli.GetBroadcastCommand()
|
||||||
|
|
||||||
testDir, cleanFunc := testutil.NewTestCaseDir(t)
|
testDir, cleanFunc := testutil.NewTestCaseDir(t)
|
||||||
t.Cleanup(cleanFunc)
|
t.Cleanup(cleanFunc)
|
||||||
|
@ -662,16 +655,7 @@ func TestIntegrationTestSuite(t *testing.T) {
|
||||||
suite.Run(t, new(IntegrationTestSuite))
|
suite.Run(t, new(IntegrationTestSuite))
|
||||||
}
|
}
|
||||||
|
|
||||||
func waitForNextBlock(network *network.Network) error {
|
func unmarshalStdTx(t require.TestingT, c codec.JSONMarshaler, s string) (stdTx authtypes.StdTx) {
|
||||||
lastBlock, err := network.LatestHeight()
|
require.Nil(t, c.UnmarshalJSON([]byte(s), &stdTx))
|
||||||
if err != nil {
|
return stdTx
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err = network.WaitForHeightWithTimeout(lastBlock+1, 10*time.Second)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,13 +7,7 @@ import (
|
||||||
|
|
||||||
clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli"
|
clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli"
|
||||||
|
|
||||||
"github.com/stretchr/testify/require"
|
|
||||||
|
|
||||||
"github.com/cosmos/cosmos-sdk/client"
|
"github.com/cosmos/cosmos-sdk/client"
|
||||||
clientkeys "github.com/cosmos/cosmos-sdk/client/keys"
|
|
||||||
"github.com/cosmos/cosmos-sdk/tests"
|
|
||||||
"github.com/cosmos/cosmos-sdk/tests/cli"
|
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
||||||
bankcli "github.com/cosmos/cosmos-sdk/x/bank/client/cli"
|
bankcli "github.com/cosmos/cosmos-sdk/x/bank/client/cli"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -30,28 +24,3 @@ func QueryBalancesExec(clientCtx client.Context, address fmt.Stringer, extraArgs
|
||||||
|
|
||||||
return clitestutil.ExecTestCLICmd(clientCtx, bankcli.GetBalancesCmd(), args)
|
return clitestutil.ExecTestCLICmd(clientCtx, bankcli.GetBalancesCmd(), args)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
// TODO: REMOVE ALL FUNCTIONS BELOW.
|
|
||||||
//
|
|
||||||
// REF: https://github.com/cosmos/cosmos-sdk/issues/6571
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
// TxSend is simcli tx send
|
|
||||||
func TxSend(f *cli.Fixtures, from string, to sdk.AccAddress, amount sdk.Coin, flags ...string) (bool, string, string) {
|
|
||||||
cmd := fmt.Sprintf("%s tx send --keyring-backend=test %s %s %s %v", f.SimdBinary, from, to, amount, f.Flags())
|
|
||||||
return cli.ExecuteWriteRetStdStreams(f.T, cli.AddFlags(cmd, flags), clientkeys.DefaultKeyPass)
|
|
||||||
}
|
|
||||||
|
|
||||||
// QueryBalances executes the bank query balances command for a given address and
|
|
||||||
// flag set.
|
|
||||||
func QueryBalances(f *cli.Fixtures, address sdk.AccAddress, flags ...string) sdk.Coins {
|
|
||||||
cmd := fmt.Sprintf("%s query bank balances %s %v", f.SimdBinary, address, f.Flags())
|
|
||||||
out, _ := tests.ExecuteT(f.T, cli.AddFlags(cmd, flags), "")
|
|
||||||
|
|
||||||
var balances sdk.Coins
|
|
||||||
|
|
||||||
require.NoError(f.T, f.Cdc.UnmarshalJSON([]byte(out), &balances), "out %v\n", out)
|
|
||||||
|
|
||||||
return balances
|
|
||||||
}
|
|
||||||
|
|
|
@ -123,6 +123,7 @@ $ %s tx distribution withdraw-rewards cosmosvaloper1gghjut3ccd8ay0zduzj64hwre2fx
|
||||||
|
|
||||||
cmd.Flags().Bool(FlagCommission, false, "Withdraw the validator's commission in addition to the rewards")
|
cmd.Flags().Bool(FlagCommission, false, "Withdraw the validator's commission in addition to the rewards")
|
||||||
flags.AddTxFlagsToCmd(cmd)
|
flags.AddTxFlagsToCmd(cmd)
|
||||||
|
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -167,6 +168,7 @@ $ %s tx distribution withdraw-all-rewards --from mykey
|
||||||
|
|
||||||
cmd.Flags().Int(FlagMaxMessagesPerTx, MaxMessagesPerTxDefault, "Limit the number of messages per tx (0 for unlimited)")
|
cmd.Flags().Int(FlagMaxMessagesPerTx, MaxMessagesPerTxDefault, "Limit the number of messages per tx (0 for unlimited)")
|
||||||
flags.AddTxFlagsToCmd(cmd)
|
flags.AddTxFlagsToCmd(cmd)
|
||||||
|
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -207,6 +209,7 @@ $ %s tx distribution set-withdraw-addr cosmos1gghjut3ccd8ay0zduzj64hwre2fxs9ld75
|
||||||
}
|
}
|
||||||
|
|
||||||
flags.AddTxFlagsToCmd(cmd)
|
flags.AddTxFlagsToCmd(cmd)
|
||||||
|
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -247,6 +250,7 @@ $ %s tx distribution fund-community-pool 100uatom --from mykey
|
||||||
}
|
}
|
||||||
|
|
||||||
flags.AddTxFlagsToCmd(cmd)
|
flags.AddTxFlagsToCmd(cmd)
|
||||||
|
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -315,5 +319,6 @@ Where proposal.json contains:
|
||||||
}
|
}
|
||||||
|
|
||||||
flags.AddTxFlagsToCmd(cmd)
|
flags.AddTxFlagsToCmd(cmd)
|
||||||
|
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,160 +1,164 @@
|
||||||
// +build cli_test
|
|
||||||
|
|
||||||
package cli_test
|
package cli_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/suite"
|
||||||
|
|
||||||
"github.com/cosmos/cosmos-sdk/tests"
|
"github.com/cosmos/cosmos-sdk/client"
|
||||||
"github.com/cosmos/cosmos-sdk/tests/cli"
|
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||||
|
"github.com/cosmos/cosmos-sdk/testutil"
|
||||||
|
"github.com/cosmos/cosmos-sdk/testutil/network"
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
banktestutils "github.com/cosmos/cosmos-sdk/x/bank/client/testutil"
|
"github.com/cosmos/cosmos-sdk/x/gov/client/cli"
|
||||||
"github.com/cosmos/cosmos-sdk/x/gov/client/testutil"
|
|
||||||
"github.com/cosmos/cosmos-sdk/x/gov/types"
|
"github.com/cosmos/cosmos-sdk/x/gov/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestCLISubmitProposal(t *testing.T) {
|
type IntegrationTestSuite struct {
|
||||||
t.SkipNow() // TODO: Bring back once viper is refactored.
|
suite.Suite
|
||||||
t.Parallel()
|
|
||||||
f := cli.InitFixtures(t)
|
|
||||||
|
|
||||||
// start simd server
|
cfg network.Config
|
||||||
proc := f.SDStart()
|
network *network.Network
|
||||||
t.Cleanup(func() { proc.Stop(false) })
|
}
|
||||||
|
|
||||||
testutil.QueryGovParamDeposit(f)
|
func (s *IntegrationTestSuite) SetupSuite() {
|
||||||
testutil.QueryGovParamVoting(f)
|
s.T().Log("setting up integration test suite")
|
||||||
testutil.QueryGovParamTallying(f)
|
|
||||||
|
cfg := network.DefaultConfig()
|
||||||
fooAddr := f.KeyAddress(cli.KeyFoo)
|
cfg.NumValidators = 1
|
||||||
|
|
||||||
startTokens := sdk.TokensFromConsensusPower(50)
|
s.cfg = cfg
|
||||||
require.Equal(t, startTokens, banktestutils.QueryBalances(f, fooAddr).AmountOf(sdk.DefaultBondDenom))
|
s.network = network.New(s.T(), cfg)
|
||||||
|
|
||||||
proposalsQuery := testutil.QueryGovProposals(f)
|
_, err := s.network.WaitForHeight(1)
|
||||||
require.Empty(t, proposalsQuery)
|
s.Require().NoError(err)
|
||||||
|
}
|
||||||
// Test submit generate only for submit proposal
|
|
||||||
proposalTokens := sdk.TokensFromConsensusPower(5)
|
func (s *IntegrationTestSuite) TearDownSuite() {
|
||||||
success, stdout, stderr := testutil.TxGovSubmitProposal(f,
|
s.T().Log("tearing down integration test suite")
|
||||||
fooAddr.String(), "Text", "Test", "test", sdk.NewCoin(cli.Denom, proposalTokens), "--generate-only", "-y")
|
s.network.Cleanup()
|
||||||
require.True(t, success)
|
}
|
||||||
require.Empty(t, stderr)
|
|
||||||
msg := cli.UnmarshalStdTx(t, f.Cdc, stdout)
|
func (s *IntegrationTestSuite) TestNewCmdSubmitProposal() {
|
||||||
require.NotZero(t, msg.Fee.Gas)
|
val := s.network.Validators[0]
|
||||||
require.Equal(t, len(msg.Msgs), 1)
|
|
||||||
require.Equal(t, 0, len(msg.GetSignatures()))
|
invalidPropFile, err := ioutil.TempFile(os.TempDir(), "invalid_text_proposal.*.json")
|
||||||
|
s.Require().NoError(err)
|
||||||
// Test --dry-run
|
defer os.Remove(invalidPropFile.Name())
|
||||||
success, _, _ = testutil.TxGovSubmitProposal(f, cli.KeyFoo, "Text", "Test", "test", sdk.NewCoin(cli.Denom, proposalTokens), "--dry-run")
|
|
||||||
require.True(t, success)
|
invalidProp := `{
|
||||||
|
"title": "",
|
||||||
// Create the proposal
|
"description": "Where is the title!?",
|
||||||
testutil.TxGovSubmitProposal(f, cli.KeyFoo, "Text", "Test", "test", sdk.NewCoin(cli.Denom, proposalTokens), "-y")
|
"type": "Text",
|
||||||
tests.WaitForNextNBlocksTM(1, f.Port)
|
"deposit": "-324foocoin"
|
||||||
|
}`
|
||||||
// Ensure transaction events can be queried
|
|
||||||
searchResult := f.QueryTxs(1, 50, "message.action=submit_proposal", fmt.Sprintf("message.sender=%s", fooAddr))
|
_, err = invalidPropFile.WriteString(invalidProp)
|
||||||
require.Len(t, searchResult.Txs, 1)
|
s.Require().NoError(err)
|
||||||
|
|
||||||
// Ensure deposit was deducted
|
validPropFile, err := ioutil.TempFile(os.TempDir(), "valid_text_proposal.*.json")
|
||||||
require.Equal(t, startTokens.Sub(proposalTokens), banktestutils.QueryBalances(f, fooAddr).AmountOf(cli.Denom))
|
s.Require().NoError(err)
|
||||||
|
defer os.Remove(validPropFile.Name())
|
||||||
// Ensure propsal is directly queryable
|
|
||||||
proposal1 := testutil.QueryGovProposal(f, 1)
|
validProp := fmt.Sprintf(`{
|
||||||
require.Equal(t, uint64(1), proposal1.ProposalID)
|
"title": "Text Proposal",
|
||||||
require.Equal(t, types.StatusDepositPeriod, proposal1.Status)
|
"description": "Hello, World!",
|
||||||
|
"type": "Text",
|
||||||
// Ensure query proposals returns properly
|
"deposit": "%s"
|
||||||
proposalsQuery = testutil.QueryGovProposals(f)
|
}`, sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(5431)))
|
||||||
require.Equal(t, uint64(1), proposalsQuery[0].ProposalID)
|
|
||||||
|
_, err = validPropFile.WriteString(validProp)
|
||||||
// Query the deposits on the proposal
|
s.Require().NoError(err)
|
||||||
deposit := testutil.QueryGovDeposit(f, 1, fooAddr)
|
|
||||||
require.Equal(t, proposalTokens, deposit.Amount.AmountOf(cli.Denom))
|
testCases := []struct {
|
||||||
|
name string
|
||||||
// Test deposit generate only
|
args []string
|
||||||
depositTokens := sdk.TokensFromConsensusPower(10)
|
expectErr bool
|
||||||
success, stdout, stderr = testutil.TxGovDeposit(f, 1, fooAddr.String(), sdk.NewCoin(cli.Denom, depositTokens), "--generate-only")
|
respType fmt.Stringer
|
||||||
require.True(t, success)
|
expectedCode uint32
|
||||||
require.Empty(t, stderr)
|
}{
|
||||||
msg = cli.UnmarshalStdTx(t, f.Cdc, stdout)
|
{
|
||||||
require.NotZero(t, msg.Fee.Gas)
|
"invalid proposal (file)",
|
||||||
require.Equal(t, len(msg.Msgs), 1)
|
[]string{
|
||||||
require.Equal(t, 0, len(msg.GetSignatures()))
|
fmt.Sprintf("--%s=%s", cli.FlagProposal, invalidPropFile.Name()),
|
||||||
|
fmt.Sprintf("--%s=%s", flags.FlagFrom, val.Address.String()),
|
||||||
// Run the deposit transaction
|
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
|
||||||
testutil.TxGovDeposit(f, 1, cli.KeyFoo, sdk.NewCoin(cli.Denom, depositTokens), "-y")
|
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()),
|
||||||
tests.WaitForNextNBlocksTM(1, f.Port)
|
},
|
||||||
|
true, nil, 0,
|
||||||
// test query deposit
|
},
|
||||||
deposits := testutil.QueryGovDeposits(f, 1)
|
{
|
||||||
require.Len(t, deposits, 1)
|
"invalid proposal",
|
||||||
require.Equal(t, proposalTokens.Add(depositTokens), deposits[0].Amount.AmountOf(cli.Denom))
|
[]string{
|
||||||
|
fmt.Sprintf("--%s='Where is the title!?'", cli.FlagDescription),
|
||||||
// Ensure querying the deposit returns the proper amount
|
fmt.Sprintf("--%s=%s", cli.FlagProposalType, types.ProposalTypeText),
|
||||||
deposit = testutil.QueryGovDeposit(f, 1, fooAddr)
|
fmt.Sprintf("--%s=%s", cli.FlagDeposit, sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(5431)).String()),
|
||||||
require.Equal(t, proposalTokens.Add(depositTokens), deposit.Amount.AmountOf(cli.Denom))
|
fmt.Sprintf("--%s=%s", flags.FlagFrom, val.Address.String()),
|
||||||
|
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
|
||||||
// Ensure events are set on the transaction
|
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()),
|
||||||
searchResult = f.QueryTxs(1, 50, "message.action=deposit", fmt.Sprintf("message.sender=%s", fooAddr))
|
},
|
||||||
require.Len(t, searchResult.Txs, 1)
|
true, nil, 0,
|
||||||
|
},
|
||||||
// Ensure account has expected amount of funds
|
{
|
||||||
require.Equal(t, startTokens.Sub(proposalTokens.Add(depositTokens)), banktestutils.QueryBalances(f, fooAddr).AmountOf(cli.Denom))
|
"valid transaction (file)",
|
||||||
|
[]string{
|
||||||
// Fetch the proposal and ensure it is now in the voting period
|
fmt.Sprintf("--%s=%s", cli.FlagProposal, validPropFile.Name()),
|
||||||
proposal1 = testutil.QueryGovProposal(f, 1)
|
fmt.Sprintf("--%s=%s", flags.FlagFrom, val.Address.String()),
|
||||||
require.Equal(t, uint64(1), proposal1.ProposalID)
|
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
|
||||||
require.Equal(t, types.StatusVotingPeriod, proposal1.Status)
|
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()),
|
||||||
|
},
|
||||||
// Test vote generate only
|
false, &sdk.TxResponse{}, 0,
|
||||||
success, stdout, stderr = testutil.TxGovVote(f, 1, types.OptionYes, fooAddr.String(), "--generate-only")
|
},
|
||||||
require.True(t, success)
|
{
|
||||||
require.Empty(t, stderr)
|
"valid transaction",
|
||||||
msg = cli.UnmarshalStdTx(t, f.Cdc, stdout)
|
[]string{
|
||||||
require.NotZero(t, msg.Fee.Gas)
|
fmt.Sprintf("--%s='Text Proposal'", cli.FlagTitle),
|
||||||
require.Equal(t, len(msg.Msgs), 1)
|
fmt.Sprintf("--%s='Where is the title!?'", cli.FlagDescription),
|
||||||
require.Equal(t, 0, len(msg.GetSignatures()))
|
fmt.Sprintf("--%s=%s", cli.FlagProposalType, types.ProposalTypeText),
|
||||||
|
fmt.Sprintf("--%s=%s", cli.FlagDeposit, sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(5431)).String()),
|
||||||
// Vote on the proposal
|
fmt.Sprintf("--%s=%s", flags.FlagFrom, val.Address.String()),
|
||||||
testutil.TxGovVote(f, 1, types.OptionYes, cli.KeyFoo, "-y")
|
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
|
||||||
tests.WaitForNextNBlocksTM(1, f.Port)
|
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()),
|
||||||
|
},
|
||||||
// Query the vote
|
false, &sdk.TxResponse{}, 0,
|
||||||
vote := testutil.QueryGovVote(f, 1, fooAddr)
|
},
|
||||||
require.Equal(t, uint64(1), vote.ProposalID)
|
}
|
||||||
require.Equal(t, types.OptionYes, vote.Option)
|
|
||||||
|
for _, tc := range testCases {
|
||||||
// Query the votes
|
tc := tc
|
||||||
votes := testutil.QueryGovVotes(f, 1)
|
|
||||||
require.Len(t, votes, 1)
|
s.Run(tc.name, func() {
|
||||||
require.Equal(t, uint64(1), votes[0].ProposalID)
|
cmd := cli.NewCmdSubmitProposal()
|
||||||
require.Equal(t, types.OptionYes, votes[0].Option)
|
_, out := testutil.ApplyMockIO(cmd)
|
||||||
|
|
||||||
// Ensure events are applied to voting transaction properly
|
clientCtx := val.ClientCtx.WithOutput(out)
|
||||||
searchResult = f.QueryTxs(1, 50, "message.action=vote", fmt.Sprintf("message.sender=%s", fooAddr))
|
|
||||||
require.Len(t, searchResult.Txs, 1)
|
ctx := context.Background()
|
||||||
|
ctx = context.WithValue(ctx, client.ClientContextKey, &clientCtx)
|
||||||
// Ensure no proposals in deposit period
|
|
||||||
proposalsQuery = testutil.QueryGovProposals(f, "--status=DepositPeriod")
|
out.Reset()
|
||||||
require.Empty(t, proposalsQuery)
|
cmd.SetArgs(tc.args)
|
||||||
|
|
||||||
// Ensure the proposal returns as in the voting period
|
s.Require().NoError(s.network.WaitForNextBlock())
|
||||||
proposalsQuery = testutil.QueryGovProposals(f, "--status=VotingPeriod")
|
|
||||||
require.Equal(t, uint64(1), proposalsQuery[0].ProposalID)
|
err := cmd.ExecuteContext(ctx)
|
||||||
|
if tc.expectErr {
|
||||||
// submit a second test proposal
|
s.Require().Error(err)
|
||||||
testutil.TxGovSubmitProposal(f, cli.KeyFoo, "Text", "Apples", "test", sdk.NewCoin(cli.Denom, proposalTokens), "-y")
|
} else {
|
||||||
tests.WaitForNextNBlocksTM(1, f.Port)
|
s.Require().NoError(err)
|
||||||
|
s.Require().NoError(clientCtx.JSONMarshaler.UnmarshalJSON(out.Bytes(), tc.respType), out.String())
|
||||||
// Test limit on proposals query
|
|
||||||
proposalsQuery = testutil.QueryGovProposals(f, "--limit=2")
|
txResp := tc.respType.(*sdk.TxResponse)
|
||||||
require.Len(t, proposalsQuery, 2)
|
s.Require().Equal(tc.expectedCode, txResp.Code, out.String())
|
||||||
require.Equal(t, uint64(1), proposalsQuery[0].ProposalID)
|
}
|
||||||
|
})
|
||||||
f.Cleanup()
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestIntegrationTestSuite(t *testing.T) {
|
||||||
|
suite.Run(t, new(IntegrationTestSuite))
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,7 @@ func parseSubmitProposalFlags(fs *pflag.FlagSet) (*proposal, error) {
|
||||||
proposalFile, _ := fs.GetString(FlagProposal)
|
proposalFile, _ := fs.GetString(FlagProposal)
|
||||||
|
|
||||||
if proposalFile == "" {
|
if proposalFile == "" {
|
||||||
proposalType, _ := fs.GetString(flagProposalType)
|
proposalType, _ := fs.GetString(FlagProposalType)
|
||||||
|
|
||||||
proposal.Title, _ = fs.GetString(FlagTitle)
|
proposal.Title, _ = fs.GetString(FlagTitle)
|
||||||
proposal.Description, _ = fs.GetString(FlagDescription)
|
proposal.Description, _ = fs.GetString(FlagDescription)
|
||||||
|
|
|
@ -55,7 +55,7 @@ func TestParseSubmitProposalFlags(t *testing.T) {
|
||||||
fs.Set(FlagProposal, "")
|
fs.Set(FlagProposal, "")
|
||||||
fs.Set(FlagTitle, proposal1.Title)
|
fs.Set(FlagTitle, proposal1.Title)
|
||||||
fs.Set(FlagDescription, proposal1.Description)
|
fs.Set(FlagDescription, proposal1.Description)
|
||||||
fs.Set(flagProposalType, proposal1.Type)
|
fs.Set(FlagProposalType, proposal1.Type)
|
||||||
fs.Set(FlagDeposit, proposal1.Deposit)
|
fs.Set(FlagDeposit, proposal1.Deposit)
|
||||||
proposal2, err := parseSubmitProposalFlags(fs)
|
proposal2, err := parseSubmitProposalFlags(fs)
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,7 @@ import (
|
||||||
const (
|
const (
|
||||||
FlagTitle = "title"
|
FlagTitle = "title"
|
||||||
FlagDescription = "description"
|
FlagDescription = "description"
|
||||||
flagProposalType = "type"
|
FlagProposalType = "type"
|
||||||
FlagDeposit = "deposit"
|
FlagDeposit = "deposit"
|
||||||
flagVoter = "voter"
|
flagVoter = "voter"
|
||||||
flagDepositor = "depositor"
|
flagDepositor = "depositor"
|
||||||
|
@ -41,7 +41,7 @@ type proposal struct {
|
||||||
var ProposalFlags = []string{
|
var ProposalFlags = []string{
|
||||||
FlagTitle,
|
FlagTitle,
|
||||||
FlagDescription,
|
FlagDescription,
|
||||||
flagProposalType,
|
FlagProposalType,
|
||||||
FlagDeposit,
|
FlagDeposit,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -110,7 +110,7 @@ $ %s tx gov submit-proposal --title="Test Proposal" --description="My awesome pr
|
||||||
|
|
||||||
proposal, err := parseSubmitProposalFlags(cmd.Flags())
|
proposal, err := parseSubmitProposalFlags(cmd.Flags())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return fmt.Errorf("failed to parse proposal: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
amount, err := sdk.ParseCoins(proposal.Deposit)
|
amount, err := sdk.ParseCoins(proposal.Deposit)
|
||||||
|
@ -120,24 +120,24 @@ $ %s tx gov submit-proposal --title="Test Proposal" --description="My awesome pr
|
||||||
|
|
||||||
content := types.ContentFromProposalType(proposal.Title, proposal.Description, proposal.Type)
|
content := types.ContentFromProposalType(proposal.Title, proposal.Description, proposal.Type)
|
||||||
|
|
||||||
msg, err := types.NewMsgSubmitProposal(content, amount, clientCtx.FromAddress)
|
msg, err := types.NewMsgSubmitProposal(content, amount, clientCtx.GetFromAddress())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return fmt.Errorf("invalid message: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = msg.ValidateBasic(); err != nil {
|
if err = msg.ValidateBasic(); err != nil {
|
||||||
return err
|
return fmt.Errorf("message validation failed: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return tx.GenerateOrBroadcastTx(clientCtx, msg)
|
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd.Flags().String(FlagTitle, "", "title of proposal")
|
cmd.Flags().String(FlagTitle, "", "The proposal title")
|
||||||
cmd.Flags().String(FlagDescription, "", "description of proposal")
|
cmd.Flags().String(FlagDescription, "", "The proposal description")
|
||||||
cmd.Flags().String(flagProposalType, "", "proposalType of proposal, types: text/parameter_change/software_upgrade")
|
cmd.Flags().String(FlagProposalType, "", "The proposal Type")
|
||||||
cmd.Flags().String(FlagDeposit, "", "deposit of proposal")
|
cmd.Flags().String(FlagDeposit, "", "The proposal deposit")
|
||||||
cmd.Flags().String(FlagProposal, "", "proposal file path (if this path is given, other proposal flags are ignored)")
|
cmd.Flags().String(FlagProposal, "", "Proposal file path (if this path is given, other proposal flags are ignored)")
|
||||||
flags.AddTxFlagsToCmd(cmd)
|
flags.AddTxFlagsToCmd(cmd)
|
||||||
|
|
||||||
return cmd
|
return cmd
|
||||||
|
@ -187,7 +187,7 @@ $ %s tx gov deposit 1 10stake --from mykey
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return tx.GenerateOrBroadcastTx(clientCtx, msg)
|
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -242,7 +242,7 @@ $ %s tx gov vote 1 yes --from mykey
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return tx.GenerateOrBroadcastTx(clientCtx, msg)
|
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,173 +0,0 @@
|
||||||
package testutil
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/stretchr/testify/require"
|
|
||||||
|
|
||||||
clientkeys "github.com/cosmos/cosmos-sdk/client/keys"
|
|
||||||
"github.com/cosmos/cosmos-sdk/tests"
|
|
||||||
"github.com/cosmos/cosmos-sdk/tests/cli"
|
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
||||||
"github.com/cosmos/cosmos-sdk/x/gov/types"
|
|
||||||
)
|
|
||||||
|
|
||||||
//___________________________________________________________________________________
|
|
||||||
// simcli query gov
|
|
||||||
|
|
||||||
// QueryGovParamDeposit is simcli query gov param deposit
|
|
||||||
func QueryGovParamDeposit(f *cli.Fixtures) types.DepositParams {
|
|
||||||
cmd := fmt.Sprintf("%s query gov param deposit %s", f.SimdBinary, f.Flags())
|
|
||||||
out, _ := tests.ExecuteT(f.T, cmd, "")
|
|
||||||
var depositParam types.DepositParams
|
|
||||||
|
|
||||||
err := f.Cdc.UnmarshalJSON([]byte(out), &depositParam)
|
|
||||||
require.NoError(f.T, err, "out %v\n, err %v", out, err)
|
|
||||||
return depositParam
|
|
||||||
}
|
|
||||||
|
|
||||||
// QueryGovParamVoting is simcli query gov param voting
|
|
||||||
func QueryGovParamVoting(f *cli.Fixtures) types.VotingParams {
|
|
||||||
cmd := fmt.Sprintf("%s query gov param voting %s", f.SimdBinary, f.Flags())
|
|
||||||
out, _ := tests.ExecuteT(f.T, cmd, "")
|
|
||||||
var votingParam types.VotingParams
|
|
||||||
|
|
||||||
err := f.Cdc.UnmarshalJSON([]byte(out), &votingParam)
|
|
||||||
require.NoError(f.T, err, "out %v\n, err %v", out, err)
|
|
||||||
return votingParam
|
|
||||||
}
|
|
||||||
|
|
||||||
// QueryGovParamTallying is simcli query gov param tallying
|
|
||||||
func QueryGovParamTallying(f *cli.Fixtures) types.TallyParams {
|
|
||||||
cmd := fmt.Sprintf("%s query gov param tallying %s", f.SimdBinary, f.Flags())
|
|
||||||
out, _ := tests.ExecuteT(f.T, cmd, "")
|
|
||||||
var tallyingParam types.TallyParams
|
|
||||||
|
|
||||||
err := f.Cdc.UnmarshalJSON([]byte(out), &tallyingParam)
|
|
||||||
require.NoError(f.T, err, "out %v\n, err %v", out, err)
|
|
||||||
return tallyingParam
|
|
||||||
}
|
|
||||||
|
|
||||||
// QueryGovProposal is simcli query gov proposal
|
|
||||||
func QueryGovProposal(f *cli.Fixtures, proposalID int, flags ...string) types.Proposal {
|
|
||||||
cmd := fmt.Sprintf("%s query gov proposal %d %v", f.SimdBinary, proposalID, f.Flags())
|
|
||||||
out, _ := tests.ExecuteT(f.T, cli.AddFlags(cmd, flags), "")
|
|
||||||
var proposal types.Proposal
|
|
||||||
|
|
||||||
err := f.Cdc.UnmarshalJSON([]byte(out), &proposal)
|
|
||||||
require.NoError(f.T, err, "out %v\n, err %v", out, err)
|
|
||||||
return proposal
|
|
||||||
}
|
|
||||||
|
|
||||||
// QueryGovProposals is simcli query gov proposals
|
|
||||||
func QueryGovProposals(f *cli.Fixtures, flags ...string) types.Proposals {
|
|
||||||
cmd := fmt.Sprintf("%s query gov proposals %v", f.SimdBinary, f.Flags())
|
|
||||||
stdout, stderr := tests.ExecuteT(f.T, cli.AddFlags(cmd, flags), "")
|
|
||||||
if strings.Contains(stderr, "no matching proposals found") {
|
|
||||||
return types.Proposals{}
|
|
||||||
}
|
|
||||||
require.Empty(f.T, stderr)
|
|
||||||
var out types.Proposals
|
|
||||||
|
|
||||||
err := f.Cdc.UnmarshalJSON([]byte(stdout), &out)
|
|
||||||
require.NoError(f.T, err)
|
|
||||||
return out
|
|
||||||
}
|
|
||||||
|
|
||||||
// QueryGovVote is simcli query gov vote
|
|
||||||
func QueryGovVote(f *cli.Fixtures, proposalID int, voter sdk.AccAddress, flags ...string) types.Vote {
|
|
||||||
cmd := fmt.Sprintf("%s query gov vote %d %s %v", f.SimdBinary, proposalID, voter, f.Flags())
|
|
||||||
out, _ := tests.ExecuteT(f.T, cli.AddFlags(cmd, flags), "")
|
|
||||||
var vote types.Vote
|
|
||||||
|
|
||||||
err := f.Cdc.UnmarshalJSON([]byte(out), &vote)
|
|
||||||
require.NoError(f.T, err, "out %v\n, err %v", out, err)
|
|
||||||
return vote
|
|
||||||
}
|
|
||||||
|
|
||||||
// QueryGovVotes is simcli query gov votes
|
|
||||||
func QueryGovVotes(f *cli.Fixtures, proposalID int, flags ...string) []types.Vote {
|
|
||||||
cmd := fmt.Sprintf("%s query gov votes %d %v", f.SimdBinary, proposalID, f.Flags())
|
|
||||||
out, _ := tests.ExecuteT(f.T, cli.AddFlags(cmd, flags), "")
|
|
||||||
var votes []types.Vote
|
|
||||||
|
|
||||||
err := f.Cdc.UnmarshalJSON([]byte(out), &votes)
|
|
||||||
require.NoError(f.T, err, "out %v\n, err %v", out, err)
|
|
||||||
return votes
|
|
||||||
}
|
|
||||||
|
|
||||||
// QueryGovDeposit is simcli query gov deposit
|
|
||||||
func QueryGovDeposit(f *cli.Fixtures, proposalID int, depositor sdk.AccAddress, flags ...string) types.Deposit {
|
|
||||||
cmd := fmt.Sprintf("%s query gov deposit %d %s %v", f.SimdBinary, proposalID, depositor, f.Flags())
|
|
||||||
out, _ := tests.ExecuteT(f.T, cli.AddFlags(cmd, flags), "")
|
|
||||||
var deposit types.Deposit
|
|
||||||
|
|
||||||
err := f.Cdc.UnmarshalJSON([]byte(out), &deposit)
|
|
||||||
require.NoError(f.T, err, "out %v\n, err %v", out, err)
|
|
||||||
return deposit
|
|
||||||
}
|
|
||||||
|
|
||||||
// QueryGovDeposits is simcli query gov deposits
|
|
||||||
func QueryGovDeposits(f *cli.Fixtures, propsalID int, flags ...string) []types.Deposit {
|
|
||||||
cmd := fmt.Sprintf("%s query gov deposits %d %v", f.SimdBinary, propsalID, f.Flags())
|
|
||||||
out, _ := tests.ExecuteT(f.T, cli.AddFlags(cmd, flags), "")
|
|
||||||
var deposits []types.Deposit
|
|
||||||
|
|
||||||
err := f.Cdc.UnmarshalJSON([]byte(out), &deposits)
|
|
||||||
require.NoError(f.T, err, "out %v\n, err %v", out, err)
|
|
||||||
return deposits
|
|
||||||
}
|
|
||||||
|
|
||||||
//___________________________________________________________________________________
|
|
||||||
// simcli tx gov
|
|
||||||
|
|
||||||
// TxGovSubmitProposal is simcli tx gov submit-proposal
|
|
||||||
func TxGovSubmitProposal(f *cli.Fixtures, from, typ, title, description string, deposit sdk.Coin, flags ...string) (bool, string, string) {
|
|
||||||
cmd := fmt.Sprintf("%s tx gov submit-proposal %v --keyring-backend=test --from=%s --type=%s",
|
|
||||||
f.SimdBinary, f.Flags(), from, typ)
|
|
||||||
cmd += fmt.Sprintf(" --title=%s --description=%s --deposit=%s", title, description, deposit)
|
|
||||||
return cli.ExecuteWriteRetStdStreams(f.T, cli.AddFlags(cmd, flags), clientkeys.DefaultKeyPass)
|
|
||||||
}
|
|
||||||
|
|
||||||
// TxGovDeposit is simcli tx gov deposit
|
|
||||||
func TxGovDeposit(f *cli.Fixtures, proposalID int, from string, amount sdk.Coin, flags ...string) (bool, string, string) {
|
|
||||||
cmd := fmt.Sprintf("%s tx gov deposit %d %s --keyring-backend=test --from=%s %v",
|
|
||||||
f.SimdBinary, proposalID, amount, from, f.Flags())
|
|
||||||
return cli.ExecuteWriteRetStdStreams(f.T, cli.AddFlags(cmd, flags), clientkeys.DefaultKeyPass)
|
|
||||||
}
|
|
||||||
|
|
||||||
// TxGovVote is simcli tx gov vote
|
|
||||||
func TxGovVote(f *cli.Fixtures, proposalID int, option types.VoteOption, from string, flags ...string) (bool, string, string) {
|
|
||||||
cmd := fmt.Sprintf("%s tx gov vote %d %s --keyring-backend=test --from=%s %v",
|
|
||||||
f.SimdBinary, proposalID, option, from, f.Flags())
|
|
||||||
return cli.ExecuteWriteRetStdStreams(f.T, cli.AddFlags(cmd, flags), clientkeys.DefaultKeyPass)
|
|
||||||
}
|
|
||||||
|
|
||||||
// TxGovSubmitParamChangeProposal executes a CLI parameter change proposal
|
|
||||||
// submission.
|
|
||||||
func TxGovSubmitParamChangeProposal(f *cli.Fixtures,
|
|
||||||
from, proposalPath string, deposit sdk.Coin, flags ...string,
|
|
||||||
) (bool, string, string) {
|
|
||||||
|
|
||||||
cmd := fmt.Sprintf(
|
|
||||||
"%s tx gov submit-proposal param-change %s --keyring-backend=test --from=%s %v",
|
|
||||||
f.SimdBinary, proposalPath, from, f.Flags(),
|
|
||||||
)
|
|
||||||
|
|
||||||
return cli.ExecuteWriteRetStdStreams(f.T, cli.AddFlags(cmd, flags), clientkeys.DefaultKeyPass)
|
|
||||||
}
|
|
||||||
|
|
||||||
// TxGovSubmitCommunityPoolSpendProposal executes a CLI community pool spend proposal
|
|
||||||
// submission.
|
|
||||||
func TxGovSubmitCommunityPoolSpendProposal(f *cli.Fixtures,
|
|
||||||
from, proposalPath string, deposit sdk.Coin, flags ...string,
|
|
||||||
) (bool, string, string) {
|
|
||||||
|
|
||||||
cmd := fmt.Sprintf(
|
|
||||||
"%s tx gov submit-proposal community-pool-spend %s --keyring-backend=test --from=%s %v",
|
|
||||||
f.SimdBinary, proposalPath, from, f.Flags(),
|
|
||||||
)
|
|
||||||
|
|
||||||
return cli.ExecuteWriteRetStdStreams(f.T, cli.AddFlags(cmd, flags), clientkeys.DefaultKeyPass)
|
|
||||||
}
|
|
|
@ -1,30 +1,190 @@
|
||||||
// +build cli_test
|
|
||||||
|
|
||||||
package cli_test
|
package cli_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/suite"
|
||||||
|
tmcli "github.com/tendermint/tendermint/libs/cli"
|
||||||
|
|
||||||
"github.com/cosmos/cosmos-sdk/tests/cli"
|
"github.com/cosmos/cosmos-sdk/client"
|
||||||
"github.com/cosmos/cosmos-sdk/x/mint/client/testutil"
|
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||||
|
"github.com/cosmos/cosmos-sdk/testutil"
|
||||||
|
testnet "github.com/cosmos/cosmos-sdk/testutil/network"
|
||||||
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
|
"github.com/cosmos/cosmos-sdk/x/mint/client/cli"
|
||||||
|
minttypes "github.com/cosmos/cosmos-sdk/x/mint/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestCLIMintQueries(t *testing.T) {
|
type IntegrationTestSuite struct {
|
||||||
t.SkipNow() // TODO: Bring back once viper is refactored.
|
suite.Suite
|
||||||
t.Parallel()
|
|
||||||
f := cli.InitFixtures(t)
|
|
||||||
|
|
||||||
proc := f.SDStart()
|
cfg testnet.Config
|
||||||
t.Cleanup(func() { proc.Stop(false) })
|
network *testnet.Network
|
||||||
|
}
|
||||||
params := testutil.QueryMintingParams(f)
|
|
||||||
require.NotEmpty(t, params)
|
func (s *IntegrationTestSuite) SetupSuite() {
|
||||||
|
s.T().Log("setting up integration test suite")
|
||||||
inflation := testutil.QueryInflation(f)
|
|
||||||
require.False(t, inflation.IsZero())
|
cfg := testnet.DefaultConfig()
|
||||||
|
genesisState := cfg.GenesisState
|
||||||
annualProvisions := testutil.QueryAnnualProvisions(f)
|
cfg.NumValidators = 1
|
||||||
require.False(t, annualProvisions.IsZero())
|
|
||||||
|
var mintData minttypes.GenesisState
|
||||||
|
s.Require().NoError(cfg.Codec.UnmarshalJSON(genesisState[minttypes.ModuleName], &mintData))
|
||||||
|
|
||||||
|
inflation := sdk.MustNewDecFromStr("1.0")
|
||||||
|
mintData.Minter.Inflation = inflation
|
||||||
|
mintData.Params.InflationMin = inflation
|
||||||
|
mintData.Params.InflationMax = inflation
|
||||||
|
|
||||||
|
mintDataBz, err := cfg.Codec.MarshalJSON(mintData)
|
||||||
|
s.Require().NoError(err)
|
||||||
|
genesisState[minttypes.ModuleName] = mintDataBz
|
||||||
|
cfg.GenesisState = genesisState
|
||||||
|
|
||||||
|
s.cfg = cfg
|
||||||
|
s.network = testnet.New(s.T(), cfg)
|
||||||
|
|
||||||
|
_, err = s.network.WaitForHeight(1)
|
||||||
|
s.Require().NoError(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *IntegrationTestSuite) TearDownSuite() {
|
||||||
|
s.T().Log("tearing down integration test suite")
|
||||||
|
s.network.Cleanup()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *IntegrationTestSuite) TestGetCmdQueryParams() {
|
||||||
|
val := s.network.Validators[0]
|
||||||
|
|
||||||
|
testCases := []struct {
|
||||||
|
name string
|
||||||
|
args []string
|
||||||
|
expectedOutput string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
"default output",
|
||||||
|
[]string{fmt.Sprintf("--%s=1", flags.FlagHeight)},
|
||||||
|
`{"mint_denom":"stake","inflation_rate_change":"0.130000000000000000","inflation_max":"1.000000000000000000","inflation_min":"1.000000000000000000","goal_bonded":"0.670000000000000000","blocks_per_year":"6311520"}`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"text output",
|
||||||
|
[]string{fmt.Sprintf("--%s=1", flags.FlagHeight), fmt.Sprintf("--%s=text", tmcli.OutputFlag)},
|
||||||
|
`blocks_per_year: "6311520"
|
||||||
|
goal_bonded: "0.670000000000000000"
|
||||||
|
inflation_max: "1.000000000000000000"
|
||||||
|
inflation_min: "1.000000000000000000"
|
||||||
|
inflation_rate_change: "0.130000000000000000"
|
||||||
|
mint_denom: stake`,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tc := range testCases {
|
||||||
|
tc := tc
|
||||||
|
|
||||||
|
s.Run(tc.name, func() {
|
||||||
|
cmd := cli.GetCmdQueryParams()
|
||||||
|
_, out := testutil.ApplyMockIO(cmd)
|
||||||
|
|
||||||
|
clientCtx := val.ClientCtx.WithOutput(out)
|
||||||
|
|
||||||
|
ctx := context.Background()
|
||||||
|
ctx = context.WithValue(ctx, client.ClientContextKey, &clientCtx)
|
||||||
|
|
||||||
|
out.Reset()
|
||||||
|
cmd.SetArgs(tc.args)
|
||||||
|
|
||||||
|
s.Require().NoError(cmd.ExecuteContext(ctx))
|
||||||
|
s.Require().Equal(tc.expectedOutput, strings.TrimSpace(out.String()))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *IntegrationTestSuite) TestGetCmdQueryInflation() {
|
||||||
|
val := s.network.Validators[0]
|
||||||
|
|
||||||
|
testCases := []struct {
|
||||||
|
name string
|
||||||
|
args []string
|
||||||
|
expectedOutput string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
"default output",
|
||||||
|
[]string{fmt.Sprintf("--%s=1", flags.FlagHeight)},
|
||||||
|
`"1.000000000000000000"`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"text output",
|
||||||
|
[]string{fmt.Sprintf("--%s=1", flags.FlagHeight), fmt.Sprintf("--%s=text", tmcli.OutputFlag)},
|
||||||
|
`"1.000000000000000000"`,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tc := range testCases {
|
||||||
|
tc := tc
|
||||||
|
|
||||||
|
s.Run(tc.name, func() {
|
||||||
|
cmd := cli.GetCmdQueryInflation()
|
||||||
|
_, out := testutil.ApplyMockIO(cmd)
|
||||||
|
|
||||||
|
clientCtx := val.ClientCtx.WithOutput(out)
|
||||||
|
|
||||||
|
ctx := context.Background()
|
||||||
|
ctx = context.WithValue(ctx, client.ClientContextKey, &clientCtx)
|
||||||
|
|
||||||
|
out.Reset()
|
||||||
|
cmd.SetArgs(tc.args)
|
||||||
|
|
||||||
|
s.Require().NoError(cmd.ExecuteContext(ctx))
|
||||||
|
s.Require().Equal(tc.expectedOutput, strings.TrimSpace(out.String()))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *IntegrationTestSuite) TestGetCmdQueryAnnualProvisions() {
|
||||||
|
val := s.network.Validators[0]
|
||||||
|
|
||||||
|
testCases := []struct {
|
||||||
|
name string
|
||||||
|
args []string
|
||||||
|
expectedOutput string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
"default output",
|
||||||
|
[]string{fmt.Sprintf("--%s=1", flags.FlagHeight)},
|
||||||
|
`"500000000.000000000000000000"`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"text output",
|
||||||
|
[]string{fmt.Sprintf("--%s=1", flags.FlagHeight), fmt.Sprintf("--%s=text", tmcli.OutputFlag)},
|
||||||
|
`"500000000.000000000000000000"`,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tc := range testCases {
|
||||||
|
tc := tc
|
||||||
|
|
||||||
|
s.Run(tc.name, func() {
|
||||||
|
cmd := cli.GetCmdQueryAnnualProvisions()
|
||||||
|
_, out := testutil.ApplyMockIO(cmd)
|
||||||
|
|
||||||
|
clientCtx := val.ClientCtx.WithOutput(out)
|
||||||
|
|
||||||
|
ctx := context.Background()
|
||||||
|
ctx = context.WithValue(ctx, client.ClientContextKey, &clientCtx)
|
||||||
|
|
||||||
|
out.Reset()
|
||||||
|
cmd.SetArgs(tc.args)
|
||||||
|
|
||||||
|
s.Require().NoError(cmd.ExecuteContext(ctx))
|
||||||
|
s.Require().Equal(tc.expectedOutput, strings.TrimSpace(out.String()))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestIntegrationTestSuite(t *testing.T) {
|
||||||
|
suite.Run(t, new(IntegrationTestSuite))
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,7 +52,7 @@ func GetCmdQueryParams() *cobra.Command {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return clientCtx.PrintOutput(res.Params)
|
return clientCtx.PrintOutput(res.GetParams())
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,45 +0,0 @@
|
||||||
package testutil
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"github.com/stretchr/testify/require"
|
|
||||||
|
|
||||||
"github.com/cosmos/cosmos-sdk/tests"
|
|
||||||
"github.com/cosmos/cosmos-sdk/tests/cli"
|
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
||||||
"github.com/cosmos/cosmos-sdk/x/mint/types"
|
|
||||||
)
|
|
||||||
|
|
||||||
// QueryMintingParams returns the current minting parameters
|
|
||||||
func QueryMintingParams(f *cli.Fixtures, flags ...string) types.Params {
|
|
||||||
cmd := fmt.Sprintf("%s query mint params %v", f.SimdBinary, f.Flags())
|
|
||||||
out, errStr := tests.ExecuteT(f.T, cli.AddFlags(cmd, flags), "")
|
|
||||||
require.Empty(f.T, errStr)
|
|
||||||
|
|
||||||
var params types.Params
|
|
||||||
require.NoError(f.T, f.Cdc.UnmarshalJSON([]byte(out), ¶ms))
|
|
||||||
return params
|
|
||||||
}
|
|
||||||
|
|
||||||
// QueryInflation returns the current minting inflation value
|
|
||||||
func QueryInflation(f *cli.Fixtures, flags ...string) sdk.Dec {
|
|
||||||
cmd := fmt.Sprintf("%s query mint inflation %v", f.SimdBinary, f.Flags())
|
|
||||||
out, errStr := tests.ExecuteT(f.T, cli.AddFlags(cmd, flags), "")
|
|
||||||
require.Empty(f.T, errStr)
|
|
||||||
|
|
||||||
var inflation sdk.Dec
|
|
||||||
require.NoError(f.T, f.Cdc.UnmarshalJSON([]byte(out), &inflation))
|
|
||||||
return inflation
|
|
||||||
}
|
|
||||||
|
|
||||||
// QueryAnnualProvisions returns the current minting annual provisions value
|
|
||||||
func QueryAnnualProvisions(f *cli.Fixtures, flags ...string) sdk.Dec {
|
|
||||||
cmd := fmt.Sprintf("%s query mint annual-provisions %v", f.SimdBinary, f.Flags())
|
|
||||||
out, errStr := tests.ExecuteT(f.T, cli.AddFlags(cmd, flags), "")
|
|
||||||
require.Empty(f.T, errStr)
|
|
||||||
|
|
||||||
var annualProvisions sdk.Dec
|
|
||||||
require.NoError(f.T, f.Cdc.UnmarshalJSON([]byte(out), &annualProvisions))
|
|
||||||
return annualProvisions
|
|
||||||
}
|
|
|
@ -6,7 +6,6 @@ import (
|
||||||
"math/rand"
|
"math/rand"
|
||||||
|
|
||||||
"github.com/gogo/protobuf/grpc"
|
"github.com/gogo/protobuf/grpc"
|
||||||
|
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
abci "github.com/tendermint/tendermint/abci/types"
|
abci "github.com/tendermint/tendermint/abci/types"
|
||||||
|
@ -113,9 +112,11 @@ func (am AppModule) NewQuerierHandler() sdk.Querier {
|
||||||
return keeper.NewQuerier(am.keeper)
|
return keeper.NewQuerier(am.keeper)
|
||||||
}
|
}
|
||||||
|
|
||||||
// RegisterQueryService registers a GRPC query service to respond to the
|
// RegisterQueryService registers a gRPC query service to respond to the
|
||||||
// module-specific GRPC queries.
|
// module-specific gRPC queries.
|
||||||
func (am AppModule) RegisterQueryService(grpc.Server) {}
|
func (am AppModule) RegisterQueryService(server grpc.Server) {
|
||||||
|
types.RegisterQueryServer(server, am.keeper)
|
||||||
|
}
|
||||||
|
|
||||||
// InitGenesis performs genesis initialization for the mint module. It returns
|
// InitGenesis performs genesis initialization for the mint module. It returns
|
||||||
// no validator updates.
|
// no validator updates.
|
||||||
|
|
|
@ -102,8 +102,8 @@ func (am AppModule) NewQuerierHandler() sdk.Querier {
|
||||||
return keeper.NewQuerier(am.keeper)
|
return keeper.NewQuerier(am.keeper)
|
||||||
}
|
}
|
||||||
|
|
||||||
// RegisterQueryService registers a GRPC query service to respond to the
|
// RegisterQueryService registers a gRPC query service to respond to the
|
||||||
// module-specific GRPC queries.
|
// module-specific gRPC queries.
|
||||||
func (am AppModule) RegisterQueryService(server grpc.Server) {
|
func (am AppModule) RegisterQueryService(server grpc.Server) {
|
||||||
proposal.RegisterQueryServer(server, am.keeper)
|
proposal.RegisterQueryServer(server, am.keeper)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,35 +0,0 @@
|
||||||
package testutil
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"github.com/stretchr/testify/require"
|
|
||||||
|
|
||||||
"github.com/cosmos/cosmos-sdk/tests"
|
|
||||||
"github.com/cosmos/cosmos-sdk/tests/cli"
|
|
||||||
"github.com/cosmos/cosmos-sdk/x/slashing/types"
|
|
||||||
)
|
|
||||||
|
|
||||||
// QuerySigningInfo returns the signing info for a validator
|
|
||||||
func QuerySigningInfo(f *cli.Fixtures, val string) types.ValidatorSigningInfo {
|
|
||||||
cmd := fmt.Sprintf("%s query slashing signing-info %s %s", f.SimdBinary, val, f.Flags())
|
|
||||||
res, errStr := tests.ExecuteT(f.T, cmd, "")
|
|
||||||
require.Empty(f.T, errStr)
|
|
||||||
|
|
||||||
var sinfo types.ValidatorSigningInfo
|
|
||||||
err := f.Cdc.UnmarshalJSON([]byte(res), &sinfo)
|
|
||||||
require.NoError(f.T, err)
|
|
||||||
return sinfo
|
|
||||||
}
|
|
||||||
|
|
||||||
// QuerySlashingParams returns query slashing params
|
|
||||||
func QuerySlashingParams(f *cli.Fixtures) types.Params {
|
|
||||||
cmd := fmt.Sprintf("%s query slashing params %s", f.SimdBinary, f.Flags())
|
|
||||||
res, errStr := tests.ExecuteT(f.T, cmd, "")
|
|
||||||
require.Empty(f.T, errStr)
|
|
||||||
|
|
||||||
var params types.Params
|
|
||||||
err := f.Cdc.UnmarshalJSON([]byte(res), ¶ms)
|
|
||||||
require.NoError(f.T, err)
|
|
||||||
return params
|
|
||||||
}
|
|
|
@ -1,195 +1,187 @@
|
||||||
// +build cli_test
|
|
||||||
|
|
||||||
package cli_test
|
package cli_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/suite"
|
||||||
"github.com/tendermint/tendermint/crypto/ed25519"
|
"github.com/tendermint/tendermint/crypto/ed25519"
|
||||||
|
|
||||||
"github.com/cosmos/cosmos-sdk/tests"
|
"github.com/cosmos/cosmos-sdk/client"
|
||||||
"github.com/cosmos/cosmos-sdk/tests/cli"
|
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||||
|
"github.com/cosmos/cosmos-sdk/crypto/hd"
|
||||||
|
"github.com/cosmos/cosmos-sdk/crypto/keyring"
|
||||||
|
"github.com/cosmos/cosmos-sdk/testutil"
|
||||||
|
"github.com/cosmos/cosmos-sdk/testutil/network"
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
bankclienttestutil "github.com/cosmos/cosmos-sdk/x/bank/client/testutil"
|
banktestutil "github.com/cosmos/cosmos-sdk/x/bank/client/testutil"
|
||||||
"github.com/cosmos/cosmos-sdk/x/staking/client/testutil"
|
"github.com/cosmos/cosmos-sdk/x/staking/client/cli"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestCLICreateValidator(t *testing.T) {
|
type IntegrationTestSuite struct {
|
||||||
t.SkipNow() // Recreate when using CLI tests.
|
suite.Suite
|
||||||
|
|
||||||
t.Parallel()
|
cfg network.Config
|
||||||
f := cli.InitFixtures(t)
|
network *network.Network
|
||||||
|
}
|
||||||
// start simd server
|
|
||||||
proc := f.SDStart()
|
func (s *IntegrationTestSuite) SetupSuite() {
|
||||||
t.Cleanup(func() { proc.Stop(false) })
|
s.T().Log("setting up integration test suite")
|
||||||
|
|
||||||
barAddr := f.KeyAddress(cli.KeyBar)
|
cfg := network.DefaultConfig()
|
||||||
barVal := sdk.ValAddress(barAddr)
|
cfg.NumValidators = 1
|
||||||
|
|
||||||
// Check for the params
|
s.cfg = cfg
|
||||||
params := testutil.QueryStakingParameters(f)
|
s.network = network.New(s.T(), cfg)
|
||||||
require.NotEmpty(t, params)
|
|
||||||
|
_, err := s.network.WaitForHeight(1)
|
||||||
// Query for the staking pool
|
s.Require().NoError(err)
|
||||||
pool := testutil.QueryStakingPool(f)
|
}
|
||||||
require.NotEmpty(t, pool)
|
|
||||||
|
func (s *IntegrationTestSuite) TearDownSuite() {
|
||||||
consPubKey := sdk.MustBech32ifyPubKey(sdk.Bech32PubKeyTypeConsPub, ed25519.GenPrivKey().PubKey())
|
s.T().Log("tearing down integration test suite")
|
||||||
|
s.network.Cleanup()
|
||||||
sendTokens := sdk.TokensFromConsensusPower(10)
|
}
|
||||||
bankclienttestutil.TxSend(f, cli.KeyFoo, barAddr, sdk.NewCoin(cli.Denom, sendTokens), "-y")
|
|
||||||
tests.WaitForNextNBlocksTM(1, f.Port)
|
func (s *IntegrationTestSuite) TestNewCreateValidatorCmd() {
|
||||||
|
val := s.network.Validators[0]
|
||||||
require.Equal(t, sendTokens.String(), bankclienttestutil.QueryBalances(f, barAddr).AmountOf(cli.Denom).String())
|
|
||||||
|
consPrivKey := ed25519.GenPrivKey()
|
||||||
// Generate a create validator transaction and ensure correctness
|
consPubKey, err := sdk.Bech32ifyPubKey(sdk.Bech32PubKeyTypeConsPub, consPrivKey.PubKey())
|
||||||
success, stdout, stderr := testutil.TxStakingCreateValidator(f, barAddr.String(), consPubKey, sdk.NewInt64Coin(cli.Denom, 2), "--generate-only")
|
s.Require().NoError(err)
|
||||||
require.True(t, success)
|
|
||||||
require.Empty(t, stderr)
|
info, _, err := val.ClientCtx.Keyring.NewMnemonic("NewValidator", keyring.English, sdk.FullFundraiserPath, hd.Secp256k1)
|
||||||
|
s.Require().NoError(err)
|
||||||
msg := cli.UnmarshalStdTx(t, f.Cdc, stdout)
|
|
||||||
require.NotZero(t, msg.Fee.Gas)
|
newAddr := sdk.AccAddress(info.GetPubKey().Address())
|
||||||
require.Len(t, msg.Msgs, 1)
|
|
||||||
require.Len(t, msg.GetSignatures(), 0)
|
_, err = banktestutil.MsgSendExec(
|
||||||
|
val.ClientCtx,
|
||||||
// Test --dry-run
|
val.Address,
|
||||||
newValTokens := sdk.TokensFromConsensusPower(2)
|
newAddr,
|
||||||
success, _, _ = testutil.TxStakingCreateValidator(f, barAddr.String(), consPubKey, sdk.NewCoin(cli.Denom, newValTokens), "--dry-run")
|
sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(200))), fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
|
||||||
require.True(t, success)
|
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock),
|
||||||
|
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()),
|
||||||
// Create the validator
|
)
|
||||||
testutil.TxStakingCreateValidator(f, cli.KeyBar, consPubKey, sdk.NewCoin(cli.Denom, newValTokens), "-y")
|
s.Require().NoError(err)
|
||||||
tests.WaitForNextNBlocksTM(1, f.Port)
|
|
||||||
|
testCases := []struct {
|
||||||
// Ensure funds were deducted properly
|
name string
|
||||||
require.Equal(t, sendTokens.Sub(newValTokens), bankclienttestutil.QueryBalances(f, barAddr).AmountOf(cli.Denom))
|
args []string
|
||||||
|
expectErr bool
|
||||||
// Ensure that validator state is as expected
|
respType fmt.Stringer
|
||||||
validator := testutil.QueryStakingValidator(f, barVal)
|
expectedCode uint32
|
||||||
require.Equal(t, validator.OperatorAddress, barVal)
|
}{
|
||||||
require.True(sdk.IntEq(t, newValTokens, validator.Tokens))
|
{
|
||||||
|
"invalid transaction (missing amount)",
|
||||||
// Query delegations to the validator
|
[]string{
|
||||||
validatorDelegations := testutil.QueryStakingDelegationsTo(f, barVal)
|
fmt.Sprintf("--%s=AFAF00C4", cli.FlagIdentity),
|
||||||
require.Len(t, validatorDelegations, 1)
|
fmt.Sprintf("--%s=https://newvalidator.io", cli.FlagWebsite),
|
||||||
require.NotNil(t, validatorDelegations[0].Shares)
|
fmt.Sprintf("--%s=contact@newvalidator.io", cli.FlagSecurityContact),
|
||||||
|
fmt.Sprintf("--%s='Hey, I am a new validator. Please delegate!'", cli.FlagDetails),
|
||||||
// Edit validator
|
fmt.Sprintf("--%s=0.5", cli.FlagCommissionRate),
|
||||||
// params to be changed in edit validator (NOTE: a validator can only change its commission once per day)
|
fmt.Sprintf("--%s=1.0", cli.FlagCommissionMaxRate),
|
||||||
newMoniker := "test-moniker"
|
fmt.Sprintf("--%s=0.1", cli.FlagCommissionMaxChangeRate),
|
||||||
newWebsite := "https://cosmos.network"
|
fmt.Sprintf("--%s=1", cli.FlagMinSelfDelegation),
|
||||||
newIdentity := "6A0D65E29A4CBC8D"
|
fmt.Sprintf("--%s=%s", flags.FlagFrom, newAddr),
|
||||||
newDetails := "To-infinity-and-beyond!"
|
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
|
||||||
|
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock),
|
||||||
// Test --generate-only"
|
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()),
|
||||||
success, stdout, stderr = testutil.TxStakingEditValidator(f, barAddr.String(), newMoniker, newWebsite, newIdentity, newDetails, "--generate-only")
|
},
|
||||||
require.True(t, success)
|
true, nil, 0,
|
||||||
require.True(t, success)
|
},
|
||||||
require.Empty(t, stderr)
|
{
|
||||||
|
"invalid transaction (missing pubkey)",
|
||||||
msg = cli.UnmarshalStdTx(t, f.Cdc, stdout)
|
[]string{
|
||||||
require.NotZero(t, msg.Fee.Gas)
|
fmt.Sprintf("--%s=100stake", cli.FlagAmount),
|
||||||
require.Len(t, msg.Msgs, 1)
|
fmt.Sprintf("--%s=AFAF00C4", cli.FlagIdentity),
|
||||||
require.Len(t, msg.GetSignatures(), 0)
|
fmt.Sprintf("--%s=https://newvalidator.io", cli.FlagWebsite),
|
||||||
|
fmt.Sprintf("--%s=contact@newvalidator.io", cli.FlagSecurityContact),
|
||||||
success, _, _ = testutil.TxStakingEditValidator(f, cli.KeyBar, newMoniker, newWebsite, newIdentity, newDetails, "-y")
|
fmt.Sprintf("--%s='Hey, I am a new validator. Please delegate!'", cli.FlagDetails),
|
||||||
require.True(t, success)
|
fmt.Sprintf("--%s=0.5", cli.FlagCommissionRate),
|
||||||
tests.WaitForNextNBlocksTM(1, f.Port)
|
fmt.Sprintf("--%s=1.0", cli.FlagCommissionMaxRate),
|
||||||
|
fmt.Sprintf("--%s=0.1", cli.FlagCommissionMaxChangeRate),
|
||||||
udpatedValidator := testutil.QueryStakingValidator(f, barVal)
|
fmt.Sprintf("--%s=1", cli.FlagMinSelfDelegation),
|
||||||
require.Equal(t, udpatedValidator.Description.Moniker, newMoniker)
|
fmt.Sprintf("--%s=%s", flags.FlagFrom, newAddr),
|
||||||
require.Equal(t, udpatedValidator.Description.Identity, newIdentity)
|
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
|
||||||
require.Equal(t, udpatedValidator.Description.Website, newWebsite)
|
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock),
|
||||||
require.Equal(t, udpatedValidator.Description.Details, newDetails)
|
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()),
|
||||||
|
},
|
||||||
// unbond a single share
|
true, nil, 0,
|
||||||
validators := testutil.QueryStakingValidators(f)
|
},
|
||||||
require.Len(t, validators, 2)
|
{
|
||||||
|
"invalid transaction (missing moniker)",
|
||||||
unbondAmt := sdk.NewCoin(sdk.DefaultBondDenom, sdk.TokensFromConsensusPower(1))
|
[]string{
|
||||||
success = testutil.TxStakingUnbond(f, cli.KeyBar, unbondAmt.String(), barVal, "-y")
|
fmt.Sprintf("--%s=%s", cli.FlagPubKey, consPubKey),
|
||||||
require.True(t, success)
|
fmt.Sprintf("--%s=100stake", cli.FlagAmount),
|
||||||
tests.WaitForNextNBlocksTM(1, f.Port)
|
fmt.Sprintf("--%s=AFAF00C4", cli.FlagIdentity),
|
||||||
|
fmt.Sprintf("--%s=https://newvalidator.io", cli.FlagWebsite),
|
||||||
// Ensure bonded staking is correct
|
fmt.Sprintf("--%s=contact@newvalidator.io", cli.FlagSecurityContact),
|
||||||
remainingTokens := newValTokens.Sub(unbondAmt.Amount)
|
fmt.Sprintf("--%s='Hey, I am a new validator. Please delegate!'", cli.FlagDetails),
|
||||||
validator = testutil.QueryStakingValidator(f, barVal)
|
fmt.Sprintf("--%s=0.5", cli.FlagCommissionRate),
|
||||||
require.Equal(t, remainingTokens, validator.Tokens)
|
fmt.Sprintf("--%s=1.0", cli.FlagCommissionMaxRate),
|
||||||
|
fmt.Sprintf("--%s=0.1", cli.FlagCommissionMaxChangeRate),
|
||||||
// Query for historical info
|
fmt.Sprintf("--%s=1", cli.FlagMinSelfDelegation),
|
||||||
require.NotEmpty(t, testutil.QueryStakingHistoricalInfo(f, 1))
|
fmt.Sprintf("--%s=%s", flags.FlagFrom, newAddr),
|
||||||
|
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
|
||||||
// Get unbonding delegations from the validator
|
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock),
|
||||||
validatorUbds := testutil.QueryStakingUnbondingDelegationsFrom(f, barVal)
|
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()),
|
||||||
require.Len(t, validatorUbds, 1)
|
},
|
||||||
require.Len(t, validatorUbds[0].Entries, 1)
|
true, nil, 0,
|
||||||
require.Equal(t, remainingTokens.String(), validatorUbds[0].Entries[0].Balance.String())
|
},
|
||||||
|
{
|
||||||
// Query staking unbonding delegation
|
"valid transaction",
|
||||||
ubd := testutil.QueryStakingUnbondingDelegation(f, barAddr.String(), barVal.String())
|
[]string{
|
||||||
require.NotEmpty(t, ubd)
|
fmt.Sprintf("--%s=%s", cli.FlagPubKey, consPubKey),
|
||||||
|
fmt.Sprintf("--%s=100stake", cli.FlagAmount),
|
||||||
// Query staking unbonding delegations
|
fmt.Sprintf("--%s=NewValidator", cli.FlagMoniker),
|
||||||
ubds := testutil.QueryStakingUnbondingDelegations(f, barAddr.String())
|
fmt.Sprintf("--%s=AFAF00C4", cli.FlagIdentity),
|
||||||
require.Len(t, ubds, 1)
|
fmt.Sprintf("--%s=https://newvalidator.io", cli.FlagWebsite),
|
||||||
|
fmt.Sprintf("--%s=contact@newvalidator.io", cli.FlagSecurityContact),
|
||||||
fooAddr := f.KeyAddress(cli.KeyFoo)
|
fmt.Sprintf("--%s='Hey, I am a new validator. Please delegate!'", cli.FlagDetails),
|
||||||
|
fmt.Sprintf("--%s=0.5", cli.FlagCommissionRate),
|
||||||
delegateTokens := sdk.TokensFromConsensusPower(2)
|
fmt.Sprintf("--%s=1.0", cli.FlagCommissionMaxRate),
|
||||||
delegateAmount := sdk.NewCoin(cli.Denom, delegateTokens)
|
fmt.Sprintf("--%s=0.1", cli.FlagCommissionMaxChangeRate),
|
||||||
|
fmt.Sprintf("--%s=1", cli.FlagMinSelfDelegation),
|
||||||
// Delegate txn
|
fmt.Sprintf("--%s=%s", flags.FlagFrom, newAddr),
|
||||||
// Generate a create validator transaction and ensure correctness
|
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
|
||||||
success, stdout, stderr = testutil.TxStakingDelegate(f, fooAddr.String(), barVal.String(), delegateAmount, "--generate-only")
|
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock),
|
||||||
require.True(t, success)
|
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()),
|
||||||
require.Empty(t, stderr)
|
},
|
||||||
|
false, &sdk.TxResponse{}, 0,
|
||||||
msg = cli.UnmarshalStdTx(t, f.Cdc, stdout)
|
},
|
||||||
require.NotZero(t, msg.Fee.Gas)
|
}
|
||||||
require.Len(t, msg.Msgs, 1)
|
|
||||||
require.Len(t, msg.GetSignatures(), 0)
|
for _, tc := range testCases {
|
||||||
|
tc := tc
|
||||||
// Delegate
|
|
||||||
success, _, err := testutil.TxStakingDelegate(f, cli.KeyFoo, barVal.String(), delegateAmount, "-y")
|
s.Run(tc.name, func() {
|
||||||
tests.WaitForNextNBlocksTM(1, f.Port)
|
cmd := cli.NewCreateValidatorCmd()
|
||||||
require.Empty(t, err)
|
_, out := testutil.ApplyMockIO(cmd)
|
||||||
require.True(t, success)
|
|
||||||
|
clientCtx := val.ClientCtx.WithOutput(out)
|
||||||
// Query the delegation from foo address to barval
|
|
||||||
delegation := testutil.QueryStakingDelegation(f, fooAddr.String(), barVal)
|
ctx := context.Background()
|
||||||
require.NotZero(t, delegation.Shares)
|
ctx = context.WithValue(ctx, client.ClientContextKey, &clientCtx)
|
||||||
|
|
||||||
// Query the delegations from foo address to barval
|
out.Reset()
|
||||||
delegations := testutil.QueryStakingDelegations(f, barAddr.String())
|
cmd.SetArgs(tc.args)
|
||||||
require.Len(t, delegations, 1)
|
|
||||||
|
err := cmd.ExecuteContext(ctx)
|
||||||
fooVal := sdk.ValAddress(fooAddr)
|
if tc.expectErr {
|
||||||
|
s.Require().Error(err)
|
||||||
// Redelegate
|
} else {
|
||||||
success, stdout, stderr = testutil.TxStakingRedelegate(f, fooAddr.String(), barVal.String(), fooVal.String(), delegateAmount, "--generate-only")
|
s.Require().NoError(err, out.String())
|
||||||
require.True(t, success)
|
s.Require().NoError(clientCtx.JSONMarshaler.UnmarshalJSON(out.Bytes(), tc.respType), out.String())
|
||||||
require.Empty(t, stderr)
|
|
||||||
|
txResp := tc.respType.(*sdk.TxResponse)
|
||||||
msg = cli.UnmarshalStdTx(t, f.Cdc, stdout)
|
s.Require().Equal(tc.expectedCode, txResp.Code, out.String())
|
||||||
require.NotZero(t, msg.Fee.Gas)
|
}
|
||||||
require.Len(t, msg.Msgs, 1)
|
})
|
||||||
require.Len(t, msg.GetSignatures(), 0)
|
}
|
||||||
|
}
|
||||||
success, _, err = testutil.TxStakingRedelegate(f, cli.KeyFoo, barVal.String(), fooVal.String(), delegateAmount, "-y")
|
|
||||||
tests.WaitForNextNBlocksTM(1, f.Port)
|
func TestIntegrationTestSuite(t *testing.T) {
|
||||||
require.Empty(t, err)
|
suite.Run(t, new(IntegrationTestSuite))
|
||||||
require.True(t, success)
|
|
||||||
|
|
||||||
redelegation := testutil.QueryStakingRedelegation(f, fooAddr.String(), barVal.String(), fooVal.String())
|
|
||||||
require.Len(t, redelegation, 1)
|
|
||||||
|
|
||||||
redelegations := testutil.QueryStakingRedelegations(f, fooAddr.String())
|
|
||||||
require.Len(t, redelegations, 1)
|
|
||||||
|
|
||||||
redelegationsFrom := testutil.QueryStakingRedelegationsFrom(f, barVal.String())
|
|
||||||
require.Len(t, redelegationsFrom, 1)
|
|
||||||
|
|
||||||
f.Cleanup()
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,7 +28,7 @@ var (
|
||||||
)
|
)
|
||||||
|
|
||||||
// NewTxCmd returns a root CLI command handler for all x/staking transaction commands.
|
// NewTxCmd returns a root CLI command handler for all x/staking transaction commands.
|
||||||
func NewTxCmd(clientCtx client.Context) *cobra.Command {
|
func NewTxCmd() *cobra.Command {
|
||||||
stakingTxCmd := &cobra.Command{
|
stakingTxCmd := &cobra.Command{
|
||||||
Use: types.ModuleName,
|
Use: types.ModuleName,
|
||||||
Short: "Staking transaction subcommands",
|
Short: "Staking transaction subcommands",
|
||||||
|
@ -38,22 +38,26 @@ func NewTxCmd(clientCtx client.Context) *cobra.Command {
|
||||||
}
|
}
|
||||||
|
|
||||||
stakingTxCmd.AddCommand(
|
stakingTxCmd.AddCommand(
|
||||||
NewCreateValidatorCmd(clientCtx),
|
NewCreateValidatorCmd(),
|
||||||
NewEditValidatorCmd(clientCtx),
|
NewEditValidatorCmd(),
|
||||||
NewDelegateCmd(clientCtx),
|
NewDelegateCmd(),
|
||||||
NewRedelegateCmd(clientCtx),
|
NewRedelegateCmd(),
|
||||||
NewUnbondCmd(clientCtx),
|
NewUnbondCmd(),
|
||||||
)
|
)
|
||||||
|
|
||||||
return stakingTxCmd
|
return stakingTxCmd
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewCreateValidatorCmd(clientCtx client.Context) *cobra.Command {
|
func NewCreateValidatorCmd() *cobra.Command {
|
||||||
cmd := &cobra.Command{
|
cmd := &cobra.Command{
|
||||||
Use: "create-validator",
|
Use: "create-validator",
|
||||||
Short: "create new validator initialized with a self-delegation to it",
|
Short: "create new validator initialized with a self-delegation to it",
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
clientCtx.WithInput(cmd.InOrStdin())
|
clientCtx := client.GetClientContextFromCmd(cmd)
|
||||||
|
clientCtx, err := client.ReadTxCommandFlags(clientCtx, cmd.Flags())
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
txf := tx.NewFactoryCLI(clientCtx, cmd.Flags()).WithTxConfig(clientCtx.TxConfig).WithAccountRetriever(clientCtx.AccountRetriever)
|
txf := tx.NewFactoryCLI(clientCtx, cmd.Flags()).WithTxConfig(clientCtx.TxConfig).WithAccountRetriever(clientCtx.AccountRetriever)
|
||||||
|
|
||||||
|
@ -61,6 +65,7 @@ func NewCreateValidatorCmd(clientCtx client.Context) *cobra.Command {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return tx.GenerateOrBroadcastTxWithFactory(clientCtx, txf, msg)
|
return tx.GenerateOrBroadcastTxWithFactory(clientCtx, txf, msg)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -83,12 +88,16 @@ func NewCreateValidatorCmd(clientCtx client.Context) *cobra.Command {
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewEditValidatorCmd(clientCtx client.Context) *cobra.Command {
|
func NewEditValidatorCmd() *cobra.Command {
|
||||||
cmd := &cobra.Command{
|
cmd := &cobra.Command{
|
||||||
Use: "edit-validator",
|
Use: "edit-validator",
|
||||||
Short: "edit an existing validator account",
|
Short: "edit an existing validator account",
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
clientCtx := clientCtx.WithInput(cmd.InOrStdin())
|
clientCtx := client.GetClientContextFromCmd(cmd)
|
||||||
|
clientCtx, err := client.ReadTxCommandFlags(clientCtx, cmd.Flags())
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
valAddr := clientCtx.GetFromAddress()
|
valAddr := clientCtx.GetFromAddress()
|
||||||
|
|
||||||
|
@ -97,13 +106,7 @@ func NewEditValidatorCmd(clientCtx client.Context) *cobra.Command {
|
||||||
website, _ := cmd.Flags().GetString(FlagWebsite)
|
website, _ := cmd.Flags().GetString(FlagWebsite)
|
||||||
security, _ := cmd.Flags().GetString(FlagSecurityContact)
|
security, _ := cmd.Flags().GetString(FlagSecurityContact)
|
||||||
details, _ := cmd.Flags().GetString(FlagDetails)
|
details, _ := cmd.Flags().GetString(FlagDetails)
|
||||||
description := types.NewDescription(
|
description := types.NewDescription(moniker, identity, website, security, details)
|
||||||
moniker,
|
|
||||||
identity,
|
|
||||||
website,
|
|
||||||
security,
|
|
||||||
details,
|
|
||||||
)
|
|
||||||
|
|
||||||
var newRate *sdk.Dec
|
var newRate *sdk.Dec
|
||||||
|
|
||||||
|
@ -134,8 +137,7 @@ func NewEditValidatorCmd(clientCtx client.Context) *cobra.Command {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// build and sign the transaction, then broadcast to Tendermint
|
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
|
||||||
return tx.GenerateOrBroadcastTx(clientCtx, msg)
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -147,7 +149,7 @@ func NewEditValidatorCmd(clientCtx client.Context) *cobra.Command {
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewDelegateCmd(clientCtx client.Context) *cobra.Command {
|
func NewDelegateCmd() *cobra.Command {
|
||||||
cmd := &cobra.Command{
|
cmd := &cobra.Command{
|
||||||
Use: "delegate [validator-addr] [amount]",
|
Use: "delegate [validator-addr] [amount]",
|
||||||
Args: cobra.ExactArgs(2),
|
Args: cobra.ExactArgs(2),
|
||||||
|
@ -184,7 +186,7 @@ $ %s tx staking delegate cosmosvaloper1l2rsakp388kuv9k8qzq6lrm9taddae7fpx59wm 10
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return tx.GenerateOrBroadcastTx(clientCtx, msg)
|
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -193,7 +195,7 @@ $ %s tx staking delegate cosmosvaloper1l2rsakp388kuv9k8qzq6lrm9taddae7fpx59wm 10
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewRedelegateCmd(clientCtx client.Context) *cobra.Command {
|
func NewRedelegateCmd() *cobra.Command {
|
||||||
cmd := &cobra.Command{
|
cmd := &cobra.Command{
|
||||||
Use: "redelegate [src-validator-addr] [dst-validator-addr] [amount]",
|
Use: "redelegate [src-validator-addr] [dst-validator-addr] [amount]",
|
||||||
Short: "Redelegate illiquid tokens from one validator to another",
|
Short: "Redelegate illiquid tokens from one validator to another",
|
||||||
|
@ -235,7 +237,7 @@ $ %s tx staking redelegate cosmosvaloper1gghjut3ccd8ay0zduzj64hwre2fxs9ldmqhffj
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return tx.GenerateOrBroadcastTx(clientCtx, msg)
|
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -244,7 +246,7 @@ $ %s tx staking redelegate cosmosvaloper1gghjut3ccd8ay0zduzj64hwre2fxs9ldmqhffj
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewUnbondCmd(clientCtx client.Context) *cobra.Command {
|
func NewUnbondCmd() *cobra.Command {
|
||||||
cmd := &cobra.Command{
|
cmd := &cobra.Command{
|
||||||
Use: "unbond [validator-addr] [amount]",
|
Use: "unbond [validator-addr] [amount]",
|
||||||
Short: "Unbond shares from a validator",
|
Short: "Unbond shares from a validator",
|
||||||
|
@ -281,7 +283,7 @@ $ %s tx staking unbond cosmosvaloper1gghjut3ccd8ay0zduzj64hwre2fxs9ldmqhffj 100s
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return tx.GenerateOrBroadcastTx(clientCtx, msg)
|
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,220 +0,0 @@
|
||||||
package testutil
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"github.com/stretchr/testify/require"
|
|
||||||
|
|
||||||
clientkeys "github.com/cosmos/cosmos-sdk/client/keys"
|
|
||||||
"github.com/cosmos/cosmos-sdk/tests"
|
|
||||||
"github.com/cosmos/cosmos-sdk/tests/cli"
|
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
||||||
staking "github.com/cosmos/cosmos-sdk/x/staking/types"
|
|
||||||
)
|
|
||||||
|
|
||||||
// TxStakingCreateValidator is simcli tx staking create-validator
|
|
||||||
func TxStakingCreateValidator(f *cli.Fixtures, from, consPubKey string, amount sdk.Coin, flags ...string) (bool, string, string) {
|
|
||||||
cmd := fmt.Sprintf("%s tx staking create-validator %v --keyring-backend=test --from=%s"+
|
|
||||||
" --pubkey=%s", f.SimdBinary, f.Flags(), from, consPubKey)
|
|
||||||
cmd += fmt.Sprintf(" --amount=%v --moniker=%v --commission-rate=%v", amount, from, "0.05")
|
|
||||||
cmd += fmt.Sprintf(" --commission-max-rate=%v --commission-max-change-rate=%v", "0.20", "0.10")
|
|
||||||
cmd += fmt.Sprintf(" --min-self-delegation=%v", "1")
|
|
||||||
|
|
||||||
return cli.ExecuteWriteRetStdStreams(f.T, cli.AddFlags(cmd, flags), clientkeys.DefaultKeyPass)
|
|
||||||
}
|
|
||||||
|
|
||||||
// TxStakingEditValidator is simcli tx staking update validator info
|
|
||||||
func TxStakingEditValidator(f *cli.Fixtures, from, moniker, website, identity, details string, flags ...string) (bool, string, string) {
|
|
||||||
cmd := fmt.Sprintf("%s tx staking edit-validator %v --keyring-backend=test --from=%s", f.SimdBinary, f.Flags(), from)
|
|
||||||
cmd += fmt.Sprintf(" --moniker=%v --website=%s", moniker, website)
|
|
||||||
cmd += fmt.Sprintf(" --identity=%s --details=%s", identity, details)
|
|
||||||
|
|
||||||
return cli.ExecuteWriteRetStdStreams(f.T, cli.AddFlags(cmd, flags), clientkeys.DefaultKeyPass)
|
|
||||||
}
|
|
||||||
|
|
||||||
// TxStakingUnbond is simcli tx staking unbond
|
|
||||||
func TxStakingUnbond(f *cli.Fixtures, from, shares string, validator sdk.ValAddress, flags ...string) bool {
|
|
||||||
cmd := fmt.Sprintf("%s tx staking unbond --keyring-backend=test %s %v --from=%s %v",
|
|
||||||
f.SimdBinary, validator, shares, from, f.Flags())
|
|
||||||
return cli.ExecuteWrite(f.T, cli.AddFlags(cmd, flags), clientkeys.DefaultKeyPass)
|
|
||||||
}
|
|
||||||
|
|
||||||
// TxStakingDelegate is simcli tx staking delegate
|
|
||||||
func TxStakingDelegate(f *cli.Fixtures, from, valOperAddr string, amount sdk.Coin, flags ...string) (bool, string, string) {
|
|
||||||
cmd := fmt.Sprintf("%s tx staking delegate %s %v --keyring-backend=test --from=%s %v", f.SimdBinary, valOperAddr, amount, from, f.Flags())
|
|
||||||
return cli.ExecuteWriteRetStdStreams(f.T, cli.AddFlags(cmd, flags), clientkeys.DefaultKeyPass)
|
|
||||||
}
|
|
||||||
|
|
||||||
// TxStakingRedelegate is simcli tx staking redelegate
|
|
||||||
func TxStakingRedelegate(f *cli.Fixtures, from, srcVal, dstVal string, amount sdk.Coin, flags ...string) (bool, string, string) {
|
|
||||||
cmd := fmt.Sprintf("%s tx staking redelegate %s %s %v --keyring-backend=test --from=%s %v", f.SimdBinary, srcVal, dstVal, amount, from, f.Flags())
|
|
||||||
return cli.ExecuteWriteRetStdStreams(f.T, cli.AddFlags(cmd, flags), clientkeys.DefaultKeyPass)
|
|
||||||
}
|
|
||||||
|
|
||||||
// QueryStakingValidator is simcli query staking validator
|
|
||||||
func QueryStakingValidator(f *cli.Fixtures, valAddr sdk.ValAddress, flags ...string) staking.Validator {
|
|
||||||
cmd := fmt.Sprintf("%s query staking validator %s %v", f.SimdBinary, valAddr, f.Flags())
|
|
||||||
out, errStr := tests.ExecuteT(f.T, cli.AddFlags(cmd, flags), "")
|
|
||||||
require.Empty(f.T, errStr)
|
|
||||||
|
|
||||||
var validator staking.Validator
|
|
||||||
require.NoError(f.T, f.Cdc.UnmarshalJSON([]byte(out), &validator))
|
|
||||||
|
|
||||||
return validator
|
|
||||||
}
|
|
||||||
|
|
||||||
// QueryStakingValidators is simcli query staking validators
|
|
||||||
func QueryStakingValidators(f *cli.Fixtures, flags ...string) []staking.Validator {
|
|
||||||
cmd := fmt.Sprintf("%s query staking validators %v", f.SimdBinary, f.Flags())
|
|
||||||
out, errStr := tests.ExecuteT(f.T, cli.AddFlags(cmd, flags), "")
|
|
||||||
require.Empty(f.T, errStr)
|
|
||||||
|
|
||||||
var validators []staking.Validator
|
|
||||||
require.NoError(f.T, f.Cdc.UnmarshalJSON([]byte(out), &validators))
|
|
||||||
|
|
||||||
return validators
|
|
||||||
}
|
|
||||||
|
|
||||||
// QueryStakingUnbondingDelegationsFrom is simcli query staking unbonding-delegations-from
|
|
||||||
func QueryStakingUnbondingDelegationsFrom(f *cli.Fixtures, valAddr sdk.ValAddress, flags ...string) []staking.UnbondingDelegation {
|
|
||||||
cmd := fmt.Sprintf("%s query staking unbonding-delegations-from %s %v", f.SimdBinary, valAddr, f.Flags())
|
|
||||||
out, errStr := tests.ExecuteT(f.T, cli.AddFlags(cmd, flags), "")
|
|
||||||
require.Empty(f.T, errStr)
|
|
||||||
|
|
||||||
var ubds []staking.UnbondingDelegation
|
|
||||||
require.NoError(f.T, f.Cdc.UnmarshalJSON([]byte(out), &ubds))
|
|
||||||
|
|
||||||
return ubds
|
|
||||||
}
|
|
||||||
|
|
||||||
// QueryStakingDelegationsTo is simcli query staking delegations-to
|
|
||||||
func QueryStakingDelegationsTo(f *cli.Fixtures, valAddr sdk.ValAddress, flags ...string) []staking.Delegation {
|
|
||||||
cmd := fmt.Sprintf("%s query staking delegations-to %s %v", f.SimdBinary, valAddr, f.Flags())
|
|
||||||
out, errStr := tests.ExecuteT(f.T, cli.AddFlags(cmd, flags), "")
|
|
||||||
require.Empty(f.T, errStr)
|
|
||||||
|
|
||||||
var delegations []staking.Delegation
|
|
||||||
require.NoError(f.T, f.Cdc.UnmarshalJSON([]byte(out), &delegations))
|
|
||||||
|
|
||||||
return delegations
|
|
||||||
}
|
|
||||||
|
|
||||||
// QueryStakingPool is simcli query staking pool
|
|
||||||
func QueryStakingPool(f *cli.Fixtures, flags ...string) staking.Pool {
|
|
||||||
cmd := fmt.Sprintf("%s query staking pool %v", f.SimdBinary, f.Flags())
|
|
||||||
out, errStr := tests.ExecuteT(f.T, cli.AddFlags(cmd, flags), "")
|
|
||||||
require.Empty(f.T, errStr)
|
|
||||||
|
|
||||||
var pool staking.Pool
|
|
||||||
require.NoError(f.T, f.Cdc.UnmarshalJSON([]byte(out), &pool))
|
|
||||||
|
|
||||||
return pool
|
|
||||||
}
|
|
||||||
|
|
||||||
// QueryStakingParameters is simcli query staking parameters
|
|
||||||
func QueryStakingParameters(f *cli.Fixtures, flags ...string) staking.Params {
|
|
||||||
cmd := fmt.Sprintf("%s query staking params %v", f.SimdBinary, f.Flags())
|
|
||||||
out, errStr := tests.ExecuteT(f.T, cli.AddFlags(cmd, flags), "")
|
|
||||||
require.Empty(f.T, errStr)
|
|
||||||
|
|
||||||
var params staking.Params
|
|
||||||
require.NoError(f.T, f.Cdc.UnmarshalJSON([]byte(out), ¶ms))
|
|
||||||
|
|
||||||
return params
|
|
||||||
}
|
|
||||||
|
|
||||||
// QueryStakingDelegation is simcli query staking delegation
|
|
||||||
func QueryStakingDelegation(f *cli.Fixtures, from string, valAddr sdk.ValAddress, flags ...string) staking.Delegation {
|
|
||||||
cmd := fmt.Sprintf("%s query staking delegation %s %s %v", f.SimdBinary, from, valAddr, f.Flags())
|
|
||||||
out, errStr := tests.ExecuteT(f.T, cli.AddFlags(cmd, flags), "")
|
|
||||||
require.Empty(f.T, errStr)
|
|
||||||
|
|
||||||
var delegation staking.Delegation
|
|
||||||
require.NoError(f.T, f.Cdc.UnmarshalJSON([]byte(out), &delegation))
|
|
||||||
|
|
||||||
return delegation
|
|
||||||
}
|
|
||||||
|
|
||||||
// QueryStakingDelegations is simcli query staking delegations
|
|
||||||
func QueryStakingDelegations(f *cli.Fixtures, from string, flags ...string) []staking.Delegation {
|
|
||||||
cmd := fmt.Sprintf("%s query staking delegations %s %v", f.SimdBinary, from, f.Flags())
|
|
||||||
out, errStr := tests.ExecuteT(f.T, cli.AddFlags(cmd, flags), "")
|
|
||||||
require.Empty(f.T, errStr)
|
|
||||||
|
|
||||||
var delegations []staking.Delegation
|
|
||||||
require.NoError(f.T, f.Cdc.UnmarshalJSON([]byte(out), &delegations))
|
|
||||||
|
|
||||||
return delegations
|
|
||||||
}
|
|
||||||
|
|
||||||
// QueryStakingRedelegation is simcli query staking redelegation
|
|
||||||
func QueryStakingRedelegation(f *cli.Fixtures, delAdrr, srcVal, dstVal string, flags ...string) []staking.RedelegationResponse {
|
|
||||||
cmd := fmt.Sprintf("%s query staking redelegation %v %v %v %v", f.SimdBinary, delAdrr, srcVal, dstVal, f.Flags())
|
|
||||||
out, errStr := tests.ExecuteT(f.T, cli.AddFlags(cmd, flags), "")
|
|
||||||
require.Empty(f.T, errStr)
|
|
||||||
|
|
||||||
var redelegations []staking.RedelegationResponse
|
|
||||||
require.NoError(f.T, f.Cdc.UnmarshalJSON([]byte(out), &redelegations))
|
|
||||||
|
|
||||||
return redelegations
|
|
||||||
}
|
|
||||||
|
|
||||||
// QueryStakingRedelegations is simcli query staking redelegation
|
|
||||||
func QueryStakingRedelegations(f *cli.Fixtures, delAdrr string, flags ...string) []staking.RedelegationResponse {
|
|
||||||
cmd := fmt.Sprintf("%s query staking redelegations %v %v", f.SimdBinary, delAdrr, f.Flags())
|
|
||||||
out, errStr := tests.ExecuteT(f.T, cli.AddFlags(cmd, flags), "")
|
|
||||||
require.Empty(f.T, errStr)
|
|
||||||
|
|
||||||
var redelegations []staking.RedelegationResponse
|
|
||||||
require.NoError(f.T, f.Cdc.UnmarshalJSON([]byte(out), &redelegations))
|
|
||||||
|
|
||||||
return redelegations
|
|
||||||
}
|
|
||||||
|
|
||||||
// QueryStakingRedelegationsFrom is simcli query staking redelegations-from
|
|
||||||
func QueryStakingRedelegationsFrom(f *cli.Fixtures, valAddr string, flags ...string) []staking.RedelegationResponse {
|
|
||||||
cmd := fmt.Sprintf("%s query staking redelegations-from %v %v", f.SimdBinary, valAddr, f.Flags())
|
|
||||||
out, errStr := tests.ExecuteT(f.T, cli.AddFlags(cmd, flags), "")
|
|
||||||
require.Empty(f.T, errStr)
|
|
||||||
|
|
||||||
var redelegations []staking.RedelegationResponse
|
|
||||||
require.NoError(f.T, f.Cdc.UnmarshalJSON([]byte(out), &redelegations))
|
|
||||||
|
|
||||||
return redelegations
|
|
||||||
}
|
|
||||||
|
|
||||||
// QueryStakingUnbondingDelegation is simcli query staking unbonding-delegation
|
|
||||||
func QueryStakingUnbondingDelegation(f *cli.Fixtures, delAdrr, valAddr string, flags ...string) staking.UnbondingDelegation {
|
|
||||||
cmd := fmt.Sprintf("%s query staking unbonding-delegation %v %v %v", f.SimdBinary, delAdrr, valAddr, f.Flags())
|
|
||||||
out, errStr := tests.ExecuteT(f.T, cli.AddFlags(cmd, flags), "")
|
|
||||||
require.Empty(f.T, errStr)
|
|
||||||
|
|
||||||
var ubd staking.UnbondingDelegation
|
|
||||||
require.NoError(f.T, f.Cdc.UnmarshalJSON([]byte(out), &ubd))
|
|
||||||
|
|
||||||
return ubd
|
|
||||||
}
|
|
||||||
|
|
||||||
// QueryStakingUnbondingDelegations is simcli query staking unbonding-delegations
|
|
||||||
func QueryStakingUnbondingDelegations(f *cli.Fixtures, delAdrr string, flags ...string) []staking.UnbondingDelegation {
|
|
||||||
cmd := fmt.Sprintf("%s query staking unbonding-delegations %v %v", f.SimdBinary, delAdrr, f.Flags())
|
|
||||||
out, errStr := tests.ExecuteT(f.T, cli.AddFlags(cmd, flags), "")
|
|
||||||
require.Empty(f.T, errStr)
|
|
||||||
|
|
||||||
var ubds []staking.UnbondingDelegation
|
|
||||||
require.NoError(f.T, f.Cdc.UnmarshalJSON([]byte(out), &ubds))
|
|
||||||
|
|
||||||
return ubds
|
|
||||||
}
|
|
||||||
|
|
||||||
// QueryStakingHistoricalInfo is simcli query staking historical-info
|
|
||||||
func QueryStakingHistoricalInfo(f *cli.Fixtures, height uint, flags ...string) staking.HistoricalInfo {
|
|
||||||
cmd := fmt.Sprintf("%s query staking historical-info %d %v", f.SimdBinary, height, f.Flags())
|
|
||||||
out, errStr := tests.ExecuteT(f.T, cli.AddFlags(cmd, flags), "")
|
|
||||||
require.Empty(f.T, errStr)
|
|
||||||
|
|
||||||
var historicalInfo staking.HistoricalInfo
|
|
||||||
require.NoError(f.T, f.Cdc.UnmarshalJSON([]byte(out), &historicalInfo))
|
|
||||||
|
|
||||||
return historicalInfo
|
|
||||||
}
|
|
|
@ -68,8 +68,8 @@ func (AppModuleBasic) RegisterRESTRoutes(clientCtx client.Context, rtr *mux.Rout
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetTxCmd returns the root tx command for the staking module.
|
// GetTxCmd returns the root tx command for the staking module.
|
||||||
func (AppModuleBasic) GetTxCmd(clientCtx client.Context) *cobra.Command {
|
func (AppModuleBasic) GetTxCmd(_ client.Context) *cobra.Command {
|
||||||
return cli.NewTxCmd(clientCtx)
|
return cli.NewTxCmd()
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetQueryCmd returns no root query command for the staking module.
|
// GetQueryCmd returns no root query command for the staking module.
|
||||||
|
|
|
@ -137,7 +137,7 @@ func NewCmdSubmitCancelUpgradeProposal() *cobra.Command {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return tx.GenerateOrBroadcastTx(clientCtx, msg)
|
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue