Skip to content

Commit 2f53b04

Browse files
feat(ebe): fix testing
1 parent fbeb114 commit 2f53b04

1 file changed

Lines changed: 72 additions & 0 deletions

File tree

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import 'should';
2+
import * as request from 'supertest';
3+
import nock from 'nock';
4+
import { app as expressApp } from '../../../enclavedApp';
5+
import { AppMode, EnclavedConfig, TlsMode } from '../../../shared/types';
6+
import sinon from 'sinon';
7+
import * as middleware from '../../../shared/middleware';
8+
import { BitGoRequest } from '../../../types/request';
9+
import { BitGoAPI as BitGo } from '@bitgo-beta/sdk-api';
10+
11+
describe('Non Recovery', () => {
12+
let agent: request.SuperAgentTest;
13+
const coin = 'tbtc';
14+
const config: EnclavedConfig = {
15+
appMode: AppMode.ENCLAVED,
16+
port: 0,
17+
bind: 'localhost',
18+
timeout: 60000,
19+
tlsMode: TlsMode.DISABLED,
20+
httpLoggerFile: '',
21+
allowSelfSigned: true,
22+
kmsUrl: 'kms.example.com',
23+
};
24+
25+
beforeEach(() => {
26+
nock.disableNetConnect();
27+
nock.enableNetConnect('127.0.0.1');
28+
29+
// Initialize BitGo with test environment
30+
const bitgo = new BitGo({
31+
env: 'test',
32+
accessToken: 'test_token',
33+
});
34+
35+
// Setup middleware stubs before creating app
36+
sinon.stub(middleware, 'prepareBitGo').callsFake(() => (req, res, next) => {
37+
(req as BitGoRequest<EnclavedConfig>).bitgo = bitgo;
38+
(req as BitGoRequest<EnclavedConfig>).config = config;
39+
next();
40+
});
41+
42+
// Create app after middleware is stubbed
43+
const app = expressApp(config);
44+
agent = request.agent(app);
45+
});
46+
47+
afterEach(() => {
48+
nock.cleanAll();
49+
sinon.restore();
50+
});
51+
52+
it('should fail to run ebe recovery if not in recovery mode', async () => {
53+
const userPub = 'xpub_user';
54+
const backupPub = 'xpub_backup';
55+
const bitgoPub = 'xpub_bitgo';
56+
57+
const response = await agent.post(`/api/${coin}/multisig/recovery`).send({
58+
userPub,
59+
backupPub,
60+
bitgoPub,
61+
unsignedSweepPrebuildTx: {},
62+
walletContractAddress: '',
63+
coin,
64+
});
65+
response.status.should.equal(500);
66+
response.body.should.have.property('error');
67+
response.body.should.have.property('details');
68+
response.body.details.should.containEql(
69+
'Recovery operations are not enabled. The server must be in recovery mode to perform this action.',
70+
);
71+
});
72+
});

0 commit comments

Comments
 (0)