2014-03-31 11:47:47 +08:00
|
|
|
var assert = require('assert')
|
2014-05-13 16:35:07 +10:00
|
|
|
var base58 = require('..').base58
|
2014-04-20 05:41:20 +10:00
|
|
|
var fixtures = require('./fixtures/base58')
|
2014-03-06 17:19:35 +08:00
|
|
|
|
2014-04-21 05:45:55 +10:00
|
|
|
function b2h(b) { return new Buffer(b).toString('hex') }
|
|
|
|
function h2b(h) { return new Buffer(h, 'hex') }
|
|
|
|
|
2014-04-20 05:41:20 +10:00
|
|
|
describe('base58', function() {
|
2014-04-03 19:45:05 +11:00
|
|
|
describe('decode', function() {
|
2014-04-21 05:45:55 +10:00
|
|
|
it('can decode Bitcoin core test data', function() {
|
2014-04-20 05:41:20 +10:00
|
|
|
fixtures.valid.forEach(function(f) {
|
2014-04-21 05:45:55 +10:00
|
|
|
var actual = base58.decode(f.string)
|
|
|
|
var expected = f.hex
|
|
|
|
|
|
|
|
assert.strictEqual(b2h(actual), expected)
|
|
|
|
})
|
|
|
|
})
|
2014-03-06 17:19:35 +08:00
|
|
|
|
2014-04-21 05:45:55 +10:00
|
|
|
fixtures.invalid.forEach(function(f) {
|
|
|
|
it('throws on ' + f.description, function() {
|
|
|
|
assert.throws(function() {
|
|
|
|
base58.decode(f.string)
|
|
|
|
})
|
2014-04-03 19:45:05 +11:00
|
|
|
})
|
2014-03-06 17:19:35 +08:00
|
|
|
})
|
2014-03-31 11:47:47 +08:00
|
|
|
})
|
2014-03-06 17:19:35 +08:00
|
|
|
|
2014-04-03 19:45:05 +11:00
|
|
|
describe('encode', function() {
|
2014-04-21 05:45:55 +10:00
|
|
|
it('can encode Bitcoin core test data', function() {
|
2014-04-20 05:41:20 +10:00
|
|
|
fixtures.valid.forEach(function(f) {
|
2014-04-21 05:45:55 +10:00
|
|
|
var actual = base58.encode(h2b(f.hex))
|
|
|
|
var expected = f.string.trim()
|
2014-03-06 17:19:35 +08:00
|
|
|
|
2014-04-21 05:45:55 +10:00
|
|
|
assert.strictEqual(actual, expected)
|
2014-04-03 19:45:05 +11:00
|
|
|
})
|
2014-03-06 17:19:35 +08:00
|
|
|
})
|
2014-03-31 11:47:47 +08:00
|
|
|
})
|
2014-01-11 13:57:43 +07:00
|
|
|
})
|