Skip to content

Commit

Permalink
Tidy up code (#117)
Browse files Browse the repository at this point in the history
Signed-off-by: conanoc <[email protected]>
  • Loading branch information
conanoc authored Jun 19, 2024
1 parent e9e3b2b commit 101cac6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 32 deletions.
35 changes: 17 additions & 18 deletions Sources/AriesFramework/connection/ConnectionCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -120,28 +120,27 @@ public class ConnectionCommand {
handshakeProtocol: HandshakeProtocol?,
config: ReceiveOutOfBandInvitationConfig?) async throws -> ConnectionRecord {
var connection = try await receiveInvitation(outOfBandInvitation: outOfBandRecord.outOfBandInvitation,
autoAcceptConnection: false, alias: config?.alias)
let message: OutboundMessage
if let handshakeProtocol = handshakeProtocol {
if handshakeProtocol == .Connections {
message = try await agent.connectionService.createRequest(connectionId: connection.id,
label: config?.label,
imageUrl: config?.imageUrl,
autoAcceptConnection: config?.autoAcceptConnection)
} else {
message = try await agent.didExchangeService.createRequest(connectionId: connection.id,
label: config?.label,
autoAcceptConnection: config?.autoAcceptConnection)
}
try await agent.messageSender.send(message: message)
return message.connection
} else {
autoAcceptConnection: false, alias: config?.alias)
guard let handshakeProtocol = handshakeProtocol else {
let didDocServices = try outOfBandRecord.outOfBandInvitation.services.compactMap { try $0.asDidDocService() }
let theirDidDoc = try connection.theirDidDoc ?? DidDoc(from: didDocServices)
connection.theirDidDoc = theirDidDoc
connection.theirDidDoc = try connection.theirDidDoc ?? DidDoc(from: didDocServices)
try await agent.connectionService.updateState(connectionRecord: &connection, newState: .Complete)
return connection
}

let message: OutboundMessage
switch handshakeProtocol {
case .Connections:
message = try await agent.connectionService.createRequest(connectionId: connection.id,
label: config?.label,
imageUrl: config?.imageUrl,
autoAcceptConnection: config?.autoAcceptConnection)
case .DidExchange10, .DidExchange11:
message = try await agent.didExchangeService.createRequest(connectionId: connection.id,
label: config?.label,
autoAcceptConnection: config?.autoAcceptConnection)
}
try await agent.messageSender.send(message: message)
return message.connection
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ class ConnectionlessExchangeTest: XCTestCase {
"name": "John",
"age": "99"
])
let receiveInvitationConfig = ReceiveOutOfBandInvitationConfig(autoAcceptConnection: true)

override func setUp() async throws {
try await super.setUp()
Expand Down Expand Up @@ -50,7 +49,6 @@ class ConnectionlessExchangeTest: XCTestCase {
self.holderAgent.setOutboundTransport(SubjectOutboundTransport(subject: issuerAgent))

let offerOptions = CreateOfferOptions(
connection: nil,
credentialDefinitionId: credDefId,
attributes: credentialPreview.attributes,
comment: "this is credential-offer for you")
Expand All @@ -60,19 +58,15 @@ class ConnectionlessExchangeTest: XCTestCase {
let oobConfig = CreateOutOfBandInvitationConfig(
label: "issuer-to-holder-invitation",
alias: "issuer-to-holder-invitation",
imageUrl: nil,
goalCode: nil,
goal: nil,
handshake: false,
messages: [message],
multiUseInvitation: false,
autoAcceptConnection: true,
routing: nil)
autoAcceptConnection: true)
let oobInvitation = try await issuerAgent.oob.createInvitation(config: oobConfig)

let (oob, connection) = try await holderAgent.oob.receiveInvitation(oobInvitation.outOfBandInvitation)
XCTAssertNotNil(connection)
XCTAssertEqual(connection?.state, .Complete) // this is a fake connection.
XCTAssertEqual(connection?.state, .Complete)
XCTAssertNotNil(oob)

try await Task.sleep(nanoseconds: UInt64(5 * SECOND))
Expand All @@ -91,19 +85,15 @@ class ConnectionlessExchangeTest: XCTestCase {
let oobConfigForProofExchange = CreateOutOfBandInvitationConfig(
label: "verifier-to-holder-invitation",
alias: "verifier-to-holder-invitation",
imageUrl: nil,
goalCode: nil,
goal: nil,
handshake: false,
messages: [proofRequestMessage],
multiUseInvitation: false,
autoAcceptConnection: true,
routing: nil)
autoAcceptConnection: true)
let oobInvitationForProofExchange = try await verifierAgent.oob.createInvitation(config: oobConfigForProofExchange)

let (oobForProofExchange, connectionForProofExchange) = try await holderAgent.oob.receiveInvitation(oobInvitationForProofExchange.outOfBandInvitation)
XCTAssertNotNil(connectionForProofExchange)
XCTAssertEqual(connectionForProofExchange?.state, .Complete) // this is a fake connection.
XCTAssertEqual(connectionForProofExchange?.state, .Complete)
XCTAssertNotNil(oobForProofExchange)

try await Task.sleep(nanoseconds: UInt64(5 * SECOND))
Expand Down

0 comments on commit 101cac6

Please sign in to comment.