Exemple #1
0
        public void RemoveSigsAfterPruningTest()
        {
            var hash          = GetMockHash().Object;
            var rand          = new Random(2);
            var volatileStore = new VolatilePackStore(1, new[] { 4096, 4096 });
            var sozu          = GetSozuTable(volatileStore, hash);
            var lineage       = new MockLineage();
            var pruneCount    = 3;

            int cumulSize = 0;

            for (var i = 0; i < pruneCount; i++)
            {
                var coin1 = GetCoin(rand);
                var ret1  = sozu.AddProduction(hash.Hash(ref coin1.Outpoint), ref coin1.Outpoint, false, coin1.Payload,
                                               MockLineage.CoinEventToPrune.BlockAlias, lineage);
                Assert.Equal(CoinChangeStatus.Success, ret1);
                cumulSize += coin1.SizeInBytes;
            }

            do
            {
                var coin    = GetCoin(rand);
                var context = new BlockAlias(123, 0);
                var ret     = sozu.AddProduction(hash.Hash(ref coin.Outpoint), ref coin.Outpoint, false, coin.Payload,
                                                 context, lineage);

                Assert.Equal(CoinChangeStatus.Success, ret);
                cumulSize += coin.SizeInBytes;
            } while (cumulSize <= 4096);

            var p0 = volatileStore.Read(0, 0);

            cumulSize = p0.SizeInBytes;
            int sigsCount = 0;
            int opCount   = 0;

            do
            {
                var coin    = GetCoin(rand);
                var context = new BlockAlias(123, 0);
                if (cumulSize + coin.SizeInBytes > 4096)
                {
                    p0                    = volatileStore.Read(0, 0);
                    sigsCount             = p0.OutpointSigCount;
                    opCount               = p0.CoinCount + 1;
                    lineage.PruningActive = true;
                }

                var ret = sozu.AddProduction(hash.Hash(ref coin.Outpoint), ref coin.Outpoint, false, coin.Payload,
                                             context, lineage);

                Assert.Equal(CoinChangeStatus.Success, ret);
                cumulSize += coin.SizeInBytes;
            } while (cumulSize <= 4096);

            p0 = volatileStore.Read(0, 0);
            Assert.True(opCount - p0.CoinCount + sigsCount - p0.OutpointSigCount == pruneCount);
        }
Exemple #2
0
        public void OverflowThenPruneTest()
        {
            var hash          = GetMockHash().Object;
            var rand          = new Random(2);
            var volatileStore = new VolatilePackStore(1, new[] { 4096, 4096 });
            var sozu          = GetSozuTable(volatileStore, hash);
            var lineage       = new MockLineage();

            lineage.PruningActive = true;

            int cumulSize = 0;

            for (var i = 0; i < 3; i++)
            {
                var coin1 = GetCoin(rand);
                var ret1  = sozu.AddProduction(hash.Hash(ref coin1.Outpoint), ref coin1.Outpoint, false, coin1.Payload,
                                               MockLineage.CoinEventToPrune.BlockAlias, lineage);
                Assert.Equal(CoinChangeStatus.Success, ret1);
                cumulSize += coin1.SizeInBytes;
            }

            do
            {
                var coin    = GetCoin(rand);
                var context = new BlockAlias(123, 0);
                var ret     = sozu.AddProduction(hash.Hash(ref coin.Outpoint), ref coin.Outpoint, false, coin.Payload,
                                                 context, lineage);

                Assert.Equal(CoinChangeStatus.Success, ret);
                cumulSize += coin.SizeInBytes;
            } while (cumulSize <= 4096);

            var p0 = volatileStore.Read(0, 0);

            Assert.True(p0.OutpointSigCount == 0);
            var p1 = volatileStore.Read(1, 0);

            Assert.True(p1.CoinCount == 0);
        }