Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion modules/sdk-coin-trx/src/lib/iface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ export interface UnfreezeBalanceContractParameter {
*/
export interface FreezeContractDecoded {
ownerAddress?: string;
resource?: number;
resource?: string;
frozenBalance?: string | number;
}

Expand Down
2 changes: 1 addition & 1 deletion modules/sdk-coin-trx/src/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ export function decodeFreezeBalanceV2Contract(base64: string): FreezeBalanceCont
getByteArrayFromHexAddress(Buffer.from(freezeContract.ownerAddress, 'base64').toString('hex'))
);

const resourceValue = freezeContract.resource === 0 ? TronResource.BANDWIDTH : TronResource.ENERGY;
const resourceValue = freezeContract.resource === 'BANDWIDTH' ? TronResource.BANDWIDTH : TronResource.ENERGY;

return [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ import {
BLOCK_NUMBER,
EXPIRATION,
RESOURCE_ENERGY,
RESOURCE_BANDWIDTH,
FROZEN_BALANCE,
FREEZE_BALANCE_V2_CONTRACT,
} from '../../resources';
import { getBuilder } from '../../../src/lib/builder';
import { Transaction, WrappedBuilder } from '../../../src';
import { decodeTransaction } from '../../../src/lib/utils';

describe('Tron FreezeBalanceV2 builder', function () {
const initTxBuilder = () => {
Expand Down Expand Up @@ -320,4 +322,44 @@ describe('Tron FreezeBalanceV2 builder', function () {
});
});
});

describe('decode freeze txns correctly', () => {
it('should decode a freeze transaction with resource as ENERGY', async () => {
const rawHex =
'0a0263562208aeb6dfb8e968626440bc91f6c39c335a5a083612560a34747970652e676f6f676c65617069732e636f6d2f70726f746f636f6c2e467265657a6542616c616e63655632436f6e7472616374121e0a154160b9ab837fd7153c1baa5e55a16d05d60e21d0d31080e1eb17180170fcd8f3c39c33';
const decodedTransaction = decodeTransaction(rawHex);

// Verify transaction has contracts
assert.ok(decodedTransaction.contract?.length > 0, 'Transaction should have at least one contract');

const contract = decodedTransaction.contract[0];
assert.ok(contract, 'contract should exist');

if (!('parameter' in contract) || !contract.parameter?.value || !('resource' in contract.parameter.value)) {
throw new Error('Invalid contract format: missing parameter or resource');
}

// Verify resource type
assert.equal(contract.parameter.value.resource, RESOURCE_ENERGY, 'Resource type should be ENERGY');
});

it('should decode a freeze transaction with resource as BANDWIDTH', async () => {
const rawHex =
'0a028d372208f403372490b5b8e240bbaab7f69b335a5b083612570a34747970652e676f6f676c65617069732e636f6d2f70726f746f636f6c2e467265657a6542616c616e63655632436f6e7472616374121f0a154160b9ab837fd7153c1baa5e55a16d05d60e21d0d31080cab5ee01180070bbcddbf49b33';
const decodedTransaction = decodeTransaction(rawHex);

// Verify transaction has contracts
assert.ok(decodedTransaction.contract?.length > 0, 'Transaction should have at least one contract');

const contract = decodedTransaction.contract[0];
assert.ok(contract, 'contract should exist');

if (!('parameter' in contract) || !contract.parameter?.value || !('resource' in contract.parameter.value)) {
throw new Error('Invalid contract format: missing parameter or resource');
}

// Verify resource type
assert.equal(contract.parameter.value.resource, RESOURCE_BANDWIDTH, 'Resource type should be BANDWIDTH');
});
});
});