Skip to content

Commit 5999f53

Browse files
OttoAllmendingerllm-git
andcommitted
refactor(utxo-staking): add toDescriptor helper for descriptor type handling
Add DescriptorLike type and toDescriptor helper function to improve code readability and reduce duplicate conversion logic in undelegation tests. Issue: BTC-2143 Co-authored-by: llm-git <[email protected]>
1 parent 050c7cb commit 5999f53

File tree

1 file changed

+45
-38
lines changed

1 file changed

+45
-38
lines changed

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

Lines changed: 45 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,15 @@ async function getFixture(txid: string): Promise<UndelegationResponse> {
2727
return result.right.btc_delegation.undelegation_response;
2828
}
2929

30-
function runTest(network: utxolib.Network, txid: string, descriptor: Descriptor | ast.DescriptorNode | string): void {
30+
type DescriptorLike = Descriptor | ast.DescriptorNode | string;
31+
32+
function toDescriptor(descriptor: DescriptorLike): Descriptor {
33+
return descriptor instanceof Descriptor
34+
? descriptor
35+
: Descriptor.fromStringDetectType(typeof descriptor === 'string' ? descriptor : ast.formatNode(descriptor));
36+
}
37+
38+
function runTest(network: utxolib.Network, txid: string, descriptor: Descriptor): void {
3139
describe(`Unbonding transaction ${txid}`, function () {
3240
it('should create a PSBT from the unbonding transaction', async function () {
3341
const fixture = await getFixture(txid);
@@ -37,11 +45,6 @@ function runTest(network: utxolib.Network, txid: string, descriptor: Descriptor
3745
});
3846
const signatures = fixture.covenant_unbonding_sig_list.map((sig) => toPartialSig(sig));
3947

40-
descriptor =
41-
descriptor instanceof Descriptor
42-
? descriptor
43-
: Descriptor.fromStringDetectType(typeof descriptor === 'string' ? descriptor : ast.formatNode(descriptor));
44-
4548
const psbt = toUnbondingPsbtWithSignatures(
4649
tx,
4750
{
@@ -63,38 +66,21 @@ function runTest(network: utxolib.Network, txid: string, descriptor: Descriptor
6366
});
6467
}
6568

66-
runTest(utxolib.networks.bitcoinPublicSignet, '5d277e1b29e5589074aea95ac8c8230fd911c2ec3c58774aafdef915619b772c', {
67-
tr: [
68-
'50929b74c1a04954b78b4b6035e97a5e078a5a0f28ec96d547bfee9ace803ac0',
69-
[
70-
{
71-
and_v: [
72-
{
73-
and_v: [
74-
{ 'v:pk': '1b443f34ddc1bbaef52a8c5162dfa5a84524636ec745292f949470369ee67391' },
75-
{ 'v:pk': 'd23c2c25e1fcf8fd1c21b9a402c19e2e309e531e45e92fb1e9805b6056b0cc76' },
76-
],
77-
},
78-
{
79-
multi_a: [
80-
6,
81-
'0aee0509b16db71c999238a4827db945526859b13c95487ab46725357c9a9f25',
82-
'113c3a32a9d320b72190a04a020a0db3976ef36972673258e9a38a364f3dc3b0',
83-
'17921cf156ccb4e73d428f996ed11b245313e37e27c978ac4d2cc21eca4672e4',
84-
'3bb93dfc8b61887d771f3630e9a63e97cbafcfcc78556a474df83a31a0ef899c',
85-
'40afaf47c4ffa56de86410d8e47baa2bb6f04b604f4ea24323737ddc3fe092df',
86-
'79a71ffd71c503ef2e2f91bccfc8fcda7946f4653cef0d9f3dde20795ef3b9f0',
87-
'd21faf78c6751a0d38e6bd8028b907ff07e9a869a43fc837d6b3f8dff6119a36',
88-
'f5199efae3f28bb82476163a7e458c7ad445d9bffb0682d10d3bdb2cb41f8e8e',
89-
'fa9d882d45f4060bdb8042183828cd87544f1ea997380e586cab77d5fd698737',
90-
],
91-
},
92-
],
93-
},
69+
runTest(
70+
utxolib.networks.bitcoinPublicSignet,
71+
'5d277e1b29e5589074aea95ac8c8230fd911c2ec3c58774aafdef915619b772c',
72+
toDescriptor({
73+
tr: [
74+
'50929b74c1a04954b78b4b6035e97a5e078a5a0f28ec96d547bfee9ace803ac0',
9475
[
9576
{
9677
and_v: [
97-
{ 'v:pk': '1b443f34ddc1bbaef52a8c5162dfa5a84524636ec745292f949470369ee67391' },
78+
{
79+
and_v: [
80+
{ 'v:pk': '1b443f34ddc1bbaef52a8c5162dfa5a84524636ec745292f949470369ee67391' },
81+
{ 'v:pk': 'd23c2c25e1fcf8fd1c21b9a402c19e2e309e531e45e92fb1e9805b6056b0cc76' },
82+
],
83+
},
9884
{
9985
multi_a: [
10086
6,
@@ -111,8 +97,29 @@ runTest(utxolib.networks.bitcoinPublicSignet, '5d277e1b29e5589074aea95ac8c8230fd
11197
},
11298
],
11399
},
114-
{ and_v: [{ 'v:pk': '1b443f34ddc1bbaef52a8c5162dfa5a84524636ec745292f949470369ee67391' }, { older: 10000 }] },
100+
[
101+
{
102+
and_v: [
103+
{ 'v:pk': '1b443f34ddc1bbaef52a8c5162dfa5a84524636ec745292f949470369ee67391' },
104+
{
105+
multi_a: [
106+
6,
107+
'0aee0509b16db71c999238a4827db945526859b13c95487ab46725357c9a9f25',
108+
'113c3a32a9d320b72190a04a020a0db3976ef36972673258e9a38a364f3dc3b0',
109+
'17921cf156ccb4e73d428f996ed11b245313e37e27c978ac4d2cc21eca4672e4',
110+
'3bb93dfc8b61887d771f3630e9a63e97cbafcfcc78556a474df83a31a0ef899c',
111+
'40afaf47c4ffa56de86410d8e47baa2bb6f04b604f4ea24323737ddc3fe092df',
112+
'79a71ffd71c503ef2e2f91bccfc8fcda7946f4653cef0d9f3dde20795ef3b9f0',
113+
'd21faf78c6751a0d38e6bd8028b907ff07e9a869a43fc837d6b3f8dff6119a36',
114+
'f5199efae3f28bb82476163a7e458c7ad445d9bffb0682d10d3bdb2cb41f8e8e',
115+
'fa9d882d45f4060bdb8042183828cd87544f1ea997380e586cab77d5fd698737',
116+
],
117+
},
118+
],
119+
},
120+
{ and_v: [{ 'v:pk': '1b443f34ddc1bbaef52a8c5162dfa5a84524636ec745292f949470369ee67391' }, { older: 10000 }] },
121+
],
115122
],
116123
],
117-
],
118-
});
124+
})
125+
);

0 commit comments

Comments
 (0)