Updates
This commit is contained in:
@@ -4,23 +4,36 @@ const { HyperP2PAuctionGossip, PROTOCOL } = require('../index.js')
|
||||
|
||||
test('exports', (t) => {
|
||||
t.ok(HyperP2PAuctionGossip)
|
||||
t.ok(PROTOCOL)
|
||||
t.is(PROTOCOL, 'auction-gossip/v1')
|
||||
})
|
||||
|
||||
test('basic operation', async (t) => {
|
||||
test('open bid close', async (t) => {
|
||||
const m = new HyperP2PAuctionGossip()
|
||||
m.put('k', 1); t.is(m.get('k'), 1)
|
||||
m.openAuction('a1', { item: 'widget' })
|
||||
m.placeBid('a1', 10)
|
||||
m.placeBid('a1', 20)
|
||||
const closed = m.closeAuction('a1')
|
||||
t.is(closed.winner.amount, 20)
|
||||
await m.close()
|
||||
})
|
||||
|
||||
test('validation', async (t) => {
|
||||
const m = new HyperP2PAuctionGossip()
|
||||
try { m.put(null, 1) } catch (e) { t.ok(e) }
|
||||
try { m.placeBid('missing', 1) } catch (e) { t.ok(e) }
|
||||
await m.close()
|
||||
})
|
||||
|
||||
test('remote bid via gossip', async (t) => {
|
||||
const m = new HyperP2PAuctionGossip()
|
||||
m.openAuction('a1')
|
||||
m._onGossip({ type: 'auction-bid', auctionId: 'a1', bid: { amount: 5, bidder: 'remote', at: 1 } })
|
||||
t.is(m.getAuction('a1').bids.length, 1)
|
||||
await m.close()
|
||||
})
|
||||
|
||||
test('getStats', async (t) => {
|
||||
const m = new HyperP2PAuctionGossip()
|
||||
t.ok(m.getStats().protocol)
|
||||
m.openAuction('x')
|
||||
t.is(m.getStats().opened, 1)
|
||||
await m.close()
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user