github.com/hyperledger/burrow@v0.34.5-0.20220512172541-77f09336001d/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  export solang_bin=${solang_bin:-solang}
    23  
    24  # If false we will not try to start Burrow and expect them to be running
    25  export boot=${boot:-true}
    26  export debug=${debug:-false}
    27  export clean=${clean:-true}
    28  
    29  export test_exit=0
    30  
    31  if [[ "$debug" = true ]]; then
    32      set -o xtrace
    33  fi
    34  
    35  
    36  # Note: do not set -e in order to capture exit correctly in mocha
    37  # ----------------------------------------------------------
    38  # Constants
    39  
    40  # Ports etc must match those in burrow.toml
    41  export BURROW_HOST=127.0.0.1
    42  export BURROW_GRPC_PORT=20123
    43  
    44  
    45  export chain_dir="$script_dir/chain"
    46  export burrow_root="$chain_dir/.burrow"
    47  
    48  # Temporary logs
    49  export burrow_log="$chain_dir/burrow.log"
    50  #
    51  # ----------------------------------------------------------
    52  
    53  # ---------------------------------------------------------------------------
    54  # Needed functionality
    55  
    56  pubkey_of() {
    57      jq -r ".Accounts | map(select(.Name == \"$1\"))[0].PublicKey.PublicKey" "$chain_dir/genesis.json"
    58  }
    59  
    60  address_of() {
    61      jq -r ".Accounts | map(select(.Name == \"$1\"))[0].Address" "$chain_dir/genesis.json"
    62  }
    63  
    64  test_setup(){
    65    echo "Setting up..."
    66    cd "$script_dir"
    67  
    68    echo
    69    echo "Using binaries:"
    70    echo "  $(type ${solc_bin}) (version: $(${solc_bin} --version))"
    71    echo "  $(type ${solang_bin}) (version: $(${solang_bin} --version))"
    72    echo "  $(type ${burrow_bin}) (version: $(${burrow_bin} --version))"
    73    echo
    74    # start test chain
    75    BURROW_ADDRESS="$BURROW_HOST:$BURROW_GRPC_PORT"
    76    if [[ "$boot" = true ]]; then
    77      echo "Starting Burrow using GRPC address: $BURROW_ADDRESS..."
    78      echo
    79      rm -rf ${burrow_root}
    80      pushd "$chain_dir"
    81      ${burrow_bin} start --index 0 --grpc-address $BURROW_ADDRESS 2> "$burrow_log"&
    82      burrow_pid=$!
    83      popd
    84    else
    85      echo "Not booting Burrow, but expecting Burrow to be running with tm RPC on port $BURROW_GRPC_PORT"
    86    fi
    87  
    88    export key1_addr=$(address_of "Full_0")
    89    export key2_addr=$(address_of "Participant_0")
    90    export key1=Full_0
    91    export key2=Participant_0
    92    export key2_pub=$(pubkey_of "Participant_0")
    93  
    94    echo -e "Default Key =>\t\t\t\t$key1_addr"
    95    echo -e "Backup Key =>\t\t\t\t$key2_addr"
    96    sleep 4 # boot time
    97  
    98    echo "Setup complete"
    99    echo ""
   100  }
   101  
   102  test_teardown(){
   103    echo "Cleaning up..."
   104    if [[ "$boot" = true ]]; then
   105      echo "Killing burrow with PID $burrow_pid"
   106      kill ${burrow_pid} 2> /dev/null
   107      echo "Waiting for burrow to shutdown..."
   108      wait ${burrow_pid} 2> /dev/null
   109      rm -rf "$burrow_root"
   110    fi
   111    echo ""
   112    if [[ "$test_exit" -eq 0 ]]
   113    then
   114      [[ "$boot" = true ]] && rm -f "$burrow_log"
   115      echo "Tests complete! Tests are Green. :)"
   116    else
   117      echo "Tests complete. Tests are Red. :("
   118     fi
   119    exit ${test_exit}
   120  }
   121