test.sh 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #!/usr/bin/env bash
  2. # Exit script as soon as a command fails.
  3. set -o errexit
  4. # Executes cleanup function at script exit.
  5. trap cleanup EXIT
  6. cleanup() {
  7. # Kill the testrpc instance that we started (if we started one and if it's still running).
  8. if [ -n "$testrpc_pid" ] && ps -p $testrpc_pid > /dev/null; then
  9. kill -9 $testrpc_pid
  10. fi
  11. }
  12. if [ "$SOLIDITY_COVERAGE" = true ]; then
  13. testrpc_port=8555
  14. else
  15. testrpc_port=8545
  16. fi
  17. testrpc_running() {
  18. nc -z localhost "$testrpc_port"
  19. }
  20. start_testrpc() {
  21. # We define 10 accounts with balance 1M ether, needed for high-value tests.
  22. local accounts=(
  23. --account="0x2bdd21761a483f71054e14f5b827213567971c676928d9a1808cbfa4b7501200,1000000000000000000000000"
  24. --account="0x2bdd21761a483f71054e14f5b827213567971c676928d9a1808cbfa4b7501201,1000000000000000000000000"
  25. --account="0x2bdd21761a483f71054e14f5b827213567971c676928d9a1808cbfa4b7501202,1000000000000000000000000"
  26. --account="0x2bdd21761a483f71054e14f5b827213567971c676928d9a1808cbfa4b7501203,1000000000000000000000000"
  27. --account="0x2bdd21761a483f71054e14f5b827213567971c676928d9a1808cbfa4b7501204,1000000000000000000000000"
  28. --account="0x2bdd21761a483f71054e14f5b827213567971c676928d9a1808cbfa4b7501205,1000000000000000000000000"
  29. --account="0x2bdd21761a483f71054e14f5b827213567971c676928d9a1808cbfa4b7501206,1000000000000000000000000"
  30. --account="0x2bdd21761a483f71054e14f5b827213567971c676928d9a1808cbfa4b7501207,1000000000000000000000000"
  31. --account="0x2bdd21761a483f71054e14f5b827213567971c676928d9a1808cbfa4b7501208,1000000000000000000000000"
  32. --account="0x2bdd21761a483f71054e14f5b827213567971c676928d9a1808cbfa4b7501209,1000000000000000000000000"
  33. )
  34. if [ "$SOLIDITY_COVERAGE" = true ]; then
  35. node_modules/.bin/testrpc-sc --gasLimit 0xfffffffffff --port "$testrpc_port" "${accounts[@]}" > /dev/null &
  36. else
  37. node_modules/.bin/testrpc --gasLimit 0xfffffffffff "${accounts[@]}" > /dev/null &
  38. fi
  39. testrpc_pid=$!
  40. }
  41. if testrpc_running; then
  42. echo "Using existing testrpc instance"
  43. else
  44. echo "Starting our own testrpc instance"
  45. start_testrpc
  46. fi
  47. if [ "$SOLIDITY_COVERAGE" = true ]; then
  48. node_modules/.bin/solidity-coverage
  49. if [ "$CONTINUOUS_INTEGRATION" = true ]; then
  50. cat coverage/lcov.info | node_modules/.bin/coveralls
  51. fi
  52. else
  53. node_modules/.bin/truffle test "$@"
  54. fi