@bitpay-labs/bitcore-wallet-service 11.11.0 → 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 +4 -4
- 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/routes/services.ts +0 -12
- package/src/lib/server.ts +0 -3
- 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/ts_build/package.json +3 -3
- 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/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/server.d.ts +0 -2
- package/ts_build/src/lib/server.d.ts.map +1 -1
- package/ts_build/src/lib/server.js +0 -2
- package/ts_build/src/lib/server.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/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,21 +1,25 @@
|
|
|
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('OneInch integration', function() {
|
|
14
16
|
this.timeout(5000);
|
|
17
|
+
const sandbox = sinon.createSandbox();
|
|
15
18
|
let server;
|
|
16
19
|
let wallet;
|
|
17
20
|
let fakeRequest;
|
|
18
21
|
let req;
|
|
22
|
+
let loggerError: sinon.SinonStub;
|
|
19
23
|
|
|
20
24
|
before(async () => {
|
|
21
25
|
await helpers.before();
|
|
@@ -47,6 +51,12 @@ describe('OneInch integration', function() {
|
|
|
47
51
|
clientVersion: 'bwc-2.0.0',
|
|
48
52
|
walletId: '123',
|
|
49
53
|
}));
|
|
54
|
+
sandbox.stub(logger, 'warn');
|
|
55
|
+
loggerError = sandbox.stub(logger, 'error');
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
afterEach(() => {
|
|
59
|
+
sandbox.restore();
|
|
50
60
|
});
|
|
51
61
|
|
|
52
62
|
after(async () => {
|
|
@@ -119,7 +129,24 @@ describe('OneInch integration', function() {
|
|
|
119
129
|
await server.externalServices.oneInch.oneInchGetSwap(req);
|
|
120
130
|
should.fail('should have thrown');
|
|
121
131
|
} catch (err) {
|
|
122
|
-
|
|
132
|
+
loggerError.callCount.should.equal(1);
|
|
133
|
+
loggerError.args[0][0].should.contain('1Inch request failed with error (');
|
|
134
|
+
err.message.should.equal('Failed to get 1Inch swap data');
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
it('should return error and not leak the response if body is empty', async () => {
|
|
139
|
+
const fakeRequest2 = {
|
|
140
|
+
post: (_url, opts, cb) => { return cb(null, { statusCode: 200, body: undefined, request: { headers: opts.headers } }); },
|
|
141
|
+
get: (_url, opts, cb) => { return cb(null, { statusCode: 200, body: undefined, request: { headers: opts.headers } }); }
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
server.externalServices.oneInch.request = fakeRequest2;
|
|
145
|
+
try {
|
|
146
|
+
await server.externalServices.oneInch.oneInchGetSwap(req);
|
|
147
|
+
should.fail('should have thrown');
|
|
148
|
+
} catch (err) {
|
|
149
|
+
err.message.should.equal('1Inch did not return swap data');
|
|
123
150
|
}
|
|
124
151
|
});
|
|
125
152
|
|
|
@@ -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 crypto from 'crypto';
|
|
5
6
|
import 'chai/register-should';
|
|
6
7
|
import util from 'util';
|
|
@@ -8,6 +9,8 @@ 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 { ClientError } from '../../../src/lib/errors/clienterror';
|
|
13
|
+
import logger from '../../../src/lib/logger';
|
|
11
14
|
|
|
12
15
|
const should = chai.should();
|
|
13
16
|
const { privateKey: privDer } = crypto.generateKeyPairSync('ed25519', {
|
|
@@ -22,10 +25,13 @@ const { privateKey: privDer } = crypto.generateKeyPairSync('ed25519', {
|
|
|
22
25
|
});
|
|
23
26
|
|
|
24
27
|
describe('Ramp integration', () => {
|
|
28
|
+
const sandbox = sinon.createSandbox();
|
|
25
29
|
let server;
|
|
26
30
|
let wallet;
|
|
27
31
|
let fakeRequest;
|
|
28
32
|
let req;
|
|
33
|
+
let loggerError: sinon.SinonStub;
|
|
34
|
+
let loggerWarn: sinon.SinonStub;
|
|
29
35
|
|
|
30
36
|
before(async () => {
|
|
31
37
|
await helpers.before();
|
|
@@ -77,6 +83,12 @@ describe('Ramp integration', () => {
|
|
|
77
83
|
clientVersion: 'bwc-2.0.0',
|
|
78
84
|
walletId: '123',
|
|
79
85
|
}));
|
|
86
|
+
loggerWarn = sandbox.stub(logger, 'warn');
|
|
87
|
+
loggerError = sandbox.stub(logger, 'error');
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
afterEach(() => {
|
|
91
|
+
sandbox.restore();
|
|
80
92
|
});
|
|
81
93
|
|
|
82
94
|
after(async () => {
|
|
@@ -118,7 +130,23 @@ describe('Ramp integration', () => {
|
|
|
118
130
|
await server.externalServices.ramp.rampGetQuote(req);
|
|
119
131
|
should.fail('should have thrown');
|
|
120
132
|
} catch (err) {
|
|
121
|
-
|
|
133
|
+
loggerError.callCount.should.equal(1);
|
|
134
|
+
loggerError.args[0][0].should.contain('Ramp request failed with error (');
|
|
135
|
+
err.message.should.equal('Failed to get Ramp quote');
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
it('should return error and not leak the response if body is empty', async () => {
|
|
140
|
+
const fakeRequest2 = {
|
|
141
|
+
post: (_url, opts, cb) => { return cb(null, { statusCode: 200, body: undefined, request: { headers: opts.headers } }); },
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
server.externalServices.ramp.request = fakeRequest2;
|
|
145
|
+
try {
|
|
146
|
+
await server.externalServices.ramp.rampGetQuote(req);
|
|
147
|
+
should.fail('should have thrown');
|
|
148
|
+
} catch (err) {
|
|
149
|
+
err.message.should.equal('Ramp did not return quote data');
|
|
122
150
|
}
|
|
123
151
|
});
|
|
124
152
|
|
|
@@ -178,7 +206,23 @@ describe('Ramp integration', () => {
|
|
|
178
206
|
await server.externalServices.ramp.rampGetSellQuote(req);
|
|
179
207
|
should.fail('should have thrown');
|
|
180
208
|
} catch (err) {
|
|
181
|
-
|
|
209
|
+
loggerError.callCount.should.equal(1);
|
|
210
|
+
loggerError.args[0][0].should.contain('Ramp request failed with error (');
|
|
211
|
+
err.message.should.equal('Failed to get Ramp sell quote');
|
|
212
|
+
}
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
it('should return error and not leak the response if body is empty', async () => {
|
|
216
|
+
const fakeRequest2 = {
|
|
217
|
+
post: (_url, opts, cb) => { return cb(null, { statusCode: 200, body: undefined, request: { headers: opts.headers } }); },
|
|
218
|
+
};
|
|
219
|
+
|
|
220
|
+
server.externalServices.ramp.request = fakeRequest2;
|
|
221
|
+
try {
|
|
222
|
+
await server.externalServices.ramp.rampGetSellQuote(req);
|
|
223
|
+
should.fail('should have thrown');
|
|
224
|
+
} catch (err) {
|
|
225
|
+
err.message.should.equal('Ramp did not return sell quote data');
|
|
182
226
|
}
|
|
183
227
|
});
|
|
184
228
|
|
|
@@ -541,7 +585,23 @@ describe('Ramp integration', () => {
|
|
|
541
585
|
await server.externalServices.ramp.rampGetAssets(req);
|
|
542
586
|
should.fail('should have thrown');
|
|
543
587
|
} catch (err) {
|
|
544
|
-
|
|
588
|
+
loggerError.callCount.should.equal(1);
|
|
589
|
+
loggerError.args[0][0].should.contain('Ramp request failed with error (');
|
|
590
|
+
err.message.should.equal('Failed to get Ramp assets');
|
|
591
|
+
}
|
|
592
|
+
});
|
|
593
|
+
|
|
594
|
+
it('should return error and not leak the response if body is empty', async () => {
|
|
595
|
+
const fakeRequest2 = {
|
|
596
|
+
get: (_url, opts, cb) => { return cb(null, { statusCode: 200, body: undefined, request: { headers: opts.headers } }); },
|
|
597
|
+
};
|
|
598
|
+
|
|
599
|
+
server.externalServices.ramp.request = fakeRequest2;
|
|
600
|
+
try {
|
|
601
|
+
await server.externalServices.ramp.rampGetAssets(req);
|
|
602
|
+
should.fail('should have thrown');
|
|
603
|
+
} catch (err) {
|
|
604
|
+
err.message.should.equal('Ramp did not return assets data');
|
|
545
605
|
}
|
|
546
606
|
});
|
|
547
607
|
|
|
@@ -584,7 +644,69 @@ describe('Ramp integration', () => {
|
|
|
584
644
|
await server.externalServices.ramp.rampGetSellTransactionDetails(req);
|
|
585
645
|
should.fail('should have thrown');
|
|
586
646
|
} catch (err) {
|
|
587
|
-
|
|
647
|
+
loggerError.callCount.should.equal(1);
|
|
648
|
+
loggerError.args[0][0].should.contain('Ramp request failed with error (');
|
|
649
|
+
err.message.should.equal('Failed to get Ramp sell transaction details');
|
|
650
|
+
}
|
|
651
|
+
});
|
|
652
|
+
|
|
653
|
+
it('should return error and not leak the response if body is empty', async () => {
|
|
654
|
+
const fakeRequest2 = {
|
|
655
|
+
get: (_url, opts, cb) => { return cb(null, { statusCode: 200, body: undefined, request: { headers: opts.headers } }); },
|
|
656
|
+
};
|
|
657
|
+
|
|
658
|
+
server.externalServices.ramp.request = fakeRequest2;
|
|
659
|
+
try {
|
|
660
|
+
await server.externalServices.ramp.rampGetSellTransactionDetails(req);
|
|
661
|
+
should.fail('should have thrown');
|
|
662
|
+
} catch (err) {
|
|
663
|
+
err.message.should.equal('Ramp did not return sell transaction details');
|
|
664
|
+
}
|
|
665
|
+
});
|
|
666
|
+
|
|
667
|
+
it('should log the redacted URL and not leak the saleViewToken if get returns error', async () => {
|
|
668
|
+
let requestedUrl;
|
|
669
|
+
const fakeRequest2 = {
|
|
670
|
+
get: (url, _opts, cb) => { requestedUrl = url; return cb(new Error('Error'), null); },
|
|
671
|
+
};
|
|
672
|
+
|
|
673
|
+
server.externalServices.ramp.request = fakeRequest2;
|
|
674
|
+
try {
|
|
675
|
+
await server.externalServices.ramp.rampGetSellTransactionDetails(req);
|
|
676
|
+
should.fail('should have thrown');
|
|
677
|
+
} catch (err) {
|
|
678
|
+
// the real request must still carry the token
|
|
679
|
+
requestedUrl.should.equal('api2/host-api/v3/offramp/sale/id1?secret=saleViewToken1');
|
|
680
|
+
|
|
681
|
+
loggerError.callCount.should.equal(1);
|
|
682
|
+
loggerError.args[0][0].should.contain('(api2/host-api/v3/offramp/sale/id1?secret=***)');
|
|
683
|
+
loggerError.args[0][0].should.not.contain('saleViewToken1');
|
|
684
|
+
|
|
685
|
+
err.should.be.instanceOf(ClientError);
|
|
686
|
+
err.message.should.equal('Failed to get Ramp sell transaction details');
|
|
687
|
+
JSON.stringify(err).should.not.contain('saleViewToken1');
|
|
688
|
+
err.toString().should.not.contain('saleViewToken1');
|
|
689
|
+
}
|
|
690
|
+
});
|
|
691
|
+
|
|
692
|
+
it('should log the redacted URL and not leak the saleViewToken on non-2xx status', async () => {
|
|
693
|
+
const fakeRequest2 = {
|
|
694
|
+
get: (_url, _opts, cb) => { return cb(null, { statusCode: 401, body: undefined }); },
|
|
695
|
+
};
|
|
696
|
+
|
|
697
|
+
server.externalServices.ramp.request = fakeRequest2;
|
|
698
|
+
try {
|
|
699
|
+
await server.externalServices.ramp.rampGetSellTransactionDetails(req);
|
|
700
|
+
should.fail('should have thrown');
|
|
701
|
+
} catch (err) {
|
|
702
|
+
loggerWarn.callCount.should.equal(1);
|
|
703
|
+
loggerWarn.args[0][0].should.equal('Ramp request failed with status code 401: api2/host-api/v3/offramp/sale/id1?secret=***');
|
|
704
|
+
loggerWarn.args[0][0].should.not.contain('saleViewToken1');
|
|
705
|
+
|
|
706
|
+
err.should.be.instanceOf(ClientError);
|
|
707
|
+
err.message.should.equal('Ramp did not return sell transaction details');
|
|
708
|
+
JSON.stringify(err).should.not.contain('saleViewToken1');
|
|
709
|
+
err.toString().should.not.contain('saleViewToken1');
|
|
588
710
|
}
|
|
589
711
|
});
|
|
590
712
|
|
|
@@ -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('Sardine 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();
|
|
@@ -62,6 +66,12 @@ describe('Sardine integration', () => {
|
|
|
62
66
|
clientVersion: 'bwc-2.0.0',
|
|
63
67
|
walletId: '123',
|
|
64
68
|
}));
|
|
69
|
+
sandbox.stub(logger, 'warn');
|
|
70
|
+
loggerError = sandbox.stub(logger, 'error');
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
afterEach(() => {
|
|
74
|
+
sandbox.restore();
|
|
65
75
|
});
|
|
66
76
|
|
|
67
77
|
after(async () => {
|
|
@@ -106,7 +116,23 @@ describe('Sardine integration', () => {
|
|
|
106
116
|
await server.externalServices.sardine.sardineGetQuote(req);
|
|
107
117
|
should.fail('should have thrown');
|
|
108
118
|
} catch (err) {
|
|
109
|
-
|
|
119
|
+
loggerError.callCount.should.equal(1);
|
|
120
|
+
loggerError.args[0][0].should.contain('Sardine request failed with error (');
|
|
121
|
+
err.message.should.equal('Failed to get Sardine quote');
|
|
122
|
+
};
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
it('should return error and not leak the response if body is empty', async () => {
|
|
126
|
+
const fakeRequest2 = {
|
|
127
|
+
get: (_url, opts, cb) => { return cb(null, { statusCode: 200, body: undefined, request: { headers: opts.headers } }); },
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
server.externalServices.sardine.request = fakeRequest2;
|
|
131
|
+
try {
|
|
132
|
+
await server.externalServices.sardine.sardineGetQuote(req);
|
|
133
|
+
should.fail('should have thrown');
|
|
134
|
+
} catch (err) {
|
|
135
|
+
err.message.should.equal('Sardine did not return a quote');
|
|
110
136
|
};
|
|
111
137
|
});
|
|
112
138
|
|
|
@@ -163,7 +189,23 @@ describe('Sardine integration', () => {
|
|
|
163
189
|
await server.externalServices.sardine.sardineGetCurrencyLimits(req);
|
|
164
190
|
should.fail('should have thrown');
|
|
165
191
|
} catch (err) {
|
|
166
|
-
|
|
192
|
+
loggerError.callCount.should.equal(1);
|
|
193
|
+
loggerError.args[0][0].should.contain('Sardine request failed with error (');
|
|
194
|
+
err.message.should.equal('Failed to get Sardine currency limits');
|
|
195
|
+
};
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
it('should return error and not leak the response if body is empty', async () => {
|
|
199
|
+
const fakeRequest2 = {
|
|
200
|
+
get: (_url, opts, cb) => { return cb(null, { statusCode: 200, body: undefined, request: { headers: opts.headers } }); },
|
|
201
|
+
};
|
|
202
|
+
|
|
203
|
+
server.externalServices.sardine.request = fakeRequest2;
|
|
204
|
+
try {
|
|
205
|
+
await server.externalServices.sardine.sardineGetCurrencyLimits(req);
|
|
206
|
+
should.fail('should have thrown');
|
|
207
|
+
} catch (err) {
|
|
208
|
+
err.message.should.equal('Sardine did not return currency limits');
|
|
167
209
|
};
|
|
168
210
|
});
|
|
169
211
|
|
|
@@ -213,7 +255,23 @@ describe('Sardine integration', () => {
|
|
|
213
255
|
await server.externalServices.sardine.sardineGetToken(req);
|
|
214
256
|
should.fail('should have thrown');
|
|
215
257
|
} catch (err) {
|
|
216
|
-
|
|
258
|
+
loggerError.callCount.should.equal(1);
|
|
259
|
+
loggerError.args[0][0].should.contain('Sardine request failed with error (');
|
|
260
|
+
err.message.should.equal('Failed to get Sardine token');
|
|
261
|
+
};
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
it('should return error and not leak the response if body is empty', async () => {
|
|
265
|
+
const fakeRequest2 = {
|
|
266
|
+
post: (_url, opts, cb) => { return cb(null, { statusCode: 200, body: undefined, request: { headers: opts.headers } }); },
|
|
267
|
+
};
|
|
268
|
+
|
|
269
|
+
server.externalServices.sardine.request = fakeRequest2;
|
|
270
|
+
try {
|
|
271
|
+
await server.externalServices.sardine.sardineGetToken(req);
|
|
272
|
+
should.fail('should have thrown');
|
|
273
|
+
} catch (err) {
|
|
274
|
+
err.message.should.equal('Sardine did not return a token');
|
|
217
275
|
};
|
|
218
276
|
});
|
|
219
277
|
|
|
@@ -270,7 +328,23 @@ describe('Sardine integration', () => {
|
|
|
270
328
|
await server.externalServices.sardine.sardineGetSupportedTokens(req);
|
|
271
329
|
should.fail('should have thrown');
|
|
272
330
|
} catch (err) {
|
|
273
|
-
|
|
331
|
+
loggerError.callCount.should.equal(1);
|
|
332
|
+
loggerError.args[0][0].should.contain('Sardine request failed with error (');
|
|
333
|
+
err.message.should.equal('Failed to get Sardine supported tokens');
|
|
334
|
+
};
|
|
335
|
+
});
|
|
336
|
+
|
|
337
|
+
it('should return error and not leak the response if body is empty', async() => {
|
|
338
|
+
const fakeRequest2 = {
|
|
339
|
+
get: (_url, opts, cb) => { return cb(null, { statusCode: 200, body: undefined, request: { headers: opts.headers } }); },
|
|
340
|
+
};
|
|
341
|
+
|
|
342
|
+
server.externalServices.sardine.request = fakeRequest2;
|
|
343
|
+
try {
|
|
344
|
+
await server.externalServices.sardine.sardineGetSupportedTokens(req);
|
|
345
|
+
should.fail('should have thrown');
|
|
346
|
+
} catch (err) {
|
|
347
|
+
err.message.should.equal('Sardine did not return supported tokens');
|
|
274
348
|
};
|
|
275
349
|
});
|
|
276
350
|
|
|
@@ -318,7 +392,23 @@ describe('Sardine integration', () => {
|
|
|
318
392
|
await server.externalServices.sardine.sardineGetOrdersDetails(req);
|
|
319
393
|
should.fail('should have thrown');
|
|
320
394
|
} catch (err) {
|
|
321
|
-
|
|
395
|
+
loggerError.callCount.should.equal(1);
|
|
396
|
+
loggerError.args[0][0].should.contain('Sardine request failed with error (');
|
|
397
|
+
err.message.should.equal('Failed to get Sardine order details');
|
|
398
|
+
};
|
|
399
|
+
});
|
|
400
|
+
|
|
401
|
+
it('should return error and not leak the response if body is empty', async () => {
|
|
402
|
+
const fakeRequest2 = {
|
|
403
|
+
get: (_url, opts, cb) => { return cb(null, { statusCode: 200, body: undefined, request: { headers: opts.headers } }); },
|
|
404
|
+
};
|
|
405
|
+
|
|
406
|
+
server.externalServices.sardine.request = fakeRequest2;
|
|
407
|
+
try {
|
|
408
|
+
await server.externalServices.sardine.sardineGetOrdersDetails(req);
|
|
409
|
+
should.fail('should have thrown');
|
|
410
|
+
} catch (err) {
|
|
411
|
+
err.message.should.equal('Sardine did not return order details');
|
|
322
412
|
};
|
|
323
413
|
});
|
|
324
414
|
|
|
@@ -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('Simplex 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();
|
|
@@ -74,6 +78,12 @@ describe('Simplex integration', () => {
|
|
|
74
78
|
clientVersion: 'bwc-2.0.0',
|
|
75
79
|
walletId: '123',
|
|
76
80
|
}));
|
|
81
|
+
sandbox.stub(logger, 'warn');
|
|
82
|
+
loggerError = sandbox.stub(logger, 'error');
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
afterEach(() => {
|
|
86
|
+
sandbox.restore();
|
|
77
87
|
});
|
|
78
88
|
|
|
79
89
|
after(async () => {
|
|
@@ -112,7 +122,23 @@ describe('Simplex integration', () => {
|
|
|
112
122
|
await server.externalServices.simplex.simplexGetCurrencies(req);
|
|
113
123
|
should.fail('should have thrown');
|
|
114
124
|
} catch (err) {
|
|
115
|
-
|
|
125
|
+
loggerError.callCount.should.equal(1);
|
|
126
|
+
loggerError.args[0][0].should.contain('Simplex request failed with error (');
|
|
127
|
+
err.message.should.equal('Failed to get Simplex supported currencies');
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
it('should return error and not leak the response if body is empty', async () => {
|
|
132
|
+
const fakeRequest2 = {
|
|
133
|
+
get: (_url, opts, cb) => { return cb(null, { statusCode: 200, body: undefined, request: { headers: opts.headers } }); },
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
server.externalServices.simplex.request = fakeRequest2;
|
|
137
|
+
try {
|
|
138
|
+
await server.externalServices.simplex.simplexGetCurrencies(req);
|
|
139
|
+
should.fail('should have thrown');
|
|
140
|
+
} catch (err) {
|
|
141
|
+
err.message.should.equal('Simplex did not return supported currencies');
|
|
116
142
|
}
|
|
117
143
|
});
|
|
118
144
|
|
|
@@ -230,7 +256,23 @@ describe('Simplex integration', () => {
|
|
|
230
256
|
await server.externalServices.simplex.simplexGetQuote(req);
|
|
231
257
|
should.fail('should have thrown');
|
|
232
258
|
} catch (err) {
|
|
233
|
-
|
|
259
|
+
loggerError.callCount.should.equal(1);
|
|
260
|
+
loggerError.args[0][0].should.contain('Simplex request failed with error (');
|
|
261
|
+
err.message.should.equal('Failed to get Simplex quote');
|
|
262
|
+
}
|
|
263
|
+
});
|
|
264
|
+
|
|
265
|
+
it('should return error and not leak the response if body is empty', async () => {
|
|
266
|
+
const fakeRequest2 = {
|
|
267
|
+
post: (_url, opts, cb) => { return cb(null, { statusCode: 200, body: undefined, request: { headers: opts.headers } }); },
|
|
268
|
+
};
|
|
269
|
+
|
|
270
|
+
server.externalServices.simplex.request = fakeRequest2;
|
|
271
|
+
try {
|
|
272
|
+
await server.externalServices.simplex.simplexGetQuote(req);
|
|
273
|
+
should.fail('should have thrown');
|
|
274
|
+
} catch (err) {
|
|
275
|
+
err.message.should.equal('Simplex did not return a quote');
|
|
234
276
|
}
|
|
235
277
|
});
|
|
236
278
|
|
|
@@ -284,7 +326,23 @@ describe('Simplex integration', () => {
|
|
|
284
326
|
await server.externalServices.simplex.simplexGetSellQuote(req);
|
|
285
327
|
should.fail('should have thrown');
|
|
286
328
|
} catch (err) {
|
|
287
|
-
|
|
329
|
+
loggerError.callCount.should.equal(1);
|
|
330
|
+
loggerError.args[0][0].should.contain('Simplex request failed with error (');
|
|
331
|
+
err.message.should.equal('Failed to get Simplex sell quote');
|
|
332
|
+
}
|
|
333
|
+
});
|
|
334
|
+
|
|
335
|
+
it('should return error and not leak the response if body is empty', async () => {
|
|
336
|
+
const fakeRequest2 = {
|
|
337
|
+
get: (_url, opts, cb) => { return cb(null, { statusCode: 200, body: undefined, request: { headers: opts.headers } }); },
|
|
338
|
+
};
|
|
339
|
+
|
|
340
|
+
server.externalServices.simplex.request = fakeRequest2;
|
|
341
|
+
try {
|
|
342
|
+
await server.externalServices.simplex.simplexGetSellQuote(req);
|
|
343
|
+
should.fail('should have thrown');
|
|
344
|
+
} catch (err) {
|
|
345
|
+
err.message.should.equal('Simplex did not return a sell quote');
|
|
288
346
|
}
|
|
289
347
|
});
|
|
290
348
|
|
|
@@ -416,7 +474,23 @@ describe('Simplex integration', () => {
|
|
|
416
474
|
await server.externalServices.simplex.simplexPaymentRequest(req);
|
|
417
475
|
should.fail('should have thrown');
|
|
418
476
|
} catch (err) {
|
|
419
|
-
|
|
477
|
+
loggerError.callCount.should.equal(1);
|
|
478
|
+
loggerError.args[0][0].should.contain('Simplex request failed with error (');
|
|
479
|
+
err.message.should.equal('Failed to get Simplex payment data');
|
|
480
|
+
}
|
|
481
|
+
});
|
|
482
|
+
|
|
483
|
+
it('should return error and not leak the response if body is empty', async () => {
|
|
484
|
+
const fakeRequest2 = {
|
|
485
|
+
post: (_url, opts, cb) => { return cb(null, { statusCode: 200, body: undefined, request: { headers: opts.headers } }); },
|
|
486
|
+
};
|
|
487
|
+
|
|
488
|
+
server.externalServices.simplex.request = fakeRequest2;
|
|
489
|
+
try {
|
|
490
|
+
await server.externalServices.simplex.simplexPaymentRequest(req);
|
|
491
|
+
should.fail('should have thrown');
|
|
492
|
+
} catch (err) {
|
|
493
|
+
err.message.should.equal('Simplex did not return payment data');
|
|
420
494
|
}
|
|
421
495
|
});
|
|
422
496
|
|
|
@@ -477,7 +551,23 @@ describe('Simplex integration', () => {
|
|
|
477
551
|
await server.externalServices.simplex.simplexSellPaymentRequest(req);
|
|
478
552
|
should.fail('should have thrown');
|
|
479
553
|
} catch (err) {
|
|
480
|
-
|
|
554
|
+
loggerError.callCount.should.equal(1);
|
|
555
|
+
loggerError.args[0][0].should.contain('Simplex request failed with error (');
|
|
556
|
+
err.message.should.equal('Failed to initiate Simplex sell payment');
|
|
557
|
+
}
|
|
558
|
+
});
|
|
559
|
+
|
|
560
|
+
it('should return error and not leak the response if body is empty', async () => {
|
|
561
|
+
const fakeRequest2 = {
|
|
562
|
+
post: (_url, opts, cb) => { return cb(null, { statusCode: 200, body: undefined, request: { headers: opts.headers } }); },
|
|
563
|
+
};
|
|
564
|
+
|
|
565
|
+
server.externalServices.simplex.request = fakeRequest2;
|
|
566
|
+
try {
|
|
567
|
+
await server.externalServices.simplex.simplexSellPaymentRequest(req);
|
|
568
|
+
should.fail('should have thrown');
|
|
569
|
+
} catch (err) {
|
|
570
|
+
err.message.should.equal('Simplex did not return sell data');
|
|
481
571
|
}
|
|
482
572
|
});
|
|
483
573
|
|