Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions yarn-project/kv-store/.mocharc.json

This file was deleted.

16 changes: 3 additions & 13 deletions yarn-project/kv-store/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
"build": "yarn clean && ../scripts/tsc.sh",
"build:dev": "../scripts/tsc.sh --watch",
"clean": "rm -rf ./dest .tsbuildinfo",
"test:node": "NODE_NO_WARNINGS=1 mocha --config ./.mocharc.json",
"test:node": "vitest run --project node",
"test:browser": "bash scripts/run-browser-tests.sh",
"bench:browser": "VITE_BENCH=1 vitest run --config ./vitest.config.ts src/bench",
"test": "yarn test:node && yarn test:browser",
"bench:browser": "VITE_BENCH=1 vitest run --project browser src/bench",
"test": "vitest run",
"test:jest": "NODE_NO_WARNINGS=1 node --experimental-vm-modules ../node_modules/.bin/jest --passWithNoTests --maxWorkers=${JEST_MAX_WORKERS:-8}"
},
"inherits": [
Expand All @@ -41,23 +41,13 @@
},
"devDependencies": {
"@jest/globals": "^30.0.0",
"@types/chai": "^5.0.1",
"@types/chai-as-promised": "^8.0.1",
"@types/jest": "^30.0.0",
"@types/mocha": "^10.0.10",
"@types/mocha-each": "^2.0.4",
"@types/node": "^22.15.17",
"@types/sinon": "^17.0.3",
"@typescript/native-preview": "7.0.0-dev.20260113.1",
"@vitest/browser-playwright": "^4.0.0",
"buffer": "^6.0.3",
"chai": "^5.1.2",
"chai-as-promised": "^8.0.1",
"jest": "^30.0.0",
"mocha": "^10.8.2",
"mocha-each": "^2.0.1",
"playwright": "1.49.0",
"sinon": "^19.0.2",
"ts-node": "^10.9.1",
"typescript": "^5.3.3",
"util": "^0.12.5",
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/kv-store/package.local.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"scripts": {
"test": "yarn test:node && yarn test:browser",
"test": "vitest run",
"test:browser": "bash scripts/run-browser-tests.sh"
}
}
18 changes: 4 additions & 14 deletions yarn-project/kv-store/scripts/run_test.sh
Original file line number Diff line number Diff line change
@@ -1,20 +1,10 @@
#!/usr/bin/env bash
# Runs a single kv-store test file. Dispatches to vitest+chromium for
# browser tests (under src/indexeddb or src/sqlite-opfs) and to mocha for
# everything else. Emitted by yarn-project/kv-store/bootstrap.sh test_cmds
# for CI per-file fan-out and runnable directly for local reproduction:
#
# yarn-project/kv-store/scripts/run_test.sh src/lmdb-v2/store.test.ts
# Runs a single kv-store test file via vitest. The vitest config
# (vitest.config.ts, projects array) determines whether the file runs
# in node or browser environment based on its path.
source $(git rev-parse --show-toplevel)/ci3/source

test=${1:?"Usage: $0 <test-file relative to kv-store/>"}
cd ..

case "$test" in
src/indexeddb/*|src/sqlite-opfs/*)
exec yarn vitest run --config ./vitest.config.ts "$test"
;;
*)
NODE_NO_WARNINGS=1 exec yarn mocha --config ./.mocharc.json "$test"
;;
esac
NODE_NO_WARNINGS=1 exec yarn vitest run --config ./vitest.config.ts "$test"
26 changes: 12 additions & 14 deletions yarn-project/kv-store/src/indexeddb/version_management.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { EthAddress } from '@aztec/foundation/eth-address';
import { DatabaseVersion } from '@aztec/stdlib/database-version/version';

import { expect } from 'chai';

import { mockLogger } from '../interfaces/utils.js';
import { initStoreForRollupAndSchemaVersion } from '../utils.js';
import { AztecIndexedDBStore } from './store.js';
Expand Down Expand Up @@ -31,8 +29,8 @@ describe('IndexedDB Version Management', () => {
const stored = await versionSingleton.getAsync();

const storedVersion = DatabaseVersion.fromBuffer(Buffer.from(stored!, 'utf-8'));
expect(storedVersion.schemaVersion).to.equal(schemaVersion);
expect(storedVersion.rollupAddress.toString()).to.equal(rollupAddress.toString());
expect(storedVersion.schemaVersion).toBe(schemaVersion);
expect(storedVersion.rollupAddress.toString()).toBe(rollupAddress.toString());
});
});

Expand All @@ -46,7 +44,7 @@ describe('IndexedDB Version Management', () => {
await initStoreForRollupAndSchemaVersion(store, schemaVersion, rollupAddress, mockLogger);

// Data should still exist
expect(await testMap.getAsync('key')).to.equal('value');
expect(await testMap.getAsync('key')).toBe('value');
});
});

Expand All @@ -60,7 +58,7 @@ describe('IndexedDB Version Management', () => {
const newRollupAddress = EthAddress.random();
await initStoreForRollupAndSchemaVersion(store, schemaVersion, newRollupAddress, mockLogger);

expect(await testMap.getAsync('key')).to.be.undefined;
expect(await testMap.getAsync('key')).toBeUndefined();
});
});

Expand All @@ -73,7 +71,7 @@ describe('IndexedDB Version Management', () => {

await initStoreForRollupAndSchemaVersion(store, schemaVersion + 1, rollupAddress, mockLogger);

expect(await testMap.getAsync('key')).to.be.undefined;
expect(await testMap.getAsync('key')).toBeUndefined();
});

it('clears store when schema version decreases', async () => {
Expand All @@ -84,7 +82,7 @@ describe('IndexedDB Version Management', () => {

await initStoreForRollupAndSchemaVersion(store, schemaVersion - 1, rollupAddress, mockLogger);

expect(await testMap.getAsync('key')).to.be.undefined;
expect(await testMap.getAsync('key')).toBeUndefined();
});
});

Expand All @@ -98,7 +96,7 @@ describe('IndexedDB Version Management', () => {

await initStoreForRollupAndSchemaVersion(store, schemaVersion, rollupAddress, mockLogger);

expect(await testMap.getAsync('key')).to.be.undefined;
expect(await testMap.getAsync('key')).toBeUndefined();
});

it('clears store when version has wrong structure', async () => {
Expand All @@ -110,7 +108,7 @@ describe('IndexedDB Version Management', () => {

await initStoreForRollupAndSchemaVersion(store, schemaVersion, rollupAddress, mockLogger);

expect(await testMap.getAsync('key')).to.be.undefined;
expect(await testMap.getAsync('key')).toBeUndefined();
});
});

Expand All @@ -126,13 +124,13 @@ describe('IndexedDB Version Management', () => {
// Init with new version management should clear the old data
await initStoreForRollupAndSchemaVersion(store, schemaVersion, rollupAddress, mockLogger);

expect(await testMap.getAsync('key')).to.be.undefined;
expect(await testMap.getAsync('key')).toBeUndefined();

const versionSingleton = store.openSingleton<string>('dbVersion');
const stored = await versionSingleton.getAsync();
const storedVersion = DatabaseVersion.fromBuffer(Buffer.from(stored!, 'utf-8'));
expect(storedVersion.schemaVersion).to.equal(schemaVersion);
expect(storedVersion.rollupAddress.toString()).to.equal(rollupAddress.toString());
expect(storedVersion.schemaVersion).toBe(schemaVersion);
expect(storedVersion.rollupAddress.toString()).toBe(rollupAddress.toString());
});

it('clears store with old format even if rollup address matches', async () => {
Expand All @@ -145,7 +143,7 @@ describe('IndexedDB Version Management', () => {

await initStoreForRollupAndSchemaVersion(store, schemaVersion, rollupAddress, mockLogger);

expect(await testMap.getAsync('key')).to.be.undefined;
expect(await testMap.getAsync('key')).toBeUndefined();
});
});
});
Expand Down
68 changes: 33 additions & 35 deletions yarn-project/kv-store/src/interfaces/array_test_suite.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { toArray } from '@aztec/foundation/iterable';

import { expect } from 'chai';

import type { AztecArray, AztecAsyncArray } from './array.js';
import type { AztecAsyncKVStore, AztecKVStore } from './store.js';
import { isSyncStore } from './utils.js';
Expand Down Expand Up @@ -53,64 +51,64 @@ export function describeAztecArray(
await arr.push(2);
await arr.push(3);

expect(await length()).to.equal(3);
expect(await length()).toBe(3);

expect(await arr.pop()).to.equal(3);
expect(await arr.pop()).to.equal(2);
expect(await arr.pop()).to.equal(1);
expect(await arr.pop()).to.equal(undefined);
expect(await arr.pop()).toBe(3);
expect(await arr.pop()).toBe(2);
expect(await arr.pop()).toBe(1);
expect(await arr.pop()).toBe(undefined);
});

it('should be able to get values by index', async () => {
await arr.push(1);
await arr.push(2);
await arr.push(3);

expect(await at(0)).to.equal(1);
expect(await at(1)).to.equal(2);
expect(await at(2)).to.equal(3);
expect(await at(3)).to.equal(undefined);
expect(await at(-1)).to.equal(3);
expect(await at(-2)).to.equal(2);
expect(await at(-3)).to.equal(1);
expect(await at(-4)).to.equal(undefined);
expect(await at(0)).toBe(1);
expect(await at(1)).toBe(2);
expect(await at(2)).toBe(3);
expect(await at(3)).toBe(undefined);
expect(await at(-1)).toBe(3);
expect(await at(-2)).toBe(2);
expect(await at(-3)).toBe(1);
expect(await at(-4)).toBe(undefined);
});

it('should be able to set values by index', async () => {
await arr.push(1);
await arr.push(2);
await arr.push(3);

expect(await arr.setAt(0, 4)).to.equal(true);
expect(await arr.setAt(1, 5)).to.equal(true);
expect(await arr.setAt(2, 6)).to.equal(true);
expect(await arr.setAt(0, 4)).toBe(true);
expect(await arr.setAt(1, 5)).toBe(true);
expect(await arr.setAt(2, 6)).toBe(true);

expect(await arr.setAt(3, 7)).to.equal(false);
expect(await arr.setAt(3, 7)).toBe(false);

expect(await at(0)).to.equal(4);
expect(await at(1)).to.equal(5);
expect(await at(2)).to.equal(6);
expect(await at(3)).to.equal(undefined);
expect(await at(0)).toBe(4);
expect(await at(1)).toBe(5);
expect(await at(2)).toBe(6);
expect(await at(3)).toBe(undefined);

expect(await arr.setAt(-1, 8)).to.equal(true);
expect(await arr.setAt(-2, 9)).to.equal(true);
expect(await arr.setAt(-3, 10)).to.equal(true);
expect(await arr.setAt(-1, 8)).toBe(true);
expect(await arr.setAt(-2, 9)).toBe(true);
expect(await arr.setAt(-3, 10)).toBe(true);

expect(await arr.setAt(-4, 11)).to.equal(false);
expect(await arr.setAt(-4, 11)).toBe(false);

expect(await at(-1)).to.equal(8);
expect(await at(-2)).to.equal(9);
expect(await at(-3)).to.equal(10);
expect(await at(-4)).to.equal(undefined);
expect(await at(-1)).toBe(8);
expect(await at(-2)).toBe(9);
expect(await at(-3)).toBe(10);
expect(await at(-4)).toBe(undefined);
});

it('should be able to iterate over values', async () => {
await arr.push(1);
await arr.push(2);
await arr.push(3);

expect(await values()).to.deep.equal([1, 2, 3]);
expect(await entries()).to.deep.equal([
expect(await values()).toEqual([1, 2, 3]);
expect(await entries()).toEqual([
[0, 1],
[1, 2],
[2, 3],
Expand All @@ -123,8 +121,8 @@ export function describeAztecArray(
await arr.push(3);

const arr2 = store.openArray<number>('test');
expect(await length(arr2)).to.equal(3);
expect(await values(arr2)).to.deep.equal(await values());
expect(await length(arr2)).toBe(3);
expect(await values(arr2)).toEqual(await values());
});
});
}
Loading
Loading