2014-03-31 05:47:47 +02:00
|
|
|
var assert = require('assert')
|
2014-05-13 09:55:53 +02:00
|
|
|
var base58 = require('../src/base58')
|
2014-03-06 10:19:35 +01:00
|
|
|
|
2014-05-18 11:47:39 +02:00
|
|
|
var fixtures = require('./fixtures/base58.json')
|
2014-04-20 21:45:55 +02:00
|
|
|
|
2014-04-19 21:41:20 +02:00
|
|
|
describe('base58', function() {
|
2014-04-03 10:45:05 +02:00
|
|
|
describe('decode', function() {
|
2014-04-20 21:45:55 +02:00
|
|
|
it('can decode Bitcoin core test data', function() {
|
2014-04-19 21:41:20 +02:00
|
|
|
fixtures.valid.forEach(function(f) {
|
2014-04-20 21:45:55 +02:00
|
|
|
var actual = base58.decode(f.string)
|
|
|
|
var expected = f.hex
|
|
|
|
|
2014-05-18 11:47:39 +02:00
|
|
|
assert.strictEqual(actual.toString('hex'), expected)
|
2014-04-20 21:45:55 +02:00
|
|
|
})
|
|
|
|
})
|
2014-03-06 10:19:35 +01:00
|
|
|
|
2014-04-20 21:45:55 +02:00
|
|
|
fixtures.invalid.forEach(function(f) {
|
|
|
|
it('throws on ' + f.description, function() {
|
|
|
|
assert.throws(function() {
|
|
|
|
base58.decode(f.string)
|
2014-05-28 05:29:01 +02:00
|
|
|
}, /Non-base58 character/)
|
2014-04-03 10:45:05 +02:00
|
|
|
})
|
2014-03-06 10:19:35 +01:00
|
|
|
})
|
2014-03-31 05:47:47 +02:00
|
|
|
})
|
2014-03-06 10:19:35 +01:00
|
|
|
|
2014-04-03 10:45:05 +02:00
|
|
|
describe('encode', function() {
|
2014-04-20 21:45:55 +02:00
|
|
|
it('can encode Bitcoin core test data', function() {
|
2014-04-19 21:41:20 +02:00
|
|
|
fixtures.valid.forEach(function(f) {
|
2014-05-18 11:47:39 +02:00
|
|
|
var actual = base58.encode(new Buffer(f.hex, 'hex'))
|
2014-04-20 21:45:55 +02:00
|
|
|
var expected = f.string.trim()
|
2014-03-06 10:19:35 +01:00
|
|
|
|
2014-04-20 21:45:55 +02:00
|
|
|
assert.strictEqual(actual, expected)
|
2014-04-03 10:45:05 +02:00
|
|
|
})
|
2014-03-06 10:19:35 +01:00
|
|
|
})
|
2014-03-31 05:47:47 +02:00
|
|
|
})
|
2014-01-11 07:57:43 +01:00
|
|
|
})
|