-
Notifications
You must be signed in to change notification settings - Fork 9
/
regression.bash
executable file
·1898 lines (1521 loc) · 74.7 KB
/
regression.bash
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
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env bash
# shellcheck disable=SC2046,SC2086,SC2002
# To debug, uncomment:
# set -x
set -euo pipefail
IDXR="$1"
shift
# Collect the binaries under test and the test ledgers.
SRC="$(git rev-parse --show-toplevel)"
REV="$(git rev-parse --short=8 HEAD)"
STAKING_LEDGERS="$SRC"/tests/data/staking_ledgers
SUMMARY_SCHEMA="$SRC"/tests/data/json-schemas/summary.json
# The rest of this script's logic assumes that the testing is done from within
# this temporary directory.
: "${VOLUMES_DIR:=/mnt}"
DEV_DIR="$VOLUMES_DIR"/mina-indexer-dev
BASE_DIR="$DEV_DIR"/rev-"$REV"
mkdir -p "$BASE_DIR"
cd "$BASE_DIR"
idxr() {
RUST_BACKTRACE=full "$IDXR" --socket ./mina-indexer.sock "$@"
}
# Performs a shutdown of the Indexer, possibly returning failure.
#
shutdown_idxr() {
echo "Shutting down Mina Indexer."
if [ ! -S ./mina-indexer.sock ]; then
echo " Missing socket. Shutdown failed."
return 1
fi
if [ ! -e ./idxr_pid ]; then
echo " Missing PID file. Shutdown failed."
return 1
fi
if ! idxr server shutdown; then
echo " Server shutdown command failed."
return 1
fi
# The shutdown command succeeded. Give a the process a generous amount of
# time to exit cleanly. If this gets too big, then we don't really shut
# down correctly.
sleep 3
# Either it timed out, or that PID did not exist.
if ps -p "$(cat ./idxr_pid)" >/dev/null; then
echo " The shutdown command did not kill the process. Failure."
return 1
else
# The process does not exist. Check for socket deletion.
if [ -S ./mina-indexer.sock ]; then
echo " The shutdown command did not delete the socket. Failure."
return 1
fi
fi
echo "Deleting PID file."
rm -f ./idxr_pid
sleep 2
}
ephemeral_port() {
set +e
LOW_BOUND=49152
RANGE=16384
while true; do
CANDIDATE=$(( LOW_BOUND + (RANDOM % RANGE) ))
if ! (echo "" >/dev/tcp/127.0.0.1/${CANDIDATE}) >/dev/null 2>&1; then
echo $CANDIDATE
break
fi
done
set -e
}
wait_for_socket() {
num_retries=0
# We retry 100 times before giving up because there is a good chance that
# the machine is heavily loaded.
while [ $num_retries -lt 100 ]; do
if [ -S ./mina-indexer.sock ]; then
return
fi
(( num_retries+=1 ))
echo "Sleeping ($num_retries)..."
sleep 1
done
}
wait_forever_for_socket() {
while true; do
if [ -S ./mina-indexer.sock ]; then
return
fi
echo "Sleeping 10 s ..."
sleep 10
done
}
idxr_database_create() {
idxr database create \
--blocks-dir ./blocks \
--database-dir ./database \
--staking-ledgers-dir ./staking-ledgers \
"$@"
}
idxr_server() {
RUST_BACKTRACE=full "$IDXR" --socket ./mina-indexer.sock server "$@" &
echo $! > ./idxr_pid
}
idxr_server_start() {
port=$(ephemeral_port)
idxr_server start --web-port "$port" "$@"
}
idxr_server_start_standard() {
echo "Creating mina indexer database"
idxr_database_create "$@"
echo "Starting mina indexer server from database"
idxr_server_start \
--blocks-dir ./blocks \
--staking-ledgers-dir ./staking-ledgers \
--database-dir ./database \
"$@"
}
stage_mainnet_blocks() {
"$SRC"/ops/stage-blocks.rb 2 "$1" mainnet "$2"
}
stage_mainnet_single() {
"$SRC"/ops/stage-blocks.rb "$1" "$1" mainnet "$2"
}
stage_mainnet_range() {
"$SRC"/ops/stage-blocks.rb "$1" "$2" mainnet "$3"
}
assert() {
expected="$1"
actual="$2"
if [ "$expected" != "$actual" ]; then
echo " Test Failed: Expected $expected, but got $actual"
exit 1
else
echo " True: ${expected} = ${actual}"
fi
}
assert_directory_exists() {
directory="$1"
if [ ! -d "$directory" ]; then
echo " Test Failed: Expected directory $directory to exist, but it does not."
exit 1
else
echo " True: Directory $directory exists."
fi
}
test_indexer_cli_reports() {
# Indexer reports usage with no arguments
( "$IDXR" 2>&1 || true ) | grep -iq "Usage:"
# Client commands
idxr accounts --help 2>&1 |
grep -iq "Usage: mina-indexer accounts"
idxr accounts public-key --help 2>&1 |
grep -iq "Usage: mina-indexer accounts public-key"
idxr blocks --help 2>&1 |
grep -iq "Usage: mina-indexer blocks"
idxr blocks best --help 2>&1 |
grep -iq "Usage: mina-indexer blocks best"
idxr blocks state-hash --help 2>&1 |
grep -iq "Usage: mina-indexer blocks state-hash"
idxr blocks height --help 2>&1 |
grep -iq "Usage: mina-indexer blocks height"
idxr blocks global-slot --help 2>&1 |
grep -iq "Usage: mina-indexer blocks global-slot"
idxr blocks public-key --help 2>&1 |
grep -iq "Usage: mina-indexer blocks public-key"
idxr blocks children --help 2>&1 |
grep -iq "Usage: mina-indexer blocks children"
idxr ledgers --help 2>&1 |
grep -iq "Usage: mina-indexer ledgers"
idxr ledgers best --help 2>&1 |
grep -iq "Usage: mina-indexer ledgers best"
idxr ledgers height --help 2>&1 |
grep -iq "Usage: mina-indexer ledgers height"
idxr staking-ledgers delegations --help 2>&1 |
grep -iq "Usage: mina-indexer staking-ledgers delegations"
idxr staking-ledgers public-key --help 2>&1 |
grep -iq "Usage: mina-indexer staking-ledgers public-key"
idxr staking-ledgers epoch --help 2>&1 |
grep -iq "Usage: mina-indexer staking-ledgers epoch"
idxr staking-ledgers hash --help 2>&1 |
grep -iq "Usage: mina-indexer staking-ledgers hash"
idxr shutdown --help 2>&1 |
grep -iq "Usage: mina-indexer shutdown"
idxr summary --help 2>&1 |
grep -iq "Usage: mina-indexer summary"
idxr transactions hash --help 2>&1 |
grep -iq "Usage: mina-indexer transactions hash"
idxr transactions public-key --help 2>&1 |
grep -iq "Usage: mina-indexer transactions public-key"
idxr transactions state-hash --help 2>&1 |
grep -iq "Usage: mina-indexer transactions state-hash"
idxr transactions state-hash --help 2>&1 |
grep -iq "Usage: mina-indexer transactions state-hash"
idxr internal-commands public-key --help 2>&1 |
grep -iq "Usage: mina-indexer internal-commands public-key"
idxr internal-commands state-hash --help 2>&1 |
grep -iq "Usage: mina-indexer internal-commands state-hash"
idxr snarks public-key --help 2>&1 |
grep -iq "Usage: mina-indexer snarks public-key"
idxr snarks state-hash --help 2>&1 |
grep -iq "Usage: mina-indexer snarks state-hash"
idxr version --help 2>&1 |
grep -iq "Usage: mina-indexer version"
idxr db-version --help 2>&1 |
grep -iq "Usage: mina-indexer db-version"
# Server commands
idxr server start --help 2>&1 |
grep -iq "Usage: mina-indexer server start"
idxr server shutdown --help 2>&1 |
grep -iq "Usage: mina-indexer server shutdown"
# Database commands
idxr database create --help 2>&1 |
grep -iq "Usage: mina-indexer database create"
idxr database snapshot --help 2>&1 |
grep -iq "Usage: mina-indexer database snapshot"
idxr database restore --help 2>&1 |
grep -iq "Usage: mina-indexer database restore"
idxr database version --help 2>&1 |
grep -iq "Usage: mina-indexer database version"
}
# Indexer server starts up without blocks & staking ledger directories
test_server_startup() {
idxr database create --database-dir ./database
idxr_server_start --database-dir ./database
wait_for_socket
best=$(idxr summary --json | jq -r .witness_tree.best_tip_hash)
root=$(idxr summary --json | jq -r .witness_tree.canonical_root_hash)
assert $root $best
assert '3NKeMoncuHab5ScarV5ViyF16cJPT4taWNSaTLS64Dp67wuXigPZ' $best
}
# Indexer server ipc is available during initialization
test_ipc_is_available_immediately() {
stage_mainnet_blocks 100 ./blocks
idxr_server_start_standard
wait_for_socket
idxr summary
}
# Indexer database creates directories with minimal args
test_startup_dirs_get_created() {
idxr database create \
--blocks-dir ./blocks-dir \
--staking-ledgers-dir ./staking-ledgers-dir \
--database-dir ./database-dir
assert_directory_exists "./blocks-dir"
assert_directory_exists "./staking-ledgers-dir"
assert_directory_exists "./database-dir"
rm -fr ./database-dir
rm -fr ./staking-ledgers-dir
rm -fr ./blocks-dir
}
# Indexer hashes v2 signed commands correctly
# Transaction from mainnet-359606-3NKvvtFwjEtQLswWJzXBSxxiKuYVbLJrKXCnmhp6jctYMqAWcftg
test_v2_signed_command_hash() {
idxr_server_start_standard
wait_for_socket
result=$(idxr hash txn --json '{"payload":{"body":["Payment",{"amount":"1000000000","receiver_pk":"B62qpjxUpgdjzwQfd8q2gzxi99wN7SCgmofpvw27MBkfNHfHoY2VH32"}],"common":{"fee":"0.0011","fee_payer_pk":"B62qpjxUpgdjzwQfd8q2gzxi99wN7SCgmofpvw27MBkfNHfHoY2VH32","memo":"E4YM2vTHhWEg66xpj52JErHUBU4pZ1yageL4TVDDpTTSsv8mK6YaH","nonce":"765","valid_until":"4294967295"}},"signature":"7mX5FyaaoRY5a3hKP3kqhm6A4gWo9NtoHMh7irbB3Dt326wm8gyfsEQeHKJgYqQeo7nBgFGNjCD9eC265VrECYZJqYsD5V5R","signer":"B62qpjxUpgdjzwQfd8q2gzxi99wN7SCgmofpvw27MBkfNHfHoY2VH32"}')
assert '5JuJ1eRNWdE8jSMmCDoHnAdBGhLyBnCk2gkcvkfCZ7WvrKtGuWHB' $result
}
# Indexer server reports correct balance for Genesis Ledger Account
test_account_balance_cli() {
idxr_server_start_standard
wait_for_socket
result=$(idxr accounts public-key --public-key B62qqDJCQsfDoHJvJCh1hgTpiVbmgBg8SbNKLMXsjuVsX5pxCELDyFk | jq -r .balance)
assert '148837200000000' $result
}
# Indexer server returns the correct account
test_account_public_key_json() {
idxr_server_start_standard
wait_for_socket
result=$(idxr accounts public-key --public-key B62qqDJCQsfDoHJvJCh1hgTpiVbmgBg8SbNKLMXsjuVsX5pxCELDyFk | jq -r .public_key)
assert 'B62qqDJCQsfDoHJvJCh1hgTpiVbmgBg8SbNKLMXsjuVsX5pxCELDyFk' $result
}
# Indexer summary returns the correct canonical root
test_canonical_root() {
stage_mainnet_blocks 15 ./blocks
idxr_server_start_standard
wait_for_socket
hash=$(idxr summary --json | jq -r .witness_tree.canonical_root_hash)
length=$(idxr summary --json | jq -r .witness_tree.canonical_root_length)
assert 5 $length
assert '3NKQUoBfi9vkbuqtDJmSEYBQrcSo4GjwG8bPCiii4yqM8AxEQvtY' $hash
}
# Indexer server handles canonical threshold correctly
test_canonical_threshold() {
num_seq_blocks=15
canonical_threshold=2
stage_mainnet_blocks $num_seq_blocks ./blocks
idxr_server_start_standard --canonical-threshold $canonical_threshold
wait_for_socket
hash=$(idxr summary --json | jq -r .witness_tree.canonical_root_hash)
length=$(idxr summary --json | jq -r .witness_tree.canonical_root_length)
assert $(( num_seq_blocks - canonical_threshold )) $length
assert '3NKXzc1hAE1bK9BSkJUhBBSznMhwW3ZxUTgdoLoqzW6SvqVFcAw5' $hash
}
# Indexer server returns the correct best tip
test_best_tip() {
stage_mainnet_blocks 15 ./blocks
idxr_server_start_standard
wait_for_socket
# best tip query
hash=$(idxr blocks best | jq -r .state_hash)
canonicity=$(idxr blocks best | jq -r .canonicity)
length=$(idxr blocks best | jq -r .blockchain_length)
canonicity_v=$(idxr blocks best --verbose | jq -r .canonicity)
# witness tree summary
wt_hash=$(idxr summary --json | jq -r .witness_tree.best_tip_hash)
wt_length=$(idxr summary --json | jq -r .witness_tree.best_tip_length)
assert $wt_hash $hash
assert $wt_length $length
assert 'Canonical' $canonicity
assert 'Canonical' $canonicity_v
}
# Indexer server returns the correct blocks for height and slot queries
test_blocks() {
stage_mainnet_blocks 10 ./blocks
idxr_server_start_standard
wait_for_socket
# basic height query
hash=$(idxr blocks height --height 10 | jq -r .[0].state_hash)
slot=$(idxr blocks height --height 10 | jq -r .[0].global_slot_since_genesis)
length=$(idxr blocks height --height 10 | jq -r .[0].blockchain_length)
canonicity=$(idxr blocks height --height 10 | jq -r .[0].canonicity)
# verbose height query
hash_v=$(idxr blocks height --height 10 --verbose | jq -r .[0].state_hash)
length_v=$(idxr blocks height --height 10 --verbose | jq -r .[0].blockchain_length)
canonicity_v=$(idxr blocks height --height 10 --verbose | jq -r .[0].canonicity)
# witness tree summary
wt_hash=$(idxr summary --json | jq -r .witness_tree.best_tip_hash)
wt_length=$(idxr summary --json | jq -r .witness_tree.best_tip_length)
assert 9 $slot
assert $wt_hash $hash
assert $wt_hash $hash_v
assert $wt_length $length
assert $wt_length $length_v
assert 'Canonical' $canonicity
assert 'Canonical' $canonicity_v
# basic slot query
hash=$(idxr blocks global-slot --slot 9 | jq -r .[0].state_hash)
slot=$(idxr blocks global-slot --slot 9 | jq -r .[0].global_slot_since_genesis)
length=$(idxr blocks global-slot --slot 9 | jq -r .[0].blockchain_length)
canonicity=$(idxr blocks global-slot --slot 9 | jq -r .[0].canonicity)
# verbose slot query
hash_v=$(idxr blocks global-slot --slot 9 --verbose | jq -r .[0].state_hash)
length_v=$(idxr blocks global-slot --slot 9 --verbose | jq -r .[0].blockchain_length)
canonicity_v=$(idxr blocks global-slot --slot 9 --verbose | jq -r .[0].canonicity)
assert 9 $slot
assert $wt_hash $hash
assert $wt_hash $hash_v
assert $wt_length $length
assert $wt_length $length_v
assert 'Canonical' $canonicity
assert 'Canonical' $canonicity_v
# basic public key query
hash=$(idxr blocks public-key --public-key B62qpbZkvpHZ1a5nsTbANuRtrdw4YraTyA4nvJDm6HpP1YMC9QStxX3 | jq -r .[0].state_hash)
slot=$(idxr blocks public-key --public-key B62qpbZkvpHZ1a5nsTbANuRtrdw4YraTyA4nvJDm6HpP1YMC9QStxX3 | jq -r .[0].global_slot_since_genesis)
length=$(idxr blocks public-key --public-key B62qpbZkvpHZ1a5nsTbANuRtrdw4YraTyA4nvJDm6HpP1YMC9QStxX3 | jq -r .[0].blockchain_length)
canonicity=$(idxr blocks public-key --public-key B62qpbZkvpHZ1a5nsTbANuRtrdw4YraTyA4nvJDm6HpP1YMC9QStxX3 | jq -r .[0].canonicity)
# verbose public key query
hash_v=$(idxr blocks public-key --public-key B62qpbZkvpHZ1a5nsTbANuRtrdw4YraTyA4nvJDm6HpP1YMC9QStxX3 --verbose | jq -r .[0].state_hash)
length_v=$(idxr blocks public-key --public-key B62qpbZkvpHZ1a5nsTbANuRtrdw4YraTyA4nvJDm6HpP1YMC9QStxX3 --verbose | jq -r .[0].blockchain_length)
canonicity_v=$(idxr blocks public-key --public-key B62qpbZkvpHZ1a5nsTbANuRtrdw4YraTyA4nvJDm6HpP1YMC9QStxX3 --verbose | jq -r .[0].canonicity)
assert 9 $slot
assert $wt_hash $hash
assert $wt_hash $hash_v
assert $wt_length $length
assert $wt_length $length_v
assert 'Canonical' $canonicity
assert 'Canonical' $canonicity_v
# height 10 = slot 9
slot=$(idxr blocks global-slot --slot 9 | jq -r .)
height=$(idxr blocks height --height 10 | jq -r .)
assert "$slot" "$height"
# write at height to file
file=./blocks_at_height.json
idxr blocks height --height 10 --path $file
height=$(cat $file | jq -r .[0].blockchain_length)
slot=$(cat $file | jq -r .[0].global_slot_since_genesis)
assert 9 $slot
assert 10 $height
# write at slot to file
file=./blocks_at_slot.json
idxr blocks global-slot --slot 9 --path $file
height=$(cat $file | jq -r .[0].blockchain_length)
slot=$(cat $file | jq -r .[0].global_slot_since_genesis)
assert 9 $slot
assert 10 $height
# write at public key to file
file=./blocks_at_pk.json
idxr blocks public-key --public-key B62qpbZkvpHZ1a5nsTbANuRtrdw4YraTyA4nvJDm6HpP1YMC9QStxX3 --path $file
height=$(cat $file | jq -r .[0].blockchain_length)
slot=$(cat $file | jq -r .[0].global_slot_since_genesis)
assert 9 $slot
assert 10 $height
}
# Indexer handles copied blocks correctly
test_block_copy() {
stage_mainnet_blocks 10 ./blocks
idxr_server_start_standard
wait_for_socket
# start without block 11
best_hash=$(idxr summary --json | jq -r .witness_tree.best_tip_hash)
best_length=$(idxr summary --json | jq -r .witness_tree.best_tip_length)
canonical_hash=$(idxr summary --json | jq -r .witness_tree.canonical_root_hash)
canonical_length=$(idxr summary --json | jq -r .witness_tree.canonical_root_length)
assert 10 $best_length
assert 1 $canonical_length
assert '3NKGgTk7en3347KH81yDra876GPAUSoSePrfVKPmwR1KHfMpvJC5' $best_hash
assert '3NKeMoncuHab5ScarV5ViyF16cJPT4taWNSaTLS64Dp67wuXigPZ' $canonical_hash
# add block 11
stage_mainnet_single 11 ./blocks
sleep 1
# check
best_hash=$(idxr summary --json | jq -r .witness_tree.best_tip_hash)
best_length=$(idxr summary --json | jq -r .witness_tree.best_tip_length)
canonical_hash=$(idxr summary --json | jq -r .witness_tree.canonical_root_hash)
canonical_length=$(idxr summary --json | jq -r .witness_tree.canonical_root_length)
assert 11 $best_length
assert 1 $canonical_length
assert '3NLMeYAFXxsmhSFtLHFxdtjGcfHTVFmBmBF8uTJvP4Ve5yEmxYeA' $best_hash
assert '3NKeMoncuHab5ScarV5ViyF16cJPT4taWNSaTLS64Dp67wuXigPZ' $canonical_hash
}
# Indexer handles missing blocks correctly
test_missing_blocks() {
stage_mainnet_blocks 10 ./blocks
stage_mainnet_range 12 20 ./blocks # missing 11
stage_mainnet_range 22 30 ./blocks # missing 21
idxr_server_start_standard
wait_for_socket
# start out missing block 11 & 21
num_dangling=$(idxr summary --json | jq -r .witness_tree.num_dangling)
best_hash=$(idxr summary --json | jq -r .witness_tree.best_tip_hash)
best_length=$(idxr summary --json | jq -r .witness_tree.best_tip_length)
canonical_hash=$(idxr summary --json | jq -r .witness_tree.canonical_root_hash)
canonical_length=$(idxr summary --json | jq -r .witness_tree.canonical_root_length)
assert 4 $num_dangling
assert 10 $best_length
assert 1 $canonical_length
assert '3NKGgTk7en3347KH81yDra876GPAUSoSePrfVKPmwR1KHfMpvJC5' $best_hash
assert '3NKeMoncuHab5ScarV5ViyF16cJPT4taWNSaTLS64Dp67wuXigPZ' $canonical_hash
# add missing block which connects the dangling branches
stage_mainnet_single 21 ./blocks
sleep 1
# dangling branches combine
# no new canonical blocks
num_dangling=$(idxr summary --json | jq -r .witness_tree.num_dangling)
best_hash=$(idxr summary --json | jq -r .witness_tree.best_tip_hash)
best_length=$(idxr summary --json | jq -r .witness_tree.best_tip_length)
canonical_hash=$(idxr summary --json | jq -r .witness_tree.canonical_root_hash)
canonical_length=$(idxr summary --json | jq -r .witness_tree.canonical_root_length)
assert 3 $num_dangling
assert 10 $best_length
assert 1 $canonical_length
assert '3NKGgTk7en3347KH81yDra876GPAUSoSePrfVKPmwR1KHfMpvJC5' $best_hash
assert '3NKeMoncuHab5ScarV5ViyF16cJPT4taWNSaTLS64Dp67wuXigPZ' $canonical_hash
# add remaining missing block
stage_mainnet_single 11 ./blocks
sleep 1
# dangling branches move into the root branch
num_dangling=$(idxr summary --json | jq -r .witness_tree.num_dangling)
best_hash=$(idxr summary --json | jq -r .witness_tree.best_tip_hash)
best_length=$(idxr summary --json | jq -r .witness_tree.best_tip_length)
canonical_hash=$(idxr summary --json | jq -r .witness_tree.canonical_root_hash)
canonical_length=$(idxr summary --json | jq -r .witness_tree.canonical_root_length)
assert 0 $num_dangling
assert 30 $best_length
assert 20 $canonical_length
assert '3NLpGhdRifLr31DGc61jUhsAdZiTy7EUw8cap41jrmzbTem5hc3V' $best_hash
assert '3NLPpt5SyVnD1U5uJAqR3DL1Cqj5dG26SuWutRQ6AQpbQtQUWSYA' $canonical_hash
}
# Indexer server returns the correct best chain
test_best_chain() {
stage_mainnet_blocks 12 ./blocks
mkdir -p best_chain
idxr_server_start_standard
wait_for_socket
result=$(idxr chain best --num 1 | jq -r .[0].state_hash)
assert '3NKkJDmNZGYdKVDDJkkamGdvNzASia2SXxKpu18imps7KqbNXENY' $result
result=$(idxr chain best --verbose | jq -r .[0].state_hash)
assert '3NKkJDmNZGYdKVDDJkkamGdvNzASia2SXxKpu18imps7KqbNXENY' $result
# best chain with bounds
bounds=$(idxr chain best \
--start-state-hash 3NKd5So3VNqGZtRZiWsti4yaEe1fX79yz5TbfG6jBZqgMnCQQp3R \
--end-state-hash 3NKQUoBfi9vkbuqtDJmSEYBQrcSo4GjwG8bPCiii4yqM8AxEQvtY \
| jq -r .[0].state_hash)
assert '3NKQUoBfi9vkbuqtDJmSEYBQrcSo4GjwG8bPCiii4yqM8AxEQvtY' $bounds
bounds=$(idxr chain best \
--start-state-hash '3NKd5So3VNqGZtRZiWsti4yaEe1fX79yz5TbfG6jBZqgMnCQQp3R' \
--end-state-hash '3NKQUoBfi9vkbuqtDJmSEYBQrcSo4GjwG8bPCiii4yqM8AxEQvtY' \
| jq -r .[1].state_hash)
assert '3NL9qBsNibXPm5Nh8cSg5CCqrbzX5VUVY9gJzAbg7EVCF3hfhazG' $bounds
bounds=$(idxr chain best --start-state-hash '3NKd5So3VNqGZtRZiWsti4yaEe1fX79yz5TbfG6jBZqgMnCQQp3R' \
--end-state-hash '3NKQUoBfi9vkbuqtDJmSEYBQrcSo4GjwG8bPCiii4yqM8AxEQvtY' \
| jq -r .[2].state_hash)
assert '3NKd5So3VNqGZtRZiWsti4yaEe1fX79yz5TbfG6jBZqgMnCQQp3R' $bounds
# write best chain to file
file=./best_chain/best_chain.json
idxr chain best --path $file
file_result=$(cat $file | jq -r .[0].state_hash)
assert '3NKkJDmNZGYdKVDDJkkamGdvNzASia2SXxKpu18imps7KqbNXENY' $file_result
idxr chain best --verbose --path $file
file_result=$(cat $file | jq -r .[0].state_hash)
assert '3NKkJDmNZGYdKVDDJkkamGdvNzASia2SXxKpu18imps7KqbNXENY' $file_result
rm -rf best_chain
}
# Indexer server returns correct ledgers
test_ledgers() {
stage_mainnet_blocks 15 ./blocks
mkdir -p ledgers
idxr_server_start_standard
wait_for_socket
pk=B62qp1RJRL7x249Z6sHCjKm1dbkpUWHRdiQbcDaz1nWUGa9rx48tYkR # non-genesis account
pk0=B62qpJ4Q5J4LoBXgQBfq6gbXTyevFPhwMNYZEBdTSixmFq4UrdNadSN # genesis account
# canonical ledgers match
canonical_hash=$(idxr summary --json | jq -r .witness_tree.canonical_root_hash)
canonical_height=$(idxr summary --json | jq -r .witness_tree.canonical_root_length)
hash_balance=$(idxr ledgers hash --hash $canonical_hash --memoize | jq -r .wSHV2S4qX9jFsLjQo8r1BsMLH2ZRKsZx6EJd1sbozGPieEC4Jf.${pk}.balance)
height_balance=$(idxr ledgers height --height $canonical_height | jq -r .wSHV2S4qX9jFsLjQo8r1BsMLH2ZRKsZx6EJd1sbozGPieEC4Jf.${pk}.balance)
assert 607904750000000 $hash_balance
assert 607904750000000 $height_balance
# genesis ledger account
hash_balance=$(idxr ledgers hash --hash $canonical_hash | jq -r .wSHV2S4qX9jFsLjQo8r1BsMLH2ZRKsZx6EJd1sbozGPieEC4Jf.${pk0}.balance)
height_balance=$(idxr ledgers height --height $canonical_height | jq -r .wSHV2S4qX9jFsLjQo8r1BsMLH2ZRKsZx6EJd1sbozGPieEC4Jf.${pk0}.balance)
assert 502777775000000 $hash_balance
assert 502777775000000 $height_balance
# best ledgers match
best_hash=$(idxr summary --json | jq -r .witness_tree.best_tip_hash)
best_height=$(idxr summary --json | jq -r .witness_tree.best_tip_length)
best_balance=$(idxr ledgers best --memoize | jq -r .wSHV2S4qX9jFsLjQo8r1BsMLH2ZRKsZx6EJd1sbozGPieEC4Jf.${pk}.balance)
hash_balance=$(idxr ledgers hash --hash $best_hash | jq -r .wSHV2S4qX9jFsLjQo8r1BsMLH2ZRKsZx6EJd1sbozGPieEC4Jf.${pk}.balance)
height_balance=$(idxr ledgers height --height $best_height | jq -r .wSHV2S4qX9jFsLjQo8r1BsMLH2ZRKsZx6EJd1sbozGPieEC4Jf.${pk}.balance)
assert 607904750000000 $best_balance
assert 607904750000000 $hash_balance
assert 607904750000000 $height_balance
# genesis ledger account
best_balance=$(idxr ledgers best | jq -r .wSHV2S4qX9jFsLjQo8r1BsMLH2ZRKsZx6EJd1sbozGPieEC4Jf.${pk0}.balance)
hash_balance=$(idxr ledgers hash --hash $best_hash | jq -r .wSHV2S4qX9jFsLjQo8r1BsMLH2ZRKsZx6EJd1sbozGPieEC4Jf.${pk0}.balance)
height_balance=$(idxr ledgers height --height $best_height | jq -r .wSHV2S4qX9jFsLjQo8r1BsMLH2ZRKsZx6EJd1sbozGPieEC4Jf.${pk0}.balance)
assert 502777775000000 $best_balance
assert 502777775000000 $hash_balance
assert 502777775000000 $height_balance
# write ledgers to file
file=./ledgers/best-block-$best_height-$best_hash.json
idxr ledgers best --path $file
file_result=$(cat $file | jq -r .wSHV2S4qX9jFsLjQo8r1BsMLH2ZRKsZx6EJd1sbozGPieEC4Jf.${pk}.balance)
assert 607904750000000 $file_result
rm -f $file
file=./ledgers/best-ledger-$best_height-$best_hash.json
idxr ledgers hash --hash $best_hash --path $file
file_result=$(cat $file | jq -r .wSHV2S4qX9jFsLjQo8r1BsMLH2ZRKsZx6EJd1sbozGPieEC4Jf.${pk}.balance)
assert 607904750000000 $file_result
rm -f $file
file=./ledgers/ledger-height-$best_height-$best_hash.json
idxr ledgers height --height $best_height --path $file
file_result=$(cat $file | jq -r .wSHV2S4qX9jFsLjQo8r1BsMLH2ZRKsZx6EJd1sbozGPieEC4Jf.${pk}.balance)
assert 607904750000000 $file_result
rm -f $file
rm -rf ledgers
}
# Indexer server syncs with existing Speedb
test_sync() {
stage_mainnet_blocks 15 ./blocks
idxr_server_start_standard
wait_for_socket
idxr summary --verbose
assert 26 $(idxr summary --json | jq -r .blocks_processed)
shutdown_idxr
# add more blocks to the watch dir while not indexing
stage_mainnet_range 16 20 ./blocks
# sync from previous indexer db
idxr_server_start \
--blocks-dir ./blocks \
--database-dir ./database
wait_for_socket
idxr summary --verbose
# post-sync results
sync_best_hash=$(idxr summary --json | jq -r .witness_tree.best_tip_hash)
# includes blocks added to watch dir while down
assert 34 $(idxr summary --json | jq -r .blocks_processed)
assert 20 $(idxr summary --json | jq -r .witness_tree.best_tip_length)
assert '3NLPpt5SyVnD1U5uJAqR3DL1Cqj5dG26SuWutRQ6AQpbQtQUWSYA' $sync_best_hash
}
# Indexer server replays events
test_replay() {
stage_mainnet_blocks 15 ./blocks
idxr_server_start_standard
wait_for_socket
assert 26 $(idxr summary --json | jq -r .blocks_processed)
shutdown_idxr
# add 8 more blocks to the watch dir while not indexing
stage_mainnet_range 16 20 ./blocks
# replay events from previous indexer db + new blocks
idxr_server_start \
--self-check \
--blocks-dir ./blocks \
--database-dir ./database
wait_for_socket
# post-replay results
root_hash_replay=$(idxr summary --json | jq -r .witness_tree.canonical_root_hash)
best_hash_replay=$(idxr summary --json | jq -r .witness_tree.best_tip_hash)
assert 34 $(idxr summary --json | jq -r .blocks_processed)
assert 20 $(idxr summary --json | jq -r .witness_tree.best_tip_length)
assert 10 $(idxr summary --json | jq -r .witness_tree.canonical_root_length)
assert '3NLPpt5SyVnD1U5uJAqR3DL1Cqj5dG26SuWutRQ6AQpbQtQUWSYA' $best_hash_replay
assert '3NKGgTk7en3347KH81yDra876GPAUSoSePrfVKPmwR1KHfMpvJC5' $root_hash_replay
}
# Indexer server returns correct transactions
test_transactions() {
stage_mainnet_blocks 13 ./blocks
mkdir -p transactions
idxr_server_start_standard
wait_for_socket
# basic pk transaction queries
transactions=$(idxr transactions public-key --public-key B62qp1RJRL7x249Z6sHCjKm1dbkpUWHRdiQbcDaz1nWUGa9rx48tYkR | jq -r .)
amount=$(idxr transactions public-key --public-key B62qre3erTHfzQckNuibViWQGyyKwZseztqrjPZBv6SQF384Rg6ESAy | jq -r .[0].Payment.amount)
assert '1000' $amount
assert '[]' $transactions
# basic pk transaction queries - verbose
kind=$(idxr transactions public-key --public-key B62qre3erTHfzQckNuibViWQGyyKwZseztqrjPZBv6SQF384Rg6ESAy --verbose | jq -r .[0].command.payload.body.kind)
amount=$(idxr transactions public-key --public-key B62qre3erTHfzQckNuibViWQGyyKwZseztqrjPZBv6SQF384Rg6ESAy --verbose | jq -r .[0].command.payload.body.amount)
state_hash=$(idxr transactions public-key --public-key B62qre3erTHfzQckNuibViWQGyyKwZseztqrjPZBv6SQF384Rg6ESAy --verbose | jq -r .[0].state_hash)
tx_hash=$(idxr transactions public-key --public-key B62qre3erTHfzQckNuibViWQGyyKwZseztqrjPZBv6SQF384Rg6ESAy --verbose | jq -r .[0].tx_hash)
length=$(idxr transactions public-key --public-key B62qre3erTHfzQckNuibViWQGyyKwZseztqrjPZBv6SQF384Rg6ESAy --verbose | jq -r .[0].blockchain_length)
assert 3 $length
assert '1000' $amount
assert 'Payment' $kind
assert '3NKd5So3VNqGZtRZiWsti4yaEe1fX79yz5TbfG6jBZqgMnCQQp3R' $state_hash
assert 'CkpZirFuoLVVab6x2ry4j8Ld5gMmQdak7VHW6f5C7VJYE34WAEWqa' $tx_hash
# bounded pk transaction queries
amount=$(idxr transactions public-key --public-key B62qre3erTHfzQckNuibViWQGyyKwZseztqrjPZBv6SQF384Rg6ESAy \
--start-state-hash 3NL9qBsNibXPm5Nh8cSg5CCqrbzX5VUVY9gJzAbg7EVCF3hfhazG \
--end-state-hash 3NKXzc1hAE1bK9BSkJUhBBSznMhwW3ZxUTgdoLoqzW6SvqVFcAw5 \
| jq -r .[0].Payment.amount)
assert '1000' $amount
amount=$(idxr transactions public-key --public-key B62qre3erTHfzQckNuibViWQGyyKwZseztqrjPZBv6SQF384Rg6ESAy \
--start-state-hash 3NLyWnjZqUECniE1q719CoLmes6WDQAod4vrTeLfN7XXJbHv6EHH \
--end-state-hash 3NKd5So3VNqGZtRZiWsti4yaEe1fX79yz5TbfG6jBZqgMnCQQp3R \
| jq -r .[0].Payment.amount)
assert '1000' $amount
# tx hash query
amount=$(idxr transactions hash --hash CkpZirFuoLVVab6x2ry4j8Ld5gMmQdak7VHW6f5C7VJYE34WAEWqa | jq -r .Payment.amount)
assert '1000' $amount
# tx hash query - verbose
kind=$(idxr transactions hash --hash CkpZirFuoLVVab6x2ry4j8Ld5gMmQdak7VHW6f5C7VJYE34WAEWqa --verbose | jq -r .command.payload.body.kind)
amount=$(idxr transactions hash --hash CkpZirFuoLVVab6x2ry4j8Ld5gMmQdak7VHW6f5C7VJYE34WAEWqa --verbose | jq -r .command.payload.body.amount)
status=$(idxr transactions hash --hash CkpZirFuoLVVab6x2ry4j8Ld5gMmQdak7VHW6f5C7VJYE34WAEWqa --verbose | jq -r .status.kind)
tx_hash=$(idxr transactions hash --hash CkpZirFuoLVVab6x2ry4j8Ld5gMmQdak7VHW6f5C7VJYE34WAEWqa --verbose | jq -r .tx_hash)
state_hash=$(idxr transactions hash --hash CkpZirFuoLVVab6x2ry4j8Ld5gMmQdak7VHW6f5C7VJYE34WAEWqa --verbose | jq -r .state_hash)
length=$(idxr transactions hash --hash CkpZirFuoLVVab6x2ry4j8Ld5gMmQdak7VHW6f5C7VJYE34WAEWqa --verbose | jq -r .blockchain_length)
assert 3 $length
assert 'Payment' $kind
assert '1000' $amount
assert 'Failed' $status
assert 'CkpZirFuoLVVab6x2ry4j8Ld5gMmQdak7VHW6f5C7VJYE34WAEWqa' $tx_hash
assert '3NKd5So3VNqGZtRZiWsti4yaEe1fX79yz5TbfG6jBZqgMnCQQp3R' $state_hash
# state hash query
amount=$(idxr transactions state-hash --state-hash 3NKd5So3VNqGZtRZiWsti4yaEe1fX79yz5TbfG6jBZqgMnCQQp3R | jq -r .[0].Payment.amount)
source=$(idxr transactions state-hash --state-hash 3NKd5So3VNqGZtRZiWsti4yaEe1fX79yz5TbfG6jBZqgMnCQQp3R | jq -r .[0].Payment.source)
receiver=$(idxr transactions state-hash --state-hash 3NKd5So3VNqGZtRZiWsti4yaEe1fX79yz5TbfG6jBZqgMnCQQp3R | jq -r .[0].Payment.receiver)
assert '1000' $amount
assert 'B62qre3erTHfzQckNuibViWQGyyKwZseztqrjPZBv6SQF384Rg6ESAy' $source
assert 'B62qjYanmV7y9njVeH5UHkz3GYBm7xKir1rAnoY4KsEYUGLMiU45FSM' $receiver
# state hash query - verbose
kind=$(idxr transactions state-hash --state-hash 3NKd5So3VNqGZtRZiWsti4yaEe1fX79yz5TbfG6jBZqgMnCQQp3R --verbose | jq -r .[0].data.kind)
assert 'Signed_command' $kind
amount=$(idxr transactions state-hash --state-hash 3NKd5So3VNqGZtRZiWsti4yaEe1fX79yz5TbfG6jBZqgMnCQQp3R --verbose | jq -r .[0].data.payload.body.amount)
source=$(idxr transactions state-hash --state-hash 3NKd5So3VNqGZtRZiWsti4yaEe1fX79yz5TbfG6jBZqgMnCQQp3R --verbose | jq -r .[0].data.payload.body.source_pk)
receiver=$(idxr transactions state-hash --state-hash 3NKd5So3VNqGZtRZiWsti4yaEe1fX79yz5TbfG6jBZqgMnCQQp3R --verbose | jq -r .[0].data.payload.body.receiver_pk)
token=$(idxr transactions state-hash --state-hash 3NKd5So3VNqGZtRZiWsti4yaEe1fX79yz5TbfG6jBZqgMnCQQp3R --verbose | jq -r .[0].data.payload.body.token_id)
assert '1' $token
assert '1000' $amount
assert 'B62qre3erTHfzQckNuibViWQGyyKwZseztqrjPZBv6SQF384Rg6ESAy' $source
assert 'B62qjYanmV7y9njVeH5UHkz3GYBm7xKir1rAnoY4KsEYUGLMiU45FSM' $receiver
# write transactions to file
file=./transactions/transactions.json
idxr transactions public-key --public-key B62qre3erTHfzQckNuibViWQGyyKwZseztqrjPZBv6SQF384Rg6ESAy --path $file
file_result=$(cat $file | jq -r .[0].Payment.amount)
assert '1000' $file_result
rm -rf ./transactions
}
# Indexer correctly exports user commands CSV
test_transactions_csv() {
stage_mainnet_blocks 5 ./blocks
idxr_server_start_standard
wait_for_socket
# write transactions to CSV
csv_file=./B62qre3erTHfzQckNuibViWQGyyKwZseztqrjPZBv6SQF384Rg6ESAy.csv
idxr transactions public-key --public-key B62qre3erTHfzQckNuibViWQGyyKwZseztqrjPZBv6SQF384Rg6ESAy --csv --path $csv_file
# check transactions CSV
expect="Date,BlockHeight,BlockStateHash,From,To,Nonce,Hash,Fee,Amount,Memo,Kind
2021-03-17T00:12:00.000Z,5,3NKQUoBfi9vkbuqtDJmSEYBQrcSo4GjwG8bPCiii4yqM8AxEQvtY,B62qre3erTHfzQckNuibViWQGyyKwZseztqrjPZBv6SQF384Rg6ESAy,B62qjYanmV7y9njVeH5UHkz3GYBm7xKir1rAnoY4KsEYUGLMiU45FSM,8,CkpZP9pjDC5qqpHJtSaA6WpoT3GQPNYZJkCLxkERqPSb37brMTAPy,10000000,1000,,PAYMENT
2021-03-17T00:12:00.000Z,5,3NKQUoBfi9vkbuqtDJmSEYBQrcSo4GjwG8bPCiii4yqM8AxEQvtY,B62qre3erTHfzQckNuibViWQGyyKwZseztqrjPZBv6SQF384Rg6ESAy,B62qjYanmV7y9njVeH5UHkz3GYBm7xKir1rAnoY4KsEYUGLMiU45FSM,7,CkpZSZBvLsgsPnndQKkysZJDJ9gNkSR2oeaTp9grBpcCBamGsg7hV,50000000,10000,,PAYMENT
2021-03-17T00:12:00.000Z,5,3NKQUoBfi9vkbuqtDJmSEYBQrcSo4GjwG8bPCiii4yqM8AxEQvtY,B62qre3erTHfzQckNuibViWQGyyKwZseztqrjPZBv6SQF384Rg6ESAy,B62qjYanmV7y9njVeH5UHkz3GYBm7xKir1rAnoY4KsEYUGLMiU45FSM,6,CkpYeYaPLcM3JKLySyEcPeeANEVwQ3aTNYzJ9oFxqQamW9kZnFuPU,10000000,1000,,PAYMENT
2021-03-17T00:09:00.000Z,4,3NL9qBsNibXPm5Nh8cSg5CCqrbzX5VUVY9gJzAbg7EVCF3hfhazG,B62qre3erTHfzQckNuibViWQGyyKwZseztqrjPZBv6SQF384Rg6ESAy,B62qjYanmV7y9njVeH5UHkz3GYBm7xKir1rAnoY4KsEYUGLMiU45FSM,5,CkpZK28AEmzhB8AjsfT6Dd1cKdR5WF2gQw4xqDu4f93ozDX2jekTq,50000000,10000,,PAYMENT
2021-03-17T00:09:00.000Z,4,3NL9qBsNibXPm5Nh8cSg5CCqrbzX5VUVY9gJzAbg7EVCF3hfhazG,B62qre3erTHfzQckNuibViWQGyyKwZseztqrjPZBv6SQF384Rg6ESAy,B62qjYanmV7y9njVeH5UHkz3GYBm7xKir1rAnoY4KsEYUGLMiU45FSM,4,CkpaDbDiRtzF6AUVrny7VoJKTu1wStBHDEsG9W27UFeoeDwMP8VAc,10000000,1000,,PAYMENT
2021-03-17T00:06:00.000Z,3,3NKd5So3VNqGZtRZiWsti4yaEe1fX79yz5TbfG6jBZqgMnCQQp3R,B62qre3erTHfzQckNuibViWQGyyKwZseztqrjPZBv6SQF384Rg6ESAy,B62qjYanmV7y9njVeH5UHkz3GYBm7xKir1rAnoY4KsEYUGLMiU45FSM,3,CkpZ1u12zrTuEttp7QktfEy7wosHrPV6r3DJkq4sA9f1yKgEqmj5k,50000000,10000,,PAYMENT
2021-03-17T00:06:00.000Z,3,3NKd5So3VNqGZtRZiWsti4yaEe1fX79yz5TbfG6jBZqgMnCQQp3R,B62qre3erTHfzQckNuibViWQGyyKwZseztqrjPZBv6SQF384Rg6ESAy,B62qjYanmV7y9njVeH5UHkz3GYBm7xKir1rAnoY4KsEYUGLMiU45FSM,2,CkpYeG32dVJUjs6iq3oroXWitXar1eBtV3GVFyH5agw7HPp9bG4yQ,10000000,1000,,PAYMENT
2021-03-17T00:06:00.000Z,3,3NKd5So3VNqGZtRZiWsti4yaEe1fX79yz5TbfG6jBZqgMnCQQp3R,B62qre3erTHfzQckNuibViWQGyyKwZseztqrjPZBv6SQF384Rg6ESAy,B62qjYanmV7y9njVeH5UHkz3GYBm7xKir1rAnoY4KsEYUGLMiU45FSM,1,CkpZB4WE3wDRJ4CqCXqS4dqF8hoRQDVK8banePKUgTR6kvhTfyjRp,50000000,10000,,PAYMENT
2021-03-17T00:06:00.000Z,3,3NKd5So3VNqGZtRZiWsti4yaEe1fX79yz5TbfG6jBZqgMnCQQp3R,B62qre3erTHfzQckNuibViWQGyyKwZseztqrjPZBv6SQF384Rg6ESAy,B62qjYanmV7y9njVeH5UHkz3GYBm7xKir1rAnoY4KsEYUGLMiU45FSM,0,CkpZirFuoLVVab6x2ry4j8Ld5gMmQdak7VHW6f5C7VJYE34WAEWqa,10000000,1000,,PAYMENT"
assert "$expect" "$(cat $csv_file)"
rm -f $csv_file
}
# Indexer server returns correct SNARK work
test_snark_work() {
stage_mainnet_blocks 120 ./blocks
mkdir -p snark_work
idxr_server_start_standard --canonical-threshold 5
wait_for_socket
# pk SNARK work queries
# prover has SNARK work in block 111
fee=$(idxr snarks public-key --public-key B62qrCz3ehCqi8Pn8y3vWC9zYEB9RKsidauv15DeZxhzkxL3bKeba5h | jq -r .[0].fee)
prover=$(idxr snarks public-key --public-key B62qrCz3ehCqi8Pn8y3vWC9zYEB9RKsidauv15DeZxhzkxL3bKeba5h | jq -r .[0].prover)
state_hash=$(idxr snarks public-key --public-key B62qrCz3ehCqi8Pn8y3vWC9zYEB9RKsidauv15DeZxhzkxL3bKeba5h | jq -r .[0].state_hash)
assert '0' $fee
assert 'B62qrCz3ehCqi8Pn8y3vWC9zYEB9RKsidauv15DeZxhzkxL3bKeba5h' $prover
assert '3NL33j16AWm3Jhjj1Ud25E54hu7HpUq4WBQcAiijEKMfXqwFJwzK' $state_hash
# state hash SNARK work queries
fee=$(idxr snarks state-hash --state-hash 3NL33j16AWm3Jhjj1Ud25E54hu7HpUq4WBQcAiijEKMfXqwFJwzK | jq -r .[0].fee)
prover=$(idxr snarks state-hash --state-hash 3NL33j16AWm3Jhjj1Ud25E54hu7HpUq4WBQcAiijEKMfXqwFJwzK | jq -r .[0].prover)
assert '0' $fee
assert 'B62qrCz3ehCqi8Pn8y3vWC9zYEB9RKsidauv15DeZxhzkxL3bKeba5h' $prover
# write SNARK work from public key to file
file=./snark_work/snark_work.json
idxr snarks public-key --public-key B62qrCz3ehCqi8Pn8y3vWC9zYEB9RKsidauv15DeZxhzkxL3bKeba5h --path $file
fee=$(cat $file | jq -r .[0].fee)
prover=$(cat $file | jq -r .[0].prover)
state_hash=$(cat $file | jq -r .[0].state_hash)
assert '0' $fee
assert 'B62qrCz3ehCqi8Pn8y3vWC9zYEB9RKsidauv15DeZxhzkxL3bKeba5h' $prover
assert '3NL33j16AWm3Jhjj1Ud25E54hu7HpUq4WBQcAiijEKMfXqwFJwzK' $state_hash
# write SNARK work from block to file
file=./snark_work/snark_work.json
idxr snarks state-hash --state-hash 3NL33j16AWm3Jhjj1Ud25E54hu7HpUq4WBQcAiijEKMfXqwFJwzK --path $file
fee=$(cat $file | jq -r .[0].fee)
prover=$(cat $file | jq -r .[0].prover)
assert '0' $fee
assert 'B62qrCz3ehCqi8Pn8y3vWC9zYEB9RKsidauv15DeZxhzkxL3bKeba5h' $prover
# get top 5 SNARKers
assert 0 $(idxr snarks top --num 5 | jq -r .[0].total_fees)
assert 'B62qrCz3ehCqi8Pn8y3vWC9zYEB9RKsidauv15DeZxhzkxL3bKeba5h' $(idxr snarks top --num 5 | jq -r .[0].prover)
rm -rf ./snark_work
}
# Restart from a snapshot of a running indexer database
test_snapshot() {
stage_mainnet_blocks 13 ./blocks
idxr_server_start_standard
wait_for_socket
# pre-snapshot results
canonical_hash=$(idxr summary --json | jq -r .witness_tree.canonical_root_hash)
canonical_length=$(idxr summary --json | jq -r .witness_tree.canonical_root_length)
best_hash=$(idxr summary --json | jq -r .witness_tree.best_tip_hash)
best_length=$(idxr summary --json | jq -r .witness_tree.best_tip_length)
amount=$(idxr transactions public-key --public-key B62qre3erTHfzQckNuibViWQGyyKwZseztqrjPZBv6SQF384Rg6ESAy --verbose | jq -r .[0].command.payload.body.amount)
# create snapshot of running indexer
idxr database snapshot --output-path ./snapshot
# kill running indexer and remove directories
shutdown_idxr
rm -rf ./blocks
rm -rf ./staking-ledgers
rm -rf ./database
rm -f ./mina-indexer.sock
# restore the db directory from the snapshot
idxr database restore --snapshot-file ./snapshot --restore-dir ./restore-path
# start a new indexer from the db
idxr_server_start \
--database-dir ./restore-path \
--blocks-dir ./blocks \
--staking-ledgers-dir ./staking-ledgers
wait_for_socket
# post-snapshot reults
canonical_hash_snapshot=$(idxr summary --json | jq -r .witness_tree.canonical_root_hash)
canonical_length_snapshot=$(idxr summary --json | jq -r .witness_tree.canonical_root_length)
best_hash_snapshot=$(idxr summary --json | jq -r .witness_tree.best_tip_hash)
best_length_snapshot=$(idxr summary --json | jq -r .witness_tree.best_tip_length)
amount_snapshot=$(idxr transactions public-key --public-key B62qre3erTHfzQckNuibViWQGyyKwZseztqrjPZBv6SQF384Rg6ESAy --verbose | jq -r .[0].command.payload.body.amount)
assert $canonical_hash $canonical_hash_snapshot
assert $canonical_length $canonical_length_snapshot
assert $best_hash $best_hash_snapshot
assert $best_length $best_length_snapshot
assert $amount $amount_snapshot
rm -rf ./snapshot ./restore-path
}
test_rest_accounts_summary() {