itests.sh 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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 "Killing the cdk lnd mintd"
  9. kill -2 $cdk_mintd_lnd_pid
  10. wait $cdk_mintd_lnd_pid
  11. echo "Killing the cdk regtest"
  12. kill -2 $cdk_regtest_pid
  13. wait $cdk_regtest_pid
  14. echo "Mint binary terminated"
  15. # Remove the temporary directory
  16. rm -rf "$cdk_itests"
  17. echo "Temp directory removed: $cdk_itests"
  18. unset cdk_itests
  19. unset cdk_itests_mint_addr
  20. unset cdk_itests_mint_port
  21. }
  22. # Set up trap to call cleanup on script exit
  23. trap cleanup EXIT
  24. # Create a temporary directory
  25. export cdk_itests=$(mktemp -d)
  26. export cdk_itests_mint_addr="127.0.0.1";
  27. export cdk_itests_mint_port_0=8085;
  28. export cdk_itests_mint_port_1=8087;
  29. # Check if the temporary directory was created successfully
  30. if [[ ! -d "$cdk_itests" ]]; then
  31. echo "Failed to create temp directory"
  32. exit 1
  33. fi
  34. echo "Temp directory created: $cdk_itests"
  35. export MINT_DATABASE="$1";
  36. cargo build -p cdk-integration-tests
  37. cargo run --bin start_regtest &
  38. cdk_regtest_pid=$!
  39. mkfifo "$cdk_itests/progress_pipe"
  40. rm -f "$cdk_itests/signal_received" # Ensure clean state
  41. # Start reading from pipe in background
  42. (while read line; do
  43. case "$line" in
  44. "checkpoint1")
  45. echo "Reached first checkpoint"
  46. touch "$cdk_itests/signal_received"
  47. exit 0
  48. ;;
  49. esac
  50. done < "$cdk_itests/progress_pipe") &
  51. # Wait for up to 120 seconds
  52. for ((i=0; i<120; i++)); do
  53. if [ -f "$cdk_itests/signal_received" ]; then
  54. echo "break signal received"
  55. break
  56. fi
  57. sleep 1
  58. done
  59. echo "Regtest set up continuing"
  60. echo "Starting regtest mint"
  61. # cargo run --bin regtest_mint &
  62. export CDK_MINTD_CLN_RPC_PATH="$cdk_itests/cln/one/regtest/lightning-rpc";
  63. export CDK_MINTD_URL="http://$cdk_itests_mint_addr:$cdk_itests_mint_port_0";
  64. export CDK_MINTD_WORK_DIR="$cdk_itests";
  65. export CDK_MINTD_LISTEN_HOST=$cdk_itests_mint_addr;
  66. export CDK_MINTD_LISTEN_PORT=$cdk_itests_mint_port_0;
  67. export CDK_MINTD_LN_BACKEND="cln";
  68. export CDK_MINTD_MNEMONIC="eye survey guilt napkin crystal cup whisper salt luggage manage unveil loyal";
  69. export CDK_MINTD_DATABASE=$MINT_DATABASE;
  70. export RUST_BACKTRACE=1
  71. echo "Starting cln mintd";
  72. cargo run --bin cdk-mintd &
  73. cdk_mintd_pid=$!
  74. echo $cdk_itests
  75. URL="http://$cdk_itests_mint_addr:$cdk_itests_mint_port_0/v1/info"
  76. TIMEOUT=100
  77. START_TIME=$(date +%s)
  78. # Loop until the endpoint returns a 200 OK status or timeout is reached
  79. while true; do
  80. # Get the current time
  81. CURRENT_TIME=$(date +%s)
  82. # Calculate the elapsed time
  83. ELAPSED_TIME=$((CURRENT_TIME - START_TIME))
  84. # Check if the elapsed time exceeds the timeout
  85. if [ $ELAPSED_TIME -ge $TIMEOUT ]; then
  86. echo "Timeout of $TIMEOUT seconds reached. Exiting..."
  87. exit 1
  88. fi
  89. # Make a request to the endpoint and capture the HTTP status code
  90. HTTP_STATUS=$(curl -o /dev/null -s -w "%{http_code}" $URL)
  91. # Check if the HTTP status is 200 OK
  92. if [ "$HTTP_STATUS" -eq 200 ]; then
  93. echo "Received 200 OK from $URL"
  94. break
  95. else
  96. echo "Waiting for 200 OK response, current status: $HTTP_STATUS"
  97. sleep 2 # Wait for 2 seconds before retrying
  98. fi
  99. done
  100. export CDK_MINTD_LND_ADDRESS="https://localhost:10010";
  101. export CDK_MINTD_LND_CERT_FILE="$cdk_itests/lnd/two/tls.cert";
  102. export CDK_MINTD_LND_MACAROON_FILE="$cdk_itests/lnd/two/data/chain/bitcoin/regtest/admin.macaroon";
  103. export CDK_MINTD_URL="http://$cdk_itests_mint_addr:$cdk_itests_mint_port_1";
  104. mkdir -p "$cdk_itests/lnd_mint"
  105. export CDK_MINTD_WORK_DIR="$cdk_itests/lnd_mint";
  106. export CDK_MINTD_LISTEN_HOST=$cdk_itests_mint_addr;
  107. export CDK_MINTD_LISTEN_PORT=$cdk_itests_mint_port_1;
  108. export CDK_MINTD_LN_BACKEND="lnd";
  109. export CDK_MINTD_MNEMONIC="eye survey guilt napkin crystal cup whisper salt luggage manage unveil loyal";
  110. echo "Starting lnd mintd";
  111. cargo run --bin cdk-mintd &
  112. cdk_mintd_lnd_pid=$!
  113. URL="http://$cdk_itests_mint_addr:$cdk_itests_mint_port_1/v1/info"
  114. TIMEOUT=100
  115. START_TIME=$(date +%s)
  116. # Loop until the endpoint returns a 200 OK status or timeout is reached
  117. while true; do
  118. # Get the current time
  119. CURRENT_TIME=$(date +%s)
  120. # Calculate the elapsed time
  121. ELAPSED_TIME=$((CURRENT_TIME - START_TIME))
  122. # Check if the elapsed time exceeds the timeout
  123. if [ $ELAPSED_TIME -ge $TIMEOUT ]; then
  124. echo "Timeout of $TIMEOUT seconds reached. Exiting..."
  125. exit 1
  126. fi
  127. # Make a request to the endpoint and capture the HTTP status code
  128. HTTP_STATUS=$(curl -o /dev/null -s -w "%{http_code}" $URL)
  129. # Check if the HTTP status is 200 OK
  130. if [ "$HTTP_STATUS" -eq 200 ]; then
  131. echo "Received 200 OK from $URL"
  132. break
  133. else
  134. echo "Waiting for 200 OK response, current status: $HTTP_STATUS"
  135. sleep 2 # Wait for 2 seconds before retrying
  136. fi
  137. done
  138. # Run cargo test
  139. cargo test -p cdk-integration-tests --test regtest
  140. # Run cargo test with the http_subscription feature
  141. cargo test -p cdk-integration-tests --test regtest --features http_subscription
  142. # Switch Mints: Run tests with LND mint
  143. export cdk_itests_mint_port_0=8087;
  144. export cdk_itests_mint_port_1=8085;
  145. cargo test -p cdk-integration-tests --test regtest
  146. # Capture the exit status of cargo test
  147. test_status=$?
  148. # Exit with the status of the tests
  149. exit $test_status