import test from 'ava';
import * as app from './basex.mjs';

// Base58
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));
});