From 43e4b9d58182f2498e71d3e8a808e5bdd88d3b30 Mon Sep 17 00:00:00 2001 From: shannonwells Date: Fri, 3 Apr 2020 17:57:07 -0700 Subject: [PATCH] include rejection reason in client response --- storagemarket/impl/clientstates/client_fsm.go | 4 ++-- storagemarket/impl/clientstates/client_states.go | 2 +- storagemarket/impl/clientstates/cliest_states_test.go | 4 +++- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/storagemarket/impl/clientstates/client_fsm.go b/storagemarket/impl/clientstates/client_fsm.go index bb1d2912..4fd6d479 100644 --- a/storagemarket/impl/clientstates/client_fsm.go +++ b/storagemarket/impl/clientstates/client_fsm.go @@ -55,8 +55,8 @@ var ClientEvents = fsm.Events{ }), fsm.Event(storagemarket.ClientEventDealRejected). From(storagemarket.StorageDealValidating).To(storagemarket.StorageDealFailing). - Action(func(deal *storagemarket.ClientDeal, state storagemarket.StorageDealStatus) error { - deal.Message = xerrors.Errorf("deal wasn't accepted (State=%d)", state).Error() + Action(func(deal *storagemarket.ClientDeal, state storagemarket.StorageDealStatus, reason string) error { + deal.Message = xerrors.Errorf("deal failed: (State=%d) %s", state, reason).Error() return nil }), fsm.Event(storagemarket.ClientEventDealAccepted). diff --git a/storagemarket/impl/clientstates/client_states.go b/storagemarket/impl/clientstates/client_states.go index b942fabe..b1ae0ab0 100644 --- a/storagemarket/impl/clientstates/client_states.go +++ b/storagemarket/impl/clientstates/client_states.go @@ -80,7 +80,7 @@ func VerifyDealResponse(ctx fsm.Context, environment ClientDealEnvironment, deal } if resp.Response.State != storagemarket.StorageDealProposalAccepted { - return ctx.Trigger(storagemarket.ClientEventDealRejected, resp.Response.State) + return ctx.Trigger(storagemarket.ClientEventDealRejected, resp.Response.State, resp.Response.Message) } if err := environment.CloseStream(deal.ProposalCid); err != nil { diff --git a/storagemarket/impl/clientstates/cliest_states_test.go b/storagemarket/impl/clientstates/cliest_states_test.go index fdc3c8b8..8656cb63 100644 --- a/storagemarket/impl/clientstates/cliest_states_test.go +++ b/storagemarket/impl/clientstates/cliest_states_test.go @@ -185,12 +185,14 @@ func TestVerifyResponse(t *testing.T) { State: storagemarket.StorageDealProposalRejected, Proposal: proposalNd.Cid(), PublishMessage: publishMessage, + Message: "because reasons", }, Signature: tut.MakeTestSignature(), })) + expErr := fmt.Sprintf("deal failed: (State=%d) because reasons", storagemarket.StorageDealProposalRejected) runVerifyResponse(t, node(false), nil, stream, nil, func(deal storagemarket.ClientDeal) { require.Equal(t, deal.State, storagemarket.StorageDealFailing) - require.Equal(t, deal.Message, fmt.Sprintf("deal wasn't accepted (State=%d)", storagemarket.StorageDealProposalRejected)) + require.Equal(t, expErr, deal.Message) }) })