-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Clean LnInvoiceUtils and add tests (#107)
- Loading branch information
Showing
2 changed files
with
67 additions
and
3 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
64 changes: 64 additions & 0 deletions
64
app/src/test/kotlin/net/primal/android/wallet/utils/LnInvoiceUtilsTest.kt
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 |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package net.primal.android.wallet.utils | ||
|
||
import io.kotest.matchers.shouldBe | ||
import org.junit.Test | ||
|
||
class LnInvoiceUtilsTest { | ||
|
||
private val validLnInvoice = | ||
"lnbc123450n1pj7welppp53umfyxp6jn9uvkt463hydtq2zpfvz78hxhpfv9wqx6v4uwdw2rnqdzqg3hkuct5v56zu3n4dcsxgmmwv96x" + | ||
"jmmwyp6x7gzqgpc8ymmrv4h8ghmrwfuhqar0cqzpgxqrrsssp5tntqjpngx6l8y9va9tzd7fmtemtyp5vvsqphw8f8yqjjrr26x5qs9" + | ||
"qyyssqyyv7tqp5kpsmv6s5825kcq8fxsn4ag2h5uj2j6lnsnclyyq6844khayzqrl7yue46nwlukfr4uftqcwzxzh8krqg9rqsg9tg6x" + | ||
"ggszcp0gyjcd" | ||
|
||
private val invoiceInvalidCharacter = | ||
"lnbc123450n1pj7welpp 53umfyxp6jn9uvkt463hydtq2zpfvz78hxhpfv9wqx6v4uwdw2rnqdzqg3hkuct5v56zu3n4dcsxgmmwv96x" + | ||
"jmmwyp6x7gzqgpc8ymmrv4h8ghmrwfuhqar0cqzpgxqrrsssp5tntqjpngx6l8y9va9tzd7fmtemtyp5vvsqphw8f8yqjjrr26x5qs9" + | ||
"qyyssqyyv7tqp5kpsmv6s5825kcq8fxsn4ag2h5uj2j6lnsnclyyq6844khayzqrl7yue46nwlukfr4uftqcwzxzh8krqg9rqsg9tg6" + | ||
"xggszcp0gyjcd" | ||
|
||
private val invalidLnInvoice = | ||
"lnbc123450n1pj7welppp53umfyxp6jn9uvkt463hydtq2zpfvz78hxhpfv9wqx6v4uwdw2rnqdzqg3hkuct5v56zu3n4dcsxgmmwv96x" + | ||
"jmmwyp6x7gzqgpc8ymmrv4h8ghmrwXuhqar0cqzpgxqrrsssp5tntqjpngx6l8y9va9tzd7fmtemtyp5vvsqphw8f8yqjjrr26x5qs9" + | ||
"qyyssqyyv7tqp5kpsmv6s5825kcq8fxsn4ag2h5uj2j6lnsnclyyq6844khayzqrl7yue46nwlukfr4uftqcwzxzh8krqg9rqsg9tg6x" + | ||
"ggszcp0gyjcd" | ||
|
||
private val validLnInvoiceNoAmount = | ||
"lnbc1pvjluezpp5qqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqypqdpl2pkx2ctnv5sxxmmwwd5kgetjypeh2ursdae8g" + | ||
"6twvus8g6rfwvs8qun0dfjkxaq8rkx3yf5tcsyz3d73gafnh3cax9rn449d9p5uxz9ezhhypd0elx87sjle52x86fux2ypatgddc6k6" + | ||
"3n7erqz25le42c4u4ecky03ylcqca784w" | ||
|
||
@Test | ||
fun getAmountInSatsValidInvoice() { | ||
val expectedValue = 12345 | ||
|
||
val amount = LnInvoiceUtils.getAmountInSats(validLnInvoice) | ||
|
||
amount.toInt() shouldBe expectedValue | ||
|
||
} | ||
|
||
@Test | ||
fun getAmountInSatsValidInvoiceNoAmount() { | ||
val expectedValue = 0 | ||
|
||
val amount = LnInvoiceUtils.getAmountInSats(validLnInvoiceNoAmount) | ||
|
||
amount.toInt() shouldBe expectedValue | ||
|
||
} | ||
|
||
@Test(expected = IllegalArgumentException::class) | ||
fun getAmountInSatsInvalidInvoice() { | ||
|
||
LnInvoiceUtils.getAmountInSats(invalidLnInvoice) | ||
|
||
} | ||
|
||
@Test(expected = IllegalArgumentException::class) | ||
fun getAmountInSatsInvalidCharacter() { | ||
|
||
LnInvoiceUtils.getAmountInSats(invoiceInvalidCharacter) | ||
|
||
} | ||
} |