fixing tests
This commit is contained in:
parent
8dfe0f25d4
commit
5f29ae0140
2
.github/workflows/test-lint.yaml
vendored
2
.github/workflows/test-lint.yaml
vendored
@ -11,7 +11,7 @@ jobs:
|
|||||||
- name: Setup Node.js
|
- name: Setup Node.js
|
||||||
uses: actions/setup-node@v3
|
uses: actions/setup-node@v3
|
||||||
with:
|
with:
|
||||||
node-version: 16
|
node-version: 19
|
||||||
- name: Install Dependencies
|
- name: Install Dependencies
|
||||||
run: yarn install
|
run: yarn install
|
||||||
- name: Build packages
|
- name: Build packages
|
||||||
|
@ -36,7 +36,6 @@
|
|||||||
"throttle-debounce": "^5.0.0",
|
"throttle-debounce": "^5.0.0",
|
||||||
"unist-util-visit": "^4.1.2",
|
"unist-util-visit": "^4.1.2",
|
||||||
"use-long-press": "^2.0.3",
|
"use-long-press": "^2.0.3",
|
||||||
"uuid": "^9.0.0",
|
|
||||||
"workbox-background-sync": "^6.4.2",
|
"workbox-background-sync": "^6.4.2",
|
||||||
"workbox-broadcast-update": "^6.4.2",
|
"workbox-broadcast-update": "^6.4.2",
|
||||||
"workbox-cacheable-response": "^6.4.2",
|
"workbox-cacheable-response": "^6.4.2",
|
||||||
@ -85,7 +84,6 @@
|
|||||||
"@types/node": "^18.11.18",
|
"@types/node": "^18.11.18",
|
||||||
"@types/react": "^18.0.26",
|
"@types/react": "^18.0.26",
|
||||||
"@types/react-dom": "^18.0.10",
|
"@types/react-dom": "^18.0.10",
|
||||||
"@types/uuid": "^9.0.0",
|
|
||||||
"@types/webscopeio__react-textarea-autocomplete": "^4.7.2",
|
"@types/webscopeio__react-textarea-autocomplete": "^4.7.2",
|
||||||
"@types/webtorrent": "^0.109.3",
|
"@types/webtorrent": "^0.109.3",
|
||||||
"@webscopeio/react-textarea-autocomplete": "^4.9.2",
|
"@webscopeio/react-textarea-autocomplete": "^4.9.2",
|
||||||
|
@ -1,6 +1,10 @@
|
|||||||
import { Connection, RelaySettings } from "@snort/nostr";
|
import { Connection } from "@snort/nostr";
|
||||||
import { unixNow } from "Util";
|
import { unixNow } from "Util";
|
||||||
import { Query } from "./Query";
|
import { Query } from "./Query";
|
||||||
|
import { getRandomValues } from "crypto";
|
||||||
|
|
||||||
|
window.crypto = {} as any;
|
||||||
|
window.crypto.getRandomValues = getRandomValues as any;
|
||||||
|
|
||||||
describe("query", () => {
|
describe("query", () => {
|
||||||
test("progress", () => {
|
test("progress", () => {
|
||||||
@ -16,7 +20,7 @@ describe("query", () => {
|
|||||||
const opt = {
|
const opt = {
|
||||||
read: true,
|
read: true,
|
||||||
write: true,
|
write: true,
|
||||||
} as RelaySettings;
|
};
|
||||||
const c1 = new Connection("wss://one.com", opt);
|
const c1 = new Connection("wss://one.com", opt);
|
||||||
c1.Down = false;
|
c1.Down = false;
|
||||||
const c2 = new Connection("wss://two.com", opt);
|
const c2 = new Connection("wss://two.com", opt);
|
||||||
|
@ -31,12 +31,14 @@
|
|||||||
"@noble/hashes": "^1.2.0",
|
"@noble/hashes": "^1.2.0",
|
||||||
"@noble/secp256k1": "^1.7.1",
|
"@noble/secp256k1": "^1.7.1",
|
||||||
"@types/chai": "^4.3.4",
|
"@types/chai": "^4.3.4",
|
||||||
|
"@types/uuid": "^9.0.1",
|
||||||
"base64-js": "^1.5.1",
|
"base64-js": "^1.5.1",
|
||||||
"bech32": "^2.0.0",
|
"bech32": "^2.0.0",
|
||||||
"chai": "^4.3.7",
|
"chai": "^4.3.7",
|
||||||
"events": "^3.3.0",
|
"events": "^3.3.0",
|
||||||
"isomorphic-ws": "^5.0.0",
|
"isomorphic-ws": "^5.0.0",
|
||||||
"ts-loader": "^9.4.2",
|
"ts-loader": "^9.4.2",
|
||||||
|
"uuid": "^9.0.0",
|
||||||
"webpack": "^5.77.0",
|
"webpack": "^5.77.0",
|
||||||
"webpack-cli": "^5.0.1",
|
"webpack-cli": "^5.0.1",
|
||||||
"ws": "^8.12.1"
|
"ws": "^8.12.1"
|
||||||
|
@ -7,7 +7,10 @@ import { RelayInfo } from "./RelayInfo";
|
|||||||
import { unwrap } from "./Util";
|
import { unwrap } from "./Util";
|
||||||
|
|
||||||
export type CustomHook = (state: Readonly<StateSnapshot>) => void;
|
export type CustomHook = (state: Readonly<StateSnapshot>) => void;
|
||||||
export type AuthHandler = (challenge: string, relay: string) => Promise<RawEvent | undefined>;
|
export type AuthHandler = (
|
||||||
|
challenge: string,
|
||||||
|
relay: string
|
||||||
|
) => Promise<RawEvent | undefined>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Relay settings
|
* Relay settings
|
||||||
@ -15,7 +18,7 @@ export type AuthHandler = (challenge: string, relay: string) => Promise<RawEvent
|
|||||||
export interface RelaySettings {
|
export interface RelaySettings {
|
||||||
read: boolean;
|
read: boolean;
|
||||||
write: boolean;
|
write: boolean;
|
||||||
};
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Snapshot of connection stats
|
* Snapshot of connection stats
|
||||||
@ -32,7 +35,7 @@ export interface StateSnapshot {
|
|||||||
pendingRequests: Array<string>;
|
pendingRequests: Array<string>;
|
||||||
activeRequests: Array<string>;
|
activeRequests: Array<string>;
|
||||||
id: string;
|
id: string;
|
||||||
};
|
}
|
||||||
|
|
||||||
export class Connection {
|
export class Connection {
|
||||||
Id: string;
|
Id: string;
|
||||||
@ -64,7 +67,12 @@ export class Connection {
|
|||||||
EphemeralTimeout: ReturnType<typeof setTimeout> | undefined;
|
EphemeralTimeout: ReturnType<typeof setTimeout> | undefined;
|
||||||
Down = true;
|
Down = true;
|
||||||
|
|
||||||
constructor(addr: string, options: RelaySettings, auth?: AuthHandler, ephemeral: boolean = false) {
|
constructor(
|
||||||
|
addr: string,
|
||||||
|
options: RelaySettings,
|
||||||
|
auth?: AuthHandler,
|
||||||
|
ephemeral: boolean = false
|
||||||
|
) {
|
||||||
this.Id = uuid();
|
this.Id = uuid();
|
||||||
this.Address = addr;
|
this.Address = addr;
|
||||||
this.Settings = options;
|
this.Settings = options;
|
||||||
@ -106,11 +114,14 @@ export class Connection {
|
|||||||
try {
|
try {
|
||||||
if (this.Info === undefined) {
|
if (this.Info === undefined) {
|
||||||
const u = new URL(this.Address);
|
const u = new URL(this.Address);
|
||||||
const rsp = await fetch(`${u.protocol === "wss:" ? "https:" : "http:"}//${u.host}`, {
|
const rsp = await fetch(
|
||||||
headers: {
|
`${u.protocol === "wss:" ? "https:" : "http:"}//${u.host}`,
|
||||||
accept: "application/nostr+json",
|
{
|
||||||
},
|
headers: {
|
||||||
});
|
accept: "application/nostr+json",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
);
|
||||||
if (rsp.ok) {
|
if (rsp.ok) {
|
||||||
const data = await rsp.json();
|
const data = await rsp.json();
|
||||||
for (const [k, v] of Object.entries(data)) {
|
for (const [k, v] of Object.entries(data)) {
|
||||||
@ -327,8 +338,8 @@ export class Connection {
|
|||||||
|
|
||||||
#ResetQueues() {
|
#ResetQueues() {
|
||||||
//send EOSE on disconnect for active subs
|
//send EOSE on disconnect for active subs
|
||||||
this.ActiveRequests.forEach(v => this.OnEose?.(v))
|
this.ActiveRequests.forEach((v) => this.OnEose?.(v));
|
||||||
this.PendingRequests.forEach(v => this.OnEose?.(v[1]));
|
this.PendingRequests.forEach((v) => this.OnEose?.(v[1]));
|
||||||
|
|
||||||
this.ActiveRequests.clear();
|
this.ActiveRequests.clear();
|
||||||
this.PendingRequests = [];
|
this.PendingRequests = [];
|
||||||
@ -343,12 +354,14 @@ export class Connection {
|
|||||||
this.CurrentState.avgLatency =
|
this.CurrentState.avgLatency =
|
||||||
this.Stats.Latency.length > 0
|
this.Stats.Latency.length > 0
|
||||||
? this.Stats.Latency.reduce((acc, v) => acc + v, 0) /
|
? this.Stats.Latency.reduce((acc, v) => acc + v, 0) /
|
||||||
this.Stats.Latency.length
|
this.Stats.Latency.length
|
||||||
: 0;
|
: 0;
|
||||||
this.CurrentState.disconnects = this.Stats.Disconnects;
|
this.CurrentState.disconnects = this.Stats.Disconnects;
|
||||||
this.CurrentState.info = this.Info;
|
this.CurrentState.info = this.Info;
|
||||||
this.CurrentState.id = this.Id;
|
this.CurrentState.id = this.Id;
|
||||||
this.CurrentState.pendingRequests = [...this.PendingRequests.map(a => a[1])];
|
this.CurrentState.pendingRequests = [
|
||||||
|
...this.PendingRequests.map((a) => a[1]),
|
||||||
|
];
|
||||||
this.CurrentState.activeRequests = [...this.ActiveRequests];
|
this.CurrentState.activeRequests = [...this.ActiveRequests];
|
||||||
this.Stats.Latency = this.Stats.Latency.slice(-20); // trim
|
this.Stats.Latency = this.Stats.Latency.slice(-20); // trim
|
||||||
this.HasStateChange = true;
|
this.HasStateChange = true;
|
||||||
|
@ -27,5 +27,9 @@ module.exports = {
|
|||||||
output: {
|
output: {
|
||||||
filename: "[name].js",
|
filename: "[name].js",
|
||||||
path: `${__dirname}/dist`,
|
path: `${__dirname}/dist`,
|
||||||
|
library: {
|
||||||
|
type: "umd",
|
||||||
|
name: "Nostr",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -2470,7 +2470,7 @@
|
|||||||
resolved "https://registry.yarnpkg.com/@types/use-sync-external-store/-/use-sync-external-store-0.0.3.tgz#b6725d5f4af24ace33b36fafd295136e75509f43"
|
resolved "https://registry.yarnpkg.com/@types/use-sync-external-store/-/use-sync-external-store-0.0.3.tgz#b6725d5f4af24ace33b36fafd295136e75509f43"
|
||||||
integrity sha512-EwmlvuaxPNej9+T4v5AuBPJa2x2UOJVdjCtDHgcDqitUeOtjnJKJ+apYjVcAoBEMjKW1VVFGZLUb5+qqa09XFA==
|
integrity sha512-EwmlvuaxPNej9+T4v5AuBPJa2x2UOJVdjCtDHgcDqitUeOtjnJKJ+apYjVcAoBEMjKW1VVFGZLUb5+qqa09XFA==
|
||||||
|
|
||||||
"@types/uuid@^9.0.0":
|
"@types/uuid@^9.0.1":
|
||||||
version "9.0.1"
|
version "9.0.1"
|
||||||
resolved "https://registry.yarnpkg.com/@types/uuid/-/uuid-9.0.1.tgz#98586dc36aee8dacc98cc396dbca8d0429647aa6"
|
resolved "https://registry.yarnpkg.com/@types/uuid/-/uuid-9.0.1.tgz#98586dc36aee8dacc98cc396dbca8d0429647aa6"
|
||||||
integrity sha512-rFT3ak0/2trgvp4yYZo5iKFEPsET7vKydKF+VRCxlQ9bpheehyAJH89dAkaLEq/j/RZXJIqcgsmPJKUP1Z28HA==
|
integrity sha512-rFT3ak0/2trgvp4yYZo5iKFEPsET7vKydKF+VRCxlQ9bpheehyAJH89dAkaLEq/j/RZXJIqcgsmPJKUP1Z28HA==
|
||||||
|
Loading…
x
Reference in New Issue
Block a user