Files
wownerogue/test/paymentProviderBootstrap_ultra.test.js
T
jwinterm 74753c17b2 feat(payments): wire provider registry into invoice creation + fit real BTCPay infra
Recon of the operator's LAN BTCPay box (ssh four-btcpay / 10.42.1.33) showed the
real topology: BTCPay Server 2.3.9 handles BTC/LTC only (BTCPAY_CHAINS=ltc,btc),
while XMR and WOW run through separate 'xmrcheckout' (:8080) and 'wowcheckout'
(:8180) apps — and crucially, both expose a BTCPay-Greenfield-COMPATIBLE API
(/api/v1/stores/{id}/invoices, token auth, Settled/New/Expired status). Grin
isn't deployed there yet. So one Greenfield client class serves all three.

- btcpayProvider: id is now constructor-configurable so the same class registers
  as 'btcpay' (BTC/LTC), 'xmrcheckout' (XMR), and 'wowcheckout' (WOW).
- buildProviderRegistry: activates each gateway independently from its *_URL/
  _STORE_ID/_API_KEY trio (BTCPAY_*, XMRCHECKOUT_*, WOWCHECKOUT_*), with
  topology-correct default routing (BTC/LTC->btcpay, XMR/WOW->their checkout or
  native), BTCPAY_CHAINS to widen, PAYMENT_ROUTING to override.
- gameModeManager: takes an optional paymentProviders registry (defaults to a
  native-wrapping registry built from walletService). createPaymentRequest now
  creates the invoice via getProvider(cryptoType).createInvoice(...). The native
  provider delegates to walletService.createPaymentRequest, so the shipped
  single-chain config is byte-for-byte unchanged — same subaddress, same
  monitoring maps. paymentRequest now also carries invoiceId for the monitoring
  wire to come.
- nativeMoneroProvider: surfaces addressIndex so the call site stays provider-agnostic.

Behavior-preserving: no gateway env => native-only, every chain routes native.
Monitoring + payout paths intentionally left on the native path this pass;
gateway monitoring (provider.startWatch) is the flagged next step. Tests: +4
(provider wiring routes to a gateway; default registry delegates to native).
Suite 53 suites / 365 tests green.
2026-07-10 17:17:49 -04:00

72 lines
3.6 KiB
JavaScript

const { buildProviderRegistry, parseRouting } = require('../src/payments/providers');
const fakeWallet = { createPaymentRequest: async () => ({}), checkPaymentStatus: async () => ({}), processBatchPayout: async () => ({}) };
const CHECKOUT = { // full LAN infra: real BTCPay (BTC/LTC) + xmrcheckout + wowcheckout
BTCPAY_URL: 'http://10.42.1.33', BTCPAY_STORE_ID: 'b', BTCPAY_API_KEY: 'k',
XMRCHECKOUT_URL: 'http://10.42.1.33:8080', XMRCHECKOUT_STORE_ID: 'x', XMRCHECKOUT_API_KEY: 'k',
WOWCHECKOUT_URL: 'http://10.42.1.33:8180', WOWCHECKOUT_STORE_ID: 'w', WOWCHECKOUT_API_KEY: 'k'
};
describe('parseRouting', () => {
test('parses JSON and compact forms, ignores garbage', () => {
expect(parseRouting('{"btc":"btcpay","xmr":"xmrcheckout"}')).toEqual({ BTC: 'btcpay', XMR: 'xmrcheckout' });
expect(parseRouting('BTC:btcpay, XMR:xmrcheckout')).toEqual({ BTC: 'btcpay', XMR: 'xmrcheckout' });
expect(parseRouting('')).toEqual({});
expect(parseRouting('{not json')).toEqual({});
});
});
describe('buildProviderRegistry', () => {
test('native-only (no gateway env): every chain routes to native — behavior-preserving', () => {
const reg = buildProviderRegistry({ env: {}, walletService: fakeWallet });
expect(reg.getProvider('WOW').id).toBe('native-monero');
expect(reg.getProvider('XMR').id).toBe('native-monero');
expect(reg.getProvider('BTC').id).toBe('native-monero'); // default provider, no routing entry
});
test('real BTCPay + native wallet: BTC/LTC -> btcpay, XMR/WOW stay native', () => {
const reg = buildProviderRegistry({
env: { BTCPAY_URL: 'u', BTCPAY_STORE_ID: 's', BTCPAY_API_KEY: 'k' },
walletService: fakeWallet
});
expect(reg.getProvider('BTC').id).toBe('btcpay');
expect(reg.getProvider('LTC').id).toBe('btcpay');
expect(reg.getProvider('XMR').id).toBe('native-monero');
expect(reg.getProvider('WOW').id).toBe('native-monero');
});
test('full LAN infra: BTC/LTC -> btcpay, XMR -> xmrcheckout, WOW -> wowcheckout', () => {
const reg = buildProviderRegistry({ env: CHECKOUT, walletService: fakeWallet });
expect(reg.getProvider('BTC').id).toBe('btcpay');
expect(reg.getProvider('LTC').id).toBe('btcpay');
expect(reg.getProvider('XMR').id).toBe('xmrcheckout'); // dedicated gateway wins over native
expect(reg.getProvider('WOW').id).toBe('wowcheckout');
});
test('a checkout gateway wins over the native wallet for its chain', () => {
const reg = buildProviderRegistry({
env: { XMRCHECKOUT_URL: 'http://10.42.1.33:8080', XMRCHECKOUT_STORE_ID: 'x', XMRCHECKOUT_API_KEY: 'k' },
walletService: fakeWallet
});
expect(reg.getProvider('XMR').id).toBe('xmrcheckout');
expect(reg.getProvider('WOW').id).toBe('native-monero'); // no wowcheckout -> native
});
test('BTCPAY_CHAINS widens the real BTCPay gateway', () => {
const reg = buildProviderRegistry({
env: { BTCPAY_URL: 'u', BTCPAY_STORE_ID: 's', BTCPAY_API_KEY: 'k', BTCPAY_CHAINS: 'btc,ltc,xmr' },
walletService: null
});
expect(reg.getProvider('XMR').id).toBe('btcpay');
});
test('PAYMENT_ROUTING override wins over defaults', () => {
const reg = buildProviderRegistry({
env: { ...CHECKOUT, PAYMENT_ROUTING: 'XMR:native-monero' },
walletService: fakeWallet
});
expect(reg.getProvider('XMR').id).toBe('native-monero'); // overrode the xmrcheckout default
expect(reg.getProvider('WOW').id).toBe('wowcheckout'); // untouched
});
});