Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release version to master #401

Merged
merged 182 commits into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
182 commits
Select commit Hold shift + click to select a range
d8a5b50
Add TransactionTaxReport service type
ZIMkaRU May 21, 2024
a97d30a
Add TransactionTaxReport service
ZIMkaRU May 21, 2024
c305738
Add TransactionTaxReport service into di
ZIMkaRU May 21, 2024
c9e5984
Add data consistency checker for TransactionTaxReport
ZIMkaRU May 21, 2024
bffe544
Add params schema for TransactionTaxReport
ZIMkaRU May 21, 2024
140b0d1
Add getTransactionTaxReport entrypoint to main service
ZIMkaRU May 21, 2024
e612133
Add makeTrxTaxReportInBackground entrypoint to main service
ZIMkaRU May 21, 2024
112a580
Add getTransactionTaxReportFile entrypoint to main service
ZIMkaRU May 21, 2024
3f25cb9
Add report file job data for TransactionTaxReport
ZIMkaRU May 21, 2024
5e285ba
Add ability to send ws event when trx tax report generated
ZIMkaRU May 21, 2024
e7b2f9d
Merge pull request #380 from ZIMkaRU/feature/add-transaction-tax-repo…
ezewer May 21, 2024
e713966
Add exactUsdValue field to ledgers, trades, movements tables
ZIMkaRU May 22, 2024
2617430
Add v41 db migration
ZIMkaRU May 22, 2024
2113fcd
Cleanup v31 db migration
ZIMkaRU May 22, 2024
6aa4483
Merge pull request #381 from ZIMkaRU/feature/add-exact-usd-value-fiel…
ezewer May 23, 2024
d39d0b9
Add ability to return exactUsdValue and _id for movements
ZIMkaRU May 22, 2024
4a06bed
Add helper to remap movements
ZIMkaRU May 22, 2024
3ee7a6d
Add helper to remap trades
ZIMkaRU May 22, 2024
ce89422
Add ability to fetch transactions
ZIMkaRU May 22, 2024
2a30f18
Add collection flags to trx entries
ZIMkaRU May 23, 2024
3753a31
Improve pair price naming in usd
ZIMkaRU May 24, 2024
f8b6da5
Merge pull request #382 from ZIMkaRU/feature/add-transaction-tax-repo…
ezewer May 24, 2024
aec5ba7
Speed up back iteration
ZIMkaRU May 27, 2024
4a53ea3
Add utility to push large array into array
ZIMkaRU May 27, 2024
4ee6760
Add CurrencyConversionError class
ZIMkaRU May 27, 2024
604c341
Add CurrencyPairSeparationError class
ZIMkaRU May 27, 2024
7f12b5b
Add core fn for lookup trx with realized or unrealized profit
ZIMkaRU May 27, 2024
b3bdb09
Implement main flow for lookup trx with required start-end
ZIMkaRU May 27, 2024
0d055bf
Merge pull request #383 from ZIMkaRU/feature/add-transaction-tax-repo…
ezewer May 30, 2024
f3bc3ae
Add priority currency list
ZIMkaRU Jun 17, 2024
161d0fe
Add ability to fetch pub trades
ZIMkaRU Jun 17, 2024
3be36fc
Add ability to get trx map by ccy
ZIMkaRU Jun 17, 2024
d9f0ffa
Add ability to find pub trades with binary search
ZIMkaRU Jun 18, 2024
e1d3513
Add ability to get pub trade price
ZIMkaRU Jun 18, 2024
c5789eb
Implement trx price calculator
ZIMkaRU Jun 19, 2024
8a675d7
Provide TrxPriceCalculator instances for ccy conv
ZIMkaRU Jun 19, 2024
5fd18cf
Calc price using TrxPriceCalculator instances
ZIMkaRU Jun 19, 2024
04e9fa2
Add ccy calculator setter
ZIMkaRU Jun 19, 2024
1d1d00e
Update exactUsdValue in colls after fetching
ZIMkaRU Jun 19, 2024
95f5b82
Add PubTradeFindForTrxTaxError error class
ZIMkaRU Jun 19, 2024
71a1d89
Add PubTradePriceFindForTrxTaxError error class
ZIMkaRU Jun 19, 2024
431c53d
Fix trx price calculator
ZIMkaRU Jun 20, 2024
df29b29
Fix trade usd price calc when remapping
ZIMkaRU Jun 20, 2024
79716b7
Fix movement usd price calc when remapping
ZIMkaRU Jun 20, 2024
c6512a5
Improve convert currencies flow
ZIMkaRU Jun 20, 2024
7229486
Merge pull request #384 from ZIMkaRU/feature/add-transaction-tax-repo…
ezewer Jun 20, 2024
00b0ce7
Add interrupter factory
ZIMkaRU Jun 24, 2024
0142633
Add InterrupterFactory service type
ZIMkaRU Jun 24, 2024
2b198ae
Add InterrupterFactory service into di
ZIMkaRU Jun 24, 2024
8d20289
Add ability to process interrupters on sign-out
ZIMkaRU Jun 24, 2024
1045b30
Add interrupter into lookUpTrades helper
ZIMkaRU Jun 24, 2024
c588f8a
Add ability to interrupt trx tax report
ZIMkaRU Jun 24, 2024
5ff92a6
Set name into sync interrupter
ZIMkaRU Jun 24, 2024
3f3a8a9
Add interruptOperations endpoint
ZIMkaRU Jun 24, 2024
868a594
Add params schema for interruptOperations endpoint
ZIMkaRU Jun 24, 2024
f7331f6
Implement interruption ability in BfxApiRouter service
ZIMkaRU Jun 24, 2024
37ab0fa
Turn off interrupter for full snapshot report csv writer
ZIMkaRU Jun 24, 2024
a44b9a8
Turn off interrupter for full tax report csv writer
ZIMkaRU Jun 24, 2024
34ca331
Turn off interrupter for sub.account.api.data service
ZIMkaRU Jun 24, 2024
6ff759a
Merge pull request #385 from ZIMkaRU/feature/add-transaction-tax-repo…
ezewer Jun 24, 2024
4012dd9
Use bignumber.js in remapping trades
ZIMkaRU Jun 25, 2024
487e5c9
Use bignumber.js in remapping movements
ZIMkaRU Jun 25, 2024
43ab36d
Use bignumber.js in price calculator
ZIMkaRU Jun 25, 2024
69f648c
Use bignumber.js in core trade lookup module
ZIMkaRU Jun 25, 2024
4625c71
Add bignumber.js to deps
ZIMkaRU Jun 25, 2024
6b755ac
Increase request timeout for dev mode
ZIMkaRU Jun 25, 2024
810c649
Expand mocked trade data
ZIMkaRU Jun 25, 2024
106825c
Fix getTrades test case to consider new mock data
ZIMkaRU Jun 25, 2024
515d3f6
Add test cases for getTransactionTaxReport method
ZIMkaRU Jun 25, 2024
855fca9
Add test case for getTransactionTaxReportFile method
ZIMkaRU Jun 25, 2024
700d700
Reverse pub-trades array for trx tax report for test env
ZIMkaRU Jun 25, 2024
43441ea
Add test coverage for trx tax report interruption
ZIMkaRU Jun 25, 2024
2f21dd9
Merge pull request #386 from ZIMkaRU/feature/add-transaction-tax-repo…
ezewer Jun 25, 2024
f4ef894
Merge pull request #387 from ZIMkaRU/feature/add-test-coverage-for-tr…
ezewer Jun 25, 2024
bd02ec4
Add mock trades
ZIMkaRU Jun 27, 2024
4e97f45
Add helper to get mocked trades
ZIMkaRU Jun 27, 2024
24d1cf6
Add test case to test buy trades with unrealized profit
ZIMkaRU Jun 27, 2024
3ad7e1d
Add test case to test sale trades with realized profit
ZIMkaRU Jun 27, 2024
d018a42
Add unit test for core look-up-trades fn
ZIMkaRU Jun 27, 2024
0ac2bb7
Merge pull request #388 from ZIMkaRU/feature/add-transaction-tax-repo…
ezewer Jun 27, 2024
cbdd2e6
Add _isExchange field to trades table model
ZIMkaRU Jun 28, 2024
a663131
Remap trades table via migration to fill _isExchange
ZIMkaRU Jun 28, 2024
e09775c
Fill trade _isExchange field after sync
ZIMkaRU Jun 28, 2024
b246964
Select exchange trades for trx tax report
ZIMkaRU Jun 28, 2024
d09ae7a
Improve PubTradeFindForTrxTaxError error log
ZIMkaRU Jun 28, 2024
3665213
Fix pub-trade price lookup for trx tax report
ZIMkaRU Jun 28, 2024
c1bde5b
Add pair separator if ccy length more than 3
ZIMkaRU Jun 28, 2024
58b15df
Merge pull request #389 from ZIMkaRU/feature/add-transaction-tax-repo…
ezewer Jul 1, 2024
48a506f
Merge pull request #390 from ZIMkaRU/bugfix/fix-pub-trade-price-looku…
ezewer Jul 1, 2024
bd6624c
Add _isInvoicePayOrder and _isAirdropOnWallet fields to db model
ZIMkaRU Jul 2, 2024
7e9c2d0
Remap ledgers table via migration to fill _isInvoicePayOrder and _isA…
ZIMkaRU Jul 2, 2024
a9c03ef
Fill ledger _isInvoicePayOrder and _isAirdropOnWallet fields after sync
ZIMkaRU Jul 2, 2024
3481671
Add new flags to deserialization
ZIMkaRU Jul 2, 2024
b7727e7
Provide ability to set where sql condition to sub-query
ZIMkaRU Jul 2, 2024
ff56334
Add _isInvoicePayOrder and _isAirdropOnWallet ledgers to movements
ZIMkaRU Jul 2, 2024
a73c0d3
Consider ledger entries with platform payments as a deposit for taxes
ZIMkaRU Jul 3, 2024
00ba285
Merge pull request #391 from ZIMkaRU/feature/add-transaction-tax-repo…
ezewer Jul 4, 2024
1295bd3
Return taxable payment flags with movements
ZIMkaRU Jul 4, 2024
b9e27e0
Remap movements with taxable payment flag
ZIMkaRU Jul 4, 2024
89163d8
Show taxable payment amounts in tax report
ZIMkaRU Jul 4, 2024
366f0fb
Add forex ccy triangulation to trx price calculator
ZIMkaRU Jul 8, 2024
52e1500
Place triangulation ccy at start
ZIMkaRU Jul 8, 2024
2497bc5
Add helper to get ccy pair for conversion
ZIMkaRU Jul 8, 2024
31c6c79
Add triangulation for trx currency conversion
ZIMkaRU Jul 8, 2024
3d83685
Fix ccy pair getter for conversion
ZIMkaRU Jul 9, 2024
d0002b5
Fix trx tax response for taxable payments
ZIMkaRU Jul 9, 2024
8b53cd1
Add trx tax types
ZIMkaRU Jul 9, 2024
c0b1a07
Add helper to get trx tax type
ZIMkaRU Jul 9, 2024
d472426
Add taxable payment flags to trx
ZIMkaRU Jul 9, 2024
9e609f7
Add trx tax type to response
ZIMkaRU Jul 9, 2024
a0157c3
Add margin funding payment to mocked trades
ZIMkaRU Jul 9, 2024
bf68de9
Add taxable payment check to tax test case
ZIMkaRU Jul 9, 2024
1d0f6d8
Add taxable payment to look-up-trades unit test
ZIMkaRU Jul 9, 2024
7d61010
Add trx tax type to getTransactionTaxReport test cases
ZIMkaRU Jul 9, 2024
ad5448e
Fix remap movements
ZIMkaRU Jul 10, 2024
dbb1af5
Fix isBuyTrx flag for lookup trades
ZIMkaRU Jul 10, 2024
c04636c
Fix lookup trades unit test
ZIMkaRU Jul 10, 2024
ced562d
Merge pull request #392 from ZIMkaRU/feature/show-taxable-payment-amo…
ezewer Jul 10, 2024
2dba8bc
Move users model to separate file
ZIMkaRU Jul 12, 2024
7b193ef
Move subAccounts model to separate file
ZIMkaRU Jul 15, 2024
2efc033
Move ledgers model to separate file
ZIMkaRU Jul 15, 2024
2628ccc
Move trades model to separate file
ZIMkaRU Jul 15, 2024
4c6a607
Move fundingTrades model to separate file
ZIMkaRU Jul 15, 2024
b22b265
Move publicTrades model to separate file
ZIMkaRU Jul 15, 2024
bfa4023
Move orders model to separate file
ZIMkaRU Jul 15, 2024
a0a6f75
Move movements model to separate file
ZIMkaRU Jul 15, 2024
fc91e4a
Move fundingOfferHistory model to separate file
ZIMkaRU Jul 15, 2024
709b65c
Move fundingLoanHistory model to separate file
ZIMkaRU Jul 15, 2024
9e66c55
Move fundingCreditHistory model to separate file
ZIMkaRU Jul 15, 2024
a64f2ed
Move positionsHistory model to separate file
ZIMkaRU Jul 15, 2024
41d6619
Move positionsSnapshot model to separate file
ZIMkaRU Jul 15, 2024
8ba57b0
Move logins model to separate file
ZIMkaRU Jul 15, 2024
3260dca
Move changeLogs model to separate file
ZIMkaRU Jul 15, 2024
3d1a946
Move payInvoiceList model to separate file
ZIMkaRU Jul 15, 2024
ad55ec8
Move tickersHistory model to separate file
ZIMkaRU Jul 16, 2024
20ae8c0
Move statusMessages model to separate file
ZIMkaRU Jul 16, 2024
bb369e5
Move publicCollsConf model to separate file
ZIMkaRU Jul 16, 2024
cf22903
Move symbol models to separate files
ZIMkaRU Jul 16, 2024
f64ba5c
Move candles model to separate file
ZIMkaRU Jul 16, 2024
79ddf93
Move sync service models to separate files
ZIMkaRU Jul 16, 2024
2245e0f
Merge pull request #393 from ZIMkaRU/refactoring/move-models-to-separ…
ezewer Jul 16, 2024
181c830
Add progress states
ZIMkaRU Jul 17, 2024
f57ecbf
Add ability to emit emitTrxTaxReportGenerationProgressToOne event
ZIMkaRU Jul 17, 2024
138b636
Emit base progress states for trx tax report generation
ZIMkaRU Jul 17, 2024
5879f9f
Add ability to calc total trx amount
ZIMkaRU Jul 18, 2024
d227ece
Emit progress for tax report based on trxs
ZIMkaRU Jul 18, 2024
be7f0ec
Merge pull request #394 from ZIMkaRU/feature/add-perc-progress-of-trx…
ezewer Jul 22, 2024
983ac53
Move ledgers sync-schema to separate file
ZIMkaRU Jul 22, 2024
cd32b6b
Move trades sync-schema to separate file
ZIMkaRU Jul 22, 2024
bef0187
Move fundingTrades sync-schema to separate file
ZIMkaRU Jul 22, 2024
7a21307
Move publicTrades sync-schema to separate file
ZIMkaRU Jul 22, 2024
2bf6c0b
Move statusMessages sync-schema to separate file
ZIMkaRU Jul 22, 2024
fd0c2a9
Move orders sync-schema to separate file
ZIMkaRU Jul 22, 2024
3e1f3b8
Move movements sync-schema to separate file
ZIMkaRU Jul 22, 2024
852acf9
Move fundingOfferHistory sync-schema to separate file
ZIMkaRU Jul 22, 2024
a84fa11
Move fundingLoanHistory sync-schema to separate file
ZIMkaRU Jul 22, 2024
e9603c1
Move fundingCreditHistory sync-schema to separate file
ZIMkaRU Jul 22, 2024
1e84909
Move positionsHistory sync-schema to separate file
ZIMkaRU Jul 22, 2024
a6765d7
Move positionsSnapshot sync-schema to separate file
ZIMkaRU Jul 22, 2024
2b1c864
Move logins sync-schema to separate file
ZIMkaRU Jul 23, 2024
9a7cade
Move changeLogs sync-schema to separate file
ZIMkaRU Jul 23, 2024
3853494
Move payInvoiceList sync-schema to separate file
ZIMkaRU Jul 23, 2024
5d46a3b
Move tickersHistory sync-schema to separate file
ZIMkaRU Jul 23, 2024
fbeb066
Move wallets sync-schema to separate file
ZIMkaRU Jul 23, 2024
c515d21
Move symbols sync-schema to separate file
ZIMkaRU Jul 23, 2024
5f8e698
Move mapSymbols sync-schema to separate file
ZIMkaRU Jul 23, 2024
7be533c
Move inactiveCurrencies sync-schema to separate file
ZIMkaRU Jul 23, 2024
b65452d
Move inactiveSymbols sync-schema to separate file
ZIMkaRU Jul 23, 2024
e4b2809
Move futures sync-schema to separate file
ZIMkaRU Jul 23, 2024
38ece4b
Move currencies sync-schema to separate file
ZIMkaRU Jul 23, 2024
1aa3602
Move marginCurrencyList sync-schema to separate file
ZIMkaRU Jul 23, 2024
b9a226d
Move candles sync-schema to separate file
ZIMkaRU Jul 23, 2024
ee25929
Merge pull request #395 from ZIMkaRU/refactoring/move-sync-schema-to-…
ezewer Jul 23, 2024
d796142
Fix tax report if bfx-api pub-trades endpoint does not return array
ZIMkaRU Jul 24, 2024
ae56a8c
Add process messages for trx tax report
ZIMkaRU Jul 25, 2024
eb0d587
Send ipc messages when trx tax report is ready
ZIMkaRU Jul 25, 2024
42a6a5d
Merge pull request #397 from ZIMkaRU/feature/add-ipc-messages-when-tr…
ezewer Jul 25, 2024
10f2357
Add source field to csv-pdf of tax report
ZIMkaRU Jul 29, 2024
3780a60
Merge pull request #398 from ZIMkaRU/feature/add-source-field-to-csv-…
ezewer Jul 30, 2024
69dfcaf
Bump version up to 4.18.0
ZIMkaRU Jul 31, 2024
944f5dd
Update bfx-report-ui sub-module
ZIMkaRU Jul 31, 2024
833b178
Merge pull request #399 from ZIMkaRU/feature/release-version
ezewer Jul 31, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bfx-report-ui
Submodule bfx-report-ui updated 74 files
+13 −9 package-lock.json
+1 −1 package.json
+28 −6 public/locales/en/translations.json
+1 −1 src/components/AffiliatesEarnings/AffiliatesEarnings.js
+3 −3 src/components/Auth/LoginOtp/LoginOtp.js
+19 −101 src/components/Derivatives/Derivatives.columns.js
+25 −109 src/components/FundingCreditHistory/FundingCreditHistory.columns.js
+22 −99 src/components/FundingLoanHistory/FundingLoanHistory.columns.js
+19 −90 src/components/FundingOfferHistory/FundingOfferHistory.columns.js
+1 −1 src/components/FundingPayment/FundingPayment.js
+0 −18 src/components/Header/Export/Export.container.js
+10 −11 src/components/Header/Export/Export.js
+1 −1 src/components/Header/Export/index.js
+35 −149 src/components/Invoices/Invoices.columns.js
+114 −189 src/components/Ledgers/Ledgers.columns.js
+1 −1 src/components/Ledgers/Ledgers.js
+80 −133 src/components/PublicFunding/PublicFunding.columns.js
+1 −1 src/components/PublicFunding/PublicFunding.js
+78 −137 src/components/PublicTrades/PublicTrades.columns.js
+1 −1 src/components/PublicTrades/PublicTrades.js
+1 −1 src/components/StakingPayments/StakingPayments.js
+0 −73 src/components/TaxReport/Result/Balances.columns.js
+0 −35 src/components/TaxReport/Result/Result.container.js
+0 −286 src/components/TaxReport/Result/Result.js
+0 −1 src/components/TaxReport/Result/index.js
+0 −38 src/components/TaxReport/Snapshot/Snapshot.container.js
+0 −132 src/components/TaxReport/Snapshot/Snapshot.js
+0 −19 src/components/TaxReport/Snapshot/Snapshots.props.js
+0 −1 src/components/TaxReport/Snapshot/index.js
+112 −0 src/components/TaxReport/TaxReport.columns.js
+0 −18 src/components/TaxReport/TaxReport.container.js
+28 −0 src/components/TaxReport/TaxReport.disclaimer.js
+111 −74 src/components/TaxReport/TaxReport.js
+33 −0 src/components/TaxReport/TaxReport.loader.js
+0 −7 src/components/TaxReport/TaxReport.props.js
+0 −7 src/components/TaxReport/TaxReport.sections.js
+61 −11 src/components/TaxReport/_TaxReport.scss
+1 −1 src/components/TaxReport/index.js
+55 −94 src/components/Tickers/Tickers.columns.js
+1 −1 src/components/Tickers/Tickers.js
+4 −13 src/state/query/saga.js
+2 −0 src/state/sync/saga.js
+18 −41 src/state/taxReport/actions.js
+10 −6 src/state/taxReport/constants.js
+45 −147 src/state/taxReport/reducer.js
+31 −52 src/state/taxReport/saga.js
+15 −42 src/state/taxReport/selectors.js
+2 −2 src/styles/themes/_dark.scss
+44 −45 src/ui/CollapsedTable/CollapsedTable.js
+1 −3 src/ui/CollapsedTable/index.js
+3 −0 src/ui/DataTable/_DataTable.scss
+0 −18 src/ui/DateFormatSelector/DateFormatSelector.container.js
+22 −26 src/ui/DateFormatSelector/DateFormatSelector.js
+0 −9 src/ui/DateFormatSelector/DateFormatSelector.props.js
+1 −3 src/ui/DateFormatSelector/index.js
+0 −13 src/ui/ExportButton/ExportButton.container.js
+0 −20 src/ui/ExportButton/ExportButton.js
+0 −3 src/ui/ExportButton/index.js
+1 −1 src/ui/JSONFormat/_JSONFormat.scss
+0 −18 src/ui/LangMenu/LangMenu.container.js
+15 −12 src/ui/LangMenu/LangMenu.js
+0 −8 src/ui/LangMenu/LangMenu.props.js
+1 −3 src/ui/LangMenu/index.js
+25 −10 src/ui/NavSwitcher/NavSwitcher.js
+0 −9 src/ui/NavSwitcher/NavSwitcher.props.js
+1 −3 src/ui/NavSwitcher/index.js
+0 −18 src/ui/ShowMilliseconds/ShowMilliseconds.container.js
+17 −25 src/ui/ShowMilliseconds/ShowMilliseconds.js
+0 −11 src/ui/ShowMilliseconds/ShowMilliseconds.props.js
+1 −3 src/ui/ShowMilliseconds/index.js
+32 −0 src/ui/TaxStrategySelector/TaxStrategySelector.js
+1 −0 src/ui/TaxStrategySelector/index.js
+12 −0 src/ui/utils.js
+50 −0 src/utils/columns.js
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bfx-reports-framework",
"version": "4.17.2",
"version": "4.18.0",
"description": "Bitfinex reports framework",
"main": "worker.js",
"license": "Apache-2.0",
Expand All @@ -10,6 +10,7 @@
"bfx-facs-scheduler": "git+https://github.com:bitfinexcom/bfx-facs-scheduler.git",
"bfx-report": "git+https://github.com/bitfinexcom/bfx-report.git",
"bfx-svc-boot-js": "https://github.com/bitfinexcom/bfx-svc-boot-js.git",
"bignumber.js": "9.1.2",
"csv": "5.5.3",
"grenache-nodejs-ws": "git+https://github.com:bitfinexcom/grenache-nodejs-ws.git",
"html-pdf": "3.0.1",
Expand Down
267 changes: 267 additions & 0 deletions test/7-interrupt-operations.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,267 @@
'use strict'

const {
setTimeout
} = require('node:timers/promises')
const path = require('node:path')
const request = require('supertest')
const { assert } = require('chai')

const {
stopEnvironment
} = require('bfx-report/test/helpers/helpers.boot')
const {
rmDB,
rmAllFiles
} = require('bfx-report/test/helpers/helpers.core')

const {
startEnvironment
} = require('./helpers/helpers.boot')
const {
getRServiceProxy,
emptyDB,
rmRf
} = require('./helpers/helpers.core')
const {
createMockRESTv2SrvWithDate
} = require('./helpers/helpers.mock-rest-v2')

process.env.NODE_CONFIG_DIR = path.join(__dirname, 'config')
const { app } = require('bfx-report-express')
const agent = request.agent(app)

const {
signUpTestCase,
getSyncProgressTestCase
} = require('./test-cases')

let wrkReportServiceApi = null
let mockRESTv2Srv = null

const basePath = '/api'
const tempDirPath = path.join(__dirname, '..', 'workers/loc.api/queue/temp')
const dbDirPath = path.join(__dirname, '..', 'db')
const reportFolderPath = path.join(__dirname, '..', 'report-files')
const date = new Date()
const end = date.getTime()
const start = (new Date()).setDate(date.getDate() - 90)

const apiKeys = {
apiKey: 'fake',
apiSecret: 'fake'
}
const email = '[email protected]'
const password = '123Qwerty'
const isSubAccount = false

describe('Interrupt operations', () => {
const params = {
processorQueue: null,
aggregatorQueue: null,
basePath,
auth: {
email,
password,
isSubAccount
},
apiKeys,
date,
end,
start
}
const auth = { token: 'user-token' }

before(async function () {
this.timeout(20000)

mockRESTv2Srv = createMockRESTv2SrvWithDate(start, end, 100)

await rmRf(reportFolderPath)
await rmAllFiles(tempDirPath, ['README.md'])
await rmDB(dbDirPath)
const env = await startEnvironment(false, false, 1)

wrkReportServiceApi = env.wrksReportServiceApi[0]
const rService = wrkReportServiceApi.grc_bfx.api
const rServiceProxy = getRServiceProxy(rService, {
async _getPublicTrades (targetMethod, context, argsList) {
await setTimeout(5000)

return Reflect.apply(...arguments)
}
})
rService._transactionTaxReport.rService = rServiceProxy
params.processorQueue = wrkReportServiceApi.lokue_processor.q
params.aggregatorQueue = wrkReportServiceApi.lokue_aggregator.q

await emptyDB()
})

after(async function () {
this.timeout(20000)

await stopEnvironment()
await rmDB(dbDirPath)
await rmAllFiles(tempDirPath, ['README.md'])
await rmRf(reportFolderPath)

try {
await mockRESTv2Srv.close()
} catch (err) { }
})

signUpTestCase(agent, params, (token) => { auth.token = token })

it('it should be successfully performed by the syncNow method', async function () {
this.timeout(60000)

const res = await agent
.post(`${basePath}/json-rpc`)
.type('json')
.send({
auth,
method: 'syncNow',
id: 5
})
.expect('Content-Type', /json/)
.expect(200)

assert.isObject(res.body)
assert.propertyVal(res.body, 'id', 5)
assert.isOk(
typeof res.body.result === 'number' ||
res.body.result === 'SYNCHRONIZATION_IS_STARTED'
)
})

getSyncProgressTestCase(agent, { basePath, auth })

it('it should interrupt transaction tax report', async function () {
this.timeout(60000)

const trxTaxReportPromise = agent
.post(`${basePath}/json-rpc`)
.type('json')
.send({
auth,
method: 'getTransactionTaxReport',
params: {
end,
start: start + (45 * 24 * 60 * 60 * 1000),
strategy: 'LIFO'
},
id: 5
})
.expect('Content-Type', /json/)
.expect(200)
const interruptOperationsPromise = setTimeout(1000).then(() => {
return agent
.post(`${basePath}/json-rpc`)
.type('json')
.send({
auth,
method: 'interruptOperations',
params: {
names: ['TRX_TAX_REPORT_INTERRUPTER']
},
id: 5
})
.expect('Content-Type', /json/)
.expect(200)
})

const [
trxTaxReport,
interruptOperations
] = await Promise.all([
trxTaxReportPromise,
interruptOperationsPromise
])

assert.isObject(interruptOperations.body)
assert.propertyVal(interruptOperations.body, 'id', 5)
assert.isBoolean(interruptOperations.body.result)
assert.isOk(interruptOperations.body.result)

assert.isObject(trxTaxReport.body)
assert.propertyVal(trxTaxReport.body, 'id', 5)
assert.isArray(trxTaxReport.body.result)
assert.lengthOf(trxTaxReport.body.result, 0)
})

it('it should not be successfully performed by the interruptOperations method', async function () {
const res = await agent
.post(`${basePath}/json-rpc`)
.type('json')
.send({
auth,
method: 'interruptOperations',
params: {
names: [
'FAKE_INTERRUPTER',
'TRX_TAX_REPORT_INTERRUPTER'
]
},
id: 5
})
.expect('Content-Type', /json/)
.expect(400)

assert.isObject(res.body)
assert.isObject(res.body.error)
assert.propertyVal(res.body.error, 'code', 400)
assert.propertyVal(res.body.error, 'message', 'Args params is not valid')
assert.propertyVal(res.body, 'id', 5)
})

it('it should interrupt transaction tax report after sign-out', async function () {
this.timeout(60000)

const trxTaxReportPromise = agent
.post(`${basePath}/json-rpc`)
.type('json')
.send({
auth,
method: 'getTransactionTaxReport',
params: {
end,
start: start + (45 * 24 * 60 * 60 * 1000),
strategy: 'LIFO'
},
id: 5
})
.expect('Content-Type', /json/)
.expect(200)
const signOutPromise = setTimeout(1000).then(() => {
return agent
.post(`${basePath}/json-rpc`)
.type('json')
.send({
auth,
method: 'signOut',
id: 5
})
.expect('Content-Type', /json/)
.expect(200)
})

const [
trxTaxReport,
signOut
] = await Promise.all([
trxTaxReportPromise,
signOutPromise
])

assert.isObject(signOut.body)
assert.propertyVal(signOut.body, 'id', 5)
assert.isBoolean(signOut.body.result)
assert.isOk(signOut.body.result)

assert.isObject(trxTaxReport.body)
assert.propertyVal(trxTaxReport.body, 'id', 5)
assert.isArray(trxTaxReport.body.result)
assert.lengthOf(trxTaxReport.body.result, 0)
})
})
4 changes: 3 additions & 1 deletion test/config/default.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
{
"app": {
"port": 31339,
"host": "127.0.0.1"
"host": "127.0.0.1",
"httpRpcTimeout": 600000,
"wsRpcTimeout": 3600000
},
"grenacheClient": {
"query": "rest:report:api",
Expand Down
Loading