run-test.sh 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. # Build programs.
  21. #
  22. local composite_pid="EHthziFziNoac9LBGxEaVN47Y3uUiRoXvqAiR6oes4iU"
  23. local basic_2_pid="Fg6PaFpoGXkYsidMpWTK6W2BeZ7FEfcYkg476zPFsLnS"
  24. local basic_4_pid="CwrqeMj2U8tFr1Rhkgwc84tpAsqbt9pTt2a4taoTADPr"
  25. local events_pid="2dhGsWUzy5YKUsjZdLHLmkNpUDAXkNa9MYWsPc4Ziqzy"
  26. #
  27. # Bootup validator.
  28. #
  29. solana-test-validator \
  30. --bpf-program $composite_pid ../../tests/composite/target/deploy/composite.so \
  31. --bpf-program $basic_2_pid ../../examples/tutorial/basic-2/target/deploy/basic_2.so \
  32. --bpf-program $basic_4_pid ../../examples/tutorial/basic-4/target/deploy/basic_4.so \
  33. --bpf-program $events_pid ../../tests/events/target/deploy/events.so \
  34. > test-validator.log &
  35. sleep 5
  36. #
  37. # Run Test.
  38. #
  39. cargo run -- --composite-pid $composite_pid --basic-2-pid $basic_2_pid --basic-4-pid $basic_4_pid --events-pid $events_pid
  40. }
  41. cleanup() {
  42. pkill -P $$ || true
  43. wait || true
  44. }
  45. trap_add() {
  46. trap_add_cmd=$1; shift || fatal "${FUNCNAME} usage error"
  47. for trap_add_name in "$@"; do
  48. trap -- "$(
  49. extract_trap_cmd() { printf '%s\n' "${3:-}"; }
  50. eval "extract_trap_cmd $(trap -p "${trap_add_name}")"
  51. printf '%s\n' "${trap_add_cmd}"
  52. )" "${trap_add_name}" \
  53. || fatal "unable to add to trap ${trap_add_name}"
  54. done
  55. }
  56. declare -f -t trap_add
  57. trap_add 'cleanup' EXIT
  58. main