run-test.sh 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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/tutorial/basic-4/
  38. anchor build
  39. anchor deploy
  40. local basic_4_pid=$(cat target/idl/basic_4.json | jq -r .metadata.address)
  41. popd
  42. pushd ../../examples/events
  43. anchor build
  44. anchor deploy
  45. local events_pid=$(cat target/idl/events.json | jq -r .metadata.address)
  46. popd
  47. #
  48. # Run Test.
  49. #
  50. cargo run -- --composite-pid $composite_pid --basic-2-pid $basic_2_pid --basic-4-pid $basic_4_pid --events-pid $events_pid
  51. }
  52. cleanup() {
  53. pkill -P $$ || true
  54. wait || true
  55. }
  56. trap_add() {
  57. trap_add_cmd=$1; shift || fatal "${FUNCNAME} usage error"
  58. for trap_add_name in "$@"; do
  59. trap -- "$(
  60. extract_trap_cmd() { printf '%s\n' "${3:-}"; }
  61. eval "extract_trap_cmd $(trap -p "${trap_add_name}")"
  62. printf '%s\n' "${trap_add_cmd}"
  63. )" "${trap_add_name}" \
  64. || fatal "unable to add to trap ${trap_add_name}"
  65. done
  66. }
  67. declare -f -t trap_add
  68. trap_add 'cleanup' EXIT
  69. main