Fix tests

This commit is contained in:
haad 2023-02-22 10:09:15 +02:00
parent 2189f39b3d
commit e03af7e905
8 changed files with 39 additions and 40 deletions

View File

@ -29,7 +29,7 @@ Object.keys(testAPIs).forEach((IPFS) => {
ipfsd = await startIpfs(IPFS, config.daemon1)
ipfs = ipfsd.api
const [identities, testIdentities] = await createTestIdentities([ipfs])
const [identities, testIdentities] = await createTestIdentities(ipfs)
identities1 = identities[0]
testIdentity1 = testIdentities[0]

View File

@ -30,7 +30,7 @@ Object.keys(testAPIs).forEach((IPFS) => {
ipfsd = await startIpfs(IPFS, config.daemon1)
ipfs = ipfsd.api
const [identities, testIdentities] = await createTestIdentities([ipfs])
const [identities, testIdentities] = await createTestIdentities(ipfs)
identities1 = identities[0]
testIdentity1 = testIdentities[0]
@ -185,7 +185,7 @@ Object.keys(testAPIs).forEach((IPFS) => {
it('returns head only', async () => {
const all = []
for await (const ev of db.iterator({ amount: 1 })) {
all.unshift(ev)
all.unshift(ev)
}
strictEqual(all.length, 1)
@ -195,7 +195,7 @@ Object.keys(testAPIs).forEach((IPFS) => {
it('returns head + 1', async () => {
const all = []
for await (const ev of db.iterator({ amount: 2 })) {
all.unshift(ev)
all.unshift(ev)
}
strictEqual(all.length, 2)
@ -205,7 +205,7 @@ Object.keys(testAPIs).forEach((IPFS) => {
it('returns head + 2', async () => {
const all = []
for await (const ev of db.iterator({ amount: 3 })) {
all.unshift(ev)
all.unshift(ev)
}
strictEqual(all.length, 3)
@ -215,27 +215,27 @@ Object.keys(testAPIs).forEach((IPFS) => {
it('returns next item greater than root', async () => {
const all = []
for await (const ev of db.iterator({ gt: first(hashes), amount: 1 })) {
all.unshift(ev)
all.unshift(ev)
}
strictEqual(all.length, 1)
deepStrictEqual(all.map(e => e.value), ['hello2'])
deepStrictEqual(all.map(e => e.value), ['hello1'])
})
it('returns next two items greater than root', async () => {
const all = []
for await (const ev of db.iterator({ gt: first(hashes), amount: 2 })) {
all.unshift(ev)
all.unshift(ev)
}
strictEqual(all.length, 2)
deepStrictEqual(all.map(e => e.value), ['hello2', 'hello3'])
deepStrictEqual(all.map(e => e.value), ['hello1', 'hello2'])
})
it('returns first item less than head', async () => {
const all = []
for await (const ev of db.iterator({ lt: last(hashes), amount: 1 })) {
all.unshift(ev)
all.unshift(ev)
}
strictEqual(all.length, 1)

View File

@ -1,16 +1,16 @@
import { 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 { Feed, Database } from '../src/db/index.js'
import { IPFSBlockStorage, LevelStorage } from '../src/storage/index.js'
import { Log, Entry } from '../../src/oplog/index.js'
import { Identities } from '../../src/identities/index.js'
import KeyStore from '../../src/key-store.js'
import { Feed, Database } from '../../src/db/index.js'
import { IPFSBlockStorage, LevelStorage } from '../../src/storage/index.js'
// Test utils
import { config, testAPIs, getIpfsPeerId, waitForPeers, startIpfs, stopIpfs } from 'orbit-db-test-utils'
import connectPeers from './utils/connect-nodes.js'
import waitFor from './utils/wait-for.js'
import { createTestIdentities, cleanUpTestIdentities } from './fixtures/orbit-db-identity-keys.js'
import connectPeers from '../utils/connect-nodes.js'
import waitFor from '../utils/wait-for.js'
import { createTestIdentities, cleanUpTestIdentities } from '../fixtures/orbit-db-identity-keys.js'
const { sync: rmrf } = rimraf
const { createIdentity } = Identities

View File

@ -1,16 +1,16 @@
import { 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 { KeyValue, KeyValuePersisted, Database } from '../src/db/index.js'
import { IPFSBlockStorage, LevelStorage } from '../src/storage/index.js'
import { Log, Entry } from '../../src/oplog/index.js'
import { Identities } from '../../src/identities/index.js'
import KeyStore from '../../src/key-store.js'
import { KeyValue, KeyValuePersisted, Database } from '../../src/db/index.js'
import { IPFSBlockStorage, LevelStorage } from '../../src/storage/index.js'
// Test utils
import { config, testAPIs, getIpfsPeerId, waitForPeers, startIpfs, stopIpfs } from 'orbit-db-test-utils'
import connectPeers from './utils/connect-nodes.js'
import waitFor from './utils/wait-for.js'
import { createTestIdentities, cleanUpTestIdentities } from './fixtures/orbit-db-identity-keys.js'
import connectPeers from '../utils/connect-nodes.js'
import waitFor from '../utils/wait-for.js'
import { createTestIdentities, cleanUpTestIdentities } from '../fixtures/orbit-db-identity-keys.js'
const { sync: rmrf } = rimraf
const { createIdentity } = Identities

View File

@ -40,7 +40,7 @@ Object.keys(testAPIs).forEach((IPFS) => {
peerId1 = await getIpfsPeerId(ipfs1)
peerId2 = await getIpfsPeerId(ipfs2)
const [identities, testIdentities] = await createTestIdentities([ipfs1, ipfs2])
const [identities, testIdentities] = await createTestIdentities(ipfs1, ipfs2)
identities1 = identities[0]
identities2 = identities[1]
testIdentity1 = testIdentities[0]

View File

@ -40,7 +40,7 @@ Object.keys(testAPIs).forEach((IPFS) => {
peerId1 = await getIpfsPeerId(ipfs1)
peerId2 = await getIpfsPeerId(ipfs2)
const [identities, testIdentities] = await createTestIdentities([ipfs1, ipfs2])
const [identities, testIdentities] = await createTestIdentities(ipfs1, ipfs2)
identities1 = identities[0]
identities2 = identities[1]
testIdentity1 = testIdentities[0]

View File

@ -28,7 +28,7 @@ const signingKeys = {
userD: userD_,
}
const createTestIdentities = async (ipfsInstances) => {
const createTestIdentities = async (ipfs1, ipfs2) => {
rmrf('./keys_1')
const keystore = new KeyStore('./keys_1')
@ -41,16 +41,13 @@ const createTestIdentities = async (ipfsInstances) => {
await keystore.addKey(key, value)
}
const identities = []
const testIdentities = []
// Create an identity for each peers
const identities1 = await Identities({ keystore, ipfs: ipfs1 })
const identities2 = await Identities({ keystore, ipfs: ipfs2 })
const testIdentity1 = await identities1.createIdentity({ id: 'userA' })
const testIdentity2 = await identities2.createIdentity({ id: 'userB' })
let i = 0
for (const ipfsInstance of ipfsInstances) {
identities.push(await Identities({ keystore, ipfs: ipfsInstance }))
testIdentities.push(await identities[i].createIdentity({ id: 'user'+(++i) }))
}
return [identities, testIdentities]
return [[identities1, identities2], [testIdentity1, testIdentity2]]
}
const cleanUpTestIdentities = async (identities) => {

View File

@ -89,6 +89,7 @@ Object.keys(testAPIs).forEach((IPFS) => {
const result = await all(it)
strictEqual([...result].length, 10)
strictEqual(result[0].hash, startHash)
})
it('returns entries with lte and amount', async () => {
@ -146,7 +147,7 @@ Object.keys(testAPIs).forEach((IPFS) => {
let i = 0
for await (const entry of it) {
strictEqual(entry.payload, 'entry' + (73 - i++))
strictEqual(entry.payload, 'entry' + (72 - i++))
}
strictEqual(i, amount)
@ -163,6 +164,7 @@ Object.keys(testAPIs).forEach((IPFS) => {
const result = await all(it)
strictEqual([...result].length, amount)
strictEqual(result[result.length - 1].hash, startHash)
})
it('returns entries with gte and amount', async () => {
@ -175,7 +177,7 @@ Object.keys(testAPIs).forEach((IPFS) => {
let i = 0
for await (const entry of it) {
strictEqual(entry.payload, 'entry' + (79 - i++))
strictEqual(entry.payload, 'entry' + (78 - i++))
}
strictEqual(i, amount)