itests.sh 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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. echo "Starting cln mintd";
  71. cargo run --bin cdk-mintd &
  72. cdk_mintd_pid=$!
  73. echo $cdk_itests
  74. URL="http://$cdk_itests_mint_addr:$cdk_itests_mint_port_0/v1/info"
  75. TIMEOUT=100
  76. START_TIME=$(date +%s)
  77. # Loop until the endpoint returns a 200 OK status or timeout is reached
  78. while true; do
  79. # Get the current time
  80. CURRENT_TIME=$(date +%s)
  81. # Calculate the elapsed time
  82. ELAPSED_TIME=$((CURRENT_TIME - START_TIME))
  83. # Check if the elapsed time exceeds the timeout
  84. if [ $ELAPSED_TIME -ge $TIMEOUT ]; then
  85. echo "Timeout of $TIMEOUT seconds reached. Exiting..."
  86. exit 1
  87. fi
  88. # Make a request to the endpoint and capture the HTTP status code
  89. HTTP_STATUS=$(curl -o /dev/null -s -w "%{http_code}" $URL)
  90. # Check if the HTTP status is 200 OK
  91. if [ "$HTTP_STATUS" -eq 200 ]; then
  92. echo "Received 200 OK from $URL"
  93. break
  94. else
  95. echo "Waiting for 200 OK response, current status: $HTTP_STATUS"
  96. sleep 2 # Wait for 2 seconds before retrying
  97. fi
  98. done
  99. export CDK_MINTD_LND_ADDRESS="https://localhost:10010";
  100. export CDK_MINTD_LND_CERT_FILE="$cdk_itests/lnd/two/tls.cert";
  101. export CDK_MINTD_LND_MACAROON_FILE="$cdk_itests/lnd/two/data/chain/bitcoin/regtest/admin.macaroon";
  102. export CDK_MINTD_URL="http://$cdk_itests_mint_addr:$cdk_itests_mint_port_1";
  103. mkdir -p "$cdk_itests/lnd_mint"
  104. export CDK_MINTD_WORK_DIR="$cdk_itests/lnd_mint";
  105. export CDK_MINTD_LISTEN_HOST=$cdk_itests_mint_addr;
  106. export CDK_MINTD_LISTEN_PORT=$cdk_itests_mint_port_1;
  107. export CDK_MINTD_LN_BACKEND="lnd";
  108. export CDK_MINTD_MNEMONIC="eye survey guilt napkin crystal cup whisper salt luggage manage unveil loyal";
  109. echo "Starting lnd mintd";
  110. cargo run --bin cdk-mintd &
  111. cdk_mintd_lnd_pid=$!
  112. URL="http://$cdk_itests_mint_addr:$cdk_itests_mint_port_1/v1/info"
  113. TIMEOUT=100
  114. START_TIME=$(date +%s)
  115. # Loop until the endpoint returns a 200 OK status or timeout is reached
  116. while true; do
  117. # Get the current time
  118. CURRENT_TIME=$(date +%s)
  119. # Calculate the elapsed time
  120. ELAPSED_TIME=$((CURRENT_TIME - START_TIME))
  121. # Check if the elapsed time exceeds the timeout
  122. if [ $ELAPSED_TIME -ge $TIMEOUT ]; then
  123. echo "Timeout of $TIMEOUT seconds reached. Exiting..."
  124. exit 1
  125. fi
  126. # Make a request to the endpoint and capture the HTTP status code
  127. HTTP_STATUS=$(curl -o /dev/null -s -w "%{http_code}" $URL)
  128. # Check if the HTTP status is 200 OK
  129. if [ "$HTTP_STATUS" -eq 200 ]; then
  130. echo "Received 200 OK from $URL"
  131. break
  132. else
  133. echo "Waiting for 200 OK response, current status: $HTTP_STATUS"
  134. sleep 2 # Wait for 2 seconds before retrying
  135. fi
  136. done
  137. # Run cargo test
  138. cargo test -p cdk-integration-tests --test regtest
  139. # Run cargo test with the http_subscription feature
  140. cargo test -p cdk-integration-tests --test regtest --features http_subscription
  141. # Switch Mints: Run tests with LND mint
  142. export cdk_itests_mint_port_0=8087;
  143. export cdk_itests_mint_port_1=8085;
  144. cargo test -p cdk-integration-tests --test regtest
  145. # Capture the exit status of cargo test
  146. test_status=$?
  147. # Exit with the status of the tests
  148. exit $test_status