@@ -674,6 +674,85 @@ describe('ADA', function () {
674674 should . deepEqual ( Number ( txJson . outputs [ 0 ] . amount ) + fee , testnetUTXO . UTXO_1 . value ) ;
675675 } ) ;
676676
677+ it ( 'should recover ADA plus token UTXOs - token and ADA both appear in outputs (unsigned sweep)' , async function ( ) {
678+ callBack
679+ . withArgs ( 'address_info' , { _addresses : [ wrwUser . walletAddress0 ] } )
680+ . resolves ( endpointResponses . addressInfoResponse . ADAAndTokenUTXOs ) ;
681+
682+ const res = await basecoin . recover ( {
683+ bitgoKey : wrwUser . bitgoKey ,
684+ recoveryDestination : destAddr ,
685+ } ) ;
686+ res . should . not . be . empty ( ) ;
687+ const unsignedTx = res . txRequests [ 0 ] . transactions [ 0 ] . unsignedTx ;
688+ unsignedTx . should . hasOwnProperty ( 'serializedTx' ) ;
689+
690+ const tx = new Transaction ( basecoin ) ;
691+ tx . fromRawTransaction ( unsignedTx . serializedTx ) ;
692+ const txJson = tx . toJson ( ) ;
693+
694+ txJson . inputs . length . should . equal ( 2 ) ;
695+ should . deepEqual ( txJson . inputs [ 0 ] . transaction_id , testnetUTXO . UTXO_1 . tx_hash ) ;
696+ should . deepEqual ( txJson . inputs [ 1 ] . transaction_id , testnetUTXO . UTXO_TOKEN . tx_hash ) ;
697+
698+ txJson . outputs . length . should . equal ( 2 ) ;
699+
700+ const tokenPolicyId = '2533cca6eb42076e144e9f2772c390dece9fce173bc38c72294b3924' ;
701+ const tokenEncodedAssetName = '5741544552' ;
702+ const tokenQuantity = '111' ;
703+ const minADAForToken = 1500000 ;
704+
705+ const tokenOutput = txJson . outputs . find ( ( o ) => o . multiAssets !== undefined ) ;
706+ should . exist ( tokenOutput ) ;
707+ should . deepEqual ( tokenOutput ! . address , destAddr ) ;
708+ should . deepEqual ( Number ( tokenOutput ! . amount ) , minADAForToken ) ;
709+ const expectedPolicyId = CardanoWasm . ScriptHash . from_bytes ( Buffer . from ( tokenPolicyId , 'hex' ) ) ;
710+ const expectedAssetName = CardanoWasm . AssetName . new ( Buffer . from ( tokenEncodedAssetName , 'hex' ) ) ;
711+ ( tokenOutput ! . multiAssets as CardanoWasm . MultiAsset )
712+ . get_asset ( expectedPolicyId , expectedAssetName )
713+ . to_str ( )
714+ . should . equal ( tokenQuantity ) ;
715+
716+ const adaOutput = txJson . outputs . find ( ( o ) => o . multiAssets === undefined ) ;
717+ should . exist ( adaOutput ) ;
718+ should . deepEqual ( adaOutput ! . address , destAddr ) ;
719+ const fee = Number ( tx . explainTransaction ( ) . fee . fee ) ;
720+ const totalBalance = testnetUTXO . UTXO_1 . value + testnetUTXO . UTXO_TOKEN . value ;
721+ should . deepEqual ( Number ( adaOutput ! . amount ) , totalBalance - minADAForToken - fee ) ;
722+
723+ const explained = tx . explainTransaction ( ) ;
724+ const explainedTokenOutput = explained . outputs . find ( ( o ) => o . amount === minADAForToken . toString ( ) ) ;
725+ should . exist ( explainedTokenOutput ) ;
726+
727+ // inputs and outputs in parsedTx should carry the assetList from the UTXO directly
728+ const parsedTxInputs = res . txRequests [ 0 ] . transactions [ 0 ] . unsignedTx . parsedTx . inputs as {
729+ address : string ;
730+ valueString : string ;
731+ assetList ?: { policy_id : string ; asset_name : string ; quantity : string } [ ] ;
732+ } [ ] ;
733+ parsedTxInputs . length . should . equal ( 1 ) ;
734+ should . exist ( parsedTxInputs [ 0 ] . assetList ) ;
735+ parsedTxInputs [ 0 ] . assetList ! . length . should . equal ( 1 ) ;
736+ should . deepEqual ( parsedTxInputs [ 0 ] . assetList ! [ 0 ] . policy_id , tokenPolicyId ) ;
737+ should . deepEqual ( parsedTxInputs [ 0 ] . assetList ! [ 0 ] . asset_name , tokenEncodedAssetName ) ;
738+ should . deepEqual ( parsedTxInputs [ 0 ] . assetList ! [ 0 ] . quantity , tokenQuantity ) ;
739+
740+ const parsedTxOutputs = res . txRequests [ 0 ] . transactions [ 0 ] . unsignedTx . parsedTx . outputs as {
741+ address : string ;
742+ valueString : string ;
743+ assetList ?: { policy_id : string ; asset_name : string ; quantity : string } [ ] ;
744+ } [ ] ;
745+ const parsedTokenOutput = parsedTxOutputs . find ( ( o ) => o . assetList !== undefined ) ;
746+ should . exist ( parsedTokenOutput ) ;
747+ parsedTokenOutput ! . assetList ! . length . should . equal ( 1 ) ;
748+ should . deepEqual ( parsedTokenOutput ! . assetList ! [ 0 ] . policy_id , tokenPolicyId ) ;
749+ should . deepEqual ( parsedTokenOutput ! . assetList ! [ 0 ] . asset_name , tokenEncodedAssetName ) ;
750+ should . deepEqual ( parsedTokenOutput ! . assetList ! [ 0 ] . quantity , tokenQuantity ) ;
751+ // pure ADA output should not have assetList
752+ const parsedAdaOutput = parsedTxOutputs . find ( ( o ) => o . assetList === undefined ) ;
753+ should . exist ( parsedAdaOutput ) ;
754+ } ) ;
755+
677756 it ( 'should recover ADA plus token UTXOs - token and ADA both appear in outputs (signed)' , async function ( ) {
678757 callBack
679758 . withArgs ( 'address_info' , { _addresses : [ wrwUser . walletAddress0 ] } )
0 commit comments