aboutsummaryrefslogtreecommitdiffstats
path: root/packages/pipeline/test/parsers/bloxy/index_test.ts
blob: 2b8d68f98808a61b2f98e051fd1c5f64f0cb4eff (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
// tslint:disable:custom-no-magic-numbers
import { BigNumber } from '@0x/utils';
import * as chai from 'chai';
import 'mocha';
import * as R from 'ramda';

import { BLOXY_DEX_TRADES_URL, BloxyTrade } from '../../../src/data_sources/bloxy';
import { DexTrade } from '../../../src/entities';
import { _parseBloxyTrade } from '../../../src/parsers/bloxy';
import { _convertToExchangeFillEvent } from '../../../src/parsers/events';
import { chaiSetup } from '../../utils/chai_setup';

chaiSetup.configure();
const expect = chai.expect;

const baseInput: BloxyTrade = {
    tx_hash: '0xb93a7faf92efbbb5405c9a73cd4efd99702fe27c03ff22baee1f1b1e37b3a0bf',
    tx_time: '2018-11-21T09:06:28.000+00:00',
    tx_date: '2018-11-21',
    tx_sender: '0x00923b9a074762b93650716333b3e1473a15048e',
    smart_contract_id: 7091917,
    smart_contract_address: '0x818e6fecd516ecc3849daf6845e3ec868087b755',
    contract_type: 'DEX/Kyber Network Proxy',
    maker: '0x0000000000000000000000000000000000000001',
    taker: '0x0000000000000000000000000000000000000002',
    amountBuy: 1.011943163078103,
    makerFee: 38.912083,
    buyCurrencyId: 1,
    buySymbol: 'ETH',
    amountSell: 941.4997928436911,
    takerFee: 100.39,
    sellCurrencyId: 16610,
    sellSymbol: 'ELF',
    maker_annotation: 'random annotation',
    taker_annotation: 'random other annotation',
    protocol: 'Kyber Network Proxy',
    buyAddress: '0xbf2179859fc6d5bee9bf9158632dc51678a4100d',
    sellAddress: '0xbf2179859fc6d5bee9bf9158632dc51678a4100e',
};

const baseExpected: DexTrade = {
    sourceUrl: BLOXY_DEX_TRADES_URL,
    txHash: '0xb93a7faf92efbbb5405c9a73cd4efd99702fe27c03ff22baee1f1b1e37b3a0bf',
    txTimestamp: 1542791188000,
    txDate: '2018-11-21',
    txSender: '0x00923b9a074762b93650716333b3e1473a15048e',
    smartContractId: 7091917,
    smartContractAddress: '0x818e6fecd516ecc3849daf6845e3ec868087b755',
    contractType: 'DEX/Kyber Network Proxy',
    maker: '0x0000000000000000000000000000000000000001',
    taker: '0x0000000000000000000000000000000000000002',
    amountBuy: new BigNumber('1.011943163078103'),
    makerFeeAmount: new BigNumber('38.912083'),
    buyCurrencyId: 1,
    buySymbol: 'ETH',
    amountSell: new BigNumber('941.4997928436911'),
    takerFeeAmount: new BigNumber('100.39'),
    sellCurrencyId: 16610,
    sellSymbol: 'ELF',
    makerAnnotation: 'random annotation',
    takerAnnotation: 'random other annotation',
    protocol: 'Kyber Network Proxy',
    buyAddress: '0xbf2179859fc6d5bee9bf9158632dc51678a4100d',
    sellAddress: '0xbf2179859fc6d5bee9bf9158632dc51678a4100e',
};

interface TestCase {
    input: BloxyTrade;
    expected: DexTrade;
}

const testCases: TestCase[] = [
    {
        input: baseInput,
        expected: baseExpected,
    },
    {
        input: R.merge(baseInput, { buyAddress: null, sellAddress: null }),
        expected: R.merge(baseExpected, { buyAddress: null, sellAddress: null }),
    },
    {
        input: R.merge(baseInput, {
            buySymbol:
                'RING\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000',
        }),
        expected: R.merge(baseExpected, { buySymbol: 'RING' }),
    },
];

describe('bloxy', () => {
    describe('_parseBloxyTrade', () => {
        for (const [i, testCase] of testCases.entries()) {
            it(`converts BloxyTrade to DexTrade entity (${i + 1}/${testCases.length})`, () => {
                const actual = _parseBloxyTrade(testCase.input);
                expect(actual).deep.equal(testCase.expected);
            });
        }
    });
});