2020-04-29 08:52:30 -07:00
|
|
|
package cli
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"fmt"
|
2020-04-29 19:36:34 -07:00
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
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"
|
|
|
|
"github.com/cosmos/cosmos-sdk/x/auth"
|
|
|
|
)
|
|
|
|
|
|
|
|
// 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-04-29 08:52:30 -07:00
|
|
|
cmd := fmt.Sprintf("%s tx send --keyring-backend=test %s %s %s %v", f.SimcliBinary, 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
|
|
|
}
|
|
|
|
|
|
|
|
// QueryAccount is simcli query account
|
2020-05-01 13:16:17 -07:00
|
|
|
func QueryAccount(f *cli.Fixtures, address sdk.AccAddress, flags ...string) auth.BaseAccount {
|
2020-04-29 08:52:30 -07:00
|
|
|
cmd := fmt.Sprintf("%s query account %s %v", f.SimcliBinary, 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 initRes map[string]json.RawMessage
|
|
|
|
err := json.Unmarshal([]byte(out), &initRes)
|
|
|
|
require.NoError(f.T, err, "out %v, err %v", out, err)
|
|
|
|
value := initRes["value"]
|
|
|
|
|
|
|
|
var acc auth.BaseAccount
|
|
|
|
err = f.Cdc.UnmarshalJSON(value, &acc)
|
|
|
|
require.NoError(f.T, err, "value %v, err %v", string(value), err)
|
|
|
|
|
|
|
|
return acc
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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-04-29 08:52:30 -07:00
|
|
|
cmd := fmt.Sprintf("%s query bank balances %s %v", f.SimcliBinary, 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
|
|
|
|
}
|