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)
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)
}

View File

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