Updates
This commit is contained in:
@@ -1,26 +1,39 @@
|
||||
require('bare-process/global')
|
||||
const test = require('brittle')
|
||||
const b4a = require('b4a')
|
||||
const { HyperP2PEncryptedTopic, PROTOCOL } = require('../index.js')
|
||||
|
||||
test('exports', (t) => {
|
||||
t.ok(HyperP2PEncryptedTopic)
|
||||
t.ok(PROTOCOL)
|
||||
t.is(PROTOCOL, 'encrypted-topic/v1')
|
||||
})
|
||||
|
||||
test('basic operation', async (t) => {
|
||||
test('encrypt decrypt roundtrip', async (t) => {
|
||||
const m = new HyperP2PEncryptedTopic()
|
||||
m.put('k', 1); t.is(m.get('k'), 1)
|
||||
m.registerTopic('secret', 'hint-abc')
|
||||
const plain = b4a.from('hello peers')
|
||||
const cipher = m.encryptPayload('secret', plain)
|
||||
const out = m.decryptPayload('secret', cipher)
|
||||
t.alike(out, plain)
|
||||
await m.close()
|
||||
})
|
||||
|
||||
test('unregistered topic throws', async (t) => {
|
||||
const m = new HyperP2PEncryptedTopic()
|
||||
try { m.encryptPayload('nope', 'x') } catch (e) { t.ok(e) }
|
||||
await m.close()
|
||||
})
|
||||
|
||||
test('validation', async (t) => {
|
||||
const m = new HyperP2PEncryptedTopic()
|
||||
try { m.put(null, 1) } catch (e) { t.ok(e) }
|
||||
try { m.registerTopic(null, 'h') } catch (e) { t.ok(e) }
|
||||
await m.close()
|
||||
})
|
||||
|
||||
test('getStats', async (t) => {
|
||||
const m = new HyperP2PEncryptedTopic()
|
||||
t.ok(m.getStats().protocol)
|
||||
m.registerTopic('t', 'h')
|
||||
m.encryptPayload('t', 'a')
|
||||
t.is(m.getStats().encrypted, 1)
|
||||
await m.close()
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user