Skip to content

Commit 0385049

Browse files
Merge pull request #7597 from BitGo/fix-vet-precision
fix(sdk-coin-vet): preserve precision for large value transactions
2 parents 91e4a40 + a5cd30b commit 0385049

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

modules/sdk-coin-vet/src/lib/transaction/transaction.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ export class Transaction extends BaseTransaction {
292292
// Set recipients from clauses
293293
this.recipients = body.clauses.map((clause) => ({
294294
address: (clause.to || '0x0').toString().toLowerCase(),
295-
amount: Number(clause.value).toString(),
295+
amount: new BigNumber(clause.value).toFixed(),
296296
}));
297297
this.loadInputsAndOutputs();
298298

modules/sdk-coin-vet/test/transactionBuilder/transferBuilder.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,44 @@ describe('Vet Transfer Transaction', () => {
166166
should.equal(completelySignedTx.toBroadcastFormat(), testData.completeSignedSerializedHex);
167167
should.equal(completelySignedTx.id, '0xb988d614d3c24420cb2183239ab601b53e63ff4c81cea1e4888bc9d0aa6aad13');
168168
});
169+
170+
it('should preserve full precision of large number values', async function () {
171+
// A very large number that would normally be represented in scientific notation '2.332734928448876e+22
172+
const largeAmount = '23327349284488761096413';
173+
174+
const transaction = new Transaction(coins.get('tvet'));
175+
const txBuilder = factory.getTransferBuilder(transaction);
176+
177+
// Use the large amount in recipients
178+
const recipients = [
179+
{
180+
address: testData.addresses.validAddresses[1].toLowerCase(),
181+
amount: largeAmount,
182+
},
183+
];
184+
185+
txBuilder.sender(testData.addresses.validAddresses[0]);
186+
txBuilder.recipients(recipients);
187+
txBuilder.gas(21000);
188+
txBuilder.nonce('64248');
189+
txBuilder.blockRef('0x014ead140e77bbc1');
190+
txBuilder.addFeePayerAddress(testData.feePayer.address);
191+
txBuilder.expiration(64);
192+
txBuilder.gasPriceCoef(128);
193+
194+
const tx = (await txBuilder.build()) as Transaction;
195+
196+
// Verify that the value is preserved exactly as provided
197+
should.equal(tx.outputs[0].value, largeAmount);
198+
199+
// Create a serialized transaction and parse it back
200+
const serializedTx = tx.toBroadcastFormat();
201+
const deserializedTxBuilder = factory.from(serializedTx);
202+
const deserializedTx = await deserializedTxBuilder.build();
203+
204+
// Verify the value is still preserved after serialization/deserialization
205+
should.equal(deserializedTx.outputs[0].value, largeAmount);
206+
});
169207
});
170208

171209
describe('Fail', () => {

0 commit comments

Comments
 (0)