tests
This commit is contained in:
@ -33,7 +33,7 @@ export const DefaultConnectTimeout = 2000;
|
||||
/**
|
||||
* How long profile cache should be considered valid for
|
||||
*/
|
||||
export const ProfileCacheExpire = 1_000 * 60 * 30;
|
||||
export const ProfileCacheExpire = 1_000 * 60 * 60 * 6;
|
||||
|
||||
/**
|
||||
* Default bootstrap relays
|
||||
|
@ -1,4 +1,5 @@
|
||||
import { TaggedRawEvent } from "@snort/nostr";
|
||||
import { describe, expect } from "@jest/globals";
|
||||
import { FlatNoteStore, ReplaceableNoteStore } from "./NoteCollection";
|
||||
|
||||
describe("NoteStore", () => {
|
||||
|
@ -1,4 +1,5 @@
|
||||
import { Connection } from "@snort/nostr";
|
||||
import { describe, expect } from "@jest/globals";
|
||||
import { Query } from "./Query";
|
||||
import { getRandomValues } from "crypto";
|
||||
import { FlatNoteStore } from "./NoteCollection";
|
||||
|
@ -1,4 +1,5 @@
|
||||
import { RequestBuilder } from "./RequestBuilder";
|
||||
import { describe, expect } from "@jest/globals";
|
||||
|
||||
describe("RequestBuilder", () => {
|
||||
describe("basic", () => {
|
||||
|
@ -1,4 +1,5 @@
|
||||
import { RawReqFilter } from "@snort/nostr";
|
||||
import { describe, expect } from "@jest/globals";
|
||||
import { diffFilters } from "./RequestSplitter";
|
||||
|
||||
describe("RequestSplitter", () => {
|
||||
|
@ -1,4 +1,5 @@
|
||||
import { splitByUrl, magnetURIDecode, getRelayName, validateNostrLink } from "./Util";
|
||||
import { describe, expect } from "@jest/globals";
|
||||
|
||||
describe("splitByUrl", () => {
|
||||
it("should split a string by URLs", () => {
|
||||
@ -12,8 +13,8 @@ describe("splitByUrl", () => {
|
||||
" but I made a ",
|
||||
"https://example.com",
|
||||
"! simple example (",
|
||||
"https://example.com",
|
||||
") of how ",
|
||||
"https://example.com)",
|
||||
" of how ",
|
||||
"https://example.com/yo-yo",
|
||||
" ",
|
||||
"https://example.example.com",
|
||||
@ -92,22 +93,18 @@ describe("getRelayName", () => {
|
||||
});
|
||||
|
||||
describe("validateNostrLink", () => {
|
||||
it("should return true for valid nostr links", () => {
|
||||
[
|
||||
"nostr:npub10elfcs4fr0l0r8af98jlmgdh9c8tcxjvz9qkw038js35mp4dma8qzvjptg",
|
||||
"web+nostr:npub10elfcs4fr0l0r8af98jlmgdh9c8tcxjvz9qkw038js35mp4dma8qzvjptg",
|
||||
"nostr:note15449edq4qa5wzgqvh8td0q0dp6hwtes4pknsrm7eygeenhlj99xsq94wu9",
|
||||
"nostr:nprofile1qqsrhuxx8l9ex335q7he0f09aej04zpazpl0ne2cgukyawd24mayt8gpp4mhxue69uhhytnc9e3k7mgpz4mhxue69uhkg6nzv9ejuumpv34kytnrdaksjlyr9p",
|
||||
"nostr:nevent1qqs226juks2sw68pyqxtn4khs8ksath9uc2smfcpalvjyvuemlezjngrd87dq",
|
||||
"nostr:naddr1qqzkjurnw4ksz9thwden5te0wfjkccte9ehx7um5wghx7un8qgs2d90kkcq3nk2jry62dyf50k0h36rhpdtd594my40w9pkal876jxgrqsqqqa28pccpzu",
|
||||
].forEach(link => {
|
||||
expect(validateNostrLink(link)).toBe(true);
|
||||
});
|
||||
test.each([
|
||||
"nostr:npub10elfcs4fr0l0r8af98jlmgdh9c8tcxjvz9qkw038js35mp4dma8qzvjptg",
|
||||
"web+nostr:npub10elfcs4fr0l0r8af98jlmgdh9c8tcxjvz9qkw038js35mp4dma8qzvjptg",
|
||||
"nostr:note15449edq4qa5wzgqvh8td0q0dp6hwtes4pknsrm7eygeenhlj99xsq94wu9",
|
||||
"nostr:nprofile1qqsrhuxx8l9ex335q7he0f09aej04zpazpl0ne2cgukyawd24mayt8gpp4mhxue69uhhytnc9e3k7mgpz4mhxue69uhkg6nzv9ejuumpv34kytnrdaksjlyr9p",
|
||||
"nostr:nevent1qqs226juks2sw68pyqxtn4khs8ksath9uc2smfcpalvjyvuemlezjngrd87dq",
|
||||
"nostr:naddr1qqzkjurnw4ksz9thwden5te0wfjkccte9ehx7um5wghx7un8qgs2d90kkcq3nk2jry62dyf50k0h36rhpdtd594my40w9pkal876jxgrqsqqqa28pccpzu",
|
||||
])("should return true for valid nostr links", la => {
|
||||
expect(validateNostrLink(la)).toBe(true);
|
||||
});
|
||||
|
||||
it("should return false for invalid nostr links", () => {
|
||||
["nostr:npub", "web+nostr:npub", "nostr:nevent1xxx"].forEach(link => {
|
||||
expect(validateNostrLink(link)).toBe(false);
|
||||
});
|
||||
test.each(["nostr:npub", "web+nostr:npub", "nostr:nevent1xxx"])("should return false for invalid nostr links", lb => {
|
||||
expect(validateNostrLink(lb)).toBe(false);
|
||||
});
|
||||
});
|
||||
|
@ -65,7 +65,7 @@ export function bech32ToHex(str: string) {
|
||||
const nKey = bech32.decode(str, 1_000);
|
||||
const buff = bech32.fromWords(nKey.words);
|
||||
return utils.bytesToHex(Uint8Array.from(buff));
|
||||
} catch {
|
||||
} catch (e) {
|
||||
return str;
|
||||
}
|
||||
}
|
||||
@ -517,11 +517,9 @@ export interface NostrLink {
|
||||
export function validateNostrLink(link: string): boolean {
|
||||
try {
|
||||
const parsedLink = parseNostrLink(link);
|
||||
|
||||
if (!parsedLink) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (parsedLink.type === NostrPrefix.PublicKey || parsedLink.type === NostrPrefix.Note) {
|
||||
return parsedLink.id.length === 64;
|
||||
}
|
||||
|
Reference in New Issue
Block a user