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 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 FillExtraData_Test() { var fakeMerkleTreeRoot1 = Hash.FromString("fakeMerkleTreeRoot1"); var fakeMerkleTreeRoot2 = Hash.FromString("fakeMerkleTreeRoot2"); var fakeMerkleTreeRoot3 = Hash.FromString("fakeMerkleTreeRoot3"); int chainId1 = ChainHelper.ConvertBase58ToChainId("2112"); int chainId2 = ChainHelper.ConvertBase58ToChainId("2113"); int chainId3 = ChainHelper.ConvertBase58ToChainId("2114"); var fakeSideChainBlockDataList = new List <SideChainBlockData> { new SideChainBlockData { Height = 1, TransactionStatusMerkleTreeRoot = fakeMerkleTreeRoot1, ChainId = chainId1 }, new SideChainBlockData { Height = 1, TransactionStatusMerkleTreeRoot = fakeMerkleTreeRoot2, ChainId = chainId2 }, new SideChainBlockData { Height = 1, TransactionStatusMerkleTreeRoot = fakeMerkleTreeRoot3, ChainId = chainId3 } }; var list1 = new List <SideChainBlockData>(); var list2 = new List <SideChainBlockData>(); var list3 = new List <SideChainBlockData>(); list1.Add(fakeSideChainBlockDataList[0]); list2.Add(fakeSideChainBlockDataList[1]); list3.Add(fakeSideChainBlockDataList[2]); for (int i = 2; i < CrossChainConstants.DefaultBlockCacheEntityCount + 2; i++) { list1.Add(new SideChainBlockData { Height = i, TransactionStatusMerkleTreeRoot = fakeMerkleTreeRoot1, ChainId = chainId1 }); list2.Add(new SideChainBlockData { Height = i, TransactionStatusMerkleTreeRoot = fakeMerkleTreeRoot2, ChainId = chainId2 }); list3.Add(new SideChainBlockData { Height = i, TransactionStatusMerkleTreeRoot = fakeMerkleTreeRoot3, ChainId = chainId3 }); } _crossChainTestHelper.AddFakePendingCrossChainIndexingProposal( new GetPendingCrossChainIndexingProposalOutput { Proposer = SampleAddress.AddressList[0], ProposalId = Hash.FromString("ProposalId"), ProposedCrossChainBlockData = new CrossChainBlockData { SideChainBlockDataList = { list1, list2, list3 } }, ToBeReleased = true, ExpiredTime = TimestampHelper.GetUtcNow().AddSeconds(10) }); _crossChainTestHelper.SetFakeLibHeight(1); var header = new BlockHeader { PreviousBlockHash = Hash.FromString("PreviousHash"), Height = 2 }; var sideChainTxMerkleTreeRoot = await _crossChainBlockExtraDataProvider.GetExtraDataForFillingBlockHeaderAsync(header); var merkleTreeRoot = BinaryMerkleTree .FromLeafNodes(list1.Concat(list2).Concat(list3).Select(sideChainBlockData => sideChainBlockData.TransactionStatusMerkleTreeRoot)).Root; var expected = new CrossChainExtraData { TransactionStatusMerkleTreeRoot = merkleTreeRoot }.ToByteString(); Assert.Equal(expected, sideChainTxMerkleTreeRoot); }