bitcoinjs-lib/test/psbt.js

42 lines
1.1 KiB
JavaScript
Raw Normal View History

2019-06-28 12:17:18 +02:00
const { describe, it } = require('mocha')
const assert = require('assert')
const ECPair = require('../src/ecpair')
const Psbt = require('..').Psbt
2019-06-28 11:55:00 +02:00
const fixtures = require('./fixtures/psbt')
describe(`Psbt`, () => {
2019-07-03 11:40:37 +02:00
describe('BIP174 Test Vectors', () => {
fixtures.bip174.invalid.forEach((f, i) => {
it(`Invalid #${i + 1}: "${f.errorMessage}"`, () => {
2019-07-03 11:40:37 +02:00
assert.throws(() => {
Psbt.fromBase64(f.psbt)
}, {message: f.errorMessage})
})
})
})
describe('signInput', () => {
2019-06-28 11:55:00 +02:00
fixtures.signInput.checks.forEach(f => {
it(f.description, () => {
const psbtThatShouldsign = Psbt.fromBase64(f.shouldSign.psbt)
assert.doesNotThrow(() => {
psbtThatShouldsign.signInput(
f.shouldSign.inputToCheck,
ECPair.fromWIF(f.shouldSign.WIF),
)
2019-06-28 11:55:00 +02:00
})
const psbtThatShouldThrow = Psbt.fromBase64(f.shouldThrow.psbt)
assert.throws(() => {
psbtThatShouldThrow.signInput(
f.shouldThrow.inputToCheck,
ECPair.fromWIF(f.shouldThrow.WIF),
)
2019-06-28 11:55:00 +02:00
}, {message: f.shouldThrow.errorMessage})
})
})
})
})