Skip to content

Commit b1caf30

Browse files
committed
test(master-express): add missing keychain nocks for walletPubs fetch
The new walletPubs logic fetches all 3 keychains after getWalletAndSigningKeychain. Tests using nock.disableNetConnect() were missing mocks for the backup and bitgo keychain requests, causing 500s in all success-path tests. Ticket: WCN-447 Session-Id: 79c78e55-7d60-4e54-b656-da465c33eb23 Task-Id: 7abc45de-23d0-4914-8dad-885882f82710
1 parent cdc62c2 commit b1caf30

2 files changed

Lines changed: 150 additions & 0 deletions

File tree

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

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,26 @@ describe('POST /api/v1/:coin/advancedwallet/:walletId/accelerate', () => {
7474
.matchHeader('authorization', `Bearer ${accessToken}`)
7575
.reply(200, mockWalletData);
7676

77+
// Signing keychain fetched by getWalletAndSigningKeychain
7778
const keychainGetNock = nock(bitgoApiUrl)
7879
.get(`/api/v2/${coin}/key/user-key-id`)
7980
.matchHeader('authorization', `Bearer ${accessToken}`)
8081
.reply(200, mockUserKeychain);
8182

83+
// All 3 keychains fetched for walletPubs
84+
nock(bitgoApiUrl)
85+
.get(`/api/v2/${coin}/key/user-key-id`)
86+
.matchHeader('authorization', `Bearer ${accessToken}`)
87+
.reply(200, mockUserKeychain);
88+
nock(bitgoApiUrl)
89+
.get(`/api/v2/${coin}/key/backup-key-id`)
90+
.matchHeader('authorization', `Bearer ${accessToken}`)
91+
.reply(200, mockBackupKeychain);
92+
nock(bitgoApiUrl)
93+
.get(`/api/v2/${coin}/key/bitgo-key-id`)
94+
.matchHeader('authorization', `Bearer ${accessToken}`)
95+
.reply(200, mockBitgoKeychain);
96+
8297
const accelerateTransactionStub = sinon
8398
.stub(Wallet.prototype, 'accelerateTransaction')
8499
.resolves({
@@ -123,11 +138,26 @@ describe('POST /api/v1/:coin/advancedwallet/:walletId/accelerate', () => {
123138
.matchHeader('authorization', `Bearer ${accessToken}`)
124139
.reply(200, mockWalletData);
125140

141+
// Signing keychain fetched by getWalletAndSigningKeychain
126142
const keychainGetNock = nock(bitgoApiUrl)
127143
.get(`/api/v2/${coin}/key/backup-key-id`)
128144
.matchHeader('authorization', `Bearer ${accessToken}`)
129145
.reply(200, mockBackupKeychain);
130146

147+
// All 3 keychains fetched for walletPubs
148+
nock(bitgoApiUrl)
149+
.get(`/api/v2/${coin}/key/user-key-id`)
150+
.matchHeader('authorization', `Bearer ${accessToken}`)
151+
.reply(200, mockUserKeychain);
152+
nock(bitgoApiUrl)
153+
.get(`/api/v2/${coin}/key/backup-key-id`)
154+
.matchHeader('authorization', `Bearer ${accessToken}`)
155+
.reply(200, mockBackupKeychain);
156+
nock(bitgoApiUrl)
157+
.get(`/api/v2/${coin}/key/bitgo-key-id`)
158+
.matchHeader('authorization', `Bearer ${accessToken}`)
159+
.reply(200, mockBitgoKeychain);
160+
131161
const accelerateTransactionStub = sinon
132162
.stub(Wallet.prototype, 'accelerateTransaction')
133163
.resolves({
@@ -163,11 +193,26 @@ describe('POST /api/v1/:coin/advancedwallet/:walletId/accelerate', () => {
163193
.matchHeader('authorization', `Bearer ${accessToken}`)
164194
.reply(200, mockWalletData);
165195

196+
// Signing keychain fetched by getWalletAndSigningKeychain
166197
const keychainGetNock = nock(bitgoApiUrl)
167198
.get(`/api/v2/${coin}/key/user-key-id`)
168199
.matchHeader('authorization', `Bearer ${accessToken}`)
169200
.reply(200, mockUserKeychain);
170201

202+
// All 3 keychains fetched for walletPubs
203+
nock(bitgoApiUrl)
204+
.get(`/api/v2/${coin}/key/user-key-id`)
205+
.matchHeader('authorization', `Bearer ${accessToken}`)
206+
.reply(200, mockUserKeychain);
207+
nock(bitgoApiUrl)
208+
.get(`/api/v2/${coin}/key/backup-key-id`)
209+
.matchHeader('authorization', `Bearer ${accessToken}`)
210+
.reply(200, mockBackupKeychain);
211+
nock(bitgoApiUrl)
212+
.get(`/api/v2/${coin}/key/bitgo-key-id`)
213+
.matchHeader('authorization', `Bearer ${accessToken}`)
214+
.reply(200, mockBitgoKeychain);
215+
171216
const accelerateTransactionStub = sinon
172217
.stub(Wallet.prototype, 'accelerateTransaction')
173218
.resolves({
@@ -330,11 +375,26 @@ describe('POST /api/v1/:coin/advancedwallet/:walletId/accelerate', () => {
330375
.matchHeader('authorization', `Bearer ${accessToken}`)
331376
.reply(200, mockWalletData);
332377

378+
// Signing keychain fetched by getWalletAndSigningKeychain
333379
const keychainGetNock = nock(bitgoApiUrl)
334380
.get(`/api/v2/${coin}/key/user-key-id`)
335381
.matchHeader('authorization', `Bearer ${accessToken}`)
336382
.reply(200, mockUserKeychain);
337383

384+
// All 3 keychains fetched for walletPubs
385+
nock(bitgoApiUrl)
386+
.get(`/api/v2/${coin}/key/user-key-id`)
387+
.matchHeader('authorization', `Bearer ${accessToken}`)
388+
.reply(200, mockUserKeychain);
389+
nock(bitgoApiUrl)
390+
.get(`/api/v2/${coin}/key/backup-key-id`)
391+
.matchHeader('authorization', `Bearer ${accessToken}`)
392+
.reply(200, mockBackupKeychain);
393+
nock(bitgoApiUrl)
394+
.get(`/api/v2/${coin}/key/bitgo-key-id`)
395+
.matchHeader('authorization', `Bearer ${accessToken}`)
396+
.reply(200, mockBitgoKeychain);
397+
338398
const accelerateTransactionStub = sinon
339399
.stub(Wallet.prototype, 'accelerateTransaction')
340400
.rejects(new Error('Insufficient funds for acceleration'));

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

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,26 @@ describe('POST /api/v1/:coin/advancedwallet/:walletId/consolidateunspents', () =
7474
.matchHeader('authorization', `Bearer ${accessToken}`)
7575
.reply(200, mockWalletData);
7676

77+
// Signing keychain fetched by getWalletAndSigningKeychain
7778
const keychainGetNock = nock(bitgoApiUrl)
7879
.get(`/api/v2/${coin}/key/user-key-id`)
7980
.matchHeader('authorization', `Bearer ${accessToken}`)
8081
.reply(200, mockUserKeychain);
8182

83+
// All 3 keychains fetched for walletPubs
84+
nock(bitgoApiUrl)
85+
.get(`/api/v2/${coin}/key/user-key-id`)
86+
.matchHeader('authorization', `Bearer ${accessToken}`)
87+
.reply(200, mockUserKeychain);
88+
nock(bitgoApiUrl)
89+
.get(`/api/v2/${coin}/key/backup-key-id`)
90+
.matchHeader('authorization', `Bearer ${accessToken}`)
91+
.reply(200, mockBackupKeychain);
92+
nock(bitgoApiUrl)
93+
.get(`/api/v2/${coin}/key/bitgo-key-id`)
94+
.matchHeader('authorization', `Bearer ${accessToken}`)
95+
.reply(200, mockBitgoKeychain);
96+
8297
const mockResult = {
8398
transfer: {
8499
entries: [
@@ -141,11 +156,26 @@ describe('POST /api/v1/:coin/advancedwallet/:walletId/consolidateunspents', () =
141156
.matchHeader('authorization', `Bearer ${accessToken}`)
142157
.reply(200, mockWalletData);
143158

159+
// Signing keychain fetched by getWalletAndSigningKeychain
144160
const keychainGetNock = nock(bitgoApiUrl)
145161
.get(`/api/v2/${coin}/key/backup-key-id`)
146162
.matchHeader('authorization', `Bearer ${accessToken}`)
147163
.reply(200, mockBackupKeychain);
148164

165+
// All 3 keychains fetched for walletPubs
166+
nock(bitgoApiUrl)
167+
.get(`/api/v2/${coin}/key/user-key-id`)
168+
.matchHeader('authorization', `Bearer ${accessToken}`)
169+
.reply(200, mockUserKeychain);
170+
nock(bitgoApiUrl)
171+
.get(`/api/v2/${coin}/key/backup-key-id`)
172+
.matchHeader('authorization', `Bearer ${accessToken}`)
173+
.reply(200, mockBackupKeychain);
174+
nock(bitgoApiUrl)
175+
.get(`/api/v2/${coin}/key/bitgo-key-id`)
176+
.matchHeader('authorization', `Bearer ${accessToken}`)
177+
.reply(200, mockBitgoKeychain);
178+
149179
const mockResult = {
150180
txid: 'backup-consolidation-tx-id',
151181
tx: '01000000000102backup...',
@@ -184,11 +214,26 @@ describe('POST /api/v1/:coin/advancedwallet/:walletId/consolidateunspents', () =
184214
.matchHeader('authorization', `Bearer ${accessToken}`)
185215
.reply(200, mockWalletData);
186216

217+
// Signing keychain fetched by getWalletAndSigningKeychain
187218
const keychainGetNock = nock(bitgoApiUrl)
188219
.get(`/api/v2/${coin}/key/user-key-id`)
189220
.matchHeader('authorization', `Bearer ${accessToken}`)
190221
.reply(200, mockUserKeychain);
191222

223+
// All 3 keychains fetched for walletPubs
224+
nock(bitgoApiUrl)
225+
.get(`/api/v2/${coin}/key/user-key-id`)
226+
.matchHeader('authorization', `Bearer ${accessToken}`)
227+
.reply(200, mockUserKeychain);
228+
nock(bitgoApiUrl)
229+
.get(`/api/v2/${coin}/key/backup-key-id`)
230+
.matchHeader('authorization', `Bearer ${accessToken}`)
231+
.reply(200, mockBackupKeychain);
232+
nock(bitgoApiUrl)
233+
.get(`/api/v2/${coin}/key/bitgo-key-id`)
234+
.matchHeader('authorization', `Bearer ${accessToken}`)
235+
.reply(200, mockBitgoKeychain);
236+
192237
const mockArrayResult = [
193238
{
194239
transfer: {
@@ -247,11 +292,26 @@ describe('POST /api/v1/:coin/advancedwallet/:walletId/consolidateunspents', () =
247292
.matchHeader('authorization', `Bearer ${accessToken}`)
248293
.reply(200, mockWalletData);
249294

295+
// Signing keychain fetched by getWalletAndSigningKeychain
250296
const keychainGetNock = nock(bitgoApiUrl)
251297
.get(`/api/v2/${coin}/key/user-key-id`)
252298
.matchHeader('authorization', `Bearer ${accessToken}`)
253299
.reply(200, mockUserKeychain);
254300

301+
// All 3 keychains fetched for walletPubs
302+
nock(bitgoApiUrl)
303+
.get(`/api/v2/${coin}/key/user-key-id`)
304+
.matchHeader('authorization', `Bearer ${accessToken}`)
305+
.reply(200, mockUserKeychain);
306+
nock(bitgoApiUrl)
307+
.get(`/api/v2/${coin}/key/backup-key-id`)
308+
.matchHeader('authorization', `Bearer ${accessToken}`)
309+
.reply(200, mockBackupKeychain);
310+
nock(bitgoApiUrl)
311+
.get(`/api/v2/${coin}/key/bitgo-key-id`)
312+
.matchHeader('authorization', `Bearer ${accessToken}`)
313+
.reply(200, mockBitgoKeychain);
314+
255315
const mockArrayResult = [
256316
{
257317
txid: 'first-tx-id',
@@ -299,11 +359,26 @@ describe('POST /api/v1/:coin/advancedwallet/:walletId/consolidateunspents', () =
299359
.matchHeader('authorization', `Bearer ${accessToken}`)
300360
.reply(200, mockWalletData);
301361

362+
// Signing keychain fetched by getWalletAndSigningKeychain
302363
const keychainGetNock = nock(bitgoApiUrl)
303364
.get(`/api/v2/${coin}/key/user-key-id`)
304365
.matchHeader('authorization', `Bearer ${accessToken}`)
305366
.reply(200, mockUserKeychain);
306367

368+
// All 3 keychains fetched for walletPubs
369+
nock(bitgoApiUrl)
370+
.get(`/api/v2/${coin}/key/user-key-id`)
371+
.matchHeader('authorization', `Bearer ${accessToken}`)
372+
.reply(200, mockUserKeychain);
373+
nock(bitgoApiUrl)
374+
.get(`/api/v2/${coin}/key/backup-key-id`)
375+
.matchHeader('authorization', `Bearer ${accessToken}`)
376+
.reply(200, mockBackupKeychain);
377+
nock(bitgoApiUrl)
378+
.get(`/api/v2/${coin}/key/bitgo-key-id`)
379+
.matchHeader('authorization', `Bearer ${accessToken}`)
380+
.reply(200, mockBitgoKeychain);
381+
307382
const mockResult = {
308383
txid: 'full-params-consolidation-tx-id',
309384
tx: '01000000000102full...',
@@ -478,11 +553,26 @@ describe('POST /api/v1/:coin/advancedwallet/:walletId/consolidateunspents', () =
478553
.matchHeader('authorization', `Bearer ${accessToken}`)
479554
.reply(200, mockWalletData);
480555

556+
// Signing keychain fetched by getWalletAndSigningKeychain
481557
const keychainGetNock = nock(bitgoApiUrl)
482558
.get(`/api/v2/${coin}/key/user-key-id`)
483559
.matchHeader('authorization', `Bearer ${accessToken}`)
484560
.reply(200, mockUserKeychain);
485561

562+
// All 3 keychains fetched for walletPubs
563+
nock(bitgoApiUrl)
564+
.get(`/api/v2/${coin}/key/user-key-id`)
565+
.matchHeader('authorization', `Bearer ${accessToken}`)
566+
.reply(200, mockUserKeychain);
567+
nock(bitgoApiUrl)
568+
.get(`/api/v2/${coin}/key/backup-key-id`)
569+
.matchHeader('authorization', `Bearer ${accessToken}`)
570+
.reply(200, mockBackupKeychain);
571+
nock(bitgoApiUrl)
572+
.get(`/api/v2/${coin}/key/bitgo-key-id`)
573+
.matchHeader('authorization', `Bearer ${accessToken}`)
574+
.reply(200, mockBitgoKeychain);
575+
486576
const consolidateUnspentsStub = sinon
487577
.stub(Wallet.prototype, 'consolidateUnspents')
488578
.rejects(new Error('No unspents available for consolidation'));

0 commit comments

Comments
 (0)