Add tests
This commit is contained in:
@@ -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))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user