2017-12-27 11:48:05 +00:00
|
|
|
from common import *
|
|
|
|
from apps.ethereum.layout import format_amount
|
|
|
|
|
|
|
|
|
|
|
|
class TestEthereumLayout(unittest.TestCase):
|
|
|
|
|
|
|
|
def test_format(self):
|
2018-01-13 14:40:04 +00:00
|
|
|
text = format_amount((1).to_bytes(5, 'big'), None, 1)
|
2017-12-27 11:48:05 +00:00
|
|
|
self.assertEqual(text, '1 Wei')
|
2018-01-13 14:40:04 +00:00
|
|
|
text = format_amount((1000).to_bytes(5, 'big'), None, 1)
|
2017-12-27 11:48:05 +00:00
|
|
|
self.assertEqual(text, '1000 Wei')
|
|
|
|
|
2018-01-13 14:40:04 +00:00
|
|
|
text = format_amount((1000000000000000001).to_bytes(20, 'big'), None, 1)
|
2017-12-27 11:48:05 +00:00
|
|
|
self.assertEqual(text, '1 ETH')
|
2018-01-13 14:40:04 +00:00
|
|
|
text = format_amount((10000000000000000001).to_bytes(20, 'big'), None, 1)
|
2017-12-27 11:48:05 +00:00
|
|
|
self.assertEqual(text, '10 ETH')
|
2018-01-13 14:40:04 +00:00
|
|
|
text = format_amount((10000000000000000001).to_bytes(20, 'big'), None, 61)
|
2017-12-27 11:48:05 +00:00
|
|
|
self.assertEqual(text, '10 ETC')
|
2018-01-13 14:40:04 +00:00
|
|
|
text = format_amount((1000000000000000001).to_bytes(20, 'big'), None, 31)
|
2017-12-27 11:48:05 +00:00
|
|
|
self.assertEqual(text, '1 tRSK')
|
|
|
|
|
|
|
|
# unknown chain
|
2018-01-13 14:40:04 +00:00
|
|
|
text = format_amount((1).to_bytes(20, 'big'), None, 9999)
|
2017-12-27 11:48:05 +00:00
|
|
|
self.assertEqual(text, '1 Wei')
|
2018-01-13 14:40:04 +00:00
|
|
|
text = format_amount((10000000000000000001).to_bytes(20, 'big'), None, 9999)
|
2017-12-27 11:48:05 +00:00
|
|
|
self.assertEqual(text, '10 UNKN')
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
unittest.main()
|