Skip to content

Instantly share code, notes, and snippets.

@PhilosopherRex
Last active January 7, 2023 15:24
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
script to continuously upload random data to the safe network testnet and to verify data afterwards
#!/bin/bash
# isu -- infinite safe upload
msg() {
printf '%s\n' "${0##*/}>> ${1}" | tee -a "test.log"
}
verify_put() {
safeURL=$(echo "${3}" | grep -o ' | safe://[^ ]*' | grep -o 'safe://[^ ]*')
safe cat "${safeURL}" >"${1}"
[ "$(md5sum "${1}")" = "${2}" ] && msg "file: ${1} has good checksum" || msg "file: ${1} has BAD checksum"
rm "${1}"
}
while true
do
filesize=$(shuf -i 10000-9000000 -n 1)
filename=$(cat /dev/urandom | tr -cd 'a-f0-9' | head -c 16)
head -c "${filesize}" </dev/urandom >"${filename}"
checksum=$(md5sum "${filename}")
counter=$((counter + 1))
TBU=$(($TBU + $filesize))
msg "uploading filename:${filename} -- size in bytes:${filesize}; please wait ..."
safeOutput="$(safe files put "${filename}")"
while [[ "${safeOutput}" =~ "Error" ]]
do
errcounter=$((errcounter + 1))
msg "Error during upload, retrying; please wait ..."
safeOutput="$(safe files put "${filename}")"
done
msg "${safeOutput}"
msg "Error Ratio:${errcounter}/${counter} (errors per total uploads) -- total bytes uploaded:${TBU}"
rm "${filename}"
verify_put "$filename" "$checksum" "${safeOutput}" &
sleep "$(shuf -i 1-10 -n 1)s"
done
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment