@@ -4,8 +4,17 @@ import {
4
4
getChangeOutputVSizesForDescriptor ,
5
5
getInputVSizesForDescriptors ,
6
6
getVirtualSize ,
7
+ getVirtualSizeEstimateForPsbt ,
7
8
} from '../../../src/descriptor/VirtualSize' ;
8
- import { DescriptorTemplate , getDescriptor , getDescriptorMap } from '../../../src/testutil/descriptor' ;
9
+ import {
10
+ DescriptorTemplate ,
11
+ getDefaultXPubs ,
12
+ getDescriptor ,
13
+ getDescriptorMap ,
14
+ mockPsbtDefault ,
15
+ } from '../../../src/testutil/descriptor' ;
16
+ import { getKeyTriple } from '../../../src/testutil' ;
17
+ import { finalizePsbt } from '../../../src/descriptor' ;
9
18
10
19
describe ( 'VirtualSize' , function ( ) {
11
20
describe ( 'getInputVSizesForDescriptorWallet' , function ( ) {
@@ -45,11 +54,11 @@ describe('VirtualSize', function () {
45
54
getVirtualSize (
46
55
{
47
56
inputs : [ { descriptorName : 'internal' } ] ,
48
- outputs : [ { script : Buffer . alloc ( 32 ) } ] ,
57
+ outputs : [ { script : Buffer . alloc ( 34 ) } ] ,
49
58
} ,
50
59
getDescriptorMap ( t )
51
60
) ,
52
- outputSize
61
+ inputSize + outputSize + 11
53
62
) ;
54
63
55
64
const descriptor = getDescriptor ( t ) ;
@@ -65,8 +74,28 @@ describe('VirtualSize', function () {
65
74
) ;
66
75
} ) ;
67
76
} ) ;
77
+
78
+ describe ( `getVirtualSizeForPsbt ${ t } ` , function ( ) {
79
+ const keys = getKeyTriple ( 'a' ) ;
80
+ const descriptorSelf = getDescriptor (
81
+ t ,
82
+ keys . map ( ( k ) => k . neutered ( ) . toBase58 ( ) )
83
+ ) ;
84
+ const descriptorOther = getDescriptor ( t , getDefaultXPubs ( 'b' ) ) ;
85
+ it ( 'returns expected virtual size' , function ( ) {
86
+ const psbt = mockPsbtDefault ( { descriptorSelf, descriptorOther } ) ;
87
+ const descriptorMap = new Map ( [ [ 'internal' , descriptorSelf ] ] ) ;
88
+ const expectedVirtualSize = inputSize * 2 + outputSize * 2 + 11 ;
89
+ assert . deepStrictEqual ( getVirtualSizeEstimateForPsbt ( psbt , descriptorMap ) , expectedVirtualSize ) ;
90
+ psbt . signAllInputsHD ( keys [ 0 ] ) ;
91
+ psbt . signAllInputsHD ( keys [ 1 ] ) ;
92
+ finalizePsbt ( psbt ) ;
93
+ // TODO(BTC-1797): figure out why we overestimate by 1
94
+ assert . strictEqual ( psbt . extractTransaction ( ) . virtualSize ( ) , expectedVirtualSize - 1 ) ;
95
+ } ) ;
96
+ } ) ;
68
97
}
69
98
70
- describeWithTemplate ( 'Wsh2Of3' , 105 , 157 ) ;
71
- describeWithTemplate ( 'Tr2Of3-NoKeyPath' , 109 , 161 ) ;
99
+ describeWithTemplate ( 'Wsh2Of3' , 105 , 43 ) ;
100
+ describeWithTemplate ( 'Tr2Of3-NoKeyPath' , 109 , 43 ) ;
72
101
} ) ;
0 commit comments