caelum0x 315020a760 feat: Wave E — api platform surface (51 services, 288 routes, 19 indexers, 481 tests)
- routes across all domains: trade finance, compliance, dpp, logistics, commodities,
  energy, workforce, data + cross-cutting (auth/webhooks/exports/reports/admin/analytics)
- service layer per domain aggregating chain reads + infra repositories into typed DTOs
- indexer handlers mapping every contract group's events to repository upserts
- api + workspace typecheck green

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-08-01 00:19:24 +03:00

56 lines
2.6 KiB
TypeScript

import { describe, expect, it } from 'vitest';
import type { AppContext } from '../../src/context.js';
import { loadConfig } from '../../src/config/env.js';
import { createAuctionsService } from '../../src/services/auctions.js';
import { makeChain, makeDb, type Row } from '../routers-kit.js';
import { silentLogger } from '../helpers.js';
const SELLER = '0x1111111111111111111111111111111111111111';
const BIDDER = '0x4444444444444444444444444444444444444444';
const config = loadConfig({ BASE_SEPOLIA_RPC_URL: 'https://sepolia.base.org' });
const auctions: Row[] = [
{ id: 'a1', seller: SELLER, highest_bid: '100', highest_bidder: BIDDER, end_time: '1900', status: 'active', created_at: '2026-01-02' },
{ id: 'a2', seller: '0x2222222222222222222222222222222222222222', highest_bid: '0', highest_bidder: null, end_time: '1800', status: 'cancelled', created_at: '2026-01-01' },
];
const events: Row[] = [
{ group_name: 'marketplace', contract: 'AuctionHouse', event_name: 'Bid', 'args->>auctionId': 'a1', created_at: '2026-01-02' },
{ group_name: 'marketplace', contract: 'AuctionHouse', event_name: 'Bid', 'args->>auctionId': 'a2', created_at: '2026-01-01' },
];
const makeCtx = (parts: Partial<Pick<AppContext, 'db' | 'chain'>> = {}): AppContext => ({
config,
logger: silentLogger,
chain: parts.chain ?? makeChain(),
db: parts.db ?? makeDb(),
});
const page = { limit: 25, offset: 0 };
describe('AuctionsService', () => {
it('lists and filters by status/seller', async () => {
const svc = createAuctionsService(makeCtx({ db: makeDb({ auctions }) }));
expect((await svc.list({ pagination: page })).rows[0]?.id).toBe('a1');
const active = await svc.list({ pagination: page, status: 'active' });
expect(active.total).toBe(1);
});
it('resolves detail DB-first then via auctionOf', async () => {
const dbSvc = createAuctionsService(makeCtx({ db: makeDb({ auctions }) }));
expect(await dbSvc.getById('a1')).toMatchObject({ id: 'a1', source: 'db' });
const chain = makeChain({
contracts: { AuctionHouse: true },
reads: { auctionOf: { seller: SELLER, highestBid: 5n, highestBidder: BIDDER, endTime: 42n, status: 1, exists: true } },
});
const chainSvc = createAuctionsService(makeCtx({ db: makeDb({}), chain }));
expect(await chainSvc.getById('a9')).toMatchObject({ status: 'settled', highest_bid: '5', source: 'chain' });
});
it('lists bid events scoped to an auction', async () => {
const svc = createAuctionsService(makeCtx({ db: makeDb({ indexer_events: events }) }));
const bids = await svc.listBids('a1', page);
expect(bids.total).toBe(1);
});
});