forked from smartcontractkit/external-adapters-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtotal-burned.test.ts
148 lines (141 loc) · 3.38 KB
/
total-burned.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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
import { Requester } from '@chainlink/ea-bootstrap'
import { assertError } from '@chainlink/ea-test-helpers'
import { AdapterRequest } from '@chainlink/types'
import { ethers, BigNumber } from 'ethers'
import { makeExecute } from '../../src/adapter'
import { AssetMetrics, calculateBurnedTKN } from '../../src/endpoint/total-burned'
describe('validation error', () => {
process.env.API_KEY = process.env.API_KEY || 'test_api_key'
const execute = makeExecute()
it(`asset not supplied`, async () => {
const testData = {
id: '1',
data: {
endpoint: 'total-burned',
},
}
try {
await execute(testData as AdapterRequest)
} catch (error) {
const errorResp = Requester.errored(testData.id, error)
assertError({ expected: 400, actual: errorResp.statusCode }, errorResp, testData.id)
}
})
})
describe('calculateBurnedTKN()', () => {
const testCasesError = [
{
name: 'FeeTotNtv is missing',
testData: {
jobRunID: '1',
assetMetricsList: [
{
RevNtv: '42',
IssTotNtv: '777',
},
],
},
},
{
name: 'RevNtv is missing',
testData: {
jobRunID: '1',
assetMetricsList: [
{
FeeTotNtv: '42',
IssTotNtv: '777',
},
],
},
},
{
name: 'IssTotNtv is missing',
testData: {
jobRunID: '1',
assetMetricsList: [
{
FeeTotNtv: '42',
RevNtv: '777',
},
],
},
},
{
name: 'FeeTotNtv is unprocessable',
testData: {
jobRunID: '1',
assetMetricsList: [
{
FeeTotNtv: 'unprocessable',
RevNtv: '42',
IssTotNtv: '777',
},
],
},
},
{
name: 'RevNtv is unprocessable',
testData: {
jobRunID: '1',
assetMetricsList: [
{
FeeTotNtv: '42',
RevNtv: 'unprocessable',
IssTotNtv: '777',
},
],
},
},
{
name: 'IssTotNtv is unprocessable',
testData: {
jobRunID: '1',
assetMetricsList: [
{
FeeTotNtv: '42',
RevNtv: '777',
IssTotNtv: 'unprocessable',
},
],
},
},
]
testCasesError.forEach((testCase) => {
it(`throws an Error when ${testCase.name}`, async () => {
expect(() =>
calculateBurnedTKN(testCase.testData.assetMetricsList as AssetMetrics[]),
).toThrow()
})
})
const testCasesSuccess = [
{
name: 'zero when there are no asset metrics',
testData: {
jobRunID: '1',
assetMetricsList: [],
expectedOutput: BigNumber.from('0'),
},
},
{
name: 'the expected value',
testData: {
jobRunID: '1',
assetMetricsList: [
{
FeeTotNtv: '6253.96108770342420449',
RevNtv: '16433.128000846204783707',
IssTotNtv: '13232.9375',
},
],
expectedOutput: ethers.utils.parseEther('3053.770586857219420783'),
},
},
]
testCasesSuccess.forEach((testCase) => {
it(`returns ${testCase.name}`, async () => {
expect(calculateBurnedTKN(testCase.testData.assetMetricsList as AssetMetrics[])).toEqual(
testCase.testData.expectedOutput,
)
})
})
})