def test_compareto_valid(self): u1 = UInt160(b'12345678901234567890') # Same value should return 0 u2 = UIntBase(20, b'12345678901234567890') self.assertEqual(u1.CompareTo(u2), 0) # Higher digit in 'other' should return -1 u2 = UIntBase(20, b'12345678901234567891') self.assertEqual(u1.CompareTo(u2), -1) # Lower digit in 'other' should return 1 u2 = UIntBase(20, b'12345678901234567980') self.assertEqual(u1.CompareTo(u2), 1) # CompareTo across different UIntBase subclasses data = b'12345678901234567890' self.assertEqual(UInt160(data).CompareTo(UIntBase(len(data), data)), 0) self.assertEqual(UIntBase(len(data), data).CompareTo(UInt160(data)), 0) data = b'12345678901234567890123456789012' self.assertEqual(UInt256(data).CompareTo(UIntBase(len(data), data)), 0) self.assertEqual(UIntBase(len(data), data).CompareTo(UInt256(data)), 0)
def test_hash_code(self): x = UIntBase(num_bytes=4, data=bytearray.fromhex('DEADBEEF')) self.assertEqual(x.GetHashCode(), 4022250974) x = UIntBase(num_bytes=2, data=bytearray.fromhex('1122')) self.assertEqual(x.GetHashCode(), 8721)
def test_tobytes(self): u1 = UIntBase(3, b'abc') self.assertEqual(u1.ToBytes(), b'636261')
def test_to0xstring(self): u1 = UIntBase(3, b'abc') self.assertEqual(u1.To0xString(), '0x636261')
def test_tostring2(self): u1 = UIntBase(3, b'abc') self.assertEqual(u1.ToString2(), '616263')
def test_str(self): u1 = UIntBase(3, b'abc') self.assertEqual(str(u1), '636261')
def test_toarray(self): data = b'abc' u1 = UIntBase(3, data) self.assertEqual(u1.ToArray(), data)
def test_size(self): u1 = UIntBase(3, bytearray(b'abc')) self.assertEqual(u1.Size, 3)
def test_initialization_with_invalid_datatype(self): with self.assertRaises(TypeError): UIntBase(3, 'abc')
def test_initialization_with_invalid_datalen(self): with self.assertRaises(ValueError): UIntBase(3, bytearray(b'abcd'))
def test_initialization_with_bytearray(self): u1 = UIntBase(3, bytearray(b'abc')) self.assertEqual(hash(u1), 6513249)