Skip to content

Commit 0b56c4e

Browse files
yaroslav-glukhov-chainlinkro-texapp-token-issuer-data-feeds[bot]
authored
[DS-3267] [Streams adapter] 504 error on view-function-multi-chain ad… (#5024)
* [DS-3267] [Streams adapter] 504 error on view-function-multi-chain adapter Updated ea-framework-js version to support json only FeedId * Add changeset * Add tests and update tesgt snapshots Added FEED_ID_JSON tests for empty and hashed keys Updated tests snapshots to match actual behavior * fix test * revert snapshots * revert tests * update dependencies * fix pnp * fix tests --------- Co-authored-by: Ivaylo Novakov <inovakov@gmail.com> Co-authored-by: app-token-issuer-data-feeds[bot] <134377064+app-token-issuer-data-feeds[bot]@users.noreply.github.com>
1 parent 1510a71 commit 0b56c4e

4 files changed

Lines changed: 48 additions & 9 deletions

File tree

.changeset/soft-symbols-behave.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@chainlink/view-function-multi-chain-adapter': minor
3+
'@chainlink/the-network-firm-adapter': minor
4+
---
5+
6+
Update ea framework to support json only feed id

packages/sources/the-network-firm/test/integration/adapter.test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ describe('execute', () => {
4141
})
4242
})
4343

44+
beforeEach(() => {
45+
testAdapter.adapter.config.settings.FEED_ID_JSON = false
46+
testAdapter.adapter.config.settings.METRICS_ENABLED = false
47+
})
48+
4449
afterEach(() => {
4550
nock.cleanAll()
4651
// clear EA cache
@@ -70,6 +75,17 @@ describe('execute', () => {
7075
})
7176
})
7277

78+
describe('mco2 endpoint empty feed id with FEED_ID_JSON=true', () => {
79+
it('should return empty json feed id', async () => {
80+
testAdapter.adapter.config.settings.FEED_ID_JSON = true
81+
testAdapter.adapter.config.settings.METRICS_ENABLED = true
82+
mockMCO2Response()
83+
const response = await testAdapter.request()
84+
expect(response.statusCode).toBe(200)
85+
expect(response.json().meta.metrics.feedId).toBe('{}')
86+
})
87+
})
88+
7389
describe('stbt endpoint', () => {
7490
it('should return success', async () => {
7591
const data = {

packages/sources/view-function-multi-chain/test/integration/adapter.test.ts

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ describe('execute', () => {
1818

1919
beforeAll(async () => {
2020
oldEnv = JSON.parse(JSON.stringify(process.env))
21+
const mockDate = new Date('2001-01-01T11:11:11.111Z')
22+
spy = jest.spyOn(Date, 'now').mockReturnValue(mockDate.getTime())
2123
process.env.ETHEREUM_MAINNET_RPC_URL =
2224
process.env.ETHEREUM_MAINNET_RPC_URL ?? 'http://localhost:8545'
2325
process.env.ETHEREUM_MAINNET_CHAIN_ID = process.env.ETHEREUM_MAINNET_CHAIN_ID ?? '1'
@@ -27,9 +29,6 @@ describe('execute', () => {
2729
process.env.BACKGROUND_EXECUTE_MS = '0'
2830
process.env.APTOS_URL = process.env.APTOS_URL ?? 'http://fake-aptos'
2931
process.env.APTOS_TESTNET_URL = process.env.APTOS_TESTNET_URL ?? 'http://fake-aptos-testnet'
30-
const mockDate = new Date('2001-01-01T11:11:11.111Z')
31-
spy = jest.spyOn(Date, 'now').mockReturnValue(mockDate.getTime())
32-
3332
const adapter = (await import('./../../src')).adapter
3433
adapter.rateLimiting = undefined
3534
testAdapter = await TestAdapter.startWithMockedCache(adapter, {
@@ -45,6 +44,12 @@ describe('execute', () => {
4544
spy.mockRestore()
4645
})
4746

47+
beforeEach(() => {
48+
testAdapter.adapter.config.settings.MAX_COMMON_KEY_SIZE = 500
49+
testAdapter.adapter.config.settings.FEED_ID_JSON = false
50+
testAdapter.adapter.config.settings.METRICS_ENABLED = false
51+
})
52+
4853
afterEach(() => {
4954
nock.cleanAll()
5055
})
@@ -62,6 +67,21 @@ describe('execute', () => {
6267
expect(response.json()).toMatchSnapshot()
6368
})
6469

70+
it('should return hash code if data length exceeds max key size', async () => {
71+
testAdapter.adapter.config.settings.MAX_COMMON_KEY_SIZE = 1
72+
testAdapter.adapter.config.settings.FEED_ID_JSON = true
73+
testAdapter.adapter.config.settings.METRICS_ENABLED = true
74+
const data = {
75+
contract: '0x2c1d072e956AFFC0D435Cb7AC38EF18d24d9127c',
76+
function: 'function latestAnswer() external view returns (int256)',
77+
network: 'ethereum_mainnet',
78+
}
79+
mockETHMainnetContractCallResponseSuccess()
80+
const response = await testAdapter.request(data)
81+
expect(response.statusCode).toBe(200)
82+
expect(response.json().meta.metrics.feedId).toBe('{"hash":"oZQF1WbGvmgrgf32HSV0Mm5GSyo="}')
83+
})
84+
6585
it('should return success for different network', async () => {
6686
const data = {
6787
contract: '0x779877a7b0d9e8603169ddbd7836e478b4624789',

packages/streams-adapter/helpers/helpers.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ package helpers
33
import (
44
"errors"
55
"fmt"
6-
"sort"
6+
"maps"
7+
"slices"
78
"strings"
89

910
"github.com/goccy/go-json"
@@ -65,11 +66,7 @@ func CalculateCacheKey(params types.RequestParams) (string, error) {
6566
}
6667

6768
// Extract and sort keys for deterministic ordering
68-
keys := make([]string, 0, len(params))
69-
for key := range params {
70-
keys = append(keys, key)
71-
}
72-
sort.Strings(keys)
69+
keys := slices.Sorted(maps.Keys(params))
7370

7471
// Build the cache key
7572
var parts []string

0 commit comments

Comments
 (0)