Versie 0.2.0
This commit is contained in:
commit
e77d8fd373
495 files changed
+81026
No files matched your search
@@ -0,0 +1,64 @@
|
||||
// Generated, do not edit. sha256:f9a7d616a0b0b96337b4d9aa3810013fc2a8851cf64050bbc67d182adee97bf4
|
||||
import { describe, it } from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
|
||||
import { zapContext, compactMemo, npub, npubShort, memoNote, MEMO_MAX } from '../../shared/zap.js';
|
||||
|
||||
const ALICE = '3bf0c63fcb93463407af97a5e5ee64fa883d107ef9e558472c4eb9aaaefa459d';
|
||||
const BOB = 'a'.repeat(64);
|
||||
const verzoek = (extra = {}) => JSON.stringify({
|
||||
kind: 9734, pubkey: ALICE, content: 'Mooi stuk!', created_at: 1,
|
||||
tags: [['p', BOB], ['e', 'b'.repeat(64)], ['relays', 'wss://a', 'wss://b'], ['amount', '21000']], sig: 'x', ...extra,
|
||||
});
|
||||
|
||||
describe('npub', () => {
|
||||
it('geeft de npub van NIP-19 voor een bekende sleutel', () => {
|
||||
assert.equal(npub(ALICE), 'npub180cvv07tjdrrgpa0j7j7tmnyl2yr6yr7l8j4s3evf6u64th6gkwsyjh6w6');
|
||||
assert.equal(npubShort(ALICE), 'npub180cv…h6w6');
|
||||
});
|
||||
|
||||
it('weigert wat geen sleutel van 32 bytes is', () => {
|
||||
assert.equal(npub('abc'), null);
|
||||
assert.equal(npub(null), null);
|
||||
});
|
||||
});
|
||||
|
||||
describe('zapContext', () => {
|
||||
it('leest afzender, ontvanger, bericht en de gezapte notitie', () => {
|
||||
assert.deepEqual(zapContext(verzoek()), { sender: ALICE, recipient: BOB, message: 'Mooi stuk!', note: 'b'.repeat(64) });
|
||||
});
|
||||
|
||||
it('een gewone memo, ander JSON of een ander soort event is geen zap', () => {
|
||||
assert.equal(zapContext('Koffie'), null);
|
||||
assert.equal(zapContext('{"kind":1,"content":"x"}'), null);
|
||||
assert.equal(zapContext('{kapot'), null);
|
||||
assert.equal(zapContext(null), null);
|
||||
});
|
||||
});
|
||||
|
||||
describe('compactMemo', () => {
|
||||
it('houdt van een zap-verzoek alleen wat gelezen wordt, en de context blijft gelijk', () => {
|
||||
const klein = compactMemo(verzoek());
|
||||
assert.ok(!klein.includes('relays') && !klein.includes('sig'));
|
||||
assert.deepEqual(zapContext(klein), zapContext(verzoek()));
|
||||
});
|
||||
|
||||
it('kort een lange memo in en laat een lege weg', () => {
|
||||
assert.equal(compactMemo('x'.repeat(MEMO_MAX + 50)).length, MEMO_MAX);
|
||||
assert.equal(compactMemo(' '), null);
|
||||
assert.equal(compactMemo(undefined), null);
|
||||
});
|
||||
});
|
||||
|
||||
describe('memoNote', () => {
|
||||
it('noemt bij binnenkomend de afzender en bij uitgaand de ontvanger', () => {
|
||||
assert.equal(memoNote(verzoek(), 'in'), 'zap from npub180cv…h6w6: "Mooi stuk!"');
|
||||
assert.match(memoNote(verzoek(), 'out'), /^zap to npub1/);
|
||||
assert.equal(memoNote(verzoek({ content: '' }), 'in'), 'zap from npub180cv…h6w6');
|
||||
});
|
||||
|
||||
it('een gewone memo komt zoals hij is, en niets geeft niets', () => {
|
||||
assert.equal(memoNote('Koffie', 'out'), 'Koffie');
|
||||
assert.equal(memoNote(null, 'in'), null);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user