diff --git a/api/api_full.go b/api/api_full.go index 2e0b81d1a..2d5ed580c 100644 --- a/api/api_full.go +++ b/api/api_full.go @@ -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, } diff --git a/api/test/deals.go b/api/test/deals.go index 62830c382..f4a815594 100644 --- a/api/test/deals.go +++ b/api/test/deals.go @@ -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 diff --git a/cli/client.go b/cli/client.go index ff82455ba..0f1fdc991 100644 --- a/cli/client.go +++ b/cli/client.go @@ -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 } diff --git a/node/node_test.go b/node/node_test.go index f5760230b..c97eae27c 100644 --- a/node/node_test.go +++ b/node/node_test.go @@ -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) diff --git a/paych/simple.go b/paych/simple.go index 99c578d05..81ba51830 100644 --- a/paych/simple.go +++ b/paych/simple.go @@ -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