|
1 | 1 | from unittest import TestCase
|
2 | 2 |
|
3 |
| -from fastecdsa.curve import W25519 |
4 |
| -from fastecdsa.point import Point |
| 3 | +from fastecdsa.curve import P256, W25519 |
| 4 | +from fastecdsa.point import CurveMismatchError, Point |
5 | 5 |
|
6 | 6 |
|
7 |
| -class TestTypeValidation(TestCase): |
| 7 | +class TestPoint(TestCase): |
| 8 | + def test_init_invalid_coordinates_point(self): |
| 9 | + with self.assertRaises(ValueError): |
| 10 | + Point(0, 1, P256) |
| 11 | + |
| 12 | + def test_add_different_curves(self): |
| 13 | + with self.assertRaises(CurveMismatchError): |
| 14 | + P256.G + W25519.G |
| 15 | + |
| 16 | + def test_str_reprs(self): |
| 17 | + expected = ( |
| 18 | + "X: 0x6b17d1f2e12c4247f8bce6e563a440f277037d812deb33a0f4a13945d898c296\n" |
| 19 | + "Y: 0x4fe342e2fe1a7f9b8ee7eb4a7c0f9e162bce33576b315ececbb6406837bf51f5\n" |
| 20 | + "(On curve <P256>)" |
| 21 | + ) |
| 22 | + |
| 23 | + self.assertEqual(expected, str(P256.G)) |
| 24 | + self.assertEqual(expected, repr(P256.G)) |
| 25 | + |
| 26 | + self.assertEqual("<POINT AT INFINITY>", str(Point._identity_element())) |
| 27 | + self.assertEqual("<POINT AT INFINITY>", repr(Point._identity_element())) |
| 28 | + |
| 29 | + def test_eq(self): |
| 30 | + self.assertTrue(P256.G == P256.G) |
| 31 | + self.assertFalse(P256.G == W25519.G) |
| 32 | + |
| 33 | + with self.assertRaises(TypeError): |
| 34 | + P256.G == 2 |
| 35 | + |
| 36 | + def test_sub(self): |
| 37 | + value = P256.G - P256.G |
| 38 | + |
| 39 | + self.assertTrue(value._is_identity()) |
| 40 | + |
| 41 | + def test_neg(self): |
| 42 | + value = Point._identity_element() |
| 43 | + |
| 44 | + self.assertTrue((-value)._is_identity()) |
| 45 | + |
| 46 | + |
| 47 | +class TestPointTypeValidation(TestCase): |
8 | 48 | def test_type_validation_add(self):
|
9 | 49 | with self.assertRaises(TypeError):
|
10 | 50 | _ = Point._identity_element() + 2 # type: ignore
|
|
0 commit comments