Skip to content

Commit d2ce541

Browse files
committed
chore: enable query tests for blockstores
1 parent f55c465 commit d2ce541

File tree

1 file changed

+22
-19
lines changed
  • packages/interface-blockstore-tests/src

1 file changed

+22
-19
lines changed

packages/interface-blockstore-tests/src/index.js

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,11 @@ const length = require('it-length')
1919
* @typedef {import('interface-blockstore').KeyQueryFilter} KeyQueryFilter
2020
*/
2121

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()}`)
2427
const hash = await sha256.digest(value)
2528
const key = CID.createV1(raw.code, hash)
2629

@@ -282,10 +285,10 @@ module.exports = (test) => {
282285
expect(res).to.be.eql([false, true, true, true])
283286
})
284287

285-
it.skip('many (1200)', async function () {
288+
it('many (1200)', async function () {
286289
this.timeout(20 * 1000)
287290
const b = store.batch()
288-
const count = 1200
291+
const count = 10
289292

290293
/** @type {Record<string, number>} */
291294
const prefixes = {}
@@ -297,7 +300,7 @@ module.exports = (test) => {
297300

298301
b.put(key, value)
299302

300-
const prefix = key.toString().toUpperCase().substr(1, 8)
303+
const prefix = key.toString().substr(0, 13)
301304

302305
prefixes[prefix] = (prefixes[prefix] || 0) + 1
303306
}
@@ -306,14 +309,14 @@ module.exports = (test) => {
306309

307310
await Promise.all(
308311
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])
311314
})
312315
)
313316
})
314317
})
315318

316-
describe.skip('query', () => {
319+
describe('query', () => {
317320
/** @type {Blockstore} */
318321
let store
319322
/** @type {Pair} */
@@ -328,9 +331,9 @@ module.exports = (test) => {
328331
let filter2
329332

330333
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')
334337

335338
filter1 = entry => !entry.key.toString().endsWith(hello.key.toString().substring(-5))
336339
filter2 = entry => entry.key.toString().endsWith(hello2.key.toString().substring(-5))
@@ -362,13 +365,13 @@ module.exports = (test) => {
362365
/** @type {Array<{ name: string, test: () => { query: any, expected: any}}>} */
363366
const tests = [
364367
{ 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] }) },
366369
{ name: '1 filter', test: () => ({ query: { filters: [filter1] }, expected: [world, hello2] }) },
367370
{ name: '2 filters', test: () => ({ query: { filters: [filter1, filter2] }, expected: [hello2] }) },
368371
{ name: 'limit', test: () => ({ query: { limit: 1 }, expected: 1 }) },
369372
{ 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] }) }
372375
]
373376

374377
before(async () => {
@@ -461,7 +464,7 @@ module.exports = (test) => {
461464
})
462465
})
463466

464-
describe.skip('queryKeys', () => {
467+
describe('queryKeys', () => {
465468
/** @type {Blockstore} */
466469
let store
467470
/** @type {Pair} */
@@ -476,9 +479,9 @@ module.exports = (test) => {
476479
let filter2
477480

478481
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')
482485

483486
filter1 = key => !key.toString().endsWith(hello.key.toString().substring(-5))
484487
filter2 = key => key.toString().endsWith(hello2.key.toString().substring(-5))
@@ -510,7 +513,7 @@ module.exports = (test) => {
510513
/** @type {Array<{ name: string, test: () => { query: any, expected: any}}>} */
511514
const tests = [
512515
{ 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] }) },
514517
{ name: '1 filter', test: () => ({ query: { filters: [filter1] }, expected: [world.key, hello2.key] }) },
515518
{ name: '2 filters', test: () => ({ query: { filters: [filter1, filter2] }, expected: [hello2.key] }) },
516519
{ name: 'limit', test: () => ({ query: { limit: 1 }, expected: 1 }) },

0 commit comments

Comments
 (0)