Skip to content
Snippets Groups Projects
Commit 554211c4 authored by Millicent Billette's avatar Millicent Billette
Browse files

100% coverage

parent 819346b1
No related branches found
No related tags found
No related merge requests found
......@@ -2,8 +2,8 @@
const B58_ALPHABET = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz';
export const b58 = basex(B58_ALPHABET);
export const b16 = basex('0123456789abcdef');
export default function basex(ALPHABET) {
export default basex;
export function basex(ALPHABET) {
const ALPHABET_MAP = {};
const BASE = ALPHABET.length;
const LEADER = ALPHABET.charAt(0);
......
......@@ -7,3 +7,24 @@ const pubKey = 'AoxVA41dGL2s4ogMNdbCw3FFYjFo5FPK36LuiW1tjGbG';
test('b58 should decode/encode well', t => {
t.is(app.b58.encode(app.b58.decode(pubKey)), pubKey);
});
test('basex dont allow ambigous alphabet (each character must be unique)', t => {
t.throws(() => app.basex('zz'));
});
test('empty input empty output', t => {
t.is(app.b58.encode([]), '');
});
test('encode 0000 filled source', t => {
t.is(app.b16.encode([0, 0, 0, 0, 15]), '0000f');
});
test('decode 0000 filled source', t => {
t.deepEqual(app.b16.decode('0000f'), new Uint8Array([0, 0, 0, 0, 15]));
});
test('decode out of base chr throw error', t => {
t.throws(() => app.b58.decode(pubKey + '§'));
});
test('no string decode throw', t => {
t.throws(() => app.b58.decode([]));
});
test('decode empty string => empty array', t => {
t.deepEqual(app.b16.decode(''), new Uint8Array(0));
});
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment