refactor: simplify cli test RunCmd

This commit is contained in:
Dirk McCormick 2020-10-26 14:26:46 +01:00
parent b097a5fb0c
commit 1fefcc2b46
4 changed files with 75 additions and 112 deletions

View File

@ -37,6 +37,7 @@ func init() {
// commands // commands
func TestPaymentChannels(t *testing.T) { func TestPaymentChannels(t *testing.T) {
_ = os.Setenv("BELLMAN_NO_GPU", "1") _ = os.Setenv("BELLMAN_NO_GPU", "1")
clitest.QuietMiningLogs()
blocktime := 5 * time.Millisecond blocktime := 5 * time.Millisecond
ctx := context.Background() ctx := context.Background()
@ -53,8 +54,7 @@ func TestPaymentChannels(t *testing.T) {
// creator: paych add-funds <creator> <receiver> <amount> // creator: paych add-funds <creator> <receiver> <amount>
channelAmt := "100000" channelAmt := "100000"
cmd := []string{"paych", "add-funds", creatorAddr.String(), receiverAddr.String(), channelAmt} chstr := creatorCLI.RunCmd("paych", "add-funds", creatorAddr.String(), receiverAddr.String(), channelAmt)
chstr := creatorCLI.RunCmd(cmd)
chAddr, err := address.NewFromString(chstr) chAddr, err := address.NewFromString(chstr)
require.NoError(t, err) require.NoError(t, err)
@ -62,16 +62,13 @@ func TestPaymentChannels(t *testing.T) {
// creator: paych voucher create <channel> <amount> // creator: paych voucher create <channel> <amount>
voucherAmt := 100 voucherAmt := 100
vamt := strconv.Itoa(voucherAmt) vamt := strconv.Itoa(voucherAmt)
cmd = []string{"paych", "voucher", "create", chAddr.String(), vamt} voucher := creatorCLI.RunCmd("paych", "voucher", "create", chAddr.String(), vamt)
voucher := creatorCLI.RunCmd(cmd)
// receiver: paych voucher add <channel> <voucher> // receiver: paych voucher add <channel> <voucher>
cmd = []string{"paych", "voucher", "add", chAddr.String(), voucher} receiverCLI.RunCmd("paych", "voucher", "add", chAddr.String(), voucher)
receiverCLI.RunCmd(cmd)
// creator: paych settle <channel> // creator: paych settle <channel>
cmd = []string{"paych", "settle", chAddr.String()} creatorCLI.RunCmd("paych", "settle", chAddr.String())
creatorCLI.RunCmd(cmd)
// Wait for the chain to reach the settle height // Wait for the chain to reach the settle height
chState := getPaychState(ctx, t, paymentReceiver, chAddr) chState := getPaychState(ctx, t, paymentReceiver, chAddr)
@ -80,8 +77,7 @@ func TestPaymentChannels(t *testing.T) {
waitForHeight(ctx, t, paymentReceiver, sa) waitForHeight(ctx, t, paymentReceiver, sa)
// receiver: paych collect <channel> // receiver: paych collect <channel>
cmd = []string{"paych", "collect", chAddr.String()} receiverCLI.RunCmd("paych", "collect", chAddr.String())
receiverCLI.RunCmd(cmd)
} }
type voucherSpec struct { type voucherSpec struct {
@ -93,6 +89,7 @@ type voucherSpec struct {
// TestPaymentChannelStatus tests the payment channel status CLI command // TestPaymentChannelStatus tests the payment channel status CLI command
func TestPaymentChannelStatus(t *testing.T) { func TestPaymentChannelStatus(t *testing.T) {
_ = os.Setenv("BELLMAN_NO_GPU", "1") _ = os.Setenv("BELLMAN_NO_GPU", "1")
clitest.QuietMiningLogs()
blocktime := 5 * time.Millisecond blocktime := 5 * time.Millisecond
ctx := context.Background() ctx := context.Background()
@ -106,8 +103,7 @@ func TestPaymentChannelStatus(t *testing.T) {
creatorCLI := mockCLI.Client(paymentCreator.ListenAddr) creatorCLI := mockCLI.Client(paymentCreator.ListenAddr)
// creator: paych status-by-from-to <creator> <receiver> // creator: paych status-by-from-to <creator> <receiver>
cmd := []string{"paych", "status-by-from-to", creatorAddr.String(), receiverAddr.String()} out := creatorCLI.RunCmd("paych", "status-by-from-to", creatorAddr.String(), receiverAddr.String())
out := creatorCLI.RunCmd(cmd)
fmt.Println(out) fmt.Println(out)
noChannelState := "Channel does not exist" noChannelState := "Channel does not exist"
require.Regexp(t, regexp.MustCompile(noChannelState), out) require.Regexp(t, regexp.MustCompile(noChannelState), out)
@ -116,14 +112,17 @@ func TestPaymentChannelStatus(t *testing.T) {
create := make(chan string) create := make(chan string)
go func() { go func() {
// creator: paych add-funds <creator> <receiver> <amount> // creator: paych add-funds <creator> <receiver> <amount>
cmd := []string{"paych", "add-funds", creatorAddr.String(), receiverAddr.String(), fmt.Sprintf("%d", channelAmt)} create <- creatorCLI.RunCmd(
create <- creatorCLI.RunCmd(cmd) "paych",
"add-funds",
creatorAddr.String(),
receiverAddr.String(),
fmt.Sprintf("%d", channelAmt))
}() }()
// Wait for the output to stop being "Channel does not exist" // Wait for the output to stop being "Channel does not exist"
for regexp.MustCompile(noChannelState).MatchString(out) { for regexp.MustCompile(noChannelState).MatchString(out) {
cmd := []string{"paych", "status-by-from-to", creatorAddr.String(), receiverAddr.String()} out = creatorCLI.RunCmd("paych", "status-by-from-to", creatorAddr.String(), receiverAddr.String())
out = creatorCLI.RunCmd(cmd)
} }
fmt.Println(out) fmt.Println(out)
@ -143,8 +142,7 @@ func TestPaymentChannelStatus(t *testing.T) {
// Wait for create channel to complete // Wait for create channel to complete
chstr := <-create chstr := <-create
cmd = []string{"paych", "status", chstr} out = creatorCLI.RunCmd("paych", "status", chstr)
out = creatorCLI.RunCmd(cmd)
fmt.Println(out) fmt.Println(out)
// Output should have the channel address // Output should have the channel address
require.Regexp(t, regexp.MustCompile("Channel.*"+chstr), out) require.Regexp(t, regexp.MustCompile("Channel.*"+chstr), out)
@ -156,11 +154,9 @@ func TestPaymentChannelStatus(t *testing.T) {
// creator: paych voucher create <channel> <amount> // creator: paych voucher create <channel> <amount>
voucherAmt := uint64(10) voucherAmt := uint64(10)
cmd = []string{"paych", "voucher", "create", chAddr.String(), fmt.Sprintf("%d", voucherAmt)} creatorCLI.RunCmd("paych", "voucher", "create", chAddr.String(), fmt.Sprintf("%d", voucherAmt))
creatorCLI.RunCmd(cmd)
cmd = []string{"paych", "status", chstr} out = creatorCLI.RunCmd("paych", "status", chstr)
out = creatorCLI.RunCmd(cmd)
fmt.Println(out) fmt.Println(out)
voucherAmtAtto := types.BigMul(types.NewInt(voucherAmt), types.NewInt(build.FilecoinPrecision)) voucherAmtAtto := types.BigMul(types.NewInt(voucherAmt), types.NewInt(build.FilecoinPrecision))
voucherAmtStr := fmt.Sprintf("%d", voucherAmtAtto) voucherAmtStr := fmt.Sprintf("%d", voucherAmtAtto)
@ -172,6 +168,7 @@ func TestPaymentChannelStatus(t *testing.T) {
// channel voucher commands // channel voucher commands
func TestPaymentChannelVouchers(t *testing.T) { func TestPaymentChannelVouchers(t *testing.T) {
_ = os.Setenv("BELLMAN_NO_GPU", "1") _ = os.Setenv("BELLMAN_NO_GPU", "1")
clitest.QuietMiningLogs()
blocktime := 5 * time.Millisecond blocktime := 5 * time.Millisecond
ctx := context.Background() ctx := context.Background()
@ -188,8 +185,7 @@ func TestPaymentChannelVouchers(t *testing.T) {
// creator: paych add-funds <creator> <receiver> <amount> // creator: paych add-funds <creator> <receiver> <amount>
channelAmt := "100000" channelAmt := "100000"
cmd := []string{"paych", "add-funds", creatorAddr.String(), receiverAddr.String(), channelAmt} chstr := creatorCLI.RunCmd("paych", "add-funds", creatorAddr.String(), receiverAddr.String(), channelAmt)
chstr := creatorCLI.RunCmd(cmd)
chAddr, err := address.NewFromString(chstr) chAddr, err := address.NewFromString(chstr)
require.NoError(t, err) require.NoError(t, err)
@ -199,39 +195,33 @@ func TestPaymentChannelVouchers(t *testing.T) {
// creator: paych voucher create <channel> <amount> // creator: paych voucher create <channel> <amount>
// Note: implied --lane=0 // Note: implied --lane=0
voucherAmt1 := 100 voucherAmt1 := 100
cmd = []string{"paych", "voucher", "create", chAddr.String(), strconv.Itoa(voucherAmt1)} voucher1 := creatorCLI.RunCmd("paych", "voucher", "create", chAddr.String(), strconv.Itoa(voucherAmt1))
voucher1 := creatorCLI.RunCmd(cmd)
vouchers = append(vouchers, voucherSpec{serialized: voucher1, lane: 0, amt: voucherAmt1}) vouchers = append(vouchers, voucherSpec{serialized: voucher1, lane: 0, amt: voucherAmt1})
// creator: paych voucher create <channel> <amount> --lane=5 // creator: paych voucher create <channel> <amount> --lane=5
lane5 := "--lane=5" lane5 := "--lane=5"
voucherAmt2 := 50 voucherAmt2 := 50
cmd = []string{"paych", "voucher", "create", lane5, chAddr.String(), strconv.Itoa(voucherAmt2)} voucher2 := creatorCLI.RunCmd("paych", "voucher", "create", lane5, chAddr.String(), strconv.Itoa(voucherAmt2))
voucher2 := creatorCLI.RunCmd(cmd)
vouchers = append(vouchers, voucherSpec{serialized: voucher2, lane: 5, amt: voucherAmt2}) vouchers = append(vouchers, voucherSpec{serialized: voucher2, lane: 5, amt: voucherAmt2})
// creator: paych voucher create <channel> <amount> --lane=5 // creator: paych voucher create <channel> <amount> --lane=5
voucherAmt3 := 70 voucherAmt3 := 70
cmd = []string{"paych", "voucher", "create", lane5, chAddr.String(), strconv.Itoa(voucherAmt3)} voucher3 := creatorCLI.RunCmd("paych", "voucher", "create", lane5, chAddr.String(), strconv.Itoa(voucherAmt3))
voucher3 := creatorCLI.RunCmd(cmd)
vouchers = append(vouchers, voucherSpec{serialized: voucher3, lane: 5, amt: voucherAmt3}) vouchers = append(vouchers, voucherSpec{serialized: voucher3, lane: 5, amt: voucherAmt3})
// creator: paych voucher create <channel> <amount> --lane=5 // creator: paych voucher create <channel> <amount> --lane=5
voucherAmt4 := 80 voucherAmt4 := 80
cmd = []string{"paych", "voucher", "create", lane5, chAddr.String(), strconv.Itoa(voucherAmt4)} voucher4 := creatorCLI.RunCmd("paych", "voucher", "create", lane5, chAddr.String(), strconv.Itoa(voucherAmt4))
voucher4 := creatorCLI.RunCmd(cmd)
vouchers = append(vouchers, voucherSpec{serialized: voucher4, lane: 5, amt: voucherAmt4}) vouchers = append(vouchers, voucherSpec{serialized: voucher4, lane: 5, amt: voucherAmt4})
// creator: paych voucher list <channel> --export // creator: paych voucher list <channel> --export
cmd = []string{"paych", "voucher", "list", "--export", chAddr.String()} list := creatorCLI.RunCmd("paych", "voucher", "list", "--export", chAddr.String())
list := creatorCLI.RunCmd(cmd)
// Check that voucher list output is correct on creator // Check that voucher list output is correct on creator
checkVoucherOutput(t, list, vouchers) checkVoucherOutput(t, list, vouchers)
// creator: paych voucher best-spendable <channel> // creator: paych voucher best-spendable <channel>
cmd = []string{"paych", "voucher", "best-spendable", "--export", chAddr.String()} bestSpendable := creatorCLI.RunCmd("paych", "voucher", "best-spendable", "--export", chAddr.String())
bestSpendable := creatorCLI.RunCmd(cmd)
// Check that best spendable output is correct on creator // Check that best spendable output is correct on creator
bestVouchers := []voucherSpec{ bestVouchers := []voucherSpec{
@ -241,31 +231,25 @@ func TestPaymentChannelVouchers(t *testing.T) {
checkVoucherOutput(t, bestSpendable, bestVouchers) checkVoucherOutput(t, bestSpendable, bestVouchers)
// receiver: paych voucher add <voucher> // receiver: paych voucher add <voucher>
cmd = []string{"paych", "voucher", "add", chAddr.String(), voucher1} receiverCLI.RunCmd("paych", "voucher", "add", chAddr.String(), voucher1)
receiverCLI.RunCmd(cmd)
// receiver: paych voucher add <voucher> // receiver: paych voucher add <voucher>
cmd = []string{"paych", "voucher", "add", chAddr.String(), voucher2} receiverCLI.RunCmd("paych", "voucher", "add", chAddr.String(), voucher2)
receiverCLI.RunCmd(cmd)
// receiver: paych voucher add <voucher> // receiver: paych voucher add <voucher>
cmd = []string{"paych", "voucher", "add", chAddr.String(), voucher3} receiverCLI.RunCmd("paych", "voucher", "add", chAddr.String(), voucher3)
receiverCLI.RunCmd(cmd)
// receiver: paych voucher add <voucher> // receiver: paych voucher add <voucher>
cmd = []string{"paych", "voucher", "add", chAddr.String(), voucher4} receiverCLI.RunCmd("paych", "voucher", "add", chAddr.String(), voucher4)
receiverCLI.RunCmd(cmd)
// receiver: paych voucher list <channel> --export // receiver: paych voucher list <channel> --export
cmd = []string{"paych", "voucher", "list", "--export", chAddr.String()} list = receiverCLI.RunCmd("paych", "voucher", "list", "--export", chAddr.String())
list = receiverCLI.RunCmd(cmd)
// Check that voucher list output is correct on receiver // Check that voucher list output is correct on receiver
checkVoucherOutput(t, list, vouchers) checkVoucherOutput(t, list, vouchers)
// receiver: paych voucher best-spendable <channel> // receiver: paych voucher best-spendable <channel>
cmd = []string{"paych", "voucher", "best-spendable", "--export", chAddr.String()} bestSpendable = receiverCLI.RunCmd("paych", "voucher", "best-spendable", "--export", chAddr.String())
bestSpendable = receiverCLI.RunCmd(cmd)
// Check that best spendable output is correct on receiver // Check that best spendable output is correct on receiver
bestVouchers = []voucherSpec{ bestVouchers = []voucherSpec{
@ -275,12 +259,10 @@ func TestPaymentChannelVouchers(t *testing.T) {
checkVoucherOutput(t, bestSpendable, bestVouchers) checkVoucherOutput(t, bestSpendable, bestVouchers)
// receiver: paych voucher submit <channel> <voucher> // receiver: paych voucher submit <channel> <voucher>
cmd = []string{"paych", "voucher", "submit", chAddr.String(), voucher1} receiverCLI.RunCmd("paych", "voucher", "submit", chAddr.String(), voucher1)
receiverCLI.RunCmd(cmd)
// receiver: paych voucher best-spendable <channel> // receiver: paych voucher best-spendable <channel>
cmd = []string{"paych", "voucher", "best-spendable", "--export", chAddr.String()} bestSpendable = receiverCLI.RunCmd("paych", "voucher", "best-spendable", "--export", chAddr.String())
bestSpendable = receiverCLI.RunCmd(cmd)
// Check that best spendable output no longer includes submitted voucher // Check that best spendable output no longer includes submitted voucher
bestVouchers = []voucherSpec{ bestVouchers = []voucherSpec{
@ -291,12 +273,10 @@ func TestPaymentChannelVouchers(t *testing.T) {
// There are three vouchers in lane 5: 50, 70, 80 // There are three vouchers in lane 5: 50, 70, 80
// Submit the voucher for 50. Best spendable should still be 80. // Submit the voucher for 50. Best spendable should still be 80.
// receiver: paych voucher submit <channel> <voucher> // receiver: paych voucher submit <channel> <voucher>
cmd = []string{"paych", "voucher", "submit", chAddr.String(), voucher2} receiverCLI.RunCmd("paych", "voucher", "submit", chAddr.String(), voucher2)
receiverCLI.RunCmd(cmd)
// receiver: paych voucher best-spendable <channel> // receiver: paych voucher best-spendable <channel>
cmd = []string{"paych", "voucher", "best-spendable", "--export", chAddr.String()} bestSpendable = receiverCLI.RunCmd("paych", "voucher", "best-spendable", "--export", chAddr.String())
bestSpendable = receiverCLI.RunCmd(cmd)
// Check that best spendable output still includes the voucher for 80 // Check that best spendable output still includes the voucher for 80
bestVouchers = []voucherSpec{ bestVouchers = []voucherSpec{
@ -306,12 +286,10 @@ func TestPaymentChannelVouchers(t *testing.T) {
// Submit the voucher for 80 // Submit the voucher for 80
// receiver: paych voucher submit <channel> <voucher> // receiver: paych voucher submit <channel> <voucher>
cmd = []string{"paych", "voucher", "submit", chAddr.String(), voucher4} receiverCLI.RunCmd("paych", "voucher", "submit", chAddr.String(), voucher4)
receiverCLI.RunCmd(cmd)
// receiver: paych voucher best-spendable <channel> // receiver: paych voucher best-spendable <channel>
cmd = []string{"paych", "voucher", "best-spendable", "--export", chAddr.String()} bestSpendable = receiverCLI.RunCmd("paych", "voucher", "best-spendable", "--export", chAddr.String())
bestSpendable = receiverCLI.RunCmd(cmd)
// Check that best spendable output no longer includes submitted voucher // Check that best spendable output no longer includes submitted voucher
bestVouchers = []voucherSpec{} bestVouchers = []voucherSpec{}
@ -322,6 +300,7 @@ func TestPaymentChannelVouchers(t *testing.T) {
// is greater than what's left in the channel, voucher create fails // is greater than what's left in the channel, voucher create fails
func TestPaymentChannelVoucherCreateShortfall(t *testing.T) { func TestPaymentChannelVoucherCreateShortfall(t *testing.T) {
_ = os.Setenv("BELLMAN_NO_GPU", "1") _ = os.Setenv("BELLMAN_NO_GPU", "1")
clitest.QuietMiningLogs()
blocktime := 5 * time.Millisecond blocktime := 5 * time.Millisecond
ctx := context.Background() ctx := context.Background()
@ -336,8 +315,12 @@ func TestPaymentChannelVoucherCreateShortfall(t *testing.T) {
// creator: paych add-funds <creator> <receiver> <amount> // creator: paych add-funds <creator> <receiver> <amount>
channelAmt := 100 channelAmt := 100
cmd := []string{"paych", "add-funds", creatorAddr.String(), receiverAddr.String(), fmt.Sprintf("%d", channelAmt)} chstr := creatorCLI.RunCmd(
chstr := creatorCLI.RunCmd(cmd) "paych",
"add-funds",
creatorAddr.String(),
receiverAddr.String(),
fmt.Sprintf("%d", channelAmt))
chAddr, err := address.NewFromString(chstr) chAddr, err := address.NewFromString(chstr)
require.NoError(t, err) require.NoError(t, err)
@ -345,15 +328,25 @@ func TestPaymentChannelVoucherCreateShortfall(t *testing.T) {
// creator: paych voucher create <channel> <amount> --lane=1 // creator: paych voucher create <channel> <amount> --lane=1
voucherAmt1 := 60 voucherAmt1 := 60
lane1 := "--lane=1" lane1 := "--lane=1"
cmd = []string{"paych", "voucher", "create", lane1, chAddr.String(), strconv.Itoa(voucherAmt1)} voucher1 := creatorCLI.RunCmd(
voucher1 := creatorCLI.RunCmd(cmd) "paych",
"voucher",
"create",
lane1,
chAddr.String(),
strconv.Itoa(voucherAmt1))
fmt.Println(voucher1) fmt.Println(voucher1)
// creator: paych voucher create <channel> <amount> --lane=2 // creator: paych voucher create <channel> <amount> --lane=2
lane2 := "--lane=2" lane2 := "--lane=2"
voucherAmt2 := 70 voucherAmt2 := 70
cmd = []string{"paych", "voucher", "create", lane2, chAddr.String(), strconv.Itoa(voucherAmt2)} _, err = creatorCLI.RunCmdRaw(
_, err = creatorCLI.RunCmdRaw(cmd) "paych",
"voucher",
"create",
lane2,
chAddr.String(),
strconv.Itoa(voucherAmt2))
// Should fail because channel doesn't have required amount // Should fail because channel doesn't have required amount
require.Error(t, err) require.Error(t, err)

View File

@ -37,10 +37,7 @@ func RunClientTest(t *testing.T, cmds []*lcli.Command, clientNode test.TestNode)
fmt.Println("Miner:", minerAddr) fmt.Println("Miner:", minerAddr)
// client query-ask <miner addr> // client query-ask <miner addr>
cmd := []string{ out := clientCLI.RunCmd("client", "query-ask", minerAddr.String())
"client", "query-ask", minerAddr.String(),
}
out := clientCLI.RunCmd(cmd)
require.Regexp(t, regexp.MustCompile("Ask:"), out) require.Regexp(t, regexp.MustCompile("Ask:"), out)
// Create a deal (non-interactive) // Create a deal (non-interactive)
@ -50,10 +47,7 @@ func RunClientTest(t *testing.T, cmds []*lcli.Command, clientNode test.TestNode)
dataCid := res.Root dataCid := res.Root
price := "1000000attofil" price := "1000000attofil"
duration := fmt.Sprintf("%d", build.MinDealDuration) duration := fmt.Sprintf("%d", build.MinDealDuration)
cmd = []string{ out = clientCLI.RunCmd("client", "deal", dataCid.String(), minerAddr.String(), price, duration)
"client", "deal", dataCid.String(), minerAddr.String(), price, duration,
}
out = clientCLI.RunCmd(cmd)
fmt.Println("client deal", out) fmt.Println("client deal", out)
// Create a deal (interactive) // Create a deal (interactive)
@ -67,9 +61,7 @@ func RunClientTest(t *testing.T, cmds []*lcli.Command, clientNode test.TestNode)
require.NoError(t, err) require.NoError(t, err)
dataCid2 := res.Root dataCid2 := res.Root
duration = fmt.Sprintf("%d", build.MinDealDuration/builtin.EpochsInDay) duration = fmt.Sprintf("%d", build.MinDealDuration/builtin.EpochsInDay)
cmd = []string{ cmd := []string{"client", "deal"}
"client", "deal",
}
interactiveCmds := []string{ interactiveCmds := []string{
dataCid2.String(), dataCid2.String(),
duration, duration,
@ -84,8 +76,7 @@ func RunClientTest(t *testing.T, cmds []*lcli.Command, clientNode test.TestNode)
dealStatus := "" dealStatus := ""
for dealStatus != "StorageDealSealing" { for dealStatus != "StorageDealSealing" {
// client list-deals // client list-deals
cmd = []string{"client", "list-deals"} out = clientCLI.RunCmd("client", "list-deals")
out = clientCLI.RunCmd(cmd)
fmt.Println("list-deals:\n", out) fmt.Println("list-deals:\n", out)
lines := strings.Split(out, "\n") lines := strings.Split(out, "\n")
@ -106,10 +97,7 @@ func RunClientTest(t *testing.T, cmds []*lcli.Command, clientNode test.TestNode)
tmpdir, err := ioutil.TempDir(os.TempDir(), "test-cli-client") tmpdir, err := ioutil.TempDir(os.TempDir(), "test-cli-client")
require.NoError(t, err) require.NoError(t, err)
path := filepath.Join(tmpdir, "outfile.dat") path := filepath.Join(tmpdir, "outfile.dat")
cmd = []string{ out = clientCLI.RunCmd("client", "retrieve", dataCid.String(), path)
"client", "retrieve", dataCid.String(), path,
}
out = clientCLI.RunCmd(cmd)
fmt.Println("retrieve:\n", out) fmt.Println("retrieve:\n", out)
require.Regexp(t, regexp.MustCompile("Success"), out) require.Regexp(t, regexp.MustCompile("Success"), out)
} }

View File

@ -52,22 +52,8 @@ type MockCLIClient struct {
out *bytes.Buffer out *bytes.Buffer
} }
func (c *MockCLIClient) run(cmd []string, params []string, args []string) string { func (c *MockCLIClient) RunCmd(input ...string) string {
// Add parameter --api-url=<node api listener address> out, err := c.RunCmdRaw(input...)
apiFlag := "--api-url=" + c.addr.String()
params = append([]string{apiFlag}, params...)
err := c.cctx.App.Run(append(append(cmd, params...), args...))
require.NoError(c.t, err)
// Get the output
str := strings.TrimSpace(c.out.String())
c.out.Reset()
return str
}
func (c *MockCLIClient) RunCmd(input []string) string {
out, err := c.RunCmdRaw(input)
require.NoError(c.t, err) require.NoError(c.t, err)
return out return out
@ -102,7 +88,7 @@ func (c *MockCLIClient) findSubcommand(cmd *lcli.Command, input []string) (*lcli
return nil, []string{} return nil, []string{}
} }
func (c *MockCLIClient) RunCmdRaw(input []string) (string, error) { func (c *MockCLIClient) RunCmdRaw(input ...string) (string, error) {
cmd, input := c.cmdByNameSub(input) cmd, input := c.cmdByNameSub(input)
if cmd == nil { if cmd == nil {
panic("Could not find command " + input[0] + " " + input[1]) panic("Could not find command " + input[0] + " " + input[1])
@ -145,7 +131,7 @@ func (c *MockCLIClient) flagSet(cmd *lcli.Command) *flag.FlagSet {
func (c *MockCLIClient) RunInteractiveCmd(cmd []string, interactive []string) string { func (c *MockCLIClient) RunInteractiveCmd(cmd []string, interactive []string) string {
c.toStdin(strings.Join(interactive, "\n") + "\n") c.toStdin(strings.Join(interactive, "\n") + "\n")
return c.RunCmd(cmd) return c.RunCmd(cmd...)
} }
func (c *MockCLIClient) toStdin(s string) { func (c *MockCLIClient) toStdin(s string) {

View File

@ -39,7 +39,7 @@ func RunMultisigTest(t *testing.T, cmds []*lcli.Command, clientNode test.TestNod
paramDuration := "--duration=50" paramDuration := "--duration=50"
paramRequired := fmt.Sprintf("--required=%d", threshold) paramRequired := fmt.Sprintf("--required=%d", threshold)
paramValue := fmt.Sprintf("--value=%dattofil", amtAtto) paramValue := fmt.Sprintf("--value=%dattofil", amtAtto)
cmd := []string{ out := clientCLI.RunCmd(
"msig", "create", "msig", "create",
paramRequired, paramRequired,
paramDuration, paramDuration,
@ -47,8 +47,7 @@ func RunMultisigTest(t *testing.T, cmds []*lcli.Command, clientNode test.TestNod
walletAddrs[0].String(), walletAddrs[0].String(),
walletAddrs[1].String(), walletAddrs[1].String(),
walletAddrs[2].String(), walletAddrs[2].String(),
} )
out := clientCLI.RunCmd(cmd)
fmt.Println(out) fmt.Println(out)
// Extract msig robust address from output // Extract msig robust address from output
@ -62,18 +61,16 @@ func RunMultisigTest(t *testing.T, cmds []*lcli.Command, clientNode test.TestNod
// Propose to add a new address to the msig // Propose to add a new address to the msig
// msig add-propose --from=<addr> <msig> <addr> // msig add-propose --from=<addr> <msig> <addr>
paramFrom := fmt.Sprintf("--from=%s", walletAddrs[0]) paramFrom := fmt.Sprintf("--from=%s", walletAddrs[0])
cmd = []string{ out = clientCLI.RunCmd(
"msig", "add-propose", "msig", "add-propose",
paramFrom, paramFrom,
msigRobustAddr, msigRobustAddr,
walletAddrs[3].String(), walletAddrs[3].String(),
} )
out = clientCLI.RunCmd(cmd)
fmt.Println(out) fmt.Println(out)
// msig inspect <msig> // msig inspect <msig>
cmd = []string{"msig", "inspect", "--vesting", "--decode-params", msigRobustAddr} out = clientCLI.RunCmd("msig", "inspect", "--vesting", "--decode-params", msigRobustAddr)
out = clientCLI.RunCmd(cmd)
fmt.Println(out) fmt.Println(out)
// Expect correct balance // Expect correct balance
@ -87,7 +84,7 @@ func RunMultisigTest(t *testing.T, cmds []*lcli.Command, clientNode test.TestNod
// msig add-approve --from=<addr> <msig> <addr> 0 <addr> false // msig add-approve --from=<addr> <msig> <addr> 0 <addr> false
txnID := "0" txnID := "0"
paramFrom = fmt.Sprintf("--from=%s", walletAddrs[1]) paramFrom = fmt.Sprintf("--from=%s", walletAddrs[1])
cmd = []string{ out = clientCLI.RunCmd(
"msig", "add-approve", "msig", "add-approve",
paramFrom, paramFrom,
msigRobustAddr, msigRobustAddr,
@ -95,7 +92,6 @@ func RunMultisigTest(t *testing.T, cmds []*lcli.Command, clientNode test.TestNod
txnID, txnID,
walletAddrs[3].String(), walletAddrs[3].String(),
"false", "false",
} )
out = clientCLI.RunCmd(cmd)
fmt.Println(out) fmt.Println(out)
} }