1
1
global . Buffer = Buffer
2
2
3
3
const test = require ( 'tape' )
4
- const IPFS = require ( 'ipfs' )
4
+ const IPFS = require ( 'ipfs-core ' )
5
5
const makeIPFSFetch = require ( './' )
6
6
7
7
const TEST_DATA = 'Hello World!'
@@ -20,7 +20,7 @@ test('Load a file via fetch', async (t) => {
20
20
21
21
t . pass ( 'Able to make create fetch instance' )
22
22
23
- const { cid } = await ipfs . add ( TEST_DATA )
23
+ const { cid } = await ipfs . add ( TEST_DATA , { cidVersion : 1 } )
24
24
25
25
const response = await fetch ( `ipfs://${ cid } ` )
26
26
@@ -55,7 +55,7 @@ test('Load a range from a file', async (t) => {
55
55
56
56
t . pass ( 'Able to make create fetch instance' )
57
57
58
- const { cid } = await ipfs . add ( TEST_DATA )
58
+ const { cid } = await ipfs . add ( TEST_DATA , { cidVersion : 1 } )
59
59
60
60
const response = await fetch ( `ipfs://${ cid } ` , { headers : { Range : 'bytes=0-4' } } )
61
61
@@ -87,7 +87,7 @@ test('Get expected headers from HEAD', async (t) => {
87
87
88
88
t . pass ( 'Able to make create fetch instance' )
89
89
90
- const { cid } = await ipfs . add ( TEST_DATA )
90
+ const { cid } = await ipfs . add ( TEST_DATA , { cidVersion : 1 } )
91
91
92
92
const response = await fetch ( `ipfs://${ cid } ` , { method : 'head' } )
93
93
@@ -171,7 +171,7 @@ test('Resolve index.html from a directory', async (t) => {
171
171
const results = await collect ( ipfs . addAll ( [
172
172
{ path : '/index.html' , content : TEST_DATA } ,
173
173
{ path : 'example/index.html' , content : TEST_DATA }
174
- ] , { wrapWithDirectory : true } ) )
174
+ ] , { wrapWithDirectory : true , cidVersion : 1 } ) )
175
175
176
176
// The last element should be the directory itself
177
177
const { cid } = results [ results . length - 1 ]
@@ -236,16 +236,23 @@ test('POST a file into IPFS', async (t) => {
236
236
t . ok ( response , 'Got a response object' )
237
237
t . equal ( response . status , 200 , 'Got OK in response' )
238
238
239
- const cid = await response . text ( )
240
-
241
- t . match ( cid , / i p f s : \/ \/ \w + \/ e x a m p l e .t x t / , 'returned IPFS url with CID' )
239
+ const ipfsUri = await response . text ( )
240
+ t . match ( ipfsUri , / i p f s : \/ \/ \w + \/ e x a m p l e .t x t / , 'returned IPFS url with CID' )
242
241
243
- const fileResponse = await fetch ( cid )
242
+ const fileResponse = await fetch ( ipfsUri )
244
243
t . equal ( fileResponse . status , 200 , 'Got OK in response' )
245
244
246
245
const text = await fileResponse . text ( )
247
-
248
246
t . equal ( text , TEST_DATA , 'Able to load POSTed file' )
247
+
248
+ const { cid } = await ipfs . add ( {
249
+ path : 'example.txt' ,
250
+ content : TEST_DATA
251
+ } , {
252
+ cidVersion : 1 ,
253
+ wrapWithDirectory : true
254
+ } )
255
+ t . equal ( ipfsUri . match ( / i p f s : \/ \/ ( [ ^ / ] + ) / ) [ 1 ] , cid . toString ( 'base32' ) , 'Matches cid from ipfs.add' )
249
256
} catch ( e ) {
250
257
t . fail ( e . message )
251
258
} finally {
@@ -277,7 +284,8 @@ test('Publish and resolve IPNS', async (t) => {
277
284
278
285
const ipnsURI = await publishResponse . text ( )
279
286
280
- t . ok ( ipnsURI , 'Got resulting IPNS url' )
287
+ // base36 prefix is k https://github.com/multiformats/js-multibase/blob/ddd99e6d0d089d5d1209094f2e7a2a07d87729fb/src/constants.js#L43
288
+ t . ok ( ipnsURI . startsWith ( 'ipns://k' ) , 'Got base36 encoded IPNS url' )
281
289
282
290
const resolvedResponse = await fetch ( ipnsURI , {
283
291
headers : {
0 commit comments