ihm_client/tests/unit/sp-address.utils.test.ts

46 lines
1.5 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { generateEmojiList, addressToEmoji } from '../../src/utils/sp-address.utils';
describe('sp-address.utils', () => {
describe('generateEmojiList', () => {
it('retourne exactement 256 emojis', () => {
const list = generateEmojiList();
expect(Array.isArray(list)).toBe(true);
expect(list.length).toBe(256);
expect(list.every((e) => typeof e === 'string' && e.length > 0)).toBe(true);
});
});
describe('addressToEmoji', () => {
const mockDigest = jest.fn(async (algorithm: string, data: ArrayBuffer) => {
// Retourne un buffer de 32 octets avec un motif déterministe basé sur la longueur
const len = (data as Uint8Array).byteLength || new Uint8Array(data).byteLength;
const out = new Uint8Array(32).map((_, i) => (i * 7 + len) % 256);
return out.buffer;
});
beforeAll(() => {
// @ts-ignore
if (!global.crypto) {
// @ts-ignore
global.crypto = {};
}
// @ts-ignore
global.crypto.subtle = { digest: mockDigest } as any;
});
it('est déterministe pour une même adresse', async () => {
const addr = 'sp1qexampleaddress0001';
const a = await addressToEmoji(addr);
const b = await addressToEmoji(addr);
expect(a).toBe(b);
expect(a.length).toBeGreaterThan(0);
});
it('retourne une chaîne demojis de longueur > 0', async () => {
const a = await addressToEmoji('sp1qexampleA');
expect(typeof a).toBe('string');
expect(a.length).toBeGreaterThan(0);
});
});
});