@@ -7,11 +7,13 @@ import {
77 BLOCK_NUMBER ,
88 EXPIRATION ,
99 RESOURCE_ENERGY ,
10+ RESOURCE_BANDWIDTH ,
1011 FROZEN_BALANCE ,
1112 FREEZE_BALANCE_V2_CONTRACT ,
1213} from '../../resources' ;
1314import { getBuilder } from '../../../src/lib/builder' ;
1415import { Transaction , WrappedBuilder } from '../../../src' ;
16+ import { decodeTransaction } from '../../../src/lib/utils' ;
1517
1618describe ( 'Tron FreezeBalanceV2 builder' , function ( ) {
1719 const initTxBuilder = ( ) => {
@@ -320,4 +322,44 @@ describe('Tron FreezeBalanceV2 builder', function () {
320322 } ) ;
321323 } ) ;
322324 } ) ;
325+
326+ describe ( 'decode freeze txns correctly' , ( ) => {
327+ it ( 'should decode a freeze transaction with resource as ENERGY' , async ( ) => {
328+ const rawHex =
329+ '0a0263562208aeb6dfb8e968626440bc91f6c39c335a5a083612560a34747970652e676f6f676c65617069732e636f6d2f70726f746f636f6c2e467265657a6542616c616e63655632436f6e7472616374121e0a154160b9ab837fd7153c1baa5e55a16d05d60e21d0d31080e1eb17180170fcd8f3c39c33' ;
330+ const decodedTransaction = decodeTransaction ( rawHex ) ;
331+
332+ // Verify transaction has contracts
333+ assert . ok ( decodedTransaction . contract ?. length > 0 , 'Transaction should have at least one contract' ) ;
334+
335+ const contract = decodedTransaction . contract [ 0 ] ;
336+ assert . ok ( contract , 'contract should exist' ) ;
337+
338+ if ( ! ( 'parameter' in contract ) || ! contract . parameter ?. value || ! ( 'resource' in contract . parameter . value ) ) {
339+ throw new Error ( 'Invalid contract format: missing parameter or resource' ) ;
340+ }
341+
342+ // Verify resource type
343+ assert . equal ( contract . parameter . value . resource , RESOURCE_ENERGY , 'Resource type should be ENERGY' ) ;
344+ } ) ;
345+
346+ it ( 'should decode a freeze transaction with resource as BANDWIDTH' , async ( ) => {
347+ const rawHex =
348+ '0a028d372208f403372490b5b8e240bbaab7f69b335a5b083612570a34747970652e676f6f676c65617069732e636f6d2f70726f746f636f6c2e467265657a6542616c616e63655632436f6e7472616374121f0a154160b9ab837fd7153c1baa5e55a16d05d60e21d0d31080cab5ee01180070bbcddbf49b33' ;
349+ const decodedTransaction = decodeTransaction ( rawHex ) ;
350+
351+ // Verify transaction has contracts
352+ assert . ok ( decodedTransaction . contract ?. length > 0 , 'Transaction should have at least one contract' ) ;
353+
354+ const contract = decodedTransaction . contract [ 0 ] ;
355+ assert . ok ( contract , 'contract should exist' ) ;
356+
357+ if ( ! ( 'parameter' in contract ) || ! contract . parameter ?. value || ! ( 'resource' in contract . parameter . value ) ) {
358+ throw new Error ( 'Invalid contract format: missing parameter or resource' ) ;
359+ }
360+
361+ // Verify resource type
362+ assert . equal ( contract . parameter . value . resource , RESOURCE_BANDWIDTH , 'Resource type should be BANDWIDTH' ) ;
363+ } ) ;
364+ } ) ;
323365} ) ;
0 commit comments