Skip to content

Commit 4635da9

Browse files
authored
Merge pull request #7772 from BitGo/WIN-8354
fix(sdk-coin-flr): set default transaction fee for export in P txn
2 parents c839ddf + 046c92a commit 4635da9

File tree

4 files changed

+90
-8
lines changed

4 files changed

+90
-8
lines changed

modules/sdk-coin-flrp/src/lib/ImportInCTxBuilder.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,6 @@ export class ImportInCTxBuilder extends AtomicInCTransactionBuilder {
126126
protected buildFlareTransaction(): void {
127127
// if tx has credentials or was already recovered from raw, tx shouldn't change
128128
if (this.transaction.hasCredentials) return;
129-
// If fee is already calculated (from initBuilder), the transaction is already built
130-
if (this.transaction._fee.fee) return;
131129
if (this.transaction._to.length !== 1) {
132130
throw new Error('to is required');
133131
}

modules/sdk-coin-flrp/src/lib/atomicTransactionBuilder.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export abstract class AtomicTransactionBuilder extends TransactionBuilder {
2020
constructor(_coinConfig: Readonly<CoinConfig>) {
2121
super(_coinConfig);
2222
this.transaction = new Transaction(_coinConfig);
23+
this.transaction._fee.fee = this.fixedFee;
2324
}
2425

2526
/**

modules/sdk-coin-flrp/test/unit/lib/exportInPTxBuilder.ts

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,54 @@ import {
55
EXPORT_IN_P_TWO_UTXOS as twoUtxoTestData,
66
EXPORT_IN_P_NO_CHANGE as noChangeTestData,
77
} from '../../resources/transactionData/exportInP';
8-
import { TransactionBuilderFactory, DecodedUtxoObj } from '../../../src/lib';
9-
import { coins } from '@bitgo/statics';
8+
import { TransactionBuilderFactory, DecodedUtxoObj, Transaction } from '../../../src/lib';
9+
import { coins, FlareNetwork } from '@bitgo/statics';
1010
import signFlowTest from './signFlowTestSuit';
1111

1212
describe('Flrp Export In P Tx Builder', () => {
13-
const factory = new TransactionBuilderFactory(coins.get('tflrp'));
13+
const coinConfig = coins.get('tflrp');
14+
const factory = new TransactionBuilderFactory(coinConfig);
15+
16+
describe('default fee', () => {
17+
const FIXED_FEE = (coinConfig.network as FlareNetwork).txFee;
18+
19+
it('should set fixedFee (1000000) by default in constructor', () => {
20+
const txBuilder = factory.getExportInPBuilder();
21+
// The fixedFee should be set from network.txFee = '1000000'
22+
const transaction = (txBuilder as any).transaction;
23+
transaction._fee.fee.should.equal(FIXED_FEE);
24+
});
25+
26+
it('should use default fixedFee when fee is not explicitly set', async () => {
27+
// Create a UTXO with enough balance to cover amount + default fee
28+
const amount = '500000000'; // 0.5 FLR
29+
const utxoAmount = (BigInt(amount) + BigInt(FIXED_FEE)).toString(); // amount + fixedFee
30+
31+
const txBuilder = factory
32+
.getExportInPBuilder()
33+
.threshold(testData.threshold)
34+
.locktime(testData.locktime)
35+
.fromPubKey(testData.pAddresses)
36+
.amount(amount)
37+
.externalChainId(testData.sourceChainId)
38+
// NOTE: .fee() is NOT called - should use default fixedFee
39+
.utxos([
40+
{
41+
outputID: 0,
42+
amount: utxoAmount,
43+
txid: '21hcD64N9QzdayPjhKLsBQBa8FyXcsJGNStBZ3vCRdCCEsLru2',
44+
outputidx: '0',
45+
addresses: testData.outputs[0].addresses,
46+
threshold: testData.threshold,
47+
},
48+
]);
49+
50+
const tx = (await txBuilder.build()) as Transaction;
51+
52+
// Verify the fee in the built transaction equals the fixedFee
53+
tx.fee.fee.should.equal(FIXED_FEE);
54+
});
55+
});
1456

1557
describe('validate txBuilder fields', () => {
1658
const txBuilder = factory.getExportInPBuilder();

modules/sdk-coin-flrp/test/unit/lib/importInPTxBuilder.ts

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,53 @@
11
import assert from 'assert';
22
import 'should';
33
import { IMPORT_IN_P as testData } from '../../resources/transactionData/importInP';
4-
import { TransactionBuilderFactory, DecodedUtxoObj } from '../../../src/lib';
5-
import { coins } from '@bitgo/statics';
4+
import { TransactionBuilderFactory, DecodedUtxoObj, Transaction } from '../../../src/lib';
5+
import { coins, FlareNetwork } from '@bitgo/statics';
66
import signFlowTest from './signFlowTestSuit';
77

88
describe('Flrp Import In P Tx Builder', () => {
9-
const factory = new TransactionBuilderFactory(coins.get('tflrp'));
9+
const coinConfig = coins.get('tflrp');
10+
const factory = new TransactionBuilderFactory(coinConfig);
11+
12+
describe('default fee', () => {
13+
const FIXED_FEE = (coinConfig.network as FlareNetwork).txFee;
14+
15+
it('should set fixedFee (1000000) by default in constructor', () => {
16+
const txBuilder = factory.getImportInPBuilder();
17+
// The fixedFee should be set from network.txFee = '1000000'
18+
const transaction = (txBuilder as any).transaction;
19+
transaction._fee.fee.should.equal(FIXED_FEE);
20+
});
21+
22+
it('should use default fixedFee when fee is not explicitly set', async () => {
23+
// Create a UTXO with enough balance to cover the default fee
24+
const utxoAmount = '50000000'; // 0.05 FLR - enough to cover fee and have output
25+
26+
const txBuilder = factory
27+
.getImportInPBuilder()
28+
.threshold(testData.threshold)
29+
.locktime(testData.locktime)
30+
.fromPubKey(testData.pAddresses)
31+
.externalChainId(testData.sourceChainId)
32+
// NOTE: .fee() is NOT called - should use default fixedFee
33+
.utxos([
34+
{
35+
outputID: 0,
36+
amount: utxoAmount,
37+
txid: testData.outputs[0].txid,
38+
outputidx: '0',
39+
addresses: testData.outputs[0].addresses,
40+
threshold: testData.threshold,
41+
},
42+
]);
43+
44+
const tx = (await txBuilder.build()) as Transaction;
45+
46+
// Verify the fee in the built transaction equals the fixedFee
47+
tx.fee.fee.should.equal(FIXED_FEE);
48+
});
49+
});
50+
1051
describe('validate txBuilder fields', () => {
1152
const txBuilder = factory.getImportInPBuilder();
1253

0 commit comments

Comments
 (0)