github.com/cosmos/cosmos-sdk@v0.50.10/testutil/cli/cmd.go (about)

     1  package cli
     2  
     3  import (
     4  	"context"
     5  	"fmt"
     6  
     7  	"github.com/spf13/cobra"
     8  
     9  	"cosmossdk.io/core/address"
    10  
    11  	"github.com/cosmos/cosmos-sdk/client"
    12  	"github.com/cosmos/cosmos-sdk/testutil"
    13  	"github.com/cosmos/cosmos-sdk/x/bank/client/cli"
    14  )
    15  
    16  // ExecTestCLICmd builds the client context, mocks the output and executes the command.
    17  func ExecTestCLICmd(clientCtx client.Context, cmd *cobra.Command, extraArgs []string) (testutil.BufferWriter, error) {
    18  	cmd.SetArgs(extraArgs)
    19  
    20  	_, out := testutil.ApplyMockIO(cmd)
    21  	clientCtx = clientCtx.WithOutput(out)
    22  
    23  	ctx := context.Background()
    24  	ctx = context.WithValue(ctx, client.ClientContextKey, &clientCtx)
    25  
    26  	if err := cmd.ExecuteContext(ctx); err != nil {
    27  		return out, err
    28  	}
    29  
    30  	return out, nil
    31  }
    32  
    33  func MsgSendExec(clientCtx client.Context, from, to, amount fmt.Stringer, ac address.Codec, extraArgs ...string) (testutil.BufferWriter, error) {
    34  	args := []string{from.String(), to.String(), amount.String()}
    35  	args = append(args, extraArgs...)
    36  
    37  	return ExecTestCLICmd(clientCtx, cli.NewSendTxCmd(ac), args)
    38  }