11import 'should' ;
22import sinon from 'sinon' ;
33
4- import { AbstractEthLikeNewCoins } from '@bitgo-beta/abstract-eth' ;
54import nock from 'nock' ;
65import * as request from 'supertest' ;
76import { app as expressApp } from '../../../masterBitGoExpressApp' ;
87import { AppMode , MasterExpressConfig , TlsMode } from '../../../shared/types' ;
98import { data as ethRecoveryData } from '../../mocks/ethRecoveryMusigMockData' ;
9+ import { BitGoAPITestHarness } from './testUtils' ;
1010
1111describe ( 'POST /api/v1/:coin/advancedwallet/recovery' , ( ) => {
1212 let agent : request . SuperAgentTest ;
@@ -41,23 +41,51 @@ describe('POST /api/v1/:coin/advancedwallet/recovery', () => {
4141 afterEach ( ( ) => {
4242 nock . cleanAll ( ) ;
4343 sinon . restore ( ) ;
44+ BitGoAPITestHarness . clearConstantsCache ( ) ;
4445 } ) ;
4546
4647 it ( 'should get the tx hex for broadcasting from eve on musig recovery ' , async ( ) => {
47- // sdk call mock on mbe
48- const recoverStub = sinon
49- . stub ( AbstractEthLikeNewCoins . prototype , 'recover' )
50- . resolves ( ethRecoveryData . unsignedSweepPrebuildTx ) ;
48+ const backupKeyAddress = '0x30edc88a77598833f58947638b2ac3d5713d9845' ;
49+ const apiKey = 'etherscan-api-token' ;
50+ const etherscanBase = 'https://api.etherscan.io' ;
51+ const chainid = '560048' ;
52+
53+ // Etherscan calls to get the nonce, balance, and sequence ID for the backup key and wallet contract
54+ const txlistNock = nock ( etherscanBase )
55+ . get (
56+ `/v2/api?chainid=${ chainid } &module=account&action=txlist&address=${ backupKeyAddress } &apikey=${ apiKey } ` ,
57+ )
58+ . twice ( )
59+ . reply ( 200 , { result : [ ] } ) ;
60+
61+ const backupBalanceNock = nock ( etherscanBase )
62+ . get (
63+ `/v2/api?chainid=${ chainid } &module=account&action=balance&address=${ backupKeyAddress } &apikey=${ apiKey } ` ,
64+ )
65+ . reply ( 200 , { result : '10000000000000000' } ) ;
66+
67+ const walletBalanceNock = nock ( etherscanBase )
68+ . get (
69+ `/v2/api?chainid=${ chainid } &module=account&action=balance&address=${ ethRecoveryData . walletContractAddress } &apikey=${ apiKey } ` ,
70+ )
71+ . reply ( 200 , { result : '1000000000000000000' } ) ;
72+
73+ const sequenceIdNock = nock ( etherscanBase )
74+ . get (
75+ `/v2/api?chainid=${ chainid } &module=proxy&action=eth_call&to=${ ethRecoveryData . walletContractAddress } &data=a0b7967b&tag=latest&apikey=${ apiKey } ` ,
76+ )
77+ . reply ( 200 , {
78+ result : '0x0000000000000000000000000000000000000000000000000000000000000001' ,
79+ } ) ;
5180
52- // the call to eve.recoverWallet(...)
53- // that contains the calls to sdk.signTransaction
5481 const eveRecoverWalletNock = nock ( advancedWalletManagerUrl )
55- . post ( `/api/${ coin } /multisig/recovery` , {
56- userPub : ethRecoveryData . userKey ,
57- backupPub : ethRecoveryData . backupKey ,
58- unsignedSweepPrebuildTx : ethRecoveryData . unsignedSweepPrebuildTx ,
59- coinSpecificParams : undefined ,
60- walletContractAddress : ethRecoveryData . walletContractAddress ,
82+ . post ( `/api/${ coin } /multisig/recovery` , ( body ) => {
83+ return (
84+ body . userPub === ethRecoveryData . userKey &&
85+ body . backupPub === ethRecoveryData . backupKey &&
86+ body . walletContractAddress === ethRecoveryData . walletContractAddress &&
87+ body . unsignedSweepPrebuildTx !== undefined
88+ ) ;
6189 } )
6290 . reply ( 200 , {
6391 txHex : ethRecoveryData . txHexFullSigned ,
@@ -74,13 +102,16 @@ describe('POST /api/v1/:coin/advancedwallet/recovery', () => {
74102 walletContractAddress : ethRecoveryData . walletContractAddress ,
75103 bitgoPub : '' ,
76104 } ,
77- apiKey : 'etherscan-api-token' ,
105+ apiKey,
78106 recoveryDestinationAddress : ethRecoveryData . recoveryDestinationAddress ,
79107 } ) ;
80108
81109 response . status . should . equal ( 200 ) ;
82110 response . body . should . have . property ( 'txHex' , ethRecoveryData . txHexFullSigned ) ;
83- sinon . assert . calledOnce ( recoverStub ) ;
111+ txlistNock . isDone ( ) . should . be . true ( ) ;
112+ backupBalanceNock . isDone ( ) . should . be . true ( ) ;
113+ walletBalanceNock . isDone ( ) . should . be . true ( ) ;
114+ sequenceIdNock . isDone ( ) . should . be . true ( ) ;
84115 eveRecoverWalletNock . done ( ) ;
85116 } ) ;
86117
0 commit comments