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/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import { AbiCoder, hexConcat } from 'ethers/lib/utils';
import { DELEGATION_TYPE_URL } from './constants';

export const TRANSACTION_MAX_EXPIRATION = 86400000; // one day
export const TRANSACTION_DEFAULT_EXPIRATION = 3600000; // one hour
export const TRANSACTION_DEFAULT_EXPIRATION = 10800000; // three hours
const ADDRESS_PREFIX_REGEX = /^(41)/;
const ADDRESS_PREFIX = '41';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import assert from 'node:assert';
import { describe, it } from 'node:test';
import { getBuilder } from '../../../src/lib/builder';
import { WrappedBuilder } from '../../../src';
import { TRANSACTION_DEFAULT_EXPIRATION } from '../../../src/lib/utils';
import {
PARTICIPANTS,
BLOCK_HASH,
Expand Down Expand Up @@ -36,6 +37,23 @@ describe('TRX Token Transfer Builder', () => {
assert.deepStrictEqual(rawData.contract, TOKEN_TX_CONTRACT);
});

it('a token transfer transaction should have a default expiration of 3 hours', async () => {
const before = Date.now();
const txBuilder = initTxBuilder();
txBuilder.tokenTransferData(TOKEN_TRANSFER_RECIPIENT, '1000000000').sign({ key: PARTICIPANTS.custodian.pk });
const tx = await txBuilder.build();
const after = Date.now();
const txJson = tx.toJson();
const expiration = txJson.raw_data.expiration;

assert.equal(TRANSACTION_DEFAULT_EXPIRATION, 10800000, 'TRANSACTION_DEFAULT_EXPIRATION should be 3 hours');
// The default expiration should be ~3 hours (10800000ms) from when the tx was built
assert.ok(
expiration >= before + TRANSACTION_DEFAULT_EXPIRATION && expiration <= after + TRANSACTION_DEFAULT_EXPIRATION,
`Expiration ${expiration} should be approximately 3 hours from now`
);
});

it('from a signed token contract call transaction', async () => {
const txHex =
'{"raw_data":{"contractType":2,"contract":[{"parameter":{"value":{"data":"a9059cbb0000000000000000000000008483618ca85c35a9b923d98bebca718f5a1db2790000000000000000000000000000000000000000000000000000000005f5e100","owner_address":"41c51fbeea78910b15b1d3e8a9b62914ca94d1a4ac","contract_address":"4142a1e39aefa49290f2b3f9ed688d7cecf86cd6e0"},"type_url":"type.googleapis.com/protocol.TriggerSmartContract"},"type":"TriggerSmartContract"}],"expiration":1674581767432,"timestamp":1674578167432,"ref_block_bytes":"578b","ref_block_hash":"6113bb9ac351432b","fee_limit":15000000},"raw_data_hex":"0a02578b22086113bb9ac351432b4088eae7a6de305aae01081f12a9010a31747970652e676f6f676c65617069732e636f6d2f70726f746f636f6c2e54726967676572536d617274436f6e747261637412740a1541c51fbeea78910b15b1d3e8a9b62914ca94d1a4ac12154142a1e39aefa49290f2b3f9ed688d7cecf86cd6e02244a9059cbb0000000000000000000000008483618ca85c35a9b923d98bebca718f5a1db2790000000000000000000000000000000000000000000000000000000005f5e10070888d8ca5de309001c0c39307","txID":"fe21c49f4febd9089125e3a006943c145721d8fcb7ab84136f8c6663ff92f8ed","signature":["0775cde302689eb8293883c66a89b31e80d608bfc3ad3c283b64a490ea4cc712c55a2fd2e62c75843dd7e77d8c4cb52e0f371fbb29b332c259f8cb63c2e6195301"]}';
Expand Down