bitcoinjs-lib/test/psbt.js

60 lines
1.6 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 => {
it(`Invalid: ${f.description}`, () => {
2019-07-03 11:40:37 +02:00
assert.throws(() => {
Psbt.fromBase64(f.psbt)
}, {message: f.errorMessage})
})
})
2019-07-03 12:02:02 +02:00
fixtures.bip174.valid.forEach(f => {
it(`Valid: ${f.description}`, () => {
2019-07-03 12:02:02 +02:00
assert.doesNotThrow(() => {
Psbt.fromBase64(f.psbt)
2019-07-03 12:02:02 +02:00
})
})
})
2019-07-03 12:38:09 +02:00
fixtures.bip174.failSignChecks.forEach(f => {
const keyPair = ECPair.makeRandom()
it(`Fails Signer checks: ${f.description}`, () => {
const psbt = Psbt.fromBase64(f.psbt)
assert.throws(() => {
psbt.signInput(f.inputToCheck, keyPair)
}, {message: f.errorMessage})
})
})
2019-07-03 11:40:37 +02:00
})
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})
})
})
})
})