test-sprocket-simple.sh raw

   1  #!/bin/bash
   2  
   3  # Simple Sprocket Test
   4  # This script demonstrates sprocket functionality
   5  
   6  set -e
   7  
   8  echo "๐Ÿงช Simple Sprocket Test"
   9  echo "======================"
  10  
  11  # Configuration
  12  RELAY_PORT="3334"
  13  TEST_CONFIG_DIR="$HOME/.config/ORLY_TEST"
  14  
  15  # Clean up any existing test processes
  16  echo "๐Ÿงน Cleaning up existing processes..."
  17  pkill -f "ORLY_TEST" || true
  18  sleep 2
  19  
  20  # Create test configuration directory
  21  echo "๐Ÿ“ Setting up test environment..."
  22  mkdir -p "$TEST_CONFIG_DIR"
  23  
  24  # Copy the Python sprocket script
  25  cp test-sprocket.py "$TEST_CONFIG_DIR/sprocket.py"
  26  
  27  # Create bash wrapper for the Python script
  28  cat > "$TEST_CONFIG_DIR/sprocket.sh" << 'EOF'
  29  #!/bin/bash
  30  python3 "$(dirname "$0")/sprocket.py"
  31  EOF
  32  
  33  chmod +x "$TEST_CONFIG_DIR/sprocket.sh"
  34  
  35  echo "โœ… Sprocket script created at: $TEST_CONFIG_DIR/sprocket.sh"
  36  
  37  # Test the sprocket script directly first
  38  echo "๐Ÿงช Testing sprocket script directly..."
  39  
  40  # Test 1: Normal event
  41  echo "๐Ÿ“ค Test 1: Normal event"
  42  current_time=$(date +%s)
  43  normal_event="{\"id\":\"test_normal_123\",\"pubkey\":\"1234567890abcdef1234567890abcdef12345678\",\"created_at\":$current_time,\"kind\":1,\"content\":\"Hello, world!\",\"sig\":\"test_sig\"}"
  44  echo "$normal_event" | python3 "$TEST_CONFIG_DIR/sprocket.py"
  45  
  46  # Test 2: Spam content
  47  echo "๐Ÿ“ค Test 2: Spam content"
  48  spam_event="{\"id\":\"test_spam_456\",\"pubkey\":\"1234567890abcdef1234567890abcdef12345678\",\"created_at\":$current_time,\"kind\":1,\"content\":\"This is spam content\",\"sig\":\"test_sig\"}"
  49  echo "$spam_event" | python3 "$TEST_CONFIG_DIR/sprocket.py"
  50  
  51  # Test 3: Test kind 9999
  52  echo "๐Ÿ“ค Test 3: Test kind 9999"
  53  kind_event="{\"id\":\"test_kind_789\",\"pubkey\":\"1234567890abcdef1234567890abcdef12345678\",\"created_at\":$current_time,\"kind\":9999,\"content\":\"Test message\",\"sig\":\"test_sig\"}"
  54  echo "$kind_event" | python3 "$TEST_CONFIG_DIR/sprocket.py"
  55  
  56  # Test 4: Blocked hashtag
  57  echo "๐Ÿ“ค Test 4: Blocked hashtag"
  58  hashtag_event="{\"id\":\"test_hashtag_101\",\"pubkey\":\"1234567890abcdef1234567890abcdef12345678\",\"created_at\":$current_time,\"kind\":1,\"content\":\"Message with hashtag\",\"tags\":[[\"t\",\"blocked\"]],\"sig\":\"test_sig\"}"
  59  echo "$hashtag_event" | python3 "$TEST_CONFIG_DIR/sprocket.py"
  60  
  61  echo ""
  62  echo "โœ… Direct sprocket script tests completed!"
  63  echo ""
  64  echo "Expected results:"
  65  echo "1. Normal event: {\"id\":\"test_normal_123\",\"action\":\"accept\",\"msg\":\"\"}"
  66  echo "2. Spam content: {\"id\":\"test_spam_456\",\"action\":\"reject\",\"msg\":\"Content contains spam\"}"
  67  echo "3. Test kind 9999: {\"id\":\"test_kind_789\",\"action\":\"shadowReject\",\"msg\":\"\"}"
  68  echo "4. Blocked hashtag: {\"id\":\"test_hashtag_101\",\"action\":\"reject\",\"msg\":\"Hashtag \\\"blocked\\\" is not allowed\"}"
  69  echo ""
  70  echo "๐Ÿ’ก To test with the full relay, run:"
  71  echo "   export ORLY_SPROCKET_ENABLED=true"
  72  echo "   export ORLY_APP_NAME=ORLY_TEST"
  73  echo "   go run . test"
  74  echo ""
  75  echo "   Then in another terminal:"
  76  echo "   ./test-sprocket-manual.sh"
  77