44'use strict'
55
66const expect = require ( 'chai' ) . expect
7+ const Block = require ( 'ipfs-block' )
8+ const multihash = require ( 'multihashes' )
79
810module . exports = ( common ) => {
9- describe ( '.block' , ( ) => {
11+ describe . only ( '.block' , ( ) => {
1012 let ipfs
1113
1214 before ( function ( done ) {
@@ -30,13 +32,26 @@ module.exports = (common) => {
3032 } )
3133
3234 describe ( 'callback API' , ( ) => {
33- it ( '.put' , ( done ) => {
35+ it ( '.put a buffer ' , ( done ) => {
3436 const expectedHash = 'QmPv52ekjS75L4JmHpXVeuJ5uX2ecSfSZo88NSyxwA3rAQ'
3537 const blob = Buffer ( 'blorb' )
3638
37- ipfs . block . put ( blob , ( err , res ) => {
39+ ipfs . block . put ( blob , ( err , block ) => {
3840 expect ( err ) . to . not . exist
39- expect ( res ) . to . have . a . property ( 'Key' , expectedHash )
41+ expect ( block . key ) . to . eql ( multihash . fromB58String ( expectedHash ) )
42+ expect ( block ) . to . have . a . property ( 'data' , blob )
43+ done ( )
44+ } )
45+ } )
46+
47+ it ( '.put a block' , ( done ) => {
48+ const expectedHash = 'QmPv52ekjS75L4JmHpXVeuJ5uX2ecSfSZo88NSyxwA3rAQ'
49+ const blob = new Block ( new Buffer ( 'blorb' ) )
50+
51+ ipfs . block . put ( blob , ( err , block ) => {
52+ expect ( err ) . to . not . exist
53+ expect ( block . key ) . to . eql ( multihash . fromB58String ( expectedHash ) )
54+ expect ( block . data ) . to . eql ( new Buffer ( 'blorb' ) )
4055 done ( )
4156 } )
4257 } )
@@ -52,30 +67,26 @@ module.exports = (common) => {
5267 it ( 'block.get' , ( done ) => {
5368 const hash = 'QmPv52ekjS75L4JmHpXVeuJ5uX2ecSfSZo88NSyxwA3rAQ'
5469
55- ipfs . block . get ( hash , ( err , res ) => {
70+ ipfs . block . get ( hash , ( err , block ) => {
5671 expect ( err ) . to . not . exist
57-
58- // TODO review this
59- let buf = ''
60- res
61- . on ( 'data' , function ( data ) { buf += data } )
62- . on ( 'end' , function ( ) {
63- expect ( buf ) . to . be . equal ( 'blorb' )
64- done ( )
65- } )
72+ expect ( block . key ) . to . eql ( multihash . fromB58String ( hash ) )
73+ expect ( block . data ) . to . eql ( new Buffer ( 'blorb' ) )
74+ done ( )
6675 } )
6776 } )
6877
6978 it ( 'block.stat' , ( done ) => {
7079 const hash = 'QmPv52ekjS75L4JmHpXVeuJ5uX2ecSfSZo88NSyxwA3rAQ'
7180
72- ipfs . block . stat ( hash , ( err , res ) => {
81+ ipfs . block . stat ( hash , ( err , stats ) => {
7382 expect ( err ) . to . not . exist
74- expect ( res ) . to . have . property ( 'Key ' )
75- expect ( res ) . to . have . property ( 'Size ' )
83+ expect ( stats ) . to . have . property ( 'key ' )
84+ expect ( stats ) . to . have . property ( 'size ' )
7685 done ( )
7786 } )
7887 } )
88+
89+ it . skip ( 'block.rm' , ( done ) => { } ) // TODO once block.rm is shipped in go-ipfs
7990 } )
8091
8192 describe ( 'promise API' , ( ) => {
0 commit comments