From dca79fb97c5c207be03be4eba3cf354e9f1d4e1d Mon Sep 17 00:00:00 2001 From: haad Date: Fri, 29 Nov 2024 14:58:24 +0100 Subject: [PATCH] Unify naming of components to Voyager --- .github/workflows/npm-publish-next.yml | 8 +- .github/workflows/npm-publish.yml | 8 +- .github/workflows/run-test.yml | 8 +- .gitignore | 4 +- README.md | 47 ++++---- package.json | 12 +- src/daemon.js | 28 ++--- src/index.js | 8 +- src/lib/handle-request.js | 6 +- src/lib/handlers/add.js | 2 +- src/lib/handlers/remove.js | 2 +- src/lib/{orbiter.js => host.js} | 6 +- src/lib/{lander.js => voyager.js} | 6 +- src/rpc/handle-command.js | 4 +- src/utils/id.js | 6 +- test/add.test.js | 66 +++++----- test/authorization.test.js | 26 ++-- test/commands/daemon.test.js | 8 +- test/config-manager.test.js | 2 +- test/e2e-browser.test.js | 114 +++++++++--------- test/host.test.js | 38 ++++++ test/messages.test.js | 42 +++---- test/orbiter.test.js | 37 ------ test/remove.test.js | 42 +++---- test/stress-test.js | 79 ------------ test/stress.test.js | 79 ++++++++++++ test/utils/create-and-add-databases.js | 6 +- ...unch-orbiter.js => launch-voyager-host.js} | 21 ++-- ...nch-lander.js => launch-voyager-remote.js} | 18 +-- ...config.js => voyager-app-libp2p-config.js} | 0 ...onfig.js => voyager-host-libp2p-config.js} | 0 ...config.js => voyager-app-libp2p-config.js} | 0 ...onfig.js => voyager-host-libp2p-config.js} | 0 33 files changed, 364 insertions(+), 369 deletions(-) rename src/lib/{orbiter.js => host.js} (91%) rename src/lib/{lander.js => voyager.js} (77%) create mode 100644 test/host.test.js delete mode 100644 test/orbiter.test.js delete mode 100644 test/stress-test.js create mode 100644 test/stress.test.js rename test/utils/{launch-orbiter.js => launch-voyager-host.js} (71%) rename test/utils/{launch-lander.js => launch-voyager-remote.js} (59%) rename test/utils/test-config-browser/{lander-libp2p-config.js => voyager-app-libp2p-config.js} (100%) rename test/utils/test-config-browser/{orbiter-libp2p-config.js => voyager-host-libp2p-config.js} (100%) rename test/utils/test-config/{lander-libp2p-config.js => voyager-app-libp2p-config.js} (100%) rename test/utils/test-config/{orbiter-libp2p-config.js => voyager-host-libp2p-config.js} (100%) diff --git a/.github/workflows/npm-publish-next.yml b/.github/workflows/npm-publish-next.yml index 124ff59..420e250 100644 --- a/.github/workflows/npm-publish-next.yml +++ b/.github/workflows/npm-publish-next.yml @@ -17,10 +17,10 @@ jobs: registry-url: https://registry.npmjs.org/ - run: npm ci - run: npm run lint - - name: Run an Orbiter 1 instance in the background - run: npm run start:orbiter1:background - - name: Run an Orbiter 2 instance in the background - run: npm run start:orbiter2:background + - name: Run an Voyager 1 instance in the background + run: npm run start:host1:background + - name: Run an Voyager 2 instance in the background + run: npm run start:host2:background - run: npm test - run: | npm version prerelease --no-git-tag-version \ diff --git a/.github/workflows/npm-publish.yml b/.github/workflows/npm-publish.yml index decc8c0..83aaa69 100644 --- a/.github/workflows/npm-publish.yml +++ b/.github/workflows/npm-publish.yml @@ -16,10 +16,10 @@ jobs: node-version: 'lts/*' registry-url: https://registry.npmjs.org/ - run: npm ci - - name: Run an Orbiter 1 instance in the background - run: npm run start:orbiter1:background - - name: Run an Orbiter 2 instance in the background - run: npm run start:orbiter2:background + - name: Run an Voyager 1 instance in the background + run: npm run start:host1:background + - name: Run an Voyager 2 instance in the background + run: npm run start:host2:background - run: npm test - run: npm publish env: diff --git a/.github/workflows/run-test.yml b/.github/workflows/run-test.yml index fd78590..3e05a82 100644 --- a/.github/workflows/run-test.yml +++ b/.github/workflows/run-test.yml @@ -18,10 +18,10 @@ jobs: run: npm run lint - name: Run libp2p relay in the background run: npm run start:relay:background - - name: Run an Orbiter 1 instance in the background - run: npm run start:orbiter1:background - - name: Run an Orbiter 2 instance in the background - run: npm run start:orbiter2:background + - name: Run an Voyager 1 instance in the background + run: npm run start:host1:background + - name: Run an Voyager 2 instance in the background + run: npm run start:host2:background - name: Run tests run: npm run test:ci - name: Run browser tests diff --git a/.gitignore b/.gitignore index 0895d74..1049c23 100644 --- a/.gitignore +++ b/.gitignore @@ -2,5 +2,5 @@ node_modules coverage voyager bundle.js* -orbiter1/ -orbiter2/ +host1/ +host2/ diff --git a/README.md b/README.md index 66b20dc..9e59bd9 100644 --- a/README.md +++ b/README.md @@ -26,8 +26,6 @@ npm i -g @orbitdb/voyager ## Usage -Voyager, like OrbitDB, is peer-to-peer and does not have a traditional server/client architecture and so terms "server" and "client" do not apply. Therefore, in keeping with OrbitDB's "celestial" naming convention, the storage service peer is called ***"Orbiter"*** and the interface which the developer or user uses to communicate with the storage service peer is called ***"Lander"***. - ### CLI The `voyager` CLI tool can be used to manage a Voyager instance. Run `voyager` on the command line to get started. @@ -41,15 +39,15 @@ voyager address Show the voyager's network addresses voyager auth Add or remove authorized user ``` -### Orbiter Daemon +### Daemon -Voyager's **Orbiter**, the storage service, can be run as a daemon process. You can install the package globally and run it using the `voyager` CLI binary: +Voyager can be run as a daemon process. You can install the package globally and run it using the `voyager` CLI binary: ```sh voyager daemon ``` -To store Orbiter's configuration and data to a different directory, use the `-d` or `--directory` flag or `VOYAGER_PATH` environment variable: +To store Voyager's configuration and data to a different directory, use the `-d` or `--directory` flag or `VOYAGER_PATH` environment variable: ```sh voyager daemon -d /path/to/voyager @@ -61,7 +59,7 @@ VOYAGER_PATH=/path/to/voyager voyager daemon ### Docker -You can run an Orbiter storage service using a pre-configured Docker image. +You can run an Voyager storage service using a pre-configured Docker image. Once you have cloned this repo, cd into the voyager directory root and run: @@ -72,31 +70,31 @@ docker run --rm -d -p 8000:8000 orbitdb-voyager Adjust the port if required. -## Managing Orbiter Access +## Managing Voyager Access -Orbiter will deny all requests by default. To allow a user to interact with Orbiter, the (requesting) user's `id` must be added to Orbiter's "allow" list. +Voyager will deny all requests by default. To allow a user to interact with Voyager, the (requesting) user's `id` must be added to Voyager's "allow" list. -Access to Orbiter can be configured in two ways; from the terminal and programmatically, using RPC. +Access can be configured in two ways; from the terminal and programmatically, using RPC. **NOTE** The user's `id` used in the examples below can be retrieved using **`orbitdb.identity.id`**, which is available from the user's OrbitDB instance. ### Managing access from the terminal -To add an authorized user to Orbiter: +To add an authorized user to Voyager: ```sh voyager auth add ``` -where `` identifies a user who can add databases to this Orbiter. The `` is the string from user's OrbitDB instance `orbitdb.identity.id`. +where `` identifies a user who can add databases to this Voyager instance. The `` is the string from user's OrbitDB instance `orbitdb.identity.id`. -To remove an authorized user from Orbiter: +To remove an authorized user from Voyager: ```sh voyager auth del ``` -where `` identifies a user who can add databases to this Orbiter. The `` is the string from user's OrbitDB instance `orbitdb.identity.id`. +where `` identifies a user who can add databases to this Voyager instance. The `` is the string from user's OrbitDB instance `orbitdb.identity.id`. List authorized users: @@ -104,7 +102,7 @@ List authorized users: voyager auth list ``` -If Orbiter is deployed to a custom directory, call Voyager with the `-d` or `--directory` flag, or `VOYAGER_PATH`environment variable, and specify the directory: +If Voyager is deployed to a custom directory, call Voyager with the `-d` or `--directory` flag, or `VOYAGER_PATH`environment variable, and specify the directory: ```sh voyager auth add -d /custom/voyager/path @@ -150,35 +148,34 @@ And to remove an authorization: await rpc.authDel() ``` -## Adding databases using Lander +## Adding databases to Voyager -To make databases accessible from Voyager, the database needs to be added to an Orbiter storage service instance. This can be achieved programmatically by using the **Lander** module. +To make databases accessible from a Voyager storage service, the database needs to be added to a Voyager instance. This can be achieved programmatically by using the **Voyager remote API** module. -To use Lander, first install the [@orbitdb/voyager](https://www.npmjs.com/package/@orbitdb/voyager) package: +To use Voyager remote API, first install the [@orbitdb/voyager](https://www.npmjs.com/package/@orbitdb/voyager) package: ```sh npm i @orbitdb/voyager ``` -Next, instantiate Lander: +Next, instantiate Voyager remote API: ```js import { createLibp2p } from 'libp2p' import { createHelia } from 'helia' import { createOrbitDB } from '@orbitdb/core' -import { Lander } from '@orbitdb/voyager' +import { Voyager } from '@orbitdb/voyager' // set up libp2p, helia and orbitdb - const libp2p = await createLibp2p() const ipfs = await createHelia({ libp2p }) const orbitdb = await createOrbitDB({ ipfs }) -// deployed orbiter peer id or listening address, it looks like this: +// deployed voyager peer's listening address, it looks like this: // /ip4/127.0.0.1/tcp/54322/p2p/16Uiu2HAmATMovCwY46yyJib7bGZF2f2XLRar7d7R3NJCSJtuyQLt -const orbiterAddressOrId = '...' +const address = '...' -const lander = await Lander({ orbitdb, orbiterAddressOrId }) +const voyager = await Voyager({ orbitdb, address }) ``` To add a database to voyager: @@ -188,7 +185,7 @@ To add a database to voyager: const db = await orbitdb.open('my-db') // add the address to voyager (can also pass an array of addresses) -await lander.add(db.address) +await voyager.add(db.address) ``` To remove a database from voyager: @@ -198,7 +195,7 @@ To remove a database from voyager: const db = await orbitdb.open('my-db') // remove the address from voyager (can also pass an array of addresses) -await lander.remove(db.address) +await voyager.remove(db.address) ``` ## The OrbitDB Voyager Protocol diff --git a/package.json b/package.json index d165ed0..4a8a928 100644 --- a/package.json +++ b/package.json @@ -48,14 +48,14 @@ "test:ci": "c8 npm run test", "lint": "standard", "lint:fix": "standard --fix", - "copy:fixtures1": "rm -rf ./orbiter1 && mkdir -p ./orbiter1/voyager/orbiter/keystore && cp -Rf test/fixtures/keystore1/** ./orbiter1/voyager/orbiter/keystore/", - "copy:fixtures2": "rm -rf ./orbiter2 && mkdir -p ./orbiter2/voyager/orbiter/keystore && cp -Rf test/fixtures/keystore2/** ./orbiter2/voyager/orbiter/keystore/", + "copy:fixtures1": "rm -rf ./host1 && mkdir -p ./host1/voyager/host/keystore && cp -Rf test/fixtures/keystore1/** ./host1/voyager/host/keystore/", + "copy:fixtures2": "rm -rf ./host2 && mkdir -p ./host2/voyager/host/keystore && cp -Rf test/fixtures/keystore2/** ./host2/voyager/host/keystore/", "start:relay": "node ./test/utils/relay.js", "start:relay:background": "node ./test/utils/relay.js &", - "start:orbiter1": "npm run copy:fixtures1 && node ./src/bin/cli.js daemon -p 54321 -w 55441 --allow --directory ./orbiter1 -vv", - "start:orbiter2": "npm run copy:fixtures2 && node ./src/bin/cli.js daemon -p 54322 -w 55442 --allow --directory ./orbiter2 -vv", - "start:orbiter1:background": "npm run copy:fixtures1 && node ./src/bin/cli.js daemon -p 54321 -w 55441 --allow --directory ./orbiter1 &", - "start:orbiter2:background": "npm run copy:fixtures2 && node ./src/bin/cli.js daemon -p 54322 -w 55442 --allow --directory ./orbiter2 &", + "start:host1": "npm run copy:fixtures1 && node ./src/bin/cli.js daemon -p 54321 -w 55441 --allow --directory ./host1 -vv", + "start:host2": "npm run copy:fixtures2 && node ./src/bin/cli.js daemon -p 54322 -w 55442 --allow --directory ./host2 -vv", + "start:host1:background": "npm run copy:fixtures1 && node ./src/bin/cli.js daemon -p 54321 -w 55441 --allow --directory ./host1 &", + "start:host2:background": "npm run copy:fixtures2 && node ./src/bin/cli.js daemon -p 54322 -w 55442 --allow --directory ./host2 &", "test:browser": "npm run build:tests && ./node_modules/.bin/playwright-test test/browser/bundle.js --runner mocha" }, "standard": { diff --git a/src/daemon.js b/src/daemon.js index 0df465f..f1c3067 100644 --- a/src/daemon.js +++ b/src/daemon.js @@ -5,12 +5,12 @@ import { createOrbitDB, Identities, KeyStore } from '@orbitdb/core' import { LevelBlockstore } from 'blockstore-level' import { LevelDatastore } from 'datastore-level' import { pipe } from 'it-pipe' -import Orbiter from './lib/orbiter.js' +import Host from './lib/host.js' import { voyagerRPCProtocol } from './rpc/protocol.js' import { handleCommand } from './rpc/index.js' import { Access } from './lib/authorization.js' import { config as libp2pConfig } from './utils/libp2p-config.js' -import { rpc as rpcId, appPath, rpcPath, app, orbiter as orbiterId, orbiterPath } from './utils/id.js' +import { rpc as rpcId, appPath, rpcPath, app, host as hostId, hostPath } from './utils/id.js' import { saveConfig } from './utils/config-manager.js' import { logger, enable } from '@libp2p/logger' @@ -41,19 +41,17 @@ export default async ({ options }) => { options.port = options.port || 0 options.wsport = options.wsport || 0 - const id = orbiterId - log('app:', app) - log('orbiter:', id) + log('host:', hostId) log('rpc:', rpcId) const appDirectory = appPath(options.directory) - const orbiterDirectory = orbiterPath(options.directory) + const hostDirectory = hostPath(options.directory) - log('directory:', orbiterDirectory) + log('directory:', hostDirectory) - const blockstore = new LevelBlockstore(join(orbiterDirectory, '/', 'ipfs', '/', 'blocks')) - const datastore = new LevelDatastore(join(orbiterDirectory, '/', 'ipfs', '/', 'data')) + const blockstore = new LevelBlockstore(join(hostDirectory, '/', 'ipfs', '/', 'blocks')) + const datastore = new LevelDatastore(join(hostDirectory, '/', 'ipfs', '/', 'data')) const libp2p = await createLibp2p(libp2pConfig({ port: options.port, websocketPort: options.wsport })) @@ -68,25 +66,25 @@ export default async ({ options }) => { } const ipfs = await createHelia({ libp2p, datastore, blockstore }) - const orbitdb = await createOrbitDB({ ipfs, directory: orbiterDirectory, id }) - const orbiter = await Orbiter({ defaultAccess, verbose: options.verbose, orbitdb }) + const orbitdb = await createOrbitDB({ ipfs, directory: hostDirectory, id: hostId }) + const host = await Host({ defaultAccess, verbose: options.verbose, orbitdb }) const authorizedRPCIdentity = await createRPCIdentity({ id: rpcId, directory: options.directory }) const rpcConfig = { - address: orbiter.orbitdb.ipfs.libp2p.getMultiaddrs().shift(), // get 127.0.0.1 address + address: host.orbitdb.ipfs.libp2p.getMultiaddrs().shift(), // get 127.0.0.1 address identities: [authorizedRPCIdentity] } await saveConfig({ path: appDirectory, config: rpcConfig }) const handleRPCMessages = async ({ stream }) => { - await pipe(stream, handleCommand(rpcConfig, orbiter), stream) + await pipe(stream, handleCommand(rpcConfig, host), stream) } - await orbiter.orbitdb.ipfs.libp2p.handle(voyagerRPCProtocol, handleRPCMessages) + await host.orbitdb.ipfs.libp2p.handle(voyagerRPCProtocol, handleRPCMessages) process.on('SIGINT', async () => { - await orbiter.stop() + await host.stop() await blockstore.close() await datastore.close() process.exit(0) diff --git a/src/index.js b/src/index.js index 6c59250..4773652 100755 --- a/src/index.js +++ b/src/index.js @@ -1,9 +1,9 @@ -import Orbiter from './lib/orbiter.js' -import Lander from './lib/lander.js' +import Host from './lib/host.js' +import Voyager from './lib/voyager.js' import RPC from './rpc-client.js' export { - Orbiter, - Lander, + Host, + Voyager, RPC } diff --git a/src/lib/handle-request.js b/src/lib/handle-request.js index 22710c5..b9f1efe 100644 --- a/src/lib/handle-request.js +++ b/src/lib/handle-request.js @@ -2,11 +2,11 @@ import handleAddRequest from './handlers/add.js' import handleRemoveRequest from './handlers/remove.js' import { ResponseMessage, parseMessage, Requests, Responses } from './messages/index.js' -export const handleRequest = (orbiter) => source => { +export const handleRequest = (host) => source => { return (async function * () { for await (const chunk of source) { const { type, signature, id, addresses } = parseMessage(chunk.subarray()) - const { orbitdb, auth, databases, log } = orbiter + const { orbitdb, auth, databases, log } = host log('handle request', type, signature, id, addresses) @@ -21,7 +21,7 @@ export const handleRequest = (orbiter) => source => { await orbitdb.identities.verifyIdentity(identity) } - // check that the identity is authorized to store their databases on this orbiter + // check that the identity is authorized to store their databases on this voyager if (!await auth.hasAccess(identity.id)) { throw Object.assign(new Error('user is not authorized to add'), { type: Responses.E_NOT_AUTHORIZED }) } diff --git a/src/lib/handlers/add.js b/src/lib/handlers/add.js index 3f3111c..a0ef50c 100644 --- a/src/lib/handlers/add.js +++ b/src/lib/handlers/add.js @@ -1,6 +1,6 @@ import { logger } from '@libp2p/logger' -const log = logger('voyager:orbiter:add') +const log = logger('voyager:add') const waitForReplication = (db) => { return new Promise((resolve, reject) => { diff --git a/src/lib/handlers/remove.js b/src/lib/handlers/remove.js index b658af9..faf85c9 100644 --- a/src/lib/handlers/remove.js +++ b/src/lib/handlers/remove.js @@ -1,6 +1,6 @@ import { logger } from '@libp2p/logger' -const log = logger('voyager:orbiter:remove') +const log = logger('voyager:remove') export default async ({ orbitdb, databases, id, addresses }) => { for (const address of addresses) { diff --git a/src/lib/orbiter.js b/src/lib/host.js similarity index 91% rename from src/lib/orbiter.js rename to src/lib/host.js index 1d0142a..0dfc855 100644 --- a/src/lib/orbiter.js +++ b/src/lib/host.js @@ -6,13 +6,13 @@ import { handleRequest } from './handle-request.js' import Authorization, { Access } from './authorization.js' export default async ({ orbitdb, defaultAccess, verbose } = {}) => { - const log = logger('voyager:orbiter') + const log = logger('voyager:host') if (verbose > 0) { - enable('voyager:orbiter' + (verbose > 1 ? '*' : ':error')) + enable('voyager:host' + (verbose > 1 ? '*' : ':error')) } - log('start orbiter') + log('start voyager') defaultAccess = defaultAccess || Access.DENY diff --git a/src/lib/lander.js b/src/lib/voyager.js similarity index 77% rename from src/lib/lander.js rename to src/lib/voyager.js index c569d68..19dd57d 100644 --- a/src/lib/lander.js +++ b/src/lib/voyager.js @@ -9,7 +9,7 @@ const getSubarray = (e) => e.subarray() const getType = (e) => e.type const isOk = (e) => e === Responses.OK -export default async ({ orbitdb, orbiterAddressOrId }) => { +export default async ({ orbitdb, address }) => { const request = async (type, addresses) => { return await RequestMessage(type, addresses, orbitdb.identity) } @@ -22,14 +22,14 @@ export default async ({ orbitdb, orbiterAddressOrId }) => { const add = async (addresses) => { const addDBs = () => [request(Requests.ADD, toArray(addresses))] - const stream = await orbitdb.ipfs.libp2p.dialProtocol(orbiterAddressOrId, voyagerProtocol, { runOnLimitedConnection: true }) + const stream = await orbitdb.ipfs.libp2p.dialProtocol(address, voyagerProtocol, { runOnLimitedConnection: true }) const added = await pipe(addDBs, stream, parseResponse) return added } const remove = async (addresses) => { const removeDBs = () => [request(Requests.REMOVE, toArray(addresses))] - const stream = await orbitdb.ipfs.libp2p.dialProtocol(orbiterAddressOrId, voyagerProtocol, { runOnLimitedConnection: true }) + const stream = await orbitdb.ipfs.libp2p.dialProtocol(address, voyagerProtocol, { runOnLimitedConnection: true }) const removed = await pipe(removeDBs, stream, parseResponse) return removed } diff --git a/src/rpc/handle-command.js b/src/rpc/handle-command.js index bdff626..684e0e9 100644 --- a/src/rpc/handle-command.js +++ b/src/rpc/handle-command.js @@ -6,11 +6,11 @@ import handleIdRequest from './handlers/id.js' import handleAddressRequest from './handlers/address.js' import { ResponseMessage, parseMessage, Responses } from '../lib/messages/index.js' -export const handleCommand = (rpcConfig, orbiter) => source => { +export const handleCommand = (rpcConfig, host) => source => { return (async function * () { for await (const chunk of source) { const { type, signature, id, addresses } = parseMessage(chunk.subarray()) - const { orbitdb, auth, log } = orbiter + const { orbitdb, auth, log } = host log('handle command', type, signature, id, addresses) diff --git a/src/utils/id.js b/src/utils/id.js index c5c6893..6309328 100644 --- a/src/utils/id.js +++ b/src/utils/id.js @@ -1,7 +1,7 @@ import { join } from 'path' export const app = 'voyager' -export const orbiter = 'orbiter' +export const host = 'host' export const rpc = 'rpc' export const appPath = (rootDir) => { @@ -9,9 +9,9 @@ export const appPath = (rootDir) => { return join(rootDir, app) } -export const orbiterPath = (rootDir) => { +export const hostPath = (rootDir) => { rootDir = rootDir || '.' - return join(appPath(rootDir), orbiter) + return join(appPath(rootDir), host) } export const rpcPath = (rootDir) => { diff --git a/test/add.test.js b/test/add.test.js index 3586973..d90cb32 100644 --- a/test/add.test.js +++ b/test/add.test.js @@ -1,84 +1,84 @@ import { strictEqual } from 'assert' import { rimraf } from 'rimraf' -import { launchLander } from './utils/launch-lander.js' -import { launchOrbiter } from './utils/launch-orbiter.js' +import { Voyager } from './utils/launch-voyager-remote.js' +import { launchVoyagerHost } from './utils/launch-voyager-host.js' import { createAndAddDatabases } from './utils/create-and-add-databases.js' describe('Add', function () { this.timeout(10000) - let orbiter + let host beforeEach(async function () { - orbiter = await launchOrbiter() + host = await launchVoyagerHost() }) afterEach(async function () { - await orbiter.shutdown() - await rimraf('./orbiter') + await host.shutdown() + await rimraf('./host') }) describe('Single Transient Peer', function () { - let lander + let voyager beforeEach(async function () { - lander = await launchLander({ orbiterAddress: orbiter.orbitdb.ipfs.libp2p.getMultiaddrs().pop() }) - await orbiter.auth.add(lander.orbitdb.identity.id) + voyager = await Voyager({ address: host.orbitdb.ipfs.libp2p.getMultiaddrs().pop() }) + await host.auth.add(voyager.orbitdb.identity.id) }) afterEach(async function () { - await lander.shutdown() - await rimraf('./lander') + await voyager.shutdown() + await rimraf('./voyager') }) it('adds a database', async function () { - const { added, addresses } = await createAndAddDatabases(1, lander) + const { added, addresses } = await createAndAddDatabases(1, voyager) strictEqual(added, true) - strictEqual((await orbiter.databases.all()).pop().key, addresses.pop()) + strictEqual((await host.databases.all()).pop().key, addresses.pop()) }) it('adds multiple databases', async function () { - const { added, addresses } = await createAndAddDatabases(2, lander) + const { added, addresses } = await createAndAddDatabases(2, voyager) strictEqual(added, true) - strictEqual((await orbiter.databases.all())[0].key, addresses[0]) - strictEqual((await orbiter.databases.all())[1].key, addresses[1]) + strictEqual((await host.databases.all())[0].key, addresses[0]) + strictEqual((await host.databases.all())[1].key, addresses[1]) }) it('tries to add a database when not authorized', async function () { - await orbiter.auth.del(lander.orbitdb.identity.id) - const db = await lander.orbitdb.open('db') - const added = await lander.add(db.address) + await host.auth.del(voyager.orbitdb.identity.id) + const db = await voyager.orbitdb.open('db') + const added = await voyager.add(db.address) strictEqual(added, false) }) }) describe('Multiple Transient Peers', function () { - let lander1, lander2 + let voyager1, voyager2 beforeEach(async function () { - lander1 = await launchLander({ orbiterAddress: orbiter.orbitdb.ipfs.libp2p.getMultiaddrs().pop(), directory: './lander1' }) - await orbiter.auth.add(lander1.orbitdb.identity.id) + voyager1 = await Voyager({ address: host.orbitdb.ipfs.libp2p.getMultiaddrs().pop(), directory: './voyager1' }) + await host.auth.add(voyager1.orbitdb.identity.id) - lander2 = await launchLander({ orbiterAddress: orbiter.orbitdb.ipfs.libp2p.getMultiaddrs().pop(), directory: './lander2' }) - await orbiter.auth.add(lander2.orbitdb.identity.id) + voyager2 = await Voyager({ address: host.orbitdb.ipfs.libp2p.getMultiaddrs().pop(), directory: './voyager2' }) + await host.auth.add(voyager2.orbitdb.identity.id) }) afterEach(async function () { - await lander1.shutdown() - await rimraf('./lander1') - await lander2.shutdown() - await rimraf('./lander2') + await voyager1.shutdown() + await rimraf('./voyager1') + await voyager2.shutdown() + await rimraf('./voyager2') }) - it('adds a databases to voyager', async function () { - const { addresses: addresses1 } = await createAndAddDatabases(1, lander1) - const { addresses: addresses2 } = await createAndAddDatabases(1, lander2) + it('adds a databases to Voyager', async function () { + const { addresses: addresses1 } = await createAndAddDatabases(1, voyager1) + const { addresses: addresses2 } = await createAndAddDatabases(1, voyager2) - strictEqual((await orbiter.databases.all())[0].key, addresses1.pop()) - strictEqual((await orbiter.databases.all())[1].key, addresses2.pop()) + strictEqual((await host.databases.all())[0].key, addresses1.pop()) + strictEqual((await host.databases.all())[1].key, addresses2.pop()) }) }) }) diff --git a/test/authorization.test.js b/test/authorization.test.js index 0111d02..ae50cd7 100644 --- a/test/authorization.test.js +++ b/test/authorization.test.js @@ -1,40 +1,40 @@ import { strictEqual } from 'assert' import { Access } from '../src/lib/authorization.js' import { rimraf } from 'rimraf' -import { launchOrbiter } from './utils/launch-orbiter.js' +import { launchVoyagerHost } from './utils/launch-voyager-host.js' describe('Authorization', function () { - let orbiter + let host before(async function () { - orbiter = await launchOrbiter() + host = await launchVoyagerHost() }) after(async function () { - await orbiter.shutdown() - await rimraf('./orbiter') + await host.shutdown() + await rimraf('./host') }) it('defaults access to deny all', function () { - strictEqual(orbiter.auth.defaultAccess, Access.DENY) + strictEqual(host.auth.defaultAccess, Access.DENY) }) it('sets default access as allow all', function () { - orbiter.auth.defaultAccess = Access.ALLOW - strictEqual(orbiter.auth.defaultAccess, Access.ALLOW) + host.auth.defaultAccess = Access.ALLOW + strictEqual(host.auth.defaultAccess, Access.ALLOW) }) it('adds an authorized user', async function () { const id = '037ba2545db2e2ec0ba17fc9b35fbbf6bc09db82c9ab324521e62693e8aa96ceb4' - await orbiter.auth.add(id) + await host.auth.add(id) - strictEqual(await orbiter.auth.hasAccess(id), true) + strictEqual(await host.auth.hasAccess(id), true) }) it('removes an authorized user', async function () { const id = '037ba2545db2e2ec0ba17fc9b35fbbf6bc09db82c9ab324521e62693e8aa96ceb4' - await orbiter.auth.add(id) - await orbiter.auth.del(id) - strictEqual(await orbiter.auth.hasAccess(id), false) + await host.auth.add(id) + await host.auth.del(id) + strictEqual(await host.auth.hasAccess(id), false) }) }) diff --git a/test/commands/daemon.test.js b/test/commands/daemon.test.js index 0822d4c..5e90f39 100644 --- a/test/commands/daemon.test.js +++ b/test/commands/daemon.test.js @@ -1,4 +1,4 @@ -import { appPath, orbiterPath } from '../../src/utils/id.js' +import { appPath, hostPath } from '../../src/utils/id.js' import { spawn } from 'node:child_process' import { strictEqual } from 'assert' import { existsSync } from 'fs' @@ -14,7 +14,7 @@ describe('Commands - daemon', function () { await waitForDaemonStarted(daemon) strictEqual(existsSync(appPath()), true) - strictEqual(existsSync(orbiterPath()), true) + strictEqual(existsSync(hostPath()), true) daemon.kill() await rimraf('voyager') @@ -30,7 +30,7 @@ describe('Commands - daemon', function () { strictEqual(existsSync(directory), true) strictEqual(existsSync(join(directory, appPath())), true) - strictEqual(existsSync(join(directory, orbiterPath())), true) + strictEqual(existsSync(join(directory, hostPath())), true) daemon.kill() await rimraf(directory) @@ -46,7 +46,7 @@ describe('Commands - daemon', function () { strictEqual(existsSync(directory), true) strictEqual(existsSync(join(directory, appPath())), true) - strictEqual(existsSync(join(directory, orbiterPath())), true) + strictEqual(existsSync(join(directory, hostPath())), true) daemon.kill() await rimraf(directory) diff --git a/test/config-manager.test.js b/test/config-manager.test.js index 526b258..e2b8054 100644 --- a/test/config-manager.test.js +++ b/test/config-manager.test.js @@ -4,7 +4,7 @@ import { rimraf } from 'rimraf' import { join } from 'path' describe('Config Manager', function () { - const path = join('.', 'voyager', 'orbiter') + const path = join('.', 'voyager', 'host') afterEach(async function () { await rimraf('./voyager') diff --git a/test/e2e-browser.test.js b/test/e2e-browser.test.js index 9a3dbf0..862735a 100644 --- a/test/e2e-browser.test.js +++ b/test/e2e-browser.test.js @@ -1,55 +1,55 @@ import { multiaddr } from '@multiformats/multiaddr' import { strictEqual, deepStrictEqual } from 'assert' import { rimraf } from 'rimraf' -import { launchLander } from './utils/launch-lander.js' -import { launchOrbiter } from './utils/launch-orbiter.js' +import { Voyager } from './utils/launch-voyager-remote.js' +import { launchVoyagerHost } from './utils/launch-voyager-host.js' import waitFor from './utils/wait-for.js' import connectPeers from './utils/connect-nodes-via-relay.js' const isBrowser = () => typeof window !== 'undefined' describe('End-to-End Browser Tests', function () { - describe('Orbiter in Nodejs', function () { + describe('Voyager in Nodejs', function () { this.timeout(10000) - const orbiterAddress1 = isBrowser() + const address1 = isBrowser() ? multiaddr('/ip4/127.0.0.1/tcp/55441/ws/p2p/16Uiu2HAmBzKcgCfpJ4j4wJSLkKLbCVvnNBWPnhexrnJWJf1fDu5y') : multiaddr('/ip4/127.0.0.1/tcp/54321/p2p/16Uiu2HAmBzKcgCfpJ4j4wJSLkKLbCVvnNBWPnhexrnJWJf1fDu5y') - const orbiterAddress2 = isBrowser() + const address2 = isBrowser() ? multiaddr('/ip4/127.0.0.1/tcp/55442/ws/p2p/16Uiu2HAmATMovCwY46yyJib7bGZF2f2XLRar7d7R3NJCSJtuyQLt') : multiaddr('/ip4/127.0.0.1/tcp/54322/p2p/16Uiu2HAmATMovCwY46yyJib7bGZF2f2XLRar7d7R3NJCSJtuyQLt') - let lander1 - let lander2 - let lander3 + let voyager1 + let voyager2 + let voyager3 beforeEach(async function () { - lander1 = await launchLander({ orbiterAddress: orbiterAddress1, directory: 'lander1' }) - lander2 = await launchLander({ orbiterAddress: orbiterAddress1, directory: 'lander2' }) - lander3 = await launchLander({ orbiterAddress: orbiterAddress2, directory: 'lander3' }) + voyager1 = await Voyager({ address: address1, directory: 'voyager1' }) + voyager2 = await Voyager({ address: address1, directory: 'voyager2' }) + voyager3 = await Voyager({ address: address2, directory: 'voyager3' }) }) afterEach(async function () { - if (lander1) { - await lander1.shutdown() + if (voyager1) { + await voyager1.shutdown() } - if (lander2) { - await lander2.shutdown() + if (voyager2) { + await voyager2.shutdown() } - if (lander3) { - await lander3.shutdown() + if (voyager3) { + await voyager3.shutdown() } - await rimraf('./lander1') - await rimraf('./lander2') - await rimraf('./lander3') + await rimraf('./voyager1') + await rimraf('./voyager2') + await rimraf('./voyager3') }) - it('add and replicate a database - lander1->orbiter1->lander2', async function () { + it('add and replicate a database - app1->voyager1->app2', async function () { const entryAmount = 100 let replicated = false - const db1 = await lander1.orbitdb.open('my-db') + const db1 = await voyager1.orbitdb.open('my-db') for (let i = 0; i < entryAmount; i++) { await db1.add('hello world ' + i) @@ -58,16 +58,16 @@ describe('End-to-End Browser Tests', function () { const expected = await db1.all() console.time('add') - await lander1.add(db1.address) + await voyager1.add(db1.address) console.timeEnd('add') - await lander1.shutdown() + await voyager1.shutdown() console.time('add2') - await lander2.add(db1.address) + await voyager2.add(db1.address) console.timeEnd('add2') console.time('replicate') - const db2 = await lander2.orbitdb.open(db1.address) + const db2 = await voyager2.orbitdb.open(db1.address) const onConnected = (peerId, heads) => { replicated = true @@ -85,11 +85,11 @@ describe('End-to-End Browser Tests', function () { deepStrictEqual(expected, res) }) - it('add and replicate a database - lander1->orbiter1->orbiter2->lander3', async function () { + it('add and replicate a database - app1->voyager1->voyager2->app3', async function () { const entryAmount = 100 let replicated = false - const db1 = await lander1.orbitdb.open('my-db2') + const db1 = await voyager1.orbitdb.open('my-db2') for (let i = 0; i < entryAmount; i++) { await db1.add('hello world ' + i) @@ -98,16 +98,16 @@ describe('End-to-End Browser Tests', function () { const expected = await db1.all() console.time('add') - await lander1.add(db1.address) + await voyager1.add(db1.address) console.timeEnd('add') - await lander1.shutdown() + await voyager1.shutdown() console.time('add2') - await lander3.add(db1.address) + await voyager3.add(db1.address) console.timeEnd('add2') console.time('replicate') - const db2 = await lander3.orbitdb.open(db1.address) + const db2 = await voyager3.orbitdb.open(db1.address) const onConnected = (peerId, heads) => { replicated = true } @@ -125,45 +125,45 @@ describe('End-to-End Browser Tests', function () { }) }) - describe('Orbiter in the browser', function () { + describe('Voyager in browsers', function () { this.timeout(10000) - const orbiterAddress1 = isBrowser() + const address1 = isBrowser() ? multiaddr('/ip4/127.0.0.1/tcp/55441/ws/p2p/16Uiu2HAmBzKcgCfpJ4j4wJSLkKLbCVvnNBWPnhexrnJWJf1fDu5y') : multiaddr('/ip4/127.0.0.1/tcp/54321/p2p/16Uiu2HAmBzKcgCfpJ4j4wJSLkKLbCVvnNBWPnhexrnJWJf1fDu5y') - let orbiter - let lander1 - let lander2 + let host + let voyager1 + let voyager2 beforeEach(async function () { - orbiter = await launchOrbiter({ directory: 'orbiter3' }) + host = await launchVoyagerHost({ directory: 'host3' }) - await connectPeers(orbiter.orbitdb.ipfs, orbiterAddress1) + await connectPeers(host.orbitdb.ipfs, address1) - lander1 = await launchLander({ orbiterAddress: orbiterAddress1, directory: 'lander4' }) + voyager1 = await Voyager({ address: address1, directory: 'voyager4' }) }) afterEach(async function () { - if (lander1) { - await lander1.shutdown() + if (voyager1) { + await voyager1.shutdown() } - if (lander2) { - await lander2.shutdown() + if (voyager2) { + await voyager2.shutdown() } - if (orbiter) { - await orbiter.shutdown() + if (host) { + await host.shutdown() } - await rimraf('./lander4') - await rimraf('./lander5') - await rimraf('./orbiter3') + await rimraf('./voyager4') + await rimraf('./voyager5') + await rimraf('./host3') }) - it('add and replicate a database - lander1->orbiter1(nodejs)->orbiter2(browser)->lander3', async function () { + it('add and replicate a database - app1->voyager1(nodejs)->voyager2(browser)->app3', async function () { const entryAmount = 100 let replicated = false - const db1 = await lander1.orbitdb.open('my-db3') + const db1 = await voyager1.orbitdb.open('my-db3') for (let i = 0; i < entryAmount; i++) { await db1.add('hello world ' + i) @@ -172,21 +172,21 @@ describe('End-to-End Browser Tests', function () { const expected = await db1.all() console.time('add') - await lander1.add(db1.address) + await voyager1.add(db1.address) console.timeEnd('add') - await lander1.shutdown() + await voyager1.shutdown() - lander2 = await launchLander({ orbiterAddress: orbiter.orbitdb.ipfs.libp2p.getMultiaddrs().shift(), directory: 'lander5' }) + voyager2 = await Voyager({ address: host.orbitdb.ipfs.libp2p.getMultiaddrs().shift(), directory: 'voyager5' }) - await orbiter.auth.add(lander2.orbitdb.identity.id) + await host.auth.add(voyager2.orbitdb.identity.id) console.time('add2') - await lander2.add(db1.address) + await voyager2.add(db1.address) console.timeEnd('add2') console.time('replicate') - const db2 = await lander2.orbitdb.open(db1.address) + const db2 = await voyager2.orbitdb.open(db1.address) const onConnected = (peerId, heads) => { replicated = true diff --git a/test/host.test.js b/test/host.test.js new file mode 100644 index 0000000..e541af3 --- /dev/null +++ b/test/host.test.js @@ -0,0 +1,38 @@ +import { strictEqual } from 'assert' +import { rimraf } from 'rimraf' +import { Voyager } from './utils/launch-voyager-remote.js' +import { launchVoyagerHost } from './utils/launch-voyager-host.js' +import { createAndAddDatabases } from './utils/create-and-add-databases.js' + +describe('Voyager Host', function () { + this.timeout(10000) + + let host + let voyager + + beforeEach(async function () { + await rimraf('./voyager') + await rimraf('./host') + host = await launchVoyagerHost() + voyager = await Voyager({ address: host.orbitdb.ipfs.libp2p.getMultiaddrs().pop() }) + await host.auth.add(voyager.orbitdb.identity.id) + }) + + afterEach(async function () { + await voyager.shutdown() + await rimraf('./voyager') + + await host.shutdown() + await rimraf('./host') + }) + + it('loads an added database', async function () { + const { addresses } = await createAndAddDatabases(1, voyager) + + await host.shutdown() + + host = await launchVoyagerHost() + + strictEqual((await host.databases.all()).pop().key, addresses.pop()) + }) +}) diff --git a/test/messages.test.js b/test/messages.test.js index 209208b..ede0847 100644 --- a/test/messages.test.js +++ b/test/messages.test.js @@ -1,8 +1,8 @@ import { deepStrictEqual } from 'assert' import { Requests, Responses, RequestMessage, parseMessage } from '../src/lib/messages/index.js' import { handleRequest } from '../src/lib/handle-request.js' -import { launchLander } from './utils/launch-lander.js' -import { launchOrbiter } from './utils/launch-orbiter.js' +import { Voyager } from './utils/launch-voyager-remote.js' +import { launchVoyagerHost } from './utils/launch-voyager-host.js' import { rimraf } from 'rimraf' import { pipe } from 'it-pipe' import { Identities } from '@orbitdb/core' @@ -10,33 +10,33 @@ import { Identities } from '@orbitdb/core' describe('Messages', function () { this.timeout(10000) - let orbiter - let lander + let host + let voyager let db const addDBs = ({ type, signer } = {}) => source => { return (async function * () { const addresses = [db.address] - const message = await RequestMessage(type || Requests.ADD, addresses, lander.orbitdb.identity, signer) + const message = await RequestMessage(type || Requests.ADD, addresses, voyager.orbitdb.identity, signer) yield message })() } beforeEach(async function () { - orbiter = await launchOrbiter() - lander = await launchLander({ orbiterAddress: orbiter.orbitdb.ipfs.libp2p.getMultiaddrs().pop() }) - db = await lander.orbitdb.open('db') + host = await launchVoyagerHost() + voyager = await Voyager({ address: host.orbitdb.ipfs.libp2p.getMultiaddrs().pop() }) + db = await voyager.orbitdb.open('db') }) afterEach(async function () { - await orbiter.shutdown() - await lander.shutdown() - await rimraf('./lander') - await rimraf('./orbiter') + await host.shutdown() + await voyager.shutdown() + await rimraf('./voyager') + await rimraf('./host') }) it('adds a database with OK response', async function () { - await orbiter.auth.add(lander.orbitdb.identity.id) + await host.auth.add(voyager.orbitdb.identity.id) const sink = async source => { for await (const chunk of source) { @@ -45,7 +45,7 @@ describe('Messages', function () { } } - await pipe(addDBs(), handleRequest(orbiter), sink) + await pipe(addDBs(), handleRequest(host), sink) }) it('adds a database with E_NOT_AUTHORIZED response', async function () { @@ -56,14 +56,14 @@ describe('Messages', function () { } } - await pipe(addDBs(), handleRequest(orbiter), sink) + await pipe(addDBs(), handleRequest(host), sink) }) it('adds a database with E_INVALID_SIGNATURE response', async function () { - await orbiter.auth.add(lander.orbitdb.identity.id) + await host.auth.add(voyager.orbitdb.identity.id) - const identities = await Identities({ path: './lander/identities', ipfs: lander.ipfs }) - const invalidIdentity = await identities.createIdentity({ id: 'lander2' }) + const identities = await Identities({ path: './voyager/identities', ipfs: voyager.ipfs }) + const invalidIdentity = await identities.createIdentity({ id: 'voyager' }) const createInvalidSignature = async addresses => invalidIdentity.sign(invalidIdentity, addresses) const sink = async source => { @@ -73,11 +73,11 @@ describe('Messages', function () { } } - await pipe(addDBs({ signer: { sign: createInvalidSignature } }), handleRequest(orbiter), sink) + await pipe(addDBs({ signer: { sign: createInvalidSignature } }), handleRequest(host), sink) }) it('tries to add a database with non-existent message', async function () { - await orbiter.auth.add(lander.orbitdb.identity.id) + await host.auth.add(voyager.orbitdb.identity.id) const sink = async source => { for await (const chunk of source) { @@ -86,6 +86,6 @@ describe('Messages', function () { } } - await pipe(addDBs({ type: 'UNKNOWN' }), handleRequest(orbiter), sink) + await pipe(addDBs({ type: 'UNKNOWN' }), handleRequest(host), sink) }) }) diff --git a/test/orbiter.test.js b/test/orbiter.test.js deleted file mode 100644 index 54e03d9..0000000 --- a/test/orbiter.test.js +++ /dev/null @@ -1,37 +0,0 @@ -import { strictEqual } from 'assert' -import { rimraf } from 'rimraf' -import { launchLander } from './utils/launch-lander.js' -import { launchOrbiter } from './utils/launch-orbiter.js' -import { createAndAddDatabases } from './utils/create-and-add-databases.js' - -describe('Orbiter', function () { - this.timeout(10000) - - let orbiter, lander - - beforeEach(async function () { - await rimraf('./lander') - await rimraf('./orbiter') - orbiter = await launchOrbiter() - lander = await launchLander({ orbiterAddress: orbiter.orbitdb.ipfs.libp2p.getMultiaddrs().pop() }) - await orbiter.auth.add(lander.orbitdb.identity.id) - }) - - afterEach(async function () { - await lander.shutdown() - await rimraf('./lander') - - await orbiter.shutdown() - await rimraf('./orbiter') - }) - - it('loads an added database', async function () { - const { addresses } = await createAndAddDatabases(1, lander) - - await orbiter.shutdown() - - orbiter = await launchOrbiter() - - strictEqual((await orbiter.databases.all()).pop().key, addresses.pop()) - }) -}) diff --git a/test/remove.test.js b/test/remove.test.js index 57b1815..61ae463 100644 --- a/test/remove.test.js +++ b/test/remove.test.js @@ -1,62 +1,62 @@ import { strictEqual } from 'assert' import { rimraf } from 'rimraf' -import { launchLander } from './utils/launch-lander.js' -import { launchOrbiter } from './utils/launch-orbiter.js' +import { Voyager } from './utils/launch-voyager-remote.js' +import { launchVoyagerHost } from './utils/launch-voyager-host.js' import { createAndAddDatabases } from './utils/create-and-add-databases.js' describe('Remove', function () { this.timeout(10000) - let orbiter + let host beforeEach(async function () { - orbiter = await launchOrbiter() + host = await launchVoyagerHost() }) afterEach(async function () { - await orbiter.shutdown() - await rimraf('./orbiter') + await host.shutdown() + await rimraf('./host') }) describe('Single Transient Peer', function () { - let lander + let app beforeEach(async function () { - lander = await launchLander({ orbiterAddress: orbiter.orbitdb.ipfs.libp2p.getMultiaddrs().pop() }) - await orbiter.auth.add(lander.orbitdb.identity.id) + app = await Voyager({ address: host.orbitdb.ipfs.libp2p.getMultiaddrs().pop() }) + await host.auth.add(app.orbitdb.identity.id) }) afterEach(async function () { - await lander.shutdown() - await rimraf('./lander') + await app.shutdown() + await rimraf('./app') }) it('removes a database', async function () { - const { addresses } = await createAndAddDatabases(1, lander) + const { addresses } = await createAndAddDatabases(1, app) - const removed = await lander.remove(addresses) + const removed = await app.remove(addresses) strictEqual(removed, true) - strictEqual((await orbiter.databases.all()).length, 0) + strictEqual((await host.databases.all()).length, 0) }) it('removes multiple databases', async function () { - const { addresses } = await createAndAddDatabases(2, lander) + const { addresses } = await createAndAddDatabases(2, app) - const removed = await lander.remove(addresses) + const removed = await app.remove(addresses) strictEqual(removed, true) - strictEqual((await orbiter.databases.all()).length, 0) + strictEqual((await host.databases.all()).length, 0) }) it('removes a database when multiple databases have been added', async function () { - const { addresses } = await createAndAddDatabases(2, lander) + const { addresses } = await createAndAddDatabases(2, app) - const removed = await lander.remove(addresses.slice(0, 1)) + const removed = await app.remove(addresses.slice(0, 1)) strictEqual(removed, true) - strictEqual((await orbiter.databases.all()).length, 1) - strictEqual((await orbiter.databases.all()).pop().key, addresses[1]) + strictEqual((await host.databases.all()).length, 1) + strictEqual((await host.databases.all()).pop().key, addresses[1]) }) }) }) diff --git a/test/stress-test.js b/test/stress-test.js deleted file mode 100644 index 193c416..0000000 --- a/test/stress-test.js +++ /dev/null @@ -1,79 +0,0 @@ -import { strictEqual, deepStrictEqual } from 'assert' -import { rimraf } from 'rimraf' -import { launchLander } from './utils/launch-lander.js' -import { launchOrbiter } from './utils/launch-orbiter.js' -import waitFor from './utils/wait-for.js' - -describe('Stress test', function () { - this.timeout(10000000) - - let orbiter - let lander1 - let lander2 - - before(async function () { - orbiter = await launchOrbiter({ directory: 'orbiter3' }) - }) - - after(async function () { - if (orbiter) { - await orbiter.shutdown() - } - await rimraf('./orbiter3') - }) - - it('add and replicate a database - lander1->orbiter1->lander2', async function () { - const rounds = 50 - const entryAmount = 100 - const addr = orbiter.orbitdb.ipfs.libp2p.getMultiaddrs().shift() - - for (let k = 1; k <= rounds; k++) { - let replicated = false - - lander1 = await launchLander({ orbiterAddress: addr, directory: 'lander4' }) - await orbiter.auth.add(lander1.orbitdb.identity.id) - - const db1 = await lander1.orbitdb.open('my-db3') - - for (let i = 0; i < entryAmount; i++) { - await db1.add('hello world ' + i) - } - - const expected = await db1.all() - - await lander1.add(db1.address) - - await lander1.shutdown() - - lander2 = await launchLander({ orbiterAddress: addr, directory: 'lander5' }) - await orbiter.auth.add(lander2.orbitdb.identity.id) - - console.time('Round ' + k + '/' + rounds) - const db2 = await lander2.orbitdb.open(db1.address) - - const onConnected = (peerId, heads) => { - replicated = true - } - - db2.events.on('join', onConnected) - - await waitFor(() => replicated, () => true, 0) - console.timeEnd('Round ' + k + '/' + rounds) - - const res = await db2.all() - - strictEqual(expected.length, entryAmount) - strictEqual(res.length, entryAmount) - deepStrictEqual(expected, res) - - if (lander1) { - await lander1.shutdown() - } - if (lander2) { - await lander2.shutdown() - } - await rimraf('./lander4') - await rimraf('./lander5') - } - }) -}) diff --git a/test/stress.test.js b/test/stress.test.js new file mode 100644 index 0000000..8e8846f --- /dev/null +++ b/test/stress.test.js @@ -0,0 +1,79 @@ +import { strictEqual, deepStrictEqual } from 'assert' +import { rimraf } from 'rimraf' +import { Voyager } from './utils/launch-voyager-remote.js' +import { launchVoyagerHost } from './utils/launch-voyager-host.js' +import waitFor from './utils/wait-for.js' + +describe('Stress test', function () { + this.timeout(10000000) + + let host + let voyager1 + let voyager2 + + before(async function () { + host = await launchVoyagerHost({ directory: 'host' }) + }) + + after(async function () { + if (host) { + await host.shutdown() + } + await rimraf('./host') + }) + + it('add and replicate a database - app1->voyager1->app2', async function () { + const rounds = 50 + const entryAmount = 100 + const addr = host.orbitdb.ipfs.libp2p.getMultiaddrs().shift() + + for (let k = 1; k <= rounds; k++) { + let replicated = false + + voyager1 = await Voyager({ address: addr, directory: 'voyager4' }) + await host.auth.add(voyager1.orbitdb.identity.id) + + const db1 = await voyager1.orbitdb.open('my-db3') + + for (let i = 0; i < entryAmount; i++) { + await db1.add('hello world ' + i) + } + + const expected = await db1.all() + + await voyager1.add(db1.address) + + await voyager1.shutdown() + + voyager2 = await Voyager({ address: addr, directory: 'voyager5' }) + await host.auth.add(voyager2.orbitdb.identity.id) + + console.time('Round ' + k + '/' + rounds) + const db2 = await voyager2.orbitdb.open(db1.address) + + const onConnected = (peerId, heads) => { + replicated = true + } + + db2.events.on('join', onConnected) + + await waitFor(() => replicated, () => true, 0) + console.timeEnd('Round ' + k + '/' + rounds) + + const res = await db2.all() + + strictEqual(expected.length, entryAmount) + strictEqual(res.length, entryAmount) + deepStrictEqual(expected, res) + + if (voyager1) { + await voyager1.shutdown() + } + if (voyager2) { + await voyager2.shutdown() + } + await rimraf('./voyager4') + await rimraf('./voyager5') + } + }) +}) diff --git a/test/utils/create-and-add-databases.js b/test/utils/create-and-add-databases.js index 72354e1..c6cf294 100644 --- a/test/utils/create-and-add-databases.js +++ b/test/utils/create-and-add-databases.js @@ -1,12 +1,12 @@ -export const createAndAddDatabases = async (howMany, lander) => { +export const createAndAddDatabases = async (howMany, voyager) => { const addresses = [] for (let i = 1; i <= howMany; i++) { - const db = await lander.orbitdb.open(`db${i}`) + const db = await voyager.orbitdb.open(`db${i}`) addresses.push(db.address) } - const added = await lander.add(addresses) + const added = await voyager.add(addresses) return { added, addresses } } diff --git a/test/utils/launch-orbiter.js b/test/utils/launch-voyager-host.js similarity index 71% rename from test/utils/launch-orbiter.js rename to test/utils/launch-voyager-host.js index f2092f0..c73bb2d 100644 --- a/test/utils/launch-orbiter.js +++ b/test/utils/launch-voyager-host.js @@ -6,10 +6,10 @@ import { createLibp2p } from 'libp2p' import { bitswap } from '@helia/block-brokers' import { multiaddr } from '@multiformats/multiaddr' import { createOrbitDB } from '@orbitdb/core' -import Orbiter from '../../src/lib/orbiter.js' -import { orbiter as orbiterId } from '../../src/utils/id.js' +import Host from '../../src/lib/host.js' +import { host as hostId } from '../../src/utils/id.js' -import Libp2pOptions from './test-config/orbiter-libp2p-config.js' +import Libp2pOptions from './test-config/voyager-host-libp2p-config.js' const isBrowser = () => typeof window !== 'undefined' @@ -24,32 +24,31 @@ const heliaOptions = { ] } -export const launchOrbiter = async ({ directory } = {}) => { +export const launchVoyagerHost = async ({ directory } = {}) => { const options = Libp2pOptions - directory = directory || './orbiter' - const id = orbiterId + directory = directory || './host' const blockstore = new LevelBlockstore(join(directory, '/', 'ipfs', '/', 'blocks')) const datastore = new LevelDatastore(join(directory, '/', 'ipfs', '/', 'data')) const libp2p = await createLibp2p({ ...options }) const ipfs = await createHelia({ libp2p, ...heliaOptions, datastore, blockstore }) - const orbitdb = await createOrbitDB({ ipfs, directory, id }) - const orbiter = await Orbiter({ orbitdb }) + const orbitdb = await createOrbitDB({ ipfs, directory, id: hostId }) + const host = await Host({ orbitdb }) if (isBrowser()) { await ipfs.libp2p.dial(relayAddress) } // Helper function for tests - orbiter.shutdown = async () => { - await orbiter.stop() + host.shutdown = async () => { + await host.stop() await orbitdb.stop() await ipfs.stop() await datastore.close() await blockstore.close() } - return orbiter + return host } diff --git a/test/utils/launch-lander.js b/test/utils/launch-voyager-remote.js similarity index 59% rename from test/utils/launch-lander.js rename to test/utils/launch-voyager-remote.js index 22041cd..1a6b3a7 100644 --- a/test/utils/launch-lander.js +++ b/test/utils/launch-voyager-remote.js @@ -2,11 +2,11 @@ import { createHelia } from 'helia' import { createLibp2p } from 'libp2p' import { bitswap } from '@helia/block-brokers' import { createOrbitDB } from '@orbitdb/core' -import Lander from '../../src/lib/lander.js' +import Voyager_ from '../../src/lib/voyager.js' // import connectPeers from './connect-nodes.js' import connect from './connect-nodes-via-relay.js' -import Libp2pOptions from './test-config/lander-libp2p-config.js' +import Libp2pOptions from './test-config/voyager-app-libp2p-config.js' const heliaOptions = { blockBrokers: [ @@ -16,25 +16,25 @@ const heliaOptions = { ] } -export const launchLander = async ({ directory, orbiterAddress } = {}) => { +export const Voyager = async ({ address, directory } = {}) => { const options = Libp2pOptions const libp2p = await createLibp2p({ ...options }) const ipfs = await createHelia({ libp2p, ...heliaOptions }) - directory = directory || './lander' + directory = directory || './app' const orbitdb = await createOrbitDB({ ipfs, directory }) - // await connectPeers(ipfs, orbiterAddress) - await connect(ipfs, orbiterAddress) + // await connectPeers(ipfs, address) + await connect(ipfs, address) - const lander = await Lander({ orbitdb, orbiterAddressOrId: orbiterAddress }) + const voyager = await Voyager_({ orbitdb, address }) // Helper function for tests - lander.shutdown = async () => { + voyager.shutdown = async () => { await orbitdb.stop() await ipfs.stop() } - return lander + return voyager } diff --git a/test/utils/test-config-browser/lander-libp2p-config.js b/test/utils/test-config-browser/voyager-app-libp2p-config.js similarity index 100% rename from test/utils/test-config-browser/lander-libp2p-config.js rename to test/utils/test-config-browser/voyager-app-libp2p-config.js diff --git a/test/utils/test-config-browser/orbiter-libp2p-config.js b/test/utils/test-config-browser/voyager-host-libp2p-config.js similarity index 100% rename from test/utils/test-config-browser/orbiter-libp2p-config.js rename to test/utils/test-config-browser/voyager-host-libp2p-config.js diff --git a/test/utils/test-config/lander-libp2p-config.js b/test/utils/test-config/voyager-app-libp2p-config.js similarity index 100% rename from test/utils/test-config/lander-libp2p-config.js rename to test/utils/test-config/voyager-app-libp2p-config.js diff --git a/test/utils/test-config/orbiter-libp2p-config.js b/test/utils/test-config/voyager-host-libp2p-config.js similarity index 100% rename from test/utils/test-config/orbiter-libp2p-config.js rename to test/utils/test-config/voyager-host-libp2p-config.js