public void InitTest(string addr, bool expected)
        {
            var  comp   = new PrvToAddrBothComparer();
            bool actual = comp.Init(addr);

            Assert.Equal(expected, actual);
        }
        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_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 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);
        }
Exemple #5
0
        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 });
        }