This commit is contained in:
Raven Scott
2026-05-20 21:02:45 -04:00
parent 1f3f4b24a2
commit 14d0980b4f
734 changed files with 682 additions and 746 deletions
@@ -0,0 +1,56 @@
require('bare-process/global')
const test = require('brittle')
const { HyperP2PMyceliumPool } = require('../index.js')
test('mycelium-pool: donate borrow', async (t) => {
const p = new HyperP2PMyceliumPool()
p.donate('peer-a', 100)
t.ok(p.borrow('peer-a', 30))
t.is(p.balance('peer-a'), 70)
await p.close()
})
test('mycelium-pool: reject negative credits', async (t) => {
const p = new HyperP2PMyceliumPool()
try {
p.donate('peer-a', -1)
t.fail('expected error')
} catch (err) {
t.ok(/non-negative/i.test(err.message))
}
await p.close()
})
test('mycelium-pool: merge balances', async (t) => {
const a = new HyperP2PMyceliumPool()
const b = new HyperP2PMyceliumPool()
a.donate('peer-x', 50)
b.mergeBalances(a.toJSON())
t.is(b.balance('peer-x'), 50)
await a.close()
await b.close()
})
test('hyper-p2p-mycelium-pool: close without leak', async (t) => {
const m = new HyperP2PMyceliumPool()
await m.close()
t.pass()
})
test('hyper-p2p-mycelium-pool: validation rejects invalid input', async (t) => {
const m = new HyperP2PMyceliumPool()
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()
})