Merge pull request #6081 from filecoin-project/test/offline-deals
Integration tests for offline deals
This commit is contained in:
commit
b8deee048e
@ -75,19 +75,7 @@ func MakeDeal(t *testing.T, ctx context.Context, rseed int, client api.FullNode,
|
|||||||
}
|
}
|
||||||
|
|
||||||
func CreateClientFile(ctx context.Context, client api.FullNode, rseed, size int) (*api.ImportRes, []byte, error) {
|
func CreateClientFile(ctx context.Context, client api.FullNode, rseed, size int) (*api.ImportRes, []byte, error) {
|
||||||
if size == 0 {
|
data, path, err := createRandomFile(rseed, size)
|
||||||
size = 1600
|
|
||||||
}
|
|
||||||
data := make([]byte, size)
|
|
||||||
rand.New(rand.NewSource(int64(rseed))).Read(data)
|
|
||||||
|
|
||||||
dir, err := ioutil.TempDir(os.TempDir(), "test-make-deal-")
|
|
||||||
if err != nil {
|
|
||||||
return nil, nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
path := filepath.Join(dir, "sourcefile.dat")
|
|
||||||
err = ioutil.WriteFile(path, data, 0644)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
@ -99,6 +87,27 @@ func CreateClientFile(ctx context.Context, client api.FullNode, rseed, size int)
|
|||||||
return res, data, nil
|
return res, data, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func createRandomFile(rseed, size int) ([]byte, string, error) {
|
||||||
|
if size == 0 {
|
||||||
|
size = 1600
|
||||||
|
}
|
||||||
|
data := make([]byte, size)
|
||||||
|
rand.New(rand.NewSource(int64(rseed))).Read(data)
|
||||||
|
|
||||||
|
dir, err := ioutil.TempDir(os.TempDir(), "test-make-deal-")
|
||||||
|
if err != nil {
|
||||||
|
return nil, "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
path := filepath.Join(dir, "sourcefile.dat")
|
||||||
|
err = ioutil.WriteFile(path, data, 0644)
|
||||||
|
if err != nil {
|
||||||
|
return nil, "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
return data, path, nil
|
||||||
|
}
|
||||||
|
|
||||||
func TestPublishDealsBatching(t *testing.T, b APIBuilder, blocktime time.Duration, startEpoch abi.ChainEpoch) {
|
func TestPublishDealsBatching(t *testing.T, b APIBuilder, blocktime time.Duration, startEpoch abi.ChainEpoch) {
|
||||||
publishPeriod := 10 * time.Second
|
publishPeriod := 10 * time.Second
|
||||||
maxDealsPerMsg := uint64(2)
|
maxDealsPerMsg := uint64(2)
|
||||||
@ -382,6 +391,79 @@ func TestZeroPricePerByteRetrievalDealFlow(t *testing.T, b APIBuilder, blocktime
|
|||||||
MakeDeal(t, s.ctx, 6, s.client, s.miner, false, false, startEpoch)
|
MakeDeal(t, s.ctx, 6, s.client, s.miner, false, false, startEpoch)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestOfflineDealFlow(t *testing.T, b APIBuilder, blocktime time.Duration, startEpoch abi.ChainEpoch, fastRet bool) {
|
||||||
|
s := setupOneClientOneMiner(t, b, blocktime)
|
||||||
|
defer s.blockMiner.Stop()
|
||||||
|
|
||||||
|
// Create a random file
|
||||||
|
data, path, err := createRandomFile(1, 0)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
// Import the file on the client
|
||||||
|
importRes, err := s.client.ClientImport(s.ctx, api.FileRef{Path: path})
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
// Get the piece size and commP
|
||||||
|
fcid := importRes.Root
|
||||||
|
pieceInfo, err := s.client.ClientDealPieceCID(s.ctx, fcid)
|
||||||
|
require.NoError(t, err)
|
||||||
|
fmt.Println("FILE CID: ", fcid)
|
||||||
|
|
||||||
|
// Create a storage deal with the miner
|
||||||
|
maddr, err := s.miner.ActorAddress(s.ctx)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
addr, err := s.client.WalletDefaultAddress(s.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 := s.client.ClientStartDeal(s.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 := s.client.ClientGetDealInfo(s.ctx, *proposalCid)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Eventually(t, func() bool {
|
||||||
|
cd, _ := s.client.ClientGetDealInfo(s.ctx, *proposalCid)
|
||||||
|
return cd.State == storagemarket.StorageDealCheckForAcceptance
|
||||||
|
}, 1*time.Second, 100*time.Millisecond, "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 = s.client.ClientGenCar(s.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 = s.miner.DealsImportData(s.ctx, *proposalCid, carFilePath)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
// Wait for the deal to be published
|
||||||
|
waitDealPublished(t, s.ctx, s.miner, proposalCid)
|
||||||
|
|
||||||
|
t.Logf("deal published, retrieving")
|
||||||
|
|
||||||
|
// Retrieve the deal
|
||||||
|
testRetrieval(t, s.ctx, s.client, fcid, &pieceInfo.PieceCID, false, data)
|
||||||
|
}
|
||||||
|
|
||||||
func startDeal(t *testing.T, ctx context.Context, miner TestStorageNode, client api.FullNode, fcid cid.Cid, fastRet bool, startEpoch abi.ChainEpoch) *cid.Cid {
|
func startDeal(t *testing.T, ctx context.Context, miner TestStorageNode, client api.FullNode, fcid cid.Cid, fastRet bool, startEpoch abi.ChainEpoch) *cid.Cid {
|
||||||
maddr, err := miner.ActorAddress(ctx)
|
maddr, err := miner.ActorAddress(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -58,6 +58,12 @@ func TestAPIDealFlow(t *testing.T) {
|
|||||||
t.Run("TestPublishDealsBatching", func(t *testing.T) {
|
t.Run("TestPublishDealsBatching", func(t *testing.T) {
|
||||||
test.TestPublishDealsBatching(t, builder.MockSbBuilder, blockTime, dealStartEpoch)
|
test.TestPublishDealsBatching(t, builder.MockSbBuilder, blockTime, dealStartEpoch)
|
||||||
})
|
})
|
||||||
|
t.Run("TestOfflineDealFlow", func(t *testing.T) {
|
||||||
|
test.TestOfflineDealFlow(t, builder.MockSbBuilder, blockTime, dealStartEpoch, false)
|
||||||
|
})
|
||||||
|
t.Run("TestOfflineDealFlowFastRetrieval", func(t *testing.T) {
|
||||||
|
test.TestOfflineDealFlow(t, builder.MockSbBuilder, blockTime, dealStartEpoch, true)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestBatchDealInput(t *testing.T) {
|
func TestBatchDealInput(t *testing.T) {
|
||||||
|
Loading…
Reference in New Issue
Block a user