|
| 1 | +import { describe, expect, test } from '@jest/globals' |
| 2 | + |
| 3 | +import { SPECIAL_CURRENCY_INFO } from '../constants/WalletAndCurrencyConstants' |
| 4 | +import { isMoneroEdgeLws } from '../util/monero' |
| 5 | + |
| 6 | +describe('isMoneroEdgeLws', () => { |
| 7 | + test('Edge LWS when custom servers are disabled', () => { |
| 8 | + expect( |
| 9 | + isMoneroEdgeLws({ |
| 10 | + enableCustomServers: false, |
| 11 | + enableCustomMonerod: false, |
| 12 | + moneroLightwalletServer: '', |
| 13 | + monerodServer: '' |
| 14 | + }) |
| 15 | + ).toBe(true) |
| 16 | + }) |
| 17 | + |
| 18 | + test('Edge LWS when the custom server points at an Edge host', () => { |
| 19 | + expect( |
| 20 | + isMoneroEdgeLws({ |
| 21 | + enableCustomServers: true, |
| 22 | + enableCustomMonerod: false, |
| 23 | + moneroLightwalletServer: 'https://monerolws1.edge.app', |
| 24 | + monerodServer: '' |
| 25 | + }) |
| 26 | + ).toBe(true) |
| 27 | + }) |
| 28 | + |
| 29 | + test('custom LWS when the custom server points elsewhere', () => { |
| 30 | + expect( |
| 31 | + isMoneroEdgeLws({ |
| 32 | + enableCustomServers: true, |
| 33 | + enableCustomMonerod: false, |
| 34 | + moneroLightwalletServer: 'https://my.node.example.com', |
| 35 | + monerodServer: '' |
| 36 | + }) |
| 37 | + ).toBe(false) |
| 38 | + }) |
| 39 | +}) |
| 40 | + |
| 41 | +describe('monero checkImportedWalletSettings', () => { |
| 42 | + const check = SPECIAL_CURRENCY_INFO.monero.checkImportedWalletSettings |
| 43 | + if (check == null) |
| 44 | + throw new Error('monero checkImportedWalletSettings missing') |
| 45 | + |
| 46 | + test('overrides lws -> monerod when using Edge LWS (default settings)', () => { |
| 47 | + const result = check( |
| 48 | + { backend: 'lws' }, |
| 49 | + { enableCustomServers: false, moneroLightwalletServer: '' } |
| 50 | + ) |
| 51 | + expect(result?.settings.backend).toBe('monerod') |
| 52 | + expect(result?.warning).toBeTruthy() |
| 53 | + }) |
| 54 | + |
| 55 | + test('allows lws when using a custom (non-Edge) LWS server', () => { |
| 56 | + const result = check( |
| 57 | + { backend: 'lws' }, |
| 58 | + { |
| 59 | + enableCustomServers: true, |
| 60 | + moneroLightwalletServer: 'https://my.node.example.com' |
| 61 | + } |
| 62 | + ) |
| 63 | + expect(result).toBeUndefined() |
| 64 | + }) |
| 65 | + |
| 66 | + test('overrides lws -> monerod when the custom server is an Edge LWS host', () => { |
| 67 | + const result = check( |
| 68 | + { backend: 'lws' }, |
| 69 | + { |
| 70 | + enableCustomServers: true, |
| 71 | + moneroLightwalletServer: 'https://monerolws2.edge.app' |
| 72 | + } |
| 73 | + ) |
| 74 | + expect(result?.settings.backend).toBe('monerod') |
| 75 | + }) |
| 76 | + |
| 77 | + test('no override when the backend is already monerod', () => { |
| 78 | + const result = check( |
| 79 | + { backend: 'monerod' }, |
| 80 | + { enableCustomServers: false, moneroLightwalletServer: '' } |
| 81 | + ) |
| 82 | + expect(result).toBeUndefined() |
| 83 | + }) |
| 84 | + |
| 85 | + test('treats an unset backend as needing the override under Edge LWS', () => { |
| 86 | + const result = check( |
| 87 | + {}, |
| 88 | + { enableCustomServers: false, moneroLightwalletServer: '' } |
| 89 | + ) |
| 90 | + expect(result?.settings.backend).toBe('monerod') |
| 91 | + }) |
| 92 | + |
| 93 | + test('overrides lws -> monerod for an account with empty user settings', () => { |
| 94 | + // A never-configured account stores `{}`; it resolves to Edge LWS, so an |
| 95 | + // imported lws wallet must still be pushed to the full node. |
| 96 | + const result = check({ backend: 'lws' }, {}) |
| 97 | + expect(result?.settings.backend).toBe('monerod') |
| 98 | + expect(result?.warning).toBeTruthy() |
| 99 | + }) |
| 100 | +}) |
0 commit comments