verify_test.sh 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #!/bin/bash
  2. # This test script verifies that `avm` correctly installs `solana-verify`
  3. # and that `anchor verify` can successfully verify a known public program.
  4. # Exit on first error
  5. set -e
  6. # --- Helper for timing and logging ---
  7. function step_start {
  8. echo ""
  9. echo "============================================================"
  10. echo "🚀 Starting Step: $1"
  11. echo "============================================================"
  12. STEP_START_TIME=$(date +%s)
  13. }
  14. function step_end {
  15. local end_time=$(date +%s)
  16. local duration=$((end_time - STEP_START_TIME))
  17. echo "✅ Step completed in ${duration}s."
  18. }
  19. # --- Cleanup ---
  20. trap 'echo ""; echo "🧹 Cleaning up..."' INT TERM EXIT
  21. # --- Dependency Checks ---
  22. step_start "Checking dependencies"
  23. # Check for docker
  24. if ! command -v docker &> /dev/null; then
  25. echo "❌ Docker is not installed. Please install it to run this test."
  26. exit 1
  27. fi
  28. if ! docker info > /dev/null 2>&1; then
  29. echo "❌ Docker is not running. Please start Docker and run the test again."
  30. exit 1
  31. fi
  32. step_end
  33. # --- Build and Install Anchor from Local Source ---
  34. step_start "Building local avm"
  35. (cd ../.. && cargo build --package avm)
  36. step_end
  37. step_start "Installing local anchor-cli and solana-verify via avm"
  38. ../../target/debug/avm install --path ../.. --force
  39. step_end
  40. # --- Verify `solana-verify` Installation ---
  41. step_start "Checking for solana-verify installation"
  42. if ! [ -x ~/.avm/bin/solana-verify ]; then
  43. echo "❌ solana-verify was not found in ~/.avm/bin."
  44. exit 1
  45. fi
  46. echo "-> solana-verify found successfully."
  47. step_end
  48. # --- Verify a Known Public Program ---
  49. step_start "Verifying a known public program (Phoenix on Mainnet)"
  50. OUTPUT=$(../../target/debug/anchor verify PhoeNiXZ8ByJGLkxNfZRnkUfjvmuYqLR89jjFHGqdXY \
  51. --repo-url https://github.com/Ellipsis-Labs/phoenix-v1 \
  52. -- \
  53. --skip-prompt \
  54. --url https://api.mainnet-beta.solana.com 2>&1) || true
  55. step_end
  56. # --- Check Results ---
  57. step_start "Checking verification results"
  58. if echo "$OUTPUT" | grep -q "Program hash matches ✅"; then
  59. # This is the expected outcome in a test environment without a funded mainnet wallet.
  60. # ⚠️ CAUTION: if you have a mainnet wallet with funds, and configured the CLI to use it, this will fail. And you will lose money.
  61. if echo "$OUTPUT" | grep -q "Failed to send verification transaction to the blockchain"; then
  62. echo "✅ Test successful: Verification passed and transaction failed as expected."
  63. else
  64. echo "❌ Test failed: Verification passed, but an unexpected error occurred."
  65. echo "$OUTPUT"
  66. exit 1
  67. fi
  68. else
  69. echo "❌ Test failed: Verification did not pass."
  70. echo "$OUTPUT"
  71. exit 1
  72. fi
  73. step_end
  74. echo ""
  75. echo "============================================================"
  76. echo "🎉 All tests passed successfully! 🎉"
  77. echo "============================================================"