Test signing a non-whitelisted sighashtype
This commit is contained in:
parent
1feef9569c
commit
f25938d3ca
2 changed files with 101 additions and 68 deletions
9
test/fixtures/psbt.json
vendored
9
test/fixtures/psbt.json
vendored
|
@ -427,6 +427,15 @@
|
|||
"inputToCheck": 0,
|
||||
"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"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
|
|
24
test/psbt.js
24
test/psbt.js
|
@ -167,19 +167,24 @@ describe(`Psbt`, () => {
|
|||
describe('signInputAsync', () => {
|
||||
fixtures.signInput.checks.forEach(f => {
|
||||
it(f.description, async () => {
|
||||
if (f.shouldSign) {
|
||||
const psbtThatShouldsign = Psbt.fromBase64(f.shouldSign.psbt)
|
||||
assert.doesNotReject(async () => {
|
||||
await psbtThatShouldsign.signInputAsync(
|
||||
f.shouldSign.inputToCheck,
|
||||
ECPair.fromWIF(f.shouldSign.WIF),
|
||||
f.shouldSign.sighashTypes || undefined,
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
if (f.shouldThrow) {
|
||||
const psbtThatShouldThrow = Psbt.fromBase64(f.shouldThrow.psbt)
|
||||
assert.rejects(async () => {
|
||||
await psbtThatShouldThrow.signInputAsync(
|
||||
f.shouldThrow.inputToCheck,
|
||||
ECPair.fromWIF(f.shouldThrow.WIF),
|
||||
f.shouldThrow.sighashTypes || undefined,
|
||||
)
|
||||
}, new RegExp(f.shouldThrow.errorMessage))
|
||||
assert.rejects(async () => {
|
||||
|
@ -187,6 +192,7 @@ describe(`Psbt`, () => {
|
|||
f.shouldThrow.inputToCheck,
|
||||
)
|
||||
}, new RegExp('Need Signer to sign input'))
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
||||
|
@ -194,19 +200,24 @@ describe(`Psbt`, () => {
|
|||
describe('signInput', () => {
|
||||
fixtures.signInput.checks.forEach(f => {
|
||||
it(f.description, () => {
|
||||
if (f.shouldSign) {
|
||||
const psbtThatShouldsign = Psbt.fromBase64(f.shouldSign.psbt)
|
||||
assert.doesNotThrow(() => {
|
||||
psbtThatShouldsign.signInput(
|
||||
f.shouldSign.inputToCheck,
|
||||
ECPair.fromWIF(f.shouldSign.WIF),
|
||||
f.shouldSign.sighashTypes || undefined,
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
if (f.shouldThrow) {
|
||||
const psbtThatShouldThrow = Psbt.fromBase64(f.shouldThrow.psbt)
|
||||
assert.throws(() => {
|
||||
psbtThatShouldThrow.signInput(
|
||||
f.shouldThrow.inputToCheck,
|
||||
ECPair.fromWIF(f.shouldThrow.WIF),
|
||||
f.shouldThrow.sighashTypes || undefined,
|
||||
)
|
||||
}, new RegExp(f.shouldThrow.errorMessage))
|
||||
assert.throws(() => {
|
||||
|
@ -214,6 +225,7 @@ describe(`Psbt`, () => {
|
|||
f.shouldThrow.inputToCheck,
|
||||
)
|
||||
}, new RegExp('Need Signer to sign input'))
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
||||
|
@ -222,22 +234,28 @@ describe(`Psbt`, () => {
|
|||
fixtures.signInput.checks.forEach(f => {
|
||||
if (f.description === 'checks the input exists') return
|
||||
it(f.description, async () => {
|
||||
if (f.shouldSign) {
|
||||
const psbtThatShouldsign = Psbt.fromBase64(f.shouldSign.psbt)
|
||||
assert.doesNotReject(async () => {
|
||||
await psbtThatShouldsign.signAsync(
|
||||
ECPair.fromWIF(f.shouldSign.WIF),
|
||||
f.shouldSign.sighashTypes || undefined,
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
if (f.shouldThrow) {
|
||||
const psbtThatShouldThrow = Psbt.fromBase64(f.shouldThrow.psbt)
|
||||
assert.rejects(async () => {
|
||||
await psbtThatShouldThrow.signAsync(
|
||||
ECPair.fromWIF(f.shouldThrow.WIF),
|
||||
f.shouldThrow.sighashTypes || undefined,
|
||||
)
|
||||
}, new RegExp('No inputs were signed'))
|
||||
assert.rejects(async () => {
|
||||
await psbtThatShouldThrow.signAsync()
|
||||
}, new RegExp('Need Signer to sign input'))
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
||||
|
@ -246,22 +264,28 @@ describe(`Psbt`, () => {
|
|||
fixtures.signInput.checks.forEach(f => {
|
||||
if (f.description === 'checks the input exists') return
|
||||
it(f.description, () => {
|
||||
if (f.shouldSign) {
|
||||
const psbtThatShouldsign = Psbt.fromBase64(f.shouldSign.psbt)
|
||||
assert.doesNotThrow(() => {
|
||||
psbtThatShouldsign.sign(
|
||||
ECPair.fromWIF(f.shouldSign.WIF),
|
||||
f.shouldSign.sighashTypes || undefined,
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
if (f.shouldThrow) {
|
||||
const psbtThatShouldThrow = Psbt.fromBase64(f.shouldThrow.psbt)
|
||||
assert.throws(() => {
|
||||
psbtThatShouldThrow.sign(
|
||||
ECPair.fromWIF(f.shouldThrow.WIF),
|
||||
f.shouldThrow.sighashTypes || undefined,
|
||||
)
|
||||
}, new RegExp('No inputs were signed'))
|
||||
assert.throws(() => {
|
||||
psbtThatShouldThrow.sign()
|
||||
}, new RegExp('Need Signer to sign input'))
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
Loading…
Add table
Reference in a new issue