run-test.sh 2.2 KB

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