Skip to content

Commit 7474f2a

Browse files
committed
test vectors
1 parent a4ce8c8 commit 7474f2a

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

test/utils/Base58.test.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ describe('Base58', function () {
1313
});
1414

1515
describe('base58', function () {
16-
describe('encode/decode', function () {
16+
describe('encode/decode random buffers', function () {
1717
// length 512 runs out of gas.
1818
// this checks are very slow when running coverage, causing CI to timeout.
1919
for (const length of [0, 1, 2, 3, 4, 32, 42, 128, 384])
@@ -30,6 +30,24 @@ describe('Base58', function () {
3030
);
3131
});
3232

33+
describe('test vectors', function () {
34+
for (const { raw, b58 } of [
35+
{ raw: 'Hello World!', b58: '2NEpo7TZRRrLZSi2U' },
36+
{
37+
raw: 'The quick brown fox jumps over the lazy dog.',
38+
b58: 'USm3fpXnKG5EUBx2ndxBDMPVciP5hGey2Jh4NDv6gmeo1LkMeiKrLJUUBk6Z',
39+
},
40+
{ raw: '0x0000287fb4cd', b58: '11233QC4' },
41+
])
42+
it(raw, async function () {
43+
const buffer = (ethers.isHexString(raw) ? ethers.getBytes : ethers.toUtf8Bytes)(raw);
44+
const hex = ethers.hexlify(buffer);
45+
46+
await expect(this.mock.$encode(hex)).to.eventually.equal(b58);
47+
await expect(this.mock.$decode(b58)).to.eventually.equal(hex);
48+
});
49+
});
50+
3351
describe('decode invalid format', function () {
3452
for (const chr of ['I', '-', '~'])
3553
it(`Invalid base58 char ${chr}`, async function () {

0 commit comments

Comments
 (0)