forked from smartcontractkit/external-adapters-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
write.test.ts
90 lines (87 loc) · 2.65 KB
/
write.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
import { assertSuccess } from '@chainlink/ea-test-helpers'
import { AdapterRequest } from '@chainlink/ea-bootstrap'
import { execute } from '../../src/endpoint/write'
import { makeConfig } from '../../src'
import mockOracleRewardsData from '../mock-data/mock-oracle-rewards-data.json'
import { CID } from '../../src/endpoint/read'
describe('execute', () => {
const jobID = '1'
const config = makeConfig()
const mockEpoch0 = CID.parse('QmdJZkigqJfvjya9YQ5qW7mFdNHpxUUsSQFKPDjLrdFfg4')
const mockEpoch1 = CID.parse('QmRmAK7teai1Mki1V2zNxmBLXnYVVeJ92DCuEotwHPa98a')
describe('successful calls', () => {
const requests = [
{
name: 'simple text',
testData: { id: jobID, data: { data: 'some simple text' } },
},
{
name: 'dag-cbor codec',
testData: { id: jobID, data: { data: { name: 'my object', id: 123 }, codec: 'dag-cbor' } },
},
{
name: 'dag-cbor codec with link',
testData: {
id: jobID,
data: {
data: {
name: 'my object',
id: 123,
link: CID.parse('QmXLpPi3yorJmGe6NsdBfyWSFvLnkX12EJR5zitwv4q8Tf'),
},
codec: 'dag-cbor',
},
},
},
{
name: 'json codec',
testData: { id: jobID, data: { data: { name: 'my object', id: 123 }, codec: 'json' } },
},
{
name: 'json codec CID v1',
testData: {
id: jobID,
data: { data: { name: 'my object', id: 123 }, codec: 'json', cidVersion: 1 },
},
},
{
name: 'dag',
testData: { id: jobID, data: { data: { name: 'my object', id: 123 }, type: 'dag' } },
},
{
name: 'json mockOracleRewardsData',
testData: { id: jobID, data: { data: mockOracleRewardsData, codec: 'json' } },
},
{
name: 'json mockOracleRewardsData epoch 1',
testData: {
id: jobID,
data: { data: { ...mockOracleRewardsData, epoch: 1 }, codec: 'json' },
},
},
{
name: 'dag-cbor oracleRewardsDataByEpoch',
testData: {
id: jobID,
data: {
data: {
latestEpoch: 0,
dataByEpoch: {
'0': mockEpoch0,
'1': mockEpoch1,
},
},
type: 'dag',
},
},
},
]
requests.forEach((req) => {
it(`${req.name}`, async () => {
const data = await execute(req.testData as AdapterRequest, {}, config)
assertSuccess({ expected: 200, actual: data.statusCode }, data, jobID)
expect(data).toMatchSnapshot()
})
})
})
})