Updates test fixtures to use bitcoin core test data
This commit is contained in:
parent
540b70ccca
commit
c178804356
4 changed files with 571 additions and 199 deletions
test
|
@ -1,43 +1,51 @@
|
|||
var assert = require('assert')
|
||||
var base58check = require('../').base58check
|
||||
var fixtures = require('./fixtures/base58check')
|
||||
|
||||
var fixtures = require('./fixtures/base58')
|
||||
function b2h(b) { return new Buffer(b).toString('hex') }
|
||||
function h2b(h) { return new Buffer(h, 'hex') }
|
||||
|
||||
describe('base58check', function() {
|
||||
describe('decode', function() {
|
||||
it('decodes the test vectors', function() {
|
||||
it('can decode Bitcoin core test data', function() {
|
||||
fixtures.valid.forEach(function(f) {
|
||||
var actual = base58check.decode(f.encoded.string)
|
||||
var expected = f.decoded
|
||||
var actual = base58check.decode(f.string)
|
||||
var expected = {
|
||||
version: f.decode.version,
|
||||
payload: h2b(f.decode.payload),
|
||||
checksum: h2b(f.decode.checksum)
|
||||
}
|
||||
|
||||
assert.deepEqual({
|
||||
version: actual.version,
|
||||
payload: actual.payload.toString('hex'),
|
||||
checksum: actual.checksum.toString('hex')
|
||||
}, expected)
|
||||
assert.deepEqual(actual, expected)
|
||||
})
|
||||
})
|
||||
|
||||
it('throws on invalid strings', function() {
|
||||
fixtures.invalid.forEach(function(f) {
|
||||
fixtures.invalid.forEach(function(f) {
|
||||
it('throws on ' + f.description, function() {
|
||||
assert.throws(function() {
|
||||
base58check.decode(f)
|
||||
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)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('encode', function() {
|
||||
it('encodes the test vectors', function() {
|
||||
it('can encode Bitcoin core test data', function() {
|
||||
fixtures.valid.forEach(function(f) {
|
||||
var actual = base58check.encode(
|
||||
new Buffer(f.decoded.payload, 'hex'),
|
||||
f.decoded.version
|
||||
)
|
||||
var expected = f.encoded.string
|
||||
var actual = base58check.encode(h2b(f.decode.payload), f.decode.version)
|
||||
var expected = f.string
|
||||
|
||||
assert.equal(actual, expected)
|
||||
assert.strictEqual(actual, expected)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue