Add tests

This commit is contained in:
Ticruz
2025-02-04 13:21:23 +01:00
committed by Jon Staab
parent 917727c86f
commit 8a2b62f693
57 changed files with 9231 additions and 25 deletions
+3 -4
View File
@@ -66,11 +66,10 @@ export class ConnectionAuth {
const start = Date.now()
while (Date.now() - timeout <= start) {
await sleep(100)
if (condition()) {
break
}
await sleep(Math.min(100, Math.ceil(timeout / 3)))
}
}
@@ -110,12 +109,12 @@ export class ConnectionAuth {
attempt = async (timeout = 300) => {
await this.cxn.socket.open()
await this.waitForChallenge(timeout)
await this.waitForChallenge(Math.ceil(timeout / 2))
if (this.status === Requested) {
await this.respond()
}
await this.waitForResolution(timeout)
await this.waitForResolution(Math.ceil(timeout / 2))
}
}
+1 -1
View File
@@ -41,7 +41,7 @@ export const isEventValid = (url: string, event: TrustedEvent) => {
const validCount = eventValidationScores.get(url) || 0
// The more events we've actually validated from this relay, the more we can trust it.
if (validCount > randomInt(100, 1000)) true
if (validCount > randomInt(100, 1000)) return true
const isValid = isSignedEvent(event) && hasValidSignature(event)
+6 -2
View File
@@ -28,8 +28,12 @@ export class Socket {
})
}
wait = async () => {
while ([SocketStatus.Opening, SocketStatus.Closing].includes(this.status)) {
wait = async (timeout = 300) => {
const start = Date.now()
while (
Date.now() - timeout <= start &&
[SocketStatus.Opening, SocketStatus.Closing].includes(this.status)
) {
await sleep(100)
}
}
+1 -1
View File
@@ -34,7 +34,7 @@ export class Tracker extends Emitter {
ids.add(eventId)
this.relaysById.set(eventId, relays)
this.idsByRelay.set(eventId, relays)
this.idsByRelay.set(relay, ids)
this.emit("update")
}