4
4
'use strict'
5
5
6
6
const expect = require ( 'chai' ) . expect
7
+ const Block = require ( 'ipfs-block' )
8
+ const multihash = require ( 'multihashes' )
7
9
8
10
module . exports = ( common ) => {
9
- describe ( '.block' , ( ) => {
11
+ describe . only ( '.block' , ( ) => {
10
12
let ipfs
11
13
12
14
before ( function ( done ) {
@@ -30,13 +32,26 @@ module.exports = (common) => {
30
32
} )
31
33
32
34
describe ( 'callback API' , ( ) => {
33
- it ( '.put' , ( done ) => {
35
+ it ( '.put a buffer ' , ( done ) => {
34
36
const expectedHash = 'QmPv52ekjS75L4JmHpXVeuJ5uX2ecSfSZo88NSyxwA3rAQ'
35
37
const blob = Buffer ( 'blorb' )
36
38
37
- ipfs . block . put ( blob , ( err , res ) => {
39
+ ipfs . block . put ( blob , ( err , block ) => {
38
40
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' ) )
40
55
done ( )
41
56
} )
42
57
} )
@@ -52,30 +67,26 @@ module.exports = (common) => {
52
67
it ( 'block.get' , ( done ) => {
53
68
const hash = 'QmPv52ekjS75L4JmHpXVeuJ5uX2ecSfSZo88NSyxwA3rAQ'
54
69
55
- ipfs . block . get ( hash , ( err , res ) => {
70
+ ipfs . block . get ( hash , ( err , block ) => {
56
71
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 ( )
66
75
} )
67
76
} )
68
77
69
78
it ( 'block.stat' , ( done ) => {
70
79
const hash = 'QmPv52ekjS75L4JmHpXVeuJ5uX2ecSfSZo88NSyxwA3rAQ'
71
80
72
- ipfs . block . stat ( hash , ( err , res ) => {
81
+ ipfs . block . stat ( hash , ( err , stats ) => {
73
82
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 ' )
76
85
done ( )
77
86
} )
78
87
} )
88
+
89
+ it . skip ( 'block.rm' , ( done ) => { } ) // TODO once block.rm is shipped in go-ipfs
79
90
} )
80
91
81
92
describe ( 'promise API' , ( ) => {
0 commit comments