2014-04-03 10:45:05 +02:00
|
|
|
var assert = require('assert')
|
|
|
|
var base58check = require('../').base58check
|
|
|
|
|
2014-04-19 21:41:20 +02:00
|
|
|
var fixtures = require('./fixtures/base58')
|
2014-04-03 10:45:05 +02:00
|
|
|
|
2014-04-19 21:41:20 +02:00
|
|
|
describe('base58check', function() {
|
2014-04-03 10:45:05 +02:00
|
|
|
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-03 10:45:05 +02:00
|
|
|
|
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)
|
|
|
|
})
|
2014-04-03 10:45:05 +02:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
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)
|
2014-04-03 10:45:05 +02:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|