wownero-python/tests/numbers.py
2018-01-07 01:26:30 +01:00

39 lines
1.6 KiB
Python

from decimal import Decimal
import unittest
from monero.numbers import to_atomic, from_atomic, PaymentID
class NumbersTestCase(unittest.TestCase):
def test_simple_numbers(self):
self.assertEqual(to_atomic(Decimal('0')), 0)
self.assertEqual(from_atomic(0), Decimal('0'))
self.assertEqual(to_atomic(Decimal('1')), 1000000000000)
self.assertEqual(from_atomic(1000000000000), Decimal('1'))
self.assertEqual(to_atomic(Decimal('0.000000000001')), 1)
self.assertEqual(from_atomic(1), Decimal('0.000000000001'))
def test_rounding(self):
self.assertEqual(to_atomic(Decimal('1.0000000000004')), 1000000000000)
def test_payment_id(self):
pid = PaymentID('0')
self.assertTrue(pid.is_short())
self.assertEqual(pid, 0)
self.assertEqual(pid, '0000000000000000')
self.assertEqual(PaymentID(pid), pid)
pid = PaymentID('abcdef')
self.assertTrue(pid.is_short())
self.assertEqual(pid, 0xabcdef)
self.assertEqual(pid, '0000000000abcdef')
self.assertEqual(PaymentID(pid), pid)
pid = PaymentID('1234567812345678')
self.assertTrue(pid.is_short())
self.assertEqual(pid, 0x1234567812345678)
self.assertEqual(pid, '1234567812345678')
self.assertEqual(PaymentID(pid), pid)
pid = PaymentID('a1234567812345678')
self.assertFalse(pid.is_short())
self.assertEqual(pid, 0xa1234567812345678)
self.assertEqual(pid, '00000000000000000000000000000000000000000000000a1234567812345678')
self.assertEqual(PaymentID(pid), pid)
self.assertRaises(ValueError, PaymentID, 2**256+1)