Updates
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
require('bare-process/global')
|
||||
const test = require('brittle')
|
||||
const { HyperP2PTrustGraph } = require('../index.js')
|
||||
|
||||
test('trust-graph: edge and score', async (t) => {
|
||||
const g = new HyperP2PTrustGraph()
|
||||
g.addEdge('a', 'b', 0.9)
|
||||
g.addEdge('b', 'c', 0.8)
|
||||
t.ok(g.trustScore('a', 'c') > 0)
|
||||
await g.close()
|
||||
})
|
||||
|
||||
test('trust-graph: merge', async (t) => {
|
||||
const a = new HyperP2PTrustGraph()
|
||||
const b = new HyperP2PTrustGraph()
|
||||
a.addEdge('x', 'y', 1)
|
||||
b.merge(a.toJSON())
|
||||
t.ok(b.trustScore('x', 'y') > 0)
|
||||
await a.close()
|
||||
await b.close()
|
||||
})
|
||||
test('hyper-p2p-trust-graph: close without leak', async (t) => {
|
||||
const m = new HyperP2PTrustGraph()
|
||||
await m.close()
|
||||
t.pass()
|
||||
})
|
||||
test('hyper-p2p-trust-graph: validation rejects invalid input', async (t) => {
|
||||
const m = new HyperP2PTrustGraph()
|
||||
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