parent 32cc9a9b009d0d8543f81a6bab96ad9bcccd3088

author Mark Henderson <mark@mrh.io> 1598051057 -0400
committer Mark Henderson <mark@mrh.io> 1598229380 -0400

parent 32cc9a9b009d0d8543f81a6bab96ad9bcccd3088
author Mark Henderson <mark@mrh.io> 1598051057 -0400
committer Mark Henderson <mark@mrh.io> 1598229291 -0400

package updates and ipfs repo migration

validate-maintainers and orbit-db-test-utils

moving from 3 tabs to 2

wait workaround

wait 1000

standard --fix

redoing the replication test changes for some reason

validate-maintainers and orbit-db-test-utils

moving from 3 tabs to 2

wait workaround

wait 1000

standard --fix

fix create-open tests

fixing eventlog tests

fixing feed tests

fixing kvstore tests

fixing set identity tests

skipping replication tests for now

repo path based on API variable

js-ipfs.zip

go-ipfs.zip

skipping replicate tests as well

repo path based on API variable

js-ipfs.zip

go-ipfs.zip

package-lock

finalizing rebase
This commit is contained in:
Mark Henderson 2020-08-21 19:04:17 -04:00 committed by Mark Robert Henderson
parent 32cc9a9b00
commit 39a00060d6
16 changed files with 7620 additions and 5625 deletions

View File

@ -24,7 +24,7 @@ module.exports = {
plugins: [ plugins: [
new webpack.DefinePlugin({ new webpack.DefinePlugin({
'process.env': { 'process.env': {
'NODE_ENV': JSON.stringify(process.env.NODE_ENV) NODE_ENV: JSON.stringify(process.env.NODE_ENV)
} }
}) })
], ],

View File

@ -18,7 +18,7 @@ module.exports = {
plugins: [ plugins: [
new webpack.DefinePlugin({ new webpack.DefinePlugin({
'process.env': { 'process.env': {
'NODE_ENV': JSON.stringify(process.env.NODE_ENV) NODE_ENV: JSON.stringify(process.env.NODE_ENV)
} }
}) })
], ],

12977
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
{ {
"name": "orbit-db", "name": "orbit-db",
"version": "0.24.2", "version": "0.24.3",
"description": "Distributed p2p database on IPFS", "description": "Distributed p2p database on IPFS",
"author": "Haad", "author": "Haad",
"license": "MIT", "license": "MIT",
@ -13,12 +13,12 @@
}, },
"main": "src/OrbitDB.js", "main": "src/OrbitDB.js",
"dependencies": { "dependencies": {
"cids": "^0.7.1", "cids": "^1.0.0",
"ipfs-pubsub-1on1": "~0.0.6", "ipfs-pubsub-1on1": "~0.0.6",
"is-node": "^1.0.2", "is-node": "^1.0.2",
"localstorage-down": "^0.6.7", "localstorage-down": "^0.6.7",
"logplease": "^1.2.14", "logplease": "^1.2.14",
"multihashes": "^0.4.12", "multihashes": "~3.0.1",
"orbit-db-access-controllers": "^0.2.2", "orbit-db-access-controllers": "^0.2.2",
"orbit-db-cache": "~0.3.0", "orbit-db-cache": "~0.3.0",
"orbit-db-counterstore": "~1.9.0", "orbit-db-counterstore": "~1.9.0",
@ -31,36 +31,36 @@
"orbit-db-kvstore": "~1.9.0", "orbit-db-kvstore": "~1.9.0",
"orbit-db-pubsub": "~0.5.5", "orbit-db-pubsub": "~0.5.5",
"orbit-db-storage-adapter": "~0.5.3", "orbit-db-storage-adapter": "~0.5.3",
"orbit-db-store": "~3.3.0" "orbit-db-store": "~3.3.1"
}, },
"devDependencies": { "devDependencies": {
"adm-zip": "^0.4.13", "adm-zip": "^0.4.16",
"babel-cli": "^6.26.0", "babel-cli": "^6.26.0",
"babel-core": "^6.26.0", "babel-core": "^6.26.0",
"babel-loader": "^7.1.2", "babel-loader": "^8.1.0",
"babel-plugin-transform-runtime": "^6.23.0", "babel-plugin-transform-runtime": "^6.23.0",
"babel-polyfill": "^6.26.0", "babel-polyfill": "^6.26.0",
"babel-preset-env": "^1.7.0", "babel-preset-env": "^1.7.0",
"cpy-cli": "^2.0.0", "cpy-cli": "^3.1.1",
"cross-env": "^6.0.3", "cross-env": "^7.0.2",
"datastore-level": "~0.14.0", "datastore-level": "~2.0.0",
"fs-extra": "^7.0.1", "fs-extra": "^9.0.1",
"localstorage-level-migration": "~0.1.0", "localstorage-level-migration": "~0.1.0",
"markdown-toc": "^1.2.0", "markdown-toc": "^1.2.0",
"mkdirp": "^0.5.1", "mkdirp": "^1.0.4",
"mocha": "^5.2.0", "mocha": "^8.1.1",
"orbit-db-test-utils": "^0.9.4", "orbit-db-test-utils": "^0.10.2",
"p-each-series": "^1.0.0", "p-each-series": "^2.1.0",
"p-map": "^1.2.0", "p-map": "^4.0.0",
"p-map-series": "^1.0.0", "p-map-series": "^2.1.0",
"p-whilst": "^1.0.0", "p-whilst": "^2.1.0",
"pify": "^4.0.1", "pify": "^5.0.0",
"puppeteer": "^1.18.1", "puppeteer": "^5.2.1",
"remark-cli": "^5.0.0", "remark-cli": "^8.0.1",
"remark-validate-links": "^7.0.0", "remark-validate-links": "^10.0.2",
"rimraf": "^2.6.2", "rimraf": "^3.0.2",
"standard": "^12.0.1", "standard": "^14.3.4",
"validate-maintainers": "^1.1.0", "validate-maintainers": "^1.2.2",
"webpack": "^4.41.2", "webpack": "^4.41.2",
"webpack-cli": "^3.3.10" "webpack-cli": "^3.3.10"
}, },

View File

@ -82,7 +82,7 @@ class OrbitDB {
options.offline = false options.offline = false
} }
if (options.offline && !options.id ) { if (options.offline && !options.id) {
throw new Error('Offline mode requires passing an `id` in the options') throw new Error('Offline mode requires passing an `id` in the options')
} }

View File

@ -11,6 +11,13 @@ const {
const clicksPerTab = 20 const clicksPerTab = 20
const numTabs = 3 const numTabs = 3
const wait = async (milliseconds) => {
return new Promise((resolve, reject) => {
console.log("waiting...")
setTimeout(resolve, milliseconds)
})
}
describe(`orbit-db - browser concurrent writes`, function() { describe(`orbit-db - browser concurrent writes`, function() {
this.timeout(numTabs * config.timeout) this.timeout(numTabs * config.timeout)
@ -36,6 +43,7 @@ describe(`orbit-db - browser concurrent writes`, function() {
await page.goto(`file://${path.resolve(__dirname, 'index.html')}`) await page.goto(`file://${path.resolve(__dirname, 'index.html')}`)
page.on('dialog', dialog => dialog.dismiss()) page.on('dialog', dialog => dialog.dismiss())
page.on('pageerror', err => console.error(err)) page.on('pageerror', err => console.error(err))
await wait(1000)
return page return page
} }

View File

@ -24,15 +24,16 @@ const {
const dbPath = path.join('./orbitdb', 'tests', 'create-open') const dbPath = path.join('./orbitdb', 'tests', 'create-open')
const ipfsPath = path.join('./orbitdb', 'tests', 'create-open', 'ipfs') const ipfsPath = path.join('./orbitdb', 'tests', 'create-open', 'ipfs')
const migrationFixturePath = path.join('./test', 'fixtures', 'migration', 'cache-schema-test') const migrationFixturePath = path.join('./test', 'fixtures', 'migration', 'cache-schema-test')
const ipfsFixtures = path.join('./test', 'fixtures', 'ipfs.zip')
const ipfsFixturesDir = path.join('./test', 'fixtures', 'ipfs') const ipfsFixturesDir = path.join('./test', 'fixtures', 'ipfs')
Object.keys(testAPIs).forEach(API => { Object.keys(testAPIs).forEach(API => {
describe(`orbit-db - Create & Open (${API})`, function () { describe(`orbit-db - Create & Open (${API})`, function () {
let ipfsFixtures = path.join('./test', 'fixtures', `${API}.zip`)
this.retries(1) // windows... this.retries(1) // windows...
this.timeout(config.timeout) this.timeout(config.timeout)
let ipfsd, ipfs, orbitdb, db, address let ipfsd, ipfs, orbitdb, address
let localDataPath let localDataPath
const filterFunc = (src, dest) => { const filterFunc = (src, dest) => {
@ -68,7 +69,7 @@ Object.keys(testAPIs).forEach(API => {
it('throws an error if given an invalid database type', async () => { it('throws an error if given an invalid database type', async () => {
let err let err
try { try {
db = await orbitdb.create('first', 'invalid-type') const db = await orbitdb.create('first', 'invalid-type')
} catch (e) { } catch (e) {
err = e.toString() err = e.toString()
} }
@ -78,7 +79,7 @@ Object.keys(testAPIs).forEach(API => {
it('throws an error if given an address instead of name', async () => { it('throws an error if given an address instead of name', async () => {
let err let err
try { try {
db = await orbitdb.create('/orbitdb/Qmc9PMho3LwTXSaUXJ8WjeBZyXesAwUofdkGeadFXsqMzW/first', 'feed') const db = await orbitdb.create('/orbitdb/Qmc9PMho3LwTXSaUXJ8WjeBZyXesAwUofdkGeadFXsqMzW/first', 'feed')
} catch (e) { } catch (e) {
err = e.toString() err = e.toString()
} }
@ -86,14 +87,15 @@ Object.keys(testAPIs).forEach(API => {
}) })
it('throws an error if database already exists', async () => { it('throws an error if database already exists', async () => {
let err let err, db
try { try {
db = await orbitdb.create('first', 'feed', { replicate: false }) db = await orbitdb.create('first', 'feed', { replicate: false })
db = await orbitdb.create('first', 'feed', { replicate: false }) const db2 = await orbitdb.create('first', 'feed', { replicate: false })
} catch (e) { } catch (e) {
err = e.toString() err = e.toString()
} }
assert.equal(err, `Error: Database '${db.address}' already exists!`) assert.equal(err, `Error: Database '${db.address}' already exists!`)
await db.close()
}) })
@ -110,6 +112,8 @@ Object.keys(testAPIs).forEach(API => {
}) })
describe('Success', function () { describe('Success', function () {
let db
before(async () => { before(async () => {
db = await orbitdb.create('second', 'feed', { replicate: false }) db = await orbitdb.create('second', 'feed', { replicate: false })
localDataPath = path.join(dbPath, orbitdb.id, 'cache') localDataPath = path.join(dbPath, orbitdb.id, 'cache')
@ -150,8 +154,9 @@ Object.keys(testAPIs).forEach(API => {
it('can pass local database directory as an option', async () => { it('can pass local database directory as an option', async () => {
const dir = './orbitdb/tests/another-feed' const dir = './orbitdb/tests/another-feed'
db = await orbitdb.create('third', 'feed', { directory: dir }) const db2 = await orbitdb.create('third', 'feed', { directory: dir })
assert.equal(fs.existsSync(dir), true) assert.equal(fs.existsSync(dir), true)
await db2.close()
}) })
it('loads cache from previous version of orbit-db', async () => { it('loads cache from previous version of orbit-db', async () => {
@ -283,19 +288,16 @@ Object.keys(testAPIs).forEach(API => {
}) })
it('returns the address that would have been created', async () => { it('returns the address that would have been created', async () => {
db = await orbitdb.create('third', 'feed', { replicate: false }) const db = await orbitdb.create('third', 'feed', { replicate: false })
assert.equal(address.toString().indexOf('/orbitdb'), 0) assert.equal(address.toString().indexOf('/orbitdb'), 0)
assert.equal(address.toString().indexOf('zd'), 9) assert.equal(address.toString().indexOf('zd'), 9)
assert.equal(address.toString(), db.address.toString()) assert.equal(address.toString(), db.address.toString())
await db.close()
}) })
}) })
}) })
describe('Open', function () { describe('Open', function () {
beforeEach(async () => {
db = await orbitdb.open('abc', { create: true, type: 'feed' })
})
it('throws an error if trying to open a database with name only and \'create\' is not set to \'true\'', async () => { it('throws an error if trying to open a database with name only and \'create\' is not set to \'true\'', async () => {
let err let err
try { try {
@ -317,36 +319,45 @@ Object.keys(testAPIs).forEach(API => {
}) })
it('opens a database - name only', async () => { it('opens a database - name only', async () => {
db = await orbitdb.open('abc', { create: true, type: 'feed', overwrite: true }) 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('/orbitdb'), 0)
assert.equal(db.address.toString().indexOf('zd'), 9) assert.equal(db.address.toString().indexOf('zd'), 9)
assert.equal(db.address.toString().indexOf('abc'), 59) assert.equal(db.address.toString().indexOf('abc'), 59)
await db.drop()
}) })
it('opens a database - with a different identity', async () => { it('opens a database - with a different identity', async () => {
const identity = await Identities.createIdentity({ id: 'test-id', keystore: orbitdb.keystore }) const identity = await Identities.createIdentity({ id: 'test-id', keystore: orbitdb.keystore })
db = await orbitdb.open('abc', { create: true, type: 'feed', overwrite: true, identity }) 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('/orbitdb'), 0)
assert.equal(db.address.toString().indexOf('zd'), 9) assert.equal(db.address.toString().indexOf('zd'), 9)
assert.equal(db.address.toString().indexOf('abc'), 59) assert.equal(db.address.toString().indexOf('abc'), 59)
assert.equal(db.identity, identity) assert.equal(db.identity, identity)
await db.drop()
}) })
it('opens the same database - from an address', async () => { it('opens the same database - from an address', async () => {
db = await orbitdb.open(db.address) const identity = await Identities.createIdentity({ id: 'test-id', keystore: orbitdb.keystore })
assert.equal(db.address.toString().indexOf('/orbitdb'), 0) const db = await orbitdb.open('abc', { create: true, type: 'feed', overwrite: true, identity })
assert.equal(db.address.toString().indexOf('zd'), 9) const db2 = await orbitdb.open(db.address)
assert.equal(db.address.toString().indexOf('abc'), 59) 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 () => { it('opens a database and adds the creator as the only writer', async () => {
db = await orbitdb.open('abc', { create: true, type: 'feed', overwrite: true }) const db = await orbitdb.open('abc', { create: true, type: 'feed', overwrite: true })
assert.equal(db.access.write.length, 1) assert.equal(db.access.write.length, 1)
assert.equal(db.access.write[0], db.identity.id) 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 () => { it('doesn\'t open a database if we don\'t have it locally', async () => {
const db = await orbitdb.open('abc', { create: true, type: 'feed', overwrite: true })
const address = new OrbitDBAddress(db.address.root.slice(0, -1) + 'A', 'non-existent') const address = new OrbitDBAddress(db.address.root.slice(0, -1) + 'A', 'non-existent')
await db.drop()
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
setTimeout(resolve, 900) setTimeout(resolve, 900)
orbitdb.open(address) orbitdb.open(address)
@ -355,8 +366,10 @@ Object.keys(testAPIs).forEach(API => {
}) })
}) })
it('throws an error if trying to open a database locally and we don\'t have it', () => { 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') const address = new OrbitDBAddress(db.address.root.slice(0, -1) + 'A', 'second')
await db.drop()
return orbitdb.open(address, { localOnly: true }) return orbitdb.open(address, { localOnly: true })
.then(() => new Error('Shouldn\'t open the database')) .then(() => new Error('Shouldn\'t open the database'))
.catch(e => { .catch(e => {
@ -365,11 +378,12 @@ Object.keys(testAPIs).forEach(API => {
}) })
it('open the database and it has the added entries', async () => { it('open the database and it has the added entries', async () => {
db = await orbitdb.open('ZZZ', { create: true, type: 'feed' }) const db = await orbitdb.open('ZZZ', { create: true, type: 'feed' })
await db.add('hello1') await db.add('hello1')
await db.add('hello2') await db.add('hello2')
await db.close()
db = await orbitdb.open(db.address) const db2 = await orbitdb.open(db.address)
await db.load() await db.load()
const res = db.iterator({ limit: -1 }).collect() const res = db.iterator({ limit: -1 }).collect()
@ -377,6 +391,8 @@ Object.keys(testAPIs).forEach(API => {
assert.equal(res.length, 2) assert.equal(res.length, 2)
assert.equal(res[0].payload.value, 'hello1') assert.equal(res[0].payload.value, 'hello1')
assert.equal(res[1].payload.value, 'hello2') assert.equal(res[1].payload.value, 'hello2')
await db.drop()
await db2.drop()
}) })
}) })
@ -387,14 +403,14 @@ Object.keys(testAPIs).forEach(API => {
}) })
it('closes a custom store', async () => { it('closes a custom store', async () => {
const directory = path.join(dbPath, "custom-store") const directory = path.join(dbPath, "custom-store")
db = await orbitdb.open('xyz', { create: true, type: 'feed', directory }) const db = await orbitdb.open('xyz', { create: true, type: 'feed', directory })
await db.close() await db.close()
assert.strictEqual(db._cache._store._db.status, 'closed') assert.strictEqual(db._cache._store._db.status, 'closed')
}) })
it("close load close sets status to 'closed'", async () => { it("close load close sets status to 'closed'", async () => {
const directory = path.join(dbPath, "custom-store") const directory = path.join(dbPath, "custom-store")
db = await orbitdb.open('xyz', { create: true, type: 'feed', directory }) const db = await orbitdb.open('xyz', { create: true, type: 'feed', directory })
await db.close() await db.close()
await db.load() await db.load()
await db.close() await db.close()

View File

@ -23,7 +23,7 @@ Object.keys(testAPIs).forEach(API => {
describe(`orbit-db - Log Database (${API})`, function() { describe(`orbit-db - Log Database (${API})`, function() {
this.timeout(config.timeout) this.timeout(config.timeout)
let ipfsd, ipfs, orbitdb1, db let ipfsd, ipfs, orbitdb1
before(async () => { before(async () => {
config.daemon1.repo = ipfsPath config.daemon1.repo = ipfsPath
@ -44,30 +44,34 @@ Object.keys(testAPIs).forEach(API => {
describe('Eventlog', function () { describe('Eventlog', function () {
it('creates and opens a database', async () => { it('creates and opens a database', async () => {
db = await orbitdb1.eventlog('log database') const db = await orbitdb1.eventlog('log database')
assert.notEqual(db, null) assert.notEqual(db, null)
assert.equal(db.type, 'eventlog') assert.equal(db.type, 'eventlog')
assert.equal(db.dbname, 'log database') assert.equal(db.dbname, 'log database')
await db.drop()
}) })
it('returns 0 items when it\'s a fresh database', async () => { it('returns 0 items when it\'s a fresh database', async () => {
db = await orbitdb1.eventlog('log database') const db = await orbitdb1.eventlog('log database')
const items = db.iterator({ limit: -1 }).collect() const items = db.iterator({ limit: -1 }).collect()
assert.equal(items.length, 0) assert.equal(items.length, 0)
await db.drop()
}) })
it('returns the added entry\'s hash, 1 entry', async () => { it('returns the added entry\'s hash, 1 entry', async () => {
db = await orbitdb1.eventlog('first database') const db = await orbitdb1.eventlog('first database')
const hash = await db.add('hello1') const hash = await db.add('hello1')
const items = db.iterator({ limit: -1 }).collect() const items = db.iterator({ limit: -1 }).collect()
assert.notEqual(hash, null) assert.notEqual(hash, null)
assert.equal(hash, last(items).hash) assert.equal(hash, last(items).hash)
assert.equal(items.length, 1) assert.equal(items.length, 1)
await db.drop()
}) })
it('returns the added entry\'s hash, 2 entries', async () => { it('returns the added entry\'s hash, 2 entries', async () => {
db = await orbitdb1.eventlog('first database') const db = await orbitdb1.eventlog('first database')
await db.load() await db.load()
await db.add('hello1')
const prevHash = db.iterator().collect()[0].hash const prevHash = db.iterator().collect()[0].hash
const hash = await db.add('hello2') const hash = await db.add('hello2')
const items = db.iterator({ limit: -1 }).collect() const items = db.iterator({ limit: -1 }).collect()
@ -75,31 +79,35 @@ Object.keys(testAPIs).forEach(API => {
assert.notEqual(hash, null) assert.notEqual(hash, null)
assert.notEqual(hash, prevHash) assert.notEqual(hash, prevHash)
assert.equal(hash, last(items).hash) assert.equal(hash, last(items).hash)
await db.drop()
}) })
it('adds five items', async () => { it('adds five items', async () => {
db = await orbitdb1.eventlog('second database') const db = await orbitdb1.eventlog('second database')
await mapSeries([1, 2, 3, 4, 5], (i) => db.add('hello' + i)) await mapSeries([1, 2, 3, 4, 5], (i) => db.add('hello' + i))
const items = db.iterator({ limit: -1 }).collect() const items = db.iterator({ limit: -1 }).collect()
assert.equal(items.length, 5) assert.equal(items.length, 5)
assert.equal(items[0].payload.value, 'hello1') assert.equal(items[0].payload.value, 'hello1')
assert.equal(last(items.map((f) => f.payload.value)), 'hello5') assert.equal(last(items.map((f) => f.payload.value)), 'hello5')
await db.drop()
}) })
it('adds an item that is > 256 bytes', async () => { it('adds an item that is > 256 bytes', async () => {
db = await orbitdb1.eventlog('third database') const db = await orbitdb1.eventlog('third database')
let msg = Buffer.alloc(1024) let msg = Buffer.alloc(1024)
msg.fill('a') msg.fill('a')
const hash = await db.add(msg.toString()) const hash = await db.add(msg.toString())
assert.notEqual(hash, null) assert.notEqual(hash, null)
assert.equal(hash.startsWith('zd'), true) assert.equal(hash.startsWith('zd'), true)
assert.equal(hash.length, 49) assert.equal(hash.length, 49)
await db.drop()
}) })
}) })
describe('Iterator', function() { describe('Iterator', function() {
let hashes = [] let hashes = []
const itemCount = 5 const itemCount = 5
let db
before(async () => { before(async () => {
hashes = [] hashes = []

View File

@ -23,7 +23,7 @@ Object.keys(testAPIs).forEach(API => {
describe(`orbit-db - Feed Database (${API})`, function() { describe(`orbit-db - Feed Database (${API})`, function() {
this.timeout(config.timeout) this.timeout(config.timeout)
let ipfsd, ipfs, orbitdb1, db, address let ipfsd, ipfs, orbitdb1, address
before(async () => { before(async () => {
config.daemon1.repo = ipfsPath config.daemon1.repo = ipfsPath
@ -44,31 +44,35 @@ Object.keys(testAPIs).forEach(API => {
describe('Feed', function() { describe('Feed', function() {
it('creates and opens a database', async () => { it('creates and opens a database', async () => {
db = await orbitdb1.feed('feed database') const db = await orbitdb1.feed('feed database')
assert.notEqual(db, null) assert.notEqual(db, null)
assert.equal(db.type, 'feed') assert.equal(db.type, 'feed')
assert.equal(db.dbname, 'feed database') assert.equal(db.dbname, 'feed database')
await db.drop()
}) })
it('returns 0 items when it\'s a fresh database', async () => { it('returns 0 items when it\'s a fresh database', async () => {
db = await orbitdb1.feed('feed database') const db = await orbitdb1.feed('feed database')
const items = db.iterator({ limit: -1 }).collect() const items = db.iterator({ limit: -1 }).collect()
assert.equal(items.length, 0) assert.equal(items.length, 0)
await db.drop()
}) })
it('returns the added entry\'s hash, 1 entry', async () => { it('returns the added entry\'s hash, 1 entry', async () => {
db = await orbitdb1.feed('first') const db = await orbitdb1.feed('first')
address = db.address.toString() address = db.address.toString()
const hash = await db.add('hello1') const hash = await db.add('hello1')
const items = db.iterator({ limit: -1 }).collect() const items = db.iterator({ limit: -1 }).collect()
assert.notEqual(hash, null) assert.notEqual(hash, null)
assert.equal(hash, last(items).hash) assert.equal(hash, last(items).hash)
assert.equal(items.length, 1) assert.equal(items.length, 1)
await db.drop()
}) })
it('returns the added entry\'s hash, 2 entries', async () => { it('returns the added entry\'s hash, 2 entries', async () => {
db = await orbitdb1.feed(address) const db = await orbitdb1.feed(address)
await db.load() await db.load()
await db.add('hello1')
const prevHash = db.iterator().collect()[0].hash const prevHash = db.iterator().collect()[0].hash
const hash = await db.add('hello2') const hash = await db.add('hello2')
const items = db.iterator({ limit: -1 }).collect() const items = db.iterator({ limit: -1 }).collect()
@ -76,49 +80,53 @@ Object.keys(testAPIs).forEach(API => {
assert.notEqual(hash, null) assert.notEqual(hash, null)
assert.notEqual(hash, prevHash) assert.notEqual(hash, prevHash)
assert.equal(hash, last(items).hash) assert.equal(hash, last(items).hash)
await db.drop()
}) })
it('adds five items', async () => { it('adds five items', async () => {
db = await orbitdb1.feed('second') const db = await orbitdb1.feed('second')
await mapSeries([1, 2, 3, 4, 5], (i) => db.add('hello' + i)) await mapSeries([1, 2, 3, 4, 5], (i) => db.add('hello' + i))
const items = db.iterator({ limit: -1 }).collect() const items = db.iterator({ limit: -1 }).collect()
assert.equal(items.length, 5) assert.equal(items.length, 5)
assert.equal(items[0].payload.value, 'hello1') assert.equal(items[0].payload.value, 'hello1')
assert.equal(items[items.length - 1].payload.value, 'hello5') assert.equal(items[items.length - 1].payload.value, 'hello5')
await db.drop()
}) })
it('adds an item that is > 256 bytes', async () => { it('adds an item that is > 256 bytes', async () => {
db = await orbitdb1.feed('third') const db = await orbitdb1.feed('third')
let msg = Buffer.alloc(1024) let msg = Buffer.alloc(1024)
msg.fill('a') msg.fill('a')
const hash = await db.add(msg.toString()) const hash = await db.add(msg.toString())
assert.notEqual(hash, null) assert.notEqual(hash, null)
assert.equal(hash.startsWith('zd'), true) assert.equal(hash.startsWith('zd'), true)
assert.equal(hash.length, 49) assert.equal(hash.length, 49)
await db.drop()
}) })
it('deletes an item when only one item in the database', async () => { it('deletes an item when only one item in the database', async () => {
db = await orbitdb1.feed('fourth') const db = await orbitdb1.feed('fourth')
const hash = await db.add('hello3') const hash = await db.add('hello3')
const delopHash = await db.remove(hash) const delopHash = await db.remove(hash)
const items = db.iterator().collect() const items = db.iterator().collect()
assert.equal(delopHash.startsWith('zd'), true) assert.equal(delopHash.startsWith('zd'), true)
assert.equal(items.length, 0) assert.equal(items.length, 0)
await db.drop()
}) })
it('deletes an item when two items in the database', async () => { it('deletes an item when two items in the database', async () => {
db = await orbitdb1.feed('fifth') const db = await orbitdb1.feed('fifth')
await db.add('hello1') await db.add('hello1')
const hash = await db.add('hello2') const hash = await db.add('hello2')
await db.remove(hash) await db.remove(hash)
const items = db.iterator({ limit: -1 }).collect() const items = db.iterator({ limit: -1 }).collect()
assert.equal(items.length, 1) assert.equal(items.length, 1)
assert.equal(items[0].payload.value, 'hello1') assert.equal(items[0].payload.value, 'hello1')
await db.drop()
}) })
it('deletes an item between adds', async () => { it('deletes an item between adds', async () => {
db = await orbitdb1.feed('sixth') const db = await orbitdb1.feed('sixth')
const hash = await db.add('hello1') const hash = await db.add('hello1')
await db.add('hello2') await db.add('hello2')
@ -134,10 +142,13 @@ Object.keys(testAPIs).forEach(API => {
assert.equal(firstItem.payload.key, null) assert.equal(firstItem.payload.key, null)
assert.equal(firstItem.payload.value, 'hello2') assert.equal(firstItem.payload.value, 'hello2')
assert.equal(secondItem.payload.value, 'hello3') assert.equal(secondItem.payload.value, 'hello3')
await db.drop()
}) })
}) })
describe('Iterator', function() { describe('Iterator', function() {
let db
let hashes = [] let hashes = []
const itemCount = 5 const itemCount = 5

BIN
test/fixtures/js-ipfs.zip vendored Normal file

Binary file not shown.

View File

@ -20,7 +20,7 @@ Object.keys(testAPIs).forEach(API => {
describe(`orbit-db - Key-Value Database (${API})`, function() { describe(`orbit-db - Key-Value Database (${API})`, function() {
this.timeout(config.timeout) this.timeout(config.timeout)
let ipfsd, ipfs, orbitdb1, db let ipfsd, ipfs, orbitdb1
before(async () => { before(async () => {
config.daemon1.repo = ipfsPath config.daemon1.repo = ipfsPath
@ -38,47 +38,49 @@ Object.keys(testAPIs).forEach(API => {
}, 0) }, 0)
}) })
beforeEach(async () => {
db = await orbitdb1.kvstore('orbit-db-tests', { path: dbPath })
})
afterEach(async () => {
await db.drop()
})
it('creates and opens a database', async () => { it('creates and opens a database', async () => {
db = await orbitdb1.keyvalue('first kv database') const db = await orbitdb1.keyvalue('first kv database')
assert.notEqual(db, null) assert.notEqual(db, null)
assert.equal(db.type, 'keyvalue') assert.equal(db.type, 'keyvalue')
assert.equal(db.dbname, 'first kv database') assert.equal(db.dbname, 'first kv database')
await db.drop()
}) })
it('put', async () => { it('put', async () => {
const db = await orbitdb1.keyvalue('first kv database')
await db.put('key1', 'hello1') await db.put('key1', 'hello1')
const value = db.get('key1') const value = db.get('key1')
assert.equal(value, 'hello1') assert.equal(value, 'hello1')
await db.drop()
}) })
it('get', async () => { it('get', async () => {
const db = await orbitdb1.keyvalue('first kv database')
await db.put('key1', 'hello2') await db.put('key1', 'hello2')
const value = db.get('key1') const value = db.get('key1')
assert.equal(value, 'hello2') assert.equal(value, 'hello2')
await db.drop()
}) })
it('put updates a value', async () => { it('put updates a value', async () => {
const db = await orbitdb1.keyvalue('first kv database')
await db.put('key1', 'hello3') await db.put('key1', 'hello3')
await db.put('key1', 'hello4') await db.put('key1', 'hello4')
const value = db.get('key1') const value = db.get('key1')
assert.equal(value, 'hello4') assert.equal(value, 'hello4')
await db.drop()
}) })
it('set is an alias for put', async () => { it('set is an alias for put', async () => {
const db = await orbitdb1.keyvalue('first kv database')
await db.set('key1', 'hello5') await db.set('key1', 'hello5')
const value = db.get('key1') const value = db.get('key1')
assert.equal(value, 'hello5') assert.equal(value, 'hello5')
await db.drop()
}) })
it('put/get - multiple keys', async () => { it('put/get - multiple keys', async () => {
const db = await orbitdb1.keyvalue('first kv database')
await db.put('key1', 'hello1') await db.put('key1', 'hello1')
await db.put('key2', 'hello2') await db.put('key2', 'hello2')
await db.put('key3', 'hello3') await db.put('key3', 'hello3')
@ -88,43 +90,54 @@ Object.keys(testAPIs).forEach(API => {
assert.equal(v1, 'hello1') assert.equal(v1, 'hello1')
assert.equal(v2, 'hello2') assert.equal(v2, 'hello2')
assert.equal(v3, 'hello3') assert.equal(v3, 'hello3')
await db.drop()
}) })
it('deletes a key', async () => { it('deletes a key', async () => {
const db = await orbitdb1.keyvalue('first kv database')
await db.put('key1', 'hello!') await db.put('key1', 'hello!')
await db.del('key1') await db.del('key1')
const value = db.get('key1') const value = db.get('key1')
assert.equal(value, null) assert.equal(value, null)
await db.drop()
}) })
it('deletes a key after multiple updates', async () => { it('deletes a key after multiple updates', async () => {
const db = await orbitdb1.keyvalue('first kv database')
await db.put('key1', 'hello1') await db.put('key1', 'hello1')
await db.put('key1', 'hello2') await db.put('key1', 'hello2')
await db.put('key1', 'hello3') await db.put('key1', 'hello3')
await db.del('key1') await db.del('key1')
const value = db.get('key1') const value = db.get('key1')
assert.equal(value, null) assert.equal(value, null)
await db.drop()
}) })
it('get - integer value', async () => { it('get - integer value', async () => {
const db = await orbitdb1.keyvalue('first kv database')
const val = 123 const val = 123
await db.put('key1', val) await db.put('key1', val)
const v1 = db.get('key1') const v1 = db.get('key1')
assert.equal(v1, val) assert.equal(v1, val)
await db.drop()
}) })
it('get - object value', async () => { it('get - object value', async () => {
const db = await orbitdb1.keyvalue('first kv database')
const val = { one: 'first', two: 2 } const val = { one: 'first', two: 2 }
await db.put('key1', val) await db.put('key1', val)
const v1 = db.get('key1') const v1 = db.get('key1')
assert.deepEqual(v1, val) assert.deepEqual(v1, val)
await db.drop()
}) })
it('get - array value', async () => { it('get - array value', async () => {
const db = await orbitdb1.keyvalue('first kv database')
const val = [1, 2, 3, 4, 5] const val = [1, 2, 3, 4, 5]
await db.put('key1', val) await db.put('key1', val)
const v1 = db.get('key1') const v1 = db.get('key1')
assert.deepEqual(v1, val) assert.deepEqual(v1, val)
await db.drop()
}) })
}) })
}) })

View File

@ -25,7 +25,7 @@ Object.keys(testAPIs).forEach(API => {
this.timeout(config.timeout * 2) this.timeout(config.timeout * 2)
let ipfsd1, ipfsd2, ipfs1, ipfs2 let ipfsd1, ipfsd2, ipfs1, ipfs2
let orbitdb1, orbitdb2, db1, db2 let orbitdb1, orbitdb2
before(async () => { before(async () => {
config.daemon1.repo = ipfsPath1 config.daemon1.repo = ipfsPath1
@ -59,20 +59,7 @@ Object.keys(testAPIs).forEach(API => {
}) })
describe('two peers', function() { describe('two peers', function() {
// Opens two databases db1 and db2 and gives write-access to both of the peers let db1, db2
const openDatabases1 = async (options) => {
// Set write access for both clients
options.write = [
orbitdb1.identity.publicKey,
orbitdb2.identity.publicKey
],
options = Object.assign({}, options, { path: dbPath1 })
db1 = await orbitdb1.eventlog('replicate-and-load-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)
}
const openDatabases = async (options) => { const openDatabases = async (options) => {
// Set write access for both clients // Set write access for both clients
@ -88,7 +75,7 @@ Object.keys(testAPIs).forEach(API => {
db2 = await orbitdb2.eventlog(db1.address.toString(), options) db2 = await orbitdb2.eventlog(db1.address.toString(), options)
} }
beforeEach(async () => { before(async () => {
await openDatabases({ sync: true }) await openDatabases({ sync: true })
assert.equal(db1.address.toString(), db2.address.toString()) assert.equal(db1.address.toString(), db2.address.toString())
@ -99,7 +86,7 @@ Object.keys(testAPIs).forEach(API => {
console.log("Found peers") console.log("Found peers")
}) })
afterEach(async () => { after(async () => {
await db1.drop() await db1.drop()
await db2.drop() await db2.drop()
}) })
@ -126,8 +113,6 @@ Object.keys(testAPIs).forEach(API => {
assert.equal(items[0].payload.value, 'hello0') assert.equal(items[0].payload.value, 'hello0')
assert.equal(items[items.length - 1].payload.value, 'hello99') assert.equal(items[items.length - 1].payload.value, 'hello99')
db2 = null
try { try {
// Set write access for both clients // Set write access for both clients
@ -145,19 +130,22 @@ Object.keys(testAPIs).forEach(API => {
// Open the database again (this time from the disk) // Open the database again (this time from the disk)
options = Object.assign({}, options, { path: dbPath1, create: false }) options = Object.assign({}, options, { path: dbPath1, create: false })
db1 = await orbitdb1.eventlog(addr, options) const db3 = await orbitdb1.eventlog(addr, options)
// Set 'localOnly' flag on and it'll error if the database doesn't exist locally // Set 'localOnly' flag on and it'll error if the database doesn't exist locally
options = Object.assign({}, options, { path: dbPath2, localOnly: true }) options = Object.assign({}, options, { path: dbPath2, localOnly: true })
db2 = await orbitdb2.eventlog(addr, options) const db4 = await orbitdb2.eventlog(addr, options)
await db1.load() await db3.load()
await db2.load() await db4.load()
// Make sure we have all the entries in the databases // Make sure we have all the entries in the databases
const result1 = db1.iterator({ limit: -1 }).collect() const result1 = db3.iterator({ limit: -1 }).collect()
const result2 = db2.iterator({ limit: -1 }).collect() const result2 = db4.iterator({ limit: -1 }).collect()
assert.equal(result1.length, entryCount) assert.equal(result1.length, entryCount)
assert.equal(result2.length, entryCount) assert.equal(result2.length, entryCount)
await db3.drop()
await db4.drop()
} catch (e) { } catch (e) {
reject(e) reject(e)
} }

View File

@ -488,7 +488,7 @@ Object.keys(testAPIs).forEach(API => {
resolve() resolve()
} }
}, 100) }, 500)
} catch (e) { } catch (e) {
reject(e) reject(e)
} }

View File

@ -26,7 +26,7 @@ Object.keys(testAPIs).forEach(API => {
describe(`orbit-db - Set identities (${API})`, function() { describe(`orbit-db - Set identities (${API})`, function() {
this.timeout(config.timeout) this.timeout(config.timeout)
let ipfsd, ipfs, orbitdb, db, keystore let ipfsd, ipfs, orbitdb, keystore, options
let identity1, identity2 let identity1, identity2
let localDataPath let localDataPath
@ -56,7 +56,7 @@ Object.keys(testAPIs).forEach(API => {
}) })
beforeEach(async () => { beforeEach(async () => {
let options = {} options = {}
options.accessController = { options.accessController = {
write : [ write : [
orbitdb.identity.id, orbitdb.identity.id,
@ -64,16 +64,18 @@ Object.keys(testAPIs).forEach(API => {
] ]
} }
options = Object.assign({}, options, { create: true, type: 'eventlog', overwrite: true }) options = Object.assign({}, options, { create: true, type: 'eventlog', overwrite: true })
db = await orbitdb.open('abc', options)
}) })
it('sets identity', async () => { it('sets identity', async () => {
const db = await orbitdb.open('abc', options)
assert.equal(db.identity, orbitdb.identity) assert.equal(db.identity, orbitdb.identity)
db.setIdentity(identity1) db.setIdentity(identity1)
assert.equal(db.identity, identity1) assert.equal(db.identity, identity1)
await db.close()
}) })
it('writes with new identity with access', async () => { it('writes with new identity with access', async () => {
const db = await orbitdb.open('abc', options)
assert.equal(db.identity, orbitdb.identity) assert.equal(db.identity, orbitdb.identity)
db.setIdentity(identity1) db.setIdentity(identity1)
assert.equal(db.identity, identity1) assert.equal(db.identity, identity1)
@ -84,9 +86,11 @@ Object.keys(testAPIs).forEach(API => {
err = e.message err = e.message
} }
assert.equal(err, null) assert.equal(err, null)
await db.drop()
}) })
it('cannot write with new identity without access', async () => { it('cannot write with new identity without access', async () => {
const db = await orbitdb.open('abc', options)
assert.equal(db.identity, orbitdb.identity) assert.equal(db.identity, orbitdb.identity)
db.setIdentity(identity2) db.setIdentity(identity2)
assert.equal(db.identity, identity2) assert.equal(db.identity, identity2)
@ -97,6 +101,7 @@ Object.keys(testAPIs).forEach(API => {
err = e.message err = e.message
} }
assert.equal(err, `Could not append entry, key "${identity2.id}" is not allowed to write to the log`) assert.equal(err, `Could not append entry, key "${identity2.id}" is not allowed to write to the log`)
await db.drop()
}) })
}) })
}) })

View File

@ -32,10 +32,11 @@ const dbPath = path.join('./orbitdb', 'tests', 'v0')
const dbFixturesDir = path.join('./test', 'fixtures', 'v0', 'QmWDUfC4zcWJGgc9UHn1X3qQ5KZqBv4KCiCtjnpMmBT8JC', 'v0-db') const dbFixturesDir = path.join('./test', 'fixtures', 'v0', 'QmWDUfC4zcWJGgc9UHn1X3qQ5KZqBv4KCiCtjnpMmBT8JC', 'v0-db')
const keyFixtures = path.join('./test', 'fixtures', 'keys','QmRfPsKJs9YqTot5krRibra4gPwoK4kghhU8iKWxBjGDDX') const keyFixtures = path.join('./test', 'fixtures', 'keys','QmRfPsKJs9YqTot5krRibra4gPwoK4kghhU8iKWxBjGDDX')
const ipfsFixtures = path.join('./test', 'fixtures', 'ipfs.zip')
const ipfsFixturesDir = path.join('./test', 'fixtures', 'ipfs') const ipfsFixturesDir = path.join('./test', 'fixtures', 'ipfs')
Object.keys(testAPIs).forEach(API => { Object.keys(testAPIs).forEach(API => {
let ipfsFixtures = path.join('./test', 'fixtures', `${API}.zip`)
describe(`orbit-db - Backward-Compatibility - Open & Load (${API})`, function () { describe(`orbit-db - Backward-Compatibility - Open & Load (${API})`, function () {
this.retries(1) // windows... this.retries(1) // windows...
this.timeout(config.timeout) this.timeout(config.timeout)