@chainlink/external-adapter-framework 0.0.12 → 0.0.15
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/.eslintignore +1 -0
- package/.github/README.MD +35 -10
- package/.github/workflows/label.yaml +39 -0
- package/.github/workflows/publish.yaml +0 -3
- package/dist/examples/coingecko/test/e2e/adapter.test.ts.js +82953 -0
- package/dist/examples/coingecko/test/integration/adapter.test.ts.js +91672 -0
- package/dist/main.js +72703 -0
- package/jest.config.js +5 -0
- package/package.json +14 -3
- package/src/config/provider-limits.ts +14 -17
- package/src/examples/coingecko/src/config/index.ts +12 -0
- package/src/examples/coingecko/src/config/overrides.json +10826 -0
- package/src/examples/coingecko/src/cryptoUtils.ts +88 -0
- package/src/examples/coingecko/src/endpoint/coins.ts +54 -0
- package/src/examples/coingecko/src/endpoint/crypto-marketcap.ts +66 -0
- package/src/examples/coingecko/src/endpoint/crypto-volume.ts +66 -0
- package/src/examples/coingecko/src/endpoint/crypto.ts +63 -0
- package/src/examples/coingecko/src/endpoint/dominance.ts +40 -0
- package/src/examples/coingecko/src/endpoint/global-marketcap.ts +40 -0
- package/src/examples/coingecko/src/endpoint/index.ts +6 -0
- package/src/examples/coingecko/src/globalUtils.ts +78 -0
- package/src/examples/coingecko/src/index.ts +17 -0
- package/src/examples/coingecko/test/e2e/adapter.test.ts +278 -0
- package/src/examples/coingecko/test/integration/__snapshots__/adapter.test.ts.snap +15 -0
- package/src/examples/coingecko/test/integration/adapter.test.ts +281 -0
- package/src/examples/coingecko/test/integration/capturedRequests.json +1 -0
- package/src/examples/coingecko/test/integration/fixtures.ts +42 -0
- package/src/examples/{coingecko → coingecko-old}/batch-warming.ts +1 -0
- package/src/examples/{coingecko → coingecko-old}/index.ts +0 -0
- package/src/examples/{coingecko → coingecko-old}/rest.ts +0 -0
- package/src/transports/batch-warming.ts +7 -2
- package/src/transports/rest.ts +5 -1
- package/src/util/index.ts +1 -0
- package/src/util/recordRequests.ts +47 -0
- package/src/validation/overrideFunctions.ts +44 -0
- package/test/metrics/warmer-metrics.test.ts +1 -0
- package/test/{smoke.test.ts → smoke/smoke.test.ts} +13 -13
- package/{test-payload-fail.json → test/smoke/test-payload-fail.json} +0 -0
- package/{test-payload.js → test/smoke/test-payload.js} +0 -0
- package/{test-payload.json → test/smoke/test-payload.json} +0 -0
- package/test/transports/batch.test.ts +1 -0
- package/tsconfig.json +4 -1
- package/webpack.config.js +39 -5
- package/yarn-error.log +3778 -0
- package/dist/src/adapter.d.ts +0 -135
- package/dist/src/adapter.js +0 -145
- package/dist/src/background-executor.d.ts +0 -11
- package/dist/src/background-executor.js +0 -45
- package/dist/src/cache/factory.d.ts +0 -6
- package/dist/src/cache/factory.js +0 -55
- package/dist/src/cache/index.d.ts +0 -94
- package/dist/src/cache/index.js +0 -173
- package/dist/src/cache/local.d.ts +0 -23
- package/dist/src/cache/local.js +0 -83
- package/dist/src/cache/metrics.d.ts +0 -27
- package/dist/src/cache/metrics.js +0 -120
- package/dist/src/cache/redis.d.ts +0 -16
- package/dist/src/cache/redis.js +0 -100
- package/dist/src/chainlink-external-adapter-framework-0.0.6.tgz +0 -0
- package/dist/src/config/index.d.ts +0 -214
- package/dist/src/config/index.js +0 -380
- package/dist/src/config/provider-limits.d.ts +0 -31
- package/dist/src/config/provider-limits.js +0 -75
- package/dist/src/examples/bank-frick/accounts.d.ts +0 -39
- package/dist/src/examples/bank-frick/accounts.js +0 -192
- package/dist/src/examples/bank-frick/config/index.d.ts +0 -4
- package/dist/src/examples/bank-frick/config/index.js +0 -54
- package/dist/src/examples/bank-frick/index.d.ts +0 -2
- package/dist/src/examples/bank-frick/index.js +0 -15
- package/dist/src/examples/bank-frick/util.d.ts +0 -4
- package/dist/src/examples/bank-frick/util.js +0 -39
- package/dist/src/examples/coingecko/batch-warming.d.ts +0 -7
- package/dist/src/examples/coingecko/batch-warming.js +0 -53
- package/dist/src/examples/coingecko/index.d.ts +0 -2
- package/dist/src/examples/coingecko/index.js +0 -11
- package/dist/src/examples/coingecko/rest.d.ts +0 -12
- package/dist/src/examples/coingecko/rest.js +0 -51
- package/dist/src/examples/ncfx/config/index.d.ts +0 -12
- package/dist/src/examples/ncfx/config/index.js +0 -15
- package/dist/src/examples/ncfx/index.d.ts +0 -13
- package/dist/src/examples/ncfx/index.js +0 -11
- package/dist/src/examples/ncfx/websocket.d.ts +0 -47
- package/dist/src/examples/ncfx/websocket.js +0 -73
- package/dist/src/index.d.ts +0 -11
- package/dist/src/index.js +0 -128
- package/dist/src/metrics/constants.d.ts +0 -16
- package/dist/src/metrics/constants.js +0 -25
- package/dist/src/metrics/index.d.ts +0 -15
- package/dist/src/metrics/index.js +0 -122
- package/dist/src/metrics/util.d.ts +0 -7
- package/dist/src/metrics/util.js +0 -9
- package/dist/src/package/adapter.d.ts +0 -88
- package/dist/src/package/adapter.js +0 -112
- package/dist/src/package/background-executor.d.ts +0 -11
- package/dist/src/package/background-executor.js +0 -45
- package/dist/src/package/cache/factory.d.ts +0 -6
- package/dist/src/package/cache/factory.js +0 -57
- package/dist/src/package/cache/index.d.ts +0 -90
- package/dist/src/package/cache/index.js +0 -169
- package/dist/src/package/cache/local.d.ts +0 -23
- package/dist/src/package/cache/local.js +0 -83
- package/dist/src/package/cache/metrics.d.ts +0 -27
- package/dist/src/package/cache/metrics.js +0 -120
- package/dist/src/package/cache/redis.d.ts +0 -16
- package/dist/src/package/cache/redis.js +0 -100
- package/dist/src/package/config/index.d.ts +0 -195
- package/dist/src/package/config/index.js +0 -365
- package/dist/src/package/config/provider-limits.d.ts +0 -31
- package/dist/src/package/config/provider-limits.js +0 -76
- package/dist/src/package/examples/coingecko/batch-warming.d.ts +0 -2
- package/dist/src/package/examples/coingecko/batch-warming.js +0 -52
- package/dist/src/package/examples/coingecko/index.d.ts +0 -2
- package/dist/src/package/examples/coingecko/index.js +0 -10
- package/dist/src/package/examples/coingecko/rest.d.ts +0 -2
- package/dist/src/package/examples/coingecko/rest.js +0 -50
- package/dist/src/package/examples/ncfx/config/index.d.ts +0 -12
- package/dist/src/package/examples/ncfx/config/index.js +0 -15
- package/dist/src/package/examples/ncfx/index.d.ts +0 -2
- package/dist/src/package/examples/ncfx/index.js +0 -10
- package/dist/src/package/examples/ncfx/websocket.d.ts +0 -36
- package/dist/src/package/examples/ncfx/websocket.js +0 -72
- package/dist/src/package/index.d.ts +0 -12
- package/dist/src/package/index.js +0 -92
- package/dist/src/package/metrics/constants.d.ts +0 -16
- package/dist/src/package/metrics/constants.js +0 -25
- package/dist/src/package/metrics/index.d.ts +0 -15
- package/dist/src/package/metrics/index.js +0 -123
- package/dist/src/package/metrics/util.d.ts +0 -3
- package/dist/src/package/metrics/util.js +0 -9
- package/dist/src/package/package.json +0 -72
- package/dist/src/package/rate-limiting/background/fixed-frequency.d.ts +0 -10
- package/dist/src/package/rate-limiting/background/fixed-frequency.js +0 -37
- package/dist/src/package/rate-limiting/index.d.ts +0 -54
- package/dist/src/package/rate-limiting/index.js +0 -63
- package/dist/src/package/rate-limiting/metrics.d.ts +0 -3
- package/dist/src/package/rate-limiting/metrics.js +0 -44
- package/dist/src/package/rate-limiting/request/simple-counting.d.ts +0 -20
- package/dist/src/package/rate-limiting/request/simple-counting.js +0 -62
- package/dist/src/package/test.d.ts +0 -1
- package/dist/src/package/test.js +0 -6
- package/dist/src/package/transports/batch-warming.d.ts +0 -34
- package/dist/src/package/transports/batch-warming.js +0 -101
- package/dist/src/package/transports/index.d.ts +0 -87
- package/dist/src/package/transports/index.js +0 -87
- package/dist/src/package/transports/metrics.d.ts +0 -21
- package/dist/src/package/transports/metrics.js +0 -105
- package/dist/src/package/transports/rest.d.ts +0 -43
- package/dist/src/package/transports/rest.js +0 -129
- package/dist/src/package/transports/util.d.ts +0 -8
- package/dist/src/package/transports/util.js +0 -85
- package/dist/src/package/transports/websocket.d.ts +0 -80
- package/dist/src/package/transports/websocket.js +0 -169
- package/dist/src/package/util/expiring-sorted-set.d.ts +0 -21
- package/dist/src/package/util/expiring-sorted-set.js +0 -47
- package/dist/src/package/util/index.d.ts +0 -11
- package/dist/src/package/util/index.js +0 -35
- package/dist/src/package/util/logger.d.ts +0 -42
- package/dist/src/package/util/logger.js +0 -62
- package/dist/src/package/util/request.d.ts +0 -55
- package/dist/src/package/util/request.js +0 -2
- package/dist/src/package/validation/error.d.ts +0 -50
- package/dist/src/package/validation/error.js +0 -79
- package/dist/src/package/validation/index.d.ts +0 -5
- package/dist/src/package/validation/index.js +0 -86
- package/dist/src/package/validation/input-params.d.ts +0 -15
- package/dist/src/package/validation/input-params.js +0 -30
- package/dist/src/package/validation/override-functions.d.ts +0 -3
- package/dist/src/package/validation/override-functions.js +0 -40
- package/dist/src/package/validation/preset-tokens.json +0 -23
- package/dist/src/package/validation/validator.d.ts +0 -47
- package/dist/src/package/validation/validator.js +0 -303
- package/dist/src/package.json +0 -72
- package/dist/src/rate-limiting/background/fixed-frequency.d.ts +0 -11
- package/dist/src/rate-limiting/background/fixed-frequency.js +0 -35
- package/dist/src/rate-limiting/index.d.ts +0 -55
- package/dist/src/rate-limiting/index.js +0 -63
- package/dist/src/rate-limiting/metrics.d.ts +0 -3
- package/dist/src/rate-limiting/metrics.js +0 -44
- package/dist/src/rate-limiting/request/simple-counting.d.ts +0 -21
- package/dist/src/rate-limiting/request/simple-counting.js +0 -62
- package/dist/src/test.d.ts +0 -1
- package/dist/src/test.js +0 -6
- package/dist/src/transports/batch-warming.d.ts +0 -35
- package/dist/src/transports/batch-warming.js +0 -101
- package/dist/src/transports/index.d.ts +0 -70
- package/dist/src/transports/index.js +0 -87
- package/dist/src/transports/metrics.d.ts +0 -22
- package/dist/src/transports/metrics.js +0 -105
- package/dist/src/transports/rest.d.ts +0 -44
- package/dist/src/transports/rest.js +0 -131
- package/dist/src/transports/util.d.ts +0 -8
- package/dist/src/transports/util.js +0 -85
- package/dist/src/transports/websocket.d.ts +0 -80
- package/dist/src/transports/websocket.js +0 -166
- package/dist/src/util/expiring-sorted-set.d.ts +0 -21
- package/dist/src/util/expiring-sorted-set.js +0 -47
- package/dist/src/util/index.d.ts +0 -12
- package/dist/src/util/index.js +0 -35
- package/dist/src/util/logger.d.ts +0 -42
- package/dist/src/util/logger.js +0 -62
- package/dist/src/util/request.d.ts +0 -57
- package/dist/src/util/request.js +0 -2
- package/dist/src/util/subscription-set/expiring-sorted-set.d.ts +0 -22
- package/dist/src/util/subscription-set/expiring-sorted-set.js +0 -47
- package/dist/src/util/subscription-set/subscription-set.d.ts +0 -18
- package/dist/src/util/subscription-set/subscription-set.js +0 -19
- package/dist/src/util/test-payload-loader.d.ts +0 -25
- package/dist/src/util/test-payload-loader.js +0 -83
- package/dist/src/validation/error.d.ts +0 -50
- package/dist/src/validation/error.js +0 -79
- package/dist/src/validation/index.d.ts +0 -5
- package/dist/src/validation/index.js +0 -91
- package/dist/src/validation/input-params.d.ts +0 -15
- package/dist/src/validation/input-params.js +0 -30
- package/dist/src/validation/override-functions.d.ts +0 -3
- package/dist/src/validation/override-functions.js +0 -40
- package/dist/src/validation/preset-tokens.json +0 -23
- package/dist/src/validation/validator.d.ts +0 -47
- package/dist/src/validation/validator.js +0 -303
- package/src/test.ts +0 -5
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
/* eslint-disable max-nested-callbacks */
|
|
2
|
+
import { adapter } from '../../src/index'
|
|
3
|
+
import { expose } from '../../../..'
|
|
4
|
+
import { Server } from 'http'
|
|
5
|
+
import request, { SuperTest, Test } from 'supertest'
|
|
6
|
+
|
|
7
|
+
let adapterServer: Server | undefined
|
|
8
|
+
|
|
9
|
+
function sleep(ms: number) {
|
|
10
|
+
// eslint-disable-next-line
|
|
11
|
+
return new Promise((resolve) => setTimeout(resolve, ms))
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
describe('execute', () => {
|
|
15
|
+
const id = '1'
|
|
16
|
+
let req: SuperTest<Test>
|
|
17
|
+
|
|
18
|
+
jest.setTimeout(10000)
|
|
19
|
+
|
|
20
|
+
const successfulRequests = {
|
|
21
|
+
crypto: {
|
|
22
|
+
id,
|
|
23
|
+
data: {
|
|
24
|
+
base: 'ETH',
|
|
25
|
+
quote: 'USD',
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
cryptoWithCoinid: {
|
|
29
|
+
id,
|
|
30
|
+
data: {
|
|
31
|
+
coinid: 'bitcoin',
|
|
32
|
+
quote: 'USD',
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
cryptoWithOverride: {
|
|
36
|
+
id,
|
|
37
|
+
data: {
|
|
38
|
+
base: 'BTC',
|
|
39
|
+
quote: 'EUR',
|
|
40
|
+
overrides: {
|
|
41
|
+
coingecko: {
|
|
42
|
+
BTC: 'solana',
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
coins: {
|
|
48
|
+
id,
|
|
49
|
+
endpoint: 'coins',
|
|
50
|
+
},
|
|
51
|
+
marketcap: {
|
|
52
|
+
id,
|
|
53
|
+
endpoint: 'marketcap',
|
|
54
|
+
data: {
|
|
55
|
+
base: 'ETH',
|
|
56
|
+
quote: 'USD',
|
|
57
|
+
},
|
|
58
|
+
},
|
|
59
|
+
volume: {
|
|
60
|
+
id,
|
|
61
|
+
endpoint: 'volume',
|
|
62
|
+
data: {
|
|
63
|
+
base: 'ETH',
|
|
64
|
+
quote: 'USD',
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
globalmarketcap: {
|
|
68
|
+
id,
|
|
69
|
+
endpoint: 'globalmarketcap',
|
|
70
|
+
data: {
|
|
71
|
+
market: 'ETH',
|
|
72
|
+
},
|
|
73
|
+
},
|
|
74
|
+
dominance: {
|
|
75
|
+
id,
|
|
76
|
+
endpoint: 'dominance',
|
|
77
|
+
data: {
|
|
78
|
+
market: 'ETH',
|
|
79
|
+
},
|
|
80
|
+
},
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const errorRequests = {
|
|
84
|
+
cryptoWithBadSymbol: {
|
|
85
|
+
id,
|
|
86
|
+
data: {
|
|
87
|
+
base: 'ZWXK',
|
|
88
|
+
quote: 'USD',
|
|
89
|
+
},
|
|
90
|
+
},
|
|
91
|
+
cryptoWithBadOverride: {
|
|
92
|
+
id,
|
|
93
|
+
data: {
|
|
94
|
+
base: 'LINK',
|
|
95
|
+
quote: 'USD',
|
|
96
|
+
overrides: {
|
|
97
|
+
coingecko: {
|
|
98
|
+
LINK: 'badtokenid',
|
|
99
|
+
},
|
|
100
|
+
},
|
|
101
|
+
},
|
|
102
|
+
},
|
|
103
|
+
dominanceWithBadSymbol: {
|
|
104
|
+
id,
|
|
105
|
+
endpoint: 'dominance',
|
|
106
|
+
data: {
|
|
107
|
+
market: 'ZWXK',
|
|
108
|
+
},
|
|
109
|
+
},
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
beforeAll(async () => {
|
|
113
|
+
try {
|
|
114
|
+
adapterServer = await expose(adapter)
|
|
115
|
+
req = request('localhost:8080')
|
|
116
|
+
} catch {
|
|
117
|
+
throw new Error('Could not start server when running CoinGecko e2e tests')
|
|
118
|
+
}
|
|
119
|
+
if (!adapterServer) {
|
|
120
|
+
throw new Error('Could not start server when running CoinGecko e2e tests')
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// Send inital requests to warm the cache
|
|
124
|
+
const pendingRequests: Test[] = []
|
|
125
|
+
for (const reqData of Object.values(successfulRequests)) {
|
|
126
|
+
pendingRequests.push(req.post('/').send(reqData))
|
|
127
|
+
}
|
|
128
|
+
for (const reqData of Object.values(errorRequests)) {
|
|
129
|
+
pendingRequests.push(req.post('/').send(reqData))
|
|
130
|
+
}
|
|
131
|
+
// Wait for all the pending requests to be complete
|
|
132
|
+
Promise.all(pendingRequests)
|
|
133
|
+
// Sleep while the cache is filled
|
|
134
|
+
await sleep(5000)
|
|
135
|
+
})
|
|
136
|
+
|
|
137
|
+
afterAll((done) => {
|
|
138
|
+
if (adapterServer) {
|
|
139
|
+
adapterServer.close(done())
|
|
140
|
+
}
|
|
141
|
+
})
|
|
142
|
+
|
|
143
|
+
describe('crypto api', () => {
|
|
144
|
+
it('should return success', async () => {
|
|
145
|
+
// Send inital request to warm cache
|
|
146
|
+
const response = await req
|
|
147
|
+
.post('/')
|
|
148
|
+
.send(successfulRequests.crypto)
|
|
149
|
+
.set('Accept', '*/*')
|
|
150
|
+
.set('Content-Type', 'application/json')
|
|
151
|
+
.expect(200)
|
|
152
|
+
expect(response.body.result).toBeGreaterThan(0)
|
|
153
|
+
})
|
|
154
|
+
|
|
155
|
+
it('should return success with coinid', async () => {
|
|
156
|
+
const response = await req
|
|
157
|
+
.post('/')
|
|
158
|
+
.send(successfulRequests.cryptoWithCoinid)
|
|
159
|
+
.set('Accept', '*/*')
|
|
160
|
+
.set('Content-Type', 'application/json')
|
|
161
|
+
.expect('Content-Type', /json/)
|
|
162
|
+
.expect(200)
|
|
163
|
+
expect(response.body.result).toBeGreaterThan(0)
|
|
164
|
+
})
|
|
165
|
+
|
|
166
|
+
it('should return error message for bad symbol', async () => {
|
|
167
|
+
await req
|
|
168
|
+
.post('/')
|
|
169
|
+
.send(errorRequests.cryptoWithBadSymbol)
|
|
170
|
+
.set('Accept', '*/*')
|
|
171
|
+
.set('Content-Type', 'application/json')
|
|
172
|
+
.expect(504)
|
|
173
|
+
})
|
|
174
|
+
|
|
175
|
+
it('should return success with override', async () => {
|
|
176
|
+
const response = await req
|
|
177
|
+
.post('/')
|
|
178
|
+
.send(successfulRequests.cryptoWithOverride)
|
|
179
|
+
.set('Accept', '*/*')
|
|
180
|
+
.set('Content-Type', 'application/json')
|
|
181
|
+
.expect('Content-Type', /json/)
|
|
182
|
+
.expect(200)
|
|
183
|
+
expect(response.body.result).toBeGreaterThan(0)
|
|
184
|
+
})
|
|
185
|
+
|
|
186
|
+
it('should return 504 for bad override', async () => {
|
|
187
|
+
const response = await req
|
|
188
|
+
.post('/')
|
|
189
|
+
.send(errorRequests.cryptoWithBadOverride)
|
|
190
|
+
.set('Accept', '*/*')
|
|
191
|
+
.set('Content-Type', 'application/json')
|
|
192
|
+
.expect(504)
|
|
193
|
+
expect(typeof response.body.result === 'string')
|
|
194
|
+
})
|
|
195
|
+
|
|
196
|
+
it('should return 504 for bad symbol', async () => {
|
|
197
|
+
await req
|
|
198
|
+
.post('/')
|
|
199
|
+
.send(errorRequests.cryptoWithBadSymbol)
|
|
200
|
+
.set('Accept', '*/*')
|
|
201
|
+
.set('Content-Type', 'application/json')
|
|
202
|
+
.expect(504)
|
|
203
|
+
})
|
|
204
|
+
})
|
|
205
|
+
|
|
206
|
+
describe('coins api', () => {
|
|
207
|
+
it('should return success', async () => {
|
|
208
|
+
await req
|
|
209
|
+
.post('/')
|
|
210
|
+
.send(successfulRequests.coins)
|
|
211
|
+
.set('Accept', '*/*')
|
|
212
|
+
.set('Content-Type', 'application/json')
|
|
213
|
+
.expect('Content-Type', /json/)
|
|
214
|
+
.expect(200)
|
|
215
|
+
})
|
|
216
|
+
})
|
|
217
|
+
|
|
218
|
+
describe('volume api', () => {
|
|
219
|
+
it('should return success', async () => {
|
|
220
|
+
const response = await req
|
|
221
|
+
.post('/')
|
|
222
|
+
.send(successfulRequests.volume)
|
|
223
|
+
.set('Accept', '*/*')
|
|
224
|
+
.set('Content-Type', 'application/json')
|
|
225
|
+
.expect('Content-Type', /json/)
|
|
226
|
+
.expect(200)
|
|
227
|
+
expect(response.body.result).toBeGreaterThan(0)
|
|
228
|
+
})
|
|
229
|
+
})
|
|
230
|
+
|
|
231
|
+
describe('marketcap api', () => {
|
|
232
|
+
it('should return success', async () => {
|
|
233
|
+
const response = await req
|
|
234
|
+
.post('/')
|
|
235
|
+
.send(successfulRequests.marketcap)
|
|
236
|
+
.set('Accept', '*/*')
|
|
237
|
+
.set('Content-Type', 'application/json')
|
|
238
|
+
.expect('Content-Type', /json/)
|
|
239
|
+
.expect(200)
|
|
240
|
+
expect(response.body.result).toBeGreaterThan(0)
|
|
241
|
+
})
|
|
242
|
+
})
|
|
243
|
+
|
|
244
|
+
describe('globalmarketcap api', () => {
|
|
245
|
+
it('should return success', async () => {
|
|
246
|
+
const response = await req
|
|
247
|
+
.post('/')
|
|
248
|
+
.send(successfulRequests.globalmarketcap)
|
|
249
|
+
.set('Accept', '*/*')
|
|
250
|
+
.set('Content-Type', 'application/json')
|
|
251
|
+
.expect('Content-Type', /json/)
|
|
252
|
+
.expect(200)
|
|
253
|
+
expect(response.body.result).toBeGreaterThan(0)
|
|
254
|
+
})
|
|
255
|
+
})
|
|
256
|
+
|
|
257
|
+
describe('dominance api', () => {
|
|
258
|
+
it('should return success', async () => {
|
|
259
|
+
const response = await req
|
|
260
|
+
.post('/')
|
|
261
|
+
.send(successfulRequests.dominance)
|
|
262
|
+
.set('Accept', '*/*')
|
|
263
|
+
.set('Content-Type', 'application/json')
|
|
264
|
+
.expect('Content-Type', /json/)
|
|
265
|
+
.expect(200)
|
|
266
|
+
expect(response.body.result).toBeGreaterThan(0)
|
|
267
|
+
})
|
|
268
|
+
|
|
269
|
+
it('should return 504 for bad symbol', async () => {
|
|
270
|
+
await req
|
|
271
|
+
.post('/')
|
|
272
|
+
.send(errorRequests.dominanceWithBadSymbol)
|
|
273
|
+
.set('Accept', '*/*')
|
|
274
|
+
.set('Content-Type', 'application/json')
|
|
275
|
+
.expect(504)
|
|
276
|
+
})
|
|
277
|
+
})
|
|
278
|
+
})
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
+
|
|
3
|
+
exports[`execute crypto api should return success 1`] = `1538.07`;
|
|
4
|
+
|
|
5
|
+
exports[`execute crypto api should return success with coinid 1`] = `19870.79`;
|
|
6
|
+
|
|
7
|
+
exports[`execute crypto api should return success with override 1`] = `31.56`;
|
|
8
|
+
|
|
9
|
+
exports[`execute dominance api should return success 1`] = `18.279852881342133`;
|
|
10
|
+
|
|
11
|
+
exports[`execute globalmarketcap api should return success 1`] = `658754556.659843`;
|
|
12
|
+
|
|
13
|
+
exports[`execute marketcap api should return success 1`] = `185951583005.47522`;
|
|
14
|
+
|
|
15
|
+
exports[`execute volume api should return success 1`] = `19905025820.52171`;
|
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
/* eslint-disable max-nested-callbacks */
|
|
2
|
+
import { adapter } from '../../src/index'
|
|
3
|
+
import { expose } from '../../../..'
|
|
4
|
+
import { Server } from 'http'
|
|
5
|
+
import request, { SuperTest, Test } from 'supertest'
|
|
6
|
+
import { createMocks } from './fixtures'
|
|
7
|
+
|
|
8
|
+
let adapterServer: Server | undefined
|
|
9
|
+
|
|
10
|
+
function sleep(ms: number) {
|
|
11
|
+
// eslint-disable-next-line
|
|
12
|
+
return new Promise((resolve) => setTimeout(resolve, ms))
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
describe('execute', () => {
|
|
16
|
+
const id = '1'
|
|
17
|
+
let req: SuperTest<Test>
|
|
18
|
+
|
|
19
|
+
jest.setTimeout(10000)
|
|
20
|
+
|
|
21
|
+
const successfulRequests = {
|
|
22
|
+
crypto: {
|
|
23
|
+
id,
|
|
24
|
+
data: {
|
|
25
|
+
base: 'ETH',
|
|
26
|
+
quote: 'USD',
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
cryptoWithCoinid: {
|
|
30
|
+
id,
|
|
31
|
+
data: {
|
|
32
|
+
coinid: 'bitcoin',
|
|
33
|
+
quote: 'USD',
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
cryptoWithOverride: {
|
|
37
|
+
id,
|
|
38
|
+
data: {
|
|
39
|
+
base: 'BTC',
|
|
40
|
+
quote: 'EUR',
|
|
41
|
+
overrides: {
|
|
42
|
+
coingecko: {
|
|
43
|
+
BTC: 'solana',
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
coins: {
|
|
49
|
+
id,
|
|
50
|
+
endpoint: 'coins',
|
|
51
|
+
},
|
|
52
|
+
marketcap: {
|
|
53
|
+
id,
|
|
54
|
+
endpoint: 'marketcap',
|
|
55
|
+
data: {
|
|
56
|
+
base: 'ETH',
|
|
57
|
+
quote: 'USD',
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
volume: {
|
|
61
|
+
id,
|
|
62
|
+
endpoint: 'volume',
|
|
63
|
+
data: {
|
|
64
|
+
base: 'ETH',
|
|
65
|
+
quote: 'USD',
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
globalmarketcap: {
|
|
69
|
+
id,
|
|
70
|
+
endpoint: 'globalmarketcap',
|
|
71
|
+
data: {
|
|
72
|
+
market: 'ETH',
|
|
73
|
+
},
|
|
74
|
+
},
|
|
75
|
+
dominance: {
|
|
76
|
+
id,
|
|
77
|
+
endpoint: 'dominance',
|
|
78
|
+
data: {
|
|
79
|
+
market: 'ETH',
|
|
80
|
+
},
|
|
81
|
+
},
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const errorRequests = {
|
|
85
|
+
cryptoWithBadSymbol: {
|
|
86
|
+
id,
|
|
87
|
+
data: {
|
|
88
|
+
base: 'ZWXK',
|
|
89
|
+
quote: 'USD',
|
|
90
|
+
},
|
|
91
|
+
},
|
|
92
|
+
cryptoWithBadOverride: {
|
|
93
|
+
id,
|
|
94
|
+
data: {
|
|
95
|
+
base: 'LINK',
|
|
96
|
+
quote: 'USD',
|
|
97
|
+
overrides: {
|
|
98
|
+
coingecko: {
|
|
99
|
+
LINK: 'badtokenid',
|
|
100
|
+
},
|
|
101
|
+
},
|
|
102
|
+
},
|
|
103
|
+
},
|
|
104
|
+
dominanceWithBadSymbol: {
|
|
105
|
+
id,
|
|
106
|
+
endpoint: 'dominance',
|
|
107
|
+
data: {
|
|
108
|
+
market: 'ZWXK',
|
|
109
|
+
},
|
|
110
|
+
},
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
beforeAll(async () => {
|
|
114
|
+
try {
|
|
115
|
+
adapterServer = await expose(adapter)
|
|
116
|
+
req = request('localhost:8080')
|
|
117
|
+
} catch {
|
|
118
|
+
throw new Error('Could not start server when running CoinGecko e2e tests')
|
|
119
|
+
}
|
|
120
|
+
if (!adapterServer) {
|
|
121
|
+
throw new Error('Could not start server when running CoinGecko e2e tests')
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
createMocks()
|
|
125
|
+
|
|
126
|
+
// Send inital requests to warm the cache
|
|
127
|
+
const pendingRequests: Test[] = []
|
|
128
|
+
for (const reqData of Object.values(successfulRequests)) {
|
|
129
|
+
pendingRequests.push(req.post('/').send(reqData))
|
|
130
|
+
}
|
|
131
|
+
for (const reqData of Object.values(errorRequests)) {
|
|
132
|
+
pendingRequests.push(req.post('/').send(reqData))
|
|
133
|
+
}
|
|
134
|
+
// Wait for all the pending requests to be complete
|
|
135
|
+
Promise.all(pendingRequests)
|
|
136
|
+
// Sleep while the cache is filled
|
|
137
|
+
await sleep(5000)
|
|
138
|
+
})
|
|
139
|
+
|
|
140
|
+
afterAll((done) => {
|
|
141
|
+
if (adapterServer) {
|
|
142
|
+
adapterServer.close(done())
|
|
143
|
+
}
|
|
144
|
+
})
|
|
145
|
+
|
|
146
|
+
describe('crypto api', () => {
|
|
147
|
+
it('should return success', async () => {
|
|
148
|
+
// Send inital request to warm cache
|
|
149
|
+
const response = await req
|
|
150
|
+
.post('/')
|
|
151
|
+
.send(successfulRequests.crypto)
|
|
152
|
+
.set('Accept', '*/*')
|
|
153
|
+
.set('Content-Type', 'application/json')
|
|
154
|
+
.expect(200)
|
|
155
|
+
expect(response.body.result).toMatchSnapshot()
|
|
156
|
+
})
|
|
157
|
+
|
|
158
|
+
it('should return success with coinid', async () => {
|
|
159
|
+
const response = await req
|
|
160
|
+
.post('/')
|
|
161
|
+
.send(successfulRequests.cryptoWithCoinid)
|
|
162
|
+
.set('Accept', '*/*')
|
|
163
|
+
.set('Content-Type', 'application/json')
|
|
164
|
+
.expect('Content-Type', /json/)
|
|
165
|
+
.expect(200)
|
|
166
|
+
expect(response.body.result).toMatchSnapshot()
|
|
167
|
+
})
|
|
168
|
+
|
|
169
|
+
it('should return error message for bad symbol', async () => {
|
|
170
|
+
await req
|
|
171
|
+
.post('/')
|
|
172
|
+
.send(errorRequests.cryptoWithBadSymbol)
|
|
173
|
+
.set('Accept', '*/*')
|
|
174
|
+
.set('Content-Type', 'application/json')
|
|
175
|
+
.expect(504)
|
|
176
|
+
})
|
|
177
|
+
|
|
178
|
+
it('should return success with override', async () => {
|
|
179
|
+
const response = await req
|
|
180
|
+
.post('/')
|
|
181
|
+
.send(successfulRequests.cryptoWithOverride)
|
|
182
|
+
.set('Accept', '*/*')
|
|
183
|
+
.set('Content-Type', 'application/json')
|
|
184
|
+
.expect('Content-Type', /json/)
|
|
185
|
+
.expect(200)
|
|
186
|
+
expect(response.body.result).toMatchSnapshot()
|
|
187
|
+
})
|
|
188
|
+
|
|
189
|
+
it('should return 504 for bad override', async () => {
|
|
190
|
+
const response = await req
|
|
191
|
+
.post('/')
|
|
192
|
+
.send(errorRequests.cryptoWithBadOverride)
|
|
193
|
+
.set('Accept', '*/*')
|
|
194
|
+
.set('Content-Type', 'application/json')
|
|
195
|
+
.expect(504)
|
|
196
|
+
expect(typeof response.body.result === 'string')
|
|
197
|
+
})
|
|
198
|
+
|
|
199
|
+
it('should return 504 for bad symbol', async () => {
|
|
200
|
+
await req
|
|
201
|
+
.post('/')
|
|
202
|
+
.send(errorRequests.cryptoWithBadSymbol)
|
|
203
|
+
.set('Accept', '*/*')
|
|
204
|
+
.set('Content-Type', 'application/json')
|
|
205
|
+
.expect(504)
|
|
206
|
+
})
|
|
207
|
+
})
|
|
208
|
+
|
|
209
|
+
describe('coins api', () => {
|
|
210
|
+
it('should return success', async () => {
|
|
211
|
+
await req
|
|
212
|
+
.post('/')
|
|
213
|
+
.send(successfulRequests.coins)
|
|
214
|
+
.set('Accept', '*/*')
|
|
215
|
+
.set('Content-Type', 'application/json')
|
|
216
|
+
.expect('Content-Type', /json/)
|
|
217
|
+
.expect(200)
|
|
218
|
+
})
|
|
219
|
+
})
|
|
220
|
+
|
|
221
|
+
describe('volume api', () => {
|
|
222
|
+
it('should return success', async () => {
|
|
223
|
+
const response = await req
|
|
224
|
+
.post('/')
|
|
225
|
+
.send(successfulRequests.volume)
|
|
226
|
+
.set('Accept', '*/*')
|
|
227
|
+
.set('Content-Type', 'application/json')
|
|
228
|
+
.expect('Content-Type', /json/)
|
|
229
|
+
.expect(200)
|
|
230
|
+
expect(response.body.result).toMatchSnapshot()
|
|
231
|
+
})
|
|
232
|
+
})
|
|
233
|
+
|
|
234
|
+
describe('marketcap api', () => {
|
|
235
|
+
it('should return success', async () => {
|
|
236
|
+
const response = await req
|
|
237
|
+
.post('/')
|
|
238
|
+
.send(successfulRequests.marketcap)
|
|
239
|
+
.set('Accept', '*/*')
|
|
240
|
+
.set('Content-Type', 'application/json')
|
|
241
|
+
.expect('Content-Type', /json/)
|
|
242
|
+
.expect(200)
|
|
243
|
+
expect(response.body.result).toMatchSnapshot()
|
|
244
|
+
})
|
|
245
|
+
})
|
|
246
|
+
|
|
247
|
+
describe('globalmarketcap api', () => {
|
|
248
|
+
it('should return success', async () => {
|
|
249
|
+
const response = await req
|
|
250
|
+
.post('/')
|
|
251
|
+
.send(successfulRequests.globalmarketcap)
|
|
252
|
+
.set('Accept', '*/*')
|
|
253
|
+
.set('Content-Type', 'application/json')
|
|
254
|
+
.expect('Content-Type', /json/)
|
|
255
|
+
.expect(200)
|
|
256
|
+
expect(response.body.result).toMatchSnapshot()
|
|
257
|
+
})
|
|
258
|
+
})
|
|
259
|
+
|
|
260
|
+
describe('dominance api', () => {
|
|
261
|
+
it('should return success', async () => {
|
|
262
|
+
const response = await req
|
|
263
|
+
.post('/')
|
|
264
|
+
.send(successfulRequests.dominance)
|
|
265
|
+
.set('Accept', '*/*')
|
|
266
|
+
.set('Content-Type', 'application/json')
|
|
267
|
+
.expect('Content-Type', /json/)
|
|
268
|
+
.expect(200)
|
|
269
|
+
expect(response.body.result).toMatchSnapshot()
|
|
270
|
+
})
|
|
271
|
+
|
|
272
|
+
it('should return 504 for bad symbol', async () => {
|
|
273
|
+
await req
|
|
274
|
+
.post('/')
|
|
275
|
+
.send(errorRequests.dominanceWithBadSymbol)
|
|
276
|
+
.set('Accept', '*/*')
|
|
277
|
+
.set('Content-Type', 'application/json')
|
|
278
|
+
.expect(504)
|
|
279
|
+
})
|
|
280
|
+
})
|
|
281
|
+
})
|