2019-06-28 12:17:18 +02:00
|
|
|
const { describe, it } = require('mocha')
|
2019-06-26 13:20:49 +02:00
|
|
|
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')
|
2019-06-26 13:20:49 +02:00
|
|
|
|
|
|
|
describe(`Psbt`, () => {
|
2019-07-03 11:40:37 +02:00
|
|
|
describe('BIP174 Test Vectors', () => {
|
2019-07-03 12:01:47 +02:00
|
|
|
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})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2019-06-26 13:20:49 +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(() => {
|
2019-07-02 13:15:30 +02:00
|
|
|
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(() => {
|
2019-07-02 13:15:30 +02:00
|
|
|
psbtThatShouldThrow.signInput(
|
|
|
|
f.shouldThrow.inputToCheck,
|
|
|
|
ECPair.fromWIF(f.shouldThrow.WIF),
|
|
|
|
)
|
2019-06-28 11:55:00 +02:00
|
|
|
}, {message: f.shouldThrow.errorMessage})
|
2019-06-27 13:20:19 +02:00
|
|
|
})
|
|
|
|
})
|
2019-06-26 13:20:49 +02:00
|
|
|
})
|
|
|
|
})
|