-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #388 from ZIMkaRU/feature/add-transaction-tax-repo…
…rt-v2 Add unit test for core look-up-trades fn
- Loading branch information
Showing
7 changed files
with
681 additions
and
0 deletions.
There are no files selected for viewing
56 changes: 56 additions & 0 deletions
56
workers/loc.api/sync/transaction.tax.report/helpers/__test__/helpers/get-mocked-trades.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
'use strict' | ||
|
||
const splitSymbolPairs = require( | ||
'bfx-report/workers/loc.api/helpers/split-symbol-pairs' | ||
) | ||
|
||
module.exports = (mockTrades, opts) => { | ||
const missingFields = { | ||
_id: 1, | ||
id: 1, | ||
orderID: 1, | ||
orderType: 'EXCHANGE LIMIT', | ||
orderPrice: null, | ||
maker: 1, | ||
fee: -0.5, | ||
feeCurrency: 'USD', | ||
subUserId: null, | ||
user_id: 1, | ||
|
||
firstSymb: null, | ||
lastSymb: null, | ||
firstSymbPriceUsd: null, | ||
lastSymbPriceUsd: null | ||
} | ||
|
||
return mockTrades.map((trade, i) => { | ||
const isAdditionalTrxMovements = opts?.isAdditionalTrxMovements ?? | ||
trade?.isAdditionalTrxMovements ?? | ||
trade?.isMovements ?? | ||
trade?.isLedgers | ||
const [firstSymb, lastSymb] = splitSymbolPairs(trade.symbol) | ||
|
||
return { | ||
...missingFields, | ||
|
||
isAdditionalTrxMovements, | ||
isMovements: !!trade?.isMovements, | ||
isLedgers: !!trade?.isLedgers, | ||
isTrades: !isAdditionalTrxMovements, | ||
_id: i + 1, | ||
id: i + 1, | ||
orderID: i + 1, | ||
orderPrice: trade.execPrice, | ||
firstSymb, | ||
lastSymb, | ||
firstSymbPriceUsd: lastSymb === 'USD' ? trade.execPrice : null, | ||
lastSymbPriceUsd: lastSymb === 'USD' ? 1 : null, | ||
|
||
...trade, | ||
|
||
mtsCreate: opts?.year | ||
? new Date(trade.mtsCreate).setUTCFullYear(opts?.year) | ||
: trade.mtsCreate | ||
} | ||
}) | ||
} |
13 changes: 13 additions & 0 deletions
13
workers/loc.api/sync/transaction.tax.report/helpers/__test__/helpers/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
'use strict' | ||
|
||
const { | ||
mockTradesForNextYear, | ||
mockTrades | ||
} = require('./mock-trades') | ||
const getMockedTrades = require('./get-mocked-trades') | ||
|
||
module.exports = { | ||
mockTradesForNextYear, | ||
mockTrades, | ||
getMockedTrades | ||
} |
113 changes: 113 additions & 0 deletions
113
workers/loc.api/sync/transaction.tax.report/helpers/__test__/helpers/mock-trades.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
'use strict' | ||
|
||
const mockTradesForNextYear = [ | ||
{ | ||
symbol: 'tUSTUSD', | ||
mtsCreate: Date.UTC(2024, 3, 27), | ||
execAmount: -200, | ||
execPrice: 0.98 | ||
}, | ||
{ | ||
isAdditionalTrxMovements: true, | ||
symbol: 'tBTCUSD', | ||
mtsCreate: Date.UTC(2024, 3, 1), | ||
execAmount: -1, | ||
execPrice: 41_000 | ||
}, | ||
{ | ||
symbol: 'tBTCUSD', | ||
mtsCreate: Date.UTC(2024, 2, 17), | ||
execAmount: -5, | ||
execPrice: 61_000 | ||
}, | ||
{ | ||
isAdditionalTrxMovements: true, | ||
symbol: 'tBTCUSD', | ||
mtsCreate: Date.UTC(2024, 1, 8), | ||
execAmount: -3, | ||
execPrice: 44_000 | ||
}, | ||
{ | ||
symbol: 'tBTCUSD', | ||
mtsCreate: Date.UTC(2024, 0, 14), | ||
execAmount: 2, | ||
execPrice: 48_000 | ||
} | ||
] | ||
const mockTrades = [ | ||
{ | ||
symbol: 'tUSTEUR', | ||
mtsCreate: Date.UTC(2023, 6, 21), | ||
execAmount: -100, | ||
execPrice: 0.9, | ||
firstSymbPriceUsd: 1.05, | ||
lastSymbPriceUsd: 0.95 | ||
}, | ||
{ | ||
symbol: 'tETHUST', | ||
mtsCreate: Date.UTC(2023, 5, 11), | ||
execAmount: -1, | ||
execPrice: 2800, | ||
firstSymbPriceUsd: 3_110, | ||
lastSymbPriceUsd: 1.11 | ||
}, | ||
{ | ||
symbol: 'tETHBTC', | ||
mtsCreate: Date.UTC(2023, 4, 22), | ||
execAmount: -1, | ||
execPrice: 0.055, | ||
firstSymbPriceUsd: 2_650, | ||
lastSymbPriceUsd: 48_000 | ||
}, | ||
{ | ||
symbol: 'tETHUSD', | ||
mtsCreate: Date.UTC(2023, 4, 10), | ||
execAmount: -1, | ||
execPrice: 2_000 | ||
}, | ||
{ | ||
symbol: 'tETHUSD', | ||
mtsCreate: Date.UTC(2023, 3, 10), | ||
execAmount: -2, | ||
execPrice: 3_200 | ||
}, | ||
{ | ||
isAdditionalTrxMovements: true, | ||
symbol: 'tETHUSD', | ||
mtsCreate: Date.UTC(2023, 3, 2), | ||
execAmount: -2, | ||
execPrice: 3000 | ||
}, | ||
{ | ||
symbol: 'tETHBTC', | ||
mtsCreate: Date.UTC(2023, 2, 23), | ||
execAmount: 10, | ||
execPrice: 0.05, | ||
firstSymbPriceUsd: 2_601, | ||
lastSymbPriceUsd: 50_000 | ||
}, | ||
{ | ||
symbol: 'tBTCUSD', | ||
mtsCreate: Date.UTC(2023, 2, 3), | ||
execAmount: -2, | ||
execPrice: 33_000 | ||
}, | ||
{ | ||
isAdditionalTrxMovements: true, | ||
symbol: 'tBTCUSD', | ||
mtsCreate: Date.UTC(2023, 1, 5), | ||
execAmount: 20, | ||
execPrice: 43_000 | ||
}, | ||
{ | ||
symbol: 'tBTCUSD', | ||
mtsCreate: Date.UTC(2023, 0, 10), | ||
execAmount: 3, | ||
execPrice: 20_000 | ||
} | ||
] | ||
|
||
module.exports = { | ||
mockTradesForNextYear, | ||
mockTrades | ||
} |
Oops, something went wrong.