From d3664ff1c866e3542b0f0e97b993cd5111cbe290 Mon Sep 17 00:00:00 2001 From: Andre Staltz Date: Fri, 29 Dec 2023 12:39:03 +0200 Subject: [PATCH] update secret-stack to 8.0 --- package.json | 4 ++-- test/index.test.js | 37 +++++++++---------------------------- test/util.js | 44 ++++++++++++++++++++++++++++---------------- 3 files changed, 39 insertions(+), 46 deletions(-) diff --git a/package.json b/package.json index 68a5916..98e6690 100644 --- a/package.json +++ b/package.json @@ -33,8 +33,8 @@ "ppppp-caps": "github:staltz/ppppp-caps", "ppppp-keypair": "github:staltz/ppppp-keypair", "rimraf": "^4.4.0", - "secret-stack": "~7.1.1", - "secret-handshake-ext": "0.0.8", + "secret-stack": "~8.0.0", + "secret-handshake-ext": "0.0.10", "ssb-box": "^1.0.1", "typescript": "^5.1.3" }, diff --git a/test/index.test.js b/test/index.test.js index 6549483..58e3046 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -28,8 +28,10 @@ let peer let aliceID test('setup', async (t) => { peer = createPeer({ - keypair: aliceKeypair, - db: {path: DIR}, + global: { + keypair: aliceKeypair, + path: DIR, + }, dict: { ghostSpan: 40 }, }) @@ -51,19 +53,10 @@ test('Dict update() and get()', async (t) => { 'update .name' ) const UPDATE0_ID = getMsgID(peer, 0, 'dict_v1__profile') - assert.deepEqual( - peer.dict.read(aliceID, 'profile'), - { name: 'alice' }, - 'get' - ) - + assert.deepEqual(peer.dict.read(aliceID, 'profile'), { name: 'alice' }, 'get') const fieldRoots1 = peer.dict._getFieldRoots('profile') - assert.deepEqual( - fieldRoots1, - { name: [UPDATE0_ID] }, - 'fieldRoots' - ) + assert.deepEqual(fieldRoots1, { name: [UPDATE0_ID] }, 'fieldRoots') assert(await p(peer.dict.update)('profile', { age: 20 }), 'update .age') const UPDATE1_ID = getMsgID(peer, 1, 'dict_v1__profile') @@ -125,11 +118,7 @@ test('Dict squeeze', async (t) => { 'fieldRoots' ) - assert.equal( - peer.dict._squeezePotential('profile'), - 3, - 'squeezePotential=3' - ) + assert.equal(peer.dict._squeezePotential('profile'), 3, 'squeezePotential=3') assert.equal(await p(peer.dict.squeeze)('profile'), true, 'squeezed') const UPDATE6_ID = getMsgID(peer, 6, 'dict_v1__profile') @@ -140,11 +129,7 @@ test('Dict squeeze', async (t) => { 'fieldRoots' ) - assert.equal( - peer.dict._squeezePotential('profile'), - 0, - 'squeezePotential=0' - ) + assert.equal(peer.dict._squeezePotential('profile'), 0, 'squeezePotential=0') assert.equal( await p(peer.dict.squeeze)('profile'), false, @@ -215,11 +200,7 @@ test('Dict receives old branched update', async (t) => { assert.equal(peer.dict.minRequiredDepth(mootID), 1, 'minRequiredDepth') - assert.equal( - peer.dict._squeezePotential('profile'), - 6, - 'squeezePotential=6' - ) + assert.equal(peer.dict._squeezePotential('profile'), 6, 'squeezePotential=6') }) test('teardown', async (t) => { diff --git a/test/util.js b/test/util.js index 5f7cb3d..d1a56c2 100644 --- a/test/util.js +++ b/test/util.js @@ -4,17 +4,26 @@ const rimraf = require('rimraf') const caps = require('ppppp-caps') const Keypair = require('ppppp-keypair') -function createPeer(opts) { - if (opts.name) { +function createPeer(config) { + if (config.name) { + const name = config.name const tmp = OS.tmpdir() - opts.db ??= {path: Path.join(tmp, `ppppp-dict-${opts.name}-${Date.now()}`)} - opts.keypair ??= Keypair.generate('ed25519', opts.name) - opts.name = undefined + config.global ??= {} + config.global.path ??= Path.join(tmp, `ppppp-dict-${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.path in createPeer()') - if (!opts.keypair) throw new Error('need opts.keypair in createPeer()') - rimraf.sync(opts.db.path) + rimraf.sync(config.db.path) return require('secret-stack/bare')() .use(require('secret-stack/plugins/net')) .use(require('secret-handshake-ext/secret-stack')) @@ -22,16 +31,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, }) }