forked from Granola-Team/mina-indexer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test
executable file
·127 lines (103 loc) · 2.9 KB
/
test
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
#!/bin/sh
set -ex
DOMAIN_SOCKET="$(pwd)/mina-indexer.sock"
# Create temporary directory for blocks and things in a cross platform
# compatible way
TMPDIR=$(mktemp -d 2>/dev/null || mktemp -d -t 'mytmpdir')
BLOCKS_DIR="${TMPDIR}/blocks"
mkdir $BLOCKS_DIR
cleanup() {
echo "Exiting with $?"
rm -rf $TMPDIR
}
trap cleanup EXIT
cargo build
teardown() {
rm -rf $HOME/.mina-indexer/database || true
rm -rf $HOME/.mina-indexer/logs || true
}
shutdown() {
echo "shutdown \0" | nc -U $DOMAIN_SOCKET
}
account_balance() {
echo "account $1\0" | nc -U $DOMAIN_SOCKET | jq .balance
}
best_ledger() {
echo "best-ledger\0" | nc -U $DOMAIN_SOCKET | jq .ledger
}
summary() {
echo "summary\0" | nc -U $DOMAIN_SOCKET | jq .summary
}
idxr() {
./target/debug/mina-indexer "$@"
}
server() {
./target/debug/mina-indexer server "$@"
}
client() {
./target/debug/mina-indexer client "$@"
}
dl_mainnet() {
MAX_SLOT=$1; OUT_DIR=$2
./download_blocks mina_network_block_data $MAX_SLOT mainnet $OUT_DIR
}
# Indexer reports usage with no arguments
idxr 2>&1 |
grep -iq "Usage:"
# Indexer reports usage for server subcommand
idxr server 2>&1 |
grep -iq "Usage: mina-indexer server"
# Indexer reports usage for client subcommand
idxr client 2>&1 |
grep -iq "Usage: mina-indexer client"
# Indexer server config subcommand exists
idxr server config 2>&1 |
grep -iq "Usage: mina-indexer server config"
# Indexer server cli subcommand works
idxr server cli --help 2>/dev/null
# Indexer server config passes cli with minimal args
idxr server cli \
--initial-ledger tests/ledgers/mainnet-genesis.json \
--is-genesis-ledger \
--root-hash 3NKeMoncuHab5ScarV5ViyF16cJPT4taWNSaTLS64Dp67wuXigPZ &
IDXR_PID=$(pgrep mina-indexer)
kill $IDXR_PID
teardown
# Indexer server starts up on a minimal selection of blocks
dl_mainnet 15 $BLOCKS_DIR
server cli \
--startup-dir $BLOCKS_DIR \
--watch-dir $BLOCKS_DIR \
--initial-ledger tests/ledgers/mainnet-genesis.json \
--is-genesis-ledger \
--root-hash 3NKeMoncuHab5ScarV5ViyF16cJPT4taWNSaTLS64Dp67wuXigPZ &
IDXR_PID=$(pgrep mina-indexer)
sleep 5
client -o summary |
jq .witness_tree.canonical_tip_hash |
grep -iq "3NKQUoBfi9vkbuqtDJmSEYBQrcSo4GjwG8bPCiii4yqM8AxEQvtY"
kill $IDXR_PID
teardown
# Indexer server ipc is available during initialization
dl_mainnet 250 $BLOCKS_DIR
server cli \
--startup-dir $BLOCKS_DIR \
--watch-dir $BLOCKS_DIR \
--initial-ledger tests/ledgers/mainnet-genesis.json \
--is-genesis-ledger \
--root-hash 3NKeMoncuHab5ScarV5ViyF16cJPT4taWNSaTLS64Dp67wuXigPZ &
IDXR_PID=$(pgrep mina-indexer)
sleep 5
client -o summary |
jq .
kill $IDXR_PID
teardown
sleep 5
# Signal indexer to shutdown
idxr server cli \
--initial-ledger tests/ledgers/mainnet-genesis.json \
--is-genesis-ledger \
--root-hash 3NKeMoncuHab5ScarV5ViyF16cJPT4taWNSaTLS64Dp67wuXigPZ &
sleep 3
shutdown
echo "Done"