150 lines
5.4 KiB
TypeScript
150 lines
5.4 KiB
TypeScript
import { describe, test } from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
|
|
import {
|
|
resolveMaturityOutcomeMode,
|
|
resolveGameOutcomeCreditKind,
|
|
computeMultiCandlePoolContribution,
|
|
} from '../services/candlePredictMultiService';
|
|
import {
|
|
resolvePoolOutcome,
|
|
type PoolNeutralityRules,
|
|
} from '../services/candleGenerationService';
|
|
|
|
const maxTolOn: PoolNeutralityRules = {
|
|
minTolerancePercent: 2,
|
|
maxTolerancePercent: 95,
|
|
minToleranceEnabled: true,
|
|
maxToleranceEnabled: true,
|
|
};
|
|
|
|
const maxTolOff: PoolNeutralityRules = {
|
|
minTolerancePercent: 2,
|
|
maxTolerancePercent: 95,
|
|
minToleranceEnabled: true,
|
|
maxToleranceEnabled: false,
|
|
};
|
|
|
|
const LEVEL_5_PAYOUT = 15;
|
|
|
|
describe('multi-candle maturity outcome mode', () => {
|
|
test('intermediate validation only (in progress) uses auto generation, not pools', () => {
|
|
assert.equal(
|
|
resolveMaturityOutcomeMode({
|
|
realMoneySinglePending: false,
|
|
multiFinalPoolShort: 0,
|
|
multiFinalPoolLong: 0,
|
|
}),
|
|
'auto'
|
|
);
|
|
});
|
|
|
|
test('test-wallet multi on final step still uses auto (no real-money pool weight)', () => {
|
|
assert.equal(
|
|
resolveMaturityOutcomeMode({
|
|
realMoneySinglePending: false,
|
|
multiFinalPoolShort: 0,
|
|
multiFinalPoolLong: 0,
|
|
}),
|
|
'auto'
|
|
);
|
|
});
|
|
|
|
test('real-money multi final step pool contribution triggers pool mode', () => {
|
|
const poolContribution = computeMultiCandlePoolContribution(100, LEVEL_5_PAYOUT);
|
|
|
|
assert.equal(
|
|
resolveMaturityOutcomeMode({
|
|
realMoneySinglePending: false,
|
|
multiFinalPoolShort: 0,
|
|
multiFinalPoolLong: poolContribution,
|
|
}),
|
|
'pool'
|
|
);
|
|
});
|
|
|
|
test('single pending real-money bet at maturity triggers pool mode', () => {
|
|
assert.equal(
|
|
resolveMaturityOutcomeMode({
|
|
realMoneySinglePending: true,
|
|
multiFinalPoolShort: 0,
|
|
multiFinalPoolLong: 0,
|
|
}),
|
|
'pool'
|
|
);
|
|
});
|
|
});
|
|
|
|
describe('solo multi-candle final candle pool resolution', () => {
|
|
test('sole participant, majority rule, max tolerance off → winning side is the only pool', () => {
|
|
const poolContribution = computeMultiCandlePoolContribution(100, LEVEL_5_PAYOUT);
|
|
const outcome = resolvePoolOutcome(0, poolContribution, maxTolOff, 'majority');
|
|
assert.equal(outcome.type, 'long_win');
|
|
assert.equal(outcome.winner, 'long');
|
|
});
|
|
|
|
test('sole participant short pool, majority rule, max tolerance off → short wins', () => {
|
|
const poolContribution = computeMultiCandlePoolContribution(100, LEVEL_5_PAYOUT);
|
|
const outcome = resolvePoolOutcome(poolContribution, 0, maxTolOff, 'majority');
|
|
assert.equal(outcome.type, 'short_win');
|
|
assert.equal(outcome.winner, 'short');
|
|
});
|
|
|
|
test('sole participant, max tolerance on (95%) → neutral refund path', () => {
|
|
const poolContribution = computeMultiCandlePoolContribution(100, LEVEL_5_PAYOUT);
|
|
const outcome = resolvePoolOutcome(0, poolContribution, maxTolOn, 'majority');
|
|
assert.equal(outcome.type, 'neutral');
|
|
assert.equal(outcome.winner, null);
|
|
});
|
|
|
|
test('sole long pool, minority rule, max tolerance off → empty short side wins (player loses if final pick was long)', () => {
|
|
const poolContribution = computeMultiCandlePoolContribution(100, LEVEL_5_PAYOUT);
|
|
const outcome = resolvePoolOutcome(0, poolContribution, maxTolOff, 'minority');
|
|
assert.equal(outcome.type, 'short_win');
|
|
assert.equal(outcome.winner, 'short');
|
|
assert.notEqual(outcome.winner, 'long');
|
|
});
|
|
|
|
test('sole short pool, minority rule, max tolerance off → empty long side wins (player loses if final pick was short)', () => {
|
|
const poolContribution = computeMultiCandlePoolContribution(100, LEVEL_5_PAYOUT);
|
|
const outcome = resolvePoolOutcome(poolContribution, 0, maxTolOff, 'minority');
|
|
assert.equal(outcome.type, 'long_win');
|
|
assert.equal(outcome.winner, 'long');
|
|
assert.notEqual(outcome.winner, 'short');
|
|
});
|
|
|
|
test('level-5 solo multi: final Short prediction, minority rule → long wins so sequence fails', () => {
|
|
const poolContribution = computeMultiCandlePoolContribution(100, LEVEL_5_PAYOUT);
|
|
const finalPrediction = 'short' as const;
|
|
const outcome = resolvePoolOutcome(poolContribution, 0, maxTolOff, 'minority');
|
|
assert.equal(outcome.winner, 'long');
|
|
assert.notEqual(outcome.winner, finalPrediction);
|
|
});
|
|
|
|
test('level-5 solo multi: final Long prediction, minority rule → short wins so sequence fails', () => {
|
|
const poolContribution = computeMultiCandlePoolContribution(100, LEVEL_5_PAYOUT);
|
|
const finalPrediction = 'long' as const;
|
|
const outcome = resolvePoolOutcome(0, poolContribution, maxTolOff, 'minority');
|
|
assert.equal(outcome.winner, 'short');
|
|
assert.notEqual(outcome.winner, finalPrediction);
|
|
});
|
|
});
|
|
|
|
describe('multi-candle test wallet credit routing', () => {
|
|
test('test wallet win payout credits test account', () => {
|
|
assert.equal(resolveGameOutcomeCreditKind('test', 'game_payout'), 'test');
|
|
});
|
|
|
|
test('test wallet neutral refund credits test account', () => {
|
|
assert.equal(resolveGameOutcomeCreditKind('test', 'game_refund'), 'test');
|
|
});
|
|
|
|
test('bonus wallet win payout credits main account', () => {
|
|
assert.equal(resolveGameOutcomeCreditKind('bonus', 'game_payout'), 'main');
|
|
});
|
|
|
|
test('main wallet win payout credits main account', () => {
|
|
assert.equal(resolveGameOutcomeCreditKind('main', 'game_payout'), 'main');
|
|
});
|
|
});
|