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-caps": "github:staltz/ppppp-caps",
|
||||||
"ppppp-keypair": "github:staltz/ppppp-keypair",
|
"ppppp-keypair": "github:staltz/ppppp-keypair",
|
||||||
"rimraf": "^4.4.0",
|
"rimraf": "^4.4.0",
|
||||||
"secret-stack": "~7.1.1",
|
"secret-stack": "~8.0.0",
|
||||||
"secret-handshake-ext": "0.0.8",
|
"secret-handshake-ext": "0.0.10",
|
||||||
"ssb-box": "^1.0.1",
|
"ssb-box": "^1.0.1",
|
||||||
"typescript": "^5.1.3"
|
"typescript": "^5.1.3"
|
||||||
},
|
},
|
||||||
|
|
|
@ -28,8 +28,10 @@ let peer
|
||||||
let aliceID
|
let aliceID
|
||||||
test('setup', async (t) => {
|
test('setup', async (t) => {
|
||||||
peer = createPeer({
|
peer = createPeer({
|
||||||
keypair: aliceKeypair,
|
global: {
|
||||||
db: {path: DIR},
|
keypair: aliceKeypair,
|
||||||
|
path: DIR,
|
||||||
|
},
|
||||||
dict: { ghostSpan: 40 },
|
dict: { ghostSpan: 40 },
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -51,19 +53,10 @@ test('Dict update() and get()', async (t) => {
|
||||||
'update .name'
|
'update .name'
|
||||||
)
|
)
|
||||||
const UPDATE0_ID = getMsgID(peer, 0, 'dict_v1__profile')
|
const UPDATE0_ID = getMsgID(peer, 0, 'dict_v1__profile')
|
||||||
assert.deepEqual(
|
assert.deepEqual(peer.dict.read(aliceID, 'profile'), { name: 'alice' }, 'get')
|
||||||
peer.dict.read(aliceID, 'profile'),
|
|
||||||
{ name: 'alice' },
|
|
||||||
'get'
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
const fieldRoots1 = peer.dict._getFieldRoots('profile')
|
const fieldRoots1 = peer.dict._getFieldRoots('profile')
|
||||||
assert.deepEqual(
|
assert.deepEqual(fieldRoots1, { name: [UPDATE0_ID] }, 'fieldRoots')
|
||||||
fieldRoots1,
|
|
||||||
{ name: [UPDATE0_ID] },
|
|
||||||
'fieldRoots'
|
|
||||||
)
|
|
||||||
|
|
||||||
assert(await p(peer.dict.update)('profile', { age: 20 }), 'update .age')
|
assert(await p(peer.dict.update)('profile', { age: 20 }), 'update .age')
|
||||||
const UPDATE1_ID = getMsgID(peer, 1, 'dict_v1__profile')
|
const UPDATE1_ID = getMsgID(peer, 1, 'dict_v1__profile')
|
||||||
|
@ -125,11 +118,7 @@ test('Dict squeeze', async (t) => {
|
||||||
'fieldRoots'
|
'fieldRoots'
|
||||||
)
|
)
|
||||||
|
|
||||||
assert.equal(
|
assert.equal(peer.dict._squeezePotential('profile'), 3, 'squeezePotential=3')
|
||||||
peer.dict._squeezePotential('profile'),
|
|
||||||
3,
|
|
||||||
'squeezePotential=3'
|
|
||||||
)
|
|
||||||
assert.equal(await p(peer.dict.squeeze)('profile'), true, 'squeezed')
|
assert.equal(await p(peer.dict.squeeze)('profile'), true, 'squeezed')
|
||||||
const UPDATE6_ID = getMsgID(peer, 6, 'dict_v1__profile')
|
const UPDATE6_ID = getMsgID(peer, 6, 'dict_v1__profile')
|
||||||
|
|
||||||
|
@ -140,11 +129,7 @@ test('Dict squeeze', async (t) => {
|
||||||
'fieldRoots'
|
'fieldRoots'
|
||||||
)
|
)
|
||||||
|
|
||||||
assert.equal(
|
assert.equal(peer.dict._squeezePotential('profile'), 0, 'squeezePotential=0')
|
||||||
peer.dict._squeezePotential('profile'),
|
|
||||||
0,
|
|
||||||
'squeezePotential=0'
|
|
||||||
)
|
|
||||||
assert.equal(
|
assert.equal(
|
||||||
await p(peer.dict.squeeze)('profile'),
|
await p(peer.dict.squeeze)('profile'),
|
||||||
false,
|
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.minRequiredDepth(mootID), 1, 'minRequiredDepth')
|
||||||
|
|
||||||
assert.equal(
|
assert.equal(peer.dict._squeezePotential('profile'), 6, 'squeezePotential=6')
|
||||||
peer.dict._squeezePotential('profile'),
|
|
||||||
6,
|
|
||||||
'squeezePotential=6'
|
|
||||||
)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
test('teardown', async (t) => {
|
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 caps = require('ppppp-caps')
|
||||||
const Keypair = require('ppppp-keypair')
|
const Keypair = require('ppppp-keypair')
|
||||||
|
|
||||||
function createPeer(opts) {
|
function createPeer(config) {
|
||||||
if (opts.name) {
|
if (config.name) {
|
||||||
|
const name = config.name
|
||||||
const tmp = OS.tmpdir()
|
const tmp = OS.tmpdir()
|
||||||
opts.db ??= {path: Path.join(tmp, `ppppp-dict-${opts.name}-${Date.now()}`)}
|
config.global ??= {}
|
||||||
opts.keypair ??= Keypair.generate('ed25519', opts.name)
|
config.global.path ??= Path.join(tmp, `ppppp-dict-${name}-${Date.now()}`)
|
||||||
opts.name = undefined
|
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')()
|
return require('secret-stack/bare')()
|
||||||
.use(require('secret-stack/plugins/net'))
|
.use(require('secret-stack/plugins/net'))
|
||||||
.use(require('secret-handshake-ext/secret-stack'))
|
.use(require('secret-handshake-ext/secret-stack'))
|
||||||
|
@ -22,16 +31,19 @@ function createPeer(opts) {
|
||||||
.use(require('ssb-box'))
|
.use(require('ssb-box'))
|
||||||
.use(require('../lib'))
|
.use(require('../lib'))
|
||||||
.call(null, {
|
.call(null, {
|
||||||
caps,
|
shse: { caps },
|
||||||
connections: {
|
...config,
|
||||||
incoming: {
|
global: {
|
||||||
net: [{ scope: 'device', transform: 'shse', port: null }],
|
connections: {
|
||||||
},
|
incoming: {
|
||||||
outgoing: {
|
net: [{ scope: 'device', transform: 'shse', port: null }],
|
||||||
net: [{ transform: 'shse' }],
|
},
|
||||||
|
outgoing: {
|
||||||
|
net: [{ transform: 'shse' }],
|
||||||
|
},
|
||||||
},
|
},
|
||||||
|
...config.global,
|
||||||
},
|
},
|
||||||
...opts,
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue