run-test.sh 2.1 KB

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