Format the transaction window fee rate with 1 decimal place (#4286)
* Fix format_satoshi to properly handle non-integer values Handling the integer and fraction parts together via string formatting simplifies the initial composition because the default behavior manages the - sign, and the incorporation of the fractional part. * Limit fee rate output to one decimal place Via a new precision arg * Introduce format_fee_satoshis and use it for all fee display
This commit is contained in:
@@ -8,6 +8,43 @@ class TestUtil(unittest.TestCase):
|
||||
expected = "0.00001234"
|
||||
self.assertEqual(expected, result)
|
||||
|
||||
def test_format_satoshis_negative(self):
|
||||
result = format_satoshis(-1234)
|
||||
expected = "-0.00001234"
|
||||
self.assertEqual(expected, result)
|
||||
|
||||
def test_format_fee(self):
|
||||
result = format_satoshis(1700/1000, 0, 0)
|
||||
expected = "1.7"
|
||||
self.assertEqual(expected, result)
|
||||
|
||||
def test_format_fee_precision(self):
|
||||
result = format_satoshis(1666/1000, 0, 0, precision=6)
|
||||
expected = "1.666"
|
||||
self.assertEqual(expected, result)
|
||||
|
||||
result = format_satoshis(1666/1000, 0, 0, precision=1)
|
||||
expected = "1.7"
|
||||
self.assertEqual(expected, result)
|
||||
|
||||
def test_format_satoshis_whitespaces(self):
|
||||
result = format_satoshis(12340, whitespaces=True)
|
||||
expected = " 0.0001234 "
|
||||
self.assertEqual(expected, result)
|
||||
|
||||
result = format_satoshis(1234, whitespaces=True)
|
||||
expected = " 0.00001234"
|
||||
self.assertEqual(expected, result)
|
||||
|
||||
def test_format_satoshis_whitespaces_negative(self):
|
||||
result = format_satoshis(-12340, whitespaces=True)
|
||||
expected = " -0.0001234 "
|
||||
self.assertEqual(expected, result)
|
||||
|
||||
result = format_satoshis(-1234, whitespaces=True)
|
||||
expected = " -0.00001234"
|
||||
self.assertEqual(expected, result)
|
||||
|
||||
def test_format_satoshis_diff_positive(self):
|
||||
result = format_satoshis(1234, is_diff=True)
|
||||
expected = "+0.00001234"
|
||||
@@ -67,4 +104,3 @@ class TestUtil(unittest.TestCase):
|
||||
|
||||
def test_parse_URI_parameter_polution(self):
|
||||
self.assertRaises(Exception, parse_URI, 'bitcoin:15mKKb2eos1hWa6tisdPwwDC1a5J1y9nma?amount=0.0003&label=test&amount=30.0')
|
||||
|
||||
|
||||
Reference in New Issue
Block a user