@@ -14,6 +14,7 @@ import * as testData from '../fixtures/sol';
1414import * as resources from '../resources/sol' ;
1515import { getBuilderFactory } from './getBuilderFactory' ;
1616import { solBackupKey } from './fixtures/solBackupKey' ;
17+ import { TOKEN_2022_PROGRAM_ID } from '@solana/spl-token' ;
1718
1819describe ( 'SOL:' , function ( ) {
1920 let bitgo : TestBitGoAPI ;
@@ -1487,6 +1488,7 @@ describe('SOL:', function () {
14871488 const sandBox = sinon . createSandbox ( ) ;
14881489 const coin = coins . get ( 'tsol' ) ;
14891490 const usdtMintAddress = '9cgpBeNZ2HnLda7NWaaU1i3NyTstk2c4zCMUcoAGsi9C' ;
1491+ const t22mintAddress = '5NR1bQwLWqjbkhbQ1hx72HKJybbuvwkDnUZNoAZ2VhW6' ;
14901492 let callBack ;
14911493
14921494 beforeEach ( ( ) => {
@@ -1685,6 +1687,42 @@ describe('SOL:', function () {
16851687 } ,
16861688 } )
16871689 . resolves ( testData . SolResponses . getTokenAccountsByOwnerResponse ) ;
1690+ callBack
1691+ . withArgs ( {
1692+ payload : {
1693+ id : '1' ,
1694+ jsonrpc : '2.0' ,
1695+ method : 'getTokenAccountsByOwner' ,
1696+ params : [
1697+ testData . keys . destinationPubKey2 ,
1698+ {
1699+ programId : 'TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb' ,
1700+ } ,
1701+ {
1702+ encoding : 'jsonParsed' ,
1703+ } ,
1704+ ] ,
1705+ } ,
1706+ } )
1707+ . resolves ( testData . SolResponses . getTokenAccountsByOwnerForSol2022Response2 ) ;
1708+ callBack
1709+ . withArgs ( {
1710+ payload : {
1711+ id : '1' ,
1712+ jsonrpc : '2.0' ,
1713+ method : 'getTokenAccountsByOwner' ,
1714+ params : [
1715+ testData . wrwUser . walletAddress0 ,
1716+ {
1717+ programId : 'TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb' ,
1718+ } ,
1719+ {
1720+ encoding : 'jsonParsed' ,
1721+ } ,
1722+ ] ,
1723+ } ,
1724+ } )
1725+ . resolves ( testData . SolResponses . getTokenAccountsByOwnerForSol2022Response ) ;
16881726 callBack
16891727 . withArgs ( {
16901728 payload : {
@@ -2019,6 +2057,56 @@ describe('SOL:', function () {
20192057 sandBox . assert . callCount ( solCoin . getDataFromNode , 7 ) ;
20202058 } ) ;
20212059
2060+ it ( 'should recover sol 2022 tokens to recovery destination with existing token accounts' , async function ( ) {
2061+ const tokenTxn = await basecoin . recover ( {
2062+ userKey : testData . wrwUser . userKey ,
2063+ backupKey : testData . wrwUser . backupKey ,
2064+ bitgoKey : testData . wrwUser . bitgoKey ,
2065+ recoveryDestination : testData . keys . destinationPubKey2 ,
2066+ tokenContractAddress : t22mintAddress ,
2067+ walletPassphrase : testData . wrwUser . walletPassphrase ,
2068+ durableNonce : {
2069+ publicKey : testData . keys . durableNoncePubKey ,
2070+ secretKey : testData . keys . durableNoncePrivKey ,
2071+ } ,
2072+ programId : TOKEN_2022_PROGRAM_ID . toString ( ) ,
2073+ } ) ;
2074+
2075+ tokenTxn . should . not . be . empty ( ) ;
2076+ tokenTxn . should . hasOwnProperty ( 'serializedTx' ) ;
2077+ tokenTxn . should . hasOwnProperty ( 'scanIndex' ) ;
2078+ should . equal ( ( tokenTxn as MPCTx ) . scanIndex , 0 ) ;
2079+
2080+ const tokenTxnDeserialize = new Transaction ( coin ) ;
2081+ tokenTxnDeserialize . fromRawTransaction ( ( tokenTxn as MPCTx ) . serializedTx ) ;
2082+ const tokenTxnJson = tokenTxnDeserialize . toJson ( ) ;
2083+ console . log ( tokenTxnJson ) ;
2084+ should . equal ( tokenTxnJson . nonce , testData . SolInputData . durableNonceBlockhash ) ;
2085+ should . equal ( tokenTxnJson . feePayer , testData . wrwUser . walletAddress0 ) ;
2086+ should . equal ( tokenTxnJson . numSignatures , testData . SolInputData . durableNonceSignatures ) ;
2087+
2088+ const instructionsData = tokenTxnJson . instructionsData as TokenTransfer [ ] ;
2089+ should . equal ( instructionsData . length , 2 ) ;
2090+ should . equal ( instructionsData [ 0 ] . type , 'NonceAdvance' ) ;
2091+
2092+ const source2022TokenAccount = await getAssociatedTokenAccountAddress (
2093+ t22mintAddress ,
2094+ testData . wrwUser . walletAddress0
2095+ ) ;
2096+ const destination2022TokenAccount = await getAssociatedTokenAccountAddress (
2097+ t22mintAddress ,
2098+ testData . keys . destinationPubKey2
2099+ ) ;
2100+ should . equal ( instructionsData [ 1 ] . type , 'TokenTransfer' ) ;
2101+ should . equal ( instructionsData [ 1 ] . params . fromAddress , testData . wrwUser . walletAddress0 ) ;
2102+ should . equal ( instructionsData [ 1 ] . params . toAddress , destination2022TokenAccount ) ;
2103+ should . equal ( instructionsData [ 1 ] . params . amount , '2000000000' ) ;
2104+ should . equal ( instructionsData [ 1 ] . params . tokenName , 'tsol:t22mint' ) ;
2105+ should . equal ( instructionsData [ 1 ] . params . sourceAddress , source2022TokenAccount ) ;
2106+ const solCoin = basecoin as any ;
2107+ sandBox . assert . callCount ( solCoin . getDataFromNode , 7 ) ;
2108+ } ) ;
2109+
20222110 it ( 'should recover sol tokens to recovery destination with existing token accounts for unsigned sweep recoveries' , async function ( ) {
20232111 const feeResponse = testData . SolResponses . getFeesForMessageResponse ;
20242112 feeResponse . body . result . value = 10000 ;
0 commit comments