mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-01-11 16:00:57 +00:00
tests: fix test_apps.ethereum.layout
This commit is contained in:
parent
9aa947d2e1
commit
b0242d3a3e
@ -32,5 +32,5 @@ def format_amount(amount, decimals):
|
||||
d = pow(10, decimals)
|
||||
amount = ('%d.%0*d' % (amount // d, decimals, amount % d)).rstrip('0')
|
||||
if amount.endswith('.'):
|
||||
amount += '0'
|
||||
amount = amount[:-1]
|
||||
return amount
|
||||
|
@ -1,29 +1,38 @@
|
||||
from common import *
|
||||
from apps.ethereum.layout import format_amount
|
||||
from apps.ethereum.layout import format_ethereum_amount
|
||||
|
||||
|
||||
class TestEthereumLayout(unittest.TestCase):
|
||||
|
||||
def test_format(self):
|
||||
text = format_amount((1).to_bytes(5, 'big'), None, 1)
|
||||
text = format_ethereum_amount((1).to_bytes(5, 'big'), None, 1)
|
||||
self.assertEqual(text, '1 Wei')
|
||||
text = format_amount((1000).to_bytes(5, 'big'), None, 1)
|
||||
text = format_ethereum_amount((1000).to_bytes(5, 'big'), None, 1)
|
||||
self.assertEqual(text, '1000 Wei')
|
||||
|
||||
text = format_amount((1000000000000000001).to_bytes(20, 'big'), None, 1)
|
||||
text = format_ethereum_amount((1000000000000000000).to_bytes(20, 'big'), None, 1)
|
||||
self.assertEqual(text, '1 ETH')
|
||||
text = format_amount((10000000000000000001).to_bytes(20, 'big'), None, 1)
|
||||
text = format_ethereum_amount((10000000000000000000).to_bytes(20, 'big'), None, 1)
|
||||
self.assertEqual(text, '10 ETH')
|
||||
text = format_amount((10000000000000000001).to_bytes(20, 'big'), None, 61)
|
||||
text = format_ethereum_amount((10000000000000000000).to_bytes(20, 'big'), None, 61)
|
||||
self.assertEqual(text, '10 ETC')
|
||||
text = format_amount((1000000000000000001).to_bytes(20, 'big'), None, 31)
|
||||
text = format_ethereum_amount((1000000000000000000).to_bytes(20, 'big'), None, 31)
|
||||
self.assertEqual(text, '1 tRSK')
|
||||
|
||||
text = format_ethereum_amount((1000000000000000001).to_bytes(20, 'big'), None, 1)
|
||||
self.assertEqual(text, '1.000000000000000001 ETH')
|
||||
text = format_ethereum_amount((10000000000000000001).to_bytes(20, 'big'), None, 1)
|
||||
self.assertEqual(text, '10.000000000000000001 ETH')
|
||||
text = format_ethereum_amount((10000000000000000001).to_bytes(20, 'big'), None, 61)
|
||||
self.assertEqual(text, '10.000000000000000001 ETC')
|
||||
text = format_ethereum_amount((1000000000000000001).to_bytes(20, 'big'), None, 31)
|
||||
self.assertEqual(text, '1.000000000000000001 tRSK')
|
||||
|
||||
# unknown chain
|
||||
text = format_amount((1).to_bytes(20, 'big'), None, 9999)
|
||||
text = format_ethereum_amount((1).to_bytes(20, 'big'), None, 9999)
|
||||
self.assertEqual(text, '1 Wei')
|
||||
text = format_amount((10000000000000000001).to_bytes(20, 'big'), None, 9999)
|
||||
self.assertEqual(text, '10 UNKN')
|
||||
text = format_ethereum_amount((10000000000000000001).to_bytes(20, 'big'), None, 9999)
|
||||
self.assertEqual(text, '10.000000000000000001 UNKN')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
Loading…
Reference in New Issue
Block a user