Files
modules/applications-economy/hyper-p2p-auction-gossip/test/test.js
T
Raven ScottandCursor 44b8a80907 Expand economy, autobase, network, observability, and scheduling modules.
Add auction withdraw/cancel, marketplace search helpers, update gossip history, autobase fork/lease/indexer/view APIs, link-probe and circuit-loom utilities, trace trees, pheromone ranking, and scheduling/measurement helpers with tests.

Co-authored-by: Cursor <[email protected]>
2026-05-21 01:09:29 -04:00

53 lines
1.5 KiB
JavaScript

require('bare-process/global')
const test = require('brittle')
const { HyperP2PAuctionGossip, PROTOCOL } = require('../index.js')
test('exports', (t) => {
t.ok(HyperP2PAuctionGossip)
t.is(PROTOCOL, 'auction-gossip/v1')
})
test('open bid close', async (t) => {
const m = new HyperP2PAuctionGossip()
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.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()
m.openAuction('x')
t.is(m.getStats().opened, 1)
await m.close()
})
test('withdraw cancel highest', async (t) => {
const m = new HyperP2PAuctionGossip()
m.openAuction('a1')
m.placeBid('a1', 10)
m._onGossip({ type: 'auction-bid', auctionId: 'a1', bid: { amount: 30, bidder: 'remote', at: 2 } })
t.is(m.highestBid('a1').amount, 30)
t.is(m.withdrawBid('a1', 'remote'), 1)
t.is(m.highestBid('a1').amount, 10)
t.ok(m.cancelAuction('a1'))
t.is(m.listAuctionIds().length, 0)
await m.close()
})