-
Notifications
You must be signed in to change notification settings - Fork 308
/
Copy pathadapter.test.ts
110 lines (95 loc) · 3.03 KB
/
adapter.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
import { AdapterRequest, Execute } from '@chainlink/ea-bootstrap'
import * as tokenAllocationAdapter from '../../src/index'
import { dataProviderConfig, mockDataProviderResponses } from './fixtures'
import nock from 'nock'
const jobRunID = '1'
const getPriceRequest = (
source: string,
method = 'price',
quote = 'EUR',
additional = {},
): AdapterRequest => ({
id: jobRunID,
data: {
source,
allocations: [
{
symbol: 'wBTC',
balance: 100000000,
decimals: 8,
},
{
symbol: 'DAI',
balance: '1000000000000000000',
},
],
quote,
method,
...additional,
},
})
let oldEnv: NodeJS.ProcessEnv
describe('execute', () => {
let execute: Execute
beforeAll(async () => {
execute = await tokenAllocationAdapter.makeExecute()
oldEnv = JSON.parse(JSON.stringify(process.env))
process.env.CACHE_ENABLED = 'false'
for (const source of Object.keys(dataProviderConfig)) {
const { providerUrlEnvVar, providerUrl } = dataProviderConfig[source]
process.env[providerUrlEnvVar] = providerUrl
}
if (process.env.RECORD) {
nock.recorder.rec()
}
})
afterAll(() => {
process.env = oldEnv
if (process.env.RECORD) {
nock.recorder.play()
}
nock.restore()
nock.cleanAll()
nock.enableNetConnect()
})
describe('price method', () => {
mockDataProviderResponses()
for (const source of Object.keys(dataProviderConfig)) {
const request = getPriceRequest(source)
it(`should return the correct price for source ${source}`, async () => {
const resp = await execute(request, {})
expect(resp).toMatchSnapshot()
})
}
it('should return the correct price using a batched request when pulling data from coin API and the quote is USD', async () => {
const request = getPriceRequest('coinapi', 'price', 'USD')
const resp = await execute(request, {})
expect(resp).toMatchSnapshot()
})
})
describe('marketcap method', () => {
mockDataProviderResponses()
for (const source of Object.keys(dataProviderConfig)) {
const request = getPriceRequest(source, 'marketcap')
it(`should return the correct price for source ${source}`, async () => {
const resp = await execute(request, {})
expect(resp).toMatchSnapshot()
})
}
it('should return the correct price using a batched request when pulling data from coin API and the quote is USD', async () => {
const request = getPriceRequest('coinapi', 'marketcap', 'USD')
const resp = await execute(request, {})
expect(resp).toMatchSnapshot()
})
})
describe('additional input parameter pass through', () => {
mockDataProviderResponses()
for (const source of Object.keys(dataProviderConfig)) {
const request = getPriceRequest(source, 'price')
it(`should return the correct price for source ${source} with additional input `, async () => {
const resp = await execute(request, {})
expect(resp).toMatchSnapshot()
})
}
})
})