From e398617fdc0013fdbc1e074ab6dbaeeda6ec69bf Mon Sep 17 00:00:00 2001 From: Vinit Date: Tue, 17 Sep 2024 20:40:04 +0300 Subject: [PATCH] chore: use describe block to group NostrTypeGuard tests this way we don't need to repeat NostrTypeGuard in each tests description --- nip19.test.ts | 297 +++++++++++++++++++++++++------------------------- 1 file changed, 149 insertions(+), 148 deletions(-) diff --git a/nip19.test.ts b/nip19.test.ts index 8349deb..176b8b6 100644 --- a/nip19.test.ts +++ b/nip19.test.ts @@ -1,4 +1,4 @@ -import { test, expect } from 'bun:test' +import { test, expect, describe } from 'bun:test' import { generateSecretKey, getPublicKey } from './pure.ts' import { decode, @@ -153,153 +153,154 @@ test('decode naddr from go-nostr with different TLV ordering', () => { expect(pointer.identifier).toEqual('banana') }) +describe('NostrTypeGuard', () => { + test('isNProfile', () => { + const is = NostrTypeGuard.isNProfile('nprofile1qqsvc6ulagpn7kwrcwdqgp797xl7usumqa6s3kgcelwq6m75x8fe8yc5usxdg') -test('NostrTypeGuard isNProfile', () => { - const is = NostrTypeGuard.isNProfile('nprofile1qqsvc6ulagpn7kwrcwdqgp797xl7usumqa6s3kgcelwq6m75x8fe8yc5usxdg') + expect(is).toBeTrue() + }) - expect(is).toBeTrue() -}) - -test('NostrTypeGuard isNProfile invalid nprofile', () => { - const is = NostrTypeGuard.isNProfile('nprofile1qqsvc6ulagpn7kwrcwdqgp797xl7usumqa6s3kgcelwq6m75x8fe8yc5usxãg') - - expect(is).toBeFalse() -}) - -test('NostrTypeGuard isNProfile with invalid nprofile', () => { - const is = NostrTypeGuard.isNProfile('nsec1lqw6zqyanj9mz8gwhdam6tqge42vptz4zg93qsfej440xm5h5esqya0juv') - - expect(is).toBeFalse() -}) - -test('NostrTypeGuard isNRelay', () => { - const is = NostrTypeGuard.isNRelay('nrelay1qqt8wumn8ghj7un9d3shjtnwdaehgu3wvfskueq4r295t') - - expect(is).toBeTrue() -}) - -test('NostrTypeGuard isNRelay with invalid nrelay', () => { - const is = NostrTypeGuard.isNRelay('nrelay1qqt8wumn8ghj7un9d3shjtnwdaehgu3wvfskueã4r295t') - - expect(is).toBeFalse() -}) - -test('NostrTypeGuard isNRelay with invalid nrelay', () => { - const is = NostrTypeGuard.isNRelay( - 'nevent1qqst8cujky046negxgwwm5ynqwn53t8aqjr6afd8g59nfqwxpdhylpcpzamhxue69uhhyetvv9ujuetcv9khqmr99e3k7mg8arnc9', - ) - - expect(is).toBeFalse() -}) - -test('NostrTypeGuard isNEvent', () => { - const is = NostrTypeGuard.isNEvent( - 'nevent1qqst8cujky046negxgwwm5ynqwn53t8aqjr6afd8g59nfqwxpdhylpcpzamhxue69uhhyetvv9ujuetcv9khqmr99e3k7mg8arnc9', - ) - - expect(is).toBeTrue() -}) - -test('NostrTypeGuard isNEvent with invalid nevent', () => { - const is = NostrTypeGuard.isNEvent( - 'nevent1qqst8cujky046negxgwwm5ynqwn53t8aqjr6afd8g59nfqwxpdhylpcpzamhxue69uhhyetvv9ujuetcv9khqmr99e3k7mg8ãrnc9', - ) - - expect(is).toBeFalse() -}) - -test('NostrTypeGuard isNEvent with invalid nevent', () => { - const is = NostrTypeGuard.isNEvent('nprofile1qqsvc6ulagpn7kwrcwdqgp797xl7usumqa6s3kgcelwq6m75x8fe8yc5usxdg') - - expect(is).toBeFalse() -}) - -test('NostrTypeGuard isNAddr', () => { - const is = NostrTypeGuard.isNAddr( - 'naddr1qqxnzdesxqmnxvpexqunzvpcqyt8wumn8ghj7un9d3shjtnwdaehgu3wvfskueqzypve7elhmamff3sr5mgxxms4a0rppkmhmn7504h96pfcdkpplvl2jqcyqqq823cnmhuld', - ) - - expect(is).toBeTrue() -}) - -test('NostrTypeGuard isNAddr with invalid nadress', () => { - const is = NostrTypeGuard.isNAddr('nsec1lqw6zqyanj9mz8gwhdam6tqge42vptz4zg93qsfej440xm5h5esqya0juv') - - expect(is).toBeFalse() -}) - -test('NostrTypeGuard isNSec', () => { - const is = NostrTypeGuard.isNSec('nsec1lqw6zqyanj9mz8gwhdam6tqge42vptz4zg93qsfej440xm5h5esqya0juv') - - expect(is).toBeTrue() -}) - -test('NostrTypeGuard isNSec with invalid nsec', () => { - const is = NostrTypeGuard.isNSec('nsec1lqw6zqyanj9mz8gwhdam6tqge42vptz4zg93qsfej440xm5h5esqya0juã') - - expect(is).toBeFalse() -}) - -test('NostrTypeGuard isNSec with invalid nsec', () => { - const is = NostrTypeGuard.isNSec('nprofile1qqsvc6ulagpn7kwrcwdqgp797xl7usumqa6s3kgcelwq6m75x8fe8yc5usxdg') - - expect(is).toBeFalse() -}) - -test('NostrTypeGuard isNPub', () => { - const is = NostrTypeGuard.isNPub('npub1jz5mdljkmffmqjshpyjgqgrhdkuxd9ztzasv8xeh5q92fv33sjgqy4pats') - - expect(is).toBeTrue() -}) - -test('NostrTypeGuard isNPub with invalid npub', () => { - const is = NostrTypeGuard.isNPub('npub1jz5mdljkmffmqjshpyjgqgrhdkuxd9ztzãsv8xeh5q92fv33sjgqy4pats') - - expect(is).toBeFalse() -}) - -test('NostrTypeGuard isNPub with invalid npub', () => { - const is = NostrTypeGuard.isNPub('nsec1lqw6zqyanj9mz8gwhdam6tqge42vptz4zg93qsfej440xm5h5esqya0juv') - - expect(is).toBeFalse() -}) - -test('NostrTypeGuard isNote', () => { - const is = NostrTypeGuard.isNote('note1gmtnz6q2m55epmlpe3semjdcq987av3jvx4emmjsa8g3s9x7tg4sclreky') - - expect(is).toBeTrue() -}) - -test('NostrTypeGuard isNote with invalid note', () => { - const is = NostrTypeGuard.isNote('note1gmtnz6q2m55epmlpe3semjdcq987av3jvx4emmjsa8g3s9x7tg4sçlreky') - - expect(is).toBeFalse() -}) - -test('NostrTypeGuard isNote with invalid note', () => { - const is = NostrTypeGuard.isNote('npub1jz5mdljkmffmqjshpyjgqgrhdkuxd9ztzasv8xeh5q92fv33sjgqy4pats') - - expect(is).toBeFalse() -}) - -test('NostrTypeGuard isNcryptsec', () => { - const is = NostrTypeGuard.isNcryptsec( - 'ncryptsec1qgg9947rlpvqu76pj5ecreduf9jxhselq2nae2kghhvd5g7dgjtcxfqtd67p9m0w57lspw8gsq6yphnm8623nsl8xn9j4jdzz84zm3frztj3z7s35vpzmqf6ksu8r89qk5z2zxfmu5gv8th8wclt0h4p', - ) - - expect(is).toBeTrue() -}) - -test('NostrTypeGuard isNcryptsec with invalid ncrytpsec', () => { - const is = NostrTypeGuard.isNcryptsec( - 'ncryptsec1qgg9947rlpvqu76pj5ecreduf9jxhselq2nae2kghhvd5g7dgjtcxfqtd67p9m0w57lspw8gsq6yphnm8623nsã8xn9j4jdzz84zm3frztj3z7s35vpzmqf6ksu8r89qk5z2zxfmu5gv8th8wclt0h4p', - ) - - expect(is).toBeFalse() -}) - -test('NostrTypeGuard isNcryptsec with invalid ncrytpsec', () => { - const is = NostrTypeGuard.isNcryptsec('note1gmtnz6q2m55epmlpe3semjdcq987av3jvx4emmjsa8g3s9x7tg4sçlreky') - - expect(is).toBeFalse() + test('isNProfile invalid nprofile', () => { + const is = NostrTypeGuard.isNProfile('nprofile1qqsvc6ulagpn7kwrcwdqgp797xl7usumqa6s3kgcelwq6m75x8fe8yc5usxãg') + + expect(is).toBeFalse() + }) + + test('isNProfile with invalid nprofile', () => { + const is = NostrTypeGuard.isNProfile('nsec1lqw6zqyanj9mz8gwhdam6tqge42vptz4zg93qsfej440xm5h5esqya0juv') + + expect(is).toBeFalse() + }) + + test('isNRelay', () => { + const is = NostrTypeGuard.isNRelay('nrelay1qqt8wumn8ghj7un9d3shjtnwdaehgu3wvfskueq4r295t') + + expect(is).toBeTrue() + }) + + test('isNRelay with invalid nrelay', () => { + const is = NostrTypeGuard.isNRelay('nrelay1qqt8wumn8ghj7un9d3shjtnwdaehgu3wvfskueã4r295t') + + expect(is).toBeFalse() + }) + + test('isNRelay with invalid nrelay', () => { + const is = NostrTypeGuard.isNRelay( + 'nevent1qqst8cujky046negxgwwm5ynqwn53t8aqjr6afd8g59nfqwxpdhylpcpzamhxue69uhhyetvv9ujuetcv9khqmr99e3k7mg8arnc9', + ) + + expect(is).toBeFalse() + }) + + test('isNEvent', () => { + const is = NostrTypeGuard.isNEvent( + 'nevent1qqst8cujky046negxgwwm5ynqwn53t8aqjr6afd8g59nfqwxpdhylpcpzamhxue69uhhyetvv9ujuetcv9khqmr99e3k7mg8arnc9', + ) + + expect(is).toBeTrue() + }) + + test('isNEvent with invalid nevent', () => { + const is = NostrTypeGuard.isNEvent( + 'nevent1qqst8cujky046negxgwwm5ynqwn53t8aqjr6afd8g59nfqwxpdhylpcpzamhxue69uhhyetvv9ujuetcv9khqmr99e3k7mg8ãrnc9', + ) + + expect(is).toBeFalse() + }) + + test('isNEvent with invalid nevent', () => { + const is = NostrTypeGuard.isNEvent('nprofile1qqsvc6ulagpn7kwrcwdqgp797xl7usumqa6s3kgcelwq6m75x8fe8yc5usxdg') + + expect(is).toBeFalse() + }) + + test('isNAddr', () => { + const is = NostrTypeGuard.isNAddr( + 'naddr1qqxnzdesxqmnxvpexqunzvpcqyt8wumn8ghj7un9d3shjtnwdaehgu3wvfskueqzypve7elhmamff3sr5mgxxms4a0rppkmhmn7504h96pfcdkpplvl2jqcyqqq823cnmhuld', + ) + + expect(is).toBeTrue() + }) + + test('isNAddr with invalid nadress', () => { + const is = NostrTypeGuard.isNAddr('nsec1lqw6zqyanj9mz8gwhdam6tqge42vptz4zg93qsfej440xm5h5esqya0juv') + + expect(is).toBeFalse() + }) + + test('isNSec', () => { + const is = NostrTypeGuard.isNSec('nsec1lqw6zqyanj9mz8gwhdam6tqge42vptz4zg93qsfej440xm5h5esqya0juv') + + expect(is).toBeTrue() + }) + + test('isNSec with invalid nsec', () => { + const is = NostrTypeGuard.isNSec('nsec1lqw6zqyanj9mz8gwhdam6tqge42vptz4zg93qsfej440xm5h5esqya0juã') + + expect(is).toBeFalse() + }) + + test('isNSec with invalid nsec', () => { + const is = NostrTypeGuard.isNSec('nprofile1qqsvc6ulagpn7kwrcwdqgp797xl7usumqa6s3kgcelwq6m75x8fe8yc5usxdg') + + expect(is).toBeFalse() + }) + + test('isNPub', () => { + const is = NostrTypeGuard.isNPub('npub1jz5mdljkmffmqjshpyjgqgrhdkuxd9ztzasv8xeh5q92fv33sjgqy4pats') + + expect(is).toBeTrue() + }) + + test('isNPub with invalid npub', () => { + const is = NostrTypeGuard.isNPub('npub1jz5mdljkmffmqjshpyjgqgrhdkuxd9ztzãsv8xeh5q92fv33sjgqy4pats') + + expect(is).toBeFalse() + }) + + test('isNPub with invalid npub', () => { + const is = NostrTypeGuard.isNPub('nsec1lqw6zqyanj9mz8gwhdam6tqge42vptz4zg93qsfej440xm5h5esqya0juv') + + expect(is).toBeFalse() + }) + + test('isNote', () => { + const is = NostrTypeGuard.isNote('note1gmtnz6q2m55epmlpe3semjdcq987av3jvx4emmjsa8g3s9x7tg4sclreky') + + expect(is).toBeTrue() + }) + + test('isNote with invalid note', () => { + const is = NostrTypeGuard.isNote('note1gmtnz6q2m55epmlpe3semjdcq987av3jvx4emmjsa8g3s9x7tg4sçlreky') + + expect(is).toBeFalse() + }) + + test('isNote with invalid note', () => { + const is = NostrTypeGuard.isNote('npub1jz5mdljkmffmqjshpyjgqgrhdkuxd9ztzasv8xeh5q92fv33sjgqy4pats') + + expect(is).toBeFalse() + }) + + test('isNcryptsec', () => { + const is = NostrTypeGuard.isNcryptsec( + 'ncryptsec1qgg9947rlpvqu76pj5ecreduf9jxhselq2nae2kghhvd5g7dgjtcxfqtd67p9m0w57lspw8gsq6yphnm8623nsl8xn9j4jdzz84zm3frztj3z7s35vpzmqf6ksu8r89qk5z2zxfmu5gv8th8wclt0h4p', + ) + + expect(is).toBeTrue() + }) + + test('isNcryptsec with invalid ncrytpsec', () => { + const is = NostrTypeGuard.isNcryptsec( + 'ncryptsec1qgg9947rlpvqu76pj5ecreduf9jxhselq2nae2kghhvd5g7dgjtcxfqtd67p9m0w57lspw8gsq6yphnm8623nsã8xn9j4jdzz84zm3frztj3z7s35vpzmqf6ksu8r89qk5z2zxfmu5gv8th8wclt0h4p', + ) + + expect(is).toBeFalse() + }) + + test('isNcryptsec with invalid ncrytpsec', () => { + const is = NostrTypeGuard.isNcryptsec('note1gmtnz6q2m55epmlpe3semjdcq987av3jvx4emmjsa8g3s9x7tg4sçlreky') + + expect(is).toBeFalse() + }) })