-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixing convert number functions for Longs #56
Changes from 3 commits
cbbb9c8
2249aa0
02cf83b
cbf8e31
bcaa590
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,7 +34,7 @@ data class InvoiceCurrency( | |
0 -> code = bytes.getString(offset.valueOffset(), length) | ||
1 -> name = bytes.getString(offset.valueOffset(), length) | ||
2 -> symbol = bytes.getString(offset.valueOffset(), length) | ||
3 -> decimals = bytes.getNumber(offset.valueOffset(), length) | ||
3 -> decimals = bytes.getInt(offset.valueOffset(), length) | ||
} | ||
offset = offset.valueOffset() + length | ||
} | ||
|
@@ -77,7 +77,7 @@ data class Invoice( | |
/** The currency of the invoice */ | ||
val receivingCurrency: InvoiceCurrency, | ||
/** The unix timestamp the UMA invoice expires */ | ||
val expiration: Int, | ||
val expiration: Number, | ||
/** Indicates whether the VASP is a financial institution that requires travel rule information. */ | ||
val isSubjectToTravelRule: Boolean, | ||
/** RequiredPayerData the data about the payer that the sending VASP must provide in order to send a payment. */ | ||
|
@@ -141,12 +141,12 @@ data class Invoice( | |
when (bytes[offset].toInt()) { | ||
0 -> ib.receiverUma = bytes.getString(offset.valueOffset(), length) | ||
1 -> ib.invoiceUUID = bytes.getString(offset.valueOffset(), length) | ||
2 -> ib.amount = bytes.getNumber(offset.valueOffset(), length) | ||
2 -> ib.amount = bytes.getInt(offset.valueOffset(), length) | ||
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. Should this be a long too? Could just see for units like msats, this could get pretty big. Not sure if @zhenlu was thinking of this as an int or long, though. I know it's a Long in UMA generally. |
||
3 -> | ||
ib.receivingCurrency = | ||
bytes.getTLV(offset.valueOffset(), length, InvoiceCurrency::fromTLV) as InvoiceCurrency | ||
|
||
4 -> ib.expiration = bytes.getNumber(offset.valueOffset(), length) | ||
4 -> ib.expiration = bytes.getLong(offset.valueOffset(), length) | ||
5 -> ib.isSubjectToTravelRule = bytes.getBoolean(offset.valueOffset()) | ||
6 -> | ||
ib.requiredPayerData = | ||
|
@@ -159,9 +159,9 @@ data class Invoice( | |
).options | ||
|
||
7 -> ib.umaVersion = bytes.getString(offset.valueOffset(), length) | ||
8 -> ib.commentCharsAllowed = bytes.getNumber(offset.valueOffset(), length) | ||
8 -> ib.commentCharsAllowed = bytes.getInt(offset.valueOffset(), length) | ||
9 -> ib.senderUma = bytes.getString(offset.valueOffset(), length) | ||
10 -> ib.invoiceLimit = bytes.getNumber(offset.valueOffset(), length) | ||
10 -> ib.invoiceLimit = bytes.getInt(offset.valueOffset(), length) | ||
11 -> | ||
ib.kycStatus = ( | ||
bytes.getByteCodeable( | ||
|
@@ -195,7 +195,7 @@ class InvoiceBuilder { | |
var invoiceUUID: String? = null | ||
var amount: Int? = null | ||
var receivingCurrency: InvoiceCurrency? = null | ||
var expiration: Int? = null | ||
var expiration: Number? = null | ||
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. Why use Number instead of Long directly? I think we're going to need to be explicit about 64-bit ints to be consistent, right? 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. converted all back to Int / Long, it's a bit clearer. during serialization, the values will be converted to their smallest possible representation, so Long fields might actually be serialized as small as a byte, but this detail is now better hidden inside of the getLong/getInt functions |
||
var isSubjectToTravelRule: Boolean? = null | ||
var requiredPayerData: CounterPartyDataOptions? = null | ||
var umaVersion: String? = null | ||
|
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) | ||
|
@@ -251,7 +260,7 @@ class UmaTests { | |
) | ||
} | ||
|
||
private fun createInvoice(): Invoice { | ||
private fun createInvoice(timestamp: Long? = null): Invoice { | ||
val requiredPayerData = | ||
mapOf( | ||
"name" to CounterPartyDataOption(false), | ||
|
@@ -271,7 +280,7 @@ class UmaTests { | |
invoiceUUID = "c7c07fec-cf00-431c-916f-6c13fc4b69f9", | ||
amount = 1000, | ||
receivingCurrency = invoiceCurrency, | ||
expiration = 1000000, | ||
expiration = timestamp ?: 1000000L, | ||
isSubjectToTravelRule = true, | ||
requiredPayerData = requiredPayerData, | ||
commentCharsAllowed = null, | ||
|
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.
This one should be a Long then, right?
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.
good catch, it should. I'll switch amount to long as well, to cover msat