|
|
@ -1,18 +1,16 @@ |
|
|
|
/* global describe, it */ |
|
|
|
|
|
|
|
var assert = require('assert') |
|
|
|
var baddress = require('../src/address') |
|
|
|
var networks = require('../src/networks') |
|
|
|
var scripts = require('../src/scripts') |
|
|
|
|
|
|
|
var Address = require('../src/address') |
|
|
|
|
|
|
|
var fixtures = require('./fixtures/address.json') |
|
|
|
|
|
|
|
describe('Address', function () { |
|
|
|
describe('address', function () { |
|
|
|
describe('fromBase58Check', function () { |
|
|
|
fixtures.valid.forEach(function (f) { |
|
|
|
it('decodes ' + f.base58check, function () { |
|
|
|
var decode = Address.fromBase58Check(f.base58check) |
|
|
|
var decode = baddress.fromBase58Check(f.base58check) |
|
|
|
|
|
|
|
assert.strictEqual(decode.version, f.version) |
|
|
|
assert.strictEqual(decode.hash.toString('hex'), f.hash) |
|
|
@ -22,7 +20,7 @@ describe('Address', function () { |
|
|
|
fixtures.invalid.fromBase58Check.forEach(function (f) { |
|
|
|
it('throws on ' + f.exception, function () { |
|
|
|
assert.throws(function () { |
|
|
|
Address.fromBase58Check(f.address) |
|
|
|
baddress.fromBase58Check(f.address) |
|
|
|
}, new RegExp(f.address + ' ' + f.exception)) |
|
|
|
}) |
|
|
|
}) |
|
|
@ -32,7 +30,7 @@ describe('Address', function () { |
|
|
|
fixtures.valid.forEach(function (f) { |
|
|
|
it('parses ' + f.script.slice(0, 30) + '... (' + f.network + ')', function () { |
|
|
|
var script = scripts.fromASM(f.script) |
|
|
|
var address = Address.fromOutputScript(script, networks[f.network]) |
|
|
|
var address = baddress.fromOutputScript(script, networks[f.network]) |
|
|
|
|
|
|
|
assert.strictEqual(address, f.base58check) |
|
|
|
}) |
|
|
@ -43,7 +41,7 @@ describe('Address', function () { |
|
|
|
var script = scripts.fromASM(f.script) |
|
|
|
|
|
|
|
assert.throws(function () { |
|
|
|
Address.fromOutputScript(script) |
|
|
|
baddress.fromOutputScript(script) |
|
|
|
}, new RegExp(f.script + ' ' + f.exception)) |
|
|
|
}) |
|
|
|
}) |
|
|
@ -52,7 +50,7 @@ describe('Address', function () { |
|
|
|
describe('toBase58Check', function () { |
|
|
|
fixtures.valid.forEach(function (f) { |
|
|
|
it('formats ' + f.hash + ' (' + f.network + ')', function () { |
|
|
|
var address = Address.toBase58Check(new Buffer(f.hash, 'hex'), f.version) |
|
|
|
var address = baddress.toBase58Check(new Buffer(f.hash, 'hex'), f.version) |
|
|
|
|
|
|
|
assert.strictEqual(address, f.base58check) |
|
|
|
}) |
|
|
@ -64,7 +62,7 @@ describe('Address', function () { |
|
|
|
var network = networks[f.network] |
|
|
|
|
|
|
|
it('exports ' + f.script.slice(0, 30) + '... (' + f.network + ')', function () { |
|
|
|
var script = Address.toOutputScript(f.base58check, network) |
|
|
|
var script = baddress.toOutputScript(f.base58check, network) |
|
|
|
|
|
|
|
assert.strictEqual(scripts.toASM(script), f.script) |
|
|
|
}) |
|
|
@ -73,7 +71,7 @@ describe('Address', function () { |
|
|
|
fixtures.invalid.toOutputScript.forEach(function (f) { |
|
|
|
it('throws when ' + f.exception, function () { |
|
|
|
assert.throws(function () { |
|
|
|
Address.toOutputScript(f.address) |
|
|
|
baddress.toOutputScript(f.address) |
|
|
|
}, new RegExp(f.address + ' ' + f.exception)) |
|
|
|
}) |
|
|
|
}) |
|
|
|