Skip to content

Commit 54140af

Browse files
committed
refactor: improve nocks in signAndSendTxRequest tests
Ticket: WAL-1489
1 parent f966dfd commit 54140af

1 file changed

Lines changed: 19 additions & 5 deletions

File tree

src/__tests__/api/master/signAndSendTxRequest.test.ts

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ describe('POST /api/v1/:coin/advancedwallet/:walletId/txrequest/:txRequestId/sig
5757
});
5858

5959
function nockWalletAndSigningKeychain(coinName: string) {
60-
nock(bitgoApiUrl)
60+
const walletNock = nock(bitgoApiUrl)
6161
.get(`/api/v2/${coinName}/wallet/${walletId}`)
6262
.matchHeader('any', () => true)
6363
.reply(200, {
@@ -68,7 +68,7 @@ describe('POST /api/v1/:coin/advancedwallet/:walletId/txrequest/:txRequestId/sig
6868
coin: coinName,
6969
});
7070

71-
nock(bitgoApiUrl)
71+
const keychainNock = nock(bitgoApiUrl)
7272
.get(`/api/v2/${coinName}/key/user-key-id`)
7373
.matchHeader('any', () => true)
7474
.reply(200, {
@@ -77,11 +77,13 @@ describe('POST /api/v1/:coin/advancedwallet/:walletId/txrequest/:txRequestId/sig
7777
commonKeychain: 'common-keychain-123',
7878
source: 'user',
7979
});
80+
81+
return { walletNock, keychainNock };
8082
}
8183

8284
describe('ECDSA MPCv2 Sign and Send:', () => {
8385
it('should successfully sign and send ECDSA MPCv2 transaction with user key', async () => {
84-
nockWalletAndSigningKeychain(coin);
86+
const { walletNock, keychainNock } = nockWalletAndSigningKeychain(coin);
8587

8688
const getTxRequestNock = nock(bitgoApiUrl)
8789
.get(`/api/v2/wallet/${walletId}/txrequests`)
@@ -117,6 +119,8 @@ describe('POST /api/v1/:coin/advancedwallet/:walletId/txrequest/:txRequestId/sig
117119
response.body.should.have.property('txid', 'test-tx-id');
118120
response.body.should.have.property('tx', 'signed-transaction-hex');
119121

122+
walletNock.done();
123+
keychainNock.done();
120124
getTxRequestNock.done();
121125
nocks.round1SignNock.done();
122126
nocks.round2SignNock.done();
@@ -128,7 +132,7 @@ describe('POST /api/v1/:coin/advancedwallet/:walletId/txrequest/:txRequestId/sig
128132
});
129133

130134
it('should handle pending approval response', async () => {
131-
nockWalletAndSigningKeychain(coin);
135+
const { walletNock, keychainNock } = nockWalletAndSigningKeychain(coin);
132136

133137
const getTxRequestNock = nock(bitgoApiUrl)
134138
.get(`/api/v2/wallet/${walletId}/txrequests`)
@@ -168,8 +172,16 @@ describe('POST /api/v1/:coin/advancedwallet/:walletId/txrequest/:txRequestId/sig
168172
response.body.should.have.property('txRequest');
169173
response.body.pendingApproval.should.have.property('id', 'pending-approval-id');
170174

175+
walletNock.done();
176+
keychainNock.done();
171177
getTxRequestNock.done();
178+
nocks.round1SignNock.done();
179+
nocks.round2SignNock.done();
180+
nocks.round3SignNock.done();
172181
nocks.sendTxNock.done();
182+
nocks.awmRound1Nock.done();
183+
nocks.awmRound2Nock.done();
184+
nocks.awmRound3Nock.done();
173185
pendingApprovalNock.done();
174186
});
175187
});
@@ -219,7 +231,7 @@ describe('POST /api/v1/:coin/advancedwallet/:walletId/txrequest/:txRequestId/sig
219231
],
220232
};
221233

222-
nockWalletAndSigningKeychain(eddsaCoin);
234+
const { walletNock, keychainNock } = nockWalletAndSigningKeychain(eddsaCoin);
223235

224236
// pickBitgoPubGpgKeyForSigning resolves the BitGo GPG key from the keychain hsmType
225237
nock(bitgoApiUrl)
@@ -305,6 +317,8 @@ describe('POST /api/v1/:coin/advancedwallet/:walletId/txrequest/:txRequestId/sig
305317
response.body.should.have.property('txid', 'test-tx-id');
306318
response.body.should.have.property('tx', 'signed-transaction-hex');
307319

320+
walletNock.done();
321+
keychainNock.done();
308322
handlerGetTxRequestNock.done();
309323
exchangeCommitmentsNock.done();
310324
offerRShareNock.done();

0 commit comments

Comments
 (0)