-
Notifications
You must be signed in to change notification settings - Fork 302
Expand file tree
/
Copy pathton.ts
More file actions
850 lines (760 loc) · 38.8 KB
/
ton.ts
File metadata and controls
850 lines (760 loc) · 38.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
import { TestBitGo } from '@bitgo/sdk-test';
import { BitGoAPI } from '@bitgo/sdk-api';
import { Ton, TonParseTransactionOptions, Tton } from '../../src';
import * as sinon from 'sinon';
import assert from 'assert';
import * as testData from '../resources/ton';
import { EDDSAMethods, TransactionExplanation } from '@bitgo/sdk-core';
import should from 'should';
import utils from '../../src/lib/utils';
import Tonweb from 'tonweb';
describe('TON:', function () {
let basecoin;
const bitgo = TestBitGo.decorate(BitGoAPI, { env: 'mock' });
bitgo.safeRegister('ton', Ton.createInstance);
bitgo.safeRegister('tton', Tton.createInstance);
bitgo.initializeTestVars();
const txPrebuildList = [
{
txHex: Buffer.from(testData.signedSendTransaction.tx, 'base64').toString('hex'),
txInfo: {},
},
{
txHex: Buffer.from(testData.signedSingleNominatorWithdrawTransaction.tx, 'base64').toString('hex'),
txInfo: {},
},
];
const txPrebuildBounceableList = [
{
txHex: Buffer.from(testData.signedSendTransaction.txBounceable, 'base64').toString('hex'),
txInfo: {},
},
{
txHex: Buffer.from(testData.signedSingleNominatorWithdrawTransaction.txBounceable, 'base64').toString('hex'),
txInfo: {},
},
];
const txParamsList = [
{
recipients: [testData.signedSendTransaction.recipient],
},
{
recipients: [testData.signedSingleNominatorWithdrawTransaction.recipient],
},
];
const txParamsBounceableList = [
{
recipients: [testData.signedSendTransaction.recipientBounceable],
},
{
recipients: [testData.signedSingleNominatorWithdrawTransaction.recipientBounceable],
},
];
it('should return the right info', function () {
const ton = bitgo.coin('ton');
const tton = bitgo.coin('tton');
ton.getChain().should.equal('ton');
ton.getFamily().should.equal('ton');
ton.getFullName().should.equal('Ton');
ton.getBaseFactor().should.equal(1e9);
tton.getChain().should.equal('tton');
tton.getFamily().should.equal('ton');
tton.getFullName().should.equal('Testnet Ton');
tton.getBaseFactor().should.equal(1e9);
});
describe('Verify transaction: ', () => {
basecoin = bitgo.coin('tton');
txParamsList.forEach((_, index) => {
const txParams = txParamsList[index];
const txPrebuild = txPrebuildList[index];
const txParamsBounceable = txParamsBounceableList[index];
const txPrebuildBounceable = txPrebuildBounceableList[index];
it('should succeed to verify transaction', async function () {
const verification = {};
const isTransactionVerified = await basecoin.verifyTransaction({
txParams,
txPrebuild,
verification,
} as any);
isTransactionVerified.should.equal(true);
const isBounceableTransactionVerified = await basecoin.verifyTransaction({
txParams: txParamsBounceable,
txPrebuild: txPrebuildBounceable,
verification: {},
} as any);
isBounceableTransactionVerified.should.equal(true);
});
it('should succeed to verify transaction when recipients amount are numbers', async function () {
const txParamsWithNumberAmounts = JSON.parse(JSON.stringify(txParams));
txParamsWithNumberAmounts.recipients[0].amount = 20000000;
const verification = {};
await basecoin
.verifyTransaction({
txParams: txParamsWithNumberAmounts,
txPrebuild,
verification,
} as any)
.should.rejectedWith('Tx outputs does not match with expected txParams recipients');
});
it('should succeed to verify transaction when recipients amount are strings', async function () {
const txParamsWithNumberAmounts = JSON.parse(JSON.stringify(txParams));
txParamsWithNumberAmounts.recipients[0].amount = '20000000';
const verification = {};
await basecoin
.verifyTransaction({
txParams: txParamsWithNumberAmounts,
txPrebuild,
verification,
} as any)
.should.rejectedWith('Tx outputs does not match with expected txParams recipients');
});
it('should succeed to verify transaction when recipients amounts are number and amount is same', async function () {
const verification = {};
await basecoin
.verifyTransaction({
txParams,
txPrebuild,
verification,
} as any)
.should.resolvedWith(true);
});
it('should succeed to verify transaction when recipients amounts are string and amount is same', async function () {
const verification = {};
await basecoin
.verifyTransaction({
txParams,
txPrebuild,
verification,
} as any)
.should.resolvedWith(true);
});
it('should succeed to verify transaction when recipient address are non bounceable', async function () {
const txParamsWithNumberAmounts = JSON.parse(JSON.stringify(txParams));
txParamsWithNumberAmounts.recipients[0].address = new Tonweb.Address(
txParamsWithNumberAmounts.recipients[0].address
).toString(true, true, false);
const verification = {};
const isVerified = await basecoin.verifyTransaction({
txParams: txParamsWithNumberAmounts,
txPrebuild,
verification,
} as any);
isVerified.should.equal(true);
});
it('should fail to verify transaction with invalid param', async function () {
const txPrebuild = {};
await basecoin
.verifyTransaction({
txParams,
txPrebuild,
} as any)
.should.rejectedWith('missing required tx prebuild property txHex');
});
});
it('should succeed to verify transaction with recipient having memo', async function () {
const txParams = {
recipients: [testData.signedSendTransactionForMemoId.recipient],
};
const txPrebuild = {
txHex: Buffer.from(testData.signedSendTransactionForMemoId.tx, 'base64').toString('hex'),
txInfo: {},
};
const verification = {};
const isTransactionVerified = await basecoin.verifyTransaction({
txParams,
txPrebuild,
verification,
} as any);
isTransactionVerified.should.equal(true);
});
});
describe('Explain Transaction: ', () => {
const basecoin = bitgo.coin('tton');
it('should explain a transfer transaction', async function () {
const explainedTransaction = (await basecoin.explainTransaction({
txHex: Buffer.from(testData.signedSendTransaction.tx, 'base64').toString('hex'),
})) as TransactionExplanation;
explainedTransaction.should.deepEqual({
displayOrder: ['id', 'outputs', 'outputAmount', 'changeOutputs', 'changeAmount', 'fee', 'withdrawAmount'],
id: 'tuyOkyFUMv_neV_FeNBH24Nd4cML2jUgDP4zjGkuOFI=',
outputs: [
{
address: testData.signedSendTransaction.recipient.address,
amount: testData.signedSendTransaction.recipient.amount,
},
],
outputAmount: testData.signedSendTransaction.recipient.amount,
changeOutputs: [],
changeAmount: '0',
fee: { fee: 'UNKNOWN' },
withdrawAmount: undefined,
});
});
it('should explain a non-bounceable transfer transaction', async function () {
const explainedTransaction = (await basecoin.explainTransaction({
txHex: Buffer.from(testData.signedSendTransaction.tx, 'base64').toString('hex'),
toAddressBounceable: false,
fromAddressBounceable: false,
})) as TransactionExplanation;
explainedTransaction.should.deepEqual({
displayOrder: ['id', 'outputs', 'outputAmount', 'changeOutputs', 'changeAmount', 'fee', 'withdrawAmount'],
id: 'tuyOkyFUMv_neV_FeNBH24Nd4cML2jUgDP4zjGkuOFI=',
outputs: [
{
address: testData.signedSendTransaction.recipientBounceable.address,
amount: testData.signedSendTransaction.recipientBounceable.amount,
},
],
outputAmount: testData.signedSendTransaction.recipientBounceable.amount,
changeOutputs: [],
changeAmount: '0',
fee: { fee: 'UNKNOWN' },
withdrawAmount: undefined,
});
});
it('should explain a single nominator withdraw transaction', async function () {
const explainedTransaction = (await basecoin.explainTransaction({
txHex: Buffer.from(testData.signedSingleNominatorWithdrawTransaction.tx, 'base64').toString('hex'),
})) as TransactionExplanation;
explainedTransaction.should.deepEqual({
displayOrder: ['id', 'outputs', 'outputAmount', 'changeOutputs', 'changeAmount', 'fee', 'withdrawAmount'],
id: testData.signedSingleNominatorWithdrawTransaction.txId,
outputs: [
{
address: testData.signedSingleNominatorWithdrawTransaction.recipient.address,
amount: testData.signedSingleNominatorWithdrawTransaction.recipient.amount,
},
],
outputAmount: testData.signedSingleNominatorWithdrawTransaction.recipient.amount,
changeOutputs: [],
changeAmount: '0',
fee: { fee: 'UNKNOWN' },
withdrawAmount: '932178112330000',
});
});
it('should explain a non-bounceable single nominator withdraw transaction', async function () {
const explainedTransaction = (await basecoin.explainTransaction({
txHex: Buffer.from(testData.signedSingleNominatorWithdrawTransaction.tx, 'base64').toString('hex'),
toAddressBounceable: false,
fromAddressBounceable: false,
})) as TransactionExplanation;
explainedTransaction.should.deepEqual({
displayOrder: ['id', 'outputs', 'outputAmount', 'changeOutputs', 'changeAmount', 'fee', 'withdrawAmount'],
id: testData.signedSingleNominatorWithdrawTransaction.txId,
outputs: [
{
address: testData.signedSingleNominatorWithdrawTransaction.recipientBounceable.address,
amount: testData.signedSingleNominatorWithdrawTransaction.recipientBounceable.amount,
},
],
outputAmount: testData.signedSingleNominatorWithdrawTransaction.recipientBounceable.amount,
changeOutputs: [],
changeAmount: '0',
fee: { fee: 'UNKNOWN' },
withdrawAmount: '932178112330000',
});
});
it('should fail to explain transaction with missing params', async function () {
try {
await basecoin.explainTransaction({});
} catch (error) {
should.equal(error.message, 'Invalid transaction');
}
});
it('should fail to explain transaction with invalid params', async function () {
try {
await basecoin.explainTransaction({ txHex: 'randomString' });
} catch (error) {
should.equal(error.message, 'Invalid transaction');
}
});
});
describe('Parse Transactions: ', () => {
const basecoin = bitgo.coin('tton');
const transactionsList = [testData.signedSendTransaction.tx, testData.signedSingleNominatorWithdrawTransaction.tx];
const transactionInputsResponseList = [
[
{
address: 'EQCSBjR3fUOL98WTw2F_IT4BrcqjZJWVLWUSz5WQDpaL9Jpl',
amount: '10000000',
},
],
[
{
address: 'EQAbJug-k-tufWMjEC1RKSM0iiJTDUcYkC7zWANHrkT55Fol',
amount: '123400000',
},
],
];
const transactionInputsResponseBounceableList = [
[
{
address: 'UQCSBjR3fUOL98WTw2F_IT4BrcqjZJWVLWUSz5WQDpaL9Meg',
amount: '10000000',
},
],
[
{
address: 'UQAbJug-k-tufWMjEC1RKSM0iiJTDUcYkC7zWANHrkT55Afg',
amount: '123400000',
},
],
];
const transactionOutputsResponseList = [
[
{
address: 'EQA0i8-CdGnF_DhUHHf92R1ONH6sIA9vLZ_WLcCIhfBBXwtG',
amount: '10000000',
},
],
[
{
address: 'EQA0i8-CdGnF_DhUHHf92R1ONH6sIA9vLZ_WLcCIhfBBXwtG',
amount: '123400000',
},
],
];
const transactionOutputsResponseBounceableList = [
[
{
address: 'UQA0i8-CdGnF_DhUHHf92R1ONH6sIA9vLZ_WLcCIhfBBX1aD',
amount: '10000000',
},
],
[
{
address: 'UQA0i8-CdGnF_DhUHHf92R1ONH6sIA9vLZ_WLcCIhfBBX1aD',
amount: '123400000',
},
],
];
transactionsList.forEach((_, index) => {
const transaction = transactionsList[index];
const transactionInputsResponse = transactionInputsResponseList[index];
const transactionInputsResponseBounceable = transactionInputsResponseBounceableList[index];
const transactionOutputsResponse = transactionOutputsResponseList[index];
const transactionOutputsResponseBounceable = transactionOutputsResponseBounceableList[index];
it('should parse a TON transaction', async function () {
const parsedTransaction = await basecoin.parseTransaction({
txHex: Buffer.from(transaction, 'base64').toString('hex'),
});
parsedTransaction.should.deepEqual({
inputs: transactionInputsResponse,
outputs: transactionOutputsResponse,
});
});
it('should parse a non-bounceable TON transaction', async function () {
const parsedTransaction = await basecoin.parseTransaction({
txHex: Buffer.from(transaction, 'base64').toString('hex'),
toAddressBounceable: false,
fromAddressBounceable: false,
} as TonParseTransactionOptions);
parsedTransaction.should.deepEqual({
inputs: transactionInputsResponseBounceable,
outputs: transactionOutputsResponseBounceable,
});
});
it('should fail to parse a TON transaction when explainTransaction response is undefined', async function () {
const stub = sinon.stub(Ton.prototype, 'explainTransaction');
stub.resolves(undefined);
await basecoin.parseTransaction({ txHex: transaction }).should.be.rejectedWith('invalid raw transaction');
stub.restore();
});
});
});
describe('Address Validation', () => {
const basecoin = bitgo.coin('tton');
let keychains;
let commonKeychain;
before(function () {
commonKeychain =
'19bdfe2a4b498a05511381235a8892d54267807c4a3f654e310b938b8b424ff4adedbe92f4c146de641c67508a961324c8504cdf8e0c0acbb68d6104ccccd781';
keychains = [
{
id: '6424c353eaf78d000766e95949868468',
source: 'user',
type: 'tss',
commonKeychain:
'19bdfe2a4b498a05511381235a8892d54267807c4a3f654e310b938b8b424ff4adedbe92f4c146de641c67508a961324c8504cdf8e0c0acbb68d6104ccccd781',
encryptedPrv:
'{"iv":"cZd5i7L4RxtwrALW2rK7UA==","v":1,"iter":10000,"ks":256,"ts":64,"mode":"ccm","adata":"","cipher":"aes","salt":"5zgoH1Bd3Fw=","ct":"9vVlnXFRtrM9FVEo+d2chbGHlM9lFZemueBuAs3BIkPo33Fo7jzwwNK/kIWkEyg+NmEBd5IaqAS157nvvvwzzsmMWlQdUz9qbmXNv3pg987cXFR08exS+4uhwP1YNOjJTRvRNcO9ZqHb46d4fmyJ/yC9/susCge7r/EsbaN5C3afv1dzybuq912FwaQElZLYYp5BICudFOMZ9k0UDMfKM/PMDkH7WexoGHr9GKq/bgCH2B39TZZyHKU6Uy47lXep2s6h0DrMwHOrnmiL3DZjOj88Ynvphlzxuo4eOlD2UHia2+nvIaISYs29Pr0DAvREutchvcBpExj1kWWPv7hQYrv8F0NAdatsbWl3w+xKyfiMKo1USlrwyJviypGtQtXOJyw0XPN0rv2+L5lW8BbjpzHfYYN13fJTedlGTFhhkzVtbbPAKE02kx7zCJcjYaiexdSTsrDLScYNT9/Jhdt27KpsooehwVohLfSKz4vbFfRu2MPZw3/+c/hfiJNgtz6esWbnxGrcE8U2IwPYCaK+Ghk4DcqWNIni59RI5B5kAsQOToII40qPN510uTgxBSPO7q7MHgkxdd4CqBq+ojr9j0P7oao8E5Y+CBDJrojDoCh1oCCDW9vo2dXlVcD8SIbw7U/9AfvEbA4xyE/5md1M7CIwLnWs2Ynv0YtaKoqhdS9x6FmHlMDhN/DKHinrwmowtrTT82fOkpO5g9saSmgU7Qy3gLt8t+VwdEyeFeQUKRSyci8qgqXQaZIg4+aXgaSOnlCFMtmB8ekYxEhTY5uzRfrNgS4s1QeqFBpNtUF+Ydi297pbVXnJoXAN+SVWd80GCx+yI2dpVC89k3rOWK9WeyqlnzuLJWp2RIOB9cdW8GFv/fN+QAJpYeVxOE4+nZDsKnsj8nKcg9t4Dlx1G6gLM1/Vq9YxNLbuzuRC0asUYvdMnoMvszmpm++TxndYisgNYscpZSoz7wvcazJNEPfhPVjEkd6tUUuN4GM35H0DmKCUQNT+a6B6hmHlTZvjxiyGAg5bY59hdjvJ+22QduazlEEC6LI3HrA7uK0TpplWzS1tCIFvTMUhj65DEZmNJ2+ZY9bQ4vsMf+DRR3OOG4t+DMlNfjOd3zNv3QoY95BjfWpryFwPzDq7bCP67JDsoj7j2TY5FRSrRkD77H0Ewlux2cWfjRTwcMHcdQxxuV0OP0aNjGDjybFN"}',
},
{
id: '6424c353eaf78d000766e96137d4404b',
source: 'backup',
type: 'tss',
commonKeychain:
'19bdfe2a4b498a05511381235a8892d54267807c4a3f654e310b938b8b424ff4adedbe92f4c146de641c67508a961324c8504cdf8e0c0acbb68d6104ccccd781',
encryptedPrv:
'{"iv":"vi0dPef/Rx7kG/pRySQi6Q==","v":1,"iter":10000,"ks":256,"ts":64,"mode":"ccm","adata":"","cipher":"aes","salt":"9efhQsiEvVs=","ct":"Gw6atvf6gxKzsjtl3xseipO3rAxp1mAz7Yu1ihFsi5/lf2vMZegApgZx+pyILFS9KKLHbNF3U6WgSYdrr2t4vzdLsXkH1WIxfHS+cd2C5N59yADZDnPJBT6pv/IRvaYelP0Ck3nIYQ2hSMm8op+VOWC/SzHeh7slYDqwEHTGan0Wigfvk1yRd7CCJTaEAomnc/4eFi2NY3X3gt/3opy9IAgknnwUFohn96EWpEQ0F6pbzH/Z8VF6gF+DUcrrByAxExUPnHQZiFk3YHU/vVV4FxBU/mVAE8xBsBn5ul5e5SUMPfc7TBuJWv4BByTNg9xDShF/91Yx2nbfUm5d9QmM8lpKgzzQvcK8POAPk87gRCuKnsGh5vNS0UppkHc+ocfzRQlGA6jze7QyyQO0rMj5Ly8kWjwk2vISvKYHYS1NR7VU549UIXo7NXjatunKSc3+IreoRUHIshiaLg6hl+pxCCuc0qQ43V0mdIfCjTN8gkGWLNk8R7tAGPz9jyapQPcPEGHgEz0ATIi6yMNWCsibS2eLiE1uVEJONoM4lk6FPl3Q2CHbW2MeEbqjY8hbaw18mNb2xSBH/Fwpiial+Tvi2imqgnCO4ZpO9bllKftZPcQy0stN+eGBlb5ufyflKkDSiChHYroGjEpmiFicdde48cJszF52uKNnf1q67fA9/S2FAHQab3EXojxH2Gbk+kkV2h/TYKFFZSWC3vi4e8mO+vjMUcR0AdsgPFyEIz0SCGuba3CnTLNdEuZwsauAeHkx2vUTnRgJPVgNeeuXmsVG76Sy2ggJHuals0Hj8U2Xda0qO1RuFfoCWfss9wn6HGRwPPkhSB/8oNguAqmRVGKkd8Zwt3IvrTd9fk0/rFFDJKGz7WyNHkYgUmNiGcItD12v0jx7FZ52EJzl3Av1RyJUQK18+8EYPh3SGiU9dt7VX0aF0uo6JouKhOeldUvMP+AugQz8fUclwTQsbboVg27Yxo0DyATVwThW5a56R6Qf5ZiQJluFuzs5y98rq0S5q046lE6o3vVmJpEdwjeSCJoET5CL4nTgkXyWvhm4eB8u/e66l3o0qbaSx8q9YYmT9EpRcl5TP4ThLBKETYdzVvg4exjQfektMatk5EyUpEIhZPXh5vXpJZesdfO9LJ8zTaHBsBjDPU7cdNgQMbebpataRi8A0el2/IJXl+E+olgAz5zC4i2O1Q=="}',
},
{
id: '6424c353eaf78d000766e9510b125fba',
source: 'bitgo',
type: 'tss',
commonKeychain:
'19bdfe2a4b498a05511381235a8892d54267807c4a3f654e310b938b8b424ff4adedbe92f4c146de641c67508a961324c8504cdf8e0c0acbb68d6104ccccd781',
verifiedVssProof: true,
isBitGo: true,
},
];
});
it('should return true when validating a well formatted address', async function () {
const address = 'UQB0Hyt1bTRfI0WK_ULZyKvrvP0PPtpTQFi_jKXVXX6KFOMi';
basecoin.isValidAddress(address).should.equal(true);
});
it('should return false when validating an incorrectly formatted', async function () {
const address = 'wrongaddress';
basecoin.isValidAddress(address).should.equal(false);
});
it('should return true when validating a non-bounceable address format', async function () {
const address = 'UQA0i8-CdGnF_DhUHHf92R1ONH6sIA9vLZ_WLcCIhfBBX1aD';
basecoin.isValidAddress(address).should.equal(true);
});
it('should return true when validating addresses with memoIds', async function () {
const address1 = 'EQB0Hyt1bTRfI0WK_ULZyKvrvP0PPtpTQFi_jKXVXX6KFL7n?memoId=123';
const address2 = 'UQB0Hyt1bTRfI0WK_ULZyKvrvP0PPtpTQFi_jKXVXX6KFOMi?memoId=123';
basecoin.isValidAddress(address1).should.equal(true);
basecoin.isValidAddress(address2).should.equal(true);
});
it('should return true for isWalletAddress with valid address for index 4', async function () {
const newAddress = 'EQB0Hyt1bTRfI0WK_ULZyKvrvP0PPtpTQFi_jKXVXX6KFL7n';
const index = 4;
const params = { commonKeychain, address: newAddress, index, keychains };
(await basecoin.isWalletAddress(params)).should.equal(true);
});
it('should return true for isWalletAddress with valid addressand index', async function () {
const newAddress = 'EQB0Hyt1bTRfI0WK_ULZyKvrvP0PPtpTQFi_jKXVXX6KFL7n?memoId=4';
const index = 4;
const params = { commonKeychain, address: newAddress, index, keychains };
(await basecoin.isWalletAddress(params)).should.equal(true);
});
it('should return false for isWalletAddress with valid address for index 5 and address is for a different index', async function () {
const wrongAddressForIndex5 = 'EQB0Hyt1bTRfI0WK_ULZyKvrvP0PPtpTQFi_jKXVXX6KFL7n';
const index = 5;
const params = { commonKeychain, address: wrongAddressForIndex5, index, keychains };
(await basecoin.isWalletAddress(params)).should.equal(false);
});
it('should throw error for isWalletAddress when keychains is missing', async function () {
const address = 'EQB0Hyt1bTRfI0WK_ULZyKvrvP0PPtpTQFi_jKXVXX6KFL7n';
const index = 0;
const params = { commonKeychain, address, index };
await assert.rejects(async () => basecoin.isWalletAddress(params));
});
it('should throw error for isWalletAddress when new address is invalid', async function () {
const wrongAddress = 'badAddress';
const index = 0;
const params = { commonKeychain, address: wrongAddress, index };
await assert.rejects(async () => basecoin.isWalletAddress(params), {
message: `invalid address: ${wrongAddress}`,
});
});
});
describe('util class ', () => {
let commonKeychain;
let derivedPublicKey;
before(async function () {
commonKeychain =
'19bdfe2a4b498a05511381235a8892d54267807c4a3f654e310b938b8b424ff4adedbe92f4c146de641c67508a961324c8504cdf8e0c0acbb68d6104ccccd781';
const MPC = await EDDSAMethods.getInitializedMpcInstance();
derivedPublicKey = MPC.deriveUnhardened(commonKeychain, 'm/' + 0).slice(0, 64);
});
describe('getAddressFromPublicKey', function () {
it('should derive bounceable address by default', async function () {
(await utils.getAddressFromPublicKey(derivedPublicKey)).should.equal(
'EQDVeyUJOx3AnZGWLtE0l-Vxv7c7uTnD8OXtCFhaO-nvavQ5'
);
(await utils.getAddressFromPublicKey(derivedPublicKey, true)).should.equal(
'EQDVeyUJOx3AnZGWLtE0l-Vxv7c7uTnD8OXtCFhaO-nvavQ5'
);
});
it('should derive non-bounceable address when requested', async function () {
(await utils.getAddressFromPublicKey(derivedPublicKey, false)).should.equal(
'UQDVeyUJOx3AnZGWLtE0l-Vxv7c7uTnD8OXtCFhaO-nvaqn8'
);
});
it('should derive raw address when requested', async function () {
(await utils.getAddressFromPublicKey(derivedPublicKey, false, false)).should.equal(
'0:d57b25093b1dc09d91962ed13497e571bfb73bb939c3f0e5ed08585a3be9ef6a'
);
});
it('should get valid vesting contract address', async function () {
const vestingParams = {
subWalletId: 698983191,
publicKeyHex: '71013394862995cfb527dea9cadcc84d66d1197d2a4454579b93a08223e4b309',
vestingStartTime: 1760999164,
vestingTotalDuration: 60 * 60 * 24 * 30,
unlockPeriod: 60 * 60 * 24,
cliffDuration: 60 * 60,
vestingTotalAmount: BigInt('400000000'),
vestingSenderAddress: '0QDOEyzC6KXiVh2Rco2bapH96Vn6lb9YWxgkTVWtq-9CXFtp',
ownerAddress: '0QDBrOgjQThbN7eWBHErRhrJQH3ApecGDtu3K11Lujjmx49Z',
};
const vestingContractAddress = await utils.getVestingContractAddress(vestingParams);
vestingContractAddress.should.equal('EQAjmgMbwU3WVK_pn2gj1XBG_NMvrkoT4earvs_C9Q6fs-SE');
});
});
describe('getAddress', function () {
it('should return address as per bounceable flag', function () {
should.equal(
utils.getAddress('UQB0Hyt1bTRfI0WK_ULZyKvrvP0PPtpTQFi_jKXVXX6KFOMi', false),
'UQB0Hyt1bTRfI0WK_ULZyKvrvP0PPtpTQFi_jKXVXX6KFOMi'
);
should.equal(
utils.getAddress('UQB0Hyt1bTRfI0WK_ULZyKvrvP0PPtpTQFi_jKXVXX6KFOMi', true),
'EQB0Hyt1bTRfI0WK_ULZyKvrvP0PPtpTQFi_jKXVXX6KFL7n'
);
should.equal(
utils.getAddress('EQB0Hyt1bTRfI0WK_ULZyKvrvP0PPtpTQFi_jKXVXX6KFL7n', true),
'EQB0Hyt1bTRfI0WK_ULZyKvrvP0PPtpTQFi_jKXVXX6KFL7n'
);
should.equal(
utils.getAddress('EQB0Hyt1bTRfI0WK_ULZyKvrvP0PPtpTQFi_jKXVXX6KFL7n', false),
'UQB0Hyt1bTRfI0WK_ULZyKvrvP0PPtpTQFi_jKXVXX6KFOMi'
);
});
});
it('should validate block hash', async function () {
should.equal(utils.isValidBlockId('MPuOvHdu/z+t2l82YpZtiJQk8+FVKmWuKxd6ubn09fI='), true);
should.equal(utils.isValidBlockId('MPuOvHdu/z+t2l82YpZtiJQk8+FVKmWuKxd'), false);
should.equal(utils.isValidBlockId(''), false);
});
it('should validate transaction id', async function () {
should.equal(utils.isValidTransactionId('wlTdDOAXwJp8ESRfQAEJQIn0Tci_S5oLbVKBYxDtvpk='), true);
should.equal(utils.isValidTransactionId('3sykx6Rujy7UtBwHQ/X5kLgvKE0SKLA+ABiCKi7sX8o='), true); // No url friendly txid
should.equal(utils.isValidTransactionId('3sykx6Rujy7UtBwHQ_X5kLgvKE0SKLA-ABiCKi7sX8o='), true); // Url friendly txid
should.equal(utils.isValidTransactionId('wlTdDOAXwJp8ESRfQAEJQIn0Tci_S5oLb='), false);
should.equal(utils.isValidTransactionId('wlTdDOAXwJp8ESRfQAEJQIn0Tci_S5oLbVKBYxDtafdsasdadsfvpk='), false);
should.equal(utils.isValidTransactionId(''), false);
});
it('should generate transaction id', async function () {
const id = await utils.getMessageHashFromData(
'te6cckECCgEAAkoAA7V2k4Vw1nhxr7XcCBjWcFFHKqGwCglPSRuYAkWjWiTVAIAAAPbLgva0G7ytKw/xeE9a3FHK2RM8fgOpGvTpQRseeMer3efRKsiQAADxPhnaQFZWYrlQADRqbCUIAQIDAgHgBAUAgnIAZ0UIwmknkMaW7QboTcq48FfZ1NT5oMUj2VPOBr3zPoxriab4SfV65i6Hd1J2sFsuTcIWUobcKXMcIys+JWknAhMMwSvWBhmTzwRACAkB4YgA0nCuGs8ONfa7gQMazgoo5VQ2AUEp6SNzAEi0a0SaoBAHHgnPJBQQJ/meoCwzK5/PajBSxuJK2Gkva7NmlALNDs2IMEWi4ZRfIV4VeJpKBhzhKjNlFjuz60g+aeT5cNi4CU1NGLsrey/4AAAAGAAcBgEB3wcAaGIAK2cYdYCtxtBaWJ9hi7N+HVzeMsPQxLHSqYn7bfpOcRyh3NZQAAAAAAAAAAAAAAAAAAAAsWgA0nCuGs8ONfa7gQMazgoo5VQ2AUEp6SNzAEi0a0SaoBEAFbOMOsBW42gtLE+wxdm/Dq5vGWHoYljpVMT9tv0nOI5Q7msoAAYUWGAAAB7ZcF7WhMrMVypAAJ1BnYMTiAAAAAAAAAAAEQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAgAG/Jh6EgTBRYQAAAAAAAAgAAAAAAA4E52AP/eAYnVhJkoII4YUrhpLfpDFt6mRKiktbFnqs+QFAWDAAacQ0=\\'
);
should.equal(id, 'TsVgNKT05cde4Q54sC+RFC7nToTrHk9ppGgE5M0jXtE=');
});
it('should deserialize a cell to get the address', function () {
const data1 = 'te6cckEBAQEAJAAAQ4AaFUTgUQ/k2i+DdAooib0wNVREZQ2z+8R9WQvvFNpUJBARyAgK';
const rawAddress1 = '0:d0aa2702887f26d17c1ba051444de981aaa223286d9fde23eac85f78a6d2a120';
should.equal(utils.getRawWalletAddressFromCell(data1), rawAddress1);
const data2 = 'te6cckEBAQEAJAAAQ5/75w034qP9T0ZXY3muM5ouvFlNoNPky2YUs+Hcxd8otjDkIOPq';
const rawAddress2 = '-1:df3869bf151fea7a32bb1bcd719cd175e2ca6d069f265b30a59f0ee62ef945b1';
should.equal(utils.getRawWalletAddressFromCell(data2), rawAddress2);
});
});
describe('getAddressBoc', function () {
it('should return the correct BOC for a friendly address', async function () {
const result = await utils.getAddressBoc(testData.getMemberStackFixture.friendlyAddress);
result.should.equal(testData.getMemberStackFixture.boc);
});
it('should return the correct BOC for a raw address', async function () {
const result = await utils.getAddressBoc(testData.getMemberStackFixture.rawAddress);
result.should.equal(testData.getMemberStackFixture.boc);
});
});
describe('Ton recover - Non-BitGo and Unsigned Sweep Transactions', function () {
let sandbox: sinon.SinonSandbox;
beforeEach(() => {
sandbox = sinon.createSandbox(); // Create a new sandbox for each test
});
afterEach(() => {
sandbox.restore(); // Restore all stubs after each test
});
it('should successfully recover funds for non-BitGo recovery', async function () {
// Define recovery parameters
const recoveryParams = {
bitgoKey:
'1baafa0d62174bf0c78f3256318613ffc44b6dd54ab1a63c2185232f92ede9dae1b2818dbeb52a8215fd56f5a5f2a9f94c079ce89e4dc3b1ce6ed6e84ce71857',
recoveryDestination: 'UQBL2idCXR4ATdQtaNa4VpofcpSxuxIgHH7_slOZfdOXSadJ',
apiKey: 'db2554641c61e60a979cc6c0053f2ec91da9b13e71d287768c93c2fb556be53b',
userKey:
'1baafa0d62174bf0c78f3256318613ffc44b6dd54ab1a63c2185232f92ede9dae1b2818dbeb52a8215fd56f5a5f2a9f94c079ce89e4dc3b1ce6ed6e84ce71857',
walletPassphrase: 'dummyPassphrase',
};
// Mock the expected result for non-BitGo recovery
const mockResult = {
serializedTx:
'te6cckEBAgEAqgAB4YgAl7ROhLo8AJuoWtGtcK00PuUpY3YkQDj9/2SnMvunLpIFbl896wlMv7fsUOc+sMHzEl8q3vX5bm6noHginPJKBRznOrO7veIpHIEpiRLbH7/eNdpSsRhvL260JP/fD0vAIU1NGLtABDqAAAAACAAcAQBoQgB/OeiNdLeaL7+O04XuujuChSGrRd7ZnFl2fCd9FXdzAyDOJYCwAAAAAAAAAAAAAAAAAFwXGt8=',
scanIndex: 0,
coin: 'tton',
};
// Stub the recover function to return the mocked result
const sandbox = sinon.createSandbox();
sandbox.stub(basecoin, 'recover').resolves(mockResult);
// Call the recover function
const result = await basecoin.recover(recoveryParams);
// Validate the result
result.serializedTx.should.equal(
'te6cckEBAgEAqgAB4YgAl7ROhLo8AJuoWtGtcK00PuUpY3YkQDj9/2SnMvunLpIFbl896wlMv7fsUOc+sMHzEl8q3vX5bm6noHginPJKBRznOrO7veIpHIEpiRLbH7/eNdpSsRhvL260JP/fD0vAIU1NGLtABDqAAAAACAAcAQBoQgB/OeiNdLeaL7+O04XuujuChSGrRd7ZnFl2fCd9FXdzAyDOJYCwAAAAAAAAAAAAAAAAAFwXGt8='
);
result.scanIndex.should.equal(0);
result.coin.should.equal('tton');
sandbox.restore(); // Restore the stubbed method
});
it('should successfully recover funds using senderJettonAddress', async function () {
const recoveryParams = {
bitgoKey:
'e31b1580400dd4f96e8c6281cfb83e28aa25fcf8fb831996a40176a3e30878c80f366ff6463567dbeb7aa7faeeb9f0f6d1fc0a091ec9918e81ad2c34c345f4d0',
recoveryDestination: 'UQBL2idCXR4ATdQtaNa4VpofcpSxuxIgHH7_slOZfdOXSadJ',
apiKey: 'db2554641c61e60a979cc6c0053f2ec91da9b13e71d287768c93c2fb556be53b',
userKey:
'{"iv":"/9Ca180omwEYKiMgUJ90JQ==","v":1,"iter":10000,"ks":256,"ts":64,"mode":"ccm","adata":"","cipher":"aes","salt":"ipPFqg6qHHY=","ct":"eF6ZstvqobLWB/UfjpmsOcz5+bgvkMhq+Zh+f6TDIa++JkPYRq6hr2LhbidBBCNYHCgahi3nd/FdsFLQ1UkaN9t40mHbUdlSTA42ThH5FI9Um1aACm961Eu5b0Mp7o6U3zuVlaFay6T+/nUWlOKjv+/5MYwfxA/EzMd6yDie7qAIryLCPEIvRuusHupzcJWfN2WGkxw4EhGsSQvs62+PBOCJUeOCThv2HpssJV9gb6mj4lYVTqtEay7G6VFNb+T6OIDU9HNrdxV+5D1zzV5sHNWqDghF03w9adwxgTCPSeZywZPDgBrM/NqHIt+8CPd84wgey61Mz58br08zl2ikksDF5PB8DJzEens6AbY0gosqzAPTuOmy7IS9vP9lfCSaHDoS66hD/I0yh1c6th4gQ1dziwx+hnBKNgqpekJz6P0isnB3urhZInpc0RzKh6R2jrx+hKNr/2dok3dIwgbXWGq7NAm1mSREEs/ChVVeUMmeU9UFmwhOTbRK8CLYHqAqydRLCexNmWhTOPKy3WqS8yG6WkHqSGb9FGLyBRcmQFIBpihV8Xl4W2dB6AX7HsI0F2dYABX0drLiuj2N7mNraRGzxs5jT0lzwjXmy5gmyar23Dqa2eBVOyGdK3DL8jYvgX0mJ58/pKkogrxzMrPkJo2a+gP4OR7cDcL6TxrcwnViYOOGP9OaQZfcKKaAhmJZJGwzyWzjvyEILkCksESuy+c53tdLAku51j2KiV32Rg0tDO3UNjze0qTj3t+YfmTN1GuiNjxFx8dNbX2yxzYxB+MzesuNZAMunwVHrqJpAiozRqpE79R7KRLw7qhBhm5Uez60FBtmAf0kQsGdiIlEwCyTcBYyADlZE+ojD8+x2uiJBBIzd0s7n9ZY3aCYuTVEYGfI9EMGs9WzXcGeTu2xw2OubVHYkvaBbswlrJihIqRH+ce/9+wDedcjbsbo2MODsCJ3sK9KL6JjMWPvhSwR6cMbzDjWrFmRyuekmfSTHuhQEdBAK11N43/ZoYYDBMwBwxjMwwA4hLuBqjehYQ2N0N4o6fpbGSA1+g0IJqkQvh2qn8teYSj67m1vGlEJu852UjJZ4tdt9rSjQ5Tc23YK+XD2kKrXbB7wprraa9PQjnrrIT25yX+l5g7W0EcGTlAcv5/5FC6f6+7R8K5WlLGrp3YM/+570gBS2qbIhl2JzfwgTqjfyh5Z"}',
backupKey:
'{"iv":"NY65fme2sMeYdu77SW/aLw==","v":1,"iter":10000,"ks":256,"ts":64,"mode":"ccm","adata":"","cipher":"aes","salt":"1SErmofmV7s=","ct":"28zQG7xA2zFzAFyNJQfnIPvou12RwVPu3juzo2cIDareyfMkIXp1QDbo6mSBfzlJfOLgYAn0iQH8uCgnmYCN4CbK2IfOukMmQHGa4lHMGUXrL1rnNOsUZkh8YMcMMvr7qoCRjaKLQvRUWeqGt1/TCoROoHwR88ctVhEKwkhpQoIY0TBeLdvluGVB7pFATtEKgolyQaizZ8YOFvjQn9AGhVlOrRrjRwzHXqiu7yW8guL6f0B7ZczvFgLdCTFVNiyQQdr6Fo1Mi4GS/wRKbWakEx7Lktl3kva88BXARe8+undTZ0H2MbmzMSr5zBYpfhVXTO/axttktL2AWqMy8lR85Y7tVp307VUA8XNY3neTbTxuSqm+xrlB/R0nGFEvRfikGsk4KKHOQ6HFneNRdhj/k6dxE2VyH9IwQ6j+Lxjms+pg1yb56iBnGWM1sU0bdKaJFTRZGdiF//lQaKUVPcH2ReNJsRJaU8go5g1HBuOHeMqdnlB7uK2MQKNPCRb3y0ZFQx8ygidOaAF6aiJpz3LewnXhstD1y9lZ0yY9qXImB4lFCrMrmBnHPjEymzmrK+pchd4dBJHtJiqwngxqpL6l+aa69xGeyWDsVmMklZVPwdS5l+5SVygQGF5M1s1I7RfbTWb7WlHFFCv0C1J/tpKT3BziGEfP5Vj0aqeqicgmTRFwvhR1HiNmGvBANHM/PvSv5+cyRj8G7EHmTeuHeghO2h9ZwoZbihnSmyb/ncSM9MgxrSR4Xz7G33hnbujfHV4IpBG/vWTpJUKI11Lgwr71U2cVCn9WA+TY9CXsGkfeOQbbXngoPt4pOhikJKQYg9rOvgaR+hZAOSItk6pWXozADD8sSfs7R6+n/wlkEvuPI1cfcimbHLQ6oH9kTkDU/LbOzmtDDd8MYZUbqvpyES7bFujmw6tc1ZIBLDsSWD2r4siv0KPeVr5WuoJSYw6QRduAryO1NDw4Sk1alypgOXxJapcXgqwi1v9HdRzG1A0IULDZtyEcHjUBFW3vYqHxVc/j/z2hnAC/SbtRcCcZKgDerTNLbPw3iTQQfLiw+LPkeZdO4UUwsImaP3ywb112ieljWJoUtuYAYCEnz5k9sP3PfCDdgSb5BRJZIaDk7i3vWNXW1ydLNeXzRYpmr4vyMkGE7agL/+I5SZh5EVK/CYcAXgY2Mp/VfZWmeMbFVPXS89xLAwWnQQ=="}',
walletPassphrase: 'Ghghjfbvdkmn!234',
senderJettonAddress: 'UQBL2idCXR4ATdQtaNa4VpofcpSxuxIgHH7_slOZfdOXSadJ',
};
const mockProvider = {
getBalance: sandbox.stub().resolves('1000000000'),
getEstimateFee: sandbox.stub().resolves({
source_fees: {
in_fwd_fee: 1000,
storage_fee: 1000,
gas_fee: 1000,
fwd_fee: 1000,
},
}),
call: sandbox.stub().callsFake((address, method, params) => {
if (method === 'get_wallet_data') {
return Promise.resolve({
stack: [
['num', '5000000000'],
['num', '0'],
['cell', { bytes: '' }],
['cell', { bytes: '' }],
],
});
}
return Promise.resolve({ stack: [] });
}),
send: sandbox.stub().callsFake((method, params) => {
if (method === 'runGetMethod') {
return Promise.resolve({
gas_used: 0,
stack: [['num', '0']],
});
}
if (method === 'sendBoc') {
return Promise.resolve({ ok: true });
}
return Promise.resolve({});
}),
};
sandbox.stub(Tonweb, 'HttpProvider').returns(mockProvider);
const decryptStub = sandbox.stub(bitgo, 'decrypt');
decryptStub.onFirstCall().returns(JSON.stringify({ dummy: 'userSigningMaterial' }));
decryptStub.onSecondCall().returns(JSON.stringify({ dummy: 'backupSigningMaterial' }));
sandbox
.stub(EDDSAMethods, 'getTSSSignature')
.resolves(
Buffer.from(
'1baafa0d62174bf0c78f3256318613ffc44b6dd54ab1a63c2185232f92ede9da' +
'e1b2818dbeb52a8215fd56f5a5f2a9f94c079ce89e4dc3b1ce6ed6e84ce71857',
'hex'
)
);
const result = await basecoin.recover(recoveryParams);
result.should.have.property('serializedTx');
result.should.have.property('scanIndex');
result.scanIndex.should.equal(0);
});
it('should return an unsigned sweep transaction if userKey and backupKey are missing', async function () {
// Define recovery parameters
const recoveryParams = {
bitgoKey:
'1baafa0d62174bf0c78f3256318613ffc44b6dd54ab1a63c2185232f92ede9dae1b2818dbeb52a8215fd56f5a5f2a9f94c079ce89e4dc3b1ce6ed6e84ce71857',
recoveryDestination: 'UQBL2idCXR4ATdQtaNa4VpofcpSxuxIgHH7_slOZfdOXSadJ',
apiKey: 'db2554641c61e60a979cc6c0053f2ec91da9b13e71d287768c93c2fb556be53b',
};
// Mock the expected result for unsigned sweep transaction
const mockUnsignedTx = {
serializedTx:
'te6cckEBAgEAqgAB4YgAl7ROhLo8AJuoWtGtcK00PuUpY3YkQDj9/2SnMvunLpIFbl896wlMv7fsUOc+sMHzEl8q3vX5bm6noHginPJKBRznOrO7veIpHIEpiRLbH7/eNdpSsRhvL260JP/fD0vAIU1NGLtABDqAAAAACAAcAQBoQgB/OeiNdLeaL7+O04XuujuChSGrRd7ZnFl2fCd9FXdzAyDOJYCwAAAAAAAAAAAAAAAAAFwXGt8=',
scanIndex: 0,
coin: 'tton',
signableHex: 'dd98eb5a3700c0203237095ca1c0d5288bc0d650a9b59f7b81bac552f76137df',
derivationPath: 'm/0',
parsedTx: {
inputs: [
{
address: 'UQBL2idCXR4ATdQtaNa4VpofcpSxuxIgHH7_slOZfdOXSadJ',
valueString: '1000000000',
value: 1000000000,
},
],
outputs: [
{
address: 'UQBL2idCXR4ATdQtaNa4VpofcpSxuxIgHH7_slOZfdOXSadJ',
valueString: '999000000',
coinName: 'tton',
},
],
spendAmount: 999000000,
type: '',
},
feeInfo: {
fee: 1000000,
feeString: '1000000',
},
coinSpecific: {
commonKeychain:
'1baafa0d62174bf0c78f3256318613ffc44b6dd54ab1a63c2185232f92ede9dae1b2818dbeb52a8215fd56f5a5f2a9f94c079ce89e4dc3b1ce6ed6e84ce71857',
},
};
const mockTxRequest = {
transactions: [
{
unsignedTx: mockUnsignedTx,
signatureShares: [],
},
],
walletCoin: 'ton',
};
const mockTxRequests = {
txRequests: [mockTxRequest],
};
// Stub the recover function to return the mocked unsigned sweep transaction
const sandbox = sinon.createSandbox();
sandbox.stub(basecoin, 'recover').resolves(mockTxRequests);
// Call the recover function
const result = await basecoin.recover(recoveryParams);
// Validate the result
result.should.have.property('txRequests');
result.txRequests[0].should.have.property('transactions');
result.txRequests[0].transactions[0].should.have.property('unsignedTx');
result.txRequests[0].transactions[0].unsignedTx.should.equal(mockUnsignedTx);
});
it('should take OVC output and generate a signed sweep transaction', async function () {
// Define the parameters (mock OVC response)
const params = {
ovcResponse: {
serializedTx:
'te6cckEBAgEAqgAB4YgAl7ROhLo8AJuoWtGtcK00PuUpY3YkQDj9/2SnMvunLpIFbl896wlMv7fsUOc+sMHzEl8q3vX5bm6noHginPJKBRznOrO7veIpHIEpiRLbH7/eNdpSsRhvL260JP/fD0vAIU1NGLtABDqAAAAACAAcAQBoQgB/OeiNdLeaL7+O04XuujuChSGrRd7ZnFl2fCd9FXdzAyDOJYCwAAAAAAAAAAAAAAAAAFwXGt8=',
scanIndex: 0,
lastScanIndex: 0,
},
};
// Mock the expected result for the signed sweep transaction
const mockSignedSweepTxn = {
transactions: [
{
serializedTx:
'te6cckEBAgEAqgAB4YgAl7ROhLo8AJuoWtGtcK00PuUpY3YkQDj9/2SnMvunLpIFbl896wlMv7fsUOc+sMHzEl8q3vX5bm6noHginPJKBRznOrO7veIpHIEpiRLbH7/eNdpSsRhvL260JP/fD0vAIU1NGLtABDqAAAAACAAcAQBoQgB/OeiNdLeaL7+O04XuujuChSGrRd7ZnFl2fCd9FXdzAyDOJYCwAAAAAAAAAAAAAAAAAFwXGt8=',
scanIndex: 0,
},
],
lastScanIndex: 0,
};
// Stub the createBroadcastableSweepTransaction function to return the mocked result
sandbox.stub(basecoin, 'createBroadcastableSweepTransaction').resolves(mockSignedSweepTxn);
// Call the createBroadcastableSweepTransaction function
const recoveryTxn = await basecoin.createBroadcastableSweepTransaction(params);
// Validate the result
recoveryTxn.transactions[0].serializedTx.should.equal(
'te6cckEBAgEAqgAB4YgAl7ROhLo8AJuoWtGtcK00PuUpY3YkQDj9/2SnMvunLpIFbl896wlMv7fsUOc+sMHzEl8q3vX5bm6noHginPJKBRznOrO7veIpHIEpiRLbH7/eNdpSsRhvL260JP/fD0vAIU1NGLtABDqAAAAACAAcAQBoQgB/OeiNdLeaL7+O04XuujuChSGrRd7ZnFl2fCd9FXdzAyDOJYCwAAAAAAAAAAAAAAAAAFwXGt8='
);
recoveryTxn.transactions[0].scanIndex.should.equal(0);
recoveryTxn.lastScanIndex.should.equal(0);
});
});
});