|
|
@ -8,7 +8,7 @@ var fixtures = require('./fixtures/address.json') |
|
|
|
|
|
|
|
describe('address', function () { |
|
|
|
describe('fromBase58Check', function () { |
|
|
|
fixtures.valid.forEach(function (f) { |
|
|
|
fixtures.standard.forEach(function (f) { |
|
|
|
it('decodes ' + f.base58check, function () { |
|
|
|
var decode = baddress.fromBase58Check(f.base58check) |
|
|
|
|
|
|
@ -26,8 +26,30 @@ describe('address', function () { |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
describe('fromBech32', function () { |
|
|
|
fixtures.bech32.forEach((f) => { |
|
|
|
it('encodes ' + f.address, function () { |
|
|
|
var actual = baddress.fromBech32(f.address) |
|
|
|
|
|
|
|
assert.strictEqual(actual.prefix, f.prefix) |
|
|
|
assert.strictEqual(actual.program.toString('hex'), f.program) |
|
|
|
assert.strictEqual(actual.version, f.version) |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
fixtures.invalid.bech32.forEach((f, i) => { |
|
|
|
if (f.address === undefined) return |
|
|
|
|
|
|
|
it('decode fails for ' + f.address + '(' + f.exception + ')', function () { |
|
|
|
assert.throws(function () { |
|
|
|
baddress.fromBech32(f.address, f.prefix) |
|
|
|
}, new RegExp(f.exception)) |
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
describe('fromOutputScript', function () { |
|
|
|
fixtures.valid.forEach(function (f) { |
|
|
|
fixtures.standard.forEach(function (f) { |
|
|
|
it('parses ' + f.script.slice(0, 30) + '... (' + f.network + ')', function () { |
|
|
|
var script = bscript.fromASM(f.script) |
|
|
|
var address = baddress.fromOutputScript(script, networks[f.network]) |
|
|
@ -48,7 +70,7 @@ describe('address', function () { |
|
|
|
}) |
|
|
|
|
|
|
|
describe('toBase58Check', function () { |
|
|
|
fixtures.valid.forEach(function (f) { |
|
|
|
fixtures.standard.forEach(function (f) { |
|
|
|
it('formats ' + f.hash + ' (' + f.network + ')', function () { |
|
|
|
var address = baddress.toBase58Check(Buffer.from(f.hash, 'hex'), f.version) |
|
|
|
|
|
|
@ -57,8 +79,30 @@ describe('address', function () { |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
describe('toBech32', function () { |
|
|
|
fixtures.bech32.forEach((f, i) => { |
|
|
|
// unlike the reference impl., we don't support mixed/uppercase
|
|
|
|
var string = f.address.toLowerCase() |
|
|
|
var program = Buffer.from(f.program, 'hex') |
|
|
|
|
|
|
|
it('encode ' + string, function () { |
|
|
|
assert.deepEqual(baddress.toBech32(f.prefix, f.version, program), string) |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
fixtures.invalid.bech32.forEach((f, i) => { |
|
|
|
if (!f.prefix || f.version === undefined || f.program === undefined) return |
|
|
|
|
|
|
|
it('encode fails (' + f.exception, function () { |
|
|
|
assert.throws(function () { |
|
|
|
baddress.toBech32(f.prefix, f.version, Buffer.from(f.program, 'hex')) |
|
|
|
}, new RegExp(f.exception)) |
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
describe('toOutputScript', function () { |
|
|
|
fixtures.valid.forEach(function (f) { |
|
|
|
fixtures.standard.forEach(function (f) { |
|
|
|
var network = networks[f.network] |
|
|
|
|
|
|
|
it('exports ' + f.script.slice(0, 30) + '... (' + f.network + ')', function () { |
|
|
|