2015-02-23 00:36:57 +01:00
|
|
|
/* global describe, it */
|
|
|
|
|
2014-03-07 00:21:42 +01:00
|
|
|
var assert = require('assert')
|
2014-05-13 09:55:53 +02:00
|
|
|
var networks = require('../src/networks')
|
2014-06-12 13:14:22 +02:00
|
|
|
|
|
|
|
var Address = require('../src/address')
|
2014-05-13 09:55:53 +02:00
|
|
|
var Script = require('../src/script')
|
2014-04-19 21:43:10 +02:00
|
|
|
|
2014-05-18 11:47:39 +02:00
|
|
|
var fixtures = require('./fixtures/address.json')
|
2014-03-07 00:21:42 +01:00
|
|
|
|
2015-02-23 00:36:57 +01:00
|
|
|
describe('Address', function () {
|
|
|
|
describe('fromBase58Check', function () {
|
|
|
|
fixtures.valid.forEach(function (f) {
|
2015-07-21 02:55:47 +02:00
|
|
|
it('decodes ' + f.base58check, function () {
|
|
|
|
var decode = Address.fromBase58Check(f.base58check)
|
2014-03-31 05:47:47 +02:00
|
|
|
|
2015-07-21 02:55:47 +02:00
|
|
|
assert.strictEqual(decode.version, f.version)
|
|
|
|
assert.strictEqual(decode.hash.toString('hex'), f.hash)
|
2014-04-17 15:31:45 +02:00
|
|
|
})
|
2014-03-06 02:45:56 +01:00
|
|
|
})
|
2014-05-08 05:28:20 +02:00
|
|
|
|
2015-02-23 00:36:57 +01:00
|
|
|
fixtures.invalid.fromBase58Check.forEach(function (f) {
|
|
|
|
it('throws on ' + f.description, function () {
|
|
|
|
assert.throws(function () {
|
2014-05-28 05:34:10 +02:00
|
|
|
Address.fromBase58Check(f.base58check)
|
|
|
|
}, new RegExp(f.exception))
|
2014-05-08 05:28:20 +02:00
|
|
|
})
|
|
|
|
})
|
2014-03-31 05:47:47 +02:00
|
|
|
})
|
|
|
|
|
2015-02-23 00:36:57 +01:00
|
|
|
describe('fromOutputScript', function () {
|
|
|
|
fixtures.valid.forEach(function (f) {
|
2015-07-21 02:55:47 +02:00
|
|
|
it('parses ' + f.script + ' (' + f.network + ')', function () {
|
2014-11-28 04:02:19 +01:00
|
|
|
var script = Script.fromASM(f.script)
|
2015-07-21 02:55:47 +02:00
|
|
|
var address = Address.fromOutputScript(script, networks[f.network])
|
2014-05-05 07:31:40 +02:00
|
|
|
|
2015-07-21 02:55:47 +02:00
|
|
|
assert.strictEqual(address, f.base58check)
|
2014-05-05 07:31:40 +02:00
|
|
|
})
|
|
|
|
})
|
2014-05-28 05:17:04 +02:00
|
|
|
|
2015-02-23 00:36:57 +01:00
|
|
|
fixtures.invalid.fromOutputScript.forEach(function (f) {
|
|
|
|
it('throws when ' + f.description, function () {
|
2014-11-28 04:02:19 +01:00
|
|
|
var script = Script.fromASM(f.script)
|
2014-05-28 05:17:04 +02:00
|
|
|
|
2015-02-23 00:36:57 +01:00
|
|
|
assert.throws(function () {
|
2014-06-13 03:30:07 +02:00
|
|
|
Address.fromOutputScript(script)
|
2014-05-28 05:17:04 +02:00
|
|
|
}, new RegExp(f.description))
|
|
|
|
})
|
|
|
|
})
|
2014-05-05 07:31:40 +02:00
|
|
|
})
|
|
|
|
|
2015-02-23 00:36:57 +01:00
|
|
|
describe('toBase58Check', function () {
|
|
|
|
fixtures.valid.forEach(function (f) {
|
2015-07-21 02:55:47 +02:00
|
|
|
it('formats ' + f.hash + ' (' + f.network + ')', function () {
|
|
|
|
var address = Address.toBase58Check(new Buffer(f.hash, 'hex'), f.version)
|
2014-03-06 02:45:56 +01:00
|
|
|
|
2015-07-21 02:55:47 +02:00
|
|
|
assert.strictEqual(address, 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-05-05 07:31:40 +02:00
|
|
|
|
2015-02-23 00:36:57 +01:00
|
|
|
describe('toOutputScript', function () {
|
|
|
|
fixtures.valid.forEach(function (f) {
|
2015-07-24 03:59:48 +02:00
|
|
|
var network = networks[f.network]
|
|
|
|
|
2015-07-21 02:55:47 +02:00
|
|
|
it('exports ' + f.script + '(' + f.network + ')', function () {
|
2015-07-24 03:59:48 +02:00
|
|
|
var script = Address.toOutputScript(f.base58check, network)
|
2014-05-05 07:31:40 +02:00
|
|
|
|
2015-05-07 03:29:20 +02:00
|
|
|
assert.strictEqual(script.toASM(), f.script)
|
2014-05-05 07:31:40 +02:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2015-02-23 00:36:57 +01:00
|
|
|
fixtures.invalid.toOutputScript.forEach(function (f) {
|
|
|
|
it('throws when ' + f.description, function () {
|
|
|
|
assert.throws(function () {
|
2015-07-21 02:55:47 +02:00
|
|
|
Address.toOutputScript(f.address)
|
2014-05-28 05:17:04 +02:00
|
|
|
}, new RegExp(f.description))
|
2014-05-05 07:31:40 +02:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
2014-01-11 07:57:43 +01:00
|
|
|
})
|