fake_itests.sh 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. #!/usr/bin/env bash
  2. # Function to perform cleanup
  3. cleanup() {
  4. echo "Cleaning up..."
  5. echo "Killing the cdk mintd"
  6. kill -2 $cdk_mintd_pid
  7. wait $cdk_mintd_pid
  8. echo "Mint binary terminated"
  9. # Remove the temporary directory
  10. rm -rf "$cdk_itests"
  11. echo "Temp directory removed: $cdk_itests"
  12. unset cdk_itests
  13. unset cdk_itests_mint_addr
  14. unset cdk_itests_mint_port
  15. }
  16. # Set up trap to call cleanup on script exit
  17. trap cleanup EXIT
  18. # Create a temporary directory
  19. export cdk_itests=$(mktemp -d)
  20. export cdk_itests_mint_addr="127.0.0.1";
  21. export cdk_itests_mint_port=8086;
  22. # Check if the temporary directory was created successfully
  23. if [[ ! -d "$cdk_itests" ]]; then
  24. echo "Failed to create temp directory"
  25. exit 1
  26. fi
  27. echo "Temp directory created: $cdk_itests"
  28. export MINT_DATABASE="$1";
  29. cargo build -p cdk-integration-tests
  30. export CDK_MINTD_URL="http://$cdk_itests_mint_addr:$cdk_itests_mint_port";
  31. export CDK_MINTD_WORK_DIR="$cdk_itests";
  32. export CDK_MINTD_LISTEN_HOST=$cdk_itests_mint_addr;
  33. export CDK_MINTD_LISTEN_PORT=$cdk_itests_mint_port;
  34. export CDK_MINTD_LN_BACKEND="fakewallet";
  35. export CDK_MINTD_FAKE_WALLET_SUPPORTED_UNITS="sat,usd";
  36. export CDK_MINTD_MNEMONIC="eye survey guilt napkin crystal cup whisper salt luggage manage unveil loyal";
  37. export CDK_MINTD_FAKE_WALLET_FEE_PERCENT="0";
  38. export CDK_MINTD_FAKE_WALLET_RESERVE_FEE_MIN="1";
  39. export CDK_MINTD_DATABASE=$MINT_DATABASE;
  40. echo "Starting fake mintd";
  41. cargo run --bin cdk-mintd &
  42. cdk_mintd_pid=$!
  43. URL="http://$cdk_itests_mint_addr:$cdk_itests_mint_port/v1/info"
  44. TIMEOUT=100
  45. START_TIME=$(date +%s)
  46. # Loop until the endpoint returns a 200 OK status or timeout is reached
  47. while true; do
  48. # Get the current time
  49. CURRENT_TIME=$(date +%s)
  50. # Calculate the elapsed time
  51. ELAPSED_TIME=$((CURRENT_TIME - START_TIME))
  52. # Check if the elapsed time exceeds the timeout
  53. if [ $ELAPSED_TIME -ge $TIMEOUT ]; then
  54. echo "Timeout of $TIMEOUT seconds reached. Exiting..."
  55. exit 1
  56. fi
  57. # Make a request to the endpoint and capture the HTTP status code
  58. HTTP_STATUS=$(curl -o /dev/null -s -w "%{http_code}" $URL)
  59. # Check if the HTTP status is 200 OK
  60. if [ "$HTTP_STATUS" -eq 200 ]; then
  61. echo "Received 200 OK from $URL"
  62. break
  63. else
  64. echo "Waiting for 200 OK response, current status: $HTTP_STATUS"
  65. sleep 2 # Wait for 2 seconds before retrying
  66. fi
  67. done
  68. # Run cargo test
  69. cargo test -p cdk-integration-tests --test fake_wallet
  70. # cargo test -p cdk-integration-tests --test mint
  71. # Capture the exit status of cargo test
  72. test_status=$?
  73. # Exit with the status of the testexit $test_status
  74. exit $test_status