@@ -177,6 +177,43 @@ export function interfaceBlockstoreTests <B extends Blockstore = Blockstore> (te
177
177
} )
178
178
} )
179
179
180
+ describe ( 'getAll' , ( ) => {
181
+ let store : B
182
+
183
+ beforeEach ( async ( ) => {
184
+ store = await createStore ( )
185
+ } )
186
+
187
+ afterEach ( async ( ) => {
188
+ await cleanup ( store )
189
+ } )
190
+
191
+ it ( 'returns all blocks' , async ( ) => {
192
+ const data = await getKeyValuePairs ( 100 )
193
+
194
+ await drain ( store . putMany ( data ) )
195
+
196
+ const allBlocks = await all ( store . getAll ( ) )
197
+
198
+ expect ( allBlocks ) . of . have . lengthOf ( data . length )
199
+
200
+ // order is not preserved
201
+ for ( const { cid, block } of data ) {
202
+ const retrievedPair = allBlocks . find ( pair => {
203
+ return base32 . encode ( cid . multihash . bytes ) === base32 . encode ( pair . cid . multihash . bytes )
204
+ } )
205
+
206
+ expect ( retrievedPair ) . to . be . ok ( )
207
+
208
+ if ( retrievedPair == null ) {
209
+ throw new Error ( 'Could not find cid/block pair' )
210
+ }
211
+
212
+ expect ( retrievedPair . block ) . to . equalBytes ( block )
213
+ }
214
+ } )
215
+ } )
216
+
180
217
describe ( 'delete' , ( ) => {
181
218
let store : B
182
219
@@ -247,41 +284,4 @@ export function interfaceBlockstoreTests <B extends Blockstore = Blockstore> (te
247
284
res1 . forEach ( res => expect ( res ) . to . be . eql ( false ) )
248
285
} )
249
286
} )
250
-
251
- describe ( 'blocks' , ( ) => {
252
- let store : B
253
-
254
- beforeEach ( async ( ) => {
255
- store = await createStore ( )
256
- } )
257
-
258
- afterEach ( async ( ) => {
259
- await cleanup ( store )
260
- } )
261
-
262
- it ( 'returns all blocks' , async ( ) => {
263
- const data = await getKeyValuePairs ( 100 )
264
-
265
- await drain ( store . putMany ( data ) )
266
-
267
- const allBlocks = await all ( store . getAll ( ) )
268
-
269
- expect ( allBlocks ) . of . have . lengthOf ( data . length )
270
-
271
- // order is not preserved
272
- for ( const { cid, block } of data ) {
273
- const retrievedPair = allBlocks . find ( pair => {
274
- return base32 . encode ( cid . multihash . bytes ) === base32 . encode ( pair . cid . multihash . bytes )
275
- } )
276
-
277
- expect ( retrievedPair ) . to . be . ok ( )
278
-
279
- if ( retrievedPair == null ) {
280
- throw new Error ( 'Could not find cid/block pair' )
281
- }
282
-
283
- expect ( retrievedPair . block ) . to . equalBytes ( block )
284
- }
285
- } )
286
- } )
287
287
}
0 commit comments