11import should from 'should' ;
2- import { pubKeyfromPrivKey , publicKeyToString } from '@stacks/transactions' ;
2+ import { ClarityType , pubKeyfromPrivKey , publicKeyToString } from '@stacks/transactions' ;
3+ import { ContractCallPayload } from '@stacks/transactions/dist/payload' ;
34
45import { TestBitGo , TestBitGoAPI } from '@bitgo/sdk-test' ;
56import { BitGoAPI } from '@bitgo/sdk-api' ;
@@ -52,6 +53,18 @@ describe('Stacks: sBTC Withdraw Builder', function () {
5253 should . exist ( txJson . payload ) ;
5354 txJson . payload . should . have . property ( 'contractName' , 'sbtc-withdrawal' ) ;
5455 txJson . payload . should . have . property ( 'functionName' , 'initiate-withdrawal-request' ) ;
56+
57+ // Verify hashbytes is 20 bytes for P2PKH
58+ const payload = ( tx as StxLib . Transaction ) . stxTransaction . payload as ContractCallPayload ;
59+ const recipientTuple = payload . functionArgs [ 1 ] ;
60+ should . equal ( recipientTuple . type , ClarityType . Tuple ) ;
61+ if ( recipientTuple . type === ClarityType . Tuple ) {
62+ const hashbytes = recipientTuple . data [ 'hashbytes' ] ;
63+ should . equal ( hashbytes . type , ClarityType . Buffer ) ;
64+ if ( hashbytes . type === ClarityType . Buffer ) {
65+ hashbytes . buffer . length . should . equal ( 20 ) ;
66+ }
67+ }
5568 } ) ;
5669
5770 it ( 'a withdrawal with P2SH address' , async ( ) => {
@@ -68,6 +81,16 @@ describe('Stacks: sBTC Withdraw Builder', function () {
6881 const tx = await builder . build ( ) ;
6982 const txJson = tx . toJson ( ) ;
7083 txJson . payload . should . have . property ( 'functionName' , 'initiate-withdrawal-request' ) ;
84+
85+ // Verify hashbytes is 20 bytes for P2SH
86+ const payload = ( tx as StxLib . Transaction ) . stxTransaction . payload as ContractCallPayload ;
87+ const recipientTuple = payload . functionArgs [ 1 ] ;
88+ if ( recipientTuple . type === ClarityType . Tuple ) {
89+ const hashbytes = recipientTuple . data [ 'hashbytes' ] ;
90+ if ( hashbytes . type === ClarityType . Buffer ) {
91+ hashbytes . buffer . length . should . equal ( 20 ) ;
92+ }
93+ }
7194 } ) ;
7295
7396 it ( 'a withdrawal with P2WPKH (bech32) address' , async ( ) => {
@@ -84,6 +107,16 @@ describe('Stacks: sBTC Withdraw Builder', function () {
84107 const tx = await builder . build ( ) ;
85108 const txJson = tx . toJson ( ) ;
86109 txJson . payload . should . have . property ( 'functionName' , 'initiate-withdrawal-request' ) ;
110+
111+ // Verify hashbytes is 20 bytes for P2WPKH
112+ const payload = ( tx as StxLib . Transaction ) . stxTransaction . payload as ContractCallPayload ;
113+ const recipientTuple = payload . functionArgs [ 1 ] ;
114+ if ( recipientTuple . type === ClarityType . Tuple ) {
115+ const hashbytes = recipientTuple . data [ 'hashbytes' ] ;
116+ if ( hashbytes . type === ClarityType . Buffer ) {
117+ hashbytes . buffer . length . should . equal ( 20 ) ;
118+ }
119+ }
87120 } ) ;
88121
89122 it ( 'a withdrawal with P2WSH (bech32) address' , async ( ) => {
@@ -100,6 +133,16 @@ describe('Stacks: sBTC Withdraw Builder', function () {
100133 const tx = await builder . build ( ) ;
101134 const txJson = tx . toJson ( ) ;
102135 txJson . payload . should . have . property ( 'functionName' , 'initiate-withdrawal-request' ) ;
136+
137+ // Verify hashbytes is 32 bytes for P2WSH
138+ const payload = ( tx as StxLib . Transaction ) . stxTransaction . payload as ContractCallPayload ;
139+ const recipientTuple = payload . functionArgs [ 1 ] ;
140+ if ( recipientTuple . type === ClarityType . Tuple ) {
141+ const hashbytes = recipientTuple . data [ 'hashbytes' ] ;
142+ if ( hashbytes . type === ClarityType . Buffer ) {
143+ hashbytes . buffer . length . should . equal ( 32 ) ;
144+ }
145+ }
103146 } ) ;
104147
105148 it ( 'a withdrawal with P2TR (bech32m) address' , async ( ) => {
@@ -116,6 +159,16 @@ describe('Stacks: sBTC Withdraw Builder', function () {
116159 const tx = await builder . build ( ) ;
117160 const txJson = tx . toJson ( ) ;
118161 txJson . payload . should . have . property ( 'functionName' , 'initiate-withdrawal-request' ) ;
162+
163+ // Verify hashbytes is 32 bytes for P2TR
164+ const payload = ( tx as StxLib . Transaction ) . stxTransaction . payload as ContractCallPayload ;
165+ const recipientTuple = payload . functionArgs [ 1 ] ;
166+ if ( recipientTuple . type === ClarityType . Tuple ) {
167+ const hashbytes = recipientTuple . data [ 'hashbytes' ] ;
168+ if ( hashbytes . type === ClarityType . Buffer ) {
169+ hashbytes . buffer . length . should . equal ( 32 ) ;
170+ }
171+ }
119172 } ) ;
120173 } ) ;
121174
0 commit comments