test.sh 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. testrpc() {
  21. if [ "$SOLIDITY_COVERAGE" = true ]; then
  22. node_modules/.bin/testrpc-sc --gasLimit 0xfffffffffff --port "$testrpc_port" "$@"
  23. else
  24. node_modules/.bin/testrpc "$@"
  25. fi
  26. }
  27. if testrpc_running; then
  28. echo "Using existing testrpc instance"
  29. else
  30. echo "Starting our own testrpc instance"
  31. # We define 10 accounts with balance 1M ether, needed for high-value tests.
  32. testrpc \
  33. --account="0x2bdd21761a483f71054e14f5b827213567971c676928d9a1808cbfa4b7501200,1000000000000000000000000" \
  34. --account="0x2bdd21761a483f71054e14f5b827213567971c676928d9a1808cbfa4b7501201,1000000000000000000000000" \
  35. --account="0x2bdd21761a483f71054e14f5b827213567971c676928d9a1808cbfa4b7501202,1000000000000000000000000" \
  36. --account="0x2bdd21761a483f71054e14f5b827213567971c676928d9a1808cbfa4b7501203,1000000000000000000000000" \
  37. --account="0x2bdd21761a483f71054e14f5b827213567971c676928d9a1808cbfa4b7501204,1000000000000000000000000" \
  38. --account="0x2bdd21761a483f71054e14f5b827213567971c676928d9a1808cbfa4b7501205,1000000000000000000000000" \
  39. --account="0x2bdd21761a483f71054e14f5b827213567971c676928d9a1808cbfa4b7501206,1000000000000000000000000" \
  40. --account="0x2bdd21761a483f71054e14f5b827213567971c676928d9a1808cbfa4b7501207,1000000000000000000000000" \
  41. --account="0x2bdd21761a483f71054e14f5b827213567971c676928d9a1808cbfa4b7501208,1000000000000000000000000" \
  42. --account="0x2bdd21761a483f71054e14f5b827213567971c676928d9a1808cbfa4b7501209,1000000000000000000000000" \
  43. > /dev/null &
  44. testrpc_pid=$!
  45. fi
  46. if [ "$SOLIDITY_COVERAGE" = true ]; then
  47. node_modules/.bin/solidity-coverage
  48. if [ "$CONTINUOUS_INTEGRATION" = true ]; then
  49. cat coverage/lcov.info | node_modules/.bin/coveralls
  50. fi
  51. else
  52. node_modules/.bin/truffle test "$@"
  53. fi