diff options
Diffstat (limited to 'tests/integration/test-relay-nip11.mjs')
| -rw-r--r-- | tests/integration/test-relay-nip11.mjs | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/tests/integration/test-relay-nip11.mjs b/tests/integration/test-relay-nip11.mjs new file mode 100644 index 0000000..422ae6a --- /dev/null +++ b/tests/integration/test-relay-nip11.mjs | |||
| @@ -0,0 +1,86 @@ | |||
| 1 | import { execSync } from 'child_process'; | ||
| 2 | |||
| 3 | const IP = process.env.TOLLGATE_IP || '10.192.45.1'; | ||
| 4 | const RELAY_PORT = 4869; | ||
| 5 | const RELAY_URL = `http://${IP}:${RELAY_PORT}`; | ||
| 6 | |||
| 7 | let passed = 0, failed = 0; | ||
| 8 | |||
| 9 | function assert(condition, test) { | ||
| 10 | if (condition) { console.log(` \u2713 ${test}`); passed++; } | ||
| 11 | else { console.log(` \u2717 ${test}`); failed++; } | ||
| 12 | } | ||
| 13 | |||
| 14 | async function runTests() { | ||
| 15 | console.log(`\n=== NIP-11 Relay Info Tests (target: ${RELAY_URL}) ===\n`); | ||
| 16 | |||
| 17 | console.log('--- Test 1: NIP-11 info document ---'); | ||
| 18 | let nip11; | ||
| 19 | try { | ||
| 20 | nip11 = execSync( | ||
| 21 | `curl -s --connect-timeout 5 -H "Accept: application/nostr+json" "${RELAY_URL}"`, | ||
| 22 | { encoding: 'utf8', timeout: 8000 } | ||
| 23 | ); | ||
| 24 | } catch (e) { | ||
| 25 | console.log(` Failed to fetch NIP-11: ${e.message}`); | ||
| 26 | console.log(`\n=== Results: ${passed} passed, ${failed} failed ===\n`); | ||
| 27 | process.exit(1); | ||
| 28 | } | ||
| 29 | |||
| 30 | let doc; | ||
| 31 | try { | ||
| 32 | doc = JSON.parse(nip11); | ||
| 33 | assert(true, 'NIP-11 returns valid JSON'); | ||
| 34 | } catch (e) { | ||
| 35 | assert(false, `NIP-11 returns valid JSON — ${e.message}`); | ||
| 36 | console.log(` Response: ${nip11.substring(0, 200)}`); | ||
| 37 | console.log(`\n=== Results: ${passed} passed, ${failed} failed ===\n`); | ||
| 38 | process.exit(1); | ||
| 39 | } | ||
| 40 | |||
| 41 | console.log('\n--- Test 2: Required NIP-11 fields ---'); | ||
| 42 | assert(typeof doc.name === 'string' && doc.name.length > 0, `name: "${doc.name}"`); | ||
| 43 | assert(typeof doc.description === 'string' && doc.description.length > 0, `description present (${doc.description.length} chars)`); | ||
| 44 | assert(typeof doc.software === 'string', `software: "${doc.software}"`); | ||
| 45 | assert(typeof doc.version === 'string', `version: "${doc.version}"`); | ||
| 46 | |||
| 47 | console.log('\n--- Test 3: NIP support ---'); | ||
| 48 | assert(Array.isArray(doc.supported_nips), 'supported_nips is array'); | ||
| 49 | if (Array.isArray(doc.supported_nips)) { | ||
| 50 | assert(doc.supported_nips.includes(1), 'NIP-01 (basic protocol) supported'); | ||
| 51 | assert(doc.supported_nips.includes(9), 'NIP-09 (deletion) supported'); | ||
| 52 | assert(doc.supported_nips.includes(11), 'NIP-11 (relay info) supported'); | ||
| 53 | console.log(` Supported NIPs: ${doc.supported_nips.join(', ')}`); | ||
| 54 | } | ||
| 55 | |||
| 56 | console.log('\n--- Test 4: TollGate-specific fields ---'); | ||
| 57 | if (doc.name) assert(doc.name.includes('TollGate') || doc.name.includes('4869'), | ||
| 58 | 'Name mentions TollGate or port 4869'); | ||
| 59 | if (doc.supported_nips && doc.limitation) { | ||
| 60 | console.log(` Limitations: ${JSON.stringify(doc.limitation)}`); | ||
| 61 | } | ||
| 62 | |||
| 63 | console.log('\n--- Test 5: HTTP without Accept header returns HTML (not NIP-11) ---'); | ||
| 64 | try { | ||
| 65 | const html = execSync( | ||
| 66 | `curl -s --connect-timeout 5 "${RELAY_URL}"`, | ||
| 67 | { encoding: 'utf8', timeout: 8000 } | ||
| 68 | ); | ||
| 69 | try { | ||
| 70 | JSON.parse(html); | ||
| 71 | assert(false, 'Without Accept header, returns non-JSON (HTML page)'); | ||
| 72 | } catch { | ||
| 73 | assert(true, 'Without Accept header, returns non-JSON (HTML page)'); | ||
| 74 | } | ||
| 75 | } catch (e) { | ||
| 76 | assert(true, 'Without Accept header, returns non-JSON or empty'); | ||
| 77 | } | ||
| 78 | |||
| 79 | console.log(`\n=== Results: ${passed} passed, ${failed} failed ===\n`); | ||
| 80 | process.exit(failed > 0 ? 1 : 0); | ||
| 81 | } | ||
| 82 | |||
| 83 | runTests().catch(e => { | ||
| 84 | console.error('Test error:', e.message); | ||
| 85 | process.exit(1); | ||
| 86 | }); | ||