public void InitTest(string addr, bool expected) { var comp = new PrvToAddrBothComparer(); bool actual = comp.Init(addr); Assert.Equal(expected, actual); }
public unsafe void Compare_Sha512Hpt_Test(PrvToAddrBothComparer comp, byte[] key, bool expected) { ulong *hPt = stackalloc ulong[8]; Helper.WriteToHpt32(key, hPt); bool actual = comp.Compare(hPt); Assert.Equal(expected, actual); }
public unsafe void Compare_PointJ_Test(PrvToAddrBothComparer comp, byte[] key, bool expected) { Scalar sc = new(key, out int overflow); if (overflow == 0 && !sc.IsZero) { PointJacobian point = Helper.Calc.MultiplyByG(sc); bool actual = comp.Compare(point); Assert.Equal(expected, actual); } }
public void Compare_UncompressedTest() { var comp = new PrvToAddrBothComparer(); Assert.True(comp.Init(KeyHelper.Pub1UnCompAddr)); byte[] key = KeyHelper.Prv1.ToBytes(); key[0]++; bool b = comp.Compare(key); Assert.False(b); key[0]--; b = comp.Compare(key); Assert.True(b); }
public void CloneTest() { var original = new PrvToAddrBothComparer(); Assert.True(original.Init(KeyHelper.Pub1CompAddr)); // Make sure it is successfully initialized var cloned = original.Clone(); // Change original field value to make sure it is cloned not a reference copy Assert.True(original.Init(KeyHelper.Pub2CompAddr)); byte[] key = KeyHelper.Prv1.ToBytes(); // Since the original was changed it should fail when comparing Assert.False(original.Compare(key)); Assert.True(cloned.Compare(key)); }
public void Compare_EdgeTest() { var comp = new PrvToAddrBothComparer(); Assert.True(comp.Init(KeyHelper.Pub1CompAddr)); byte[] key = new byte[32]; bool b = comp.Compare(key); Assert.False(b); ((Span <byte>)key).Fill(255); b = comp.Compare(key); Assert.False(b); key = new SecP256k1().N.ToByteArray(true, true); b = comp.Compare(key); Assert.False(b); }
public static IEnumerable <object[]> GetCases() { var comp = new PrvToAddrBothComparer(); var uncomp = new PrvToAddrBothComparer(); Assert.True(comp.Init(KeyHelper.Pub1CompAddr)); Assert.True(uncomp.Init(KeyHelper.Pub1UnCompAddr)); yield return(new object[] { comp, new byte[32], false }); yield return(new object[] { comp, Enumerable.Repeat((byte)255, 32).ToArray(), false }); yield return(new object[] { comp, KeyHelper.Prv1.ToBytes(), true }); yield return(new object[] { comp, KeyHelper.Prv2.ToBytes(), false }); yield return(new object[] { uncomp, new byte[32], false }); yield return(new object[] { uncomp, Enumerable.Repeat((byte)255, 32).ToArray(), false }); yield return(new object[] { uncomp, KeyHelper.Prv1.ToBytes(), true }); yield return(new object[] { uncomp, KeyHelper.Prv2.ToBytes(), false }); }