@@ -21,6 +21,7 @@ import {
2121 wrwUser ,
2222} from '../resources' ;
2323import * as _ from 'lodash' ;
24+ import * as CardanoWasm from '@emurgo/cardano-serialization-lib-nodejs' ;
2425import { Ada , KeyPair , Tada } from '../../src' ;
2526import { Transaction } from '../../src/lib' ;
2627import { TransactionType } from '../../../sdk-core/src/account-lib/baseCoin/enum' ;
@@ -584,9 +585,10 @@ describe('ADA', function () {
584585 describe ( 'Recover Transactions:' , ( ) => {
585586 const destAddr = address . address2 ;
586587 const sandBox = sinon . createSandbox ( ) ;
588+ let callBack : sinon . SinonStub ;
587589
588590 beforeEach ( function ( ) {
589- const callBack = sandBox . stub ( Ada . prototype , 'getDataFromNode' as keyof Ada ) ;
591+ callBack = sandBox . stub ( Ada . prototype , 'getDataFromNode' as keyof Ada ) ;
590592 callBack
591593 . withArgs ( 'address_info' , {
592594 _addresses : [ wrwUser . walletAddress0 ] ,
@@ -671,6 +673,56 @@ describe('ADA', function () {
671673 should . deepEqual ( txJson . outputs [ 0 ] . address , destAddr ) ;
672674 should . deepEqual ( Number ( txJson . outputs [ 0 ] . amount ) + fee , testnetUTXO . UTXO_1 . value ) ;
673675 } ) ;
676+
677+ it ( 'should recover ADA plus token UTXOs - token and ADA both appear in outputs (signed)' , async function ( ) {
678+ callBack
679+ . withArgs ( 'address_info' , { _addresses : [ wrwUser . walletAddress0 ] } )
680+ . resolves ( endpointResponses . addressInfoResponse . ADAAndTokenUTXOs ) ;
681+
682+ const res = await basecoin . recover ( {
683+ userKey : wrwUser . userKey ,
684+ backupKey : wrwUser . backupKey ,
685+ bitgoKey : wrwUser . bitgoKey ,
686+ walletPassphrase : wrwUser . walletPassphrase ,
687+ recoveryDestination : destAddr ,
688+ } ) ;
689+ res . should . not . be . empty ( ) ;
690+ res . should . hasOwnProperty ( 'serializedTx' ) ;
691+
692+ const tx = new Transaction ( basecoin ) ;
693+ tx . fromRawTransaction ( res . serializedTx ) ;
694+ const txJson = tx . toJson ( ) ;
695+
696+ txJson . inputs . length . should . equal ( 2 ) ;
697+ should . deepEqual ( txJson . inputs [ 0 ] . transaction_id , testnetUTXO . UTXO_1 . tx_hash ) ;
698+ should . deepEqual ( txJson . inputs [ 1 ] . transaction_id , testnetUTXO . UTXO_TOKEN . tx_hash ) ;
699+
700+ // expect 2 outputs: one token output + one ADA change output, both at destAddr
701+ txJson . outputs . length . should . equal ( 2 ) ;
702+
703+ const tokenPolicyId = '2533cca6eb42076e144e9f2772c390dece9fce173bc38c72294b3924' ;
704+ const tokenEncodedAssetName = '5741544552' ;
705+ const tokenQuantity = '111' ;
706+ const minADAForToken = 1500000 ;
707+
708+ const tokenOutput = txJson . outputs . find ( ( o ) => o . multiAssets !== undefined ) ;
709+ should . exist ( tokenOutput ) ;
710+ should . deepEqual ( tokenOutput ! . address , destAddr ) ;
711+ should . deepEqual ( Number ( tokenOutput ! . amount ) , minADAForToken ) ;
712+ const expectedPolicyId = CardanoWasm . ScriptHash . from_bytes ( Buffer . from ( tokenPolicyId , 'hex' ) ) ;
713+ const expectedAssetName = CardanoWasm . AssetName . new ( Buffer . from ( tokenEncodedAssetName , 'hex' ) ) ;
714+ ( tokenOutput ! . multiAssets as CardanoWasm . MultiAsset )
715+ . get_asset ( expectedPolicyId , expectedAssetName )
716+ . to_str ( )
717+ . should . equal ( tokenQuantity ) ;
718+
719+ const adaOutput = txJson . outputs . find ( ( o ) => o . multiAssets === undefined ) ;
720+ should . exist ( adaOutput ) ;
721+ should . deepEqual ( adaOutput ! . address , destAddr ) ;
722+ const fee = Number ( tx . explainTransaction ( ) . fee . fee ) ;
723+ const totalBalance = testnetUTXO . UTXO_1 . value + testnetUTXO . UTXO_TOKEN . value ;
724+ should . deepEqual ( Number ( adaOutput ! . amount ) , totalBalance - minADAForToken - fee ) ;
725+ } ) ;
674726 } ) ;
675727
676728 describe ( 'Recover Transactions Multiple UTXO:' , ( ) => {
0 commit comments