Skip to content

Commit

Permalink
include rejection reason in client response
Browse files Browse the repository at this point in the history
  • Loading branch information
shannonwells committed Apr 6, 2020
1 parent 412b34d commit 43e4b9d
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
4 changes: 2 additions & 2 deletions storagemarket/impl/clientstates/client_fsm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
2 changes: 1 addition & 1 deletion storagemarket/impl/clientstates/client_states.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 3 additions & 1 deletion storagemarket/impl/clientstates/cliest_states_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
})

Expand Down

0 comments on commit 43e4b9d

Please sign in to comment.