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

Commit

Permalink
add tests for protocol version
Browse files Browse the repository at this point in the history
  • Loading branch information
kirahsapong committed Mar 20, 2024
1 parent e776214 commit b9ac6ff
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 1 deletion.
22 changes: 21 additions & 1 deletion Tests/tbDEXTests/Protocol/Models/Messages/CloseTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,26 @@ final class CloseTests: XCTestCase {
XCTAssertEqual(close.metadata.to, pfi.uri)
XCTAssertEqual(close.metadata.exchangeID, "exchange_123")
XCTAssertEqual(close.data.reason, "test reason")
XCTAssertEqual(close.metadata.protocol, "1.0")
}

func test_overrideProtocolVersion() {
let close = Close(
from: did.uri,
to: pfi.uri,
exchangeID: "exchange_123",
data: .init(
reason: "test reason"
),
externalID: nil,
protocol: "2.0"
)

XCTAssertEqual(close.metadata.id.prefix, "close")
XCTAssertEqual(close.metadata.from, did.uri)
XCTAssertEqual(close.metadata.to, pfi.uri)
XCTAssertEqual(close.metadata.exchangeID, "exchange_123")
XCTAssertEqual(close.metadata.protocol, "2.0")
}

func test_signAndVerify() async throws {
Expand Down Expand Up @@ -48,7 +68,7 @@ final class CloseTests: XCTestCase {
reason: "test reason"
),
externalID: nil,
protocol: "1.0"
protocol: nil
)
}
}
19 changes: 19 additions & 0 deletions Tests/tbDEXTests/Protocol/Models/Messages/OrderStatusTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,25 @@ final class OrderStatusTests: XCTestCase {
XCTAssertEqual(orderStatus.metadata.exchangeID, "exchange_123")
XCTAssertEqual(orderStatus.data.orderStatus, "test status")
}

func test_overrideProtocolVersion() {
let orderstatus = OrderStatus(
from: did.uri,
to: pfi.uri,
exchangeID: "exchange_123",
data: .init(
orderStatus: "test status"
),
externalID: nil,
protocol: "2.0"
)

XCTAssertEqual(orderstatus.metadata.id.prefix, "orderstatus")
XCTAssertEqual(orderstatus.metadata.from, did.uri)
XCTAssertEqual(orderstatus.metadata.to, pfi.uri)
XCTAssertEqual(orderstatus.metadata.exchangeID, "exchange_123")
XCTAssertEqual(orderstatus.metadata.protocol, "2.0")
}

func test_signAndVerify() async throws {
let did = try DIDJWK.create(keyManager: InMemoryKeyManager())
Expand Down
17 changes: 17 additions & 0 deletions Tests/tbDEXTests/Protocol/Models/Messages/OrderTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,23 @@ final class OrderTests: XCTestCase {
XCTAssertEqual(order.metadata.to, pfi.uri)
XCTAssertEqual(order.metadata.exchangeID, "exchange_123")
}

func test_overrideProtocolVersion() {
let order = Order(
from: did.uri,
to: pfi.uri,
exchangeID: "exchange_123",
data: .init(),
externalID: nil,
protocol: "2.0"
)

XCTAssertEqual(order.metadata.id.prefix, "order")
XCTAssertEqual(order.metadata.from, did.uri)
XCTAssertEqual(order.metadata.to, pfi.uri)
XCTAssertEqual(order.metadata.exchangeID, "exchange_123")
XCTAssertEqual(order.metadata.protocol, "2.0")
}

func test_signAndVerify() async throws {
let did = try DIDJWK.create(keyManager: InMemoryKeyManager())
Expand Down
32 changes: 32 additions & 0 deletions Tests/tbDEXTests/Protocol/Models/Messages/QuoteTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,38 @@ final class QuoteTests: XCTestCase {
XCTAssertEqual(quote.data.payout.fee, "0.50")
XCTAssertNil(quote.data.payout.paymentInstruction)
}

func test_overrideProtocolVersion() {
let quote = Quote(
from: did.uri,
to: pfi.uri,
exchangeID: "exchange_123",
data: .init(
expiresAt: Date().addingTimeInterval(60),
payin: .init(
currencyCode: "USD",
amount: "1.00",
paymentInstruction: .init(
link: "https://example.com",
instruction: "test instruction"
)
),
payout: .init(
currencyCode: "AUD",
amount: "2.00",
fee: "0.50"
)
),
externalID: nil,
protocol: "2.0"
)

XCTAssertEqual(quote.metadata.id.prefix, "quote")
XCTAssertEqual(quote.metadata.from, did.uri)
XCTAssertEqual(quote.metadata.to, pfi.uri)
XCTAssertEqual(quote.metadata.exchangeID, "exchange_123")
XCTAssertEqual(quote.metadata.protocol, "2.0")
}

func test_signAndVerify() async throws {
var quote = createQuote(from: did.uri, to: pfi.uri)
Expand Down
26 changes: 26 additions & 0 deletions Tests/tbDEXTests/Protocol/Models/Messages/RFQTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,32 @@ final class RFQTests: XCTestCase {
XCTAssertEqual(rfq.data.payinMethod.kind, "DEBIT_CARD")
XCTAssertEqual(rfq.data.payoutMethod.kind, "BITCOIN_ADDRESS")
}

func test_overrideProtocolVersion() {
let rfq = RFQ(
to: pfi.uri,
from: did.uri,
data: .init(
offeringId: TypeID(rawValue:"offering_01hmz7ehw6e5k9bavj0ywypfpy")!,
payinAmount: "1.00",
payinMethod: .init(
kind: "DEBIT_CARD"
),
payoutMethod: .init(
kind: "BITCOIN_ADDRESS"
),
claims: []
),
externalID: nil,
protocol: "2.0"
)

XCTAssertEqual(rfq.metadata.id.prefix, "rfq")
XCTAssertEqual(rfq.metadata.from, did.uri)
XCTAssertEqual(rfq.metadata.to, pfi.uri)
XCTAssertEqual(rfq.metadata.exchangeID, rfq.metadata.id.rawValue)
XCTAssertEqual(rfq.metadata.protocol, "2.0")
}

func test_signAndVerify() async throws {
var rfq = createRFQ(from: did.uri, to: pfi.uri)
Expand Down

0 comments on commit b9ac6ff

Please sign in to comment.