@@ -6,7 +6,6 @@ import { expect } from 'aegir/utils/chai.js'
66import * as dagPB from '@ipld/dag-pb'
77import * as dagCBOR from '@ipld/dag-cbor'
88import * as raw from 'multiformats/codecs/raw'
9- import { base58btc } from 'multiformats/bases/base58'
109import { base32 } from 'multiformats/bases/base32'
1110import { create as httpClient } from '../src/index.js'
1211import { factory } from './utils/factory.js'
@@ -22,25 +21,25 @@ describe('.dag', function () {
2221
2322 after ( ( ) => f . clean ( ) )
2423
25- it ( 'should be able to put and get a DAG node with format dag-pb' , async ( ) => {
24+ it ( 'should be able to put and get a DAG node with dag-pb codec ' , async ( ) => {
2625 const data = uint8ArrayFromString ( 'some data' )
2726 const node = {
2827 Data : data ,
2928 Links : [ ]
3029 }
3130
32- const cid = await ipfs . dag . put ( node , { format : 'dag-pb' , hashAlg : 'sha2-256' , cidVersion : 0 } )
31+ const cid = await ipfs . dag . put ( node , { storeCodec : 'dag-pb' , hashAlg : 'sha2-256' } )
3332 expect ( cid . code ) . to . equal ( dagPB . code )
34- expect ( cid . toString ( base58btc ) ) . to . equal ( 'Qmd7xRhW5f29QuBFtqu3oSD27iVy35NRB91XFjmKFhtgMr' )
33+ expect ( cid . toV0 ( ) . toString ( ) ) . to . equal ( 'Qmd7xRhW5f29QuBFtqu3oSD27iVy35NRB91XFjmKFhtgMr' )
3534
3635 const result = await ipfs . dag . get ( cid )
3736
3837 expect ( result . value . Data ) . to . deep . equal ( data )
3938 } )
4039
41- it ( 'should be able to put and get a DAG node with format dag-cbor' , async ( ) => {
40+ it ( 'should be able to put and get a DAG node with dag-cbor codec ' , async ( ) => {
4241 const cbor = { foo : 'dag-cbor-bar' }
43- const cid = await ipfs . dag . put ( cbor , { format : 'dag-cbor' , hashAlg : 'sha2-256' } )
42+ const cid = await ipfs . dag . put ( cbor , { storeCodec : 'dag-cbor' , hashAlg : 'sha2-256' } )
4443
4544 expect ( cid . code ) . to . equal ( dagCBOR . code )
4645 expect ( cid . toString ( base32 ) ) . to . equal ( 'bafyreic6f672hnponukaacmk2mmt7vs324zkagvu4hcww6yba6kby25zce' )
@@ -50,9 +49,9 @@ describe('.dag', function () {
5049 expect ( result . value ) . to . deep . equal ( cbor )
5150 } )
5251
53- it ( 'should be able to put and get a DAG node with format raw' , async ( ) => {
52+ it ( 'should be able to put and get a DAG node with raw codec ' , async ( ) => {
5453 const node = uint8ArrayFromString ( 'some data' )
55- const cid = await ipfs . dag . put ( node , { format : 'raw' , hashAlg : 'sha2-256' } )
54+ const cid = await ipfs . dag . put ( node , { storeCodec : 'raw' , hashAlg : 'sha2-256' } )
5655
5756 expect ( cid . code ) . to . equal ( raw . code )
5857 expect ( cid . toString ( base32 ) ) . to . equal ( 'bafkreiata6mq425fzikf5m26temcvg7mizjrxrkn35swuybmpah2ajan5y' )
@@ -70,19 +69,28 @@ describe('.dag', function () {
7069 await expect ( ipfs . dag . get ( cid ) ) . to . eventually . be . rejectedWith ( / N o c o d e c f o u n d / )
7170 } )
7271
73- it ( 'should error when putting node with esoteric format ' , ( ) => {
72+ it ( 'should error when putting node with esoteric codec ' , ( ) => {
7473 const node = uint8ArrayFromString ( 'some data' )
7574
76- return expect ( ipfs . dag . put ( node , { format : 'git-raw' , hashAlg : 'sha2-256' } ) ) . to . eventually . be . rejectedWith ( / N o c o d e c f o u n d / )
75+ return expect ( ipfs . dag . put ( node , { storeCodec : 'git-raw' , hashAlg : 'sha2-256' } ) ) . to . eventually . be . rejectedWith ( / N o c o d e c f o u n d / )
7776 } )
7877
79- it ( 'should attempt to load an unsupported format' , async ( ) => {
80- let askedToLoadFormat
78+ it ( 'should pass through raw bytes with inputCodec' , async ( ) => {
79+ const node = uint8ArrayFromString ( 'blob 9\0some data' )
80+ // we don't support git-raw in the HTTP client, but inputCodec and a Uint8Array should make
81+ // the raw data pass through to go-ipfs, which does talk git-raw
82+ const cid = await ipfs . dag . put ( node , { inputCodec : 'git-raw' , storeCodec : 'git-raw' , hashAlg : 'sha1' } )
83+ expect ( cid . code ) . to . equal ( 0x78 )
84+ expect ( cid . toString ( base32 ) ) . to . equal ( 'baf4bcfd4azdl7vj4d4hnix75qfld6mabo4l4uwa' )
85+ } )
86+
87+ it ( 'should attempt to load an unsupported codec' , async ( ) => {
88+ let askedToLoadCodec
8189 const ipfs2 = httpClient ( {
8290 url : `http://${ ipfs . apiHost } :${ ipfs . apiPort } ` ,
8391 ipld : {
84- loadCodec : ( format ) => {
85- askedToLoadFormat = format === 'git-raw '
92+ loadCodec : ( codec ) => {
93+ askedToLoadCodec = codec === 'boop '
8694 return {
8795 encode : ( buf ) => buf
8896 }
@@ -93,9 +101,9 @@ describe('.dag', function () {
93101 const node = uint8ArrayFromString ( 'some data' )
94102
95103 // error is from go-ipfs, this means the client serialized it ok
96- await expect ( ipfs2 . dag . put ( node , { format : 'git-raw ' , hashAlg : 'sha2-256' } ) ) . to . eventually . be . rejectedWith ( / n o p a r s e r f o r f o r m a t " g i t - r a w " / )
104+ await expect ( ipfs2 . dag . put ( node , { storeCodec : 'boop ' , hashAlg : 'sha2-256' } ) ) . to . eventually . be . rejectedWith ( / u n k n o w n m u l t i c o d e c : " b o o p " / )
97105
98- expect ( askedToLoadFormat ) . to . be . true ( )
106+ expect ( askedToLoadCodec ) . to . be . true ( )
99107 } )
100108
101109 it ( 'should allow formats to be specified without overwriting others' , async ( ) => {
@@ -115,7 +123,7 @@ describe('.dag', function () {
115123 hello : 'world'
116124 }
117125 const cid1 = await ipfs2 . dag . put ( dagCborNode , {
118- format : 'dag-cbor' ,
126+ storeCodec : 'dag-cbor' ,
119127 hashAlg : 'sha2-256'
120128 } )
121129
@@ -124,7 +132,7 @@ describe('.dag', function () {
124132 Links : [ ]
125133 }
126134 const cid2 = await ipfs2 . dag . put ( dagPbNode , {
127- format : 'dag-pb' ,
135+ storeCodec : 'dag-pb' ,
128136 hashAlg : 'sha2-256'
129137 } )
130138
0 commit comments