deals tests: migrate TestOfflineDealFlow.

This commit is contained in:
Raúl Kripalani 2021-06-10 15:54:16 +01:00
parent 4f2aaa54d2
commit dcd6fc239b
3 changed files with 98 additions and 95 deletions

View File

@ -61,7 +61,7 @@ func TestMinerAllInfo(t *testing.T) {
t.Run("pre-info-all", run) t.Run("pre-info-all", run)
dh := kit.NewDealHarness(t, client, miner) dh := kit.NewDealHarness(t, client, miner)
dh.MakeFullDeal(context.Background(), 6, false, false, 0) dh.MakeOnlineDeal(context.Background(), 6, false, false, 0)
t.Run("post-info-all", run) t.Run("post-info-all", run)
} }

View File

@ -3,12 +3,16 @@ package itests
import ( import (
"bytes" "bytes"
"context" "context"
"io/ioutil"
"os"
"path/filepath"
"testing" "testing"
"time" "time"
"github.com/filecoin-project/go-fil-markets/storagemarket" "github.com/filecoin-project/go-fil-markets/storagemarket"
"github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/abi"
"github.com/filecoin-project/lotus/api" "github.com/filecoin-project/lotus/api"
"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/types" "github.com/filecoin-project/lotus/chain/types"
"github.com/filecoin-project/lotus/itests/kit" "github.com/filecoin-project/lotus/itests/kit"
@ -227,97 +231,96 @@ func TestFirstDealEnablesMining(t *testing.T) {
<-providerMined <-providerMined
} }
// func TestOfflineDealFlow(t *testing.T) {
// func TestOfflineDealFlow(t *testing.T) { blocktime := 10 * time.Millisecond
// blocktime := 10 * time.Millisecond
// // For these tests where the block time is artificially short, just use
// // For these tests where the block time is artificially short, just use // a deal start epoch that is guaranteed to be far enough in the future
// // a deal start epoch that is guaranteed to be far enough in the future // so that the deal starts sealing in time
// // so that the deal starts sealing in time startEpoch := abi.ChainEpoch(2 << 12)
// startEpoch := abi.ChainEpoch(2 << 12)
// runTest := func(t *testing.T, fastRet bool) {
// runTest := func(t *testing.T, fastRet bool) { ctx := context.Background()
// ctx := context.Background() client, miner, ens := kit.EnsembleMinimal(t, kit.MockProofs())
// fulls, miners := kit.MockMinerBuilder(t, kit.OneFull, kit.OneMiner) ens.InterconnectAll().BeginMining(blocktime)
// client, miner := fulls[0].FullNode.(*impl.FullNodeAPI), miners[0]
// dh := kit.NewDealHarness(t, client, miner)
// kit.ConnectAndStartMining(t, blocktime, miner, client)
// // Create a random file and import on the client.
// dh := kit.NewDealHarness(t, client, miner) res, path, data, err := kit.CreateImportFile(ctx, client, 1, 0)
// require.NoError(t, err)
// // Create a random file and import on the client.
// res, path, data, err := kit.CreateImportFile(ctx, client, 1, 0) // Get the piece size and commP
// require.NoError(t, err) fcid := res.Root
// pieceInfo, err := client.ClientDealPieceCID(ctx, fcid)
// // Get the piece size and commP require.NoError(t, err)
// fcid := res.Root t.Log("FILE CID:", fcid)
// pieceInfo, err := client.ClientDealPieceCID(ctx, fcid)
// require.NoError(t, err) // Create a storage deal with the miner
// fmt.Println("FILE CID: ", fcid) maddr, err := miner.ActorAddress(ctx)
// require.NoError(t, err)
// // Create a storage deal with the miner
// maddr, err := miner.ActorAddress(ctx) addr, err := client.WalletDefaultAddress(ctx)
// require.NoError(t, err) require.NoError(t, err)
//
// addr, err := client.WalletDefaultAddress(ctx) // Manual storage deal (offline deal)
// require.NoError(t, err) dataRef := &storagemarket.DataRef{
// TransferType: storagemarket.TTManual,
// // Manual storage deal (offline deal) Root: fcid,
// dataRef := &storagemarket.DataRef{ PieceCid: &pieceInfo.PieceCID,
// TransferType: storagemarket.TTManual, PieceSize: pieceInfo.PieceSize.Unpadded(),
// Root: fcid, }
// PieceCid: &pieceInfo.PieceCID,
// PieceSize: pieceInfo.PieceSize.Unpadded(), proposalCid, err := client.ClientStartDeal(ctx, &api.StartDealParams{
// } Data: dataRef,
// Wallet: addr,
// proposalCid, err := client.ClientStartDeal(ctx, &api.StartDealParams{ Miner: maddr,
// Data: dataRef, EpochPrice: types.NewInt(1000000),
// Wallet: addr, DealStartEpoch: startEpoch,
// Miner: maddr, MinBlocksDuration: uint64(build.MinDealDuration),
// EpochPrice: types.NewInt(1000000), FastRetrieval: fastRet,
// DealStartEpoch: startEpoch, })
// MinBlocksDuration: uint64(build.MinDealDuration), require.NoError(t, err)
// FastRetrieval: fastRet,
// }) // Wait for the deal to reach StorageDealCheckForAcceptance on the client
// require.NoError(t, err) cd, err := client.ClientGetDealInfo(ctx, *proposalCid)
// require.NoError(t, err)
// // Wait for the deal to reach StorageDealCheckForAcceptance on the client require.Eventually(t, func() bool {
// cd, err := client.ClientGetDealInfo(ctx, *proposalCid) cd, _ := client.ClientGetDealInfo(ctx, *proposalCid)
// require.NoError(t, err) return cd.State == storagemarket.StorageDealCheckForAcceptance
// require.Eventually(t, func() bool { }, 30*time.Second, 1*time.Second, "actual deal status is %s", storagemarket.DealStates[cd.State])
// cd, _ := client.ClientGetDealInfo(ctx, *proposalCid)
// return cd.State == storagemarket.StorageDealCheckForAcceptance // Create a CAR file from the raw file
// }, 30*time.Second, 1*time.Second, "actual deal status is %s", storagemarket.DealStates[cd.State]) carFileDir, err := ioutil.TempDir(os.TempDir(), "test-make-deal-car")
// require.NoError(t, err)
// // Create a CAR file from the raw file
// carFileDir, err := ioutil.TempDir(os.TempDir(), "test-make-deal-car") carFilePath := filepath.Join(carFileDir, "out.car")
// require.NoError(t, err) err = client.ClientGenCar(ctx, api.FileRef{Path: path}, carFilePath)
// carFilePath := filepath.Join(carFileDir, "out.car") require.NoError(t, err)
// err = client.ClientGenCar(ctx, api.FileRef{Path: path}, carFilePath)
// require.NoError(t, err) // Import the CAR file on the miner - this is the equivalent to
// // transferring the file across the wire in a normal (non-offline) deal
// // Import the CAR file on the miner - this is the equivalent to err = miner.DealsImportData(ctx, *proposalCid, carFilePath)
// // transferring the file across the wire in a normal (non-offline) deal require.NoError(t, err)
// err = miner.DealsImportData(ctx, *proposalCid, carFilePath)
// require.NoError(t, err) // Wait for the deal to be published
// dh.WaitDealPublished(ctx, proposalCid)
// // Wait for the deal to be published
// dh.WaitDealPublished(ctx, proposalCid) t.Logf("deal published, retrieving")
//
// t.Logf("deal published, retrieving") // Retrieve the deal
// dh.PerformRetrieval(ctx, fcid, &pieceInfo.PieceCID, false, data)
// // Retrieve the deal }
// dh.PerformRetrieval(ctx, fcid, &pieceInfo.PieceCID, false, data)
// } t.Run("NormalRetrieval", func(t *testing.T) {
// runTest(t, false)
// t.Run("NormalRetrieval", func(t *testing.T) { })
// runTest(t, false) t.Run("FastRetrieval", func(t *testing.T) {
// }) runTest(t, true)
// t.Run("FastRetrieval", func(t *testing.T) { })
// runTest(t, true)
// }) }
//
// }
// //
// func runFullDealCycles(t *testing.T, n int, b kit.APIBuilder, blocktime time.Duration, carExport, fastRet bool, startEpoch abi.ChainEpoch) { // func runFullDealCycles(t *testing.T, n int, b kit.APIBuilder, blocktime time.Duration, carExport, fastRet bool, startEpoch abi.ChainEpoch) {
// full, _, ens := kit.EnsembleMinimal(t) // full, _, ens := kit.EnsembleMinimal(t)
@ -326,7 +329,7 @@ func TestFirstDealEnablesMining(t *testing.T) {
// //
// baseseed := 6 // baseseed := 6
// for i := 0; i < n; i++ { // for i := 0; i < n; i++ {
// dh.MakeFullDeal(context.Background(), baseseed+i, carExport, fastRet, startEpoch) // dh.MakeOnlineDeal(context.Background(), baseseed+i, carExport, fastRet, startEpoch)
// } // }
// } // }
// //
@ -434,5 +437,5 @@ func TestFirstDealEnablesMining(t *testing.T) {
// err = miner.MarketSetRetrievalAsk(ctx, ask) // err = miner.MarketSetRetrievalAsk(ctx, ask)
// require.NoError(t, err) // require.NoError(t, err)
// //
// dh.MakeFullDeal(ctx, 6, false, false, startEpoch) // dh.MakeOnlineDeal(ctx, 6, false, false, startEpoch)
// } // }

View File

@ -42,7 +42,7 @@ func NewDealHarness(t *testing.T, client api.FullNode, miner *TestMiner) *DealHa
} }
} }
func (dh *DealHarness) MakeFullDeal(ctx context.Context, rseed int, carExport, fastRet bool, startEpoch abi.ChainEpoch) { func (dh *DealHarness) MakeOnlineDeal(ctx context.Context, rseed int, carExport, fastRet bool, startEpoch abi.ChainEpoch) {
res, _, data, err := CreateImportFile(ctx, dh.client, rseed, 0) res, _, data, err := CreateImportFile(ctx, dh.client, rseed, 0)
require.NoError(dh.t, err) require.NoError(dh.t, err)