Skip to content

Commit 604ecdb

Browse files
authored
Make mock-ea test output deterministic (#4165)
* Make mock-ea test output deterministic * changeset
1 parent 7db60b6 commit 604ecdb

File tree

4 files changed

+14
-8
lines changed

4 files changed

+14
-8
lines changed

.changeset/hungry-numbers-buy.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@chainlink/mock-ea-adapter': minor
3+
---
4+
5+
Only start deviating after the first response, which is now always 1000.

packages/sources/mock-ea/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,9 @@ Response:
6060
{
6161
"jobRunID": "1",
6262
"data": {
63-
"result": 950
63+
"result": 1000
6464
},
65-
"result": 950,
65+
"result": 1000,
6666
"statusCode": 200
6767
}
6868
```

packages/sources/mock-ea/src/endpoint/price.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { Requester, Validator } from '@chainlink/ea-bootstrap'
2-
import { ExecuteWithConfig, InputParameters } from '@chainlink/ea-bootstrap'
1+
import { ExecuteWithConfig, InputParameters, Requester, Validator } from '@chainlink/ea-bootstrap'
32
import { ExtendedConfig } from '../config'
43

54
export const supportedEndpoints = ['price']
@@ -28,7 +27,9 @@ export const execute: ExecuteWithConfig<ExtendedConfig> = async (request, _, con
2827
const jobRunID = validator.validated.id
2928
const lastUpdated = responseInfo.lastUpdated
3029
const now = Date.now()
31-
if (!lastUpdated || now - lastUpdated >= config.updateIntervalInMS) {
30+
if (!lastUpdated) {
31+
responseInfo.lastUpdated = now
32+
} else if (now - lastUpdated >= config.updateIntervalInMS) {
3233
const amountToDeviate = (config.deviationAmount * responseInfo.result) / 100
3334
responseInfo.result =
3435
now % 2 === 0 ? responseInfo.result + amountToDeviate : responseInfo.result - amountToDeviate

packages/sources/mock-ea/test/integration/adapter.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { AdapterRequest } from '@chainlink/ea-bootstrap'
2-
import { server as startServer } from '../../src'
3-
import { setupExternalAdapterTest } from '@chainlink/ea-test-helpers'
42
import type { SuiteContext } from '@chainlink/ea-test-helpers'
3+
import { setupExternalAdapterTest } from '@chainlink/ea-test-helpers'
54
import { SuperTest, Test } from 'supertest'
5+
import { server as startServer } from '../../src'
66

77
describe('execute', () => {
88
const id = '1'
@@ -27,7 +27,7 @@ describe('execute', () => {
2727
.set('Content-Type', 'application/json')
2828
.expect('Content-Type', /json/)
2929
.expect(200)
30-
expect([950, 1050]).toContain(response.body.data.result)
30+
expect(response.body.data.result).toBe(1000)
3131
})
3232
})
3333
})

0 commit comments

Comments
 (0)