@@ -132,6 +132,68 @@ describe('Ton Single Nominator Withdraw Builder', () => {
132132 should . equal ( txBounceable . toJson ( ) . withdrawAmount , singleNominatorWithdrawAmount ) ;
133133 } ) ;
134134
135+ it ( 'should build a full withdrawal tx using setFullWithdrawalMessage' , async function ( ) {
136+ const txBuilder = factory . getSingleNominatorWithdrawBuilder ( ) ;
137+ txBuilder . sender ( testData . sender . address ) ;
138+ txBuilder . sequenceNumber ( 0 ) ;
139+ txBuilder . publicKey ( testData . sender . publicKey ) ;
140+ txBuilder . expireTime ( 1234567890 ) ;
141+ txBuilder . send ( testData . recipients [ 0 ] ) ;
142+ txBuilder . setFullWithdrawalMessage ( ) ;
143+ const tx = await txBuilder . build ( ) ;
144+ should . equal ( tx . type , TransactionType . SingleNominatorWithdraw ) ;
145+ should . equal ( tx . toJson ( ) . bounceable , false ) ;
146+ should . equal ( tx . toJson ( ) . withdrawAmount , undefined ) ;
147+ tx . inputs . length . should . equal ( 1 ) ;
148+ tx . inputs [ 0 ] . should . deepEqual ( {
149+ address : testData . sender . address ,
150+ value : testData . recipients [ 0 ] . amount ,
151+ coin : 'tton' ,
152+ } ) ;
153+ tx . outputs . length . should . equal ( 1 ) ;
154+ tx . outputs [ 0 ] . should . deepEqual ( {
155+ address : testData . recipients [ 0 ] . address ,
156+ value : testData . recipients [ 0 ] . amount ,
157+ coin : 'tton' ,
158+ } ) ;
159+ const rawTx = tx . toBroadcastFormat ( ) ;
160+ // Verify the raw transaction can be parsed back as a full withdrawal
161+ // Full withdrawal is inferred by: transactionType === SingleNominatorWithdraw && !withdrawAmount
162+ const txBuilder2 = factory . from ( rawTx ) ;
163+ const tx2 = await txBuilder2 . build ( ) ;
164+ should . equal ( tx2 . type , TransactionType . SingleNominatorWithdraw ) ;
165+ should . equal ( tx2 . toJson ( ) . withdrawAmount , undefined ) ;
166+ should . equal ( tx2 . toBroadcastFormat ( ) , rawTx ) ;
167+ } ) ;
168+
169+ it ( 'should build a signed full withdrawal tx using add signature' , async function ( ) {
170+ const keyPair = new KeyPair ( { prv : testData . privateKeys . prvKey1 } ) ;
171+ const publicKey = keyPair . getKeys ( ) . pub ;
172+ const address = await utils . default . getAddressFromPublicKey ( publicKey ) ;
173+ const txBuilder = factory . getSingleNominatorWithdrawBuilder ( ) ;
174+ txBuilder . sender ( address ) ;
175+ txBuilder . sequenceNumber ( 0 ) ;
176+ txBuilder . publicKey ( publicKey ) ;
177+ const expireAt = Math . floor ( Date . now ( ) / 1e3 ) + 60 * 60 * 24 * 7 ;
178+ txBuilder . expireTime ( expireAt ) ;
179+ txBuilder . send ( testData . recipients [ 0 ] ) ;
180+ txBuilder . setFullWithdrawalMessage ( ) ;
181+ const tx = await txBuilder . build ( ) ;
182+ should . equal ( tx . type , TransactionType . SingleNominatorWithdraw ) ;
183+ should . equal ( tx . toJson ( ) . withdrawAmount , undefined ) ;
184+ const signable = tx . signablePayload ;
185+ const signature = keyPair . signMessageinUint8Array ( signable ) ;
186+ txBuilder . addSignature ( keyPair . getKeys ( ) , Buffer . from ( signature ) ) ;
187+ const signedTx = await txBuilder . build ( ) ;
188+ const builder2 = factory . from ( signedTx . toBroadcastFormat ( ) ) ;
189+ const tx2 = await builder2 . build ( ) ;
190+ const signature2 = keyPair . signMessageinUint8Array ( tx2 . signablePayload ) ;
191+ should . equal ( Buffer . from ( signature ) . toString ( 'hex' ) , Buffer . from ( signature2 ) . toString ( 'hex' ) ) ;
192+ should . equal ( tx . toBroadcastFormat ( ) , tx2 . toBroadcastFormat ( ) ) ;
193+ should . equal ( tx2 . type , TransactionType . SingleNominatorWithdraw ) ;
194+ should . equal ( tx2 . toJson ( ) . withdrawAmount , undefined ) ;
195+ } ) ;
196+
135197 xit ( 'should build a signed withdraw tx and submit onchain' , async function ( ) {
136198 const tonweb = new TonWeb ( new TonWeb . HttpProvider ( 'https://testnet.toncenter.com/api/v2/jsonRPC' ) ) ;
137199 const keyPair = new KeyPair ( { prv : testData . privateKeys . prvKey1 } ) ;
0 commit comments