Adding async publish to relay pool
This commit is contained in:
49
tests/backward_compat_test.c
Normal file
49
tests/backward_compat_test.c
Normal file
@@ -0,0 +1,49 @@
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "../nostr_core/nostr_core.h"
|
||||
#include "../cjson/cJSON.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
int main() {
|
||||
printf("🧪 Backward Compatibility Test\n");
|
||||
printf("===============================\n");
|
||||
|
||||
// Create pool
|
||||
nostr_relay_pool_t* pool = nostr_relay_pool_create(NULL);
|
||||
if (!pool) {
|
||||
printf("❌ Failed to create pool\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Create a test event
|
||||
cJSON* event = cJSON_CreateObject();
|
||||
cJSON_AddStringToObject(event, "id", "test_event_sync");
|
||||
cJSON_AddNumberToObject(event, "kind", 1);
|
||||
cJSON_AddStringToObject(event, "content", "Test sync publish");
|
||||
cJSON_AddNumberToObject(event, "created_at", time(NULL));
|
||||
cJSON_AddStringToObject(event, "pubkey", "test_pubkey");
|
||||
cJSON_AddStringToObject(event, "sig", "test_signature");
|
||||
|
||||
// Test with non-existent relay (should return 0 successful publishes)
|
||||
const char* test_relays[] = {"ws://nonexistent.example.com"};
|
||||
|
||||
printf("🚀 Testing synchronous publish (backward compatibility)...\n");
|
||||
|
||||
// Call synchronous publish (old API)
|
||||
int result = nostr_relay_pool_publish_async(pool, test_relays, 1, event, NULL, NULL);
|
||||
|
||||
printf("📊 Synchronous publish result: %d successful publishes\n", result);
|
||||
|
||||
// Cleanup
|
||||
cJSON_Delete(event);
|
||||
nostr_relay_pool_destroy(pool);
|
||||
|
||||
printf("\n✅ Backward compatibility test completed!\n");
|
||||
printf(" Expected: 0 successful publishes (connection failure)\n");
|
||||
printf(" Actual: %d successful publishes\n", result);
|
||||
printf(" Result: %s\n", result == 0 ? "PASS" : "FAIL");
|
||||
|
||||
return result == 0 ? 0 : 1;
|
||||
}
|
||||
Reference in New Issue
Block a user