@@ -3,6 +3,7 @@ import cloneDeep from "lodash/cloneDeep";
3
3
import {
4
4
SolanaAccount ,
5
5
SolanaTokenAccount ,
6
+ SolanaTokenProgram ,
6
7
TokenTransferCommand ,
7
8
TokenTransferTransaction ,
8
9
Transaction ,
@@ -24,7 +25,11 @@ import { prepareTransaction } from "../prepareTransaction";
24
25
import { encodeAccountId } from "@ledgerhq/coin-framework/lib/account/accountId" ;
25
26
import { NonTransferableExt , TransferFeeConfigExt } from "../network/chain/account/tokenExtensions" ;
26
27
import { PublicKey } from "@solana/web3.js" ;
27
- import { ASSOCIATED_TOKEN_PROGRAM_ID , TOKEN_PROGRAM_ID } from "@solana/spl-token" ;
28
+ import {
29
+ ASSOCIATED_TOKEN_PROGRAM_ID ,
30
+ TOKEN_2022_PROGRAM_ID ,
31
+ TOKEN_PROGRAM_ID ,
32
+ } from "@solana/spl-token" ;
28
33
import { calculateToken2022TransferFees } from "../helpers/token" ;
29
34
import { PARSED_PROGRAMS } from "../network/chain/program/constants" ;
30
35
@@ -58,8 +63,8 @@ const wSolSubAccId = encodeAccountIdWithTokenAccountAddress(mainAccId, testData.
58
63
const wSolToken = findTokenByAddressInCurrency ( testData . mintAddress , "solana" ) as TokenCurrency ;
59
64
60
65
const baseAccount = {
61
- balance : new BigNumber ( 0 ) ,
62
- spendableBalance : new BigNumber ( 0 ) ,
66
+ balance : new BigNumber ( 10000 ) ,
67
+ spendableBalance : new BigNumber ( 10000 ) ,
63
68
} as Account ;
64
69
65
70
const baseAPI = {
@@ -83,11 +88,23 @@ const baseAPI = {
83
88
} ,
84
89
getSimulationComputeUnits : ( _ixs : any [ ] , _payer : any ) => Promise . resolve ( 1000 ) ,
85
90
getBalance : ( _ : string ) => Promise . resolve ( 10 ) ,
91
+ findAssocTokenAccAddress : ( owner : string , mint : string , program : SolanaTokenProgram ) => {
92
+ return Promise . resolve (
93
+ PublicKey . findProgramAddressSync (
94
+ [
95
+ new PublicKey ( owner ) . toBuffer ( ) ,
96
+ program === "spl-token" ? TOKEN_PROGRAM_ID . toBuffer ( ) : TOKEN_2022_PROGRAM_ID . toBuffer ( ) ,
97
+ new PublicKey ( mint ) . toBuffer ( ) ,
98
+ ] ,
99
+ ASSOCIATED_TOKEN_PROGRAM_ID ,
100
+ ) [ 0 ] . toBase58 ( ) ,
101
+ ) ;
102
+ } ,
86
103
} as ChainAPI ;
87
104
88
105
// Broken tests as the address used is not support anymore
89
106
// Returning other errors we don't expect
90
- describe . skip ( "Solana tokens bridge integration tests" , ( ) => {
107
+ describe ( "Solana tokens bridge integration tests" , ( ) => {
91
108
const baseSolanaAccount : SolanaAccount = {
92
109
...baseAccount ,
93
110
freshAddress : testData . address1 ,
@@ -234,13 +251,93 @@ describe.skip("Solana tokens bridge integration tests", () => {
234
251
} ;
235
252
} ;
236
253
254
+ test ( "token.transfer :: status is success" , async ( ) => {
255
+ const api = {
256
+ ...baseAPI ,
257
+ getAccountInfo : ( address : string ) => {
258
+ if ( address === wSolToken . contractAddress ) {
259
+ return Promise . resolve ( baseTokenMintMock as any ) ;
260
+ }
261
+ if ( address === testData . address2 ) {
262
+ return Promise . resolve ( { data : { } } ) ;
263
+ }
264
+ return Promise . resolve ( { data : baseAtaMock } as any ) ;
265
+ } ,
266
+ } as ChainAPI ;
267
+
268
+ const account : SolanaAccount = {
269
+ ...baseSolanaAccount ,
270
+ subAccounts : [ mockedTokenAcc ] ,
271
+ } ;
272
+
273
+ const preparedTx = await prepareTransaction ( account , baseTx , api ) ;
274
+ const receivedTxStatus = await getTransactionStatus ( account , preparedTx ) ;
275
+ const expectedTxStatus : TransactionStatus = {
276
+ amount : new BigNumber ( 10 ) ,
277
+ estimatedFees : new BigNumber ( testData . fees ) ,
278
+ totalSpent : new BigNumber ( 10 ) ,
279
+ errors : { } ,
280
+ warnings : { } ,
281
+ } ;
282
+
283
+ expect ( receivedTxStatus ) . toEqual ( expectedTxStatus ) ;
284
+ } ) ;
285
+
286
+ // Send flow
287
+ test ( "token.transfer :: status is success: transfer with subAccountId" , async ( ) => {
288
+ const api = {
289
+ ...baseAPI ,
290
+ getAccountInfo : ( address : string ) => {
291
+ if ( address === wSolToken . contractAddress ) {
292
+ return Promise . resolve ( baseTokenMintMock as any ) ;
293
+ }
294
+ if ( address === testData . address2 ) {
295
+ return Promise . resolve ( { data : { } } ) ;
296
+ }
297
+ return Promise . resolve ( { data : baseAtaMock } as any ) ;
298
+ } ,
299
+ } as ChainAPI ;
300
+
301
+ const account : SolanaAccount = {
302
+ ...baseSolanaAccount ,
303
+ subAccounts : [ mockedTokenAcc ] ,
304
+ } ;
305
+
306
+ const transferTxWithSubAccountId : Transaction = {
307
+ model : {
308
+ kind : "transfer" ,
309
+ uiState : { } ,
310
+ } ,
311
+ amount : new BigNumber ( 10 ) ,
312
+ recipient : testData . address2 ,
313
+ family : "solana" ,
314
+ subAccountId : wSolSubAccId ,
315
+ } ;
316
+
317
+ const preparedTx = await prepareTransaction ( account , transferTxWithSubAccountId , api ) ;
318
+ const receivedTxStatus = await getTransactionStatus ( account , preparedTx ) ;
319
+ const expectedTxStatus : TransactionStatus = {
320
+ amount : new BigNumber ( 10 ) ,
321
+ estimatedFees : new BigNumber ( testData . fees ) ,
322
+ totalSpent : new BigNumber ( 10 ) ,
323
+ errors : { } ,
324
+ warnings : { } ,
325
+ } ;
326
+
327
+ expect ( preparedTx . model . commandDescriptor ?. command . kind ) . toEqual ( "token.transfer" ) ;
328
+ expect ( receivedTxStatus ) . toEqual ( expectedTxStatus ) ;
329
+ } ) ;
330
+
237
331
test ( "token.transfer :: status is error: sender ATA is frozen" , async ( ) => {
238
332
const api = {
239
333
...baseAPI ,
240
334
getAccountInfo : ( address : string ) => {
241
335
if ( address === wSolToken . contractAddress ) {
242
336
return Promise . resolve ( baseTokenMintMock as any ) ;
243
337
}
338
+ if ( address === testData . address2 ) {
339
+ return Promise . resolve ( { data : { } } ) ;
340
+ }
244
341
return Promise . resolve ( { data : baseAtaMock } as any ) ;
245
342
} ,
246
343
} as ChainAPI ;
@@ -276,6 +373,9 @@ describe.skip("Solana tokens bridge integration tests", () => {
276
373
if ( address === wSolToken . contractAddress ) {
277
374
return Promise . resolve ( baseTokenMintMock as any ) ;
278
375
}
376
+ if ( address === testData . address2 ) {
377
+ return Promise . resolve ( { data : { } } ) ;
378
+ }
279
379
return Promise . resolve ( { data : frozenAtaMock } as any ) ;
280
380
} ,
281
381
} as ChainAPI ;
@@ -310,6 +410,9 @@ describe.skip("Solana tokens bridge integration tests", () => {
310
410
if ( address === wSolToken . contractAddress ) {
311
411
return Promise . resolve ( baseToken2022MintMock as any ) ;
312
412
}
413
+ if ( address === testData . address2 ) {
414
+ return Promise . resolve ( { data : { } } ) ;
415
+ }
313
416
return Promise . resolve ( { data : baseAta2022Mock } as any ) ;
314
417
} ,
315
418
} as ChainAPI ;
@@ -346,6 +449,9 @@ describe.skip("Solana tokens bridge integration tests", () => {
346
449
if ( address === wSolToken . contractAddress ) {
347
450
return Promise . resolve ( baseToken2022MintMock as any ) ;
348
451
}
452
+ if ( address === testData . address2 ) {
453
+ return Promise . resolve ( { data : { } } ) ;
454
+ }
349
455
return Promise . resolve ( { data : ataWithRequiredMemoMock } as any ) ;
350
456
} ,
351
457
getBalance : ( ) => Promise . resolve ( 10 ) ,
@@ -381,6 +487,9 @@ describe.skip("Solana tokens bridge integration tests", () => {
381
487
if ( address === wSolToken . contractAddress ) {
382
488
return Promise . resolve ( mintWithTransferFeeMock as any ) ;
383
489
}
490
+ if ( address === testData . address2 ) {
491
+ return Promise . resolve ( { data : { } } ) ;
492
+ }
384
493
return Promise . resolve ( { data : baseAta2022Mock } ) ;
385
494
} ,
386
495
getBalance : ( ) => Promise . resolve ( BigNumber ( 100 ) . times ( magnitude ) . toNumber ( ) ) ,
@@ -444,6 +553,9 @@ describe.skip("Solana tokens bridge integration tests", () => {
444
553
if ( address === wSolToken . contractAddress ) {
445
554
return Promise . resolve ( mintWithTransferFeeMock as any ) ;
446
555
}
556
+ if ( address === testData . address2 ) {
557
+ return Promise . resolve ( { data : { } } ) ;
558
+ }
447
559
return Promise . resolve ( { data : baseAta2022Mock } ) ;
448
560
} ,
449
561
getBalance : ( ) => Promise . resolve ( balance . toNumber ( ) ) ,
@@ -519,6 +631,9 @@ describe.skip("Solana tokens bridge integration tests", () => {
519
631
if ( address === wSolToken . contractAddress ) {
520
632
return Promise . resolve ( mintWithTransferFeeMock as any ) ;
521
633
}
634
+ if ( address === testData . address2 ) {
635
+ return Promise . resolve ( { data : { } } ) ;
636
+ }
522
637
return Promise . resolve ( { data : baseAta2022Mock } ) ;
523
638
} ,
524
639
getBalance : ( ) => Promise . resolve ( balance . toNumber ( ) ) ,
@@ -563,6 +678,9 @@ describe.skip("Solana tokens bridge integration tests", () => {
563
678
if ( address === wSolToken . contractAddress ) {
564
679
return Promise . resolve ( mintWithNonTransferableExtensionMock as any ) ;
565
680
}
681
+ if ( address === testData . address2 ) {
682
+ return Promise . resolve ( { data : { } } ) ;
683
+ }
566
684
return Promise . resolve ( { data : baseAta2022Mock } as any ) ;
567
685
} ,
568
686
} as ChainAPI ;
0 commit comments