aboutsummaryrefslogtreecommitdiffstats
path: root/packages/json-schemas/test/schema_test.ts
blob: ac6a68b5911c2accc01cbe2e422ac1cc73e1321b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
import { BigNumber } from '@0xproject/utils';
import * as chai from 'chai';
import * as dirtyChai from 'dirty-chai';
import forEach = require('lodash.foreach');
import 'make-promises-safe';
import 'mocha';

import { schemas, SchemaValidator } from '../src/index';

chai.config.includeStack = true;
chai.use(dirtyChai);
const expect = chai.expect;
const NULL_ADDRESS = '0x0000000000000000000000000000000000000000';
const {
    numberSchema,
    addressSchema,
    ecSignatureSchema,
    ecSignatureParameterSchema,
    orderCancellationRequestsSchema,
    orderFillOrKillRequestsSchema,
    orderFillRequestsSchema,
    orderHashSchema,
    orderSchema,
    signedOrderSchema,
    signedOrdersSchema,
    blockParamSchema,
    blockRangeSchema,
    tokenSchema,
    jsNumber,
    txDataSchema,
    relayerApiErrorResponseSchema,
    relayerApiOrderBookResponseSchema,
    relayerApiTokenPairsResponseSchema,
    relayerApiFeesPayloadSchema,
    relayerApiFeesResponseSchema,
    relayerApiOrderbookChannelSubscribeSchema,
    relayerApiOrderbookChannelUpdateSchema,
    relayerApiOrderbookChannelSnapshotSchema,
} = schemas;

describe('Schema', () => {
    const validator = new SchemaValidator();
    const validateAgainstSchema = (testCases: any[], schema: any, shouldFail = false) => {
        forEach(testCases, (testCase: any) => {
            const validationResult = validator.validate(testCase, schema);
            const hasErrors = validationResult.errors.length !== 0;
            if (shouldFail) {
                if (!hasErrors) {
                    throw new Error(
                        `Expected testCase: ${JSON.stringify(testCase, null, '\t')} to fail and it didn't.`,
                    );
                }
            } else {
                if (hasErrors) {
                    throw new Error(JSON.stringify(validationResult.errors, null, '\t'));
                }
            }
        });
    };
    describe('#numberSchema', () => {
        it('should validate valid numbers', () => {
            const testCases = ['42', '0', '1.3', '0.2', '00.00'];
            validateAgainstSchema(testCases, numberSchema);
        });
        it('should fail for invalid numbers', () => {
            const testCases = ['.3', '1.', 'abacaba', 'и', '1..0'];
            const shouldFail = true;
            validateAgainstSchema(testCases, numberSchema, shouldFail);
        });
    });
    describe('#addressSchema', () => {
        it('should validate valid addresses', () => {
            const testCases = ['0x8b0292b11a196601ed2ce54b665cafeca0347d42', NULL_ADDRESS];
            validateAgainstSchema(testCases, addressSchema);
        });
        it('should fail for invalid addresses', () => {
            const testCases = [
                '0x',
                '0',
                '0x00',
                '0xzzzzzzB11a196601eD2ce54B665CaFEca0347D42',
                '0x8b0292B11a196601eD2ce54B665CaFEca0347D42',
            ];
            const shouldFail = true;
            validateAgainstSchema(testCases, addressSchema, shouldFail);
        });
    });
    describe('#ecSignatureParameterSchema', () => {
        it('should validate valid parameters', () => {
            const testCases = [
                '0x61a3ed31b43c8780e905a260a35faefcc527be7516aa11c0256729b5b351bc33',
                '0X40349190569279751135161d22529dc25add4f6069af05be04cacbda2ace2254',
            ];
            validateAgainstSchema(testCases, ecSignatureParameterSchema);
        });
        it('should fail for invalid parameters', () => {
            const testCases = [
                '0x61a3ed31b43c8780e905a260a35faefcc527be7516aa11c0256729b5b351bc3', // shorter
                '0xzzzz9190569279751135161d22529dc25add4f6069af05be04cacbda2ace2254', // invalid characters
                '40349190569279751135161d22529dc25add4f6069af05be04cacbda2ace2254', // no 0x
            ];
            const shouldFail = true;
            validateAgainstSchema(testCases, ecSignatureParameterSchema, shouldFail);
        });
    });
    describe('#ecSignatureSchema', () => {
        it('should validate valid signature', () => {
            const signature = {
                v: 27,
                r: '0x61a3ed31b43c8780e905a260a35faefcc527be7516aa11c0256729b5b351bc33',
                s: '0x40349190569279751135161d22529dc25add4f6069af05be04cacbda2ace2254',
            };
            const testCases = [
                signature,
                {
                    ...signature,
                    v: 28,
                },
            ];
            validateAgainstSchema(testCases, ecSignatureSchema);
        });
        it('should fail for invalid signature', () => {
            const v = 27;
            const r = '0x61a3ed31b43c8780e905a260a35faefcc527be7516aa11c0256729b5b351bc33';
            const s = '0x40349190569279751135161d22529dc25add4f6069af05be04cacbda2ace2254';
            const testCases = [{}, { v }, { r, s, v: 31 }];
            const shouldFail = true;
            validateAgainstSchema(testCases, ecSignatureSchema, shouldFail);
        });
    });
    describe('#orderHashSchema', () => {
        it('should validate valid order hash', () => {
            const testCases = [
                '0x61a3ed31B43c8780e905a260a35faefEc527be7516aa11c0256729b5b351bc33',
                '0x40349190569279751135161d22529dc25add4f6069af05be04cacbda2ace2254',
            ];
            validateAgainstSchema(testCases, orderHashSchema);
        });
        it('should fail for invalid order hash', () => {
            const testCases = [
                {},
                '0x',
                '0x8b0292B11a196601eD2ce54B665CaFEca0347D42',
                '61a3ed31B43c8780e905a260a35faefEc527be7516aa11c0256729b5b351bc33',
            ];
            const shouldFail = true;
            validateAgainstSchema(testCases, orderHashSchema, shouldFail);
        });
    });
    describe('#blockParamSchema', () => {
        it('should validate valid block param', () => {
            const testCases = [42, 'latest', 'pending', 'earliest'];
            validateAgainstSchema(testCases, blockParamSchema);
        });
        it('should fail for invalid block param', () => {
            const testCases = [{}, '42', 'pemding'];
            const shouldFail = true;
            validateAgainstSchema(testCases, blockParamSchema, shouldFail);
        });
    });
    describe('#blockRangeSchema', () => {
        it('should validate valid subscription opts', () => {
            const testCases = [{ fromBlock: 42, toBlock: 'latest' }, { fromBlock: 42 }, {}];
            validateAgainstSchema(testCases, blockRangeSchema);
        });
        it('should fail for invalid subscription opts', () => {
            const testCases = [{ fromBlock: '42' }];
            const shouldFail = true;
            validateAgainstSchema(testCases, blockRangeSchema, shouldFail);
        });
    });
    describe('#tokenSchema', () => {
        const token = {
            name: 'Zero Ex',
            symbol: 'ZRX',
            decimals: 100500,
            address: '0x8b0292b11a196601ed2ce54b665cafeca0347d42',
            url: 'https://0xproject.com',
        };
        it('should validate valid token', () => {
            const testCases = [token];
            validateAgainstSchema(testCases, tokenSchema);
        });
        it('should fail for invalid token', () => {
            const testCases = [
                {
                    ...token,
                    address: null,
                },
                {
                    ...token,
                    decimals: undefined,
                },
                [],
                4,
            ];
            const shouldFail = true;
            validateAgainstSchema(testCases, tokenSchema, shouldFail);
        });
    });
    describe('order including schemas', () => {
        const order = {
            maker: NULL_ADDRESS,
            taker: NULL_ADDRESS,
            makerFee: '1',
            takerFee: '2',
            makerTokenAmount: '1',
            takerTokenAmount: '2',
            makerTokenAddress: NULL_ADDRESS,
            takerTokenAddress: NULL_ADDRESS,
            salt: '67006738228878699843088602623665307406148487219438534730168799356281242528500',
            feeRecipient: NULL_ADDRESS,
            exchangeContractAddress: NULL_ADDRESS,
            expirationUnixTimestampSec: '42',
        };
        describe('#orderSchema', () => {
            it('should validate valid order', () => {
                const testCases = [order];
                validateAgainstSchema(testCases, orderSchema);
            });
            it('should fail for invalid order', () => {
                const testCases = [
                    {
                        ...order,
                        salt: undefined,
                    },
                    {
                        ...order,
                        salt: 'salt',
                    },
                    'order',
                ];
                const shouldFail = true;
                validateAgainstSchema(testCases, orderSchema, shouldFail);
            });
        });
        describe('signed order including schemas', () => {
            const signedOrder = {
                ...order,
                ecSignature: {
                    v: 27,
                    r: '0x61a3ed31b43c8780e905a260a35faefcc527be7516aa11c0256729b5b351bc33',
                    s: '0x40349190569279751135161d22529dc25add4f6069af05be04cacbda2ace2254',
                },
            };
            describe('#signedOrdersSchema', () => {
                it('should validate valid signed orders', () => {
                    const testCases = [[signedOrder], []];
                    validateAgainstSchema(testCases, signedOrdersSchema);
                });
                it('should fail for invalid signed orders', () => {
                    const testCases = [[signedOrder, 1]];
                    const shouldFail = true;
                    validateAgainstSchema(testCases, signedOrdersSchema, shouldFail);
                });
            });
            describe('#signedOrderSchema', () => {
                it('should validate valid signed order', () => {
                    const testCases = [signedOrder];
                    validateAgainstSchema(testCases, signedOrderSchema);
                });
                it('should fail for invalid signed order', () => {
                    const testCases = [
                        {
                            ...signedOrder,
                            ecSignature: undefined,
                        },
                    ];
                    const shouldFail = true;
                    validateAgainstSchema(testCases, signedOrderSchema, shouldFail);
                });
            });
            describe('#orderFillOrKillRequestsSchema', () => {
                const orderFillOrKillRequests = [
                    {
                        signedOrder,
                        fillTakerAmount: '5',
                    },
                ];
                it('should validate valid order fill or kill requests', () => {
                    const testCases = [orderFillOrKillRequests];
                    validateAgainstSchema(testCases, orderFillOrKillRequestsSchema);
                });
                it('should fail for invalid order fill or kill requests', () => {
                    const testCases = [
                        [
                            {
                                ...orderFillOrKillRequests[0],
                                fillTakerAmount: undefined,
                            },
                        ],
                    ];
                    const shouldFail = true;
                    validateAgainstSchema(testCases, orderFillOrKillRequestsSchema, shouldFail);
                });
            });
            describe('#orderCancellationRequestsSchema', () => {
                const orderCancellationRequests = [
                    {
                        order,
                        takerTokenCancelAmount: '5',
                    },
                ];
                it('should validate valid order cancellation requests', () => {
                    const testCases = [orderCancellationRequests];
                    validateAgainstSchema(testCases, orderCancellationRequestsSchema);
                });
                it('should fail for invalid order cancellation requests', () => {
                    const testCases = [
                        [
                            {
                                ...orderCancellationRequests[0],
                                takerTokenCancelAmount: undefined,
                            },
                        ],
                    ];
                    const shouldFail = true;
                    validateAgainstSchema(testCases, orderCancellationRequestsSchema, shouldFail);
                });
            });
            describe('#orderFillRequestsSchema', () => {
                const orderFillRequests = [
                    {
                        signedOrder,
                        takerTokenFillAmount: '5',
                    },
                ];
                it('should validate valid order fill requests', () => {
                    const testCases = [orderFillRequests];
                    validateAgainstSchema(testCases, orderFillRequestsSchema);
                });
                it('should fail for invalid order fill requests', () => {
                    const testCases = [
                        [
                            {
                                ...orderFillRequests[0],
                                takerTokenFillAmount: undefined,
                            },
                        ],
                    ];
                    const shouldFail = true;
                    validateAgainstSchema(testCases, orderFillRequestsSchema, shouldFail);
                });
            });
            describe('#relayerApiOrderBookResponseSchema', () => {
                it('should validate valid order book responses', () => {
                    const testCases = [
                        {
                            bids: [],
                            asks: [],
                        },
                        {
                            bids: [signedOrder, signedOrder],
                            asks: [],
                        },
                        {
                            bids: [],
                            asks: [signedOrder, signedOrder],
                        },
                        {
                            bids: [signedOrder],
                            asks: [signedOrder, signedOrder],
                        },
                    ];
                    validateAgainstSchema(testCases, relayerApiOrderBookResponseSchema);
                });
                it('should fail for invalid order fill requests', () => {
                    const testCases = [
                        {},
                        {
                            bids: [signedOrder, signedOrder],
                        },
                        {
                            asks: [signedOrder, signedOrder],
                        },
                        {
                            bids: signedOrder,
                            asks: [signedOrder, signedOrder],
                        },
                        {
                            bids: [signedOrder],
                            asks: signedOrder,
                        },
                    ];
                    const shouldFail = true;
                    validateAgainstSchema(testCases, relayerApiOrderBookResponseSchema, shouldFail);
                });
            });
            describe('#relayerApiOrderbookChannelSubscribeSchema', () => {
                it('should validate valid orderbook channel websocket subscribe message', () => {
                    const testCases = [
                        {
                            type: 'subscribe',
                            channel: 'orderbook',
                            requestId: 1,
                            payload: {
                                baseTokenAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d',
                                quoteTokenAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d',
                                snapshot: true,
                                limit: 100,
                            },
                        },
                        {
                            type: 'subscribe',
                            channel: 'orderbook',
                            requestId: 1,
                            payload: {
                                baseTokenAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d',
                                quoteTokenAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d',
                            },
                        },
                    ];
                    validateAgainstSchema(testCases, relayerApiOrderbookChannelSubscribeSchema);
                });
                it('should fail for invalid orderbook channel websocket subscribe message', () => {
                    const checksummedAddress = '0xA2b31daCf30a9C50ca473337c01d8A201ae33e32';
                    const testCases = [
                        {
                            type: 'subscribe',
                            channel: 'orderbook',
                            payload: {
                                baseTokenAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d',
                                quoteTokenAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d',
                                snapshot: true,
                                limit: 100,
                            },
                        },
                        {
                            type: 'foo',
                            channel: 'orderbook',
                            requestId: 1,
                            payload: {
                                baseTokenAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d',
                                quoteTokenAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d',
                            },
                        },
                        {
                            type: 'subscribe',
                            channel: 'bar',
                            requestId: 1,
                            payload: {
                                baseTokenAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d',
                                quoteTokenAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d',
                            },
                        },
                        {
                            type: 'subscribe',
                            channel: 'orderbook',
                            requestId: 1,
                            payload: {
                                baseTokenAddress: checksummedAddress,
                                quoteTokenAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d',
                            },
                        },
                        {
                            type: 'subscribe',
                            channel: 'orderbook',
                            requestId: 1,
                            payload: {
                                baseTokenAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d',
                                quoteTokenAddress: checksummedAddress,
                            },
                        },
                        {
                            type: 'subscribe',
                            channel: 'orderbook',
                            requestId: 1,
                            payload: {
                                quoteTokenAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d',
                            },
                        },
                        {
                            type: 'subscribe',
                            channel: 'orderbook',
                            requestId: 1,
                            payload: {
                                baseTokenAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d',
                            },
                        },
                        {
                            type: 'subscribe',
                            channel: 'orderbook',
                            requestId: 1,
                            payload: {
                                baseTokenAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d',
                                quoteTokenAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d',
                                snapshot: 'true',
                                limit: 100,
                            },
                        },
                        {
                            type: 'subscribe',
                            channel: 'orderbook',
                            requestId: 1,
                            payload: {
                                baseTokenAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d',
                                quoteTokenAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d',
                                snapshot: true,
                                limit: '100',
                            },
                        },
                    ];
                    const shouldFail = true;
                    validateAgainstSchema(testCases, relayerApiOrderbookChannelSubscribeSchema, shouldFail);
                });
            });
            describe('#relayerApiOrderbookChannelSnapshotSchema', () => {
                it('should validate valid orderbook channel websocket snapshot message', () => {
                    const testCases = [
                        {
                            type: 'snapshot',
                            channel: 'orderbook',
                            requestId: 2,
                            payload: {
                                bids: [],
                                asks: [],
                            },
                        },
                        {
                            type: 'snapshot',
                            channel: 'orderbook',
                            requestId: 2,
                            payload: {
                                bids: [signedOrder],
                                asks: [signedOrder],
                            },
                        },
                    ];
                    validateAgainstSchema(testCases, relayerApiOrderbookChannelSnapshotSchema);
                });
                it('should fail for invalid orderbook channel websocket snapshot message', () => {
                    const testCases = [
                        {
                            type: 'foo',
                            channel: 'orderbook',
                            requestId: 2,
                            payload: {
                                bids: [signedOrder],
                                asks: [signedOrder],
                            },
                        },
                        {
                            type: 'snapshot',
                            channel: 'bar',
                            requestId: 2,
                            payload: {
                                bids: [signedOrder],
                                asks: [signedOrder],
                            },
                        },
                        {
                            type: 'snapshot',
                            channel: 'orderbook',
                            payload: {
                                bids: [signedOrder],
                                asks: [signedOrder],
                            },
                        },
                        {
                            type: 'snapshot',
                            channel: 'orderbook',
                            requestId: '2',
                            payload: {
                                bids: [signedOrder],
                                asks: [signedOrder],
                            },
                        },
                        {
                            type: 'snapshot',
                            channel: 'orderbook',
                            requestId: 2,
                            payload: {
                                bids: [signedOrder],
                            },
                        },
                        {
                            type: 'snapshot',
                            channel: 'orderbook',
                            requestId: 2,
                            payload: {
                                asks: [signedOrder],
                            },
                        },
                        {
                            type: 'snapshot',
                            channel: 'orderbook',
                            requestId: 2,
                            payload: {
                                bids: [signedOrder],
                                asks: [{}],
                            },
                        },
                        {
                            type: 'snapshot',
                            channel: 'orderbook',
                            requestId: 2,
                            payload: {
                                bids: [{}],
                                asks: [signedOrder],
                            },
                        },
                    ];
                    const shouldFail = true;
                    validateAgainstSchema(testCases, relayerApiOrderbookChannelSnapshotSchema, shouldFail);
                });
            });
            describe('#relayerApiOrderbookChannelUpdateSchema', () => {
                it('should validate valid orderbook channel websocket update message', () => {
                    const testCases = [
                        {
                            type: 'update',
                            channel: 'orderbook',
                            requestId: 2,
                            payload: signedOrder,
                        },
                    ];
                    validateAgainstSchema(testCases, relayerApiOrderbookChannelUpdateSchema);
                });
                it('should fail for invalid orderbook channel websocket update message', () => {
                    const testCases = [
                        {
                            type: 'foo',
                            channel: 'orderbook',
                            requestId: 2,
                            payload: signedOrder,
                        },
                        {
                            type: 'update',
                            channel: 'bar',
                            requestId: 2,
                            payload: signedOrder,
                        },
                        {
                            type: 'update',
                            channel: 'orderbook',
                            requestId: 2,
                            payload: {},
                        },
                    ];
                    const shouldFail = true;
                    validateAgainstSchema(testCases, relayerApiOrderbookChannelUpdateSchema, shouldFail);
                });
            });
        });
    });
    describe('BigNumber serialization', () => {
        it('should correctly serialize BigNumbers', () => {
            const testCases = {
                '42': '42',
                '0': '0',
                '1.3': '1.3',
                '0.2': '0.2',
                '00.00': '0',
                '.3': '0.3',
            };
            forEach(testCases, (serialized: string, input: string) => {
                expect(JSON.parse(JSON.stringify(new BigNumber(input)))).to.be.equal(serialized);
            });
        });
    });
    describe('#relayerApiErrorResponseSchema', () => {
        it('should validate valid errorResponse', () => {
            const testCases = [
                {
                    code: 102,
                    reason: 'Order submission disabled',
                },
                {
                    code: 101,
                    reason: 'Validation failed',
                    validationErrors: [
                        {
                            field: 'maker',
                            code: 1002,
                            reason: 'Invalid address',
                        },
                    ],
                },
            ];
            validateAgainstSchema(testCases, relayerApiErrorResponseSchema);
        });
        it('should fail for invalid error responses', () => {
            const testCases = [
                {},
                {
                    code: 102,
                },
                {
                    code: '102',
                    reason: 'Order submission disabled',
                },
                {
                    reason: 'Order submission disabled',
                },
                {
                    code: 101,
                    reason: 'Validation failed',
                    validationErrors: [
                        {
                            field: 'maker',
                            reason: 'Invalid address',
                        },
                    ],
                },
                {
                    code: 101,
                    reason: 'Validation failed',
                    validationErrors: [
                        {
                            field: 'maker',
                            code: '1002',
                            reason: 'Invalid address',
                        },
                    ],
                },
            ];
            const shouldFail = true;
            validateAgainstSchema(testCases, relayerApiErrorResponseSchema, shouldFail);
        });
    });
    describe('#relayerApiFeesPayloadSchema', () => {
        it('should validate valid fees payloads', () => {
            const testCases = [
                {
                    exchangeContractAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d',
                    maker: '0x323b5d4c32345ced77393b3530b1eed0f346429d',
                    taker: '0x323b5d4c32345ced77393b3530b1eed0f346429d',
                    makerTokenAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d',
                    takerTokenAddress: '0xef7fff64389b814a946f3e92105513705ca6b990',
                    makerTokenAmount: '10000000000000000000',
                    takerTokenAmount: '30000000000000000000',
                    expirationUnixTimestampSec: '42',
                    salt: '67006738228878699843088602623665307406148487219438534730168799356281242528500',
                },
            ];
            validateAgainstSchema(testCases, relayerApiFeesPayloadSchema);
        });
        it('should fail for invalid fees payloads', () => {
            const checksummedAddress = '0xA2b31daCf30a9C50ca473337c01d8A201ae33e32';
            const testCases = [
                {},
                {
                    takerTokenAddress: '0xef7fff64389b814a946f3e92105513705ca6b990',
                    makerTokenAmount: '10000000000000000000',
                    takerTokenAmount: '30000000000000000000',
                },
                {
                    taker: checksummedAddress,
                    makerTokenAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d',
                    takerTokenAddress: '0xef7fff64389b814a946f3e92105513705ca6b990',
                    makerTokenAmount: '10000000000000000000',
                    takerTokenAmount: '30000000000000000000',
                },
                {
                    makerTokenAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d',
                    takerTokenAddress: '0xef7fff64389b814a946f3e92105513705ca6b990',
                    makerTokenAmount: 10000000000000000000,
                    takerTokenAmount: 30000000000000000000,
                },
            ];
            const shouldFail = true;
            validateAgainstSchema(testCases, relayerApiFeesPayloadSchema, shouldFail);
        });
    });
    describe('#relayerApiFeesResponseSchema', () => {
        it('should validate valid fees responses', () => {
            const testCases = [
                {
                    makerFee: '10000000000000000',
                    takerFee: '30000000000000000',
                    feeRecipient: '0x323b5d4c32345ced77393b3530b1eed0f346429d',
                },
            ];
            validateAgainstSchema(testCases, relayerApiFeesResponseSchema);
        });
        it('should fail for invalid fees responses', () => {
            const checksummedAddress = '0xA2b31daCf30a9C50ca473337c01d8A201ae33e32';
            const testCases = [
                {},
                {
                    makerFee: 10000000000000000,
                    takerFee: 30000000000000000,
                },
                {
                    feeRecipient: checksummedAddress,
                    takerToSpecify: checksummedAddress,
                    makerFee: '10000000000000000',
                    takerFee: '30000000000000000',
                },
            ];
            const shouldFail = true;
            validateAgainstSchema(testCases, relayerApiFeesResponseSchema, shouldFail);
        });
    });
    describe('#relayerApiTokenPairsResponseSchema', () => {
        it('should validate valid tokenPairs response', () => {
            const testCases = [
                [],
                [
                    {
                        tokenA: {
                            address: '0x323b5d4c32345ced77393b3530b1eed0f346429d',
                            minAmount: '0',
                            maxAmount: '10000000000000000000',
                            precision: 5,
                        },
                        tokenB: {
                            address: '0xef7fff64389b814a946f3e92105513705ca6b990',
                            minAmount: '0',
                            maxAmount: '50000000000000000000',
                            precision: 5,
                        },
                    },
                ],
                [
                    {
                        tokenA: {
                            address: '0x323b5d4c32345ced77393b3530b1eed0f346429d',
                        },
                        tokenB: {
                            address: '0xef7fff64389b814a946f3e92105513705ca6b990',
                        },
                    },
                ],
            ];
            validateAgainstSchema(testCases, relayerApiTokenPairsResponseSchema);
        });
        it('should fail for invalid tokenPairs responses', () => {
            const checksummedAddress = '0xA2b31daCf30a9C50ca473337c01d8A201ae33e32';
            const testCases = [
                [
                    {
                        tokenA: {
                            address: checksummedAddress,
                        },
                        tokenB: {
                            address: checksummedAddress,
                        },
                    },
                ],
                [
                    {
                        tokenA: {
                            address: '0x323b5d4c32345ced77393b3530b1eed0f346429d',
                            minAmount: 0,
                            maxAmount: 10000000000000000000,
                        },
                        tokenB: {
                            address: '0xef7fff64389b814a946f3e92105513705ca6b990',
                            minAmount: 0,
                            maxAmount: 50000000000000000000,
                        },
                    },
                ],
                [
                    {
                        tokenA: {
                            address: '0x323b5d4c32345ced77393b3530b1eed0f346429d',
                            precision: '5',
                        },
                        tokenB: {
                            address: '0xef7fff64389b814a946f3e92105513705ca6b990',
                            precision: '5',
                        },
                    },
                ],
            ];
            const shouldFail = true;
            validateAgainstSchema(testCases, relayerApiTokenPairsResponseSchema, shouldFail);
        });
    });
    describe('#jsNumberSchema', () => {
        it('should validate valid js number', () => {
            const testCases = [1, 42];
            validateAgainstSchema(testCases, jsNumber);
        });
        it('should fail for invalid js number', () => {
            const testCases = [NaN, -1, new BigNumber(1)];
            const shouldFail = true;
            validateAgainstSchema(testCases, jsNumber, shouldFail);
        });
    });
    describe('#txDataSchema', () => {
        it('should validate valid txData', () => {
            const testCases = [
                {
                    from: NULL_ADDRESS,
                },
                {
                    from: NULL_ADDRESS,
                    gas: new BigNumber(42),
                },
                {
                    from: NULL_ADDRESS,
                    gas: 42,
                },
            ];
            validateAgainstSchema(testCases, txDataSchema);
        });
        it('should fail for invalid txData', () => {
            const testCases = [
                {
                    gas: new BigNumber(42),
                },
                {
                    from: NULL_ADDRESS,
                    unknownProp: 'here',
                },
                {},
                [],
                new BigNumber(1),
            ];
            const shouldFail = true;
            validateAgainstSchema(testCases, txDataSchema, shouldFail);
        });
    });
}); // tslint:disable:max-file-line-count