3
3
4
4
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
5
5
import { expect } from 'aegir/utils/chai.js'
6
+ import { CID } from 'multiformats/cid'
6
7
import * as dagPB from '@ipld/dag-pb'
7
8
import * as dagCBOR from '@ipld/dag-cbor'
8
9
import * as raw from 'multiformats/codecs/raw'
@@ -14,33 +15,33 @@ const f = factory()
14
15
15
16
let ipfs
16
17
17
- describe ( '.dag' , function ( ) {
18
+ describe . only ( '.dag' , function ( ) {
18
19
this . timeout ( 20 * 1000 )
19
20
before ( async function ( ) {
20
21
ipfs = ( await f . spawn ( ) ) . api
21
22
} )
22
23
23
24
after ( ( ) => f . clean ( ) )
24
25
25
- it ( 'should be able to put and get a DAG node with format dag-pb' , async ( ) => {
26
+ it ( 'should be able to put and get a DAG node with dag-pb codec ' , async ( ) => {
26
27
const data = uint8ArrayFromString ( 'some data' )
27
28
const node = {
28
29
Data : data ,
29
30
Links : [ ]
30
31
}
31
32
32
- const cid = await ipfs . dag . put ( node , { format : 'dag-pb' , hashAlg : 'sha2-256' , cidVersion : 0 } )
33
+ const cid = await ipfs . dag . put ( node , { storeCodec : 'dag-pb' , hashAlg : 'sha2-256' } )
33
34
expect ( cid . code ) . to . equal ( dagPB . code )
34
- expect ( cid . toString ( base58btc ) ) . to . equal ( 'Qmd7xRhW5f29QuBFtqu3oSD27iVy35NRB91XFjmKFhtgMr' )
35
+ expect ( cid . toV0 ( ) . toString ( ) ) . to . equal ( 'Qmd7xRhW5f29QuBFtqu3oSD27iVy35NRB91XFjmKFhtgMr' )
35
36
36
37
const result = await ipfs . dag . get ( cid )
37
38
38
39
expect ( result . value . Data ) . to . deep . equal ( data )
39
40
} )
40
41
41
- it ( 'should be able to put and get a DAG node with format dag-cbor' , async ( ) => {
42
+ it ( 'should be able to put and get a DAG node with dag-cbor codec ' , async ( ) => {
42
43
const cbor = { foo : 'dag-cbor-bar' }
43
- const cid = await ipfs . dag . put ( cbor , { format : 'dag-cbor' , hashAlg : 'sha2-256' } )
44
+ const cid = await ipfs . dag . put ( cbor , { storeCodec : 'dag-cbor' , hashAlg : 'sha2-256' } )
44
45
45
46
expect ( cid . code ) . to . equal ( dagCBOR . code )
46
47
expect ( cid . toString ( base32 ) ) . to . equal ( 'bafyreic6f672hnponukaacmk2mmt7vs324zkagvu4hcww6yba6kby25zce' )
@@ -50,9 +51,9 @@ describe('.dag', function () {
50
51
expect ( result . value ) . to . deep . equal ( cbor )
51
52
} )
52
53
53
- it ( 'should be able to put and get a DAG node with format raw' , async ( ) => {
54
+ it ( 'should be able to put and get a DAG node with raw codec ' , async ( ) => {
54
55
const node = uint8ArrayFromString ( 'some data' )
55
- const cid = await ipfs . dag . put ( node , { format : 'raw' , hashAlg : 'sha2-256' } )
56
+ const cid = await ipfs . dag . put ( node , { storeCodec : 'raw' , hashAlg : 'sha2-256' } )
56
57
57
58
expect ( cid . code ) . to . equal ( raw . code )
58
59
expect ( cid . toString ( base32 ) ) . to . equal ( 'bafkreiata6mq425fzikf5m26temcvg7mizjrxrkn35swuybmpah2ajan5y' )
@@ -70,19 +71,28 @@ describe('.dag', function () {
70
71
await expect ( ipfs . dag . get ( cid ) ) . to . eventually . be . rejectedWith ( / N o c o d e c f o u n d / )
71
72
} )
72
73
73
- it ( 'should error when putting node with esoteric format ' , ( ) => {
74
+ it ( 'should error when putting node with esoteric codec ' , ( ) => {
74
75
const node = uint8ArrayFromString ( 'some data' )
75
76
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 / )
77
+ 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
78
} )
78
79
79
- it ( 'should attempt to load an unsupported format' , async ( ) => {
80
- let askedToLoadFormat
80
+ it ( 'should pass through raw bytes with inputCodec' , async ( ) => {
81
+ const node = uint8ArrayFromString ( 'blob 9\0some data' )
82
+ // we don't support git-raw in the HTTP client, but inputCodec and a Uint8Array should make
83
+ // the raw data pass through to go-ipfs, which does talk git-raw
84
+ const cid = await ipfs . dag . put ( node , { inputCodec : 'git-raw' , storeCodec : 'git-raw' , hashAlg : 'sha1' } )
85
+ expect ( cid . code ) . to . equal ( 0x78 )
86
+ expect ( cid . toString ( base32 ) ) . to . equal ( 'baf4bcfd4azdl7vj4d4hnix75qfld6mabo4l4uwa' )
87
+ } )
88
+
89
+ it ( 'should attempt to load an unsupported codec' , async ( ) => {
90
+ let askedToLoadCodec
81
91
const ipfs2 = httpClient ( {
82
92
url : `http://${ ipfs . apiHost } :${ ipfs . apiPort } ` ,
83
93
ipld : {
84
- loadCodec : ( format ) => {
85
- askedToLoadFormat = format === 'git-raw '
94
+ loadCodec : ( codec ) => {
95
+ askedToLoadCodec = codec === 'boop '
86
96
return {
87
97
encode : ( buf ) => buf
88
98
}
@@ -93,9 +103,9 @@ describe('.dag', function () {
93
103
const node = uint8ArrayFromString ( 'some data' )
94
104
95
105
// 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 " / )
106
+ 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
107
98
- expect ( askedToLoadFormat ) . to . be . true ( )
108
+ expect ( askedToLoadCodec ) . to . be . true ( )
99
109
} )
100
110
101
111
it ( 'should allow formats to be specified without overwriting others' , async ( ) => {
@@ -115,7 +125,7 @@ describe('.dag', function () {
115
125
hello : 'world'
116
126
}
117
127
const cid1 = await ipfs2 . dag . put ( dagCborNode , {
118
- format : 'dag-cbor' ,
128
+ storeCodec : 'dag-cbor' ,
119
129
hashAlg : 'sha2-256'
120
130
} )
121
131
@@ -124,7 +134,7 @@ describe('.dag', function () {
124
134
Links : [ ]
125
135
}
126
136
const cid2 = await ipfs2 . dag . put ( dagPbNode , {
127
- format : 'dag-pb' ,
137
+ storeCodec : 'dag-pb' ,
128
138
hashAlg : 'sha2-256'
129
139
} )
130
140
0 commit comments