-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathtest-full.jsx
65 lines (63 loc) · 1.88 KB
/
test-full.jsx
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
import {
EthCallData,
EthCallQueryRequest,
EthCallQueryResponse,
PerChainQueryRequest,
QueryProxyMock,
QueryRequest,
QueryResponse,
} from '@wormhole-foundation/wormhole-query-sdk';
import axios from 'axios';
const rpc = 'https://ethereum.publicnode.com';
const callData: EthCallData = {
to: '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2', // WETH
data: '0x18160ddd', // web3.eth.abi.encodeFunctionSignature("totalSupply()")
};
(async () => {
const latestBlock: string = (
await axios.post(rpc, {
method: 'eth_getBlockByNumber',
params: ['latest', false],
id: 1,
jsonrpc: '2.0',
})
).data?.result?.number;
if (!latestBlock) {
console.error(`❌ Invalid block returned`);
return;
}
console.log('Latest Block: ', latestBlock, `(${BigInt(latestBlock)})`);
const targetResponse = await axios.post(rpc, {
method: 'eth_call',
params: [callData, latestBlock],
id: 1,
jsonrpc: '2.0',
});
// console.log(finalizedResponse.data);
if (targetResponse.data.error) {
console.error(`❌ ${targetResponse.data.error.message}`);
}
const targetResult = targetResponse.data?.result;
console.log('Target Result: ', targetResult, `(${BigInt(targetResult)})`);
// Form the query request
const request = new QueryRequest(
0, // Nonce
[
new PerChainQueryRequest(
2, // Ethereum Wormhole Chain ID
new EthCallQueryRequest(latestBlock, [callData])
),
]
);
console.log(JSON.stringify(request, undefined, 2));
const mock = new QueryProxyMock({ 2: rpc });
const mockData = await mock.mock(request);
console.log(mockData);
const mockQueryResponse = QueryResponse.from(mockData.bytes);
const mockQueryResult = (
mockQueryResponse.responses[0].response as EthCallQueryResponse
).results[0];
console.log(
`Mock Query Result: ${mockQueryResult} (${BigInt(mockQueryResult)})`
);
})();