-
Notifications
You must be signed in to change notification settings - Fork 308
/
adapter.test.ts
166 lines (157 loc) · 6.29 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
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
import {
TestAdapter,
setEnvVariables,
} from '@chainlink/external-adapter-framework/util/testing-utils'
import * as nock from 'nock'
import {
mockBalanceLimboValidator,
mockBalanceSuccess,
mockBalanceWithStatusSuccess,
mockGetEthDepositContract,
} from './fixtures'
jest.mock('ethers', () => {
const actualModule = jest.requireActual('ethers')
return {
...actualModule,
ethers: {
...actualModule.ethers,
providers: {
JsonRpcProvider: function () {
return {
getBlockNumber: jest.fn().mockReturnValue(10000),
getLogs: jest.fn().mockImplementation(() => {
return [
{
blockNumber: 9000,
blockHash: '0xe5a4ff6958f847e5ae8757fe62b023dc16e5a53776064b79659e41de9491a14d',
transactionIndex: 18,
removed: false,
address: '0x8c5fecdC472E27Bc447696F431E425D02dd46a8c',
data:
'0x00000000000000000000000000000000000000000000000000000000000000a000000000000' +
'00000000000000000000000000000000000000000000000000100000000000000000000000000' +
'00000000000000000000000000000000000001400000000000000000000000000000000000000' +
'00000000000000000000000018000000000000000000000000000000000000000000000000000' +
'00000000000200000000000000000000000000000000000000000000000000000000000000003' +
'098416f837d457d72f0dd5297898e1225a1e7731c2579f642626fbdc8ee8ce4f1e89ca538b72d' +
'5c3b75fdd1e9e10c87c6000000000000000000000000000000000000000000000000000000000' +
'00000000000000000000000000000000000002000000000000000000000000000000000000000' +
'00000000000000000000000000000000000000000000000000000000000000000000000000000' +
'000000000000800ca9a3b00000000000000000000000000000000000000000000000000000000' +
'00000000000000000000000000000000000000000000000000000000000000600000000000000' +
'00000000000000000000000000000000000000000000000000000000000000000000000000000' +
'00000000000000000000000000000000000000000000000000000000000000000000000000000' +
'00000000000000000000000000000000000000000000000000000000000000000000000000000' +
'0000000000089718040000000000000000000000000000000000000000000000000000000000',
topics: ['0x649bbc62d0e31342afea4e5cd82d4049e7e1ee912fc0889aa790803be39038c5'],
transactionHash:
'0xb562350898581dfa4318404319c36989ae4b9bce4f35dda4f0c5469b659d15a1',
logIndex: 10,
},
]
}),
}
},
},
},
}
})
describe('execute', () => {
let spy: jest.SpyInstance
let testAdapter: TestAdapter
let oldEnv: NodeJS.ProcessEnv
beforeAll(async () => {
oldEnv = JSON.parse(JSON.stringify(process.env))
process.env.ETH_CONSENSUS_RPC_URL = process.env.ETH_CONSENSUS_RPC_UR ?? 'http://localhost:3500'
process.env.ETH_EXECUTION_RPC_URL = process.env.ETH_EXECUTION_RPC_URL ?? 'http://localhost:3501'
process.env['BACKGROUND_EXECUTE_MS'] = '0'
const mockDate = new Date('2001-01-01T11:11:11.111Z')
spy = jest.spyOn(Date, 'now').mockReturnValue(mockDate.getTime())
const adapter = (await import('./../../src')).adapter
testAdapter = await TestAdapter.startWithMockedCache(adapter, {
testAdapter: {} as TestAdapter<never>,
})
})
afterAll(async () => {
setEnvVariables(oldEnv)
await testAdapter.api.close()
nock.restore()
nock.cleanAll()
spy.mockRestore()
})
describe('balance endpoint', () => {
it('should return success', async () => {
const data = {
result: [
{
address:
'0x8bdb63ea991f42129d6defa8d3cc5926108232c89824ad50d57f49a0310de73e81e491eae6587bd1465fa5fd8e4dee21',
},
{
address:
'0xb672b5976879c6423ad484ba4fa0e76069684eed8e2a8081f6730907f3618d43828d1b399d2fd22d7961824594f73462',
},
],
}
mockBalanceSuccess()
const response = await testAdapter.request(data)
expect(response.statusCode).toBe(200)
expect(response.json()).toMatchSnapshot()
})
it('should return success with validator that is not on the beacon chain', async () => {
const data = {
result: [
{
address:
'0x8bdb63ea991f42129d6defa8d3cc5926108232c89824ad50d57f49a0310de73e81e491eae6587bd1465fa5fd8e4dee21',
},
{
address:
'0xb672b5976879c6423ad484ba4fa0e76069684eed8e2a8081f6730907f3618d43828d1b399d2fd22d7961824594f73462',
},
{
address:
'0x000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
},
],
validatorStatus: ['active'],
}
mockBalanceWithStatusSuccess()
const response = await testAdapter.request(data)
expect(response.statusCode).toBe(200)
expect(response.json()).toMatchSnapshot()
})
it('should return success with limbo validator balance', async () => {
const data = {
searchLimboValidators: true,
result: [
{
address:
'0x8bdb63ea991f42129d6defa8d3cc5926108232c89824ad50d57f49a0310de73e81e491eae6587bd1465fa5fd8e4dee21',
},
{
address:
'0xb672b5976879c6423ad484ba4fa0e76069684eed8e2a8081f6730907f3618d43828d1b399d2fd22d7961824594f73462',
},
{
address:
'0x98416f837d457d72f0dd5297898e1225a1e7731c2579f642626fbdc8ee8ce4f1e89ca538b72d5c3b75fdd1e9e10c87c6',
},
],
}
mockGetEthDepositContract()
mockBalanceLimboValidator()
const response = await testAdapter.request(data)
expect(response.statusCode).toBe(200)
expect(response.json()).toMatchSnapshot()
})
it('should return error with empty addresses', async () => {
const data = {
result: [],
}
const response = await testAdapter.request(data)
expect(response.statusCode).toBe(400)
expect(response.json()).toMatchSnapshot()
})
})
})