1+ #! /bin/bash
2+ set -euo pipefail
3+ # Copyright (c) 2024 Status Research & Development GmbH
4+ # Licensed under either of
5+ # * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or
6+ # http://www.apache.org/licenses/LICENSE-2.0)
7+ # * MIT license ([LICENSE-MIT](LICENSE-MIT) or
8+ # http://opensource.org/licenses/MIT)
9+ # at your option. This file may not be copied, modified, or distributed except
10+ # according to those terms.
11+
12+ # ------------------------------------------------
13+ # Inputs on how to run checks
14+ # ------------------------------------------------
15+ echo
16+ printf " Do you want to run the checks in terminal or visit the assertoor URL? (terminal/url) "
17+ read reply
18+
19+ echo
20+ printf " Build new changes (yes/no)? "
21+ read use_previous_image
22+
23+ # ------------------------------------------------
24+ # Installation Checks
25+ # ------------------------------------------------
26+
27+ # Checking for docker installation
28+ echo " Checking docker installation"
29+ if command -v docker & > /dev/null; then
30+ echo " Docker installation found"
31+ else
32+ echo " Docker installation not found. Please install docker."
33+ exit 1
34+ fi
35+
36+ echo " Checking kurtosis installation"
37+ if command -v kurtosis & > /dev/null; then
38+ echo " Kurtosis installation found"
39+ else
40+ echo " Kurtosis installation not found. Installing kurtosis"
41+ echo " deb [trusted=yes] https://apt.fury.io/kurtosis-tech/ /" | sudo tee /etc/apt/sources.list.d/kurtosis.list
42+ sudo apt-get update
43+ sudo apt-get install -y kurtosis
44+ fi
45+
46+ # Install jq if not installed already
47+ if [ " $( which jq) " != " " ];
48+ then
49+ echo " jq is already installed"
50+ else
51+ echo " jq is not installed. Installing jq"
52+ sudo apt-get install -y jq
53+ fi
54+
55+ new_cl_image=" localtestnet"
56+
57+ # ------------------------------------------------
58+ # Build the Docker Image
59+ # ------------------------------------------------
60+ if [[ " $use_previous_image " == " no" ]]; then
61+ echo " Using the previously built Docker image"
62+ echo
63+ echo -n " Please enter the docker image name (default: localtestnet) "
64+ read -r cl_image
65+ if [[ " $cl_image " == " " ]]; then
66+ new_cl_image=" localtestnet"
67+ else
68+ new_cl_image=$cl_image
69+ fi
70+ else
71+ echo " Starting the Docker Build!"
72+ # Build the docker Image
73+ sudo docker build . -t localtestnet
74+ # The new el_image value
75+ new_cl_image=" localtestnet"
76+ fi
77+
78+
79+ # ------------------------------------------------
80+ # Run the Kurtosis Tests
81+ # ------------------------------------------------
82+
83+ # Use sed to replace the el_image value in the file
84+ cat kurtosis-network-params.yml | envsubst > assertoor.yaml
85+ sed -i " s/cl_image: .*/cl_image: $new_cl_image /" assertoor.yaml
86+
87+ sudo kurtosis run \
88+ --enclave nimbus-localtestnet \
89+ github.com/ethpandaops/ethereum-package \
90+ --args-file assertoor.yaml
91+
92+ enclave_dump=$( kurtosis enclave inspect nimbus-localtestnet)
93+ assertoor_url=$( echo " $enclave_dump " | grep assertoor | grep http | sed ' s/.*\(http:\/\/[0-9.:]\+\).*/\1/' )
94+
95+ # ------------------------------------------------
96+ # Remove Generated File
97+ # ------------------------------------------------
98+ rm assertoor.yaml
99+
100+ # Check the user's input and respond accordingly
101+ if [[ " $reply " == " url" ]]; then
102+ echo " You chose to visit the assertoor URL."
103+ echo " Assertoor Checks Please Visit -> ${assertoor_url} "
104+ echo " Please visit the URL to check the status of the tests"
105+ echo " The kurtosis enclave needs to be cleared, after the tests are done. Please run the following command ----- sudo kurtosis enclave rm -f nimbus-localtestnet"
106+ else
107+ echo " Running the checks over terminal"
108+
109+
110+ # ------------------------------------------------
111+ # Check for Test Status
112+ # ------------------------------------------------
113+ YELLOW=' \033[1;33m'
114+ GRAY=' \033[0;37m'
115+ GREEN=' \033[0;32m'
116+ RED=' \033[0;31m'
117+ NC=' \033[0m'
118+
119+ # print assertor logs
120+ assertoor_container=$( docker container list | grep assertoor | sed ' s/^\([^ ]\+\) .*$/\1/' )
121+ docker logs -f " $assertoor_container " &
122+
123+ # helper to fetch task status for specific test id
124+ get_tasks_status () {
125+ tasks=$( curl -s " ${assertoor_url} " /api/v1/test_run/" $1 " | jq -c " .data.tasks[] | {index, parent_index, name, title, status, result}" )
126+ declare -A task_graph_map
127+ task_graph_map[0]=" "
128+
129+ while read task; do
130+ task_id=$( echo " $task " | jq -r " .index" )
131+ task_parent=$( echo " $task " | jq -r " .parent_index" )
132+ task_name=$( echo " $task " | jq -r " .name" )
133+ task_title=$( echo " $task " | jq -r " .title" )
134+ task_status=$( echo " $task " | jq -r " .status" )
135+ task_result=$( echo " $task " | jq -r " .result" )
136+
137+ task_graph=" ${task_graph_map[$task_parent]} "
138+ task_graph_map[$task_id ]=" $task_graph |"
139+ if [ ! -z " $task_graph " ]; then
140+ task_graph=" ${task_graph} - "
141+ fi
142+
143+ if [ " $task_status " == " pending" ]; then
144+ task_status=" ${GRAY} pending ${NC} "
145+ elif [ " $task_status " == " running" ]; then
146+ task_status=" ${YELLOW} running ${NC} "
147+ elif [ " $task_status " == " complete" ]; then
148+ task_status=" ${GREEN} complete${NC} "
149+ fi
150+
151+ if [ " $task_result " == " none" ]; then
152+ task_result=" ${GRAY} none ${NC} "
153+ elif [ " $task_result " == " success" ]; then
154+ task_result=" ${GREEN} success${NC} "
155+ elif [ " $task_result " == " failure" ]; then
156+ task_result=" ${RED} failure${NC} "
157+ fi
158+
159+ echo -e " $( printf ' %-4s' " $task_id " ) \t$task_status \t$task_result \t$( printf ' %-50s' " $task_graph$task_name " ) \t$task_title "
160+ done <<< $( echo " $tasks " )
161+ }
162+
163+ # poll & check test status
164+ final_test_result=" "
165+ failed_test_id=" "
166+ while true
167+ do
168+ pending_tests=0
169+ failed_tests=0
170+ total_tests=0
171+ running_test=" "
172+
173+ status_lines=()
174+ task_lines=" "
175+ status_lines+=(" $( date +' %Y-%m-%d %H:%M:%S' ) Test Status:" )
176+
177+ tests=$( curl -s " ${assertoor_url} " /api/v1/test_runs | jq -c " .data[] | {run_id, test_id, name, status}" )
178+ while read -r test ; do
179+ if [ -z " $test " ]; then
180+ continue
181+ fi
182+ run_id=$( echo " $test " | jq -r " .run_id" )
183+ test_id=$( echo " $test " | jq -r " .test_id" )
184+ test_name=$( echo " $test " | jq -r " .name" )
185+ test_status=$( echo " $test " | jq -r " .status" )
186+
187+ if [ " $test_status " == " pending" ]; then
188+ pending_tests=$( expr $pending_tests + 1)
189+ status_name=" ${GRAY} pending${NC} "
190+ elif [ " $test_status " == " running" ]; then
191+ pending_tests=$( expr $pending_tests + 1)
192+ running_test=" $run_id "
193+ status_name=" ${YELLOW} running${NC} "
194+
195+ elif [ " $test_status " == " success" ]; then
196+ status_name=" ${GREEN} success${NC} "
197+ elif [ " $test_status " == " failure" ]; then
198+ failed_tests=$( expr $failed_tests + 1)
199+ failed_test_id=" $run_id "
200+ status_name=" ${RED} failure${NC} "
201+ else
202+ status_name=" $test_status "
203+ fi
204+ status_lines+=(" $( printf ' %-3s' " $test_id " ) $status_name \t$test_name " )
205+ total_tests=$( expr $total_tests + 1)
206+ done <<< $( echo " $tests " )
207+
208+ for status_line in " ${status_lines[@]} "
209+ do
210+ echo -e " $status_line "
211+ done
212+
213+ if [ -n " $running_test " ]; then
214+ task_lines=$( get_tasks_status " $running_test " )
215+ echo " Active Test Task Status:"
216+ echo " $task_lines "
217+ fi
218+
219+ if [ " $failed_tests " -gt 0 ]; then
220+ final_test_result=" failure"
221+ break
222+ fi
223+ if [ " $total_tests " -gt 0 ] && [ " $pending_tests " -le 0 ]; then
224+ final_test_result=" success"
225+ break
226+ fi
227+
228+ sleep 60
229+ done
230+
231+ # save test results & status to github output
232+ echo " test_result=$( echo " $final_test_result " ) "
233+ echo " test_status"
234+ for status_line in " ${status_lines[@]} "
235+ do
236+ echo -e " $status_line "
237+ done
238+ echo
239+
240+ if [ -n " $failed_test_id " ]; then
241+ echo " failed_test_status"
242+ get_tasks_status " $failed_test_id "
243+ echo " "
244+ else
245+ echo " failed_test_status="
246+ fi
247+
248+ # ------------------------------------------------
249+ # Cleanup
250+ # ------------------------------------------------
251+ sudo kurtosis enclave rm -f nimbus-localtestnet
252+ fi
0 commit comments