-
Notifications
You must be signed in to change notification settings - Fork 262
Expand file tree
/
Copy pathfixtures.ts
More file actions
219 lines (214 loc) · 7.48 KB
/
fixtures.ts
File metadata and controls
219 lines (214 loc) · 7.48 KB
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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
import nock from 'nock'
type JsonRpcPayload = {
id: number
method: string
params: {
to: string
data: string
}[]
jsonrpc: '2.0'
}
export const mockETHMainnetContractCallResponseSuccess = (): nock.Scope =>
nock('http://localhost:8545', {
encodedQueryParams: true,
})
.persist()
.post('/', (body: any) => Array.isArray(body))
.reply(
200,
(_uri, requestBody: any[]) => {
// Create an array of mocked responses for each batched request
return requestBody.map((request: JsonRpcPayload) => {
if (request.method === 'eth_chainId') {
return {
jsonrpc: '2.0',
id: request.id,
result: '0x1',
}
} else if (
request.method === 'eth_call' &&
request.params[0].to === '0x2c1d072e956affc0d435cb7ac38ef18d24d9127c' &&
request.params[0].data === '0x50d25bcd'
) {
return {
jsonrpc: '2.0',
id: request.id,
result: '0x000000000000000000000000000000000000000000000000000000005ad789f8',
}
} else if (
request.method === 'eth_call' &&
request.params[0].to === '0x2c1d072e956affc0d435cb7ac38ef18d24d9127c' &&
request.params[0].data === '0x313ce567' // decimals()
) {
return {
jsonrpc: '2.0',
id: request.id,
result: '0x0000000000000000000000000000000000000000000000000000000000000008',
}
} else if (
request.method === 'eth_call' &&
request.params[0].to === '0x2c1d072e956affc0d435cb7ac38ef18d24d9127c' &&
request.params[0].data ===
'0xb5ab58dc0000000000000000000000000000000000000000000000060000000000001df4'
) {
return {
jsonrpc: '2.0',
id: request.id,
result: '0x000000000000000000000000000000000000000000000000000000005cf7ff3b',
}
} else if (
request.method === 'eth_call' &&
request.params[0].to === '0xae2364579d6cb4bbd6695846c1d595ca9af3574d' &&
request.params[0].data === '0x053f14da' // lastPrice()
) {
return {
jsonrpc: '2.0',
id: request.id,
// Example return: price = 123456789, timestamp = 1718000000
result:
'0x00000000000000000000000000000000000000000000000000000000075bcd150000000000000000000000000000000000000000000000000000000066b7b9c0',
}
} else {
// Default response for unsupported calls
return {
jsonrpc: '2.0',
id: request.id,
error: { code: -32601, message: 'Method not found' },
}
}
})
},
[
'Content-Type',
'application/json',
'Connection',
'close',
'Vary',
'Accept-Encoding',
'Vary',
'Origin',
],
)
.persist()
export const mockETHGoerliContractCallResponseSuccess = (): nock.Scope =>
nock('http://localhost:8554', {
encodedQueryParams: true,
})
.persist()
.post('/', (body: any) => Array.isArray(body))
.reply(
200,
(_uri, requestBody: any[]) => {
// Create an array of mocked responses for each batched request
return requestBody.map((request: JsonRpcPayload) => {
if (request.method === 'eth_chainId') {
return {
jsonrpc: '2.0',
id: request.id,
result: '0x5',
}
} else if (
request.method === 'eth_call' &&
request.params[0].to === '0x779877a7b0d9e8603169ddbd7836e478b4624789' &&
request.params[0].data === '0x50d25bcd'
) {
return {
jsonrpc: '2.0',
id: request.id,
result: '0x000000000000000000000000000000000000000000000000eead809f678d30f0',
}
} else if (
request.method === 'eth_call' &&
request.params[0].to === '0x779877a7b0d9e8603169ddbd7836e478b4624789' &&
request.params[0].data === '0x313ce567' // decimals()
) {
return {
jsonrpc: '2.0',
id: request.id,
result: '0x0000000000000000000000000000000000000000000000000000000000000018',
}
} else {
// Default response for unsupported calls
return {
jsonrpc: '2.0',
id: request.id,
error: { code: -32601, message: 'Method not found' },
}
}
})
},
[
'Content-Type',
'application/json',
'Connection',
'close',
'Vary',
'Accept-Encoding',
'Vary',
'Origin',
],
)
.persist()
export const mockAptosSuccess = (): nock.Scope =>
nock('http://fake-aptos', {
encodedQueryParams: true,
})
.persist()
.post('/view')
.reply(200, () => [1], [
'Content-Type',
'application/json',
'Connection',
'close',
'Vary',
'Accept-Encoding',
'Vary',
'Origin',
])
.persist()
export const mockAptosDfReaderSuccess = (): nock.Scope =>
nock('http://fake-aptos-testnet', {
encodedQueryParams: true,
})
.persist()
.post('/view')
.reply(
200,
() => [
[
{
feed: {
benchmark: '10568348893862534',
config_id: '0x',
description: 'truAPT-APT Exchange Rate',
observation_timestamp: '1747197639',
report:
'0x00030b04d917b020da9373073eebdf46a804972050dc1c28f6fb4e9975e84e700000000000000000000000000000000000000000000000000000000068241cfe0000000000000000000000000000000000000000000000000000000068241ec700000000000000007fffffffffffffffffffffffffffffffffffffffffffffff00000000000000007fffffffffffffffffffffffffffffffffffffffffffffff000000000000000000000000000000000000000000000000000000006825704700000000000000000000000000000000000000000000000000258bdb79ae5a8600000000000000000000000000000000000000000000000000258bdb79ae5a8600000000000000000000000000000000000000000000000000258bdb79ae5a86',
},
feed_id: '0x015d2ae47f000328000000000000000000000000000000000000000000000000',
},
{
feed: {
benchmark: '1025605000000',
config_id: '0x',
description: 'eAPT-APT Exchange Rate',
observation_timestamp: '1747158560',
report:
'0x00030b04d917b020da9373073eebdf46a804972050dc1c28f6fb4e9975e84e71000000000000000000000000000000000000000000000000000000006823861c000000000000000000000000000000000000000000000000000000006823862000000000000000007fffffffffffffffffffffffffffffffffffffffffffffff00000000000000007fffffffffffffffffffffffffffffffffffffffffffffff000000000000000000000000000000000000000000000000000000006824d7a0000000000000000000000000000000000000000000000000000000eecad25b40000000000000000000000000000000000000000000000000000000eecad25b40000000000000000000000000000000000000000000000000000000eecad25b40',
},
feed_id: '0x017b2eb719000326000000000000000000000000000000000000000000000000',
},
],
],
[
'Content-Type',
'application/json',
'Connection',
'close',
'Vary',
'Accept-Encoding',
'Vary',
'Origin',
],
)
.persist()