test.sh 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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/ganache-cli-coverage --emitFreeLogs true --allowUnlimitedContractSize true --gasLimit 0xfffffffffff --port "$ganache_port" "${accounts[@]}" > /dev/null &
  36. else
  37. node_modules/.bin/ganache-cli --gasLimit 0xfffffffffff --port "$ganache_port" "${accounts[@]}" > /dev/null &
  38. fi
  39. ganache_pid=$!
  40. echo "Waiting for ganache to launch on port "$ganache_port"..."
  41. while ! ganache_running; do
  42. sleep 0.1 # wait for 1/10 of the second before check again
  43. done
  44. echo "Ganache launched!"
  45. }
  46. if ganache_running; then
  47. echo "Using existing ganache instance"
  48. else
  49. echo "Starting our own ganache instance"
  50. start_ganache
  51. fi
  52. if [ "$SOLC_NIGHTLY" = true ]; then
  53. echo "Downloading solc nightly"
  54. 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 {} \;
  55. fi
  56. truffle version
  57. if [ "$SOLIDITY_COVERAGE" = true ]; then
  58. node_modules/.bin/solidity-coverage
  59. if [ "$CONTINUOUS_INTEGRATION" = true ]; then
  60. cat coverage/lcov.info | node_modules/.bin/coveralls
  61. fi
  62. else
  63. node_modules/.bin/truffle test "$@"
  64. fi