diff --git a/test/db/document-store.test.js b/test/db/document-store.test.js index 67236c1..79728e7 100644 --- a/test/db/document-store.test.js +++ b/test/db/document-store.test.js @@ -1,19 +1,14 @@ import { deepStrictEqual, strictEqual } from 'assert' -import rimraf from 'rimraf' +import rmrf from 'rimraf' import { Log, Entry, Database } from '../../src/index.js' import { DocumentStore } from '../../src/db/index.js' -import { IPFSBlockStorage, LevelStorage } from '../../src/storage/index.js' import { config, testAPIs, startIpfs, stopIpfs } from 'orbit-db-test-utils' import { createTestIdentities, cleanUpTestIdentities } from '../fixtures/orbit-db-identity-keys.js' -const { sync: rmrf } = rimraf - -const OpLog = { Log, Entry, IPFSBlockStorage, LevelStorage } +const OpLog = { Log, Entry } Object.keys(testAPIs).forEach((IPFS) => { describe('DocumentStore Database (' + IPFS + ')', function () { - this.timeout(config.timeout * 2) - let ipfsd let ipfs let keystore, signingKeyStore @@ -25,15 +20,12 @@ Object.keys(testAPIs).forEach((IPFS) => { const databaseId = 'documentstore-AAA' before(async () => { - // Start two IPFS instances ipfsd = await startIpfs(IPFS, config.daemon1) ipfs = ipfsd.api const [identities, testIdentities] = await createTestIdentities(ipfs) identities1 = identities[0] testIdentity1 = testIdentities[0] - - rmrf(testIdentity1.id) }) after(async () => { @@ -42,15 +34,8 @@ Object.keys(testAPIs).forEach((IPFS) => { if (ipfsd) { await stopIpfs(ipfsd) } - if (keystore) { - await keystore.close() - } - if (signingKeyStore) { - await signingKeyStore.close() - } - if (testIdentity1) { - rmrf(testIdentity1.id) - } + + await rmrf('./orbitdb') }) describe('Default index \'_id\'', () => { diff --git a/test/db/event-store.test.js b/test/db/event-store.test.js index e0dfcad..f07b9ab 100644 --- a/test/db/event-store.test.js +++ b/test/db/event-store.test.js @@ -1,21 +1,16 @@ import { deepStrictEqual, strictEqual } from 'assert' import mapSeries from 'p-map-series' -import rimraf from 'rimraf' +import rmrf from 'rimraf' import { Log, Entry } from '../../src/oplog/index.js' import { EventStore } from '../../src/db/index.js' import { Database } from '../../src/index.js' -import { IPFSBlockStorage, LevelStorage } from '../../src/storage/index.js' import { config, testAPIs, startIpfs, stopIpfs } from 'orbit-db-test-utils' import { createTestIdentities, cleanUpTestIdentities } from '../fixtures/orbit-db-identity-keys.js' -const { sync: rmrf } = rimraf - -const OpLog = { Log, Entry, IPFSBlockStorage, LevelStorage } +const OpLog = { Log, Entry } Object.keys(testAPIs).forEach((IPFS) => { describe('EventStore Database (' + IPFS + ')', function () { - this.timeout(config.timeout * 2) - let ipfsd let ipfs let keystore, signingKeyStore @@ -27,7 +22,6 @@ Object.keys(testAPIs).forEach((IPFS) => { const databaseId = 'eventstore-AAA' before(async () => { - // Start two IPFS instances ipfsd = await startIpfs(IPFS, config.daemon1) ipfs = ipfsd.api @@ -44,15 +38,8 @@ Object.keys(testAPIs).forEach((IPFS) => { if (ipfsd) { await stopIpfs(ipfsd) } - if (keystore) { - await keystore.close() - } - if (signingKeyStore) { - await signingKeyStore.close() - } - if (testIdentity1) { - rmrf(testIdentity1.id) - } + + await rmrf('./orbitdb') }) beforeEach(async () => { diff --git a/test/db/keyvalue-persisted.js b/test/db/keyvalue-persisted.js index 4f19886..b69ff6a 100644 --- a/test/db/keyvalue-persisted.js +++ b/test/db/keyvalue-persisted.js @@ -1,23 +1,17 @@ import { deepStrictEqual, strictEqual } from 'assert' -import rimraf from 'rimraf' +import rmrf from 'rimraf' import { Log, Entry } from '../../src/oplog/index.js' import { KeyValuePersisted, KeyValue } from '../../src/db/index.js' import { Database } from '../../src/index.js' -import { IPFSBlockStorage, LevelStorage } from '../../src/storage/index.js' import { config, testAPIs, startIpfs, stopIpfs } from 'orbit-db-test-utils' import { createTestIdentities, cleanUpTestIdentities } from '../fixtures/orbit-db-identity-keys.js' -const { sync: rmrf } = rimraf - -const OpLog = { Log, Entry, IPFSBlockStorage, LevelStorage } +const OpLog = { Log, Entry } Object.keys(testAPIs).forEach((IPFS) => { describe('KeyValuePersisted Database (' + IPFS + ')', function () { - this.timeout(config.timeout * 2) - let ipfsd let ipfs - let keystore, signingKeyStore let accessController let identities1 let testIdentity1 @@ -26,15 +20,12 @@ Object.keys(testAPIs).forEach((IPFS) => { const databaseId = 'keyvalue-AAA' before(async () => { - // Start two IPFS instances ipfsd = await startIpfs(IPFS, config.daemon1) ipfs = ipfsd.api const [identities, testIdentities] = await createTestIdentities(ipfs) identities1 = identities[0] testIdentity1 = testIdentities[0] - - rmrf(testIdentity1.id) }) after(async () => { @@ -43,15 +34,8 @@ Object.keys(testAPIs).forEach((IPFS) => { if (ipfsd) { await stopIpfs(ipfsd) } - if (keystore) { - await keystore.close() - } - if (signingKeyStore) { - await signingKeyStore.close() - } - if (testIdentity1) { - rmrf(testIdentity1.id) - } + + await rmrf('./orbitdb') }) beforeEach(async () => { diff --git a/test/db/keyvalue.test.js b/test/db/keyvalue.test.js index 32a72e2..5f2fd3e 100644 --- a/test/db/keyvalue.test.js +++ b/test/db/keyvalue.test.js @@ -1,20 +1,15 @@ import { deepStrictEqual, strictEqual } from 'assert' -import rimraf from 'rimraf' +import rmrf from 'rimraf' import { Log, Entry } from '../../src/oplog/index.js' import { KeyValue } from '../../src/db/index.js' import { Database } from '../../src/index.js' -import { IPFSBlockStorage, LevelStorage } from '../../src/storage/index.js' import { config, testAPIs, startIpfs, stopIpfs } from 'orbit-db-test-utils' import { createTestIdentities, cleanUpTestIdentities } from '../fixtures/orbit-db-identity-keys.js' -const { sync: rmrf } = rimraf - -const OpLog = { Log, Entry, IPFSBlockStorage, LevelStorage } +const OpLog = { Log, Entry } Object.keys(testAPIs).forEach((IPFS) => { describe('KeyValue Database (' + IPFS + ')', function () { - this.timeout(config.timeout * 2) - let ipfsd let ipfs let accessController @@ -25,8 +20,6 @@ Object.keys(testAPIs).forEach((IPFS) => { const databaseId = 'keyvalue-AAA' before(async () => { - rmrf('./orbitdb') - ipfsd = await startIpfs(IPFS, config.daemon1) ipfs = ipfsd.api @@ -41,7 +34,8 @@ Object.keys(testAPIs).forEach((IPFS) => { if (ipfsd) { await stopIpfs(ipfsd) } - rmrf('./orbitdb') + + await rmrf('./orbitdb') }) beforeEach(async () => { diff --git a/test/db/replication/document-store.test.js b/test/db/replication/document-store.test.js index 6f1066f..99c01f5 100644 --- a/test/db/replication/document-store.test.js +++ b/test/db/replication/document-store.test.js @@ -1,6 +1,6 @@ import { deepStrictEqual } from 'assert' -import rimraf from 'rimraf' -import { Log, Entry } from '../../../src/oplog/index.js' +import rmrf from 'rimraf' +import { Log, Entry } from '../../../src/index.js' import { DocumentStore } from '../../../src/db/index.js' import { Database } from '../../../src/index.js' import { config, startIpfs, stopIpfs } from 'orbit-db-test-utils' @@ -8,13 +8,11 @@ import connectPeers from '../../utils/connect-nodes.js' import { createTestIdentities, cleanUpTestIdentities } from '../../fixtures/orbit-db-identity-keys.js' import waitFor from '../../utils/wait-for.js' -const { sync: rmrf } = rimraf - const OpLog = { Log, Entry } const IPFS = 'js-ipfs' describe('Documents Database Replication', function () { - this.timeout(config.timeout * 2) + this.timeout(5000) let ipfsd1, ipfsd2 let ipfs1, ipfs2 @@ -33,7 +31,6 @@ describe('Documents Database Replication', function () { } before(async () => { - // Start two IPFS instances ipfsd1 = await startIpfs(IPFS, config.daemon1) ipfsd2 = await startIpfs(IPFS, config.daemon2) ipfs1 = ipfsd1.api diff --git a/test/db/replication/event-store.test.js b/test/db/replication/event-store.test.js index 88ff71c..d71af41 100644 --- a/test/db/replication/event-store.test.js +++ b/test/db/replication/event-store.test.js @@ -1,17 +1,14 @@ import { deepStrictEqual } from 'assert' import rmrf from 'rimraf' -import { Log, Entry } from '../../../src/oplog/index.js' +import { Log, Entry } from '../../../src/index.js' import { EventStore } from '../../../src/db/index.js' import { Database } from '../../../src/index.js' -import { IPFSBlockStorage, LevelStorage } from '../../../src/storage/index.js' - -// Test utils import { config, startIpfs, stopIpfs } from 'orbit-db-test-utils' import connectPeers from '../../utils/connect-nodes.js' import waitFor from '../../utils/wait-for.js' import { createTestIdentities, cleanUpTestIdentities } from '../../fixtures/orbit-db-identity-keys.js' -const OpLog = { Log, Entry, IPFSBlockStorage, LevelStorage } +const OpLog = { Log, Entry } const IPFS = 'js-ipfs' describe('Events Database Replication', function () { @@ -44,6 +41,9 @@ describe('Events Database Replication', function () { ] before(async () => { + await rmrf('./orbitdb1') + await rmrf('./orbitdb2') + ipfsd1 = await startIpfs(IPFS, config.daemon1) ipfsd2 = await startIpfs(IPFS, config.daemon2) ipfs1 = ipfsd1.api @@ -56,9 +56,6 @@ describe('Events Database Replication', function () { identities2 = identities[1] testIdentity1 = testIdentities[0] testIdentity2 = testIdentities[1] - - await rmrf('./orbitdb1') - await rmrf('./orbitdb2') }) after(async () => { diff --git a/test/db/replication/keyvalue.test.js b/test/db/replication/keyvalue.test.js index c98b76b..a95b212 100644 --- a/test/db/replication/keyvalue.test.js +++ b/test/db/replication/keyvalue.test.js @@ -1,217 +1,216 @@ import { deepStrictEqual } from 'assert' import rmrf from 'rimraf' -import { Log, Entry } from '../../../src/oplog/index.js' +import { Log, Entry } from '../../../src/index.js' import { KeyValue, KeyValuePersisted } from '../../../src/db/index.js' import { Database } from '../../../src/index.js' -import { config, testAPIs, startIpfs, stopIpfs } from 'orbit-db-test-utils' +import { config, startIpfs, stopIpfs } from 'orbit-db-test-utils' import connectPeers from '../../utils/connect-nodes.js' import waitFor from '../../utils/wait-for.js' import { createTestIdentities, cleanUpTestIdentities } from '../../fixtures/orbit-db-identity-keys.js' const OpLog = { Log, Entry } +const IPFS = 'js-ipfs' -Object.keys(testAPIs).forEach((IPFS) => { - describe('KeyValue Database Replication (' + IPFS + ')', function () { - this.timeout(config.timeout) +describe('KeyValue Database Replication', function () { + this.timeout(5000) - let ipfsd1, ipfsd2 - let ipfs1, ipfs2 - let identities1, identities2 - let testIdentity1, testIdentity2 - let kv1, kv2 + let ipfsd1, ipfsd2 + let ipfs1, ipfs2 + let identities1, identities2 + let testIdentity1, testIdentity2 + let kv1, kv2 - const databaseId = 'kv-AAA' + const databaseId = 'kv-AAA' - const accessController = { - canAppend: async (entry) => { - const identity = await identities1.getIdentity(entry.identity) - return identity.id === testIdentity1.id - } + const accessController = { + canAppend: async (entry) => { + const identity = await identities1.getIdentity(entry.identity) + return identity.id === testIdentity1.id + } + } + + before(async () => { + ipfsd1 = await startIpfs(IPFS, config.daemon1) + ipfsd2 = await startIpfs(IPFS, config.daemon2) + ipfs1 = ipfsd1.api + ipfs2 = ipfsd2.api + + await connectPeers(ipfs1, ipfs2) + + const [identities, testIdentities] = await createTestIdentities(ipfs1, ipfs2) + identities1 = identities[0] + identities2 = identities[1] + testIdentity1 = testIdentities[0] + testIdentity2 = testIdentities[1] + + await rmrf('./orbitdb1') + await rmrf('./orbitdb2') + }) + + after(async () => { + await cleanUpTestIdentities([identities1, identities2]) + + if (ipfsd1) { + await stopIpfs(ipfsd1) + } + if (ipfsd2) { + await stopIpfs(ipfsd2) } - before(async () => { - ipfsd1 = await startIpfs(IPFS, config.daemon1) - ipfsd2 = await startIpfs(IPFS, config.daemon2) - ipfs1 = ipfsd1.api - ipfs2 = ipfsd2.api - - await connectPeers(ipfs1, ipfs2) - - const [identities, testIdentities] = await createTestIdentities(ipfs1, ipfs2) - identities1 = identities[0] - identities2 = identities[1] - testIdentity1 = testIdentities[0] - testIdentity2 = testIdentities[1] - - await rmrf('./orbitdb1') - await rmrf('./orbitdb2') - }) - - after(async () => { - await cleanUpTestIdentities([identities1, identities2]) - - if (ipfsd1) { - await stopIpfs(ipfsd1) - } - if (ipfsd2) { - await stopIpfs(ipfsd2) - } - - await rmrf('./orbitdb1') - await rmrf('./orbitdb2') - }) - - afterEach(async () => { - if (kv1) { - await kv1.drop() - await kv1.close() - } - if (kv2) { - await kv2.drop() - await kv2.close() - } - }) - - it('replicates a database', async () => { - let connected = false - let updateCount = 0 - - const onConnected = async (peerId) => { - connected = true - } - - const onUpdate = (entry) => { - ++updateCount - } - - const onError = (err) => { - console.error(err) - } - - kv1 = await KeyValuePersisted({ KeyValue, OpLog, Database, ipfs: ipfs1, identity: testIdentity1, address: databaseId, accessController, directory: './orbitdb1' }) - kv2 = await KeyValuePersisted({ KeyValue, OpLog, Database, ipfs: ipfs2, identity: testIdentity2, address: databaseId, accessController, directory: './orbitdb2' }) - - kv2.events.on('join', onConnected) - kv1.events.on('join', onConnected) - kv2.events.on('update', onUpdate) - kv2.events.on('error', onError) - kv1.events.on('error', onError) - - await kv1.set('init', true) - await kv1.set('hello', 'friend') - await kv1.del('hello') - await kv1.set('hello', 'friend2') - await kv1.del('hello') - await kv1.set('empty', '') - await kv1.del('empty') - await kv1.set('hello', 'friend3') - - await waitFor(() => connected, () => true) - await waitFor(() => updateCount > 0, () => true) - - const value0 = await kv2.get('init') - deepStrictEqual(value0, true) - - const value2 = await kv2.get('hello') - deepStrictEqual(value2, 'friend3') - - const value1 = await kv1.get('hello') - deepStrictEqual(value1, 'friend3') - - const value9 = await kv1.get('empty') - deepStrictEqual(value9, undefined) - - const all2 = [] - for await (const keyValue of kv2.iterator()) { - all2.push(keyValue) - } - deepStrictEqual(all2, [ - { key: 'hello', value: 'friend3' }, - { key: 'init', value: true } - ]) - - const all1 = [] - for await (const keyValue of kv1.iterator()) { - all1.push(keyValue) - } - deepStrictEqual(all1, [ - { key: 'hello', value: 'friend3' }, - { key: 'init', value: true } - ]) - }) - - it('loads the database after replication', async () => { - let updateCount = 0 - let connected = false - - const onConnected = async (peerId) => { - connected = true - } - - const onUpdate = (entry) => { - ++updateCount - } - - const onError = (err) => { - console.error(err) - } - - kv1 = await KeyValuePersisted({ KeyValue, OpLog, Database, ipfs: ipfs1, identity: testIdentity1, address: databaseId, accessController, directory: './orbitdb1' }) - kv2 = await KeyValuePersisted({ KeyValue, OpLog, Database, ipfs: ipfs2, identity: testIdentity2, address: databaseId, accessController, directory: './orbitdb2' }) - - kv2.events.on('join', onConnected) - kv1.events.on('join', onConnected) - kv2.events.on('update', onUpdate) - kv2.events.on('error', onError) - kv1.events.on('error', onError) - - await kv1.set('init', true) - await kv1.set('hello', 'friend') - await kv1.del('hello') - await kv1.set('hello', 'friend2') - await kv1.del('hello') - await kv1.set('empty', '') - await kv1.del('empty') - await kv1.set('hello', 'friend3') - - await waitFor(() => connected, () => true) - await waitFor(() => updateCount > 0, () => true) + await rmrf('./orbitdb1') + await rmrf('./orbitdb2') + }) + afterEach(async () => { + if (kv1) { + await kv1.drop() await kv1.close() + } + if (kv2) { + await kv2.drop() await kv2.close() + } + }) - kv1 = await KeyValuePersisted({ KeyValue, OpLog, Database, ipfs: ipfs1, identity: testIdentity1, address: databaseId, accessController, directory: './orbitdb1' }) - kv2 = await KeyValuePersisted({ KeyValue, OpLog, Database, ipfs: ipfs2, identity: testIdentity2, address: databaseId, accessController, directory: './orbitdb2' }) + it('replicates a database', async () => { + let connected = false + let updateCount = 0 - const value0 = await kv2.get('init') - deepStrictEqual(value0, true) + const onConnected = async (peerId) => { + connected = true + } - const value2 = await kv2.get('hello') - deepStrictEqual(value2, 'friend3') + const onUpdate = (entry) => { + ++updateCount + } - const value1 = await kv1.get('hello') - deepStrictEqual(value1, 'friend3') + const onError = (err) => { + console.error(err) + } - const value9 = await kv1.get('empty') - deepStrictEqual(value9, undefined) + kv1 = await KeyValuePersisted({ KeyValue, OpLog, Database, ipfs: ipfs1, identity: testIdentity1, address: databaseId, accessController, directory: './orbitdb1' }) + kv2 = await KeyValuePersisted({ KeyValue, OpLog, Database, ipfs: ipfs2, identity: testIdentity2, address: databaseId, accessController, directory: './orbitdb2' }) - const all2 = [] - for await (const keyValue of kv2.iterator()) { - all2.push(keyValue) - } - deepStrictEqual(all2, [ - { key: 'hello', value: 'friend3' }, - { key: 'init', value: true } - ]) + kv2.events.on('join', onConnected) + kv1.events.on('join', onConnected) + kv2.events.on('update', onUpdate) + kv2.events.on('error', onError) + kv1.events.on('error', onError) - const all1 = [] - for await (const keyValue of kv1.iterator()) { - all1.push(keyValue) - } - deepStrictEqual(all1, [ - { key: 'hello', value: 'friend3' }, - { key: 'init', value: true } - ]) - }) + await kv1.set('init', true) + await kv1.set('hello', 'friend') + await kv1.del('hello') + await kv1.set('hello', 'friend2') + await kv1.del('hello') + await kv1.set('empty', '') + await kv1.del('empty') + await kv1.set('hello', 'friend3') + + await waitFor(() => connected, () => true) + await waitFor(() => updateCount > 0, () => true) + + const value0 = await kv2.get('init') + deepStrictEqual(value0, true) + + const value2 = await kv2.get('hello') + deepStrictEqual(value2, 'friend3') + + const value1 = await kv1.get('hello') + deepStrictEqual(value1, 'friend3') + + const value9 = await kv1.get('empty') + deepStrictEqual(value9, undefined) + + const all2 = [] + for await (const keyValue of kv2.iterator()) { + all2.push(keyValue) + } + deepStrictEqual(all2, [ + { key: 'hello', value: 'friend3' }, + { key: 'init', value: true } + ]) + + const all1 = [] + for await (const keyValue of kv1.iterator()) { + all1.push(keyValue) + } + deepStrictEqual(all1, [ + { key: 'hello', value: 'friend3' }, + { key: 'init', value: true } + ]) + }) + + it('loads the database after replication', async () => { + let updateCount = 0 + let connected = false + + const onConnected = async (peerId) => { + connected = true + } + + const onUpdate = (entry) => { + ++updateCount + } + + const onError = (err) => { + console.error(err) + } + + kv1 = await KeyValuePersisted({ KeyValue, OpLog, Database, ipfs: ipfs1, identity: testIdentity1, address: databaseId, accessController, directory: './orbitdb1' }) + kv2 = await KeyValuePersisted({ KeyValue, OpLog, Database, ipfs: ipfs2, identity: testIdentity2, address: databaseId, accessController, directory: './orbitdb2' }) + + kv2.events.on('join', onConnected) + kv1.events.on('join', onConnected) + kv2.events.on('update', onUpdate) + kv2.events.on('error', onError) + kv1.events.on('error', onError) + + await kv1.set('init', true) + await kv1.set('hello', 'friend') + await kv1.del('hello') + await kv1.set('hello', 'friend2') + await kv1.del('hello') + await kv1.set('empty', '') + await kv1.del('empty') + await kv1.set('hello', 'friend3') + + await waitFor(() => connected, () => true) + await waitFor(() => updateCount > 0, () => true) + + await kv1.close() + await kv2.close() + + kv1 = await KeyValuePersisted({ KeyValue, OpLog, Database, ipfs: ipfs1, identity: testIdentity1, address: databaseId, accessController, directory: './orbitdb1' }) + kv2 = await KeyValuePersisted({ KeyValue, OpLog, Database, ipfs: ipfs2, identity: testIdentity2, address: databaseId, accessController, directory: './orbitdb2' }) + + const value0 = await kv2.get('init') + deepStrictEqual(value0, true) + + const value2 = await kv2.get('hello') + deepStrictEqual(value2, 'friend3') + + const value1 = await kv1.get('hello') + deepStrictEqual(value1, 'friend3') + + const value9 = await kv1.get('empty') + deepStrictEqual(value9, undefined) + + const all2 = [] + for await (const keyValue of kv2.iterator()) { + all2.push(keyValue) + } + deepStrictEqual(all2, [ + { key: 'hello', value: 'friend3' }, + { key: 'init', value: true } + ]) + + const all1 = [] + for await (const keyValue of kv1.iterator()) { + all1.push(keyValue) + } + deepStrictEqual(all1, [ + { key: 'hello', value: 'friend3' }, + { key: 'init', value: true } + ]) }) })