bitcoinjs-lib/test/base58check.js
Daniel Cousens 2fc69b0834 address/base58check: fix missing exceptions/tests
All the `invalid2` tests have been removed as they were not invalid
base58check.  They were actually valid in some cases.
They will be re-integrated in more specific bitcoin core tests in
relation to Address/ECKey respectively.
2014-05-29 14:43:44 +10:00

43 lines
1.1 KiB
JavaScript

var assert = require('assert')
var base58check = require('../src/base58check')
var fixtures = require('./fixtures/base58check.json')
function h2b(h) { return new Buffer(h, 'hex') }
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 = {
version: f.decode.version,
payload: h2b(f.decode.payload),
checksum: h2b(f.decode.checksum)
}
assert.deepEqual(actual, expected)
})
})
fixtures.invalid.forEach(function(f) {
it('throws on ' + f.description, function() {
assert.throws(function() {
base58check.decode(f.string)
}, /Invalid checksum/)
})
})
})
describe('encode', function() {
fixtures.valid.forEach(function(f) {
it('can encode ' + f.string, function() {
var actual = base58check.encode(h2b(f.decode.payload), f.decode.version)
var expected = f.string
assert.strictEqual(actual, expected)
})
})
})
})