Skip to content

Commit cb30c2c

Browse files
[DF-22956] fix casing issue blocksize capital EA (#4780)
* fix casing issue blocksize capital EA --------- Co-authored-by: app-token-issuer-data-feeds[bot] <134377064+app-token-issuer-data-feeds[bot]@users.noreply.github.com>
1 parent 7877f44 commit cb30c2c

15 files changed

Lines changed: 221 additions & 7 deletions

File tree

.changeset/flat-drinks-fail.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@chainlink/blocksize-capital-state-adapter': patch
3+
'@chainlink/blocksize-capital-adapter': patch
4+
---
5+
6+
add casing normalization for blocksize-capital

.pnp.cjs

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/sources/blocksize-capital-state/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
"typescript": "5.8.3"
3737
},
3838
"dependencies": {
39-
"@chainlink/external-adapter-framework": "2.11.6",
39+
"@chainlink/external-adapter-framework": "2.13.1",
4040
"tslib": "2.4.1"
4141
}
4242
}

packages/sources/blocksize-capital-state/src/endpoint/state.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { SingleNumberResultResponse } from '@chainlink/external-adapter-framewor
66
import { InputParameters } from '@chainlink/external-adapter-framework/validation'
77
import { config } from '../config'
88
import { stateTransport } from '../transport/state'
9+
import { blocksizeStateSubscriptionRequestTransform } from './utils'
910

1011
export const inputParameters = new InputParameters(priceEndpointInputParametersDefinition, [
1112
{
@@ -25,4 +26,5 @@ export const endpoint = new PriceEndpoint({
2526
aliases: ['crypto', 'state'],
2627
transport: stateTransport,
2728
inputParameters,
29+
requestTransforms: [blocksizeStateSubscriptionRequestTransform()],
2830
})
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { AdapterRequest } from '@chainlink/external-adapter-framework/util'
2+
3+
export function blocksizeStateSubscriptionRequestTransform() {
4+
return (req: AdapterRequest<{ base: string; quote?: string }>) => {
5+
req.requestContext.data.base = req.requestContext.data.base.toLowerCase()
6+
if (req.requestContext.data.quote) {
7+
req.requestContext.data.quote = req.requestContext.data.quote.toLowerCase()
8+
}
9+
}
10+
}

packages/sources/blocksize-capital-state/test/integration/__snapshots__/adapter.test.ts.snap

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,21 @@ exports[`websocket state endpoint should return aggregated_state_price and inclu
1515
}
1616
`;
1717

18+
exports[`websocket state endpoint should normalize mixed-case base and quote params 1`] = `
19+
{
20+
"data": {
21+
"result": 1234.56,
22+
},
23+
"result": 1234.56,
24+
"statusCode": 200,
25+
"timestamps": {
26+
"providerDataReceivedUnixMs": 1122,
27+
"providerDataStreamEstablishedUnixMs": 1010,
28+
"providerIndicatedTimeUnixMs": 1672531200000,
29+
},
30+
}
31+
`;
32+
1833
exports[`websocket state endpoint should return success 1`] = `
1934
{
2035
"data": {

packages/sources/blocksize-capital-state/test/integration/adapter.test.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,5 +90,16 @@ describe('websocket', () => {
9090
expect(response.statusCode).toBe(200)
9191
}
9292
})
93+
94+
it('should normalize mixed-case base and quote params', async () => {
95+
const response = await testAdapter.request({
96+
base: 'CbBtC',
97+
quote: 'uSd',
98+
endpoint: 'state',
99+
})
100+
101+
expect(response.statusCode).toBe(200)
102+
expect(response.json()).toMatchSnapshot()
103+
})
93104
})
94105
})
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import { blocksizeStateSubscriptionRequestTransform } from '../../src/endpoint/utils'
2+
3+
describe('blocksizeStateSubscriptionRequestTransform', () => {
4+
it('should lowercase base and quote', () => {
5+
const req = {
6+
requestContext: {
7+
data: {
8+
base: 'CbBtC',
9+
quote: 'UsD',
10+
},
11+
},
12+
} as any
13+
14+
blocksizeStateSubscriptionRequestTransform()(req)
15+
16+
expect(req.requestContext.data).toEqual({
17+
base: 'cbbtc',
18+
quote: 'usd',
19+
})
20+
})
21+
22+
it('should not modify unrelated request data', () => {
23+
const req = {
24+
requestContext: {
25+
data: {
26+
base: 'CbBtC',
27+
quote: 'UsD',
28+
endpoint: 'state',
29+
},
30+
},
31+
} as any
32+
33+
blocksizeStateSubscriptionRequestTransform()(req)
34+
35+
expect(req.requestContext.data).toEqual({
36+
base: 'cbbtc',
37+
quote: 'usd',
38+
endpoint: 'state',
39+
})
40+
})
41+
42+
it('should lowercase base when quote is omitted', () => {
43+
const req = {
44+
requestContext: {
45+
data: {
46+
base: 'CbBtC',
47+
},
48+
},
49+
} as any
50+
51+
blocksizeStateSubscriptionRequestTransform()(req)
52+
53+
expect(req.requestContext.data).toEqual({
54+
base: 'cbbtc',
55+
})
56+
})
57+
})

packages/sources/blocksize-capital/src/endpoint/crypto-lwba.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
import { InputParameters } from '@chainlink/external-adapter-framework/validation'
77
import { config } from '../config'
88
import { transport } from '../transport/crypto-lwba'
9+
import { blocksizeStateSubscriptionRequestTransform } from './utils'
910

1011
const inputParameters = new InputParameters(lwbaEndpointInputParametersDefinition, [
1112
{
@@ -24,4 +25,5 @@ export const endpoint = new LwbaEndpoint({
2425
name: 'crypto-lwba',
2526
transport,
2627
inputParameters,
28+
requestTransforms: [blocksizeStateSubscriptionRequestTransform()],
2729
})

packages/sources/blocksize-capital/src/endpoint/price.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { SingleNumberResultResponse } from '@chainlink/external-adapter-framewor
66
import { InputParameters } from '@chainlink/external-adapter-framework/validation'
77
import { config } from '../config'
88
import { transport } from '../transport/price'
9+
import { blocksizeStateSubscriptionRequestTransform } from './utils'
910

1011
const inputParameters = new InputParameters(priceEndpointInputParametersDefinition, [
1112
{
@@ -25,4 +26,5 @@ export const endpoint = new CryptoPriceEndpoint({
2526
aliases: ['crypto'],
2627
transport,
2728
inputParameters,
29+
requestTransforms: [blocksizeStateSubscriptionRequestTransform()],
2830
})

0 commit comments

Comments
 (0)