mirror of
https://github.com/bitcoin-s/bitcoin-s.git
synced 2025-02-24 06:57:51 +01:00
Fix MilliSatoshis.toSatoshis for large values (#5016)
This commit is contained in:
parent
df5472f263
commit
5e6cb0d514
2 changed files with 14 additions and 1 deletions
|
@ -1,5 +1,6 @@
|
|||
package org.bitcoins.core.protocol.ln.currency
|
||||
|
||||
import org.bitcoins.core.currency.Satoshis
|
||||
import org.bitcoins.testkitcore.gen.ln.LnCurrencyUnitGen
|
||||
import org.bitcoins.testkitcore.gen.{CurrencyUnitGenerator, NumberGenerator}
|
||||
import org.bitcoins.testkitcore.util.BitcoinSUnitTest
|
||||
|
@ -25,6 +26,18 @@ class MilliSatoshisTest extends BitcoinSUnitTest {
|
|||
MilliSatoshis.fromPico(PicoBitcoins(110)) must be(MilliSatoshis(11))
|
||||
}
|
||||
|
||||
it must "convert msat to sat correctly" in {
|
||||
MilliSatoshis(0).toSatoshis must be(Satoshis.zero)
|
||||
MilliSatoshis(1).toSatoshis must be(Satoshis.zero)
|
||||
MilliSatoshis(999).toSatoshis must be(Satoshis.zero)
|
||||
MilliSatoshis(1000).toSatoshis must be(Satoshis.one)
|
||||
MilliSatoshis(1001).toSatoshis must be(Satoshis.one)
|
||||
MilliSatoshis(10000).toSatoshis must be(Satoshis(10))
|
||||
|
||||
val max = Satoshis.max
|
||||
MilliSatoshis.fromSatoshis(max).toSatoshis must be(max)
|
||||
}
|
||||
|
||||
it must "add millisatoshis" in {
|
||||
forAll(LnCurrencyUnitGen.milliSatoshisPair) { case (first, second) =>
|
||||
val bigInt = first.toBigInt + second.toBigInt
|
||||
|
|
|
@ -113,7 +113,7 @@ sealed abstract class MilliSatoshis
|
|||
}
|
||||
|
||||
def toSatoshis: Satoshis = {
|
||||
toLnCurrencyUnit.toSatoshis
|
||||
Satoshis(underlying / 1000)
|
||||
}
|
||||
|
||||
override def bytes: ByteVector = toUInt64.bytes.reverse
|
||||
|
|
Loading…
Add table
Reference in a new issue