mpackdb
All repositories: gitoria
2.3 KB
import assert from 'node:assert/strict';import { rm } from 'fs/promises';import MPackDB from '../src/MPackDB.js';const TEST_DB_PATH = 'db/utxo-sized-index-reopen';function makeUtxo(id, amount = 1000) {return {id,stealthAddress: id.repeat(130).slice(0, 8320),viewTag: id.slice(0, 16),amount,symbol: 'ADR',blockNumber: amount,txHash: id.padEnd(64, '0').slice(0, 64),outputIndex: 0,};}async function collect(cursor) {const rows = [];for await (const row of cursor) rows.push(row);return rows;}await rm(TEST_DB_PATH, { recursive: true, force: true });const ids = Array.from({ length: 240 }, (_, i) => `utxo-${String(i).padStart(5, '0')}`);const db = new MPackDB(`${TEST_DB_PATH}/utxos`, {primaryKey: 'id',indexes: ['symbol', '*blockNumber'],indexPersistThreshold: 10000,});for (let i = 0; i < ids.length; i++) {await db.insert(makeUtxo(ids[i], i + 1));}await db.close();const reopened = new MPackDB(`${TEST_DB_PATH}/utxos`, {primaryKey: 'id',indexes: ['symbol', '*blockNumber'],indexPersistThreshold: 10000,});for (const id of ids) {const rows = await collect(reopened.find(id));assert.equal(rows.length, 1, `expected one indexed result for ${id}`);assert.equal(rows[0].id, id);}await reopened.close();const tombstoneDb = new MPackDB(`${TEST_DB_PATH}/tombstones`, {primaryKey: 'id',indexes: ['symbol', '*blockNumber'],indexPersistThreshold: 10000,});await tombstoneDb.insert(makeUtxo('spent-utxo-0001', 12));await tombstoneDb.insert(makeUtxo('live-utxo-0002', 24));await tombstoneDb.delete('spent-utxo-0001');await tombstoneDb.close();const tombstoneReopened = new MPackDB(`${TEST_DB_PATH}/tombstones`, {primaryKey: 'id',indexes: ['symbol', '*blockNumber'],indexPersistThreshold: 10000,});assert.deepEqual(await collect(tombstoneReopened.find('spent-utxo-0001')), []);const liveRows = await collect(tombstoneReopened.find('live-utxo-0002'));assert.equal(liveRows.length, 1);assert.equal(liveRows[0].amount, 24);await tombstoneReopened.compact();assert.deepEqual(await collect(tombstoneReopened.find('spent-utxo-0001')), []);assert.equal((await collect(tombstoneReopened.find('live-utxo-0002'))).length, 1);await tombstoneReopened.close();await rm(TEST_DB_PATH, { recursive: true, force: true });console.log('✓ UTXO-sized indexed reopen/tombstone tests passed');
Branches
- mastermain branch
Latest commits
- 87888725release 1.0.7caramboleyo
- c4cdb9b6node: import prefixes (Deno compat) + pre-existing index-state WIPcaramboleyo
- 0afb8f4bupdate now must be a callbackcaramboleyo
- cde73eb4release 1.0.6caramboleyo
- d01dda02add index hints, intersection, boundingBox; remove findByIndexcaramboleyo
- b8ffc1a0release 1.0.5caramboleyo
- d47876a1reimplemented lost features like indexed find and more testscaramboleyo
- 7f08da9afixed insert ignoring model definitioncaramboleyo
- 705774a9added flush before findcaramboleyo
- b4db6391initial commitcaramboleyo