test.sh 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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 ganache instance that we started (if we started one and if it's still running).
  8. if [ -n "$ganache_pid" ] && ps -p $ganache_pid > /dev/null; then
  9. kill -9 $ganache_pid
  10. fi
  11. }
  12. if [ "$SOLIDITY_COVERAGE" = true ]; then
  13. ganache_port=8555
  14. else
  15. ganache_port=8545
  16. fi
  17. ganache_running() {
  18. nc -z localhost "$ganache_port"
  19. }
  20. start_ganache() {
  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 "$ganache_port" "${accounts[@]}" > /dev/null &
  36. else
  37. node_modules/.bin/ganache-cli --gasLimit 0xfffffffffff "${accounts[@]}" > /dev/null &
  38. fi
  39. ganache_pid=$!
  40. }
  41. if ganache_running; then
  42. echo "Using existing ganache instance"
  43. else
  44. echo "Starting our own ganache instance"
  45. start_ganache
  46. fi
  47. if [ "$SOLC_NIGHTLY" = true ]; then
  48. echo "Downloading solc nightly"
  49. wget -q https://raw.githubusercontent.com/ethereum/solc-bin/gh-pages/bin/soljson-nightly.js -O /tmp/soljson.js && find . -name soljson.js -exec cp /tmp/soljson.js {} \;
  50. fi
  51. if [ "$SOLIDITY_COVERAGE" = true ]; then
  52. node_modules/.bin/solidity-coverage
  53. if [ "$CONTINUOUS_INTEGRATION" = true ]; then
  54. cat coverage/lcov.info | node_modules/.bin/coveralls
  55. fi
  56. else
  57. node_modules/.bin/truffle test "$@"
  58. fi