aboutsummaryrefslogtreecommitdiffstats
path: root/packages/contracts/test/extensions/order_validator.ts
blob: 37bd1b0e23c2e94cbdad4e41f91eb107f74d1306 (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
import { BlockchainLifecycle } from '@0x/dev-utils';
import { assetDataUtils, orderHashUtils } from '@0x/order-utils';
import { SignedOrder } from '@0x/types';
import { BigNumber } from '@0x/utils';
import * as chai from 'chai';
import * as _ from 'lodash';

import { DummyERC20TokenContract } from '../../generated-wrappers/dummy_erc20_token';
import { DummyERC721TokenContract } from '../../generated-wrappers/dummy_erc721_token';
import { ERC20ProxyContract } from '../../generated-wrappers/erc20_proxy';
import { ERC721ProxyContract } from '../../generated-wrappers/erc721_proxy';
import { ExchangeContract } from '../../generated-wrappers/exchange';
import { OrderValidatorContract } from '../../generated-wrappers/order_validator';
import { artifacts } from '../../src/artifacts';
import { chaiSetup } from '../utils/chai_setup';
import { constants } from '../utils/constants';
import { ERC20Wrapper } from '../utils/erc20_wrapper';
import { ERC721Wrapper } from '../utils/erc721_wrapper';
import { ExchangeWrapper } from '../utils/exchange_wrapper';
import { OrderFactory } from '../utils/order_factory';
import { OrderStatus } from '../utils/types';
import { provider, txDefaults, web3Wrapper } from '../utils/web3_wrapper';

chaiSetup.configure();
const expect = chai.expect;
const blockchainLifecycle = new BlockchainLifecycle(web3Wrapper);

describe('OrderValidator', () => {
    let makerAddress: string;
    let owner: string;
    let takerAddress: string;
    let erc20AssetData: string;
    let erc721AssetData: string;

    let erc20Token: DummyERC20TokenContract;
    let zrxToken: DummyERC20TokenContract;
    let erc721Token: DummyERC721TokenContract;
    let exchange: ExchangeContract;
    let orderValidator: OrderValidatorContract;
    let erc20Proxy: ERC20ProxyContract;
    let erc721Proxy: ERC721ProxyContract;

    let signedOrder: SignedOrder;
    let signedOrder2: SignedOrder;
    let orderFactory: OrderFactory;

    const tokenId = new BigNumber(123456789);
    const tokenId2 = new BigNumber(987654321);
    const ERC721_BALANCE = new BigNumber(1);
    const ERC721_ALLOWANCE = new BigNumber(1);

    before(async () => {
        await blockchainLifecycle.startAsync();
    });
    after(async () => {
        await blockchainLifecycle.revertAsync();
    });

    before(async () => {
        const accounts = await web3Wrapper.getAvailableAddressesAsync();
        const usedAddresses = ([owner, makerAddress, takerAddress] = _.slice(accounts, 0, 3));

        const erc20Wrapper = new ERC20Wrapper(provider, usedAddresses, owner);
        const erc721Wrapper = new ERC721Wrapper(provider, usedAddresses, owner);

        const numDummyErc20ToDeploy = 2;
        [erc20Token, zrxToken] = await erc20Wrapper.deployDummyTokensAsync(
            numDummyErc20ToDeploy,
            constants.DUMMY_TOKEN_DECIMALS,
        );
        erc20Proxy = await erc20Wrapper.deployProxyAsync();

        [erc721Token] = await erc721Wrapper.deployDummyTokensAsync();
        erc721Proxy = await erc721Wrapper.deployProxyAsync();

        const zrxAssetData = assetDataUtils.encodeERC20AssetData(zrxToken.address);
        exchange = await ExchangeContract.deployFrom0xArtifactAsync(
            artifacts.Exchange,
            provider,
            txDefaults,
            zrxAssetData,
        );
        const exchangeWrapper = new ExchangeWrapper(exchange, provider);
        await exchangeWrapper.registerAssetProxyAsync(erc20Proxy.address, owner);
        await exchangeWrapper.registerAssetProxyAsync(erc721Proxy.address, owner);

        orderValidator = await OrderValidatorContract.deployFrom0xArtifactAsync(
            artifacts.OrderValidator,
            provider,
            txDefaults,
            exchange.address,
            zrxAssetData,
        );

        erc20AssetData = assetDataUtils.encodeERC20AssetData(erc20Token.address);
        erc721AssetData = assetDataUtils.encodeERC721AssetData(erc721Token.address, tokenId);
        const defaultOrderParams = {
            ...constants.STATIC_ORDER_PARAMS,
            exchangeAddress: exchange.address,
            makerAddress,
            feeRecipientAddress: constants.NULL_ADDRESS,
            makerAssetData: erc20AssetData,
            takerAssetData: erc721AssetData,
        };
        const privateKey = constants.TESTRPC_PRIVATE_KEYS[accounts.indexOf(makerAddress)];
        orderFactory = new OrderFactory(privateKey, defaultOrderParams);
    });

    beforeEach(async () => {
        await blockchainLifecycle.startAsync();
    });
    afterEach(async () => {
        await blockchainLifecycle.revertAsync();
    });

    describe('getBalanceAndAllowance', () => {
        describe('getERC721TokenOwner', async () => {
            it('should return the null address when tokenId is not owned', async () => {
                const tokenOwner = await orderValidator.getERC721TokenOwner.callAsync(makerAddress, tokenId);
                expect(tokenOwner).to.be.equal(constants.NULL_ADDRESS);
            });
            it('should return the owner address when tokenId is owned', async () => {
                await web3Wrapper.awaitTransactionSuccessAsync(
                    await erc721Token.mint.sendTransactionAsync(makerAddress, tokenId),
                    constants.AWAIT_TRANSACTION_MINED_MS,
                );
                const tokenOwner = await orderValidator.getERC721TokenOwner.callAsync(erc721Token.address, tokenId);
                expect(tokenOwner).to.be.equal(makerAddress);
            });
        });
        describe('ERC20 assetData', () => {
            it('should return the correct balances and allowances when both values are 0', async () => {
                const [newBalance, newAllowance] = await orderValidator.getBalanceAndAllowance.callAsync(
                    makerAddress,
                    erc20AssetData,
                );
                expect(constants.ZERO_AMOUNT).to.be.bignumber.equal(newBalance);
                expect(constants.ZERO_AMOUNT).to.be.bignumber.equal(newAllowance);
            });
            it('should return the correct balance and allowance when both values are non-zero', async () => {
                const balance = new BigNumber(123);
                const allowance = new BigNumber(456);
                await web3Wrapper.awaitTransactionSuccessAsync(
                    await erc20Token.setBalance.sendTransactionAsync(makerAddress, balance),
                    constants.AWAIT_TRANSACTION_MINED_MS,
                );
                await web3Wrapper.awaitTransactionSuccessAsync(
                    await erc20Token.approve.sendTransactionAsync(erc20Proxy.address, allowance, {
                        from: makerAddress,
                    }),
                    constants.AWAIT_TRANSACTION_MINED_MS,
                );
                const [newBalance, newAllowance] = await orderValidator.getBalanceAndAllowance.callAsync(
                    makerAddress,
                    erc20AssetData,
                );
                expect(balance).to.be.bignumber.equal(newBalance);
                expect(allowance).to.be.bignumber.equal(newAllowance);
            });
        });
        describe('ERC721 assetData', () => {
            it('should return a balance of 0 when the tokenId is not owned by target', async () => {
                const [newBalance] = await orderValidator.getBalanceAndAllowance.callAsync(
                    makerAddress,
                    erc721AssetData,
                );
                expect(newBalance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
            });
            it('should return an allowance of 0 when no approval is set', async () => {
                const [, newAllowance] = await orderValidator.getBalanceAndAllowance.callAsync(
                    makerAddress,
                    erc721AssetData,
                );
                expect(newAllowance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
            });
            it('should return a balance of 1 when the tokenId is owned by target', async () => {
                await web3Wrapper.awaitTransactionSuccessAsync(
                    await erc721Token.mint.sendTransactionAsync(makerAddress, tokenId),
                    constants.AWAIT_TRANSACTION_MINED_MS,
                );
                const [newBalance] = await orderValidator.getBalanceAndAllowance.callAsync(
                    makerAddress,
                    erc721AssetData,
                );
                expect(newBalance).to.be.bignumber.equal(ERC721_BALANCE);
            });
            it('should return an allowance of 1 when ERC721Proxy is approved for all', async () => {
                const isApproved = true;
                await web3Wrapper.awaitTransactionSuccessAsync(
                    await erc721Token.setApprovalForAll.sendTransactionAsync(erc721Proxy.address, isApproved, {
                        from: makerAddress,
                    }),
                    constants.AWAIT_TRANSACTION_MINED_MS,
                );
                const [, newAllowance] = await orderValidator.getBalanceAndAllowance.callAsync(
                    makerAddress,
                    erc721AssetData,
                );
                expect(newAllowance).to.be.bignumber.equal(ERC721_ALLOWANCE);
            });
            it('should return an allowance of 1 when ERC721Proxy is approved for specific tokenId', async () => {
                await web3Wrapper.awaitTransactionSuccessAsync(
                    await erc721Token.mint.sendTransactionAsync(makerAddress, tokenId),
                    constants.AWAIT_TRANSACTION_MINED_MS,
                );
                await web3Wrapper.awaitTransactionSuccessAsync(
                    await erc721Token.approve.sendTransactionAsync(erc721Proxy.address, tokenId, {
                        from: makerAddress,
                    }),
                    constants.AWAIT_TRANSACTION_MINED_MS,
                );
                const [, newAllowance] = await orderValidator.getBalanceAndAllowance.callAsync(
                    makerAddress,
                    erc721AssetData,
                );
                expect(newAllowance).to.be.bignumber.equal(ERC721_ALLOWANCE);
            });
        });
    });
    describe('getBalancesAndAllowances', () => {
        it('should return the correct balances and allowances when all values are 0', async () => {
            const [
                [erc20Balance, erc721Balance],
                [erc20Allowance, erc721Allowance],
            ] = await orderValidator.getBalancesAndAllowances.callAsync(makerAddress, [
                erc20AssetData,
                erc721AssetData,
            ]);
            expect(erc20Balance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
            expect(erc721Balance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
            expect(erc20Allowance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
            expect(erc721Allowance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
        });
        it('should return the correct balances and allowances when balances and allowances are non-zero', async () => {
            const balance = new BigNumber(123);
            const allowance = new BigNumber(456);
            await web3Wrapper.awaitTransactionSuccessAsync(
                await erc20Token.setBalance.sendTransactionAsync(makerAddress, balance),
                constants.AWAIT_TRANSACTION_MINED_MS,
            );
            await web3Wrapper.awaitTransactionSuccessAsync(
                await erc20Token.approve.sendTransactionAsync(erc20Proxy.address, allowance, {
                    from: makerAddress,
                }),
                constants.AWAIT_TRANSACTION_MINED_MS,
            );
            await web3Wrapper.awaitTransactionSuccessAsync(
                await erc721Token.mint.sendTransactionAsync(makerAddress, tokenId),
                constants.AWAIT_TRANSACTION_MINED_MS,
            );
            await web3Wrapper.awaitTransactionSuccessAsync(
                await erc721Token.approve.sendTransactionAsync(erc721Proxy.address, tokenId, {
                    from: makerAddress,
                }),
                constants.AWAIT_TRANSACTION_MINED_MS,
            );
            const [
                [erc20Balance, erc721Balance],
                [erc20Allowance, erc721Allowance],
            ] = await orderValidator.getBalancesAndAllowances.callAsync(makerAddress, [
                erc20AssetData,
                erc721AssetData,
            ]);
            expect(erc20Balance).to.be.bignumber.equal(balance);
            expect(erc721Balance).to.be.bignumber.equal(ERC721_BALANCE);
            expect(erc20Allowance).to.be.bignumber.equal(allowance);
            expect(erc721Allowance).to.be.bignumber.equal(ERC721_ALLOWANCE);
        });
    });
    describe('getTraderInfo', () => {
        beforeEach(async () => {
            signedOrder = await orderFactory.newSignedOrderAsync();
        });
        it('should return the correct info when no balances or allowances are set', async () => {
            const traderInfo = await orderValidator.getTraderInfo.callAsync(signedOrder, takerAddress);
            expect(traderInfo.makerBalance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
            expect(traderInfo.makerAllowance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
            expect(traderInfo.takerBalance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
            expect(traderInfo.takerAllowance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
            expect(traderInfo.makerZrxBalance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
            expect(traderInfo.makerZrxAllowance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
            expect(traderInfo.takerZrxBalance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
            expect(traderInfo.takerZrxAllowance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
        });
        it('should return the correct info when balances and allowances are set', async () => {
            const makerBalance = new BigNumber(123);
            const makerAllowance = new BigNumber(456);
            const makerZrxBalance = new BigNumber(789);
            const takerZrxAllowance = new BigNumber(987);
            await web3Wrapper.awaitTransactionSuccessAsync(
                await erc20Token.setBalance.sendTransactionAsync(makerAddress, makerBalance),
                constants.AWAIT_TRANSACTION_MINED_MS,
            );
            await web3Wrapper.awaitTransactionSuccessAsync(
                await erc20Token.approve.sendTransactionAsync(erc20Proxy.address, makerAllowance, {
                    from: makerAddress,
                }),
                constants.AWAIT_TRANSACTION_MINED_MS,
            );
            await web3Wrapper.awaitTransactionSuccessAsync(
                await zrxToken.setBalance.sendTransactionAsync(makerAddress, makerZrxBalance),
                constants.AWAIT_TRANSACTION_MINED_MS,
            );
            await web3Wrapper.awaitTransactionSuccessAsync(
                await zrxToken.approve.sendTransactionAsync(erc20Proxy.address, takerZrxAllowance, {
                    from: takerAddress,
                }),
                constants.AWAIT_TRANSACTION_MINED_MS,
            );
            await web3Wrapper.awaitTransactionSuccessAsync(
                await erc721Token.mint.sendTransactionAsync(takerAddress, tokenId),
                constants.AWAIT_TRANSACTION_MINED_MS,
            );
            await web3Wrapper.awaitTransactionSuccessAsync(
                await erc721Token.approve.sendTransactionAsync(erc721Proxy.address, tokenId, {
                    from: takerAddress,
                }),
                constants.AWAIT_TRANSACTION_MINED_MS,
            );
            const traderInfo = await orderValidator.getTraderInfo.callAsync(signedOrder, takerAddress);
            expect(traderInfo.makerBalance).to.be.bignumber.equal(makerBalance);
            expect(traderInfo.makerAllowance).to.be.bignumber.equal(makerAllowance);
            expect(traderInfo.takerBalance).to.be.bignumber.equal(ERC721_BALANCE);
            expect(traderInfo.takerAllowance).to.be.bignumber.equal(ERC721_ALLOWANCE);
            expect(traderInfo.makerZrxBalance).to.be.bignumber.equal(makerZrxBalance);
            expect(traderInfo.makerZrxAllowance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
            expect(traderInfo.takerZrxBalance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
            expect(traderInfo.takerZrxAllowance).to.be.bignumber.equal(takerZrxAllowance);
        });
    });
    describe('getTradersInfo', () => {
        beforeEach(async () => {
            signedOrder = await orderFactory.newSignedOrderAsync();
            signedOrder2 = await orderFactory.newSignedOrderAsync({
                takerAssetData: assetDataUtils.encodeERC721AssetData(erc721Token.address, tokenId2),
            });
        });
        it('should return the correct info when no balances or allowances have been set', async () => {
            const orders = [signedOrder, signedOrder2];
            const takers = [takerAddress, takerAddress];
            const [traderInfo1, traderInfo2] = await orderValidator.getTradersInfo.callAsync(orders, takers);
            expect(traderInfo1.makerBalance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
            expect(traderInfo1.makerAllowance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
            expect(traderInfo1.takerBalance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
            expect(traderInfo1.takerAllowance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
            expect(traderInfo1.makerZrxBalance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
            expect(traderInfo1.makerZrxAllowance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
            expect(traderInfo1.takerZrxBalance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
            expect(traderInfo1.takerZrxAllowance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
            expect(traderInfo2.makerBalance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
            expect(traderInfo2.makerAllowance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
            expect(traderInfo2.takerBalance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
            expect(traderInfo2.takerAllowance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
            expect(traderInfo2.makerZrxBalance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
            expect(traderInfo2.makerZrxAllowance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
            expect(traderInfo2.takerZrxBalance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
            expect(traderInfo2.takerZrxAllowance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
        });
        it('should return the correct info when balances and allowances are set', async () => {
            const makerBalance = new BigNumber(123);
            const makerAllowance = new BigNumber(456);
            const makerZrxBalance = new BigNumber(789);
            const takerZrxAllowance = new BigNumber(987);
            await web3Wrapper.awaitTransactionSuccessAsync(
                await erc20Token.setBalance.sendTransactionAsync(makerAddress, makerBalance),
                constants.AWAIT_TRANSACTION_MINED_MS,
            );
            await web3Wrapper.awaitTransactionSuccessAsync(
                await erc20Token.approve.sendTransactionAsync(erc20Proxy.address, makerAllowance, {
                    from: makerAddress,
                }),
                constants.AWAIT_TRANSACTION_MINED_MS,
            );
            await web3Wrapper.awaitTransactionSuccessAsync(
                await zrxToken.setBalance.sendTransactionAsync(makerAddress, makerZrxBalance),
                constants.AWAIT_TRANSACTION_MINED_MS,
            );
            await web3Wrapper.awaitTransactionSuccessAsync(
                await zrxToken.approve.sendTransactionAsync(erc20Proxy.address, takerZrxAllowance, {
                    from: takerAddress,
                }),
                constants.AWAIT_TRANSACTION_MINED_MS,
            );
            const isApproved = true;
            await web3Wrapper.awaitTransactionSuccessAsync(
                await erc721Token.setApprovalForAll.sendTransactionAsync(erc721Proxy.address, isApproved, {
                    from: takerAddress,
                }),
                constants.AWAIT_TRANSACTION_MINED_MS,
            );
            await web3Wrapper.awaitTransactionSuccessAsync(
                await erc721Token.mint.sendTransactionAsync(takerAddress, tokenId2),
                constants.AWAIT_TRANSACTION_MINED_MS,
            );
            const orders = [signedOrder, signedOrder2];
            const takers = [takerAddress, takerAddress];
            const [traderInfo1, traderInfo2] = await orderValidator.getTradersInfo.callAsync(orders, takers);

            expect(traderInfo1.makerBalance).to.be.bignumber.equal(makerBalance);
            expect(traderInfo1.makerAllowance).to.be.bignumber.equal(makerAllowance);
            expect(traderInfo1.takerBalance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
            expect(traderInfo1.takerAllowance).to.be.bignumber.equal(ERC721_ALLOWANCE);
            expect(traderInfo1.makerZrxBalance).to.be.bignumber.equal(makerZrxBalance);
            expect(traderInfo1.makerZrxAllowance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
            expect(traderInfo1.takerZrxBalance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
            expect(traderInfo1.takerZrxAllowance).to.be.bignumber.equal(takerZrxAllowance);
            expect(traderInfo2.makerBalance).to.be.bignumber.equal(makerBalance);
            expect(traderInfo2.makerAllowance).to.be.bignumber.equal(makerAllowance);
            expect(traderInfo2.takerBalance).to.be.bignumber.equal(ERC721_BALANCE);
            expect(traderInfo2.takerAllowance).to.be.bignumber.equal(ERC721_ALLOWANCE);
            expect(traderInfo2.makerZrxBalance).to.be.bignumber.equal(makerZrxBalance);
            expect(traderInfo2.makerZrxAllowance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
            expect(traderInfo2.takerZrxBalance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
            expect(traderInfo2.takerZrxAllowance).to.be.bignumber.equal(takerZrxAllowance);
        });
    });
    describe('getOrderAndTraderInfo', () => {
        beforeEach(async () => {
            signedOrder = await orderFactory.newSignedOrderAsync();
        });
        it('should return the correct info when no balances or allowances are set', async () => {
            const [orderInfo, traderInfo] = await orderValidator.getOrderAndTraderInfo.callAsync(
                signedOrder,
                takerAddress,
            );
            const expectedOrderHash = orderHashUtils.getOrderHashHex(signedOrder);
            expect(orderInfo.orderStatus).to.be.equal(OrderStatus.FILLABLE);
            expect(orderInfo.orderHash).to.be.equal(expectedOrderHash);
            expect(orderInfo.orderTakerAssetFilledAmount).to.be.bignumber.equal(constants.ZERO_AMOUNT);
            expect(traderInfo.makerBalance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
            expect(traderInfo.makerAllowance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
            expect(traderInfo.takerBalance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
            expect(traderInfo.takerAllowance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
            expect(traderInfo.makerZrxBalance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
            expect(traderInfo.makerZrxAllowance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
            expect(traderInfo.takerZrxBalance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
            expect(traderInfo.takerZrxAllowance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
        });
        it('should return the correct info when balances and allowances are set', async () => {
            const makerBalance = new BigNumber(123);
            const makerAllowance = new BigNumber(456);
            const makerZrxBalance = new BigNumber(789);
            const takerZrxAllowance = new BigNumber(987);
            await web3Wrapper.awaitTransactionSuccessAsync(
                await erc20Token.setBalance.sendTransactionAsync(makerAddress, makerBalance),
                constants.AWAIT_TRANSACTION_MINED_MS,
            );
            await web3Wrapper.awaitTransactionSuccessAsync(
                await erc20Token.approve.sendTransactionAsync(erc20Proxy.address, makerAllowance, {
                    from: makerAddress,
                }),
                constants.AWAIT_TRANSACTION_MINED_MS,
            );
            await web3Wrapper.awaitTransactionSuccessAsync(
                await zrxToken.setBalance.sendTransactionAsync(makerAddress, makerZrxBalance),
                constants.AWAIT_TRANSACTION_MINED_MS,
            );
            await web3Wrapper.awaitTransactionSuccessAsync(
                await zrxToken.approve.sendTransactionAsync(erc20Proxy.address, takerZrxAllowance, {
                    from: takerAddress,
                }),
                constants.AWAIT_TRANSACTION_MINED_MS,
            );
            await web3Wrapper.awaitTransactionSuccessAsync(
                await erc721Token.mint.sendTransactionAsync(takerAddress, tokenId),
                constants.AWAIT_TRANSACTION_MINED_MS,
            );
            await web3Wrapper.awaitTransactionSuccessAsync(
                await erc721Token.approve.sendTransactionAsync(erc721Proxy.address, tokenId, {
                    from: takerAddress,
                }),
                constants.AWAIT_TRANSACTION_MINED_MS,
            );
            const [orderInfo, traderInfo] = await orderValidator.getOrderAndTraderInfo.callAsync(
                signedOrder,
                takerAddress,
            );
            const expectedOrderHash = orderHashUtils.getOrderHashHex(signedOrder);
            expect(orderInfo.orderStatus).to.be.equal(OrderStatus.FILLABLE);
            expect(orderInfo.orderHash).to.be.equal(expectedOrderHash);
            expect(orderInfo.orderTakerAssetFilledAmount).to.be.bignumber.equal(constants.ZERO_AMOUNT);
            expect(traderInfo.makerBalance).to.be.bignumber.equal(makerBalance);
            expect(traderInfo.makerAllowance).to.be.bignumber.equal(makerAllowance);
            expect(traderInfo.takerBalance).to.be.bignumber.equal(ERC721_BALANCE);
            expect(traderInfo.takerAllowance).to.be.bignumber.equal(ERC721_ALLOWANCE);
            expect(traderInfo.makerZrxBalance).to.be.bignumber.equal(makerZrxBalance);
            expect(traderInfo.makerZrxAllowance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
            expect(traderInfo.takerZrxBalance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
            expect(traderInfo.takerZrxAllowance).to.be.bignumber.equal(takerZrxAllowance);
        });
    });
    describe('getOrdersAndTradersInfo', () => {
        beforeEach(async () => {
            signedOrder = await orderFactory.newSignedOrderAsync();
            signedOrder2 = await orderFactory.newSignedOrderAsync({
                takerAssetData: assetDataUtils.encodeERC721AssetData(erc721Token.address, tokenId2),
            });
        });
        it('should return the correct info when no balances or allowances have been set', async () => {
            const orders = [signedOrder, signedOrder2];
            const takers = [takerAddress, takerAddress];
            const [
                [orderInfo1, orderInfo2],
                [traderInfo1, traderInfo2],
            ] = await orderValidator.getOrdersAndTradersInfo.callAsync(orders, takers);
            const expectedOrderHash1 = orderHashUtils.getOrderHashHex(signedOrder);
            const expectedOrderHash2 = orderHashUtils.getOrderHashHex(signedOrder2);
            expect(orderInfo1.orderStatus).to.be.equal(OrderStatus.FILLABLE);
            expect(orderInfo1.orderHash).to.be.equal(expectedOrderHash1);
            expect(orderInfo1.orderTakerAssetFilledAmount).to.be.bignumber.equal(constants.ZERO_AMOUNT);
            expect(orderInfo2.orderStatus).to.be.equal(OrderStatus.FILLABLE);
            expect(orderInfo2.orderHash).to.be.equal(expectedOrderHash2);
            expect(orderInfo2.orderTakerAssetFilledAmount).to.be.bignumber.equal(constants.ZERO_AMOUNT);
            expect(traderInfo1.makerBalance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
            expect(traderInfo1.makerAllowance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
            expect(traderInfo1.takerBalance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
            expect(traderInfo1.takerAllowance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
            expect(traderInfo1.makerZrxBalance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
            expect(traderInfo1.makerZrxAllowance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
            expect(traderInfo1.takerZrxBalance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
            expect(traderInfo1.takerZrxAllowance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
            expect(traderInfo2.makerBalance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
            expect(traderInfo2.makerAllowance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
            expect(traderInfo2.takerBalance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
            expect(traderInfo2.takerAllowance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
            expect(traderInfo2.makerZrxBalance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
            expect(traderInfo2.makerZrxAllowance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
            expect(traderInfo2.takerZrxBalance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
            expect(traderInfo2.takerZrxAllowance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
        });
        it('should return the correct info when balances and allowances are set', async () => {
            const makerBalance = new BigNumber(123);
            const makerAllowance = new BigNumber(456);
            const makerZrxBalance = new BigNumber(789);
            const takerZrxAllowance = new BigNumber(987);
            await web3Wrapper.awaitTransactionSuccessAsync(
                await erc20Token.setBalance.sendTransactionAsync(makerAddress, makerBalance),
                constants.AWAIT_TRANSACTION_MINED_MS,
            );
            await web3Wrapper.awaitTransactionSuccessAsync(
                await erc20Token.approve.sendTransactionAsync(erc20Proxy.address, makerAllowance, {
                    from: makerAddress,
                }),
                constants.AWAIT_TRANSACTION_MINED_MS,
            );
            await web3Wrapper.awaitTransactionSuccessAsync(
                await zrxToken.setBalance.sendTransactionAsync(makerAddress, makerZrxBalance),
                constants.AWAIT_TRANSACTION_MINED_MS,
            );
            await web3Wrapper.awaitTransactionSuccessAsync(
                await zrxToken.approve.sendTransactionAsync(erc20Proxy.address, takerZrxAllowance, {
                    from: takerAddress,
                }),
                constants.AWAIT_TRANSACTION_MINED_MS,
            );
            const isApproved = true;
            await web3Wrapper.awaitTransactionSuccessAsync(
                await erc721Token.setApprovalForAll.sendTransactionAsync(erc721Proxy.address, isApproved, {
                    from: takerAddress,
                }),
                constants.AWAIT_TRANSACTION_MINED_MS,
            );
            await web3Wrapper.awaitTransactionSuccessAsync(
                await erc721Token.mint.sendTransactionAsync(takerAddress, tokenId2),
                constants.AWAIT_TRANSACTION_MINED_MS,
            );
            const orders = [signedOrder, signedOrder2];
            const takers = [takerAddress, takerAddress];
            const [
                [orderInfo1, orderInfo2],
                [traderInfo1, traderInfo2],
            ] = await orderValidator.getOrdersAndTradersInfo.callAsync(orders, takers);
            const expectedOrderHash1 = orderHashUtils.getOrderHashHex(signedOrder);
            const expectedOrderHash2 = orderHashUtils.getOrderHashHex(signedOrder2);
            expect(orderInfo1.orderStatus).to.be.equal(OrderStatus.FILLABLE);
            expect(orderInfo1.orderHash).to.be.equal(expectedOrderHash1);
            expect(orderInfo1.orderTakerAssetFilledAmount).to.be.bignumber.equal(constants.ZERO_AMOUNT);
            expect(orderInfo2.orderStatus).to.be.equal(OrderStatus.FILLABLE);
            expect(orderInfo2.orderHash).to.be.equal(expectedOrderHash2);
            expect(orderInfo2.orderTakerAssetFilledAmount).to.be.bignumber.equal(constants.ZERO_AMOUNT);
            expect(traderInfo1.makerBalance).to.be.bignumber.equal(makerBalance);
            expect(traderInfo1.makerAllowance).to.be.bignumber.equal(makerAllowance);
            expect(traderInfo1.takerBalance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
            expect(traderInfo1.takerAllowance).to.be.bignumber.equal(ERC721_ALLOWANCE);
            expect(traderInfo1.makerZrxBalance).to.be.bignumber.equal(makerZrxBalance);
            expect(traderInfo1.makerZrxAllowance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
            expect(traderInfo1.takerZrxBalance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
            expect(traderInfo1.takerZrxAllowance).to.be.bignumber.equal(takerZrxAllowance);
            expect(traderInfo2.makerBalance).to.be.bignumber.equal(makerBalance);
            expect(traderInfo2.makerAllowance).to.be.bignumber.equal(makerAllowance);
            expect(traderInfo2.takerBalance).to.be.bignumber.equal(ERC721_BALANCE);
            expect(traderInfo2.takerAllowance).to.be.bignumber.equal(ERC721_ALLOWANCE);
            expect(traderInfo2.makerZrxBalance).to.be.bignumber.equal(makerZrxBalance);
            expect(traderInfo2.makerZrxAllowance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
            expect(traderInfo2.takerZrxBalance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
            expect(traderInfo2.takerZrxAllowance).to.be.bignumber.equal(takerZrxAllowance);
        });
    });
});
// tslint:disable:max-file-line-count