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

fix: valora app version check for Aave positions #680

Merged
merged 2 commits into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"i18next-fs-backend": "^2.6.0",
"i18next-http-middleware": "^3.7.0",
"lru-cache": "^11.0.2",
"semver": "^7.6.3",
"viem": "^2.21.53",
"zod": "^3.23.8"
},
Expand Down
37 changes: 36 additions & 1 deletion src/api/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { getConfig } from '../config'

jest.mock('../config')
jest.mocked(getConfig).mockReturnValue({
POSITION_IDS: [],
POSITION_IDS: ['uniswap', 'aave', 'curve'],
GET_TOKENS_INFO_URL: 'https://valoraapp.com/mock-endpoint',
GOOGLE_CLOUD_PROJECT: 'dev-project',
SHORTCUT_IDS: [],
Expand Down Expand Up @@ -281,6 +281,10 @@ jest.mocked(getShortcuts).mockResolvedValue(TEST_SHORTCUTS)

const WALLET_ADDRESS = '0x0000000000000000000000000000000000007e57'

beforeEach(() => {
jest.clearAllMocks()
})

describe('GET /getPositions', () => {
it('returns balances for celo', async () => {
const server = getTestServer('hooks-api')
Expand Down Expand Up @@ -322,6 +326,37 @@ describe('GET /getPositions', () => {
data: TEST_POSITIONS_CELO,
})
})

for (const [userAgent, shouldIncludeAave] of [
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is the reason to use for loop over it.each is for better test names? or something else?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes for better test name.

['Valora/1.90.0', true],
['Valora/1.100.0', true],
['Valora/1.89.9', false],
['Valora/1.89.10', false],
['SomeOtherApp/1.90.0', true],
[undefined, true],
] as const) {
it(`returns positions for User-Agent ${userAgent ?? 'undefined'} ${
shouldIncludeAave ? 'including' : 'excluding'
} Aave`, async () => {
const server = getTestServer('hooks-api')
await request(server)
.get('/getPositions')
.set('user-agent', userAgent ?? '')
.query({
networkIds: [NetworkId['arbitrum-one']],
address: WALLET_ADDRESS,
})
.expect(200)

expect(getPositions).toHaveBeenCalledWith(
expect.objectContaining({
appIds: shouldIncludeAave
? expect.arrayContaining(['aave']) // eslint-disable-line jest/no-conditional-expect
: expect.not.arrayContaining(['aave']), // eslint-disable-line jest/no-conditional-expect
}),
)
})
}
})

describe('GET /getEarnPositions', () => {
Expand Down
5 changes: 3 additions & 2 deletions src/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import Backend from 'i18next-fs-backend'
import i18nextMiddleware from 'i18next-http-middleware'
import path from 'path'
import { z } from 'zod'
import semver from 'semver'
import { getConfig } from '../config'
import { logger } from '../log'
import { getBaseTokensInfo, getPositions } from '../runtime/getPositions'
Expand Down Expand Up @@ -141,8 +142,8 @@ function createApp() {
const userAgent = req.header('user-agent')
const valoraAppVersion = getValoraAppVersion(userAgent)
const returnAavePositions = valoraAppVersion
? valoraAppVersion >= '1.90.0'
: false
? semver.gte(valoraAppVersion, '1.90.0')
: true
const { address } = parsedRequest.query
const networkIds = getNetworkIds(parsedRequest.query)
const appIds = config.POSITION_IDS.filter((appId) =>
Expand Down
Loading