@aztec/kv-store 0.0.1-commit.86469d5 → 0.0.1-commit.8655d4a

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (112) hide show
  1. package/dest/bench/shared_map_bench.d.ts +19 -0
  2. package/dest/bench/shared_map_bench.d.ts.map +1 -0
  3. package/dest/bench/shared_map_bench.js +91 -0
  4. package/dest/indexeddb/index.d.ts +2 -2
  5. package/dest/indexeddb/index.d.ts.map +1 -1
  6. package/dest/indexeddb/index.js +1 -1
  7. package/dest/indexeddb/map.d.ts +7 -1
  8. package/dest/indexeddb/map.d.ts.map +1 -1
  9. package/dest/indexeddb/map.js +12 -2
  10. package/dest/indexeddb/multi_map.js +1 -1
  11. package/dest/indexeddb/store.d.ts +1 -1
  12. package/dest/indexeddb/store.d.ts.map +1 -1
  13. package/dest/indexeddb/store.js +6 -4
  14. package/dest/interfaces/array_test_suite.d.ts +1 -1
  15. package/dest/interfaces/array_test_suite.d.ts.map +1 -1
  16. package/dest/interfaces/array_test_suite.js +33 -34
  17. package/dest/interfaces/index.d.ts +2 -2
  18. package/dest/interfaces/index.d.ts.map +1 -1
  19. package/dest/interfaces/map_test_suite.d.ts +1 -1
  20. package/dest/interfaces/map_test_suite.d.ts.map +1 -1
  21. package/dest/interfaces/map_test_suite.js +32 -33
  22. package/dest/interfaces/multi_map_test_suite.d.ts +1 -1
  23. package/dest/interfaces/multi_map_test_suite.d.ts.map +1 -1
  24. package/dest/interfaces/multi_map_test_suite.js +68 -69
  25. package/dest/interfaces/set_test_suite.d.ts +1 -1
  26. package/dest/interfaces/set_test_suite.d.ts.map +1 -1
  27. package/dest/interfaces/set_test_suite.js +13 -14
  28. package/dest/interfaces/singleton_test_suite.d.ts +1 -1
  29. package/dest/interfaces/singleton_test_suite.d.ts.map +1 -1
  30. package/dest/interfaces/singleton_test_suite.js +6 -7
  31. package/dest/lmdb/index.d.ts +2 -2
  32. package/dest/lmdb/index.d.ts.map +1 -1
  33. package/dest/lmdb/index.js +2 -2
  34. package/dest/lmdb/store.d.ts +3 -3
  35. package/dest/lmdb/store.d.ts.map +1 -1
  36. package/dest/lmdb/store.js +12 -8
  37. package/dest/lmdb-v2/factory.d.ts +29 -4
  38. package/dest/lmdb-v2/factory.d.ts.map +1 -1
  39. package/dest/lmdb-v2/factory.js +61 -10
  40. package/dest/lmdb-v2/read_transaction.js +21 -19
  41. package/dest/lmdb-v2/store.d.ts +2 -2
  42. package/dest/lmdb-v2/store.d.ts.map +1 -1
  43. package/dest/lmdb-v2/store.js +4 -4
  44. package/dest/sqlite-opfs/array.d.ts +21 -0
  45. package/dest/sqlite-opfs/array.d.ts.map +1 -0
  46. package/dest/sqlite-opfs/array.js +128 -0
  47. package/dest/sqlite-opfs/errors.d.ts +27 -0
  48. package/dest/sqlite-opfs/errors.d.ts.map +1 -0
  49. package/dest/sqlite-opfs/errors.js +34 -0
  50. package/dest/sqlite-opfs/index.d.ts +16 -0
  51. package/dest/sqlite-opfs/index.d.ts.map +1 -0
  52. package/dest/sqlite-opfs/index.js +22 -0
  53. package/dest/sqlite-opfs/internal/ordered-binary-browser.d.ts +32 -0
  54. package/dest/sqlite-opfs/internal/ordered-binary-browser.d.ts.map +1 -0
  55. package/dest/sqlite-opfs/internal/ordered-binary-browser.js +448 -0
  56. package/dest/sqlite-opfs/map.d.ts +35 -0
  57. package/dest/sqlite-opfs/map.d.ts.map +1 -0
  58. package/dest/sqlite-opfs/map.js +163 -0
  59. package/dest/sqlite-opfs/messages.d.ts +66 -0
  60. package/dest/sqlite-opfs/messages.d.ts.map +1 -0
  61. package/dest/sqlite-opfs/messages.js +5 -0
  62. package/dest/sqlite-opfs/multi_map.d.ts +16 -0
  63. package/dest/sqlite-opfs/multi_map.d.ts.map +1 -0
  64. package/dest/sqlite-opfs/multi_map.js +67 -0
  65. package/dest/sqlite-opfs/set.d.ts +13 -0
  66. package/dest/sqlite-opfs/set.d.ts.map +1 -0
  67. package/dest/sqlite-opfs/set.js +19 -0
  68. package/dest/sqlite-opfs/singleton.d.ts +13 -0
  69. package/dest/sqlite-opfs/singleton.d.ts.map +1 -0
  70. package/dest/sqlite-opfs/singleton.js +48 -0
  71. package/dest/sqlite-opfs/store.d.ts +79 -0
  72. package/dest/sqlite-opfs/store.d.ts.map +1 -0
  73. package/dest/sqlite-opfs/store.js +281 -0
  74. package/dest/sqlite-opfs/worker.d.ts +2 -0
  75. package/dest/sqlite-opfs/worker.d.ts.map +1 -0
  76. package/dest/sqlite-opfs/worker.js +249 -0
  77. package/dest/stores/l2_tips_store.d.ts +3 -3
  78. package/dest/stores/l2_tips_store.d.ts.map +1 -1
  79. package/dest/stores/l2_tips_store.js +2 -2
  80. package/package.json +28 -26
  81. package/src/bench/shared_map_bench.ts +111 -0
  82. package/src/indexeddb/index.ts +2 -2
  83. package/src/indexeddb/map.ts +14 -2
  84. package/src/indexeddb/multi_map.ts +1 -1
  85. package/src/indexeddb/store.ts +6 -4
  86. package/src/interfaces/array_test_suite.ts +33 -35
  87. package/src/interfaces/index.ts +1 -1
  88. package/src/interfaces/map_test_suite.ts +32 -34
  89. package/src/interfaces/multi_map_test_suite.ts +65 -67
  90. package/src/interfaces/set_test_suite.ts +13 -15
  91. package/src/interfaces/singleton_test_suite.ts +6 -8
  92. package/src/lmdb/index.ts +3 -3
  93. package/src/lmdb/store.ts +12 -8
  94. package/src/lmdb-v2/factory.ts +80 -10
  95. package/src/lmdb-v2/read_transaction.ts +23 -23
  96. package/src/lmdb-v2/store.ts +4 -2
  97. package/src/sqlite-opfs/array.ts +124 -0
  98. package/src/sqlite-opfs/errors.ts +44 -0
  99. package/src/sqlite-opfs/index.ts +39 -0
  100. package/src/sqlite-opfs/internal/ordered-binary-browser.js +465 -0
  101. package/src/sqlite-opfs/map.ts +163 -0
  102. package/src/sqlite-opfs/messages.ts +39 -0
  103. package/src/sqlite-opfs/multi_map.ts +74 -0
  104. package/src/sqlite-opfs/set.ts +29 -0
  105. package/src/sqlite-opfs/singleton.ts +48 -0
  106. package/src/sqlite-opfs/store.ts +296 -0
  107. package/src/sqlite-opfs/worker.ts +231 -0
  108. package/src/stores/l2_tips_store.ts +3 -2
  109. package/dest/config.d.ts +0 -17
  110. package/dest/config.d.ts.map +0 -1
  111. package/dest/config.js +0 -26
  112. package/src/config.ts +0 -36
@@ -0,0 +1,111 @@
1
+ import type { Logger } from '@aztec/foundation/log';
2
+ import { Timer } from '@aztec/foundation/timer';
3
+
4
+ import type { Key } from '../interfaces/common.js';
5
+ import type { AztecAsyncMap } from '../interfaces/map.js';
6
+ import type { AztecAsyncKVStore } from '../interfaces/store.js';
7
+
8
+ /** One benchmark measurement. */
9
+ export type BenchResult = {
10
+ /** Benchmark name (includes the backend prefix for disambiguation). */
11
+ name: string;
12
+ value: number;
13
+ unit: 'ms' | 'us';
14
+ };
15
+
16
+ export type BenchReporter = (results: BenchResult[]) => void | Promise<void>;
17
+
18
+ /**
19
+ * Runs the standard Map benchmark suite against any `AztecAsyncKVStore` backend,
20
+ * populates `results`, and calls `reporter` in `afterAll`.
21
+ *
22
+ * Kept free of Node-only deps (`fs`, `path`) so the same runner works under
23
+ * vitest-browser for IndexedDB and SQLite-OPFS.
24
+ */
25
+ export function describeAztecMapBench(
26
+ backendPrefix: string,
27
+ getStore: () => Promise<AztecAsyncKVStore>,
28
+ logger: Logger,
29
+ reporter: BenchReporter,
30
+ ) {
31
+ describe(`${backendPrefix} Map benchmarks`, () => {
32
+ let store: AztecAsyncKVStore;
33
+ let map: AztecAsyncMap<Key, string>;
34
+
35
+ const results: BenchResult[] = [];
36
+
37
+ const generateKeyValuePairs = (count: number, offset = 0) => {
38
+ const keys = Array.from({ length: count }, (_, i) => `key-${i + offset}`);
39
+ const values = Array.from({ length: count }, (_, i) => `value-${i + offset}`);
40
+ return keys.map((key, i) => ({ key, value: values[i] }));
41
+ };
42
+
43
+ const record = (name: string, value: number, unit: BenchResult['unit']) => {
44
+ results.push({ name: `${backendPrefix}/Map/${name}`, value, unit });
45
+ };
46
+
47
+ beforeEach(async () => {
48
+ store = await getStore();
49
+ map = store.openMap<Key, string>('test');
50
+ });
51
+
52
+ afterEach(async () => {
53
+ await store.delete();
54
+ });
55
+
56
+ afterAll(async () => {
57
+ const pretty = results.map(r => `${r.name}: ${r.value.toFixed(2)} ${r.unit}`).join('\n');
58
+ logger.info(`\n${pretty}\n`);
59
+ await reporter(results);
60
+ });
61
+
62
+ it('adds individual values', async () => {
63
+ const pairs = generateKeyValuePairs(1000);
64
+ const timer = new Timer();
65
+ for (const pair of pairs) {
66
+ await map.set(pair.key, pair.value);
67
+ }
68
+ record('Individual insertion', timer.ms() / pairs.length, 'ms');
69
+ });
70
+
71
+ it('adds batched values', async () => {
72
+ const batches = Array.from({ length: 100 }, (_, i) => generateKeyValuePairs(1000, i * 1000));
73
+ const timer = new Timer();
74
+ for (const batch of batches) {
75
+ await map.setMany(batch);
76
+ }
77
+ record(`Batch insertion of ${batches[0].length} items`, timer.ms() / batches.length, 'ms');
78
+ });
79
+
80
+ it('reads individual values', async () => {
81
+ const pairs = generateKeyValuePairs(10000);
82
+ await map.setMany(pairs);
83
+ const timer = new Timer();
84
+ for (const pair of pairs) {
85
+ await map.getAsync(pair.key);
86
+ }
87
+ record('Individual read', (timer.ms() * 1000) / pairs.length, 'us');
88
+ });
89
+
90
+ it('reads via a cursor', async () => {
91
+ const pairs = generateKeyValuePairs(10000);
92
+ await map.setMany(pairs);
93
+ const timer = new Timer();
94
+ for await (const _ of map.entriesAsync()) {
95
+ // consume
96
+ }
97
+ record(`Iterator per item read of ${pairs.length} items`, (timer.ms() * 1000) / pairs.length, 'us');
98
+ });
99
+
100
+ it('reads the size of the map', async () => {
101
+ const numIterations = 1000;
102
+ const pairs = generateKeyValuePairs(10000);
103
+ await map.setMany(pairs);
104
+ const timer = new Timer();
105
+ for (let i = 0; i < numIterations; i++) {
106
+ await map.sizeAsync();
107
+ }
108
+ record(`Read size of ${pairs.length} items`, (timer.ms() * 1000) / numIterations, 'us');
109
+ });
110
+ });
111
+ }
@@ -1,6 +1,6 @@
1
1
  import { type Logger, createLogger } from '@aztec/foundation/log';
2
+ import type { DataStoreConfig } from '@aztec/stdlib/kv-store';
2
3
 
3
- import type { DataStoreConfig } from '../config.js';
4
4
  import { initStoreForRollupAndSchemaVersion } from '../utils.js';
5
5
  import { AztecIndexedDBStore } from './store.js';
6
6
 
@@ -23,7 +23,7 @@ export async function createStore(
23
23
  : `Creating ${name} ephemeral data store with map size ${config.dataStoreMapSizeKb} KB`,
24
24
  );
25
25
  const store = await AztecIndexedDBStore.open(createLogger('kv-store:indexeddb'), dataDirectory ?? '', false);
26
- return initStoreForRollupAndSchemaVersion(store, schemaVersion, config.l1Contracts?.rollupAddress, log);
26
+ return initStoreForRollupAndSchemaVersion(store, schemaVersion, config.rollupAddress, log);
27
27
  }
28
28
 
29
29
  export function openTmpStore(ephemeral: boolean = false): Promise<AztecIndexedDBStore> {
@@ -31,7 +31,7 @@ export class IndexedDBAztecMap<K extends Key, V extends Value> implements AztecA
31
31
 
32
32
  async getAsync(key: K): Promise<V | undefined> {
33
33
  const data = await this.db.get(this.slot(key));
34
- return data?.value as V;
34
+ return data ? this.restoreBuffers(data.value as V) : undefined;
35
35
  }
36
36
 
37
37
  async hasAsync(key: K): Promise<boolean> {
@@ -94,7 +94,7 @@ export class IndexedDBAztecMap<K extends Key, V extends Value> implements AztecA
94
94
  if (range.limit && count >= range.limit) {
95
95
  return;
96
96
  }
97
- yield [this.#denormalizeKey(cursor.value.key), cursor.value.value] as [K, V];
97
+ yield [this.#denormalizeKey(cursor.value.key), this.restoreBuffers(cursor.value.value as V)] as [K, V];
98
98
  count++;
99
99
  }
100
100
  }
@@ -111,6 +111,18 @@ export class IndexedDBAztecMap<K extends Key, V extends Value> implements AztecA
111
111
  }
112
112
  }
113
113
 
114
+ /**
115
+ * IndexedDB's structured clone downcasts Buffer (a Node.js subclass of Uint8Array) to plain Uint8Array.
116
+ * This breaks .toString() behavior: Buffer.toString() returns UTF-8, Uint8Array.toString() returns
117
+ * comma-separated decimal bytes. We restore Buffer identity on read so callers get consistent behavior.
118
+ */
119
+ protected restoreBuffers(val: V): V {
120
+ if (val instanceof Uint8Array && !Buffer.isBuffer(val)) {
121
+ return Buffer.from(val) as V;
122
+ }
123
+ return val;
124
+ }
125
+
114
126
  #denormalizeKey(key: (string | number | Uint8Array)[]): K {
115
127
  return (key.length > 1 ? key : key[0]) as K;
116
128
  }
@@ -57,7 +57,7 @@ export class IndexedDBAztecMultiMap<K extends Key, V extends Value>
57
57
  false,
58
58
  );
59
59
  for await (const cursor of index.iterate(rangeQuery)) {
60
- yield cursor.value.value as V;
60
+ yield this.restoreBuffers(cursor.value.value as V);
61
61
  }
62
62
  }
63
63
 
@@ -192,18 +192,20 @@ export class AztecIndexedDBStore implements AztecAsyncKVStore {
192
192
  }
193
193
 
194
194
  /** Deletes this store and removes the database */
195
- delete() {
195
+ async delete() {
196
196
  this.#containers.clear();
197
+ await this.#txQueue.end();
197
198
  this.#rootDB.close();
198
- return deleteDB(this.#name);
199
+ await deleteDB(this.#name);
199
200
  }
200
201
 
201
202
  estimateSize(): Promise<StoreSize> {
202
203
  return Promise.resolve({ mappingSize: 0, physicalFileSize: 0, actualSize: 0, numItems: 0 });
203
204
  }
204
205
 
205
- close(): Promise<void> {
206
- return Promise.resolve();
206
+ async close(): Promise<void> {
207
+ await this.#txQueue.end();
208
+ this.#rootDB.close();
207
209
  }
208
210
 
209
211
  backupTo(_dstPath: string, _compact?: boolean): Promise<void> {
@@ -1,7 +1,5 @@
1
1
  import { toArray } from '@aztec/foundation/iterable';
2
2
 
3
- import { expect } from 'chai';
4
-
5
3
  import type { AztecArray, AztecAsyncArray } from './array.js';
6
4
  import type { AztecAsyncKVStore, AztecKVStore } from './store.js';
7
5
  import { isSyncStore } from './utils.js';
@@ -53,12 +51,12 @@ export function describeAztecArray(
53
51
  await arr.push(2);
54
52
  await arr.push(3);
55
53
 
56
- expect(await length()).to.equal(3);
54
+ expect(await length()).toBe(3);
57
55
 
58
- expect(await arr.pop()).to.equal(3);
59
- expect(await arr.pop()).to.equal(2);
60
- expect(await arr.pop()).to.equal(1);
61
- expect(await arr.pop()).to.equal(undefined);
56
+ expect(await arr.pop()).toBe(3);
57
+ expect(await arr.pop()).toBe(2);
58
+ expect(await arr.pop()).toBe(1);
59
+ expect(await arr.pop()).toBe(undefined);
62
60
  });
63
61
 
64
62
  it('should be able to get values by index', async () => {
@@ -66,14 +64,14 @@ export function describeAztecArray(
66
64
  await arr.push(2);
67
65
  await arr.push(3);
68
66
 
69
- expect(await at(0)).to.equal(1);
70
- expect(await at(1)).to.equal(2);
71
- expect(await at(2)).to.equal(3);
72
- expect(await at(3)).to.equal(undefined);
73
- expect(await at(-1)).to.equal(3);
74
- expect(await at(-2)).to.equal(2);
75
- expect(await at(-3)).to.equal(1);
76
- expect(await at(-4)).to.equal(undefined);
67
+ expect(await at(0)).toBe(1);
68
+ expect(await at(1)).toBe(2);
69
+ expect(await at(2)).toBe(3);
70
+ expect(await at(3)).toBe(undefined);
71
+ expect(await at(-1)).toBe(3);
72
+ expect(await at(-2)).toBe(2);
73
+ expect(await at(-3)).toBe(1);
74
+ expect(await at(-4)).toBe(undefined);
77
75
  });
78
76
 
79
77
  it('should be able to set values by index', async () => {
@@ -81,27 +79,27 @@ export function describeAztecArray(
81
79
  await arr.push(2);
82
80
  await arr.push(3);
83
81
 
84
- expect(await arr.setAt(0, 4)).to.equal(true);
85
- expect(await arr.setAt(1, 5)).to.equal(true);
86
- expect(await arr.setAt(2, 6)).to.equal(true);
82
+ expect(await arr.setAt(0, 4)).toBe(true);
83
+ expect(await arr.setAt(1, 5)).toBe(true);
84
+ expect(await arr.setAt(2, 6)).toBe(true);
87
85
 
88
- expect(await arr.setAt(3, 7)).to.equal(false);
86
+ expect(await arr.setAt(3, 7)).toBe(false);
89
87
 
90
- expect(await at(0)).to.equal(4);
91
- expect(await at(1)).to.equal(5);
92
- expect(await at(2)).to.equal(6);
93
- expect(await at(3)).to.equal(undefined);
88
+ expect(await at(0)).toBe(4);
89
+ expect(await at(1)).toBe(5);
90
+ expect(await at(2)).toBe(6);
91
+ expect(await at(3)).toBe(undefined);
94
92
 
95
- expect(await arr.setAt(-1, 8)).to.equal(true);
96
- expect(await arr.setAt(-2, 9)).to.equal(true);
97
- expect(await arr.setAt(-3, 10)).to.equal(true);
93
+ expect(await arr.setAt(-1, 8)).toBe(true);
94
+ expect(await arr.setAt(-2, 9)).toBe(true);
95
+ expect(await arr.setAt(-3, 10)).toBe(true);
98
96
 
99
- expect(await arr.setAt(-4, 11)).to.equal(false);
97
+ expect(await arr.setAt(-4, 11)).toBe(false);
100
98
 
101
- expect(await at(-1)).to.equal(8);
102
- expect(await at(-2)).to.equal(9);
103
- expect(await at(-3)).to.equal(10);
104
- expect(await at(-4)).to.equal(undefined);
99
+ expect(await at(-1)).toBe(8);
100
+ expect(await at(-2)).toBe(9);
101
+ expect(await at(-3)).toBe(10);
102
+ expect(await at(-4)).toBe(undefined);
105
103
  });
106
104
 
107
105
  it('should be able to iterate over values', async () => {
@@ -109,8 +107,8 @@ export function describeAztecArray(
109
107
  await arr.push(2);
110
108
  await arr.push(3);
111
109
 
112
- expect(await values()).to.deep.equal([1, 2, 3]);
113
- expect(await entries()).to.deep.equal([
110
+ expect(await values()).toEqual([1, 2, 3]);
111
+ expect(await entries()).toEqual([
114
112
  [0, 1],
115
113
  [1, 2],
116
114
  [2, 3],
@@ -123,8 +121,8 @@ export function describeAztecArray(
123
121
  await arr.push(3);
124
122
 
125
123
  const arr2 = store.openArray<number>('test');
126
- expect(await length(arr2)).to.equal(3);
127
- expect(await values(arr2)).to.deep.equal(await values());
124
+ expect(await length(arr2)).toBe(3);
125
+ expect(await values(arr2)).toEqual(await values());
128
126
  });
129
127
  });
130
128
  }
@@ -6,4 +6,4 @@ export * from './store.js';
6
6
  export * from './set.js';
7
7
  export * from './multi_map.js';
8
8
  export { mapRange } from './common.js';
9
- export type { CustomRange, Range, StoreSize } from './common.js';
9
+ export type { CustomRange, Key, Range, StoreSize } from './common.js';
@@ -1,7 +1,5 @@
1
1
  import { toArray } from '@aztec/foundation/iterable';
2
2
 
3
- import { expect } from 'chai';
4
-
5
3
  import type { Key, Range } from './common.js';
6
4
  import type { AztecAsyncMap, AztecMap } from './map.js';
7
5
  import type { AztecAsyncKVStore, AztecKVStore } from './store.js';
@@ -59,9 +57,9 @@ export function describeAztecMap(
59
57
  await map.set('foo', 'bar');
60
58
  await map.set('baz', 'qux');
61
59
 
62
- expect(await get('foo')).to.equal('bar');
63
- expect(await get('baz')).to.equal('qux');
64
- expect(await get('quux')).to.equal(undefined);
60
+ expect(await get('foo')).toBe('bar');
61
+ expect(await get('baz')).toBe('qux');
62
+ expect(await get('quux')).toBe(undefined);
65
63
  });
66
64
 
67
65
  it('should be able to set many values', async () => {
@@ -69,7 +67,7 @@ export function describeAztecMap(
69
67
  await map.setMany(pairs);
70
68
 
71
69
  for (const { key, value } of pairs) {
72
- expect(await get(key)).to.equal(value);
70
+ expect(await get(key)).toBe(value);
73
71
  }
74
72
  });
75
73
 
@@ -77,14 +75,14 @@ export function describeAztecMap(
77
75
  await map.set('foo', 'bar');
78
76
  await map.set('foo', 'baz');
79
77
 
80
- expect(await get('foo')).to.equal('baz');
78
+ expect(await get('foo')).toBe('baz');
81
79
  });
82
80
 
83
81
  it('should be able to set values if they do not exist', async () => {
84
- expect(await map.setIfNotExists('foo', 'bar')).to.equal(true);
85
- expect(await map.setIfNotExists('foo', 'baz')).to.equal(false);
82
+ expect(await map.setIfNotExists('foo', 'bar')).toBe(true);
83
+ expect(await map.setIfNotExists('foo', 'baz')).toBe(false);
86
84
 
87
- expect(await get('foo')).to.equal('bar');
85
+ expect(await get('foo')).toBe('bar');
88
86
  });
89
87
 
90
88
  it('should be able to delete values', async () => {
@@ -93,56 +91,56 @@ export function describeAztecMap(
93
91
 
94
92
  await map.delete('foo');
95
93
 
96
- expect(await get('foo')).to.equal(undefined);
97
- expect(await get('baz')).to.equal('qux');
94
+ expect(await get('foo')).toBe(undefined);
95
+ expect(await get('baz')).toBe('qux');
98
96
  });
99
97
 
100
98
  it('should be able to return size of the map', async () => {
101
99
  await map.set('foo', 'bar');
102
- expect(await size()).to.equal(1);
100
+ expect(await size()).toBe(1);
103
101
  await map.set('baz', 'qux');
104
- expect(await size()).to.equal(2);
102
+ expect(await size()).toBe(2);
105
103
 
106
104
  await map.delete('foo');
107
- expect(await size()).to.equal(1);
105
+ expect(await size()).toBe(1);
108
106
  });
109
107
 
110
108
  it('returns 0 for empty map size', async () => {
111
- expect(await size()).to.equal(0);
109
+ expect(await size()).toBe(0);
112
110
  });
113
111
 
114
112
  it('calculates size correctly across multiple operations', async () => {
115
- expect(await size()).to.equal(0);
113
+ expect(await size()).toBe(0);
116
114
 
117
115
  // Add items
118
116
  await map.set('a', 'value1');
119
117
  await map.set('b', 'value2');
120
118
  await map.set('c', 'value3');
121
- expect(await size()).to.equal(3);
119
+ expect(await size()).toBe(3);
122
120
 
123
121
  // Update existing (size should not change)
124
122
  await map.set('b', 'updated');
125
- expect(await size()).to.equal(3);
123
+ expect(await size()).toBe(3);
126
124
 
127
125
  // Delete some
128
126
  await map.delete('a');
129
- expect(await size()).to.equal(2);
127
+ expect(await size()).toBe(2);
130
128
 
131
129
  // Delete all
132
130
  await map.delete('b');
133
131
  await map.delete('c');
134
- expect(await size()).to.equal(0);
132
+ expect(await size()).toBe(0);
135
133
  });
136
134
 
137
135
  it('should be able to iterate over entries when there are no keys', async () => {
138
- expect(await entries()).to.deep.equal([]);
136
+ expect(await entries()).toEqual([]);
139
137
  });
140
138
 
141
139
  it('should be able to iterate over entries', async () => {
142
140
  await map.set('foo', 'bar');
143
141
  await map.set('baz', 'qux');
144
142
 
145
- expect(await entries()).to.deep.equal([
143
+ expect(await entries()).toEqual([
146
144
  ['baz', 'qux'],
147
145
  ['foo', 'bar'],
148
146
  ]);
@@ -152,21 +150,21 @@ export function describeAztecMap(
152
150
  await map.set('foo', 'bar');
153
151
  await map.set('baz', 'quux');
154
152
 
155
- expect(await values()).to.deep.equal(['quux', 'bar']);
153
+ expect(await values()).toEqual(['quux', 'bar']);
156
154
  });
157
155
 
158
156
  it('should be able to iterate over keys', async () => {
159
157
  await map.set('foo', 'bar');
160
158
  await map.set('baz', 'qux');
161
159
 
162
- expect(await keys()).to.deep.equal(['baz', 'foo']);
160
+ expect(await keys()).toEqual(['baz', 'foo']);
163
161
  });
164
162
 
165
163
  it('should be able to iterate over string keys that represent numbers', async () => {
166
164
  await map.set('0x22', 'bar');
167
165
  await map.set('0x31', 'qux');
168
166
 
169
- expect(await keys()).to.deep.equal(['0x22', '0x31']);
167
+ expect(await keys()).toEqual(['0x22', '0x31']);
170
168
  });
171
169
 
172
170
  for (const [name, data] of [
@@ -186,14 +184,14 @@ export function describeAztecMap(
186
184
  await map.set(c, 'c');
187
185
  await map.set(d, 'd');
188
186
 
189
- expect(await keys()).to.deep.equal([a, b, c, d]);
190
- expect(await keys({ start: b, end: c })).to.deep.equal([b]);
191
- expect(await keys({ start: b })).to.deep.equal([b, c, d]);
192
- expect(await keys({ end: c })).to.deep.equal([a, b]);
193
- expect(await keys({ start: b, end: c, reverse: true })).to.deep.equal([c]);
194
- expect(await keys({ start: b, limit: 1 })).to.deep.equal([b]);
195
- expect(await keys({ start: b, reverse: true })).to.deep.equal([d, c]);
196
- expect(await keys({ end: b, reverse: true })).to.deep.equal([b, a]);
187
+ expect(await keys()).toEqual([a, b, c, d]);
188
+ expect(await keys({ start: b, end: c })).toEqual([b]);
189
+ expect(await keys({ start: b })).toEqual([b, c, d]);
190
+ expect(await keys({ end: c })).toEqual([a, b]);
191
+ expect(await keys({ start: b, end: c, reverse: true })).toEqual([c]);
192
+ expect(await keys({ start: b, limit: 1 })).toEqual([b]);
193
+ expect(await keys({ start: b, reverse: true })).toEqual([d, c]);
194
+ expect(await keys({ end: b, reverse: true })).toEqual([b, a]);
197
195
  });
198
196
  }
199
197
  });