From ef5dfa49a909dbe4adc0ac2309616e81ef4ba9cb Mon Sep 17 00:00:00 2001 From: mmcallister-cll <139181225+mmcallister-cll@users.noreply.github.com> Date: Thu, 2 Jan 2025 16:51:05 -0500 Subject: [PATCH] DF-20728 Tiingo uppercase (#3542) * DF-20728 force uppercase assets on tiingo lwba and crypto endpoints * add changeset * undo crypto endpoint since there are no current issues * update test --------- Co-authored-by: app-token-issuer-data-feeds[bot] <134377064+app-token-issuer-data-feeds[bot]@users.noreply.github.com> --- .changeset/cyan-grapes-sneeze.md | 5 +++ .../tiingo/src/endpoint/crypto-lwba.ts | 6 ++++ packages/sources/tiingo/src/endpoint/utils.ts | 1 + .../__snapshots__/adapter-ws.test.ts.snap | 34 +++++++++++++++++++ .../test/integration/adapter-ws.test.ts | 21 ++++++++++++ 5 files changed, 67 insertions(+) create mode 100644 .changeset/cyan-grapes-sneeze.md diff --git a/.changeset/cyan-grapes-sneeze.md b/.changeset/cyan-grapes-sneeze.md new file mode 100644 index 0000000000..f332883bc3 --- /dev/null +++ b/.changeset/cyan-grapes-sneeze.md @@ -0,0 +1,5 @@ +--- +'@chainlink/tiingo-adapter': patch +--- + +Force uppercase assets on cryptolwba endpoint diff --git a/packages/sources/tiingo/src/endpoint/crypto-lwba.ts b/packages/sources/tiingo/src/endpoint/crypto-lwba.ts index ed56173ede..0d283e5b2c 100644 --- a/packages/sources/tiingo/src/endpoint/crypto-lwba.ts +++ b/packages/sources/tiingo/src/endpoint/crypto-lwba.ts @@ -21,4 +21,10 @@ export const endpoint = new LwbaEndpoint({ transport, inputParameters: inputParameters, overrides: overrides.tiingo, + requestTransforms: [ + (req) => { + req.requestContext.data.base = req.requestContext.data.base.toUpperCase() + req.requestContext.data.quote = req.requestContext.data.quote.toUpperCase() + }, + ], }) diff --git a/packages/sources/tiingo/src/endpoint/utils.ts b/packages/sources/tiingo/src/endpoint/utils.ts index a1e78848fa..9089b26570 100644 --- a/packages/sources/tiingo/src/endpoint/utils.ts +++ b/packages/sources/tiingo/src/endpoint/utils.ts @@ -2,6 +2,7 @@ import { config } from '../config' import { InputParameters } from '@chainlink/external-adapter-framework/validation' import { priceEndpointInputParametersDefinition } from '@chainlink/external-adapter-framework/adapter' import { SingleNumberResultResponse } from '@chainlink/external-adapter-framework/util' + export const inputParameters = new InputParameters(priceEndpointInputParametersDefinition, [ { base: 'ETH', diff --git a/packages/sources/tiingo/test/integration/__snapshots__/adapter-ws.test.ts.snap b/packages/sources/tiingo/test/integration/__snapshots__/adapter-ws.test.ts.snap index f3dea1d00b..8fd802ce98 100644 --- a/packages/sources/tiingo/test/integration/__snapshots__/adapter-ws.test.ts.snap +++ b/packages/sources/tiingo/test/integration/__snapshots__/adapter-ws.test.ts.snap @@ -15,6 +15,40 @@ exports[`websocket crypto endpoint should return success 1`] = ` } `; +exports[`websocket crypto_lwba endpoint should only subscribe once 1`] = ` +{ + "data": { + "ask": 1794.2063137650225, + "bid": 1793.6242715443277, + "mid": 1793.915292654675, + }, + "result": null, + "statusCode": 200, + "timestamps": { + "providerDataReceivedUnixMs": 2028, + "providerDataStreamEstablishedUnixMs": 2020, + "providerIndicatedTimeUnixMs": 1680187094577, + }, +} +`; + +exports[`websocket crypto_lwba endpoint should only subscribe once 2`] = ` +{ + "data": { + "ask": 1794.2063137650225, + "bid": 1793.6242715443277, + "mid": 1793.915292654675, + }, + "result": null, + "statusCode": 200, + "timestamps": { + "providerDataReceivedUnixMs": 2028, + "providerDataStreamEstablishedUnixMs": 2020, + "providerIndicatedTimeUnixMs": 1680187094577, + }, +} +`; + exports[`websocket crypto_lwba endpoint should return error (invariant violation) 1`] = ` { "error": { diff --git a/packages/sources/tiingo/test/integration/adapter-ws.test.ts b/packages/sources/tiingo/test/integration/adapter-ws.test.ts index 4ff79e83a7..7188665a1f 100644 --- a/packages/sources/tiingo/test/integration/adapter-ws.test.ts +++ b/packages/sources/tiingo/test/integration/adapter-ws.test.ts @@ -13,6 +13,8 @@ import { } from './fixtures' import { WebSocketClassProvider } from '@chainlink/external-adapter-framework/transports' import FakeTimers from '@sinonjs/fake-timers' +import * as lwbaTransport from '../../src/transport/crypto-lwba' +import * as lwbaEndpoint from '../../src/endpoint/crypto-lwba' describe('websocket', () => { let mockWsServerCrypto: MockWebsocketServer | undefined @@ -100,6 +102,25 @@ describe('websocket', () => { const response = await testAdapter.request(spreadData) expect(response.json()).toMatchSnapshot() }) + it('should only subscribe once', async () => { + const lwbaDataLowercase = { + endpoint: 'crypto_lwba', + base: 'eth', + quote: 'usd', + } + const lwbaDataUppercase = { + endpoint: 'crypto_lwba', + base: 'ETH', + quote: 'USD', + } + const response1 = await testAdapter.request(lwbaDataLowercase) + expect(response1.json()).toMatchSnapshot() + + const response2 = await testAdapter.request(lwbaDataUppercase) + expect(response2.json()).toMatchSnapshot() + + expect(lwbaTransport.transport.subscriptionSet.getAll()).toHaveLength(1) + }) it('should return error (invariant violation)', async () => { // fast forward to next message (which contains an invariant violation) testAdapter.clock.tick(5000)