#define _DEFAULT_SOURCE #include "../nostr_core/nostr_core.h" #include "../cjson/cJSON.h" #include #include #include #include // Test callback function static int callback_count = 0; void test_callback(const char* relay_url, const char* event_id, int success, const char* message, void* user_data) { (void)event_id; // Suppress unused parameter warning (void)user_data; // Suppress unused parameter warning callback_count++; printf("๐Ÿ“ก Callback %d: Relay %s, Success: %s\n", callback_count, relay_url, success ? "YES" : "NO"); if (message) { printf(" Message: %s\n", message); } } int main() { printf("๐Ÿงช Simple Async Publish 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_simple"); cJSON_AddNumberToObject(event, "kind", 1); cJSON_AddStringToObject(event, "content", "Test async 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 trigger connection failure callback) const char* test_relays[] = {"ws://nonexistent.example.com"}; printf("๐Ÿš€ Testing async publish...\n"); // Call async publish int sent_count = nostr_relay_pool_publish_async( pool, test_relays, 1, event, test_callback, NULL); printf("๐Ÿ“Š Sent to %d relays\n", sent_count); // Wait a bit for callback printf("โณ Waiting for callback...\n"); for (int i = 0; i < 5 && callback_count == 0; i++) { nostr_relay_pool_poll(pool, 100); usleep(100000); // 100ms } printf("\n๐Ÿ“ˆ Results:\n"); printf(" Callbacks received: %d\n", callback_count); // Cleanup cJSON_Delete(event); nostr_relay_pool_destroy(pool); printf("\nโœ… Simple async test completed!\n"); return callback_count > 0 ? 0 : 1; }