2020-05-04 06:55:16 -07:00
|
|
|
package testutil
|
2020-04-29 08:52:30 -07:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2020-04-29 19:36:34 -07:00
|
|
|
|
2020-07-14 11:37:14 -07:00
|
|
|
"github.com/cosmos/cosmos-sdk/testutil"
|
|
|
|
|
|
|
|
clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli"
|
|
|
|
|
2020-04-29 19:36:34 -07:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
2020-07-02 06:02:28 -07:00
|
|
|
"github.com/cosmos/cosmos-sdk/client"
|
2020-04-29 08:52:30 -07:00
|
|
|
clientkeys "github.com/cosmos/cosmos-sdk/client/keys"
|
|
|
|
"github.com/cosmos/cosmos-sdk/tests"
|
2020-05-01 13:16:17 -07:00
|
|
|
"github.com/cosmos/cosmos-sdk/tests/cli"
|
2020-04-29 08:52:30 -07:00
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
2020-07-02 06:02:28 -07:00
|
|
|
bankcli "github.com/cosmos/cosmos-sdk/x/bank/client/cli"
|
2020-04-29 08:52:30 -07:00
|
|
|
)
|
|
|
|
|
2020-07-14 11:37:14 -07:00
|
|
|
func MsgSendExec(clientCtx client.Context, from, to, amount fmt.Stringer, extraArgs ...string) (testutil.BufferWriter, error) {
|
2020-07-02 06:02:28 -07:00
|
|
|
args := []string{from.String(), to.String(), amount.String()}
|
|
|
|
args = append(args, extraArgs...)
|
|
|
|
|
2020-07-14 11:37:14 -07:00
|
|
|
return clitestutil.ExecTestCLICmd(clientCtx, bankcli.NewSendTxCmd(), args)
|
|
|
|
}
|
2020-07-02 06:02:28 -07:00
|
|
|
|
2020-07-14 11:37:14 -07:00
|
|
|
func QueryBalancesExec(clientCtx client.Context, address fmt.Stringer, extraArgs ...string) (testutil.BufferWriter, error) {
|
|
|
|
args := []string{address.String()}
|
|
|
|
args = append(args, extraArgs...)
|
2020-07-02 06:02:28 -07:00
|
|
|
|
2020-07-14 11:37:14 -07:00
|
|
|
return clitestutil.ExecTestCLICmd(clientCtx, bankcli.GetBalancesCmd(), args)
|
2020-07-02 06:02:28 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// TODO: REMOVE ALL FUNCTIONS BELOW.
|
|
|
|
//
|
|
|
|
// REF: https://github.com/cosmos/cosmos-sdk/issues/6571
|
|
|
|
// ----------------------------------------------------------------------------
|
2020-06-30 13:59:21 -07:00
|
|
|
|
2020-04-29 08:52:30 -07:00
|
|
|
// TxSend is simcli tx send
|
2020-05-01 13:16:17 -07:00
|
|
|
func TxSend(f *cli.Fixtures, from string, to sdk.AccAddress, amount sdk.Coin, flags ...string) (bool, string, string) {
|
2020-07-07 08:40:46 -07:00
|
|
|
cmd := fmt.Sprintf("%s tx send --keyring-backend=test %s %s %s %v", f.SimdBinary, from, to, amount, f.Flags())
|
2020-05-01 13:16:17 -07:00
|
|
|
return cli.ExecuteWriteRetStdStreams(f.T, cli.AddFlags(cmd, flags), clientkeys.DefaultKeyPass)
|
2020-04-29 08:52:30 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// QueryBalances executes the bank query balances command for a given address and
|
|
|
|
// flag set.
|
2020-05-01 13:16:17 -07:00
|
|
|
func QueryBalances(f *cli.Fixtures, address sdk.AccAddress, flags ...string) sdk.Coins {
|
2020-07-07 08:40:46 -07:00
|
|
|
cmd := fmt.Sprintf("%s query bank balances %s %v", f.SimdBinary, address, f.Flags())
|
2020-05-01 13:16:17 -07:00
|
|
|
out, _ := tests.ExecuteT(f.T, cli.AddFlags(cmd, flags), "")
|
2020-04-29 08:52:30 -07:00
|
|
|
|
|
|
|
var balances sdk.Coins
|
|
|
|
|
|
|
|
require.NoError(f.T, f.Cdc.UnmarshalJSON([]byte(out), &balances), "out %v\n", out)
|
|
|
|
|
|
|
|
return balances
|
|
|
|
}
|