Skip to content

Commit ee6e10f

Browse files
committed
feat(ebe): added integration tests for ebe
1 parent 306852b commit ee6e10f

File tree

3 files changed

+237
-4
lines changed

3 files changed

+237
-4
lines changed

src/__tests__/masterBitgoExpress/generateWallet.test.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,6 @@ describe('POST /api/:coin/wallet/generate', () => {
4141
nock.cleanAll();
4242
});
4343

44-
after(() => {
45-
nock.restore();
46-
});
47-
4844
it('should generate a wallet by calling the enclaved express service', async () => {
4945
const userKeychainNock = nock(enclavedExpressUrl)
5046
.post(`/api/${coin}/key/independent`)
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
import 'should';
2+
3+
import * as request from 'supertest';
4+
import nock from 'nock';
5+
import { app as enclavedApp } from '../enclavedApp';
6+
import { AppMode, EnclavedConfig, TlsMode } from '../types';
7+
import express from 'express';
8+
9+
import * as sinon from 'sinon';
10+
import * as configModule from '../initConfig';
11+
12+
describe('postIndependentKey', () => {
13+
let cfg: EnclavedConfig;
14+
let app: express.Application;
15+
let agent: request.SuperAgentTest;
16+
17+
// test cofig
18+
const kmsUrl = 'http://kms.invalid';
19+
const coin = 'hteth';
20+
const accessToken = 'test-token';
21+
22+
// sinon stubs
23+
let configStub: sinon.SinonStub;
24+
25+
before(() => {
26+
// nock config
27+
nock.disableNetConnect();
28+
nock.enableNetConnect('127.0.0.1');
29+
30+
// app config
31+
cfg = {
32+
appMode: AppMode.ENCLAVED,
33+
port: 0, // Let OS assign a free port
34+
bind: 'localhost',
35+
timeout: 60000,
36+
logFile: '',
37+
kmsUrl: kmsUrl,
38+
tlsMode: TlsMode.DISABLED,
39+
mtlsRequestCert: false,
40+
allowSelfSigned: true,
41+
};
42+
43+
configStub = sinon.stub(configModule, 'config').returns(cfg);
44+
45+
// app setup
46+
app = enclavedApp(cfg);
47+
agent = request.agent(app);
48+
});
49+
50+
afterEach(() => {
51+
nock.cleanAll();
52+
});
53+
54+
after(() => {
55+
configStub.restore();
56+
});
57+
58+
// test cases
59+
it('should post an independent key successfully', async () => {
60+
const mockKmsResponse = {
61+
coin: coin,
62+
pub: 'xpub661MyMwAqRbcGAEfZmG74QD11P4dCKRkuwpsJG87QKVPcMdA1PLe76de1Ted54rZ2gyqLYhmdhBCFMrt7AoVwPZwXa3Na9aUnvndvXbvmwu',
63+
source: 'user',
64+
type: 'independent',
65+
};
66+
67+
const kmsNock = nock(kmsUrl).post(`/key`).reply(200, mockKmsResponse);
68+
69+
console.log(cfg.kmsUrl);
70+
71+
console.warn(nock.activeMocks());
72+
console.warn(nock.isActive());
73+
74+
const response = await agent
75+
.post(`/api/${coin}/key/independent`)
76+
.set('Authorization', `Bearer ${accessToken}`)
77+
.send({ source: 'user' });
78+
79+
response.status.should.equal(200);
80+
response.body.should.have.property('pub', mockKmsResponse.pub);
81+
response.body.should.have.property('coin', mockKmsResponse.coin);
82+
response.body.should.have.property('source', mockKmsResponse.source);
83+
84+
kmsNock.done();
85+
});
86+
});
Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
import 'should';
2+
3+
import * as request from 'supertest';
4+
import nock from 'nock';
5+
import { app as enclavedApp } from '../enclavedApp';
6+
import { AppMode, EnclavedConfig, TlsMode } from '../types';
7+
import express from 'express';
8+
9+
import * as sinon from 'sinon';
10+
import * as configModule from '../initConfig';
11+
12+
describe('signMultisigTransaction', () => {
13+
let cfg: EnclavedConfig;
14+
let app: express.Application;
15+
let agent: request.SuperAgentTest;
16+
17+
// test cofig
18+
const kmsUrl = 'http://kms.invalid';
19+
const coin = 'hteth';
20+
const accessToken = 'test-token';
21+
22+
// sinon stubs
23+
let configStub: sinon.SinonStub;
24+
25+
before(() => {
26+
// nock config
27+
nock.disableNetConnect();
28+
nock.enableNetConnect('127.0.0.1');
29+
30+
// app config
31+
cfg = {
32+
appMode: AppMode.ENCLAVED,
33+
port: 0, // Let OS assign a free port
34+
bind: 'localhost',
35+
timeout: 60000,
36+
logFile: '',
37+
kmsUrl: kmsUrl,
38+
tlsMode: TlsMode.DISABLED,
39+
mtlsRequestCert: false,
40+
allowSelfSigned: true,
41+
};
42+
43+
configStub = sinon.stub(configModule, 'config').returns(cfg);
44+
45+
// app setup
46+
app = enclavedApp(cfg);
47+
agent = request.agent(app);
48+
});
49+
50+
afterEach(() => {
51+
nock.cleanAll();
52+
});
53+
54+
after(() => {
55+
configStub.restore();
56+
});
57+
58+
// test cases
59+
it('should half-sign a multisig transaction successfully', async () => {
60+
const input = {
61+
source: 'user',
62+
pub: 'xpub661MyMwAqRbcGAEfZmG74QD11P4dCKRkuwpsJG87QKVPcMdA1PLe76de1Ted54rZ2gyqLYhmdhBCFMrt7AoVwPZwXa3Na9aUnvndvXbvmwu',
63+
txPrebuild: {
64+
feeInfo: {
65+
date: '2025-06-11T16:35:04.622Z',
66+
gasPrice: '11610471836',
67+
baseFee: '11478770445',
68+
gasUsedRatio: '0.9999833170418686',
69+
safeLowMinerTip: '521229555',
70+
normalMinerTip: '521229555',
71+
standardMinerTip: '521229555',
72+
fastestMinerTip: '521229555',
73+
ludicrousMinerTip: '550407891',
74+
},
75+
eip1559: { maxPriorityFeePerGas: '599413988', maxFeePerGas: '23556954878' },
76+
recipients: [
77+
{
78+
amount: '10000',
79+
address: '0xe9cbfdf9e02f4ee37ec81683a4be934b4eecc295',
80+
},
81+
],
82+
nextContractSequenceId: 5,
83+
gasLimit: 200000,
84+
isBatch: false,
85+
coin: 'hteth',
86+
walletId: '68489ecff6fb16304670b327db8eb31a',
87+
walletContractAddress: '0xe9cbfdf9e02f4ee37ec81683a4be934b4eecc295',
88+
reqId: {}, // modified
89+
wallet: {
90+
// modified
91+
bitgo: {},
92+
baseCoin: {},
93+
_wallet: {},
94+
},
95+
buildParams: {},
96+
},
97+
};
98+
99+
const mockKmsResponse = {
100+
prv: 'xprv9s21ZrQH143K3gACTjj6hGGGTME8nrhuYiuGVsiVqyxQjZJ1Tr2PZJKAABHLm2gMSwqRmXBXT8VcXppDy43xjwvt9xdgkDSyRPsBUekEaPq',
101+
pub: 'xpub661MyMwAqRbcGAEfZmG74QD11P4dCKRkuwpsJG87QKVPcMdA1PLe76de1Ted54rZ2gyqLYhmdhBCFMrt7AoVwPZwXa3Na9aUnvndvXbvmwu',
102+
source: 'user',
103+
type: 'independent',
104+
};
105+
106+
const kmsNock = nock(kmsUrl)
107+
.get(`/key/${input.pub}`)
108+
.query({ source: 'user' })
109+
.reply(200, mockKmsResponse);
110+
111+
const response = await agent
112+
.post(`/api/${coin}/multisig/sign`)
113+
.set('Authorization', `Bearer ${accessToken}`)
114+
.query({ source: input.source })
115+
.send(input);
116+
117+
response.status.should.equal(200);
118+
response.body.should.have.property('halfSigned');
119+
120+
kmsNock.done();
121+
});
122+
123+
// it('should half-sign a multisig transaction successfully', async () => {
124+
// const input = {
125+
// source: 'user',
126+
// };
127+
128+
// const mockKmsResponse = {
129+
// coin: coin,
130+
// pub: 'xpub661MyMwAqRbcGAEfZmG74QD11P4dCKRkuwpsJG87QKVPcMdA1PLe76de1Ted54rZ2gyqLYhmdhBCFMrt7AoVwPZwXa3Na9aUnvndvXbvmwu',
131+
// source: 'user',
132+
// type: 'independent',
133+
// };
134+
135+
// const kmsNock = nock(kmsUrl)
136+
// .get(`/key/${}`)
137+
// .matchHeader('any', () => true)
138+
// .reply(200, mockKmsResponse)
139+
// .persist();
140+
141+
// const response = await agent
142+
// .post(`/api/${coin}/key/independent`)
143+
// .set('Authorization', `Bearer ${accessToken}`)
144+
// .query({ source: input.source })
145+
// .send(input);
146+
147+
// response.status.should.equal(200);
148+
149+
// kmsNock.done();
150+
// });
151+
});

0 commit comments

Comments
 (0)