Skip to content

Commit

Permalink
refactor(storagemarket): minor changes after rebase
Browse files Browse the repository at this point in the history
add one state test and fix compile error
  • Loading branch information
hannahhoward committed May 20, 2020
1 parent dbf7015 commit 04c42dc
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
2 changes: 1 addition & 1 deletion storagemarket/impl/providerstates/provider_fsm.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ var ProviderEvents = fsm.Events{
return nil
}),
fsm.Event(storagemarket.ProviderEventSendResponseFailed).
FromMany(storagemarket.StorageDealPublishing, storagemarket.StorageDealFailing).To(storagemarket.StorageDealError).
FromMany(storagemarket.StorageDealAcceptWait, storagemarket.StorageDealPublishing, storagemarket.StorageDealFailing).To(storagemarket.StorageDealError).
Action(func(deal *storagemarket.MinerDeal, err error) error {
deal.Message = xerrors.Errorf("sending response to deal: %w", err).Error()
return nil
Expand Down
25 changes: 19 additions & 6 deletions storagemarket/impl/providerstates/provider_states_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func TestValidateDealProposal(t *testing.T) {
TagsProposal: true,
},
dealInspector: func(t *testing.T, deal storagemarket.MinerDeal, env *fakeEnvironment) {
tut.AssertDealState(t, StorageDealAcceptWait, deal.State)
tut.AssertDealState(t, storagemarket.StorageDealAcceptWait, deal.State)
},
},
"verify signature fails": {
Expand Down Expand Up @@ -86,7 +86,7 @@ func TestValidateDealProposal(t *testing.T) {
dealParams: dealParams{StartEpoch: 200},
nodeParams: nodeParams{Height: 190},
dealInspector: func(t *testing.T, deal storagemarket.MinerDeal, env *fakeEnvironment) {
tut.AssertDealState(t, StorageDealAcceptWait, deal.State)
tut.AssertDealState(t, storagemarket.StorageDealAcceptWait, deal.State)
},
},
"CurrentHeight > StartEpoch - DealAcceptanceBuffer() fails": {
Expand Down Expand Up @@ -153,10 +153,10 @@ func TestDecideOnProposal(t *testing.T) {
environmentParams environmentParams
fileStoreParams tut.TestFileStoreParams
pieceStoreParams tut.TestPieceStoreParams
dealInspector func(t *testing.T, deal storagemarket.MinerDeal)
dealInspector func(t *testing.T, deal storagemarket.MinerDeal, env *fakeEnvironment)
}{
"succeeds": {
dealInspector: func(t *testing.T, deal storagemarket.MinerDeal) {
dealInspector: func(t *testing.T, deal storagemarket.MinerDeal, env *fakeEnvironment) {
tut.AssertDealState(t, storagemarket.StorageDealWaitingForData, deal.State)
},
},
Expand All @@ -165,7 +165,7 @@ func TestDecideOnProposal(t *testing.T) {
RejectDeal: true,
RejectReason: "I just don't like it",
},
dealInspector: func(t *testing.T, deal storagemarket.MinerDeal) {
dealInspector: func(t *testing.T, deal storagemarket.MinerDeal, env *fakeEnvironment) {
tut.AssertDealState(t, storagemarket.StorageDealFailing, deal.State)
require.Equal(t, "deal rejected: I just don't like it", deal.Message)
},
Expand All @@ -174,11 +174,20 @@ func TestDecideOnProposal(t *testing.T) {
environmentParams: environmentParams{
DecisionError: errors.New("I can't make up my mind"),
},
dealInspector: func(t *testing.T, deal storagemarket.MinerDeal) {
dealInspector: func(t *testing.T, deal storagemarket.MinerDeal, env *fakeEnvironment) {
tut.AssertDealState(t, storagemarket.StorageDealFailing, deal.State)
require.Equal(t, "error calling node: custom deal decision logic failed: I can't make up my mind", deal.Message)
},
},
"SendSignedResponse errors": {
environmentParams: environmentParams{
SendSignedResponseError: errors.New("could not send"),
},
dealInspector: func(t *testing.T, deal storagemarket.MinerDeal, env *fakeEnvironment) {
tut.AssertDealState(t, storagemarket.StorageDealError, deal.State)
require.Equal(t, "sending response to deal: could not send", deal.Message)
},
},
}
for test, data := range tests {
t.Run(test, func(t *testing.T) {
Expand Down Expand Up @@ -1021,3 +1030,7 @@ func (fe *fakeEnvironment) PieceStore() piecestore.PieceStore {
func (fe *fakeEnvironment) DealAcceptanceBuffer() abi.ChainEpoch {
return fe.dealAcceptanceBuffer
}

func (fe *fakeEnvironment) RunCustomDecisionLogic(context.Context, storagemarket.MinerDeal) (bool, string, error) {
return !fe.rejectDeal, fe.rejectReason, fe.decisionError
}

0 comments on commit 04c42dc

Please sign in to comment.