Skip to content

Commit 6e6783f

Browse files
Merge pull request #8230 from BitGo/COIN-7612
feat(sdk-coin-trx): increase default transaction expiration to 3 hours
2 parents 16d0951 + c5b09bb commit 6e6783f

2 files changed

Lines changed: 19 additions & 1 deletion

File tree

modules/sdk-coin-trx/src/lib/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import { AbiCoder, hexConcat } from 'ethers/lib/utils';
2828
import { DELEGATION_TYPE_URL } from './constants';
2929

3030
export const TRANSACTION_MAX_EXPIRATION = 86400000; // one day
31-
export const TRANSACTION_DEFAULT_EXPIRATION = 3600000; // one hour
31+
export const TRANSACTION_DEFAULT_EXPIRATION = 10800000; // three hours
3232
const ADDRESS_PREFIX_REGEX = /^(41)/;
3333
const ADDRESS_PREFIX = '41';
3434

modules/sdk-coin-trx/test/unit/transactionBuilder/tokenTransferBuilder.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import assert from 'node:assert';
22
import { describe, it } from 'node:test';
33
import { getBuilder } from '../../../src/lib/builder';
44
import { WrappedBuilder } from '../../../src';
5+
import { TRANSACTION_DEFAULT_EXPIRATION } from '../../../src/lib/utils';
56
import {
67
PARTICIPANTS,
78
BLOCK_HASH,
@@ -36,6 +37,23 @@ describe('TRX Token Transfer Builder', () => {
3637
assert.deepStrictEqual(rawData.contract, TOKEN_TX_CONTRACT);
3738
});
3839

40+
it('a token transfer transaction should have a default expiration of 3 hours', async () => {
41+
const before = Date.now();
42+
const txBuilder = initTxBuilder();
43+
txBuilder.tokenTransferData(TOKEN_TRANSFER_RECIPIENT, '1000000000').sign({ key: PARTICIPANTS.custodian.pk });
44+
const tx = await txBuilder.build();
45+
const after = Date.now();
46+
const txJson = tx.toJson();
47+
const expiration = txJson.raw_data.expiration;
48+
49+
assert.equal(TRANSACTION_DEFAULT_EXPIRATION, 10800000, 'TRANSACTION_DEFAULT_EXPIRATION should be 3 hours');
50+
// The default expiration should be ~3 hours (10800000ms) from when the tx was built
51+
assert.ok(
52+
expiration >= before + TRANSACTION_DEFAULT_EXPIRATION && expiration <= after + TRANSACTION_DEFAULT_EXPIRATION,
53+
`Expiration ${expiration} should be approximately 3 hours from now`
54+
);
55+
});
56+
3957
it('from a signed token contract call transaction', async () => {
4058
const txHex =
4159
'{"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"]}';

0 commit comments

Comments
 (0)