commit baec2e174aae9c870fe884c71ce28e4f2c35286a
parent 49c6f375f826faadeb232b5229a80aed7014d1c7
Author: Shivakumar <[email protected]>
Date: Fri, 27 Jun 2025 00:06:35 +0530
add tests for point.py and secp256k1 curve
Diffstat:
2 files changed, 47 insertions(+), 0 deletions(-)
diff --git a/tests/test_point.py b/tests/test_point.py
@@ -0,0 +1,40 @@
+from ecc import Point
+from ecc import Curve
+from ecc import FieldElement
+
+
+G = (5, 1)
+P = 17
+n = 19
+
+curve = Curve(2, 2, P, G, n)
+
+def test_point_on_curve():
+ p = Point(3, 1, curve)
+ assert p.y**2 == p.x**3 + p.a * p.x + p.b
+
+
+def test_addition():
+ p1 = Point(5, 1, curve)
+ p2 = Point(6, 3, curve)
+
+ assert Point(10, 6, curve) == p1 + p2
+
+
+def test_point_doubling():
+ p = Point(5, 1, curve)
+ assert Point(6, 3, curve) == p + p
+
+
+def test_scalar_multiplication():
+ p = Point(5, 1, curve)
+ k = 16
+
+ assert Point(10, 11, curve) == k * p
+
+
+def test_infinity():
+ p = Point(5, 1, curve)
+ assert Point(None, None, curve) == n * p
+
+
diff --git a/tests/test_secp256k1.py b/tests/test_secp256k1.py
@@ -5,6 +5,7 @@ from ecc import secp256k1
def test_generator_point():
Gx, Gy = secp256k1.G
G = Point(Gx, Gy, secp256k1)
+
assert G
@@ -21,3 +22,9 @@ def test_scalar_multiplication():
assert G_check == G
+def test_point_order():
+ Gx, Gy = secp256k1.G
+ G = Point(Gx, Gy, secp256k1)
+ infinity = secp256k1.n * G
+
+ assert (infinity.x, infinity.y) == (None, None)