@bsv/overlay-express 2.2.1 → 2.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +33 -0
- package/dist/cjs/mod.js +4 -1
- package/dist/cjs/mod.js.map +1 -1
- package/dist/cjs/package.json +11 -10
- package/dist/cjs/src/OverlayExpress.js +27 -1
- package/dist/cjs/src/OverlayExpress.js.map +1 -1
- package/dist/cjs/src/OverlayMonitor.js +306 -0
- package/dist/cjs/src/OverlayMonitor.js.map +1 -0
- package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
- package/dist/esm/mod.js +1 -0
- package/dist/esm/mod.js.map +1 -1
- package/dist/esm/src/OverlayExpress.js +27 -1
- package/dist/esm/src/OverlayExpress.js.map +1 -1
- package/dist/esm/src/OverlayMonitor.js +304 -0
- package/dist/esm/src/OverlayMonitor.js.map +1 -0
- package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
- package/dist/types/mod.d.ts +1 -0
- package/dist/types/mod.d.ts.map +1 -1
- package/dist/types/src/OverlayExpress.d.ts +6 -0
- package/dist/types/src/OverlayExpress.d.ts.map +1 -1
- package/dist/types/src/OverlayMonitor.d.ts +125 -0
- package/dist/types/src/OverlayMonitor.d.ts.map +1 -0
- package/dist/types/tsconfig.types.tsbuildinfo +1 -1
- package/mod.ts +13 -0
- package/package.json +11 -10
- package/src/OverlayExpress.ts +30 -2
- package/src/OverlayMonitor.ts +445 -0
- package/src/__tests__/OverlayExpress.test.ts +86 -1
- package/src/__tests__/OverlayMonitor.test.ts +116 -0
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { describe, it, expect, jest } from '@jest/globals'
|
|
2
|
+
import { Transaction } from '@bsv/sdk'
|
|
3
|
+
import { OverlayMonitor, analyzeOverlayLookupResponse } from '../OverlayMonitor.js'
|
|
4
|
+
|
|
5
|
+
describe('OverlayMonitor', () => {
|
|
6
|
+
it('summarizes an empty lookup response', () => {
|
|
7
|
+
const result = analyzeOverlayLookupResponse({
|
|
8
|
+
target: 'local-overlay',
|
|
9
|
+
url: 'https://overlay.example/lookup',
|
|
10
|
+
probe: 'empty',
|
|
11
|
+
service: 'ls_empty',
|
|
12
|
+
status: 200,
|
|
13
|
+
ok: true,
|
|
14
|
+
responseBody: { outputs: [] },
|
|
15
|
+
responseBytes: 14,
|
|
16
|
+
durationMs: 5
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
expect(result.outputCount).toBe(0)
|
|
20
|
+
expect(result.analyzedOutputCount).toBe(0)
|
|
21
|
+
expect(result.warnings).toHaveLength(0)
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
it('reports missing subject proofs in returned BEEF', () => {
|
|
25
|
+
const tx = new Transaction(1, [], [], 0)
|
|
26
|
+
const result = analyzeOverlayLookupResponse({
|
|
27
|
+
target: 'local-overlay',
|
|
28
|
+
url: 'https://overlay.example/lookup',
|
|
29
|
+
probe: 'proof-shape',
|
|
30
|
+
service: 'ls_ship',
|
|
31
|
+
status: 200,
|
|
32
|
+
ok: true,
|
|
33
|
+
responseBody: {
|
|
34
|
+
outputs: [
|
|
35
|
+
{
|
|
36
|
+
outputIndex: 0,
|
|
37
|
+
beef: tx.toBEEF()
|
|
38
|
+
}
|
|
39
|
+
]
|
|
40
|
+
},
|
|
41
|
+
responseBytes: 512,
|
|
42
|
+
durationMs: 5
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
expect(result.outputs[0].txid).toBe(tx.id('hex'))
|
|
46
|
+
expect(result.outputs[0].subjectHasProof).toBe(false)
|
|
47
|
+
expect(result.outputs[0].txCount).toBe(1)
|
|
48
|
+
expect(result.warnings.map(warning => warning.code)).toContain('subject-proof-missing')
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
it('runs configured probes through Overlay Express lookup endpoints', async () => {
|
|
52
|
+
const tx = new Transaction(1, [], [], 0)
|
|
53
|
+
const responseBody = JSON.stringify({
|
|
54
|
+
outputs: [
|
|
55
|
+
{
|
|
56
|
+
outputIndex: 0,
|
|
57
|
+
beef: tx.toBEEF()
|
|
58
|
+
}
|
|
59
|
+
]
|
|
60
|
+
})
|
|
61
|
+
const fetchImpl = jest.fn<typeof fetch>(async () => new Response(responseBody, { status: 200 }))
|
|
62
|
+
const monitor = new OverlayMonitor({
|
|
63
|
+
targets: [
|
|
64
|
+
{
|
|
65
|
+
name: 'local-overlay',
|
|
66
|
+
baseUrl: 'https://overlay.example',
|
|
67
|
+
probes: [
|
|
68
|
+
{
|
|
69
|
+
name: 'ship',
|
|
70
|
+
service: 'ls_ship',
|
|
71
|
+
query: { topics: ['tm_example'] }
|
|
72
|
+
}
|
|
73
|
+
]
|
|
74
|
+
}
|
|
75
|
+
],
|
|
76
|
+
fetchImpl
|
|
77
|
+
})
|
|
78
|
+
|
|
79
|
+
const report = await monitor.runOnce()
|
|
80
|
+
|
|
81
|
+
expect(fetchImpl).toHaveBeenCalledWith('https://overlay.example/lookup', expect.objectContaining({
|
|
82
|
+
method: 'POST',
|
|
83
|
+
body: JSON.stringify({ service: 'ls_ship', query: { topics: ['tm_example'] } })
|
|
84
|
+
}))
|
|
85
|
+
expect(report.summary.targetCount).toBe(1)
|
|
86
|
+
expect(report.summary.probeCount).toBe(1)
|
|
87
|
+
expect(report.summary.outputsMissingSubjectProof).toBe(1)
|
|
88
|
+
})
|
|
89
|
+
|
|
90
|
+
it('aborts a probe that exceeds the configured timeout', async () => {
|
|
91
|
+
// Never resolves on its own; only settles when the abort signal fires.
|
|
92
|
+
const fetchImpl = jest.fn<typeof fetch>(async (_url, init) => await new Promise<Response>((_resolve, reject) => {
|
|
93
|
+
init?.signal?.addEventListener('abort', () => reject(new Error('aborted')))
|
|
94
|
+
}))
|
|
95
|
+
const monitor = new OverlayMonitor({
|
|
96
|
+
targets: [
|
|
97
|
+
{
|
|
98
|
+
name: 'slow-overlay',
|
|
99
|
+
baseUrl: 'https://overlay.example',
|
|
100
|
+
probes: [{ name: 'slow', service: 'ls_slow', query: {} }]
|
|
101
|
+
}
|
|
102
|
+
],
|
|
103
|
+
fetchImpl,
|
|
104
|
+
timeoutMs: 10
|
|
105
|
+
})
|
|
106
|
+
|
|
107
|
+
const report = await monitor.runOnce()
|
|
108
|
+
|
|
109
|
+
expect(fetchImpl).toHaveBeenCalledWith('https://overlay.example/lookup', expect.objectContaining({
|
|
110
|
+
signal: expect.anything()
|
|
111
|
+
}))
|
|
112
|
+
expect(report.results[0].ok).toBe(false)
|
|
113
|
+
expect(report.results[0].error).toContain('timed out')
|
|
114
|
+
expect(report.summary.failedProbeCount).toBe(1)
|
|
115
|
+
})
|
|
116
|
+
})
|