dealpublisher: Test deal verification
This commit is contained in:
parent
386910589d
commit
42135ec7cc
@ -6,24 +6,25 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/filecoin-project/go-state-types/crypto"
|
|
||||||
market2 "github.com/filecoin-project/specs-actors/v2/actors/builtin/market"
|
|
||||||
"github.com/ipfs/go-cid"
|
"github.com/ipfs/go-cid"
|
||||||
"github.com/raulk/clock"
|
"github.com/raulk/clock"
|
||||||
|
"golang.org/x/xerrors"
|
||||||
|
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
|
"github.com/filecoin-project/go-address"
|
||||||
|
"github.com/filecoin-project/go-state-types/abi"
|
||||||
|
"github.com/filecoin-project/go-state-types/crypto"
|
||||||
|
"github.com/filecoin-project/go-state-types/exitcode"
|
||||||
|
market2 "github.com/filecoin-project/specs-actors/v2/actors/builtin/market"
|
||||||
tutils "github.com/filecoin-project/specs-actors/v2/support/testing"
|
tutils "github.com/filecoin-project/specs-actors/v2/support/testing"
|
||||||
|
|
||||||
"github.com/filecoin-project/go-address"
|
"github.com/filecoin-project/lotus/api"
|
||||||
"github.com/filecoin-project/lotus/build"
|
"github.com/filecoin-project/lotus/build"
|
||||||
"github.com/filecoin-project/lotus/chain/actors/builtin/market"
|
"github.com/filecoin-project/lotus/chain/actors/builtin/market"
|
||||||
"github.com/filecoin-project/lotus/chain/actors/builtin/miner"
|
"github.com/filecoin-project/lotus/chain/actors/builtin/miner"
|
||||||
"github.com/filecoin-project/lotus/chain/types"
|
"github.com/filecoin-project/lotus/chain/types"
|
||||||
market0 "github.com/filecoin-project/specs-actors/actors/builtin/market"
|
market0 "github.com/filecoin-project/specs-actors/actors/builtin/market"
|
||||||
|
|
||||||
"github.com/filecoin-project/go-state-types/abi"
|
|
||||||
"github.com/filecoin-project/lotus/api"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestDealPublisher(t *testing.T) {
|
func TestDealPublisher(t *testing.T) {
|
||||||
@ -41,6 +42,7 @@ func TestDealPublisher(t *testing.T) {
|
|||||||
expiredDeals int
|
expiredDeals int
|
||||||
dealCountAfterPublishPeriod int
|
dealCountAfterPublishPeriod int
|
||||||
expectedDealsPerMsg []int
|
expectedDealsPerMsg []int
|
||||||
|
failOne bool
|
||||||
}{{
|
}{{
|
||||||
name: "publish one deal within publish period",
|
name: "publish one deal within publish period",
|
||||||
publishPeriod: 10 * time.Millisecond,
|
publishPeriod: 10 * time.Millisecond,
|
||||||
@ -93,6 +95,14 @@ func TestDealPublisher(t *testing.T) {
|
|||||||
ctxCancelledWithinPublishPeriod: 0,
|
ctxCancelledWithinPublishPeriod: 0,
|
||||||
dealCountAfterPublishPeriod: 2,
|
dealCountAfterPublishPeriod: 2,
|
||||||
expectedDealsPerMsg: []int{1, 1, 1, 1},
|
expectedDealsPerMsg: []int{1, 1, 1, 1},
|
||||||
|
}, {
|
||||||
|
name: "one deal failing doesn't fail the entire batch",
|
||||||
|
publishPeriod: 10 * time.Millisecond,
|
||||||
|
maxDealsPerMsg: 5,
|
||||||
|
dealCountWithinPublishPeriod: 2,
|
||||||
|
dealCountAfterPublishPeriod: 0,
|
||||||
|
failOne: true,
|
||||||
|
expectedDealsPerMsg: []int{1},
|
||||||
}}
|
}}
|
||||||
|
|
||||||
for _, tc := range testCases {
|
for _, tc := range testCases {
|
||||||
@ -112,14 +122,18 @@ func TestDealPublisher(t *testing.T) {
|
|||||||
|
|
||||||
// Publish deals within publish period
|
// Publish deals within publish period
|
||||||
for i := 0; i < tc.dealCountWithinPublishPeriod; i++ {
|
for i := 0; i < tc.dealCountWithinPublishPeriod; i++ {
|
||||||
deal := publishDeal(t, dp, false, false)
|
if tc.failOne && i == 1 {
|
||||||
dealsToPublish = append(dealsToPublish, deal)
|
publishDeal(t, dp, i, false, false)
|
||||||
|
} else {
|
||||||
|
deal := publishDeal(t, dp, 0, false, false)
|
||||||
|
dealsToPublish = append(dealsToPublish, deal)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
for i := 0; i < tc.ctxCancelledWithinPublishPeriod; i++ {
|
for i := 0; i < tc.ctxCancelledWithinPublishPeriod; i++ {
|
||||||
publishDeal(t, dp, true, false)
|
publishDeal(t, dp, 0, true, false)
|
||||||
}
|
}
|
||||||
for i := 0; i < tc.expiredDeals; i++ {
|
for i := 0; i < tc.expiredDeals; i++ {
|
||||||
publishDeal(t, dp, false, true)
|
publishDeal(t, dp, 0, false, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Wait until publish period has elapsed
|
// Wait until publish period has elapsed
|
||||||
@ -151,7 +165,7 @@ func TestDealPublisher(t *testing.T) {
|
|||||||
|
|
||||||
// Publish deals after publish period
|
// Publish deals after publish period
|
||||||
for i := 0; i < tc.dealCountAfterPublishPeriod; i++ {
|
for i := 0; i < tc.dealCountAfterPublishPeriod; i++ {
|
||||||
deal := publishDeal(t, dp, false, false)
|
deal := publishDeal(t, dp, 0, false, false)
|
||||||
dealsToPublish = append(dealsToPublish, deal)
|
dealsToPublish = append(dealsToPublish, deal)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -187,12 +201,12 @@ func TestForcePublish(t *testing.T) {
|
|||||||
// Queue three deals for publishing, one with a cancelled context
|
// Queue three deals for publishing, one with a cancelled context
|
||||||
var dealsToPublish []market.ClientDealProposal
|
var dealsToPublish []market.ClientDealProposal
|
||||||
// 1. Regular deal
|
// 1. Regular deal
|
||||||
deal := publishDeal(t, dp, false, false)
|
deal := publishDeal(t, dp, 0, false, false)
|
||||||
dealsToPublish = append(dealsToPublish, deal)
|
dealsToPublish = append(dealsToPublish, deal)
|
||||||
// 2. Deal with cancelled context
|
// 2. Deal with cancelled context
|
||||||
publishDeal(t, dp, true, false)
|
publishDeal(t, dp, 0, true, false)
|
||||||
// 3. Regular deal
|
// 3. Regular deal
|
||||||
deal = publishDeal(t, dp, false, false)
|
deal = publishDeal(t, dp, 0, false, false)
|
||||||
dealsToPublish = append(dealsToPublish, deal)
|
dealsToPublish = append(dealsToPublish, deal)
|
||||||
|
|
||||||
// Allow a moment for them to be queued
|
// Allow a moment for them to be queued
|
||||||
@ -217,7 +231,7 @@ func TestForcePublish(t *testing.T) {
|
|||||||
checkPublishedDeals(t, dpapi, dealsToPublish, []int{2})
|
checkPublishedDeals(t, dpapi, dealsToPublish, []int{2})
|
||||||
}
|
}
|
||||||
|
|
||||||
func publishDeal(t *testing.T, dp *DealPublisher, ctxCancelled bool, expired bool) market.ClientDealProposal {
|
func publishDeal(t *testing.T, dp *DealPublisher, invalid int, ctxCancelled bool, expired bool) market.ClientDealProposal {
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
t.Cleanup(cancel)
|
t.Cleanup(cancel)
|
||||||
|
|
||||||
@ -238,6 +252,7 @@ func publishDeal(t *testing.T, dp *DealPublisher, ctxCancelled bool, expired boo
|
|||||||
Provider: getProviderActor(t),
|
Provider: getProviderActor(t),
|
||||||
StartEpoch: startEpoch,
|
StartEpoch: startEpoch,
|
||||||
EndEpoch: abi.ChainEpoch(120),
|
EndEpoch: abi.ChainEpoch(120),
|
||||||
|
PieceSize: abi.PaddedPieceSize(invalid), // pass invalid into StateCall below
|
||||||
},
|
},
|
||||||
ClientSignature: crypto.Signature{
|
ClientSignature: crypto.Signature{
|
||||||
Type: crypto.SigTypeSecp256k1,
|
Type: crypto.SigTypeSecp256k1,
|
||||||
@ -253,7 +268,7 @@ func publishDeal(t *testing.T, dp *DealPublisher, ctxCancelled bool, expired boo
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if ctxCancelled || expired {
|
if ctxCancelled || expired || invalid == 1 {
|
||||||
require.Error(t, err)
|
require.Error(t, err)
|
||||||
} else {
|
} else {
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
@ -382,7 +397,16 @@ func (d *dpAPI) StateLookupID(ctx context.Context, a address.Address, key types.
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (d *dpAPI) StateCall(ctx context.Context, message *types.Message, key types.TipSetKey) (*api.InvocResult, error) {
|
func (d *dpAPI) StateCall(ctx context.Context, message *types.Message, key types.TipSetKey) (*api.InvocResult, error) {
|
||||||
return &api.InvocResult{MsgRct: &types.MessageReceipt{ExitCode: 0}}, nil
|
var p market2.PublishStorageDealsParams
|
||||||
|
if err := p.UnmarshalCBOR(bytes.NewReader(message.Params)); err != nil {
|
||||||
|
return nil, xerrors.Errorf("unmarshal market params: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
exit := exitcode.Ok
|
||||||
|
if p.Deals[0].Proposal.PieceSize == 1 {
|
||||||
|
exit = exitcode.ErrIllegalState
|
||||||
|
}
|
||||||
|
return &api.InvocResult{MsgRct: &types.MessageReceipt{ExitCode: exit}}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func getClientActor(t *testing.T) address.Address {
|
func getClientActor(t *testing.T) address.Address {
|
||||||
|
Loading…
Reference in New Issue
Block a user