63 lines
1.6 KiB
JavaScript
63 lines
1.6 KiB
JavaScript
|
'use strict';
|
||
|
|
||
|
const b58 = require ('b58');
|
||
|
|
||
|
// eslint-disable-next-line max-lines-per-function
|
||
|
describe ('b58', () => {
|
||
|
it ('should encode "Hello World!"', () => {
|
||
|
const enc = b58.encode (Buffer.from ('Hello World!', 'utf-8'));
|
||
|
expect (enc)
|
||
|
.toEqual ('2NEpo7TZRRrLZSi2U');
|
||
|
});
|
||
|
|
||
|
it ('should encode "The quick brown fox.."', () => {
|
||
|
const enc = b58.encode (Buffer.from (
|
||
|
'The quick brown fox jumps over the lazy dog.',
|
||
|
'utf-8'
|
||
|
));
|
||
|
expect (enc)
|
||
|
.toEqual ('USm3fpXnKG5EUBx2ndxBDMPVciP5hGey2Jh4NDv6gmeo1LkMeiKrLJUUBk6Z');
|
||
|
});
|
||
|
|
||
|
it ('should encode test hex string', () => {
|
||
|
const enc = b58.encode (Buffer.from ('0000287fb4cd', 'hex'));
|
||
|
expect (enc)
|
||
|
.toEqual ('11233QC4');
|
||
|
});
|
||
|
|
||
|
it ('should decode "Hello World!"', () => {
|
||
|
const dec = b58.decode ('2NEpo7TZRRrLZSi2U')
|
||
|
.toString ('utf-8');
|
||
|
expect (dec)
|
||
|
.toEqual ('Hello World!');
|
||
|
});
|
||
|
|
||
|
it ('should decode "The quick brown fox.."', () => {
|
||
|
const dec = b58.decode (
|
||
|
'USm3fpXnKG5EUBx2ndxBDMPVciP5hGey2Jh4NDv6gmeo1LkMeiKrLJUUBk6Z'
|
||
|
)
|
||
|
.toString ('utf-8');
|
||
|
expect (dec)
|
||
|
.toEqual ('The quick brown fox jumps over the lazy dog.');
|
||
|
});
|
||
|
|
||
|
it ('should decode test hex string', () => {
|
||
|
const dec = b58.decode ('11233QC4')
|
||
|
.toString ('hex');
|
||
|
expect (dec)
|
||
|
.toEqual ('0000287fb4cd');
|
||
|
});
|
||
|
|
||
|
it ('should encode any byte combination', () => {
|
||
|
for (let i = 0; i < 65536; i++) {
|
||
|
const buf = Buffer.alloc (2);
|
||
|
buf.writeUInt16BE (i);
|
||
|
const enc = b58.encode (buf);
|
||
|
const dec = b58.decode (enc)
|
||
|
.readUInt16BE ();
|
||
|
expect (dec)
|
||
|
.toEqual (i);
|
||
|
}
|
||
|
});
|
||
|
});
|