bitcoinjs-lib/test/base58check.js

44 lines
1.1 KiB
JavaScript
Raw Normal View History

var assert = require('assert')
var base58check = require('../').base58check
2014-04-19 21:41:20 +02:00
var fixtures = require('./fixtures/base58')
2014-04-19 21:41:20 +02:00
describe('base58check', function() {
describe('decode', function() {
it('decodes the test vectors', function() {
2014-04-19 21:41:20 +02:00
fixtures.valid.forEach(function(f) {
var actual = base58check.decode(f.encoded.string)
var expected = f.decoded
assert.deepEqual({
version: actual.version,
payload: actual.payload.toString('hex'),
checksum: actual.checksum.toString('hex')
}, expected)
})
})
2014-04-19 21:41:20 +02:00
it('throws on invalid strings', function() {
fixtures.invalid.forEach(function(f) {
assert.throws(function() {
base58check.decode(f)
})
})
})
})
describe('encode', function() {
it('encodes the test vectors', function() {
2014-04-19 21:41:20 +02:00
fixtures.valid.forEach(function(f) {
var actual = base58check.encode(
new Buffer(f.decoded.payload, 'hex'),
f.decoded.version
)
var expected = f.encoded.string
assert.equal(actual, expected)
})
})
})
})