Skip to content

Commit 86ef8bf

Browse files
feat(awm): fixing test suite
Ticket: WCN-363
1 parent 1fbe141 commit 86ef8bf

3 files changed

Lines changed: 36 additions & 39 deletions

File tree

src/__tests__/api/advancedWalletManager/postMpcV2Key.test.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ describe('postMpcV2Key', () => {
2121
const coin = 'hteth';
2222
const accessToken = 'test-token';
2323

24-
// sinon stubs
24+
// sinon sandbox
25+
const sandbox = sinon.createSandbox();
2526
let configStub: sinon.SinonStub;
2627

2728
before(() => {
@@ -42,11 +43,7 @@ describe('postMpcV2Key', () => {
4243
clientCertAllowSelfSigned: true,
4344
};
4445

45-
// Restore any existing stub from other test suites before re-stubbing
46-
if (typeof (configModule.initConfig as any).restore === 'function') {
47-
(configModule.initConfig as any).restore();
48-
}
49-
configStub = sinon.stub(configModule, 'initConfig').returns(cfg);
46+
configStub = sandbox.stub(configModule, 'initConfig').returns(cfg);
5047

5148
// app setup
5249
app = advancedWalletManagerApp(cfg);
@@ -97,7 +94,7 @@ describe('postMpcV2Key', () => {
9794
});
9895

9996
after(() => {
100-
configStub?.restore();
97+
sandbox.restore();
10198
});
10299

103100
it('should be able to create a new MPC V2 wallet', async () => {

src/__tests__/api/advancedWalletManager/recoveryMpcV2.test.ts

Lines changed: 32 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import * as sinon from 'sinon';
99
import * as configModule from '../../../initConfig';
1010
import { DklsTypes, DklsUtils } from '@bitgo-beta/sdk-lib-mpc';
1111

12-
describe('recoveryMpcV2', async () => {
12+
describe('recoveryMpcV2', () => {
1313
let cfg: AdvancedWalletManagerConfig;
1414
let app: express.Application;
1515
let agent: request.SuperAgentTest;
@@ -25,31 +25,39 @@ describe('recoveryMpcV2', async () => {
2525
let configStub: sinon.SinonStub;
2626

2727
// key provider nocks setup
28-
const [userShare, backupShare] = await DklsUtils.generateDKGKeyShares();
29-
const userKeyShare = userShare.getKeyShare().toString('base64');
30-
const backupKeyShare = backupShare.getKeyShare().toString('base64');
31-
const commonKeychain = DklsTypes.getCommonKeychain(userShare.getKeyShare());
32-
33-
const mockKeyProviderUserResponse = {
34-
prv: JSON.stringify(userKeyShare),
35-
pub: commonKeychain,
36-
source: 'user',
37-
type: 'tss',
38-
};
39-
40-
const mockKeyProviderBackupResponse = {
41-
prv: JSON.stringify(backupKeyShare),
42-
pub: commonKeychain,
43-
source: 'backup',
44-
type: 'tss',
45-
};
46-
const input = {
47-
txHex:
48-
'02f6824268018502540be4008504a817c80083030d409443442e403d64d29c4f64065d0c1a0e8edc03d6c88801550f7dca700000823078c0',
49-
pub: commonKeychain,
50-
};
28+
let userKeyShare: string;
29+
let backupKeyShare: string;
30+
let commonKeychain: string;
31+
let mockKeyProviderUserResponse: { prv: string; pub: string; source: string; type: string };
32+
let mockKeyProviderBackupResponse: { prv: string; pub: string; source: string; type: string };
33+
let input: { txHex: string; pub: string };
5134

5235
before(async () => {
36+
const [userShare, backupShare] = await DklsUtils.generateDKGKeyShares();
37+
userKeyShare = userShare.getKeyShare().toString('base64');
38+
backupKeyShare = backupShare.getKeyShare().toString('base64');
39+
commonKeychain = DklsTypes.getCommonKeychain(userShare.getKeyShare());
40+
41+
mockKeyProviderUserResponse = {
42+
prv: JSON.stringify(userKeyShare),
43+
pub: commonKeychain,
44+
source: 'user',
45+
type: 'tss',
46+
};
47+
48+
mockKeyProviderBackupResponse = {
49+
prv: JSON.stringify(backupKeyShare),
50+
pub: commonKeychain,
51+
source: 'backup',
52+
type: 'tss',
53+
};
54+
55+
input = {
56+
txHex:
57+
'02f6824268018502540be4008504a817c80083030d409443442e403d64d29c4f64065d0c1a0e8edc03d6c88801550f7dca700000823078c0',
58+
pub: commonKeychain,
59+
};
60+
5361
// nock config
5462
nock.disableNetConnect();
5563
nock.enableNetConnect('127.0.0.1');
@@ -68,10 +76,6 @@ describe('recoveryMpcV2', async () => {
6876
recoveryMode: true,
6977
};
7078

71-
// Restore any existing stub from other test suites before re-stubbing
72-
if (typeof (configModule.initConfig as any).restore === 'function') {
73-
(configModule.initConfig as any).restore();
74-
}
7579
configStub = sandbox.stub(configModule, 'initConfig').returns(cfg);
7680

7781
// app setup

src/__tests__/api/advancedWalletManager/recoveryMusigEth.test.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,6 @@ describe('recoveryMultisigTransaction', () => {
4545
recoveryMode: true,
4646
};
4747

48-
// Restore any existing stub from other test suites before re-stubbing
49-
if (typeof (configModule.initConfig as any).restore === 'function') {
50-
(configModule.initConfig as any).restore();
51-
}
5248
configStub = sandbox.stub(configModule, 'initConfig').returns(cfg);
5349

5450
// app setup

0 commit comments

Comments
 (0)