@chainlink/external-adapter-framework 0.0.15 → 0.0.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/adapter.js +128 -0
- package/background-executor.js +45 -0
- package/cache/factory.js +58 -0
- package/cache/index.js +173 -0
- package/cache/local.js +83 -0
- package/cache/metrics.js +120 -0
- package/cache/redis.js +100 -0
- package/chainlink-external-adapter-framework-v0.0.6.tgz +0 -0
- package/config/index.js +366 -0
- package/config/provider-limits.js +74 -0
- package/examples/bank-frick/accounts.js +192 -0
- package/examples/bank-frick/config/index.js +54 -0
- package/examples/bank-frick/index.js +15 -0
- package/examples/bank-frick/util.js +39 -0
- package/examples/coingecko/batch-warming.js +53 -0
- package/examples/coingecko/index.js +11 -0
- package/examples/coingecko/rest.js +51 -0
- package/examples/coingecko/src/config/index.js +13 -0
- package/examples/coingecko/src/config/overrides.json +10826 -0
- package/examples/coingecko/src/cryptoUtils.js +41 -0
- package/examples/coingecko/src/endpoint/coins.js +33 -0
- package/examples/coingecko/src/endpoint/crypto-marketcap.js +46 -0
- package/examples/coingecko/src/endpoint/crypto-volume.js +46 -0
- package/examples/coingecko/src/endpoint/crypto.js +47 -0
- package/examples/coingecko/src/endpoint/dominance.js +26 -0
- package/examples/coingecko/src/endpoint/global-marketcap.js +26 -0
- package/examples/coingecko/src/endpoint/index.js +15 -0
- package/examples/coingecko/src/globalUtils.js +48 -0
- package/examples/coingecko/src/index.js +14 -0
- package/examples/coingecko/test/e2e/adapter.test.js +262 -0
- package/examples/coingecko/test/integration/adapter.test.js +264 -0
- package/examples/coingecko/test/integration/capturedRequests.json +1 -0
- package/examples/coingecko/test/integration/fixtures.js +41 -0
- package/examples/coingecko-old/batch-warming.js +53 -0
- package/examples/coingecko-old/index.js +11 -0
- package/examples/coingecko-old/rest.js +51 -0
- package/examples/ncfx/config/index.js +15 -0
- package/examples/ncfx/index.js +11 -0
- package/examples/ncfx/websocket.js +73 -0
- package/index.js +127 -0
- package/metrics/constants.js +25 -0
- package/metrics/index.js +122 -0
- package/metrics/util.js +9 -0
- package/package.json +5 -15
- package/rate-limiting/background/fixed-frequency.js +35 -0
- package/rate-limiting/index.js +84 -0
- package/rate-limiting/metrics.js +44 -0
- package/rate-limiting/request/simple-counting.js +62 -0
- package/test.js +6 -0
- package/transports/batch-warming.js +101 -0
- package/transports/index.js +87 -0
- package/transports/metrics.js +105 -0
- package/transports/rest.js +138 -0
- package/transports/util.js +86 -0
- package/transports/websocket.js +166 -0
- package/util/index.js +35 -0
- package/util/logger.js +62 -0
- package/util/recordRequests.js +45 -0
- package/util/request.js +2 -0
- package/util/subscription-set/expiring-sorted-set.js +47 -0
- package/util/subscription-set/subscription-set.js +19 -0
- package/util/test-payload-loader.js +83 -0
- package/validation/error.js +79 -0
- package/validation/index.js +91 -0
- package/validation/input-params.js +30 -0
- package/validation/override-functions.js +40 -0
- package/validation/overrideFunctions.js +40 -0
- package/validation/preset-tokens.json +23 -0
- package/validation/validator.js +303 -0
- package/.c8rc.json +0 -3
- package/.eslintignore +0 -10
- package/.eslintrc.js +0 -96
- package/.github/README.MD +0 -42
- package/.github/actions/setup/action.yaml +0 -13
- package/.github/workflows/label.yaml +0 -39
- package/.github/workflows/main.yaml +0 -39
- package/.github/workflows/publish.yaml +0 -17
- package/.prettierignore +0 -13
- package/.yarnrc +0 -0
- package/README.md +0 -103
- package/dist/examples/coingecko/test/e2e/adapter.test.ts.js +0 -82953
- package/dist/examples/coingecko/test/integration/adapter.test.ts.js +0 -91672
- package/dist/main.js +0 -72703
- package/docker-compose.yaml +0 -35
- package/env.sh +0 -54
- package/env2.sh +0 -55
- package/jest.config.js +0 -5
- package/publish.sh +0 -0
- package/src/adapter.ts +0 -263
- package/src/background-executor.ts +0 -52
- package/src/cache/factory.ts +0 -26
- package/src/cache/index.ts +0 -258
- package/src/cache/local.ts +0 -73
- package/src/cache/metrics.ts +0 -112
- package/src/cache/redis.ts +0 -93
- package/src/config/index.ts +0 -517
- package/src/config/provider-limits.ts +0 -127
- package/src/examples/bank-frick/README.MD +0 -10
- package/src/examples/bank-frick/accounts.ts +0 -246
- package/src/examples/bank-frick/config/index.ts +0 -53
- package/src/examples/bank-frick/index.ts +0 -13
- package/src/examples/bank-frick/types.d.ts +0 -38
- package/src/examples/bank-frick/util.ts +0 -55
- package/src/examples/coingecko/src/config/index.ts +0 -12
- package/src/examples/coingecko/src/config/overrides.json +0 -10826
- package/src/examples/coingecko/src/cryptoUtils.ts +0 -88
- package/src/examples/coingecko/src/endpoint/coins.ts +0 -54
- package/src/examples/coingecko/src/endpoint/crypto-marketcap.ts +0 -66
- package/src/examples/coingecko/src/endpoint/crypto-volume.ts +0 -66
- package/src/examples/coingecko/src/endpoint/crypto.ts +0 -63
- package/src/examples/coingecko/src/endpoint/dominance.ts +0 -40
- package/src/examples/coingecko/src/endpoint/global-marketcap.ts +0 -40
- package/src/examples/coingecko/src/endpoint/index.ts +0 -6
- package/src/examples/coingecko/src/globalUtils.ts +0 -78
- package/src/examples/coingecko/src/index.ts +0 -17
- package/src/examples/coingecko/test/e2e/adapter.test.ts +0 -278
- package/src/examples/coingecko/test/integration/__snapshots__/adapter.test.ts.snap +0 -15
- package/src/examples/coingecko/test/integration/adapter.test.ts +0 -281
- package/src/examples/coingecko/test/integration/capturedRequests.json +0 -1
- package/src/examples/coingecko/test/integration/fixtures.ts +0 -42
- package/src/examples/coingecko-old/batch-warming.ts +0 -79
- package/src/examples/coingecko-old/index.ts +0 -9
- package/src/examples/coingecko-old/rest.ts +0 -77
- package/src/examples/ncfx/config/index.ts +0 -12
- package/src/examples/ncfx/index.ts +0 -9
- package/src/examples/ncfx/websocket.ts +0 -99
- package/src/index.ts +0 -149
- package/src/metrics/constants.ts +0 -23
- package/src/metrics/index.ts +0 -115
- package/src/metrics/util.ts +0 -18
- package/src/rate-limiting/background/fixed-frequency.ts +0 -45
- package/src/rate-limiting/index.ts +0 -100
- package/src/rate-limiting/metrics.ts +0 -18
- package/src/rate-limiting/request/simple-counting.ts +0 -76
- package/src/transports/batch-warming.ts +0 -127
- package/src/transports/index.ts +0 -152
- package/src/transports/metrics.ts +0 -95
- package/src/transports/rest.ts +0 -168
- package/src/transports/util.ts +0 -63
- package/src/transports/websocket.ts +0 -245
- package/src/util/index.ts +0 -23
- package/src/util/logger.ts +0 -69
- package/src/util/recordRequests.ts +0 -47
- package/src/util/request.ts +0 -117
- package/src/util/subscription-set/expiring-sorted-set.ts +0 -54
- package/src/util/subscription-set/subscription-set.ts +0 -35
- package/src/util/test-payload-loader.ts +0 -87
- package/src/validation/error.ts +0 -116
- package/src/validation/index.ts +0 -110
- package/src/validation/input-params.ts +0 -45
- package/src/validation/override-functions.ts +0 -44
- package/src/validation/overrideFunctions.ts +0 -44
- package/src/validation/preset-tokens.json +0 -23
- package/src/validation/validator.ts +0 -384
- package/test/adapter.test.ts +0 -27
- package/test/background-executor.test.ts +0 -108
- package/test/cache/cache-key.test.ts +0 -114
- package/test/cache/helper.ts +0 -100
- package/test/cache/local.test.ts +0 -54
- package/test/cache/redis.test.ts +0 -89
- package/test/correlation.test.ts +0 -114
- package/test/index.test.ts +0 -37
- package/test/metrics/feed-id.test.ts +0 -38
- package/test/metrics/helper.ts +0 -14
- package/test/metrics/labels.test.ts +0 -36
- package/test/metrics/metrics.test.ts +0 -267
- package/test/metrics/redis-metrics.test.ts +0 -113
- package/test/metrics/warmer-metrics.test.ts +0 -193
- package/test/metrics/ws-metrics.test.ts +0 -225
- package/test/rate-limit-config.test.ts +0 -242
- package/test/smoke/smoke.test.ts +0 -166
- package/test/smoke/test-payload-fail.json +0 -3
- package/test/smoke/test-payload.js +0 -22
- package/test/smoke/test-payload.json +0 -7
- package/test/transports/batch.test.ts +0 -466
- package/test/transports/rest.test.ts +0 -242
- package/test/transports/websocket.test.ts +0 -183
- package/test/tsconfig.json +0 -5
- package/test/util.ts +0 -77
- package/test/validation.test.ts +0 -178
- package/test.sh +0 -20
- package/test2.sh +0 -2
- package/tsconfig.json +0 -28
- package/typedoc.json +0 -6
- package/webpack.config.js +0 -57
- package/yarn-error.log +0 -3778
package/test/cache/helper.ts
DELETED
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
import untypedTest, { TestFn } from 'ava'
|
|
2
|
-
import axios, { AxiosError } from 'axios'
|
|
3
|
-
import { AdapterDependencies, AdapterEndpoint } from '../../src/adapter'
|
|
4
|
-
import { Cache } from '../../src/cache'
|
|
5
|
-
import { AdapterRequest, AdapterResponse } from '../../src/util'
|
|
6
|
-
import { NopTransport } from '../util'
|
|
7
|
-
|
|
8
|
-
export const test = untypedTest as TestFn<{
|
|
9
|
-
serverAddress: string
|
|
10
|
-
cache: Cache
|
|
11
|
-
adapterEndpoint: AdapterEndpoint
|
|
12
|
-
}>
|
|
13
|
-
|
|
14
|
-
export class BasicCacheSetterTransport extends NopTransport {
|
|
15
|
-
cache!: Cache
|
|
16
|
-
|
|
17
|
-
override async initialize(dependencies: AdapterDependencies): Promise<void> {
|
|
18
|
-
this.cache = dependencies.cache
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
override async setup(req: AdapterRequest): Promise<void> {
|
|
22
|
-
const response: AdapterResponse = {
|
|
23
|
-
data: null,
|
|
24
|
-
statusCode: 200,
|
|
25
|
-
result: req.requestContext.data['factor'],
|
|
26
|
-
}
|
|
27
|
-
await this.cache.setMany(
|
|
28
|
-
[
|
|
29
|
-
{
|
|
30
|
-
key: req.requestContext.cacheKey,
|
|
31
|
-
value: response,
|
|
32
|
-
},
|
|
33
|
-
],
|
|
34
|
-
10000,
|
|
35
|
-
)
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export const cacheTests = () => {
|
|
40
|
-
test('returns value set in cache from setup', async (t) => {
|
|
41
|
-
const data = {
|
|
42
|
-
base: 'eth',
|
|
43
|
-
factor: 123,
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
const response = await axios.post(`${t.context.serverAddress}`, { data })
|
|
47
|
-
t.is(response.data.result, 123)
|
|
48
|
-
})
|
|
49
|
-
|
|
50
|
-
test('returns value already found in cache', async (t) => {
|
|
51
|
-
const data = {
|
|
52
|
-
base: 'qweqwe',
|
|
53
|
-
factor: 111,
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
const cacheKey = 'test-|base:qweqwe|factor:111'
|
|
57
|
-
|
|
58
|
-
// Inject values directly into the cache
|
|
59
|
-
const injectedEntry = {
|
|
60
|
-
data: null,
|
|
61
|
-
statusCode: 200,
|
|
62
|
-
result: 'injected',
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
t.context.cache.set(cacheKey, injectedEntry, 10000)
|
|
66
|
-
|
|
67
|
-
const response = await axios.post(`${t.context.serverAddress}`, { data })
|
|
68
|
-
t.is(response.data.result, 'injected')
|
|
69
|
-
})
|
|
70
|
-
|
|
71
|
-
test('skips expired cache entry and returns set up value', async (t) => {
|
|
72
|
-
const data = {
|
|
73
|
-
base: 'sdfghj',
|
|
74
|
-
factor: 24637,
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
const cacheKey = 'test-|base:sdfghj|factor:24637'
|
|
78
|
-
|
|
79
|
-
// Inject values directly into the cache
|
|
80
|
-
const injectedEntry = {
|
|
81
|
-
data: null,
|
|
82
|
-
statusCode: 200,
|
|
83
|
-
result: 'injected',
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
t.context.cache.set(cacheKey, injectedEntry, -10)
|
|
87
|
-
|
|
88
|
-
const response = await axios.post(`${t.context.serverAddress}`, { data })
|
|
89
|
-
t.is(response.data.result, 24637)
|
|
90
|
-
})
|
|
91
|
-
|
|
92
|
-
test('polls forever and returns timeout', async (t) => {
|
|
93
|
-
const makeRequest = () =>
|
|
94
|
-
axios.post(`${t.context.serverAddress}`, {
|
|
95
|
-
endpoint: 'nowork',
|
|
96
|
-
})
|
|
97
|
-
const error: AxiosError | undefined = await t.throwsAsync(makeRequest)
|
|
98
|
-
t.is(error?.response?.status, 504)
|
|
99
|
-
})
|
|
100
|
-
}
|
package/test/cache/local.test.ts
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import { AddressInfo } from 'ws'
|
|
2
|
-
import { expose } from '../../src'
|
|
3
|
-
import { Adapter, AdapterDependencies } from '../../src/adapter'
|
|
4
|
-
import { LocalCache } from '../../src/cache'
|
|
5
|
-
import { SettingsMap } from '../../src/config'
|
|
6
|
-
import { Transport } from '../../src/transports'
|
|
7
|
-
import { NopTransport } from '../util'
|
|
8
|
-
import { BasicCacheSetterTransport, cacheTests, test } from './helper'
|
|
9
|
-
|
|
10
|
-
test.beforeEach(async (t) => {
|
|
11
|
-
const adapter: Adapter = {
|
|
12
|
-
name: 'test',
|
|
13
|
-
defaultEndpoint: 'test',
|
|
14
|
-
endpoints: [
|
|
15
|
-
{
|
|
16
|
-
name: 'test',
|
|
17
|
-
inputParameters: {
|
|
18
|
-
base: {
|
|
19
|
-
type: 'string',
|
|
20
|
-
required: true,
|
|
21
|
-
},
|
|
22
|
-
factor: {
|
|
23
|
-
type: 'number',
|
|
24
|
-
required: true,
|
|
25
|
-
},
|
|
26
|
-
},
|
|
27
|
-
transport: new BasicCacheSetterTransport() as Transport<unknown, unknown, SettingsMap>,
|
|
28
|
-
},
|
|
29
|
-
{
|
|
30
|
-
name: 'nowork',
|
|
31
|
-
inputParameters: {},
|
|
32
|
-
transport: new NopTransport(),
|
|
33
|
-
},
|
|
34
|
-
],
|
|
35
|
-
envDefaultOverrides: {
|
|
36
|
-
CACHE_POLLING_SLEEP_MS: 10,
|
|
37
|
-
CACHE_POLLING_MAX_RETRIES: 3,
|
|
38
|
-
},
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
const cache = new LocalCache()
|
|
42
|
-
const dependencies: Partial<AdapterDependencies> = {
|
|
43
|
-
cache,
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
t.context.cache = cache
|
|
47
|
-
const server = await expose(adapter, dependencies)
|
|
48
|
-
if (!server) {
|
|
49
|
-
throw 'Server did not start'
|
|
50
|
-
}
|
|
51
|
-
t.context.serverAddress = `http://localhost:${(server.address() as AddressInfo).port}`
|
|
52
|
-
})
|
|
53
|
-
|
|
54
|
-
cacheTests()
|
package/test/cache/redis.test.ts
DELETED
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
import Redis from 'ioredis'
|
|
2
|
-
import { AddressInfo } from 'ws'
|
|
3
|
-
import { expose } from '../../src'
|
|
4
|
-
import { Adapter, AdapterDependencies } from '../../src/adapter'
|
|
5
|
-
import { LocalCache, RedisCache } from '../../src/cache'
|
|
6
|
-
import { SettingsMap } from '../../src/config'
|
|
7
|
-
import { Transport } from '../../src/transports'
|
|
8
|
-
import { NopTransport } from '../util'
|
|
9
|
-
import { BasicCacheSetterTransport, cacheTests, test } from './helper'
|
|
10
|
-
|
|
11
|
-
class RedisMock {
|
|
12
|
-
store = new LocalCache<string>()
|
|
13
|
-
|
|
14
|
-
get(key: string) {
|
|
15
|
-
return this.store.get(key)
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
del(key: string) {
|
|
19
|
-
return this.store.delete(key)
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
set(key: string, value: string, px: 'PX', ttl: number) {
|
|
23
|
-
return this.store.set(key, value, ttl)
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
multi() {
|
|
27
|
-
return new CommandChainMock(this)
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
class CommandChainMock {
|
|
32
|
-
promises: Promise<unknown>[] = []
|
|
33
|
-
constructor(private redisMock: RedisMock) {}
|
|
34
|
-
|
|
35
|
-
set(key: string, value: string, px: 'PX', ttl: number) {
|
|
36
|
-
this.promises.push(this.redisMock.set(key, value, px, ttl))
|
|
37
|
-
return this
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
exec() {
|
|
41
|
-
return Promise.all(this.promises)
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
test.beforeEach(async (t) => {
|
|
46
|
-
const adapter: Adapter = {
|
|
47
|
-
name: 'test',
|
|
48
|
-
defaultEndpoint: 'test',
|
|
49
|
-
endpoints: [
|
|
50
|
-
{
|
|
51
|
-
name: 'test',
|
|
52
|
-
inputParameters: {
|
|
53
|
-
base: {
|
|
54
|
-
type: 'string',
|
|
55
|
-
required: true,
|
|
56
|
-
},
|
|
57
|
-
factor: {
|
|
58
|
-
type: 'number',
|
|
59
|
-
required: true,
|
|
60
|
-
},
|
|
61
|
-
},
|
|
62
|
-
transport: new BasicCacheSetterTransport() as Transport<unknown, unknown, SettingsMap>,
|
|
63
|
-
},
|
|
64
|
-
{
|
|
65
|
-
name: 'nowork',
|
|
66
|
-
inputParameters: {},
|
|
67
|
-
transport: new NopTransport(),
|
|
68
|
-
},
|
|
69
|
-
],
|
|
70
|
-
envDefaultOverrides: {
|
|
71
|
-
CACHE_POLLING_SLEEP_MS: 10,
|
|
72
|
-
CACHE_POLLING_MAX_RETRIES: 3,
|
|
73
|
-
},
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
const cache = new RedisCache(new RedisMock() as unknown as Redis) // Fake redis
|
|
77
|
-
const dependencies: Partial<AdapterDependencies> = {
|
|
78
|
-
cache,
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
t.context.cache = cache
|
|
82
|
-
const server = await expose(adapter, dependencies)
|
|
83
|
-
if (!server) {
|
|
84
|
-
throw 'Server did not start'
|
|
85
|
-
}
|
|
86
|
-
t.context.serverAddress = `http://localhost:${(server.address() as AddressInfo).port}`
|
|
87
|
-
})
|
|
88
|
-
|
|
89
|
-
cacheTests()
|
package/test/correlation.test.ts
DELETED
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
import untypedTest, { TestFn } from 'ava'
|
|
2
|
-
import axios from 'axios'
|
|
3
|
-
import { AddressInfo } from 'net'
|
|
4
|
-
import { expose } from '../src'
|
|
5
|
-
import { Adapter, AdapterEndpoint } from '../src/adapter'
|
|
6
|
-
import { AdapterResponse, sleep } from '../src/util'
|
|
7
|
-
import { NopTransport } from './util'
|
|
8
|
-
import { asyncLocalStorage, Store } from '../src/util/logger'
|
|
9
|
-
|
|
10
|
-
const test = untypedTest as TestFn<{
|
|
11
|
-
serverAddress: string
|
|
12
|
-
adapterEndpoint: AdapterEndpoint
|
|
13
|
-
}>
|
|
14
|
-
|
|
15
|
-
const startAdapter = async (enabled: boolean) => {
|
|
16
|
-
process.env['CORRELATION_ID_ENABLED'] = enabled.toString()
|
|
17
|
-
|
|
18
|
-
const adapter: Adapter = {
|
|
19
|
-
name: 'test',
|
|
20
|
-
defaultEndpoint: 'test',
|
|
21
|
-
endpoints: [
|
|
22
|
-
{
|
|
23
|
-
name: 'test',
|
|
24
|
-
inputParameters: {},
|
|
25
|
-
transport: new (class extends NopTransport {
|
|
26
|
-
override async setup(): Promise<void | AdapterResponse<null>> {
|
|
27
|
-
const store = asyncLocalStorage.getStore() as Store
|
|
28
|
-
if (store !== undefined && store['correlationId'] === '1') {
|
|
29
|
-
await sleep(100)
|
|
30
|
-
}
|
|
31
|
-
return {
|
|
32
|
-
data: null,
|
|
33
|
-
statusCode: 200,
|
|
34
|
-
result: store as unknown as null,
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
})(),
|
|
38
|
-
},
|
|
39
|
-
],
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
const server = await expose(adapter)
|
|
43
|
-
if (!server) {
|
|
44
|
-
throw 'Server did not start'
|
|
45
|
-
}
|
|
46
|
-
const serverAddress = `http://localhost:${(server.address() as AddressInfo).port}`
|
|
47
|
-
return serverAddress
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
test.serial('uses the correct correlation id when it is passed in a header', async (t) => {
|
|
51
|
-
const testId = 'test'
|
|
52
|
-
const serverAddress = await startAdapter(true)
|
|
53
|
-
const response = await axios.post(
|
|
54
|
-
serverAddress,
|
|
55
|
-
{
|
|
56
|
-
base: 'asd',
|
|
57
|
-
},
|
|
58
|
-
{
|
|
59
|
-
headers: {
|
|
60
|
-
'x-correlation-id': testId,
|
|
61
|
-
},
|
|
62
|
-
},
|
|
63
|
-
)
|
|
64
|
-
t.is(response.data.result.correlationId, testId)
|
|
65
|
-
})
|
|
66
|
-
|
|
67
|
-
test.serial('sets a correlation id when it is enabled as an env var', async (t) => {
|
|
68
|
-
const serverAddress = await startAdapter(true)
|
|
69
|
-
const response = await axios.post(serverAddress, {
|
|
70
|
-
base: 'asd',
|
|
71
|
-
})
|
|
72
|
-
t.is(typeof response.data.result.correlationId, 'string')
|
|
73
|
-
})
|
|
74
|
-
|
|
75
|
-
test.serial('correlation Id is not set when enabled is set to false', async (t) => {
|
|
76
|
-
const serverAddress = await startAdapter(false)
|
|
77
|
-
const response = await axios.post(serverAddress, {
|
|
78
|
-
base: 'asd',
|
|
79
|
-
})
|
|
80
|
-
t.is(response.data.result, undefined)
|
|
81
|
-
})
|
|
82
|
-
|
|
83
|
-
test.serial('preserves concurrency through subsequent calls', async (t) => {
|
|
84
|
-
const serverAddress = await startAdapter(true)
|
|
85
|
-
const request1 = await axios.post(
|
|
86
|
-
serverAddress,
|
|
87
|
-
{
|
|
88
|
-
base: 'asd',
|
|
89
|
-
},
|
|
90
|
-
{
|
|
91
|
-
headers: {
|
|
92
|
-
'x-correlation-id': '1',
|
|
93
|
-
},
|
|
94
|
-
},
|
|
95
|
-
)
|
|
96
|
-
// Send out second call normally
|
|
97
|
-
|
|
98
|
-
// Check that each call has the correct correlation Id
|
|
99
|
-
const request2 = axios.post(
|
|
100
|
-
serverAddress,
|
|
101
|
-
{
|
|
102
|
-
base: 'asd',
|
|
103
|
-
},
|
|
104
|
-
{
|
|
105
|
-
headers: {
|
|
106
|
-
'x-correlation-id': '2',
|
|
107
|
-
},
|
|
108
|
-
},
|
|
109
|
-
)
|
|
110
|
-
const response2 = await request2
|
|
111
|
-
const response1 = await request1
|
|
112
|
-
t.is(response1.data.result.correlationId === '1', true)
|
|
113
|
-
t.is(response2.data.result.correlationId === '2', true)
|
|
114
|
-
})
|
package/test/index.test.ts
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import untypedTest, { TestFn } from 'ava'
|
|
2
|
-
import axios from 'axios'
|
|
3
|
-
import { AddressInfo } from 'net'
|
|
4
|
-
import { expose } from '../src'
|
|
5
|
-
import { Adapter } from '../src/adapter'
|
|
6
|
-
import { NopTransport } from './util'
|
|
7
|
-
|
|
8
|
-
const test = untypedTest as TestFn<{
|
|
9
|
-
serverAddress: string
|
|
10
|
-
}>
|
|
11
|
-
|
|
12
|
-
test.beforeEach(async (t) => {
|
|
13
|
-
const adapter: Adapter = {
|
|
14
|
-
name: 'test',
|
|
15
|
-
endpoints: [
|
|
16
|
-
{
|
|
17
|
-
name: 'test',
|
|
18
|
-
inputParameters: {},
|
|
19
|
-
transport: new NopTransport(),
|
|
20
|
-
},
|
|
21
|
-
],
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
const server = await expose(adapter)
|
|
25
|
-
if (!server) {
|
|
26
|
-
throw 'Server did not start'
|
|
27
|
-
}
|
|
28
|
-
t.context.serverAddress = `http://localhost:${(server.address() as AddressInfo).port}`
|
|
29
|
-
})
|
|
30
|
-
|
|
31
|
-
test('health endpoint returns health OK', async (t) => {
|
|
32
|
-
const response = await axios.get(`${t.context.serverAddress}/health`)
|
|
33
|
-
t.deepEqual(response.data, {
|
|
34
|
-
message: 'OK',
|
|
35
|
-
version: process.env['npm_package_version'],
|
|
36
|
-
})
|
|
37
|
-
})
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import untypedTest, { TestFn } from 'ava'
|
|
2
|
-
import { AdapterEndpoint } from '../../src/adapter'
|
|
3
|
-
import { calculateFeedId } from '../../src/cache'
|
|
4
|
-
import { AdapterConfig, buildAdapterConfig } from '../../src/config'
|
|
5
|
-
import { NopTransport } from '../util'
|
|
6
|
-
|
|
7
|
-
const feedIdTest = untypedTest as TestFn<{
|
|
8
|
-
adapterEndpoint: AdapterEndpoint
|
|
9
|
-
adapterConfig: AdapterConfig
|
|
10
|
-
}>
|
|
11
|
-
|
|
12
|
-
feedIdTest.beforeEach(async (t) => {
|
|
13
|
-
t.context.adapterEndpoint = {
|
|
14
|
-
name: 'test',
|
|
15
|
-
inputParameters: {},
|
|
16
|
-
transport: new (class extends NopTransport {})(),
|
|
17
|
-
}
|
|
18
|
-
t.context.adapterConfig = buildAdapterConfig({})
|
|
19
|
-
})
|
|
20
|
-
|
|
21
|
-
feedIdTest.serial('no parameters returns N/A', async (t) => {
|
|
22
|
-
t.is(calculateFeedId(t.context, {}), 'N/A')
|
|
23
|
-
})
|
|
24
|
-
|
|
25
|
-
feedIdTest.serial('builds feed ID correctly from input params', async (t) => {
|
|
26
|
-
t.context.adapterEndpoint.inputParameters = {
|
|
27
|
-
base: {
|
|
28
|
-
type: 'string',
|
|
29
|
-
required: true,
|
|
30
|
-
},
|
|
31
|
-
quote: {
|
|
32
|
-
type: 'string',
|
|
33
|
-
required: true,
|
|
34
|
-
},
|
|
35
|
-
}
|
|
36
|
-
const data = { base: 'ETH', quote: 'BTC' }
|
|
37
|
-
t.is(calculateFeedId(t.context, data), '|base:eth|quote:btc')
|
|
38
|
-
})
|
package/test/metrics/helper.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
// Parse metrics scrape into object to use for tests
|
|
2
|
-
export const parsePromMetrics = (data: string): Map<string, number> => {
|
|
3
|
-
const responseLines = data.split('\n')
|
|
4
|
-
const metricsMap = new Map<string, number>()
|
|
5
|
-
responseLines.forEach((line) => {
|
|
6
|
-
if (!line.startsWith('#') && line !== '') {
|
|
7
|
-
const metric = line.split(' ')
|
|
8
|
-
const nameLabel = metric[0]
|
|
9
|
-
const value = Number(metric[1])
|
|
10
|
-
metricsMap.set(nameLabel, value)
|
|
11
|
-
}
|
|
12
|
-
})
|
|
13
|
-
return metricsMap
|
|
14
|
-
}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import test from 'ava'
|
|
2
|
-
import { cacheMetricsLabel } from '../../src/cache/metrics'
|
|
3
|
-
import { connectionErrorLabels, messageSubsLabels } from '../../src/transports/metrics'
|
|
4
|
-
|
|
5
|
-
test('Generate cache label test', (t) => {
|
|
6
|
-
const result = {
|
|
7
|
-
participant_id: 'test-|base:eth|quote:btc',
|
|
8
|
-
feed_id: '|base:eth|quote:btc',
|
|
9
|
-
cache_type: 'local',
|
|
10
|
-
}
|
|
11
|
-
t.deepEqual(cacheMetricsLabel('test-|base:eth|quote:btc', '|base:eth|quote:btc', 'local'), result)
|
|
12
|
-
})
|
|
13
|
-
|
|
14
|
-
test('Generate data provider metrics label test', (t) => {
|
|
15
|
-
const result = {
|
|
16
|
-
participant_id: 'test-|base:eth|quote:btc',
|
|
17
|
-
feed_id: '|base:eth|quote:btc',
|
|
18
|
-
cache_type: 'local',
|
|
19
|
-
}
|
|
20
|
-
t.deepEqual(cacheMetricsLabel('test-|base:eth|quote:btc', '|base:eth|quote:btc', 'local'), result)
|
|
21
|
-
})
|
|
22
|
-
|
|
23
|
-
test('Generate WS connection error label test', (t) => {
|
|
24
|
-
const result = {
|
|
25
|
-
message: 'error',
|
|
26
|
-
}
|
|
27
|
-
t.deepEqual(connectionErrorLabels('error'), result)
|
|
28
|
-
})
|
|
29
|
-
|
|
30
|
-
test('Generate WS message and subscription label test', (t) => {
|
|
31
|
-
const result = {
|
|
32
|
-
feed_id: '|base:eth|quote:btc',
|
|
33
|
-
subscription_key: 'test-|base:eth|quote:btc',
|
|
34
|
-
}
|
|
35
|
-
t.deepEqual(messageSubsLabels('|base:eth|quote:btc', 'test-|base:eth|quote:btc'), result)
|
|
36
|
-
})
|