@ledgerhq/coin-vechain 3.0.0 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.unimportedrc.json +2 -1
- package/CHANGELOG.md +42 -2699
- package/lib/api/index.d.ts +2 -2
- package/lib/api/index.d.ts.map +1 -1
- package/lib/api/index.js +25 -22
- package/lib/api/index.js.map +1 -1
- package/lib/bridge/broadcast.d.ts.map +1 -1
- package/lib/bridge/broadcast.js +2 -1
- package/lib/bridge/broadcast.js.map +1 -1
- package/lib/bridge/createTransaction.js +1 -1
- package/lib/bridge/createTransaction.js.map +1 -1
- package/lib/bridge/estimateMaxSpendable.d.ts.map +1 -1
- package/lib/bridge/estimateMaxSpendable.js +2 -1
- package/lib/bridge/estimateMaxSpendable.js.map +1 -1
- package/lib/bridge/getTransactionStatus.d.ts.map +1 -1
- package/lib/bridge/getTransactionStatus.js +2 -1
- package/lib/bridge/getTransactionStatus.js.map +1 -1
- package/lib/bridge/prepareTransaction.d.ts.map +1 -1
- package/lib/bridge/prepareTransaction.js +4 -2
- package/lib/bridge/prepareTransaction.js.map +1 -1
- package/lib/bridge/synchronisation.d.ts.map +1 -1
- package/lib/bridge/synchronisation.js +6 -4
- package/lib/bridge/synchronisation.js.map +1 -1
- package/lib/common-logic/calculateGasFees.d.ts +2 -1
- package/lib/common-logic/calculateGasFees.d.ts.map +1 -1
- package/lib/common-logic/calculateGasFees.js +3 -3
- package/lib/common-logic/calculateGasFees.js.map +1 -1
- package/lib/common-logic/calculateTransactionInfo.d.ts +2 -1
- package/lib/common-logic/calculateTransactionInfo.d.ts.map +1 -1
- package/lib/common-logic/calculateTransactionInfo.js +2 -2
- package/lib/common-logic/calculateTransactionInfo.js.map +1 -1
- package/lib/common-logic/estimateGas.d.ts +2 -1
- package/lib/common-logic/estimateGas.d.ts.map +1 -1
- package/lib/common-logic/estimateGas.js +2 -2
- package/lib/common-logic/estimateGas.js.map +1 -1
- package/lib/common-logic/getThorClient.d.ts +2 -1
- package/lib/common-logic/getThorClient.d.ts.map +1 -1
- package/lib/common-logic/getThorClient.js +2 -2
- package/lib/common-logic/getThorClient.js.map +1 -1
- package/lib/common-logic/mapTransfersToOperations.d.ts +3 -2
- package/lib/common-logic/mapTransfersToOperations.d.ts.map +1 -1
- package/lib/common-logic/mapTransfersToOperations.js +4 -4
- package/lib/common-logic/mapTransfersToOperations.js.map +1 -1
- package/lib/config.d.ts +10 -4
- package/lib/config.d.ts.map +1 -1
- package/lib/config.js +9 -5
- package/lib/config.js.map +1 -1
- package/lib/logic/account/getBalance.d.ts +2 -1
- package/lib/logic/account/getBalance.d.ts.map +1 -1
- package/lib/logic/account/getBalance.js +3 -2
- package/lib/logic/account/getBalance.js.map +1 -1
- package/lib/logic/history/getBlock.d.ts +2 -1
- package/lib/logic/history/getBlock.d.ts.map +1 -1
- package/lib/logic/history/getBlock.js +3 -2
- package/lib/logic/history/getBlock.js.map +1 -1
- package/lib/logic/history/getBlockInfo.d.ts +2 -1
- package/lib/logic/history/getBlockInfo.d.ts.map +1 -1
- package/lib/logic/history/getBlockInfo.js +3 -2
- package/lib/logic/history/getBlockInfo.js.map +1 -1
- package/lib/logic/history/lastBlock.d.ts +2 -1
- package/lib/logic/history/lastBlock.d.ts.map +1 -1
- package/lib/logic/history/lastBlock.js +4 -3
- package/lib/logic/history/lastBlock.js.map +1 -1
- package/lib/logic/history/listOperations.d.ts +2 -1
- package/lib/logic/history/listOperations.d.ts.map +1 -1
- package/lib/logic/history/listOperations.js +5 -4
- package/lib/logic/history/listOperations.js.map +1 -1
- package/lib/logic/transaction/broadcast.d.ts +2 -1
- package/lib/logic/transaction/broadcast.d.ts.map +1 -1
- package/lib/logic/transaction/broadcast.js +3 -2
- package/lib/logic/transaction/broadcast.js.map +1 -1
- package/lib/logic/transaction/combine.d.ts +1 -1
- package/lib/logic/transaction/combine.d.ts.map +1 -1
- package/lib/logic/transaction/combine.js +4 -1
- package/lib/logic/transaction/combine.js.map +1 -1
- package/lib/logic/transaction/craftTransaction.d.ts +2 -1
- package/lib/logic/transaction/craftTransaction.d.ts.map +1 -1
- package/lib/logic/transaction/craftTransaction.js +11 -10
- package/lib/logic/transaction/craftTransaction.js.map +1 -1
- package/lib/logic/transaction/estimateFees.d.ts +2 -1
- package/lib/logic/transaction/estimateFees.d.ts.map +1 -1
- package/lib/logic/transaction/estimateFees.js +2 -2
- package/lib/logic/transaction/estimateFees.js.map +1 -1
- package/lib/network/getBlock.d.ts +2 -1
- package/lib/network/getBlock.d.ts.map +1 -1
- package/lib/network/getBlock.js +2 -2
- package/lib/network/getBlock.js.map +1 -1
- package/lib/network/getFees.d.ts +2 -1
- package/lib/network/getFees.d.ts.map +1 -1
- package/lib/network/getFees.js +2 -2
- package/lib/network/getFees.js.map +1 -1
- package/lib/network/sdk.d.ts +7 -6
- package/lib/network/sdk.d.ts.map +1 -1
- package/lib/network/sdk.js +18 -18
- package/lib/network/sdk.js.map +1 -1
- package/lib/test/context.d.ts +6 -0
- package/lib/test/context.d.ts.map +1 -0
- package/lib/test/context.js +15 -0
- package/lib/test/context.js.map +1 -0
- package/lib-es/api/index.d.ts +2 -2
- package/lib-es/api/index.d.ts.map +1 -1
- package/lib-es/api/index.js +25 -22
- package/lib-es/api/index.js.map +1 -1
- package/lib-es/bridge/broadcast.d.ts.map +1 -1
- package/lib-es/bridge/broadcast.js +2 -1
- package/lib-es/bridge/broadcast.js.map +1 -1
- package/lib-es/bridge/createTransaction.js +2 -2
- package/lib-es/bridge/createTransaction.js.map +1 -1
- package/lib-es/bridge/estimateMaxSpendable.d.ts.map +1 -1
- package/lib-es/bridge/estimateMaxSpendable.js +2 -1
- package/lib-es/bridge/estimateMaxSpendable.js.map +1 -1
- package/lib-es/bridge/getTransactionStatus.d.ts.map +1 -1
- package/lib-es/bridge/getTransactionStatus.js +2 -1
- package/lib-es/bridge/getTransactionStatus.js.map +1 -1
- package/lib-es/bridge/prepareTransaction.d.ts.map +1 -1
- package/lib-es/bridge/prepareTransaction.js +4 -2
- package/lib-es/bridge/prepareTransaction.js.map +1 -1
- package/lib-es/bridge/synchronisation.d.ts.map +1 -1
- package/lib-es/bridge/synchronisation.js +6 -4
- package/lib-es/bridge/synchronisation.js.map +1 -1
- package/lib-es/common-logic/calculateGasFees.d.ts +2 -1
- package/lib-es/common-logic/calculateGasFees.d.ts.map +1 -1
- package/lib-es/common-logic/calculateGasFees.js +3 -3
- package/lib-es/common-logic/calculateGasFees.js.map +1 -1
- package/lib-es/common-logic/calculateTransactionInfo.d.ts +2 -1
- package/lib-es/common-logic/calculateTransactionInfo.d.ts.map +1 -1
- package/lib-es/common-logic/calculateTransactionInfo.js +2 -2
- package/lib-es/common-logic/calculateTransactionInfo.js.map +1 -1
- package/lib-es/common-logic/estimateGas.d.ts +2 -1
- package/lib-es/common-logic/estimateGas.d.ts.map +1 -1
- package/lib-es/common-logic/estimateGas.js +2 -2
- package/lib-es/common-logic/estimateGas.js.map +1 -1
- package/lib-es/common-logic/getThorClient.d.ts +2 -1
- package/lib-es/common-logic/getThorClient.d.ts.map +1 -1
- package/lib-es/common-logic/getThorClient.js +2 -2
- package/lib-es/common-logic/getThorClient.js.map +1 -1
- package/lib-es/common-logic/mapTransfersToOperations.d.ts +3 -2
- package/lib-es/common-logic/mapTransfersToOperations.d.ts.map +1 -1
- package/lib-es/common-logic/mapTransfersToOperations.js +4 -4
- package/lib-es/common-logic/mapTransfersToOperations.js.map +1 -1
- package/lib-es/config.d.ts +10 -4
- package/lib-es/config.d.ts.map +1 -1
- package/lib-es/config.js +9 -5
- package/lib-es/config.js.map +1 -1
- package/lib-es/logic/account/getBalance.d.ts +2 -1
- package/lib-es/logic/account/getBalance.d.ts.map +1 -1
- package/lib-es/logic/account/getBalance.js +3 -2
- package/lib-es/logic/account/getBalance.js.map +1 -1
- package/lib-es/logic/history/getBlock.d.ts +2 -1
- package/lib-es/logic/history/getBlock.d.ts.map +1 -1
- package/lib-es/logic/history/getBlock.js +3 -2
- package/lib-es/logic/history/getBlock.js.map +1 -1
- package/lib-es/logic/history/getBlockInfo.d.ts +2 -1
- package/lib-es/logic/history/getBlockInfo.d.ts.map +1 -1
- package/lib-es/logic/history/getBlockInfo.js +3 -2
- package/lib-es/logic/history/getBlockInfo.js.map +1 -1
- package/lib-es/logic/history/lastBlock.d.ts +2 -1
- package/lib-es/logic/history/lastBlock.d.ts.map +1 -1
- package/lib-es/logic/history/lastBlock.js +4 -3
- package/lib-es/logic/history/lastBlock.js.map +1 -1
- package/lib-es/logic/history/listOperations.d.ts +2 -1
- package/lib-es/logic/history/listOperations.d.ts.map +1 -1
- package/lib-es/logic/history/listOperations.js +5 -4
- package/lib-es/logic/history/listOperations.js.map +1 -1
- package/lib-es/logic/transaction/broadcast.d.ts +2 -1
- package/lib-es/logic/transaction/broadcast.d.ts.map +1 -1
- package/lib-es/logic/transaction/broadcast.js +3 -2
- package/lib-es/logic/transaction/broadcast.js.map +1 -1
- package/lib-es/logic/transaction/combine.d.ts +1 -1
- package/lib-es/logic/transaction/combine.d.ts.map +1 -1
- package/lib-es/logic/transaction/combine.js +4 -1
- package/lib-es/logic/transaction/combine.js.map +1 -1
- package/lib-es/logic/transaction/craftTransaction.d.ts +2 -1
- package/lib-es/logic/transaction/craftTransaction.d.ts.map +1 -1
- package/lib-es/logic/transaction/craftTransaction.js +11 -10
- package/lib-es/logic/transaction/craftTransaction.js.map +1 -1
- package/lib-es/logic/transaction/estimateFees.d.ts +2 -1
- package/lib-es/logic/transaction/estimateFees.d.ts.map +1 -1
- package/lib-es/logic/transaction/estimateFees.js +2 -2
- package/lib-es/logic/transaction/estimateFees.js.map +1 -1
- package/lib-es/network/getBlock.d.ts +2 -1
- package/lib-es/network/getBlock.d.ts.map +1 -1
- package/lib-es/network/getBlock.js +2 -2
- package/lib-es/network/getBlock.js.map +1 -1
- package/lib-es/network/getFees.d.ts +2 -1
- package/lib-es/network/getFees.d.ts.map +1 -1
- package/lib-es/network/getFees.js +2 -2
- package/lib-es/network/getFees.js.map +1 -1
- package/lib-es/network/sdk.d.ts +7 -6
- package/lib-es/network/sdk.d.ts.map +1 -1
- package/lib-es/network/sdk.js +18 -18
- package/lib-es/network/sdk.js.map +1 -1
- package/lib-es/test/context.d.ts +6 -0
- package/lib-es/test/context.d.ts.map +1 -0
- package/lib-es/test/context.js +11 -0
- package/lib-es/test/context.js.map +1 -0
- package/package.json +6 -6
- package/src/api/index.integ.test.ts +21 -24
- package/src/api/index.ts +74 -27
- package/src/api/index.unit.test.ts +68 -48
- package/src/bridge/broadcast.integ.test.ts +2 -1
- package/src/bridge/broadcast.test.ts +1 -1
- package/src/bridge/broadcast.ts +2 -1
- package/src/bridge/createTransaction.ts +2 -2
- package/src/bridge/estimateMaxSpendable.test.ts +19 -3
- package/src/bridge/estimateMaxSpendable.ts +2 -0
- package/src/bridge/getTransactionStatus.test.ts +11 -6
- package/src/bridge/getTransactionStatus.ts +2 -0
- package/src/bridge/prepareTransaction.test.ts +5 -1
- package/src/bridge/prepareTransaction.ts +4 -2
- package/src/bridge/synchronisation.ts +7 -3
- package/src/common-logic/calculateGasFees.test.ts +101 -27
- package/src/common-logic/calculateGasFees.ts +4 -2
- package/src/common-logic/calculateTransactionInfo.test.ts +71 -16
- package/src/common-logic/calculateTransactionInfo.ts +3 -1
- package/src/common-logic/estimateGas.test.ts +13 -10
- package/src/common-logic/estimateGas.ts +3 -1
- package/src/common-logic/getThorClient.test.ts +7 -7
- package/src/common-logic/getThorClient.ts +3 -3
- package/src/common-logic/mapTransfersToOperations.test.ts +48 -13
- package/src/common-logic/mapTransfersToOperations.ts +5 -2
- package/src/config.test.ts +3 -3
- package/src/config.ts +13 -6
- package/src/logic/account/getBalance.ts +4 -2
- package/src/logic/account/getBalance.unit.test.ts +6 -4
- package/src/logic/history/getBlock.ts +4 -2
- package/src/logic/history/getBlock.unit.test.ts +8 -5
- package/src/logic/history/getBlockInfo.ts +4 -2
- package/src/logic/history/getBlockInfo.unit.test.ts +6 -3
- package/src/logic/history/lastBlock.ts +5 -3
- package/src/logic/history/lastBlock.unit.test.ts +6 -3
- package/src/logic/history/listOperations.ts +6 -3
- package/src/logic/history/listOperations.unit.test.ts +10 -6
- package/src/logic/transaction/broadcast.msw.test.ts +7 -2
- package/src/logic/transaction/broadcast.ts +8 -2
- package/src/logic/transaction/broadcast.unit.test.ts +6 -3
- package/src/logic/transaction/combine.ts +6 -2
- package/src/logic/transaction/combine.unit.test.ts +3 -3
- package/src/logic/transaction/craftTransaction.ts +16 -9
- package/src/logic/transaction/craftTransaction.unit.test.ts +29 -28
- package/src/logic/transaction/estimateFees.ts +3 -0
- package/src/logic/transaction/estimateFees.unit.test.ts +15 -12
- package/src/network/getBlock.ts +3 -2
- package/src/network/getBlock.unit.test.ts +11 -6
- package/src/network/getFees.ts +6 -3
- package/src/network/sdk.integ.test.ts +8 -1
- package/src/network/sdk.test.ts +18 -7
- package/src/network/sdk.ts +25 -15
- package/src/test/context.ts +15 -0
|
@@ -5,6 +5,7 @@ import { parseAddress } from "./parseAddress";
|
|
|
5
5
|
import { calculateClausesVet, calculateClausesVtho } from "./calculateClauses";
|
|
6
6
|
import { estimateGas } from "./estimateGas";
|
|
7
7
|
import { getThorClient } from "./getThorClient";
|
|
8
|
+
import { mockVechainConfig } from "../test/context";
|
|
8
9
|
|
|
9
10
|
// Mock all dependencies
|
|
10
11
|
jest.mock("./parseAddress");
|
|
@@ -70,7 +71,12 @@ describe("calculateGasFees", () => {
|
|
|
70
71
|
});
|
|
71
72
|
|
|
72
73
|
it("should calculate gas fees for VET transfer", async () => {
|
|
73
|
-
const result = await calculateGasFees(
|
|
74
|
+
const result = await calculateGasFees(
|
|
75
|
+
mockVechainConfig,
|
|
76
|
+
mockTransaction,
|
|
77
|
+
false,
|
|
78
|
+
mockOriginAddress,
|
|
79
|
+
);
|
|
74
80
|
|
|
75
81
|
expect(mockedParseAddress).toHaveBeenCalledWith(mockTransaction.recipient);
|
|
76
82
|
expect(mockedCalculateClausesVet).toHaveBeenCalledWith(
|
|
@@ -78,7 +84,11 @@ describe("calculateGasFees", () => {
|
|
|
78
84
|
mockTransaction.amount,
|
|
79
85
|
);
|
|
80
86
|
expect(mockedCalculateClausesVtho).not.toHaveBeenCalled();
|
|
81
|
-
expect(mockedEstimateGas).toHaveBeenCalledWith(
|
|
87
|
+
expect(mockedEstimateGas).toHaveBeenCalledWith(
|
|
88
|
+
mockVechainConfig,
|
|
89
|
+
mockClauses,
|
|
90
|
+
mockOriginAddress,
|
|
91
|
+
);
|
|
82
92
|
expect(mockThorClient.transactions.buildTransactionBody).toHaveBeenCalledWith(
|
|
83
93
|
mockClauses,
|
|
84
94
|
mockGasEstimation.totalGas,
|
|
@@ -99,7 +109,12 @@ describe("calculateGasFees", () => {
|
|
|
99
109
|
maxPriorityFeePerGas: null,
|
|
100
110
|
});
|
|
101
111
|
|
|
102
|
-
const result = await calculateGasFees(
|
|
112
|
+
const result = await calculateGasFees(
|
|
113
|
+
mockVechainConfig,
|
|
114
|
+
mockTransaction,
|
|
115
|
+
false,
|
|
116
|
+
mockOriginAddress,
|
|
117
|
+
);
|
|
103
118
|
|
|
104
119
|
expect(result).toEqual({
|
|
105
120
|
estimatedGas: 21000,
|
|
@@ -112,7 +127,12 @@ describe("calculateGasFees", () => {
|
|
|
112
127
|
it("should handle transaction body with undefined gas values", async () => {
|
|
113
128
|
mockThorClient.transactions.buildTransactionBody.mockResolvedValue({});
|
|
114
129
|
|
|
115
|
-
const result = await calculateGasFees(
|
|
130
|
+
const result = await calculateGasFees(
|
|
131
|
+
mockVechainConfig,
|
|
132
|
+
mockTransaction,
|
|
133
|
+
false,
|
|
134
|
+
mockOriginAddress,
|
|
135
|
+
);
|
|
116
136
|
|
|
117
137
|
expect(result).toEqual({
|
|
118
138
|
estimatedGas: 21000,
|
|
@@ -131,7 +151,12 @@ describe("calculateGasFees", () => {
|
|
|
131
151
|
};
|
|
132
152
|
mockedEstimateGas.mockResolvedValue(customGasEstimation);
|
|
133
153
|
|
|
134
|
-
const result = await calculateGasFees(
|
|
154
|
+
const result = await calculateGasFees(
|
|
155
|
+
mockVechainConfig,
|
|
156
|
+
mockTransaction,
|
|
157
|
+
false,
|
|
158
|
+
mockOriginAddress,
|
|
159
|
+
);
|
|
135
160
|
|
|
136
161
|
expect(result).toEqual({
|
|
137
162
|
estimatedGas: 50000,
|
|
@@ -150,7 +175,12 @@ describe("calculateGasFees", () => {
|
|
|
150
175
|
});
|
|
151
176
|
|
|
152
177
|
it("should calculate gas fees for VTHO transfer", async () => {
|
|
153
|
-
const result = await calculateGasFees(
|
|
178
|
+
const result = await calculateGasFees(
|
|
179
|
+
mockVechainConfig,
|
|
180
|
+
mockTransaction,
|
|
181
|
+
true,
|
|
182
|
+
mockOriginAddress,
|
|
183
|
+
);
|
|
154
184
|
|
|
155
185
|
expect(mockedParseAddress).toHaveBeenCalledWith(mockTransaction.recipient);
|
|
156
186
|
expect(mockedCalculateClausesVtho).toHaveBeenCalledWith(
|
|
@@ -158,7 +188,11 @@ describe("calculateGasFees", () => {
|
|
|
158
188
|
mockTransaction.amount,
|
|
159
189
|
);
|
|
160
190
|
expect(mockedCalculateClausesVet).not.toHaveBeenCalled();
|
|
161
|
-
expect(mockedEstimateGas).toHaveBeenCalledWith(
|
|
191
|
+
expect(mockedEstimateGas).toHaveBeenCalledWith(
|
|
192
|
+
mockVechainConfig,
|
|
193
|
+
mockClauses,
|
|
194
|
+
mockOriginAddress,
|
|
195
|
+
);
|
|
162
196
|
expect(mockThorClient.transactions.buildTransactionBody).toHaveBeenCalledWith(
|
|
163
197
|
mockClauses,
|
|
164
198
|
mockGasEstimation.totalGas,
|
|
@@ -179,7 +213,12 @@ describe("calculateGasFees", () => {
|
|
|
179
213
|
amount: new BigNumber("999999999999999999999999"),
|
|
180
214
|
};
|
|
181
215
|
|
|
182
|
-
const result = await calculateGasFees(
|
|
216
|
+
const result = await calculateGasFees(
|
|
217
|
+
mockVechainConfig,
|
|
218
|
+
largeAmountTransaction,
|
|
219
|
+
true,
|
|
220
|
+
mockOriginAddress,
|
|
221
|
+
);
|
|
183
222
|
|
|
184
223
|
expect(mockedCalculateClausesVtho).toHaveBeenCalledWith(
|
|
185
224
|
largeAmountTransaction.recipient,
|
|
@@ -197,7 +236,12 @@ describe("calculateGasFees", () => {
|
|
|
197
236
|
recipient: undefined,
|
|
198
237
|
} as any;
|
|
199
238
|
|
|
200
|
-
const result = await calculateGasFees(
|
|
239
|
+
const result = await calculateGasFees(
|
|
240
|
+
mockVechainConfig,
|
|
241
|
+
transactionWithoutRecipient,
|
|
242
|
+
false,
|
|
243
|
+
mockOriginAddress,
|
|
244
|
+
);
|
|
201
245
|
|
|
202
246
|
expect(mockedParseAddress).not.toHaveBeenCalled();
|
|
203
247
|
expect(mockedCalculateClausesVet).not.toHaveBeenCalled();
|
|
@@ -218,7 +262,12 @@ describe("calculateGasFees", () => {
|
|
|
218
262
|
recipient: null,
|
|
219
263
|
} as any;
|
|
220
264
|
|
|
221
|
-
const result = await calculateGasFees(
|
|
265
|
+
const result = await calculateGasFees(
|
|
266
|
+
mockVechainConfig,
|
|
267
|
+
transactionWithNullRecipient,
|
|
268
|
+
false,
|
|
269
|
+
mockOriginAddress,
|
|
270
|
+
);
|
|
222
271
|
|
|
223
272
|
expect(result).toEqual({
|
|
224
273
|
estimatedGas: 0,
|
|
@@ -231,7 +280,12 @@ describe("calculateGasFees", () => {
|
|
|
231
280
|
it("should return zero values when parseAddress returns null/undefined", async () => {
|
|
232
281
|
mockedParseAddress.mockReturnValue(false);
|
|
233
282
|
|
|
234
|
-
const result = await calculateGasFees(
|
|
283
|
+
const result = await calculateGasFees(
|
|
284
|
+
mockVechainConfig,
|
|
285
|
+
mockTransaction,
|
|
286
|
+
false,
|
|
287
|
+
mockOriginAddress,
|
|
288
|
+
);
|
|
235
289
|
|
|
236
290
|
expect(mockedParseAddress).toHaveBeenCalledWith(mockTransaction.recipient);
|
|
237
291
|
expect(mockedCalculateClausesVet).not.toHaveBeenCalled();
|
|
@@ -249,7 +303,12 @@ describe("calculateGasFees", () => {
|
|
|
249
303
|
it("should return zero values when parseAddress returns empty string", async () => {
|
|
250
304
|
mockedParseAddress.mockReturnValue(false);
|
|
251
305
|
|
|
252
|
-
const result = await calculateGasFees(
|
|
306
|
+
const result = await calculateGasFees(
|
|
307
|
+
mockVechainConfig,
|
|
308
|
+
mockTransaction,
|
|
309
|
+
false,
|
|
310
|
+
mockOriginAddress,
|
|
311
|
+
);
|
|
253
312
|
|
|
254
313
|
expect(result).toEqual({
|
|
255
314
|
estimatedGas: 0,
|
|
@@ -269,18 +328,18 @@ describe("calculateGasFees", () => {
|
|
|
269
328
|
const error = new Error("Failed to calculate VET clauses");
|
|
270
329
|
mockedCalculateClausesVet.mockRejectedValue(error);
|
|
271
330
|
|
|
272
|
-
await expect(
|
|
273
|
-
|
|
274
|
-
);
|
|
331
|
+
await expect(
|
|
332
|
+
calculateGasFees(mockVechainConfig, mockTransaction, false, mockOriginAddress),
|
|
333
|
+
).rejects.toThrow("Failed to calculate VET clauses");
|
|
275
334
|
});
|
|
276
335
|
|
|
277
336
|
it("should throw error when calculateClausesVtho fails", async () => {
|
|
278
337
|
const error = new Error("Failed to calculate VTHO clauses");
|
|
279
338
|
mockedCalculateClausesVtho.mockRejectedValue(error);
|
|
280
339
|
|
|
281
|
-
await expect(
|
|
282
|
-
|
|
283
|
-
);
|
|
340
|
+
await expect(
|
|
341
|
+
calculateGasFees(mockVechainConfig, mockTransaction, true, mockOriginAddress),
|
|
342
|
+
).rejects.toThrow("Failed to calculate VTHO clauses");
|
|
284
343
|
});
|
|
285
344
|
|
|
286
345
|
it("should throw error when estimateGas fails", async () => {
|
|
@@ -288,9 +347,9 @@ describe("calculateGasFees", () => {
|
|
|
288
347
|
const error = new Error("Failed to estimate gas");
|
|
289
348
|
mockedEstimateGas.mockRejectedValue(error);
|
|
290
349
|
|
|
291
|
-
await expect(
|
|
292
|
-
|
|
293
|
-
);
|
|
350
|
+
await expect(
|
|
351
|
+
calculateGasFees(mockVechainConfig, mockTransaction, false, mockOriginAddress),
|
|
352
|
+
).rejects.toThrow("Failed to estimate gas");
|
|
294
353
|
});
|
|
295
354
|
|
|
296
355
|
it("should throw error when buildTransactionBody fails", async () => {
|
|
@@ -299,9 +358,9 @@ describe("calculateGasFees", () => {
|
|
|
299
358
|
const error = new Error("Failed to build transaction body");
|
|
300
359
|
mockThorClient.transactions.buildTransactionBody.mockRejectedValue(error);
|
|
301
360
|
|
|
302
|
-
await expect(
|
|
303
|
-
|
|
304
|
-
);
|
|
361
|
+
await expect(
|
|
362
|
+
calculateGasFees(mockVechainConfig, mockTransaction, false, mockOriginAddress),
|
|
363
|
+
).rejects.toThrow("Failed to build transaction body");
|
|
305
364
|
});
|
|
306
365
|
});
|
|
307
366
|
|
|
@@ -318,7 +377,12 @@ describe("calculateGasFees", () => {
|
|
|
318
377
|
amount: new BigNumber("0"),
|
|
319
378
|
};
|
|
320
379
|
|
|
321
|
-
const result = await calculateGasFees(
|
|
380
|
+
const result = await calculateGasFees(
|
|
381
|
+
mockVechainConfig,
|
|
382
|
+
zeroAmountTransaction,
|
|
383
|
+
false,
|
|
384
|
+
mockOriginAddress,
|
|
385
|
+
);
|
|
322
386
|
|
|
323
387
|
expect(mockedCalculateClausesVet).toHaveBeenCalledWith(
|
|
324
388
|
zeroAmountTransaction.recipient,
|
|
@@ -335,7 +399,12 @@ describe("calculateGasFees", () => {
|
|
|
335
399
|
vmErrors: [],
|
|
336
400
|
});
|
|
337
401
|
|
|
338
|
-
const result = await calculateGasFees(
|
|
402
|
+
const result = await calculateGasFees(
|
|
403
|
+
mockVechainConfig,
|
|
404
|
+
mockTransaction,
|
|
405
|
+
false,
|
|
406
|
+
mockOriginAddress,
|
|
407
|
+
);
|
|
339
408
|
|
|
340
409
|
expect(result).toEqual({
|
|
341
410
|
estimatedGas: 0,
|
|
@@ -352,7 +421,12 @@ describe("calculateGasFees", () => {
|
|
|
352
421
|
};
|
|
353
422
|
mockThorClient.transactions.buildTransactionBody.mockResolvedValue(highGasTransactionBody);
|
|
354
423
|
|
|
355
|
-
const result = await calculateGasFees(
|
|
424
|
+
const result = await calculateGasFees(
|
|
425
|
+
mockVechainConfig,
|
|
426
|
+
mockTransaction,
|
|
427
|
+
false,
|
|
428
|
+
mockOriginAddress,
|
|
429
|
+
);
|
|
356
430
|
|
|
357
431
|
expect(result).toEqual({
|
|
358
432
|
estimatedGas: 21000,
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import BigNumber from "bignumber.js";
|
|
2
2
|
import { Transaction } from "../types";
|
|
3
|
+
import type { VechainCurrencyConfig } from "../config";
|
|
3
4
|
import { parseAddress } from "./parseAddress";
|
|
4
5
|
import { calculateClausesVet, calculateClausesVtho } from "./calculateClauses";
|
|
5
6
|
import { estimateGas } from "./estimateGas";
|
|
6
7
|
import { getThorClient } from "./getThorClient";
|
|
7
8
|
|
|
8
9
|
export const calculateGasFees = async (
|
|
10
|
+
config: VechainCurrencyConfig,
|
|
9
11
|
transaction: Transaction,
|
|
10
12
|
isTokenAccount: boolean,
|
|
11
13
|
originAddress: string,
|
|
@@ -24,8 +26,8 @@ export const calculateGasFees = async (
|
|
|
24
26
|
clauses = await calculateClausesVet(transaction.recipient, transaction.amount);
|
|
25
27
|
}
|
|
26
28
|
|
|
27
|
-
const gasEstimation = await estimateGas(clauses, originAddress);
|
|
28
|
-
const thorClient = getThorClient();
|
|
29
|
+
const gasEstimation = await estimateGas(config, clauses, originAddress);
|
|
30
|
+
const thorClient = getThorClient(config);
|
|
29
31
|
const body = await thorClient.transactions.buildTransactionBody(
|
|
30
32
|
clauses,
|
|
31
33
|
gasEstimation.totalGas,
|
|
@@ -4,6 +4,7 @@ import { calculateTransactionInfo } from "./calculateTransactionInfo";
|
|
|
4
4
|
import { Transaction } from "../types";
|
|
5
5
|
import { ImpossibleToCalculateAmountAndFees } from "../errors";
|
|
6
6
|
import { calculateGasFees } from "./calculateGasFees";
|
|
7
|
+
import { mockVechainConfig } from "../test/context";
|
|
7
8
|
|
|
8
9
|
// Mock dependencies
|
|
9
10
|
jest.mock("./calculateGasFees");
|
|
@@ -71,7 +72,11 @@ describe("calculateTransactionInfo", () => {
|
|
|
71
72
|
|
|
72
73
|
describe("VET transactions", () => {
|
|
73
74
|
it("should calculate transaction info for normal VET transaction", async () => {
|
|
74
|
-
const result = await calculateTransactionInfo(
|
|
75
|
+
const result = await calculateTransactionInfo(
|
|
76
|
+
mockVechainConfig,
|
|
77
|
+
mockAccount,
|
|
78
|
+
mockBaseTransaction,
|
|
79
|
+
);
|
|
75
80
|
|
|
76
81
|
expect(result).toEqual({
|
|
77
82
|
isTokenAccount: false,
|
|
@@ -92,16 +97,21 @@ describe("calculateTransactionInfo", () => {
|
|
|
92
97
|
useAllAmount: true,
|
|
93
98
|
};
|
|
94
99
|
|
|
95
|
-
const result = await calculateTransactionInfo(
|
|
100
|
+
const result = await calculateTransactionInfo(
|
|
101
|
+
mockVechainConfig,
|
|
102
|
+
mockAccount,
|
|
103
|
+
useAllAmountTransaction,
|
|
104
|
+
);
|
|
96
105
|
|
|
97
106
|
expect(result.amount).toEqual(new BigNumber("5000000000000000000"));
|
|
98
107
|
expect(result.spendableBalance).toEqual(new BigNumber("5000000000000000000"));
|
|
99
108
|
});
|
|
100
109
|
|
|
101
110
|
it("should call calculateGasFees with correct parameters for VET", async () => {
|
|
102
|
-
await calculateTransactionInfo(mockAccount, mockBaseTransaction);
|
|
111
|
+
await calculateTransactionInfo(mockVechainConfig, mockAccount, mockBaseTransaction);
|
|
103
112
|
|
|
104
113
|
expect(mockedCalculateGasFees).toHaveBeenCalledWith(
|
|
114
|
+
mockVechainConfig,
|
|
105
115
|
expect.objectContaining({
|
|
106
116
|
amount: new BigNumber("1000000000000000000"),
|
|
107
117
|
}),
|
|
@@ -123,7 +133,11 @@ describe("calculateTransactionInfo", () => {
|
|
|
123
133
|
};
|
|
124
134
|
|
|
125
135
|
it("should calculate transaction info for normal token transaction", async () => {
|
|
126
|
-
const result = await calculateTransactionInfo(
|
|
136
|
+
const result = await calculateTransactionInfo(
|
|
137
|
+
mockVechainConfig,
|
|
138
|
+
mockAccountWithToken,
|
|
139
|
+
mockTokenTransaction,
|
|
140
|
+
);
|
|
127
141
|
|
|
128
142
|
expect(result).toEqual({
|
|
129
143
|
isTokenAccount: true,
|
|
@@ -145,6 +159,7 @@ describe("calculateTransactionInfo", () => {
|
|
|
145
159
|
};
|
|
146
160
|
|
|
147
161
|
const result = await calculateTransactionInfo(
|
|
162
|
+
mockVechainConfig,
|
|
148
163
|
mockAccountWithToken,
|
|
149
164
|
useAllAmountTokenTransaction,
|
|
150
165
|
);
|
|
@@ -160,15 +175,20 @@ describe("calculateTransactionInfo", () => {
|
|
|
160
175
|
};
|
|
161
176
|
mockedCalculateGasFees.mockResolvedValue(highGasResult);
|
|
162
177
|
|
|
163
|
-
const result = await calculateTransactionInfo(
|
|
178
|
+
const result = await calculateTransactionInfo(
|
|
179
|
+
mockVechainConfig,
|
|
180
|
+
mockAccountWithToken,
|
|
181
|
+
mockTokenTransaction,
|
|
182
|
+
);
|
|
164
183
|
|
|
165
184
|
expect(result.spendableBalance).toEqual(new BigNumber("0"));
|
|
166
185
|
});
|
|
167
186
|
|
|
168
187
|
it("should call calculateGasFees with correct parameters for token", async () => {
|
|
169
|
-
await calculateTransactionInfo(mockAccountWithToken, mockTokenTransaction);
|
|
188
|
+
await calculateTransactionInfo(mockVechainConfig, mockAccountWithToken, mockTokenTransaction);
|
|
170
189
|
|
|
171
190
|
expect(mockedCalculateGasFees).toHaveBeenCalledWith(
|
|
191
|
+
mockVechainConfig,
|
|
172
192
|
expect.objectContaining({
|
|
173
193
|
amount: new BigNumber("1000000000000000000"),
|
|
174
194
|
}),
|
|
@@ -184,6 +204,7 @@ describe("calculateTransactionInfo", () => {
|
|
|
184
204
|
};
|
|
185
205
|
|
|
186
206
|
const result = await calculateTransactionInfo(
|
|
207
|
+
mockVechainConfig,
|
|
187
208
|
mockAccountWithToken,
|
|
188
209
|
transactionWithNonExistentToken,
|
|
189
210
|
);
|
|
@@ -202,7 +223,12 @@ describe("calculateTransactionInfo", () => {
|
|
|
202
223
|
};
|
|
203
224
|
|
|
204
225
|
it("should use fixed gas fees when provided", async () => {
|
|
205
|
-
const result = await calculateTransactionInfo(
|
|
226
|
+
const result = await calculateTransactionInfo(
|
|
227
|
+
mockVechainConfig,
|
|
228
|
+
mockAccount,
|
|
229
|
+
mockBaseTransaction,
|
|
230
|
+
fixedGasFees,
|
|
231
|
+
);
|
|
206
232
|
|
|
207
233
|
expect(mockedCalculateGasFees).not.toHaveBeenCalled();
|
|
208
234
|
expect(result.estimatedFees).toBe("500000000000000000");
|
|
@@ -223,6 +249,7 @@ describe("calculateTransactionInfo", () => {
|
|
|
223
249
|
};
|
|
224
250
|
|
|
225
251
|
const result = await calculateTransactionInfo(
|
|
252
|
+
mockVechainConfig,
|
|
226
253
|
mockAccountWithToken,
|
|
227
254
|
mockTokenTransaction,
|
|
228
255
|
fixedGasFees,
|
|
@@ -255,7 +282,11 @@ describe("calculateTransactionInfo", () => {
|
|
|
255
282
|
useAllAmount: true,
|
|
256
283
|
};
|
|
257
284
|
|
|
258
|
-
const result = await calculateTransactionInfo(
|
|
285
|
+
const result = await calculateTransactionInfo(
|
|
286
|
+
mockVechainConfig,
|
|
287
|
+
mockAccount,
|
|
288
|
+
useAllAmountTransaction,
|
|
289
|
+
);
|
|
259
290
|
|
|
260
291
|
expect(result.amount).toEqual(new BigNumber("5000000000000000000"));
|
|
261
292
|
expect(mockedCalculateGasFees).toHaveBeenCalledTimes(2);
|
|
@@ -287,7 +318,7 @@ describe("calculateTransactionInfo", () => {
|
|
|
287
318
|
});
|
|
288
319
|
|
|
289
320
|
await expect(
|
|
290
|
-
calculateTransactionInfo(mockAccountWithToken, mockTokenTransaction),
|
|
321
|
+
calculateTransactionInfo(mockVechainConfig, mockAccountWithToken, mockTokenTransaction),
|
|
291
322
|
).rejects.toThrow(ImpossibleToCalculateAmountAndFees);
|
|
292
323
|
});
|
|
293
324
|
|
|
@@ -306,7 +337,7 @@ describe("calculateTransactionInfo", () => {
|
|
|
306
337
|
useAllAmount: true,
|
|
307
338
|
};
|
|
308
339
|
|
|
309
|
-
await calculateTransactionInfo(mockAccount, useAllAmountTransaction);
|
|
340
|
+
await calculateTransactionInfo(mockVechainConfig, mockAccount, useAllAmountTransaction);
|
|
310
341
|
|
|
311
342
|
// Should be called at least once, might be called twice in the loop
|
|
312
343
|
expect(mockedCalculateGasFees).toHaveBeenCalledTimes(2);
|
|
@@ -320,7 +351,11 @@ describe("calculateTransactionInfo", () => {
|
|
|
320
351
|
amount: new BigNumber(NaN),
|
|
321
352
|
};
|
|
322
353
|
|
|
323
|
-
const result = await calculateTransactionInfo(
|
|
354
|
+
const result = await calculateTransactionInfo(
|
|
355
|
+
mockVechainConfig,
|
|
356
|
+
mockAccount,
|
|
357
|
+
nanAmountTransaction,
|
|
358
|
+
);
|
|
324
359
|
|
|
325
360
|
expect(mockedCalculateGasFees).not.toHaveBeenCalled();
|
|
326
361
|
expect(result.amount.isNaN()).toBe(true);
|
|
@@ -334,7 +369,11 @@ describe("calculateTransactionInfo", () => {
|
|
|
334
369
|
amount: new BigNumber(NaN),
|
|
335
370
|
};
|
|
336
371
|
|
|
337
|
-
const result = await calculateTransactionInfo(
|
|
372
|
+
const result = await calculateTransactionInfo(
|
|
373
|
+
mockVechainConfig,
|
|
374
|
+
mockAccount,
|
|
375
|
+
nanAmountTransaction,
|
|
376
|
+
);
|
|
338
377
|
|
|
339
378
|
expect(result.balance).toEqual(mockAccount.balance);
|
|
340
379
|
expect(result.spendableBalance).toEqual(mockAccount.balance);
|
|
@@ -348,7 +387,11 @@ describe("calculateTransactionInfo", () => {
|
|
|
348
387
|
subAccounts: [],
|
|
349
388
|
};
|
|
350
389
|
|
|
351
|
-
const result = await calculateTransactionInfo(
|
|
390
|
+
const result = await calculateTransactionInfo(
|
|
391
|
+
mockVechainConfig,
|
|
392
|
+
accountWithoutSubAccounts,
|
|
393
|
+
mockBaseTransaction,
|
|
394
|
+
);
|
|
352
395
|
|
|
353
396
|
expect(result.isTokenAccount).toBe(false);
|
|
354
397
|
expect(result.tokenAccount).toBeUndefined();
|
|
@@ -365,7 +408,11 @@ describe("calculateTransactionInfo", () => {
|
|
|
365
408
|
subAccountId: "some-id",
|
|
366
409
|
};
|
|
367
410
|
|
|
368
|
-
const result = await calculateTransactionInfo(
|
|
411
|
+
const result = await calculateTransactionInfo(
|
|
412
|
+
mockVechainConfig,
|
|
413
|
+
accountWithEmptySubAccounts,
|
|
414
|
+
tokenTransaction,
|
|
415
|
+
);
|
|
369
416
|
|
|
370
417
|
expect(result.isTokenAccount).toBe(false);
|
|
371
418
|
expect(result.tokenAccount).toBeUndefined();
|
|
@@ -377,7 +424,11 @@ describe("calculateTransactionInfo", () => {
|
|
|
377
424
|
balance: new BigNumber("0"),
|
|
378
425
|
};
|
|
379
426
|
|
|
380
|
-
const result = await calculateTransactionInfo(
|
|
427
|
+
const result = await calculateTransactionInfo(
|
|
428
|
+
mockVechainConfig,
|
|
429
|
+
zeroBalanceAccount,
|
|
430
|
+
mockBaseTransaction,
|
|
431
|
+
);
|
|
381
432
|
|
|
382
433
|
expect(result.balance).toEqual(new BigNumber("0"));
|
|
383
434
|
expect(result.spendableBalance).toEqual(new BigNumber("0"));
|
|
@@ -389,7 +440,11 @@ describe("calculateTransactionInfo", () => {
|
|
|
389
440
|
amount: new BigNumber("0"),
|
|
390
441
|
};
|
|
391
442
|
|
|
392
|
-
const result = await calculateTransactionInfo(
|
|
443
|
+
const result = await calculateTransactionInfo(
|
|
444
|
+
mockVechainConfig,
|
|
445
|
+
mockAccount,
|
|
446
|
+
zeroAmountTransaction,
|
|
447
|
+
);
|
|
393
448
|
|
|
394
449
|
expect(result.amount).toEqual(new BigNumber("0"));
|
|
395
450
|
expect(mockedCalculateGasFees).toHaveBeenCalled();
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import BigNumber from "bignumber.js";
|
|
2
2
|
import { Account, TokenAccount } from "@ledgerhq/types-live";
|
|
3
3
|
import { Transaction, TransactionInfo } from "../types";
|
|
4
|
+
import type { VechainCurrencyConfig } from "../config";
|
|
4
5
|
import { ImpossibleToCalculateAmountAndFees } from "../errors";
|
|
5
6
|
import { calculateGasFees } from "./calculateGasFees";
|
|
6
7
|
|
|
@@ -25,6 +26,7 @@ const getTokenAccount = (
|
|
|
25
26
|
// amount -> spendableBalance -> fees -> amount
|
|
26
27
|
|
|
27
28
|
export const calculateTransactionInfo = async (
|
|
29
|
+
config: VechainCurrencyConfig,
|
|
28
30
|
account: Account,
|
|
29
31
|
transaction: Transaction,
|
|
30
32
|
fixedMaxTokenFees?: {
|
|
@@ -58,7 +60,7 @@ export const calculateTransactionInfo = async (
|
|
|
58
60
|
|
|
59
61
|
const estimatedGasAndFees =
|
|
60
62
|
fixedMaxTokenFees ||
|
|
61
|
-
(await calculateGasFees(tempTransaction, isTokenAccount, account.freshAddress));
|
|
63
|
+
(await calculateGasFees(config, tempTransaction, isTokenAccount, account.freshAddress));
|
|
62
64
|
|
|
63
65
|
maxEstimatedGasFees = estimatedGasAndFees.estimatedGasFees;
|
|
64
66
|
maxEstimatedGas = estimatedGasAndFees.estimatedGas;
|
|
@@ -2,6 +2,7 @@ import { estimateGas } from "./estimateGas";
|
|
|
2
2
|
import { getThorClient } from "./getThorClient";
|
|
3
3
|
import { TransactionClause } from "@vechain/sdk-core";
|
|
4
4
|
import { EstimateGasResult } from "@vechain/sdk-network";
|
|
5
|
+
import { mockVechainConfig } from "../test/context";
|
|
5
6
|
|
|
6
7
|
// Mock dependencies
|
|
7
8
|
jest.mock("./getThorClient");
|
|
@@ -45,7 +46,7 @@ describe("estimateGas", () => {
|
|
|
45
46
|
it("should estimate gas for transaction clauses", async () => {
|
|
46
47
|
mockThorClient.gas.estimateGas.mockResolvedValue(mockEstimateGasResult);
|
|
47
48
|
|
|
48
|
-
const result = await estimateGas(mockClauses, mockOrigin);
|
|
49
|
+
const result = await estimateGas(mockVechainConfig, mockClauses, mockOrigin);
|
|
49
50
|
|
|
50
51
|
expect(mockedGetThorClient).toHaveBeenCalledTimes(1);
|
|
51
52
|
expect(mockThorClient.gas.estimateGas).toHaveBeenCalledWith(mockClauses, mockOrigin);
|
|
@@ -56,7 +57,7 @@ describe("estimateGas", () => {
|
|
|
56
57
|
const singleClause: TransactionClause[] = [mockClauses[0]];
|
|
57
58
|
mockThorClient.gas.estimateGas.mockResolvedValue(mockEstimateGasResult);
|
|
58
59
|
|
|
59
|
-
const result = await estimateGas(singleClause, mockOrigin);
|
|
60
|
+
const result = await estimateGas(mockVechainConfig, singleClause, mockOrigin);
|
|
60
61
|
|
|
61
62
|
expect(mockThorClient.gas.estimateGas).toHaveBeenCalledWith(singleClause, mockOrigin);
|
|
62
63
|
expect(result).toEqual(mockEstimateGasResult);
|
|
@@ -71,7 +72,7 @@ describe("estimateGas", () => {
|
|
|
71
72
|
vmErrors: [],
|
|
72
73
|
});
|
|
73
74
|
|
|
74
|
-
const result = await estimateGas(emptyClauses, mockOrigin);
|
|
75
|
+
const result = await estimateGas(mockVechainConfig, emptyClauses, mockOrigin);
|
|
75
76
|
|
|
76
77
|
expect(mockThorClient.gas.estimateGas).toHaveBeenCalledWith(emptyClauses, mockOrigin);
|
|
77
78
|
expect(result.totalGas).toBe(0);
|
|
@@ -86,7 +87,7 @@ describe("estimateGas", () => {
|
|
|
86
87
|
};
|
|
87
88
|
mockThorClient.gas.estimateGas.mockResolvedValue(revertedResult);
|
|
88
89
|
|
|
89
|
-
const result = await estimateGas(mockClauses, mockOrigin);
|
|
90
|
+
const result = await estimateGas(mockVechainConfig, mockClauses, mockOrigin);
|
|
90
91
|
|
|
91
92
|
expect(result).toEqual(revertedResult);
|
|
92
93
|
expect(result.reverted).toBe(true);
|
|
@@ -102,7 +103,7 @@ describe("estimateGas", () => {
|
|
|
102
103
|
};
|
|
103
104
|
mockThorClient.gas.estimateGas.mockResolvedValue(highGasResult);
|
|
104
105
|
|
|
105
|
-
const result = await estimateGas(mockClauses, mockOrigin);
|
|
106
|
+
const result = await estimateGas(mockVechainConfig, mockClauses, mockOrigin);
|
|
106
107
|
|
|
107
108
|
expect(result.totalGas).toBe(500000);
|
|
108
109
|
});
|
|
@@ -111,7 +112,9 @@ describe("estimateGas", () => {
|
|
|
111
112
|
const errorMessage = "Network error";
|
|
112
113
|
mockThorClient.gas.estimateGas.mockRejectedValue(new Error(errorMessage));
|
|
113
114
|
|
|
114
|
-
await expect(estimateGas(mockClauses, mockOrigin)).rejects.toThrow(
|
|
115
|
+
await expect(estimateGas(mockVechainConfig, mockClauses, mockOrigin)).rejects.toThrow(
|
|
116
|
+
errorMessage,
|
|
117
|
+
);
|
|
115
118
|
});
|
|
116
119
|
|
|
117
120
|
it("should handle clauses with data for token transfers", async () => {
|
|
@@ -131,7 +134,7 @@ describe("estimateGas", () => {
|
|
|
131
134
|
};
|
|
132
135
|
mockThorClient.gas.estimateGas.mockResolvedValue(tokenGasResult);
|
|
133
136
|
|
|
134
|
-
const result = await estimateGas(tokenTransferClause, mockOrigin);
|
|
137
|
+
const result = await estimateGas(mockVechainConfig, tokenTransferClause, mockOrigin);
|
|
135
138
|
|
|
136
139
|
expect(mockThorClient.gas.estimateGas).toHaveBeenCalledWith(tokenTransferClause, mockOrigin);
|
|
137
140
|
expect(result.totalGas).toBe(37000);
|
|
@@ -140,8 +143,8 @@ describe("estimateGas", () => {
|
|
|
140
143
|
it("should get a new thor client instance for each call", async () => {
|
|
141
144
|
mockThorClient.gas.estimateGas.mockResolvedValue(mockEstimateGasResult);
|
|
142
145
|
|
|
143
|
-
await estimateGas(mockClauses, mockOrigin);
|
|
144
|
-
await estimateGas(mockClauses, mockOrigin);
|
|
146
|
+
await estimateGas(mockVechainConfig, mockClauses, mockOrigin);
|
|
147
|
+
await estimateGas(mockVechainConfig, mockClauses, mockOrigin);
|
|
145
148
|
|
|
146
149
|
expect(mockedGetThorClient).toHaveBeenCalledTimes(2);
|
|
147
150
|
});
|
|
@@ -155,7 +158,7 @@ describe("estimateGas", () => {
|
|
|
155
158
|
};
|
|
156
159
|
mockThorClient.gas.estimateGas.mockResolvedValue(exactResult);
|
|
157
160
|
|
|
158
|
-
const result = await estimateGas(mockClauses, mockOrigin);
|
|
161
|
+
const result = await estimateGas(mockVechainConfig, mockClauses, mockOrigin);
|
|
159
162
|
|
|
160
163
|
expect(result).toBe(exactResult);
|
|
161
164
|
});
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { TransactionClause } from "@vechain/sdk-core";
|
|
2
2
|
import { getThorClient } from "./getThorClient";
|
|
3
3
|
import { EstimateGasResult } from "@vechain/sdk-network";
|
|
4
|
+
import type { VechainCurrencyConfig } from "../config";
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* Estimates gas fees for transaction clauses
|
|
@@ -9,10 +10,11 @@ import { EstimateGasResult } from "@vechain/sdk-network";
|
|
|
9
10
|
* @return {Promise<EstimateGasResult>} Estimated gas result
|
|
10
11
|
*/
|
|
11
12
|
export const estimateGas = async (
|
|
13
|
+
config: VechainCurrencyConfig,
|
|
12
14
|
clauses: TransactionClause[],
|
|
13
15
|
origin: string,
|
|
14
16
|
): Promise<EstimateGasResult> => {
|
|
15
|
-
const thorClient = getThorClient();
|
|
17
|
+
const thorClient = getThorClient(config);
|
|
16
18
|
const gasResult = await thorClient.gas.estimateGas(clauses, origin);
|
|
17
19
|
return gasResult;
|
|
18
20
|
};
|