Test Retrieval

This commit is contained in:
Łukasz Magiera 2019-12-01 22:52:24 +01:00
parent c7cf20843e
commit 68d1fd5958
5 changed files with 52 additions and 11 deletions

View File

@ -226,12 +226,14 @@ type QueryOffer struct {
MinerPeerID peer.ID
}
func (o *QueryOffer) Order() RetrievalOrder {
func (o *QueryOffer) Order(client address.Address) RetrievalOrder {
return RetrievalOrder{
Root: o.Root,
Size: o.Size,
Total: o.MinPrice,
Client: client,
Miner: o.Miner,
MinerPeerID: o.MinerPeerID,
}

View File

@ -1,11 +1,14 @@
package test
import (
"bytes"
"context"
"fmt"
"io"
"io/ioutil"
"math/rand"
"os"
"path/filepath"
"testing"
"time"
@ -40,7 +43,8 @@ func TestDealFlow(t *testing.T, b APIBuilder) {
}
time.Sleep(time.Second)
r := io.LimitReader(rand.New(rand.NewSource(17)), 1000)
data, _ := ioutil.ReadAll(io.LimitReader(rand.New(rand.NewSource(5)), 1000))
r := bytes.NewReader(data)
fcid, err := client.ClientImportLocal(ctx, r)
if err != nil {
t.Fatal(err)
@ -94,6 +98,42 @@ loop:
time.Sleep(time.Second / 2)
}
// Retrieval
offers, err := client.ClientFindData(ctx, fcid)
if err != nil {
t.Fatal(err)
}
if len(offers) < 1 {
t.Fatal("no offers")
}
rpath, err := ioutil.TempDir("", "lotus-retrieve-test-")
if err != nil {
t.Fatal(err)
}
defer os.RemoveAll(rpath)
caddr, err := client.WalletDefaultAddress(ctx)
if err != nil {
t.Fatal(err)
}
err = client.ClientRetrieve(ctx, offers[0].Order(caddr), filepath.Join(rpath, "ret"))
if err != nil {
t.Fatalf("%+v", err)
}
rdata, err := ioutil.ReadFile(filepath.Join(rpath, "ret"))
if err != nil {
t.Fatal(err)
}
if !bytes.Equal(rdata, data) {
t.Fatal("wrong data retrieved")
}
mine = false
fmt.Println("shutting down mining")
<-done

View File

@ -234,10 +234,8 @@ var clientRetrieveCmd = &cli.Command{
fmt.Println("Failed to find file")
return nil
}
order := offers[0].Order()
order.Client = payer
if err := api.ClientRetrieve(ctx, order, cctx.Args().Get(1)); err != nil {
if err := api.ClientRetrieve(ctx, offers[0].Order(payer), cctx.Args().Get(1)); err != nil {
return err
}

View File

@ -227,7 +227,7 @@ func builder(t *testing.T, nFull int, storage []int) ([]test.TestNode, []test.Te
CacheDir: filepath.Join(psd, "cache"),
StagedDir: filepath.Join(psd, "staging"),
SealedDir: filepath.Join(psd, "sealed"),
MetadataDir: filepath.Join(psd, "meta"),
UnsealedDir: filepath.Join(psd, "unsealed"),
}, mds)
if err != nil {
t.Fatal(err)

View File

@ -5,6 +5,7 @@ import (
"fmt"
"github.com/ipfs/go-cid"
"golang.org/x/xerrors"
"github.com/filecoin-project/lotus/chain/actors"
"github.com/filecoin-project/lotus/chain/address"
@ -37,7 +38,7 @@ func (pm *Manager) createPaych(ctx context.Context, from, to address.Address, am
smsg, err := pm.mpool.MpoolPushMessage(ctx, msg)
if err != nil {
return address.Undef, cid.Undef, err
return address.Undef, cid.Undef, xerrors.Errorf("initializing paych actor: %w", err)
}
mcid := smsg.Cid()
@ -46,7 +47,7 @@ func (pm *Manager) createPaych(ctx context.Context, from, to address.Address, am
// (tricky because we need to setup channel tracking before we know it's address)
mwait, err := pm.state.StateWaitMsg(ctx, mcid)
if err != nil {
return address.Undef, cid.Undef, err
return address.Undef, cid.Undef, xerrors.Errorf("wait msg: %w", err)
}
if mwait.Receipt.ExitCode != 0 {
@ -60,11 +61,11 @@ func (pm *Manager) createPaych(ctx context.Context, from, to address.Address, am
ci, err := pm.loadOutboundChannelInfo(ctx, paychaddr)
if err != nil {
return address.Undef, cid.Undef, err
return address.Undef, cid.Undef, xerrors.Errorf("loading channel info: %w", err)
}
if err := pm.store.trackChannel(ci); err != nil {
return address.Undef, cid.Undef, err
return address.Undef, cid.Undef, xerrors.Errorf("tracking channel: %w", err)
}
return paychaddr, mcid, nil
@ -108,7 +109,7 @@ func (pm *Manager) GetPaych(ctx context.Context, from, to address.Address, ensur
return ci.Control == from && ci.Target == to
})
if err != nil {
return address.Undef, cid.Undef, err
return address.Undef, cid.Undef, xerrors.Errorf("findChan: %w", err)
}
if ch != address.Undef {
// TODO: Track available funds