-
Notifications
You must be signed in to change notification settings - Fork 188
Expand file tree
/
Copy pathcalibnet_eth_mapping_check.sh
More file actions
executable file
·77 lines (55 loc) · 2.13 KB
/
calibnet_eth_mapping_check.sh
File metadata and controls
executable file
·77 lines (55 loc) · 2.13 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
#!/usr/bin/env bash
# This script is checking the correctness of the ethereum mapping feature
# It requires both the `forest` and `forest-cli` binaries to be in the PATH.
set -eu
source "$(dirname "$0")/harness.sh"
forest_init --backfill-db 200
FOREST_URL='http://127.0.0.1:2345/rpc/v1'
NUM_TIPSETS=200
echo "Get Ethereum block hashes and transactions hashes from the last $NUM_TIPSETS tipsets"
OUTPUT=$($FOREST_CLI_PATH info show)
HEAD_EPOCH=$(echo "$OUTPUT" | sed -n 's/.*epoch: \([0-9]*\).*/\1/p')
EPOCH=$((HEAD_EPOCH - 1))
ETH_BLOCK_HASHES=()
ETH_TX_HASHES=()
for ((i=0; i<=NUM_TIPSETS; i++)); do
EPOCH_HEX=$(printf "0x%x" $EPOCH)
JSON=$(curl -s -X POST "$FOREST_URL" \
-H 'Content-Type: application/json' \
--data "$(jq -n --arg epoch "$EPOCH_HEX" '{jsonrpc: "2.0", id: 1, method: "Filecoin.EthGetBlockByNumber", params: [$epoch, false]}')")
HASH=$(echo "$JSON" | jq -r '.result.hash')
ETH_BLOCK_HASHES+=("$HASH")
if [[ $(echo "$JSON" | jq -e '.result.transactions') != "null" ]]; then
TRANSACTIONS=$(echo "$JSON" | jq -r '.result.transactions[]')
for tx in $TRANSACTIONS; do
ETH_TX_HASHES+=("$tx")
done
else
echo "No transactions found for block hash: $EPOCH_HEX"
fi
EPOCH=$((EPOCH - 1))
done
echo "Done"
forest_wait_for_healthcheck_ready
ERROR=0
echo "Testing Ethereum mappings"
for hash in "${ETH_BLOCK_HASHES[@]}"; do
JSON=$(curl -s -X POST "$FOREST_URL" \
-H 'Content-Type: application/json' \
--data "$(jq -n --arg hash "$hash" '{jsonrpc: "2.0", id: 1, method: "Filecoin.EthGetBalance", params: ["0xff38c072f286e3b20b3954ca9f99c05fbecc64aa", $hash]}')")
if [[ $(echo "$JSON" | jq -e '.result') == "null" ]]; then
echo "Missing tipset key for hash $hash"
ERROR=1
fi
done
for hash in "${ETH_TX_HASHES[@]}"; do
JSON=$(curl -s -X POST "$FOREST_URL" \
-H 'Content-Type: application/json' \
--data "$(jq -n --arg hash "$hash" '{jsonrpc: "2.0", id: 1, method: "Filecoin.EthGetMessageCidByTransactionHash", params: [$hash]}')")
if [[ $(echo "$JSON" | jq -e '.result') == "null" ]]; then
echo "Missing cid for hash $hash"
ERROR=1
fi
done
echo "Done"
exit $ERROR