diff --git a/.github/workflows/api-publish.yml b/.github/workflows/api-publish.yml index 3e02be23..9bcc4e17 100644 --- a/.github/workflows/api-publish.yml +++ b/.github/workflows/api-publish.yml @@ -24,6 +24,7 @@ jobs: node-version: 'lts/*' registry-url: https://registry.npmjs.org/ - run: npm ci + - run: npm run lint - run: npm run build:docs - uses: actions/upload-pages-artifact@v3 with: diff --git a/.github/workflows/npm-publish.yml b/.github/workflows/npm-publish.yml index a1266f42..e004810a 100644 --- a/.github/workflows/npm-publish.yml +++ b/.github/workflows/npm-publish.yml @@ -16,6 +16,7 @@ jobs: node-version: 'lts/*' registry-url: https://registry.npmjs.org/ - run: npm ci + - run: npm run lint - run: npm test - run: npm publish env: diff --git a/.github/workflows/run-linter.yml b/.github/workflows/run-linter.yml new file mode 100644 index 00000000..fd890fb0 --- /dev/null +++ b/.github/workflows/run-linter.yml @@ -0,0 +1,18 @@ +--- +name: Run Linter + +on: [push, pull_request] + +jobs: + lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + node-version: 'lts/*' + registry-url: https://registry.npmjs.org/ + - name: Install dependencies + run: npm ci + - name: Run linter + run: npm run lint diff --git a/.github/workflows/run-test-node-min-ver.yml b/.github/workflows/run-test-node-min-ver.yml index 03b4474d..82e0f8e0 100644 --- a/.github/workflows/run-test-node-min-ver.yml +++ b/.github/workflows/run-test-node-min-ver.yml @@ -14,8 +14,6 @@ jobs: registry-url: https://registry.npmjs.org/ - name: Install dependencies run: npm ci - - name: Run linter - run: npm run lint - name: Run tests run: npm run test:ci test-browser: @@ -28,8 +26,6 @@ jobs: registry-url: https://registry.npmjs.org/ - name: Install dependencies run: npm ci - - name: Run linter - run: npm run lint - name: Run a webrtc relay in the background run: npm run webrtc:background - name: Run browser tests diff --git a/.github/workflows/run-test.yml b/.github/workflows/run-test.yml index 7f9231af..736a017a 100644 --- a/.github/workflows/run-test.yml +++ b/.github/workflows/run-test.yml @@ -14,8 +14,6 @@ jobs: registry-url: https://registry.npmjs.org/ - name: Install dependencies run: npm ci - - name: Run linter - run: npm run lint - name: Run tests run: npm run test:ci test-browser: @@ -28,8 +26,6 @@ jobs: registry-url: https://registry.npmjs.org/ - name: Install dependencies run: npm ci - - name: Run linter - run: npm run lint - name: Run a webrtc relay in the background run: npm run webrtc:background - name: Run browser tests diff --git a/.gitignore b/.gitignore index 7e261d75..eaf0bd6e 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,10 @@ test/ipfs/ test/browser/ipfs/ test/browser/bundle.js* +# Don't track test databases +test-data/ +benchmark-data/ + # Don't track builds in git # Distribution builds are available via npm dist/ diff --git a/benchmarks/log-append.js b/benchmarks/log-append.js index cf71abc2..5ed9adb7 100644 --- a/benchmarks/log-append.js +++ b/benchmarks/log-append.js @@ -28,7 +28,7 @@ const queryLoop = async () => { console.log('Benchmark duration is ' + benchmarkDuration + ' seconds') - await rmrf('./orbitdb') + await rmrf('./benchmarks/test-data/orbitdb') const identities = await Identities() const testIdentity = await identities.createIdentity({ id: 'userA' }) @@ -59,7 +59,7 @@ const queryLoop = async () => { } if (seconds >= benchmarkDuration) { clearInterval(interval) - await rmrf('./orbitdb') + await rmrf('./benchmarks/test-data/orbitdb') process.exit(0) } console.log(`${queriesPerSecond} queries per second, ${totalQueries} queries in ${seconds} seconds`) diff --git a/benchmarks/log-iterator.js b/benchmarks/log-iterator.js index b6abb99f..fad9f3fb 100644 --- a/benchmarks/log-iterator.js +++ b/benchmarks/log-iterator.js @@ -6,7 +6,7 @@ import { rimraf as rmrf } from 'rimraf' ;(async () => { console.log('Starting benchmark...') - await rmrf('./orbitdb') + await rmrf('./benchmarks/test-data/orbitdb') const identities = await Identities() const testIdentity = await identities.createIdentity({ id: 'userA' }) @@ -55,7 +55,7 @@ import { rimraf as rmrf } from 'rimraf' console.log(`Iterating ${all.length} entries took ${duration2} ms, ${operationsPerSecond2} ops/s, ${millisecondsPerOp2} ms/op`) - await rmrf('./orbitdb') + await rmrf('./benchmarks/test-data/orbitdb') process.exit(0) })() diff --git a/benchmarks/orbitdb-documents.js b/benchmarks/orbitdb-documents.js index 110b4411..b6dbba17 100644 --- a/benchmarks/orbitdb-documents.js +++ b/benchmarks/orbitdb-documents.js @@ -11,8 +11,8 @@ EventEmitter.defaultMaxListeners = 10000 const entryCount = 1000 - await rmrf('./ipfs') - await rmrf('./orbitdb') + await rmrf('./benchmarks/test-data/ipfs') + await rmrf('./benchmarks/test-data/orbitdb') const ipfs = await createHelia() const orbitdb = await createOrbitDB({ ipfs }) @@ -61,8 +61,8 @@ EventEmitter.defaultMaxListeners = 10000 await orbitdb.stop() await ipfs.stop() - await rmrf('./ipfs') - await rmrf('./orbitdb') + await rmrf('./benchmarks/test-data/ipfs') + await rmrf('./benchmarks/test-data/orbitdb') process.exit(0) })() diff --git a/benchmarks/orbitdb-events.js b/benchmarks/orbitdb-events.js index 0a3cc560..a13784a5 100644 --- a/benchmarks/orbitdb-events.js +++ b/benchmarks/orbitdb-events.js @@ -10,8 +10,8 @@ EventEmitter.defaultMaxListeners = 10000 const entryCount = 1000 - await rmrf('./ipfs') - await rmrf('./orbitdb') + await rmrf('./benchmarks/test-data/ipfs') + await rmrf('./benchmarks/test-data/orbitdb') const ipfs = await createHelia() const orbitdb = await createOrbitDB({ ipfs }) @@ -53,8 +53,8 @@ EventEmitter.defaultMaxListeners = 10000 await orbitdb.stop() await ipfs.stop() - await rmrf('./ipfs') - await rmrf('./orbitdb') + await rmrf('./benchmarks/test-data/ipfs') + await rmrf('./benchmarks/test-data/orbitdb') process.exit(0) })() diff --git a/benchmarks/orbitdb-keyvalue.js b/benchmarks/orbitdb-keyvalue.js index 656f5c94..3a941d9d 100644 --- a/benchmarks/orbitdb-keyvalue.js +++ b/benchmarks/orbitdb-keyvalue.js @@ -10,8 +10,8 @@ EventEmitter.defaultMaxListeners = 10000 const entryCount = 1000 - await rmrf('./ipfs') - await rmrf('./orbitdb') + await rmrf('./benchmarks/test-data/ipfs') + await rmrf('./benchmarks/test-data/orbitdb') const ipfs = await createHelia() const orbitdb = await createOrbitDB({ ipfs }) @@ -53,8 +53,8 @@ EventEmitter.defaultMaxListeners = 10000 await orbitdb.stop() await ipfs.stop() - await rmrf('./ipfs') - await rmrf('./orbitdb') + await rmrf('./benchmarks/test-data/ipfs') + await rmrf('./benchmarks/test-data/orbitdb') process.exit(0) })() diff --git a/benchmarks/orbitdb-kv-indexed.js b/benchmarks/orbitdb-kv-indexed.js index 38dc69ec..4a16e8bf 100644 --- a/benchmarks/orbitdb-kv-indexed.js +++ b/benchmarks/orbitdb-kv-indexed.js @@ -10,8 +10,8 @@ EventEmitter.defaultMaxListeners = 10000 const entryCount = 1000 - await rmrf('./ipfs') - await rmrf('./orbitdb') + await rmrf('./benchmarks/test-data/ipfs') + await rmrf('./benchmarks/test-data/orbitdb') const ipfs = await createHelia() const orbitdb = await createOrbitDB({ ipfs }) @@ -53,8 +53,8 @@ EventEmitter.defaultMaxListeners = 10000 await orbitdb.stop() await ipfs.stop() - await rmrf('./ipfs') - await rmrf('./orbitdb') + await rmrf('./benchmarks/test-data/ipfs') + await rmrf('./benchmarks/test-data/orbitdb') process.exit(0) })() diff --git a/benchmarks/orbitdb-replicate.js b/benchmarks/orbitdb-replicate.js index 99170364..192063eb 100644 --- a/benchmarks/orbitdb-replicate.js +++ b/benchmarks/orbitdb-replicate.js @@ -12,13 +12,13 @@ EventEmitter.defaultMaxListeners = 10000 const entryCount = 1000 - await rmrf('./orbitdb1') - await rmrf('./orbitdb2') + await rmrf('./benchmarks/test-data/orbitdb1') + await rmrf('./benchmarks/test-data/orbitdb2') const [ipfs1, ipfs2] = await Promise.all([createHelia(), createHelia()]) - const orbitdb1 = await createOrbitDB({ ipfs: ipfs1, directory: './orbitdb1' }) - const orbitdb2 = await createOrbitDB({ ipfs: ipfs2, directory: './orbitdb2' }) + const orbitdb1 = await createOrbitDB({ ipfs: ipfs1, directory: './benchmarks/test-data/orbitdb1' }) + const orbitdb2 = await createOrbitDB({ ipfs: ipfs2, directory: './benchmarks/test-data/orbitdb2' }) await connectPeers(ipfs1, ipfs2) @@ -67,8 +67,8 @@ EventEmitter.defaultMaxListeners = 10000 await ipfs1.stop() await ipfs2.stop() - await rmrf('./orbitdb1') - await rmrf('./orbitdb2') + await rmrf('./benchmarks/test-data/orbitdb1') + await rmrf('./benchmarks/test-data/orbitdb2') process.exit(0) })() diff --git a/package-lock.json b/package-lock.json index 39099daf..9e148367 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,6 +11,7 @@ "dependencies": { "@ipld/dag-cbor": "^9.0.6", "@libp2p/crypto": "^5.0.5", + "abortable-iterator": "5.1.0", "it-pipe": "^3.0.1", "level": "^8.0.0", "lru": "^3.1.0", @@ -5373,6 +5374,16 @@ "integrity": "sha512-PMKqKW8CHeXFYW9GdeavZbOt2qE3/UTv5FKk8PGK583pRmvdGq/d8M9UpLBzAL95Ss3Fe3LvGjLhWeWo9d0QAg==", "dev": true }, + "node_modules/abortable-iterator": { + "version": "5.1.0", + "resolved": "https://registry.npmjs.org/abortable-iterator/-/abortable-iterator-5.1.0.tgz", + "integrity": "sha512-a3nRG0GOGw3IPFA2hdhrZU+QuD3mA6i+5f4YM/Obe+D5lYccxScI32rAIHAW5ttFV7+beiof09gHav4qUEZDwg==", + "license": "Apache-2.0 OR MIT", + "dependencies": { + "get-iterator": "^2.0.0", + "it-stream-types": "^2.0.1" + } + }, "node_modules/abstract-level": { "version": "1.0.4", "resolved": "https://registry.npmjs.org/abstract-level/-/abstract-level-1.0.4.tgz", @@ -8766,8 +8777,7 @@ "node_modules/get-iterator": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/get-iterator/-/get-iterator-2.0.1.tgz", - "integrity": "sha512-7HuY/hebu4gryTDT7O/XY/fvY9wRByEGdK6QOa4of8npTcv0+NS6frFKABcf6S9EBAsveTuKTsZQQBFMMNILIg==", - "dev": true + "integrity": "sha512-7HuY/hebu4gryTDT7O/XY/fvY9wRByEGdK6QOa4of8npTcv0+NS6frFKABcf6S9EBAsveTuKTsZQQBFMMNILIg==" }, "node_modules/get-package-type": { "version": "0.1.0", diff --git a/package.json b/package.json index 12400e56..2aa0df74 100644 --- a/package.json +++ b/package.json @@ -20,6 +20,7 @@ "dependencies": { "@ipld/dag-cbor": "^9.0.6", "@libp2p/crypto": "^5.0.5", + "abortable-iterator": "5.1.0", "it-pipe": "^3.0.1", "level": "^8.0.0", "lru": "^3.1.0", diff --git a/src/database.js b/src/database.js index afae4d4c..d20f3dcb 100644 --- a/src/database.js +++ b/src/database.js @@ -42,7 +42,7 @@ const defaultCacheSize = 1000 * @return {module:Databases~Database} An instance of Database. * @instance */ -const Database = async ({ ipfs, identity, address, name, access, directory, meta, headsStorage, entryStorage, indexStorage, referencesCount, syncAutomatically, onUpdate }) => { +const Database = async ({ ipfs, identity, address, name, access, directory, meta, headsStorage, entryStorage, indexStorage, referencesCount, syncAutomatically, onUpdate, events }) => { /** * @namespace module:Databases~Database * @description The instance returned by {@link module:Database~Database}. @@ -93,24 +93,27 @@ const Database = async ({ ipfs, identity, address, name, access, directory, meta meta = meta || {} referencesCount = Number(referencesCount) > -1 ? referencesCount : defaultReferencesCount + events = events || new EventEmitter() + entryStorage = entryStorage || await ComposedStorage( await LRUStorage({ size: defaultCacheSize }), - await IPFSBlockStorage({ ipfs, pin: true }) + await IPFSBlockStorage({ ipfs, pin: true }), + events ) headsStorage = headsStorage || await ComposedStorage( await LRUStorage({ size: defaultCacheSize }), - await LevelStorage({ path: pathJoin(directory, '/log/_heads/') }) + await LevelStorage({ path: pathJoin(directory, '/log/_heads/') }), + events ) indexStorage = indexStorage || await ComposedStorage( await LRUStorage({ size: defaultCacheSize }), - await LevelStorage({ path: pathJoin(directory, '/log/_index/') }) + await LevelStorage({ path: pathJoin(directory, '/log/_index/') }), + events ) - const log = await Log(identity, { logId: address, access, entryStorage, headsStorage, indexStorage }) - - const events = new EventEmitter() + const log = await Log(identity, { logId: address, access, entryStorage, headsStorage, indexStorage, events }) const queue = new PQueue({ concurrency: 1 }) @@ -125,13 +128,17 @@ const Database = async ({ ipfs, identity, address, name, access, directory, meta */ const addOperation = async (op) => { const task = async () => { - const entry = await log.append(op, { referencesCount }) - await sync.add(entry) - if (onUpdate) { - await onUpdate(log, entry) + try { + const entry = await log.append(op, { referencesCount }) + await sync.add(entry) + if (onUpdate) { + await onUpdate(log, entry) + } + events.emit('update', entry) + return entry.hash + } catch (e) { + events.emit('error', e) } - events.emit('update', entry) - return entry.hash } const hash = await queue.add(task) await queue.onIdle() @@ -140,15 +147,19 @@ const Database = async ({ ipfs, identity, address, name, access, directory, meta const applyOperation = async (bytes) => { const task = async () => { - const entry = await Entry.decode(bytes) - if (entry) { - const updated = await log.joinEntry(entry) - if (updated) { - if (onUpdate) { - await onUpdate(log, entry) + try { + const entry = await Entry.decode(bytes) + if (entry) { + const updated = await log.joinEntry(entry) + if (updated) { + if (onUpdate) { + await onUpdate(log, entry) + } + events.emit('update', entry) } - events.emit('update', entry) } + } catch (e) { + events.emit('error', e) } } await queue.add(task) @@ -241,7 +252,7 @@ const Database = async ({ ipfs, identity, address, name, access, directory, meta * @memberof module:Databases~Database * @instance */ - access, + access } } diff --git a/src/databases/documents.js b/src/databases/documents.js index e89d3fc2..263d6757 100644 --- a/src/databases/documents.js +++ b/src/databases/documents.js @@ -25,8 +25,8 @@ const DefaultOptions = { indexBy: '_id' } * @return {module:Databases.Databases-Documents} A Documents function. * @memberof module:Databases */ -const Documents = ({ indexBy } = DefaultOptions) => async ({ ipfs, identity, address, name, access, directory, meta, headsStorage, entryStorage, indexStorage, referencesCount, syncAutomatically, onUpdate }) => { - const database = await Database({ ipfs, identity, address, name, access, directory, meta, headsStorage, entryStorage, indexStorage, referencesCount, syncAutomatically }) +const Documents = ({ indexBy } = DefaultOptions) => async ({ ipfs, identity, address, name, access, directory, meta, headsStorage, entryStorage, indexStorage, referencesCount, syncAutomatically, onUpdate, events }) => { + const database = await Database({ ipfs, identity, address, name, access, directory, meta, headsStorage, entryStorage, indexStorage, referencesCount, syncAutomatically, events }) const { addOperation, log } = database diff --git a/src/databases/events.js b/src/databases/events.js index 1ddfe87f..dca8bc7c 100644 --- a/src/databases/events.js +++ b/src/databases/events.js @@ -15,8 +15,8 @@ const type = 'events' * @return {module:Databases.Databases-Events} A Events function. * @memberof module:Databases */ -const Events = () => async ({ ipfs, identity, address, name, access, directory, meta, headsStorage, entryStorage, indexStorage, referencesCount, syncAutomatically, onUpdate }) => { - const database = await Database({ ipfs, identity, address, name, access, directory, meta, headsStorage, entryStorage, indexStorage, referencesCount, syncAutomatically, onUpdate }) +const Events = () => async ({ ipfs, identity, address, name, access, directory, meta, headsStorage, entryStorage, indexStorage, referencesCount, syncAutomatically, onUpdate, events }) => { + const database = await Database({ ipfs, identity, address, name, access, directory, meta, headsStorage, entryStorage, indexStorage, referencesCount, syncAutomatically, onUpdate, events }) const { addOperation, log } = database diff --git a/src/databases/keyvalue-indexed.js b/src/databases/keyvalue-indexed.js index ceff5361..f336ef86 100644 --- a/src/databases/keyvalue-indexed.js +++ b/src/databases/keyvalue-indexed.js @@ -109,7 +109,7 @@ const Index = ({ directory } = {}) => async () => { * function. * @memberof module:Databases */ -const KeyValueIndexed = () => async ({ ipfs, identity, address, name, access, directory, meta, headsStorage, entryStorage, indexStorage, referencesCount, syncAutomatically, onUpdate }) => { +const KeyValueIndexed = () => async ({ ipfs, identity, address, name, access, directory, meta, headsStorage, entryStorage, indexStorage, referencesCount, syncAutomatically, onUpdate, events }) => { // Set up the directory for an index directory = pathJoin(directory || './orbitdb', `./${address}/_index/`) @@ -117,7 +117,7 @@ const KeyValueIndexed = () => async ({ ipfs, identity, address, name, access, di const index = await Index({ directory })() // Set up the underlying KeyValue database - const keyValueStore = await KeyValue()({ ipfs, identity, address, name, access, directory, meta, headsStorage, entryStorage, indexStorage, referencesCount, syncAutomatically, onUpdate: index.update }) + const keyValueStore = await KeyValue()({ ipfs, identity, address, name, access, directory, meta, headsStorage, entryStorage, indexStorage, referencesCount, syncAutomatically, onUpdate: index.update, events }) /** * Gets a value from the store by key. diff --git a/src/databases/keyvalue.js b/src/databases/keyvalue.js index 0e2bc624..f37e71f6 100644 --- a/src/databases/keyvalue.js +++ b/src/databases/keyvalue.js @@ -15,8 +15,8 @@ const type = 'keyvalue' * @return {module:Databases.Databases-KeyValue} A KeyValue function. * @memberof module:Databases */ -const KeyValue = () => async ({ ipfs, identity, address, name, access, directory, meta, headsStorage, entryStorage, indexStorage, referencesCount, syncAutomatically, onUpdate }) => { - const database = await Database({ ipfs, identity, address, name, access, directory, meta, headsStorage, entryStorage, indexStorage, referencesCount, syncAutomatically, onUpdate }) +const KeyValue = () => async ({ ipfs, identity, address, name, access, directory, meta, headsStorage, entryStorage, indexStorage, referencesCount, syncAutomatically, onUpdate, events }) => { + const database = await Database({ ipfs, identity, address, name, access, directory, meta, headsStorage, entryStorage, indexStorage, referencesCount, syncAutomatically, onUpdate, events }) const { addOperation, log } = database diff --git a/src/oplog/log.js b/src/oplog/log.js index dd76c8cd..b24d2d76 100644 --- a/src/oplog/log.js +++ b/src/oplog/log.js @@ -13,6 +13,7 @@ import Clock, { tickClock } from './clock.js' import Heads from './heads.js' import ConflictResolution from './conflict-resolution.js' import MemoryStorage from '../storage/memory.js' +import { EventEmitter } from 'events' const { LastWriteWins, NoZeroes } = ConflictResolution @@ -56,7 +57,7 @@ const DefaultAccessController = async () => { * @memberof module:Log * @instance */ -const Log = async (identity, { logId, logHeads, access, entryStorage, headsStorage, indexStorage, sortFn } = {}) => { +const Log = async (identity, { logId, logHeads, access, entryStorage, headsStorage, indexStorage, sortFn, events } = {}) => { /** * @namespace Log * @description The instance returned by {@link module:Log} @@ -86,6 +87,8 @@ const Log = async (identity, { logId, logHeads, access, entryStorage, headsStora const appendQueue = new PQueue({ concurrency: 1 }) const joinQueue = new PQueue({ concurrency: 1 }) + events = events || new EventEmitter() + /** * Returns the clock of the log. * @return {module:Clock} diff --git a/src/storage/composed.js b/src/storage/composed.js index 91b9b8d3..70c1b227 100644 --- a/src/storage/composed.js +++ b/src/storage/composed.js @@ -12,6 +12,8 @@ * await ComposedStorage(storage1, await IPFSBlockStorage()) */ +import EventEmitter from 'events' + /** * Creates an instance of ComposedStorage. * @function @@ -21,7 +23,9 @@ * @memberof module:Storage * @instance */ -const ComposedStorage = async (storage1, storage2) => { +const ComposedStorage = async (storage1, storage2, events) => { + events = events || new EventEmitter() + /** * Puts data to all configured storages. * @function @@ -31,8 +35,13 @@ const ComposedStorage = async (storage1, storage2) => { * @instance */ const put = async (hash, data) => { - await storage1.put(hash, data) - await storage2.put(hash, data) + try { + await storage1.put(hash, data) + await storage2.put(hash, data) + } catch (e) { + console.error(`Error while putting hash ${hash} into composed storage`, e) + events.emit('error', e) + } } /** @@ -47,14 +56,21 @@ const ComposedStorage = async (storage1, storage2) => { * @instance */ const get = async (hash) => { - let value = await storage1.get(hash) - if (!value) { - value = await storage2.get(hash) - if (value) { - await storage1.put(hash, value) + try { + let value = await storage1.get(hash) + if (!value) { + value = await storage2.get(hash) + if (value) { + await storage1.put(hash, value) + } } + return value + } catch (e) { + console.error(`Error while getting hash ${hash} from composed storage`, e) + events.emit('error', e) } - return value + + return undefined } /** diff --git a/src/sync.js b/src/sync.js index d5adfe0d..7e2963f0 100644 --- a/src/sync.js +++ b/src/sync.js @@ -3,6 +3,7 @@ import PQueue from 'p-queue' import { EventEmitter } from 'events' import { TimeoutController } from 'timeout-abort-controller' import pathJoin from './utils/path-join.js' +import { abortableSource } from 'abortable-iterator' const DefaultTimeout = 30000 // 30 seconds @@ -143,17 +144,17 @@ const Sync = async ({ ipfs, log, events, onSynced, start, timeout }) => { events.emit('join', peerId, heads) } - const sendHeads = (source) => { - return (async function * () { + const sendHeads = (abortController) => (source) => { + return abortableSource((async function * () { const heads = await log.heads() for await (const { bytes } of heads) { yield bytes } - })() + })(), abortController.signal) } - const receiveHeads = (peerId) => async (source) => { - for await (const value of source) { + const receiveHeads = (peerId, abortController) => async (source) => { + for await (const value of abortableSource(source, abortController.signal)) { const headBytes = value.subarray() if (headBytes && onSynced) { await onSynced(headBytes) @@ -166,10 +167,14 @@ const Sync = async ({ ipfs, log, events, onSynced, start, timeout }) => { const handleReceiveHeads = async ({ connection, stream }) => { const peerId = String(connection.remotePeer) + const abortController = new AbortController() try { peers.add(peerId) - await pipe(stream, receiveHeads(peerId), sendHeads, stream) + await pipe(stream, receiveHeads(peerId, abortController), sendHeads(abortController), stream) } catch (e) { + if (!abortController.signal.aborted) { + abortController.abort(e) + } peers.delete(peerId) events.emit('error', e) } @@ -188,18 +193,18 @@ const Sync = async ({ ipfs, log, events, onSynced, start, timeout }) => { return } const timeoutController = new TimeoutController(timeout) + const abortController = new AbortController() const { signal } = timeoutController try { peers.add(peerId) const stream = await libp2p.dialProtocol(remotePeer, headsSyncAddress, { signal }) - await pipe(sendHeads, stream, receiveHeads(peerId)) + await pipe(sendHeads(abortController), stream, receiveHeads(peerId, abortController)) } catch (e) { peers.delete(peerId) - if (e.name === 'UnsupportedProtocolError') { - // Skip peer, they don't have this database currently - } else { - events.emit('error', e) + if (!abortController.signal.aborted) { + abortController.abort(e) } + events.emit('error', e) } finally { if (timeoutController) { timeoutController.clear() diff --git a/test/access-controllers/ipfs-access-controller.test.js b/test/access-controllers/ipfs-access-controller.test.js index cd9748c5..7d7b8f52 100644 --- a/test/access-controllers/ipfs-access-controller.test.js +++ b/test/access-controllers/ipfs-access-controller.test.js @@ -7,8 +7,8 @@ import connectPeers from '../utils/connect-nodes.js' import createHelia from '../utils/create-helia.js' describe('IPFSAccessController', function () { - const dbPath1 = './orbitdb/tests/ipfs-access-controller/1' - const dbPath2 = './orbitdb/tests/ipfs-access-controller/2' + const dbPath1 = './test/test-data/orbitdb/tests/ipfs-access-controller/1' + const dbPath2 = './test/test-data/orbitdb/tests/ipfs-access-controller/2' let ipfs1, ipfs2 let keystore1, keystore2 @@ -50,9 +50,9 @@ describe('IPFSAccessController', function () { await keystore2.close() } - await rimraf('./orbitdb') - await rimraf('./ipfs1') - await rimraf('./ipfs2') + await rimraf('./test/test-data/orbitdb') + await rimraf('./test/test-data/ipfs1') + await rimraf('./test/test-data/ipfs2') }) let accessController diff --git a/test/access-controllers/orbit-db-access-controller.test.js b/test/access-controllers/orbit-db-access-controller.test.js index ab5ab187..635f2198 100644 --- a/test/access-controllers/orbit-db-access-controller.test.js +++ b/test/access-controllers/orbit-db-access-controller.test.js @@ -7,8 +7,8 @@ import OrbitDBAccessController from '../../src/access-controllers/orbitdb.js' import connectPeers from '../utils/connect-nodes.js' import createHelia from '../utils/create-helia.js' -const dbPath1 = './orbitdb/tests/orbitdb-access-controller/1' -const dbPath2 = './orbitdb/tests/orbitdb-access-controller/2' +const dbPath1 = './test/test-data/orbitdb/tests/orbitdb-access-controller/1' +const dbPath2 = './test/test-data/orbitdb/tests/orbitdb-access-controller/2' describe('OrbitDBAccessController', function () { let ipfs1, ipfs2 @@ -49,9 +49,9 @@ describe('OrbitDBAccessController', function () { await ipfs2.stop() } - await rimraf('./orbitdb') - await rimraf('./ipfs1') - await rimraf('./ipfs2') + await rimraf('./test/test-data/orbitdb') + await rimraf('./test/test-data/ipfs1') + await rimraf('./test/test-data/ipfs2') }) describe('Default write access', function () { diff --git a/test/browser/setup-fixtures.js b/test/browser/setup-fixtures.js index 83dd7b30..32d18b43 100644 --- a/test/browser/setup-fixtures.js +++ b/test/browser/setup-fixtures.js @@ -2,7 +2,7 @@ import { privateKeyFromRaw } from '@libp2p/crypto/keys' import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' import { Identities, KeyStore } from '../../src/index.js' -const keysPath = './testkeys' +const keysPath = './test/test-data/testkeys' const isBrowser = () => typeof window !== 'undefined' diff --git a/test/database-replication.test.js b/test/database-replication.test.js index 3d029f44..83109968 100644 --- a/test/database-replication.test.js +++ b/test/database-replication.test.js @@ -10,7 +10,7 @@ import IPFSBlockStorage from '../src/storage/ipfs-block.js' import MemoryStorage from '../src/storage/memory.js' import createHelia from './utils/create-helia.js' -const keysPath = './testkeys' +const keysPath = './test/test-data/testkeys' describe('Database - Replication', function () { let ipfs1, ipfs2 @@ -45,13 +45,13 @@ describe('Database - Replication', function () { await db1.drop() await db1.close() - await rimraf('./orbitdb1') + await rimraf('./test/test-data/orbitdb1') } if (db2) { await db2.drop() await db2.close() - await rimraf('./orbitdb2') + await rimraf('./test/test-data/orbitdb2') } if (ipfs1) { @@ -67,13 +67,13 @@ describe('Database - Replication', function () { } await rimraf(keysPath) - await rimraf('./ipfs1') - await rimraf('./ipfs2') + await rimraf('./test/test-data/ipfs1') + await rimraf('./test/test-data/ipfs2') }) describe('Replicate across peers', () => { beforeEach(async () => { - db1 = await Database({ ipfs: ipfs1, identity: testIdentity1, address: databaseId, accessController, directory: './orbitdb1' }) + db1 = await Database({ ipfs: ipfs1, identity: testIdentity1, address: databaseId, accessController, directory: './test/test-data/orbitdb1' }) }) it('replicates databases across two peers', async () => { @@ -88,7 +88,7 @@ describe('Database - Replication', function () { replicated = expectedEntryHash !== null && entry.hash === expectedEntryHash } - db2 = await Database({ ipfs: ipfs2, identity: testIdentity2, address: databaseId, accessController, directory: './orbitdb2' }) + db2 = await Database({ ipfs: ipfs2, identity: testIdentity2, address: databaseId, accessController, directory: './test/test-data/orbitdb2' }) db2.events.on('join', onConnected) db2.events.on('update', onUpdate) @@ -125,7 +125,7 @@ describe('Database - Replication', function () { replicated = expectedEntryHash && entry.hash === expectedEntryHash } - db2 = await Database({ ipfs: ipfs2, identity: testIdentity2, address: databaseId, accessController, directory: './orbitdb2' }) + db2 = await Database({ ipfs: ipfs2, identity: testIdentity2, address: databaseId, accessController, directory: './test/test-data/orbitdb2' }) db2.events.on('join', onConnected) db2.events.on('update', onUpdate) @@ -169,7 +169,7 @@ describe('Database - Replication', function () { await db1.addOperation({ op: 'PUT', key: 1, value: 'record 1 on db 1' }) - db2 = await Database({ ipfs: ipfs2, identity: testIdentity2, address: databaseId, accessController, directory: './orbitdb2' }) + db2 = await Database({ ipfs: ipfs2, identity: testIdentity2, address: databaseId, accessController, directory: './test/test-data/orbitdb2' }) db2.events.on('join', onConnected) @@ -193,8 +193,8 @@ describe('Database - Replication', function () { it('uses given ComposedStorage with MemoryStorage/IPFSBlockStorage for entryStorage', async () => { const storage1 = await ComposedStorage(await MemoryStorage(), await IPFSBlockStorage({ ipfs: ipfs1, pin: true })) const storage2 = await ComposedStorage(await MemoryStorage(), await IPFSBlockStorage({ ipfs: ipfs2, pin: true })) - db1 = await Database({ ipfs: ipfs1, identity: testIdentity1, address: databaseId, accessController, directory: './orbitdb1', entryStorage: storage1 }) - db2 = await Database({ ipfs: ipfs2, identity: testIdentity2, address: databaseId, accessController, directory: './orbitdb2', entryStorage: storage2 }) + db1 = await Database({ ipfs: ipfs1, identity: testIdentity1, address: databaseId, accessController, directory: './test/test-data/orbitdb1', entryStorage: storage1 }) + db2 = await Database({ ipfs: ipfs2, identity: testIdentity2, address: databaseId, accessController, directory: './test/test-data/orbitdb2', entryStorage: storage2 }) let connected1 = false let connected2 = false @@ -234,8 +234,8 @@ describe('Database - Replication', function () { describe('Events', () => { beforeEach(async () => { - db1 = await Database({ ipfs: ipfs1, identity: testIdentity1, address: databaseId, accessController, directory: './orbitdb1' }) - db2 = await Database({ ipfs: ipfs2, identity: testIdentity2, address: databaseId, accessController, directory: './orbitdb2' }) + db1 = await Database({ ipfs: ipfs1, identity: testIdentity1, address: databaseId, accessController, directory: './test/test-data/orbitdb1' }) + db2 = await Database({ ipfs: ipfs2, identity: testIdentity2, address: databaseId, accessController, directory: './test/test-data/orbitdb2' }) }) it('emits \'update\' once when one operation is added', async () => { diff --git a/test/database.test.js b/test/database.test.js index 5677b586..8af519b8 100644 --- a/test/database.test.js +++ b/test/database.test.js @@ -9,7 +9,7 @@ import MemoryStorage from '../src/storage/memory.js' import testKeysPath from './fixtures/test-keys-path.js' import createHelia from './utils/create-helia.js' -const keysPath = './testkeys' +const keysPath = './test/test-data/testkeys' describe('Database', function () { this.timeout(30000) @@ -47,15 +47,15 @@ describe('Database', function () { } await rimraf(keysPath) - await rimraf('./ipfs1') + await rimraf('./test/test-data/ipfs1') }) afterEach(async () => { - await rimraf('./orbitdb') + await rimraf('./test/test-data/orbitdb') }) it('adds an operation', async () => { - db = await Database({ ipfs, identity: testIdentity, address: databaseId, accessController, directory: './orbitdb' }) + db = await Database({ ipfs, identity: testIdentity, address: databaseId, accessController, directory: './test/test-data/orbitdb' }) const expected = 'zdpuAwhx6xVpnMPUA7Q4JrvZsyoti5wZ18iDeFwBjPAwsRNof' const op = { op: 'PUT', key: 1, value: 'record 1 on db 1' } const actual = await db.addOperation(op) @@ -67,11 +67,11 @@ describe('Database', function () { describe('Options', () => { it('uses default directory for headsStorage', async () => { - db = await Database({ ipfs, identity: testIdentity, address: databaseId, accessController }) + db = await Database({ ipfs, identity: testIdentity, address: databaseId, accessController, directory: './test/test-data/orbitdb' }) const op = { op: 'PUT', key: 1, value: 'record 1 on db 1' } const hash = await db.addOperation(op) - const headsPath = Path.join('./orbitdb/', `${databaseId}/`, '/log/_heads/') + const headsPath = Path.join('./test/test-data/orbitdb/', `${databaseId}/`, '/log/_heads/') strictEqual(await existsSync(headsPath), true) @@ -87,11 +87,11 @@ describe('Database', function () { }) it('uses given directory for headsStorage', async () => { - db = await Database({ ipfs, identity: testIdentity, address: databaseId, accessController, directory: './custom-directory' }) + db = await Database({ ipfs, identity: testIdentity, address: databaseId, accessController, directory: './test/test-data/custom-directory' }) const op = { op: 'PUT', key: 1, value: 'record 1 on db 1' } const hash = await db.addOperation(op) - const headsPath = Path.join('./custom-directory/', `${databaseId}/`, '/log/_heads/') + const headsPath = Path.join('./test/test-data/custom-directory/', `${databaseId}/`, '/log/_heads/') strictEqual(await existsSync(headsPath), true) @@ -104,12 +104,12 @@ describe('Database', function () { await headsStorage.close() await rimraf(headsPath) - await rimraf('./custom-directory') + await rimraf('./test/test-data/custom-directory') }) it('uses given MemoryStorage for headsStorage', async () => { const headsStorage = await MemoryStorage() - db = await Database({ ipfs, identity: testIdentity, address: databaseId, accessController, directory: './orbitdb', headsStorage }) + db = await Database({ ipfs, identity: testIdentity, address: databaseId, accessController, directory: './test/test-data/orbitdb', headsStorage }) const op = { op: 'PUT', key: 1, value: 'record 1 on db 1' } const hash = await db.addOperation(op) @@ -120,7 +120,7 @@ describe('Database', function () { it('uses given MemoryStorage for entryStorage', async () => { const entryStorage = await MemoryStorage() - db = await Database({ ipfs, identity: testIdentity, address: databaseId, accessController, directory: './orbitdb', entryStorage }) + db = await Database({ ipfs, identity: testIdentity, address: databaseId, accessController, directory: './test/test-data/orbitdb', entryStorage }) const op = { op: 'PUT', key: 1, value: 'record 1 on db 1' } const hash = await db.addOperation(op) @@ -132,7 +132,7 @@ describe('Database', function () { describe('Events', () => { beforeEach(async () => { - db = await Database({ ipfs, identity: testIdentity, address: databaseId, accessController, directory: './orbitdb' }) + db = await Database({ ipfs, identity: testIdentity, address: databaseId, accessController, directory: './test/test-data/orbitdb' }) }) it('emits \'close\' when the database is closed', async () => { diff --git a/test/databases/documents.test.js b/test/databases/documents.test.js index e36b4d84..9a7b5bbd 100644 --- a/test/databases/documents.test.js +++ b/test/databases/documents.test.js @@ -6,7 +6,7 @@ import Documents from '../../src/databases/documents.js' import testKeysPath from '../fixtures/test-keys-path.js' import createHelia from '../utils/create-helia.js' -const keysPath = './testkeys' +const keysPath = './test/test-data/testkeys' describe('Documents Database', function () { let ipfs @@ -37,13 +37,13 @@ describe('Documents Database', function () { } await rimraf(keysPath) - await rimraf('./orbitdb') - await rimraf('./ipfs1') + await rimraf('./test/test-data/orbitdb') + await rimraf('./test/test-data/ipfs1') }) describe('Default index \'_id\'', () => { beforeEach(async () => { - db = await Documents()({ ipfs, identity: testIdentity1, address: databaseId, accessController }) + db = await Documents()({ ipfs, identity: testIdentity1, address: databaseId, accessController, directory: './test/test-data/orbitdb' }) }) afterEach(async () => { @@ -147,7 +147,7 @@ describe('Documents Database', function () { describe('Custom index \'doc\'', () => { beforeEach(async () => { - db = await Documents({ indexBy: 'doc' })({ ipfs, identity: testIdentity1, address: databaseId, accessController }) + db = await Documents({ indexBy: 'doc' })({ ipfs, identity: testIdentity1, address: databaseId, accessController, directory: './test/test-data/orbitdb' }) }) afterEach(async () => { @@ -250,7 +250,7 @@ describe('Documents Database', function () { describe('Iterator', () => { before(async () => { - db = await Documents()({ ipfs, identity: testIdentity1, address: databaseId, accessController }) + db = await Documents()({ ipfs, identity: testIdentity1, address: databaseId, accessController, directory: './test/test-data/orbitdb' }) }) after(async () => { @@ -334,12 +334,12 @@ describe('Documents Database', function () { } beforeEach(async () => { - db = await Documents()({ ipfs, identity: testIdentity1, address: databaseId, accessController }) + db = await Documents()({ ipfs, identity: testIdentity1, address: databaseId, accessController, directory: './test/test-data/orbitdb' }) for (const doc of Object.values(data)) { await db.put(doc) } await db.close() - db = await Documents()({ ipfs, identity: testIdentity1, address: databaseId, accessController }) + db = await Documents()({ ipfs, identity: testIdentity1, address: databaseId, accessController, directory: './test/test-data/orbitdb' }) }) afterEach(async () => { diff --git a/test/databases/events.test.js b/test/databases/events.test.js index ef8aefad..06060398 100644 --- a/test/databases/events.test.js +++ b/test/databases/events.test.js @@ -6,7 +6,7 @@ import Events from '../../src/databases/events.js' import testKeysPath from '../fixtures/test-keys-path.js' import createHelia from '../utils/create-helia.js' -const keysPath = './testkeys' +const keysPath = './test/test-data/testkeys' describe('Events Database', function () { let ipfs @@ -37,12 +37,12 @@ describe('Events Database', function () { } await rimraf(keysPath) - await rimraf('./orbitdb') - await rimraf('./ipfs1') + await rimraf('./test/test-data/orbitdb') + await rimraf('./test/test-data/ipfs1') }) beforeEach(async () => { - db = await Events()({ ipfs, identity: testIdentity1, address: databaseId, accessController }) + db = await Events()({ ipfs, identity: testIdentity1, address: databaseId, accessController, directory: './test/test-data/orbitdb' }) }) afterEach(async () => { diff --git a/test/databases/keyvalue-indexed.js b/test/databases/keyvalue-indexed.js index 3e54a112..b966fb8e 100644 --- a/test/databases/keyvalue-indexed.js +++ b/test/databases/keyvalue-indexed.js @@ -8,7 +8,7 @@ import KeyValueIndexed from '../../src/databases/keyvalue-indexed.js' import testKeysPath from '../fixtures/test-keys-path.js' import createHelia from '../utils/create-helia.js' -const keysPath = './testkeys' +const keysPath = './test/test-data/testkeys' describe('KeyValueIndexed Database', function () { let ipfs @@ -43,13 +43,13 @@ describe('KeyValueIndexed Database', function () { } await rimraf(keysPath) - await rimraf('./orbitdb') - await rimraf('./ipfs1') + await rimraf('./test/test-data/orbitdb') + await rimraf('./test/test-data/ipfs1') }) describe('Creating a KeyValueIndexed database', () => { beforeEach(async () => { - db = await KeyValueIndexed()({ ipfs, identity: testIdentity1, address: databaseId, accessController }) + db = await KeyValueIndexed()({ ipfs, identity: testIdentity1, address: databaseId, accessController, directory: './test/test-data/orbitdb' }) }) afterEach(async () => { @@ -65,7 +65,7 @@ describe('KeyValueIndexed Database', function () { }) it('creates a directory for the persisted index', async () => { - const expectedPath = path.join('./orbitdb', `./${db.address}`, '/_index') + const expectedPath = path.join('./test/test-data/orbitdb', `./${db.address}`, '/_index') const directoryExists = fs.existsSync(expectedPath) strictEqual(directoryExists, true) }) @@ -82,7 +82,7 @@ describe('KeyValueIndexed Database', function () { describe('KeyValueIndexed database API', () => { beforeEach(async () => { - db = await KeyValueIndexed()({ ipfs, identity: testIdentity1, address: databaseId, accessController }) + db = await KeyValueIndexed()({ ipfs, identity: testIdentity1, address: databaseId, accessController, directory: './test/test-data/orbitdb' }) }) afterEach(async () => { @@ -199,7 +199,7 @@ describe('KeyValueIndexed Database', function () { describe('Iterator', () => { before(async () => { - db = await KeyValueIndexed()({ ipfs, identity: testIdentity1, address: databaseId, accessController }) + db = await KeyValueIndexed()({ ipfs, identity: testIdentity1, address: databaseId, accessController, directory: './test/test-data/orbitdb' }) }) after(async () => { @@ -282,7 +282,7 @@ describe('KeyValueIndexed Database', function () { it('can use a custom indexStorage', async () => { const storage = await MemoryStorage() - db = await KeyValueIndexed({ storage })({ ipfs, identity: testIdentity1, address: databaseId, accessController }) + db = await KeyValueIndexed({ storage })({ ipfs, identity: testIdentity1, address: databaseId, accessController, directory: './test/test-data/orbitdb' }) await db.put('key', 'value') diff --git a/test/databases/keyvalue.test.js b/test/databases/keyvalue.test.js index 6a1cd3ef..a04954eb 100644 --- a/test/databases/keyvalue.test.js +++ b/test/databases/keyvalue.test.js @@ -6,7 +6,7 @@ import KeyValue from '../../src/databases/keyvalue.js' import testKeysPath from '../fixtures/test-keys-path.js' import createHelia from '../utils/create-helia.js' -const keysPath = './testkeys' +const keysPath = './test/test-data/testkeys' describe('KeyValue Database', function () { let ipfs @@ -37,13 +37,13 @@ describe('KeyValue Database', function () { } await rimraf(keysPath) - await rimraf('./orbitdb') - await rimraf('./ipfs1') + await rimraf('./test/test-data/orbitdb') + await rimraf('./test/test-data/ipfs1') }) describe('Creating a KeyValue database', () => { beforeEach(async () => { - db = await KeyValue()({ ipfs, identity: testIdentity1, address: databaseId, accessController }) + db = await KeyValue()({ ipfs, identity: testIdentity1, address: databaseId, accessController, directory: './test/test-data/orbitdb' }) }) afterEach(async () => { @@ -70,7 +70,7 @@ describe('KeyValue Database', function () { describe('KeyValue database API', () => { beforeEach(async () => { - db = await KeyValue()({ ipfs, identity: testIdentity1, address: databaseId, accessController }) + db = await KeyValue()({ ipfs, identity: testIdentity1, address: databaseId, accessController, directory: './test/test-data/orbitdb' }) }) afterEach(async () => { @@ -187,7 +187,7 @@ describe('KeyValue Database', function () { describe('Iterator', () => { before(async () => { - db = await KeyValue()({ ipfs, identity: testIdentity1, address: databaseId, accessController }) + db = await KeyValue()({ ipfs, identity: testIdentity1, address: databaseId, accessController, directory: './test/test-data/orbitdb' }) }) after(async () => { diff --git a/test/databases/replication/documents.test.js b/test/databases/replication/documents.test.js index 4c167cd0..12fcebe5 100644 --- a/test/databases/replication/documents.test.js +++ b/test/databases/replication/documents.test.js @@ -8,7 +8,7 @@ import connectPeers from '../../utils/connect-nodes.js' import waitFor from '../../utils/wait-for.js' import createHelia from '../../utils/create-helia.js' -const keysPath = './testkeys' +const keysPath = './test/test-data/testkeys' describe('Documents Database Replication', function () { this.timeout(10000) @@ -54,15 +54,15 @@ describe('Documents Database Replication', function () { } await rimraf(keysPath) - await rimraf('./orbitdb1') - await rimraf('./orbitdb2') - await rimraf('./ipfs1') - await rimraf('./ipfs2') + await rimraf('./test/test-data/orbitdb1') + await rimraf('./test/test-data/orbitdb2') + await rimraf('./test/test-data/ipfs1') + await rimraf('./test/test-data/ipfs2') }) beforeEach(async () => { - db1 = await Documents()({ ipfs: ipfs1, identity: testIdentity1, address: databaseId, accessController, directory: './orbitdb1' }) - db2 = await Documents()({ ipfs: ipfs2, identity: testIdentity2, address: databaseId, accessController, directory: './orbitdb2' }) + db1 = await Documents()({ ipfs: ipfs1, identity: testIdentity1, address: databaseId, accessController, directory: './test/test-data/orbitdb1' }) + db2 = await Documents()({ ipfs: ipfs2, identity: testIdentity2, address: databaseId, accessController, directory: './test/test-data/orbitdb2' }) }) afterEach(async () => { diff --git a/test/databases/replication/events.test.js b/test/databases/replication/events.test.js index c956582c..3b348a2b 100644 --- a/test/databases/replication/events.test.js +++ b/test/databases/replication/events.test.js @@ -8,7 +8,7 @@ import connectPeers from '../../utils/connect-nodes.js' import waitFor from '../../utils/wait-for.js' import createHelia from '../../utils/create-helia.js' -const keysPath = './testkeys' +const keysPath = './test/test-data/testkeys' describe('Events Database Replication', function () { this.timeout(30000) @@ -64,10 +64,10 @@ describe('Events Database Replication', function () { } await rimraf(keysPath) - await rimraf('./orbitdb1') - await rimraf('./orbitdb2') - await rimraf('./ipfs1') - await rimraf('./ipfs2') + await rimraf('./test/test-data/orbitdb1') + await rimraf('./test/test-data/orbitdb2') + await rimraf('./test/test-data/ipfs1') + await rimraf('./test/test-data/ipfs2') }) afterEach(async () => { @@ -99,8 +99,8 @@ describe('Events Database Replication', function () { console.error(err) } - db1 = await Events()({ ipfs: ipfs1, identity: testIdentity1, address: databaseId, accessController, directory: './orbitdb1' }) - db2 = await Events()({ ipfs: ipfs2, identity: testIdentity2, address: databaseId, accessController, directory: './orbitdb2' }) + db1 = await Events()({ ipfs: ipfs1, identity: testIdentity1, address: databaseId, accessController, directory: './test/test-data/orbitdb1' }) + db2 = await Events()({ ipfs: ipfs2, identity: testIdentity2, address: databaseId, accessController, directory: './test/test-data/orbitdb2' }) db2.events.on('join', onConnected) db2.events.on('update', onUpdate) @@ -145,8 +145,8 @@ describe('Events Database Replication', function () { console.error(err) } - db1 = await Events()({ ipfs: ipfs1, identity: testIdentity1, address: databaseId, accessController, directory: './orbitdb1' }) - db2 = await Events()({ ipfs: ipfs2, identity: testIdentity2, address: databaseId, accessController, directory: './orbitdb2' }) + db1 = await Events()({ ipfs: ipfs1, identity: testIdentity1, address: databaseId, accessController, directory: './test/test-data/orbitdb1' }) + db2 = await Events()({ ipfs: ipfs2, identity: testIdentity2, address: databaseId, accessController, directory: './test/test-data/orbitdb2' }) db2.events.on('join', onConnected) db2.events.on('update', onUpdate) @@ -171,7 +171,7 @@ describe('Events Database Replication', function () { await db2.close() - db2 = await Events()({ ipfs: ipfs2, identity: testIdentity2, address: databaseId, accessController, directory: './orbitdb2' }) + db2 = await Events()({ ipfs: ipfs2, identity: testIdentity2, address: databaseId, accessController, directory: './test/test-data/orbitdb2' }) const all2 = [] for await (const event of db2.iterator()) { diff --git a/test/databases/replication/keyvalue-indexed.test.js b/test/databases/replication/keyvalue-indexed.test.js index 590bf680..04e953ec 100644 --- a/test/databases/replication/keyvalue-indexed.test.js +++ b/test/databases/replication/keyvalue-indexed.test.js @@ -8,7 +8,7 @@ import connectPeers from '../../utils/connect-nodes.js' import waitFor from '../../utils/wait-for.js' import createHelia from '../../utils/create-helia.js' -const keysPath = './testkeys' +const keysPath = './test/test-data/testkeys' describe('KeyValueIndexed Database Replication', function () { this.timeout(30000) @@ -33,10 +33,10 @@ describe('KeyValueIndexed Database Replication', function () { await connectPeers(ipfs1, ipfs2) await rimraf(keysPath) - await rimraf('./orbitdb1') - await rimraf('./orbitdb2') - await rimraf('./ipfs1') - await rimraf('./ipfs2') + await rimraf('./test/test-data/orbitdb1') + await rimraf('./test/test-data/orbitdb2') + await rimraf('./test/test-data/ipfs1') + await rimraf('./test/test-data/ipfs2') await copy(testKeysPath, keysPath) keystore = await KeyStore({ path: keysPath }) @@ -59,10 +59,10 @@ describe('KeyValueIndexed Database Replication', function () { } await rimraf(keysPath) - await rimraf('./orbitdb1') - await rimraf('./orbitdb2') - await rimraf('./ipfs1') - await rimraf('./ipfs2') + await rimraf('./test/test-data/orbitdb1') + await rimraf('./test/test-data/orbitdb2') + await rimraf('./test/test-data/ipfs1') + await rimraf('./test/test-data/ipfs2') }) afterEach(async () => { @@ -92,8 +92,8 @@ describe('KeyValueIndexed Database Replication', function () { console.error(err) } - kv1 = await KeyValueIndexed()({ ipfs: ipfs1, identity: testIdentity1, address: databaseId, accessController, directory: './orbitdb1' }) - kv2 = await KeyValueIndexed()({ ipfs: ipfs2, identity: testIdentity2, address: databaseId, accessController, directory: './orbitdb2' }) + kv1 = await KeyValueIndexed()({ ipfs: ipfs1, identity: testIdentity1, address: databaseId, accessController, directory: './test/test-data/orbitdb1' }) + kv2 = await KeyValueIndexed()({ ipfs: ipfs2, identity: testIdentity2, address: databaseId, accessController, directory: './test/test-data/orbitdb2' }) kv2.events.on('join', onConnected) kv2.events.on('update', onUpdate) @@ -159,8 +159,8 @@ describe('KeyValueIndexed Database Replication', function () { console.error(err) } - kv1 = await KeyValueIndexed()({ ipfs: ipfs1, identity: testIdentity1, address: databaseId, accessController, directory: './orbitdb1' }) - kv2 = await KeyValueIndexed()({ ipfs: ipfs2, identity: testIdentity2, address: databaseId, accessController, directory: './orbitdb2' }) + kv1 = await KeyValueIndexed()({ ipfs: ipfs1, identity: testIdentity1, address: databaseId, accessController, directory: './test/test-data/orbitdb1' }) + kv2 = await KeyValueIndexed()({ ipfs: ipfs2, identity: testIdentity2, address: databaseId, accessController, directory: './test/test-data/orbitdb2' }) kv2.events.on('join', onConnected) kv2.events.on('update', onUpdate) @@ -182,8 +182,8 @@ describe('KeyValueIndexed Database Replication', function () { await kv1.close() await kv2.close() - kv1 = await KeyValueIndexed()({ ipfs: ipfs1, identity: testIdentity1, address: databaseId, accessController, directory: './orbitdb1' }) - kv2 = await KeyValueIndexed()({ ipfs: ipfs2, identity: testIdentity2, address: databaseId, accessController, directory: './orbitdb2' }) + kv1 = await KeyValueIndexed()({ ipfs: ipfs1, identity: testIdentity1, address: databaseId, accessController, directory: './test/test-data/orbitdb1' }) + kv2 = await KeyValueIndexed()({ ipfs: ipfs2, identity: testIdentity2, address: databaseId, accessController, directory: './test/test-data/orbitdb2' }) const value0 = await kv2.get('init') deepStrictEqual(value0, true) @@ -233,8 +233,8 @@ describe('KeyValueIndexed Database Replication', function () { replicated1 = expectedEntryHash1 !== null && entry.hash === expectedEntryHash1 } - kv1 = await KeyValueIndexed()({ ipfs: ipfs1, identity: testIdentity1, address: databaseId, accessController, directory: './orbitdb1' }) - kv2 = await KeyValueIndexed()({ ipfs: ipfs2, identity: testIdentity2, address: databaseId, accessController, directory: './orbitdb2' }) + kv1 = await KeyValueIndexed()({ ipfs: ipfs1, identity: testIdentity1, address: databaseId, accessController, directory: './test/test-data/orbitdb1' }) + kv2 = await KeyValueIndexed()({ ipfs: ipfs2, identity: testIdentity2, address: databaseId, accessController, directory: './test/test-data/orbitdb2' }) kv2.events.on('update', onUpdate) @@ -260,7 +260,7 @@ describe('KeyValueIndexed Database Replication', function () { await kv2.close() - kv1 = await KeyValueIndexed()({ ipfs: ipfs1, identity: testIdentity1, address: databaseId, accessController, directory: './orbitdb1' }) + kv1 = await KeyValueIndexed()({ ipfs: ipfs1, identity: testIdentity1, address: databaseId, accessController, directory: './test/test-data/orbitdb1' }) const onUpdate3 = async (entry) => { replicated3 = expectedEntryHash3 && entry.hash === expectedEntryHash3 @@ -275,7 +275,7 @@ describe('KeyValueIndexed Database Replication', function () { await kv1.del('three') expectedEntryHash2 = await kv1.set('four', 4) - kv2 = await KeyValueIndexed()({ ipfs: ipfs2, identity: testIdentity2, address: databaseId, accessController, directory: './orbitdb2' }) + kv2 = await KeyValueIndexed()({ ipfs: ipfs2, identity: testIdentity2, address: databaseId, accessController, directory: './test/test-data/orbitdb2' }) const onUpdate2 = (entry) => { replicated2 = expectedEntryHash2 && entry.hash === expectedEntryHash2 @@ -327,7 +327,7 @@ describe('KeyValueIndexed Database Replication', function () { deepStrictEqual(err, undefined) } - kv1 = await KeyValueIndexed()({ ipfs: ipfs1, identity: testIdentity1, address: databaseId, accessController, directory: './orbitdb11' }) + kv1 = await KeyValueIndexed()({ ipfs: ipfs1, identity: testIdentity1, address: databaseId, accessController, directory: './test/test-data/orbitdb11' }) kv1.events.on('error', onError) @@ -337,7 +337,7 @@ describe('KeyValueIndexed Database Replication', function () { await kv1.set('delete', 'this value') await kv1.del('delete') - kv2 = await KeyValueIndexed()({ ipfs: ipfs2, identity: testIdentity2, address: databaseId, accessController, directory: './orbitdb22' }) + kv2 = await KeyValueIndexed()({ ipfs: ipfs2, identity: testIdentity2, address: databaseId, accessController, directory: './test/test-data/orbitdb22' }) const onUpdate = (entry) => { replicated = true @@ -368,7 +368,7 @@ describe('KeyValueIndexed Database Replication', function () { { key: 'hello', value: 'friend' } ]) - await rimraf('./orbitdb11') - await rimraf('./orbitdb22') + await rimraf('./test/test-data/orbitdb11') + await rimraf('./test/test-data/orbitdb22') }) }) diff --git a/test/databases/replication/keyvalue.test.js b/test/databases/replication/keyvalue.test.js index b12114d4..56da8c11 100644 --- a/test/databases/replication/keyvalue.test.js +++ b/test/databases/replication/keyvalue.test.js @@ -8,7 +8,7 @@ import connectPeers from '../../utils/connect-nodes.js' import waitFor from '../../utils/wait-for.js' import createHelia from '../../utils/create-helia.js' -const keysPath = './testkeys' +const keysPath = './test/test-data/testkeys' describe('KeyValue Database Replication', function () { this.timeout(30000) @@ -53,10 +53,10 @@ describe('KeyValue Database Replication', function () { } await rimraf(keysPath) - await rimraf('./orbitdb1') - await rimraf('./orbitdb2') - await rimraf('./ipfs1') - await rimraf('./ipfs2') + await rimraf('./test/test-data/orbitdb1') + await rimraf('./test/test-data/orbitdb2') + await rimraf('./test/test-data/ipfs1') + await rimraf('./test/test-data/ipfs2') }) afterEach(async () => { @@ -86,8 +86,8 @@ describe('KeyValue Database Replication', function () { console.error(err) } - kv1 = await KeyValue()({ ipfs: ipfs1, identity: testIdentity1, address: databaseId, accessController, directory: './orbitdb1' }) - kv2 = await KeyValue()({ ipfs: ipfs2, identity: testIdentity2, address: databaseId, accessController, directory: './orbitdb2' }) + kv1 = await KeyValue()({ ipfs: ipfs1, identity: testIdentity1, address: databaseId, accessController, directory: './test/test-data/orbitdb1' }) + kv2 = await KeyValue()({ ipfs: ipfs2, identity: testIdentity2, address: databaseId, accessController, directory: './test/test-data/orbitdb2' }) kv2.events.on('join', onConnected) kv2.events.on('update', onUpdate) @@ -153,8 +153,8 @@ describe('KeyValue Database Replication', function () { console.error(err) } - kv1 = await KeyValue()({ ipfs: ipfs1, identity: testIdentity1, address: databaseId, accessController, directory: './orbitdb1' }) - kv2 = await KeyValue()({ ipfs: ipfs2, identity: testIdentity2, address: databaseId, accessController, directory: './orbitdb2' }) + kv1 = await KeyValue()({ ipfs: ipfs1, identity: testIdentity1, address: databaseId, accessController, directory: './test/test-data/orbitdb1' }) + kv2 = await KeyValue()({ ipfs: ipfs2, identity: testIdentity2, address: databaseId, accessController, directory: './test/test-data/orbitdb2' }) kv2.events.on('join', onConnected) kv1.events.on('join', onConnected) @@ -176,8 +176,8 @@ describe('KeyValue Database Replication', function () { await kv1.close() await kv2.close() - kv1 = await KeyValue()({ ipfs: ipfs1, identity: testIdentity1, address: databaseId, accessController, directory: './orbitdb1' }) - kv2 = await KeyValue()({ ipfs: ipfs2, identity: testIdentity2, address: databaseId, accessController, directory: './orbitdb2' }) + kv1 = await KeyValue()({ ipfs: ipfs1, identity: testIdentity1, address: databaseId, accessController, directory: './test/test-data/orbitdb1' }) + kv2 = await KeyValue()({ ipfs: ipfs2, identity: testIdentity2, address: databaseId, accessController, directory: './test/test-data/orbitdb2' }) const value0 = await kv2.get('init') deepStrictEqual(value0, true) diff --git a/test/identities/identities.test.js b/test/identities/identities.test.js index a1ca4919..be46e00b 100644 --- a/test/identities/identities.test.js +++ b/test/identities/identities.test.js @@ -11,7 +11,7 @@ import NoTypeIdentityProvider from '../fixtures/providers/no-type.js' import NoVerifyIdentityIdentityProvider from '../fixtures/providers/no-verify-identity.js' const type = 'publickey' -const keysPath = './testkeys' +const keysPath = './test/test-data/testkeys' describe('Identities', function () { before(async () => { diff --git a/test/key-store.test.js b/test/key-store.test.js index 192c788a..7e97a6cc 100644 --- a/test/key-store.test.js +++ b/test/key-store.test.js @@ -9,7 +9,7 @@ import LevelStorage from '../src/storage/level.js' import testKeysPath from './fixtures/test-keys-path.js' const defaultPath = './keystore' -const keysPath = './testkeys' +const keysPath = './test/test-data/testkeys' describe('KeyStore', () => { let keystore diff --git a/test/oplog/append.test.js b/test/oplog/append.test.js index 4ff60c1d..acc4eaf1 100644 --- a/test/oplog/append.test.js +++ b/test/oplog/append.test.js @@ -4,7 +4,7 @@ import { copy } from 'fs-extra' import { Log, Identities, KeyStore } from '../../src/index.js' import testKeysPath from '../fixtures/test-keys-path.js' -const keysPath = './testkeys' +const keysPath = './test/test-data/testkeys' describe('Log - Append', function () { this.timeout(10000) diff --git a/test/oplog/crdt.test.js b/test/oplog/crdt.test.js index 1f3a2876..cd65db46 100644 --- a/test/oplog/crdt.test.js +++ b/test/oplog/crdt.test.js @@ -4,7 +4,7 @@ import { copy } from 'fs-extra' import { Log, Identities, KeyStore } from '../../src/index.js' import testKeysPath from '../fixtures/test-keys-path.js' -const keysPath = './testkeys' +const keysPath = './test/test-data/testkeys' let testIdentity, testIdentity2, testIdentity3 diff --git a/test/oplog/entry.test.js b/test/oplog/entry.test.js index be4d8354..696731b5 100644 --- a/test/oplog/entry.test.js +++ b/test/oplog/entry.test.js @@ -6,7 +6,7 @@ import testKeysPath from '../fixtures/test-keys-path.js' import { tickClock } from '../../src/oplog/clock.js' const { create, isEntry } = Entry -const keysPath = './testkeys' +const keysPath = './test/test-data/testkeys' describe('Entry', function () { this.timeout(5000) diff --git a/test/oplog/heads.test.js b/test/oplog/heads.test.js index 0b71770a..736ffa47 100644 --- a/test/oplog/heads.test.js +++ b/test/oplog/heads.test.js @@ -4,7 +4,7 @@ import { copy } from 'fs-extra' import { Log, Identities, KeyStore } from '../../src/index.js' import testKeysPath from '../fixtures/test-keys-path.js' -const keysPath = './testkeys' +const keysPath = './test/test-data/testkeys' const last = (arr) => { return arr[arr.length - 1] diff --git a/test/oplog/iterator.test.js b/test/oplog/iterator.test.js index ca2da475..c7f7be3f 100644 --- a/test/oplog/iterator.test.js +++ b/test/oplog/iterator.test.js @@ -8,7 +8,7 @@ import testKeysPath from '../fixtures/test-keys-path.js' const { createLogWithSixteenEntries } = LogCreator -const keysPath = './testkeys' +const keysPath = './test/test-data/testkeys' describe('Log - Iterator', function () { this.timeout(5000) diff --git a/test/oplog/join-concurrent.test.js b/test/oplog/join-concurrent.test.js index e580864e..6927f30a 100644 --- a/test/oplog/join-concurrent.test.js +++ b/test/oplog/join-concurrent.test.js @@ -4,7 +4,7 @@ import { copy } from 'fs-extra' import { Log, Identities, KeyStore } from '../../src/index.js' import testKeysPath from '../fixtures/test-keys-path.js' -const keysPath = './testkeys' +const keysPath = './test/test-data/testkeys' describe('Log - Join Concurrent Entries', function () { this.timeout(5000) diff --git a/test/oplog/join.test.js b/test/oplog/join.test.js index 7c313c9e..987dae2a 100644 --- a/test/oplog/join.test.js +++ b/test/oplog/join.test.js @@ -6,7 +6,7 @@ import { Clock } from '../../src/oplog/log.js' import { MemoryStorage } from '../../src/storage/index.js' import testKeysPath from '../fixtures/test-keys-path.js' -const keysPath = './testkeys' +const keysPath = './test/test-data/testkeys' const last = (arr) => { return arr[arr.length - 1] diff --git a/test/oplog/log.test.js b/test/oplog/log.test.js index 94667015..574c030c 100644 --- a/test/oplog/log.test.js +++ b/test/oplog/log.test.js @@ -6,7 +6,7 @@ import testKeysPath from '../fixtures/test-keys-path.js' const { create } = Entry -const keysPath = './testkeys' +const keysPath = './test/test-data/testkeys' describe('Log', function () { this.timeout(5000) diff --git a/test/oplog/references.test.js b/test/oplog/references.test.js index 148bd592..c25c7474 100644 --- a/test/oplog/references.test.js +++ b/test/oplog/references.test.js @@ -5,7 +5,7 @@ import { Log } from '../../src/oplog/index.js' import { Identities, KeyStore } from '../../src/index.js' import testKeysPath from '../fixtures/test-keys-path.js' -const keysPath = './testkeys' +const keysPath = './test/test-data/testkeys' describe('Log - References', function () { this.timeout(60000) diff --git a/test/oplog/replicate.test.js b/test/oplog/replicate.test.js index 010f77ff..c77691dc 100644 --- a/test/oplog/replicate.test.js +++ b/test/oplog/replicate.test.js @@ -7,7 +7,7 @@ import connectPeers from '../utils/connect-nodes.js' import waitForPeers from '../utils/wait-for-peers.js' import createHelia from '../utils/create-helia.js' -const keysPath = './testkeys' +const keysPath = './test/test-data/testkeys' describe('Log - Replication', function () { let ipfs1, ipfs2 @@ -53,8 +53,8 @@ describe('Log - Replication', function () { await storage2.close() await rimraf(keysPath) - await rimraf('./ipfs1') - await rimraf('./ipfs2') + await rimraf('./test/test-data/ipfs1') + await rimraf('./test/test-data/ipfs2') }) describe('replicates logs deterministically', async function () { diff --git a/test/oplog/signed-log.test.js b/test/oplog/signed-log.test.js index a4dd9bf4..76f64c97 100644 --- a/test/oplog/signed-log.test.js +++ b/test/oplog/signed-log.test.js @@ -4,7 +4,7 @@ import { copy } from 'fs-extra' import { Log, Identities, KeyStore } from '../../src/index.js' import testKeysPath from '../fixtures/test-keys-path.js' -const keysPath = './testkeys' +const keysPath = './test/test-data/testkeys' describe('Signed Log', function () { this.timeout(5000) diff --git a/test/orbitdb-access-controllers.test.js b/test/orbitdb-access-controllers.test.js index d344a8c9..321073ef 100644 --- a/test/orbitdb-access-controllers.test.js +++ b/test/orbitdb-access-controllers.test.js @@ -25,7 +25,7 @@ describe('Add a custom access controller', function () { before(async () => { ipfs = await createHelia() - orbitdb = await OrbitDB({ ipfs }) + orbitdb = await OrbitDB({ ipfs, directory: './test/test-data/orbitdb' }) }) after(async () => { @@ -37,8 +37,8 @@ describe('Add a custom access controller', function () { await ipfs.stop() } - await rimraf('./orbitdb') - await rimraf('./ipfs1') + await rimraf('./test/test-data/orbitdb') + await rimraf('./test/test-data/ipfs1') }) describe('Default supported access controllers', function () { diff --git a/test/orbitdb-custom-database-types.test.js b/test/orbitdb-custom-database-types.test.js index 19292e47..52fc6f4e 100644 --- a/test/orbitdb-custom-database-types.test.js +++ b/test/orbitdb-custom-database-types.test.js @@ -27,7 +27,7 @@ describe('Add a custom database type', function () { before(async () => { ipfs = await createHelia() - orbitdb = await createOrbitDB({ ipfs }) + orbitdb = await createOrbitDB({ ipfs, directory: './test/test-data/orbitdb' }) }) after(async () => { @@ -39,8 +39,8 @@ describe('Add a custom database type', function () { await ipfs.stop() } - await rimraf('./orbitdb') - await rimraf('./ipfs1') + await rimraf('./test/test-data/orbitdb') + await rimraf('./test/test-data/ipfs1') }) describe('Default supported database types', function () { @@ -62,7 +62,7 @@ describe('Add a custom database type', function () { const name = 'hello keyvalue-indexed database' const db = await orbitdb.open(name, { type: 'keyvalue' }) - const indexDirectory = pathJoin('./orbitdb', `./${db.address}/_index/`) + const indexDirectory = pathJoin('./test/test-data/orbitdb', `./${db.address}/_index/`) strictEqual(await existsSync(indexDirectory), true) }) diff --git a/test/orbitdb-custom-identity-providers.test.js b/test/orbitdb-custom-identity-providers.test.js index 6bc9554a..198e8011 100644 --- a/test/orbitdb-custom-identity-providers.test.js +++ b/test/orbitdb-custom-identity-providers.test.js @@ -16,9 +16,9 @@ describe('Add a custom identity provider', function () { it('creates an identity using an id and default pubkey provider', async () => { useIdentityProvider(CustomIdentityProvider) - const identities = await Identities() + const identities = await Identities({ path: './test/test-data/orbitdb/identities' }) const identity = await identities.createIdentity({ id: 'abc' }) - const orbitdb = await createOrbitDB({ ipfs, identities, id: 'abc' }) + const orbitdb = await createOrbitDB({ ipfs, identities, id: 'abc', directory: './test/test-data/orbitdb' }) deepStrictEqual(orbitdb.identity, identity) @@ -27,10 +27,10 @@ describe('Add a custom identity provider', function () { it('creates an identity using a custom provider', async () => { useIdentityProvider(CustomIdentityProvider) - const identities = await Identities() + const identities = await Identities({ path: './test/test-data/orbitdb' }) const identity = { provider: CustomIdentityProvider() } const expectedIdentity = await identities.createIdentity(identity) - const orbitdb = await createOrbitDB({ ipfs, identities, identity }) + const orbitdb = await createOrbitDB({ ipfs, identities, identity, directory: './test/test-data/orbitdb' }) deepStrictEqual(orbitdb.identity, expectedIdentity) @@ -39,9 +39,9 @@ describe('Add a custom identity provider', function () { it('uses an existing identity created with a custom provider', async () => { useIdentityProvider(CustomIdentityProvider) - const identities = await Identities() + const identities = await Identities({ path: './test/test-data/orbitdb/identities' }) const identity = await identities.createIdentity({ provider: CustomIdentityProvider() }) - const orbitdb = await createOrbitDB({ ipfs, identities, identity }) + const orbitdb = await createOrbitDB({ ipfs, identities, identity, directory: './test/test-data/orbitdb' }) deepStrictEqual(orbitdb.identity, identity) @@ -53,7 +53,7 @@ describe('Add a custom identity provider', function () { await ipfs.stop() } - await rimraf('./orbitdb') - await rimraf('./ipfs1') + await rimraf('./test/test-data/orbitdb') + await rimraf('./test/test-data/ipfs1') }) }) diff --git a/test/orbitdb-drop.test.js b/test/orbitdb-drop.test.js index 68edf987..b0428227 100644 --- a/test/orbitdb-drop.test.js +++ b/test/orbitdb-drop.test.js @@ -18,7 +18,7 @@ describe('Drop databases', function () { if (ipfs) { await ipfs.stop() } - await rimraf('./orbitdb') + await rimraf('./test/test-data/orbitdb') await rimraf('./ipfs') }) @@ -26,7 +26,7 @@ describe('Drop databases', function () { const amount = 10 before(async () => { - orbitdb1 = await createOrbitDB({ ipfs, id: 'user1' }) + orbitdb1 = await createOrbitDB({ ipfs, id: 'user1', directory: './test/test-data/orbitdb' }) db = await orbitdb1.open('helloworld') }) @@ -37,7 +37,7 @@ describe('Drop databases', function () { if (orbitdb1) { await orbitdb1.stop() } - await rimraf('./orbitdb') + await rimraf('./test/test-data/orbitdb') }) it('returns no entries in the database after dropping it', async () => { @@ -88,7 +88,7 @@ describe('Drop databases', function () { describe('dropping an empty database', () => { before(async () => { - orbitdb1 = await createOrbitDB({ ipfs, id: 'user1' }) + orbitdb1 = await createOrbitDB({ ipfs, id: 'user1', directory: './test/test-data/orbitdb' }) db = await orbitdb1.open('helloworld') }) @@ -100,7 +100,7 @@ describe('Drop databases', function () { if (orbitdb1) { await orbitdb1.stop() } - await rimraf('./orbitdb1') + await rimraf('./test/test-data/orbitdb1') }) it('doesn\'t error when dropping an empty database', async () => { diff --git a/test/orbitdb-multiple-databases.test.js b/test/orbitdb-multiple-databases.test.js index 7fc4c48d..c1fcb29a 100644 --- a/test/orbitdb-multiple-databases.test.js +++ b/test/orbitdb-multiple-databases.test.js @@ -6,8 +6,8 @@ import connectPeers from './utils/connect-nodes.js' import waitFor from './utils/wait-for.js' import createHelia from './utils/create-helia.js' -const dbPath1 = './orbitdb/tests/multiple-databases/1' -const dbPath2 = './orbitdb/tests/multiple-databases/2' +const dbPath1 = './test/test-data/orbitdb/tests/multiple-databases/1' +const dbPath2 = './test/test-data/orbitdb/tests/multiple-databases/2' const databaseInterfaces = [ { @@ -64,7 +64,7 @@ describe('orbitdb - Multiple Databases', function () { await orbitdb2.stop() } - await rimraf('./orbitdb') + await rimraf('./test/test-data/orbitdb') if (ipfs1) { await ipfs1.stop() @@ -73,8 +73,8 @@ describe('orbitdb - Multiple Databases', function () { await ipfs2.stop() } - await rimraf('./ipfs1') - await rimraf('./ipfs2') + await rimraf('./test/test-data/ipfs1') + await rimraf('./test/test-data/ipfs2') }) beforeEach(async () => { diff --git a/test/orbitdb-open.test.js b/test/orbitdb-open.test.js index 165ba29e..9aac7c1f 100644 --- a/test/orbitdb-open.test.js +++ b/test/orbitdb-open.test.js @@ -26,17 +26,17 @@ describe('Open databases', function () { if (ipfs2) { await ipfs2.stop() } - await rimraf('./orbitdb1') - await rimraf('./orbitdb2') - await rimraf('./ipfs1') - await rimraf('./ipfs2') + await rimraf('./test/test-data/orbitdb1') + await rimraf('./test/test-data/orbitdb2') + await rimraf('./test/test-data/ipfs1') + await rimraf('./test/test-data/ipfs2') }) describe('creating a database instance', () => { let db before(async () => { - orbitdb1 = await createOrbitDB({ ipfs: ipfs1, id: 'user1', directory: './orbitdb1' }) + orbitdb1 = await createOrbitDB({ ipfs: ipfs1, id: 'user1', directory: './test/test-data/orbitdb1' }) db = await orbitdb1.open('helloworld') }) @@ -48,7 +48,7 @@ describe('Open databases', function () { if (orbitdb1) { await orbitdb1.stop() } - await rimraf('./orbitdb1') + await rimraf('./test/test-data/orbitdb1') }) it('creates a database instance', async () => { @@ -143,7 +143,7 @@ describe('Open databases', function () { const expected = { hello: 'world' } before(async () => { - orbitdb1 = await createOrbitDB({ ipfs: ipfs1, id: 'user1', directory: './orbitdb1' }) + orbitdb1 = await createOrbitDB({ ipfs: ipfs1, id: 'user1', directory: './test/test-data/orbitdb1' }) db = await orbitdb1.open('helloworld', { meta: expected }) }) @@ -155,7 +155,7 @@ describe('Open databases', function () { if (orbitdb1) { await orbitdb1.stop() } - await rimraf('./orbitdb1') + await rimraf('./test/test-data/orbitdb1') }) it('contains the given meta info', async () => { @@ -169,7 +169,7 @@ describe('Open databases', function () { const amount = 10 before(async () => { - orbitdb1 = await createOrbitDB({ ipfs: ipfs1, id: 'user1' }) + orbitdb1 = await createOrbitDB({ ipfs: ipfs1, id: 'user1', directory: './test/test-data/orbitdb' }) db = await orbitdb1.open('helloworld') for (let i = 0; i < amount; i++) { @@ -186,7 +186,7 @@ describe('Open databases', function () { if (orbitdb1) { await orbitdb1.stop() } - await rimraf('./orbitdb') + await rimraf('./test/test-data/orbitdb') }) it('returns all entries in the database', async () => { @@ -223,7 +223,7 @@ describe('Open databases', function () { const amount = 10 before(async () => { - orbitdb1 = await createOrbitDB({ ipfs: ipfs1, id: 'user1' }) + orbitdb1 = await createOrbitDB({ ipfs: ipfs1, id: 'user1', directory: './test/test-data/orbitdb' }) db = await orbitdb1.open('helloworld2') for (let i = 0; i < amount; i++) { @@ -235,7 +235,7 @@ describe('Open databases', function () { await db.close() await orbitdb1.stop() - orbitdb2 = await createOrbitDB({ ipfs: ipfs2, id: 'user2' }) + orbitdb2 = await createOrbitDB({ ipfs: ipfs2, id: 'user2', directory: './test/test-data/orbitdb' }) }) after(async () => { @@ -245,7 +245,7 @@ describe('Open databases', function () { if (orbitdb2) { await orbitdb2.stop() } - await rimraf('./orbitdb') + await rimraf('./test/test-data/orbitdb') }) it('returns all entries in the database', async () => { @@ -275,8 +275,8 @@ describe('Open databases', function () { const amount = 10 before(async () => { - orbitdb1 = await createOrbitDB({ ipfs: ipfs1, id: 'user1', directory: './orbitdb1' }) - orbitdb2 = await createOrbitDB({ ipfs: ipfs2, id: 'user2', directory: './orbitdb2' }) + orbitdb1 = await createOrbitDB({ ipfs: ipfs1, id: 'user1', directory: './test/test-data/orbitdb1' }) + orbitdb2 = await createOrbitDB({ ipfs: ipfs2, id: 'user2', directory: './test/test-data/orbitdb2' }) db1 = await orbitdb1.open('helloworld2') for (let i = 0; i < amount; i++) { await db1.add('hello' + i) @@ -297,8 +297,8 @@ describe('Open databases', function () { if (orbitdb2) { await orbitdb2.stop() } - await rimraf('./orbitdb1') - await rimraf('./orbitdb2') + await rimraf('./test/test-data/orbitdb1') + await rimraf('./test/test-data/orbitdb2') }) it('replicates the database', async () => { @@ -377,7 +377,7 @@ describe('Open databases', function () { const amount = 10 before(async () => { - orbitdb1 = await createOrbitDB({ ipfs: ipfs1, id: 'user1' }) + orbitdb1 = await createOrbitDB({ ipfs: ipfs1, id: 'user1', directory: './test/test-data/orbitdb' }) db = await orbitdb1.open('helloworld', { type: 'keyvalue' }) address = db.address @@ -395,7 +395,7 @@ describe('Open databases', function () { if (orbitdb1) { await orbitdb1.stop() } - await rimraf('./orbitdb') + await rimraf('./test/test-data/orbitdb') }) it('returns all entries in the database', async () => { @@ -424,7 +424,7 @@ describe('Open databases', function () { const amount = 10 before(async () => { - orbitdb1 = await createOrbitDB({ ipfs: ipfs1, id: 'user1' }) + orbitdb1 = await createOrbitDB({ ipfs: ipfs1, id: 'user1', directory: './test/test-data/orbitdb' }) db = await orbitdb1.open('helloworld', { Database: KeyValueIndexed() }) address = db.address @@ -443,7 +443,7 @@ describe('Open databases', function () { await orbitdb1.stop() } await rimraf('./index') - await rimraf('./orbitdb') + await rimraf('./test/test-data/orbitdb') }) it('returns all entries in the database and in the index', async () => { @@ -473,7 +473,7 @@ describe('Open databases', function () { const amount = 10 before(async () => { - orbitdb1 = await createOrbitDB({ ipfs: ipfs1, id: 'user1' }) + orbitdb1 = await createOrbitDB({ ipfs: ipfs1, id: 'user1', directory: './test/test-data/orbitdb' }) db = await orbitdb1.open('helloworld', { type: 'documents' }) address = db.address @@ -491,7 +491,7 @@ describe('Open databases', function () { if (orbitdb1) { await orbitdb1.stop() } - await rimraf('./orbitdb') + await rimraf('./test/test-data/orbitdb') }) it('returns all entries in the database', async () => { @@ -518,7 +518,7 @@ describe('Open databases', function () { let db1, db2 before(async () => { - orbitdb1 = await createOrbitDB({ ipfs: ipfs1, id: 'user1' }) + orbitdb1 = await createOrbitDB({ ipfs: ipfs1, id: 'user1', directory: './test/test-data/orbitdb' }) }) after(async () => { @@ -531,7 +531,7 @@ describe('Open databases', function () { if (orbitdb1) { await orbitdb1.stop() } - await rimraf('./orbitdb') + await rimraf('./test/test-data/orbitdb') }) it('returns the database instance when opened with a name multiple times', async () => { @@ -562,17 +562,17 @@ describe('Open databases', function () { if (orbitdb) { await orbitdb.stop() } - await rimraf('./orbitdb') + await rimraf('./test/test-data/orbitdb') }) it('returns the database instance', async () => { let err try { - orbitdb = await createOrbitDB({ ipfs: ipfs1, id: 'user1' }) + orbitdb = await createOrbitDB({ ipfs: ipfs1, id: 'user1', directory: './test/test-data/orbitdb' }) db = await orbitdb.open('helloworld1') await orbitdb.stop() - orbitdb = await createOrbitDB({ ipfs: ipfs1, id: 'user1' }) + orbitdb = await createOrbitDB({ ipfs: ipfs1, id: 'user1', directory: './test/test-data/orbitdb' }) db = await orbitdb.open('helloworld1') } catch (e) { err = e diff --git a/test/orbitdb-replication.test.js b/test/orbitdb-replication.test.js index 916854a8..833a3851 100644 --- a/test/orbitdb-replication.test.js +++ b/test/orbitdb-replication.test.js @@ -14,12 +14,12 @@ describe('Replicating databases', function () { let orbitdb1, orbitdb2 before(async () => { - ipfs1 = await createHelia({ directory: './ipfs1' }) - ipfs2 = await createHelia({ directory: './ipfs2' }) + ipfs1 = await createHelia({ directory: './test/test-data/ipfs1' }) + ipfs2 = await createHelia({ directory: './test/test-data/ipfs2' }) await connectPeers(ipfs1, ipfs2) - orbitdb1 = await createOrbitDB({ ipfs: ipfs1, id: 'user1', directory: './orbitdb1' }) - orbitdb2 = await createOrbitDB({ ipfs: ipfs2, id: 'user2', directory: './orbitdb2' }) + orbitdb1 = await createOrbitDB({ ipfs: ipfs1, id: 'user1', directory: './test/test-data/orbitdb1' }) + orbitdb2 = await createOrbitDB({ ipfs: ipfs2, id: 'user2', directory: './test/test-data/orbitdb2' }) }) after(async () => { @@ -30,10 +30,10 @@ describe('Replicating databases', function () { await ipfs1.stop() await ipfs2.stop() - await rimraf('./orbitdb1') - await rimraf('./orbitdb2') - await rimraf('./ipfs1') - await rimraf('./ipfs2') + await rimraf('./test/test-data/orbitdb1') + await rimraf('./test/test-data/orbitdb2') + await rimraf('./test/test-data/ipfs1') + await rimraf('./test/test-data/ipfs2') }) describe('replicating a database', () => { @@ -147,13 +147,13 @@ describe('Replicating databases', function () { await ipfs1.stop() await ipfs2.stop() - ipfs1 = await createHelia({ directory: './ipfs1' }) - ipfs2 = await createHelia({ directory: './ipfs2' }) + ipfs1 = await createHelia({ directory: './test/test-data/ipfs1' }) + ipfs2 = await createHelia({ directory: './test/test-data/ipfs2' }) await connectPeers(ipfs1, ipfs2) - orbitdb1 = await createOrbitDB({ ipfs: ipfs1, id: 'user1', directory: './orbitdb1' }) - orbitdb2 = await createOrbitDB({ ipfs: ipfs2, id: 'user2', directory: './orbitdb2' }) + orbitdb1 = await createOrbitDB({ ipfs: ipfs1, id: 'user1', directory: './test/test-data/orbitdb1' }) + orbitdb2 = await createOrbitDB({ ipfs: ipfs2, id: 'user2', directory: './test/test-data/orbitdb2' }) db1 = await orbitdb1.open('helloworld', { referencesCount: 0 }) db2 = await orbitdb2.open(db1.address) diff --git a/test/orbitdb-write-access.test.js b/test/orbitdb-write-access.test.js index f79ce353..5194d5c2 100644 --- a/test/orbitdb-write-access.test.js +++ b/test/orbitdb-write-access.test.js @@ -8,7 +8,7 @@ import IPFSAccessController from '../src/access-controllers/ipfs.js' import OrbitDBAccessController from '../src/access-controllers/orbitdb.js' import createHelia from './utils/create-helia.js' -const dbPath = './orbitdb/tests/write-permissions' +const dbPath = './test/test-data/orbitdb/tests/write-permissions' describe('Write Permissions', function () { this.timeout(20000) @@ -42,9 +42,9 @@ describe('Write Permissions', function () { await ipfs2.stop() } - await rimraf('./orbitdb') - await rimraf('./ipfs1') - await rimraf('./ipfs2') + await rimraf('./test/test-data/orbitdb') + await rimraf('./test/test-data/ipfs1') + await rimraf('./test/test-data/ipfs2') }) afterEach(async () => { diff --git a/test/orbitdb.test.js b/test/orbitdb.test.js index 7e51553a..58550477 100644 --- a/test/orbitdb.test.js +++ b/test/orbitdb.test.js @@ -124,15 +124,15 @@ describe('OrbitDB', function () { describe('OrbitDB instance creation - user given parameters', () => { before(async () => { - await rimraf('./orbitdb1') - orbitdb1 = await createOrbitDB({ ipfs: ipfs1, id: 'user1', directory: './orbitdb1' }) + await rimraf('./test/test-data/orbitdb1') + orbitdb1 = await createOrbitDB({ ipfs: ipfs1, id: 'user1', directory: './test/test-data/orbitdb1' }) }) after(async () => { if (orbitdb1) { await orbitdb1.stop() } - await rimraf('./orbitdb1') + await rimraf('./test/test-data/orbitdb1') }) it('has an IPFS instance', async () => { @@ -152,7 +152,7 @@ describe('OrbitDB', function () { }) it('has the directory given as a parameter', async () => { - strictEqual(orbitdb1.directory, './orbitdb1') + strictEqual(orbitdb1.directory, './test/test-data/orbitdb1') }) it('has a keystore', async () => { @@ -177,7 +177,7 @@ describe('OrbitDB', function () { }) it('creates a directory for the keystore', async () => { - const directoryExists = fs.existsSync(path.join('./orbitdb1/keystore')) + const directoryExists = fs.existsSync(path.join('./test/test-data/orbitdb1/keystore')) strictEqual(directoryExists, true) }) @@ -253,8 +253,8 @@ describe('OrbitDB', function () { orbitdb1 = await createOrbitDB() } catch (e) { } - const dataDirectoryExists = fs.existsSync(path.join('./orbitdb')) - const keysDirectoryExists = fs.existsSync(path.join('./orbitdb/keystore')) + const dataDirectoryExists = fs.existsSync(path.join('./test/test-data/orbitdb')) + const keysDirectoryExists = fs.existsSync(path.join('./test/test-data/orbitdb/keystore')) strictEqual(dataDirectoryExists, false) strictEqual(keysDirectoryExists, false) }) diff --git a/test/storage.test.js b/test/storage.test.js index 6447f339..0058ec4e 100644 --- a/test/storage.test.js +++ b/test/storage.test.js @@ -6,7 +6,7 @@ import { IPFSBlockStorage, MemoryStorage, LRUStorage, ComposedStorage, LevelStor import testKeysPath from './fixtures/test-keys-path.js' import createHelia from './utils/create-helia.js' -const keysPath = './testkeys' +const keysPath = './test/test-data/testkeys' describe('Storages', function () { this.timeout(5000) @@ -34,7 +34,7 @@ describe('Storages', function () { } await rimraf('./level') - await rimraf('./ipfs1') + await rimraf('./test/test-data/ipfs1') await rimraf(keysPath) }) diff --git a/test/sync.test.js b/test/sync.test.js index b3d21901..721ab663 100644 --- a/test/sync.test.js +++ b/test/sync.test.js @@ -11,7 +11,7 @@ import IPFSBlockStorage from '../src/storage/ipfs-block.js' import ComposedStorage from '../src/storage/composed.js' import createHelia from './utils/create-helia.js' -const keysPath = './testkeys' +const keysPath = './test/test-data/testkeys' describe('Sync protocol', function () { this.timeout(10000) @@ -40,8 +40,8 @@ describe('Sync protocol', function () { after(async () => { await ipfs1.stop() await ipfs2.stop() - await rimraf('./ipfs1') - await rimraf('./ipfs2') + await rimraf('./test/test-data/ipfs1') + await rimraf('./test/test-data/ipfs2') if (keystore) { await keystore.close() }