4
4
'use strict'
5
5
6
6
const expect = require ( 'chai' ) . expect
7
- const DAGNode = require ( 'ipfs-merkle-dag' ) . DAGNode
7
+ const dagPB = require ( 'ipld-dag-pb' )
8
+ const DAGNode = dagPB . DAGNode
8
9
const bs58 = require ( 'bs58' )
9
10
10
11
module . exports = ( common ) => {
@@ -89,7 +90,7 @@ module.exports = (common) => {
89
90
90
91
it ( 'of protobuf encoded buffer' , ( done ) => {
91
92
const dNode = new DAGNode ( new Buffer ( 'Some data' ) )
92
- const buf = dNode . marshal ( )
93
+ const buf = dagPB . util . serialize ( dNode )
93
94
94
95
ipfs . object . put ( buf , { enc : 'protobuf' } , ( err , node ) => {
95
96
expect ( err ) . to . not . exist
@@ -185,8 +186,8 @@ module.exports = (common) => {
185
186
186
187
ipfs . object . get ( node1 . multihash ( ) , ( err , node2 ) => {
187
188
expect ( err ) . to . not . exist
188
- // because js-ipfs-api can't infer if the returned Data is Buffer
189
- // or String
189
+ // because js-ipfs-api can't infer if the
190
+ // returned Data is Buffer or String
190
191
if ( typeof node2 . data === 'string' ) {
191
192
node2 . data = new Buffer ( node2 . data )
192
193
}
@@ -488,12 +489,13 @@ module.exports = (common) => {
488
489
let testNode
489
490
let testNodeWithLink
490
491
let testLink
491
- before ( ( done ) => {
492
- const obj = {
493
- Data : new Buffer ( 'patch test object' ) ,
494
- Links : [ ]
495
- }
496
492
493
+ const obj = {
494
+ Data : new Buffer ( 'patch test object' ) ,
495
+ Links : [ ]
496
+ }
497
+
498
+ before ( ( done ) => {
497
499
ipfs . object . put ( obj , ( err , node ) => {
498
500
expect ( err ) . to . not . exist
499
501
testNode = node
@@ -502,12 +504,14 @@ module.exports = (common) => {
502
504
} )
503
505
504
506
it ( '.addLink' , ( done ) => {
505
- const dNode1 = testNode . copy ( )
507
+ const dNode1 = new DAGNode ( obj . Data , obj . Links )
506
508
const dNode2 = new DAGNode ( new Buffer ( 'some other node' ) )
507
- // note: we need to put the linked obj, otherwise IPFS won't timeout
508
- // cause it needs the node to get its size
509
+
510
+ // note: we need to put the linked obj, otherwise IPFS won't
511
+ // timeout. Reason: it needs the node to get its size
509
512
ipfs . object . put ( dNode2 , ( err ) => {
510
513
expect ( err ) . to . not . exist
514
+
511
515
dNode1 . addNodeLink ( 'link-to-node' , dNode2 )
512
516
513
517
ipfs . object . patch . addLink ( testNode . multihash ( ) , dNode1 . links [ 0 ] , ( err , node3 ) => {
@@ -667,7 +671,7 @@ module.exports = (common) => {
667
671
} )
668
672
669
673
it ( '.addLink' , ( ) => {
670
- const dNode1 = testNode . copy ( )
674
+ const dNode1 = dagPB . util . deserialize ( dagPB . util . serialize ( testNode ) )
671
675
const dNode2 = new DAGNode ( new Buffer ( 'some other node' ) )
672
676
// note: we need to put the linked obj, otherwise IPFS won't timeout
673
677
// cause it needs the node to get its size
0 commit comments