@@ -257,7 +257,7 @@ describe('Avalanche C-Chain', function () {
257257 owner_3 : '4421ab25dd91e1a3180d03d57c323a7886dcc313d3b3a4b4256a5791572bf597' ,
258258 } ;
259259
260- it ( 'should sign an unsigned test tx ' , async function ( ) {
260+ it ( 'should use recipients from txPrebuild when available including data field ' , async function ( ) {
261261 const builder = getBuilder ( 'tavaxc' ) as TransactionBuilder ;
262262 builder . fee ( {
263263 fee : '280000000000' ,
@@ -271,21 +271,28 @@ describe('Avalanche C-Chain', function () {
271271 const unsignedTx = await builder . build ( ) ;
272272 const unsignedTxForBroadcasting = unsignedTx . toBroadcastFormat ( ) ;
273273
274+ // Test with recipients in txPrebuild including data field
275+ const customRecipients = [
276+ { address : '0x1234567890123456789012345678901234567890' , amount : '500' , data : '0xa9059cbb' } ,
277+ { address : '0x0987654321098765432109876543210987654321' , amount : '300' , data : '0x23b872dd' } ,
278+ ] ;
279+
274280 const halfSignedRawTx = await tavaxCoin . signTransaction ( {
275281 txPrebuild : {
276282 txHex : unsignedTxForBroadcasting ,
283+ recipients : customRecipients ,
277284 } ,
278285 prv : account_1 . owner_2 ,
279286 } ) ;
280287
281- builder . transfer ( ) . key ( account_1 . owner_2 ) ;
282- const halfSignedTx = await builder . build ( ) ;
283- const halfSignedTxForBroadcasting = halfSignedTx . toBroadcastFormat ( ) ;
284-
285- halfSignedRawTx . halfSigned . txHex . should . equals ( halfSignedTxForBroadcasting ) ;
286- halfSignedRawTx . halfSigned . recipients . length . should . equals ( 1 ) ;
287- halfSignedRawTx . halfSigned . recipients [ 0 ] . address . toLowerCase ( ) . should . equals ( account_2 . address . toLowerCase ( ) ) ;
288- halfSignedRawTx . halfSigned . recipients [ 0 ] . amount . toLowerCase ( ) . should . equals ( '1' ) ;
288+ // Should use recipients from txPrebuild, not from transaction outputs
289+ halfSignedRawTx . halfSigned . recipients . length . should . equals ( 2 ) ;
290+ halfSignedRawTx . halfSigned . recipients [ 0 ] . address . should . equals ( customRecipients [ 0 ] . address ) ;
291+ halfSignedRawTx . halfSigned . recipients [ 0 ] . amount . should . equals ( customRecipients [ 0 ] . amount ) ;
292+ halfSignedRawTx . halfSigned . recipients [ 0 ] . data . should . equals ( customRecipients [ 0 ] . data ) ;
293+ halfSignedRawTx . halfSigned . recipients [ 1 ] . address . should . equals ( customRecipients [ 1 ] . address ) ;
294+ halfSignedRawTx . halfSigned . recipients [ 1 ] . amount . should . equals ( customRecipients [ 1 ] . amount ) ;
295+ halfSignedRawTx . halfSigned . recipients [ 1 ] . data . should . equals ( customRecipients [ 1 ] . data ) ;
289296 } ) ;
290297
291298 it ( 'should sign an unsigned test tx with eip1559' , async function ( ) {
@@ -329,7 +336,7 @@ describe('Avalanche C-Chain', function () {
329336 halfSignedRawTx . halfSigned . eip1559 . maxPriorityFeePerGas . should . equal ( '150' ) ;
330337 } ) ;
331338
332- it ( 'should sign an unsigned mainnet tx ' , async function ( ) {
339+ it ( 'should preserve data field from txPrebuild recipients for contract interactions ' , async function ( ) {
333340 const builder = getBuilder ( 'avaxc' ) as TransactionBuilder ;
334341 builder . fee ( {
335342 fee : '280000000000' ,
@@ -343,21 +350,30 @@ describe('Avalanche C-Chain', function () {
343350 const unsignedTx = await builder . build ( ) ;
344351 const unsignedTxForBroadcasting = unsignedTx . toBroadcastFormat ( ) ;
345352
353+ // Test with complex contract interaction data
354+ const contractCallData =
355+ '0xa9059cbb000000000000000000000000abcdef1234567890abcdef1234567890abcdef120000000000000000000000000000000000000000000000000de0b6b3a7640000' ;
356+ const customRecipients = [
357+ {
358+ address : '0x1234567890123456789012345678901234567890' ,
359+ amount : '0' , // Contract call with 0 value
360+ data : contractCallData ,
361+ } ,
362+ ] ;
363+
346364 const halfSignedRawTx = await avaxCoin . signTransaction ( {
347365 txPrebuild : {
348366 txHex : unsignedTxForBroadcasting ,
367+ recipients : customRecipients ,
349368 } ,
350369 prv : account_1 . owner_2 ,
351370 } ) ;
352371
353- builder . transfer ( ) . key ( account_1 . owner_2 ) ;
354- const halfSignedTx = await builder . build ( ) ;
355- const halfSignedTxForBroadcasting = halfSignedTx . toBroadcastFormat ( ) ;
356-
357- halfSignedRawTx . halfSigned . txHex . should . equals ( halfSignedTxForBroadcasting ) ;
372+ // Should preserve the contract call data in half-signed transaction
358373 halfSignedRawTx . halfSigned . recipients . length . should . equals ( 1 ) ;
359- halfSignedRawTx . halfSigned . recipients [ 0 ] . address . toLowerCase ( ) . should . equals ( account_2 . address . toLowerCase ( ) ) ;
360- halfSignedRawTx . halfSigned . recipients [ 0 ] . amount . toLowerCase ( ) . should . equals ( '1' ) ;
374+ halfSignedRawTx . halfSigned . recipients [ 0 ] . address . should . equals ( customRecipients [ 0 ] . address ) ;
375+ halfSignedRawTx . halfSigned . recipients [ 0 ] . amount . should . equals ( customRecipients [ 0 ] . amount ) ;
376+ halfSignedRawTx . halfSigned . recipients [ 0 ] . data . should . equals ( customRecipients [ 0 ] . data ) ;
361377 } ) ;
362378 } ) ;
363379
0 commit comments