diff options
Diffstat (limited to 'tests/integration')
| -rw-r--r-- | tests/integration/test-cvm.mjs | 94 |
1 files changed, 94 insertions, 0 deletions
diff --git a/tests/integration/test-cvm.mjs b/tests/integration/test-cvm.mjs new file mode 100644 index 0000000..8deb6ec --- /dev/null +++ b/tests/integration/test-cvm.mjs | |||
| @@ -0,0 +1,94 @@ | |||
| 1 | import { execSync } from 'child_process'; | ||
| 2 | |||
| 3 | const IP = process.env.TOLLGATE_IP || '10.192.45.1'; | ||
| 4 | const RELAYS = ['wss://relay.damus.io', 'wss://nos.lol']; | ||
| 5 | |||
| 6 | let passed = 0, failed = 0; | ||
| 7 | |||
| 8 | function assert(condition, test) { | ||
| 9 | if (condition) { console.log(` \u2713 ${test}`); passed++; } | ||
| 10 | else { console.log(` \u2717 ${test}`); failed++; } | ||
| 11 | } | ||
| 12 | |||
| 13 | function nak(args, timeout = 10000) { | ||
| 14 | try { | ||
| 15 | return execSync(`timeout ${timeout / 1000} nak ${args}`, { | ||
| 16 | encoding: 'utf8', | ||
| 17 | stdio: ['pipe', 'pipe', 'pipe'], | ||
| 18 | timeout | ||
| 19 | }).trim(); | ||
| 20 | } catch (e) { | ||
| 21 | return e.stdout ? e.stdout.trim() : ''; | ||
| 22 | } | ||
| 23 | } | ||
| 24 | |||
| 25 | function sleep(ms) { return new Promise(r => setTimeout(r, ms)); } | ||
| 26 | |||
| 27 | async function runTests() { | ||
| 28 | console.log(`\n=== CVM Integration Tests (target: ${IP}) ===\n`); | ||
| 29 | |||
| 30 | const npub = nak(`key public a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2`); | ||
| 31 | const npubHex = npub.trim(); | ||
| 32 | console.log(`Board npub: ${npubHex}`); | ||
| 33 | |||
| 34 | const npubBech32 = nak(`encode npub ${npubHex}`).trim(); | ||
| 35 | console.log(`Board npub (bech32): ${npubBech32}`); | ||
| 36 | |||
| 37 | assert(npubHex.length === 64, 'npub hex is 64 chars'); | ||
| 38 | |||
| 39 | console.log('\n--- Test: Kind 11316 server announcement ---'); | ||
| 40 | for (const relay of RELAYS) { | ||
| 41 | console.log(` Querying ${relay}...`); | ||
| 42 | const result = nak(`req -k 11316 -a ${npubHex} -l 1 ${relay}`, 8000); | ||
| 43 | if (result.length > 0) { | ||
| 44 | assert(result.includes('"kind"') || result.includes('11316'), | ||
| 45 | `Kind 11316 found on ${relay}`); | ||
| 46 | if (result.includes('TollGate')) { | ||
| 47 | assert(true, `Announcement contains "TollGate"`); | ||
| 48 | } | ||
| 49 | } else { | ||
| 50 | console.log(` (no result from ${relay} — relay may be offline)`); | ||
| 51 | } | ||
| 52 | } | ||
| 53 | |||
| 54 | console.log('\n--- Test: Kind 11317 tools list ---'); | ||
| 55 | for (const relay of RELAYS) { | ||
| 56 | const result = nak(`req -k 11317 -a ${npubHex} -l 1 ${relay}`, 8000); | ||
| 57 | if (result.length > 0) { | ||
| 58 | assert(result.includes('"kind"') || result.includes('11317'), | ||
| 59 | `Kind 11317 found on ${relay}`); | ||
| 60 | if (result.includes('get_config') && result.includes('wallet_melt')) { | ||
| 61 | assert(true, `Tools list has expected tools`); | ||
| 62 | } | ||
| 63 | } else { | ||
| 64 | console.log(` (no result from ${relay} — relay may be offline)`); | ||
| 65 | } | ||
| 66 | } | ||
| 67 | |||
| 68 | console.log('\n--- Test: Kind 10002 relay list ---'); | ||
| 69 | for (const relay of RELAYS) { | ||
| 70 | const result = nak(`req -k 10002 -a ${npubHex} -l 1 ${relay}`, 8000); | ||
| 71 | if (result.length > 0) { | ||
| 72 | assert(result.includes('"kind"') || result.includes('10002'), | ||
| 73 | `Kind 10002 found on ${relay}`); | ||
| 74 | } else { | ||
| 75 | console.log(` (no result from ${relay} — relay may be offline)`); | ||
| 76 | } | ||
| 77 | } | ||
| 78 | |||
| 79 | console.log('\n--- Test: API get_config (control check) ---'); | ||
| 80 | try { | ||
| 81 | const apiResult = execSync(`curl -s http://${IP}:2121/usage`, { encoding: 'utf8', timeout: 5000 }); | ||
| 82 | assert(apiResult.length > 0, 'API /usage responds (board is reachable)'); | ||
| 83 | } catch (e) { | ||
| 84 | console.log(' (API not reachable — board may be offline or not flashed yet)'); | ||
| 85 | } | ||
| 86 | |||
| 87 | console.log(`\n=== Results: ${passed} passed, ${failed} failed ===\n`); | ||
| 88 | process.exit(failed > 0 ? 1 : 0); | ||
| 89 | } | ||
| 90 | |||
| 91 | runTests().catch(e => { | ||
| 92 | console.error('Test error:', e.message); | ||
| 93 | process.exit(1); | ||
| 94 | }); | ||