#!/usr/bin/env bash

# thanks to open-zeppelin folks!

# Exit script as soon as a command fails.
# set -o errexit
# 
# # Executes cleanup function at script exit.
# trap cleanup EXIT
# 
# cleanup() {
#     # Kill the ganache instance that we started (if we started one and if it's still running).
#     if [ -n "$ganache_pid" ] && ps -p $ganache_pid > /dev/null; then
#         kill -9 $ganache_pid
#     fi
# }
# 
# ganache_port=7545
# 
# ganache_running() {
#     nc -z localhost "$ganache_port"
# }
# 
# start_ganache() {
#     npx ganache-cli --gasLimit 0xfffffffffff --port "$ganache_port" > /dev/null &
#     ganache_pid=$!
#     echo "Waiting for ganache to launch on port "$ganache_port"..."
#     while ! ganache_running; do
#         sleep 0.1 # wait for 1/10 of the second before check again
#     done
#     echo "Ganache launched!"
# }
# 
# npx truffle version
# 
# if ganache_running; then
#     echo "Killing existing ganache instance"
#     ganache_pid=$(lsof -t -i:$ganache_port)
#     cleanup
# fi
# 
# echo "Starting our own ganache instance"
# start_ganache
# 
# npx truffle test "$@"
# 