Esempio n. 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);
        }
Esempio n. 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);
        }
Esempio n. 3
0
        public void TestRoundtrip()
        {
            var set = new List <UInt32>()
            {
                471105047
            };

            set.ForEach(compact => {
                var expected = Mint.BigToCompact(Mint.DiffToTarget(Mint.CompactToDiff(compact)));

                bool isValid = compact == expected;

                Assert.IsTrue(isValid);
            });
        }
Esempio n. 4
0
        public void IncTests()
        {
            var list = new List <long>()
            {
                0x1, 0x2, 0x12, 0x123, 0x1234, 0x12345, 0x123456, 0x800000, 0x1234567,
                0x7fffff, 0x7ffffffff,
            };
            var big = new BigInteger(0x1234567);
            var g   = long.Parse(Mint.CompactToBig(Mint.BigToCompact(big)).ToString());

            list.Add(g);
            list.Add(g - 1);

            list.ForEach(num => {
                bool isValid = IncTest(num);

                Assert.IsTrue(isValid);
            });
        }
Esempio n. 5
0
        public void BigToCompactTest()
        {
            var set = new[] {
                new uint[] { 8388608, 67141632 },
            };


            foreach (var i in set)
            {
                long data    = (long)i[0];
                var  b0      = new BigInteger(data);
                var  c0      = Mint.BigToCompact(b0);
                uint encoded = (uint)i[1];


                bool isValid = c0 == encoded;
                Assert.IsTrue(isValid);
            }
        }
Esempio n. 6
0
 public uint SetBitsWithDifficulty(float diff)
 {
     this.Bits = Mint.BigToCompact(Mint.DiffToTarget(diff));
     return(this.Bits.Value);
 }