bitcoinjs-lib/test/base58check.js

39 lines
977 B
JavaScript
Raw Normal View History

var assert = require('assert')
var base58check = require('../src/base58check')
2014-05-18 11:47:39 +02:00
var fixtures = require('./fixtures/base58check.json')
function h2b(h) { return new Buffer(h, 'hex') }
2014-04-19 21:41:20 +02:00
describe('base58check', function() {
describe('decode', function() {
fixtures.valid.forEach(function(f) {
it('can decode ' + f.string, function() {
var actual = base58check.decode(f.string)
var expected = h2b(f.payload)
assert.deepEqual(actual, expected)
2014-04-19 21:41:20 +02:00
})
})
fixtures.invalid.forEach(function(f) {
it('throws on ' + f, function() {
2014-04-19 21:41:20 +02:00
assert.throws(function() {
base58check.decode(f)
}, /Invalid checksum/)
})
})
})
describe('encode', function() {
fixtures.valid.forEach(function(f) {
it('can encode ' + f.string, function() {
var actual = base58check.encode(h2b(f.payload))
var expected = f.string
2014-04-19 21:41:20 +02:00
assert.strictEqual(actual, expected)
})
})
})
})