Skip to content
This repository has been archived by the owner on Dec 12, 2024. It is now read-only.

Commit

Permalink
updates http client to use submitCancel() since Close is reserved…
Browse files Browse the repository at this point in the history
… for pfis (#104)
  • Loading branch information
ethan-tbd authored Aug 29, 2024
1 parent 5f000a4 commit 0c71c4d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
10 changes: 5 additions & 5 deletions Sources/tbDEX/HttpClient/tbDEXHttpClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,15 @@ public enum tbDEXHttpClient {
try await sendMessage(message: order, messageEndpoint: "/exchanges/\(exchangeID)")
}

/// Sends the Close message to the PFI
/// Sends the Cancel message to the PFI
/// - Parameters:
/// - order: The Close message that will be sent to the PFI
/// - cancel: The Cancel message that will be sent to the PFI
/// - Throws: if message verification fails
/// - Throws: if recipient DID resolution fails
/// - Throws: if recipient DID does not have a PFI service entry
public static func submitClose(close: Close) async throws {
let exchangeID = close.metadata.exchangeID
try await sendMessage(message: close, messageEndpoint: "/exchanges/\(exchangeID)")
public static func submitCancel(cancel: Cancel) async throws {
let exchangeID = cancel.metadata.exchangeID
try await sendMessage(message: cancel, messageEndpoint: "/exchanges/\(exchangeID)")
}

/// Sends a message to a PFI
Expand Down
12 changes: 6 additions & 6 deletions Tests/tbDEXTests/HttpClient/tbDEXHttpClientTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -277,25 +277,25 @@ final class tbDEXHttpClientTests: XCTestCase {
}
}

func test_submitCloseWhenSuccess() async throws {
var close = DevTools.createClose(from: did.uri, to: pfiDid)
func test_submitCancelWhenSuccess() async throws {
var cancel = DevTools.createCancel(from: did.uri, to: pfiDid)

try close.sign(did: did)
try cancel.sign(did: did)

Mocker.mode = .optin
Mock(
url: URL(string: "\(endpoint)/exchanges/exchange_123")!,
contentType: .json,
statusCode: 200,
data: [
.put: try tbDEXJSONEncoder().encode(close)
.put: try tbDEXJSONEncoder().encode(cancel)
]
).register()

do {
try await tbDEXHttpClient.submitClose(close: close)
try await tbDEXHttpClient.submitCancel(cancel: cancel)
} catch {
XCTFail("Error on submit order: \(error)")
XCTFail("Error on submit cancel: \(error)")
}
}

Expand Down

0 comments on commit 0c71c4d

Please sign in to comment.