@@ -65,6 +65,44 @@ contract Secp256k1Test is Test {
65
65
Secp256k1.isOnCurve (Gx, y);
66
66
}
67
67
68
+ // ! -----------------------------------------------------------------------------------------------------------------------
69
+ // ! negatePoint() TESTS
70
+ // ! -----------------------------------------------------------------------------------------------------------------------
71
+ function test_negatePoint_Infinity () public pure {
72
+ (uint256 x , uint256 y ) = Secp256k1.negatePoint (0 , 0 );
73
+ assertEq (x, 0 );
74
+ assertEq (y, 0 );
75
+ }
76
+
77
+ // ! Line below is for reverting with internal function calls -> https://book.getfoundry.sh/cheatcodes/expect-revert?highlight=expectRevert#error
78
+ /// forge-config: default.allow_internal_expect_revert = true
79
+ function testFuzz_negatePoint_RevertIf_InvalidCoordinate_X (uint256 x ) public {
80
+ x = bound (x, Secp256k1.p, UINT256_MAX);
81
+ uint256 y = 1 ;
82
+ vm.expectRevert (abi.encodeWithSelector (Secp256k1.Secp256k1__InvalidCoordinate.selector , x));
83
+ Secp256k1.negatePoint (x, y);
84
+ }
85
+
86
+ // ! Line below is for reverting with internal function calls -> https://book.getfoundry.sh/cheatcodes/expect-revert?highlight=expectRevert#error
87
+ /// forge-config: default.allow_internal_expect_revert = true
88
+ function testFuzz_negatePoint_RevertIf_InvalidCoordinate_Y (uint256 y ) public {
89
+ uint256 x = 1 ;
90
+ y = bound (y, Secp256k1.p, UINT256_MAX);
91
+ vm.expectRevert (abi.encodeWithSelector (Secp256k1.Secp256k1__InvalidCoordinate.selector , y));
92
+ Secp256k1.negatePoint (x, y);
93
+ }
94
+
95
+ // ! Line below is for reverting with internal function calls -> https://book.getfoundry.sh/cheatcodes/expect-revert?highlight=expectRevert#error
96
+ /// forge-config: default.allow_internal_expect_revert = true
97
+ function testFuzz_negatePoint_RevertIf_InvalidPoint (uint256 x , uint256 y ) public {
98
+ x = bound (x, 0 , Secp256k1.p - 1 );
99
+ y = bound (y, 0 , Secp256k1.p - 1 );
100
+ vm.assume (! Secp256k1.isOnCurve (x, y));
101
+ vm.assume (x != 0 || y != 0 );
102
+ vm.expectRevert (abi.encodeWithSelector (Secp256k1.Secp256k1__InvalidPoint.selector , x, y));
103
+ Secp256k1.negatePoint (x, y);
104
+ }
105
+
68
106
// ! -----------------------------------------------------------------------------------------------------------------------
69
107
// ! addPoints() TESTS FOR GAS
70
108
// ! -----------------------------------------------------------------------------------------------------------------------
0 commit comments