test.sh 3.0 KB

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