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

feat: update tbDEXHttpClient to use submitCancel() #104

Merged
merged 1 commit into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading