|
1 | 1 | // Based on https://github.com/bitcoinjs/bs58check/tree/master/test |
2 | 2 |
|
3 | | -import * as lib from '@exodus/bytes/base58check.js' |
| 3 | +import * as auto from '@exodus/bytes/base58check.js' |
| 4 | +import * as js from '../../../base58check.js' |
4 | 5 | import { toHex as bytesToHex, fromHex as hexToBytes } from '@exodus/bytes/hex.js' |
5 | 6 | import { test } from 'node:test' |
6 | 7 | import fixtures from './fixtures.cjs' |
7 | 8 |
|
| 9 | +const libs = [auto] |
| 10 | +if (js.toBase58check !== auto.toBase58check) libs.push(js) |
| 11 | + |
8 | 12 | for (const f of fixtures.valid) { |
9 | 13 | test(`decodes ${f.string}`, async (t) => { |
10 | | - t.assert.strictEqual(bytesToHex(await lib.fromBase58check(f.string)), f.payload) |
11 | | - t.assert.strictEqual(bytesToHex(lib.fromBase58checkSync(f.string)), f.payload) |
| 14 | + for (const lib of libs) { |
| 15 | + t.assert.strictEqual(bytesToHex(await lib.fromBase58check(f.string)), f.payload) |
| 16 | + t.assert.strictEqual(bytesToHex(lib.fromBase58checkSync(f.string)), f.payload) |
| 17 | + } |
12 | 18 | }) |
13 | 19 | } |
14 | 20 |
|
15 | 21 | for (const f of fixtures.invalid) { |
16 | 22 | test(`decode throws on ${f.string}`, async (t) => { |
17 | 23 | const ex = |
18 | 24 | f.exception === 'Non-base58 character' ? 'Invalid character in base58 input' : f.exception |
19 | | - await t.assert.rejects(async () => lib.fromBase58check(f.string), new RegExp(ex)) |
20 | | - t.assert.throws(() => lib.fromBase58checkSync(f.string), new RegExp(ex)) |
| 25 | + for (const lib of libs) { |
| 26 | + await t.assert.rejects(async () => lib.fromBase58check(f.string), new RegExp(ex)) |
| 27 | + t.assert.throws(() => lib.fromBase58checkSync(f.string), new RegExp(ex)) |
| 28 | + } |
21 | 29 | }) |
22 | 30 | } |
23 | 31 |
|
24 | 32 | for (const f of fixtures.valid) { |
25 | 33 | test(`encodes ${f.string}`, async (t) => { |
26 | 34 | const u8 = hexToBytes(f.payload) |
27 | 35 | const buffer = Buffer.from(u8) |
28 | | - t.assert.strictEqual(await lib.toBase58check(u8), f.string) |
29 | | - t.assert.strictEqual(await lib.toBase58check(buffer), f.string) |
30 | | - t.assert.strictEqual(lib.toBase58checkSync(u8), f.string) |
31 | | - t.assert.strictEqual(lib.toBase58checkSync(buffer), f.string) |
| 36 | + for (const lib of libs) { |
| 37 | + t.assert.strictEqual(await lib.toBase58check(u8), f.string) |
| 38 | + t.assert.strictEqual(await lib.toBase58check(buffer), f.string) |
| 39 | + t.assert.strictEqual(lib.toBase58checkSync(u8), f.string) |
| 40 | + t.assert.strictEqual(lib.toBase58checkSync(buffer), f.string) |
| 41 | + } |
32 | 42 | }) |
33 | 43 | } |
0 commit comments