@@ -5,9 +5,11 @@ import { BitGoAPI } from '@bitgo/sdk-api';
55
66import { Wemix , Twemix } from '../../src/index' ;
77import { UnsignedSweepTxMPCv2 } from '@bitgo/abstract-eth' ;
8- import { mockDataUnsignedSweep } from '../resources' ;
8+ import { mockDataUnsignedSweep , mockDataNonBitGoRecovery } from '../resources' ;
99import nock from 'nock' ;
1010import { common } from '@bitgo/sdk-core' ;
11+ import { FeeMarketEIP1559Transaction } from '@ethereumjs/tx' ;
12+ import { stripHexPrefix } from '@ethereumjs/util' ;
1113
1214const bitgo : TestBitGoAPI = TestBitGo . decorate ( BitGoAPI , { env : 'test' } ) ;
1315
@@ -96,3 +98,47 @@ describe('Build Unsigned Sweep for Self-Custody Cold Wallets (MPCv2)', function
9698 tx . unsignedTx . parsedTx ?. should . have . property ( 'outputs' ) ;
9799 } ) ;
98100} ) ;
101+
102+ describe ( 'Non Bitgo Recovery for Hot Wallets' , function ( ) {
103+ const bitgo = TestBitGo . decorate ( BitGoAPI , { env : 'test' } ) ;
104+ const explorerUrl = common . Environments [ bitgo . getEnv ( ) ] . wemixExplorerBaseUrl as string ;
105+ const maxFeePerGasvalue = 20000000000 ;
106+ const maxPriorityFeePerGasValue = 10000000000 ;
107+ const chain_id = 1112 ;
108+ const gasLimitvalue = 500000 ;
109+
110+ it ( 'should generate a signed non-bitgo recovery tx' , async ( ) => {
111+ nock ( explorerUrl )
112+ . get ( '/api' )
113+ . twice ( )
114+ . query ( mockDataNonBitGoRecovery . getTxListRequest )
115+ . reply ( 200 , mockDataNonBitGoRecovery . getTxListResponse ) ;
116+ nock ( explorerUrl )
117+ . get ( '/api' )
118+ . query ( mockDataNonBitGoRecovery . getBalanceRequest )
119+ . reply ( 200 , mockDataNonBitGoRecovery . getBalanceResponse ) ;
120+
121+ const baseCoin : any = bitgo . coin ( 'twemix' ) ;
122+ const transaction = await baseCoin . recover ( {
123+ userKey : mockDataNonBitGoRecovery . userKeyData ,
124+ backupKey : mockDataNonBitGoRecovery . backupKeyData ,
125+ walletContractAddress : mockDataNonBitGoRecovery . walletRootAddress ,
126+ walletPassphrase : mockDataNonBitGoRecovery . walletPassphrase ,
127+ recoveryDestination : mockDataNonBitGoRecovery . recoveryDestination ,
128+ isTss : true ,
129+ eip1559 : { maxFeePerGas : maxFeePerGasvalue , maxPriorityFeePerGas : maxPriorityFeePerGasValue } ,
130+ gasLimit : gasLimitvalue ,
131+ replayProtectionOptions : {
132+ chain : chain_id ,
133+ hardfork : 'london' ,
134+ } ,
135+ } ) ;
136+ should . exist ( transaction ) ;
137+ transaction . should . have . property ( 'id' ) ;
138+ transaction . should . have . property ( 'tx' ) ;
139+ const tx = FeeMarketEIP1559Transaction . fromSerializedTx ( Buffer . from ( stripHexPrefix ( transaction . tx ) , 'hex' ) ) ;
140+ tx . getSenderAddress ( ) . toString ( ) . should . equal ( mockDataNonBitGoRecovery . walletRootAddress ) ;
141+ const jsonTx = tx . toJSON ( ) ;
142+ jsonTx . to ?. should . equal ( mockDataNonBitGoRecovery . recoveryDestination ) ;
143+ } ) ;
144+ } ) ;
0 commit comments