@@ -30,7 +30,7 @@ final class XcodeSignedDataVerifierTests: XCTestCase {
30
30
XCTAssertNil ( appTransaction. preorderDate)
31
31
XCTAssertEqual ( . xcode, appTransaction. receiptType)
32
32
XCTAssertEqual ( " Xcode " , appTransaction. rawReceiptType)
33
- TestingUtility . confirmCodableInternallyConsistent ( appTransaction)
33
+ confirmCodableInternallyConsistentForXcode ( appTransaction)
34
34
}
35
35
36
36
public func testXcodeSignedTransaction( ) async throws {
@@ -72,7 +72,7 @@ final class XcodeSignedDataVerifierTests: XCTestCase {
72
72
XCTAssertEqual ( " 143441 " , transaction. storefrontId)
73
73
XCTAssertEqual ( TransactionReason . purchase, transaction. transactionReason)
74
74
XCTAssertEqual ( " PURCHASE " , transaction. rawTransactionReason)
75
- TestingUtility . confirmCodableInternallyConsistent ( transaction)
75
+ confirmCodableInternallyConsistentForXcode ( transaction)
76
76
}
77
77
78
78
public func testXcodeSignedRenewalInfo( ) async throws {
@@ -102,7 +102,7 @@ final class XcodeSignedDataVerifierTests: XCTestCase {
102
102
XCTAssertEqual ( " Xcode " , renewalInfo. rawEnvironment)
103
103
compareXcodeDates ( Date ( timeIntervalSince1970: 1697679936.049 ) , renewalInfo. recentSubscriptionStartDate)
104
104
compareXcodeDates ( Date ( timeIntervalSince1970: 1700358336.049 ) , renewalInfo. renewalDate)
105
- TestingUtility . confirmCodableInternallyConsistent ( renewalInfo)
105
+ confirmCodableInternallyConsistentForXcode ( renewalInfo)
106
106
}
107
107
108
108
public func testXcodeSignedAppTransactionWithProductionEnvironment( ) async throws {
@@ -122,4 +122,13 @@ final class XcodeSignedDataVerifierTests: XCTestCase {
122
122
private func compareXcodeDates( _ first: Date , _ second: Date ? ) {
123
123
XCTAssertEqual ( floor ( ( first. timeIntervalSince1970 * 1000 ) ) , floor ( ( ( second? . timeIntervalSince1970 ?? 0.0 ) * 1000 ) ) )
124
124
}
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
+ }
125
134
}
0 commit comments