-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixing convert number functions for Longs (#56)
# Long Serialization There was an issue serializing longs in UMA Invoices - most often, the expiration field is a long, since it represents a unix timestamp This change converts the field to a long and handles serialization/deserialization of said long
- Loading branch information
Showing
4 changed files
with
69 additions
and
32 deletions.
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 |
---|---|---|
|
@@ -48,6 +48,15 @@ class UmaTests { | |
validateInvoice(invoice, result) | ||
} | ||
|
||
@Test | ||
fun `correctly serialized timestamps in invoices`() = runTest { | ||
val timestamp = System.currentTimeMillis() | ||
val invoice = createInvoice(timestamp) | ||
val serializedInvoice = serialFormat.encodeToString(invoice) | ||
val result = serialFormat.decodeFromString<Invoice>(serializedInvoice) | ||
assertEquals(result.expiration, timestamp) | ||
} | ||
|
||
@Test | ||
fun `deserializing an Invoice with missing required fields triggers error`() = runTest { | ||
val exception = | ||
|
@@ -88,7 +97,7 @@ class UmaTests { | |
assertEquals("\$[email protected]", decodedInvoice.receiverUma) | ||
assertEquals("c7c07fec-cf00-431c-916f-6c13fc4b69f9", decodedInvoice.invoiceUUID) | ||
assertEquals(1000, decodedInvoice.amount) | ||
assertEquals(1000000, decodedInvoice.expiration) | ||
assertEquals(1000000L, decodedInvoice.expiration) | ||
assertEquals(true, decodedInvoice.isSubjectToTravelRule) | ||
assertEquals("0.3", decodedInvoice.umaVersion) | ||
assertEquals(KycStatus.VERIFIED, decodedInvoice.kycStatus) | ||
|
@@ -113,10 +122,9 @@ class UmaTests { | |
commentCharsAllowed = null, | ||
senderUma = null, | ||
invoiceLimit = null, | ||
umaVersion = "0.3", | ||
kycStatus = KycStatus.VERIFIED, | ||
callback = "https://example.com/callback", | ||
privateSigningKey = keys.privateKey | ||
privateSigningKey = keys.privateKey, | ||
) | ||
assertTrue(UmaProtocolHelper().verifyUmaInvoice(invoice, PubKeyResponse(keys.publicKey, keys.publicKey))) | ||
} | ||
|
@@ -136,12 +144,11 @@ class UmaTests { | |
utxoCallback = "https://example.com/utxo", | ||
travelRuleInfo = "travel rule info", | ||
travelRuleFormat = TravelRuleFormat("someFormat", "1.0"), | ||
requestedPayeeData = | ||
createCounterPartyDataOptions( | ||
"email" to true, | ||
"name" to false, | ||
"compliance" to true, | ||
), | ||
requestedPayeeData = createCounterPartyDataOptions( | ||
"email" to true, | ||
"name" to false, | ||
"compliance" to true, | ||
), | ||
receiverUmaVersion = "1.0", | ||
) | ||
assertTrue(payreq is PayRequestV1) | ||
|
@@ -251,7 +258,7 @@ class UmaTests { | |
) | ||
} | ||
|
||
private fun createInvoice(): Invoice { | ||
private fun createInvoice(timestamp: Long? = null): Invoice { | ||
val requiredPayerData = | ||
mapOf( | ||
"name" to CounterPartyDataOption(false), | ||
|
@@ -269,9 +276,9 @@ class UmaTests { | |
return Invoice( | ||
receiverUma = "\$[email protected]", | ||
invoiceUUID = "c7c07fec-cf00-431c-916f-6c13fc4b69f9", | ||
amount = 1000, | ||
amount = 1000L, | ||
receivingCurrency = invoiceCurrency, | ||
expiration = 1000000, | ||
expiration = timestamp ?: 1000000L, | ||
isSubjectToTravelRule = true, | ||
requiredPayerData = requiredPayerData, | ||
commentCharsAllowed = null, | ||
|