orbitdb/test/set-identity.test.js
Mark Henderson 47a18b05f5 dev:updating keystore in package.json to git branch
pointing to fix/store-performance branch

fix:typo

fix: indentation

test: Changing test to reflect new orbit-store default

Update package.json

test: updating tests

update localstorage-level-migration dep

experiment:Moving keystore up ALL way

orbitdb storage adapter mark 1

fix: more passing tests

more fixes

chore:package-lock.json

reverting mkdir.c for now

package-lock.json for node 10.13

fix: circleci

fix: webpack fs updates

disabling loadCache

Moving storage adapter to its own thing

tests: fixing up

chore: long needed fixing

More linting

tests: fix up look sharp

test: v0 failure only

Reversting lint fixes

fix v0-load test

set cache heads

fix: passing in storage no longer needed

fix: removing artifact from previous merge

fix: honor default keystore and pesky call-by-reference bug

fix: removing directory arg from _addManifestToCache

chore: package-lock

fix: pending drop test

removing directory option for individual dbs

docs: removing directory options

fix: removing line instead of commenting

fix: moving storage setup to createInstance

feat: Upgrading ipfs to 0.36

chore: package-log

fix: restoring onlyHash

workaround: removing memstore from replication tests

fix: this.keystore.close and this.cache.close

chore: removing eslint annotation

chore: package-lock.json

fix: passing preCreate in as option

chore: package files

Fixing package.json

fixing replicate tests

Fixing some tests

Updating orbit-db-store dependency

CircleCI updates - To be obviated via other PR

Restoring ability to pass a custom directory to orbitdb.create

More test fixes

set identity tests fixed

Fixing replication tests

Temporarily disabling concurrency tests

Closing keystore in identities test

Restoring test:all

package.json

More replicate test fixes

successful make rebuild

Linting fixes
2019-08-30 14:18:28 -04:00

103 lines
2.9 KiB
JavaScript

'use strict'
const fs = require('fs')
const assert = require('assert')
const mapSeries = require('p-map-series')
const rmrf = require('rimraf')
const OrbitDB = require('../src/OrbitDB')
const Identities = require('orbit-db-identity-provider')
const Keystore = require('orbit-db-keystore')
const leveldown = require('leveldown')
const storage = require('orbit-db-storage-adapter')(leveldown)
// Include test utilities
const {
config,
startIpfs,
stopIpfs,
testAPIs,
} = require('./utils')
const keysPath = './orbitdb/identity/identitykeys'
const dbPath = './orbitdb/tests/change-identity'
const ipfsPath = './orbitdb/tests/change-identity/ipfs'
Object.keys(testAPIs).forEach(API => {
describe(`orbit-db - Set identities (${API})`, function() {
this.timeout(config.timeout)
let ipfsd, ipfs, orbitdb, db, keystore
let identity1, identity2
let localDataPath
before(async () => {
config.daemon1.repo = ipfsPath
rmrf.sync(config.daemon1.repo)
rmrf.sync(dbPath)
ipfsd = await startIpfs(API, config.daemon1)
ipfs = ipfsd.api
if(fs && fs.mkdirSync) fs.mkdirSync(keysPath, { recursive: true })
const identityStore = await storage.createStore(keysPath)
keystore = new Keystore(identityStore)
identity1 = await Identities.createIdentity({ id: 'test-id1', keystore })
identity2 = await Identities.createIdentity({ id: 'test-id2', keystore })
orbitdb = await OrbitDB.createInstance(ipfs, { directory: dbPath })
})
after(async () => {
await keystore.close()
if(orbitdb)
await orbitdb.stop()
if (ipfsd)
await stopIpfs(ipfsd)
})
beforeEach(async () => {
let options = {}
options.accessController = {
write : [
orbitdb.identity.id,
identity1.id
]
}
options = Object.assign({}, options, { create: true, type: 'eventlog', overwrite: true })
db = await orbitdb.open('abc', options)
})
it('sets identity', async () => {
assert.equal(db.identity, orbitdb.identity)
db.setIdentity(identity1)
assert.equal(db.identity, identity1)
})
it('writes with new identity with access', async () => {
assert.equal(db.identity, orbitdb.identity)
db.setIdentity(identity1)
assert.equal(db.identity, identity1)
let err
try {
await db.add({ hello: '1'})
} catch (e) {
err = e.message
}
assert.equal(err, null)
})
it('cannot write with new identity without access', async () => {
assert.equal(db.identity, orbitdb.identity)
db.setIdentity(identity2)
assert.equal(db.identity, identity2)
let err
try {
await db.add({ hello: '1'})
} catch (e) {
err = e.message
}
assert.equal(err, `Could not append entry, key "${identity2.id}" is not allowed to write to the log`)
})
})
})