@ledgerhq/coin-ton 0.9.1 → 0.9.2-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 +26 -0
- package/jest.config.js +2 -0
- package/lib/__tests__/fixtures/common.fixtures.d.ts.map +1 -1
- package/lib/__tests__/fixtures/common.fixtures.js +1 -2
- package/lib/__tests__/fixtures/common.fixtures.js.map +1 -1
- package/lib/transaction.d.ts +1 -0
- package/lib/transaction.d.ts.map +1 -1
- package/lib/transaction.js +240 -2
- package/lib/transaction.js.map +1 -1
- package/lib/transaction.unit.test.d.ts +2 -0
- package/lib/transaction.unit.test.d.ts.map +1 -0
- package/lib/transaction.unit.test.js +600 -0
- package/lib/transaction.unit.test.js.map +1 -0
- package/lib/types.d.ts +92 -2
- package/lib/types.d.ts.map +1 -1
- package/lib/utils.d.ts.map +1 -1
- package/lib/utils.js +2 -1
- package/lib/utils.js.map +1 -1
- package/lib-es/__tests__/fixtures/common.fixtures.d.ts.map +1 -1
- package/lib-es/__tests__/fixtures/common.fixtures.js +1 -2
- package/lib-es/__tests__/fixtures/common.fixtures.js.map +1 -1
- package/lib-es/transaction.d.ts +1 -0
- package/lib-es/transaction.d.ts.map +1 -1
- package/lib-es/transaction.js +238 -1
- package/lib-es/transaction.js.map +1 -1
- package/lib-es/transaction.unit.test.d.ts +2 -0
- package/lib-es/transaction.unit.test.d.ts.map +1 -0
- package/lib-es/transaction.unit.test.js +595 -0
- package/lib-es/transaction.unit.test.js.map +1 -0
- package/lib-es/types.d.ts +92 -2
- package/lib-es/types.d.ts.map +1 -1
- package/lib-es/utils.d.ts.map +1 -1
- package/lib-es/utils.js +2 -1
- package/lib-es/utils.js.map +1 -1
- package/package.json +8 -7
- package/src/__tests__/fixtures/common.fixtures.ts +5 -6
- package/src/transaction.ts +262 -2
- package/src/transaction.unit.test.ts +614 -0
- package/src/types.ts +119 -2
- package/src/utils.ts +9 -1
|
@@ -0,0 +1,614 @@
|
|
|
1
|
+
/* eslint-disable no-irregular-whitespace */
|
|
2
|
+
import BigNumber from "bignumber.js";
|
|
3
|
+
import { Address, Cell } from "@ton/core";
|
|
4
|
+
import type { Account } from "@ledgerhq/types-live";
|
|
5
|
+
import type { TonPayloadFormat, TonPayloadFormatRaw, Transaction, TransactionRaw } from "./types";
|
|
6
|
+
import { formatTransaction, fromTransactionRaw, toTransactionRaw } from "./transaction";
|
|
7
|
+
import { getCryptoCurrencyById } from "@ledgerhq/cryptoassets/currencies";
|
|
8
|
+
import { genAccount } from "@ledgerhq/coin-framework/mocks/account";
|
|
9
|
+
|
|
10
|
+
const baseTx: Transaction = {
|
|
11
|
+
family: "ton",
|
|
12
|
+
amount: BigNumber(0),
|
|
13
|
+
fees: BigNumber(0),
|
|
14
|
+
recipient: "recipient",
|
|
15
|
+
comment: { isEncrypted: false, text: "" },
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
const baseRawTx: TransactionRaw = {
|
|
19
|
+
family: "ton",
|
|
20
|
+
amount: "0",
|
|
21
|
+
fees: "0",
|
|
22
|
+
recipient: "recipient",
|
|
23
|
+
comment: { isEncrypted: false, text: "" },
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
const rawRandomAddress = "0:ed1691307050047117b998b561d8de82d31fbf84910ced6eb5fc92e7485ef8a7";
|
|
27
|
+
const randomAddress = Address.parse(rawRandomAddress);
|
|
28
|
+
|
|
29
|
+
const emptyCell = Cell.EMPTY;
|
|
30
|
+
const rawEmptyCell = emptyCell.toBoc().toString("base64");
|
|
31
|
+
|
|
32
|
+
const cases: Array<{
|
|
33
|
+
name: string;
|
|
34
|
+
tx: Transaction;
|
|
35
|
+
rawTx: TransactionRaw;
|
|
36
|
+
}> = [
|
|
37
|
+
{
|
|
38
|
+
name: "normal tx",
|
|
39
|
+
tx: {
|
|
40
|
+
...baseTx,
|
|
41
|
+
},
|
|
42
|
+
rawTx: {
|
|
43
|
+
...baseRawTx,
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
name: "tx with comment",
|
|
48
|
+
tx: {
|
|
49
|
+
...baseTx,
|
|
50
|
+
comment: {
|
|
51
|
+
isEncrypted: false,
|
|
52
|
+
text: "hello",
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
rawTx: {
|
|
56
|
+
...baseRawTx,
|
|
57
|
+
comment: {
|
|
58
|
+
isEncrypted: false,
|
|
59
|
+
text: "hello",
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
name: "tx with payload for jetton-transfer",
|
|
65
|
+
tx: {
|
|
66
|
+
...baseTx,
|
|
67
|
+
payload: {
|
|
68
|
+
type: "jetton-transfer",
|
|
69
|
+
queryId: BigInt(0),
|
|
70
|
+
amount: BigInt(0),
|
|
71
|
+
destination: randomAddress,
|
|
72
|
+
responseDestination: randomAddress,
|
|
73
|
+
customPayload: emptyCell,
|
|
74
|
+
forwardAmount: BigInt(0),
|
|
75
|
+
forwardPayload: emptyCell,
|
|
76
|
+
knownJetton: {
|
|
77
|
+
jettonId: 0,
|
|
78
|
+
workchain: 0,
|
|
79
|
+
},
|
|
80
|
+
},
|
|
81
|
+
},
|
|
82
|
+
rawTx: {
|
|
83
|
+
...baseRawTx,
|
|
84
|
+
payload: {
|
|
85
|
+
type: "jetton-transfer",
|
|
86
|
+
queryId: "0",
|
|
87
|
+
amount: "0",
|
|
88
|
+
destination: rawRandomAddress,
|
|
89
|
+
responseDestination: rawRandomAddress,
|
|
90
|
+
customPayload: rawEmptyCell,
|
|
91
|
+
forwardAmount: "0",
|
|
92
|
+
forwardPayload: rawEmptyCell,
|
|
93
|
+
knownJetton: {
|
|
94
|
+
jettonId: 0,
|
|
95
|
+
workchain: 0,
|
|
96
|
+
},
|
|
97
|
+
},
|
|
98
|
+
},
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
name: "tx with payload for jetton-transfer and no customPayload",
|
|
102
|
+
tx: {
|
|
103
|
+
...baseTx,
|
|
104
|
+
payload: {
|
|
105
|
+
type: "jetton-transfer",
|
|
106
|
+
queryId: BigInt(0),
|
|
107
|
+
amount: BigInt(0),
|
|
108
|
+
destination: randomAddress,
|
|
109
|
+
responseDestination: randomAddress,
|
|
110
|
+
customPayload: null,
|
|
111
|
+
forwardAmount: BigInt(0),
|
|
112
|
+
forwardPayload: emptyCell,
|
|
113
|
+
knownJetton: {
|
|
114
|
+
jettonId: 0,
|
|
115
|
+
workchain: 0,
|
|
116
|
+
},
|
|
117
|
+
},
|
|
118
|
+
},
|
|
119
|
+
rawTx: {
|
|
120
|
+
...baseRawTx,
|
|
121
|
+
payload: {
|
|
122
|
+
type: "jetton-transfer",
|
|
123
|
+
queryId: "0",
|
|
124
|
+
amount: "0",
|
|
125
|
+
destination: rawRandomAddress,
|
|
126
|
+
responseDestination: rawRandomAddress,
|
|
127
|
+
customPayload: null,
|
|
128
|
+
forwardAmount: "0",
|
|
129
|
+
forwardPayload: rawEmptyCell,
|
|
130
|
+
knownJetton: {
|
|
131
|
+
jettonId: 0,
|
|
132
|
+
workchain: 0,
|
|
133
|
+
},
|
|
134
|
+
},
|
|
135
|
+
},
|
|
136
|
+
},
|
|
137
|
+
{
|
|
138
|
+
name: "tx with payload for nft-transfer",
|
|
139
|
+
tx: {
|
|
140
|
+
...baseTx,
|
|
141
|
+
payload: {
|
|
142
|
+
type: "nft-transfer",
|
|
143
|
+
queryId: BigInt(0),
|
|
144
|
+
newOwner: randomAddress,
|
|
145
|
+
responseDestination: randomAddress,
|
|
146
|
+
customPayload: emptyCell,
|
|
147
|
+
forwardAmount: BigInt(0),
|
|
148
|
+
forwardPayload: emptyCell,
|
|
149
|
+
},
|
|
150
|
+
},
|
|
151
|
+
rawTx: {
|
|
152
|
+
...baseRawTx,
|
|
153
|
+
payload: {
|
|
154
|
+
type: "nft-transfer",
|
|
155
|
+
queryId: "0",
|
|
156
|
+
newOwner: rawRandomAddress,
|
|
157
|
+
responseDestination: rawRandomAddress,
|
|
158
|
+
customPayload: rawEmptyCell,
|
|
159
|
+
forwardAmount: "0",
|
|
160
|
+
forwardPayload: rawEmptyCell,
|
|
161
|
+
},
|
|
162
|
+
},
|
|
163
|
+
},
|
|
164
|
+
{
|
|
165
|
+
name: "tx with payload for nft-transfer and no queryId",
|
|
166
|
+
tx: {
|
|
167
|
+
...baseTx,
|
|
168
|
+
payload: {
|
|
169
|
+
type: "nft-transfer",
|
|
170
|
+
queryId: null,
|
|
171
|
+
newOwner: randomAddress,
|
|
172
|
+
responseDestination: randomAddress,
|
|
173
|
+
customPayload: emptyCell,
|
|
174
|
+
forwardAmount: BigInt(0),
|
|
175
|
+
forwardPayload: emptyCell,
|
|
176
|
+
},
|
|
177
|
+
},
|
|
178
|
+
rawTx: {
|
|
179
|
+
...baseRawTx,
|
|
180
|
+
payload: {
|
|
181
|
+
type: "nft-transfer",
|
|
182
|
+
queryId: null,
|
|
183
|
+
newOwner: rawRandomAddress,
|
|
184
|
+
responseDestination: rawRandomAddress,
|
|
185
|
+
customPayload: rawEmptyCell,
|
|
186
|
+
forwardAmount: "0",
|
|
187
|
+
forwardPayload: rawEmptyCell,
|
|
188
|
+
},
|
|
189
|
+
},
|
|
190
|
+
},
|
|
191
|
+
{
|
|
192
|
+
name: "tx with payload for comment",
|
|
193
|
+
tx: {
|
|
194
|
+
...baseTx,
|
|
195
|
+
payload: {
|
|
196
|
+
type: "comment",
|
|
197
|
+
text: "test",
|
|
198
|
+
},
|
|
199
|
+
},
|
|
200
|
+
rawTx: {
|
|
201
|
+
...baseRawTx,
|
|
202
|
+
payload: {
|
|
203
|
+
type: "comment",
|
|
204
|
+
text: "test",
|
|
205
|
+
},
|
|
206
|
+
},
|
|
207
|
+
},
|
|
208
|
+
{
|
|
209
|
+
name: "tx with payload for comment",
|
|
210
|
+
tx: {
|
|
211
|
+
...baseTx,
|
|
212
|
+
payload: {
|
|
213
|
+
type: "comment",
|
|
214
|
+
text: "test",
|
|
215
|
+
},
|
|
216
|
+
},
|
|
217
|
+
rawTx: {
|
|
218
|
+
...baseRawTx,
|
|
219
|
+
payload: {
|
|
220
|
+
type: "comment",
|
|
221
|
+
text: "test",
|
|
222
|
+
},
|
|
223
|
+
},
|
|
224
|
+
},
|
|
225
|
+
{
|
|
226
|
+
name: "tx with payload for unsafe",
|
|
227
|
+
tx: {
|
|
228
|
+
...baseTx,
|
|
229
|
+
payload: {
|
|
230
|
+
type: "unsafe",
|
|
231
|
+
message: emptyCell,
|
|
232
|
+
},
|
|
233
|
+
},
|
|
234
|
+
rawTx: {
|
|
235
|
+
...baseRawTx,
|
|
236
|
+
payload: {
|
|
237
|
+
type: "unsafe",
|
|
238
|
+
message: rawEmptyCell,
|
|
239
|
+
},
|
|
240
|
+
},
|
|
241
|
+
},
|
|
242
|
+
{
|
|
243
|
+
name: "tx with payload for jetton-burn",
|
|
244
|
+
tx: {
|
|
245
|
+
...baseTx,
|
|
246
|
+
payload: {
|
|
247
|
+
type: "jetton-burn",
|
|
248
|
+
queryId: BigInt(0),
|
|
249
|
+
amount: BigInt(0),
|
|
250
|
+
responseDestination: randomAddress,
|
|
251
|
+
customPayload: emptyCell,
|
|
252
|
+
},
|
|
253
|
+
},
|
|
254
|
+
rawTx: {
|
|
255
|
+
...baseRawTx,
|
|
256
|
+
payload: {
|
|
257
|
+
type: "jetton-burn",
|
|
258
|
+
queryId: "0",
|
|
259
|
+
amount: "0",
|
|
260
|
+
responseDestination: rawRandomAddress,
|
|
261
|
+
customPayload: rawEmptyCell,
|
|
262
|
+
},
|
|
263
|
+
},
|
|
264
|
+
},
|
|
265
|
+
{
|
|
266
|
+
name: "tx with payload for jetton-burn with buffer",
|
|
267
|
+
tx: {
|
|
268
|
+
...baseTx,
|
|
269
|
+
payload: {
|
|
270
|
+
type: "jetton-burn",
|
|
271
|
+
queryId: BigInt(0),
|
|
272
|
+
amount: BigInt(0),
|
|
273
|
+
responseDestination: randomAddress,
|
|
274
|
+
customPayload: Buffer.from("test"),
|
|
275
|
+
},
|
|
276
|
+
},
|
|
277
|
+
rawTx: {
|
|
278
|
+
...baseRawTx,
|
|
279
|
+
payload: {
|
|
280
|
+
type: "jetton-burn",
|
|
281
|
+
queryId: "0",
|
|
282
|
+
amount: "0",
|
|
283
|
+
responseDestination: rawRandomAddress,
|
|
284
|
+
customPayload: "74657374",
|
|
285
|
+
},
|
|
286
|
+
},
|
|
287
|
+
},
|
|
288
|
+
{
|
|
289
|
+
name: "tx with payload for jetton-burn and no customPayload",
|
|
290
|
+
tx: {
|
|
291
|
+
...baseTx,
|
|
292
|
+
payload: {
|
|
293
|
+
type: "jetton-burn",
|
|
294
|
+
queryId: BigInt(0),
|
|
295
|
+
amount: BigInt(0),
|
|
296
|
+
responseDestination: randomAddress,
|
|
297
|
+
customPayload: null,
|
|
298
|
+
},
|
|
299
|
+
},
|
|
300
|
+
rawTx: {
|
|
301
|
+
...baseRawTx,
|
|
302
|
+
payload: {
|
|
303
|
+
type: "jetton-burn",
|
|
304
|
+
queryId: "0",
|
|
305
|
+
amount: "0",
|
|
306
|
+
responseDestination: rawRandomAddress,
|
|
307
|
+
customPayload: null,
|
|
308
|
+
},
|
|
309
|
+
},
|
|
310
|
+
},
|
|
311
|
+
{
|
|
312
|
+
name: "tx with payload for add-whitelist",
|
|
313
|
+
tx: {
|
|
314
|
+
...baseTx,
|
|
315
|
+
payload: {
|
|
316
|
+
type: "add-whitelist",
|
|
317
|
+
queryId: BigInt(0),
|
|
318
|
+
address: randomAddress,
|
|
319
|
+
},
|
|
320
|
+
},
|
|
321
|
+
rawTx: {
|
|
322
|
+
...baseRawTx,
|
|
323
|
+
payload: {
|
|
324
|
+
type: "add-whitelist",
|
|
325
|
+
queryId: "0",
|
|
326
|
+
address: rawRandomAddress,
|
|
327
|
+
},
|
|
328
|
+
},
|
|
329
|
+
},
|
|
330
|
+
{
|
|
331
|
+
name: "tx with payload for single-nominator-withdraw",
|
|
332
|
+
tx: {
|
|
333
|
+
...baseTx,
|
|
334
|
+
payload: {
|
|
335
|
+
type: "single-nominator-withdraw",
|
|
336
|
+
queryId: BigInt(0),
|
|
337
|
+
amount: BigInt(0),
|
|
338
|
+
},
|
|
339
|
+
},
|
|
340
|
+
rawTx: {
|
|
341
|
+
...baseRawTx,
|
|
342
|
+
payload: {
|
|
343
|
+
type: "single-nominator-withdraw",
|
|
344
|
+
queryId: "0",
|
|
345
|
+
amount: "0",
|
|
346
|
+
},
|
|
347
|
+
},
|
|
348
|
+
},
|
|
349
|
+
{
|
|
350
|
+
name: "tx with payload for single-nominator-change-validator",
|
|
351
|
+
tx: {
|
|
352
|
+
...baseTx,
|
|
353
|
+
payload: {
|
|
354
|
+
type: "single-nominator-change-validator",
|
|
355
|
+
queryId: BigInt(0),
|
|
356
|
+
address: randomAddress,
|
|
357
|
+
},
|
|
358
|
+
},
|
|
359
|
+
rawTx: {
|
|
360
|
+
...baseRawTx,
|
|
361
|
+
payload: {
|
|
362
|
+
type: "single-nominator-change-validator",
|
|
363
|
+
queryId: "0",
|
|
364
|
+
address: rawRandomAddress,
|
|
365
|
+
},
|
|
366
|
+
},
|
|
367
|
+
},
|
|
368
|
+
{
|
|
369
|
+
name: "tx with payload for tonstakers-deposit",
|
|
370
|
+
tx: {
|
|
371
|
+
...baseTx,
|
|
372
|
+
payload: {
|
|
373
|
+
type: "tonstakers-deposit",
|
|
374
|
+
queryId: BigInt(0),
|
|
375
|
+
appId: BigInt(0),
|
|
376
|
+
},
|
|
377
|
+
},
|
|
378
|
+
rawTx: {
|
|
379
|
+
...baseRawTx,
|
|
380
|
+
payload: {
|
|
381
|
+
type: "tonstakers-deposit",
|
|
382
|
+
queryId: "0",
|
|
383
|
+
appId: "0",
|
|
384
|
+
},
|
|
385
|
+
},
|
|
386
|
+
},
|
|
387
|
+
{
|
|
388
|
+
name: "tx with payload for vote-for-proposal",
|
|
389
|
+
tx: {
|
|
390
|
+
...baseTx,
|
|
391
|
+
payload: {
|
|
392
|
+
type: "vote-for-proposal",
|
|
393
|
+
queryId: BigInt(0),
|
|
394
|
+
votingAddress: randomAddress,
|
|
395
|
+
expirationDate: 0,
|
|
396
|
+
vote: true,
|
|
397
|
+
needConfirmation: true,
|
|
398
|
+
},
|
|
399
|
+
},
|
|
400
|
+
rawTx: {
|
|
401
|
+
...baseRawTx,
|
|
402
|
+
payload: {
|
|
403
|
+
type: "vote-for-proposal",
|
|
404
|
+
queryId: "0",
|
|
405
|
+
votingAddress: rawRandomAddress,
|
|
406
|
+
expirationDate: 0,
|
|
407
|
+
vote: true,
|
|
408
|
+
needConfirmation: true,
|
|
409
|
+
},
|
|
410
|
+
},
|
|
411
|
+
},
|
|
412
|
+
{
|
|
413
|
+
name: "tx with payload for change-dns-record type wallet",
|
|
414
|
+
tx: {
|
|
415
|
+
...baseTx,
|
|
416
|
+
payload: {
|
|
417
|
+
type: "change-dns-record",
|
|
418
|
+
queryId: BigInt(0),
|
|
419
|
+
record: {
|
|
420
|
+
type: "wallet",
|
|
421
|
+
value: {
|
|
422
|
+
address: randomAddress,
|
|
423
|
+
capabilities: {
|
|
424
|
+
isWallet: true,
|
|
425
|
+
},
|
|
426
|
+
},
|
|
427
|
+
},
|
|
428
|
+
},
|
|
429
|
+
},
|
|
430
|
+
rawTx: {
|
|
431
|
+
...baseRawTx,
|
|
432
|
+
payload: {
|
|
433
|
+
type: "change-dns-record",
|
|
434
|
+
queryId: "0",
|
|
435
|
+
record: {
|
|
436
|
+
type: "wallet",
|
|
437
|
+
value: {
|
|
438
|
+
address: rawRandomAddress,
|
|
439
|
+
capabilities: {
|
|
440
|
+
isWallet: true,
|
|
441
|
+
},
|
|
442
|
+
},
|
|
443
|
+
},
|
|
444
|
+
},
|
|
445
|
+
},
|
|
446
|
+
},
|
|
447
|
+
{
|
|
448
|
+
name: "tx with payload for change-dns-record type wallet no value",
|
|
449
|
+
tx: {
|
|
450
|
+
...baseTx,
|
|
451
|
+
payload: {
|
|
452
|
+
type: "change-dns-record",
|
|
453
|
+
queryId: BigInt(0),
|
|
454
|
+
record: {
|
|
455
|
+
type: "wallet",
|
|
456
|
+
value: null,
|
|
457
|
+
},
|
|
458
|
+
},
|
|
459
|
+
},
|
|
460
|
+
rawTx: {
|
|
461
|
+
...baseRawTx,
|
|
462
|
+
payload: {
|
|
463
|
+
type: "change-dns-record",
|
|
464
|
+
queryId: "0",
|
|
465
|
+
record: {
|
|
466
|
+
type: "wallet",
|
|
467
|
+
value: null,
|
|
468
|
+
},
|
|
469
|
+
},
|
|
470
|
+
},
|
|
471
|
+
},
|
|
472
|
+
{
|
|
473
|
+
name: "tx with payload for change-dns-record type unknown",
|
|
474
|
+
tx: {
|
|
475
|
+
...baseTx,
|
|
476
|
+
payload: {
|
|
477
|
+
type: "change-dns-record",
|
|
478
|
+
queryId: BigInt(0),
|
|
479
|
+
record: {
|
|
480
|
+
type: "unknown",
|
|
481
|
+
key: Buffer.from("testKey"),
|
|
482
|
+
value: emptyCell,
|
|
483
|
+
},
|
|
484
|
+
},
|
|
485
|
+
},
|
|
486
|
+
rawTx: {
|
|
487
|
+
...baseRawTx,
|
|
488
|
+
payload: {
|
|
489
|
+
type: "change-dns-record",
|
|
490
|
+
queryId: "0",
|
|
491
|
+
record: {
|
|
492
|
+
type: "unknown",
|
|
493
|
+
key: "746573744b6579",
|
|
494
|
+
value: rawEmptyCell,
|
|
495
|
+
},
|
|
496
|
+
},
|
|
497
|
+
},
|
|
498
|
+
},
|
|
499
|
+
{
|
|
500
|
+
name: "tx with payload for token-bridge-pay-swap",
|
|
501
|
+
tx: {
|
|
502
|
+
...baseTx,
|
|
503
|
+
payload: {
|
|
504
|
+
type: "token-bridge-pay-swap",
|
|
505
|
+
queryId: BigInt(0),
|
|
506
|
+
swapId: Buffer.from("swapId"),
|
|
507
|
+
},
|
|
508
|
+
},
|
|
509
|
+
rawTx: {
|
|
510
|
+
...baseRawTx,
|
|
511
|
+
payload: {
|
|
512
|
+
type: "token-bridge-pay-swap",
|
|
513
|
+
queryId: "0",
|
|
514
|
+
swapId: "737761704964",
|
|
515
|
+
},
|
|
516
|
+
},
|
|
517
|
+
},
|
|
518
|
+
{
|
|
519
|
+
name: "tx with payload we don't support",
|
|
520
|
+
tx: {
|
|
521
|
+
...baseTx,
|
|
522
|
+
payload: {
|
|
523
|
+
type: "fake-type",
|
|
524
|
+
as: "is",
|
|
525
|
+
} as unknown as TonPayloadFormat,
|
|
526
|
+
},
|
|
527
|
+
rawTx: {
|
|
528
|
+
...baseRawTx,
|
|
529
|
+
payload: {
|
|
530
|
+
type: "fake-type",
|
|
531
|
+
as: "is",
|
|
532
|
+
} as unknown as TonPayloadFormatRaw,
|
|
533
|
+
},
|
|
534
|
+
},
|
|
535
|
+
];
|
|
536
|
+
|
|
537
|
+
describe("toTransactionRaw", () => {
|
|
538
|
+
it.each(cases)("should work for $name", ({ tx, rawTx }) => {
|
|
539
|
+
const resTx = toTransactionRaw(tx);
|
|
540
|
+
|
|
541
|
+
expect(resTx).toEqual(rawTx);
|
|
542
|
+
});
|
|
543
|
+
});
|
|
544
|
+
|
|
545
|
+
describe("fromTransactionRaw", () => {
|
|
546
|
+
it.each(cases)("should work for $name", ({ tx, rawTx }) => {
|
|
547
|
+
const resTx = fromTransactionRaw(rawTx);
|
|
548
|
+
|
|
549
|
+
expect(resTx).toEqual(tx);
|
|
550
|
+
});
|
|
551
|
+
});
|
|
552
|
+
|
|
553
|
+
const TON = getCryptoCurrencyById("ton");
|
|
554
|
+
|
|
555
|
+
describe("formatTransaction", () => {
|
|
556
|
+
const account: Account = genAccount("mocked-ton-account-1", {
|
|
557
|
+
currency: TON,
|
|
558
|
+
});
|
|
559
|
+
|
|
560
|
+
it("transaction with 0 amount", () => {
|
|
561
|
+
const transaction: Transaction = {
|
|
562
|
+
family: "ton",
|
|
563
|
+
amount: BigNumber(0),
|
|
564
|
+
recipient: "test-recipient",
|
|
565
|
+
fees: BigNumber(0),
|
|
566
|
+
comment: {
|
|
567
|
+
isEncrypted: false,
|
|
568
|
+
text: "",
|
|
569
|
+
},
|
|
570
|
+
};
|
|
571
|
+
expect(formatTransaction(transaction, account)).toMatchInlineSnapshot(`
|
|
572
|
+
"
|
|
573
|
+
SEND
|
|
574
|
+
TO test-recipient"
|
|
575
|
+
`);
|
|
576
|
+
});
|
|
577
|
+
|
|
578
|
+
it("transaction with amount", () => {
|
|
579
|
+
const transaction: Transaction = {
|
|
580
|
+
family: "ton",
|
|
581
|
+
amount: BigNumber(1000),
|
|
582
|
+
recipient: "test-recipient",
|
|
583
|
+
fees: BigNumber(0),
|
|
584
|
+
comment: {
|
|
585
|
+
isEncrypted: false,
|
|
586
|
+
text: "",
|
|
587
|
+
},
|
|
588
|
+
};
|
|
589
|
+
expect(formatTransaction(transaction, account)).toMatchInlineSnapshot(`
|
|
590
|
+
"
|
|
591
|
+
SEND 0.000001 TON
|
|
592
|
+
TO test-recipient"
|
|
593
|
+
`);
|
|
594
|
+
});
|
|
595
|
+
|
|
596
|
+
it("transaction with useAllAmount", () => {
|
|
597
|
+
const transaction: Transaction = {
|
|
598
|
+
family: "ton",
|
|
599
|
+
amount: BigNumber(1000),
|
|
600
|
+
recipient: "test-recipient",
|
|
601
|
+
fees: BigNumber(0),
|
|
602
|
+
comment: {
|
|
603
|
+
isEncrypted: false,
|
|
604
|
+
text: "",
|
|
605
|
+
},
|
|
606
|
+
useAllAmount: true,
|
|
607
|
+
};
|
|
608
|
+
expect(formatTransaction(transaction, account)).toMatchInlineSnapshot(`
|
|
609
|
+
"
|
|
610
|
+
SEND MAX
|
|
611
|
+
TO test-recipient"
|
|
612
|
+
`);
|
|
613
|
+
});
|
|
614
|
+
});
|