address/base58check: fix missing exceptions/tests

All the `invalid2` tests have been removed as they were not invalid
base58check.  They were actually valid in some cases.
They will be re-integrated in more specific bitcoin core tests in
relation to Address/ECKey respectively.
This commit is contained in:
Daniel Cousens 2014-05-28 13:34:10 +10:00
parent 47ae862ae9
commit 2fc69b0834
5 changed files with 28 additions and 88 deletions

View file

@ -28,7 +28,7 @@ function decode(string) {
var checksum = buffer.slice(-4)
var newChecksum = crypto.hash256(message).slice(0, 4)
assert.deepEqual(newChecksum, checksum)
assert.deepEqual(newChecksum, checksum, 'Invalid checksum')
var version = message.readUInt8(0)
var payload = message.slice(1)

View file

@ -3,11 +3,8 @@ var Address = require('../src/address')
var networks = require('../src/networks')
var Script = require('../src/script')
var b58fixtures = require('./fixtures/base58.json')
var fixtures = require('./fixtures/address.json')
function h2b(h) { return new Buffer(h, 'hex') }
describe('Address', function() {
describe('Constructor', function() {
it('does not mutate the input', function() {
@ -31,11 +28,11 @@ describe('Address', function() {
})
})
it('throws on invalid base58check', function() {
b58fixtures.invalid.forEach(function(f) {
fixtures.invalid.fromBase58Check.forEach(function(f) {
it('throws on ' + f.descpription, function() {
assert.throws(function() {
Address.fromBase58Check(f)
})
Address.fromBase58Check(f.base58check)
}, new RegExp(f.exception))
})
})
})

View file

@ -3,13 +3,12 @@ var base58check = require('../src/base58check')
var fixtures = require('./fixtures/base58check.json')
function b2h(b) { return new Buffer(b).toString('hex') }
function h2b(h) { return new Buffer(h, 'hex') }
describe('base58check', function() {
describe('decode', function() {
it('can decode Bitcoin core test data', function() {
fixtures.valid.forEach(function(f) {
fixtures.valid.forEach(function(f) {
it('can decode ' + f.string, function() {
var actual = base58check.decode(f.string)
var expected = {
version: f.decode.version,
@ -25,22 +24,14 @@ describe('base58check', function() {
it('throws on ' + f.description, function() {
assert.throws(function() {
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)
})
}, /Invalid checksum/)
})
})
})
describe('encode', function() {
it('can encode Bitcoin core test data', function() {
fixtures.valid.forEach(function(f) {
fixtures.valid.forEach(function(f) {
it('can encode ' + f.string, function() {
var actual = base58check.encode(h2b(f.decode.payload), f.decode.version)
var expected = f.string

View file

@ -34,6 +34,18 @@
}
],
"invalid": {
"fromBase58Check": [
{
"description": "hash too short",
"base58check": "7SeEnXWPaCCALbVrTnszCVGfRU8cGfx",
"exception": "Invalid hash length"
},
{
"description": "hash too long",
"base58check": "j9ywUkWg2fTQrouxxh5rSZhRvrjMkEUfuiKe",
"exception": "Invalid hash length"
}
],
"fromScriptPubKey": [
{
"description": "pubkey has no matching Address",

View file

@ -403,76 +403,16 @@
],
"invalid": [
{
"base58check": "7SeEnXWPaCCALbVrTnszCVGfRU8cGfx",
"description": "hash too short"
"description": "bad version byte",
"string": "Z9inZq4e2HGQRZQezDjFMmqgUE8NwMRok"
},
{
"base58check": "j9ywUkWg2fTQrouxxh5rSZhRvrjMkEUfuiKe",
"description": "hash too long"
"description": "bad payload",
"string": "3HK7MezAm6qEZQUMPRf8jX7wDv6zig6Ky8"
},
{
"base58check": "Z9inZq4e2HGQRZQezDjFMmqgUE8NwMRok",
"description": "bad version byte"
},
{
"base58check": "3HK7MezAm6qEZQUMPRf8jX7wDv6zig6Ky8",
"description": "bad payload"
},
{
"base58check": "3AW8j12DUk8mgA7kkfZ1BrrzCVFuH1LsXS",
"description": "bad SHA256 checksum"
"description": "bad SHA256 checksum",
"string": "3AW8j12DUk8mgA7kkfZ1BrrzCVFuH1LsXS"
}
],
"invalid2": [
"",
"x",
"37qgekLpCCHrQuSjvX3fs496FWTGsHFHizjJAs6NPcR47aefnnCWECAhHV6E3g4YN7u7Yuwod5Y",
"dzb7VV1Ui55BARxv7ATxAtCUeJsANKovDGWFVgpTbhq9gvPqP3yv",
"MuNu7ZAEDFiHthiunm7dPjwKqrVNCM3mAz6rP9zFveQu14YA8CxExSJTHcVP9DErn6u84E6Ej7S",
"rPpQpYknyNQ5AEHu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