mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-01-18 05:12:45 +01:00
pyln: failing test msat from float str
We were not able to create pyln Millisatoshi from floats, e.g.: - "0.01btc" - "0.1sat" - ... This adds a test that makes sure this won't happen again.
This commit is contained in:
parent
83a21138b8
commit
7bfb5f10c7
@ -1,4 +1,5 @@
|
|||||||
from pyln.client import Millisatoshi
|
from pyln.client import Millisatoshi
|
||||||
|
import pytest # type: ignore
|
||||||
|
|
||||||
|
|
||||||
def test_to_approx_str():
|
def test_to_approx_str():
|
||||||
@ -34,3 +35,29 @@ def test_to_approx_str():
|
|||||||
assert amount.to_approx_str() == "12btc"
|
assert amount.to_approx_str() == "12btc"
|
||||||
amount = Millisatoshi('1200000000sat')
|
amount = Millisatoshi('1200000000sat')
|
||||||
assert amount.to_approx_str(1) == "12btc" # note: no rounding
|
assert amount.to_approx_str(1) == "12btc" # note: no rounding
|
||||||
|
|
||||||
|
|
||||||
|
def test_floats():
|
||||||
|
# test parsing amounts from floating number strings
|
||||||
|
amount = Millisatoshi("0.01btc")
|
||||||
|
assert amount.to_satoshi() == 10**6
|
||||||
|
amount = Millisatoshi("1.01btc")
|
||||||
|
assert amount.to_satoshi() == 10**8 + 10**6
|
||||||
|
amount = Millisatoshi("0.1sat")
|
||||||
|
assert int(amount) == 100
|
||||||
|
amount = Millisatoshi("0.01sat")
|
||||||
|
assert int(amount) == 10
|
||||||
|
amount = Millisatoshi("1.1sat")
|
||||||
|
assert int(amount) == 1100
|
||||||
|
|
||||||
|
# test floating point arithmetic
|
||||||
|
amount = Millisatoshi("1000msat") * 0.1
|
||||||
|
assert int(amount) == 100
|
||||||
|
|
||||||
|
# sub millisatoshi are not a concept yet
|
||||||
|
with pytest.raises(ValueError, match='Millisatoshi must be a whole number'):
|
||||||
|
amount = Millisatoshi("0.000000000001btc")
|
||||||
|
with pytest.raises(ValueError, match='Millisatoshi must be a whole number'):
|
||||||
|
amount = Millisatoshi("0.0001sat")
|
||||||
|
with pytest.raises(ValueError, match='Millisatoshi must be a whole number'):
|
||||||
|
amount = Millisatoshi("0.1msat")
|
||||||
|
Loading…
Reference in New Issue
Block a user