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

Interrupt trx tax report after sign-out #378

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
106 commits
Select commit Hold shift + click to select a range
fda5cec
Add TransactionTaxReport service type
ZIMkaRU Mar 18, 2024
a262335
Add TransactionTaxReport service
ZIMkaRU Mar 18, 2024
013a0c3
Add TransactionTaxReport service into di
ZIMkaRU Mar 18, 2024
65d331d
Add data consistency checker for TransactionTaxReport
ZIMkaRU Mar 18, 2024
415e184
Add params schema for TransactionTaxReport
ZIMkaRU Mar 18, 2024
084a43b
Add getTransactionTaxReport entrypoint to main service
ZIMkaRU Mar 18, 2024
b99c94e
Add report file job data for TransactionTaxReport
ZIMkaRU Mar 18, 2024
cf609b0
Add getTransactionTaxReportFile entrypoint to main service
ZIMkaRU Mar 18, 2024
84b3f84
Add ability to get trades for trx tax report
ZIMkaRU Mar 19, 2024
095cf3c
Implement transaction tax report calc
ZIMkaRU Mar 21, 2024
219a03e
Consider trades in tax reports that were not closed in prev period
ZIMkaRU Mar 25, 2024
86dee5f
Add CurrencyConversionError class
ZIMkaRU Mar 25, 2024
fd317bf
Use CurrencyConversionError class
ZIMkaRU Mar 25, 2024
b1205ef
Add CurrencyPairSeparationError class
ZIMkaRU Mar 25, 2024
4e84ad1
Use CurrencyPairSeparationError class
ZIMkaRU Mar 25, 2024
a5d2408
Speed up back iteration
ZIMkaRU Mar 26, 2024
e11ab8b
Optimize trx tax report calc performance
ZIMkaRU Mar 26, 2024
1bb8ec9
Increase request timeouts for dev mode
ZIMkaRU Mar 26, 2024
7ad37ec
Prevent event loop locking for trx tax report
ZIMkaRU Mar 26, 2024
921c0bf
Use sale trx to declare into tax report
ZIMkaRU Apr 1, 2024
aaa1bce
Improve lookup buy trx with unrealized profit
ZIMkaRU Apr 2, 2024
3e91d51
Rework trx tax report to consider deposit-withdrawal
ZIMkaRU Apr 3, 2024
3a41322
Implement currency conversion for trx tax report
ZIMkaRU Apr 4, 2024
f20ba5f
Speed up currency conversion for trx tax report
ZIMkaRU Apr 5, 2024
ec92940
Add TrxTaxReportGenerationTimeoutError error class
ZIMkaRU Apr 5, 2024
40c6e8b
Use TrxTaxReportGenerationTimeoutError error class
ZIMkaRU Apr 5, 2024
13c8eba
Add ability to send ws event when trx tax report generated
ZIMkaRU Apr 8, 2024
7ed653c
Add ability to make trx tax report in background
ZIMkaRU Apr 8, 2024
2d03cbb
Add endpoint to make trx tax report in background
ZIMkaRU Apr 8, 2024
912d8e1
Improve data consistency checker for trx tax report
ZIMkaRU Apr 8, 2024
3a679d2
Move trades lookup fn into separate helper
ZIMkaRU Apr 8, 2024
ffc268c
Move get-trx-map-by-ccy fn into separate helper
ZIMkaRU Apr 8, 2024
14c902d
Move get-pub-trade-chunk-payloads fn into separate helper
ZIMkaRU Apr 8, 2024
fab0d2a
Fix amount column name for trx tax report file
ZIMkaRU Apr 8, 2024
bc41c2a
Fix asset column name for trx tax report file
ZIMkaRU Apr 8, 2024
9624094
Add helper to check params and set default
ZIMkaRU Apr 9, 2024
8f56d96
Add fifo strategy for trx tax report
ZIMkaRU Apr 9, 2024
1c80fb5
Add support tax strategy prop as enum field
ZIMkaRU Apr 9, 2024
304131d
Fix lookup trades logic
ZIMkaRU Apr 10, 2024
522a478
Fix movements consideration into trx tax report
ZIMkaRU Apr 10, 2024
714dcfc
Add mock trades for unit test coverage
ZIMkaRU Apr 15, 2024
2e954ed
Add mocked-trades getter for unit test coverage
ZIMkaRU Apr 15, 2024
b14117a
Add main test structure for trx tax lookUpTrades helper
ZIMkaRU Apr 15, 2024
53ea82b
Add test case checker for buy trades with unrealized profit
ZIMkaRU Apr 16, 2024
22cfede
Add test coverage for lifo lookup buy trx with unrealized profit
ZIMkaRU Apr 16, 2024
bec571f
Fix lookup buy trx with unrealized profit
ZIMkaRU Apr 16, 2024
909ee7d
Add test coverage for fifo lookup buy trx with unrealized profit
ZIMkaRU Apr 16, 2024
96932b5
Add test case checker for sale trades with realized profit
ZIMkaRU Apr 16, 2024
ac01fbe
Improve test case checker for sale trades with realized profit
ZIMkaRU Apr 17, 2024
f56ce5d
Add test coverage for lifo lookup sale trx with realized profit
ZIMkaRU Apr 17, 2024
93cfd68
Add test coverage for fifo lookup sale trx with realized profit
ZIMkaRU Apr 17, 2024
982f9d6
Add test coverage for lifo lookup sale trx with realized profit with …
ZIMkaRU Apr 17, 2024
ed64143
Add test coverage for fifo lookup sale trx with realized profit with …
ZIMkaRU Apr 17, 2024
bdb1ef9
Fix price prop naming for trx tax report
ZIMkaRU Apr 18, 2024
b18a152
Move remap trades logic into separate helper
ZIMkaRU Apr 18, 2024
bda5d2d
Move remap movements logic into separate helper
ZIMkaRU Apr 18, 2024
881c392
Improve currency conversion precision for tax
ZIMkaRU Apr 18, 2024
ee011ed
Move convertCurrencyBySymbol logic into separate helper
ZIMkaRU Apr 18, 2024
4f044d1
Enhance trade mock data for trx tax report
ZIMkaRU Apr 19, 2024
e6dd3de
Fix getTrades test case to consider new mock data
ZIMkaRU Apr 19, 2024
f71d156
Add test case for getTransactionTaxReport method with lifo strategy
ZIMkaRU Apr 19, 2024
3c34b09
Add test case for getTransactionTaxReport method with fifo strategy
ZIMkaRU Apr 19, 2024
c731dc4
Add test case for getTransactionTaxReportFile method
ZIMkaRU Apr 19, 2024
ebee507
Add mock movements
ZIMkaRU Apr 22, 2024
99b6fae
Add helper to get mocked movements
ZIMkaRU Apr 22, 2024
14009c6
Rework remap helper naming
ZIMkaRU Apr 22, 2024
3a750ad
Add test cases checker for remapped movements
ZIMkaRU Apr 22, 2024
1384e46
Add test coverage for remap-movements helper
ZIMkaRU Apr 22, 2024
f412333
Enhance mock movement data
ZIMkaRU Apr 22, 2024
e360af8
Add test cases checker for remapped trades
ZIMkaRU Apr 22, 2024
b01feb8
Add test coverage for remap-trades helper
ZIMkaRU Apr 22, 2024
9361032
Add test cases checker for trx map by currency
ZIMkaRU Apr 23, 2024
3aaaff4
Add test coverage for get-trx-map-by-ccy helper
ZIMkaRU Apr 23, 2024
42049ac
Add test cases checker for pub trade chunk payloads
ZIMkaRU Apr 23, 2024
d47ee8c
Add test coverage for get-pub-trade-chunk-payloads helper
ZIMkaRU Apr 23, 2024
8711009
Add helper to get mocked trx map by ccy
ZIMkaRU Apr 24, 2024
3e0257b
Add test cases checker for converted currency by symbol
ZIMkaRU Apr 24, 2024
1289603
Add test coverage for convert-currency-by-symbol helper
ZIMkaRU Apr 24, 2024
3a9d74e
Fix currency converter by symbol for forex ccy
ZIMkaRU Apr 24, 2024
d5910e5
Fix getting pub trade chunk
ZIMkaRU Apr 25, 2024
6e86a07
Move pub trade chunk getter into separate module
ZIMkaRU Apr 25, 2024
6250ec5
Use pub trade chunk getter for ccy conversion
ZIMkaRU Apr 25, 2024
28fa005
Add helper to get mocked pub trades
ZIMkaRU Apr 25, 2024
579707b
Add test coverage for get-pub-trade-chunk helper
ZIMkaRU Apr 25, 2024
43e2756
Fix pushing large array into array for trx tax report
ZIMkaRU May 6, 2024
8165e03
Improve error classes for trx tax report
ZIMkaRU May 7, 2024
bffc8c1
Improve error logging for trx tax report
ZIMkaRU May 7, 2024
15019ae
Fix converting symbols like tETHF0:USTF0 for trx tax report
ZIMkaRU May 7, 2024
35fac3a
Add interrupter factory
ZIMkaRU May 9, 2024
b53b159
Add InterrupterFactory service type
ZIMkaRU May 9, 2024
dbc3ee7
Add InterrupterFactory service into di
ZIMkaRU May 9, 2024
4dc785f
Add ability to process interrupters on sign-out
ZIMkaRU May 9, 2024
186c8d0
Add interrupter into lookUpTrades helper
ZIMkaRU May 9, 2024
8f41e02
Add ability to interrupt trx tax report
ZIMkaRU May 9, 2024
9e1efed
Simplify orig session obj ref return
ZIMkaRU May 9, 2024
a63e601
Fix pub trades args for trx tax report
ZIMkaRU May 9, 2024
d5ba950
Set name into sync interrupter
ZIMkaRU May 10, 2024
7a94571
Add ability to set name into interrupter using factory
ZIMkaRU May 10, 2024
521138a
Set name into trx tax report interrupter
ZIMkaRU May 10, 2024
28e742d
Add ability to interrupt user operation
ZIMkaRU May 10, 2024
2524513
Add interruptOperations endpoint
ZIMkaRU May 10, 2024
a3e88d1
Add params schema for interruptOperations endpoint
ZIMkaRU May 10, 2024
43fc721
Add TransactionTaxReport service into di singleton scope
ZIMkaRU May 13, 2024
dd66db3
Add test coverage for transaction tax report interruption
ZIMkaRU May 13, 2024
56242a6
Add test case with wrong param for interruptOperations endpoint
ZIMkaRU May 14, 2024
cfb8636
Fix interrupter name for trx tax report
ZIMkaRU May 14, 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
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