File tree Expand file tree Collapse file tree 1 file changed +29
-5
lines changed
packages/wasm-miniscript/test Expand file tree Collapse file tree 1 file changed +29
-5
lines changed Original file line number Diff line number Diff line change @@ -17,6 +17,25 @@ function removeChecksum(descriptor: string): string {
1717 return parts [ 0 ] ;
1818}
1919
20+ function getScriptPubKeyLength ( descType : string ) : number {
21+ switch ( descType ) {
22+ case "Wpkh" :
23+ return 22 ;
24+ case "Sh" :
25+ case "ShWsh" :
26+ case "ShWpkh" :
27+ return 23 ;
28+ case "Pkh" :
29+ return 25 ;
30+ case "Wsh" :
31+ return 34 ;
32+ case "Bare" :
33+ throw new Error ( "cannot determine scriptPubKey length for Bare descriptor" ) ;
34+ default :
35+ throw new Error ( "unexpected descriptor type " + descType ) ;
36+ }
37+ }
38+
2039describe ( "Descriptor fixtures" , function ( ) {
2140 fixtures . valid . forEach ( ( fixture , i ) => {
2241 it ( "should parse fixture " + i , function ( ) {
@@ -51,12 +70,17 @@ describe("Descriptor fixtures", function () {
5170 descriptorString = removeChecksum ( descriptorString ) ;
5271 }
5372 const descriptor = Descriptor . fromString ( descriptorString , "derivable" ) ;
54- assert . strictEqual (
55- Buffer . from ( descriptor . atDerivationIndex ( fixture . index ?? 0 ) . scriptPubkey ( ) ) . toString (
56- "hex" ,
57- ) ,
58- fixture . script ,
73+ const scriptPubKey = Buffer . from (
74+ descriptor . atDerivationIndex ( fixture . index ?? 0 ) . scriptPubkey ( ) ,
5975 ) ;
76+ assert . strictEqual ( scriptPubKey . toString ( "hex" ) , fixture . script ) ;
77+ if ( descriptor . descType ( ) !== "Bare" ) {
78+ assert . strictEqual (
79+ scriptPubKey . length ,
80+ getScriptPubKeyLength ( descriptor . descType ( ) ) ,
81+ `Unexpected scriptPubKey length for descriptor ${ descriptor . descType ( ) } : ${ scriptPubKey . length } ` ,
82+ ) ;
83+ }
6084 }
6185
6286 assert . ok ( Number . isInteger ( descriptor . maxWeightToSatisfy ( ) ) ) ;
You can’t perform that action at this time.
0 commit comments