55
66const chai = require ( 'chai' )
77const dirtyChai = require ( 'dirty-chai' )
8+ const chaiAsPromised = require ( 'chai-as-promised' )
89const expect = chai . expect
910chai . use ( dirtyChai )
10- const series = require ( 'async/series' )
11+ chai . use ( chaiAsPromised )
1112const { DAGNode } = require ( 'ipld-dag-pb' )
1213const CID = require ( 'cids' )
1314const ipfsClient = require ( '../src' )
@@ -18,67 +19,56 @@ let ipfs
1819
1920describe ( '.dag' , function ( ) {
2021 this . timeout ( 20 * 1000 )
21- before ( function ( done ) {
22- series ( [
23- ( cb ) => f . spawn ( { initOptions : { bits : 1024 , profile : 'test' } } , ( err , _ipfsd ) => {
24- expect ( err ) . to . not . exist ( )
25- ipfsd = _ipfsd
26- ipfs = ipfsClient ( _ipfsd . apiAddr )
27- cb ( )
28- } )
29- ] , done )
22+ before ( async function ( ) {
23+ ipfsd = await f . spawn ( {
24+ initOptions : {
25+ bits : 1024 ,
26+ profile : 'test'
27+ }
28+ } )
29+ ipfs = ipfsClient ( ipfsd . apiAddr )
3030 } )
3131
32- after ( ( done ) => {
33- if ( ! ipfsd ) return done ( )
34- ipfsd . stop ( done )
32+ after ( async ( ) => {
33+ if ( ipfsd ) {
34+ await ipfsd . stop ( )
35+ }
3536 } )
3637
37- it ( 'should be able to put and get a DAG node with format dag-pb' , ( done ) => {
38+ it ( 'should be able to put and get a DAG node with format dag-pb' , async ( ) => {
3839 const data = Buffer . from ( 'some data' )
3940 const node = DAGNode . create ( data )
4041
41- ipfs . dag . put ( node , { format : 'dag-pb' , hashAlg : 'sha2-256' } , ( err , cid ) => {
42- expect ( err ) . to . not . exist ( )
43- cid = cid . toV0 ( )
44- expect ( cid . codec ) . to . equal ( 'dag-pb' )
45- cid = cid . toBaseEncodedString ( 'base58btc' )
46- // expect(cid).to.equal('bafybeig3t3eugdchignsgkou3ly2mmy4ic4gtfor7inftnqn3yq4ws3a5u')
47- expect ( cid ) . to . equal ( 'Qmd7xRhW5f29QuBFtqu3oSD27iVy35NRB91XFjmKFhtgMr' )
48- ipfs . dag . get ( cid , ( err , result ) => {
49- expect ( err ) . to . not . exist ( )
50- expect ( result . value . Data ) . to . deep . equal ( data )
51- done ( )
52- } )
53- } )
42+ let cid = await ipfs . dag . put ( node , { format : 'dag-pb' , hashAlg : 'sha2-256' } )
43+ cid = cid . toV0 ( )
44+ expect ( cid . codec ) . to . equal ( 'dag-pb' )
45+ cid = cid . toBaseEncodedString ( 'base58btc' )
46+ // expect(cid).to.equal('bafybeig3t3eugdchignsgkou3ly2mmy4ic4gtfor7inftnqn3yq4ws3a5u')
47+ expect ( cid ) . to . equal ( 'Qmd7xRhW5f29QuBFtqu3oSD27iVy35NRB91XFjmKFhtgMr' )
48+
49+ const result = await ipfs . dag . get ( cid )
50+
51+ expect ( result . value . Data ) . to . deep . equal ( data )
5452 } )
5553
56- it ( 'should be able to put and get a DAG node with format dag-cbor' , ( done ) => {
54+ it ( 'should be able to put and get a DAG node with format dag-cbor' , async ( ) => {
5755 const cbor = { foo : 'dag-cbor-bar' }
58- ipfs . dag . put ( cbor , { format : 'dag-cbor' , hashAlg : 'sha2-256' } , ( err , cid ) => {
59- expect ( err ) . to . not . exist ( )
60- expect ( cid . codec ) . to . equal ( 'dag-cbor' )
61- cid = cid . toBaseEncodedString ( 'base32' )
62- expect ( cid ) . to . equal ( 'bafyreic6f672hnponukaacmk2mmt7vs324zkagvu4hcww6yba6kby25zce' )
63- ipfs . dag . get ( cid , ( err , result ) => {
64- expect ( err ) . to . not . exist ( )
65- expect ( result . value ) . to . deep . equal ( cbor )
66- done ( )
67- } )
68- } )
56+ let cid = await ipfs . dag . put ( cbor , { format : 'dag-cbor' , hashAlg : 'sha2-256' } )
57+
58+ expect ( cid . codec ) . to . equal ( 'dag-cbor' )
59+ cid = cid . toBaseEncodedString ( 'base32' )
60+ expect ( cid ) . to . equal ( 'bafyreic6f672hnponukaacmk2mmt7vs324zkagvu4hcww6yba6kby25zce' )
61+
62+ const result = await ipfs . dag . get ( cid )
63+
64+ expect ( result . value ) . to . deep . equal ( cbor )
6965 } )
7066
71- it ( 'should callback with error when missing DAG resolver for multicodec from requested CID' , ( done ) => {
72- ipfs . block . put ( Buffer . from ( [ 0 , 1 , 2 , 3 ] ) , {
67+ it ( 'should callback with error when missing DAG resolver for multicodec from requested CID' , async ( ) => {
68+ const block = await ipfs . block . put ( Buffer . from ( [ 0 , 1 , 2 , 3 ] ) , {
7369 cid : new CID ( 'z8mWaJ1dZ9fH5EetPuRsj8jj26pXsgpsr' )
74- } , ( err , block ) => {
75- expect ( err ) . to . not . exist ( )
76-
77- ipfs . dag . get ( block . cid , ( err , result ) => {
78- expect ( result ) . to . not . exist ( )
79- expect ( err . message ) . to . equal ( 'Missing IPLD format "git-raw"' )
80- done ( )
81- } )
8270 } )
71+
72+ await expect ( ipfs . dag . get ( block . cid ) ) . to . be . rejectedWith ( 'Missing IPLD format "git-raw"' )
8373 } )
8474} )
0 commit comments