mirror of https://codeberg.org/pzp/pzp-dict.git
update secret-stack to 8.0
This commit is contained in:
parent
0695ccc36a
commit
d3664ff1c8
|
@ -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"
|
||||
},
|
||||
|
|
|
@ -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) => {
|
||||
|
|
44
test/util.js
44
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,
|
||||
})
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue