mirror of
https://github.com/orbitdb/orbitdb.git
synced 2025-03-30 15:08:28 +00:00
commit
ec06a8e2d0
@ -1,12 +1,9 @@
|
||||
import { EventEmitter } from 'events'
|
||||
import ensureACAddress from '../utils/ensure-ac-address.js'
|
||||
import IPFSAccessController from './ipfs.js'
|
||||
|
||||
const type = 'orbitdb'
|
||||
|
||||
const OrbitDBAccessController = ({ write } = {}) => async ({ orbitdb, identities, address }) => {
|
||||
const events = new EventEmitter()
|
||||
|
||||
address = address || 'default-access-controller'
|
||||
write = write || [orbitdb.identity.id]
|
||||
|
||||
@ -14,12 +11,6 @@ const OrbitDBAccessController = ({ write } = {}) => async ({ orbitdb, identities
|
||||
const db = await orbitdb.open(ensureACAddress(address), { type: 'keyvalue', AccessController: IPFSAccessController({ write }) })
|
||||
address = db.address
|
||||
|
||||
const onUpdate = (entry) => {
|
||||
events.emit('update', entry)
|
||||
}
|
||||
|
||||
db.events.on('update', onUpdate)
|
||||
|
||||
// Return true if entry is allowed to be added to the database
|
||||
const canAppend = async (entry) => {
|
||||
const writerIdentity = await identities.getIdentity(entry.identity)
|
||||
@ -101,7 +92,7 @@ const OrbitDBAccessController = ({ write } = {}) => async ({ orbitdb, identities
|
||||
grant,
|
||||
revoke,
|
||||
close,
|
||||
events
|
||||
events: db.events
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -22,6 +22,7 @@ const addDatabaseType = (type, store) => {
|
||||
databaseTypes[type] = store
|
||||
}
|
||||
|
||||
const DefaultDatabaseType = 'events'
|
||||
const DefaultAccessController = IPFSAccessController
|
||||
|
||||
const OrbitDB = async ({ ipfs, id, identity, keystore, directory } = {}) => {
|
||||
@ -64,7 +65,7 @@ const OrbitDB = async ({ ipfs, id, identity, keystore, directory } = {}) => {
|
||||
meta = manifest.meta
|
||||
} else {
|
||||
// If the address given was not valid, eg. just the name of the database
|
||||
type = type || 'events'
|
||||
type = type || DefaultDatabaseType
|
||||
AccessController = AccessController || DefaultAccessController()
|
||||
accessController = await AccessController({ orbitdb: { open, identity, ipfs }, identities })
|
||||
const m = await manifests.create({ name: address, type, accessController: accessController.address, meta })
|
||||
|
@ -3,6 +3,7 @@
|
||||
"colors": true,
|
||||
"recursive": true,
|
||||
"exit": true,
|
||||
"bail": false,
|
||||
"slow": 1000,
|
||||
"exclude": ["test/browser/**/*.js"]
|
||||
}
|
@ -1,443 +0,0 @@
|
||||
// import assert from 'assert'
|
||||
// import mapSeries from 'p-map-series'
|
||||
// import fs from 'fs-extra'
|
||||
// import path from 'path'
|
||||
// import rmrf from 'rimraf'
|
||||
// import Zip from 'adm-zip'
|
||||
// import OrbitDB from '../src/OrbitDB.js'
|
||||
// import OrbitDBAddress from '../src/orbit-db-address.js'
|
||||
// import Identities from 'orbit-db-identity-provider'
|
||||
// import * as io from 'orbit-db-io'
|
||||
|
||||
// // Include test utilities
|
||||
// import {
|
||||
// config,
|
||||
// startIpfs,
|
||||
// stopIpfs,
|
||||
// testAPIs,
|
||||
// } from 'orbit-db-test-utils'
|
||||
|
||||
// const dbPath = path.join('./orbitdb', 'tests', 'create-open')
|
||||
// const migrationFixturePath = path.join('./test', 'fixtures', 'migration', 'cache-schema-test')
|
||||
// const ipfsFixturesDir = path.join('./test', 'fixtures', 'ipfs')
|
||||
|
||||
// Object.keys(testAPIs).forEach(API => {
|
||||
// describe(`orbit-db - Create & Open (${API})`, function () {
|
||||
// let ipfsFixtures = path.join('./test', 'fixtures', `js-ipfs.zip`)
|
||||
|
||||
// this.retries(1) // windows...
|
||||
// this.timeout(config.timeout)
|
||||
|
||||
// let ipfsd, ipfs, orbitdb, address
|
||||
// let localDataPath
|
||||
|
||||
// const filterFunc = (src, dest) => {
|
||||
// // windows has problems copying these files...
|
||||
// return !(src.includes('LOG') || src.includes('LOCK'))
|
||||
// }
|
||||
|
||||
// before(async () => {
|
||||
// rmrf.sync(dbPath)
|
||||
// ipfsd = await startIpfs(API, config.daemon1)
|
||||
// ipfs = ipfsd.api
|
||||
// const zip = new Zip(ipfsFixtures)
|
||||
// await zip.extractAllToAsync(path.join('./test', 'fixtures'), true)
|
||||
// await fs.copy(path.join(ipfsFixturesDir, 'blocks'), path.join(ipfsd.path, 'blocks'))
|
||||
// await fs.copy(path.join(ipfsFixturesDir, 'datastore'), path.join(ipfsd.path, 'datastore'), { filter: filterFunc })
|
||||
// orbitdb = await OrbitDB.createInstance(ipfs, { directory: dbPath })
|
||||
// })
|
||||
|
||||
// after(async () => {
|
||||
// if (orbitdb)
|
||||
// await orbitdb.stop()
|
||||
|
||||
// if (ipfsd)
|
||||
// await stopIpfs(ipfsd)
|
||||
|
||||
// rmrf.sync(ipfsFixturesDir)
|
||||
// })
|
||||
|
||||
// describe('Create', function () {
|
||||
// describe('Errors', function () {
|
||||
// it('throws an error if given an invalid database type', async () => {
|
||||
// let err
|
||||
// try {
|
||||
// const db = await orbitdb.create('first', 'invalid-type')
|
||||
// } catch (e) {
|
||||
// err = e.toString()
|
||||
// }
|
||||
// assert.equal(err, 'Error: Invalid database type \'invalid-type\'')
|
||||
// })
|
||||
|
||||
// it('throws an error if given an address instead of name', async () => {
|
||||
// let err
|
||||
// try {
|
||||
// const db = await orbitdb.create('/orbitdb/Qmc9PMho3LwTXSaUXJ8WjeBZyXesAwUofdkGeadFXsqMzW/first', 'feed')
|
||||
// } catch (e) {
|
||||
// err = e.toString()
|
||||
// }
|
||||
// assert.equal(err, 'Error: Given database name is an address. Please give only the name of the database!')
|
||||
// })
|
||||
|
||||
// it('throws an error if database already exists', async () => {
|
||||
// let err, db
|
||||
// try {
|
||||
// db = await orbitdb.create('first', 'feed', { replicate: false })
|
||||
// const db2 = await orbitdb.create('first', 'feed', { replicate: false })
|
||||
// } catch (e) {
|
||||
// err = e.toString()
|
||||
// }
|
||||
// assert.equal(err, `Error: Database '${db.address}' already exists!`)
|
||||
// await db.close()
|
||||
// })
|
||||
|
||||
// it('throws an error if database type doesn\'t match', async () => {
|
||||
// let err, log, kv
|
||||
// try {
|
||||
// log = await orbitdb.kvstore('keyvalue', { replicate: false })
|
||||
// kv = await orbitdb.eventlog(log.address.toString())
|
||||
// } catch (e) {
|
||||
// err = e.toString()
|
||||
// }
|
||||
// assert.equal(err, `Error: Database '${log.address}' is type 'keyvalue' but was opened as 'eventlog'`)
|
||||
// })
|
||||
// })
|
||||
|
||||
// describe('Success', function () {
|
||||
// let db
|
||||
|
||||
// before(async () => {
|
||||
// db = await orbitdb.create('second', 'feed', { replicate: false })
|
||||
// localDataPath = path.join(dbPath, orbitdb.id, 'cache')
|
||||
// await db.close()
|
||||
// })
|
||||
|
||||
// it('creates a feed database', async () => {
|
||||
// assert.notEqual(db, null)
|
||||
// })
|
||||
|
||||
// it('database has the correct address', async () => {
|
||||
// assert.equal(db.address.toString().indexOf('/orbitdb'), 0)
|
||||
// assert.equal(db.address.toString().indexOf('zd'), 9)
|
||||
// assert.equal(db.address.toString().indexOf('second'), 59)
|
||||
// })
|
||||
|
||||
// it('saves the database locally', async () => {
|
||||
// assert.equal(fs.existsSync(localDataPath), true)
|
||||
// })
|
||||
|
||||
// it('saves database manifest reference locally', async () => {
|
||||
// const address = db.id
|
||||
// const manifestHash = address.split('/')[2]
|
||||
// await db._cache._store.open()
|
||||
// const value = await db._cache.get(path.join(address, '/_manifest'))
|
||||
// assert.equal(value, manifestHash)
|
||||
// })
|
||||
|
||||
// it('saves database manifest file locally', async () => {
|
||||
// const manifestHash = db.id.split('/')[2]
|
||||
// const manifest = await io.read(ipfs, manifestHash)
|
||||
// assert.notEqual(manifest, false)
|
||||
// assert.equal(manifest.name, 'second')
|
||||
// assert.equal(manifest.type, 'feed')
|
||||
// assert.notEqual(manifest.accessController, null)
|
||||
// assert.equal(manifest.accessController.indexOf('/ipfs'), 0)
|
||||
// })
|
||||
|
||||
// it('can pass local database directory as an option', async () => {
|
||||
// const dir = './orbitdb/tests/another-feed'
|
||||
// const db2 = await orbitdb.create('third', 'feed', { directory: dir })
|
||||
// assert.equal(fs.existsSync(dir), true)
|
||||
// await db2.close()
|
||||
// })
|
||||
|
||||
// it('loads cache from previous version of orbit-db', async () => {
|
||||
// const dbName = 'cache-schema-test'
|
||||
|
||||
// db = await orbitdb.create(dbName, 'keyvalue', { overwrite: true })
|
||||
// const manifestHash = db.address.root
|
||||
// const migrationDataPath = path.join(dbPath, manifestHash, dbName)
|
||||
|
||||
// await db.load()
|
||||
// assert.equal((await db.get('key')), undefined)
|
||||
// await db.drop()
|
||||
|
||||
// await fs.copy(migrationFixturePath, migrationDataPath, { filter: filterFunc })
|
||||
// db = await orbitdb.create(dbName, 'keyvalue', { directory: migrationDataPath, overwrite: true })
|
||||
// await db.load()
|
||||
|
||||
// assert.equal(manifestHash, db.address.root)
|
||||
// assert.equal((await db.get('key')), 'value')
|
||||
// })
|
||||
|
||||
// it('loads cache from previous version of orbit-db with the directory option', async () => {
|
||||
// const dbName = 'cache-schema-test'
|
||||
// const directory = path.join(dbPath, "some-other-place")
|
||||
|
||||
// await fs.copy(migrationFixturePath, directory, { filter: filterFunc })
|
||||
// db = await orbitdb.create(dbName, 'keyvalue', { directory })
|
||||
// await db.load()
|
||||
|
||||
// assert.equal((await db.get('key')), 'value')
|
||||
// })
|
||||
|
||||
// describe('Access Controller', function () {
|
||||
// before(async () => {
|
||||
// if (db) {
|
||||
// await db.drop()
|
||||
// }
|
||||
// })
|
||||
|
||||
// afterEach(async () => {
|
||||
// if (db) {
|
||||
// await db.drop()
|
||||
// }
|
||||
// })
|
||||
|
||||
// it('creates an access controller and adds ourselves as writer by default', async () => {
|
||||
// db = await orbitdb.create('fourth', 'feed')
|
||||
// assert.deepEqual(db.access.write, [orbitdb.identity.id])
|
||||
// })
|
||||
|
||||
// it('creates an access controller and adds writers', async () => {
|
||||
// db = await orbitdb.create('fourth', 'feed', {
|
||||
// accessController: {
|
||||
// write: ['another-key', 'yet-another-key', orbitdb.identity.id]
|
||||
// }
|
||||
// })
|
||||
// assert.deepEqual(db.access.write, ['another-key', 'yet-another-key', orbitdb.identity.id])
|
||||
// })
|
||||
|
||||
// it('creates an access controller and doesn\'t add read access keys', async () => {
|
||||
// db = await orbitdb.create('seventh', 'feed', { read: ['one', 'two'] })
|
||||
// assert.deepEqual(db.access.write, [orbitdb.identity.id])
|
||||
// })
|
||||
// })
|
||||
// describe('Meta', function () {
|
||||
// before(async () => {
|
||||
// if (db) {
|
||||
// await db.close()
|
||||
// await db.drop()
|
||||
// }
|
||||
// })
|
||||
|
||||
// afterEach(async () => {
|
||||
// if (db) {
|
||||
// await db.close()
|
||||
// await db.drop()
|
||||
// }
|
||||
// })
|
||||
|
||||
// it('creates a manifest with no meta field', async () => {
|
||||
// db = await orbitdb.create('no-meta', 'feed')
|
||||
// const manifest = await io.read(ipfs, db.address.root)
|
||||
// assert.strictEqual(manifest.meta, undefined)
|
||||
// assert.deepStrictEqual(Object.keys(manifest).filter(k => k === 'meta'), [])
|
||||
// })
|
||||
|
||||
// it('creates a manifest with a meta field', async () => {
|
||||
// const meta = { test: 123 }
|
||||
// db = await orbitdb.create('meta', 'feed', { meta })
|
||||
// const manifest = await io.read(ipfs, db.address.root)
|
||||
// assert.deepStrictEqual(manifest.meta, meta)
|
||||
// assert.deepStrictEqual(Object.keys(manifest).filter(k => k === 'meta'), ['meta'])
|
||||
// })
|
||||
// })
|
||||
// })
|
||||
// })
|
||||
|
||||
// describe('determineAddress', function () {
|
||||
// describe('Errors', function () {
|
||||
// it('throws an error if given an invalid database type', async () => {
|
||||
// let err
|
||||
// try {
|
||||
// await orbitdb.determineAddress('first', 'invalid-type')
|
||||
// } catch (e) {
|
||||
// err = e.toString()
|
||||
// }
|
||||
// assert.equal(err, 'Error: Invalid database type \'invalid-type\'')
|
||||
// })
|
||||
|
||||
// it('throws an error if given an address instead of name', async () => {
|
||||
// let err
|
||||
// try {
|
||||
// await orbitdb.determineAddress('/orbitdb/Qmc9PMho3LwTXSaUXJ8WjeBZyXesAwUofdkGeadFXsqMzW/first', 'feed')
|
||||
// } catch (e) {
|
||||
// err = e.toString()
|
||||
// }
|
||||
// assert.equal(err, 'Error: Given database name is an address. Please give only the name of the database!')
|
||||
// })
|
||||
// })
|
||||
|
||||
// describe('Success', function () {
|
||||
// before(async () => {
|
||||
// address = await orbitdb.determineAddress('third', 'feed', { replicate: false })
|
||||
// localDataPath = path.join(dbPath, address.root, address.path)
|
||||
// })
|
||||
|
||||
// it('does not save the address locally', async () => {
|
||||
// assert.equal(fs.existsSync(localDataPath), false)
|
||||
// })
|
||||
|
||||
// it('returns the address that would have been created', async () => {
|
||||
// const db = await orbitdb.create('third', 'feed', { replicate: false })
|
||||
// assert.equal(address.toString().indexOf('/orbitdb'), 0)
|
||||
// assert.equal(address.toString().indexOf('zd'), 9)
|
||||
// assert.equal(address.toString(), db.address.toString())
|
||||
// await db.close()
|
||||
// })
|
||||
// })
|
||||
// })
|
||||
|
||||
// describe('Open', function () {
|
||||
// it('throws an error if trying to open a database with name only and \'create\' is not set to \'true\'', async () => {
|
||||
// let err
|
||||
// try {
|
||||
// db = await orbitdb.open('XXX', { create: false })
|
||||
// } catch (e) {
|
||||
// err = e.toString()
|
||||
// }
|
||||
// assert.equal(err, "Error: 'options.create' set to 'false'. If you want to create a database, set 'options.create' to 'true'.")
|
||||
// })
|
||||
|
||||
// it('throws an error if trying to open a database with name only and \'create\' is not set to true', async () => {
|
||||
// let err
|
||||
// try {
|
||||
// db = await orbitdb.open('YYY', { create: true })
|
||||
// } catch (e) {
|
||||
// err = e.toString()
|
||||
// }
|
||||
// assert.equal(err, `Error: Database type not provided! Provide a type with 'options.type' (${OrbitDB.databaseTypes.join('|')})`)
|
||||
// })
|
||||
|
||||
// it('opens a database - name only', async () => {
|
||||
// const db = await orbitdb.open('abc', { create: true, type: 'feed', overwrite: true })
|
||||
// assert.equal(db.address.toString().indexOf('/orbitdb'), 0)
|
||||
// assert.equal(db.address.toString().indexOf('zd'), 9)
|
||||
// assert.equal(db.address.toString().indexOf('abc'), 59)
|
||||
// await db.drop()
|
||||
// })
|
||||
|
||||
// it('opens a database - with a different identity', async () => {
|
||||
// const identity = await Identities.createIdentity({ id: 'test-id', keystore: orbitdb.keystore })
|
||||
// const db = await orbitdb.open('abc', { create: true, type: 'feed', overwrite: true, identity })
|
||||
// assert.equal(db.address.toString().indexOf('/orbitdb'), 0)
|
||||
// assert.equal(db.address.toString().indexOf('zd'), 9)
|
||||
// assert.equal(db.address.toString().indexOf('abc'), 59)
|
||||
// assert.equal(db.identity, identity)
|
||||
// await db.drop()
|
||||
// })
|
||||
|
||||
// it('opens the same database - from an address', async () => {
|
||||
// const identity = await Identities.createIdentity({ id: 'test-id', keystore: orbitdb.keystore })
|
||||
// const db = await orbitdb.open('abc', { create: true, type: 'feed', overwrite: true, identity })
|
||||
// const db2 = await orbitdb.open(db.address)
|
||||
// assert.equal(db2.address.toString().indexOf('/orbitdb'), 0)
|
||||
// assert.equal(db2.address.toString().indexOf('zd'), 9)
|
||||
// assert.equal(db2.address.toString().indexOf('abc'), 59)
|
||||
// await db.drop()
|
||||
// await db2.drop()
|
||||
// })
|
||||
|
||||
// it('opens a database and adds the creator as the only writer', async () => {
|
||||
// const db = await orbitdb.open('abc', { create: true, type: 'feed', overwrite: true })
|
||||
// assert.equal(db.access.write.length, 1)
|
||||
// assert.equal(db.access.write[0], db.identity.id)
|
||||
// await db.drop()
|
||||
// })
|
||||
|
||||
// it('doesn\'t open a database if we don\'t have it locally', async () => {
|
||||
// const db = await orbitdb.open('abcabc', { create: true, type: 'feed', overwrite: true })
|
||||
// const address = new OrbitDBAddress(db.address.root.slice(0, -1) + 'A', 'non-existent')
|
||||
// await db.drop()
|
||||
// return new Promise((resolve, reject) => {
|
||||
// setTimeout(resolve, 900)
|
||||
// orbitdb.open(address)
|
||||
// .then(() => reject(new Error('Shouldn\'t open the database')))
|
||||
// .catch(reject)
|
||||
// })
|
||||
// })
|
||||
|
||||
// it('throws an error if trying to open a database locally and we don\'t have it', async () => {
|
||||
// const db = await orbitdb.open('abc', { create: true, type: 'feed', overwrite: true })
|
||||
// const address = new OrbitDBAddress(db.address.root.slice(0, -1) + 'A', 'second')
|
||||
// await db.drop()
|
||||
// return orbitdb.open(address, { localOnly: true })
|
||||
// .then(() => new Error('Shouldn\'t open the database'))
|
||||
// .catch(e => {
|
||||
// assert.equal(e.toString(), `Error: Database '${address}' doesn't exist!`)
|
||||
// })
|
||||
// })
|
||||
|
||||
// it('open the database and it has the added entries', async () => {
|
||||
// const db = await orbitdb.open('ZZZ', { create: true, type: 'feed' })
|
||||
// await db.add('hello1')
|
||||
// await db.add('hello2')
|
||||
// await db.close()
|
||||
|
||||
// const db2 = await orbitdb.open(db.address)
|
||||
|
||||
// await db.load()
|
||||
// const res = db.iterator({ limit: -1 }).collect()
|
||||
|
||||
// assert.equal(res.length, 2)
|
||||
// assert.equal(res[0].payload.value, 'hello1')
|
||||
// assert.equal(res[1].payload.value, 'hello2')
|
||||
// await db.drop()
|
||||
// await db2.drop()
|
||||
// })
|
||||
// })
|
||||
|
||||
// describe("Close", function () {
|
||||
// before(async () => {
|
||||
// if (orbitdb) await orbitdb.stop()
|
||||
// orbitdb = await OrbitDB.createInstance(ipfs, { directory: dbPath })
|
||||
// })
|
||||
// it('closes a custom store', async () => {
|
||||
// const directory = path.join(dbPath, "custom-store")
|
||||
// const db = await orbitdb.open('xyz', { create: true, type: 'feed', directory })
|
||||
// await db.close()
|
||||
// assert.strictEqual(db._cache.status, 'closed')
|
||||
// })
|
||||
|
||||
// it("close load close sets status to 'closed'", async () => {
|
||||
// const directory = path.join(dbPath, "custom-store")
|
||||
// const db = await orbitdb.open('xyz', { create: true, type: 'feed', directory })
|
||||
// await db.close()
|
||||
// await db.load()
|
||||
// await db.close()
|
||||
// assert.strictEqual(db._cache.status, 'closed')
|
||||
// })
|
||||
|
||||
// it('successfully manages multiple caches', async () => {
|
||||
// // Cleaning up cruft from other tests
|
||||
// const directory = path.join(dbPath, "custom-store")
|
||||
// const directory2 = path.join(dbPath, "custom-store2")
|
||||
|
||||
// const db1 = await orbitdb.open('xyz1', { create: true, type: 'feed', })
|
||||
// const db2 = await orbitdb.open('xyz2', { create: true, type: 'feed', directory })
|
||||
// const db3 = await orbitdb.open('xyz3', { create: true, type: 'feed', directory })
|
||||
// const db4 = await orbitdb.open('xyz4', { create: true, type: 'feed', directory: directory2 })
|
||||
// const db5 = await orbitdb.open('xyz5', { create: true, type: 'feed', })
|
||||
|
||||
// await db1.close()
|
||||
// await db2.close()
|
||||
// await db4.close()
|
||||
|
||||
// assert.strictEqual(orbitdb.cache._store.status, 'open')
|
||||
// assert.strictEqual(db2._cache.status, 'open')
|
||||
// assert.strictEqual(db3._cache.status, 'open')
|
||||
// assert.strictEqual(db4._cache.status, 'closed')
|
||||
|
||||
// await db3.close()
|
||||
// await db5.close()
|
||||
|
||||
// assert.strictEqual(orbitdb.cache._store.status, 'closed')
|
||||
// assert.strictEqual(db2._cache.status, 'closed')
|
||||
// assert.strictEqual(db3._cache.status, 'closed')
|
||||
// assert.strictEqual(db4._cache.status, 'closed')
|
||||
// assert.strictEqual(db5._cache.status, 'closed')
|
||||
// })
|
||||
// })
|
||||
// })
|
||||
// })
|
@ -65,7 +65,7 @@ describe('Identities', function () {
|
||||
})
|
||||
})
|
||||
|
||||
describe.skip('Passing in custom keystore', async () => {
|
||||
describe('Passing in custom keystore', async () => {
|
||||
const id = 'userB'
|
||||
|
||||
let identity
|
||||
|
@ -1,85 +0,0 @@
|
||||
// import fs from 'fs'
|
||||
// import path from 'path'
|
||||
// import assert from 'assert'
|
||||
// import mapSeries from 'p-map-series'
|
||||
// import rmrf from 'rimraf'
|
||||
// import OrbitDB from '../src/OrbitDB.js'
|
||||
// import Identities from 'orbit-db-identity-provider'
|
||||
// import Keystore from 'orbit-db-keystore'
|
||||
// import storageAdapter from 'orbit-db-storage-adapter'
|
||||
|
||||
// // Include test utilities
|
||||
// import {
|
||||
// config,
|
||||
// startIpfs,
|
||||
// stopIpfs,
|
||||
// testAPIs,
|
||||
// } from 'orbit-db-test-utils'
|
||||
|
||||
// const storage = storageAdapter()
|
||||
|
||||
// const dbPath1 = './orbitdb/tests/offline/db1'
|
||||
// const dbPath2 = './orbitdb/tests/offline/db2'
|
||||
|
||||
// Object.keys(testAPIs).forEach(API => {
|
||||
// describe(`orbit-db - Offline mode (${API})`, function() {
|
||||
// this.timeout(config.timeout)
|
||||
|
||||
// let ipfsd1, ipfsd2, ipfs1, ipfs2, orbitdb, db, keystore
|
||||
// let identity1, identity2
|
||||
// let localDataPath
|
||||
|
||||
// before(async () => {
|
||||
// rmrf.sync(dbPath1)
|
||||
// rmrf.sync(dbPath2)
|
||||
// ipfsd1 = await startIpfs(API, config.daemon1)
|
||||
// ipfsd2 = await startIpfs(API, config.daemon2)
|
||||
// ipfs1 = ipfsd1.api
|
||||
// ipfs2 = ipfsd2.api
|
||||
// })
|
||||
|
||||
// after(async () => {
|
||||
// if(orbitdb)
|
||||
// await orbitdb.stop()
|
||||
|
||||
// if (ipfsd1)
|
||||
// await stopIpfs(ipfsd1)
|
||||
// if (ipfsd2)
|
||||
// await stopIpfs(ipfsd2)
|
||||
// })
|
||||
|
||||
// beforeEach(() => {
|
||||
// rmrf.sync(dbPath1)
|
||||
// rmrf.sync(dbPath2)
|
||||
// })
|
||||
|
||||
// it('starts in offline mode', async () => {
|
||||
// orbitdb = await OrbitDB.createInstance(ipfs1, { id: 'A', offline: true, directory: dbPath1 })
|
||||
// assert.equal(orbitdb._pubsub, null)
|
||||
// await orbitdb.stop()
|
||||
// })
|
||||
|
||||
// it('does not start in offline mode', async () => {
|
||||
// orbitdb = await OrbitDB.createInstance(ipfs1, { offline: false, directory: dbPath1 })
|
||||
// assert.notEqual(orbitdb._pubsub, null)
|
||||
// await orbitdb.stop()
|
||||
// })
|
||||
|
||||
// it('does not start in offline mode - default', async () => {
|
||||
// orbitdb = await OrbitDB.createInstance(ipfs1, { directory: dbPath1 })
|
||||
// assert.notEqual(orbitdb._pubsub, null)
|
||||
// await orbitdb.stop()
|
||||
// })
|
||||
|
||||
// it('throws error if no `id` passed in offline mode', async () => {
|
||||
// let err
|
||||
// try {
|
||||
// orbitdb = await OrbitDB.createInstance(ipfs1, { offline: true, directory: dbPath1 })
|
||||
// } catch (e) {
|
||||
// err = e.message
|
||||
// }
|
||||
// assert.equal(err, 'Offline mode requires passing an `id` in the options')
|
||||
// await orbitdb.stop()
|
||||
// })
|
||||
// })
|
||||
// })
|
@ -7,7 +7,7 @@ import connectPeers from './utils/connect-nodes.js'
|
||||
import waitFor from './utils/wait-for.js'
|
||||
|
||||
describe('Replicating databases', function () {
|
||||
this.timeout(60000)
|
||||
this.timeout(30000)
|
||||
|
||||
let ipfs1, ipfs2
|
||||
let orbitdb1, orbitdb2
|
||||
|
@ -1,297 +0,0 @@
|
||||
// import assert from 'assert'
|
||||
// import mapSeries from 'p-map-series'
|
||||
// import rmrf from 'rimraf'
|
||||
// import path from 'path'
|
||||
// import OrbitDB from '../src/OrbitDB.js'
|
||||
// import Cache from 'orbit-db-cache'
|
||||
// import Storage from 'orbit-db-storage-adapter'
|
||||
|
||||
// // Include test utilities
|
||||
// import {
|
||||
// config,
|
||||
// startIpfs,
|
||||
// stopIpfs,
|
||||
// testAPIs
|
||||
// } from 'orbit-db-test-utils'
|
||||
|
||||
// const dbPath = './orbitdb/tests/persistency'
|
||||
|
||||
// const tests = [
|
||||
// {
|
||||
// title: 'Persistency',
|
||||
// orbitDBConfig: { directory: path.join(dbPath, '1') }
|
||||
// },
|
||||
// ]
|
||||
|
||||
// Object.keys(testAPIs).forEach(API => {
|
||||
// tests.forEach(test => {
|
||||
// describe(`orbit-db - ${test.title} (${API})`, function() {
|
||||
// this.timeout(config.timeout)
|
||||
|
||||
// const entryCount = 65
|
||||
|
||||
// let ipfsd, ipfs, orbitdb1, db, address
|
||||
|
||||
// before(async () => {
|
||||
// const options = Object.assign({}, test.orbitDBConfig)
|
||||
|
||||
// rmrf.sync(dbPath)
|
||||
// ipfsd = await startIpfs(API, config.daemon1)
|
||||
// ipfs = ipfsd.api
|
||||
// orbitdb1 = await OrbitDB.createInstance(ipfs, options)
|
||||
// })
|
||||
|
||||
// after(async () => {
|
||||
// if(orbitdb1)
|
||||
// await orbitdb1.stop()
|
||||
|
||||
// if (ipfsd)
|
||||
// await stopIpfs(ipfsd)
|
||||
// })
|
||||
|
||||
// describe('load', function() {
|
||||
// beforeEach(async () => {
|
||||
// const dbName = new Date().getTime().toString()
|
||||
// const entryArr = []
|
||||
|
||||
// for (let i = 0; i < entryCount; i ++)
|
||||
// entryArr.push(i)
|
||||
|
||||
// db = await orbitdb1.eventlog(dbName)
|
||||
// address = db.address.toString()
|
||||
// await mapSeries(entryArr, (i) => db.add('hello' + i))
|
||||
// await db.close()
|
||||
// db = null
|
||||
// })
|
||||
|
||||
// afterEach(async () => {
|
||||
// await db.drop()
|
||||
// })
|
||||
|
||||
// it('loads database from local cache', async () => {
|
||||
// db = await orbitdb1.eventlog(address)
|
||||
// await db.load()
|
||||
// const items = db.iterator({ limit: -1 }).collect()
|
||||
// assert.equal(items.length, entryCount)
|
||||
// assert.equal(items[0].payload.value, 'hello0')
|
||||
// assert.equal(items[items.length - 1].payload.value, 'hello' + (entryCount - 1))
|
||||
// })
|
||||
|
||||
// it('loads database partially', async () => {
|
||||
// const amount = 33
|
||||
// db = await orbitdb1.eventlog(address)
|
||||
// await db.load(amount)
|
||||
// const items = db.iterator({ limit: -1 }).collect()
|
||||
// assert.equal(items.length, amount)
|
||||
// assert.equal(items[0].payload.value, 'hello' + (entryCount - amount))
|
||||
// assert.equal(items[1].payload.value, 'hello' + (entryCount - amount + 1))
|
||||
// assert.equal(items[items.length - 1].payload.value, 'hello' + (entryCount - 1))
|
||||
// })
|
||||
|
||||
// it('load and close several times', async () => {
|
||||
// const amount = 8
|
||||
// for (let i = 0; i < amount; i ++) {
|
||||
// db = await orbitdb1.eventlog(address)
|
||||
// await db.load()
|
||||
// const items = db.iterator({ limit: -1 }).collect()
|
||||
// assert.equal(items.length, entryCount)
|
||||
// assert.equal(items[0].payload.value, 'hello0')
|
||||
// assert.equal(items[1].payload.value, 'hello1')
|
||||
// assert.equal(items[items.length - 1].payload.value, 'hello' + (entryCount - 1))
|
||||
// await db.close()
|
||||
// }
|
||||
// })
|
||||
|
||||
// it('closes database while loading', async () => {
|
||||
// db = await orbitdb1.eventlog(address, { replicationConcurrency: 1 })
|
||||
// return new Promise(async (resolve, reject) => {
|
||||
// // don't wait for load to finish
|
||||
// db.load()
|
||||
// .then(() => reject("Should not finish loading?"))
|
||||
// .catch(e => {
|
||||
// if (e.code !== 'LEVEL_DATABASE_NOT_OPEN') {
|
||||
// reject(e)
|
||||
// } else {
|
||||
// assert.equal(db._cache.store, null)
|
||||
// resolve()
|
||||
// }
|
||||
// })
|
||||
// await db.close()
|
||||
// })
|
||||
// })
|
||||
|
||||
// it('load, add one, close - several times', async () => {
|
||||
// const amount = 8
|
||||
// for (let i = 0; i < amount; i ++) {
|
||||
// db = await orbitdb1.eventlog(address)
|
||||
// await db.load()
|
||||
// await db.add('hello' + (entryCount + i))
|
||||
// const items = db.iterator({ limit: -1 }).collect()
|
||||
// assert.equal(items.length, entryCount + i + 1)
|
||||
// assert.equal(items[items.length - 1].payload.value, 'hello' + (entryCount + i))
|
||||
// await db.close()
|
||||
// }
|
||||
// })
|
||||
|
||||
// it('loading a database emits \'ready\' event', async () => {
|
||||
// db = await orbitdb1.eventlog(address)
|
||||
// return new Promise(async (resolve) => {
|
||||
// db.events.on('ready', () => {
|
||||
// const items = db.iterator({ limit: -1 }).collect()
|
||||
// assert.equal(items.length, entryCount)
|
||||
// assert.equal(items[0].payload.value, 'hello0')
|
||||
// assert.equal(items[items.length - 1].payload.value, 'hello' + (entryCount - 1))
|
||||
// resolve()
|
||||
// })
|
||||
// await db.load()
|
||||
// })
|
||||
// })
|
||||
|
||||
// it('loading a database emits \'load.progress\' event', async () => {
|
||||
// db = await orbitdb1.eventlog(address)
|
||||
// return new Promise(async (resolve, reject) => {
|
||||
// let count = 0
|
||||
// db.events.on('load.progress', (address, hash, entry) => {
|
||||
// count ++
|
||||
// try {
|
||||
// assert.equal(address, db.address.toString())
|
||||
|
||||
// const { progress, max } = db.replicationStatus
|
||||
// assert.equal(max, entryCount)
|
||||
// assert.equal(progress, count)
|
||||
|
||||
// assert.notEqual(hash, null)
|
||||
// assert.notEqual(entry, null)
|
||||
|
||||
// if (progress === entryCount && count === entryCount) {
|
||||
// setTimeout(() => {
|
||||
// resolve()
|
||||
// }, 200)
|
||||
// }
|
||||
// } catch (e) {
|
||||
// reject(e)
|
||||
// }
|
||||
// })
|
||||
// // Start loading the database
|
||||
// await db.load()
|
||||
// })
|
||||
// })
|
||||
// })
|
||||
|
||||
// describe('load from empty snapshot', function() {
|
||||
// it('loads database from an empty snapshot', async () => {
|
||||
// db = await orbitdb1.eventlog('empty-snapshot')
|
||||
// address = db.address.toString()
|
||||
// await db.saveSnapshot()
|
||||
// await db.close()
|
||||
|
||||
// db = await orbitdb1.open(address)
|
||||
// await db.loadFromSnapshot()
|
||||
// const items = db.iterator({ limit: -1 }).collect()
|
||||
// assert.equal(items.length, 0)
|
||||
// })
|
||||
// })
|
||||
|
||||
// describe('load from snapshot', function() {
|
||||
// beforeEach(async () => {
|
||||
// const dbName = new Date().getTime().toString()
|
||||
// const entryArr = []
|
||||
|
||||
// for (let i = 0; i < entryCount; i ++)
|
||||
// entryArr.push(i)
|
||||
|
||||
// db = await orbitdb1.eventlog(dbName)
|
||||
// address = db.address.toString()
|
||||
// await mapSeries(entryArr, (i) => db.add('hello' + i))
|
||||
// await db.saveSnapshot()
|
||||
// await db.close()
|
||||
// db = null
|
||||
// })
|
||||
|
||||
// afterEach(async () => {
|
||||
// await db.drop()
|
||||
// })
|
||||
|
||||
// it('loads database from snapshot', async () => {
|
||||
// db = await orbitdb1.eventlog(address)
|
||||
// await db.loadFromSnapshot()
|
||||
// const items = db.iterator({ limit: -1 }).collect()
|
||||
// assert.equal(items.length, entryCount)
|
||||
// assert.equal(items[0].payload.value, 'hello0')
|
||||
// assert.equal(items[entryCount - 1].payload.value, 'hello' + (entryCount - 1))
|
||||
// })
|
||||
|
||||
// it('load, add one and save snapshot several times', async () => {
|
||||
// const amount = 4
|
||||
// for (let i = 0; i < amount; i ++) {
|
||||
// db = await orbitdb1.eventlog(address)
|
||||
// await db.loadFromSnapshot()
|
||||
// await db.add('hello' + (entryCount + i))
|
||||
// const items = db.iterator({ limit: -1 }).collect()
|
||||
// assert.equal(items.length, entryCount + i + 1)
|
||||
// assert.equal(items[0].payload.value, 'hello0')
|
||||
// assert.equal(items[items.length - 1].payload.value, 'hello' + (entryCount + i))
|
||||
// await db.saveSnapshot()
|
||||
// await db.close()
|
||||
// }
|
||||
// })
|
||||
|
||||
// it('throws an error when trying to load a missing snapshot', async () => {
|
||||
// db = await orbitdb1.eventlog(address)
|
||||
// await db.drop()
|
||||
// db = null
|
||||
// db = await orbitdb1.eventlog(address)
|
||||
|
||||
// let err
|
||||
// try {
|
||||
// await db.loadFromSnapshot()
|
||||
// } catch (e) {
|
||||
// err = e.toString()
|
||||
// }
|
||||
// assert.equal(err, `Error: Snapshot for ${address} not found!`)
|
||||
// })
|
||||
|
||||
// it('loading a database emits \'ready\' event', async () => {
|
||||
// db = await orbitdb1.eventlog(address)
|
||||
// return new Promise(async (resolve) => {
|
||||
// db.events.on('ready', () => {
|
||||
// const items = db.iterator({ limit: -1 }).collect()
|
||||
// assert.equal(items.length, entryCount)
|
||||
// assert.equal(items[0].payload.value, 'hello0')
|
||||
// assert.equal(items[entryCount - 1].payload.value, 'hello' + (entryCount - 1))
|
||||
// resolve()
|
||||
// })
|
||||
// await db.loadFromSnapshot()
|
||||
// })
|
||||
// })
|
||||
|
||||
// it('loading a database emits \'load.progress\' event', async () => {
|
||||
// db = await orbitdb1.eventlog(address)
|
||||
// return new Promise(async (resolve, reject) => {
|
||||
// let count = 0
|
||||
// db.events.on('load.progress', (address, hash, entry) => {
|
||||
// count ++
|
||||
// try {
|
||||
// assert.equal(address, db.address.toString())
|
||||
|
||||
// const { progress, max } = db.replicationStatus
|
||||
// assert.equal(max, entryCount)
|
||||
// assert.equal(progress, count)
|
||||
|
||||
// assert.notEqual(hash, null)
|
||||
// assert.notEqual(entry, null)
|
||||
// if (progress === entryCount && count === entryCount) {
|
||||
// resolve()
|
||||
// }
|
||||
// } catch (e) {
|
||||
// reject(e)
|
||||
// }
|
||||
// })
|
||||
// // Start loading the database
|
||||
// await db.loadFromSnapshot()
|
||||
// })
|
||||
// })
|
||||
// })
|
||||
// })
|
||||
// })
|
||||
// })
|
@ -1,22 +0,0 @@
|
||||
// import assert from 'assert'
|
||||
// import OrbitDB from '../src/OrbitDB.js'
|
||||
|
||||
// const AccessControllers = OrbitDB.AccessControllers
|
||||
// const Identities = OrbitDB.Identities
|
||||
// const Keystore = OrbitDB.Keystore
|
||||
|
||||
// describe('Re-exports', function () {
|
||||
// it('Successfully re-exports AccessControllers', () => {
|
||||
// assert.strictEqual(typeof AccessControllers, 'function')
|
||||
// assert.strictEqual(typeof AccessControllers.addAccessController, 'function')
|
||||
// })
|
||||
|
||||
// it('Successfully re-exports Identities', () => {
|
||||
// assert.strictEqual(typeof Identities, 'function')
|
||||
// assert.strictEqual(typeof Identities.createIdentity, 'function')
|
||||
// })
|
||||
|
||||
// it('Successfully re-exports Keystore', () => {
|
||||
// assert.strictEqual(typeof Keystore, 'function')
|
||||
// })
|
||||
// })
|
@ -1,164 +0,0 @@
|
||||
// import assert from 'assert'
|
||||
// import mapSeries from 'p-each-series'
|
||||
// import rmrf from 'rimraf'
|
||||
// import OrbitDB from '../src/OrbitDB.js'
|
||||
|
||||
// // Include test utilities
|
||||
// import {
|
||||
// config,
|
||||
// startIpfs,
|
||||
// stopIpfs,
|
||||
// testAPIs,
|
||||
// connectPeers,
|
||||
// waitForPeers,
|
||||
// } from 'orbit-db-test-utils'
|
||||
|
||||
// const orbitdbPath1 = './orbitdb/tests/replicate-and-load/1'
|
||||
// const orbitdbPath2 = './orbitdb/tests/replicate-and-load/2'
|
||||
// const dbPath1 = './orbitdb/tests/replicate-and-load/1/db1'
|
||||
// const dbPath2 = './orbitdb/tests/replicate-and-load/2/db2'
|
||||
|
||||
// Object.keys(testAPIs).forEach(API => {
|
||||
// describe(`orbit-db - Replicate and Load (${API})`, function() {
|
||||
// this.timeout(config.timeout)
|
||||
|
||||
// let ipfsd1, ipfsd2, ipfs1, ipfs2
|
||||
// let orbitdb1, orbitdb2
|
||||
|
||||
// before(async () => {
|
||||
// rmrf.sync(orbitdbPath1)
|
||||
// rmrf.sync(orbitdbPath2)
|
||||
// rmrf.sync(dbPath1)
|
||||
// rmrf.sync(dbPath2)
|
||||
// ipfsd1 = await startIpfs(API, config.daemon1)
|
||||
// ipfsd2 = await startIpfs(API, config.daemon2)
|
||||
// ipfs1 = ipfsd1.api
|
||||
// ipfs2 = ipfsd2.api
|
||||
// orbitdb1 = await OrbitDB.createInstance(ipfs1, { directory: orbitdbPath1 })
|
||||
// orbitdb2 = await OrbitDB.createInstance(ipfs2, { directory: orbitdbPath2 })
|
||||
// // Connect the peers manually to speed up test times
|
||||
// const isLocalhostAddress = (addr) => addr.toString().includes('127.0.0.1')
|
||||
// await connectPeers(ipfs1, ipfs2, { filter: isLocalhostAddress })
|
||||
// console.log("Peers connected")
|
||||
// })
|
||||
|
||||
// after(async () => {
|
||||
// if(orbitdb1)
|
||||
// await orbitdb1.stop()
|
||||
|
||||
// if(orbitdb2)
|
||||
// await orbitdb2.stop()
|
||||
|
||||
// if (ipfsd1)
|
||||
// await stopIpfs(ipfsd1)
|
||||
|
||||
// if (ipfsd2)
|
||||
// await stopIpfs(ipfsd2)
|
||||
|
||||
// rmrf.sync(dbPath1)
|
||||
// rmrf.sync(dbPath2)
|
||||
// })
|
||||
|
||||
// describe('two peers', function() {
|
||||
// let db1, db2
|
||||
|
||||
// const openDatabases = async (options = {}) => {
|
||||
// // Set write access for both clients
|
||||
// options.write = [
|
||||
// orbitdb1.identity.publicKey,
|
||||
// orbitdb2.identity.publicKey
|
||||
// ]
|
||||
|
||||
// options = Object.assign({}, options, { path: dbPath1, create: true })
|
||||
// db1 = await orbitdb1.eventlog('tests', options)
|
||||
// // Set 'localOnly' flag on and it'll error if the database doesn't exist locally
|
||||
// options = Object.assign({}, options, { path: dbPath2 })
|
||||
// db2 = await orbitdb2.eventlog(db1.address.toString(), options)
|
||||
// }
|
||||
|
||||
// before(async () => {
|
||||
// await openDatabases()
|
||||
|
||||
// assert.equal(db1.address.toString(), db2.address.toString())
|
||||
|
||||
// console.log("Waiting for peers...")
|
||||
// await waitForPeers(ipfs1, [orbitdb2.id], db1.address.toString())
|
||||
// await waitForPeers(ipfs2, [orbitdb1.id], db1.address.toString())
|
||||
// })
|
||||
|
||||
// after(async () => {
|
||||
// if (db1) {
|
||||
// await db1.drop()
|
||||
// }
|
||||
|
||||
// if (db2) {
|
||||
// await db2.drop()
|
||||
// }
|
||||
// })
|
||||
|
||||
// it('replicates database of 100 entries and loads it from the disk', async () => {
|
||||
// const entryCount = 100
|
||||
// const entryArr = []
|
||||
// let timer
|
||||
|
||||
// for (let i = 0; i < entryCount; i ++)
|
||||
// entryArr.push(i)
|
||||
|
||||
// console.log("Writing to database...")
|
||||
// await mapSeries(entryArr, (i) => db1.add('hello' + i))
|
||||
// console.log("Done")
|
||||
|
||||
// return new Promise((resolve, reject) => {
|
||||
// timer = setInterval(async () => {
|
||||
// if (db2._oplog.length === entryCount) {
|
||||
// clearInterval(timer)
|
||||
|
||||
// const items = db2.iterator({ limit: -1 }).collect()
|
||||
// assert.equal(items.length, entryCount)
|
||||
// assert.equal(items[0].payload.value, 'hello0')
|
||||
// assert.equal(items[items.length - 1].payload.value, 'hello99')
|
||||
|
||||
// try {
|
||||
|
||||
// // Set write access for both clients
|
||||
// let options = {
|
||||
// accessController: {
|
||||
// write: [
|
||||
// orbitdb1.identity.id,
|
||||
// orbitdb2.identity.id
|
||||
// ]
|
||||
// }
|
||||
// }
|
||||
|
||||
// // Get the previous address to make sure nothing mutates it
|
||||
// const addr = db1.address.toString()
|
||||
|
||||
// // Open the database again (this time from the disk)
|
||||
// options = Object.assign({}, options, { path: dbPath1, create: false })
|
||||
// const db3 = await orbitdb1.eventlog(addr, options)
|
||||
// // Set 'localOnly' flag on and it'll error if the database doesn't exist locally
|
||||
// options = Object.assign({}, options, { path: dbPath2, localOnly: true })
|
||||
// const db4 = await orbitdb2.eventlog(addr, options)
|
||||
|
||||
// await db3.load()
|
||||
// await db4.load()
|
||||
|
||||
// // Make sure we have all the entries in the databases
|
||||
// const result1 = db3.iterator({ limit: -1 }).collect()
|
||||
// const result2 = db4.iterator({ limit: -1 }).collect()
|
||||
// assert.equal(result1.length, entryCount)
|
||||
// assert.equal(result2.length, entryCount)
|
||||
|
||||
// await db3.drop()
|
||||
// await db4.drop()
|
||||
// } catch (e) {
|
||||
// reject(e)
|
||||
// }
|
||||
// resolve()
|
||||
// }
|
||||
// }, 1000)
|
||||
// })
|
||||
// })
|
||||
// })
|
||||
// })
|
||||
// })
|
@ -1,128 +0,0 @@
|
||||
// import assert from 'assert'
|
||||
// import mapSeries from 'p-each-series'
|
||||
// import rmrf from 'rimraf'
|
||||
// import OrbitDB from '../src/OrbitDB.js'
|
||||
|
||||
// // Include test utilities
|
||||
// import {
|
||||
// config,
|
||||
// startIpfs,
|
||||
// stopIpfs,
|
||||
// testAPIs,
|
||||
// connectPeers,
|
||||
// } from 'orbit-db-test-utils'
|
||||
|
||||
// const dbPath1 = './orbitdb/tests/replicate-automatically/1'
|
||||
// const dbPath2 = './orbitdb/tests/replicate-automatically/2'
|
||||
|
||||
// Object.keys(testAPIs).forEach(API => {
|
||||
// describe(`orbit-db - Automatic Replication (${API})`, function() {
|
||||
// this.timeout(config.timeout)
|
||||
|
||||
// let ipfsd1, ipfsd2, ipfs1, ipfs2
|
||||
// let orbitdb1, orbitdb2, db1, db2, db3, db4
|
||||
|
||||
// before(async () => {
|
||||
// rmrf.sync('./orbitdb')
|
||||
// rmrf.sync(dbPath1)
|
||||
// rmrf.sync(dbPath2)
|
||||
// ipfsd1 = await startIpfs(API, config.daemon1)
|
||||
// ipfsd2 = await startIpfs(API, config.daemon2)
|
||||
// ipfs1 = ipfsd1.api
|
||||
// ipfs2 = ipfsd2.api
|
||||
// orbitdb1 = await OrbitDB.createInstance(ipfs1, { directory: dbPath1 })
|
||||
// orbitdb2 = await OrbitDB.createInstance(ipfs2, { directory: dbPath2 })
|
||||
|
||||
// let options = {}
|
||||
// // Set write access for both clients
|
||||
// options.write = [
|
||||
// orbitdb1.identity.publicKey,
|
||||
// orbitdb2.identity.publicKey
|
||||
// ]
|
||||
|
||||
// options = Object.assign({}, options)
|
||||
// db1 = await orbitdb1.eventlog('replicate-automatically-tests', options)
|
||||
// db3 = await orbitdb1.keyvalue('replicate-automatically-tests-kv', options)
|
||||
// })
|
||||
|
||||
// after(async () => {
|
||||
// if (orbitdb1) {
|
||||
// await orbitdb1.stop()
|
||||
// }
|
||||
|
||||
// if (orbitdb2) {
|
||||
// await orbitdb2.stop()
|
||||
// }
|
||||
|
||||
// if (ipfsd1) {
|
||||
// await stopIpfs(ipfsd1)
|
||||
// }
|
||||
|
||||
// if (ipfs2) {
|
||||
// await stopIpfs(ipfsd2)
|
||||
// }
|
||||
|
||||
// rmrf.sync(dbPath1)
|
||||
// rmrf.sync(dbPath2)
|
||||
// })
|
||||
|
||||
// it('starts replicating the database when peers connect', async () => {
|
||||
// const isLocalhostAddress = (addr) => addr.toString().includes('127.0.0.1')
|
||||
// await connectPeers(ipfs1, ipfs2, { filter: isLocalhostAddress })
|
||||
// console.log('Peers connected')
|
||||
|
||||
// const entryCount = 33
|
||||
// const entryArr = []
|
||||
|
||||
// // Create the entries in the first database
|
||||
// for (let i = 0; i < entryCount; i++) {
|
||||
// entryArr.push(i)
|
||||
// }
|
||||
|
||||
// await mapSeries(entryArr, (i) => db1.add('hello' + i))
|
||||
|
||||
// // Open the second database
|
||||
// db2 = await orbitdb2.eventlog(db1.address.toString())
|
||||
// db4 = await orbitdb2.keyvalue(db3.address.toString())
|
||||
|
||||
// // Listen for the 'replicated' events and check that all the entries
|
||||
// // were replicated to the second database
|
||||
// return new Promise((resolve, reject) => {
|
||||
// // Check if db2 was already replicated
|
||||
// let all = db2.iterator({ limit: -1 }).collect().length
|
||||
// // Run the test asserts below if replication was done
|
||||
// let finished = (all === entryCount)
|
||||
|
||||
// db3.events.on('replicated', (address, hash, entry) => {
|
||||
// reject(new Error("db3 should not receive the 'replicated' event!"))
|
||||
// })
|
||||
|
||||
// db4.events.on('replicated', (address, hash, entry) => {
|
||||
// reject(new Error("db4 should not receive the 'replicated' event!"))
|
||||
// })
|
||||
|
||||
// db2.events.on('replicated', (address, length) => {
|
||||
// // Once db2 has finished replication, make sure it has all elements
|
||||
// // and process to the asserts below
|
||||
// all = db2.iterator({ limit: -1 }).collect().length
|
||||
// finished = (all === entryCount)
|
||||
// })
|
||||
|
||||
// try {
|
||||
// const timer = setInterval(() => {
|
||||
// if (finished) {
|
||||
// clearInterval(timer)
|
||||
// const result1 = db1.iterator({ limit: -1 }).collect()
|
||||
// const result2 = db2.iterator({ limit: -1 }).collect()
|
||||
// assert.equal(result1.length, result2.length)
|
||||
// assert.deepEqual(result1, result2)
|
||||
// resolve()
|
||||
// }
|
||||
// }, 1000)
|
||||
// } catch (e) {
|
||||
// reject(e)
|
||||
// }
|
||||
// })
|
||||
// })
|
||||
// })
|
||||
// })
|
Loading…
x
Reference in New Issue
Block a user