Add some scalar tests
MODIFY
WalletWasabi.Tests/UnitTests/Crypto/RandomTests.cs
WalletWasabi.Tests/UnitTests/Crypto/RandomTests.cs
@@ -121,8 +121,6 @@ namespace WalletWasabi.Tests.UnitTests.Crypto
// The random should not overfow.
mockRandom.GetBytesResults.Add(EC.N.ToBytes());
- // ToDo: `EC.N + new Scalar(1)` will be `new Scalar(1)` (so the `IsOverflow` property will be `false`). Investigate if it's a bug or not.
-
// The random should not overfow.
mockRandom.GetBytesResults.Add(new Scalar(uint.MaxValue, uint.MaxValue, uint.MaxValue, uint.MaxValue, uint.MaxValue, uint.MaxValue, uint.MaxValue, uint.MaxValue).ToBytes());

ADD
WalletWasabi.Tests/UnitTests/Crypto/ScalarTests.cs
+using NBitcoin.Secp256k1;
+using System;
+using System.Collections.Generic;
+using System.Text;
+using Xunit;
+
+namespace WalletWasabi.Tests.UnitTests.Crypto
+{
+ public class ScalarTests
+ {
+ [Fact]
+ public void ScalarBehavesAsExpected()
+ {
+ // Just small scalar tests to showcase some edge cases how the Scalar behaves.
+ Assert.True(EC.N.IsOverflow);
+
+ var one = new Scalar(1);
+ var nPlusOne = EC.N + one;
+ Assert.False(nPlusOne.IsOverflow);
+ Assert.Equal(one, nPlusOne);
+
+ var nPlusOneMinusOne = nPlusOne + one.Negate();
+ Assert.False(nPlusOne.IsOverflow);
+ Assert.Equal(Scalar.Zero, nPlusOneMinusOne);
+
+ var nMinusOne = EC.N + one.Negate();
+ Assert.False(nMinusOne.IsOverflow);
+ Assert.True(nMinusOne.IsHigh);
+
+ var largest = new Scalar(uint.MaxValue, uint.MaxValue, uint.MaxValue, uint.MaxValue, uint.MaxValue, uint.MaxValue, uint.MaxValue, uint.MaxValue);
+ Assert.True(largest.IsOverflow);
+
+ var two = one + one;
+ Assert.Equal(new Scalar(2), two);
+ Assert.Equal(one, two + one.Negate());
+ Assert.Equal(Scalar.Zero, two + one.Negate() + one.Negate());
+ }
+ }
+}

Add some scalar tests