Adds shared base58 test vectors
This commit is contained in:
parent
12a5b75cbe
commit
1bcc7cfd95
3 changed files with 233 additions and 90 deletions
test
|
@ -1,75 +1,42 @@
|
|||
var assert = require('assert')
|
||||
var base58check = require('../').base58check
|
||||
|
||||
var fixtures = require('./fixtures/base58')
|
||||
|
||||
describe('base58check', function() {
|
||||
var evec, dvec
|
||||
|
||||
beforeEach(function() {
|
||||
function fromHex(h) { return new Buffer(h, 'hex') }
|
||||
|
||||
// base58check encoded strings
|
||||
evec = [
|
||||
'5HpHagT65TZzG1PH3CSu63k8DbpvD8s5ip4nEB3kEsreAbuatmU', // 0x00 WIF
|
||||
'5HpHagT65TZzG1PH3CSu63k8DbpvD8s5ip4nEB3kEsreAnchuDf', // 0x01 WIF
|
||||
'5HpHagT65TZzG1PH3CSu63k8DbpvD8s5ip4nEB3kEsreQyNNN1W', // 0x7f WIF
|
||||
'1EHNa6Q4Jz2uvNExL497mE43ikXhwF6kZm', // uncompressed 0x01 address
|
||||
'1FB8cZijTpRQp3HX8AEkNuQJBqApqfTcX7' // uncompressed 0x7f address
|
||||
]
|
||||
|
||||
// decoded equivalent of above
|
||||
dvec = [
|
||||
{
|
||||
version: 0x80,
|
||||
payload: '0000000000000000000000000000000000000000000000000000000000000000',
|
||||
checksum: '0565fba7'
|
||||
},
|
||||
{
|
||||
version: 0x80,
|
||||
payload: '0000000000000000000000000000000000000000000000000000000000000001',
|
||||
checksum: 'a85aa87e',
|
||||
},
|
||||
{
|
||||
version: 0x80,
|
||||
payload: '000000000000000000000000000000000000000000000000000000000000007f',
|
||||
checksum: '64046be9',
|
||||
},
|
||||
{
|
||||
version: 0x00,
|
||||
payload: '91b24bf9f5288532960ac687abb035127b1d28a5',
|
||||
checksum: '0074ffe0',
|
||||
},
|
||||
{
|
||||
version: 0x00,
|
||||
payload: '9b7c46977b68474e12066a370b169ec6b9b02644',
|
||||
checksum: '4d210d6e'
|
||||
}
|
||||
].map(function(x) {
|
||||
return {
|
||||
version: x.version,
|
||||
payload: fromHex(x.payload),
|
||||
checksum: fromHex(x.checksum)
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
describe('decode', function() {
|
||||
it('decodes the test vectors', function() {
|
||||
evec.forEach(function(x, i) {
|
||||
var actual = base58check.decode(x)
|
||||
var expected = dvec[i]
|
||||
fixtures.valid.forEach(function(f) {
|
||||
var actual = base58check.decode(f.encoded.string)
|
||||
var expected = f.decoded
|
||||
|
||||
assert.deepEqual(actual, expected)
|
||||
assert.deepEqual({
|
||||
version: actual.version,
|
||||
payload: actual.payload.toString('hex'),
|
||||
checksum: actual.checksum.toString('hex')
|
||||
}, expected)
|
||||
})
|
||||
})
|
||||
|
||||
it('throws on invalid strings', function() {
|
||||
fixtures.invalid.forEach(function(f) {
|
||||
assert.throws(function() {
|
||||
base58check.decode(f)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('encode', function() {
|
||||
it('encodes the test vectors', function() {
|
||||
dvec.forEach(function(x, i) {
|
||||
var actual = base58check.encode(x.payload, x.version)
|
||||
var expected = evec[i]
|
||||
fixtures.valid.forEach(function(f) {
|
||||
var actual = base58check.encode(
|
||||
new Buffer(f.decoded.payload, 'hex'),
|
||||
f.decoded.version
|
||||
)
|
||||
var expected = f.encoded.string
|
||||
|
||||
assert.deepEqual(actual, expected)
|
||||
assert.equal(actual, expected)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue