github.com/tri-stone/burrow@v0.25.0/tests/test_runner.sh (about)

     1  #!/usr/bin/env bash
     2  # ----------------------------------------------------------
     3  # PURPOSE
     4  
     5  # This is the test runner for burrow integration tests.
     6  # It is responsible for starting up a single node burrow test chain and tearing it down afterwards.
     7  
     8  # ----------------------------------------------------------
     9  # REQUIREMENTS
    10  
    11  # * GNU parallel
    12  # * jq
    13  
    14  # ----------------------------------------------------------
    15  # USAGE
    16  # source test_runner.sh
    17  
    18  script_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
    19  
    20  export burrow_bin=${burrow_bin:-burrow}
    21  export solc_bin=${solc_bin:-solc}
    22  
    23  # If false we will not try to start Burrow and expect them to be running
    24  export boot=${boot:-true}
    25  export debug=${debug:-false}
    26  export clean=${clean:-true}
    27  
    28  export failures="not supplied by test"
    29  
    30  export test_exit=0
    31  
    32  if [[ "$debug" = true ]]; then
    33      set -o xtrace
    34  fi
    35  
    36  
    37  # Note: do not set -e in order to capture exit correctly in mocha
    38  # ----------------------------------------------------------
    39  # Constants
    40  
    41  # Ports etc must match those in burrow.toml
    42  export BURROW_GRPC_PORT=20997
    43  export BURROW_HOST=127.0.0.1
    44  
    45  
    46  export chain_dir="$script_dir/chain"
    47  export burrow_root="$chain_dir/.burrow"
    48  
    49  # Temporary logs
    50  export burrow_log="$chain_dir/burrow.log"
    51  #
    52  # ----------------------------------------------------------
    53  
    54  # ---------------------------------------------------------------------------
    55  # Needed functionality
    56  
    57  pubkey_of() {
    58      jq -r ".Accounts | map(select(.Name == \"$1\"))[0].PublicKey.PublicKey" "$chain_dir/genesis.json"
    59  }
    60  
    61  address_of() {
    62      jq -r ".Accounts | map(select(.Name == \"$1\"))[0].Address" "$chain_dir/genesis.json"
    63  }
    64  
    65  test_setup(){
    66    echo "Setting up..."
    67    cd "$script_dir"
    68  
    69    echo
    70    echo "Using binaries:"
    71    echo "  $(type ${solc_bin}) (version: $(${solc_bin} --version))"
    72    echo "  $(type ${burrow_bin}) (version: $(${burrow_bin} --version))"
    73    echo
    74    # start test chain
    75    if [[ "$boot" = true ]]; then
    76      echo "Starting Burrow using GRPC address: $BURROW_HOST:$BURROW_GRPC_PORT..."
    77      echo
    78      rm -rf ${burrow_root}
    79      pushd "$chain_dir"
    80      ${burrow_bin} start -v0 2> "$burrow_log"&
    81      burrow_pid=$!
    82      popd
    83    else
    84      echo "Not booting Burrow, but expecting Burrow to be running with tm RPC on port $BURROW_GRPC_PORT"
    85    fi
    86  
    87    export key1_addr=$(address_of "Full_0")
    88    export key2_addr=$(address_of "Participant_0")
    89    export key1=Full_0
    90    export key2=Participant_0
    91    export key2_pub=$(pubkey_of "Participant_0")
    92  
    93    echo -e "Default Key =>\t\t\t\t$key1_addr"
    94    echo -e "Backup Key =>\t\t\t\t$key2_addr"
    95    sleep 4 # boot time
    96  
    97    echo "Setup complete"
    98    echo ""
    99  }
   100  
   101  test_teardown(){
   102    echo "Cleaning up..."
   103    if [[ "$boot" = true ]]; then
   104      echo "Killing burrow with PID $burrow_pid"
   105      kill ${burrow_pid} 2> /dev/null
   106      echo "Waiting for burrow to shutdown..."
   107      wait ${burrow_pid} 2> /dev/null
   108      rm -rf "$burrow_root"
   109    fi
   110    echo ""
   111    if [[ "$test_exit" -eq 0 ]]
   112    then
   113      [[ "$boot" = true ]] && rm -f "$burrow_log"
   114      echo "Tests complete! Tests are Green. :)"
   115    else
   116      echo "Tests complete. Tests are Red. :("
   117      echo "Failures in:"
   118      for failure in "${failures[@]}"
   119      do
   120        echo "$failure"
   121      done
   122     fi
   123    exit ${test_exit}
   124  }
   125