Skip to content

Commit 1d117d8

Browse files
committed
watcher: mock axios for flaky rpcs
1 parent bed7bee commit 1d117d8

7 files changed

+1089
-0
lines changed

watcher/src/watchers/__tests__/CosmwasmWatcher.test.ts

+16
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,24 @@ import { SeiExplorerWatcher } from '../SeiExplorerWatcher';
66
import { WormchainWatcher } from '../WormchainWatcher';
77
import { INITIAL_DEPLOYMENT_BLOCK_BY_NETWORK_AND_CHAIN } from '@wormhole-foundation/wormhole-monitor-common';
88
import { isBase64Encoded } from '../../utils/isBase64Encoded';
9+
import { existsSync, readFileSync } from 'fs';
910

1011
jest.setTimeout(60000);
12+
jest.mock('axios', () => {
13+
const originalAxios = jest.requireActual('axios') as any;
14+
return {
15+
get: jest.fn(async (url: string, config?: any) => {
16+
const mockDataPath = `${__dirname}/mock/${url
17+
.replace('http://', '')
18+
.replace('https://', '')}`;
19+
if (existsSync(mockDataPath)) {
20+
return { data: JSON.parse(readFileSync(mockDataPath, 'utf8')) };
21+
}
22+
return originalAxios.get(url, config);
23+
}),
24+
post: jest.fn(originalAxios.post),
25+
};
26+
});
1127

1228
test('getFinalizedBlockNumber(terra2)', async () => {
1329
const watcher = new CosmwasmWatcher('Mainnet', 'Terra2');

watcher/src/watchers/__tests__/mock/terra-lcd.publicnode.com/cosmos/base/tendermint/v1beta1/blocks/10847656

+1
Large diffs are not rendered by default.

watcher/src/watchers/__tests__/mock/terra-lcd.publicnode.com/cosmos/base/tendermint/v1beta1/blocks/10847657

+1
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,373 @@
1+
{
2+
"tx": {
3+
"body": {
4+
"messages": [
5+
{
6+
"@type": "/cosmos.bank.v1beta1.MsgSend",
7+
"from_address": "terra198a4stwduvuf0ef5xqguv6wkrqscxg7970dhxl",
8+
"to_address": "terra1da9ahdnscc9mrfyulz4vkhaqlqjmgldeltyhsw",
9+
"amount": [
10+
{
11+
"denom": "uluna",
12+
"amount": "742"
13+
}
14+
]
15+
}
16+
],
17+
"memo": "",
18+
"timeout_height": "0",
19+
"extension_options": [],
20+
"non_critical_extension_options": []
21+
},
22+
"auth_info": {
23+
"signer_infos": [
24+
{
25+
"public_key": {
26+
"@type": "/cosmos.crypto.secp256k1.PubKey",
27+
"key": "A2iYfc/NTmGu2U3o+EL0xPCNSeM2Ko2wncfg2CuUbDIu"
28+
},
29+
"mode_info": {
30+
"single": {
31+
"mode": "SIGN_MODE_DIRECT"
32+
}
33+
},
34+
"sequence": "23558"
35+
}
36+
],
37+
"fee": {
38+
"amount": [
39+
{
40+
"denom": "uluna",
41+
"amount": "1196"
42+
}
43+
],
44+
"gas_limit": "79686",
45+
"payer": "",
46+
"granter": ""
47+
},
48+
"tip": null
49+
},
50+
"signatures": [
51+
"8FOiG+WQH58ZGVvbnACpxQqP0U/kEdzEFOftfhvMzGkc0aLCaGEJAi8m2i/bjXPUiVtIwEH5Phd4szsX5G0mIQ=="
52+
]
53+
},
54+
"tx_response": {
55+
"height": "10847656",
56+
"txhash": "0CF2296AAD0E629E1E776A74D2A9ED7543E4E7FB4C89A2B43C114FC086B2E4DA",
57+
"codespace": "",
58+
"code": 0,
59+
"data": "12260A242F636F736D6F732E62616E6B2E763162657461312E4D736753656E64526573706F6E7365",
60+
"raw_log": "[{\"msg_index\":0,\"events\":[{\"type\":\"message\",\"attributes\":[{\"key\":\"action\",\"value\":\"/cosmos.bank.v1beta1.MsgSend\"},{\"key\":\"sender\",\"value\":\"terra198a4stwduvuf0ef5xqguv6wkrqscxg7970dhxl\"},{\"key\":\"module\",\"value\":\"bank\"}]},{\"type\":\"coin_spent\",\"attributes\":[{\"key\":\"spender\",\"value\":\"terra198a4stwduvuf0ef5xqguv6wkrqscxg7970dhxl\"},{\"key\":\"amount\",\"value\":\"742uluna\"}]},{\"type\":\"coin_received\",\"attributes\":[{\"key\":\"receiver\",\"value\":\"terra1da9ahdnscc9mrfyulz4vkhaqlqjmgldeltyhsw\"},{\"key\":\"amount\",\"value\":\"742uluna\"}]},{\"type\":\"transfer\",\"attributes\":[{\"key\":\"recipient\",\"value\":\"terra1da9ahdnscc9mrfyulz4vkhaqlqjmgldeltyhsw\"},{\"key\":\"sender\",\"value\":\"terra198a4stwduvuf0ef5xqguv6wkrqscxg7970dhxl\"},{\"key\":\"amount\",\"value\":\"742uluna\"}]},{\"type\":\"message\",\"attributes\":[{\"key\":\"sender\",\"value\":\"terra198a4stwduvuf0ef5xqguv6wkrqscxg7970dhxl\"}]}]}]",
61+
"logs": [
62+
{
63+
"msg_index": 0,
64+
"log": "",
65+
"events": [
66+
{
67+
"type": "message",
68+
"attributes": [
69+
{
70+
"key": "action",
71+
"value": "/cosmos.bank.v1beta1.MsgSend"
72+
},
73+
{
74+
"key": "sender",
75+
"value": "terra198a4stwduvuf0ef5xqguv6wkrqscxg7970dhxl"
76+
},
77+
{
78+
"key": "module",
79+
"value": "bank"
80+
}
81+
]
82+
},
83+
{
84+
"type": "coin_spent",
85+
"attributes": [
86+
{
87+
"key": "spender",
88+
"value": "terra198a4stwduvuf0ef5xqguv6wkrqscxg7970dhxl"
89+
},
90+
{
91+
"key": "amount",
92+
"value": "742uluna"
93+
}
94+
]
95+
},
96+
{
97+
"type": "coin_received",
98+
"attributes": [
99+
{
100+
"key": "receiver",
101+
"value": "terra1da9ahdnscc9mrfyulz4vkhaqlqjmgldeltyhsw"
102+
},
103+
{
104+
"key": "amount",
105+
"value": "742uluna"
106+
}
107+
]
108+
},
109+
{
110+
"type": "transfer",
111+
"attributes": [
112+
{
113+
"key": "recipient",
114+
"value": "terra1da9ahdnscc9mrfyulz4vkhaqlqjmgldeltyhsw"
115+
},
116+
{
117+
"key": "sender",
118+
"value": "terra198a4stwduvuf0ef5xqguv6wkrqscxg7970dhxl"
119+
},
120+
{
121+
"key": "amount",
122+
"value": "742uluna"
123+
}
124+
]
125+
},
126+
{
127+
"type": "message",
128+
"attributes": [
129+
{
130+
"key": "sender",
131+
"value": "terra198a4stwduvuf0ef5xqguv6wkrqscxg7970dhxl"
132+
}
133+
]
134+
}
135+
]
136+
}
137+
],
138+
"info": "",
139+
"gas_wanted": "79686",
140+
"gas_used": "73021",
141+
"tx": {
142+
"@type": "/cosmos.tx.v1beta1.Tx",
143+
"body": {
144+
"messages": [
145+
{
146+
"@type": "/cosmos.bank.v1beta1.MsgSend",
147+
"from_address": "terra198a4stwduvuf0ef5xqguv6wkrqscxg7970dhxl",
148+
"to_address": "terra1da9ahdnscc9mrfyulz4vkhaqlqjmgldeltyhsw",
149+
"amount": [
150+
{
151+
"denom": "uluna",
152+
"amount": "742"
153+
}
154+
]
155+
}
156+
],
157+
"memo": "",
158+
"timeout_height": "0",
159+
"extension_options": [],
160+
"non_critical_extension_options": []
161+
},
162+
"auth_info": {
163+
"signer_infos": [
164+
{
165+
"public_key": {
166+
"@type": "/cosmos.crypto.secp256k1.PubKey",
167+
"key": "A2iYfc/NTmGu2U3o+EL0xPCNSeM2Ko2wncfg2CuUbDIu"
168+
},
169+
"mode_info": {
170+
"single": {
171+
"mode": "SIGN_MODE_DIRECT"
172+
}
173+
},
174+
"sequence": "23558"
175+
}
176+
],
177+
"fee": {
178+
"amount": [
179+
{
180+
"denom": "uluna",
181+
"amount": "1196"
182+
}
183+
],
184+
"gas_limit": "79686",
185+
"payer": "",
186+
"granter": ""
187+
},
188+
"tip": null
189+
},
190+
"signatures": [
191+
"8FOiG+WQH58ZGVvbnACpxQqP0U/kEdzEFOftfhvMzGkc0aLCaGEJAi8m2i/bjXPUiVtIwEH5Phd4szsX5G0mIQ=="
192+
]
193+
},
194+
"timestamp": "2024-06-20T08:02:18Z",
195+
"events": [
196+
{
197+
"type": "coin_spent",
198+
"attributes": [
199+
{
200+
"key": "spender",
201+
"value": "terra198a4stwduvuf0ef5xqguv6wkrqscxg7970dhxl",
202+
"index": true
203+
},
204+
{
205+
"key": "amount",
206+
"value": "1196uluna",
207+
"index": true
208+
}
209+
]
210+
},
211+
{
212+
"type": "coin_received",
213+
"attributes": [
214+
{
215+
"key": "receiver",
216+
"value": "terra17xpfvakm2amg962yls6f84z3kell8c5lkaeqfa",
217+
"index": true
218+
},
219+
{
220+
"key": "amount",
221+
"value": "1196uluna",
222+
"index": true
223+
}
224+
]
225+
},
226+
{
227+
"type": "transfer",
228+
"attributes": [
229+
{
230+
"key": "recipient",
231+
"value": "terra17xpfvakm2amg962yls6f84z3kell8c5lkaeqfa",
232+
"index": true
233+
},
234+
{
235+
"key": "sender",
236+
"value": "terra198a4stwduvuf0ef5xqguv6wkrqscxg7970dhxl",
237+
"index": true
238+
},
239+
{
240+
"key": "amount",
241+
"value": "1196uluna",
242+
"index": true
243+
}
244+
]
245+
},
246+
{
247+
"type": "message",
248+
"attributes": [
249+
{
250+
"key": "sender",
251+
"value": "terra198a4stwduvuf0ef5xqguv6wkrqscxg7970dhxl",
252+
"index": true
253+
}
254+
]
255+
},
256+
{
257+
"type": "tx",
258+
"attributes": [
259+
{
260+
"key": "fee",
261+
"value": "1196uluna",
262+
"index": true
263+
},
264+
{
265+
"key": "fee_payer",
266+
"value": "terra198a4stwduvuf0ef5xqguv6wkrqscxg7970dhxl",
267+
"index": true
268+
}
269+
]
270+
},
271+
{
272+
"type": "tx",
273+
"attributes": [
274+
{
275+
"key": "acc_seq",
276+
"value": "terra198a4stwduvuf0ef5xqguv6wkrqscxg7970dhxl/23558",
277+
"index": true
278+
}
279+
]
280+
},
281+
{
282+
"type": "tx",
283+
"attributes": [
284+
{
285+
"key": "signature",
286+
"value": "8FOiG+WQH58ZGVvbnACpxQqP0U/kEdzEFOftfhvMzGkc0aLCaGEJAi8m2i/bjXPUiVtIwEH5Phd4szsX5G0mIQ==",
287+
"index": true
288+
}
289+
]
290+
},
291+
{
292+
"type": "message",
293+
"attributes": [
294+
{
295+
"key": "action",
296+
"value": "/cosmos.bank.v1beta1.MsgSend",
297+
"index": true
298+
},
299+
{
300+
"key": "sender",
301+
"value": "terra198a4stwduvuf0ef5xqguv6wkrqscxg7970dhxl",
302+
"index": true
303+
},
304+
{
305+
"key": "module",
306+
"value": "bank",
307+
"index": true
308+
}
309+
]
310+
},
311+
{
312+
"type": "coin_spent",
313+
"attributes": [
314+
{
315+
"key": "spender",
316+
"value": "terra198a4stwduvuf0ef5xqguv6wkrqscxg7970dhxl",
317+
"index": true
318+
},
319+
{
320+
"key": "amount",
321+
"value": "742uluna",
322+
"index": true
323+
}
324+
]
325+
},
326+
{
327+
"type": "coin_received",
328+
"attributes": [
329+
{
330+
"key": "receiver",
331+
"value": "terra1da9ahdnscc9mrfyulz4vkhaqlqjmgldeltyhsw",
332+
"index": true
333+
},
334+
{
335+
"key": "amount",
336+
"value": "742uluna",
337+
"index": true
338+
}
339+
]
340+
},
341+
{
342+
"type": "transfer",
343+
"attributes": [
344+
{
345+
"key": "recipient",
346+
"value": "terra1da9ahdnscc9mrfyulz4vkhaqlqjmgldeltyhsw",
347+
"index": true
348+
},
349+
{
350+
"key": "sender",
351+
"value": "terra198a4stwduvuf0ef5xqguv6wkrqscxg7970dhxl",
352+
"index": true
353+
},
354+
{
355+
"key": "amount",
356+
"value": "742uluna",
357+
"index": true
358+
}
359+
]
360+
},
361+
{
362+
"type": "message",
363+
"attributes": [
364+
{
365+
"key": "sender",
366+
"value": "terra198a4stwduvuf0ef5xqguv6wkrqscxg7970dhxl",
367+
"index": true
368+
}
369+
]
370+
}
371+
]
372+
}
373+
}

0 commit comments

Comments
 (0)