This repository was archived by the owner on Feb 12, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +82
-1
lines changed Expand file tree Collapse file tree 3 files changed +82
-1
lines changed Original file line number Diff line number Diff line change 55
66const { Buffer } = require ( 'buffer' )
77const { expect } = require ( 'interface-ipfs-core/src/utils/mocha' )
8- const { DAGNode } = require ( 'ipld-dag-pb' )
8+ const ipldDagPb = require ( 'ipld-dag-pb' )
9+ const { DAGNode } = ipldDagPb
910const CID = require ( 'cids' )
1011const f = require ( './utils/factory' ) ( )
1112const ipfsHttpClient = require ( '../src' )
@@ -98,4 +99,32 @@ describe('.dag', function () {
9899
99100 expect ( askedToLoadFormat ) . to . be . true ( )
100101 } )
102+
103+ it ( 'should allow formats to be specified without overwriting others' , async ( ) => {
104+ const ipfs2 = ipfsHttpClient ( {
105+ url : `http://${ ipfs . apiHost } :${ ipfs . apiPort } ` ,
106+ ipld : {
107+ formats : [
108+ ipldDagPb
109+ ]
110+ }
111+ } )
112+
113+ const dagCborNode = {
114+ hello : 'world'
115+ }
116+ const cid1 = await ipfs2 . dag . put ( dagCborNode , {
117+ format : 'dag-cbor' ,
118+ hashAlg : 'sha2-256'
119+ } )
120+
121+ const dagPbNode = new DAGNode ( Buffer . alloc ( 0 ) , [ ] , 0 )
122+ const cid2 = await ipfs2 . dag . put ( dagPbNode , {
123+ format : 'dag-pb' ,
124+ hashAlg : 'sha2-256'
125+ } )
126+
127+ await expect ( ipfs2 . dag . get ( cid1 ) ) . to . eventually . have . property ( 'value' ) . that . deep . equals ( dagCborNode )
128+ await expect ( ipfs2 . dag . get ( cid2 ) ) . to . eventually . have . property ( 'value' ) . that . deep . equals ( dagPbNode )
129+ } )
101130} )
Original file line number Diff line number Diff line change @@ -4,6 +4,15 @@ const multicodec = require('multicodec')
44
55// All known (non-default) IPLD formats
66const IpldFormats = {
7+ get [ multicodec . DAG_PB ] ( ) {
8+ return require ( 'ipld-dag-pb' )
9+ } ,
10+ get [ multicodec . DAG_CBOR ] ( ) {
11+ return require ( 'ipld-dag-cbor' )
12+ } ,
13+ get [ multicodec . RAW ] ( ) {
14+ return require ( 'ipld-raw' )
15+ } ,
716 get [ multicodec . BITCOIN_BLOCK ] ( ) {
817 return require ( 'ipld-bitcoin' )
918 } ,
Original file line number Diff line number Diff line change 1+ /* eslint-env mocha */
2+ 'use strict'
3+
4+ const { expect } = require ( 'interface-ipfs-core/src/utils/mocha' )
5+ const factory = require ( '../utils/factory' )
6+ const ipldDagPb = require ( 'ipld-dag-pb' )
7+
8+ describe ( 'ipld' , function ( ) {
9+ this . timeout ( 10 * 1000 )
10+ const df = factory ( )
11+
12+ after ( ( ) => df . clean ( ) )
13+
14+ it ( 'should allow formats to be specified without overwriting others' , async ( ) => {
15+ const ipfs = ( await df . spawn ( {
16+ type : 'proc' ,
17+ ipfsOptions : {
18+ ipld : {
19+ formats : [
20+ require ( 'ipld-dag-pb' )
21+ ]
22+ }
23+ }
24+ } ) ) . api
25+
26+ const dagCborNode = {
27+ hello : 'world'
28+ }
29+ const cid1 = await ipfs . dag . put ( dagCborNode , {
30+ format : 'dag-cbor' ,
31+ hashAlg : 'sha2-256'
32+ } )
33+
34+ const dagPbNode = new ipldDagPb . DAGNode ( Buffer . alloc ( 0 ) , [ ] , 0 )
35+ const cid2 = await ipfs . dag . put ( dagPbNode , {
36+ format : 'dag-pb' ,
37+ hashAlg : 'sha2-256'
38+ } )
39+
40+ await expect ( ipfs . dag . get ( cid1 ) ) . to . eventually . have . property ( 'value' ) . that . deep . equals ( dagCborNode )
41+ await expect ( ipfs . dag . get ( cid2 ) ) . to . eventually . have . property ( 'value' ) . that . deep . equals ( dagPbNode )
42+ } )
43+ } )
You can’t perform that action at this time.
0 commit comments