@@ -19,8 +19,11 @@ const length = require('it-length')
19
19
* @typedef {import('interface-blockstore').KeyQueryFilter } KeyQueryFilter
20
20
*/
21
21
22
- async function getKeyValuePair ( ) {
23
- const value = uint8ArrayFromString ( `data-${ Math . random ( ) } ` )
22
+ /**
23
+ * @param {string } [data]
24
+ */
25
+ async function getKeyValuePair ( data ) {
26
+ const value = uint8ArrayFromString ( data || `data-${ Math . random ( ) } ` )
24
27
const hash = await sha256 . digest ( value )
25
28
const key = CID . createV1 ( raw . code , hash )
26
29
@@ -282,10 +285,10 @@ module.exports = (test) => {
282
285
expect ( res ) . to . be . eql ( [ false , true , true , true ] )
283
286
} )
284
287
285
- it . skip ( 'many (1200)' , async function ( ) {
288
+ it ( 'many (1200)' , async function ( ) {
286
289
this . timeout ( 20 * 1000 )
287
290
const b = store . batch ( )
288
- const count = 1200
291
+ const count = 10
289
292
290
293
/** @type {Record<string, number> } */
291
294
const prefixes = { }
@@ -297,7 +300,7 @@ module.exports = (test) => {
297
300
298
301
b . put ( key , value )
299
302
300
- const prefix = key . toString ( ) . toUpperCase ( ) . substr ( 1 , 8 )
303
+ const prefix = key . toString ( ) . substr ( 0 , 13 )
301
304
302
305
prefixes [ prefix ] = ( prefixes [ prefix ] || 0 ) + 1
303
306
}
@@ -306,14 +309,14 @@ module.exports = (test) => {
306
309
307
310
await Promise . all (
308
311
Object . keys ( prefixes )
309
- . map ( prefix => {
310
- return expect ( length ( store . query ( { prefix } ) ) ) . to . eventually . equal ( prefixes [ prefix ] )
312
+ . map ( async prefix => {
313
+ await expect ( length ( store . query ( { prefix } ) ) ) . to . eventually . equal ( prefixes [ prefix ] )
311
314
} )
312
315
)
313
316
} )
314
317
} )
315
318
316
- describe . skip ( 'query' , ( ) => {
319
+ describe ( 'query' , ( ) => {
317
320
/** @type {Blockstore } */
318
321
let store
319
322
/** @type {Pair } */
@@ -328,9 +331,9 @@ module.exports = (test) => {
328
331
let filter2
329
332
330
333
before ( async ( ) => {
331
- hello = await getKeyValuePair ( )
332
- hello2 = await getKeyValuePair ( )
333
- world = await getKeyValuePair ( )
334
+ hello = await getKeyValuePair ( 'hello' )
335
+ hello2 = await getKeyValuePair ( 'hello2' )
336
+ world = await getKeyValuePair ( 'world' )
334
337
335
338
filter1 = entry => ! entry . key . toString ( ) . endsWith ( hello . key . toString ( ) . substring ( - 5 ) )
336
339
filter2 = entry => entry . key . toString ( ) . endsWith ( hello2 . key . toString ( ) . substring ( - 5 ) )
@@ -362,13 +365,13 @@ module.exports = (test) => {
362
365
/** @type {Array<{ name: string, test: () => { query: any, expected: any}}> } */
363
366
const tests = [
364
367
{ name : 'empty' , test : ( ) => ( { query : { } , expected : [ hello , world , hello2 ] } ) } ,
365
- { name : 'prefix' , test : ( ) => ( { query : { prefix : '/z' } , expected : [ world , hello2 ] } ) } ,
368
+ { name : 'prefix' , test : ( ) => ( { query : { prefix : `/ ${ hello . key . toString ( ) . charAt ( 0 ) } ` } , expected : [ hello , world , hello2 ] } ) } ,
366
369
{ name : '1 filter' , test : ( ) => ( { query : { filters : [ filter1 ] } , expected : [ world , hello2 ] } ) } ,
367
370
{ name : '2 filters' , test : ( ) => ( { query : { filters : [ filter1 , filter2 ] } , expected : [ hello2 ] } ) } ,
368
371
{ name : 'limit' , test : ( ) => ( { query : { limit : 1 } , expected : 1 } ) } ,
369
372
{ name : 'offset' , test : ( ) => ( { query : { offset : 1 } , expected : 2 } ) } ,
370
- { name : '1 order (1)' , test : ( ) => ( { query : { orders : [ order1 ] } , expected : [ hello , world , hello2 ] } ) } ,
371
- { name : '1 order (reverse 1)' , test : ( ) => ( { query : { orders : [ order2 ] } , expected : [ hello2 , world , hello ] } ) }
373
+ { name : '1 order (1)' , test : ( ) => ( { query : { orders : [ order1 ] } , expected : [ hello , hello2 , world ] } ) } ,
374
+ { name : '1 order (reverse 1)' , test : ( ) => ( { query : { orders : [ order2 ] } , expected : [ world , hello2 , hello ] } ) }
372
375
]
373
376
374
377
before ( async ( ) => {
@@ -461,7 +464,7 @@ module.exports = (test) => {
461
464
} )
462
465
} )
463
466
464
- describe . skip ( 'queryKeys' , ( ) => {
467
+ describe ( 'queryKeys' , ( ) => {
465
468
/** @type {Blockstore } */
466
469
let store
467
470
/** @type {Pair } */
@@ -476,9 +479,9 @@ module.exports = (test) => {
476
479
let filter2
477
480
478
481
before ( async ( ) => {
479
- hello = await getKeyValuePair ( )
480
- hello2 = await getKeyValuePair ( )
481
- world = await getKeyValuePair ( )
482
+ hello = await getKeyValuePair ( 'hello' )
483
+ hello2 = await getKeyValuePair ( 'hello2' )
484
+ world = await getKeyValuePair ( 'world' )
482
485
483
486
filter1 = key => ! key . toString ( ) . endsWith ( hello . key . toString ( ) . substring ( - 5 ) )
484
487
filter2 = key => key . toString ( ) . endsWith ( hello2 . key . toString ( ) . substring ( - 5 ) )
@@ -510,7 +513,7 @@ module.exports = (test) => {
510
513
/** @type {Array<{ name: string, test: () => { query: any, expected: any}}> } */
511
514
const tests = [
512
515
{ name : 'empty' , test : ( ) => ( { query : { } , expected : [ hello . key , world . key , hello2 . key ] } ) } ,
513
- { name : 'prefix' , test : ( ) => ( { query : { prefix : '/z' } , expected : [ world . key , hello2 . key ] } ) } ,
516
+ { name : 'prefix' , test : ( ) => ( { query : { prefix : `/ ${ hello . key . toString ( ) . charAt ( 0 ) } ` } , expected : [ hello . key , world . key , hello2 . key ] } ) } ,
514
517
{ name : '1 filter' , test : ( ) => ( { query : { filters : [ filter1 ] } , expected : [ world . key , hello2 . key ] } ) } ,
515
518
{ name : '2 filters' , test : ( ) => ( { query : { filters : [ filter1 , filter2 ] } , expected : [ hello2 . key ] } ) } ,
516
519
{ name : 'limit' , test : ( ) => ( { query : { limit : 1 } , expected : 1 } ) } ,
0 commit comments