@cryptotaxi247 / kubo / commits / eb23c9003

coreapi: replace coreiface.DagAPI with ipld.DAGService

License: MIT Signed-off-by: Łukasz Magiera <magik6k@gmail.com>

Łukasz Magiera committed Jan 12, 2019 at 15:41 UTC eb23c90031dd481f3d1e3e8c192e2af5cef2dc60
9 files changed +100 -319
core/coreapi/coreapi.go
+2 -2
@@ -96,8 +96,8 @@ func (api *CoreAPI) Block() coreiface.BlockAPI {
96 }
97
98 // Dag returns the DagAPI interface implementation backed by the go-ipfs node
99 -func (api *CoreAPI) Dag() coreiface.DagAPI {
100 - return (*DagAPI)(api)
99 +func (api *CoreAPI) Dag() ipld.DAGService {
100 + return api.dag
101 }
102
103 // Name returns the NameAPI interface implementation backed by the go-ipfs node
core/coreapi/dag.go deleted
-132
@@ -1,132 +0,0 @@
1 -package coreapi
2 -
3 -import (
4 - "context"
5 - "fmt"
6 - "io"
7 - "sync"
8 -
9 - gopath "path"
10 -
11 - coreiface "github.com/ipfs/go-ipfs/core/coreapi/interface"
12 - caopts "github.com/ipfs/go-ipfs/core/coreapi/interface/options"
13 - coredag "github.com/ipfs/go-ipfs/core/coredag"
14 -
15 - cid "gx/ipfs/QmR8BauakNcBa3RbE4nbQu76PDiJgoQgz8AJdhJuiU4TAw/go-cid"
16 - ipld "gx/ipfs/QmcKKBwfz6FyQdHR2jsXrrF6XeSBXYL86anmWNewpFpoF5/go-ipld-format"
17 -)
18 -
19 -type DagAPI CoreAPI
20 -
21 -type dagBatch struct {
22 - api *DagAPI
23 - toPut []ipld.Node
24 -
25 - lk sync.Mutex
26 -}
27 -
28 -// Put inserts data using specified format and input encoding. Unless used with
29 -// `WithCodes` or `WithHash`, the defaults "dag-cbor" and "sha256" are used.
30 -// Returns the path of the inserted data.
31 -func (api *DagAPI) Put(ctx context.Context, src io.Reader, opts ...caopts.DagPutOption) (coreiface.ResolvedPath, error) {
32 - nd, err := getNode(src, opts...)
33 - if err != nil {
34 - return nil, err
35 - }
36 -
37 - err = api.dag.Add(ctx, nd)
38 - if err != nil {
39 - return nil, err
40 - }
41 -
42 - return coreiface.IpldPath(nd.Cid()), nil
43 -}
44 -
45 -// Get resolves `path` using Unixfs resolver, returns the resolved Node.
46 -func (api *DagAPI) Get(ctx context.Context, path coreiface.Path) (ipld.Node, error) {
47 - return api.core().ResolveNode(ctx, path)
48 -}
49 -
50 -// Tree returns list of paths within a node specified by the path `p`.
51 -func (api *DagAPI) Tree(ctx context.Context, p coreiface.Path, opts ...caopts.DagTreeOption) ([]coreiface.Path, error) {
52 - settings, err := caopts.DagTreeOptions(opts...)
53 - if err != nil {
54 - return nil, err
55 - }
56 -
57 - n, err := api.Get(ctx, p)
58 - if err != nil {
59 - return nil, err
60 - }
61 - paths := n.Tree("", settings.Depth)
62 - out := make([]coreiface.Path, len(paths))
63 - for n, p2 := range paths {
64 - out[n], err = coreiface.ParsePath(gopath.Join(p.String(), p2))
65 - if err != nil {
66 - return nil, err
67 - }
68 - }
69 -
70 - return out, nil
71 -}
72 -
73 -// Batch creates new DagBatch
74 -func (api *DagAPI) Batch(ctx context.Context) coreiface.DagBatch {
75 - return &dagBatch{api: api}
76 -}
77 -
78 -// Put inserts data using specified format and input encoding. Unless used with
79 -// `WithCodes` or `WithHash`, the defaults "dag-cbor" and "sha256" are used.
80 -// Returns the path of the inserted data.
81 -func (b *dagBatch) Put(ctx context.Context, src io.Reader, opts ...caopts.DagPutOption) (coreiface.ResolvedPath, error) {
82 - nd, err := getNode(src, opts...)
83 - if err != nil {
84 - return nil, err
85 - }
86 -
87 - b.lk.Lock()
88 - b.toPut = append(b.toPut, nd)
89 - b.lk.Unlock()
90 -
91 - return coreiface.IpldPath(nd.Cid()), nil
92 -}
93 -
94 -// Commit commits nodes to the datastore and announces them to the network
95 -func (b *dagBatch) Commit(ctx context.Context) error {
96 - b.lk.Lock()
97 - defer b.lk.Unlock()
98 - defer func() {
99 - b.toPut = nil
100 - }()
101 -
102 - return b.api.dag.AddMany(ctx, b.toPut)
103 -}
104 -
105 -func getNode(src io.Reader, opts ...caopts.DagPutOption) (ipld.Node, error) {
106 - settings, err := caopts.DagPutOptions(opts...)
107 - if err != nil {
108 - return nil, err
109 - }
110 -
111 - codec, ok := cid.CodecToStr[settings.Codec]
112 - if !ok {
113 - return nil, fmt.Errorf("invalid codec %d", settings.Codec)
114 - }
115 -
116 - nds, err := coredag.ParseInputs(settings.InputEnc, codec, src, settings.MhType, settings.MhLength)
117 - if err != nil {
118 - return nil, err
119 - }
120 - if len(nds) == 0 {
121 - return nil, fmt.Errorf("no node returned from ParseInputs")
122 - }
123 - if len(nds) != 1 {
124 - return nil, fmt.Errorf("got more that one node from ParseInputs")
125 - }
126 -
127 - return nds[0], nil
128 -}
129 -
130 -func (api *DagAPI) core() coreiface.CoreAPI {
131 - return (*CoreAPI)(api)
132 -}
core/coreapi/interface/coreapi.go
+1 -1
@@ -19,7 +19,7 @@ type CoreAPI interface {
19 Block() BlockAPI
20
21 // Dag returns an implementation of Dag API
22 - Dag() DagAPI
22 + Dag() ipld.DAGService
23
24 // Name returns an implementation of Name API
25 Name() NameAPI
core/coreapi/interface/dag.go deleted
-41
@@ -1,41 +0,0 @@
1 -package iface
2 -
3 -import (
4 - "context"
5 - "io"
6 -
7 - "github.com/ipfs/go-ipfs/core/coreapi/interface/options"
8 -
9 - ipld "gx/ipfs/QmcKKBwfz6FyQdHR2jsXrrF6XeSBXYL86anmWNewpFpoF5/go-ipld-format"
10 -)
11 -
12 -// DagOps groups operations that can be batched together
13 -type DagOps interface {
14 - // Put inserts data using specified format and input encoding.
15 - // Unless used with WithCodec or WithHash, the defaults "dag-cbor" and
16 - // "sha256" are used.
17 - Put(ctx context.Context, src io.Reader, opts ...options.DagPutOption) (ResolvedPath, error)
18 -}
19 -
20 -// DagBatch is the batching version of DagAPI. All implementations of DagBatch
21 -// should be threadsafe
22 -type DagBatch interface {
23 - DagOps
24 -
25 - // Commit commits nodes to the datastore and announces them to the network
26 - Commit(ctx context.Context) error
27 -}
28 -
29 -// DagAPI specifies the interface to IPLD
30 -type DagAPI interface {
31 - DagOps
32 -
33 - // Get attempts to resolve and get the node specified by the path
34 - Get(ctx context.Context, path Path) (ipld.Node, error)
35 -
36 - // Tree returns list of paths within a node specified by the path.
37 - Tree(ctx context.Context, path Path, opts ...options.DagTreeOption) ([]Path, error)
38 -
39 - // Batch creates new DagBatch
40 - Batch(ctx context.Context) DagBatch
41 -}
core/coreapi/interface/options/dag.go deleted
-95
@@ -1,95 +0,0 @@
1 -package options
2 -
3 -import (
4 - "math"
5 -
6 - cid "gx/ipfs/QmR8BauakNcBa3RbE4nbQu76PDiJgoQgz8AJdhJuiU4TAw/go-cid"
7 -)
8 -
9 -type DagPutSettings struct {
10 - InputEnc string
11 - Codec uint64
12 - MhType uint64
13 - MhLength int
14 -}
15 -
16 -type DagTreeSettings struct {
17 - Depth int
18 -}
19 -
20 -type DagPutOption func(*DagPutSettings) error
21 -type DagTreeOption func(*DagTreeSettings) error
22 -
23 -func DagPutOptions(opts ...DagPutOption) (*DagPutSettings, error) {
24 - options := &DagPutSettings{
25 - InputEnc: "json",
26 - Codec: cid.DagCBOR,
27 - MhType: math.MaxUint64,
28 - MhLength: -1,
29 - }
30 -
31 - for _, opt := range opts {
32 - err := opt(options)
33 - if err != nil {
34 - return nil, err
35 - }
36 - }
37 - return options, nil
38 -}
39 -
40 -func DagTreeOptions(opts ...DagTreeOption) (*DagTreeSettings, error) {
41 - options := &DagTreeSettings{
42 - Depth: -1,
43 - }
44 -
45 - for _, opt := range opts {
46 - err := opt(options)
47 - if err != nil {
48 - return nil, err
49 - }
50 - }
51 - return options, nil
52 -}
53 -
54 -type dagOpts struct{}
55 -
56 -var Dag dagOpts
57 -
58 -// InputEnc is an option for Dag.Put which specifies the input encoding of the
59 -// data. Default is "json", most formats/codecs support "raw"
60 -func (dagOpts) InputEnc(enc string) DagPutOption {
61 - return func(settings *DagPutSettings) error {
62 - settings.InputEnc = enc
63 - return nil
64 - }
65 -}
66 -
67 -// Codec is an option for Dag.Put which specifies the multicodec to use to
68 -// serialize the object. Default is cid.DagCBOR (0x71)
69 -func (dagOpts) Codec(codec uint64) DagPutOption {
70 - return func(settings *DagPutSettings) error {
71 - settings.Codec = codec
72 - return nil
73 - }
74 -}
75 -
76 -// Hash is an option for Dag.Put which specifies the multihash settings to use
77 -// when hashing the object. Default is based on the codec used
78 -// (mh.SHA2_256 (0x12) for DagCBOR). If mhLen is set to -1, default length for
79 -// the hash will be used
80 -func (dagOpts) Hash(mhType uint64, mhLen int) DagPutOption {
81 - return func(settings *DagPutSettings) error {
82 - settings.MhType = mhType
83 - settings.MhLength = mhLen
84 - return nil
85 - }
86 -}
87 -
88 -// Depth is an option for Dag.Tree which specifies maximum depth of the
89 -// returned tree. Default is -1 (no depth limit)
90 -func (dagOpts) Depth(depth int) DagTreeOption {
91 - return func(settings *DagTreeSettings) error {
92 - settings.Depth = depth
93 - return nil
94 - }
95 -}
core/coreapi/interface/tests/dag.go
+53 -24
@@ -2,12 +2,13 @@ package tests
2
3 import (
4 "context"
5 + "math"
6 "path"
7 "strings"
8 "testing"
9
10 coreiface "github.com/ipfs/go-ipfs/core/coreapi/interface"
10 - opt "github.com/ipfs/go-ipfs/core/coreapi/interface/options"
11 + coredag "github.com/ipfs/go-ipfs/core/coredag"
12
13 mh "gx/ipfs/QmerPMzPk1mJVowm8KgmoknWa4yCYvvugMPsgWmDNUvDLW/go-multihash"
14 )
@@ -45,13 +46,18 @@ func (tp *provider) TestPut(t *testing.T) {
46 t.Error(err)
47 }
48
48 - res, err := api.Dag().Put(ctx, strings.NewReader(`"Hello"`))
49 + nds, err := coredag.ParseInputs("json", "dag-cbor", strings.NewReader(`"Hello"`), math.MaxUint64, -1)
50 + if err != nil {
51 + t.Error(err)
52 + }
53 +
54 + err = api.Dag().Add(ctx, nds[0])
55 if err != nil {
56 t.Fatal(err)
57 }
58
53 - if res.Cid().String() != "zdpuAqckYF3ToF3gcJNxPZXmnmGuXd3gxHCXhq81HGxBejEvv" {
54 - t.Errorf("got wrong cid: %s", res.Cid().String())
59 + if nds[0].Cid().String() != "zdpuAqckYF3ToF3gcJNxPZXmnmGuXd3gxHCXhq81HGxBejEvv" {
60 + t.Errorf("got wrong cid: %s", nds[0].Cid().String())
61 }
62 }
63
@@ -63,13 +69,18 @@ func (tp *provider) TestPutWithHash(t *testing.T) {
69 t.Error(err)
70 }
71
66 - res, err := api.Dag().Put(ctx, strings.NewReader(`"Hello"`), opt.Dag.Hash(mh.ID, -1))
72 + nds, err := coredag.ParseInputs("json", "dag-cbor", strings.NewReader(`"Hello"`), mh.ID, -1)
73 + if err != nil {
74 + t.Error(err)
75 + }
76 +
77 + err = api.Dag().Add(ctx, nds[0])
78 if err != nil {
79 t.Fatal(err)
80 }
81
71 - if res.Cid().String() != "z5hRLNd2sv4z1c" {
72 - t.Errorf("got wrong cid: %s", res.Cid().String())
82 + if nds[0].Cid().String() != "z5hRLNd2sv4z1c" {
83 + t.Errorf("got wrong cid: %s", nds[0].Cid().String())
84 }
85 }
86
@@ -81,28 +92,43 @@ func (tp *provider) TestDagPath(t *testing.T) {
92 t.Error(err)
93 }
94
84 - sub, err := api.Dag().Put(ctx, strings.NewReader(`"foo"`))
95 + snds, err := coredag.ParseInputs("json", "dag-cbor", strings.NewReader(`"foo"`), math.MaxUint64, -1)
96 + if err != nil {
97 + t.Error(err)
98 + }
99 +
100 + err = api.Dag().Add(ctx, snds[0])
101 if err != nil {
102 t.Fatal(err)
103 }
104
89 - res, err := api.Dag().Put(ctx, strings.NewReader(`{"lnk": {"/": "`+sub.Cid().String()+`"}}`))
105 + nds, err := coredag.ParseInputs("json", "dag-cbor", strings.NewReader(`{"lnk": {"/": "`+snds[0].Cid().String()+`"}}`), math.MaxUint64, -1)
106 + if err != nil {
107 + t.Error(err)
108 + }
109 +
110 + err = api.Dag().Add(ctx, nds[0])
111 if err != nil {
112 t.Fatal(err)
113 }
114
94 - p, err := coreiface.ParsePath(path.Join(res.Cid().String(), "lnk"))
115 + p, err := coreiface.ParsePath(path.Join(nds[0].Cid().String(), "lnk"))
116 if err != nil {
117 t.Error(err)
118 }
119
99 - nd, err := api.Dag().Get(ctx, p)
120 + rp, err := api.ResolvePath(ctx, p)
121 if err != nil {
122 t.Error(err)
123 }
124
104 - if nd.Cid().String() != sub.Cid().String() {
105 - t.Errorf("got unexpected cid %s, expected %s", nd.Cid().String(), sub.Cid().String())
125 + nd, err := api.Dag().Get(ctx, rp.Cid())
126 + if err != nil {
127 + t.Error(err)
128 + }
129 +
130 + if nd.Cid().String() != snds[0].Cid().String() {
131 + t.Errorf("got unexpected cid %s, expected %s", nd.Cid().String(), snds[0].Cid().String())
132 }
133 }
134
@@ -114,12 +140,17 @@ func (tp *provider) TestTree(t *testing.T) {
140 t.Error(err)
141 }
142
117 - c, err := api.Dag().Put(ctx, strings.NewReader(`{"a": 123, "b": "foo", "c": {"d": 321, "e": 111}}`))
143 + nds, err := coredag.ParseInputs("json", "dag-cbor", strings.NewReader(`{"a": 123, "b": "foo", "c": {"d": 321, "e": 111}}`), math.MaxUint64, -1)
144 + if err != nil {
145 + t.Error(err)
146 + }
147 +
148 + err = api.Dag().Add(ctx, nds[0])
149 if err != nil {
150 t.Fatal(err)
151 }
152
122 - res, err := api.Dag().Get(ctx, c)
153 + res, err := api.Dag().Get(ctx, nds[0].Cid())
154 if err != nil {
155 t.Error(err)
156 }
@@ -144,27 +175,25 @@ func (tp *provider) TestBatch(t *testing.T) {
175 t.Error(err)
176 }
177
147 - batch := api.Dag().Batch(ctx)
148 -
149 - c, err := batch.Put(ctx, strings.NewReader(`"Hello"`))
178 + nds, err := coredag.ParseInputs("json", "dag-cbor", strings.NewReader(`"Hello"`), math.MaxUint64, -1)
179 if err != nil {
151 - t.Fatal(err)
180 + t.Error(err)
181 }
182
154 - if c.Cid().String() != "zdpuAqckYF3ToF3gcJNxPZXmnmGuXd3gxHCXhq81HGxBejEvv" {
155 - t.Errorf("got wrong cid: %s", c.Cid().String())
183 + if nds[0].Cid().String() != "zdpuAqckYF3ToF3gcJNxPZXmnmGuXd3gxHCXhq81HGxBejEvv" {
184 + t.Errorf("got wrong cid: %s", nds[0].Cid().String())
185 }
186
158 - _, err = api.Dag().Get(ctx, c)
187 + _, err = api.Dag().Get(ctx, nds[0].Cid())
188 if err == nil || err.Error() != "merkledag: not found" {
189 t.Error(err)
190 }
191
163 - if err := batch.Commit(ctx); err != nil {
192 + if err := api.Dag().AddMany(ctx, nds); err != nil {
193 t.Error(err)
194 }
195
167 - _, err = api.Dag().Get(ctx, c)
196 + _, err = api.Dag().Get(ctx, nds[0].Cid())
197 if err != nil {
198 t.Error(err)
199 }
core/coreapi/interface/tests/path.go
+26 -12
@@ -2,11 +2,13 @@ package tests
2
3 import (
4 "context"
5 + "math"
6 "strings"
7 "testing"
8
9 coreiface "github.com/ipfs/go-ipfs/core/coreapi/interface"
10 "github.com/ipfs/go-ipfs/core/coreapi/interface/options"
11 + "github.com/ipfs/go-ipfs/core/coredag"
12 )
13
14 func (tp *provider) TestPath(t *testing.T) {
@@ -62,12 +64,16 @@ func (tp *provider) TestPathRemainder(t *testing.T) {
64 t.Fatal(".Dag not implemented")
65 }
66
65 - obj, err := api.Dag().Put(ctx, strings.NewReader(`{"foo": {"bar": "baz"}}`))
67 + nds, err := coredag.ParseInputs("json", "dag-cbor", strings.NewReader(`{"foo": {"bar": "baz"}}`), math.MaxUint64, -1)
68 if err != nil {
69 + t.Error(err)
70 + }
71 +
72 + if err := api.Dag().AddMany(ctx, nds); err != nil {
73 t.Fatal(err)
74 }
75
70 - p1, err := coreiface.ParsePath(obj.String() + "/foo/bar")
76 + p1, err := coreiface.ParsePath(nds[0].String() + "/foo/bar")
77 if err != nil {
78 t.Error(err)
79 }
@@ -94,16 +100,16 @@ func (tp *provider) TestEmptyPathRemainder(t *testing.T) {
100 t.Fatal(".Dag not implemented")
101 }
102
97 - obj, err := api.Dag().Put(ctx, strings.NewReader(`{"foo": {"bar": "baz"}}`))
103 + nds, err := coredag.ParseInputs("json", "dag-cbor", strings.NewReader(`{"foo": {"bar": "baz"}}`), math.MaxUint64, -1)
104 if err != nil {
99 - t.Fatal(err)
105 + t.Error(err)
106 }
107
102 - if obj.Remainder() != "" {
103 - t.Error("expected the resolved path to not have a remainder")
108 + if err := api.Dag().AddMany(ctx, nds); err != nil {
109 + t.Fatal(err)
110 }
111
106 - p1, err := coreiface.ParsePath(obj.String())
112 + p1, err := coreiface.ParsePath(nds[0].Cid().String())
113 if err != nil {
114 t.Error(err)
115 }
@@ -130,12 +136,16 @@ func (tp *provider) TestInvalidPathRemainder(t *testing.T) {
136 t.Fatal(".Dag not implemented")
137 }
138
133 - obj, err := api.Dag().Put(ctx, strings.NewReader(`{"foo": {"bar": "baz"}}`))
139 + nds, err := coredag.ParseInputs("json", "dag-cbor", strings.NewReader(`{"foo": {"bar": "baz"}}`), math.MaxUint64, -1)
140 if err != nil {
141 + t.Error(err)
142 + }
143 +
144 + if err := api.Dag().AddMany(ctx, nds); err != nil {
145 t.Fatal(err)
146 }
147
138 - p1, err := coreiface.ParsePath(obj.String() + "/bar/baz")
148 + p1, err := coreiface.ParsePath("/ipld/" + nds[0].Cid().String() + "/bar/baz")
149 if err != nil {
150 t.Error(err)
151 }
@@ -167,12 +177,16 @@ func (tp *provider) TestPathRoot(t *testing.T) {
177 t.Fatal(".Dag not implemented")
178 }
179
170 - obj, err := api.Dag().Put(ctx, strings.NewReader(`{"foo": {"/": "`+blk.Path().Cid().String()+`"}}`))
180 + nds, err := coredag.ParseInputs("json", "dag-cbor", strings.NewReader(`{"foo": {"/": "`+blk.Path().Cid().String()+`"}}`), math.MaxUint64, -1)
181 if err != nil {
182 + t.Error(err)
183 + }
184 +
185 + if err := api.Dag().AddMany(ctx, nds); err != nil {
186 t.Fatal(err)
187 }
188
175 - p1, err := coreiface.ParsePath(obj.String() + "/foo")
189 + p1, err := coreiface.ParsePath("/ipld/" + nds[0].Cid().String() + "/foo")
190 if err != nil {
191 t.Error(err)
192 }
@@ -182,7 +196,7 @@ func (tp *provider) TestPathRoot(t *testing.T) {
196 t.Fatal(err)
197 }
198
185 - if rp.Root().String() != obj.Cid().String() {
199 + if rp.Root().String() != nds[0].Cid().String() {
200 t.Error("unexpected path root")
201 }
202
core/coreapi/interface/tests/pin.go
+15 -9
@@ -2,11 +2,13 @@ package tests
2
3 import (
4 "context"
5 - "github.com/ipfs/go-ipfs/core/coreapi/interface"
5 + "math"
6 "strings"
7 "testing"
8
9 + "github.com/ipfs/go-ipfs/core/coreapi/interface"
10 opt "github.com/ipfs/go-ipfs/core/coreapi/interface/options"
11 + "github.com/ipfs/go-ipfs/core/coredag"
12 )
13
14 func (tp *provider) TestPin(t *testing.T) {
@@ -109,22 +111,26 @@ func (tp *provider) TestPinRecursive(t *testing.T) {
111 t.Error(err)
112 }
113
112 - p2, err := api.Dag().Put(ctx, strings.NewReader(`{"lnk": {"/": "`+p0.Cid().String()+`"}}`))
114 + nd2, err := coredag.ParseInputs("json", "dag-cbor", strings.NewReader(`{"lnk": {"/": "`+p0.Cid().String()+`"}}`), math.MaxUint64, -1)
115 if err != nil {
116 t.Error(err)
117 }
118
117 - p3, err := api.Dag().Put(ctx, strings.NewReader(`{"lnk": {"/": "`+p1.Cid().String()+`"}}`))
119 + nd3, err := coredag.ParseInputs("json", "dag-cbor", strings.NewReader(`{"lnk": {"/": "`+p1.Cid().String()+`"}}`), math.MaxUint64, -1)
120 if err != nil {
121 t.Error(err)
122 }
123
122 - err = api.Pin().Add(ctx, p2)
124 + if err := api.Dag().AddMany(ctx, append(nd2, nd3...)); err != nil {
125 + t.Fatal(err)
126 + }
127 +
128 + err = api.Pin().Add(ctx, iface.IpldPath(nd2[0].Cid()))
129 if err != nil {
130 t.Error(err)
131 }
132
127 - err = api.Pin().Add(ctx, p3, opt.Pin.Recursive(false))
133 + err = api.Pin().Add(ctx, iface.IpldPath(nd3[0].Cid()), opt.Pin.Recursive(false))
134 if err != nil {
135 t.Error(err)
136 }
@@ -147,8 +153,8 @@ func (tp *provider) TestPinRecursive(t *testing.T) {
153 t.Errorf("unexpected pin list len: %d", len(list))
154 }
155
150 - if list[0].Path().String() != p3.String() {
151 - t.Error("unexpected path")
156 + if list[0].Path().String() != iface.IpldPath(nd3[0].Cid()).String() {
157 + t.Errorf("unexpected path, %s != %s", list[0].Path().String(), iface.IpfsPath(nd2[0].Cid()).String())
158 }
159
160 list, err = api.Pin().Ls(ctx, opt.Pin.Type.Recursive())
@@ -160,8 +166,8 @@ func (tp *provider) TestPinRecursive(t *testing.T) {
166 t.Errorf("unexpected pin list len: %d", len(list))
167 }
168
163 - if list[0].Path().String() != p2.String() {
164 - t.Error("unexpected path")
169 + if list[0].Path().String() != iface.IpldPath(nd2[0].Cid()).String() {
170 + t.Errorf("unexpected path, %s != %s", list[0].Path().String(), iface.IpldPath(nd3[0].Cid()).String())
171 }
172
173 list, err = api.Pin().Ls(ctx, opt.Pin.Type.Indirect())
core/coreapi/interface/tests/unixfs.go
+3 -3
@@ -633,7 +633,7 @@ func (tp *provider) TestGetDir(t *testing.T) {
633 t.Error(err)
634 }
635 edir := unixfs.EmptyDirNode()
636 - _, err = api.Dag().Put(ctx, bytes.NewReader(edir.RawData()), options.Dag.Codec(cid.DagProtobuf), options.Dag.InputEnc("raw"))
636 + err = api.Dag().Add(ctx, edir)
637 if err != nil {
638 t.Error(err)
639 }
@@ -667,7 +667,7 @@ func (tp *provider) TestGetNonUnixfs(t *testing.T) {
667 }
668
669 nd := new(mdag.ProtoNode)
670 - _, err = api.Dag().Put(ctx, bytes.NewReader(nd.RawData()), options.Dag.Codec(nd.CidBuilder().GetCodec()), options.Dag.InputEnc("raw"))
670 + err = api.Dag().Add(ctx, nd)
671 if err != nil {
672 t.Error(err)
673 }
@@ -801,7 +801,7 @@ func (tp *provider) TestLsNonUnixfs(t *testing.T) {
801 t.Fatal(err)
802 }
803
804 - _, err = api.Dag().Put(ctx, bytes.NewReader(nd.RawData()), options.Dag.Codec(cid.DagCBOR), options.Dag.InputEnc("raw"))
804 + err = api.Dag().Add(ctx, nd)
805 if err != nil {
806 t.Error(err)
807 }