2014-04-03 10:45:05 +02:00
|
|
|
var assert = require('assert')
|
2014-05-13 09:55:53 +02:00
|
|
|
var base58check = require('../src/base58check')
|
2014-04-20 21:45:55 +02:00
|
|
|
var fixtures = require('./fixtures/base58check')
|
2014-04-03 10:45:05 +02:00
|
|
|
|
2014-04-20 21:45:55 +02:00
|
|
|
function b2h(b) { return new Buffer(b).toString('hex') }
|
|
|
|
function h2b(h) { return new Buffer(h, 'hex') }
|
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() {
|
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 = base58check.decode(f.string)
|
|
|
|
var expected = {
|
|
|
|
version: f.decode.version,
|
|
|
|
payload: h2b(f.decode.payload),
|
|
|
|
checksum: h2b(f.decode.checksum)
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.deepEqual(actual, expected)
|
2014-04-19 21:41:20 +02:00
|
|
|
})
|
|
|
|
})
|
2014-04-03 10:45:05 +02:00
|
|
|
|
2014-04-20 21:45:55 +02:00
|
|
|
fixtures.invalid.forEach(function(f) {
|
|
|
|
it('throws on ' + f.description, function() {
|
2014-04-19 21:41:20 +02:00
|
|
|
assert.throws(function() {
|
2014-04-20 21:45:55 +02:00
|
|
|
base58check.decode(f.string)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('throws on [invalid] Bitcoin core test data', function() {
|
|
|
|
fixtures.invalid2.forEach(function(f) {
|
|
|
|
assert.throws(function() {
|
|
|
|
base58check.decode(f.string)
|
2014-04-19 21:41:20 +02: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-04-20 21:45:55 +02:00
|
|
|
var actual = base58check.encode(h2b(f.decode.payload), f.decode.version)
|
|
|
|
var expected = f.string
|
2014-04-19 21:41:20 +02:00
|
|
|
|
2014-04-20 21:45:55 +02:00
|
|
|
assert.strictEqual(actual, expected)
|
2014-04-03 10:45:05 +02:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
2014-04-20 21:45:55 +02:00
|
|
|
|