Skip to content

Commit

Permalink
added tests for locktime
Browse files Browse the repository at this point in the history
  • Loading branch information
Egge21M committed Dec 7, 2024
1 parent a5ad719 commit 02604d6
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions test/wallet.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { getDecodedToken } from '../src/utils.js';
import { Server, WebSocket } from 'mock-socket';
import { injectWebSocketImpl } from '../src/ws.js';
import { MintInfo } from '../src/model/MintInfo.js';
import { BlindingData } from '../src/model/BlindingData.js';

injectWebSocketImpl(WebSocket);

Expand Down Expand Up @@ -735,3 +736,52 @@ describe('WebSocket Updates', () => {
server.close();
});
});

describe('P2PK BlindingData', () => {
test('Create BlindingData locked to pk with locktime and single refund key', async () => {
const wallet = new CashuWallet(mint);
const keys = await wallet.getKeys();
const data = BlindingData.createP2PKData(
{ pubkey: 'thisisatest', locktime: 212, refundKeys: ['iamarefund'] },
21,
keys
);
const decoder = new TextDecoder();
const allSecrets = data.map((d) => JSON.parse(decoder.decode(d.secret)));
allSecrets.forEach((s) => {
expect(s[0] === 'P2PK');
expect(s[1].data).toBe('thisisatest');
expect(s[1].tags).toContainEqual(['locktime', 212]);
expect(s[1].tags).toContainEqual(['refund', ['iamarefund']]);
});
});
test('Create BlindingData locked to pk with locktime and multiple refund keys', async () => {
const wallet = new CashuWallet(mint);
const keys = await wallet.getKeys();
const data = BlindingData.createP2PKData(
{ pubkey: 'thisisatest', locktime: 212, refundKeys: ['iamarefund', 'asecondrefund'] },
21,
keys
);
const decoder = new TextDecoder();
const allSecrets = data.map((d) => JSON.parse(decoder.decode(d.secret)));
allSecrets.forEach((s) => {
expect(s[0] === 'P2PK');
expect(s[1].data).toBe('thisisatest');
expect(s[1].tags).toContainEqual(['locktime', 212]);
expect(s[1].tags).toContainEqual(['refund', ['iamarefund', 'asecondrefund']]);
});
});
test('Create BlindingData locked to pk without locktime and no refund keys', async () => {
const wallet = new CashuWallet(mint);
const keys = await wallet.getKeys();
const data = BlindingData.createP2PKData({ pubkey: 'thisisatest' }, 21, keys);
const decoder = new TextDecoder();
const allSecrets = data.map((d) => JSON.parse(decoder.decode(d.secret)));
allSecrets.forEach((s) => {
expect(s[0] === 'P2PK');
expect(s[1].data).toBe('thisisatest');
expect(s[1].tags).toEqual([]);
});
});
});

0 comments on commit 02604d6

Please sign in to comment.