mirror of
https://github.com/orbitdb/orbitdb.git
synced 2025-06-04 13:16:38 +00:00
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:
parent
32cc9a9b00
commit
39a00060d6
@ -24,7 +24,7 @@ module.exports = {
|
||||
plugins: [
|
||||
new webpack.DefinePlugin({
|
||||
'process.env': {
|
||||
'NODE_ENV': JSON.stringify(process.env.NODE_ENV)
|
||||
NODE_ENV: JSON.stringify(process.env.NODE_ENV)
|
||||
}
|
||||
})
|
||||
],
|
||||
|
@ -18,7 +18,7 @@ module.exports = {
|
||||
plugins: [
|
||||
new webpack.DefinePlugin({
|
||||
'process.env': {
|
||||
'NODE_ENV': JSON.stringify(process.env.NODE_ENV)
|
||||
NODE_ENV: JSON.stringify(process.env.NODE_ENV)
|
||||
}
|
||||
})
|
||||
],
|
||||
|
12977
package-lock.json
generated
12977
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
48
package.json
48
package.json
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "orbit-db",
|
||||
"version": "0.24.2",
|
||||
"version": "0.24.3",
|
||||
"description": "Distributed p2p database on IPFS",
|
||||
"author": "Haad",
|
||||
"license": "MIT",
|
||||
@ -13,12 +13,12 @@
|
||||
},
|
||||
"main": "src/OrbitDB.js",
|
||||
"dependencies": {
|
||||
"cids": "^0.7.1",
|
||||
"cids": "^1.0.0",
|
||||
"ipfs-pubsub-1on1": "~0.0.6",
|
||||
"is-node": "^1.0.2",
|
||||
"localstorage-down": "^0.6.7",
|
||||
"logplease": "^1.2.14",
|
||||
"multihashes": "^0.4.12",
|
||||
"multihashes": "~3.0.1",
|
||||
"orbit-db-access-controllers": "^0.2.2",
|
||||
"orbit-db-cache": "~0.3.0",
|
||||
"orbit-db-counterstore": "~1.9.0",
|
||||
@ -31,36 +31,36 @@
|
||||
"orbit-db-kvstore": "~1.9.0",
|
||||
"orbit-db-pubsub": "~0.5.5",
|
||||
"orbit-db-storage-adapter": "~0.5.3",
|
||||
"orbit-db-store": "~3.3.0"
|
||||
"orbit-db-store": "~3.3.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"adm-zip": "^0.4.13",
|
||||
"adm-zip": "^0.4.16",
|
||||
"babel-cli": "^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-polyfill": "^6.26.0",
|
||||
"babel-preset-env": "^1.7.0",
|
||||
"cpy-cli": "^2.0.0",
|
||||
"cross-env": "^6.0.3",
|
||||
"datastore-level": "~0.14.0",
|
||||
"fs-extra": "^7.0.1",
|
||||
"cpy-cli": "^3.1.1",
|
||||
"cross-env": "^7.0.2",
|
||||
"datastore-level": "~2.0.0",
|
||||
"fs-extra": "^9.0.1",
|
||||
"localstorage-level-migration": "~0.1.0",
|
||||
"markdown-toc": "^1.2.0",
|
||||
"mkdirp": "^0.5.1",
|
||||
"mocha": "^5.2.0",
|
||||
"orbit-db-test-utils": "^0.9.4",
|
||||
"p-each-series": "^1.0.0",
|
||||
"p-map": "^1.2.0",
|
||||
"p-map-series": "^1.0.0",
|
||||
"p-whilst": "^1.0.0",
|
||||
"pify": "^4.0.1",
|
||||
"puppeteer": "^1.18.1",
|
||||
"remark-cli": "^5.0.0",
|
||||
"remark-validate-links": "^7.0.0",
|
||||
"rimraf": "^2.6.2",
|
||||
"standard": "^12.0.1",
|
||||
"validate-maintainers": "^1.1.0",
|
||||
"mkdirp": "^1.0.4",
|
||||
"mocha": "^8.1.1",
|
||||
"orbit-db-test-utils": "^0.10.2",
|
||||
"p-each-series": "^2.1.0",
|
||||
"p-map": "^4.0.0",
|
||||
"p-map-series": "^2.1.0",
|
||||
"p-whilst": "^2.1.0",
|
||||
"pify": "^5.0.0",
|
||||
"puppeteer": "^5.2.1",
|
||||
"remark-cli": "^8.0.1",
|
||||
"remark-validate-links": "^10.0.2",
|
||||
"rimraf": "^3.0.2",
|
||||
"standard": "^14.3.4",
|
||||
"validate-maintainers": "^1.2.2",
|
||||
"webpack": "^4.41.2",
|
||||
"webpack-cli": "^3.3.10"
|
||||
},
|
||||
|
@ -82,7 +82,7 @@ class OrbitDB {
|
||||
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')
|
||||
}
|
||||
|
||||
|
@ -11,6 +11,13 @@ const {
|
||||
const clicksPerTab = 20
|
||||
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() {
|
||||
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')}`)
|
||||
page.on('dialog', dialog => dialog.dismiss())
|
||||
page.on('pageerror', err => console.error(err))
|
||||
await wait(1000)
|
||||
return page
|
||||
}
|
||||
|
||||
|
@ -24,15 +24,16 @@ const {
|
||||
const dbPath = path.join('./orbitdb', 'tests', 'create-open')
|
||||
const ipfsPath = path.join('./orbitdb', 'tests', 'create-open', 'ipfs')
|
||||
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')
|
||||
|
||||
Object.keys(testAPIs).forEach(API => {
|
||||
describe(`orbit-db - Create & Open (${API})`, function () {
|
||||
let ipfsFixtures = path.join('./test', 'fixtures', `${API}.zip`)
|
||||
|
||||
this.retries(1) // windows...
|
||||
this.timeout(config.timeout)
|
||||
|
||||
let ipfsd, ipfs, orbitdb, db, address
|
||||
let ipfsd, ipfs, orbitdb, address
|
||||
let localDataPath
|
||||
|
||||
const filterFunc = (src, dest) => {
|
||||
@ -68,7 +69,7 @@ Object.keys(testAPIs).forEach(API => {
|
||||
it('throws an error if given an invalid database type', async () => {
|
||||
let err
|
||||
try {
|
||||
db = await orbitdb.create('first', 'invalid-type')
|
||||
const db = await orbitdb.create('first', 'invalid-type')
|
||||
} catch (e) {
|
||||
err = e.toString()
|
||||
}
|
||||
@ -78,7 +79,7 @@ Object.keys(testAPIs).forEach(API => {
|
||||
it('throws an error if given an address instead of name', async () => {
|
||||
let err
|
||||
try {
|
||||
db = await orbitdb.create('/orbitdb/Qmc9PMho3LwTXSaUXJ8WjeBZyXesAwUofdkGeadFXsqMzW/first', 'feed')
|
||||
const db = await orbitdb.create('/orbitdb/Qmc9PMho3LwTXSaUXJ8WjeBZyXesAwUofdkGeadFXsqMzW/first', 'feed')
|
||||
} catch (e) {
|
||||
err = e.toString()
|
||||
}
|
||||
@ -86,14 +87,15 @@ Object.keys(testAPIs).forEach(API => {
|
||||
})
|
||||
|
||||
it('throws an error if database already exists', async () => {
|
||||
let err
|
||||
let err, db
|
||||
try {
|
||||
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) {
|
||||
err = e.toString()
|
||||
}
|
||||
assert.equal(err, `Error: Database '${db.address}' already exists!`)
|
||||
await db.close()
|
||||
})
|
||||
|
||||
|
||||
@ -110,6 +112,8 @@ Object.keys(testAPIs).forEach(API => {
|
||||
})
|
||||
|
||||
describe('Success', function () {
|
||||
let db
|
||||
|
||||
before(async () => {
|
||||
db = await orbitdb.create('second', 'feed', { replicate: false })
|
||||
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 () => {
|
||||
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)
|
||||
await db2.close()
|
||||
})
|
||||
|
||||
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 () => {
|
||||
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('zd'), 9)
|
||||
assert.equal(address.toString(), db.address.toString())
|
||||
await db.close()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
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 () => {
|
||||
let err
|
||||
try {
|
||||
@ -317,36 +319,45 @@ Object.keys(testAPIs).forEach(API => {
|
||||
})
|
||||
|
||||
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('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 })
|
||||
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('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 () => {
|
||||
db = await orbitdb.open(db.address)
|
||||
assert.equal(db.address.toString().indexOf('/orbitdb'), 0)
|
||||
assert.equal(db.address.toString().indexOf('zd'), 9)
|
||||
assert.equal(db.address.toString().indexOf('abc'), 59)
|
||||
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 () => {
|
||||
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[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('abc', { 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)
|
||||
@ -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')
|
||||
await db.drop()
|
||||
return orbitdb.open(address, { localOnly: true })
|
||||
.then(() => new Error('Shouldn\'t open the database'))
|
||||
.catch(e => {
|
||||
@ -365,11 +378,12 @@ Object.keys(testAPIs).forEach(API => {
|
||||
})
|
||||
|
||||
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('hello2')
|
||||
await db.close()
|
||||
|
||||
db = await orbitdb.open(db.address)
|
||||
const db2 = await orbitdb.open(db.address)
|
||||
|
||||
await db.load()
|
||||
const res = db.iterator({ limit: -1 }).collect()
|
||||
@ -377,6 +391,8 @@ Object.keys(testAPIs).forEach(API => {
|
||||
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()
|
||||
})
|
||||
})
|
||||
|
||||
@ -387,14 +403,14 @@ Object.keys(testAPIs).forEach(API => {
|
||||
})
|
||||
it('closes a custom store', async () => {
|
||||
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()
|
||||
assert.strictEqual(db._cache._store._db.status, 'closed')
|
||||
})
|
||||
|
||||
it("close load close sets status to 'closed'", async () => {
|
||||
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.load()
|
||||
await db.close()
|
||||
|
@ -23,7 +23,7 @@ Object.keys(testAPIs).forEach(API => {
|
||||
describe(`orbit-db - Log Database (${API})`, function() {
|
||||
this.timeout(config.timeout)
|
||||
|
||||
let ipfsd, ipfs, orbitdb1, db
|
||||
let ipfsd, ipfs, orbitdb1
|
||||
|
||||
before(async () => {
|
||||
config.daemon1.repo = ipfsPath
|
||||
@ -44,30 +44,34 @@ Object.keys(testAPIs).forEach(API => {
|
||||
|
||||
describe('Eventlog', function () {
|
||||
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.equal(db.type, 'eventlog')
|
||||
assert.equal(db.dbname, 'log database')
|
||||
await db.drop()
|
||||
})
|
||||
|
||||
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()
|
||||
assert.equal(items.length, 0)
|
||||
await db.drop()
|
||||
})
|
||||
|
||||
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 items = db.iterator({ limit: -1 }).collect()
|
||||
assert.notEqual(hash, null)
|
||||
assert.equal(hash, last(items).hash)
|
||||
assert.equal(items.length, 1)
|
||||
await db.drop()
|
||||
})
|
||||
|
||||
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.add('hello1')
|
||||
const prevHash = db.iterator().collect()[0].hash
|
||||
const hash = await db.add('hello2')
|
||||
const items = db.iterator({ limit: -1 }).collect()
|
||||
@ -75,31 +79,35 @@ Object.keys(testAPIs).forEach(API => {
|
||||
assert.notEqual(hash, null)
|
||||
assert.notEqual(hash, prevHash)
|
||||
assert.equal(hash, last(items).hash)
|
||||
await db.drop()
|
||||
})
|
||||
|
||||
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))
|
||||
const items = db.iterator({ limit: -1 }).collect()
|
||||
assert.equal(items.length, 5)
|
||||
assert.equal(items[0].payload.value, 'hello1')
|
||||
assert.equal(last(items.map((f) => f.payload.value)), 'hello5')
|
||||
await db.drop()
|
||||
})
|
||||
|
||||
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)
|
||||
msg.fill('a')
|
||||
const hash = await db.add(msg.toString())
|
||||
assert.notEqual(hash, null)
|
||||
assert.equal(hash.startsWith('zd'), true)
|
||||
assert.equal(hash.length, 49)
|
||||
await db.drop()
|
||||
})
|
||||
})
|
||||
|
||||
describe('Iterator', function() {
|
||||
let hashes = []
|
||||
const itemCount = 5
|
||||
let db
|
||||
|
||||
before(async () => {
|
||||
hashes = []
|
||||
|
@ -23,7 +23,7 @@ Object.keys(testAPIs).forEach(API => {
|
||||
describe(`orbit-db - Feed Database (${API})`, function() {
|
||||
this.timeout(config.timeout)
|
||||
|
||||
let ipfsd, ipfs, orbitdb1, db, address
|
||||
let ipfsd, ipfs, orbitdb1, address
|
||||
|
||||
before(async () => {
|
||||
config.daemon1.repo = ipfsPath
|
||||
@ -44,31 +44,35 @@ Object.keys(testAPIs).forEach(API => {
|
||||
|
||||
describe('Feed', function() {
|
||||
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.equal(db.type, 'feed')
|
||||
assert.equal(db.dbname, 'feed database')
|
||||
await db.drop()
|
||||
})
|
||||
|
||||
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()
|
||||
assert.equal(items.length, 0)
|
||||
await db.drop()
|
||||
})
|
||||
|
||||
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()
|
||||
const hash = await db.add('hello1')
|
||||
const items = db.iterator({ limit: -1 }).collect()
|
||||
assert.notEqual(hash, null)
|
||||
assert.equal(hash, last(items).hash)
|
||||
assert.equal(items.length, 1)
|
||||
await db.drop()
|
||||
})
|
||||
|
||||
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.add('hello1')
|
||||
const prevHash = db.iterator().collect()[0].hash
|
||||
const hash = await db.add('hello2')
|
||||
const items = db.iterator({ limit: -1 }).collect()
|
||||
@ -76,49 +80,53 @@ Object.keys(testAPIs).forEach(API => {
|
||||
assert.notEqual(hash, null)
|
||||
assert.notEqual(hash, prevHash)
|
||||
assert.equal(hash, last(items).hash)
|
||||
await db.drop()
|
||||
})
|
||||
|
||||
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))
|
||||
const items = db.iterator({ limit: -1 }).collect()
|
||||
assert.equal(items.length, 5)
|
||||
assert.equal(items[0].payload.value, 'hello1')
|
||||
assert.equal(items[items.length - 1].payload.value, 'hello5')
|
||||
await db.drop()
|
||||
})
|
||||
|
||||
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)
|
||||
msg.fill('a')
|
||||
const hash = await db.add(msg.toString())
|
||||
assert.notEqual(hash, null)
|
||||
assert.equal(hash.startsWith('zd'), true)
|
||||
assert.equal(hash.length, 49)
|
||||
await db.drop()
|
||||
})
|
||||
|
||||
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 delopHash = await db.remove(hash)
|
||||
const items = db.iterator().collect()
|
||||
assert.equal(delopHash.startsWith('zd'), true)
|
||||
assert.equal(items.length, 0)
|
||||
await db.drop()
|
||||
})
|
||||
|
||||
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')
|
||||
const hash = await db.add('hello2')
|
||||
await db.remove(hash)
|
||||
const items = db.iterator({ limit: -1 }).collect()
|
||||
assert.equal(items.length, 1)
|
||||
assert.equal(items[0].payload.value, 'hello1')
|
||||
await db.drop()
|
||||
})
|
||||
|
||||
it('deletes an item between adds', async () => {
|
||||
db = await orbitdb1.feed('sixth')
|
||||
const db = await orbitdb1.feed('sixth')
|
||||
|
||||
const hash = await db.add('hello1')
|
||||
await db.add('hello2')
|
||||
@ -134,10 +142,13 @@ Object.keys(testAPIs).forEach(API => {
|
||||
assert.equal(firstItem.payload.key, null)
|
||||
assert.equal(firstItem.payload.value, 'hello2')
|
||||
assert.equal(secondItem.payload.value, 'hello3')
|
||||
await db.drop()
|
||||
})
|
||||
})
|
||||
|
||||
describe('Iterator', function() {
|
||||
let db
|
||||
|
||||
let hashes = []
|
||||
const itemCount = 5
|
||||
|
||||
|
BIN
test/fixtures/ipfs.zip → test/fixtures/go-ipfs.zip
vendored
BIN
test/fixtures/ipfs.zip → test/fixtures/go-ipfs.zip
vendored
Binary file not shown.
BIN
test/fixtures/js-ipfs.zip
vendored
Normal file
BIN
test/fixtures/js-ipfs.zip
vendored
Normal file
Binary file not shown.
@ -20,7 +20,7 @@ Object.keys(testAPIs).forEach(API => {
|
||||
describe(`orbit-db - Key-Value Database (${API})`, function() {
|
||||
this.timeout(config.timeout)
|
||||
|
||||
let ipfsd, ipfs, orbitdb1, db
|
||||
let ipfsd, ipfs, orbitdb1
|
||||
|
||||
before(async () => {
|
||||
config.daemon1.repo = ipfsPath
|
||||
@ -38,47 +38,49 @@ Object.keys(testAPIs).forEach(API => {
|
||||
}, 0)
|
||||
})
|
||||
|
||||
beforeEach(async () => {
|
||||
db = await orbitdb1.kvstore('orbit-db-tests', { path: dbPath })
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
await db.drop()
|
||||
})
|
||||
|
||||
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.equal(db.type, 'keyvalue')
|
||||
assert.equal(db.dbname, 'first kv database')
|
||||
await db.drop()
|
||||
})
|
||||
|
||||
it('put', async () => {
|
||||
const db = await orbitdb1.keyvalue('first kv database')
|
||||
await db.put('key1', 'hello1')
|
||||
const value = db.get('key1')
|
||||
assert.equal(value, 'hello1')
|
||||
await db.drop()
|
||||
})
|
||||
|
||||
it('get', async () => {
|
||||
const db = await orbitdb1.keyvalue('first kv database')
|
||||
await db.put('key1', 'hello2')
|
||||
const value = db.get('key1')
|
||||
assert.equal(value, 'hello2')
|
||||
await db.drop()
|
||||
})
|
||||
|
||||
it('put updates a value', async () => {
|
||||
const db = await orbitdb1.keyvalue('first kv database')
|
||||
await db.put('key1', 'hello3')
|
||||
await db.put('key1', 'hello4')
|
||||
const value = db.get('key1')
|
||||
assert.equal(value, 'hello4')
|
||||
await db.drop()
|
||||
})
|
||||
|
||||
it('set is an alias for put', async () => {
|
||||
const db = await orbitdb1.keyvalue('first kv database')
|
||||
await db.set('key1', 'hello5')
|
||||
const value = db.get('key1')
|
||||
assert.equal(value, 'hello5')
|
||||
await db.drop()
|
||||
})
|
||||
|
||||
it('put/get - multiple keys', async () => {
|
||||
const db = await orbitdb1.keyvalue('first kv database')
|
||||
await db.put('key1', 'hello1')
|
||||
await db.put('key2', 'hello2')
|
||||
await db.put('key3', 'hello3')
|
||||
@ -88,43 +90,54 @@ Object.keys(testAPIs).forEach(API => {
|
||||
assert.equal(v1, 'hello1')
|
||||
assert.equal(v2, 'hello2')
|
||||
assert.equal(v3, 'hello3')
|
||||
await db.drop()
|
||||
})
|
||||
|
||||
it('deletes a key', async () => {
|
||||
const db = await orbitdb1.keyvalue('first kv database')
|
||||
await db.put('key1', 'hello!')
|
||||
await db.del('key1')
|
||||
const value = db.get('key1')
|
||||
assert.equal(value, null)
|
||||
await db.drop()
|
||||
})
|
||||
|
||||
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', 'hello2')
|
||||
await db.put('key1', 'hello3')
|
||||
await db.del('key1')
|
||||
const value = db.get('key1')
|
||||
assert.equal(value, null)
|
||||
await db.drop()
|
||||
})
|
||||
|
||||
it('get - integer value', async () => {
|
||||
const db = await orbitdb1.keyvalue('first kv database')
|
||||
const val = 123
|
||||
await db.put('key1', val)
|
||||
const v1 = db.get('key1')
|
||||
assert.equal(v1, val)
|
||||
await db.drop()
|
||||
})
|
||||
|
||||
it('get - object value', async () => {
|
||||
const db = await orbitdb1.keyvalue('first kv database')
|
||||
const val = { one: 'first', two: 2 }
|
||||
await db.put('key1', val)
|
||||
const v1 = db.get('key1')
|
||||
assert.deepEqual(v1, val)
|
||||
await db.drop()
|
||||
})
|
||||
|
||||
it('get - array value', async () => {
|
||||
const db = await orbitdb1.keyvalue('first kv database')
|
||||
const val = [1, 2, 3, 4, 5]
|
||||
await db.put('key1', val)
|
||||
const v1 = db.get('key1')
|
||||
assert.deepEqual(v1, val)
|
||||
await db.drop()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
@ -25,7 +25,7 @@ Object.keys(testAPIs).forEach(API => {
|
||||
this.timeout(config.timeout * 2)
|
||||
|
||||
let ipfsd1, ipfsd2, ipfs1, ipfs2
|
||||
let orbitdb1, orbitdb2, db1, db2
|
||||
let orbitdb1, orbitdb2
|
||||
|
||||
before(async () => {
|
||||
config.daemon1.repo = ipfsPath1
|
||||
@ -59,20 +59,7 @@ Object.keys(testAPIs).forEach(API => {
|
||||
})
|
||||
|
||||
describe('two peers', function() {
|
||||
// Opens two databases db1 and db2 and gives write-access to both of the peers
|
||||
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)
|
||||
}
|
||||
let db1, db2
|
||||
|
||||
const openDatabases = async (options) => {
|
||||
// Set write access for both clients
|
||||
@ -88,7 +75,7 @@ Object.keys(testAPIs).forEach(API => {
|
||||
db2 = await orbitdb2.eventlog(db1.address.toString(), options)
|
||||
}
|
||||
|
||||
beforeEach(async () => {
|
||||
before(async () => {
|
||||
await openDatabases({ sync: true })
|
||||
|
||||
assert.equal(db1.address.toString(), db2.address.toString())
|
||||
@ -99,7 +86,7 @@ Object.keys(testAPIs).forEach(API => {
|
||||
console.log("Found peers")
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
after(async () => {
|
||||
await db1.drop()
|
||||
await db2.drop()
|
||||
})
|
||||
@ -126,8 +113,6 @@ Object.keys(testAPIs).forEach(API => {
|
||||
assert.equal(items[0].payload.value, 'hello0')
|
||||
assert.equal(items[items.length - 1].payload.value, 'hello99')
|
||||
|
||||
db2 = null
|
||||
|
||||
try {
|
||||
|
||||
// Set write access for both clients
|
||||
@ -145,19 +130,22 @@ Object.keys(testAPIs).forEach(API => {
|
||||
|
||||
// Open the database again (this time from the disk)
|
||||
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
|
||||
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 db2.load()
|
||||
await db3.load()
|
||||
await db4.load()
|
||||
|
||||
// Make sure we have all the entries in the databases
|
||||
const result1 = db1.iterator({ limit: -1 }).collect()
|
||||
const result2 = db2.iterator({ limit: -1 }).collect()
|
||||
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)
|
||||
}
|
||||
|
@ -488,7 +488,7 @@ Object.keys(testAPIs).forEach(API => {
|
||||
|
||||
resolve()
|
||||
}
|
||||
}, 100)
|
||||
}, 500)
|
||||
} catch (e) {
|
||||
reject(e)
|
||||
}
|
||||
|
@ -26,7 +26,7 @@ Object.keys(testAPIs).forEach(API => {
|
||||
describe(`orbit-db - Set identities (${API})`, function() {
|
||||
this.timeout(config.timeout)
|
||||
|
||||
let ipfsd, ipfs, orbitdb, db, keystore
|
||||
let ipfsd, ipfs, orbitdb, keystore, options
|
||||
let identity1, identity2
|
||||
let localDataPath
|
||||
|
||||
@ -56,7 +56,7 @@ Object.keys(testAPIs).forEach(API => {
|
||||
})
|
||||
|
||||
beforeEach(async () => {
|
||||
let options = {}
|
||||
options = {}
|
||||
options.accessController = {
|
||||
write : [
|
||||
orbitdb.identity.id,
|
||||
@ -64,16 +64,18 @@ Object.keys(testAPIs).forEach(API => {
|
||||
]
|
||||
}
|
||||
options = Object.assign({}, options, { create: true, type: 'eventlog', overwrite: true })
|
||||
db = await orbitdb.open('abc', options)
|
||||
})
|
||||
|
||||
it('sets identity', async () => {
|
||||
const db = await orbitdb.open('abc', options)
|
||||
assert.equal(db.identity, orbitdb.identity)
|
||||
db.setIdentity(identity1)
|
||||
assert.equal(db.identity, identity1)
|
||||
await db.close()
|
||||
})
|
||||
|
||||
it('writes with new identity with access', async () => {
|
||||
const db = await orbitdb.open('abc', options)
|
||||
assert.equal(db.identity, orbitdb.identity)
|
||||
db.setIdentity(identity1)
|
||||
assert.equal(db.identity, identity1)
|
||||
@ -84,9 +86,11 @@ Object.keys(testAPIs).forEach(API => {
|
||||
err = e.message
|
||||
}
|
||||
assert.equal(err, null)
|
||||
await db.drop()
|
||||
})
|
||||
|
||||
it('cannot write with new identity without access', async () => {
|
||||
const db = await orbitdb.open('abc', options)
|
||||
assert.equal(db.identity, orbitdb.identity)
|
||||
db.setIdentity(identity2)
|
||||
assert.equal(db.identity, identity2)
|
||||
@ -97,6 +101,7 @@ Object.keys(testAPIs).forEach(API => {
|
||||
err = e.message
|
||||
}
|
||||
assert.equal(err, `Could not append entry, key "${identity2.id}" is not allowed to write to the log`)
|
||||
await db.drop()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
@ -32,10 +32,11 @@ const dbPath = path.join('./orbitdb', 'tests', 'v0')
|
||||
const dbFixturesDir = path.join('./test', 'fixtures', 'v0', 'QmWDUfC4zcWJGgc9UHn1X3qQ5KZqBv4KCiCtjnpMmBT8JC', 'v0-db')
|
||||
const keyFixtures = path.join('./test', 'fixtures', 'keys','QmRfPsKJs9YqTot5krRibra4gPwoK4kghhU8iKWxBjGDDX')
|
||||
|
||||
const ipfsFixtures = path.join('./test', 'fixtures', 'ipfs.zip')
|
||||
const ipfsFixturesDir = path.join('./test', 'fixtures', 'ipfs')
|
||||
|
||||
Object.keys(testAPIs).forEach(API => {
|
||||
let ipfsFixtures = path.join('./test', 'fixtures', `${API}.zip`)
|
||||
|
||||
describe(`orbit-db - Backward-Compatibility - Open & Load (${API})`, function () {
|
||||
this.retries(1) // windows...
|
||||
this.timeout(config.timeout)
|
||||
|
Loading…
x
Reference in New Issue
Block a user