|
| 1 | +const getAssets = require('./get-assets'); |
| 2 | + |
| 3 | +const v1EventArgs = { |
| 4 | + maker: '0x0035fc5208ef989c28d47e552e92b0c507d2b318', |
| 5 | + taker: '0x0e0f53a08d17767e6c07e2e7438f99d6ab331fa1', |
| 6 | + feeRecipient: '0x0000000000000000000000000000000000000000', |
| 7 | + makerToken: '0xe41d2489571d322189246dafa5ebde1f4699f498', |
| 8 | + takerToken: '0x2956356cd2a2bf3202f771f50d3d14a367b48070', |
| 9 | + filledMakerTokenAmount: 3.81909940372739e19, |
| 10 | + filledTakerTokenAmount: 20000000000000000.0, |
| 11 | + paidMakerFee: 0, |
| 12 | + paidTakerFee: 0, |
| 13 | + tokens: '0xba6d84bb63fd28b7ca98ab0edf677fadd1354e572c830880c5ed0a2a0ff0cadb', |
| 14 | + orderHash: |
| 15 | + '0x456517032f248eea8d9fb390c0207f5c1ceec4cca65df4ac36d3f3671f5f3f19', |
| 16 | +}; |
| 17 | + |
| 18 | +it('should get assets for V1 event args', () => { |
| 19 | + const assets = getAssets(v1EventArgs, 1); |
| 20 | + |
| 21 | + expect(assets).toEqual([ |
| 22 | + { |
| 23 | + actor: 0, |
| 24 | + amount: 38190994037273900000, |
| 25 | + tokenAddress: '0xe41d2489571d322189246dafa5ebde1f4699f498', |
| 26 | + tokenResolved: false, |
| 27 | + tokenType: 0, |
| 28 | + }, |
| 29 | + { |
| 30 | + actor: 1, |
| 31 | + amount: 20000000000000000, |
| 32 | + tokenAddress: '0x2956356cd2a2bf3202f771f50d3d14a367b48070', |
| 33 | + tokenResolved: false, |
| 34 | + tokenType: 0, |
| 35 | + }, |
| 36 | + ]); |
| 37 | +}); |
| 38 | + |
| 39 | +it('should return null when protocol is not recognised', () => { |
| 40 | + const assets = getAssets(v1EventArgs, 3); |
| 41 | + |
| 42 | + expect(assets).toBeNull(); |
| 43 | +}); |
| 44 | + |
| 45 | +it('should get assets for V2 event with only ERC-20 assets', () => { |
| 46 | + const eventArgs = { |
| 47 | + makerAddress: '0xf6da68519f78b0d0bc93c701e86affcb75c92428', |
| 48 | + feeRecipientAddress: '0xc370d2a5920344aa6b7d8d11250e3e861434cbdd', |
| 49 | + takerAddress: '0xf6da68519f78b0d0bc93c701e86affcb75c92428', |
| 50 | + senderAddress: '0xf6da68519f78b0d0bc93c701e86affcb75c92428', |
| 51 | + makerAssetFilledAmount: 10000000000000000.0, |
| 52 | + takerAssetFilledAmount: 1e18, |
| 53 | + makerFeePaid: 0, |
| 54 | + takerFeePaid: 0, |
| 55 | + orderHash: |
| 56 | + '0x97028d45c7b356db01282bff9c11ccac6dcd73c64474c2a94c2154d3fcd0d343', |
| 57 | + makerAssetData: |
| 58 | + '0xf47261b0000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', |
| 59 | + takerAssetData: |
| 60 | + '0xf47261b0000000000000000000000000e41d2489571d322189246dafa5ebde1f4699f498', |
| 61 | + }; |
| 62 | + const assets = getAssets(eventArgs, 2); |
| 63 | + |
| 64 | + expect(assets).toEqual([ |
| 65 | + { |
| 66 | + actor: 0, |
| 67 | + amount: 10000000000000000, |
| 68 | + tokenAddress: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', |
| 69 | + tokenResolved: false, |
| 70 | + tokenType: 0, |
| 71 | + }, |
| 72 | + { |
| 73 | + actor: 1, |
| 74 | + amount: 1000000000000000000, |
| 75 | + tokenAddress: '0xe41d2489571d322189246dafa5ebde1f4699f498', |
| 76 | + tokenResolved: false, |
| 77 | + tokenType: 0, |
| 78 | + }, |
| 79 | + ]); |
| 80 | +}); |
| 81 | + |
| 82 | +it('should get assets for V2 event with mixed assets', () => { |
| 83 | + const eventArgs = { |
| 84 | + makerAddress: '0xdcae967431fb51aa7453ec6c06fa544c25e0f1ff', |
| 85 | + feeRecipientAddress: '0xb0d7398d779ee9ffc727d2d5b045a5b441da8233', |
| 86 | + takerAddress: '0x76481caa104b5f6bccb540dae4cefaf1c398ebea', |
| 87 | + senderAddress: '0x76481caa104b5f6bccb540dae4cefaf1c398ebea', |
| 88 | + makerAssetFilledAmount: 1, |
| 89 | + takerAssetFilledAmount: 5000000000000000.0, |
| 90 | + makerFeePaid: 0, |
| 91 | + takerFeePaid: 0, |
| 92 | + orderHash: |
| 93 | + '0x9d67732167403eda67f8e34fa6ebb85f5c1e833c217f6c5ba4694eef8e0f461c', |
| 94 | + makerAssetData: |
| 95 | + '0x02571792000000000000000000000000bdaed67214641b7eda3bf8d7431c3ae5fc46f46600000000000000000000000000000000000000000000000000000000000000a3', |
| 96 | + takerAssetData: |
| 97 | + '0xf47261b0000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', |
| 98 | + }; |
| 99 | + const assets = getAssets(eventArgs, 2); |
| 100 | + |
| 101 | + expect(assets).toEqual([ |
| 102 | + { |
| 103 | + actor: 0, |
| 104 | + amount: 1, |
| 105 | + tokenAddress: '0xbdaed67214641b7eda3bf8d7431c3ae5fc46f466', |
| 106 | + tokenId: 163, |
| 107 | + tokenResolved: false, |
| 108 | + tokenType: 1, |
| 109 | + }, |
| 110 | + { |
| 111 | + actor: 1, |
| 112 | + amount: 5000000000000000, |
| 113 | + tokenAddress: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', |
| 114 | + tokenResolved: false, |
| 115 | + tokenType: 0, |
| 116 | + }, |
| 117 | + ]); |
| 118 | +}); |
| 119 | + |
| 120 | +it('should get assets for V2 event with multi-asset data', () => { |
| 121 | + const eventArgs = { |
| 122 | + makerAddress: '0x9193ed9cbf94d109667c3d5659caffe21b4197bc', |
| 123 | + feeRecipientAddress: '0x0000000000000000000000000000000000000000', |
| 124 | + takerAddress: '0xdf1bc6498338135de5ffdbcb98817d81e2665912', |
| 125 | + senderAddress: '0xdf1bc6498338135de5ffdbcb98817d81e2665912', |
| 126 | + makerAssetFilledAmount: 1, |
| 127 | + takerAssetFilledAmount: 46810278916603824.0, |
| 128 | + makerFeePaid: 0, |
| 129 | + takerFeePaid: 0, |
| 130 | + orderHash: |
| 131 | + '0xc9a69b17a479155016a724a250a6093903bcaafa318e757eab2c7fc6d5ca3edd', |
| 132 | + makerAssetData: |
| 133 | + '0x94cfcdd7000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000078c597355c0000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000024f47261b000000000000000000000000009adf3339867a53e5cb4df020cfa2d8a65663d65000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000024f47261b000000000000000000000000007eee91261f846b19853144aa55f06acba0f29b900000000000000000000000000000000000000000000000000000000', |
| 134 | + takerAssetData: |
| 135 | + '0xf47261b000000000000000000000000053b04999c1ff2d77fcdde98935bb936a67209e4c', |
| 136 | + }; |
| 137 | + const assets = getAssets(eventArgs, 2); |
| 138 | + |
| 139 | + expect(assets).toEqual([ |
| 140 | + { |
| 141 | + actor: 0, |
| 142 | + amount: 0, |
| 143 | + tokenAddress: '0x09adf3339867a53e5cb4df020cfa2d8a65663d65', |
| 144 | + tokenResolved: false, |
| 145 | + tokenType: 0, |
| 146 | + }, |
| 147 | + { |
| 148 | + actor: 0, |
| 149 | + amount: 518711096668, |
| 150 | + tokenAddress: '0x07eee91261f846b19853144aa55f06acba0f29b9', |
| 151 | + tokenResolved: false, |
| 152 | + tokenType: 0, |
| 153 | + }, |
| 154 | + { |
| 155 | + actor: 1, |
| 156 | + amount: 46810278916603820, |
| 157 | + tokenAddress: '0x53b04999c1ff2d77fcdde98935bb936a67209e4c', |
| 158 | + tokenResolved: false, |
| 159 | + tokenType: 0, |
| 160 | + }, |
| 161 | + ]); |
| 162 | +}); |
| 163 | + |
| 164 | +it('should return null when one of the assets data is corrupt', () => { |
| 165 | + const eventArgs = { |
| 166 | + makerAddress: '0x9193ed9cbf94d109667c3d5659caffe21b4197bc', |
| 167 | + feeRecipientAddress: '0x0000000000000000000000000000000000000000', |
| 168 | + takerAddress: '0xdf1bc6498338135de5ffdbcb98817d81e2665912', |
| 169 | + senderAddress: '0xdf1bc6498338135de5ffdbcb98817d81e2665912', |
| 170 | + makerAssetFilledAmount: 1, |
| 171 | + takerAssetFilledAmount: 46810278916603824.0, |
| 172 | + makerFeePaid: 0, |
| 173 | + takerFeePaid: 0, |
| 174 | + orderHash: |
| 175 | + '0xc9a69b17a479155016a724a250a6093903bcaafa318e757eab2c7fc6d5ca3edd', |
| 176 | + makerAssetData: 'fubar', |
| 177 | + takerAssetData: |
| 178 | + '0xf47261b000000000000000000000000053b04999c1ff2d77fcdde98935bb936a67209e4c', |
| 179 | + }; |
| 180 | + const assets = getAssets(eventArgs, 2); |
| 181 | + |
| 182 | + expect(assets).toBeNull(); |
| 183 | +}); |
0 commit comments