Test signing a non-whitelisted sighashtype

This commit is contained in:
Luke Childs 2019-07-11 16:24:35 +07:00
parent 1feef9569c
commit f25938d3ca
2 changed files with 101 additions and 68 deletions

View file

@ -427,6 +427,15 @@
"inputToCheck": 0, "inputToCheck": 0,
"WIF": "KxnAnQh6UJBxLF8Weup77yn8tWhLHhDhnXeyJuzmmcZA5aRdMJni" "WIF": "KxnAnQh6UJBxLF8Weup77yn8tWhLHhDhnXeyJuzmmcZA5aRdMJni"
} }
},
{
"description": "allows signing non-whitelisted sighashtype when explicitly passed in",
"shouldSign": {
"psbt": "cHNidP8BADMBAAAAAYaq+PdOUY2PnV9kZKa82XlqrPByOqwH2TRg2+LQdqs2AAAAAAD/////AAAAAAAAAQEgAOH1BQAAAAAXqRSTNeWHqa9INvSnQ120SZeJc+6JSocBAwSBAAAAAQQWABQvLKRyDqYsPYImhD3eURpDGL10RwAA",
"sighashTypes": [129],
"inputToCheck": 0,
"WIF": "KxnAnQh6UJBxLF8Weup77yn8tWhLHhDhnXeyJuzmmcZA5aRdMJni"
}
} }
] ]
}, },

View file

@ -167,26 +167,32 @@ describe(`Psbt`, () => {
describe('signInputAsync', () => { describe('signInputAsync', () => {
fixtures.signInput.checks.forEach(f => { fixtures.signInput.checks.forEach(f => {
it(f.description, async () => { it(f.description, async () => {
const psbtThatShouldsign = Psbt.fromBase64(f.shouldSign.psbt) if (f.shouldSign) {
assert.doesNotReject(async () => { const psbtThatShouldsign = Psbt.fromBase64(f.shouldSign.psbt)
await psbtThatShouldsign.signInputAsync( assert.doesNotReject(async () => {
f.shouldSign.inputToCheck, await psbtThatShouldsign.signInputAsync(
ECPair.fromWIF(f.shouldSign.WIF), f.shouldSign.inputToCheck,
) ECPair.fromWIF(f.shouldSign.WIF),
}) f.shouldSign.sighashTypes || undefined,
)
})
}
const psbtThatShouldThrow = Psbt.fromBase64(f.shouldThrow.psbt) if (f.shouldThrow) {
assert.rejects(async () => { const psbtThatShouldThrow = Psbt.fromBase64(f.shouldThrow.psbt)
await psbtThatShouldThrow.signInputAsync( assert.rejects(async () => {
f.shouldThrow.inputToCheck, await psbtThatShouldThrow.signInputAsync(
ECPair.fromWIF(f.shouldThrow.WIF), f.shouldThrow.inputToCheck,
) ECPair.fromWIF(f.shouldThrow.WIF),
}, new RegExp(f.shouldThrow.errorMessage)) f.shouldThrow.sighashTypes || undefined,
assert.rejects(async () => { )
await psbtThatShouldThrow.signInputAsync( }, new RegExp(f.shouldThrow.errorMessage))
f.shouldThrow.inputToCheck, assert.rejects(async () => {
) await psbtThatShouldThrow.signInputAsync(
}, new RegExp('Need Signer to sign input')) f.shouldThrow.inputToCheck,
)
}, new RegExp('Need Signer to sign input'))
}
}) })
}) })
}) })
@ -194,26 +200,32 @@ describe(`Psbt`, () => {
describe('signInput', () => { describe('signInput', () => {
fixtures.signInput.checks.forEach(f => { fixtures.signInput.checks.forEach(f => {
it(f.description, () => { it(f.description, () => {
const psbtThatShouldsign = Psbt.fromBase64(f.shouldSign.psbt) if (f.shouldSign) {
assert.doesNotThrow(() => { const psbtThatShouldsign = Psbt.fromBase64(f.shouldSign.psbt)
psbtThatShouldsign.signInput( assert.doesNotThrow(() => {
f.shouldSign.inputToCheck, psbtThatShouldsign.signInput(
ECPair.fromWIF(f.shouldSign.WIF), f.shouldSign.inputToCheck,
) ECPair.fromWIF(f.shouldSign.WIF),
}) f.shouldSign.sighashTypes || undefined,
)
})
}
const psbtThatShouldThrow = Psbt.fromBase64(f.shouldThrow.psbt) if (f.shouldThrow) {
assert.throws(() => { const psbtThatShouldThrow = Psbt.fromBase64(f.shouldThrow.psbt)
psbtThatShouldThrow.signInput( assert.throws(() => {
f.shouldThrow.inputToCheck, psbtThatShouldThrow.signInput(
ECPair.fromWIF(f.shouldThrow.WIF), f.shouldThrow.inputToCheck,
) ECPair.fromWIF(f.shouldThrow.WIF),
}, new RegExp(f.shouldThrow.errorMessage)) f.shouldThrow.sighashTypes || undefined,
assert.throws(() => { )
psbtThatShouldThrow.signInput( }, new RegExp(f.shouldThrow.errorMessage))
f.shouldThrow.inputToCheck, assert.throws(() => {
) psbtThatShouldThrow.signInput(
}, new RegExp('Need Signer to sign input')) f.shouldThrow.inputToCheck,
)
}, new RegExp('Need Signer to sign input'))
}
}) })
}) })
}) })
@ -222,22 +234,28 @@ describe(`Psbt`, () => {
fixtures.signInput.checks.forEach(f => { fixtures.signInput.checks.forEach(f => {
if (f.description === 'checks the input exists') return if (f.description === 'checks the input exists') return
it(f.description, async () => { it(f.description, async () => {
const psbtThatShouldsign = Psbt.fromBase64(f.shouldSign.psbt) if (f.shouldSign) {
assert.doesNotReject(async () => { const psbtThatShouldsign = Psbt.fromBase64(f.shouldSign.psbt)
await psbtThatShouldsign.signAsync( assert.doesNotReject(async () => {
ECPair.fromWIF(f.shouldSign.WIF), await psbtThatShouldsign.signAsync(
) ECPair.fromWIF(f.shouldSign.WIF),
}) f.shouldSign.sighashTypes || undefined,
)
})
}
const psbtThatShouldThrow = Psbt.fromBase64(f.shouldThrow.psbt) if (f.shouldThrow) {
assert.rejects(async () => { const psbtThatShouldThrow = Psbt.fromBase64(f.shouldThrow.psbt)
await psbtThatShouldThrow.signAsync( assert.rejects(async () => {
ECPair.fromWIF(f.shouldThrow.WIF), await psbtThatShouldThrow.signAsync(
) ECPair.fromWIF(f.shouldThrow.WIF),
}, new RegExp('No inputs were signed')) f.shouldThrow.sighashTypes || undefined,
assert.rejects(async () => { )
await psbtThatShouldThrow.signAsync() }, new RegExp('No inputs were signed'))
}, new RegExp('Need Signer to sign input')) assert.rejects(async () => {
await psbtThatShouldThrow.signAsync()
}, new RegExp('Need Signer to sign input'))
}
}) })
}) })
}) })
@ -246,22 +264,28 @@ describe(`Psbt`, () => {
fixtures.signInput.checks.forEach(f => { fixtures.signInput.checks.forEach(f => {
if (f.description === 'checks the input exists') return if (f.description === 'checks the input exists') return
it(f.description, () => { it(f.description, () => {
const psbtThatShouldsign = Psbt.fromBase64(f.shouldSign.psbt) if (f.shouldSign) {
assert.doesNotThrow(() => { const psbtThatShouldsign = Psbt.fromBase64(f.shouldSign.psbt)
psbtThatShouldsign.sign( assert.doesNotThrow(() => {
ECPair.fromWIF(f.shouldSign.WIF), psbtThatShouldsign.sign(
) ECPair.fromWIF(f.shouldSign.WIF),
}) f.shouldSign.sighashTypes || undefined,
)
})
}
const psbtThatShouldThrow = Psbt.fromBase64(f.shouldThrow.psbt) if (f.shouldThrow) {
assert.throws(() => { const psbtThatShouldThrow = Psbt.fromBase64(f.shouldThrow.psbt)
psbtThatShouldThrow.sign( assert.throws(() => {
ECPair.fromWIF(f.shouldThrow.WIF), psbtThatShouldThrow.sign(
) ECPair.fromWIF(f.shouldThrow.WIF),
}, new RegExp('No inputs were signed')) f.shouldThrow.sighashTypes || undefined,
assert.throws(() => { )
psbtThatShouldThrow.sign() }, new RegExp('No inputs were signed'))
}, new RegExp('Need Signer to sign input')) assert.throws(() => {
psbtThatShouldThrow.sign()
}, new RegExp('Need Signer to sign input'))
}
}) })
}) })
}) })