diff --git a/RiotTests/RendezvousServiceTests.swift b/RiotTests/RendezvousServiceTests.swift index 36297f7780..2ffe58f061 100644 --- a/RiotTests/RendezvousServiceTests.swift +++ b/RiotTests/RendezvousServiceTests.swift @@ -19,10 +19,10 @@ import XCTest @MainActor class RendezvousServiceTests: XCTestCase { - func testEnd2End() async { + func testEnd2EndV1() async { let mockTransport = MockRendezvousTransport() - let aliceService = RendezvousService(transport: mockTransport) + let aliceService = RendezvousService(transport: mockTransport, algorithm: .ECDH_V1) guard case .success(let rendezvousDetails) = await aliceService.createRendezvous(), let alicePublicKey = rendezvousDetails.key else { @@ -32,7 +32,49 @@ class RendezvousServiceTests: XCTestCase { XCTAssertNotNil(mockTransport.rendezvousURL) - let bobService = RendezvousService(transport: mockTransport) + let bobService = RendezvousService(transport: mockTransport, algorithm: .ECDH_V1) + + guard case .success = await bobService.joinRendezvous(withPublicKey: alicePublicKey) else { + XCTFail("Bob failed to join") + return + } + + guard case .success = await aliceService.waitForInterlocutor() else { + XCTFail("Alice failed to establish connection") + return + } + + guard let messageData = "Hello from alice".data(using: .utf8) else { + fatalError() + } + + guard case .success = await aliceService.send(data: messageData) else { + XCTFail("Alice failed to send message") + return + } + + guard case .success(let data) = await bobService.receive() else { + XCTFail("Bob failed to receive message") + return + } + + XCTAssertEqual(messageData, data) + } + + func testEnd2EndV2() async { + let mockTransport = MockRendezvousTransport() + + let aliceService = RendezvousService(transport: mockTransport, algorithm: .ECDH_V2) + + guard case .success(let rendezvousDetails) = await aliceService.createRendezvous(), + let alicePublicKey = rendezvousDetails.key else { + XCTFail("Rendezvous creation failed") + return + } + + XCTAssertNotNil(mockTransport.rendezvousURL) + + let bobService = RendezvousService(transport: mockTransport, algorithm: .ECDH_V2) guard case .success = await bobService.joinRendezvous(withPublicKey: alicePublicKey) else { XCTFail("Bob failed to join")