mirror of
https://github.com/Such-Software/wownerogue.git
synced 2026-10-19 07:08:33 +02:00
fix: enforce operated paid mode contracts
This commit is contained in:
@@ -192,6 +192,7 @@ describe('EnvironmentValidator production launch gate', () => {
|
||||
CRYPTO_TYPE: 'WOW',
|
||||
MONERO_NETWORK: 'mainnet',
|
||||
FREE_PLAY_ENABLED: 'true',
|
||||
GAME_MODE: 'PAID_CREDITS',
|
||||
PAYMENT_MODES: 'credits',
|
||||
DIRECT_PAYMENT_ENABLED: 'false',
|
||||
CREDITS_ENABLED: 'true',
|
||||
@@ -219,6 +220,16 @@ describe('EnvironmentValidator production launch gate', () => {
|
||||
expect(new EnvironmentValidator({ env, logger: silentLogger })
|
||||
.assertValid(operatedConfig).errors).toEqual([]);
|
||||
|
||||
for (const gameMode of [undefined, 'PAID_SINGLE']) {
|
||||
const driftedEnv = { ...env };
|
||||
if (gameMode === undefined) delete driftedEnv.GAME_MODE;
|
||||
else driftedEnv.GAME_MODE = gameMode;
|
||||
expect(new EnvironmentValidator({ env: driftedEnv, logger: silentLogger })
|
||||
.validate(operatedConfig).errors).toContain(
|
||||
'OPERATED_PRODUCT_PROFILE=such-play-wow-prestige requires GAME_MODE=PAID_CREDITS.'
|
||||
);
|
||||
}
|
||||
|
||||
expect(new EnvironmentValidator({ env, logger: silentLogger }).validate({
|
||||
...operatedConfig,
|
||||
products: { cosmetic: [{ id: 'unrelated-pack', price: 1n }] }
|
||||
@@ -237,6 +248,7 @@ describe('EnvironmentValidator production launch gate', () => {
|
||||
LEGAL_POLICY_VERSION: '2026-07-23-v2',
|
||||
TERMS_EFFECTIVE_DATE: '2026-07-23',
|
||||
FREE_PLAY_ENABLED: 'true',
|
||||
GAME_MODE: 'PAID_SINGLE',
|
||||
PAYMENT_MODES: 'direct',
|
||||
DIRECT_PAYMENT_ENABLED: 'true',
|
||||
CREDITS_ENABLED: 'false',
|
||||
@@ -312,6 +324,7 @@ describe('EnvironmentValidator production launch gate', () => {
|
||||
CRYPTO_TYPE: 'WOW',
|
||||
MONERO_NETWORK: 'mainnet',
|
||||
FREE_PLAY_ENABLED: 'true',
|
||||
GAME_MODE: 'PAID_CREDITS',
|
||||
PAYMENT_MODES: 'direct,credits',
|
||||
DIRECT_PAYMENT_ENABLED: 'true',
|
||||
CREDITS_ENABLED: 'true',
|
||||
@@ -345,6 +358,7 @@ describe('EnvironmentValidator production launch gate', () => {
|
||||
CRYPTO_TYPE: 'XMR',
|
||||
MONERO_NETWORK: 'mainnet',
|
||||
FREE_PLAY_ENABLED: 'true',
|
||||
GAME_MODE: 'PAID_CREDITS',
|
||||
PAYMENT_MODES: 'direct,credits',
|
||||
DIRECT_PAYMENT_ENABLED: 'true',
|
||||
CREDITS_ENABLED: 'true',
|
||||
@@ -376,6 +390,7 @@ describe('EnvironmentValidator production launch gate', () => {
|
||||
expect.stringContaining('requires LEGAL_POLICY_VERSION=2026-07-23-v2'),
|
||||
expect.stringContaining('requires TERMS_EFFECTIVE_DATE=2026-07-23'),
|
||||
expect.stringContaining('requires MONERO_NETWORK=stagenet'),
|
||||
expect.stringContaining('requires GAME_MODE=PAID_SINGLE'),
|
||||
expect.stringContaining('requires PAYMENT_MODES=direct'),
|
||||
expect.stringContaining('requires CREDITS_ENABLED=false'),
|
||||
expect.stringContaining('requires CREDITS_PAYOUTS_ENABLED=false'),
|
||||
|
||||
@@ -47,6 +47,7 @@ describe('operated product environment templates', () => {
|
||||
CRYPTO_TYPE: 'WOW',
|
||||
MONERO_NETWORK: 'mainnet',
|
||||
FREE_PLAY_ENABLED: 'true',
|
||||
GAME_MODE: 'PAID_CREDITS',
|
||||
PAYMENT_MODES: 'credits',
|
||||
DIRECT_PAYMENT_ENABLED: 'false',
|
||||
CREDITS_ENABLED: 'true',
|
||||
@@ -78,6 +79,7 @@ describe('operated product environment templates', () => {
|
||||
CRYPTO_TYPE: 'XMR',
|
||||
MONERO_NETWORK: 'stagenet',
|
||||
FREE_PLAY_ENABLED: 'true',
|
||||
GAME_MODE: 'PAID_SINGLE',
|
||||
PAYMENT_MODES: 'direct',
|
||||
DIRECT_PAYMENT_ENABLED: 'true',
|
||||
CREDITS_ENABLED: 'false',
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
const {
|
||||
selectPublicPaidModeDescriptors
|
||||
} = require('../src/config/operatedProductProfiles');
|
||||
|
||||
const descriptors = Object.freeze({
|
||||
PAID_SINGLE: Object.freeze({ enabled: true, name: 'Paid Single Game' }),
|
||||
PAID_CREDITS: Object.freeze({ enabled: true, name: 'Credits Package' })
|
||||
});
|
||||
|
||||
describe('operated-product public paid-mode contract', () => {
|
||||
test('play.wowne.ro publishes credits and omits direct entry', () => {
|
||||
const result = selectPublicPaidModeDescriptors({
|
||||
OPERATED_PRODUCT_PROFILE: 'such-play-wow-prestige'
|
||||
}, descriptors);
|
||||
|
||||
expect(result).toEqual({ PAID_CREDITS: descriptors.PAID_CREDITS });
|
||||
expect(result).not.toHaveProperty('PAID_SINGLE');
|
||||
});
|
||||
|
||||
test('monerogue.app publishes direct entry and omits purchased credits', () => {
|
||||
const result = selectPublicPaidModeDescriptors({
|
||||
OPERATED_PRODUCT_PROFILE: 'such-monerogue-stagenet'
|
||||
}, descriptors);
|
||||
|
||||
expect(result).toEqual({ PAID_SINGLE: descriptors.PAID_SINGLE });
|
||||
expect(result).not.toHaveProperty('PAID_CREDITS');
|
||||
});
|
||||
|
||||
test('generic MIT deployments retain both legacy API descriptors', () => {
|
||||
const result = selectPublicPaidModeDescriptors({}, descriptors);
|
||||
|
||||
expect(result).toEqual(descriptors);
|
||||
expect(result).not.toBe(descriptors);
|
||||
});
|
||||
});
|
||||
@@ -105,6 +105,38 @@ describe('production payment policy wiring', () => {
|
||||
expect(wallet.createPaymentRequest).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
test('a contradictory legacy GAME_MODE cannot misreport the enabled payment policy', () => {
|
||||
process.env.PAYMENTS_ENABLED = 'true';
|
||||
process.env.GAME_MODE = 'PAID_SINGLE';
|
||||
process.env.PAYMENT_MODES = 'credits';
|
||||
process.env.DIRECT_PAYMENT_ENABLED = 'false';
|
||||
process.env.CREDITS_ENABLED = 'true';
|
||||
process.env.PAYOUTS_ENABLED = 'false';
|
||||
process.env.DIRECT_PAYOUTS_ENABLED = 'false';
|
||||
process.env.CREDITS_PAYOUTS_ENABLED = 'false';
|
||||
|
||||
const manager = new PaymentConfigManager({ logger: { warn() {}, info() {} } });
|
||||
const gameModes = new GameModeManager(
|
||||
{ query: jest.fn(), withTransaction: jest.fn() },
|
||||
{ validateAddress: jest.fn() },
|
||||
{ CONSOLE_LOGGING: false },
|
||||
manager
|
||||
);
|
||||
|
||||
expect(manager.getConfig().modes.direct.enabled).toBe(false);
|
||||
expect(manager.getConfig().modes.credits.enabled).toBe(true);
|
||||
expect(manager.getLegacyGameMode()).toBe('PAID_CREDITS');
|
||||
expect(gameModes.getGameModeInfo()).toEqual(expect.objectContaining({
|
||||
mode: 'PAID_CREDITS',
|
||||
directModeEnabled: false,
|
||||
creditsModeEnabled: true,
|
||||
payoutsEnabled: false
|
||||
}));
|
||||
expect(gameModes.getPublicPreferredPaymentMode({
|
||||
preferred_payment_mode: 'direct'
|
||||
})).toBe('credits');
|
||||
});
|
||||
|
||||
test('global per-game payout cap is an outer bound for direct and credit wins', () => {
|
||||
process.env.PAYMENT_MODES = 'direct,credits';
|
||||
process.env.PAYOUT_MAX_PER_GAME = '123456';
|
||||
|
||||
@@ -185,10 +185,6 @@ describe('XMR stagenet financial canary safety contract', () => {
|
||||
enabled: true,
|
||||
payoutMultiplier: { escape: 2, escapeWithTreasure: 3 }
|
||||
},
|
||||
PAID_CREDITS: {
|
||||
enabled: false,
|
||||
payoutMultiplier: 0
|
||||
},
|
||||
match: {
|
||||
enabled: true,
|
||||
economies: {
|
||||
|
||||
Reference in New Issue
Block a user