@bitpay-labs/bitcore-wallet-service 11.11.0 → 11.11.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (157) hide show
  1. package/Dockerfile +1 -1
  2. package/package.json +5 -5
  3. package/src/config.ts +0 -20
  4. package/src/externalservices/banxa.ts +51 -10
  5. package/src/externalservices/changelly.ts +54 -6
  6. package/src/externalservices/moonpay.ts +85 -19
  7. package/src/externalservices/oneInch.ts +13 -5
  8. package/src/externalservices/ramp.ts +42 -8
  9. package/src/externalservices/sardine.ts +51 -10
  10. package/src/externalservices/simplex.ts +58 -11
  11. package/src/externalservices/thorswap.ts +46 -11
  12. package/src/externalservices/transak.ts +53 -11
  13. package/src/lib/chain/btc/index.ts +3 -2
  14. package/src/lib/chain/eth/index.ts +134 -117
  15. package/src/lib/chain/sol/index.ts +1 -1
  16. package/src/lib/chain/xrp/index.ts +1 -1
  17. package/src/lib/routes/services.ts +0 -12
  18. package/src/lib/routes/wallets.ts +3 -1
  19. package/src/lib/server.ts +136 -91
  20. package/src/lib/storage.ts +90 -20
  21. package/src/types/externalservices.d.ts +0 -1
  22. package/test/chain/eth.test.ts +70 -0
  23. package/test/chain/sol.test.ts +1 -1
  24. package/test/chain/xrp.test.ts +1 -1
  25. package/test/expressapp.test.ts +144 -0
  26. package/test/integration/addressReads.test.ts +503 -0
  27. package/test/integration/bcmonitor.test.ts +44 -0
  28. package/test/integration/externalservices/banxa.test.ts +95 -5
  29. package/test/integration/externalservices/changelly.test.ts +118 -6
  30. package/test/integration/externalservices/coinGecko.test.ts +4 -0
  31. package/test/integration/externalservices/moonpay.test.ts +178 -9
  32. package/test/integration/externalservices/oneInch.test.ts +28 -1
  33. package/test/integration/externalservices/ramp.test.ts +126 -4
  34. package/test/integration/externalservices/sardine.test.ts +95 -5
  35. package/test/integration/externalservices/simplex.test.ts +95 -5
  36. package/test/integration/externalservices/thorswap.test.ts +81 -5
  37. package/test/integration/externalservices/transak.test.ts +98 -6
  38. package/test/integration/helpers.ts +1 -1
  39. package/test/integration/server.test.ts +254 -136
  40. package/test/integration/walletReads.test.ts +488 -0
  41. package/ts_build/package.json +3 -3
  42. package/ts_build/src/config.d.ts.map +1 -1
  43. package/ts_build/src/config.js +0 -4
  44. package/ts_build/src/config.js.map +1 -1
  45. package/ts_build/src/externalservices/banxa.d.ts.map +1 -1
  46. package/ts_build/src/externalservices/banxa.js +51 -10
  47. package/ts_build/src/externalservices/banxa.js.map +1 -1
  48. package/ts_build/src/externalservices/changelly.d.ts.map +1 -1
  49. package/ts_build/src/externalservices/changelly.js +54 -6
  50. package/ts_build/src/externalservices/changelly.js.map +1 -1
  51. package/ts_build/src/externalservices/moonpay.d.ts.map +1 -1
  52. package/ts_build/src/externalservices/moonpay.js +85 -19
  53. package/ts_build/src/externalservices/moonpay.js.map +1 -1
  54. package/ts_build/src/externalservices/oneInch.d.ts.map +1 -1
  55. package/ts_build/src/externalservices/oneInch.js +13 -5
  56. package/ts_build/src/externalservices/oneInch.js.map +1 -1
  57. package/ts_build/src/externalservices/ramp.d.ts.map +1 -1
  58. package/ts_build/src/externalservices/ramp.js +42 -8
  59. package/ts_build/src/externalservices/ramp.js.map +1 -1
  60. package/ts_build/src/externalservices/sardine.d.ts.map +1 -1
  61. package/ts_build/src/externalservices/sardine.js +51 -10
  62. package/ts_build/src/externalservices/sardine.js.map +1 -1
  63. package/ts_build/src/externalservices/simplex.d.ts.map +1 -1
  64. package/ts_build/src/externalservices/simplex.js +55 -11
  65. package/ts_build/src/externalservices/simplex.js.map +1 -1
  66. package/ts_build/src/externalservices/thorswap.d.ts.map +1 -1
  67. package/ts_build/src/externalservices/thorswap.js +45 -11
  68. package/ts_build/src/externalservices/thorswap.js.map +1 -1
  69. package/ts_build/src/externalservices/transak.d.ts.map +1 -1
  70. package/ts_build/src/externalservices/transak.js +53 -11
  71. package/ts_build/src/externalservices/transak.js.map +1 -1
  72. package/ts_build/src/lib/chain/btc/index.d.ts.map +1 -1
  73. package/ts_build/src/lib/chain/btc/index.js +3 -2
  74. package/ts_build/src/lib/chain/btc/index.js.map +1 -1
  75. package/ts_build/src/lib/chain/eth/index.d.ts +8 -1
  76. package/ts_build/src/lib/chain/eth/index.d.ts.map +1 -1
  77. package/ts_build/src/lib/chain/eth/index.js +114 -102
  78. package/ts_build/src/lib/chain/eth/index.js.map +1 -1
  79. package/ts_build/src/lib/chain/sol/index.js +1 -1
  80. package/ts_build/src/lib/chain/sol/index.js.map +1 -1
  81. package/ts_build/src/lib/chain/xrp/index.js +1 -1
  82. package/ts_build/src/lib/chain/xrp/index.js.map +1 -1
  83. package/ts_build/src/lib/routes/services.d.ts.map +1 -1
  84. package/ts_build/src/lib/routes/services.js +0 -10
  85. package/ts_build/src/lib/routes/services.js.map +1 -1
  86. package/ts_build/src/lib/routes/wallets.d.ts.map +1 -1
  87. package/ts_build/src/lib/routes/wallets.js +2 -1
  88. package/ts_build/src/lib/routes/wallets.js.map +1 -1
  89. package/ts_build/src/lib/server.d.ts +1 -3
  90. package/ts_build/src/lib/server.d.ts.map +1 -1
  91. package/ts_build/src/lib/server.js +128 -96
  92. package/ts_build/src/lib/server.js.map +1 -1
  93. package/ts_build/src/lib/storage.d.ts +17 -10
  94. package/ts_build/src/lib/storage.d.ts.map +1 -1
  95. package/ts_build/src/lib/storage.js +73 -20
  96. package/ts_build/src/lib/storage.js.map +1 -1
  97. package/ts_build/test/chain/eth.test.js +59 -0
  98. package/ts_build/test/chain/eth.test.js.map +1 -1
  99. package/ts_build/test/chain/sol.test.js +1 -1
  100. package/ts_build/test/chain/sol.test.js.map +1 -1
  101. package/ts_build/test/chain/xrp.test.js +1 -1
  102. package/ts_build/test/chain/xrp.test.js.map +1 -1
  103. package/ts_build/test/expressapp.test.js +132 -0
  104. package/ts_build/test/expressapp.test.js.map +1 -1
  105. package/ts_build/test/integration/addressReads.test.d.ts +2 -0
  106. package/ts_build/test/integration/addressReads.test.d.ts.map +1 -0
  107. package/ts_build/test/integration/addressReads.test.js +465 -0
  108. package/ts_build/test/integration/addressReads.test.js.map +1 -0
  109. package/ts_build/test/integration/bcmonitor.test.js +40 -0
  110. package/ts_build/test/integration/bcmonitor.test.js.map +1 -1
  111. package/ts_build/test/integration/externalservices/banxa.test.d.ts.map +1 -1
  112. package/ts_build/test/integration/externalservices/banxa.test.js +93 -5
  113. package/ts_build/test/integration/externalservices/banxa.test.js.map +1 -1
  114. package/ts_build/test/integration/externalservices/changelly.test.d.ts.map +1 -1
  115. package/ts_build/test/integration/externalservices/changelly.test.js +111 -6
  116. package/ts_build/test/integration/externalservices/changelly.test.js.map +1 -1
  117. package/ts_build/test/integration/externalservices/coinGecko.test.js +4 -0
  118. package/ts_build/test/integration/externalservices/coinGecko.test.js.map +1 -1
  119. package/ts_build/test/integration/externalservices/moonpay.test.d.ts.map +1 -1
  120. package/ts_build/test/integration/externalservices/moonpay.test.js +169 -9
  121. package/ts_build/test/integration/externalservices/moonpay.test.js.map +1 -1
  122. package/ts_build/test/integration/externalservices/oneInch.test.d.ts.map +1 -1
  123. package/ts_build/test/integration/externalservices/oneInch.test.js +26 -1
  124. package/ts_build/test/integration/externalservices/oneInch.test.js.map +1 -1
  125. package/ts_build/test/integration/externalservices/ramp.test.d.ts.map +1 -1
  126. package/ts_build/test/integration/externalservices/ramp.test.js +115 -4
  127. package/ts_build/test/integration/externalservices/ramp.test.js.map +1 -1
  128. package/ts_build/test/integration/externalservices/sardine.test.d.ts.map +1 -1
  129. package/ts_build/test/integration/externalservices/sardine.test.js +94 -5
  130. package/ts_build/test/integration/externalservices/sardine.test.js.map +1 -1
  131. package/ts_build/test/integration/externalservices/simplex.test.d.ts.map +1 -1
  132. package/ts_build/test/integration/externalservices/simplex.test.js +89 -5
  133. package/ts_build/test/integration/externalservices/simplex.test.js.map +1 -1
  134. package/ts_build/test/integration/externalservices/thorswap.test.d.ts.map +1 -1
  135. package/ts_build/test/integration/externalservices/thorswap.test.js +76 -5
  136. package/ts_build/test/integration/externalservices/thorswap.test.js.map +1 -1
  137. package/ts_build/test/integration/externalservices/transak.test.d.ts.map +1 -1
  138. package/ts_build/test/integration/externalservices/transak.test.js +93 -6
  139. package/ts_build/test/integration/externalservices/transak.test.js.map +1 -1
  140. package/ts_build/test/integration/helpers.js +1 -1
  141. package/ts_build/test/integration/helpers.js.map +1 -1
  142. package/ts_build/test/integration/server.test.js +225 -124
  143. package/ts_build/test/integration/server.test.js.map +1 -1
  144. package/ts_build/test/integration/walletReads.test.d.ts +2 -0
  145. package/ts_build/test/integration/walletReads.test.d.ts.map +1 -0
  146. package/ts_build/test/integration/walletReads.test.js +436 -0
  147. package/ts_build/test/integration/walletReads.test.js.map +1 -0
  148. package/src/externalservices/wyre.ts +0 -131
  149. package/test/integration/externalservices/wyre.test.ts +0 -270
  150. package/ts_build/src/externalservices/wyre.d.ts +0 -7
  151. package/ts_build/src/externalservices/wyre.d.ts.map +0 -1
  152. package/ts_build/src/externalservices/wyre.js +0 -144
  153. package/ts_build/src/externalservices/wyre.js.map +0 -1
  154. package/ts_build/test/integration/externalservices/wyre.test.d.ts +0 -2
  155. package/ts_build/test/integration/externalservices/wyre.test.d.ts.map +0 -1
  156. package/ts_build/test/integration/externalservices/wyre.test.js +0 -281
  157. package/ts_build/test/integration/externalservices/wyre.test.js.map +0 -1
@@ -1,20 +1,24 @@
1
1
  'use strict';
2
2
 
3
3
  import * as chai from 'chai';
4
+ import * as sinon from 'sinon';
4
5
  import 'chai/register-should';
5
6
  import util from 'util';
6
7
  import { WalletService } from '../../../src/lib/server';
7
8
  import * as TestData from '../../testdata';
8
9
  import helpers from '../helpers';
9
10
  import config from '../../../src/config';
11
+ import logger from '../../../src/lib/logger';
10
12
 
11
13
  const should = chai.should();
12
14
 
13
15
  describe('Banxa integration', () => {
16
+ const sandbox = sinon.createSandbox();
14
17
  let server;
15
18
  let wallet;
16
19
  let fakeRequest;
17
20
  let req;
21
+ let loggerError: sinon.SinonStub;
18
22
 
19
23
  before(async function() {
20
24
  await helpers.before();
@@ -63,6 +67,12 @@ describe('Banxa integration', () => {
63
67
  walletId: '123',
64
68
  });
65
69
  server = s;
70
+ sandbox.stub(logger, 'warn');
71
+ loggerError = sandbox.stub(logger, 'error');
72
+ });
73
+
74
+ afterEach(() => {
75
+ sandbox.restore();
66
76
  });
67
77
 
68
78
  after(async function() {
@@ -101,7 +111,23 @@ describe('Banxa integration', () => {
101
111
  await server.externalServices.banxa.banxaGetPaymentMethods(req);
102
112
  should.fail('should have thrown');
103
113
  } catch (err) {
104
- err.message.should.equal('Error');
114
+ loggerError.callCount.should.equal(1);
115
+ loggerError.args[0][0].should.contain('Banxa request failed with error (');
116
+ err.message.should.equal('Failed to fetch Banxa payment methods');
117
+ }
118
+ });
119
+
120
+ it('should return error and not leak the response if body is empty', async () => {
121
+ const fakeRequest2 = {
122
+ get: (_url, opts, cb) => { return cb(null, { statusCode: 200, body: undefined, request: { headers: opts.headers } }); },
123
+ };
124
+
125
+ server.externalServices.banxa.request = fakeRequest2;
126
+ try {
127
+ await server.externalServices.banxa.banxaGetPaymentMethods(req);
128
+ should.fail('should have thrown');
129
+ } catch (err) {
130
+ err.message.should.equal('Banxa did not return payment methods');
105
131
  }
106
132
  });
107
133
 
@@ -155,7 +181,23 @@ describe('Banxa integration', () => {
155
181
  await server.externalServices.banxa.banxaGetCoins(req);
156
182
  should.fail('should have thrown');
157
183
  } catch (err) {
158
- err.message.should.equal('Error');
184
+ loggerError.callCount.should.equal(1);
185
+ loggerError.args[0][0].should.contain('Banxa request failed with error (');
186
+ err.message.should.equal('Failed to fetch Banxa coins');
187
+ };
188
+ });
189
+
190
+ it('should return error and not leak the response if body is empty', async () => {
191
+ const fakeRequest2 = {
192
+ get: (_url, opts, cb) => { return cb(null, { statusCode: 200, body: undefined, request: { headers: opts.headers } }); },
193
+ };
194
+
195
+ server.externalServices.banxa.request = fakeRequest2;
196
+ try {
197
+ await server.externalServices.banxa.banxaGetCoins(req);
198
+ should.fail('should have thrown');
199
+ } catch (err) {
200
+ err.message.should.equal('Banxa did not return coins');
159
201
  };
160
202
  });
161
203
 
@@ -224,7 +266,23 @@ describe('Banxa integration', () => {
224
266
  await server.externalServices.banxa.banxaGetQuote(req);
225
267
  should.fail('should have thrown');
226
268
  } catch (err) {
227
- err.message.should.equal('Error');
269
+ loggerError.callCount.should.equal(1);
270
+ loggerError.args[0][0].should.contain('Banxa request failed with error (');
271
+ err.message.should.equal('Failed to fetch Banxa quote');
272
+ };
273
+ });
274
+
275
+ it('should return error and not leak the response if body is empty', async () => {
276
+ const fakeRequest2 = {
277
+ get: (_url, opts, cb) => { return cb(null, { statusCode: 200, body: undefined, request: { headers: opts.headers } }); },
278
+ };
279
+
280
+ server.externalServices.banxa.request = fakeRequest2;
281
+ try {
282
+ await server.externalServices.banxa.banxaGetQuote(req);
283
+ should.fail('should have thrown');
284
+ } catch (err) {
285
+ err.message.should.equal('Banxa did not return quote');
228
286
  };
229
287
  });
230
288
 
@@ -287,7 +345,23 @@ describe('Banxa integration', () => {
287
345
  await server.externalServices.banxa.banxaCreateOrder(req);
288
346
  should.fail('should have thrown');
289
347
  } catch (err) {
290
- err.message.should.equal('Error');
348
+ loggerError.callCount.should.equal(1);
349
+ loggerError.args[0][0].should.contain('Banxa request failed with error (');
350
+ err.message.should.equal('Failed to create Banxa order');
351
+ };
352
+ });
353
+
354
+ it('should return error and not leak the response if body is empty', async () => {
355
+ const fakeRequest2 = {
356
+ post: (_url, opts, cb) => { return cb(null, { statusCode: 200, body: undefined, request: { headers: opts.headers } }); },
357
+ };
358
+
359
+ server.externalServices.banxa.request = fakeRequest2;
360
+ try {
361
+ await server.externalServices.banxa.banxaCreateOrder(req);
362
+ should.fail('should have thrown');
363
+ } catch (err) {
364
+ err.message.should.equal('Banxa did not return order');
291
365
  };
292
366
  });
293
367
 
@@ -345,7 +419,23 @@ describe('Banxa integration', () => {
345
419
  await server.externalServices.banxa.banxaGetOrder(req);
346
420
  should.fail('should have thrown');
347
421
  } catch (err) {
348
- err.message.should.equal('Error');
422
+ loggerError.callCount.should.equal(1);
423
+ loggerError.args[0][0].should.contain('Banxa request failed with error (');
424
+ err.message.should.equal('Failed to get Banxa order');
425
+ };
426
+ });
427
+
428
+ it('should return error and not leak the response if body is empty', async () => {
429
+ const fakeRequest2 = {
430
+ get: (_url, opts, cb) => { return cb(null, { statusCode: 200, body: undefined, request: { headers: opts.headers } }); },
431
+ };
432
+
433
+ server.externalServices.banxa.request = fakeRequest2;
434
+ try {
435
+ await server.externalServices.banxa.banxaGetOrder(req);
436
+ should.fail('should have thrown');
437
+ } catch (err) {
438
+ err.message.should.equal('Banxa did not return order');
349
439
  };
350
440
  });
351
441
 
@@ -1,6 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  import * as chai from 'chai';
4
+ import * as sinon from 'sinon';
4
5
  import 'chai/register-should';
5
6
  import crypto from 'crypto';
6
7
  import util from 'util';
@@ -8,6 +9,7 @@ import { WalletService } from '../../../src/lib/server';
8
9
  import * as TestData from '../../testdata';
9
10
  import helpers from '../helpers';
10
11
  import config from '../../../src/config';
12
+ import logger from '../../../src/lib/logger';
11
13
 
12
14
  const should = chai.should();
13
15
 
@@ -24,10 +26,12 @@ const { publicKey, privateKey } = crypto.generateKeyPairSync('rsa', {
24
26
  });
25
27
 
26
28
  describe('Changelly integration', () => {
29
+ const sandbox = sinon.createSandbox();
27
30
  let server;
28
31
  let wallet;
29
32
  let fakeRequest;
30
33
  let req;
34
+ let loggerError: sinon.SinonStub;
31
35
 
32
36
  before(async () => {
33
37
  await helpers.before();
@@ -65,6 +69,12 @@ describe('Changelly integration', () => {
65
69
  clientVersion: 'bwc-2.0.0',
66
70
  walletId: '123',
67
71
  }));
72
+ sandbox.stub(logger, 'warn');
73
+ loggerError = sandbox.stub(logger, 'error');
74
+ });
75
+
76
+ afterEach(() => {
77
+ sandbox.restore();
68
78
  });
69
79
 
70
80
  after(async () => {
@@ -140,7 +150,24 @@ describe('Changelly integration', () => {
140
150
  await server.externalServices.changelly.changellyGetCurrencies(req);
141
151
  should.fail('should have thrown');
142
152
  } catch (err) {
143
- err.message.should.equal('Error');
153
+ loggerError.callCount.should.equal(1);
154
+ loggerError.args[0][0].should.contain('Changelly request failed with error (');
155
+ err.message.should.equal('Failed to fetch Changelly currencies');
156
+ }
157
+ });
158
+
159
+ it('should return error and not leak the response if body is empty', async () => {
160
+ req.body.id = 'test';
161
+ const fakeRequest2 = {
162
+ post: (_url, opts, cb) => { return cb(null, { statusCode: 200, body: undefined, request: { headers: opts.headers } }); },
163
+ };
164
+
165
+ server.externalServices.changelly.request = fakeRequest2;
166
+ try {
167
+ await server.externalServices.changelly.changellyGetCurrencies(req);
168
+ should.fail('should have thrown');
169
+ } catch (err) {
170
+ err.message.should.equal('Changelly did not return currencies');
144
171
  }
145
172
  });
146
173
 
@@ -212,7 +239,24 @@ describe('Changelly integration', () => {
212
239
  await server.externalServices.changelly.changellyGetPairsParams(req);
213
240
  should.fail('should have thrown');
214
241
  } catch (err) {
215
- err.message.should.equal('Error');
242
+ loggerError.callCount.should.equal(1);
243
+ loggerError.args[0][0].should.contain('Changelly request failed with error (');
244
+ err.message.should.equal('Failed to fetch Changelly pairs params');
245
+ }
246
+ });
247
+
248
+ it('should return error and not leak the response if body is empty', async () => {
249
+ req.body.coinFrom = 'btc';
250
+ const fakeRequest2 = {
251
+ post: (_url, opts, cb) => { return cb(null, { statusCode: 200, body: undefined, request: { headers: opts.headers } }); },
252
+ };
253
+
254
+ server.externalServices.changelly.request = fakeRequest2;
255
+ try {
256
+ await server.externalServices.changelly.changellyGetPairsParams(req);
257
+ should.fail('should have thrown');
258
+ } catch (err) {
259
+ err.message.should.equal('Changelly did not return pairs params');
216
260
  }
217
261
  });
218
262
 
@@ -284,7 +328,24 @@ describe('Changelly integration', () => {
284
328
  await server.externalServices.changelly.changellyGetFixRateForAmount(req);
285
329
  should.fail('should have thrown');
286
330
  } catch (err) {
287
- err.message.should.equal('Error');
331
+ loggerError.callCount.should.equal(1);
332
+ loggerError.args[0][0].should.contain('Changelly request failed with error (');
333
+ err.message.should.equal('Failed to fetch Changelly fix rate for amount');
334
+ }
335
+ });
336
+
337
+ it('should return error and not leak the response if body is empty', async () => {
338
+ req.body.coinFrom = 'btc';
339
+ const fakeRequest2 = {
340
+ post: (_url, opts, cb) => { return cb(null, { statusCode: 200, body: undefined, request: { headers: opts.headers } }); },
341
+ };
342
+
343
+ server.externalServices.changelly.request = fakeRequest2;
344
+ try {
345
+ await server.externalServices.changelly.changellyGetFixRateForAmount(req);
346
+ should.fail('should have thrown');
347
+ } catch (err) {
348
+ err.message.should.equal('Changelly did not return fix rate for amount');
288
349
  }
289
350
  });
290
351
 
@@ -355,7 +416,24 @@ describe('Changelly integration', () => {
355
416
  await server.externalServices.changelly.changellyCreateFixTransaction(req);
356
417
  should.fail('should have thrown');
357
418
  } catch (err) {
358
- err.message.should.equal('Error');
419
+ loggerError.callCount.should.equal(1);
420
+ loggerError.args[0][0].should.contain('Changelly request failed with error (');
421
+ err.message.should.equal('Failed to create Changelly fix transaction');
422
+ }
423
+ });
424
+
425
+ it('should return error and not leak the response if body is empty', async () => {
426
+ req.body.coinFrom = 'btc';
427
+ const fakeRequest2 = {
428
+ post: (_url, opts, cb) => { return cb(null, { statusCode: 200, body: undefined, request: { headers: opts.headers } }); },
429
+ };
430
+
431
+ server.externalServices.changelly.request = fakeRequest2;
432
+ try {
433
+ await server.externalServices.changelly.changellyCreateFixTransaction(req);
434
+ should.fail('should have thrown');
435
+ } catch (err) {
436
+ err.message.should.equal('Changelly did not return fix transaction');
359
437
  }
360
438
  });
361
439
 
@@ -421,7 +499,24 @@ describe('Changelly integration', () => {
421
499
  await server.externalServices.changelly.changellyGetTransactions(req);
422
500
  should.fail('should have thrown');
423
501
  } catch (err) {
424
- err.message.should.equal('Error');
502
+ loggerError.callCount.should.equal(1);
503
+ loggerError.args[0][0].should.contain('Changelly request failed with error (');
504
+ err.message.should.equal('Failed to get Changelly transactions');
505
+ }
506
+ });
507
+
508
+ it('should return error and not leak the response if body is empty', async() => {
509
+ req.body.exchangeTxId = 'exchangeTxId';
510
+ const fakeRequest2 = {
511
+ post: (_url, opts, cb) => { return cb(null, { statusCode: 200, body: undefined, request: { headers: opts.headers } }); },
512
+ };
513
+ server.externalServices.changelly.request = fakeRequest2;
514
+
515
+ try {
516
+ await server.externalServices.changelly.changellyGetTransactions(req);
517
+ should.fail('should have thrown');
518
+ } catch (err) {
519
+ err.message.should.equal('Changelly did not return transactions');
425
520
  }
426
521
  });
427
522
 
@@ -487,7 +582,24 @@ describe('Changelly integration', () => {
487
582
  await server.externalServices.changelly.changellyGetStatus(req);
488
583
  should.fail('should have thrown');
489
584
  } catch (err) {
490
- err.message.should.equal('Error');
585
+ loggerError.callCount.should.equal(1);
586
+ loggerError.args[0][0].should.contain('Changelly request failed with error (');
587
+ err.message.should.equal('Failed to get Changelly status');
588
+ }
589
+ });
590
+
591
+ it('should return error and not leak the response if body is empty', async () => {
592
+ req.body.exchangeTxId = 'exchangeTxId';
593
+ const fakeRequest2 = {
594
+ post: (_url, opts, cb) => { return cb(null, { statusCode: 200, body: undefined, request: { headers: opts.headers } }); },
595
+ };
596
+
597
+ server.externalServices.changelly.request = fakeRequest2;
598
+ try {
599
+ await server.externalServices.changelly.changellyGetStatus(req);
600
+ should.fail('should have thrown');
601
+ } catch (err) {
602
+ err.message.should.equal('Changelly did not return status');
491
603
  }
492
604
  });
493
605
 
@@ -139,6 +139,7 @@ describe('CoinGecko integration', function() {
139
139
  let server;
140
140
  let wallet;
141
141
  let fakeRequest;
142
+ let loggerError: sinon.SinonStub;
142
143
 
143
144
  const cg = () => server.externalServices.coinGecko;
144
145
  const getMarketStats = (query: any, code = 'USD') => cg().coinGeckoGetMarketStats({ params: { code }, query });
@@ -188,6 +189,7 @@ describe('CoinGecko integration', function() {
188
189
  clientVersion: 'bwc-2.0.0',
189
190
  walletId: '123'
190
191
  });
192
+ loggerError = sandbox.stub(logger, 'error');
191
193
  });
192
194
 
193
195
  after(async () => {
@@ -486,6 +488,8 @@ describe('CoinGecko integration', function() {
486
488
  await getMarketStats({ coin: 'USDC.e', chain: 'arb', tokenAddress });
487
489
  should.fail('should have thrown');
488
490
  } catch (err) {
491
+ loggerError.callCount.should.equal(1);
492
+ loggerError.args[0][0].should.contain('CoinGecko request failed');
489
493
  err.message.should.equal('Unsupported tokenAddress');
490
494
  }
491
495
  });
@@ -1,20 +1,24 @@
1
1
  'use strict';
2
2
 
3
3
  import * as chai from 'chai';
4
+ import * as sinon from 'sinon';
4
5
  import 'chai/register-should';
5
6
  import util from 'util';
6
7
  import { WalletService } from '../../../src/lib/server';
7
8
  import * as TestData from '../../testdata';
8
9
  import helpers from '../helpers';
9
10
  import config from '../../../src/config';
11
+ import logger from '../../../src/lib/logger';
10
12
 
11
13
  const should = chai.should();
12
14
 
13
15
  describe('Moonpay integration', () => {
16
+ const sandbox = sinon.createSandbox();
14
17
  let server;
15
18
  let wallet;
16
19
  let fakeRequest;
17
20
  let req;
21
+ let loggerError: sinon.SinonStub;
18
22
 
19
23
  before(async () => {
20
24
  await helpers.before();
@@ -71,12 +75,75 @@ describe('Moonpay integration', () => {
71
75
  clientVersion: 'bwc-2.0.0',
72
76
  walletId: '123',
73
77
  }));
78
+ sandbox.stub(logger, 'warn');
79
+ loggerError = sandbox.stub(logger, 'error');
80
+ });
81
+
82
+ afterEach(() => {
83
+ sandbox.restore();
74
84
  });
75
85
 
76
86
  after(async () => {
77
87
  await helpers.after();
78
88
  });
79
89
 
90
+ describe('#moonpayGetCurrencies', () => {
91
+ beforeEach(() => {
92
+ req = {
93
+ headers: {},
94
+ body: {
95
+ env: 'sandbox'
96
+ }
97
+ };
98
+ server.externalServices.moonpay.request = fakeRequest;
99
+ });
100
+
101
+ it('should work properly if req is OK', async () => {
102
+ const data = await server.externalServices.moonpay.moonpayGetCurrencies(req);
103
+ should.exist(data);
104
+ });
105
+
106
+ it('should return error if get returns error', async () => {
107
+ const fakeRequest2 = {
108
+ get: (_url, _opts, _cb) => { return _cb(new Error('Error'), null); },
109
+ };
110
+
111
+ server.externalServices.moonpay.request = fakeRequest2;
112
+ try {
113
+ await server.externalServices.moonpay.moonpayGetCurrencies(req);
114
+ should.fail('should have thrown');
115
+ } catch (err) {
116
+ loggerError.callCount.should.equal(1);
117
+ loggerError.args[0][0].should.contain('Moonpay request failed with error (');
118
+ err.message.should.equal('Failed to get Moonpay currencies');
119
+ }
120
+ });
121
+
122
+ it('should return error and not leak the response if body is empty', async () => {
123
+ const fakeRequest2 = {
124
+ get: (_url, opts, cb) => { return cb(null, { statusCode: 200, body: undefined, request: { headers: opts.headers } }); },
125
+ };
126
+
127
+ server.externalServices.moonpay.request = fakeRequest2;
128
+ try {
129
+ await server.externalServices.moonpay.moonpayGetCurrencies(req);
130
+ should.fail('should have thrown');
131
+ } catch (err) {
132
+ err.message.should.equal('Moonpay did not return currencies');
133
+ }
134
+ });
135
+
136
+ it('should return error if moonpay is commented in config', async () => {
137
+ config.moonpay = undefined;
138
+ try {
139
+ await server.externalServices.moonpay.moonpayGetCurrencies(req);
140
+ should.fail('should have thrown');
141
+ } catch (err) {
142
+ err.message.should.equal('Moonpay missing credentials');
143
+ }
144
+ });
145
+ });
146
+
80
147
  describe('#moonpayGetQuote', () => {
81
148
  beforeEach(() => {
82
149
  req = {
@@ -113,7 +180,23 @@ describe('Moonpay integration', () => {
113
180
  await server.externalServices.moonpay.moonpayGetQuote(req);
114
181
  should.fail('should have thrown');
115
182
  } catch (err) {
116
- err.message.should.equal('Error');
183
+ loggerError.callCount.should.equal(1);
184
+ loggerError.args[0][0].should.contain('Moonpay request failed with error (');
185
+ err.message.should.equal('Failed to get Moonpay buy quote');
186
+ }
187
+ });
188
+
189
+ it('should return error and not leak the response if body is empty', async () => {
190
+ const fakeRequest2 = {
191
+ get: (_url, opts, cb) => { return cb(null, { statusCode: 200, body: undefined, request: { headers: opts.headers } }); },
192
+ };
193
+
194
+ server.externalServices.moonpay.request = fakeRequest2;
195
+ try {
196
+ await server.externalServices.moonpay.moonpayGetQuote(req);
197
+ should.fail('should have thrown');
198
+ } catch (err) {
199
+ err.message.should.equal('Moonpay did not return buy quote');
117
200
  }
118
201
  });
119
202
 
@@ -173,7 +256,23 @@ describe('Moonpay integration', () => {
173
256
  await server.externalServices.moonpay.moonpayGetSellQuote(req);
174
257
  should.fail('should have thrown');
175
258
  } catch (err) {
176
- err.message.should.equal('Error');
259
+ loggerError.callCount.should.equal(1);
260
+ loggerError.args[0][0].should.contain('Moonpay request failed with error (');
261
+ err.message.should.equal('Failed to get Moonpay sell quote');
262
+ };
263
+ });
264
+
265
+ it('should return error and not leak the response if body is empty', async () => {
266
+ const fakeRequest2 = {
267
+ get: (_url, opts, cb) => { return cb(null, { statusCode: 200, body: undefined, request: { headers: opts.headers } }); },
268
+ };
269
+
270
+ server.externalServices.moonpay.request = fakeRequest2;
271
+ try {
272
+ await server.externalServices.moonpay.moonpayGetSellQuote(req);
273
+ should.fail('should have thrown');
274
+ } catch (err) {
275
+ err.message.should.equal('Moonpay did not return sell quote');
177
276
  };
178
277
  });
179
278
 
@@ -232,7 +331,23 @@ describe('Moonpay integration', () => {
232
331
  await server.externalServices.moonpay.moonpayGetCurrencyLimits(req);
233
332
  should.fail('should have thrown');
234
333
  } catch (err) {
235
- err.message.should.equal('Error');
334
+ loggerError.callCount.should.equal(1);
335
+ loggerError.args[0][0].should.contain('Moonpay request failed with error (');
336
+ err.message.should.equal('Failed to get Moonpay currency limits');
337
+ };
338
+ });
339
+
340
+ it('should return error and not leak the response if body is empty', async () => {
341
+ const fakeRequest2 = {
342
+ get: (_url, opts, cb) => { return cb(null, { statusCode: 200, body: undefined, request: { headers: opts.headers } }); },
343
+ };
344
+
345
+ server.externalServices.moonpay.request = fakeRequest2;
346
+ try {
347
+ await server.externalServices.moonpay.moonpayGetCurrencyLimits(req);
348
+ should.fail('should have thrown');
349
+ } catch (err) {
350
+ err.message.should.equal('Moonpay did not return currency limits');
236
351
  };
237
352
  });
238
353
 
@@ -422,7 +537,23 @@ describe('Moonpay integration', () => {
422
537
  await server.externalServices.moonpay.moonpayGetTransactionDetails(req);
423
538
  should.fail('should have thrown');
424
539
  } catch (err) {
425
- err.message.should.equal('Error');
540
+ loggerError.callCount.should.equal(1);
541
+ loggerError.args[0][0].should.contain('Moonpay request failed with error (');
542
+ err.message.should.equal('Failed to get Moonpay transaction details');
543
+ }
544
+ });
545
+
546
+ it('should return error and not leak the response if body is empty', async () => {
547
+ const fakeRequest2 = {
548
+ get: (_url, opts, cb) => { return cb(null, { statusCode: 200, body: undefined, request: { headers: opts.headers } }); },
549
+ };
550
+
551
+ server.externalServices.moonpay.request = fakeRequest2;
552
+ try {
553
+ await server.externalServices.moonpay.moonpayGetTransactionDetails(req);
554
+ should.fail('should have thrown');
555
+ } catch (err) {
556
+ err.message.should.equal('Moonpay did not return transaction details');
426
557
  }
427
558
  });
428
559
 
@@ -482,7 +613,23 @@ describe('Moonpay integration', () => {
482
613
  await server.externalServices.moonpay.moonpayGetSellTransactionDetails(req);
483
614
  should.fail('should have thrown');
484
615
  } catch (err) {
485
- err.message.should.equal('Error');
616
+ loggerError.callCount.should.equal(1);
617
+ loggerError.args[0][0].should.contain('Moonpay request failed with error (');
618
+ err.message.should.equal('Failed to get Moonpay sell transaction details');
619
+ }
620
+ });
621
+
622
+ it('should return error and not leak the response if body is empty', async () => {
623
+ const fakeRequest2 = {
624
+ get: (_url, opts, cb) => { return cb(null, { statusCode: 200, body: undefined, request: { headers: opts.headers } }); },
625
+ };
626
+
627
+ server.externalServices.moonpay.request = fakeRequest2;
628
+ try {
629
+ await server.externalServices.moonpay.moonpayGetSellTransactionDetails(req);
630
+ should.fail('should have thrown');
631
+ } catch (err) {
632
+ err.message.should.equal('Moonpay did not return sell transaction details');
486
633
  }
487
634
  });
488
635
 
@@ -534,7 +681,23 @@ describe('Moonpay integration', () => {
534
681
  await server.externalServices.moonpay.moonpayGetAccountDetails(req);
535
682
  should.fail('should have thrown');
536
683
  } catch (err) {
537
- err.message.should.equal('Error');
684
+ loggerError.callCount.should.equal(1);
685
+ loggerError.args[0][0].should.contain('Moonpay request failed with error (');
686
+ err.message.should.equal('Failed to get Moonpay account details');
687
+ }
688
+ });
689
+
690
+ it('should return error and not leak the response if body is empty', async () => {
691
+ const fakeRequest2 = {
692
+ get: (_url, opts, cb) => { return cb(null, { statusCode: 200, body: undefined, request: { headers: opts.headers } }); },
693
+ };
694
+
695
+ server.externalServices.moonpay.request = fakeRequest2;
696
+ try {
697
+ await server.externalServices.moonpay.moonpayGetAccountDetails(req);
698
+ should.fail('should have thrown');
699
+ } catch (err) {
700
+ err.message.should.equal('Moonpay did not return account details');
538
701
  }
539
702
  });
540
703
 
@@ -612,7 +775,9 @@ describe('Moonpay integration', () => {
612
775
  await server.externalServices.moonpay.moonpayCancelSellTransaction(req);
613
776
  should.fail('should have thrown');
614
777
  } catch (err) {
615
- err.message.should.equal('Error');
778
+ loggerError.callCount.should.equal(1);
779
+ loggerError.args[0][0].should.contain('Moonpay request failed with error (');
780
+ err.message.should.equal('Failed to cancel Moonpay sell transaction');
616
781
  }
617
782
  });
618
783
 
@@ -701,7 +866,9 @@ describe('Moonpay integration', () => {
701
866
  await server.externalServices.moonpay.moonpayCreateSession(req);
702
867
  should.fail('should have thrown');
703
868
  } catch (err) {
704
- err.message.should.equal('Error');
869
+ loggerError.callCount.should.equal(1);
870
+ loggerError.args[0][0].should.contain('Moonpay request failed with error (');
871
+ err.message.should.equal('Failed to create Moonpay session');
705
872
  }
706
873
  });
707
874
 
@@ -812,7 +979,9 @@ describe('Moonpay integration', () => {
812
979
  await server.externalServices.moonpay.moonpayRevokeActiveSession(req);
813
980
  should.fail('should have thrown');
814
981
  } catch (err) {
815
- err.message.should.equal('Error');
982
+ loggerError.callCount.should.equal(1);
983
+ loggerError.args[0][0].should.contain('Moonpay request failed with error (');
984
+ err.message.should.equal('Failed to revoke Moonpay session');
816
985
  }
817
986
  });
818
987