|
1 | 1 | import { status } from '@grpc/grpc-js';
|
2 |
| -import { AuthenticationError, Exchange } from 'ccxt'; |
| 2 | +import { AuthenticationError, Exchange, NetworkError } from 'ccxt'; |
3 | 3 | import { TestScheduler } from 'rxjs/testing';
|
4 | 4 | import { errors } from '../opendex/errors';
|
5 | 5 | import { ArbyStore, getArbyStore } from '../store';
|
@@ -64,6 +64,34 @@ const assertCatchOpenDEXerror = ({
|
64 | 64 |
|
65 | 65 | const ASSERTIONS_PER_TEST = 3;
|
66 | 66 |
|
| 67 | +const assertCEXerror = (error: any) => { |
| 68 | + return () => { |
| 69 | + // 1 extra assertion after assertCatchOpenDEXerror |
| 70 | + expect.assertions(ASSERTIONS_PER_TEST + 1); |
| 71 | + const inputEvents = '1s #'; |
| 72 | + const inputError = error; |
| 73 | + const expected = ''; |
| 74 | + const expectedSubscriptions = { |
| 75 | + input$: ['^ 999ms !', '7001ms ^ 999ms !'], |
| 76 | + cleanup$: ['1s ^ 1s !', '8001ms ^ 1s !'], |
| 77 | + }; |
| 78 | + const store = { |
| 79 | + ...getArbyStore(), |
| 80 | + ...{ resetLastOrderUpdatePrice: jest.fn() }, |
| 81 | + }; |
| 82 | + const unsubscribe = '10s !'; |
| 83 | + assertCatchOpenDEXerror({ |
| 84 | + inputEvents, |
| 85 | + inputError, |
| 86 | + expected, |
| 87 | + unsubscribe, |
| 88 | + expectedSubscriptions, |
| 89 | + store, |
| 90 | + }); |
| 91 | + expect(store.resetLastOrderUpdatePrice).toHaveBeenCalledTimes(2); |
| 92 | + }; |
| 93 | +}; |
| 94 | + |
67 | 95 | describe('catchOpenDEXerror', () => {
|
68 | 96 | beforeEach(testSchedulerSetup);
|
69 | 97 |
|
@@ -189,31 +217,15 @@ describe('catchOpenDEXerror', () => {
|
189 | 217 | });
|
190 | 218 | });
|
191 | 219 |
|
192 |
| - it('cancels orders, updates store lastPriceUpdate, retries CENTRALIZED_EXCHANGE_PRICE_FEED_ERROR', () => { |
193 |
| - // 1 extra assertion after assertCatchOpenDEXerror |
194 |
| - expect.assertions(ASSERTIONS_PER_TEST + 1); |
195 |
| - const inputEvents = '1s #'; |
196 |
| - const inputError = errors.CENTRALIZED_EXCHANGE_PRICE_FEED_ERROR; |
197 |
| - const expected = ''; |
198 |
| - const expectedSubscriptions = { |
199 |
| - input$: ['^ 999ms !', '7001ms ^ 999ms !'], |
200 |
| - cleanup$: ['1s ^ 1s !', '8001ms ^ 1s !'], |
201 |
| - }; |
202 |
| - const store = { |
203 |
| - ...getArbyStore(), |
204 |
| - ...{ resetLastOrderUpdatePrice: jest.fn() }, |
205 |
| - }; |
206 |
| - const unsubscribe = '10s !'; |
207 |
| - assertCatchOpenDEXerror({ |
208 |
| - inputEvents, |
209 |
| - inputError, |
210 |
| - expected, |
211 |
| - unsubscribe, |
212 |
| - expectedSubscriptions, |
213 |
| - store, |
214 |
| - }); |
215 |
| - expect(store.resetLastOrderUpdatePrice).toHaveBeenCalledTimes(2); |
216 |
| - }); |
| 220 | + it( |
| 221 | + 'cancels orders, updates store lastPriceUpdate, retries CENTRALIZED_EXCHANGE_PRICE_FEED_ERROR', |
| 222 | + assertCEXerror(errors.CENTRALIZED_EXCHANGE_PRICE_FEED_ERROR) |
| 223 | + ); |
| 224 | + |
| 225 | + it( |
| 226 | + 'cancels orders, updates store lastPriceUpdate, retries NetworkError', |
| 227 | + assertCEXerror(new NetworkError('CEX connection lost')) |
| 228 | + ); |
217 | 229 |
|
218 | 230 | it('retries recoverable gRPC errors', () => {
|
219 | 231 | const recoverableGRPCerrors = [
|
|
0 commit comments