v0.0.4 - nip09 implemented
This commit is contained in:
@@ -99,6 +99,47 @@ publish_event() {
|
||||
fi
|
||||
}
|
||||
|
||||
# Helper function to publish invalid event and expect rejection
|
||||
publish_invalid_event() {
|
||||
local event_json="$1"
|
||||
local description="$2"
|
||||
local expected_error="$3"
|
||||
|
||||
print_info "Publishing invalid $description..."
|
||||
|
||||
# Create EVENT message in Nostr format
|
||||
local event_message="[\"EVENT\",$event_json]"
|
||||
|
||||
# Publish to relay
|
||||
local response=""
|
||||
if command -v websocat &> /dev/null; then
|
||||
response=$(echo "$event_message" | timeout 5s websocat "$RELAY_URL" 2>&1 || echo "Connection failed")
|
||||
else
|
||||
print_error "websocat not found - required for testing"
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Check response - should contain "false" and error message
|
||||
if [[ "$response" == *"Connection failed"* ]]; then
|
||||
print_error "Failed to connect to relay for $description"
|
||||
return 1
|
||||
elif [[ "$response" == *"false"* ]]; then
|
||||
# Extract error message
|
||||
local error_msg=$(echo "$response" | grep -o '"[^"]*invalid[^"]*"' | head -1 | sed 's/"//g' 2>/dev/null || echo "rejected")
|
||||
print_success "$description correctly rejected: $error_msg"
|
||||
echo # Add blank line for readability
|
||||
return 0
|
||||
elif [[ "$response" == *"true"* ]]; then
|
||||
print_error "$description was incorrectly accepted (should have been rejected)"
|
||||
echo # Add blank line for readability
|
||||
return 1
|
||||
else
|
||||
print_warning "$description response unclear: $response"
|
||||
echo # Add blank line for readability
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Test subscription with filters
|
||||
test_subscription() {
|
||||
local sub_id="$1"
|
||||
@@ -211,7 +252,41 @@ run_comprehensive_test() {
|
||||
# Brief pause to let events settle
|
||||
sleep 2
|
||||
|
||||
print_header "PHASE 2: Testing Subscriptions and Filters"
|
||||
print_header "PHASE 2: Testing Invalid Events (NIP-01 Validation)"
|
||||
|
||||
print_step "Testing various invalid events that should be rejected..."
|
||||
|
||||
# Test 1: Event with invalid JSON structure (malformed)
|
||||
local malformed_event='{"id":"invalid","pubkey":"invalid_pubkey","created_at":"not_a_number","kind":1,"tags":[],"content":"test"}'
|
||||
publish_invalid_event "$malformed_event" "malformed event with invalid created_at" "invalid"
|
||||
|
||||
# Test 2: Event with missing required fields
|
||||
local missing_field_event='{"id":"test123","pubkey":"valid_pubkey","kind":1,"tags":[],"content":"test"}'
|
||||
publish_invalid_event "$missing_field_event" "event missing created_at and sig" "invalid"
|
||||
|
||||
# Test 3: Event with invalid pubkey format (not hex)
|
||||
local invalid_pubkey_event='{"id":"abc123","pubkey":"not_valid_hex_pubkey","created_at":1234567890,"kind":1,"tags":[],"content":"test","sig":"fake_sig"}'
|
||||
publish_invalid_event "$invalid_pubkey_event" "event with invalid pubkey format" "invalid"
|
||||
|
||||
# Test 4: Event with invalid event ID format
|
||||
local invalid_id_event='{"id":"not_64_char_hex","pubkey":"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef","created_at":1234567890,"kind":1,"tags":[],"content":"test","sig":"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"}'
|
||||
publish_invalid_event "$invalid_id_event" "event with invalid ID format" "invalid"
|
||||
|
||||
# Test 5: Event with invalid signature
|
||||
local invalid_sig_event='{"id":"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef","pubkey":"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef","created_at":1234567890,"kind":1,"tags":[],"content":"test","sig":"invalid_signature_format"}'
|
||||
publish_invalid_event "$invalid_sig_event" "event with invalid signature format" "invalid"
|
||||
|
||||
# Test 6: Event with invalid kind (negative)
|
||||
local invalid_kind_event='{"id":"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef","pubkey":"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef","created_at":1234567890,"kind":-1,"tags":[],"content":"test","sig":"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"}'
|
||||
publish_invalid_event "$invalid_kind_event" "event with negative kind" "invalid"
|
||||
|
||||
# Test 7: Event with invalid tags format (not array)
|
||||
local invalid_tags_event='{"id":"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef","pubkey":"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef","created_at":1234567890,"kind":1,"tags":"not_an_array","content":"test","sig":"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"}'
|
||||
publish_invalid_event "$invalid_tags_event" "event with invalid tags format" "invalid"
|
||||
|
||||
print_success "Invalid event tests completed - all should have been rejected"
|
||||
|
||||
print_header "PHASE 3: Testing Subscriptions and Filters"
|
||||
|
||||
# Test subscription filters
|
||||
print_step "Testing various subscription filters..."
|
||||
@@ -240,7 +315,7 @@ run_comprehensive_test() {
|
||||
# Test 7: Limit results
|
||||
test_subscription "test_limit" '{"kinds":[1],"limit":1}' "Limited to 1 event" "1"
|
||||
|
||||
print_header "PHASE 3: Database Verification"
|
||||
print_header "PHASE 4: Database Verification"
|
||||
|
||||
# Check what's actually stored in the database
|
||||
print_step "Verifying database contents..."
|
||||
@@ -265,13 +340,14 @@ run_comprehensive_test() {
|
||||
}
|
||||
|
||||
# Run the comprehensive test
|
||||
print_header "Starting C-Relay Comprehensive Test Suite"
|
||||
print_header "Starting C-Relay Comprehensive Test Suite with NIP-01 Validation"
|
||||
echo
|
||||
|
||||
if run_comprehensive_test; then
|
||||
echo
|
||||
print_success "All tests completed successfully!"
|
||||
print_info "The C-Relay hybrid schema implementation is working correctly"
|
||||
print_info "The C-Relay with full NIP-01 validation is working correctly"
|
||||
print_info "✅ Event validation, signature verification, and error handling all working"
|
||||
echo
|
||||
exit 0
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user