require('bare-process/global') const test = require('brittle') const { HyperP2PBloomGossip, PROTOCOL } = require('../index.js') test('exports', (t) => { t.ok(HyperP2PBloomGossip) t.is(PROTOCOL, 'bloom-gossip/v1') }) test('add mightContain exportBits', async (t) => { const m = new HyperP2PBloomGossip() t.ok(m.add('peer-1')) t.ok(m.mightContain('peer-1')) t.ok(m.exportBits().bits) await m.close() }) test('validation', async (t) => { const m = new HyperP2PBloomGossip() try { m.add('') } catch (e) { t.ok(e) } await m.close() }) test('remote gossip', async (t) => { const m = new HyperP2PBloomGossip() m._onGossip({ type: 'bloom-add', key: 'remote-key' }) t.ok(m.mightContain('remote-key')) await m.close() }) test('getStats', async (t) => { const m = new HyperP2PBloomGossip() m.add('x') t.is(m.getStats().protocol, 'bloom-gossip/v1') t.is(m.getStats().added, 1) await m.close() }) test('listKeys clear', async (t) => { const m = new HyperP2PBloomGossip() m.add('a') m.add('b') t.is(m.listKeys().length, 2) t.is(m.clear(), 2) t.is(m.size(), 0) await m.close() }) test('union and fillRatio', async (t) => { const a = new HyperP2PBloomGossip() const b = new HyperP2PBloomGossip() a.add('shared') b.add('other') a.union(b.exportBits()) t.ok(a.mightContain('other')) t.ok(a.fillRatio() >= 0) await a.close() await b.close() })