Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bd-4590 updated handling of get code, updated exclude option handling #79

Merged
merged 2 commits into from
Dec 12, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
149 changes: 92 additions & 57 deletions scripts/queries/abi_wasm_hashout.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ function unique_values() {
function count_unique() {
local LC_ALL=C

if [ "$#" -eq 0 ] ; then
if [ "$#" -eq 0 ] ; then
echo 0
else
echo "$(printf "%s\000" "$@" |
Expand Down Expand Up @@ -170,13 +170,21 @@ do_compare_abiwasm_hashout() {
fi
fi

# Note: Even with exit code==0 the hash may still be bad; test and handle it.
# Couple of ways; posiz regex below,
# Using grep as grep -E '[0]+' or grep -E '[0]{64}'
if [[ ${exclude} != 'localnet' ]]; then
echo -n $'\e[0;36m' ' LocalNet:'
code=$(${devtools_dir}/bin/clio -u ${localhost_url} get code ${contract_code} 2>/dev/null)
if [[ $? -eq 0 ]]; then
hash=$(echo ${code} | awk -F': ' '{print $2}')
wasm_hashes+=($hash)
echo $'\e[0;39m' ${hash}
if [[ $hash =~ ^[0]+$ ]]; then
wasm_hashes+=(" ")
echo -e "\e[0m \e[41m!!! Contract not found* !!!\e[0m"
else
wasm_hashes+=($hash)
echo $'\e[0;39m' ${hash}
fi
else
wasm_hashes+=(" ")
echo -e "\e[0m \e[41m!!! Contract not found !!!\e[0m"
Expand All @@ -187,8 +195,13 @@ do_compare_abiwasm_hashout() {
code=$(${devtools_dir}/bin/clio -u ${testnet_url} get code ${contract_code} 2>/dev/null)
if [[ $? -eq 0 ]]; then
hash=$(echo ${code} | awk -F': ' '{print $2}')
wasm_hashes+=($hash)
echo $'\e[0;39m' ${hash}
if [[ $hash =~ ^[0]+$ ]]; then
wasm_hashes+=(" ")
echo -e "\e[0m \e[41m!!! Contract not found* !!!\e[0m"
else
wasm_hashes+=($hash)
echo $'\e[0;39m' ${hash}
fi
else
wasm_hashes+=(" ")
echo -e "\e[0m \e[41m!!! Contract not found !!!\e[0m"
Expand All @@ -198,13 +211,9 @@ do_compare_abiwasm_hashout() {
code=$(${devtools_dir}/bin/clio -u ${mainnet_url} get code ${contract_code} 2>/dev/null)
if [[ $? -eq 0 ]]; then
hash=$(echo ${code} | awk -F': ' '{print $2}')

# The hash may still be bad; test and handle it.
# Couple of ways; posiz regex below,
# Using grep as grep -E '[0]+' or grep -E '[0]{64}'
if [[ $hash =~ ^[0]+$ ]]; then
wasm_hashes+=(" ")
echo -e "\e[0m \e[41m!!! Contract not found !!!\e[0m"
echo -e "\e[0m \e[41m!!! Contract not found* !!!\e[0m"
else
wasm_hashes+=($hash)
echo $'\e[0;39m' ${hash}
Expand All @@ -230,77 +239,103 @@ do_compare_abiwasm_hashout() {
echo
echo -e " \e[41mABI Hash Differences:\e[0m"
c_list=("${abi_hashes[@]:0:2}")
if ! unique_values "${c_list[@]}"; then
if [[ ${exclude} == 'file' ]]; then
echo -e " \e[41m${contract}: LocalNet/TestNet ABI Hashes DIFFER!\e[0m"
echo -n $'\e[0;31m LocalNet:'
if [[ -n ${exclude} ]]; then
if ! unique_values "${c_list[@]}"; then
if [[ ${exclude} == 'file' ]]; then
echo -e " \e[41m${contract}: LocalNet/TestNet ABI Hashes DIFFER!\e[0m"
echo -n $'\e[0;31m LocalNet: '
echo $'\e[0;39m' ${c_list[0]}
echo -n $'\e[0;31m TestNet: '
echo $'\e[0;39m' ${c_list[1]}
echo
elif [[ ${exclude} == 'localnet' ]]; then
echo -e " \e[41m${contract}: File/TestNet ABI Hashes DIFFER!\e[0m"
echo -n $'\e[0;31m File: '
echo $'\e[0;39m' ${c_list[0]}
echo -n $'\e[0;31m TestNet: '
echo $'\e[0;39m' ${c_list[1]}
echo
fi
fi
else
if ! unique_values "${c_list[@]}"; then
echo -e " \e[41m${contract}: File/LocalNet ABI Hashes DIFFER!\e[0m"
echo -n $'\e[0;31m File: '
echo $'\e[0;39m' ${c_list[0]}
echo -n $'\e[0;31m TestNet: '
echo -n $'\e[0;31m LocalNet: '
echo $'\e[0;39m' ${c_list[1]}
echo
elif [[ ${exclude} == 'localnet' ]]; then
echo -e " \e[41m${contract}: File/TestNet ABI Hashes DIFFER!\e[0m"
echo -n $'\e[0;31m File: '
fi
c_list=("${abi_hashes[@]:1:2}")
if ! unique_values "${c_list[@]}"; then
echo -e " \e[41m${contract}: LocalNet/TestNet ABI Hashes DIFFER!\e[0m"
echo -n $'\e[0;31m LocalNet: '
echo $'\e[0;39m' ${c_list[0]}
echo -n $'\e[0;31m TestNet: '
echo -n $'\e[0;31m TestNet: '
echo $'\e[0;39m' ${c_list[1]}
echo
else
echo -e " \e[41m${contract}: File/LocalNet ABI Hashes DIFFER!\e[0m"
echo -n $'\e[0;31m File: '
fi
c_list=("${abi_hashes[@]:2:2}")
if ! unique_values "${c_list[@]}"; then
echo -e " \e[41m${contract}: TestNet/MainNet ABI Hashes DIFFER!\e[0m"
echo -n $'\e[0;31m TestNet: '
echo $'\e[0;39m' ${c_list[0]}
echo -n $'\e[0;31m LocalNet: '
echo -n $'\e[0;31m MainNet: '
echo $'\e[0;39m' ${c_list[1]}
echo
fi
fi
c_list=("${abi_hashes[@]:2:2}")
if ! unique_values "${c_list[@]}"; then
echo -e " \e[41m${contract}: TestNet/MainNet ABI Hashes DIFFER!\e[0m"
echo -n $'\e[0;31m TestNet: '
echo $'\e[0;39m' ${c_list[0]}
echo -n $'\e[0;31m MainNet: '
echo $'\e[0;39m' ${c_list[1]}
echo
fi
fi
if [[ "$(count_unique "${wasm_hashes[@]}")" -ne 1 ]]; then
echo
echo -e " \e[41mWASM Hash Differences:\e[0m"
c_list=("${wasm_hashes[@]:0:2}")
if ! unique_values "${c_list[@]}"; then
if [[ ${exclude} == 'file' ]]; then
echo -e " \e[41m${contract}: LocalNet/TestNet WASM Hashes DIFFER!\e[0m"
echo -n $'\e[0;31m LocalNet:'
if [[ -n ${exclude} ]]; then
if ! unique_values "${c_list[@]}"; then
if [[ ${exclude} == 'file' ]]; then
echo -e " \e[41m${contract}: LocalNet/TestNet WASM Hashes DIFFER!\e[0m"
echo -n $'\e[0;31m LocalNet: '
echo $'\e[0;39m' ${c_list[0]}
echo -n $'\e[0;31m TestNet: '
echo $'\e[0;39m' ${c_list[1]}
echo
elif [[ ${exclude} == 'localnet' ]]; then
echo -e " \e[41m${contract}: File/TestNet WASM Hashes DIFFER!\e[0m"
echo -n $'\e[0;31m File: '
echo $'\e[0;39m' ${c_list[0]}
echo -n $'\e[0;31m TestNet: '
echo $'\e[0;39m' ${c_list[1]}
echo
fi
fi
else
if ! unique_values "${c_list[@]}"; then
echo -e " \e[41m${contract}: File/LocalNet WASM Hashes DIFFER!\e[0m"
echo -n $'\e[0;31m File: '
echo $'\e[0;39m' ${c_list[0]}
echo -n $'\e[0;31m TestNet: '
echo -n $'\e[0;31m LocalNet: '
echo $'\e[0;39m' ${c_list[1]}
echo
elif [[ ${exclude} == 'localnet' ]]; then
echo -e " \e[41m${contract}: File/TestNet WASM Hashes DIFFER!\e[0m"
echo -n $'\e[0;31m File: '
fi
c_list=("${wasm_hashes[@]:1:2}")
if ! unique_values "${c_list[@]}"; then
echo -e " \e[41m${contract}: LocalNet/TestNet WASM Hashes DIFFER!\e[0m"
echo -n $'\e[0;31m LocalNet: '
echo $'\e[0;39m' ${c_list[0]}
echo -n $'\e[0;31m TestNet: '
echo -n $'\e[0;31m TestNet: '
echo $'\e[0;39m' ${c_list[1]}
echo
else
echo -e " \e[41m${contract}: File/LocalNet WASM Hashes DIFFER!\e[0m"
echo -n $'\e[0;31m File: '
fi
c_list=("${wasm_hashes[@]:2:2}")
if ! unique_values "${c_list[@]}"; then
echo -e " \e[41m${contract}: TestNet/MainNet WASM Hashes DIFFER!\e[0m"
echo -n $'\e[0;31m TestNet: '
echo $'\e[0;39m' ${c_list[0]}
echo -n $'\e[0;31m LocalNet: '
echo -n $'\e[0;31m MainNet: '
echo $'\e[0;39m' ${c_list[1]}
echo
fi
fi
c_list=("${wasm_hashes[@]:2:2}")
if ! unique_values "${c_list[@]}"; then
echo -e " \e[41m${contract}: TestNet/MainNet WASM Hashes DIFFER!\e[0m"
echo -n $'\e[0;31m TestNet: '
echo $'\e[0;39m' ${c_list[0]}
echo -n $'\e[0;31m MainNet: '
echo $'\e[0;39m' ${c_list[1]}
echo
fi
fi
done
}
Expand Down Expand Up @@ -389,7 +424,7 @@ do_net_abiwasm_hashout() {
do_wasm $url $contract $contract_code
else
do_wasm_markup $url $contract $contract_code
fi
fi
done
}

Expand Down Expand Up @@ -441,7 +476,7 @@ function do_wasm() {

echo -n $'\e[0;31m'
printf "%.20s" " ${contract}: "

code=$(${devtools_dir}/bin/clio -u ${url} get code ${contract_code} 2>/dev/null)
if [[ $? -eq 0 ]]; then
hash=$(echo ${code} | awk -F': ' '{print $2}')
Expand Down Expand Up @@ -568,7 +603,7 @@ while getopts 'cmoirxh' opt; do
echo -e "\tclio -u <URL> get code <Contract>, and openssl"
echo
echo -e "-o\tGenerate hashes for each network (localhost, TestNet, MainNet)"
echo -e "\tretrieved using the commands clio -u <URL> get code <Contract>, and"
echo -e "\tusing the commands clio -u <URL> get abi <Contract>, and"
echo -e "\tclio -u <URL> get code <Contract>, and openssl"
echo
;;
Expand Down