test.sh 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. local accounts=(
  22. # 10 accounts with balance 1M ether, needed for high-value tests.
  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. # 3 accounts to be used for GSN matters.
  34. --account="0x956b91cb2344d7863ea89e6945b753ca32f6d74bb97a59e59e04903ded14ad00,1000000000000000000000000"
  35. --account="0x956b91cb2344d7863ea89e6945b753ca32f6d74bb97a59e59e04903ded14ad01,1000000000000000000000000"
  36. --account="0x956b91cb2344d7863ea89e6945b753ca32f6d74bb97a59e59e04903ded14ad02,1000000000000000000000000"
  37. )
  38. if [ "$SOLIDITY_COVERAGE" = true ]; then
  39. npx ganache-cli-coverage --emitFreeLogs true --allowUnlimitedContractSize true --gasLimit 0xfffffffffffff --port "$ganache_port" "${accounts[@]}" > /dev/null &
  40. else
  41. npx ganache-cli --gasLimit 0xfffffffffff --port "$ganache_port" "${accounts[@]}" > /dev/null &
  42. fi
  43. ganache_pid=$!
  44. echo "Waiting for ganache to launch on port "$ganache_port"..."
  45. while ! ganache_running; do
  46. sleep 0.1 # wait for 1/10 of the second before check again
  47. done
  48. echo "Ganache launched!"
  49. }
  50. setup_relayhub() {
  51. npx oz-gsn deploy-relay-hub \
  52. --ethereumNodeURL "http://localhost:$ganache_port" \
  53. --from "0xbb49ad04422f9fa6a217f3ed82261b942f6981f7"
  54. }
  55. if ganache_running; then
  56. echo "Using existing ganache instance"
  57. else
  58. echo "Starting our own ganache instance"
  59. start_ganache
  60. fi
  61. npx truffle version
  62. setup_relayhub
  63. if [ "$SOLIDITY_COVERAGE" = true ]; then
  64. npx solidity-coverage
  65. else
  66. npx truffle test "$@"
  67. fi