Skip to content

Commit 941989d

Browse files
OttoAllmendingerllm-git
andcommitted
feat(utxo-staking): add separate tests for PSBT signature validation
Add separate test cases for validating signatures in the PSBT and for matching against fixture data in the unbonding transaction tests. This provides clearer test structure and better isolation of concerns. Issue: BTC-2319 Co-authored-by: llm-git <[email protected]>
1 parent 5999f53 commit 941989d

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

modules/utxo-staking/test/unit/babylon/undelegation.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { PathReporter } from 'io-ts/lib/PathReporter';
55
import { isLeft } from 'fp-ts/Either';
66
import * as utxolib from '@bitgo/utxo-lib';
77
import { ast, Descriptor } from '@bitgo/wasm-miniscript';
8+
import { PartialSig } from 'bip174/src/lib/interfaces';
89

910
import { toPartialSig, UndelegationResponse } from '../../../src/babylon/undelegation/UndelegationResponse';
1011
import { assertValidSignatures, toUnbondingPsbtWithSignatures } from '../../../src/babylon/undelegation/unbonding';
@@ -37,15 +38,18 @@ function toDescriptor(descriptor: DescriptorLike): Descriptor {
3738

3839
function runTest(network: utxolib.Network, txid: string, descriptor: Descriptor): void {
3940
describe(`Unbonding transaction ${txid}`, function () {
40-
it('should create a PSBT from the unbonding transaction', async function () {
41+
let psbt: utxolib.bitgo.UtxoPsbt;
42+
let signatures: PartialSig[];
43+
44+
before('should create a PSBT from the unbonding transaction', async function () {
4145
const fixture = await getFixture(txid);
4246
const txBuffer = Buffer.from(fixture.unbonding_tx_hex, 'hex');
4347
const tx = utxolib.bitgo.createTransactionFromBuffer(txBuffer, network, {
4448
amountType: 'bigint',
4549
});
46-
const signatures = fixture.covenant_unbonding_sig_list.map((sig) => toPartialSig(sig));
50+
signatures = fixture.covenant_unbonding_sig_list.map((sig) => toPartialSig(sig));
4751

48-
const psbt = toUnbondingPsbtWithSignatures(
52+
psbt = toUnbondingPsbtWithSignatures(
4953
tx,
5054
{
5155
script: Buffer.from('5120b81e8691ab3c46bddf8ea43f776e4d64abf417a0fa5a4d09976c8aaadabbb6a0', 'hex'),
@@ -55,9 +59,13 @@ function runTest(network: utxolib.Network, txid: string, descriptor: Descriptor)
5559
signatures,
5660
utxolib.networks.testnet
5761
);
62+
});
5863

64+
it('should have valid signatures', async function () {
5965
assertValidSignatures(psbt, 0, signatures);
66+
});
6067

68+
it('should match the fixture', async function () {
6169
await assertTransactionEqualsFixture(
6270
'test/fixtures/babylon/unbonding.' + txid.substring(0, 4) + '.psbt.json',
6371
psbt

0 commit comments

Comments
 (0)