@bitpay-labs/bitcore-wallet-service 11.10.14 → 11.11.1
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.
- package/package.json +5 -5
- package/src/config.ts +0 -20
- package/src/externalservices/banxa.ts +51 -10
- package/src/externalservices/changelly.ts +54 -6
- package/src/externalservices/moonpay.ts +85 -19
- package/src/externalservices/oneInch.ts +13 -5
- package/src/externalservices/ramp.ts +42 -8
- package/src/externalservices/sardine.ts +51 -10
- package/src/externalservices/simplex.ts +58 -11
- package/src/externalservices/thorswap.ts +46 -11
- package/src/externalservices/transak.ts +53 -11
- package/src/lib/common/constants.ts +1 -1
- package/src/lib/errors/errordefinitions.ts +8 -0
- package/src/lib/model/tsskeygen.ts +12 -4
- package/src/lib/routes/middleware/authRequest.ts +6 -16
- package/src/lib/routes/middleware/authTssRequest.ts +130 -26
- package/src/lib/routes/services.ts +0 -12
- package/src/lib/routes/tss.ts +21 -8
- package/src/lib/routes/wallets.ts +8 -9
- package/src/lib/server.ts +9 -20
- package/src/lib/storage.ts +55 -22
- package/src/lib/tss.ts +77 -1
- package/src/types/externalservices.d.ts +0 -1
- package/test/integration/externalservices/banxa.test.ts +95 -5
- package/test/integration/externalservices/changelly.test.ts +118 -6
- package/test/integration/externalservices/coinGecko.test.ts +4 -0
- package/test/integration/externalservices/moonpay.test.ts +178 -9
- package/test/integration/externalservices/oneInch.test.ts +28 -1
- package/test/integration/externalservices/ramp.test.ts +126 -4
- package/test/integration/externalservices/sardine.test.ts +95 -5
- package/test/integration/externalservices/simplex.test.ts +95 -5
- package/test/integration/externalservices/thorswap.test.ts +81 -5
- package/test/integration/externalservices/transak.test.ts +98 -6
- package/test/integration/helpers.ts +1 -1
- package/test/integration/server.test.ts +56 -88
- package/test/integration/tss.test.ts +706 -371
- package/test/storage.test.ts +6 -7
- package/ts_build/package.json +4 -4
- package/ts_build/src/config.d.ts.map +1 -1
- package/ts_build/src/config.js +0 -4
- package/ts_build/src/config.js.map +1 -1
- package/ts_build/src/externalservices/banxa.d.ts.map +1 -1
- package/ts_build/src/externalservices/banxa.js +51 -10
- package/ts_build/src/externalservices/banxa.js.map +1 -1
- package/ts_build/src/externalservices/changelly.d.ts.map +1 -1
- package/ts_build/src/externalservices/changelly.js +54 -6
- package/ts_build/src/externalservices/changelly.js.map +1 -1
- package/ts_build/src/externalservices/moonpay.d.ts.map +1 -1
- package/ts_build/src/externalservices/moonpay.js +85 -19
- package/ts_build/src/externalservices/moonpay.js.map +1 -1
- package/ts_build/src/externalservices/oneInch.d.ts.map +1 -1
- package/ts_build/src/externalservices/oneInch.js +13 -5
- package/ts_build/src/externalservices/oneInch.js.map +1 -1
- package/ts_build/src/externalservices/ramp.d.ts.map +1 -1
- package/ts_build/src/externalservices/ramp.js +42 -8
- package/ts_build/src/externalservices/ramp.js.map +1 -1
- package/ts_build/src/externalservices/sardine.d.ts.map +1 -1
- package/ts_build/src/externalservices/sardine.js +51 -10
- package/ts_build/src/externalservices/sardine.js.map +1 -1
- package/ts_build/src/externalservices/simplex.d.ts.map +1 -1
- package/ts_build/src/externalservices/simplex.js +55 -11
- package/ts_build/src/externalservices/simplex.js.map +1 -1
- package/ts_build/src/externalservices/thorswap.d.ts.map +1 -1
- package/ts_build/src/externalservices/thorswap.js +45 -11
- package/ts_build/src/externalservices/thorswap.js.map +1 -1
- package/ts_build/src/externalservices/transak.d.ts.map +1 -1
- package/ts_build/src/externalservices/transak.js +53 -11
- package/ts_build/src/externalservices/transak.js.map +1 -1
- package/ts_build/src/lib/common/constants.d.ts +1 -1
- package/ts_build/src/lib/common/constants.js +1 -1
- package/ts_build/src/lib/common/index.d.ts +1 -1
- package/ts_build/src/lib/errors/errordefinitions.d.ts +4 -0
- package/ts_build/src/lib/errors/errordefinitions.d.ts.map +1 -1
- package/ts_build/src/lib/errors/errordefinitions.js +4 -0
- package/ts_build/src/lib/errors/errordefinitions.js.map +1 -1
- package/ts_build/src/lib/model/tsskeygen.d.ts +2 -0
- package/ts_build/src/lib/model/tsskeygen.d.ts.map +1 -1
- package/ts_build/src/lib/model/tsskeygen.js +6 -2
- package/ts_build/src/lib/model/tsskeygen.js.map +1 -1
- package/ts_build/src/lib/routes/middleware/authRequest.d.ts.map +1 -1
- package/ts_build/src/lib/routes/middleware/authRequest.js +6 -16
- package/ts_build/src/lib/routes/middleware/authRequest.js.map +1 -1
- package/ts_build/src/lib/routes/middleware/authTssRequest.d.ts +2 -1
- package/ts_build/src/lib/routes/middleware/authTssRequest.d.ts.map +1 -1
- package/ts_build/src/lib/routes/middleware/authTssRequest.js +104 -24
- package/ts_build/src/lib/routes/middleware/authTssRequest.js.map +1 -1
- package/ts_build/src/lib/routes/services.d.ts.map +1 -1
- package/ts_build/src/lib/routes/services.js +0 -10
- package/ts_build/src/lib/routes/services.js.map +1 -1
- package/ts_build/src/lib/routes/tss.d.ts.map +1 -1
- package/ts_build/src/lib/routes/tss.js +19 -7
- package/ts_build/src/lib/routes/tss.js.map +1 -1
- package/ts_build/src/lib/routes/wallets.d.ts.map +1 -1
- package/ts_build/src/lib/routes/wallets.js +8 -9
- package/ts_build/src/lib/routes/wallets.js.map +1 -1
- package/ts_build/src/lib/server.d.ts +0 -2
- package/ts_build/src/lib/server.d.ts.map +1 -1
- package/ts_build/src/lib/server.js +8 -20
- package/ts_build/src/lib/server.js.map +1 -1
- package/ts_build/src/lib/storage.d.ts +9 -2
- package/ts_build/src/lib/storage.d.ts.map +1 -1
- package/ts_build/src/lib/storage.js +51 -20
- package/ts_build/src/lib/storage.js.map +1 -1
- package/ts_build/src/lib/tss.d.ts +8 -0
- package/ts_build/src/lib/tss.d.ts.map +1 -1
- package/ts_build/src/lib/tss.js +59 -1
- package/ts_build/src/lib/tss.js.map +1 -1
- package/ts_build/test/integration/externalservices/banxa.test.d.ts.map +1 -1
- package/ts_build/test/integration/externalservices/banxa.test.js +93 -5
- package/ts_build/test/integration/externalservices/banxa.test.js.map +1 -1
- package/ts_build/test/integration/externalservices/changelly.test.d.ts.map +1 -1
- package/ts_build/test/integration/externalservices/changelly.test.js +111 -6
- package/ts_build/test/integration/externalservices/changelly.test.js.map +1 -1
- package/ts_build/test/integration/externalservices/coinGecko.test.js +4 -0
- package/ts_build/test/integration/externalservices/coinGecko.test.js.map +1 -1
- package/ts_build/test/integration/externalservices/moonpay.test.d.ts.map +1 -1
- package/ts_build/test/integration/externalservices/moonpay.test.js +169 -9
- package/ts_build/test/integration/externalservices/moonpay.test.js.map +1 -1
- package/ts_build/test/integration/externalservices/oneInch.test.d.ts.map +1 -1
- package/ts_build/test/integration/externalservices/oneInch.test.js +26 -1
- package/ts_build/test/integration/externalservices/oneInch.test.js.map +1 -1
- package/ts_build/test/integration/externalservices/ramp.test.d.ts.map +1 -1
- package/ts_build/test/integration/externalservices/ramp.test.js +115 -4
- package/ts_build/test/integration/externalservices/ramp.test.js.map +1 -1
- package/ts_build/test/integration/externalservices/sardine.test.d.ts.map +1 -1
- package/ts_build/test/integration/externalservices/sardine.test.js +94 -5
- package/ts_build/test/integration/externalservices/sardine.test.js.map +1 -1
- package/ts_build/test/integration/externalservices/simplex.test.d.ts.map +1 -1
- package/ts_build/test/integration/externalservices/simplex.test.js +89 -5
- package/ts_build/test/integration/externalservices/simplex.test.js.map +1 -1
- package/ts_build/test/integration/externalservices/thorswap.test.d.ts.map +1 -1
- package/ts_build/test/integration/externalservices/thorswap.test.js +76 -5
- package/ts_build/test/integration/externalservices/thorswap.test.js.map +1 -1
- package/ts_build/test/integration/externalservices/transak.test.d.ts.map +1 -1
- package/ts_build/test/integration/externalservices/transak.test.js +93 -6
- package/ts_build/test/integration/externalservices/transak.test.js.map +1 -1
- package/ts_build/test/integration/helpers.js +1 -1
- package/ts_build/test/integration/helpers.js.map +1 -1
- package/ts_build/test/integration/server.test.js +44 -76
- package/ts_build/test/integration/server.test.js.map +1 -1
- package/ts_build/test/integration/tss.test.d.ts.map +1 -1
- package/ts_build/test/integration/tss.test.js +599 -357
- package/ts_build/test/integration/tss.test.js.map +1 -1
- package/ts_build/test/storage.test.js +6 -7
- package/ts_build/test/storage.test.js.map +1 -1
- package/src/externalservices/wyre.ts +0 -131
- package/test/integration/externalservices/wyre.test.ts +0 -270
- package/ts_build/src/externalservices/wyre.d.ts +0 -7
- package/ts_build/src/externalservices/wyre.d.ts.map +0 -1
- package/ts_build/src/externalservices/wyre.js +0 -144
- package/ts_build/src/externalservices/wyre.js.map +0 -1
- package/ts_build/test/integration/externalservices/wyre.test.d.ts +0 -2
- package/ts_build/test/integration/externalservices/wyre.test.d.ts.map +0 -1
- package/ts_build/test/integration/externalservices/wyre.test.js +0 -281
- 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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|