Merge pull request #6486 from filecoin-project/refactor/itest-batch-deal

refactor batch deal test to use kit2
This commit is contained in:
raulk 2021-06-16 10:41:30 +01:00 committed by GitHub
commit f0a8a85928
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -10,16 +10,15 @@ import (
"github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/abi"
"github.com/filecoin-project/go-state-types/big" "github.com/filecoin-project/go-state-types/big"
"github.com/filecoin-project/lotus/extern/storage-sealing/sealiface" "github.com/filecoin-project/lotus/extern/storage-sealing/sealiface"
"github.com/filecoin-project/lotus/itests/kit" "github.com/filecoin-project/lotus/itests/kit2"
"github.com/filecoin-project/lotus/markets/storageadapter" "github.com/filecoin-project/lotus/markets/storageadapter"
"github.com/filecoin-project/lotus/node" "github.com/filecoin-project/lotus/node"
"github.com/filecoin-project/lotus/node/impl"
"github.com/filecoin-project/lotus/node/modules/dtypes" "github.com/filecoin-project/lotus/node/modules/dtypes"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
func TestBatchDealInput(t *testing.T) { func TestBatchDealInput(t *testing.T) {
kit.QuietMiningLogs() kit2.QuietMiningLogs()
var ( var (
blockTime = 10 * time.Millisecond blockTime = 10 * time.Millisecond
@ -32,50 +31,40 @@ func TestBatchDealInput(t *testing.T) {
run := func(piece, deals, expectSectors int) func(t *testing.T) { run := func(piece, deals, expectSectors int) func(t *testing.T) {
return func(t *testing.T) { return func(t *testing.T) {
ctx := context.Background()
publishPeriod := 10 * time.Second publishPeriod := 10 * time.Second
maxDealsPerMsg := uint64(deals) maxDealsPerMsg := uint64(deals)
// Set max deals per publish deals message to maxDealsPerMsg // Set max deals per publish deals message to maxDealsPerMsg
minerDef := []kit.StorageMiner{{ opts := kit2.ConstructorOpts(node.Options(
Full: 0, node.Override(
Opts: node.Options( new(*storageadapter.DealPublisher),
node.Override( storageadapter.NewDealPublisher(nil, storageadapter.PublishMsgConfig{
new(*storageadapter.DealPublisher), Period: publishPeriod,
storageadapter.NewDealPublisher(nil, storageadapter.PublishMsgConfig{ MaxDealsPerMsg: maxDealsPerMsg,
Period: publishPeriod, })),
MaxDealsPerMsg: maxDealsPerMsg, node.Override(new(dtypes.GetSealingConfigFunc), func() (dtypes.GetSealingConfigFunc, error) {
})), return func() (sealiface.Config, error) {
node.Override(new(dtypes.GetSealingConfigFunc), func() (dtypes.GetSealingConfigFunc, error) { return sealiface.Config{
return func() (sealiface.Config, error) { MaxWaitDealsSectors: 2,
return sealiface.Config{ MaxSealingSectors: 1,
MaxWaitDealsSectors: 2, MaxSealingSectorsForDeals: 3,
MaxSealingSectors: 1, AlwaysKeepUnsealedCopy: true,
MaxSealingSectorsForDeals: 3, WaitDealsDelay: time.Hour,
AlwaysKeepUnsealedCopy: true,
WaitDealsDelay: time.Hour,
}, nil
}, nil }, nil
}), }, nil
), }),
Preseal: kit.PresealGenesis, ))
}} client, miner, ens := kit2.EnsembleMinimal(t, kit2.MockProofs(), opts)
ens.InterconnectAll().BeginMining(blockTime)
// Create a connect client and miner node dh := kit2.NewDealHarness(t, client, miner)
n, sn := kit.MockMinerBuilder(t, kit.OneFull, minerDef)
client := n[0].FullNode.(*impl.FullNodeAPI)
miner := sn[0]
blockMiner := kit.ConnectAndStartMining(t, blockTime, miner, client)
t.Cleanup(blockMiner.Stop)
dh := kit.NewDealHarness(t, client, miner)
ctx := context.Background()
err := miner.MarketSetAsk(ctx, big.Zero(), big.Zero(), 200, 128, 32<<30) err := miner.MarketSetAsk(ctx, big.Zero(), big.Zero(), 200, 128, 32<<30)
require.NoError(t, err) require.NoError(t, err)
checkNoPadding := func() { checkNoPadding := func() {
sl, err := sn[0].SectorsList(ctx) sl, err := miner.SectorsList(ctx)
require.NoError(t, err) require.NoError(t, err)
sort.Slice(sl, func(i, j int) bool { sort.Slice(sl, func(i, j int) bool {
@ -83,7 +72,7 @@ func TestBatchDealInput(t *testing.T) {
}) })
for _, snum := range sl { for _, snum := range sl {
si, err := sn[0].SectorsStatus(ctx, snum, false) si, err := miner.SectorsStatus(ctx, snum, false)
require.NoError(t, err) require.NoError(t, err)
// fmt.Printf("S %d: %+v %s\n", snum, si.Deals, si.State) // fmt.Printf("S %d: %+v %s\n", snum, si.Deals, si.State)
@ -98,7 +87,7 @@ func TestBatchDealInput(t *testing.T) {
// Starts a deal and waits until it's published // Starts a deal and waits until it's published
runDealTillSeal := func(rseed int) { runDealTillSeal := func(rseed int) {
res, _, _, err := kit.CreateImportFile(ctx, client, rseed, piece) res, _, _, err := kit2.CreateImportFile(ctx, client, rseed, piece)
require.NoError(t, err) require.NoError(t, err)
deal := dh.StartDeal(ctx, res.Root, false, dealStartEpoch) deal := dh.StartDeal(ctx, res.Root, false, dealStartEpoch)
@ -122,7 +111,7 @@ func TestBatchDealInput(t *testing.T) {
checkNoPadding() checkNoPadding()
sl, err := sn[0].SectorsList(ctx) sl, err := miner.SectorsList(ctx)
require.NoError(t, err) require.NoError(t, err)
require.Equal(t, len(sl), expectSectors) require.Equal(t, len(sl), expectSectors)
} }