From 973cc7aa2098cbe4f9f2c7d40aa9a3a4bae7a142 Mon Sep 17 00:00:00 2001 From: Hayden Young Date: Tue, 16 Jan 2024 21:46:04 +0000 Subject: [PATCH] test: Create a Level db if directory is specified. --- test/orbitdb-replication.test.js | 18 ++++++++---------- test/utils/create-helia.js | 6 +++--- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/test/orbitdb-replication.test.js b/test/orbitdb-replication.test.js index 3ef9d75..a6906a9 100644 --- a/test/orbitdb-replication.test.js +++ b/test/orbitdb-replication.test.js @@ -4,20 +4,16 @@ import { createOrbitDB } from '../src/index.js' import connectPeers from './utils/connect-nodes.js' import waitFor from './utils/wait-for.js' import createHelia from './utils/create-helia.js' -import { LevelBlockstore } from 'blockstore-level' describe('Replicating databases', function () { this.timeout(10000) - let blockstore1, blockstore2 let ipfs1, ipfs2 let orbitdb1, orbitdb2 before(async () => { - blockstore1 = new LevelBlockstore('./ipfs1') - blockstore2 = new LevelBlockstore('./ipfs2') - ipfs1 = await createHelia({ blockstore: blockstore1 }) - ipfs2 = await createHelia({ blockstore: blockstore2 }) + ipfs1 = await createHelia({ directory: './ipfs1' }) + ipfs2 = await createHelia({ directory: './ipfs2' }) await connectPeers(ipfs1, ipfs2) orbitdb1 = await createOrbitDB({ ipfs: ipfs1, id: 'user1', directory: './orbitdb1' }) @@ -27,8 +23,8 @@ describe('Replicating databases', function () { after(async () => { await orbitdb1.stop() await orbitdb2.stop() - await blockstore1.close() - await blockstore2.close() + await ipfs1.blockstore.child.child.close() + await ipfs2.blockstore.child.child.close() await ipfs1.stop() await ipfs2.stop() @@ -140,11 +136,13 @@ describe('Replicating databases', function () { await orbitdb1.stop() await orbitdb2.stop() + await ipfs1.blockstore.child.child.close() + await ipfs2.blockstore.child.child.close() await ipfs1.stop() await ipfs2.stop() - ipfs1 = await createHelia({ blockstore: blockstore1 }) - ipfs2 = await createHelia({ blockstore: blockstore2 }) + ipfs1 = await createHelia({ directory: './ipfs1' }) + ipfs2 = await createHelia({ directory: './ipfs2' }) await connectPeers(ipfs1, ipfs2) diff --git a/test/utils/create-helia.js b/test/utils/create-helia.js index bec02c8..088226f 100644 --- a/test/utils/create-helia.js +++ b/test/utils/create-helia.js @@ -2,17 +2,17 @@ import { createHelia } from 'helia' import { bitswap } from '@helia/block-brokers' import { createLibp2p } from 'libp2p' import { MemoryBlockstore } from 'blockstore-core' -// import { LevelBlockstore } from 'blockstore-level' +import { LevelBlockstore } from 'blockstore-level' import { DefaultLibp2pOptions, DefaultLibp2pBrowserOptions } from '../../src/index.js' const isBrowser = () => typeof window !== 'undefined' -export default async ({ blockstore } = {}) => { +export default async ({ directory } = {}) => { const options = isBrowser() ? DefaultLibp2pBrowserOptions : DefaultLibp2pOptions const libp2p = await createLibp2p({ ...options }) - blockstore = blockstore || new MemoryBlockstore() + const blockstore = directory ? new LevelBlockstore(`${directory}/blocks`) : new MemoryBlockstore() const heliaOptions = { blockstore,