chore!: Refactor x/bank CLI Tests (#12706)
This commit is contained in:
@@ -22,3 +22,26 @@ type AccountRetriever interface {
|
||||
EnsureExists(clientCtx Context, addr sdk.AccAddress) error
|
||||
GetAccountNumberSequence(clientCtx Context, addr sdk.AccAddress) (accNum uint64, accSeq uint64, err error)
|
||||
}
|
||||
|
||||
var _ AccountRetriever = (*MockAccountRetriever)(nil)
|
||||
|
||||
// MockAccountRetriever defines a no-op basic AccountRetriever that can be used
|
||||
// in mocked contexts. Tests or context that need more sophisticated testing
|
||||
// state should implement their own mock AccountRetriever.
|
||||
type MockAccountRetriever struct{}
|
||||
|
||||
func (mar MockAccountRetriever) GetAccount(_ Context, _ sdk.AccAddress) (Account, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (mar MockAccountRetriever) GetAccountWithHeight(_ Context, _ sdk.AccAddress) (Account, int64, error) {
|
||||
return nil, 0, nil
|
||||
}
|
||||
|
||||
func (mar MockAccountRetriever) EnsureExists(_ Context, _ sdk.AccAddress) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (mar MockAccountRetriever) GetAccountNumberSequence(_ Context, _ sdk.AccAddress) (uint64, uint64, error) {
|
||||
return 0, 0, nil
|
||||
}
|
||||
|
||||
+5
-9
@@ -7,14 +7,10 @@ import (
|
||||
"io"
|
||||
"os"
|
||||
|
||||
"github.com/spf13/viper"
|
||||
|
||||
"sigs.k8s.io/yaml"
|
||||
|
||||
"google.golang.org/grpc"
|
||||
|
||||
"github.com/gogo/protobuf/proto"
|
||||
rpcclient "github.com/tendermint/tendermint/rpc/client"
|
||||
"github.com/spf13/viper"
|
||||
"google.golang.org/grpc"
|
||||
"sigs.k8s.io/yaml"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
|
||||
@@ -26,7 +22,7 @@ import (
|
||||
// handling and queries.
|
||||
type Context struct {
|
||||
FromAddress sdk.AccAddress
|
||||
Client rpcclient.Client
|
||||
Client TendermintRPC
|
||||
GRPCClient *grpc.ClientConn
|
||||
ChainID string
|
||||
Codec codec.Codec
|
||||
@@ -128,7 +124,7 @@ func (ctx Context) WithHeight(height int64) Context {
|
||||
|
||||
// WithClient returns a copy of the context with an updated RPC client
|
||||
// instance.
|
||||
func (ctx Context) WithClient(client rpcclient.Client) Context {
|
||||
func (ctx Context) WithClient(client TendermintRPC) Context {
|
||||
ctx.Client = client
|
||||
return ctx
|
||||
}
|
||||
|
||||
@@ -79,6 +79,7 @@ const (
|
||||
FlagReverse = "reverse"
|
||||
FlagTip = "tip"
|
||||
FlagAux = "aux"
|
||||
FlagOutput = tmcli.OutputFlag
|
||||
|
||||
// Tendermint logging flags
|
||||
FlagLogLevel = "log_level"
|
||||
@@ -93,7 +94,7 @@ var LineBreak = &cobra.Command{Run: func(*cobra.Command, []string) {}}
|
||||
func AddQueryFlagsToCmd(cmd *cobra.Command) {
|
||||
cmd.Flags().String(FlagNode, "tcp://localhost:26657", "<host>:<port> to Tendermint RPC interface for this chain")
|
||||
cmd.Flags().Int64(FlagHeight, 0, "Use a specific height to query state at (this can error if the node is pruning state)")
|
||||
cmd.Flags().StringP(tmcli.OutputFlag, "o", "text", "Output format (text|json)")
|
||||
cmd.Flags().StringP(FlagOutput, "o", "text", "Output format (text|json)")
|
||||
|
||||
// some base commands does not require chainID e.g `simd testnet` while subcommands do
|
||||
// hence the flag should not be required for those commands
|
||||
@@ -102,7 +103,7 @@ func AddQueryFlagsToCmd(cmd *cobra.Command) {
|
||||
|
||||
// AddTxFlagsToCmd adds common flags to a module tx command.
|
||||
func AddTxFlagsToCmd(cmd *cobra.Command) {
|
||||
cmd.Flags().StringP(tmcli.OutputFlag, "o", "json", "Output format (text|json)")
|
||||
cmd.Flags().StringP(FlagOutput, "o", "json", "Output format (text|json)")
|
||||
cmd.Flags().String(FlagKeyringDir, "", "The client Keyring directory; if omitted, the default 'home' directory will be used")
|
||||
cmd.Flags().String(FlagFrom, "", "Name or address of private key with which to sign")
|
||||
cmd.Flags().Uint64P(FlagAccountNumber, "a", 0, "The account number of the signing account (offline mode only)")
|
||||
@@ -125,6 +126,7 @@ func AddTxFlagsToCmd(cmd *cobra.Command) {
|
||||
cmd.Flags().String(FlagFeeGranter, "", "Fee granter grants fees for the transaction")
|
||||
cmd.Flags().String(FlagTip, "", "Tip is the amount that is going to be transferred to the fee payer on the target chain. This flag is only valid when used with --aux, and is ignored if the target chain didn't enable the TipDecorator")
|
||||
cmd.Flags().Bool(FlagAux, false, "Generate aux signer data instead of sending a tx")
|
||||
cmd.Flags().String(FlagChainID, "", "The network chain ID")
|
||||
|
||||
// --gas can accept integers and "auto"
|
||||
cmd.Flags().String(FlagGas, "", fmt.Sprintf("gas limit to set per-transaction; set to %q to calculate sufficient gas automatically (default %d)", GasFlagAuto, DefaultGasLimit))
|
||||
|
||||
@@ -7,10 +7,11 @@ import (
|
||||
"reflect"
|
||||
"strconv"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
proto "github.com/gogo/protobuf/proto"
|
||||
"google.golang.org/grpc/encoding"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
|
||||
gogogrpc "github.com/gogo/protobuf/grpc"
|
||||
abci "github.com/tendermint/tendermint/abci/types"
|
||||
"google.golang.org/grpc"
|
||||
|
||||
+3
-4
@@ -6,12 +6,11 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
|
||||
abci "github.com/tendermint/tendermint/abci/types"
|
||||
tmbytes "github.com/tendermint/tendermint/libs/bytes"
|
||||
rpcclient "github.com/tendermint/tendermint/rpc/client"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/store/rootmulti"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
@@ -20,7 +19,7 @@ import (
|
||||
|
||||
// GetNode returns an RPC client. If the context's client is not defined, an
|
||||
// error is returned.
|
||||
func (ctx Context) GetNode() (rpcclient.Client, error) {
|
||||
func (ctx Context) GetNode() (TendermintRPC, error) {
|
||||
if ctx.Client == nil {
|
||||
return nil, errors.New("no RPC client is defined in offline mode")
|
||||
}
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
package client
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/tendermint/tendermint/libs/bytes"
|
||||
rpcclient "github.com/tendermint/tendermint/rpc/client"
|
||||
"github.com/tendermint/tendermint/rpc/coretypes"
|
||||
)
|
||||
|
||||
// TendermintRPC defines the interface of a Tendermint RPC client needed for
|
||||
// queries and transaction handling.
|
||||
type TendermintRPC interface {
|
||||
rpcclient.ABCIClient
|
||||
|
||||
Validators(ctx context.Context, height *int64, page, perPage *int) (*coretypes.ResultValidators, error)
|
||||
Status(context.Context) (*coretypes.ResultStatus, error)
|
||||
Block(ctx context.Context, height *int64) (*coretypes.ResultBlock, error)
|
||||
BlockchainInfo(ctx context.Context, minHeight, maxHeight int64) (*coretypes.ResultBlockchainInfo, error)
|
||||
Tx(ctx context.Context, hash bytes.HexBytes, prove bool) (*coretypes.ResultTx, error)
|
||||
TxSearch(
|
||||
ctx context.Context,
|
||||
query string,
|
||||
prove bool,
|
||||
page, perPage *int,
|
||||
orderBy string,
|
||||
) (*coretypes.ResultTxSearch, error)
|
||||
}
|
||||
@@ -392,7 +392,6 @@ func (f Factory) getSimPK() (cryptotypes.PubKey, error) {
|
||||
// the updated fields will be returned.
|
||||
func (f Factory) Prepare(clientCtx client.Context) (Factory, error) {
|
||||
fc := f
|
||||
|
||||
from := clientCtx.GetFromAddress()
|
||||
|
||||
if err := fc.accountRetriever.EnsureExists(clientCtx, from); err != nil {
|
||||
|
||||
Reference in New Issue
Block a user