gitoriaLog in with ident

mpackdb

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Branchmaster87888725release 1.0.7caramboleyomaster/tests/utxo-sized-index-reopen.test.js

2.3 KB

  1. import assert from 'node:assert/strict';
  2. import { rm } from 'fs/promises';
  3. import MPackDB from '../src/MPackDB.js';
  4. const TEST_DB_PATH = 'db/utxo-sized-index-reopen';
  5. function makeUtxo(id, amount = 1000) {
  6. return {
  7. id,
  8. stealthAddress: id.repeat(130).slice(0, 8320),
  9. viewTag: id.slice(0, 16),
  10. amount,
  11. symbol: 'ADR',
  12. blockNumber: amount,
  13. txHash: id.padEnd(64, '0').slice(0, 64),
  14. outputIndex: 0,
  15. };
  16. }
  17. async function collect(cursor) {
  18. const rows = [];
  19. for await (const row of cursor) rows.push(row);
  20. return rows;
  21. }
  22. await rm(TEST_DB_PATH, { recursive: true, force: true });
  23. const ids = Array.from({ length: 240 }, (_, i) => `utxo-${String(i).padStart(5, '0')}`);
  24. const db = new MPackDB(`${TEST_DB_PATH}/utxos`, {
  25. primaryKey: 'id',
  26. indexes: ['symbol', '*blockNumber'],
  27. indexPersistThreshold: 10000,
  28. });
  29. for (let i = 0; i < ids.length; i++) {
  30. await db.insert(makeUtxo(ids[i], i + 1));
  31. }
  32. await db.close();
  33. const reopened = new MPackDB(`${TEST_DB_PATH}/utxos`, {
  34. primaryKey: 'id',
  35. indexes: ['symbol', '*blockNumber'],
  36. indexPersistThreshold: 10000,
  37. });
  38. for (const id of ids) {
  39. const rows = await collect(reopened.find(id));
  40. assert.equal(rows.length, 1, `expected one indexed result for ${id}`);
  41. assert.equal(rows[0].id, id);
  42. }
  43. await reopened.close();
  44. const tombstoneDb = new MPackDB(`${TEST_DB_PATH}/tombstones`, {
  45. primaryKey: 'id',
  46. indexes: ['symbol', '*blockNumber'],
  47. indexPersistThreshold: 10000,
  48. });
  49. await tombstoneDb.insert(makeUtxo('spent-utxo-0001', 12));
  50. await tombstoneDb.insert(makeUtxo('live-utxo-0002', 24));
  51. await tombstoneDb.delete('spent-utxo-0001');
  52. await tombstoneDb.close();
  53. const tombstoneReopened = new MPackDB(`${TEST_DB_PATH}/tombstones`, {
  54. primaryKey: 'id',
  55. indexes: ['symbol', '*blockNumber'],
  56. indexPersistThreshold: 10000,
  57. });
  58. assert.deepEqual(await collect(tombstoneReopened.find('spent-utxo-0001')), []);
  59. const liveRows = await collect(tombstoneReopened.find('live-utxo-0002'));
  60. assert.equal(liveRows.length, 1);
  61. assert.equal(liveRows[0].amount, 24);
  62. await tombstoneReopened.compact();
  63. assert.deepEqual(await collect(tombstoneReopened.find('spent-utxo-0001')), []);
  64. assert.equal((await collect(tombstoneReopened.find('live-utxo-0002'))).length, 1);
  65. await tombstoneReopened.close();
  66. await rm(TEST_DB_PATH, { recursive: true, force: true });
  67. 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