bitcoinjs-lib/test/base58.js

39 lines
1,012 B
JavaScript
Raw Normal View History

2014-03-31 05:47:47 +02:00
var assert = require('assert')
var base58 = require('../').base58
2014-04-19 21:41:20 +02:00
var fixtures = require('./fixtures/base58')
function b2h(b) { return new Buffer(b).toString('hex') }
function h2b(h) { return new Buffer(h, 'hex') }
2014-04-19 21:41:20 +02:00
describe('base58', function() {
describe('decode', function() {
it('can decode Bitcoin core test data', function() {
2014-04-19 21:41:20 +02:00
fixtures.valid.forEach(function(f) {
var actual = base58.decode(f.string)
var expected = f.hex
assert.strictEqual(b2h(actual), expected)
})
})
fixtures.invalid.forEach(function(f) {
it('throws on ' + f.description, function() {
assert.throws(function() {
base58.decode(f.string)
})
})
})
2014-03-31 05:47:47 +02:00
})
describe('encode', function() {
it('can encode Bitcoin core test data', function() {
2014-04-19 21:41:20 +02:00
fixtures.valid.forEach(function(f) {
var actual = base58.encode(h2b(f.hex))
var expected = f.string.trim()
assert.strictEqual(actual, expected)
})
})
2014-03-31 05:47:47 +02:00
})
})