Skip to content

Commit 620c7c4

Browse files
committed
test: test noble-based base58check on Node.js too
1 parent c82c99f commit 620c7c4

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed
Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,43 @@
11
// Based on https://github.com/bitcoinjs/bs58check/tree/master/test
22

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'
45
import { toHex as bytesToHex, fromHex as hexToBytes } from '@exodus/bytes/hex.js'
56
import { test } from 'node:test'
67
import fixtures from './fixtures.cjs'
78

9+
const libs = [auto]
10+
if (js.toBase58check !== auto.toBase58check) libs.push(js)
11+
812
for (const f of fixtures.valid) {
913
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+
}
1218
})
1319
}
1420

1521
for (const f of fixtures.invalid) {
1622
test(`decode throws on ${f.string}`, async (t) => {
1723
const ex =
1824
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+
}
2129
})
2230
}
2331

2432
for (const f of fixtures.valid) {
2533
test(`encodes ${f.string}`, async (t) => {
2634
const u8 = hexToBytes(f.payload)
2735
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+
}
3242
})
3343
}

0 commit comments

Comments
 (0)