This directory contains a comprehensive test suite for the ORLY relay's sprocket event processing system.
The sprocket system allows external scripts to process Nostr events before they are stored in the relay. Events are sent to the sprocket script via stdin, and the script responds with JSONL messages indicating whether to accept, reject, or shadow reject the event.
The Python sprocket script (test-sprocket.py) implements the following test criteria:
./test-sprocket-complete.sh
This script will:
# Start relay manually with sprocket enabled
export ORLY_SPROCKET_ENABLED=true
go run . test
# In another terminal, run manual tests
./test-sprocket-manual.sh
# Run Go integration tests
go test -v -run TestSprocketIntegration ./test-sprocket-integration.go
`bash
cargo install websocat
`
`bash
go get github.com/gorilla/websocket
`
{
"id": "test_normal_123",
"pubkey": "1234567890abcdef1234567890abcdef12345678",
"created_at": 1640995200,
"kind": 1,
"content": "Hello, world!",
"sig": "test_sig"
}
Expected: ["OK","test_normal_123",true]
{
"id": "test_spam_456",
"pubkey": "1234567890abcdef1234567890abcdef12345678",
"created_at": 1640995200,
"kind": 1,
"content": "This is spam content",
"sig": "test_sig"
}
Expected: ["OK","test_spam_456",false,"error: Content contains spam"]
{
"id": "test_kind_789",
"pubkey": "1234567890abcdef1234567890abcdef12345678",
"created_at": 1640995200,
"kind": 9999,
"content": "Test message",
"sig": "test_sig"
}
Expected: ["OK","test_kind_789",true] (but event not processed)
{
"id": "test_hashtag_101",
"pubkey": "1234567890abcdef1234567890abcdef12345678",
"created_at": 1640995200,
"kind": 1,
"content": "Message with hashtag",
"tags": [["t", "blocked"]],
"sig": "test_sig"
}
Expected: ["OK","test_hashtag_101",false,"error: Hashtag \"blocked\" is not allowed"]
{
"id": "test_long_202",
"pubkey": "1234567890abcdef1234567890abcdef12345678",
"created_at": 1640995200,
"kind": 1,
"content": "a... (1001 characters)",
"sig": "test_sig"
}
Expected: ["OK","test_long_202",false,"error: Content too long (max 1000 characters)"]
Events are sent to the sprocket script as JSON objects via stdin, one per line.
The sprocket script must respond with JSONL (JSON Lines) format:
{"id": "event_id", "action": "accept", "msg": ""}
{"id": "event_id", "action": "reject", "msg": "reason for rejection"}
{"id": "event_id", "action": "shadowReject", "msg": ""}
To enable sprocket in the relay:
export ORLY_SPROCKET_ENABLED=true
export ORLY_APP_NAME="ORLY"
The sprocket script should be placed at:
~/.config/{ORLY_APP_NAME}/sprocket.sh
- Ensure the script exists at the correct path - Check file permissions (must be executable)
- Verify Python 3 is installed
- Check script syntax with python3 -m py_compile test-sprocket.py
- Ensure relay is running on the correct port - Check firewall settings
- Check relay logs for sprocket errors - Verify sprocket script is responding correctly
Enable debug logging:
export ORLY_LOG_LEVEL=debug
Test the sprocket script directly:
echo '{"id":"test","kind":1,"content":"spam test"}' | python3 test-sprocket.py
Expected output:
{"id": "test", "action": "reject", "msg": "Content contains spam"}
When adding new test cases:
test-sprocket.pytest-sprocket-complete.shThis test suite is part of the ORLY relay project and follows the same license.