Пример #1
0
        private bool IncTest(Int64 num)
        {
            var b0 = new BigInteger(num);
            var c0 = Mint.BigToCompact(b0);
            var b1 = new BigInteger(0);

            if (num < 0x800000)
            {
                b1 = new BigInteger(num + 1);
            }
            else
            {
                b1 = new BigInteger(num);
                var bytes     = BigInteger.Abs(b1).ToByteArray().Length;
                var leftshift = 8 * (bytes - 3);
                var toadd     = 1 << leftshift;

                b1 = BigInteger.Add(b1, new BigInteger(toadd));
            }
            var c1 = Mint.BigToCompact(b1);

            if (c1 == c0)
            {
                return(false);
            }
            var c1_ = Mint.IncCompact(c0);

            if (c1_ != c1)
            {
                return(false);
            }

            return(true);
        }
Пример #2
0
        public void CheckStakeKernelHashTest()
        {
            var result = Mint.CheckStakeKernelHash(new PeercoinUtils.MintTemplate(
                                                       "totest",
                                                       "Pxxxx",
                                                       1394219584,
                                                       160,
                                                       1394219584,
                                                       1,
                                                       210090000,
                                                       471087779
                                                       ),
                                                   1411634680,
                                                   15161125480764745506);

            bool isValid = result.success;

            Assert.IsTrue(isValid);

            var tpl0Hash = new List <byte> {
                0x00, 0x00, 0x00, 0xdb, 0x33, 0x30, 0x88, 0x15,
                0x19, 0xa4, 0xf3, 0x2b, 0x90, 0x91, 0xb0, 0x93,
                0x0f, 0x24, 0xec, 0x6f, 0xb0, 0x90, 0x0a, 0xcf,
                0xbf, 0xb0, 0xc2, 0x26, 0xc7, 0xbc, 0x31, 0x92,
            };

            //little endian
            tpl0Hash.Reverse();

            for (int i = 0; i < result.hash.Length; i++)
            {
                isValid = result.hash[i] == tpl0Hash[i];
                Assert.IsTrue(isValid);
            }


            // check if template satisfies min target
            var minbits = Mint.IncCompact(Mint.BigToCompact(result.minTarget));

            var minresult = Mint.CheckStakeKernelHash(new PeercoinUtils.MintTemplate(
                                                          "totest",
                                                          "Pxxx",
                                                          1394219584,
                                                          160,
                                                          1394219584,
                                                          1,
                                                          210090000,
                                                          minbits
                                                          ),
                                                      1411634680,
                                                      15161125480764745506);


            isValid = minresult.success;

            Assert.IsTrue(isValid);
        }
Пример #3
0
        public void ShouldCovertToCompact()
        {
            var dataset = new[] {
                new long[] { 7, 16842752 },
                new long[] { 734, 16842754 },
                new long[] { 42, 16842752 },
                new long[] { 1984, 16842759 }
            };

            foreach (var i in dataset)
            {
                var data     = (uint)i[0];
                var expected = i[1];

                var bn = Mint.IncCompact(data);

                bool isValid = bn == expected;
                Assert.IsTrue(isValid);
            }
        }