This repository has been archived by the owner on Dec 12, 2024. It is now read-only.
generated from TBD54566975/tbd-project-template
-
Notifications
You must be signed in to change notification settings - Fork 3
Feat/update quote orderstatus #68
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,69 +5,60 @@ import XCTest | |
|
||
final class OrderStatusTests: XCTestCase { | ||
|
||
let did = try! DIDJWK.create(keyManager: InMemoryKeyManager()) | ||
let pfi = try! DIDJWK.create(keyManager: InMemoryKeyManager()) | ||
|
||
func test_init() { | ||
let orderStatus = createOrderStatus(from: did.uri, to: pfi.uri) | ||
|
||
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.data.orderStatus, "test status") | ||
func test_parseOrderStatusFromStringified() throws { | ||
if let orderStatus = try parsedOrderStatus(orderStatus: orderStatusStringJSON) { | ||
XCTAssertEqual(orderStatus.metadata.kind, MessageKind.orderStatus) | ||
} else { | ||
XCTFail("Order status is not a parsed orderStatus") | ||
} | ||
} | ||
|
||
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_parseOrderStatusFromPrettified() throws { | ||
if let orderStatus = try parsedOrderStatus(orderStatus: orderStatusPrettyJSON) { | ||
XCTAssertEqual(orderStatus.metadata.kind, MessageKind.orderStatus) | ||
} else { | ||
XCTFail("Order status is not a parsed orderStatus") | ||
} | ||
} | ||
|
||
func test_signAndVerify() async throws { | ||
let did = try DIDJWK.create(keyManager: InMemoryKeyManager()) | ||
let pfi = try DIDJWK.create(keyManager: InMemoryKeyManager()) | ||
var orderStatus = createOrderStatus(from: did.uri, to: pfi.uri) | ||
|
||
XCTAssertNil(orderStatus.signature) | ||
try orderStatus.sign(did: did) | ||
XCTAssertNotNil(orderStatus.signature) | ||
let isValid = try await orderStatus.verify() | ||
XCTAssertTrue(isValid) | ||
func test_verifyOrderStatusIsValid() async throws { | ||
if let orderStatus = try parsedOrderStatus(orderStatus: orderStatusPrettyJSON) { | ||
XCTAssertNotNil(orderStatus.signature) | ||
XCTAssertNotNil(orderStatus.data) | ||
XCTAssertNotNil(orderStatus.metadata) | ||
let isValid = try await orderStatus.verify() | ||
XCTAssertTrue(isValid) | ||
} else { | ||
XCTFail("Order status is not a parsed orderStatus") | ||
} | ||
} | ||
|
||
func test_verifyWithoutSigningFailure() async throws { | ||
let orderStatus = createOrderStatus(from: did.uri, to: pfi.uri) | ||
|
||
await XCTAssertThrowsErrorAsync(try await orderStatus.verify()) | ||
} | ||
|
||
private func createOrderStatus( | ||
from: String, | ||
to: String | ||
) -> OrderStatus { | ||
OrderStatus( | ||
from: from, | ||
to: to, | ||
exchangeID: "exchange_123", | ||
data: .init( | ||
orderStatus: "test status" | ||
), | ||
externalID: nil, | ||
protocol: nil | ||
) | ||
|
||
private func parsedOrderStatus(orderStatus: String) throws -> OrderStatus? { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah i also thought verbs are universally clean code for functions. but learned from adam in swift you name them the noun. |
||
let parsedMessage = try AnyMessage.parse(orderStatus) | ||
guard case let .orderStatus(parsedOrderStatus) = parsedMessage else { | ||
return nil | ||
} | ||
return parsedOrderStatus | ||
} | ||
|
||
let orderStatusPrettyJSON = """ | ||
{ | ||
"metadata": { | ||
"from": "did:dht:geiro75xjbn81snmangwc35wkfsra8mt3awbga8drrjde5z9r9jo", | ||
"to": "did:dht:n46hom5afi6xrsxmddx5rjecyyx1faz4ocs4ie43tfkyo4darh9y", | ||
"exchangeId": "rfq_01hrqn6pp1e48a3meq95dzmkzs", | ||
"protocol": "1.0", | ||
"kind": "orderstatus", | ||
"id": "orderstatus_01hrqn6pp1e48a3meq9b3brgta", | ||
"createdAt": "2024-03-11T21:02:55.681Z" | ||
}, | ||
"data": { | ||
"orderStatus": "wee" | ||
}, | ||
"signature": "eyJhbGciOiJFZERTQSIsImtpZCI6ImRpZDpkaHQ6Z2Vpcm83NXhqYm44MXNubWFuZ3djMzV3a2ZzcmE4bXQzYXdiZ2E4ZHJyamRlNXo5cjlqbyMwIn0..aHifNdyzwVZ-bvqyp8H6WHE_K_24y1-sdPIohXPvdBZXIxjqMb2tDaeJLKbtz1mcoYDau_N-_5kVqVSeGtUYCA" | ||
} | ||
""" | ||
|
||
let orderStatusStringJSON = | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can this be a test vector? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. also, |
||
"{\"metadata\":{\"from\":\"did:dht:geiro75xjbn81snmangwc35wkfsra8mt3awbga8drrjde5z9r9jo\",\"to\":\"did:dht:n46hom5afi6xrsxmddx5rjecyyx1faz4ocs4ie43tfkyo4darh9y\",\"exchangeId\":\"rfq_01hrqn6pp1e48a3meq95dzmkzs\",\"protocol\":\"1.0\",\"kind\":\"orderstatus\",\"id\":\"orderstatus_01hrqn6pp1e48a3meq9b3brgta\",\"createdAt\":\"2024-03-11T21:02:55.681Z\"},\"data\":{\"orderStatus\":\"wee\"},\"signature\":\"eyJhbGciOiJFZERTQSIsImtpZCI6ImRpZDpkaHQ6Z2Vpcm83NXhqYm44MXNubWFuZ3djMzV3a2ZzcmE4bXQzYXdiZ2E4ZHJyamRlNXo5cjlqbyMwIn0..aHifNdyzwVZ-bvqyp8H6WHE_K_24y1-sdPIohXPvdBZXIxjqMb2tDaeJLKbtz1mcoYDau_N-_5kVqVSeGtUYCA\"}" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i want to understand how you expect this test to fail - are we calling this test function with 1 valid orderstatusJson and expecting it to never drop into the
else
assertion here?lining up multiple test cases and running them through tests to ensure what we want to see pass passes and what we want to see fail fails is how we've been approaching it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah i always do it that way. missed it going quickly here.