Skip to content

Commit

Permalink
test for retrieval by any cid
Browse files Browse the repository at this point in the history
  • Loading branch information
aarshkshah1992 committed Sep 17, 2021
1 parent ae01c1e commit 25fa97e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 23 deletions.
37 changes: 23 additions & 14 deletions itests/deals_anycid_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package itests

import (
"bufio"
"context"
"fmt"
"os"
Expand Down Expand Up @@ -76,9 +77,9 @@ func TestDealRetrieveByAnyCid(t *testing.T) {
//res, path := client.CreateImportFile(ctx, 5, 140*1024*1024)
dagOpts := kit.GeneratedDAGOpts{
ChunkSize: 1024,
Maxlinks: 2,
Maxlinks: 10,
}
carv1FilePath, _ := kit.CreateRandomCARv1(t, 5, 8*1024, dagOpts)
carv1FilePath, _ := kit.CreateRandomCARv1(t, 5, 100*1024, dagOpts)
res, err := client.ClientImport(ctx, api.FileRef{Path: carv1FilePath, IsCAR: true})
require.NoError(t, err)

Expand All @@ -91,7 +92,6 @@ func TestDealRetrieveByAnyCid(t *testing.T) {
prepared, err := sc.Prepare()
require.NoError(t, err)
cids := prepared.Cids()
// fmt.Println(cids)
for i, c := range cids {
blk, err := bs.Get(c)
require.NoError(t, err)
Expand Down Expand Up @@ -127,17 +127,26 @@ func TestDealRetrieveByAnyCid(t *testing.T) {
info, err := client.ClientGetDealInfo(ctx, *dealCid)
require.NoError(t, err)

//targetCid := res.Root
targetCid := cids[1]
offer, err := client.ClientMinerQueryOffer(ctx, miner.ActorAddr, targetCid, &info.PieceCID)
require.NoError(t, err)
require.Empty(t, offer.Err)
cidIndices := []int{1, 11, 27, 32, 47}

outPath := dh.PerformRetrievalForOffer(ctx, false, offer)
stat, err := os.Stat(outPath)
require.NoError(t, err)
fmt.Println(stat)
for _, val := range cidIndices {
fmt.Println("performing retrieval for cid at index", val)
targetCid := cids[val]
offer, err := client.ClientMinerQueryOffer(ctx, miner.ActorAddr, targetCid, &info.PieceCID)
require.NoError(t, err)
require.Empty(t, offer.Err)

outPath := dh.PerformRetrievalForOffer(ctx, true, offer)
_, err = os.Stat(outPath)
require.NoError(t, err)

f, err := os.Open(outPath)
require.NoError(t, err)
defer f.Close()

ch, _, _ := car.ReadHeader(bufio.NewReader(f))
require.EqualValues(t, ch.Roots[0], targetCid)
}

// TODO: compare stored vs retrieved blocks
//kit.AssertFilesEqual(t, path, outPath)
fmt.Println("finised test")
}
13 changes: 4 additions & 9 deletions itests/kit/deals.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,16 +281,16 @@ func (dh *DealHarness) PerformRetrieval(ctx context.Context, dealCid *cid.Cid, r
}

func (dh *DealHarness) PerformRetrievalForOffer(ctx context.Context, carExport bool, offer api.QueryOffer) string {
carFile, err := ioutil.TempFile(dh.t.TempDir(), "ret-car")
outputF, err := ioutil.TempFile(dh.t.TempDir(), "ret-car")
require.NoError(dh.t, err)

defer carFile.Close() //nolint:errcheck
defer outputF.Close() //nolint:errcheck

caddr, err := dh.client.WalletDefaultAddress(ctx)
require.NoError(dh.t, err)

ref := &api.FileRef{
Path: carFile.Name(),
Path: outputF.Name(),
IsCAR: carExport,
}

Expand All @@ -302,12 +302,7 @@ func (dh *DealHarness) PerformRetrievalForOffer(ctx context.Context, carExport b
require.Emptyf(dh.t, update.Err, "retrieval failed: %s", update.Err)
}

ret := carFile.Name()
if carExport {
actualFile := dh.ExtractFileFromCAR(ctx, carFile)
ret = actualFile.Name()
_ = actualFile.Close() //nolint:errcheck
}
ret := outputF.Name()

return ret
}
Expand Down

0 comments on commit 25fa97e

Please sign in to comment.