Beispiel #1
0
        public void TryTake_WithoutCache()
        {
            var initTarget     = 1;
            var blockInfoCache = new BlockInfoCache(initTarget);
            var res            = blockInfoCache.TryTake(initTarget, out var blockInfo, false);

            Assert.False(res);
        }
Beispiel #2
0
        public void TargetHeight_WithEmptyQueue()
        {
            var initTarget     = 1;
            var blockInfoCache = new BlockInfoCache(initTarget);

            blockInfoCache.TryAdd(new SideChainBlockData
            {
                SideChainHeight = 1
            });
            blockInfoCache.TryAdd(new SideChainBlockData
            {
                SideChainHeight = 2
            });
            blockInfoCache.TryTake(1, out _, false);
            blockInfoCache.TryTake(2, out _, false);

            Assert.True(blockInfoCache.TargetChainHeight() == 3);
        }
Beispiel #3
0
        public void TryTake_OutDatedData()
        {
            var initTarget     = 1;
            var blockInfoCache = new BlockInfoCache(initTarget);
            int i = 0;

            while (i++ < (int)initTarget + CrossChainConstants.MinimalBlockInfoCacheThreshold)
            {
                var t = blockInfoCache.TryAdd(new SideChainBlockData
                {
                    SideChainHeight = i
                });
            }
            blockInfoCache.TryTake(2, out var b1, true);
            var res = blockInfoCache.TryTake(1, out var b2, true);

            Assert.True(res);
            Assert.True(b2.Height == 1);
        }
Beispiel #4
0
        public void TryTake_Twice()
        {
            var initTarget     = 2;
            var blockInfoCache = new BlockInfoCache(initTarget);
            int i = 0;

            while (i++ < (int)initTarget + CrossChainConstants.MinimalBlockInfoCacheThreshold)
            {
                var t = blockInfoCache.TryAdd(new SideChainBlockData
                {
                    SideChainHeight = i
                });
            }
            blockInfoCache.TryTake(initTarget, out var b1, true);
            var res = blockInfoCache.TryTake(initTarget, out var b2, true);

            Assert.True(res);
            Assert.Equal(b1, b2);
        }
Beispiel #5
0
        public void TryTake_WithoutSizeLimit()
        {
            var initTarget     = 1;
            var blockInfoCache = new BlockInfoCache(initTarget);

            blockInfoCache.TryAdd(new SideChainBlockData
            {
                SideChainHeight = 1
            });
            var res = blockInfoCache.TryTake(initTarget, out var blockInfo, false);

            Assert.True(res);
            Assert.True(blockInfo.Height == initTarget);
        }
Beispiel #6
0
        public void TryTake_WithoutEnoughCache()
        {
            var initTarget     = 1;
            var blockInfoCache = new BlockInfoCache(initTarget);
            int i = 0;

            while (i++ < CrossChainConstants.MinimalBlockInfoCacheThreshold)
            {
                var t = blockInfoCache.TryAdd(new SideChainBlockData
                {
                    SideChainHeight = i
                });
            }
            var res = blockInfoCache.TryTake(initTarget, out var blockInfo, true);

            Assert.False(res);
        }
Beispiel #7
0
        public void TryTake_WithClearCacheNeeded()
        {
            var initTarget     = 2;
            var blockInfoCache = new BlockInfoCache(initTarget);
            int i = 0;

            while (i++ < (int)initTarget + CrossChainConstants.MinimalBlockInfoCacheThreshold)
            {
                var t = blockInfoCache.TryAdd(new SideChainBlockData
                {
                    SideChainHeight = i
                });
            }
            var res = blockInfoCache.TryTake(initTarget, out var blockInfo, true);

            Assert.True(res);
            Assert.True(blockInfo.Height == initTarget);
        }