@@ -30,7 +30,7 @@ final class XcodeSignedDataVerifierTests: XCTestCase {
3030 XCTAssertNil ( appTransaction. preorderDate)
3131 XCTAssertEqual ( . xcode, appTransaction. receiptType)
3232 XCTAssertEqual ( " Xcode " , appTransaction. rawReceiptType)
33- TestingUtility . confirmCodableInternallyConsistent ( appTransaction)
33+ confirmCodableInternallyConsistentForXcode ( appTransaction)
3434 }
3535
3636 public func testXcodeSignedTransaction( ) async throws {
@@ -72,7 +72,7 @@ final class XcodeSignedDataVerifierTests: XCTestCase {
7272 XCTAssertEqual ( " 143441 " , transaction. storefrontId)
7373 XCTAssertEqual ( TransactionReason . purchase, transaction. transactionReason)
7474 XCTAssertEqual ( " PURCHASE " , transaction. rawTransactionReason)
75- TestingUtility . confirmCodableInternallyConsistent ( transaction)
75+ confirmCodableInternallyConsistentForXcode ( transaction)
7676 }
7777
7878 public func testXcodeSignedRenewalInfo( ) async throws {
@@ -102,7 +102,7 @@ final class XcodeSignedDataVerifierTests: XCTestCase {
102102 XCTAssertEqual ( " Xcode " , renewalInfo. rawEnvironment)
103103 compareXcodeDates ( Date ( timeIntervalSince1970: 1697679936.049 ) , renewalInfo. recentSubscriptionStartDate)
104104 compareXcodeDates ( Date ( timeIntervalSince1970: 1700358336.049 ) , renewalInfo. renewalDate)
105- TestingUtility . confirmCodableInternallyConsistent ( renewalInfo)
105+ confirmCodableInternallyConsistentForXcode ( renewalInfo)
106106 }
107107
108108 public func testXcodeSignedAppTransactionWithProductionEnvironment( ) async throws {
@@ -122,4 +122,13 @@ final class XcodeSignedDataVerifierTests: XCTestCase {
122122 private func compareXcodeDates( _ first: Date , _ second: Date ? ) {
123123 XCTAssertEqual ( floor ( ( first. timeIntervalSince1970 * 1000 ) ) , floor ( ( ( second? . timeIntervalSince1970 ?? 0.0 ) * 1000 ) ) )
124124 }
125+
126+ private func confirmCodableInternallyConsistentForXcode< T> ( _ codable: T ) where T : Codable , T : Equatable {
127+ let type = type ( of: codable)
128+ let encoder = JSONEncoder ( )
129+ // Xcode receipts contain a decimal value, we encode the value as encoded in those receipts
130+ encoder. dateEncodingStrategy = . millisecondsSince1970
131+ let parsedValue = try ! getJsonDecoder ( ) . decode ( type, from: encoder. encode ( codable) )
132+ XCTAssertEqual ( parsedValue, codable)
133+ }
125134}
0 commit comments