Files
wownerogue/test/alertServiceMoney.test.js
jwinterm fad2a695bd Wownerogue
A browser-based roguelike synchronized with crypto block timing. A run is a race
against the next block: reach the exit before the block lands, or the house wins.
The same codebase runs the solo dungeon, the social Tavern, and operator-selected
PvP and race rulesets, with separate free and paid leaderboards.

Self-hostable under the MIT License. See README.md to run it, docs/ARCHITECTURE.md
for the design, and docs/DEPLOY.md to operate an instance.
2026-07-27 08:23:01 -04:00

58 lines
2.1 KiB
JavaScript

const AlertService = require('../src/services/alertService');
describe('AlertService exact reserve gate', () => {
const keys = ['BALANCE_CRITICAL', 'BALANCE_WARN', 'LOW_BALANCE_THRESHOLD'];
let previous;
let logSpy;
let errorSpy;
beforeEach(() => {
previous = Object.fromEntries(keys.map(key => [key, process.env[key]]));
process.env.BALANCE_CRITICAL = '10000000000000001';
process.env.BALANCE_WARN = '10000000000000002';
delete process.env.LOW_BALANCE_THRESHOLD;
logSpy = jest.spyOn(console, 'log').mockImplementation(() => {});
errorSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
});
afterEach(() => {
logSpy.mockRestore();
errorSpy.mockRestore();
for (const key of keys) {
if (previous[key] === undefined) delete process.env[key];
else process.env[key] = previous[key];
}
});
test('compares balances above Number.MAX_SAFE_INTEGER without rounding', async () => {
const service = new AlertService({
walletService: {
isHealthy: true,
getBalance: jest.fn(async () => ({ unlocked_balance: '10000000000000000' }))
},
db: null,
debugManager: { CONSOLE_LOGGING: false }
});
expect(service.balanceCriticalThreshold).toBe(10000000000000001n);
await expect(service.checkBalanceForGameStart()).resolves.toEqual(expect.objectContaining({ halted: true }));
});
test('wallet balance read errors fail closed for new paid games', async () => {
const service = new AlertService({
walletService: {
isHealthy: true,
getBalance: jest.fn(async () => { throw new Error('rpc unavailable'); })
},
db: null,
debugManager: { CONSOLE_LOGGING: false }
});
await expect(service.checkBalanceForGameStart()).resolves.toEqual(expect.objectContaining({
halted: true,
reason: expect.stringContaining('could not be verified')
}));
expect(service.isBalanceCritical).toBe(true);
});
});