-
Notifications
You must be signed in to change notification settings - Fork 304
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
508 additions
and
4 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Binary file added
BIN
+4.68 MB
.yarn/cache/@nomicfoundation-edr-darwin-arm64-npm-0.3.5-1d9a58a391-10.zip
Binary file not shown.
Binary file removed
BIN
-6.9 MB
.yarn/cache/@nomicfoundation-edr-linux-x64-gnu-npm-0.3.5-9de0955a33-10.zip
Binary file not shown.
Binary file added
BIN
+163 KB
.yarn/cache/@nomicfoundation-solidity-analyzer-darwin-arm64-npm-0.1.1-269bd960f5-10.zip
Binary file not shown.
Binary file removed
BIN
-178 KB
.yarn/cache/@nomicfoundation-solidity-analyzer-linux-x64-gnu-npm-0.1.1-d68b54567f-10.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
137 changes: 137 additions & 0 deletions
137
packages/sources/tp/test/integration/__snapshots__/icap_adapter.test.ts.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`Price Endpoint should return error on empty base 1`] = ` | ||
{ | ||
"error": { | ||
"message": "[Param: base] param is required but no value was provided", | ||
"name": "AdapterError", | ||
}, | ||
"status": "errored", | ||
"statusCode": 400, | ||
} | ||
`; | ||
|
||
exports[`Price Endpoint should return error on empty body 1`] = ` | ||
{ | ||
"error": { | ||
"message": "[Param: base] param is required but no value was provided", | ||
"name": "AdapterError", | ||
}, | ||
"status": "errored", | ||
"statusCode": 400, | ||
} | ||
`; | ||
|
||
exports[`Price Endpoint should return error on empty data 1`] = ` | ||
{ | ||
"error": { | ||
"message": "[Param: base] param is required but no value was provided", | ||
"name": "AdapterError", | ||
}, | ||
"status": "errored", | ||
"statusCode": 400, | ||
} | ||
`; | ||
|
||
exports[`Price Endpoint should return error on empty quote 1`] = ` | ||
{ | ||
"error": { | ||
"message": "[Param: quote] param is required but no value was provided", | ||
"name": "AdapterError", | ||
}, | ||
"status": "errored", | ||
"statusCode": 400, | ||
} | ||
`; | ||
|
||
exports[`Price Endpoint should return error when queried for TP price 1`] = ` | ||
{ | ||
"error": { | ||
"message": "The EA has not received any values from the Data Provider for the requested data yet. Retry after a short delay, and if the problem persists raise this issue in the relevant channels.", | ||
"name": "AdapterError", | ||
}, | ||
"status": "errored", | ||
"statusCode": 504, | ||
} | ||
`; | ||
|
||
exports[`Price Endpoint should return error when queried for stale price 1`] = ` | ||
{ | ||
"error": { | ||
"message": "The EA has not received any values from the Data Provider for the requested data yet. Retry after a short delay, and if the problem persists raise this issue in the relevant channels.", | ||
"name": "AdapterError", | ||
}, | ||
"status": "errored", | ||
"statusCode": 504, | ||
} | ||
`; | ||
|
||
exports[`Price Endpoint should return price 1`] = ` | ||
{ | ||
"data": { | ||
"result": 1.0539, | ||
}, | ||
"result": 1.0539, | ||
"statusCode": 200, | ||
"timestamps": { | ||
"providerDataReceivedUnixMs": 1678242600000, | ||
"providerDataStreamEstablishedUnixMs": 1678242600000, | ||
}, | ||
} | ||
`; | ||
|
||
exports[`Price Endpoint should return price for inverse pair 1`] = ` | ||
{ | ||
"data": { | ||
"result": 1.239771881973717, | ||
}, | ||
"result": 1.239771881973717, | ||
"statusCode": 200, | ||
"timestamps": { | ||
"providerDataReceivedUnixMs": 1678242600000, | ||
"providerDataStreamEstablishedUnixMs": 1678242600000, | ||
}, | ||
} | ||
`; | ||
|
||
exports[`Price Endpoint should return price for specific source 1`] = ` | ||
{ | ||
"data": { | ||
"result": 1.55, | ||
}, | ||
"result": 1.55, | ||
"statusCode": 200, | ||
"timestamps": { | ||
"providerDataReceivedUnixMs": 1678242600000, | ||
"providerDataStreamEstablishedUnixMs": 1678242600000, | ||
}, | ||
} | ||
`; | ||
|
||
exports[`Price Endpoint should succeed with CAD/USD 1`] = ` | ||
{ | ||
"data": { | ||
"result": 0.16, | ||
}, | ||
"result": 0.16, | ||
"statusCode": 200, | ||
"timestamps": { | ||
"providerDataReceivedUnixMs": 1678242600000, | ||
"providerDataStreamEstablishedUnixMs": 1678242600000, | ||
}, | ||
} | ||
`; | ||
|
||
exports[`Price Endpoint should succeed with USD/CAD 1`] = ` | ||
{ | ||
"data": { | ||
"result": 6.25, | ||
}, | ||
"result": 6.25, | ||
"statusCode": 200, | ||
"timestamps": { | ||
"providerDataReceivedUnixMs": 1678242600000, | ||
"providerDataStreamEstablishedUnixMs": 1678242600000, | ||
}, | ||
} | ||
`; |
128 changes: 128 additions & 0 deletions
128
packages/sources/tp/test/integration/icap_adapter.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
import * as process from 'process' | ||
import { AddressInfo } from 'net' | ||
import { | ||
mockWebSocketProvider, | ||
mockPriceWebSocketServer, | ||
createAdapter, | ||
setEnvVariables, | ||
} from './setup' | ||
import request, { SuperTest, Test } from 'supertest' | ||
import { Server } from 'mock-socket' | ||
import { expose, ServerInstance } from '@chainlink/external-adapter-framework' | ||
import { sleep } from '@chainlink/external-adapter-framework/util' | ||
import { WebSocketClassProvider } from '@chainlink/external-adapter-framework/transports' | ||
import { mockConnectionTime } from './icap_fixtures' | ||
import { PriceEndpointInputParametersDefinition } from '@chainlink/external-adapter-framework/adapter' | ||
import { TypeFromDefinition } from '@chainlink/external-adapter-framework/validation/input-params' | ||
|
||
type AdapterRequest = { | ||
data?: TypeFromDefinition<PriceEndpointInputParametersDefinition> | ||
} | ||
|
||
describe('Price Endpoint', () => { | ||
let fastify: ServerInstance | undefined | ||
let req: SuperTest<Test> | ||
let mockPriceWsServer: Server | undefined | ||
let spy: jest.SpyInstance | ||
|
||
const makeRequest = (body: AdapterRequest) => | ||
req | ||
.post('') | ||
.send(body) | ||
.set('Accept', '*/*') | ||
.set('Content-Type', 'application/json') | ||
.expect('Content-Type', /json/) | ||
|
||
jest.setTimeout(10000) | ||
|
||
let oldEnv: NodeJS.ProcessEnv | ||
|
||
beforeAll(async () => { | ||
const wsEndpoint = 'ws://localhost:9099' | ||
|
||
oldEnv = JSON.parse(JSON.stringify(process.env)) | ||
process.env['WS_SUBSCRIPTION_TTL'] = '5000' | ||
process.env['CACHE_MAX_AGE'] = '5000' | ||
process.env['CACHE_POLLING_MAX_RETRIES'] = '0' | ||
process.env['METRICS_ENABLED'] = 'false' | ||
process.env['WS_API_USERNAME'] = 'test-username' | ||
process.env['WS_API_PASSWORD'] = 'test-password' | ||
process.env['WS_API_ENDPOINT'] = wsEndpoint | ||
|
||
spy = jest.spyOn(Date, 'now').mockReturnValue(mockConnectionTime.getTime()) | ||
|
||
mockWebSocketProvider(WebSocketClassProvider) | ||
mockPriceWsServer = mockPriceWebSocketServer(wsEndpoint) | ||
|
||
fastify = await expose(createAdapter()) | ||
req = request( | ||
`http://localhost:${(fastify?.server.address() as AddressInfo).port}?streamName=ic`, | ||
) | ||
|
||
// Send initial request to start background execute | ||
await req.post('/').send({ data: { base: 'JPY', quote: 'USD' } }) | ||
await sleep(5000) | ||
}) | ||
|
||
afterAll((done) => { | ||
spy.mockRestore() | ||
setEnvVariables(oldEnv) | ||
mockPriceWsServer?.close() | ||
fastify?.close(done()) | ||
}) | ||
|
||
it('should succeed with CAD/USD', async () => { | ||
const response = await makeRequest({ data: { base: 'CAD', quote: 'USD' } }) | ||
expect(response.body).toMatchSnapshot() | ||
}, 30000) | ||
|
||
it('should succeed with USD/CAD', async () => { | ||
const response = await makeRequest({ data: { base: 'USD', quote: 'CAD' } }) | ||
expect(response.body).toMatchSnapshot() | ||
}, 30000) | ||
|
||
it('should return price', async () => { | ||
const response = await makeRequest({ data: { base: 'EUR', quote: 'USD' } }) | ||
expect(response.body).toMatchSnapshot() | ||
}, 30000) | ||
|
||
it('should return price for inverse pair', async () => { | ||
const response = await makeRequest({ data: { base: 'IDR', quote: 'USD' } }) | ||
expect(response.body).toMatchSnapshot() | ||
}, 30000) | ||
|
||
it('should return price for specific source', async () => { | ||
const response = await makeRequest({ data: { base: 'EUR', quote: 'USD', sourceName: 'BGK' } }) | ||
expect(response.body).toMatchSnapshot() | ||
}, 30000) | ||
|
||
it('should return error when queried for TP price', async () => { | ||
const response = await makeRequest({ data: { base: 'ABC', quote: 'USD' } }) | ||
expect(response.body).toMatchSnapshot() | ||
}, 30000) | ||
|
||
it('should return error when queried for stale price', async () => { | ||
const response = await makeRequest({ data: { base: 'JPY', quote: 'USD' } }) | ||
expect(response.body).toMatchSnapshot() | ||
}, 30000) | ||
|
||
it('should return error on empty body', async () => { | ||
const response = await makeRequest({}) | ||
expect(response.body).toMatchSnapshot() | ||
}, 30000) | ||
|
||
it('should return error on empty data', async () => { | ||
const response = await makeRequest({ data: {} }) | ||
expect(response.body).toMatchSnapshot() | ||
}, 30000) | ||
|
||
it('should return error on empty base', async () => { | ||
const response = await makeRequest({ data: { quote: 'USD' } }) | ||
expect(response.body).toMatchSnapshot() | ||
}, 30000) | ||
|
||
it('should return error on empty quote', async () => { | ||
const response = await makeRequest({ data: { base: 'EUR' } }) | ||
expect(response.body).toMatchSnapshot() | ||
}, 30000) | ||
}) |
Oops, something went wrong.