2014-03-07 00:21:42 +01:00
|
|
|
var assert = require('assert')
|
2014-04-17 15:31:45 +02:00
|
|
|
var Address = require('..').Address
|
2014-04-19 21:43:10 +02:00
|
|
|
|
|
|
|
var b58fixtures = require('./fixtures/base58')
|
2014-04-17 15:31:45 +02:00
|
|
|
var fixtures = require('./fixtures/address')
|
2014-03-07 00:21:42 +01:00
|
|
|
|
2014-04-17 15:31:45 +02:00
|
|
|
describe('Address', function() {
|
|
|
|
var bothVectors = fixtures.pubKeyHash.concat(fixtures.scriptHash)
|
2014-03-31 05:47:47 +02:00
|
|
|
|
2014-04-17 15:31:45 +02:00
|
|
|
describe('Constructor', function() {
|
2014-04-19 20:38:33 +02:00
|
|
|
it('does not mutate the input', function() {
|
2014-04-17 15:31:45 +02:00
|
|
|
bothVectors.forEach(function(f) {
|
|
|
|
var hash = new Buffer(f.hex, 'hex')
|
|
|
|
var addr = new Address(hash, f.version)
|
2014-03-31 05:47:47 +02:00
|
|
|
|
2014-04-17 15:31:45 +02:00
|
|
|
assert.equal(addr.version, f.version)
|
|
|
|
assert.equal(addr.hash.toString('hex'), f.hex)
|
|
|
|
})
|
2014-03-31 05:47:47 +02:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2014-04-17 15:31:45 +02:00
|
|
|
describe('fromBase58Check', function() {
|
|
|
|
it('throws on invalid base58check', function() {
|
2014-04-19 21:43:10 +02:00
|
|
|
b58fixtures.invalid.forEach(function(f) {
|
2014-04-17 15:31:45 +02:00
|
|
|
assert.throws(function() {
|
2014-04-19 21:42:36 +02:00
|
|
|
Address.fromBase58Check(f)
|
2014-04-17 15:31:45 +02:00
|
|
|
})
|
|
|
|
})
|
2014-01-11 07:57:43 +01:00
|
|
|
})
|
|
|
|
|
2014-04-19 20:38:33 +02:00
|
|
|
bothVectors.forEach(function(f) {
|
|
|
|
it('imports ' + f.description + ' correctly', function() {
|
2014-04-17 15:31:45 +02:00
|
|
|
var addr = Address.fromBase58Check(f.base58check)
|
2014-03-31 05:47:47 +02:00
|
|
|
|
2014-04-17 15:31:45 +02:00
|
|
|
assert.equal(addr.version, f.version)
|
|
|
|
assert.equal(addr.hash.toString('hex'), f.hex)
|
|
|
|
})
|
2014-03-06 02:45:56 +01:00
|
|
|
})
|
2014-03-31 05:47:47 +02:00
|
|
|
})
|
|
|
|
|
2014-04-17 15:31:45 +02:00
|
|
|
describe('toBase58Check', function() {
|
2014-04-19 20:38:33 +02:00
|
|
|
bothVectors.forEach(function(f) {
|
|
|
|
it('exports ' + f.description + ' correctly', function() {
|
2014-04-17 15:31:45 +02:00
|
|
|
var addr = Address.fromBase58Check(f.base58check)
|
2014-04-19 20:38:33 +02:00
|
|
|
var result = addr.toBase58Check()
|
2014-03-06 02:45:56 +01:00
|
|
|
|
2014-04-19 20:38:33 +02:00
|
|
|
assert.equal(result, f.base58check)
|
2014-04-17 15:31:45 +02:00
|
|
|
})
|
2014-01-11 07:57:43 +01:00
|
|
|
})
|
2014-03-31 05:47:47 +02:00
|
|
|
})
|
2014-01-11 07:57:43 +01:00
|
|
|
})
|