mirror of
https://github.com/orbitdb/orbitdb.git
synced 2025-06-24 23:12:29 +00:00
Merge pull request #18 from orbitdb/dev/fix-oplog-tests
Clean up oplog tests
This commit is contained in:
commit
a4fb12c65b
@ -458,4 +458,4 @@ const Log = async (identity, { logId, logHeads, access, entryStorage, headsStora
|
||||
}
|
||||
}
|
||||
|
||||
export { Log as default, DefaultAccessController }
|
||||
export { Log as default, DefaultAccessController, Clock }
|
||||
|
@ -11,7 +11,6 @@ Object.keys(testAPIs).forEach((IPFS) => {
|
||||
describe('DocumentStore Database (' + IPFS + ')', function () {
|
||||
let ipfsd
|
||||
let ipfs
|
||||
let keystore, signingKeyStore
|
||||
let accessController
|
||||
let identities1
|
||||
let testIdentity1
|
||||
|
@ -13,7 +13,6 @@ Object.keys(testAPIs).forEach((IPFS) => {
|
||||
describe('EventStore Database (' + IPFS + ')', function () {
|
||||
let ipfsd
|
||||
let ipfs
|
||||
let keystore, signingKeyStore
|
||||
let accessController
|
||||
let identities1
|
||||
let testIdentity1
|
||||
|
@ -1,8 +1,7 @@
|
||||
import { deepStrictEqual } from 'assert'
|
||||
import rmrf from 'rimraf'
|
||||
import { Log, Entry } from '../../../src/index.js'
|
||||
import { Log, Entry, Database } from '../../../src/index.js'
|
||||
import { DocumentStore } from '../../../src/db/index.js'
|
||||
import { Database } from '../../../src/index.js'
|
||||
import { config, startIpfs, stopIpfs } from 'orbit-db-test-utils'
|
||||
import connectPeers from '../../utils/connect-nodes.js'
|
||||
import { createTestIdentities, cleanUpTestIdentities } from '../../fixtures/orbit-db-identity-keys.js'
|
||||
|
@ -1,8 +1,7 @@
|
||||
import { deepStrictEqual } from 'assert'
|
||||
import rmrf from 'rimraf'
|
||||
import { Log, Entry } from '../../../src/index.js'
|
||||
import { Log, Entry, Database } from '../../../src/index.js'
|
||||
import { EventStore } from '../../../src/db/index.js'
|
||||
import { Database } from '../../../src/index.js'
|
||||
import { config, startIpfs, stopIpfs } from 'orbit-db-test-utils'
|
||||
import connectPeers from '../../utils/connect-nodes.js'
|
||||
import waitFor from '../../utils/wait-for.js'
|
||||
|
@ -1,8 +1,7 @@
|
||||
import { deepStrictEqual } from 'assert'
|
||||
import rmrf from 'rimraf'
|
||||
import { Log, Entry } from '../../../src/index.js'
|
||||
import { Log, Entry, Database } from '../../../src/index.js'
|
||||
import { KeyValue, KeyValuePersisted } from '../../../src/db/index.js'
|
||||
import { Database } from '../../../src/index.js'
|
||||
import { config, startIpfs, stopIpfs } from 'orbit-db-test-utils'
|
||||
import connectPeers from '../../utils/connect-nodes.js'
|
||||
import waitFor from '../../utils/wait-for.js'
|
||||
|
@ -1,44 +1,30 @@
|
||||
import { strictEqual, deepStrictEqual } from 'assert'
|
||||
import rimraf from 'rimraf'
|
||||
import rmrf from 'rimraf'
|
||||
import { copy } from 'fs-extra'
|
||||
import { Log } from '../../src/oplog/index.js'
|
||||
import MemoryStorage from '../../src/storage/memory.js'
|
||||
import LevelStorage from '../../src/storage/level.js'
|
||||
import { Identities } from '../../src/identities/index.js'
|
||||
import KeyStore from '../../src/key-store.js'
|
||||
import { Log, Identities, KeyStore } from '../../src/index.js'
|
||||
import testKeysPath from '../fixtures/test-keys-path.js '
|
||||
|
||||
// Test utils
|
||||
import { config, testAPIs } from 'orbit-db-test-utils'
|
||||
const keysPath = './testkeys'
|
||||
|
||||
const { sync: rmrf } = rimraf
|
||||
|
||||
let testIdentity
|
||||
|
||||
Object.keys(testAPIs).forEach((IPFS) => {
|
||||
describe('Log - Append (' + IPFS + ')', function () {
|
||||
this.timeout(config.timeout)
|
||||
|
||||
const { identityKeyFixtures, signingKeyFixtures, identityKeysPath } = config
|
||||
describe('Log - Append', function () {
|
||||
this.timeout(5000)
|
||||
|
||||
let keystore
|
||||
let identities
|
||||
let testIdentity
|
||||
|
||||
before(async () => {
|
||||
rmrf(identityKeysPath)
|
||||
await copy(identityKeyFixtures, identityKeysPath)
|
||||
await copy(signingKeyFixtures, identityKeysPath)
|
||||
|
||||
keystore = await KeyStore({ storage: await LevelStorage({ path: identityKeysPath }) })
|
||||
|
||||
const storage = await MemoryStorage()
|
||||
|
||||
identities = await Identities({ keystore, storage })
|
||||
await copy(testKeysPath, keysPath)
|
||||
keystore = await KeyStore({ path: keysPath })
|
||||
identities = await Identities({ keystore })
|
||||
testIdentity = await identities.createIdentity({ id: 'userA' })
|
||||
})
|
||||
|
||||
after(async () => {
|
||||
if (keystore) {
|
||||
await keystore.close()
|
||||
rmrf(identityKeysPath)
|
||||
}
|
||||
await rmrf(keysPath)
|
||||
})
|
||||
|
||||
describe('append', async () => {
|
||||
@ -131,4 +117,3 @@ Object.keys(testAPIs).forEach((IPFS) => {
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
@ -1,27 +1,22 @@
|
||||
import { strictEqual, deepStrictEqual } from 'assert'
|
||||
import rimraf from 'rimraf'
|
||||
import { Log } from '../../src/oplog/index.js'
|
||||
import { Identities } from '../../src/identities/index.js'
|
||||
import KeyStore from '../../src/key-store.js'
|
||||
import { config, testAPIs } from 'orbit-db-test-utils'
|
||||
import rmrf from 'rimraf'
|
||||
import { copy } from 'fs-extra'
|
||||
import { Log, Identities, KeyStore } from '../../src/index.js'
|
||||
import testKeysPath from '../fixtures/test-keys-path.js '
|
||||
|
||||
const { sync: rmrf } = rimraf
|
||||
const keysPath = './testkeys'
|
||||
|
||||
let testIdentity, testIdentity2, testIdentity3
|
||||
|
||||
Object.keys(testAPIs).forEach((IPFS) => {
|
||||
describe('Log - CRDT (' + IPFS + ')', function () {
|
||||
this.timeout(config.timeout)
|
||||
|
||||
const { identityKeysPath } = config
|
||||
describe('Log - CRDT', function () {
|
||||
this.timeout(5000)
|
||||
|
||||
let keystore
|
||||
let identities1
|
||||
|
||||
before(async () => {
|
||||
keystore = await KeyStore({ path: testKeysPath })
|
||||
|
||||
await copy(testKeysPath, keysPath)
|
||||
keystore = await KeyStore({ path: keysPath })
|
||||
identities1 = await Identities({ keystore })
|
||||
testIdentity = await identities1.createIdentity({ id: 'userA' })
|
||||
testIdentity2 = await identities1.createIdentity({ id: 'userB' })
|
||||
@ -29,8 +24,10 @@ Object.keys(testAPIs).forEach((IPFS) => {
|
||||
})
|
||||
|
||||
after(async () => {
|
||||
if (keystore) {
|
||||
await keystore.close()
|
||||
rmrf(identityKeysPath)
|
||||
}
|
||||
await rmrf(keysPath)
|
||||
})
|
||||
|
||||
describe('is a CRDT', async () => {
|
||||
@ -243,4 +240,3 @@ Object.keys(testAPIs).forEach((IPFS) => {
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
@ -1,54 +1,38 @@
|
||||
import { strictEqual, deepStrictEqual } from 'assert'
|
||||
import rimraf from 'rimraf'
|
||||
import rmrf from 'rimraf'
|
||||
import { copy } from 'fs-extra'
|
||||
import { Entry } from '../../src/oplog/index.js'
|
||||
import { Identities } from '../../src/identities/index.js'
|
||||
import KeyStore from '../../src/key-store.js'
|
||||
import { config, testAPIs, startIpfs, stopIpfs } from 'orbit-db-test-utils'
|
||||
import { Entry, Identities, KeyStore } from '../../src/index.js'
|
||||
import testKeysPath from '../fixtures/test-keys-path.js '
|
||||
|
||||
const { sync: rmrf } = rimraf
|
||||
const { create, isEntry } = Entry
|
||||
const keysPath = './testkeys'
|
||||
|
||||
Object.keys(testAPIs).forEach((IPFS) => {
|
||||
describe('Entry (' + IPFS + ')', function () {
|
||||
this.timeout(config.timeout)
|
||||
|
||||
const { identityKeyFixtures, signingKeyFixtures, identityKeysPath } = config
|
||||
describe('Entry', function () {
|
||||
this.timeout(5000)
|
||||
|
||||
let keystore
|
||||
let identities
|
||||
let testIdentity
|
||||
let ipfsd, ipfs
|
||||
|
||||
before(async () => {
|
||||
ipfsd = await startIpfs(IPFS, config.daemon1)
|
||||
ipfs = ipfsd.api
|
||||
|
||||
await copy(identityKeyFixtures, identityKeysPath)
|
||||
await copy(signingKeyFixtures, identityKeysPath)
|
||||
|
||||
keystore = await KeyStore({ path: testKeysPath })
|
||||
|
||||
identities = await Identities({ keystore, ipfs })
|
||||
await copy(testKeysPath, keysPath)
|
||||
keystore = await KeyStore({ path: keysPath })
|
||||
identities = await Identities({ keystore })
|
||||
testIdentity = await identities.createIdentity({ id: 'userA' })
|
||||
})
|
||||
|
||||
after(async () => {
|
||||
if (keystore) {
|
||||
await keystore.close()
|
||||
|
||||
if (ipfsd) {
|
||||
await stopIpfs(ipfsd)
|
||||
}
|
||||
|
||||
rmrf(identityKeysPath)
|
||||
await rmrf(keysPath)
|
||||
})
|
||||
|
||||
describe('create', () => {
|
||||
it('creates a an empty entry', async () => {
|
||||
// const expectedHash = 'zdpuAsqjGLA4aAGiSNYeTE5zH6e5ayRpgiZrfN2d3UpmzEF76'
|
||||
const expectedHash = 'zdpuApShn2wbu8aDWJhmzBtLWmoVF5VBbVVtuszMpscmiUgrH'
|
||||
const entry = await create(testIdentity, 'A', 'hello')
|
||||
// strictEqual(entry.hash, expectedHash)
|
||||
strictEqual(entry.hash, expectedHash)
|
||||
strictEqual(entry.id, 'A')
|
||||
strictEqual(entry.clock.id, testIdentity.publicKey)
|
||||
strictEqual(entry.clock.time, 0)
|
||||
@ -59,9 +43,10 @@ Object.keys(testAPIs).forEach((IPFS) => {
|
||||
})
|
||||
|
||||
it('creates a entry with payload', async () => {
|
||||
// const expectedHash = 'zdpuB2uuvoKD9cmBV8ET5R9KeytY1Jq72LNQrjEpuEyZURP5Q'
|
||||
const expectedHash = 'zdpuApKrG9gBpxSqNRQ1Zq8zkkVTS1GQxYoCkXKtDvuNKv4WB'
|
||||
const payload = 'hello world'
|
||||
const entry = await create(testIdentity, 'A', payload)
|
||||
strictEqual(entry.hash, expectedHash)
|
||||
strictEqual(entry.payload, payload)
|
||||
strictEqual(entry.id, 'A')
|
||||
strictEqual(entry.clock.id, testIdentity.publicKey)
|
||||
@ -69,7 +54,6 @@ Object.keys(testAPIs).forEach((IPFS) => {
|
||||
strictEqual(entry.v, 2)
|
||||
strictEqual(entry.next.length, 0)
|
||||
strictEqual(entry.refs.length, 0)
|
||||
// strictEqual(entry.hash, expectedHash)
|
||||
})
|
||||
|
||||
it('retrieves the identity from an entry', async () => {
|
||||
@ -198,4 +182,3 @@ Object.keys(testAPIs).forEach((IPFS) => {
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
@ -1,46 +1,34 @@
|
||||
import { strictEqual, deepStrictEqual } from 'assert'
|
||||
import rimraf from 'rimraf'
|
||||
import rmrf from 'rimraf'
|
||||
import { copy } from 'fs-extra'
|
||||
import { Log } from '../../src/oplog/index.js'
|
||||
import { Identities } from '../../src/identities/index.js'
|
||||
import KeyStore from '../../src/key-store.js'
|
||||
import MemoryStorage from '../../src/storage/memory.js'
|
||||
import { config, testAPIs } from 'orbit-db-test-utils'
|
||||
import { Log, Identities, KeyStore } from '../../src/index.js'
|
||||
import testKeysPath from '../fixtures/test-keys-path.js '
|
||||
|
||||
const { sync: rmrf } = rimraf
|
||||
|
||||
let testIdentity
|
||||
const keysPath = './testkeys'
|
||||
|
||||
const last = (arr) => {
|
||||
return arr[arr.length - 1]
|
||||
}
|
||||
|
||||
Object.keys(testAPIs).forEach((IPFS) => {
|
||||
describe('Log - Heads (' + IPFS + ')', function () {
|
||||
this.timeout(config.timeout)
|
||||
|
||||
const { identityKeyFixtures, signingKeyFixtures, identityKeysPath } = config
|
||||
describe('Log - Heads', function () {
|
||||
this.timeout(5000)
|
||||
|
||||
let keystore
|
||||
let identities
|
||||
let testIdentity
|
||||
|
||||
before(async () => {
|
||||
rmrf(identityKeysPath)
|
||||
|
||||
await copy(identityKeyFixtures, identityKeysPath)
|
||||
await copy(signingKeyFixtures, identityKeysPath)
|
||||
|
||||
keystore = await KeyStore({ path: testKeysPath })
|
||||
const storage = await MemoryStorage()
|
||||
|
||||
identities = await Identities({ keystore, storage })
|
||||
await copy(testKeysPath, keysPath)
|
||||
keystore = await KeyStore({ path: keysPath })
|
||||
identities = await Identities({ keystore })
|
||||
testIdentity = await identities.createIdentity({ id: 'userA' })
|
||||
})
|
||||
|
||||
after(async () => {
|
||||
if (keystore) {
|
||||
await keystore.close()
|
||||
rmrf(identityKeysPath)
|
||||
}
|
||||
await rmrf(keysPath)
|
||||
})
|
||||
|
||||
it('finds one head after one entry', async () => {
|
||||
@ -181,4 +169,3 @@ Object.keys(testAPIs).forEach((IPFS) => {
|
||||
deepStrictEqual(heads[2].hash, expectedHead3.hash)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
@ -1,61 +1,38 @@
|
||||
import { strictEqual, deepStrictEqual } from 'assert'
|
||||
import rimraf from 'rimraf'
|
||||
import { Log } from '../../src/oplog/index.js'
|
||||
import { Identities } from '../../src/identities/index.js'
|
||||
import KeyStore from '../../src/key-store.js'
|
||||
import LogCreator from './utils/log-creator.js'
|
||||
import all from 'it-all'
|
||||
import MemoryStorage from '../../src/storage/memory.js'
|
||||
import LevelStorage from '../../src/storage/level.js'
|
||||
import rmrf from 'rimraf'
|
||||
import { copy } from 'fs-extra'
|
||||
import { Log, Identities, KeyStore } from '../../src/index.js'
|
||||
import LogCreator from './utils/log-creator.js'
|
||||
import testKeysPath from '../fixtures/test-keys-path.js '
|
||||
|
||||
// Test utils
|
||||
import { config, testAPIs, startIpfs, stopIpfs } from 'orbit-db-test-utils'
|
||||
import { identityKeys, signingKeys } from '../fixtures/orbit-db-identity-keys.js'
|
||||
|
||||
const { sync: rmrf } = rimraf
|
||||
const { createLogWithSixteenEntries } = LogCreator
|
||||
|
||||
Object.keys(testAPIs).forEach((IPFS) => {
|
||||
describe('Log - Iterator (' + IPFS + ')', function () {
|
||||
this.timeout(config.timeout)
|
||||
const keysPath = './testkeys'
|
||||
|
||||
describe('Log - Iterator', function () {
|
||||
this.timeout(5000)
|
||||
|
||||
let ipfs
|
||||
let ipfsd
|
||||
let keystore
|
||||
let identities1, identities2, identities3
|
||||
let testIdentity, testIdentity2, testIdentity3
|
||||
|
||||
before(async () => {
|
||||
keystore = await KeyStore({ storage: await LevelStorage({ path: './keys_1', valueEncoding: 'json' }) })
|
||||
|
||||
for (const [key, value] of Object.entries(identityKeys)) {
|
||||
await keystore.addKey(key, value)
|
||||
}
|
||||
for (const [key, value] of Object.entries(signingKeys)) {
|
||||
await keystore.addKey(key, value)
|
||||
}
|
||||
|
||||
const storage = await MemoryStorage()
|
||||
|
||||
identities1 = await Identities({ keystore, storage })
|
||||
identities2 = await Identities({ keystore, storage })
|
||||
identities3 = await Identities({ keystore, storage })
|
||||
testIdentity = await identities1.createIdentity({ id: 'userA' })
|
||||
await copy(testKeysPath, keysPath)
|
||||
keystore = await KeyStore({ path: keysPath })
|
||||
identities1 = await Identities({ keystore })
|
||||
identities2 = await Identities({ keystore })
|
||||
identities3 = await Identities({ keystore })
|
||||
testIdentity = await identities1.createIdentity({ id: 'userC' })
|
||||
testIdentity2 = await identities2.createIdentity({ id: 'userB' })
|
||||
testIdentity3 = await identities3.createIdentity({ id: 'userC' })
|
||||
|
||||
ipfsd = await startIpfs(IPFS, config.defaultIpfsConfig)
|
||||
ipfs = ipfsd.api
|
||||
})
|
||||
|
||||
after(async () => {
|
||||
if (ipfsd) {
|
||||
await stopIpfs(ipfsd)
|
||||
}
|
||||
if (keystore) {
|
||||
await keystore.close()
|
||||
}
|
||||
rmrf('./keys_1')
|
||||
await rmrf(keysPath)
|
||||
})
|
||||
|
||||
describe('Basic iterator functionality', async () => {
|
||||
@ -410,7 +387,7 @@ Object.keys(testAPIs).forEach((IPFS) => {
|
||||
|
||||
before(async () => {
|
||||
identities = [testIdentity3, testIdentity2, testIdentity3, testIdentity]
|
||||
fixture = await createLogWithSixteenEntries(Log, ipfs, identities)
|
||||
fixture = await createLogWithSixteenEntries(Log, null, identities)
|
||||
heads = await fixture.log.heads()
|
||||
})
|
||||
|
||||
@ -487,4 +464,3 @@ Object.keys(testAPIs).forEach((IPFS) => {
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
@ -1,29 +1,31 @@
|
||||
import { strictEqual, deepStrictEqual } from 'assert'
|
||||
import { Log } from '../../src/oplog/index.js'
|
||||
import { Identities } from '../../src/identities/index.js'
|
||||
import KeyStore from '../../src/key-store.js'
|
||||
import { config, testAPIs } from 'orbit-db-test-utils'
|
||||
import rmrf from 'rimraf'
|
||||
import { copy } from 'fs-extra'
|
||||
import { Log, Identities, KeyStore } from '../../src/index.js'
|
||||
import testKeysPath from '../fixtures/test-keys-path.js '
|
||||
|
||||
let testIdentity, testIdentity2
|
||||
const keysPath = './testkeys'
|
||||
|
||||
Object.keys(testAPIs).forEach(IPFS => {
|
||||
describe('Log - Join Concurrent Entries (' + IPFS + ')', function () {
|
||||
this.timeout(config.timeout)
|
||||
describe('Log - Join Concurrent Entries', function () {
|
||||
this.timeout(5000)
|
||||
|
||||
let keystore
|
||||
let identities1
|
||||
let testIdentity, testIdentity2
|
||||
|
||||
before(async () => {
|
||||
keystore = await KeyStore({ path: testKeysPath })
|
||||
|
||||
await copy(testKeysPath, keysPath)
|
||||
keystore = await KeyStore({ path: keysPath })
|
||||
identities1 = await Identities({ keystore })
|
||||
testIdentity = await identities1.createIdentity({ id: 'userA' })
|
||||
testIdentity2 = await identities1.createIdentity({ id: 'userB' })
|
||||
})
|
||||
|
||||
after(async () => {
|
||||
if (keystore) {
|
||||
await keystore.close()
|
||||
}
|
||||
await rmrf(keysPath)
|
||||
})
|
||||
|
||||
describe('join ', async () => {
|
||||
@ -83,4 +85,3 @@ Object.keys(testAPIs).forEach(IPFS => {
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
@ -1,24 +1,18 @@
|
||||
import { strictEqual, notStrictEqual, deepStrictEqual } from 'assert'
|
||||
import rimraf from 'rimraf'
|
||||
import { Log, Clock } from '../../src/oplog/index.js'
|
||||
import { Identities } from '../../src/identities/index.js'
|
||||
import KeyStore from '../../src/key-store.js'
|
||||
import LevelStorage from '../../src/storage/level.js'
|
||||
import MemoryStorage from '../../src/storage/memory.js'
|
||||
import rmrf from 'rimraf'
|
||||
import { copy } from 'fs-extra'
|
||||
import { Log, Identities, KeyStore } from '../../src/index.js'
|
||||
import { Clock } from '../../src/oplog/log.js'
|
||||
import testKeysPath from '../fixtures/test-keys-path.js '
|
||||
|
||||
// Test utils
|
||||
import { config, testAPIs } from 'orbit-db-test-utils'
|
||||
import { identityKeys, signingKeys } from '../fixtures/orbit-db-identity-keys.js'
|
||||
|
||||
const { sync: rmrf } = rimraf
|
||||
const keysPath = './testkeys'
|
||||
|
||||
const last = (arr) => {
|
||||
return arr[arr.length - 1]
|
||||
}
|
||||
|
||||
Object.keys(testAPIs).forEach((IPFS) => {
|
||||
describe('Log - Join (' + IPFS + ')', async function () {
|
||||
this.timeout(config.timeout)
|
||||
describe('Log - Join', async function () {
|
||||
this.timeout(5000)
|
||||
|
||||
let keystore
|
||||
let log1, log2, log3, log4
|
||||
@ -26,32 +20,23 @@ Object.keys(testAPIs).forEach((IPFS) => {
|
||||
let testIdentity, testIdentity2, testIdentity3, testIdentity4
|
||||
|
||||
before(async () => {
|
||||
keystore = await KeyStore({ storage: await LevelStorage({ path: './keys_1', valueEncoding: 'json' }) })
|
||||
|
||||
for (const [key, value] of Object.entries(identityKeys)) {
|
||||
await keystore.addKey(key, value)
|
||||
}
|
||||
for (const [key, value] of Object.entries(signingKeys)) {
|
||||
await keystore.addKey(key, value)
|
||||
}
|
||||
|
||||
const storage = await MemoryStorage()
|
||||
|
||||
identities1 = await Identities({ keystore, storage })
|
||||
identities2 = await Identities({ keystore, storage })
|
||||
identities3 = await Identities({ keystore, storage })
|
||||
identities4 = await Identities({ keystore, storage })
|
||||
testIdentity = await identities1.createIdentity({ id: 'userC' })
|
||||
testIdentity2 = await identities2.createIdentity({ id: 'userB' })
|
||||
testIdentity3 = await identities3.createIdentity({ id: 'userD' })
|
||||
testIdentity4 = await identities4.createIdentity({ id: 'userA' })
|
||||
await copy(testKeysPath, keysPath)
|
||||
keystore = await KeyStore({ path: keysPath })
|
||||
identities1 = await Identities({ keystore })
|
||||
identities2 = await Identities({ keystore })
|
||||
identities3 = await Identities({ keystore })
|
||||
identities4 = await Identities({ keystore })
|
||||
testIdentity = await identities1.createIdentity({ id: 'userX' })
|
||||
testIdentity2 = await identities2.createIdentity({ id: 'userA' })
|
||||
testIdentity3 = await identities3.createIdentity({ id: 'userB' })
|
||||
testIdentity4 = await identities4.createIdentity({ id: 'userC' })
|
||||
})
|
||||
|
||||
after(async () => {
|
||||
if (keystore) {
|
||||
await keystore.close()
|
||||
}
|
||||
rmrf('./keys_1')
|
||||
await rmrf(keysPath)
|
||||
})
|
||||
|
||||
beforeEach(async () => {
|
||||
@ -441,4 +426,3 @@ Object.keys(testAPIs).forEach((IPFS) => {
|
||||
deepStrictEqual(values.map((e) => e.payload), expectedData)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
@ -2,9 +2,8 @@ import { strictEqual, deepStrictEqual, notStrictEqual, throws } from 'assert'
|
||||
import rimraf from 'rimraf'
|
||||
import { copy } from 'fs-extra'
|
||||
import { Log, Entry, Sorting } from '../../src/oplog/index.js'
|
||||
import { Identities, KeyStore } from '../../src/index.js'
|
||||
import bigLogString from '../fixtures/big-log.fixture.js'
|
||||
import { Identities } from '../../src/identities/index.js'
|
||||
import KeyStore from '../../src/key-store.js'
|
||||
import LogCreator from './utils/log-creator.js'
|
||||
import testKeysPath from '../fixtures/test-keys-path.js '
|
||||
import { config, testAPIs, startIpfs, stopIpfs } from 'orbit-db-test-utils'
|
||||
|
@ -1,42 +1,32 @@
|
||||
import { notStrictEqual, deepStrictEqual, strictEqual } from 'assert'
|
||||
import rimraf from 'rimraf'
|
||||
import { Log, Entry } from '../../src/oplog/index.js'
|
||||
import { Identities } from '../../src/identities/index.js'
|
||||
import KeyStore from '../../src/key-store.js'
|
||||
import rmrf from 'rimraf'
|
||||
import { copy } from 'fs-extra'
|
||||
import MemoryStorage from '../../src/storage/memory.js'
|
||||
import { config, testAPIs } from 'orbit-db-test-utils'
|
||||
import { Log, Entry, Identities, KeyStore, MemoryStorage } from '../../src/index.js'
|
||||
import testKeysPath from '../fixtures/test-keys-path.js '
|
||||
|
||||
const { sync: rmrf } = rimraf
|
||||
const { create } = Entry
|
||||
|
||||
let testIdentity
|
||||
const keysPath = './testkeys'
|
||||
|
||||
Object.keys(testAPIs).forEach((IPFS) => {
|
||||
describe('Log (' + IPFS + ')', function () {
|
||||
this.timeout(config.timeout)
|
||||
|
||||
const { identityKeyFixtures, signingKeyFixtures, identityKeysPath } = config
|
||||
describe('Log', function () {
|
||||
this.timeout(5000)
|
||||
|
||||
let keystore
|
||||
let identities
|
||||
let testIdentity
|
||||
|
||||
before(async () => {
|
||||
await copy(identityKeyFixtures, identityKeysPath)
|
||||
await copy(signingKeyFixtures, identityKeysPath)
|
||||
|
||||
keystore = await KeyStore({ path: testKeysPath })
|
||||
|
||||
const storage = await MemoryStorage()
|
||||
|
||||
identities = await Identities({ keystore, storage })
|
||||
await copy(testKeysPath, keysPath)
|
||||
keystore = await KeyStore({ path: keysPath })
|
||||
identities = await Identities({ keystore })
|
||||
testIdentity = await identities.createIdentity({ id: 'userA' })
|
||||
})
|
||||
|
||||
after(async () => {
|
||||
if (keystore) {
|
||||
await keystore.close()
|
||||
rmrf(identityKeysPath)
|
||||
}
|
||||
await rmrf(keysPath)
|
||||
})
|
||||
|
||||
describe('create', async () => {
|
||||
@ -154,4 +144,3 @@ Object.keys(testAPIs).forEach((IPFS) => {
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
@ -1,43 +1,31 @@
|
||||
import { strictEqual } from 'assert'
|
||||
import rimraf from 'rimraf'
|
||||
import rmrf from 'rimraf'
|
||||
import { copy } from 'fs-extra'
|
||||
import { Log } from '../../src/oplog/index.js'
|
||||
import { Identities } from '../../src/identities/index.js'
|
||||
import KeyStore from '../../src/key-store.js'
|
||||
import MemoryStorage from '../../src/storage/memory.js'
|
||||
import { Identities, KeyStore, MemoryStorage } from '../../src/index.js'
|
||||
import testKeysPath from '../fixtures/test-keys-path.js '
|
||||
import { config, testAPIs } from 'orbit-db-test-utils'
|
||||
|
||||
const { sync: rmrf } = rimraf
|
||||
const keysPath = './testkeys'
|
||||
|
||||
let testIdentity
|
||||
|
||||
Object.keys(testAPIs).forEach((IPFS) => {
|
||||
describe('Log - References (' + IPFS + ')', function () {
|
||||
this.timeout(config.timeout)
|
||||
|
||||
const { identityKeyFixtures, signingKeyFixtures, identityKeysPath } = config
|
||||
describe('Log - References', function () {
|
||||
this.timeout(60000)
|
||||
|
||||
let keystore
|
||||
let identities
|
||||
let testIdentity
|
||||
|
||||
before(async () => {
|
||||
rmrf(identityKeysPath)
|
||||
|
||||
await copy(identityKeyFixtures, identityKeysPath)
|
||||
await copy(signingKeyFixtures, identityKeysPath)
|
||||
|
||||
keystore = await KeyStore({ path: testKeysPath })
|
||||
|
||||
const storage = await MemoryStorage()
|
||||
|
||||
identities = await Identities({ keystore, storage })
|
||||
await copy(testKeysPath, keysPath)
|
||||
keystore = await KeyStore({ path: keysPath })
|
||||
identities = await Identities({ keystore })
|
||||
testIdentity = await identities.createIdentity({ id: 'userA' })
|
||||
})
|
||||
|
||||
after(async () => {
|
||||
if (keystore) {
|
||||
await keystore.close()
|
||||
rmrf(identityKeysPath)
|
||||
}
|
||||
await rmrf(keysPath)
|
||||
})
|
||||
|
||||
describe('References', async () => {
|
||||
@ -170,4 +158,3 @@ Object.keys(testAPIs).forEach((IPFS) => {
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
@ -1,25 +1,25 @@
|
||||
import { strictEqual } from 'assert'
|
||||
import { Log, Entry } from '../../src/index.js'
|
||||
import { IPFSBlockStorage } from '../../src/storage/index.js'
|
||||
import rmrf from 'rimraf'
|
||||
import { copy } from 'fs-extra'
|
||||
import { Log, Entry, Identities, KeyStore, IPFSBlockStorage } from '../../src/index.js'
|
||||
import { config, startIpfs, stopIpfs, getIpfsPeerId, waitForPeers, connectPeers } from 'orbit-db-test-utils'
|
||||
import testKeysPath from '../fixtures/test-keys-path.js '
|
||||
|
||||
// Test utils
|
||||
import { config, testAPIs, startIpfs, stopIpfs, getIpfsPeerId, waitForPeers, connectPeers } from 'orbit-db-test-utils'
|
||||
import { createTestIdentities, cleanUpTestIdentities } from '../fixtures/orbit-db-identity-keys.js'
|
||||
const keysPath = './testkeys'
|
||||
const IPFS = 'js-ipfs'
|
||||
|
||||
Object.keys(testAPIs).forEach((IPFS) => {
|
||||
describe('ipfs-log - Replication (' + IPFS + ')', function () {
|
||||
this.timeout(config.timeout * 2)
|
||||
describe('Log - Replication', function () {
|
||||
this.timeout(60000)
|
||||
|
||||
let ipfsd1, ipfsd2
|
||||
let ipfs1, ipfs2
|
||||
let id1, id2
|
||||
|
||||
let keystore
|
||||
let identities1, identities2
|
||||
let testIdentity1, testIdentity2
|
||||
let storage1, storage2
|
||||
|
||||
before(async () => {
|
||||
// Start two IPFS instances
|
||||
ipfsd1 = await startIpfs(IPFS, config.daemon1)
|
||||
ipfsd2 = await startIpfs(IPFS, config.daemon2)
|
||||
ipfs1 = ipfsd1.api
|
||||
@ -27,26 +27,30 @@ Object.keys(testAPIs).forEach((IPFS) => {
|
||||
|
||||
await connectPeers(ipfs1, ipfs2)
|
||||
|
||||
// Get the peer IDs
|
||||
id1 = await getIpfsPeerId(ipfs1)
|
||||
id2 = await getIpfsPeerId(ipfs2)
|
||||
|
||||
const [identities, testIdentities] = await createTestIdentities(ipfs1, ipfs2)
|
||||
identities1 = identities[0]
|
||||
identities2 = identities[1]
|
||||
testIdentity2 = testIdentities[0]
|
||||
testIdentity1 = testIdentities[1]
|
||||
await copy(testKeysPath, keysPath)
|
||||
keystore = await KeyStore({ path: keysPath })
|
||||
|
||||
identities1 = await Identities({ keystore, ipfs: ipfs1 })
|
||||
identities2 = await Identities({ keystore, ipfs: ipfs2 })
|
||||
testIdentity1 = await identities1.createIdentity({ id: 'userB' })
|
||||
testIdentity2 = await identities2.createIdentity({ id: 'userA' })
|
||||
|
||||
storage1 = await IPFSBlockStorage({ ipfs: ipfs1 })
|
||||
storage2 = await IPFSBlockStorage({ ipfs: ipfs2 })
|
||||
})
|
||||
|
||||
after(async () => {
|
||||
await cleanUpTestIdentities([identities1, identities2])
|
||||
await stopIpfs(ipfsd1)
|
||||
await stopIpfs(ipfsd2)
|
||||
if (keystore) {
|
||||
await keystore.close()
|
||||
}
|
||||
await storage1.close()
|
||||
await storage2.close()
|
||||
await rmrf(keysPath)
|
||||
})
|
||||
|
||||
describe('replicates logs deterministically', async function () {
|
||||
@ -150,4 +154,3 @@ Object.keys(testAPIs).forEach((IPFS) => {
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
@ -1,30 +1,37 @@
|
||||
import { notStrictEqual, strictEqual } from 'assert'
|
||||
import { Log } from '../../src/oplog/index.js'
|
||||
import { config, testAPIs } from 'orbit-db-test-utils'
|
||||
import { createTestIdentities, cleanUpTestIdentities } from '../fixtures/orbit-db-identity-keys.js'
|
||||
import rmrf from 'rimraf'
|
||||
import { copy } from 'fs-extra'
|
||||
import { Log, Identities, KeyStore } from '../../src/index.js'
|
||||
import testKeysPath from '../fixtures/test-keys-path.js '
|
||||
|
||||
Object.keys(testAPIs).forEach((IPFS) => {
|
||||
describe('Signed Log (' + IPFS + ')', function () {
|
||||
this.timeout(config.timeout)
|
||||
const keysPath = './testkeys'
|
||||
|
||||
let identities1, identities2
|
||||
let testIdentity, testIdentity2
|
||||
describe('Signed Log', function () {
|
||||
this.timeout(5000)
|
||||
|
||||
let keystore
|
||||
let identities
|
||||
let testIdentity1, testIdentity2
|
||||
|
||||
before(async () => {
|
||||
const [identities, testIdentities] = await createTestIdentities()
|
||||
identities1 = identities[0]
|
||||
identities2 = identities[1]
|
||||
testIdentity = testIdentities[0]
|
||||
testIdentity2 = testIdentities[1]
|
||||
await copy(testKeysPath, keysPath)
|
||||
keystore = await KeyStore({ path: keysPath })
|
||||
|
||||
identities = await Identities({ keystore })
|
||||
testIdentity1 = await identities.createIdentity({ id: 'userB' })
|
||||
testIdentity2 = await identities.createIdentity({ id: 'userA' })
|
||||
})
|
||||
|
||||
after(async () => {
|
||||
await cleanUpTestIdentities([identities1, identities2])
|
||||
if (keystore) {
|
||||
await keystore.close()
|
||||
}
|
||||
await rmrf(keysPath)
|
||||
})
|
||||
|
||||
it('creates a signed log', async () => {
|
||||
const logId = 'A'
|
||||
const log = await Log(testIdentity, { logId })
|
||||
const log = await Log(testIdentity1, { logId })
|
||||
notStrictEqual(log.id, null)
|
||||
strictEqual(log.id, logId)
|
||||
})
|
||||
@ -40,18 +47,18 @@ Object.keys(testAPIs).forEach((IPFS) => {
|
||||
// })
|
||||
|
||||
it('has the correct public key', async () => {
|
||||
const log = await Log(testIdentity, { logId: 'A' })
|
||||
strictEqual(log.identity.publicKey, testIdentity.publicKey)
|
||||
const log = await Log(testIdentity1, { logId: 'A' })
|
||||
strictEqual(log.identity.publicKey, testIdentity1.publicKey)
|
||||
})
|
||||
|
||||
it('has the correct pkSignature', async () => {
|
||||
const log = await Log(testIdentity, { logId: 'A' })
|
||||
strictEqual(log.identity.signatures.id, testIdentity.signatures.id)
|
||||
const log = await Log(testIdentity1, { logId: 'A' })
|
||||
strictEqual(log.identity.signatures.id, testIdentity1.signatures.id)
|
||||
})
|
||||
|
||||
it('has the correct signature', async () => {
|
||||
const log = await Log(testIdentity, { logId: 'A' })
|
||||
strictEqual(log.identity.signatures.publicKey, testIdentity.signatures.publicKey)
|
||||
const log = await Log(testIdentity1, { logId: 'A' })
|
||||
strictEqual(log.identity.signatures.publicKey, testIdentity1.signatures.publicKey)
|
||||
})
|
||||
|
||||
// it('entries contain an identity', async () => {
|
||||
@ -73,7 +80,7 @@ Object.keys(testAPIs).forEach((IPFS) => {
|
||||
})
|
||||
|
||||
it('throws an error if log is signed but trying to merge with an entry that doesn\'t have public signing key', async () => {
|
||||
const log1 = await Log(testIdentity, { logId: 'A' })
|
||||
const log1 = await Log(testIdentity1, { logId: 'A' })
|
||||
const log2 = await Log(testIdentity2, { logId: 'A' })
|
||||
|
||||
let err
|
||||
@ -89,7 +96,7 @@ Object.keys(testAPIs).forEach((IPFS) => {
|
||||
})
|
||||
|
||||
it('throws an error if log is signed but trying to merge an entry that doesn\'t have a signature', async () => {
|
||||
const log1 = await Log(testIdentity, { logId: 'A' })
|
||||
const log1 = await Log(testIdentity1, { logId: 'A' })
|
||||
const log2 = await Log(testIdentity2, { logId: 'A' })
|
||||
|
||||
let err
|
||||
@ -105,7 +112,7 @@ Object.keys(testAPIs).forEach((IPFS) => {
|
||||
})
|
||||
|
||||
it('throws an error if log is signed but the signature doesn\'t verify', async () => {
|
||||
const log1 = await Log(testIdentity, { logId: 'A' })
|
||||
const log1 = await Log(testIdentity1, { logId: 'A' })
|
||||
const log2 = await Log(testIdentity2, { logId: 'A' })
|
||||
let err
|
||||
|
||||
@ -127,7 +134,7 @@ Object.keys(testAPIs).forEach((IPFS) => {
|
||||
|
||||
it('throws an error if entry doesn\'t have append access', async () => {
|
||||
const denyAccess = { canAppend: () => false }
|
||||
const log1 = await Log(testIdentity, { logId: 'A' })
|
||||
const log1 = await Log(testIdentity1, { logId: 'A' })
|
||||
const log2 = await Log(testIdentity2, { logId: 'A', access: denyAccess })
|
||||
|
||||
let err
|
||||
@ -145,11 +152,11 @@ Object.keys(testAPIs).forEach((IPFS) => {
|
||||
it('throws an error upon join if entry doesn\'t have append access', async () => {
|
||||
const testACL = {
|
||||
canAppend: async (entry) => {
|
||||
const identity = await identities1.getIdentity(entry.identity)
|
||||
const identity = await identities.getIdentity(entry.identity)
|
||||
return identity && identity.id !== testIdentity2.id
|
||||
}
|
||||
}
|
||||
const log1 = await Log(testIdentity, { logId: 'A', access: testACL })
|
||||
const log1 = await Log(testIdentity1, { logId: 'A', access: testACL })
|
||||
const log2 = await Log(testIdentity2, { logId: 'A' })
|
||||
|
||||
let err
|
||||
@ -164,4 +171,3 @@ Object.keys(testAPIs).forEach((IPFS) => {
|
||||
strictEqual(err, `Error: Could not append entry:\nKey "${testIdentity2.hash}" is not allowed to write to the log`)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
Loading…
x
Reference in New Issue
Block a user