Updates
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
require('bare-process/global')
|
||||
const test = require('brittle')
|
||||
const { HyperP2PTimeCapsule } = require('../index.js')
|
||||
|
||||
test('time-capsule: quorum open', async (t) => {
|
||||
const c = new HyperP2PTimeCapsule()
|
||||
const id = c.seal({ secret: 'data' }, { quorum: 2, unlockAt: 0 })
|
||||
t.not(c.open(id))
|
||||
c.attest(id, 'v1')
|
||||
c.attest(id, 'v2')
|
||||
t.ok(c.open(id))
|
||||
await c.close()
|
||||
})
|
||||
|
||||
test('time-capsule: time lock', async (t) => {
|
||||
const c = new HyperP2PTimeCapsule()
|
||||
const id = c.seal({ x: 1 }, { unlockAt: Date.now() + 60000, quorum: 0 })
|
||||
t.not(c.canOpen(id))
|
||||
await c.close()
|
||||
})
|
||||
test('hyper-p2p-time-capsule: close without leak', async (t) => {
|
||||
const m = new HyperP2PTimeCapsule()
|
||||
await m.close()
|
||||
t.pass()
|
||||
})
|
||||
test('hyper-p2p-time-capsule: validation rejects invalid input', async (t) => {
|
||||
const m = new HyperP2PTimeCapsule()
|
||||
try {
|
||||
if (typeof m.addNeighbor === 'function') m.addNeighbor(null)
|
||||
else if (typeof m.buildCircuit === 'function') m.buildCircuit([])
|
||||
else if (typeof m.grant === 'function') m.grant(null, -1)
|
||||
else if (typeof m.enqueue === 'function') m.enqueue('bad', null)
|
||||
else if (typeof m.reportSample === 'function') m.reportSample(null, -1, -1)
|
||||
else if (typeof m.fanout === 'function') m.fanout(null, 0)
|
||||
else if (typeof m.probe === 'function') m.probe(null)
|
||||
else if (typeof m.resolve === 'function') m.resolve(null)
|
||||
else if (typeof m.acquire === 'function') m.acquire(null)
|
||||
else throw new Error('no validation hook')
|
||||
t.fail('expected throw')
|
||||
} catch (err) {
|
||||
t.ok(err instanceof Error)
|
||||
}
|
||||
await m.close()
|
||||
})
|
||||
Reference in New Issue
Block a user