@@ -45,7 +45,7 @@ module.exports = (repo) => {
45
45
} )
46
46
47
47
it ( 'empty value' , ( done ) => {
48
- const d = new Buffer ( 0 )
48
+ const d = Buffer . alloc ( 0 )
49
49
multihashing ( d , 'sha2-256' , ( err , multihash ) => {
50
50
expect ( err ) . to . not . exist ( )
51
51
const empty = new Block ( d , new CID ( multihash ) )
@@ -70,7 +70,7 @@ module.exports = (repo) => {
70
70
this . timeout ( 15000 ) // add time for ci
71
71
waterfall ( [
72
72
( cb ) => map ( _ . range ( 50 ) , ( i , cb ) => {
73
- const d = new Buffer ( 'many' + Math . random ( ) )
73
+ const d = Buffer . from ( 'many' + Math . random ( ) )
74
74
multihashing ( d , 'sha2-256' , ( err , hash ) => {
75
75
if ( err ) {
76
76
return cb ( err )
@@ -135,6 +135,46 @@ module.exports = (repo) => {
135
135
done ( )
136
136
} )
137
137
} )
138
+
139
+ it ( 'should get block stored under v0 CID with a v1 CID' , done => {
140
+ const data = Buffer . from ( `TEST${ Date . now ( ) } ` )
141
+
142
+ multihashing ( data , 'sha2-256' , ( err , hash ) => {
143
+ if ( err ) return done ( err )
144
+
145
+ const cid = new CID ( hash )
146
+
147
+ repo . blocks . put ( new Block ( data , cid ) , err => {
148
+ if ( err ) return done ( err )
149
+
150
+ repo . blocks . get ( cid . toV1 ( ) , ( err , block ) => {
151
+ expect ( err ) . to . not . exist ( )
152
+ expect ( block . data ) . to . eql ( data )
153
+ done ( )
154
+ } )
155
+ } )
156
+ } )
157
+ } )
158
+
159
+ it ( 'should get block stored under v1 CID with a v0 CID' , done => {
160
+ const data = Buffer . from ( `TEST${ Date . now ( ) } ` )
161
+
162
+ multihashing ( data , 'sha2-256' , ( err , hash ) => {
163
+ if ( err ) return done ( err )
164
+
165
+ const cid = new CID ( 1 , 'dag-pb' , hash )
166
+
167
+ repo . blocks . put ( new Block ( data , cid ) , err => {
168
+ if ( err ) return done ( err )
169
+
170
+ repo . blocks . get ( cid . toV0 ( ) , ( err , block ) => {
171
+ expect ( err ) . to . not . exist ( )
172
+ expect ( block . data ) . to . eql ( data )
173
+ done ( )
174
+ } )
175
+ } )
176
+ } )
177
+ } )
138
178
} )
139
179
140
180
describe ( '.has' , ( ) => {
@@ -153,6 +193,46 @@ module.exports = (repo) => {
153
193
done ( )
154
194
} )
155
195
} )
196
+
197
+ it ( 'should have block stored under v0 CID with a v1 CID' , done => {
198
+ const data = Buffer . from ( `TEST${ Date . now ( ) } ` )
199
+
200
+ multihashing ( data , 'sha2-256' , ( err , hash ) => {
201
+ if ( err ) return done ( err )
202
+
203
+ const cid = new CID ( hash )
204
+
205
+ repo . blocks . put ( new Block ( data , cid ) , err => {
206
+ if ( err ) return done ( err )
207
+
208
+ repo . blocks . has ( cid . toV1 ( ) , ( err , exists ) => {
209
+ expect ( err ) . to . not . exist ( )
210
+ expect ( exists ) . to . eql ( true )
211
+ done ( )
212
+ } )
213
+ } )
214
+ } )
215
+ } )
216
+
217
+ it ( 'should have block stored under v1 CID with a v0 CID' , done => {
218
+ const data = Buffer . from ( `TEST${ Date . now ( ) } ` )
219
+
220
+ multihashing ( data , 'sha2-256' , ( err , hash ) => {
221
+ if ( err ) return done ( err )
222
+
223
+ const cid = new CID ( 1 , 'dag-pb' , hash )
224
+
225
+ repo . blocks . put ( new Block ( data , cid ) , err => {
226
+ if ( err ) return done ( err )
227
+
228
+ repo . blocks . has ( cid . toV0 ( ) , ( err , exists ) => {
229
+ expect ( err ) . to . not . exist ( )
230
+ expect ( exists ) . to . eql ( true )
231
+ done ( )
232
+ } )
233
+ } )
234
+ } )
235
+ } )
156
236
} )
157
237
158
238
describe ( '.delete' , ( ) => {
0 commit comments