@@ -6,7 +6,6 @@ import { expect } from 'aegir/utils/chai.js'
6
6
import * as dagPB from '@ipld/dag-pb'
7
7
import * as dagCBOR from '@ipld/dag-cbor'
8
8
import * as raw from 'multiformats/codecs/raw'
9
- import { base58btc } from 'multiformats/bases/base58'
10
9
import { base32 } from 'multiformats/bases/base32'
11
10
import { create as httpClient } from '../src/index.js'
12
11
import { factory } from './utils/factory.js'
@@ -22,25 +21,25 @@ describe('.dag', function () {
22
21
23
22
after ( ( ) => f . clean ( ) )
24
23
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 ( ) => {
26
25
const data = uint8ArrayFromString ( 'some data' )
27
26
const node = {
28
27
Data : data ,
29
28
Links : [ ]
30
29
}
31
30
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' } )
33
32
expect ( cid . code ) . to . equal ( dagPB . code )
34
- expect ( cid . toString ( base58btc ) ) . to . equal ( 'Qmd7xRhW5f29QuBFtqu3oSD27iVy35NRB91XFjmKFhtgMr' )
33
+ expect ( cid . toV0 ( ) . toString ( ) ) . to . equal ( 'Qmd7xRhW5f29QuBFtqu3oSD27iVy35NRB91XFjmKFhtgMr' )
35
34
36
35
const result = await ipfs . dag . get ( cid )
37
36
38
37
expect ( result . value . Data ) . to . deep . equal ( data )
39
38
} )
40
39
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 ( ) => {
42
41
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' } )
44
43
45
44
expect ( cid . code ) . to . equal ( dagCBOR . code )
46
45
expect ( cid . toString ( base32 ) ) . to . equal ( 'bafyreic6f672hnponukaacmk2mmt7vs324zkagvu4hcww6yba6kby25zce' )
@@ -50,9 +49,9 @@ describe('.dag', function () {
50
49
expect ( result . value ) . to . deep . equal ( cbor )
51
50
} )
52
51
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 ( ) => {
54
53
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' } )
56
55
57
56
expect ( cid . code ) . to . equal ( raw . code )
58
57
expect ( cid . toString ( base32 ) ) . to . equal ( 'bafkreiata6mq425fzikf5m26temcvg7mizjrxrkn35swuybmpah2ajan5y' )
@@ -70,19 +69,28 @@ describe('.dag', function () {
70
69
await expect ( ipfs . dag . get ( cid ) ) . to . eventually . be . rejectedWith ( / N o c o d e c f o u n d / )
71
70
} )
72
71
73
- it ( 'should error when putting node with esoteric format ' , ( ) => {
72
+ it ( 'should error when putting node with esoteric codec ' , ( ) => {
74
73
const node = uint8ArrayFromString ( 'some data' )
75
74
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 / )
77
76
} )
78
77
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
81
89
const ipfs2 = httpClient ( {
82
90
url : `http://${ ipfs . apiHost } :${ ipfs . apiPort } ` ,
83
91
ipld : {
84
- loadCodec : ( format ) => {
85
- askedToLoadFormat = format === 'git-raw '
92
+ loadCodec : ( codec ) => {
93
+ askedToLoadCodec = codec === 'boop '
86
94
return {
87
95
encode : ( buf ) => buf
88
96
}
@@ -93,9 +101,9 @@ describe('.dag', function () {
93
101
const node = uint8ArrayFromString ( 'some data' )
94
102
95
103
// 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 " / )
97
105
98
- expect ( askedToLoadFormat ) . to . be . true ( )
106
+ expect ( askedToLoadCodec ) . to . be . true ( )
99
107
} )
100
108
101
109
it ( 'should allow formats to be specified without overwriting others' , async ( ) => {
@@ -115,7 +123,7 @@ describe('.dag', function () {
115
123
hello : 'world'
116
124
}
117
125
const cid1 = await ipfs2 . dag . put ( dagCborNode , {
118
- format : 'dag-cbor' ,
126
+ storeCodec : 'dag-cbor' ,
119
127
hashAlg : 'sha2-256'
120
128
} )
121
129
@@ -124,7 +132,7 @@ describe('.dag', function () {
124
132
Links : [ ]
125
133
}
126
134
const cid2 = await ipfs2 . dag . put ( dagPbNode , {
127
- format : 'dag-pb' ,
135
+ storeCodec : 'dag-pb' ,
128
136
hashAlg : 'sha2-256'
129
137
} )
130
138
0 commit comments