@@ -266,5 +266,61 @@ module.exports = (createCommon, options) => {
266
266
} )
267
267
} )
268
268
} )
269
+
270
+ it ( 'should be able to get part of a dag-cbor node' , ( done ) => {
271
+ const cbor = {
272
+ foo : 'dag-cbor-bar'
273
+ }
274
+ ipfs . dag . put ( cbor , { format : 'dag-cbor' , hashAlg : 'sha2-256' } , ( err , cid ) => {
275
+ expect ( err ) . to . not . exist ( )
276
+ expect ( cid . codec ) . to . equal ( 'dag-cbor' )
277
+ cid = cid . toBaseEncodedString ( 'base32' )
278
+ expect ( cid ) . to . equal ( 'bafyreic6f672hnponukaacmk2mmt7vs324zkagvu4hcww6yba6kby25zce' )
279
+ ipfs . dag . get ( cid , 'foo' , ( err , result ) => {
280
+ expect ( err ) . to . not . exist ( )
281
+ expect ( result . value ) . to . equal ( 'dag-cbor-bar' )
282
+ done ( )
283
+ } )
284
+ } )
285
+ } )
286
+
287
+ it ( 'should be able to traverse from one dag-cbor node to another' , ( done ) => {
288
+ const cbor1 = {
289
+ foo : 'dag-cbor-bar'
290
+ }
291
+
292
+ ipfs . dag . put ( cbor1 , { format : 'dag-cbor' , hashAlg : 'sha2-256' } , ( err , cid1 ) => {
293
+ expect ( err ) . to . not . exist ( )
294
+
295
+ const cbor2 = { other : cid1 }
296
+
297
+ ipfs . dag . put ( cbor2 , { format : 'dag-cbor' , hashAlg : 'sha2-256' } , ( err , cid2 ) => {
298
+ expect ( err ) . to . not . exist ( )
299
+
300
+ ipfs . dag . get ( cid2 , 'other/foo' , ( err , result ) => {
301
+ expect ( err ) . to . not . exist ( )
302
+ expect ( result . value ) . to . equal ( 'dag-cbor-bar' )
303
+ done ( )
304
+ } )
305
+ } )
306
+ } )
307
+ } )
308
+
309
+ it ( 'should be able to get a DAG node with format raw' , ( done ) => {
310
+ const buf = Buffer . from ( [ 0 , 1 , 2 , 3 ] )
311
+
312
+ ipfs . dag . put ( buf , {
313
+ format : 'raw' ,
314
+ hashAlg : 'sha2-256'
315
+ } , ( err , cid ) => {
316
+ expect ( err ) . to . not . exist ( )
317
+
318
+ ipfs . dag . get ( cid , ( err , result ) => {
319
+ expect ( err ) . to . not . exist ( )
320
+ expect ( result . value ) . to . deep . equal ( buf )
321
+ done ( )
322
+ } )
323
+ } )
324
+ } )
269
325
} )
270
326
}
0 commit comments