From ce48720e9a062cc1b117a921357377663b4b5e6e Mon Sep 17 00:00:00 2001 From: jack Date: Mon, 25 Aug 2025 17:42:41 +0200 Subject: [PATCH] Tests: gate verbose prints under DEBUG; ChatViewModel: remove legacy fingerprint helper and rely on UnifiedPeerService --- bitchat/ViewModels/ChatViewModel.swift | 22 ++-------------------- bitchatTests/NostrProtocolTests.swift | 10 ++++++++++ 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/bitchat/ViewModels/ChatViewModel.swift b/bitchat/ViewModels/ChatViewModel.swift index 260d5308..ee972217 100644 --- a/bitchat/ViewModels/ChatViewModel.swift +++ b/bitchat/ViewModels/ChatViewModel.swift @@ -3617,26 +3617,8 @@ class ChatViewModel: ObservableObject, BitchatDelegate { return unifiedPeerService.getFingerprint(for: peerID) } - private func getFingerprint_old(for peerID: String) -> String? { - // Remove debug logging to prevent console spam during view updates - - // First try to get fingerprint from mesh service's peer ID rotation mapping - if let fingerprint = meshService.getFingerprint(for: peerID) { - return fingerprint - } - - // Check noise service (direct Noise session fingerprint) - if let fingerprint = meshService.getNoiseService().getPeerFingerprint(peerID) { - return fingerprint - } - - // Last resort: check local mapping - if let fingerprint = peerIDToPublicKeyFingerprint[peerID] { - return fingerprint - } - - return nil - } + // (legacy getFingerprint_old removed; UnifiedPeerService is the source of truth) + // Helper to resolve nickname for a peer ID through various sources @MainActor diff --git a/bitchatTests/NostrProtocolTests.swift b/bitchatTests/NostrProtocolTests.swift index ea49d96a..0cc92306 100644 --- a/bitchatTests/NostrProtocolTests.swift +++ b/bitchatTests/NostrProtocolTests.swift @@ -21,8 +21,10 @@ final class NostrProtocolTests: XCTestCase { let sender = try NostrIdentity.generate() let recipient = try NostrIdentity.generate() + #if DEBUG print("Sender pubkey: \(sender.publicKeyHex)") print("Recipient pubkey: \(recipient.publicKeyHex)") + #endif // Create a test message let originalContent = "Hello from NIP-17 test!" @@ -34,8 +36,10 @@ final class NostrProtocolTests: XCTestCase { senderIdentity: sender ) + #if DEBUG print("Gift wrap created with ID: \(giftWrap.id)") print("Gift wrap pubkey: \(giftWrap.pubkey)") + #endif // Decrypt the gift wrap let (decryptedContent, senderPubkey, timestamp) = try NostrProtocol.decryptPrivateMessage( @@ -52,7 +56,9 @@ final class NostrProtocolTests: XCTestCase { let timeDiff = abs(messageDate.timeIntervalSinceNow) XCTAssertLessThan(timeDiff, 60, "Message timestamp should be recent") + #if DEBUG print("✅ Successfully decrypted message: '\(decryptedContent)' from \(senderPubkey) at \(messageDate)") + #endif } func testGiftWrapUsesUniqueEphemeralKeys() throws { @@ -75,8 +81,10 @@ final class NostrProtocolTests: XCTestCase { // Gift wrap pubkeys should be different (unique ephemeral keys) XCTAssertNotEqual(message1.pubkey, message2.pubkey) + #if DEBUG print("Message 1 gift wrap pubkey: \(message1.pubkey)") print("Message 2 gift wrap pubkey: \(message2.pubkey)") + #endif // Both should decrypt successfully let (content1, _, _) = try NostrProtocol.decryptPrivateMessage( @@ -109,7 +117,9 @@ final class NostrProtocolTests: XCTestCase { giftWrap: giftWrap, recipientIdentity: wrongRecipient )) { error in + #if DEBUG print("Expected error when decrypting with wrong key: \(error)") + #endif } }