public async Task GetParentChainBLock_WithEmptyCache() { int chainId = 123; _crossChainTestHelper.AddFakeParentChainIdHeight(chainId, 1); var res = await _crossChainDataProvider.GetParentChainBlockDataAsync(Hash.Empty, 1); Assert.Empty(res); }
public async Task FillExtraData_WithoutSideChainCacheData_Test() { int chainId = _chainOptions.ChainId; _crossChainTestHelper.AddFakeParentChainIdHeight(chainId, 0); var fakeParentChainBlockDataList = new List <IBlockCacheEntity>(); for (int i = 0; i < CrossChainConstants.MinimalBlockCacheEntityCount + 1; i++) { fakeParentChainBlockDataList.Add(new ParentChainBlockData() { Height = i + 1, ChainId = chainId } ); } AddFakeCacheData(new Dictionary <int, List <IBlockCacheEntity> > { { chainId, fakeParentChainBlockDataList } }); _crossChainTestHelper.SetFakeLibHeight(1); var header = new BlockHeader { PreviousBlockHash = Hash.FromString("PreviousHash"), Height = 2 }; var bytes = await _crossChainBlockExtraDataProvider.GetExtraDataForFillingBlockHeaderAsync(header); Assert.Empty(bytes); }
public async Task FillExtraData_WithoutSideChainCacheData() { int chainId1 = 123; _crossChainTestHelper.AddFakeParentChainIdHeight(chainId1, 0); var fakeParentChainBlockDataList = new List <IBlockInfo>(); for (int i = 0; i < CrossChainConstants.MinimalBlockInfoCacheThreshold + 1; i++) { fakeParentChainBlockDataList.Add(new ParentChainBlockData { Root = new ParentChainBlockRootInfo { ParentChainHeight = i + 1, ParentChainId = chainId1 } }); } AddFakeCacheData(new Dictionary <int, List <IBlockInfo> > { { chainId1, fakeParentChainBlockDataList } }); _crossChainTestHelper.SetFakeLibHeight(1); var header = new BlockHeader { PreviousBlockHash = Hash.FromString("PreviousHash"), Height = 2 }; var bytes = await _crossChainBlockExtraDataProvider.GetExtraDataForFillingBlockHeaderAsync(header); Assert.Empty(bytes); }
public async Task TryTwice_ValidateSideChainBlock_Test() { int chainId = _chainOptions.ChainId; var blockInfoCache = new List <IBlockCacheEntity>(); _crossChainTestHelper.AddFakeParentChainIdHeight(chainId, 0); var cachingCount = _configOptions.MaximalCountForIndexingParentChainBlock + CrossChainConstants.MinimalBlockCacheEntityCount; for (int i = 0; i <= cachingCount; i++) { blockInfoCache.Add(new SideChainBlockData() { ChainId = chainId, Height = (i + 1) }); } var list = new List <SideChainBlockData>(); for (int i = 0; i < _configOptions.MaximalCountForIndexingSideChainBlock; i++) { list.Add(new SideChainBlockData { ChainId = chainId, Height = (i + 1) }); } var fakeCache = new Dictionary <int, List <IBlockCacheEntity> > { { chainId, blockInfoCache } }; AddFakeCacheData(fakeCache); await _crossChainIndexingDataService.ValidateSideChainBlockDataAsync(list, Hash.Empty, 1); list = new List <SideChainBlockData>(); for (int i = 0; i < _configOptions.MaximalCountForIndexingSideChainBlock; i++) { list.Add(new SideChainBlockData { ChainId = chainId, Height = (i + 1) }); } var res = await _crossChainIndexingDataService.ValidateSideChainBlockDataAsync(list, Hash.Empty, 2); Assert.True(res); var expectedResultCount = _configOptions.MaximalCountForIndexingSideChainBlock; Assert.True(list.Count == expectedResultCount); }
public async Task FinishInitialSync_Test() { int chainId = _chainOptions.ChainId; long libHeight = 10; _crossChainTestHelper.SetFakeLibHeight(libHeight); _crossChainTestHelper.AddFakeParentChainIdHeight(chainId, libHeight); await _crossChainService.FinishInitialSyncAsync(); var info = _crossChainService.GetNeededChainIdAndHeightPairs(); Assert.Contains(chainId, info.Keys); Assert.Contains(libHeight + 1, info.Values); }
public async Task GetCrossChainBlockDataForNextMining_WithoutCachingSideBlock_Test() { var parentChainId = _chainOptions.ChainId; var blockInfoCache = new List <IBlockCacheEntity>(); var cachingCount = 5; for (int i = 0; i < cachingCount + CrossChainConstants.DefaultBlockCacheEntityCount; i++) { blockInfoCache.Add(new ParentChainBlockData() { ChainId = parentChainId, Height = (i + 1), TransactionStatusMerkleTreeRoot = Hash.FromString(i.ToString()) }); } _crossChainTestHelper.SetFakeLibHeight(2); _crossChainTestHelper.AddFakeParentChainIdHeight(parentChainId, 1); var fakeCache = new Dictionary <int, List <IBlockCacheEntity> > { { parentChainId, blockInfoCache } }; AddFakeCacheData(fakeCache); var res = await _crossChainIndexingDataService.PrepareExtraDataForNextMiningAsync(Hash.Empty, 1); Assert.Empty(res); var crossChainTransactionInput = await _crossChainIndexingDataService.GetCrossChainTransactionInputForNextMiningAsync(Hash.Empty, 1); Assert.NotNull(crossChainTransactionInput); var crossChainBlockData = CrossChainBlockData.Parser.ParseFrom(crossChainTransactionInput.Value); Assert.Equal(CrossChainConstants.DefaultBlockCacheEntityCount, crossChainBlockData.ParentChainBlockDataList.Count); Assert.Empty(crossChainBlockData.SideChainBlockDataList); }
public async Task TryTwice_ValidateSideChainBlock_Test() { int chainId = _chainOptions.ChainId; var blockInfoCache = new List <IBlockCacheEntity>(); _crossChainTestHelper.AddFakeParentChainIdHeight(chainId, 0); var cachingCount = CrossChainConstants.DefaultBlockCacheEntityCount * 2; for (int i = 0; i <= cachingCount; i++) { blockInfoCache.Add(new SideChainBlockData() { ChainId = chainId, Height = (i + 1), TransactionStatusMerkleTreeRoot = Hash.FromString((i + 1).ToString()) }); } var fakeCache = new Dictionary <int, List <IBlockCacheEntity> > { { chainId, blockInfoCache } }; AddFakeCacheData(fakeCache); { var list = new List <SideChainBlockData>(); for (int i = 0; i < CrossChainConstants.DefaultBlockCacheEntityCount; i++) { list.Add(new SideChainBlockData { ChainId = chainId, Height = (i + 1), TransactionStatusMerkleTreeRoot = Hash.FromString((i + 1).ToString()) }); } var crossChainBlockData = FakeCrossChainBlockData(list, new ParentChainBlockData[0]); var res = await _crossChainIndexingDataValidationService.ValidateCrossChainIndexingDataAsync( crossChainBlockData, Hash.Empty, 1); Assert.True(res); } { var list = new List <SideChainBlockData>(); for (int i = 0; i < CrossChainConstants.DefaultBlockCacheEntityCount; i++) { list.Add(new SideChainBlockData { ChainId = chainId, Height = (i + 1), TransactionStatusMerkleTreeRoot = Hash.FromString((i + 1).ToString()) }); } var crossChainBlockData = FakeCrossChainBlockData(list, new ParentChainBlockData[0]); var res = await _crossChainIndexingDataValidationService.ValidateCrossChainIndexingDataAsync( crossChainBlockData, Hash.Empty, 2); Assert.True(res); } }