diff --git a/package.json b/package.json index 8a31e02..8b874bb 100644 --- a/package.json +++ b/package.json @@ -46,8 +46,8 @@ "prettier": "^2.6.2", "pretty-quick": "^3.1.3", "rimraf": "^4.4.0", - "secret-stack": "~7.1.1", - "secret-handshake-ext": "0.0.9", + "secret-stack": "~8.0.0", + "secret-handshake-ext": "0.0.11", "ssb-box": "^1.0.1", "typescript": "^5.1.3" }, diff --git a/test/account-sync.test.js b/test/account-sync.test.js index 06c9da7..b8ed967 100644 --- a/test/account-sync.test.js +++ b/test/account-sync.test.js @@ -14,8 +14,8 @@ function getAccount(iter) { } test('sync an account tangle', async (t) => { - const alice = createPeer({ name: 'alice', keypair: aliceKeypair }) - const bob = createPeer({ name: 'bob', keypair: bobKeys }) + const alice = createPeer({ name: 'alice', global: { keypair: aliceKeypair } }) + const bob = createPeer({ name: 'bob', global: { keypair: bobKeys } }) await alice.db.loaded() await bob.db.loaded() @@ -51,7 +51,6 @@ test('sync an account tangle', async (t) => { "bob doesn't have alice's account tangle" ) - // start() on purpose before connect, to test whether this also works bob.sync.start() const remoteAlice = await p(bob.connect)(alice.getAddress()) diff --git a/test/dict-sync.test.js b/test/dict-sync.test.js index b44c276..50377a2 100644 --- a/test/dict-sync.test.js +++ b/test/dict-sync.test.js @@ -17,7 +17,9 @@ test('sync goal=dict with ghostSpan=2', async (t) => { const SPAN = 5 const alice = createPeer({ name: 'alice', - keypair: aliceKeypair, + global: { + keypair: aliceKeypair, + }, dict: { ghostSpan: SPAN }, }) const bob = createPeer({ name: 'bob' }) @@ -132,11 +134,7 @@ test('sync goal=dict with ghostSpan=2', async (t) => { .map((msg) => msg.data?.update) .filter((x) => !!x) .map((x) => x.age ?? x.name ?? x.gender) - assert.deepEqual( - arr, - [25, 'ALICE', 'w'], - 'alice has age+name+gender dict' - ) + assert.deepEqual(arr, [25, 'ALICE', 'w'], 'alice has age+name+gender dict') } assert.deepEqual(alice.db.ghosts.get(moot.id), [rec2.id]) diff --git a/test/set-sync.test.js b/test/set-sync.test.js index 04e0406..bf06fef 100644 --- a/test/set-sync.test.js +++ b/test/set-sync.test.js @@ -25,7 +25,9 @@ test('sync goal=set with ghostSpan=2', async (t) => { const SPAN = 5 const alice = createPeer({ name: 'alice', - keypair: aliceKeypair, + global: { + keypair: aliceKeypair, + }, set: { ghostSpan: SPAN }, }) const bob = createPeer({ name: 'bob' }) diff --git a/test/util.js b/test/util.js index f98ee5f..3225112 100644 --- a/test/util.js +++ b/test/util.js @@ -1,20 +1,29 @@ -const os = require('node:os') -const path = require('node:path') +const OS = require('node:os') +const Path = require('node:path') const rimraf = require('rimraf') const caps = require('ppppp-caps') const Keypair = require('ppppp-keypair') -function createPeer(opts) { - if (opts.name) { - const tmp = os.tmpdir() - opts.db ??= {path: path.join(tmp, `ppppp-sync-${opts.name}-${Date.now()}`)} - opts.keypair ??= Keypair.generate('ed25519', opts.name) - opts.name = undefined +function createPeer(config) { + if (config.name) { + const name = config.name + const tmp = OS.tmpdir() + config.global ??= {} + config.global.path ??= Path.join(tmp, `ppppp-sync-${name}-${Date.now()}`) + config.global.keypair ??= Keypair.generate('ed25519', name) + delete config.name + } + if (!config.global) { + throw new Error('need config.global in createPeer()') + } + if (!config.global.path) { + throw new Error('need config.global.path in createPeer()') + } + if (!config.global.keypair) { + throw new Error('need config.global.keypair in createPeer()') } - if (!opts.db.path) throw new Error('need opts.db.path in createPeer()') - if (!opts.keypair) throw new Error('need opts.keypair in createPeer()') - rimraf.sync(opts.db.path) + rimraf.sync(config.global.path) return require('secret-stack/bare')() .use(require('secret-stack/plugins/net')) .use(require('secret-handshake-ext/secret-stack')) @@ -25,16 +34,19 @@ function createPeer(opts) { .use(require('ssb-box')) .use(require('../lib')) .call(null, { - caps, - connections: { - incoming: { - net: [{ scope: 'device', transform: 'shse', port: null }], - }, - outgoing: { - net: [{ transform: 'shse' }], + shse: { caps }, + ...config, + global: { + connections: { + incoming: { + net: [{ scope: 'device', transform: 'shse', port: null }], + }, + outgoing: { + net: [{ transform: 'shse' }], + }, }, + ...config.global, }, - ...opts, }) }