Skip to content

Commit

Permalink
Test both v1 and v2
Browse files Browse the repository at this point in the history
  • Loading branch information
hughns committed Feb 15, 2023
1 parent 2ebd9c0 commit c9dda44
Showing 1 changed file with 45 additions and 3 deletions.
48 changes: 45 additions & 3 deletions RiotTests/RendezvousServiceTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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")
Expand Down

0 comments on commit c9dda44

Please sign in to comment.