Add cli test for query Account (#6973)

Closes: #7007

Ref: #6571

Co-authored-by: Aaron Craelius <aaron@regen.network>
Co-authored-by: Alessio Treglia <alessio@tendermint.com>
This commit is contained in:
SaReN 2020-08-17 18:17:31 +05:30 committed by GitHub
parent 23cabc0786
commit 77124da21a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 180 additions and 296 deletions

View File

@ -11,6 +11,8 @@ import (
"github.com/gogo/protobuf/proto"
abci "github.com/tendermint/tendermint/abci/types"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
"google.golang.org/grpc/codes"
grpcstatus "google.golang.org/grpc/status"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/telemetry"
@ -358,7 +360,7 @@ func (app *BaseApp) handleQueryGRPC(handler GRPCQueryHandler, req abci.RequestQu
res, err := handler(ctx, req)
if err != nil {
res = sdkerrors.QueryResult(err)
res = sdkerrors.QueryResult(gRPCErrorToSDKError(err))
res.Height = req.Height
return res
}
@ -366,6 +368,26 @@ func (app *BaseApp) handleQueryGRPC(handler GRPCQueryHandler, req abci.RequestQu
return res
}
func gRPCErrorToSDKError(err error) error {
status, ok := grpcstatus.FromError(err)
if !ok {
return err
}
switch status.Code() {
case codes.NotFound:
return sdkerrors.Wrap(sdkerrors.ErrKeyNotFound, err.Error())
case codes.InvalidArgument:
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, err.Error())
case codes.FailedPrecondition:
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, err.Error())
case codes.Unauthenticated:
return sdkerrors.Wrap(sdkerrors.ErrUnauthorized, err.Error())
default:
return sdkerrors.Wrap(sdkerrors.ErrUnknownRequest, err.Error())
}
}
// createQueryContext creates a new sdk.Context for a query, taking as args
// the block height and whether the query needs a proof or not.
func (app *BaseApp) createQueryContext(height int64, prove bool) (sdk.Context, error) {

View File

@ -66,23 +66,24 @@ type Config struct {
Codec codec.Marshaler
LegacyAmino *codec.LegacyAmino // TODO: Remove!
InterfaceRegistry codectypes.InterfaceRegistry
TxConfig client.TxConfig
AccountRetriever client.AccountRetriever
AppConstructor AppConstructor // the ABCI application constructor
GenesisState map[string]json.RawMessage // custom gensis state to provide
TimeoutCommit time.Duration // the consensus commitment timeout
ChainID string // the network chain-id
NumValidators int // the total number of validators to create and bond
BondDenom string // the staking bond denomination
MinGasPrices string // the minimum gas prices each validator will accept
AccountTokens sdk.Int // the amount of unique validator tokens (e.g. 1000node0)
StakingTokens sdk.Int // the amount of tokens each validator has available to stake
BondedTokens sdk.Int // the amount of tokens each validator stakes
PruningStrategy string // the pruning strategy each validator will have
EnableLogging bool // enable Tendermint logging to STDOUT
CleanupDir bool // remove base temporary directory during cleanup
SigningAlgo string // signing algorithm for keys
KeyringOptions []keyring.Option
TxConfig client.TxConfig
AccountRetriever client.AccountRetriever
AppConstructor AppConstructor // the ABCI application constructor
GenesisState map[string]json.RawMessage // custom gensis state to provide
TimeoutCommit time.Duration // the consensus commitment timeout
ChainID string // the network chain-id
NumValidators int // the total number of validators to create and bond
BondDenom string // the staking bond denomination
MinGasPrices string // the minimum gas prices each validator will accept
AccountTokens sdk.Int // the amount of unique validator tokens (e.g. 1000node0)
StakingTokens sdk.Int // the amount of tokens each validator has available to stake
BondedTokens sdk.Int // the amount of tokens each validator stakes
PruningStrategy string // the pruning strategy each validator will have
EnableLogging bool // enable Tendermint logging to STDOUT
CleanupDir bool // remove base temporary directory during cleanup
SigningAlgo string // signing algorithm for keys
KeyringOptions []keyring.Option
}
// DefaultConfig returns a sane default configuration suitable for nearly all
@ -324,11 +325,11 @@ func New(t *testing.T, cfg Config) *Network {
WithKeyring(kb).
WithHomeDir(tmCfg.RootDir).
WithChainID(cfg.ChainID).
WithInterfaceRegistry(cfg.InterfaceRegistry).
WithJSONMarshaler(cfg.Codec).
WithLegacyAmino(cfg.LegacyAmino).
WithTxConfig(cfg.TxConfig).
WithAccountRetriever(cfg.AccountRetriever).
WithInterfaceRegistry(cfg.InterfaceRegistry)
WithAccountRetriever(cfg.AccountRetriever)
network.Validators[i] = &Validator{
AppConfig: appCfg,

View File

@ -8,9 +8,12 @@ import (
"strings"
"testing"
"github.com/cosmos/cosmos-sdk/codec/types"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
tmcrypto "github.com/tendermint/tendermint/crypto"
tmcli "github.com/tendermint/tendermint/libs/cli"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
@ -20,10 +23,13 @@ import (
"github.com/cosmos/cosmos-sdk/crypto/types/multisig"
"github.com/cosmos/cosmos-sdk/simapp"
"github.com/cosmos/cosmos-sdk/testutil"
clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli"
"github.com/cosmos/cosmos-sdk/testutil/network"
"github.com/cosmos/cosmos-sdk/testutil/testdata"
sdk "github.com/cosmos/cosmos-sdk/types"
authcli "github.com/cosmos/cosmos-sdk/x/auth/client/cli"
authtest "github.com/cosmos/cosmos-sdk/x/auth/client/testutil"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
bankcli "github.com/cosmos/cosmos-sdk/x/bank/client/testutil"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
)
@ -211,7 +217,7 @@ func (s *IntegrationTestSuite) TestCLISendGenerateSignAndBroadcast() {
s.Require().Equal(len(txBuilder.GetTx().GetMsgs()), 1)
s.Require().Equal(0, len(txBuilder.GetTx().GetSignatures()))
resp, err := bankcli.QueryBalancesExec(val1.ClientCtx.WithOutputFormat("json"), val1.Address)
resp, err := bankcli.QueryBalancesExec(val1.ClientCtx, val1.Address)
s.Require().NoError(err)
var balRes banktypes.QueryAllBalancesResponse
@ -281,7 +287,7 @@ func (s *IntegrationTestSuite) TestCLISendGenerateSignAndBroadcast() {
s.Require().True(strings.Contains(res.String(), "[OK]"))
// Ensure foo has right amount of funds
resp, err = bankcli.QueryBalancesExec(val1.ClientCtx.WithOutputFormat("json"), val1.Address)
resp, err = bankcli.QueryBalancesExec(val1.ClientCtx, val1.Address)
s.Require().NoError(err)
err = val1.ClientCtx.JSONMarshaler.UnmarshalJSON(resp.Bytes(), &balRes)
@ -304,7 +310,7 @@ func (s *IntegrationTestSuite) TestCLISendGenerateSignAndBroadcast() {
s.Require().NoError(s.network.WaitForNextBlock())
// Ensure destiny account state
resp, err = bankcli.QueryBalancesExec(val1.ClientCtx.WithOutputFormat("json"), account.GetAddress())
resp, err = bankcli.QueryBalancesExec(val1.ClientCtx, account.GetAddress())
s.Require().NoError(err)
err = val1.ClientCtx.JSONMarshaler.UnmarshalJSON(resp.Bytes(), &balRes)
@ -312,7 +318,7 @@ func (s *IntegrationTestSuite) TestCLISendGenerateSignAndBroadcast() {
s.Require().Equal(sendTokens.Amount, balRes.Balances.AmountOf(s.cfg.BondDenom))
// Ensure origin account state
resp, err = bankcli.QueryBalancesExec(val1.ClientCtx.WithOutputFormat("json"), val1.Address)
resp, err = bankcli.QueryBalancesExec(val1.ClientCtx, val1.Address)
s.Require().NoError(err)
err = val1.ClientCtx.JSONMarshaler.UnmarshalJSON(resp.Bytes(), &balRes)
@ -448,7 +454,7 @@ func (s *IntegrationTestSuite) TestCLIMultisignSortSignatures() {
multisigInfo, err := val1.ClientCtx.Keyring.Key("multi")
s.Require().NoError(err)
resp, err := bankcli.QueryBalancesExec(val1.ClientCtx.WithOutputFormat("json"), multisigInfo.GetAddress())
resp, err := bankcli.QueryBalancesExec(val1.ClientCtx, multisigInfo.GetAddress())
s.Require().NoError(err)
var balRes banktypes.QueryAllBalancesResponse
@ -472,7 +478,7 @@ func (s *IntegrationTestSuite) TestCLIMultisignSortSignatures() {
s.Require().NoError(s.network.WaitForNextBlock())
resp, err = bankcli.QueryBalancesExec(val1.ClientCtx.WithOutputFormat("json"), multisigInfo.GetAddress())
resp, err = bankcli.QueryBalancesExec(val1.ClientCtx, multisigInfo.GetAddress())
s.Require().NoError(err)
err = val1.ClientCtx.JSONMarshaler.UnmarshalJSON(resp.Bytes(), &balRes)
@ -564,7 +570,7 @@ func (s *IntegrationTestSuite) TestCLIMultisign() {
s.Require().NoError(s.network.WaitForNextBlock())
resp, err := bankcli.QueryBalancesExec(val1.ClientCtx.WithOutputFormat("json"), multisigInfo.GetAddress())
resp, err := bankcli.QueryBalancesExec(val1.ClientCtx, multisigInfo.GetAddress())
s.Require().NoError(err)
var balRes banktypes.QueryAllBalancesResponse
@ -628,6 +634,50 @@ func (s *IntegrationTestSuite) TestCLIMultisign() {
s.Require().NoError(s.network.WaitForNextBlock())
}
func (s *IntegrationTestSuite) TestGetAccountCmd() {
val := s.network.Validators[0]
_, _, addr1 := testdata.KeyTestPubAddr()
testCases := []struct {
name string
args []string
expectErr bool
}{
{
"invalid address",
[]string{addr1.String(),
fmt.Sprintf("--%s=json", tmcli.OutputFlag)},
true,
},
{
"valid address",
[]string{val.Address.String(),
fmt.Sprintf("--%s=json", tmcli.OutputFlag)},
false,
},
}
for _, tc := range testCases {
tc := tc
s.Run(tc.name, func() {
cmd := authcli.GetAccountCmd()
clientCtx := val.ClientCtx
out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, tc.args)
if tc.expectErr {
s.Require().Error(err)
s.Require().NotEqual("internal", err.Error())
} else {
var any types.Any
s.Require().NoError(val.ClientCtx.JSONMarshaler.UnmarshalJSON(out.Bytes(), &any))
var acc authtypes.AccountI
s.Require().NoError(val.ClientCtx.InterfaceRegistry.UnpackAny(&any, &acc))
s.Require().Equal(val.Address, acc.GetAddress())
}
})
}
}
func TestGetBroadcastCommand_OfflineFlag(t *testing.T) {
clientCtx := client.Context{}.WithOffline(true)
clientCtx = clientCtx.WithTxConfig(simapp.MakeEncodingConfig().TxConfig)

View File

@ -2,13 +2,10 @@ package keeper
import (
"context"
"fmt"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
proto "github.com/gogo/protobuf/proto"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/auth/types"
@ -32,12 +29,12 @@ func (ak AccountKeeper) Account(c context.Context, req *types.QueryAccountReques
return nil, status.Errorf(codes.NotFound, "account %s not found", req.Address)
}
acc, err := ConvertAccount(account)
any, err := codectypes.NewAnyWithValue(account)
if err != nil {
return nil, status.Errorf(codes.Internal, err.Error())
}
return &types.QueryAccountResponse{Account: acc}, nil
return &types.QueryAccountResponse{Account: any}, nil
}
// Params returns parameters of auth module
@ -50,18 +47,3 @@ func (ak AccountKeeper) Params(c context.Context, req *types.QueryParamsRequest)
return &types.QueryParamsResponse{Params: params}, nil
}
// ConvertAccount converts AccountI to Any type
func ConvertAccount(account types.AccountI) (*codectypes.Any, error) {
msg, ok := account.(proto.Message)
if !ok {
return nil, fmt.Errorf("can't protomarshal %T", msg)
}
any, err := codectypes.NewAnyWithValue(msg)
if err != nil {
return nil, err
}
return any, nil
}

View File

@ -7,6 +7,8 @@ import (
"fmt"
"strings"
"github.com/gogo/protobuf/proto"
"github.com/tendermint/tendermint/crypto"
yaml "gopkg.in/yaml.v2"
@ -292,6 +294,8 @@ func (ma *ModuleAccount) UnmarshalJSON(bz []byte) error {
//
// Many complex conditions can be used in the concrete struct which implements AccountI.
type AccountI interface {
proto.Message
GetAddress() sdk.AccAddress
SetAddress(sdk.AccAddress) error // errors if already set.

10
x/auth/types/query.go Normal file
View File

@ -0,0 +1,10 @@
package types
import codectypes "github.com/cosmos/cosmos-sdk/codec/types"
func (m *QueryAccountResponse) UnpackInterfaces(unpacker codectypes.AnyUnpacker) error {
var account AccountI
return unpacker.UnpackAny(m.Account, &account)
}
var _ codectypes.UnpackInterfacesMessage = &QueryAccountResponse{}

View File

@ -5,14 +5,15 @@ import (
"fmt"
"testing"
"github.com/cosmos/cosmos-sdk/client"
"github.com/gogo/protobuf/proto"
"github.com/stretchr/testify/suite"
tmcli "github.com/tendermint/tendermint/libs/cli"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/testutil"
clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli"
"github.com/cosmos/cosmos-sdk/testutil/network"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
@ -101,22 +102,13 @@ func (s *IntegrationTestSuite) TestGetBalancesCmd() {
s.Run(tc.name, func() {
cmd := cli.GetBalancesCmd()
_, out := testutil.ApplyMockIO(cmd)
out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, tc.args)
clientCtx := val.ClientCtx.WithOutput(out)
ctx := context.Background()
ctx = context.WithValue(ctx, client.ClientContextKey, &clientCtx)
out.Reset()
cmd.SetArgs(tc.args)
err := cmd.ExecuteContext(ctx)
if tc.expectErr {
s.Require().Error(err)
} else {
s.Require().NoError(err)
s.Require().NoError(clientCtx.JSONMarshaler.UnmarshalJSON(out.Bytes(), tc.respType))
s.Require().NoError(val.ClientCtx.JSONMarshaler.UnmarshalJSON(out.Bytes(), tc.respType))
s.Require().Equal(tc.expected.String(), tc.respType.String())
}
})
@ -173,17 +165,9 @@ func (s *IntegrationTestSuite) TestGetCmdQueryTotalSupply() {
s.Run(tc.name, func() {
cmd := cli.GetCmdQueryTotalSupply()
_, out := testutil.ApplyMockIO(cmd)
clientCtx := val.ClientCtx
clientCtx := val.ClientCtx.WithOutput(out)
ctx := context.Background()
ctx = context.WithValue(ctx, client.ClientContextKey, &clientCtx)
out.Reset()
cmd.SetArgs(tc.args)
err := cmd.ExecuteContext(ctx)
out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, tc.args)
if tc.expectErr {
s.Require().Error(err)
} else {
@ -295,9 +279,6 @@ func (s *IntegrationTestSuite) TestNewSendTxCmd() {
s.Run(tc.name, func() {
clientCtx := val.ClientCtx
ctx := context.Background()
ctx = context.WithValue(ctx, client.ClientContextKey, &clientCtx)
bz, err := banktestutil.MsgSendExec(clientCtx, tc.from, tc.to, tc.amount, tc.args...)
if tc.expectErr {
s.Require().Error(err)

View File

@ -3,6 +3,8 @@ package testutil
import (
"fmt"
"github.com/tendermint/tendermint/libs/cli"
"github.com/cosmos/cosmos-sdk/testutil"
clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli"
@ -19,7 +21,7 @@ func MsgSendExec(clientCtx client.Context, from, to, amount fmt.Stringer, extraA
}
func QueryBalancesExec(clientCtx client.Context, address fmt.Stringer, extraArgs ...string) (testutil.BufferWriter, error) {
args := []string{address.String()}
args := []string{address.String(), fmt.Sprintf("--%s=json", cli.OutputFlag)}
args = append(args, extraArgs...)
return clitestutil.ExecTestCLICmd(clientCtx, bankcli.GetBalancesCmd(), args)

View File

@ -1,15 +1,13 @@
package cli_test
import (
"context"
"fmt"
"testing"
"github.com/stretchr/testify/suite"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/testutil"
clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli"
"github.com/cosmos/cosmos-sdk/testutil/network"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/crisis/client/cli"
@ -90,17 +88,9 @@ func (s *IntegrationTestSuite) TestNewMsgVerifyInvariantTxCmd() {
s.Run(tc.name, func() {
cmd := cli.NewMsgVerifyInvariantTxCmd()
_, out := testutil.ApplyMockIO(cmd)
clientCtx := val.ClientCtx
clientCtx := val.ClientCtx.WithOutput(out)
ctx := context.Background()
ctx = context.WithValue(ctx, client.ClientContextKey, &clientCtx)
out.Reset()
cmd.SetArgs(tc.args)
err := cmd.ExecuteContext(ctx)
out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, tc.args)
if tc.expectErr {
s.Require().Error(err)
} else {

View File

@ -14,7 +14,7 @@ import (
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/testutil"
clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli"
testnet "github.com/cosmos/cosmos-sdk/testutil/network"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/distribution/client/cli"
@ -94,17 +94,10 @@ withdraw_addr_enabled: true`,
s.Run(tc.name, func() {
cmd := cli.GetCmdQueryParams()
_, out := testutil.ApplyMockIO(cmd)
clientCtx := val.ClientCtx
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))
out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, tc.args)
s.Require().NoError(err)
s.Require().Equal(tc.expectedOutput, strings.TrimSpace(out.String()))
})
}
@ -160,17 +153,9 @@ func (s *IntegrationTestSuite) TestGetCmdQueryValidatorOutstandingRewards() {
s.Run(tc.name, func() {
cmd := cli.GetCmdQueryValidatorOutstandingRewards()
_, out := testutil.ApplyMockIO(cmd)
clientCtx := val.ClientCtx
clientCtx := val.ClientCtx.WithOutput(out)
ctx := context.Background()
ctx = context.WithValue(ctx, client.ClientContextKey, &clientCtx)
out.Reset()
cmd.SetArgs(tc.args)
err := cmd.ExecuteContext(ctx)
out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, tc.args)
if tc.expectErr {
s.Require().Error(err)
} else {
@ -231,17 +216,9 @@ func (s *IntegrationTestSuite) TestGetCmdQueryValidatorCommission() {
s.Run(tc.name, func() {
cmd := cli.GetCmdQueryValidatorCommission()
_, out := testutil.ApplyMockIO(cmd)
clientCtx := val.ClientCtx
clientCtx := val.ClientCtx.WithOutput(out)
ctx := context.Background()
ctx = context.WithValue(ctx, client.ClientContextKey, &clientCtx)
out.Reset()
cmd.SetArgs(tc.args)
err := cmd.ExecuteContext(ctx)
out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, tc.args)
if tc.expectErr {
s.Require().Error(err)
} else {
@ -318,17 +295,9 @@ func (s *IntegrationTestSuite) TestGetCmdQueryValidatorSlashes() {
s.Run(tc.name, func() {
cmd := cli.GetCmdQueryValidatorSlashes()
_, out := testutil.ApplyMockIO(cmd)
clientCtx := val.ClientCtx
clientCtx := val.ClientCtx.WithOutput(out)
ctx := context.Background()
ctx = context.WithValue(ctx, client.ClientContextKey, &clientCtx)
out.Reset()
cmd.SetArgs(tc.args)
err := cmd.ExecuteContext(ctx)
out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, tc.args)
if tc.expectErr {
s.Require().Error(err)
} else {
@ -427,17 +396,9 @@ total:
s.Run(tc.name, func() {
cmd := cli.GetCmdQueryDelegatorRewards()
_, out := testutil.ApplyMockIO(cmd)
clientCtx := val.ClientCtx
clientCtx := val.ClientCtx.WithOutput(out)
ctx := context.Background()
ctx = context.WithValue(ctx, client.ClientContextKey, &clientCtx)
out.Reset()
cmd.SetArgs(tc.args)
err := cmd.ExecuteContext(ctx)
out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, tc.args)
if tc.expectErr {
s.Require().Error(err)
} else {
@ -478,17 +439,10 @@ func (s *IntegrationTestSuite) TestGetCmdQueryCommunityPool() {
s.Run(tc.name, func() {
cmd := cli.GetCmdQueryCommunityPool()
_, out := testutil.ApplyMockIO(cmd)
clientCtx := val.ClientCtx
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))
out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, tc.args)
s.Require().NoError(err)
s.Require().Equal(tc.expectedOutput, strings.TrimSpace(out.String()))
})
}
@ -601,17 +555,9 @@ func (s *IntegrationTestSuite) TestNewWithdrawAllRewardsCmd() {
s.Run(tc.name, func() {
cmd := cli.NewWithdrawAllRewardsCmd()
_, out := testutil.ApplyMockIO(cmd)
clientCtx := val.ClientCtx
clientCtx := val.ClientCtx.WithOutput(out)
ctx := context.Background()
ctx = context.WithValue(ctx, client.ClientContextKey, &clientCtx)
out.Reset()
cmd.SetArgs(tc.args)
err := cmd.ExecuteContext(ctx)
out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, tc.args)
if tc.expectErr {
s.Require().Error(err)
} else {
@ -664,17 +610,9 @@ func (s *IntegrationTestSuite) TestNewSetWithdrawAddrCmd() {
s.Run(tc.name, func() {
cmd := cli.NewSetWithdrawAddrCmd()
_, out := testutil.ApplyMockIO(cmd)
clientCtx := val.ClientCtx
clientCtx := val.ClientCtx.WithOutput(out)
ctx := context.Background()
ctx = context.WithValue(ctx, client.ClientContextKey, &clientCtx)
out.Reset()
cmd.SetArgs(tc.args)
err := cmd.ExecuteContext(ctx)
out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, tc.args)
if tc.expectErr {
s.Require().Error(err)
} else {
@ -727,17 +665,9 @@ func (s *IntegrationTestSuite) TestNewFundCommunityPoolCmd() {
s.Run(tc.name, func() {
cmd := cli.NewFundCommunityPoolCmd()
_, out := testutil.ApplyMockIO(cmd)
clientCtx := val.ClientCtx
clientCtx := val.ClientCtx.WithOutput(out)
ctx := context.Background()
ctx = context.WithValue(ctx, client.ClientContextKey, &clientCtx)
out.Reset()
cmd.SetArgs(tc.args)
err := cmd.ExecuteContext(ctx)
out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, tc.args)
if tc.expectErr {
s.Require().Error(err)
} else {
@ -820,18 +750,10 @@ func (s *IntegrationTestSuite) TestGetCmdSubmitProposal() {
s.Run(tc.name, func() {
cmd := cli.GetCmdSubmitProposal()
clientCtx := val.ClientCtx
flags.AddTxFlagsToCmd(cmd)
_, 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)
err := cmd.ExecuteContext(ctx)
out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, tc.args)
if tc.expectErr {
s.Require().Error(err)
} else {

View File

@ -1,7 +1,6 @@
package cli_test
import (
"context"
"fmt"
"io/ioutil"
"os"
@ -9,9 +8,8 @@ import (
"github.com/stretchr/testify/suite"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/testutil"
clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli"
"github.com/cosmos/cosmos-sdk/testutil/network"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/gov/client/cli"
@ -135,25 +133,14 @@ func (s *IntegrationTestSuite) TestNewCmdSubmitProposal() {
s.Run(tc.name, func() {
cmd := cli.NewCmdSubmitProposal()
_, out := testutil.ApplyMockIO(cmd)
clientCtx := val.ClientCtx
clientCtx := val.ClientCtx.WithOutput(out)
ctx := context.Background()
ctx = context.WithValue(ctx, client.ClientContextKey, &clientCtx)
out.Reset()
cmd.SetArgs(tc.args)
s.Require().NoError(s.network.WaitForNextBlock())
err := cmd.ExecuteContext(ctx)
out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, tc.args)
if tc.expectErr {
s.Require().Error(err)
} else {
s.Require().NoError(err)
s.Require().NoError(clientCtx.JSONMarshaler.UnmarshalJSON(out.Bytes(), tc.respType), out.String())
txResp := tc.respType.(*sdk.TxResponse)
s.Require().Equal(tc.expectedCode, txResp.Code, out.String())
}

View File

@ -1,7 +1,6 @@
package cli_test
import (
"context"
"fmt"
"strings"
"testing"
@ -9,9 +8,8 @@ import (
"github.com/stretchr/testify/suite"
tmcli "github.com/tendermint/tendermint/libs/cli"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/testutil"
clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli"
testnet "github.com/cosmos/cosmos-sdk/testutil/network"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/mint/client/cli"
@ -87,17 +85,10 @@ mint_denom: stake`,
s.Run(tc.name, func() {
cmd := cli.GetCmdQueryParams()
_, out := testutil.ApplyMockIO(cmd)
clientCtx := val.ClientCtx
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))
out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, tc.args)
s.Require().NoError(err)
s.Require().Equal(tc.expectedOutput, strings.TrimSpace(out.String()))
})
}
@ -128,17 +119,10 @@ func (s *IntegrationTestSuite) TestGetCmdQueryInflation() {
s.Run(tc.name, func() {
cmd := cli.GetCmdQueryInflation()
_, out := testutil.ApplyMockIO(cmd)
clientCtx := val.ClientCtx
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))
out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, tc.args)
s.Require().NoError(err)
s.Require().Equal(tc.expectedOutput, strings.TrimSpace(out.String()))
})
}
@ -169,17 +153,10 @@ func (s *IntegrationTestSuite) TestGetCmdQueryAnnualProvisions() {
s.Run(tc.name, func() {
cmd := cli.GetCmdQueryAnnualProvisions()
_, out := testutil.ApplyMockIO(cmd)
clientCtx := val.ClientCtx
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))
out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, tc.args)
s.Require().NoError(err)
s.Require().Equal(tc.expectedOutput, strings.TrimSpace(out.String()))
})
}

View File

@ -1,7 +1,6 @@
package cli_test
import (
"context"
"fmt"
"strings"
"testing"
@ -9,8 +8,7 @@ import (
"github.com/stretchr/testify/suite"
tmcli "github.com/tendermint/tendermint/libs/cli"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/testutil"
clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli"
"github.com/cosmos/cosmos-sdk/testutil/network"
"github.com/cosmos/cosmos-sdk/x/params/client/cli"
)
@ -73,17 +71,10 @@ value: "100"`,
s.Run(tc.name, func() {
cmd := cli.NewQuerySubspaceParamsCmd()
_, out := testutil.ApplyMockIO(cmd)
clientCtx := val.ClientCtx
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))
out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, tc.args)
s.Require().NoError(err)
s.Require().Equal(tc.expectedOutput, strings.TrimSpace(out.String()))
})
}

View File

@ -1,7 +1,6 @@
package cli_test
import (
"context"
"fmt"
"strings"
"testing"
@ -9,9 +8,8 @@ import (
"github.com/stretchr/testify/suite"
tmcli "github.com/tendermint/tendermint/libs/cli"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/testutil"
clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli"
"github.com/cosmos/cosmos-sdk/testutil/network"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/slashing/client/cli"
@ -91,17 +89,9 @@ tombstoned: false`, sdk.ConsAddress(val.PubKey.Address())),
s.Run(tc.name, func() {
cmd := cli.GetCmdQuerySigningInfo()
_, out := testutil.ApplyMockIO(cmd)
clientCtx := val.ClientCtx
clientCtx := val.ClientCtx.WithOutput(out)
ctx := context.Background()
ctx = context.WithValue(ctx, client.ClientContextKey, &clientCtx)
out.Reset()
cmd.SetArgs(tc.args)
err := cmd.ExecuteContext(ctx)
out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, tc.args)
if tc.expectErr {
s.Require().Error(err)
} else {
@ -141,17 +131,10 @@ slash_fraction_downtime: "0.010000000000000000"`,
s.Run(tc.name, func() {
cmd := cli.GetCmdQueryParams()
_, out := testutil.ApplyMockIO(cmd)
clientCtx := val.ClientCtx
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))
out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, tc.args)
s.Require().NoError(err)
s.Require().Equal(tc.expectedOutput, strings.TrimSpace(out.String()))
})
}
@ -184,17 +167,9 @@ func (s *IntegrationTestSuite) TestNewUnjailTxCmd() {
s.Run(tc.name, func() {
cmd := cli.NewUnjailTxCmd()
_, out := testutil.ApplyMockIO(cmd)
clientCtx := val.ClientCtx
clientCtx := val.ClientCtx.WithOutput(out)
ctx := context.Background()
ctx = context.WithValue(ctx, client.ClientContextKey, &clientCtx)
out.Reset()
cmd.SetArgs(tc.args)
err := cmd.ExecuteContext(ctx)
out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, tc.args)
if tc.expectErr {
s.Require().Error(err)
} else {

View File

@ -1,18 +1,16 @@
package cli_test
import (
"context"
"fmt"
"testing"
"github.com/stretchr/testify/suite"
"github.com/tendermint/tendermint/crypto/ed25519"
"github.com/cosmos/cosmos-sdk/client"
"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"
clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli"
"github.com/cosmos/cosmos-sdk/testutil/network"
sdk "github.com/cosmos/cosmos-sdk/types"
banktestutil "github.com/cosmos/cosmos-sdk/x/bank/client/testutil"
@ -158,17 +156,9 @@ func (s *IntegrationTestSuite) TestNewCreateValidatorCmd() {
s.Run(tc.name, func() {
cmd := cli.NewCreateValidatorCmd()
_, out := testutil.ApplyMockIO(cmd)
clientCtx := val.ClientCtx
clientCtx := val.ClientCtx.WithOutput(out)
ctx := context.Background()
ctx = context.WithValue(ctx, client.ClientContextKey, &clientCtx)
out.Reset()
cmd.SetArgs(tc.args)
err := cmd.ExecuteContext(ctx)
out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, tc.args)
if tc.expectErr {
s.Require().Error(err)
} else {