2017-12-27 11:48:05 +00:00
|
|
|
from common import *
|
2018-02-09 12:36:08 +00:00
|
|
|
from apps.ethereum.layout import format_ethereum_amount
|
2017-12-27 11:48:05 +00:00
|
|
|
|
|
|
|
|
|
|
|
class TestEthereumLayout(unittest.TestCase):
|
|
|
|
|
|
|
|
def test_format(self):
|
2018-03-09 15:12:17 +00:00
|
|
|
text = format_ethereum_amount(1, None, 1)
|
2018-03-03 22:37:21 +00:00
|
|
|
self.assertEqual(text, '1 Wei ETH')
|
2018-03-09 15:12:17 +00:00
|
|
|
text = format_ethereum_amount(1000, None, 1)
|
2018-03-03 22:37:21 +00:00
|
|
|
self.assertEqual(text, '1000 Wei ETH')
|
2018-03-09 15:12:17 +00:00
|
|
|
text = format_ethereum_amount(1000000, None, 1)
|
2018-03-03 22:37:21 +00:00
|
|
|
self.assertEqual(text, '1000000 Wei ETH')
|
2018-03-09 15:12:17 +00:00
|
|
|
text = format_ethereum_amount(10000000, None, 1)
|
2018-03-03 22:37:21 +00:00
|
|
|
self.assertEqual(text, '10000000 Wei ETH')
|
2018-03-09 15:12:17 +00:00
|
|
|
text = format_ethereum_amount(100000000, None, 1)
|
2018-03-03 22:37:21 +00:00
|
|
|
self.assertEqual(text, '100000000 Wei ETH')
|
2018-03-09 15:12:17 +00:00
|
|
|
text = format_ethereum_amount(1000000000, None, 1)
|
2018-03-03 22:37:21 +00:00
|
|
|
self.assertEqual(text, '1000000000 Wei ETH')
|
2018-03-09 15:12:17 +00:00
|
|
|
text = format_ethereum_amount(10000000000, None, 1)
|
2018-03-03 22:37:21 +00:00
|
|
|
self.assertEqual(text, '0.00000001 ETH')
|
2018-03-09 15:12:17 +00:00
|
|
|
text = format_ethereum_amount(100000000000, None, 1)
|
2018-03-03 22:37:21 +00:00
|
|
|
self.assertEqual(text, '0.0000001 ETH')
|
2018-03-09 15:12:17 +00:00
|
|
|
text = format_ethereum_amount(1000000000000, None, 1)
|
2018-03-03 22:37:21 +00:00
|
|
|
self.assertEqual(text, '0.000001 ETH')
|
2018-03-09 15:12:17 +00:00
|
|
|
text = format_ethereum_amount(10000000000000, None, 1)
|
2018-03-03 22:37:21 +00:00
|
|
|
self.assertEqual(text, '0.00001 ETH')
|
2018-03-09 15:12:17 +00:00
|
|
|
text = format_ethereum_amount(100000000000000, None, 1)
|
2018-03-03 22:37:21 +00:00
|
|
|
self.assertEqual(text, '0.0001 ETH')
|
2018-03-09 15:12:17 +00:00
|
|
|
text = format_ethereum_amount(1000000000000000, None, 1)
|
2018-03-03 22:37:21 +00:00
|
|
|
self.assertEqual(text, '0.001 ETH')
|
2018-03-09 15:12:17 +00:00
|
|
|
text = format_ethereum_amount(10000000000000000, None, 1)
|
2018-03-03 22:37:21 +00:00
|
|
|
self.assertEqual(text, '0.01 ETH')
|
2018-03-09 15:12:17 +00:00
|
|
|
text = format_ethereum_amount(100000000000000000, None, 1)
|
2018-03-03 22:37:21 +00:00
|
|
|
self.assertEqual(text, '0.1 ETH')
|
2018-03-09 15:12:17 +00:00
|
|
|
text = format_ethereum_amount(1000000000000000000, None, 1)
|
2017-12-27 11:48:05 +00:00
|
|
|
self.assertEqual(text, '1 ETH')
|
2018-03-09 15:12:17 +00:00
|
|
|
text = format_ethereum_amount(10000000000000000000, None, 1)
|
2017-12-27 11:48:05 +00:00
|
|
|
self.assertEqual(text, '10 ETH')
|
2018-03-09 15:12:17 +00:00
|
|
|
text = format_ethereum_amount(100000000000000000000, None, 1)
|
2018-03-03 22:37:21 +00:00
|
|
|
self.assertEqual(text, '100 ETH')
|
2018-03-09 15:12:17 +00:00
|
|
|
text = format_ethereum_amount(1000000000000000000000, None, 1)
|
2018-03-03 22:37:21 +00:00
|
|
|
self.assertEqual(text, '1000 ETH')
|
|
|
|
|
2018-03-09 15:12:17 +00:00
|
|
|
text = format_ethereum_amount(1000000000000000000, None, 61)
|
2018-03-03 22:37:21 +00:00
|
|
|
self.assertEqual(text, '1 ETC')
|
2018-03-09 15:12:17 +00:00
|
|
|
text = format_ethereum_amount(1000000000000000000, None, 31)
|
2018-12-05 14:38:49 +00:00
|
|
|
self.assertEqual(text, '1 tRBTC')
|
2017-12-27 11:48:05 +00:00
|
|
|
|
2018-03-09 15:12:17 +00:00
|
|
|
text = format_ethereum_amount(1000000000000000001, None, 1)
|
2018-02-09 12:36:08 +00:00
|
|
|
self.assertEqual(text, '1.000000000000000001 ETH')
|
2018-03-09 15:12:17 +00:00
|
|
|
text = format_ethereum_amount(10000000000000000001, None, 1)
|
2018-02-09 12:36:08 +00:00
|
|
|
self.assertEqual(text, '10.000000000000000001 ETH')
|
2018-03-09 15:12:17 +00:00
|
|
|
text = format_ethereum_amount(10000000000000000001, None, 61)
|
2018-02-09 12:36:08 +00:00
|
|
|
self.assertEqual(text, '10.000000000000000001 ETC')
|
2018-03-09 15:12:17 +00:00
|
|
|
text = format_ethereum_amount(1000000000000000001, None, 31)
|
2018-12-05 14:38:49 +00:00
|
|
|
self.assertEqual(text, '1.000000000000000001 tRBTC')
|
2018-02-09 12:36:08 +00:00
|
|
|
|
2017-12-27 11:48:05 +00:00
|
|
|
# unknown chain
|
2018-03-09 15:12:17 +00:00
|
|
|
text = format_ethereum_amount(1, None, 9999)
|
2018-03-03 22:37:21 +00:00
|
|
|
self.assertEqual(text, '1 Wei UNKN')
|
2018-03-09 15:12:17 +00:00
|
|
|
text = format_ethereum_amount(10000000000000000001, None, 9999)
|
2018-02-09 12:36:08 +00:00
|
|
|
self.assertEqual(text, '10.000000000000000001 UNKN')
|
2017-12-27 11:48:05 +00:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
unittest.main()
|