run-test.sh 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #!/bin/bash
  2. ################################################################################
  3. #
  4. # A script to run the example as an integration test. It starts up a localnet
  5. # and executes the current directory's rust binary.
  6. #
  7. # Usage:
  8. #
  9. # ./run.sh
  10. #
  11. # Run this script from within the `example/` directory in which it is located.
  12. # The anchor cli must be installed.
  13. #
  14. # cargo install --git https://github.com/project-serum/anchor anchor-cli --locked
  15. #
  16. ################################################################################
  17. set -euox pipefail
  18. main() {
  19. #
  20. # Bootup validator.
  21. #
  22. solana-test-validator > test-validator.log &
  23. sleep 5
  24. #
  25. # Deploy programs.
  26. #
  27. pushd ../../examples/composite/
  28. anchor build
  29. anchor deploy
  30. local composite_pid=$(cat target/idl/composite.json | jq -r .metadata.address)
  31. popd
  32. pushd ../../examples/tutorial/basic-2/
  33. anchor build
  34. anchor deploy
  35. local basic_2_pid=$(cat target/idl/basic_2.json | jq -r .metadata.address)
  36. popd
  37. pushd ../../examples/events
  38. anchor build
  39. anchor deploy
  40. local events_pid=$(cat target/idl/events.json | jq -r .metadata.address)
  41. popd
  42. #
  43. # Run Test.
  44. #
  45. cargo run -- --composite-pid $composite_pid --basic-2-pid $basic_2_pid --events-pid $events_pid
  46. }
  47. cleanup() {
  48. pkill -P $$ || true
  49. wait || true
  50. }
  51. trap_add() {
  52. trap_add_cmd=$1; shift || fatal "${FUNCNAME} usage error"
  53. for trap_add_name in "$@"; do
  54. trap -- "$(
  55. extract_trap_cmd() { printf '%s\n' "${3:-}"; }
  56. eval "extract_trap_cmd $(trap -p "${trap_add_name}")"
  57. printf '%s\n' "${trap_add_cmd}"
  58. )" "${trap_add_name}" \
  59. || fatal "unable to add to trap ${trap_add_name}"
  60. done
  61. }
  62. declare -f -t trap_add
  63. trap_add 'cleanup' EXIT
  64. main