This commit is contained in:
62
test/spec/b58.js
Normal file
62
test/spec/b58.js
Normal file
@ -0,0 +1,62 @@
|
||||
'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);
|
||||
}
|
||||
});
|
||||
});
|
@ -24,12 +24,24 @@ describe ('encoding', () => {
|
||||
.toEqual ('Zm9v');
|
||||
});
|
||||
|
||||
it ('encoding to_b58', () => {
|
||||
const hex = encoding.to_b58 ('foo');
|
||||
expect (hex)
|
||||
.toEqual ('bQbp');
|
||||
});
|
||||
|
||||
it ('encoding to_utf8', () => {
|
||||
const utf = encoding.to_utf8 ('Zm9v', 'base64');
|
||||
expect (utf)
|
||||
.toEqual ('foo');
|
||||
});
|
||||
|
||||
it ('encoding to_utf8 from b58', () => {
|
||||
const utf = encoding.to_utf8 ('bQbp', 'base58');
|
||||
expect (utf)
|
||||
.toEqual ('foo');
|
||||
});
|
||||
|
||||
it ('convert num to hex', () => {
|
||||
const res = encoding.num_to_hex (11);
|
||||
expect (res)
|
||||
@ -54,4 +66,3 @@ describe ('encoding', () => {
|
||||
.toEqual (11);
|
||||
});
|
||||
});
|
||||
|
||||
|
Reference in New Issue
Block a user