@ledgerhq/coin-vechain 2.11.0 → 2.11.1-nightly.1
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/.turbo/turbo-build.log +1 -1
- package/CHANGELOG.md +15 -0
- package/package.json +6 -6
- package/lib/bridge/broadcast.test.d.ts +0 -2
- package/lib/bridge/broadcast.test.d.ts.map +0 -1
- package/lib/bridge/broadcast.test.js +0 -188
- package/lib/bridge/broadcast.test.js.map +0 -1
- package/lib/bridge/buildOptimisticOperatioin.test.d.ts +0 -2
- package/lib/bridge/buildOptimisticOperatioin.test.d.ts.map +0 -1
- package/lib/bridge/buildOptimisticOperatioin.test.js +0 -286
- package/lib/bridge/buildOptimisticOperatioin.test.js.map +0 -1
- package/lib/bridge/createTransaction.test.d.ts +0 -2
- package/lib/bridge/createTransaction.test.d.ts.map +0 -1
- package/lib/bridge/createTransaction.test.js +0 -167
- package/lib/bridge/createTransaction.test.js.map +0 -1
- package/lib/bridge/estimateMaxSpendable.test.d.ts +0 -2
- package/lib/bridge/estimateMaxSpendable.test.d.ts.map +0 -1
- package/lib/bridge/estimateMaxSpendable.test.js +0 -269
- package/lib/bridge/estimateMaxSpendable.test.js.map +0 -1
- package/lib/bridge/getTransactionStatus.test.d.ts +0 -2
- package/lib/bridge/getTransactionStatus.test.d.ts.map +0 -1
- package/lib/bridge/getTransactionStatus.test.js +0 -282
- package/lib/bridge/getTransactionStatus.test.js.map +0 -1
- package/lib/bridge/helpers.test.d.ts +0 -2
- package/lib/bridge/helpers.test.d.ts.map +0 -1
- package/lib/bridge/helpers.test.js +0 -298
- package/lib/bridge/helpers.test.js.map +0 -1
- package/lib/bridge/prepareTransaction.test.d.ts +0 -2
- package/lib/bridge/prepareTransaction.test.d.ts.map +0 -1
- package/lib/bridge/prepareTransaction.test.js +0 -277
- package/lib/bridge/prepareTransaction.test.js.map +0 -1
- package/lib/bridge/signOperation.test.d.ts +0 -2
- package/lib/bridge/signOperation.test.d.ts.map +0 -1
- package/lib/bridge/signOperation.test.js +0 -295
- package/lib/bridge/signOperation.test.js.map +0 -1
- package/lib/bridge/synchronisation.test.d.ts +0 -2
- package/lib/bridge/synchronisation.test.d.ts.map +0 -1
- package/lib/bridge/synchronisation.test.js +0 -201
- package/lib/bridge/synchronisation.test.js.map +0 -1
- package/lib/bridge/transaction.test.d.ts +0 -2
- package/lib/bridge/transaction.test.d.ts.map +0 -1
- package/lib/bridge/transaction.test.js +0 -353
- package/lib/bridge/transaction.test.js.map +0 -1
- package/lib/common-logic/calculateClauses.test.d.ts +0 -2
- package/lib/common-logic/calculateClauses.test.d.ts.map +0 -1
- package/lib/common-logic/calculateClauses.test.js +0 -156
- package/lib/common-logic/calculateClauses.test.js.map +0 -1
- package/lib/common-logic/calculateGasFees.test.d.ts +0 -2
- package/lib/common-logic/calculateGasFees.test.d.ts.map +0 -1
- package/lib/common-logic/calculateGasFees.test.js +0 -279
- package/lib/common-logic/calculateGasFees.test.js.map +0 -1
- package/lib/common-logic/calculateTransactionInfo.test.d.ts +0 -2
- package/lib/common-logic/calculateTransactionInfo.test.d.ts.map +0 -1
- package/lib/common-logic/calculateTransactionInfo.test.js +0 -314
- package/lib/common-logic/calculateTransactionInfo.test.js.map +0 -1
- package/lib/common-logic/estimateGas.test.d.ts +0 -2
- package/lib/common-logic/estimateGas.test.d.ts.map +0 -1
- package/lib/common-logic/estimateGas.test.js +0 -129
- package/lib/common-logic/estimateGas.test.js.map +0 -1
- package/lib/common-logic/fixPrefixCase.test.d.ts +0 -2
- package/lib/common-logic/fixPrefixCase.test.d.ts.map +0 -1
- package/lib/common-logic/fixPrefixCase.test.js +0 -46
- package/lib/common-logic/fixPrefixCase.test.js.map +0 -1
- package/lib/common-logic/generateNonce.test.d.ts +0 -2
- package/lib/common-logic/generateNonce.test.d.ts.map +0 -1
- package/lib/common-logic/generateNonce.test.js +0 -59
- package/lib/common-logic/generateNonce.test.js.map +0 -1
- package/lib/common-logic/getThorClient.test.d.ts +0 -2
- package/lib/common-logic/getThorClient.test.d.ts.map +0 -1
- package/lib/common-logic/getThorClient.test.js +0 -53
- package/lib/common-logic/getThorClient.test.js.map +0 -1
- package/lib/common-logic/mapTransfersToOperations.test.d.ts +0 -2
- package/lib/common-logic/mapTransfersToOperations.test.d.ts.map +0 -1
- package/lib/common-logic/mapTransfersToOperations.test.js +0 -274
- package/lib/common-logic/mapTransfersToOperations.test.js.map +0 -1
- package/lib/common-logic/padAddress.test.d.ts +0 -2
- package/lib/common-logic/padAddress.test.d.ts.map +0 -1
- package/lib/common-logic/padAddress.test.js +0 -59
- package/lib/common-logic/padAddress.test.js.map +0 -1
- package/lib/common-logic/parseAddress.test.d.ts +0 -2
- package/lib/common-logic/parseAddress.test.d.ts.map +0 -1
- package/lib/common-logic/parseAddress.test.js +0 -97
- package/lib/common-logic/parseAddress.test.js.map +0 -1
- package/lib/signer/getAddress.test.d.ts +0 -2
- package/lib/signer/getAddress.test.d.ts.map +0 -1
- package/lib/signer/getAddress.test.js +0 -357
- package/lib/signer/getAddress.test.js.map +0 -1
- package/lib/signer/signMessage.test.d.ts +0 -2
- package/lib/signer/signMessage.test.d.ts.map +0 -1
- package/lib/signer/signMessage.test.js +0 -242
- package/lib/signer/signMessage.test.js.map +0 -1
- package/lib-es/bridge/broadcast.test.d.ts +0 -2
- package/lib-es/bridge/broadcast.test.d.ts.map +0 -1
- package/lib-es/bridge/broadcast.test.js +0 -183
- package/lib-es/bridge/broadcast.test.js.map +0 -1
- package/lib-es/bridge/buildOptimisticOperatioin.test.d.ts +0 -2
- package/lib-es/bridge/buildOptimisticOperatioin.test.d.ts.map +0 -1
- package/lib-es/bridge/buildOptimisticOperatioin.test.js +0 -281
- package/lib-es/bridge/buildOptimisticOperatioin.test.js.map +0 -1
- package/lib-es/bridge/createTransaction.test.d.ts +0 -2
- package/lib-es/bridge/createTransaction.test.d.ts.map +0 -1
- package/lib-es/bridge/createTransaction.test.js +0 -162
- package/lib-es/bridge/createTransaction.test.js.map +0 -1
- package/lib-es/bridge/estimateMaxSpendable.test.d.ts +0 -2
- package/lib-es/bridge/estimateMaxSpendable.test.d.ts.map +0 -1
- package/lib-es/bridge/estimateMaxSpendable.test.js +0 -264
- package/lib-es/bridge/estimateMaxSpendable.test.js.map +0 -1
- package/lib-es/bridge/getTransactionStatus.test.d.ts +0 -2
- package/lib-es/bridge/getTransactionStatus.test.d.ts.map +0 -1
- package/lib-es/bridge/getTransactionStatus.test.js +0 -277
- package/lib-es/bridge/getTransactionStatus.test.js.map +0 -1
- package/lib-es/bridge/helpers.test.d.ts +0 -2
- package/lib-es/bridge/helpers.test.d.ts.map +0 -1
- package/lib-es/bridge/helpers.test.js +0 -293
- package/lib-es/bridge/helpers.test.js.map +0 -1
- package/lib-es/bridge/prepareTransaction.test.d.ts +0 -2
- package/lib-es/bridge/prepareTransaction.test.d.ts.map +0 -1
- package/lib-es/bridge/prepareTransaction.test.js +0 -272
- package/lib-es/bridge/prepareTransaction.test.js.map +0 -1
- package/lib-es/bridge/signOperation.test.d.ts +0 -2
- package/lib-es/bridge/signOperation.test.d.ts.map +0 -1
- package/lib-es/bridge/signOperation.test.js +0 -290
- package/lib-es/bridge/signOperation.test.js.map +0 -1
- package/lib-es/bridge/synchronisation.test.d.ts +0 -2
- package/lib-es/bridge/synchronisation.test.d.ts.map +0 -1
- package/lib-es/bridge/synchronisation.test.js +0 -196
- package/lib-es/bridge/synchronisation.test.js.map +0 -1
- package/lib-es/bridge/transaction.test.d.ts +0 -2
- package/lib-es/bridge/transaction.test.d.ts.map +0 -1
- package/lib-es/bridge/transaction.test.js +0 -347
- package/lib-es/bridge/transaction.test.js.map +0 -1
- package/lib-es/common-logic/calculateClauses.test.d.ts +0 -2
- package/lib-es/common-logic/calculateClauses.test.d.ts.map +0 -1
- package/lib-es/common-logic/calculateClauses.test.js +0 -151
- package/lib-es/common-logic/calculateClauses.test.js.map +0 -1
- package/lib-es/common-logic/calculateGasFees.test.d.ts +0 -2
- package/lib-es/common-logic/calculateGasFees.test.d.ts.map +0 -1
- package/lib-es/common-logic/calculateGasFees.test.js +0 -274
- package/lib-es/common-logic/calculateGasFees.test.js.map +0 -1
- package/lib-es/common-logic/calculateTransactionInfo.test.d.ts +0 -2
- package/lib-es/common-logic/calculateTransactionInfo.test.d.ts.map +0 -1
- package/lib-es/common-logic/calculateTransactionInfo.test.js +0 -309
- package/lib-es/common-logic/calculateTransactionInfo.test.js.map +0 -1
- package/lib-es/common-logic/estimateGas.test.d.ts +0 -2
- package/lib-es/common-logic/estimateGas.test.d.ts.map +0 -1
- package/lib-es/common-logic/estimateGas.test.js +0 -127
- package/lib-es/common-logic/estimateGas.test.js.map +0 -1
- package/lib-es/common-logic/fixPrefixCase.test.d.ts +0 -2
- package/lib-es/common-logic/fixPrefixCase.test.d.ts.map +0 -1
- package/lib-es/common-logic/fixPrefixCase.test.js +0 -44
- package/lib-es/common-logic/fixPrefixCase.test.js.map +0 -1
- package/lib-es/common-logic/generateNonce.test.d.ts +0 -2
- package/lib-es/common-logic/generateNonce.test.d.ts.map +0 -1
- package/lib-es/common-logic/generateNonce.test.js +0 -57
- package/lib-es/common-logic/generateNonce.test.js.map +0 -1
- package/lib-es/common-logic/getThorClient.test.d.ts +0 -2
- package/lib-es/common-logic/getThorClient.test.d.ts.map +0 -1
- package/lib-es/common-logic/getThorClient.test.js +0 -51
- package/lib-es/common-logic/getThorClient.test.js.map +0 -1
- package/lib-es/common-logic/mapTransfersToOperations.test.d.ts +0 -2
- package/lib-es/common-logic/mapTransfersToOperations.test.d.ts.map +0 -1
- package/lib-es/common-logic/mapTransfersToOperations.test.js +0 -269
- package/lib-es/common-logic/mapTransfersToOperations.test.js.map +0 -1
- package/lib-es/common-logic/padAddress.test.d.ts +0 -2
- package/lib-es/common-logic/padAddress.test.d.ts.map +0 -1
- package/lib-es/common-logic/padAddress.test.js +0 -57
- package/lib-es/common-logic/padAddress.test.js.map +0 -1
- package/lib-es/common-logic/parseAddress.test.d.ts +0 -2
- package/lib-es/common-logic/parseAddress.test.d.ts.map +0 -1
- package/lib-es/common-logic/parseAddress.test.js +0 -95
- package/lib-es/common-logic/parseAddress.test.js.map +0 -1
- package/lib-es/signer/getAddress.test.d.ts +0 -2
- package/lib-es/signer/getAddress.test.d.ts.map +0 -1
- package/lib-es/signer/getAddress.test.js +0 -352
- package/lib-es/signer/getAddress.test.js.map +0 -1
- package/lib-es/signer/signMessage.test.d.ts +0 -2
- package/lib-es/signer/signMessage.test.d.ts.map +0 -1
- package/lib-es/signer/signMessage.test.js +0 -240
- package/lib-es/signer/signMessage.test.js.map +0 -1
|
@@ -1,309 +0,0 @@
|
|
|
1
|
-
import BigNumber from "bignumber.js";
|
|
2
|
-
import { calculateTransactionInfo } from "./calculateTransactionInfo";
|
|
3
|
-
import { ImpossibleToCalculateAmountAndFees } from "../errors";
|
|
4
|
-
import { calculateGasFees } from "./calculateGasFees";
|
|
5
|
-
// Mock dependencies
|
|
6
|
-
jest.mock("./calculateGasFees");
|
|
7
|
-
const mockedCalculateGasFees = jest.mocked(calculateGasFees);
|
|
8
|
-
describe("calculateTransactionInfo", () => {
|
|
9
|
-
const mockAccount = {
|
|
10
|
-
type: "Account",
|
|
11
|
-
id: "vechain:1:0x123:",
|
|
12
|
-
seedIdentifier: "seed123",
|
|
13
|
-
derivationMode: "",
|
|
14
|
-
index: 0,
|
|
15
|
-
freshAddress: "0x742d35Cc6634C0532925a3b8D0B251d8c1743eC4",
|
|
16
|
-
freshAddressPath: "44'/818'/0'/0/0",
|
|
17
|
-
used: true,
|
|
18
|
-
balance: new BigNumber("5000000000000000000"), // 5 VET
|
|
19
|
-
spendableBalance: new BigNumber("5000000000000000000"),
|
|
20
|
-
creationDate: new Date("2022-01-01"),
|
|
21
|
-
blockHeight: 12345,
|
|
22
|
-
currency: {},
|
|
23
|
-
operationsCount: 10,
|
|
24
|
-
operations: [],
|
|
25
|
-
pendingOperations: [],
|
|
26
|
-
lastSyncDate: new Date("2022-01-01"),
|
|
27
|
-
balanceHistoryCache: { HOUR: {}, DAY: {}, WEEK: {} },
|
|
28
|
-
swapHistory: [],
|
|
29
|
-
subAccounts: [],
|
|
30
|
-
};
|
|
31
|
-
const mockTokenAccount = {
|
|
32
|
-
type: "TokenAccount",
|
|
33
|
-
id: "vechain:1:0x123:+0x0000000000000000000000000000456e65726779",
|
|
34
|
-
parentId: "vechain:1:0x123:",
|
|
35
|
-
token: {},
|
|
36
|
-
balance: new BigNumber("1000000000000000000000"), // 1000 VTHO
|
|
37
|
-
spendableBalance: new BigNumber("1000000000000000000000"),
|
|
38
|
-
creationDate: new Date("2022-01-01"),
|
|
39
|
-
operationsCount: 5,
|
|
40
|
-
operations: [],
|
|
41
|
-
pendingOperations: [],
|
|
42
|
-
balanceHistoryCache: { HOUR: {}, DAY: {}, WEEK: {} },
|
|
43
|
-
swapHistory: [],
|
|
44
|
-
};
|
|
45
|
-
const mockBaseTransaction = {
|
|
46
|
-
family: "vechain",
|
|
47
|
-
recipient: "0x456789012345678901234567890123456789abcd",
|
|
48
|
-
amount: new BigNumber("1000000000000000000"), // 1 VET/VTHO
|
|
49
|
-
estimatedFees: "0",
|
|
50
|
-
body: {},
|
|
51
|
-
};
|
|
52
|
-
const mockGasFeesResult = {
|
|
53
|
-
estimatedGas: 21000,
|
|
54
|
-
estimatedGasFees: new BigNumber("210000000000000000"), // 0.21 VET
|
|
55
|
-
maxFeePerGas: 10000000000000,
|
|
56
|
-
maxPriorityFeePerGas: 1000000000000,
|
|
57
|
-
};
|
|
58
|
-
beforeEach(() => {
|
|
59
|
-
jest.clearAllMocks();
|
|
60
|
-
mockedCalculateGasFees.mockResolvedValue(mockGasFeesResult);
|
|
61
|
-
});
|
|
62
|
-
describe("VET transactions", () => {
|
|
63
|
-
it("should calculate transaction info for normal VET transaction", async () => {
|
|
64
|
-
const result = await calculateTransactionInfo(mockAccount, mockBaseTransaction);
|
|
65
|
-
expect(result).toEqual({
|
|
66
|
-
isTokenAccount: false,
|
|
67
|
-
amount: new BigNumber("1000000000000000000"),
|
|
68
|
-
spendableBalance: new BigNumber("5000000000000000000"),
|
|
69
|
-
balance: new BigNumber("5000000000000000000"),
|
|
70
|
-
tokenAccount: undefined,
|
|
71
|
-
estimatedFees: "210000000000000000",
|
|
72
|
-
estimatedGas: 21000,
|
|
73
|
-
maxFeePerGas: 10000000000000,
|
|
74
|
-
maxPriorityFeePerGas: 1000000000000,
|
|
75
|
-
});
|
|
76
|
-
});
|
|
77
|
-
it("should handle useAllAmount for VET transaction", async () => {
|
|
78
|
-
const useAllAmountTransaction = {
|
|
79
|
-
...mockBaseTransaction,
|
|
80
|
-
useAllAmount: true,
|
|
81
|
-
};
|
|
82
|
-
const result = await calculateTransactionInfo(mockAccount, useAllAmountTransaction);
|
|
83
|
-
expect(result.amount).toEqual(new BigNumber("5000000000000000000"));
|
|
84
|
-
expect(result.spendableBalance).toEqual(new BigNumber("5000000000000000000"));
|
|
85
|
-
});
|
|
86
|
-
it("should call calculateGasFees with correct parameters for VET", async () => {
|
|
87
|
-
await calculateTransactionInfo(mockAccount, mockBaseTransaction);
|
|
88
|
-
expect(mockedCalculateGasFees).toHaveBeenCalledWith(expect.objectContaining({
|
|
89
|
-
amount: new BigNumber("1000000000000000000"),
|
|
90
|
-
}), false);
|
|
91
|
-
});
|
|
92
|
-
});
|
|
93
|
-
describe("Token transactions", () => {
|
|
94
|
-
const mockAccountWithToken = {
|
|
95
|
-
...mockAccount,
|
|
96
|
-
subAccounts: [mockTokenAccount],
|
|
97
|
-
};
|
|
98
|
-
const mockTokenTransaction = {
|
|
99
|
-
...mockBaseTransaction,
|
|
100
|
-
subAccountId: "vechain:1:0x123:+0x0000000000000000000000000000456e65726779",
|
|
101
|
-
};
|
|
102
|
-
it("should calculate transaction info for normal token transaction", async () => {
|
|
103
|
-
const result = await calculateTransactionInfo(mockAccountWithToken, mockTokenTransaction);
|
|
104
|
-
expect(result).toEqual({
|
|
105
|
-
isTokenAccount: true,
|
|
106
|
-
amount: new BigNumber("1000000000000000000"),
|
|
107
|
-
spendableBalance: new BigNumber("999790000000000000000"), // token balance - gas fees
|
|
108
|
-
balance: new BigNumber("1000000000000000000000"),
|
|
109
|
-
tokenAccount: mockTokenAccount,
|
|
110
|
-
estimatedFees: "210000000000000000",
|
|
111
|
-
estimatedGas: 21000,
|
|
112
|
-
maxFeePerGas: 10000000000000,
|
|
113
|
-
maxPriorityFeePerGas: 1000000000000,
|
|
114
|
-
});
|
|
115
|
-
});
|
|
116
|
-
it("should handle useAllAmount for token transaction", async () => {
|
|
117
|
-
const useAllAmountTokenTransaction = {
|
|
118
|
-
...mockTokenTransaction,
|
|
119
|
-
useAllAmount: true,
|
|
120
|
-
};
|
|
121
|
-
const result = await calculateTransactionInfo(mockAccountWithToken, useAllAmountTokenTransaction);
|
|
122
|
-
expect(result.amount).toEqual(new BigNumber("999790000000000000000"));
|
|
123
|
-
expect(result.spendableBalance).toEqual(new BigNumber("999790000000000000000"));
|
|
124
|
-
});
|
|
125
|
-
it("should handle token transaction when gas fees exceed balance", async () => {
|
|
126
|
-
const highGasResult = {
|
|
127
|
-
...mockGasFeesResult,
|
|
128
|
-
estimatedGasFees: new BigNumber("2000000000000000000000"), // 2000 VET (more than token balance)
|
|
129
|
-
};
|
|
130
|
-
mockedCalculateGasFees.mockResolvedValue(highGasResult);
|
|
131
|
-
const result = await calculateTransactionInfo(mockAccountWithToken, mockTokenTransaction);
|
|
132
|
-
expect(result.spendableBalance).toEqual(new BigNumber("0"));
|
|
133
|
-
});
|
|
134
|
-
it("should call calculateGasFees with correct parameters for token", async () => {
|
|
135
|
-
await calculateTransactionInfo(mockAccountWithToken, mockTokenTransaction);
|
|
136
|
-
expect(mockedCalculateGasFees).toHaveBeenCalledWith(expect.objectContaining({
|
|
137
|
-
amount: new BigNumber("1000000000000000000"),
|
|
138
|
-
}), true);
|
|
139
|
-
});
|
|
140
|
-
it("should handle missing token account", async () => {
|
|
141
|
-
const transactionWithNonExistentToken = {
|
|
142
|
-
...mockTokenTransaction,
|
|
143
|
-
subAccountId: "vechain:1:0x123:+nonexistent",
|
|
144
|
-
};
|
|
145
|
-
const result = await calculateTransactionInfo(mockAccountWithToken, transactionWithNonExistentToken);
|
|
146
|
-
expect(result.isTokenAccount).toBe(false);
|
|
147
|
-
expect(result.tokenAccount).toBeUndefined();
|
|
148
|
-
});
|
|
149
|
-
});
|
|
150
|
-
describe("Fixed gas fees", () => {
|
|
151
|
-
const fixedGasFees = {
|
|
152
|
-
estimatedGas: 50000,
|
|
153
|
-
estimatedGasFees: new BigNumber("500000000000000000"),
|
|
154
|
-
maxFeePerGas: 20000000000000,
|
|
155
|
-
maxPriorityFeePerGas: 2000000000000,
|
|
156
|
-
};
|
|
157
|
-
it("should use fixed gas fees when provided", async () => {
|
|
158
|
-
const result = await calculateTransactionInfo(mockAccount, mockBaseTransaction, fixedGasFees);
|
|
159
|
-
expect(mockedCalculateGasFees).not.toHaveBeenCalled();
|
|
160
|
-
expect(result.estimatedFees).toBe("500000000000000000");
|
|
161
|
-
expect(result.estimatedGas).toBe(50000);
|
|
162
|
-
expect(result.maxFeePerGas).toBe(20000000000000);
|
|
163
|
-
expect(result.maxPriorityFeePerGas).toBe(2000000000000);
|
|
164
|
-
});
|
|
165
|
-
it("should use fixed gas fees for token transactions", async () => {
|
|
166
|
-
const mockAccountWithToken = {
|
|
167
|
-
...mockAccount,
|
|
168
|
-
subAccounts: [mockTokenAccount],
|
|
169
|
-
};
|
|
170
|
-
const mockTokenTransaction = {
|
|
171
|
-
...mockBaseTransaction,
|
|
172
|
-
subAccountId: "vechain:1:0x123:+0x0000000000000000000000000000456e65726779",
|
|
173
|
-
};
|
|
174
|
-
const result = await calculateTransactionInfo(mockAccountWithToken, mockTokenTransaction, fixedGasFees);
|
|
175
|
-
expect(mockedCalculateGasFees).not.toHaveBeenCalled();
|
|
176
|
-
expect(result.estimatedFees).toBe("500000000000000000");
|
|
177
|
-
});
|
|
178
|
-
});
|
|
179
|
-
describe("Circular dependency resolution", () => {
|
|
180
|
-
it("should handle iterative calculation when useAllAmount changes values", async () => {
|
|
181
|
-
// Mock calculateGasFees to return different values based on amount
|
|
182
|
-
mockedCalculateGasFees
|
|
183
|
-
.mockResolvedValueOnce({
|
|
184
|
-
estimatedGas: 21000,
|
|
185
|
-
estimatedGasFees: new BigNumber("210000000000000000"),
|
|
186
|
-
maxFeePerGas: 10000000000000,
|
|
187
|
-
maxPriorityFeePerGas: 1000000000000,
|
|
188
|
-
})
|
|
189
|
-
.mockResolvedValueOnce({
|
|
190
|
-
estimatedGas: 21000,
|
|
191
|
-
estimatedGasFees: new BigNumber("210000000000000000"),
|
|
192
|
-
maxFeePerGas: 10000000000000,
|
|
193
|
-
maxPriorityFeePerGas: 1000000000000,
|
|
194
|
-
});
|
|
195
|
-
const useAllAmountTransaction = {
|
|
196
|
-
...mockBaseTransaction,
|
|
197
|
-
useAllAmount: true,
|
|
198
|
-
};
|
|
199
|
-
const result = await calculateTransactionInfo(mockAccount, useAllAmountTransaction);
|
|
200
|
-
expect(result.amount).toEqual(new BigNumber("5000000000000000000"));
|
|
201
|
-
expect(mockedCalculateGasFees).toHaveBeenCalledTimes(2);
|
|
202
|
-
});
|
|
203
|
-
it("should throw error when max iterations reached", async () => {
|
|
204
|
-
// Create a token account scenario where gas fees can affect spendableBalance
|
|
205
|
-
const mockAccountWithToken = {
|
|
206
|
-
...mockAccount,
|
|
207
|
-
subAccounts: [mockTokenAccount],
|
|
208
|
-
};
|
|
209
|
-
const mockTokenTransaction = {
|
|
210
|
-
...mockBaseTransaction,
|
|
211
|
-
subAccountId: "vechain:1:0x123:+0x0000000000000000000000000000456e65726779",
|
|
212
|
-
useAllAmount: true,
|
|
213
|
-
};
|
|
214
|
-
// Mock calculateGasFees to always return incrementally higher fees
|
|
215
|
-
let callCount = 0;
|
|
216
|
-
mockedCalculateGasFees.mockImplementation(() => {
|
|
217
|
-
callCount++;
|
|
218
|
-
return Promise.resolve({
|
|
219
|
-
estimatedGas: 21000,
|
|
220
|
-
estimatedGasFees: new BigNumber(`${100000000000000000 + callCount * 100000000000000000}`), // Incremental fees
|
|
221
|
-
maxFeePerGas: 10000000000000,
|
|
222
|
-
maxPriorityFeePerGas: 1000000000000,
|
|
223
|
-
});
|
|
224
|
-
});
|
|
225
|
-
await expect(calculateTransactionInfo(mockAccountWithToken, mockTokenTransaction)).rejects.toThrow(ImpossibleToCalculateAmountAndFees);
|
|
226
|
-
});
|
|
227
|
-
it("should stop iterating when amount stabilizes", async () => {
|
|
228
|
-
const constantGasResult = {
|
|
229
|
-
estimatedGas: 21000,
|
|
230
|
-
estimatedGasFees: new BigNumber("210000000000000000"),
|
|
231
|
-
maxFeePerGas: 10000000000000,
|
|
232
|
-
maxPriorityFeePerGas: 1000000000000,
|
|
233
|
-
};
|
|
234
|
-
mockedCalculateGasFees.mockResolvedValue(constantGasResult);
|
|
235
|
-
const useAllAmountTransaction = {
|
|
236
|
-
...mockBaseTransaction,
|
|
237
|
-
useAllAmount: true,
|
|
238
|
-
};
|
|
239
|
-
await calculateTransactionInfo(mockAccount, useAllAmountTransaction);
|
|
240
|
-
// Should be called at least once, might be called twice in the loop
|
|
241
|
-
expect(mockedCalculateGasFees).toHaveBeenCalledTimes(2);
|
|
242
|
-
});
|
|
243
|
-
});
|
|
244
|
-
describe("NaN amount handling", () => {
|
|
245
|
-
it("should handle NaN amount without calling calculateGasFees", async () => {
|
|
246
|
-
const nanAmountTransaction = {
|
|
247
|
-
...mockBaseTransaction,
|
|
248
|
-
amount: new BigNumber(NaN),
|
|
249
|
-
};
|
|
250
|
-
const result = await calculateTransactionInfo(mockAccount, nanAmountTransaction);
|
|
251
|
-
expect(mockedCalculateGasFees).not.toHaveBeenCalled();
|
|
252
|
-
expect(result.amount.isNaN()).toBe(true);
|
|
253
|
-
expect(result.estimatedFees).toBe("0");
|
|
254
|
-
expect(result.estimatedGas).toBe(0);
|
|
255
|
-
});
|
|
256
|
-
it("should use account balance and spendableBalance for NaN amount", async () => {
|
|
257
|
-
const nanAmountTransaction = {
|
|
258
|
-
...mockBaseTransaction,
|
|
259
|
-
amount: new BigNumber(NaN),
|
|
260
|
-
};
|
|
261
|
-
const result = await calculateTransactionInfo(mockAccount, nanAmountTransaction);
|
|
262
|
-
expect(result.balance).toEqual(mockAccount.balance);
|
|
263
|
-
expect(result.spendableBalance).toEqual(mockAccount.balance);
|
|
264
|
-
});
|
|
265
|
-
});
|
|
266
|
-
describe("Edge cases", () => {
|
|
267
|
-
it("should handle account without subAccounts", async () => {
|
|
268
|
-
const accountWithoutSubAccounts = {
|
|
269
|
-
...mockAccount,
|
|
270
|
-
subAccounts: [],
|
|
271
|
-
};
|
|
272
|
-
const result = await calculateTransactionInfo(accountWithoutSubAccounts, mockBaseTransaction);
|
|
273
|
-
expect(result.isTokenAccount).toBe(false);
|
|
274
|
-
expect(result.tokenAccount).toBeUndefined();
|
|
275
|
-
});
|
|
276
|
-
it("should handle empty subAccounts array", async () => {
|
|
277
|
-
const accountWithEmptySubAccounts = {
|
|
278
|
-
...mockAccount,
|
|
279
|
-
subAccounts: [],
|
|
280
|
-
};
|
|
281
|
-
const tokenTransaction = {
|
|
282
|
-
...mockBaseTransaction,
|
|
283
|
-
subAccountId: "some-id",
|
|
284
|
-
};
|
|
285
|
-
const result = await calculateTransactionInfo(accountWithEmptySubAccounts, tokenTransaction);
|
|
286
|
-
expect(result.isTokenAccount).toBe(false);
|
|
287
|
-
expect(result.tokenAccount).toBeUndefined();
|
|
288
|
-
});
|
|
289
|
-
it("should handle zero balance account", async () => {
|
|
290
|
-
const zeroBalanceAccount = {
|
|
291
|
-
...mockAccount,
|
|
292
|
-
balance: new BigNumber("0"),
|
|
293
|
-
};
|
|
294
|
-
const result = await calculateTransactionInfo(zeroBalanceAccount, mockBaseTransaction);
|
|
295
|
-
expect(result.balance).toEqual(new BigNumber("0"));
|
|
296
|
-
expect(result.spendableBalance).toEqual(new BigNumber("0"));
|
|
297
|
-
});
|
|
298
|
-
it("should handle zero amount transaction", async () => {
|
|
299
|
-
const zeroAmountTransaction = {
|
|
300
|
-
...mockBaseTransaction,
|
|
301
|
-
amount: new BigNumber("0"),
|
|
302
|
-
};
|
|
303
|
-
const result = await calculateTransactionInfo(mockAccount, zeroAmountTransaction);
|
|
304
|
-
expect(result.amount).toEqual(new BigNumber("0"));
|
|
305
|
-
expect(mockedCalculateGasFees).toHaveBeenCalled();
|
|
306
|
-
});
|
|
307
|
-
});
|
|
308
|
-
});
|
|
309
|
-
//# sourceMappingURL=calculateTransactionInfo.test.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"calculateTransactionInfo.test.js","sourceRoot":"","sources":["../../src/common-logic/calculateTransactionInfo.test.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,cAAc,CAAC;AAErC,OAAO,EAAE,wBAAwB,EAAE,MAAM,4BAA4B,CAAC;AAEtE,OAAO,EAAE,kCAAkC,EAAE,MAAM,WAAW,CAAC;AAC/D,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAEtD,oBAAoB;AACpB,IAAI,CAAC,IAAI,CAAC,oBAAoB,CAAC,CAAC;AAEhC,MAAM,sBAAsB,GAAG,IAAI,CAAC,MAAM,CAAC,gBAAgB,CAAC,CAAC;AAE7D,QAAQ,CAAC,0BAA0B,EAAE,GAAG,EAAE;IACxC,MAAM,WAAW,GAAY;QAC3B,IAAI,EAAE,SAAS;QACf,EAAE,EAAE,kBAAkB;QACtB,cAAc,EAAE,SAAS;QACzB,cAAc,EAAE,EAAS;QACzB,KAAK,EAAE,CAAC;QACR,YAAY,EAAE,4CAA4C;QAC1D,gBAAgB,EAAE,iBAAiB;QACnC,IAAI,EAAE,IAAI;QACV,OAAO,EAAE,IAAI,SAAS,CAAC,qBAAqB,CAAC,EAAE,QAAQ;QACvD,gBAAgB,EAAE,IAAI,SAAS,CAAC,qBAAqB,CAAC;QACtD,YAAY,EAAE,IAAI,IAAI,CAAC,YAAY,CAAC;QACpC,WAAW,EAAE,KAAK;QA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CAAC,uCAAuC,EAAE,KAAK,IAAI,EAAE;YACrD,MAAM,qBAAqB,GAAgB;gBACzC,GAAG,mBAAmB;gBACtB,MAAM,EAAE,IAAI,SAAS,CAAC,GAAG,CAAC;aAC3B,CAAC;YAEF,MAAM,MAAM,GAAG,MAAM,wBAAwB,CAAC,WAAW,EAAE,qBAAqB,CAAC,CAAC;YAElF,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,IAAI,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC;YAClD,MAAM,CAAC,sBAAsB,CAAC,CAAC,gBAAgB,EAAE,CAAC;QACpD,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"estimateGas.test.d.ts","sourceRoot":"","sources":["../../src/common-logic/estimateGas.test.ts"],"names":[],"mappings":""}
|
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
import { estimateGas } from "./estimateGas";
|
|
2
|
-
import { getThorClient } from "./getThorClient";
|
|
3
|
-
// Mock dependencies
|
|
4
|
-
jest.mock("./getThorClient");
|
|
5
|
-
const mockedGetThorClient = jest.mocked(getThorClient);
|
|
6
|
-
describe("estimateGas", () => {
|
|
7
|
-
const mockClauses = [
|
|
8
|
-
{
|
|
9
|
-
to: "0x742d35Cc6634C0532925a3b8D0B251d8c1743eC4",
|
|
10
|
-
value: "1000000000000000000",
|
|
11
|
-
data: "0x",
|
|
12
|
-
},
|
|
13
|
-
{
|
|
14
|
-
to: "0x123456789012345678901234567890123456789a",
|
|
15
|
-
value: "2000000000000000000",
|
|
16
|
-
data: "0xa9059cbb000000000000000000000000742d35cc6634c0532925a3b8d0b251d8c1743ec40000000000000000000000000000000000000000000000000de0b6b3a7640000",
|
|
17
|
-
},
|
|
18
|
-
];
|
|
19
|
-
const mockOrigin = "0x5034aa590125b64023a0262112b98d72e3c8e40e";
|
|
20
|
-
const mockEstimateGasResult = {
|
|
21
|
-
totalGas: 21000,
|
|
22
|
-
reverted: false,
|
|
23
|
-
revertReasons: [],
|
|
24
|
-
vmErrors: [],
|
|
25
|
-
};
|
|
26
|
-
const mockThorClient = {
|
|
27
|
-
gas: {
|
|
28
|
-
estimateGas: jest.fn(),
|
|
29
|
-
},
|
|
30
|
-
};
|
|
31
|
-
beforeEach(() => {
|
|
32
|
-
jest.clearAllMocks();
|
|
33
|
-
mockedGetThorClient.mockReturnValue(mockThorClient);
|
|
34
|
-
});
|
|
35
|
-
it("should estimate gas for transaction clauses", async () => {
|
|
36
|
-
mockThorClient.gas.estimateGas.mockResolvedValue(mockEstimateGasResult);
|
|
37
|
-
const result = await estimateGas(mockClauses, mockOrigin);
|
|
38
|
-
expect(mockedGetThorClient).toHaveBeenCalledTimes(1);
|
|
39
|
-
expect(mockThorClient.gas.estimateGas).toHaveBeenCalledWith(mockClauses, mockOrigin);
|
|
40
|
-
expect(result).toEqual(mockEstimateGasResult);
|
|
41
|
-
});
|
|
42
|
-
it("should handle single clause", async () => {
|
|
43
|
-
const singleClause = [mockClauses[0]];
|
|
44
|
-
mockThorClient.gas.estimateGas.mockResolvedValue(mockEstimateGasResult);
|
|
45
|
-
const result = await estimateGas(singleClause, mockOrigin);
|
|
46
|
-
expect(mockThorClient.gas.estimateGas).toHaveBeenCalledWith(singleClause, mockOrigin);
|
|
47
|
-
expect(result).toEqual(mockEstimateGasResult);
|
|
48
|
-
});
|
|
49
|
-
it("should handle empty clauses array", async () => {
|
|
50
|
-
const emptyClauses = [];
|
|
51
|
-
mockThorClient.gas.estimateGas.mockResolvedValue({
|
|
52
|
-
totalGas: 0,
|
|
53
|
-
reverted: false,
|
|
54
|
-
revertReasons: [],
|
|
55
|
-
vmErrors: [],
|
|
56
|
-
});
|
|
57
|
-
const result = await estimateGas(emptyClauses, mockOrigin);
|
|
58
|
-
expect(mockThorClient.gas.estimateGas).toHaveBeenCalledWith(emptyClauses, mockOrigin);
|
|
59
|
-
expect(result.totalGas).toBe(0);
|
|
60
|
-
});
|
|
61
|
-
it("should handle gas estimation with revert", async () => {
|
|
62
|
-
const revertedResult = {
|
|
63
|
-
totalGas: 0,
|
|
64
|
-
reverted: true,
|
|
65
|
-
revertReasons: ["insufficient balance"],
|
|
66
|
-
vmErrors: ["VM error: out of gas"],
|
|
67
|
-
};
|
|
68
|
-
mockThorClient.gas.estimateGas.mockResolvedValue(revertedResult);
|
|
69
|
-
const result = await estimateGas(mockClauses, mockOrigin);
|
|
70
|
-
expect(result).toEqual(revertedResult);
|
|
71
|
-
expect(result.reverted).toBe(true);
|
|
72
|
-
expect(result.revertReasons).toContain("insufficient balance");
|
|
73
|
-
});
|
|
74
|
-
it("should handle high gas estimation", async () => {
|
|
75
|
-
const highGasResult = {
|
|
76
|
-
totalGas: 500000,
|
|
77
|
-
reverted: false,
|
|
78
|
-
revertReasons: [],
|
|
79
|
-
vmErrors: [],
|
|
80
|
-
};
|
|
81
|
-
mockThorClient.gas.estimateGas.mockResolvedValue(highGasResult);
|
|
82
|
-
const result = await estimateGas(mockClauses, mockOrigin);
|
|
83
|
-
expect(result.totalGas).toBe(500000);
|
|
84
|
-
});
|
|
85
|
-
it("should propagate errors from thor client", async () => {
|
|
86
|
-
const errorMessage = "Network error";
|
|
87
|
-
mockThorClient.gas.estimateGas.mockRejectedValue(new Error(errorMessage));
|
|
88
|
-
await expect(estimateGas(mockClauses, mockOrigin)).rejects.toThrow(errorMessage);
|
|
89
|
-
});
|
|
90
|
-
it("should handle clauses with data for token transfers", async () => {
|
|
91
|
-
const tokenTransferClause = [
|
|
92
|
-
{
|
|
93
|
-
to: "0x0000000000000000000000000000456e65726779",
|
|
94
|
-
value: "0",
|
|
95
|
-
data: "0xa9059cbb000000000000000000000000742d35cc6634c0532925a3b8d0b251d8c1743ec40000000000000000000000000000000000000000000000000de0b6b3a7640000",
|
|
96
|
-
},
|
|
97
|
-
];
|
|
98
|
-
const tokenGasResult = {
|
|
99
|
-
totalGas: 37000,
|
|
100
|
-
reverted: false,
|
|
101
|
-
revertReasons: [],
|
|
102
|
-
vmErrors: [],
|
|
103
|
-
};
|
|
104
|
-
mockThorClient.gas.estimateGas.mockResolvedValue(tokenGasResult);
|
|
105
|
-
const result = await estimateGas(tokenTransferClause, mockOrigin);
|
|
106
|
-
expect(mockThorClient.gas.estimateGas).toHaveBeenCalledWith(tokenTransferClause, mockOrigin);
|
|
107
|
-
expect(result.totalGas).toBe(37000);
|
|
108
|
-
});
|
|
109
|
-
it("should get a new thor client instance for each call", async () => {
|
|
110
|
-
mockThorClient.gas.estimateGas.mockResolvedValue(mockEstimateGasResult);
|
|
111
|
-
await estimateGas(mockClauses, mockOrigin);
|
|
112
|
-
await estimateGas(mockClauses, mockOrigin);
|
|
113
|
-
expect(mockedGetThorClient).toHaveBeenCalledTimes(2);
|
|
114
|
-
});
|
|
115
|
-
it("should return the exact result from thor client", async () => {
|
|
116
|
-
const exactResult = {
|
|
117
|
-
totalGas: 123456,
|
|
118
|
-
reverted: false,
|
|
119
|
-
revertReasons: [],
|
|
120
|
-
vmErrors: [],
|
|
121
|
-
};
|
|
122
|
-
mockThorClient.gas.estimateGas.mockResolvedValue(exactResult);
|
|
123
|
-
const result = await estimateGas(mockClauses, mockOrigin);
|
|
124
|
-
expect(result).toBe(exactResult);
|
|
125
|
-
});
|
|
126
|
-
});
|
|
127
|
-
//# sourceMappingURL=estimateGas.test.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"estimateGas.test.js","sourceRoot":"","sources":["../../src/common-logic/estimateGas.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAIhD,oBAAoB;AACpB,IAAI,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC;AAE7B,MAAM,mBAAmB,GAAG,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC;AAEvD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AAC,CAAC;IACnC,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"fixPrefixCase.test.d.ts","sourceRoot":"","sources":["../../src/common-logic/fixPrefixCase.test.ts"],"names":[],"mappings":""}
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { fixPrefixCase } from "./fixPrefixCase";
|
|
2
|
-
describe("fixPrefixCase", () => {
|
|
3
|
-
it("should convert uppercase 0X prefix to lowercase 0x", () => {
|
|
4
|
-
const input = "0X1234567890abcdef";
|
|
5
|
-
const result = fixPrefixCase(input);
|
|
6
|
-
expect(result).toBe("0x1234567890abcdef");
|
|
7
|
-
});
|
|
8
|
-
it("should keep lowercase 0x prefix unchanged", () => {
|
|
9
|
-
const input = "0x1234567890abcdef";
|
|
10
|
-
const result = fixPrefixCase(input);
|
|
11
|
-
expect(result).toBe("0x1234567890abcdef");
|
|
12
|
-
});
|
|
13
|
-
it("should add 0x prefix when missing", () => {
|
|
14
|
-
const input = "1234567890abcdef";
|
|
15
|
-
const result = fixPrefixCase(input);
|
|
16
|
-
expect(result).toBe("0x1234567890abcdef");
|
|
17
|
-
});
|
|
18
|
-
it("should handle empty string by adding 0x prefix", () => {
|
|
19
|
-
const input = "";
|
|
20
|
-
const result = fixPrefixCase(input);
|
|
21
|
-
expect(result).toBe("0x");
|
|
22
|
-
});
|
|
23
|
-
it("should handle mixed case prefix 0X", () => {
|
|
24
|
-
const input = "0X123abc";
|
|
25
|
-
const result = fixPrefixCase(input);
|
|
26
|
-
expect(result).toBe("0x123abc");
|
|
27
|
-
});
|
|
28
|
-
it("should handle string starting with just 0 by adding x", () => {
|
|
29
|
-
const input = "01234";
|
|
30
|
-
const result = fixPrefixCase(input);
|
|
31
|
-
expect(result).toBe("0x01234");
|
|
32
|
-
});
|
|
33
|
-
it("should handle valid ethereum address", () => {
|
|
34
|
-
const input = "0x742d35Cc6634C0532925a3b8D0B251d8c1743eC4";
|
|
35
|
-
const result = fixPrefixCase(input);
|
|
36
|
-
expect(result).toBe("0x742d35Cc6634C0532925a3b8D0B251d8c1743eC4");
|
|
37
|
-
});
|
|
38
|
-
it("should handle address without prefix", () => {
|
|
39
|
-
const input = "742d35Cc6634C0532925a3b8D0B251d8c1743eC4";
|
|
40
|
-
const result = fixPrefixCase(input);
|
|
41
|
-
expect(result).toBe("0x742d35Cc6634C0532925a3b8D0B251d8c1743eC4");
|
|
42
|
-
});
|
|
43
|
-
});
|
|
44
|
-
//# sourceMappingURL=fixPrefixCase.test.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"fixPrefixCase.test.js","sourceRoot":"","sources":["../../src/common-logic/fixPrefixCase.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEhD,QAAQ,CAAC,eAAe,EAAE,GAAG,EAAE;IAC7B,EAAE,CAAC,oDAAoD,EAAE,GAAG,EAAE;QAC5D,MAAM,KAAK,GAAG,oBAAoB,CAAC;QACnC,MAAM,MAAM,GAAG,aAAa,CAAC,KAAK,CAAC,CAAC;QACpC,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,oBAAoB,CAAC,CAAC;IAC5C,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,2CAA2C,EAAE,GAAG,EAAE;QACnD,MAAM,KAAK,GAAG,oBAAoB,CAAC;QACnC,MAAM,MAAM,GAAG,aAAa,CAAC,KAAK,CAAC,CAAC;QACpC,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,oBAAoB,CAAC,CAAC;IAC5C,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,mCAAmC,EAAE,GAAG,EAAE;QAC3C,MAAM,KAAK,GAAG,kBAAkB,CAAC;QACjC,MAAM,MAAM,GAAG,aAAa,CAAC,KAAK,CAAC,CAAC;QACpC,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,oBAAoB,CA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
|
-
{"version":3,"file":"generateNonce.test.d.ts","sourceRoot":"","sources":["../../src/common-logic/generateNonce.test.ts"],"names":[],"mappings":""}
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import { generateNonce } from "./generateNonce";
|
|
2
|
-
import { Hex } from "@vechain/sdk-core";
|
|
3
|
-
// Mock the Hex.random method
|
|
4
|
-
jest.mock("@vechain/sdk-core", () => ({
|
|
5
|
-
Hex: {
|
|
6
|
-
random: jest.fn(),
|
|
7
|
-
},
|
|
8
|
-
}));
|
|
9
|
-
const mockedHex = jest.mocked(Hex);
|
|
10
|
-
describe("generateNonce", () => {
|
|
11
|
-
beforeEach(() => {
|
|
12
|
-
jest.clearAllMocks();
|
|
13
|
-
});
|
|
14
|
-
it("should generate a nonce using Hex.random with length 8", () => {
|
|
15
|
-
const mockHexValue = {
|
|
16
|
-
toString: jest.fn().mockReturnValue("0x1234567890abcdef"),
|
|
17
|
-
};
|
|
18
|
-
mockedHex.random.mockReturnValue(mockHexValue);
|
|
19
|
-
const result = generateNonce();
|
|
20
|
-
expect(mockedHex.random).toHaveBeenCalledWith(8);
|
|
21
|
-
expect(mockHexValue.toString).toHaveBeenCalled();
|
|
22
|
-
expect(result).toBe("0x1234567890abcdef");
|
|
23
|
-
});
|
|
24
|
-
it("should return a string", () => {
|
|
25
|
-
const mockHexValue = {
|
|
26
|
-
toString: jest.fn().mockReturnValue("0xabcdef1234567890"),
|
|
27
|
-
};
|
|
28
|
-
mockedHex.random.mockReturnValue(mockHexValue);
|
|
29
|
-
const result = generateNonce();
|
|
30
|
-
expect(typeof result).toBe("string");
|
|
31
|
-
});
|
|
32
|
-
it("should call toString on the hex value", () => {
|
|
33
|
-
const mockHexValue = {
|
|
34
|
-
toString: jest.fn().mockReturnValue("0x123456789abcdef0"),
|
|
35
|
-
};
|
|
36
|
-
mockedHex.random.mockReturnValue(mockHexValue);
|
|
37
|
-
generateNonce();
|
|
38
|
-
expect(mockHexValue.toString).toHaveBeenCalledTimes(1);
|
|
39
|
-
});
|
|
40
|
-
it("should handle different hex values", () => {
|
|
41
|
-
const testCases = [
|
|
42
|
-
"0x0000000000000000",
|
|
43
|
-
"0xffffffffffffffff",
|
|
44
|
-
"0x123456789abcdef0",
|
|
45
|
-
"0xa1b2c3d4e5f67890",
|
|
46
|
-
];
|
|
47
|
-
testCases.forEach(expectedValue => {
|
|
48
|
-
const mockHexValue = {
|
|
49
|
-
toString: jest.fn().mockReturnValue(expectedValue),
|
|
50
|
-
};
|
|
51
|
-
mockedHex.random.mockReturnValue(mockHexValue);
|
|
52
|
-
const result = generateNonce();
|
|
53
|
-
expect(result).toBe(expectedValue);
|
|
54
|
-
});
|
|
55
|
-
});
|
|
56
|
-
});
|
|
57
|
-
//# sourceMappingURL=generateNonce.test.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"generateNonce.test.js","sourceRoot":"","sources":["../../src/common-logic/generateNonce.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAExC,6BAA6B;AAC7B,IAAI,CAAC,IAAI,CAAC,mBAAmB,EAAE,GAAG,EAAE,CAAC,CAAC;IACpC,GAAG,EAAE;QACH,MAAM,EAAE,IAAI,CAAC,EAAE,EAAE;KAClB;CACF,CAAC,CAAC,CAAC;AAEJ,MAAM,SAAS,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;AAEnC,QAAQ,CAAC,eAAe,EAAE,GAAG,EAAE;IAC7B,UAAU,CAAC,GAAG,EAAE;QACd,IAAI,CAAC,aAAa,EAAE,CAAC;IACvB,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,wDAAwD,EAAE,GAAG,EAAE;QAChE,MAAM,YAAY,GAAG;YACnB,QAAQ,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC,eAAe,CAAC,oBAAoB,CAAC;SAC1D,CAAC;QAC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