diff --git a/cli/paych_test.go b/cli/paych_test.go index fcd9c99a3..dac8411c5 100644 --- a/cli/paych_test.go +++ b/cli/paych_test.go @@ -48,7 +48,7 @@ func TestPaymentChannels(t *testing.T) { receiverAddr := addrs[1] // Create mock CLI - mockCLI := clitest.NewMockCLI(t, Commands) + mockCLI := clitest.NewMockCLI(ctx, t, Commands) creatorCLI := mockCLI.Client(paymentCreator.ListenAddr) receiverCLI := mockCLI.Client(paymentReceiver.ListenAddr) @@ -99,7 +99,7 @@ func TestPaymentChannelStatus(t *testing.T) { receiverAddr := addrs[1] // Create mock CLI - mockCLI := clitest.NewMockCLI(t, Commands) + mockCLI := clitest.NewMockCLI(ctx, t, Commands) creatorCLI := mockCLI.Client(paymentCreator.ListenAddr) // creator: paych status-by-from-to @@ -179,7 +179,7 @@ func TestPaymentChannelVouchers(t *testing.T) { receiverAddr := addrs[1] // Create mock CLI - mockCLI := clitest.NewMockCLI(t, Commands) + mockCLI := clitest.NewMockCLI(ctx, t, Commands) creatorCLI := mockCLI.Client(paymentCreator.ListenAddr) receiverCLI := mockCLI.Client(paymentReceiver.ListenAddr) @@ -310,7 +310,7 @@ func TestPaymentChannelVoucherCreateShortfall(t *testing.T) { receiverAddr := addrs[1] // Create mock CLI - mockCLI := clitest.NewMockCLI(t, Commands) + mockCLI := clitest.NewMockCLI(ctx, t, Commands) creatorCLI := mockCLI.Client(paymentCreator.ListenAddr) // creator: paych add-funds diff --git a/cli/test/client.go b/cli/test/client.go index c74f881b0..95abd39c2 100644 --- a/cli/test/client.go +++ b/cli/test/client.go @@ -11,6 +11,8 @@ import ( "testing" "time" + "golang.org/x/xerrors" + "github.com/filecoin-project/lotus/api/test" "github.com/filecoin-project/lotus/build" "github.com/filecoin-project/lotus/chain/types" @@ -25,7 +27,7 @@ func RunClientTest(t *testing.T, cmds []*lcli.Command, clientNode test.TestNode) defer cancel() // Create mock CLI - mockCLI := NewMockCLI(t, cmds) + mockCLI := NewMockCLI(ctx, t, cmds) clientCLI := mockCLI.Client(clientNode.ListenAddr) // Get the miner address @@ -74,7 +76,7 @@ func RunClientTest(t *testing.T, cmds []*lcli.Command, clientNode test.TestNode) // Wait for provider to start sealing deal dealStatus := "" - for dealStatus != "StorageDealSealing" { + for { // client list-deals out = clientCLI.RunCmd("client", "list-deals") fmt.Println("list-deals:\n", out) @@ -88,6 +90,9 @@ func RunClientTest(t *testing.T, cmds []*lcli.Command, clientNode test.TestNode) } dealStatus = parts[3] fmt.Println(" Deal status:", dealStatus) + if dealComplete(t, dealStatus) { + break + } time.Sleep(time.Second) } @@ -101,3 +106,14 @@ func RunClientTest(t *testing.T, cmds []*lcli.Command, clientNode test.TestNode) fmt.Println("retrieve:\n", out) require.Regexp(t, regexp.MustCompile("Success"), out) } + +func dealComplete(t *testing.T, dealStatus string) bool { + switch dealStatus { + case "StorageDealFailing", "StorageDealError": + t.Fatal(xerrors.Errorf("Storage deal failed with status: " + dealStatus)) + case "StorageDealStaged", "StorageDealSealing", "StorageDealActive", "StorageDealExpired", "StorageDealSlashed": + return true + } + + return false +} diff --git a/cli/test/mockcli.go b/cli/test/mockcli.go index 65b0bc30a..e8eb78f1b 100644 --- a/cli/test/mockcli.go +++ b/cli/test/mockcli.go @@ -2,6 +2,7 @@ package test import ( "bytes" + "context" "flag" "strings" "testing" @@ -18,7 +19,7 @@ type MockCLI struct { out *bytes.Buffer } -func NewMockCLI(t *testing.T, cmds []*lcli.Command) *MockCLI { +func NewMockCLI(ctx context.Context, t *testing.T, cmds []*lcli.Command) *MockCLI { // Create a CLI App with an --api-url flag so that we can specify which node // the command should be executed against app := &lcli.App{ @@ -36,6 +37,7 @@ func NewMockCLI(t *testing.T, cmds []*lcli.Command) *MockCLI { app.Setup() cctx := lcli.NewContext(app, &flag.FlagSet{}, nil) + cctx.Context = ctx return &MockCLI{t: t, cmds: cmds, cctx: cctx, out: &out} } diff --git a/cli/test/multisig.go b/cli/test/multisig.go index dd867d0b5..5a60894e6 100644 --- a/cli/test/multisig.go +++ b/cli/test/multisig.go @@ -18,7 +18,7 @@ func RunMultisigTest(t *testing.T, cmds []*lcli.Command, clientNode test.TestNod ctx := context.Background() // Create mock CLI - mockCLI := NewMockCLI(t, cmds) + mockCLI := NewMockCLI(ctx, t, cmds) clientCLI := mockCLI.Client(clientNode.ListenAddr) // Create some wallets on the node to use for testing multisig