mintd_payment_processor.sh 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. #!/usr/bin/env bash
  2. # Function to perform cleanup
  3. cleanup() {
  4. echo "Cleaning up..."
  5. echo "Killing the cdk payment processor"
  6. kill -2 $cdk_payment_processor_pid
  7. wait $cdk_payment_processor_pid
  8. echo "Killing the cdk mintd"
  9. kill -2 $cdk_mintd_pid
  10. wait $cdk_mintd_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=8086;
  28. export LN_BACKEND="$1";
  29. URL="http://$cdk_itests_mint_addr:$cdk_itests_mint_port_0/v1/info"
  30. # Check if the temporary directory was created successfully
  31. if [[ ! -d "$cdk_itests" ]]; then
  32. echo "Failed to create temp directory"
  33. exit 1
  34. fi
  35. echo "Temp directory created: $cdk_itests"
  36. export MINT_DATABASE="$1";
  37. cargo build -p cdk-integration-tests
  38. if [ "$LN_BACKEND" != "FAKEWALLET" ]; then
  39. cargo run --bin start_regtest &
  40. cdk_regtest_pid=$!
  41. mkfifo "$cdk_itests/progress_pipe"
  42. rm -f "$cdk_itests/signal_received" # Ensure clean state
  43. # Start reading from pipe in background
  44. (while read line; do
  45. case "$line" in
  46. "checkpoint1")
  47. echo "Reached first checkpoint"
  48. touch "$cdk_itests/signal_received"
  49. exit 0
  50. ;;
  51. esac
  52. done < "$cdk_itests/progress_pipe") &
  53. # Wait for up to 120 seconds
  54. for ((i=0; i<120; i++)); do
  55. if [ -f "$cdk_itests/signal_received" ]; then
  56. echo "break signal received"
  57. break
  58. fi
  59. sleep 1
  60. done
  61. echo "Regtest set up continuing"
  62. fi
  63. # Start payment processor
  64. export CDK_PAYMENT_PROCESSOR_CLN_RPC_PATH="$cdk_itests/cln/one/regtest/lightning-rpc";
  65. export CDK_PAYMENT_PROCESSOR_LND_ADDRESS="https://localhost:10010";
  66. export CDK_PAYMENT_PROCESSOR_LND_CERT_FILE="$cdk_itests/lnd/two/tls.cert";
  67. export CDK_PAYMENT_PROCESSOR_LND_MACAROON_FILE="$cdk_itests/lnd/two/data/chain/bitcoin/regtest/admin.macaroon";
  68. export CDK_PAYMENT_PROCESSOR_LN_BACKEND=$LN_BACKEND;
  69. export CDK_PAYMENT_PROCESSOR_LISTEN_HOST="127.0.0.1";
  70. export CDK_PAYMENT_PROCESSOR_LISTEN_PORT="8090";
  71. echo "$CDK_PAYMENT_PROCESSOR_CLN_RPC_PATH"
  72. cargo run --bin cdk-payment-processor &
  73. cdk_payment_processor_pid=$!
  74. sleep 10;
  75. export CDK_MINTD_URL="http://$cdk_itests_mint_addr:$cdk_itests_mint_port_0";
  76. export CDK_MINTD_WORK_DIR="$cdk_itests";
  77. export CDK_MINTD_LISTEN_HOST=$cdk_itests_mint_addr;
  78. export CDK_MINTD_LISTEN_PORT=$cdk_itests_mint_port_0;
  79. export CDK_MINTD_LN_BACKEND="grpcprocessor";
  80. export CDK_MINTD_GRPC_PAYMENT_PROCESSOR_ADDRESS="http://127.0.0.1";
  81. export CDK_MINTD_GRPC_PAYMENT_PROCESSOR_PORT="8090";
  82. export CDK_MINTD_GRPC_PAYMENT_PROCESSOR_SUPPORTED_UNITS="sat";
  83. export CDK_MINTD_MNEMONIC="eye survey guilt napkin crystal cup whisper salt luggage manage unveil loyal";
  84. cargo run --bin cdk-mintd --no-default-features --features grpc-processor &
  85. cdk_mintd_pid=$!
  86. echo $cdk_itests
  87. TIMEOUT=100
  88. START_TIME=$(date +%s)
  89. # Loop until the endpoint returns a 200 OK status or timeout is reached
  90. while true; do
  91. # Get the current time
  92. CURRENT_TIME=$(date +%s)
  93. # Calculate the elapsed time
  94. ELAPSED_TIME=$((CURRENT_TIME - START_TIME))
  95. # Check if the elapsed time exceeds the timeout
  96. if [ $ELAPSED_TIME -ge $TIMEOUT ]; then
  97. echo "Timeout of $TIMEOUT seconds reached. Exiting..."
  98. exit 1
  99. fi
  100. # Make a request to the endpoint and capture the HTTP status code
  101. HTTP_STATUS=$(curl -o /dev/null -s -w "%{http_code}" $URL)
  102. # Check if the HTTP status is 200 OK
  103. if [ "$HTTP_STATUS" -eq 200 ]; then
  104. echo "Received 200 OK from $URL"
  105. break
  106. else
  107. echo "Waiting for 200 OK response, current status: $HTTP_STATUS"
  108. sleep 2 # Wait for 2 seconds before retrying
  109. fi
  110. done
  111. cargo test -p cdk-integration-tests --test payment_processor
  112. # Run cargo test
  113. # cargo test -p cdk-integration-tests --test fake_wallet
  114. # Capture the exit status of cargo test
  115. test_status=$?
  116. # Exit with the status of the tests
  117. exit $test_status