mirror of
https://github.com/db9979/wibosim.git
synced 2026-12-06 13:34:09 +01:00
- 13 neue fiktive Aktien in allen Branchen; WIBO-10 bleibt bei den zehn Standardwerten - WiboCoin (WIBC): Krypto, rund um die Uhr handelbar, Hype/Ereignisse/Krypto-Meldungen, keine Leerverkäufe, weiterer Preiskorridor - Börsengänge: Ankündigung (Zufall, Admin, echte Meldungen -> fiktives Unternehmen derselben Branche), Zeichnung mit reservierter Kaufkraft, Preisfindung nach Nachfrage, anteilige Zuteilung, Absage bei zu wenig Nachfrage, Erstnotiz in der Eröffnungsauktion - Rivalen handeln WiboCoin und zeichnen Börsengänge - Client: Krypto-Gruppe, 24/7- und Neu-Kennzeichen, Zeichnung unter Termine; Admin-Aktionen - Tests, Doku, Changelog Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018i4GUhQVoPUusUzxgxLWkK
88 lines
4.1 KiB
JavaScript
88 lines
4.1 KiB
JavaScript
import { test } from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import os from 'node:os';
|
|
import fs from 'node:fs';
|
|
import path from 'node:path';
|
|
|
|
process.env.NODE_ENV = 'test';
|
|
process.env.TIME_MODE = 'turbo';
|
|
process.env.DATA_DIR = fs.mkdtempSync(path.join(os.tmpdir(), 'wibosim-test-'));
|
|
const { settings } = await import('./settings.js');
|
|
const { Store } = await import('./store.js');
|
|
const { Game } = await import('./game.js');
|
|
|
|
Object.assign(settings.game, { dayMs: 60_000, tickMs: 1000, rivalsEnabled: false, ipoEveryDays: 0 });
|
|
settings.news.enabled = false;
|
|
|
|
const dir = () => fs.mkdtempSync(path.join(os.tmpdir(), 'wibosim-ipo-'));
|
|
const player = async (g, name) => (await g.register({ name, password: 'geheim123' })).player;
|
|
|
|
test('Börsengang: Zeichnen reserviert Kaufkraft, Zuteilung, Erstnotiz, übersteht Neustart', async () => {
|
|
const d = dir();
|
|
const g = new Game({ store: new Store(d) });
|
|
const p = await player(g, 'Zeichnerin');
|
|
const before = g.freeCash(p);
|
|
const x = g.adminAction({ name: 'admin' }, 'ipo', { value: { sector: 'tech', name: 'Testwerk AG' } });
|
|
const ipo = g.ipo.pending.find((i) => i.id === x.ipo);
|
|
assert.ok(ipo && ipo.status === 'signup');
|
|
assert.ok(g.news.some((n) => n.title.includes('Testwerk AG')));
|
|
assert.throws(() => g.ipo.subscribe(p, ipo.id, Math.floor(before / ipo.hi) + 10), /Kaufkraft/);
|
|
g.ipo.subscribe(p, ipo.id, 100);
|
|
const held = before - g.freeCash(p);
|
|
assert.ok(held >= 100 * ipo.hi && held < 100 * ipo.hi * 1.01, 'Höchstpreis reserviert');
|
|
assert.equal(g.ipo.view(p).pending[0].mine, 100);
|
|
// Nachfrage erzwingen, Zeichnungsschluss
|
|
ipo.fair = ipo.hi * 2;
|
|
g.macro.sentiment = 1;
|
|
g.day = ipo.closeDay;
|
|
g.ipo.newDay();
|
|
const s = g.stocks.get(ipo.symbol);
|
|
assert.ok(s, 'notiert');
|
|
assert.equal(ipo.status, 'listed');
|
|
assert.ok(ipo.price >= ipo.lo && ipo.price <= ipo.hi);
|
|
assert.ok(p.positions[ipo.symbol].qty > 0 && p.positions[ipo.symbol].qty <= 100);
|
|
assert.ok(Math.abs(g.freeCash(p) - (before - p.positions[ipo.symbol].qty * ipo.price * (1 + settings.game.feeRate))) < 1);
|
|
assert.ok(s.fund && s.fv > 0 && s.fund.analysts);
|
|
assert.ok(!g.index().constituents || !g.index().constituents.includes?.(ipo.symbol));
|
|
assert.equal(g.ipo.pending.length, 0);
|
|
// Neustart: Aktie, Position und Fundamentaldaten bleiben erhalten
|
|
const qty = p.positions[ipo.symbol].qty;
|
|
const store = g.store;
|
|
g.flush(true);
|
|
store.close();
|
|
const g2 = new Game({ store: new Store(d) });
|
|
const s2 = g2.stocks.get(ipo.symbol);
|
|
assert.ok(s2 && s2.name === 'Testwerk AG' && s2.sector === 'tech');
|
|
assert.equal(s2.last, s.last);
|
|
assert.ok(s2.fund?.analysts);
|
|
assert.equal(g2.players.get(p.id).positions[ipo.symbol].qty, qty);
|
|
assert.ok(g2.company(ipo.symbol, p.id));
|
|
});
|
|
|
|
test('Börsengang: zu wenig Nachfrage → Absage, Reservierung frei', async () => {
|
|
const g = new Game({ store: new Store(dir()) });
|
|
const p = await player(g, 'Vorsicht');
|
|
const before = g.freeCash(p);
|
|
const x = g.ipo.announce({ sector: 'pharma' });
|
|
g.ipo.subscribe(p, x.id, 10);
|
|
x.fair = x.lo * 0.2; // Institutionelle winken ab
|
|
g.macro.sentiment = -1;
|
|
g.day = x.closeDay;
|
|
g.ipo.newDay();
|
|
assert.equal(x.status, 'cancelled');
|
|
assert.ok(!g.stocks.has(x.symbol));
|
|
assert.ok(Math.abs(g.freeCash(p) - before) < 1e-6);
|
|
});
|
|
|
|
test('Börsengang aus echter Meldung: fiktives Unternehmen derselben Branche, höchstens einer je 12 h', async () => {
|
|
const g = new Game({ store: new Store(dir()) });
|
|
g.addNews({ id: 'r1', title: 'Chiphersteller plant Börsengang in Frankfurt', source: 'Test', real: true, sentiment: 0.1, sectors: ['tech'], ts: Date.now() });
|
|
const a = g.ipo.pending[0];
|
|
assert.ok(a && a.source === 'news' && a.sector === 'tech');
|
|
assert.ok(!a.name.includes('Chiphersteller'));
|
|
g.addNews({ id: 'r2', title: 'Autobauer kündigt IPO an', source: 'Test', real: true, sentiment: 0, sectors: ['auto'], ts: Date.now() });
|
|
assert.equal(g.ipo.pending.length, 1);
|
|
g.addNews({ id: 'r3', title: 'Zinsen bleiben unverändert', source: 'Test', real: true, sentiment: 0, ts: Date.now() });
|
|
assert.equal(g.ipo.pending.length, 1);
|
|
});
|