-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathnonRecovery.test.ts
More file actions
126 lines (115 loc) · 4.1 KB
/
Copy pathnonRecovery.test.ts
File metadata and controls
126 lines (115 loc) · 4.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
import 'should';
import * as request from 'supertest';
import nock from 'nock';
import { app as expressApp } from '../../../masterBitGoExpressApp';
import { AppMode, MasterExpressConfig, TlsMode } from '../../../shared/types';
import sinon from 'sinon';
import * as middleware from '../../../shared/middleware';
import * as masterMiddleware from '../../../api/master/middleware/middleware';
import { BitGoRequest } from '../../../types/request';
import { BitGoAPI } from '@bitgo-beta/sdk-api';
import { AdvancedWalletManagerClient } from '../../../api/master/clients/advancedWalletManagerClient';
describe('Non Recovery Tests', () => {
let agent: request.SuperAgentTest;
let mockBitgo: BitGoAPI;
const advancedWalletManagerUrl = 'http://advancedwalletmanager.invalid';
const accessToken = 'test-token';
const config: MasterExpressConfig = {
appMode: AppMode.MASTER_EXPRESS,
port: 0,
bind: 'localhost',
timeout: 60000,
env: 'test',
disableEnvCheck: true,
authVersion: 2,
advancedWalletManagerUrl: advancedWalletManagerUrl,
advancedWalletManagerCert: 'dummy-cert',
tlsMode: TlsMode.DISABLED,
httpLoggerFile: '',
clientCertAllowSelfSigned: true,
recoveryMode: false,
};
beforeEach(() => {
nock.disableNetConnect();
nock.enableNetConnect('127.0.0.1');
// Create mock BitGo instance with base functionality
mockBitgo = new BitGoAPI({ env: 'test' });
// Setup middleware stubs before creating app
sinon.stub(middleware, 'prepareBitGo').callsFake(() => (req, res, next) => {
(req as BitGoRequest<MasterExpressConfig>).bitgo = mockBitgo;
(req as BitGoRequest<MasterExpressConfig>).config = config;
next();
});
// Create app after middleware is stubbed
const app = expressApp(config);
agent = request.agent(app);
});
afterEach(() => {
nock.cleanAll();
sinon.restore();
});
describe('Recovery', () => {
const coin = 'tbtc';
beforeEach(() => {
sinon.stub(masterMiddleware, 'validateMasterExpressConfig').callsFake((req, res, next) => {
(req as BitGoRequest<MasterExpressConfig>).params = { coin };
(req as BitGoRequest<MasterExpressConfig>).awmClient = new AdvancedWalletManagerClient(
config,
coin,
);
next();
return undefined;
});
});
it('should fail to run mbe recovery if not in recovery mode', async () => {
const coin = 'tbtc';
const userPub = 'xpub_user';
const backupPub = 'xpub_backup';
const bitgoPub = 'xpub_bitgo';
const recoveryDestination = 'tb1qprdy6jwxrrr2qrwgd2tzl8z99hqp29jn6f3sguxulqm448myj6jsy2nwsu';
const response = await agent
.post(`/api/${coin}/wallet/recovery`)
.set('Authorization', `Bearer ${accessToken}`)
.send({
multiSigRecoveryParams: {
userPub,
backupPub,
bitgoPub,
walletContractAddress: '',
},
recoveryDestinationAddress: recoveryDestination,
coin,
apiKey: 'key',
coinSpecificParams: {
evmRecoveryOptions: {
gasPrice: 20000000000,
gasLimit: 500000,
},
},
});
response.status.should.equal(500);
response.body.should.have.property('error');
response.body.should.have.property('details');
response.body.details.should.containEql(
'Recovery operations are not enabled. The server must be in recovery mode to perform this action.',
);
});
});
describe('Recovery Consolidation', () => {
it('should fail to run mbe recovery consolidation if not in recovery mode', async () => {
const response = await agent
.post(`/api/trx/wallet/recoveryconsolidations`)
.set('Authorization', `Bearer ${accessToken}`)
.send({
multisigType: 'onchain',
userPub: 'user-xpub',
backupPub: 'backup-xpub',
bitgoPub: 'bitgo-xpub',
tokenContractAddress: 'tron-token',
startingScanIndex: 1,
endingScanIndex: 3,
});
response.status.should.equal(500);
});
});
});