1+ #! /usr/bin/env bash
2+
3+ set -euox pipefail
4+
5+ # This script runs the archive hardfork toolbox tests.
6+ # It assumes that the archive hardfork toolbox has already been built.
7+ # It requires the archive database URI to be provided via --postgres-uri argument.
8+
9+ # Parse command line arguments
10+ POSTGRES_URI=" ${PG_CONN:- } "
11+ TOOLBOX_PATH=" mina-archive-hardfork-toolbox"
12+ AVAILABLE_MODES=(" pre-fork" " post-fork" " upgrade" )
13+ MODE=" "
14+
15+ while [[ $# -gt 0 ]]; do
16+ case $1 in
17+ --postgres-uri)
18+ POSTGRES_URI=" $2 "
19+ shift 2
20+ ;;
21+ --toolbox-path)
22+ TOOLBOX_PATH=" $2 "
23+ shift 2
24+ ;;
25+ --mode)
26+ MODE=" $2 "
27+ if [[ ! " ${AVAILABLE_MODES[*]} " =~ ${MODE} ]]; then
28+ echo " Invalid mode: $MODE "
29+ echo " Available modes are: ${AVAILABLE_MODES[*]} "
30+ exit 1
31+ fi
32+ shift 2
33+ ;;
34+ * )
35+ echo " Unknown option: $1 "
36+ echo " Usage: $0 --postgres-uri <database_uri> [--toolbox-path <path_to_binary>]"
37+ exit 1
38+ ;;
39+ esac
40+ done
41+
42+ # Validate required arguments
43+ if [[ -z " $POSTGRES_URI " ]]; then
44+ echo " Error: --postgres-uri argument is required"
45+ echo " Usage: $0 --postgres-uri <database_uri> [--toolbox-path <path_to_binary>]"
46+ exit 1
47+ fi
48+
49+ echo " Using archive database URI: $POSTGRES_URI "
50+ echo " Using toolbox binary: $TOOLBOX_PATH "
51+
52+ # Run the archive hardfork toolbox tests
53+ echo " Running archive hardfork toolbox tests..."
54+
55+ # Define test parameters
56+ # Those values are hardcoded for the purpose of testing the toolbox.
57+ # They correspond sql scripts scripts/tests/archive-hardfork-toolbox/*.sql
58+ # Reason for using two databases is to simulate pre-fork and post-fork states independently.
59+ # This is required as for example pre-fork db cannot include transactions after stop slot.
60+ # Such check will fail if we try to run it on a single db including both pre and post fork data.
61+
62+ # Pre-fork test parameters
63+
64+ FORK_CANDIDATE_HEIGHT=297884
65+ FORK_CANDIDATE_GENESIS_SLOT=448610
66+ FORK_CANDIDATE_STATE_HASH=" 3NKJ8d6ncwhLGv3B28xCuTQfXxa3MyEShSWasVFYjtnm8sFZrhF6"
67+ LATEST_STATE_HASH=" 3NKX1QQ5bSjPwE5HLxLZ6dj2Abe9uk4tqWsjGisxittxLEd8rrLK"
68+
69+ # Post-fork test parameters
70+ # these values correspond to the fork defined in scripts/tests/archive-hardfork-toolbox/hf_archive.tar.gz
71+ # that data can be different from the pre-fork test data. They are independent tests.
72+ FORK_SLOT=1067
73+ FORK_STATE_HASH=" 3NK38gNjWR6sE2MTKV8AqogjY6WaboPjSDq3zfpfVtiUgLMze1Wm"
74+
75+ if [[ " $MODE " == " pre-fork" ]]; then
76+ " $TOOLBOX_PATH " fork-candidate is-in-best-chain --postgres-uri " $POSTGRES_URI " --fork-state-hash " $FORK_CANDIDATE_STATE_HASH " --fork-height " $FORK_CANDIDATE_HEIGHT " --fork-slot " $FORK_CANDIDATE_GENESIS_SLOT "
77+
78+ " $TOOLBOX_PATH " fork-candidate confirmations --postgres-uri " $POSTGRES_URI " --latest-state-hash " $LATEST_STATE_HASH " --fork-slot " $FORK_CANDIDATE_GENESIS_SLOT " --required-confirmations 1
79+
80+ " $TOOLBOX_PATH " fork-candidate no-commands-after --postgres-uri " $POSTGRES_URI " --fork-state-hash " $FORK_CANDIDATE_STATE_HASH " --fork-slot " $FORK_CANDIDATE_GENESIS_SLOT "
81+ fi
82+
83+ if [[ " $MODE " == " upgrade" ]]; then
84+ " $TOOLBOX_PATH " verify-upgrade --postgres-uri " $POSTGRES_URI " --version 4.0.0
85+ fi
86+
87+ if [[ " $MODE " == " post-fork" ]]; then
88+ " $TOOLBOX_PATH " validate-fork --postgres-uri " $POSTGRES_URI " --fork-slot " $FORK_SLOT " --fork-state-hash " $FORK_STATE_HASH "
89+ fi
0 commit comments