run-test.sh 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. #
  38. # Run Test.
  39. #
  40. cargo run -- --composite-pid $composite_pid --basic-2-pid $basic_2_pid
  41. }
  42. cleanup() {
  43. pkill -P $$ || true
  44. wait || true
  45. }
  46. trap_add() {
  47. trap_add_cmd=$1; shift || fatal "${FUNCNAME} usage error"
  48. for trap_add_name in "$@"; do
  49. trap -- "$(
  50. extract_trap_cmd() { printf '%s\n' "${3:-}"; }
  51. eval "extract_trap_cmd $(trap -p "${trap_add_name}")"
  52. printf '%s\n' "${trap_add_cmd}"
  53. )" "${trap_add_name}" \
  54. || fatal "unable to add to trap ${trap_add_name}"
  55. done
  56. }
  57. declare -f -t trap_add
  58. trap_add 'cleanup' EXIT
  59. main