@@ -6,6 +6,7 @@ const Block = require('ipfs-block')
6
6
const pull = require ( 'pull-stream' )
7
7
const _ = require ( 'lodash' )
8
8
const series = require ( 'run-series' )
9
+ const CID = require ( 'cids' )
9
10
10
11
const BlockService = require ( '../src' )
11
12
@@ -20,10 +21,11 @@ module.exports = (repo) => {
20
21
describe ( 'offline' , ( ) => {
21
22
it ( 'store and get a block' , ( done ) => {
22
23
const b = new Block ( 'A random data block' )
24
+ const cid = new CID ( b . key ( ) )
23
25
24
26
series ( [
25
27
( cb ) => bs . put ( b , cb ) ,
26
- ( cb ) => bs . get ( b . key ( ) , ( err , block ) => {
28
+ ( cb ) => bs . get ( cid , ( err , block ) => {
27
29
if ( err ) {
28
30
return cb ( err )
29
31
}
@@ -35,7 +37,9 @@ module.exports = (repo) => {
35
37
36
38
it ( 'get a non existent block' , ( done ) => {
37
39
const b = new Block ( 'Not stored' )
38
- bs . get ( b . key ( ) , ( err , block ) => {
40
+ const cid = new CID ( b . key ( ) )
41
+
42
+ bs . get ( cid , ( err , block ) => {
39
43
expect ( err ) . to . exist
40
44
done ( )
41
45
} )
@@ -61,13 +65,6 @@ module.exports = (repo) => {
61
65
)
62
66
} )
63
67
64
- it ( 'get: bad invocation' , ( done ) => {
65
- bs . get ( null , ( err ) => {
66
- expect ( err ) . to . be . an ( 'error' )
67
- done ( )
68
- } )
69
- } )
70
-
71
68
it ( 'get many blocks' , ( done ) => {
72
69
const b1 = new Block ( '1' )
73
70
const b2 = new Block ( '2' )
@@ -94,7 +91,8 @@ module.exports = (repo) => {
94
91
b3 . key ( )
95
92
] ) ,
96
93
pull . map ( ( key ) => {
97
- return bs . getStream ( key )
94
+ const cid = new CID ( key )
95
+ return bs . getStream ( cid )
98
96
} ) ,
99
97
pull . flatten ( ) ,
100
98
pull . collect ( ( err , blocks ) => {
@@ -114,26 +112,21 @@ module.exports = (repo) => {
114
112
const b = new Block ( 'Will not live that much' )
115
113
bs . put ( b , ( err ) => {
116
114
expect ( err ) . to . not . exist
117
- bs . delete ( b . key ( ) , ( err ) => {
115
+ const cid = new CID ( b . key ( ) )
116
+ bs . delete ( cid , ( err ) => {
118
117
expect ( err ) . to . not . exist
119
- bs . get ( b . key ( ) , ( err , block ) => {
118
+ bs . get ( cid , ( err , block ) => {
120
119
expect ( err ) . to . exist
121
120
done ( )
122
121
} )
123
122
} )
124
123
} )
125
124
} )
126
125
127
- it ( 'delete: bad invocation' , ( done ) => {
128
- bs . delete ( null , ( err ) => {
129
- expect ( err ) . to . be . an ( 'error' )
130
- done ( )
131
- } )
132
- } )
133
-
134
126
it ( 'delete a non existent block' , ( done ) => {
135
127
const b = new Block ( 'I do not exist' )
136
- bs . delete ( b . key ( ) , ( err ) => {
128
+ const cid = new CID ( b . key ( ) )
129
+ bs . delete ( cid , ( err ) => {
137
130
expect ( err ) . to . not . exist
138
131
done ( )
139
132
} )
@@ -145,9 +138,9 @@ module.exports = (repo) => {
145
138
const b3 = new Block ( '3' )
146
139
147
140
bs . delete ( [
148
- b1 . key ( ) ,
149
- b2 . key ( ) ,
150
- b3 . key ( )
141
+ new CID ( b1 . key ( ) ) ,
142
+ new CID ( b2 . key ( ) ) ,
143
+ new CID ( b3 . key ( ) )
151
144
] , ( err ) => {
152
145
expect ( err ) . to . not . exist
153
146
done ( )
@@ -173,7 +166,8 @@ module.exports = (repo) => {
173
166
return block . key ( )
174
167
} ) ,
175
168
pull . map ( ( key ) => {
176
- return bs . getStream ( key )
169
+ const cid = new CID ( key )
170
+ return bs . getStream ( cid )
177
171
} ) ,
178
172
pull . flatten ( ) ,
179
173
pull . collect ( ( err , retrievedBlocks ) => {
0 commit comments