public async Task Set_IrreversibleBlock_Test() { NewIrreversibleBlockFoundEvent eventData = null; _eventBus.Subscribe <NewIrreversibleBlockFoundEvent>(d => { eventData = d; return(Task.CompletedTask); }); var chain = await _fullBlockchainService.GetChainAsync(); { // LIB height: 7 // // Height: 1 -> 2 -> 3 -> 4 -> 5 -> 6 -> 7 -> 8 -> 9 -> 10 -> 11 -> 12 -> 13 -> 14 // Best Branch: a -> b -> c -> d -> e -> f -> g -> h -> i -> j -> k // Longest Branch: (h)-> l -> m -> n -> o -> p // Fork Branch: (e)-> q -> r -> s -> t -> u // Unlinked Branch: v -> w -> x -> y -> z await _fullBlockchainService.SetIrreversibleBlockAsync(chain, _kernelTestHelper.BestBranchBlockList[6] .Height, _kernelTestHelper.BestBranchBlockList[6].GetHash()); chain = await _fullBlockchainService.GetChainAsync(); chain.LastIrreversibleBlockHash.ShouldBe(_kernelTestHelper.BestBranchBlockList[6].GetHash()); chain.LastIrreversibleBlockHeight.ShouldBe(_kernelTestHelper.BestBranchBlockList[6].Height); eventData.ShouldNotBeNull(); eventData.BlockHash.ShouldBe(_kernelTestHelper.BestBranchBlockList[6].GetHash()); eventData.BlockHeight.ShouldBe(_kernelTestHelper.BestBranchBlockList[6].Height); eventData.PreviousIrreversibleBlockHash.ShouldBe(_kernelTestHelper.BestBranchBlockList[4].GetHash()); eventData.PreviousIrreversibleBlockHeight.ShouldBe(_kernelTestHelper.BestBranchBlockList[4].Height); var blockLink = await _chainManager.GetChainBlockLinkAsync(_kernelTestHelper.BestBranchBlockList[6].GetHash()); while (blockLink != null) { blockLink.IsIrreversibleBlock.ShouldBeTrue(); var chainBlockIndex = await _chainManager.GetChainBlockIndexAsync(blockLink.Height); chainBlockIndex.BlockHash.ShouldBe(blockLink.BlockHash); blockLink = await _chainManager.GetChainBlockLinkAsync(blockLink.PreviousBlockHash); } } { // LIB height: 11 // // Height: 1 -> 2 -> 3 -> 4 -> 5 -> 6 -> 7 -> 8 -> 9 -> 10 -> 11 -> 12 -> 13 -> 14 // Best Branch: a -> b -> c -> d -> e -> f -> g -> h -> i -> j -> k // Longest Branch: (-) (h)-> l -> m -> n -> o -> p // Fork Branch: (-) (e)-> q -> r -> s -> t -> u // Unlinked Branch: v(-) -> w -> x -> y -> z eventData = null; await _fullBlockchainService.SetIrreversibleBlockAsync(chain, _kernelTestHelper.BestBranchBlockList[10] .Height, _kernelTestHelper.BestBranchBlockList[10].GetHash()); chain = await _fullBlockchainService.GetChainAsync(); chain.LastIrreversibleBlockHash.ShouldBe(_kernelTestHelper.BestBranchBlockList[10].GetHash()); chain.LastIrreversibleBlockHeight.ShouldBe(_kernelTestHelper.BestBranchBlockList[10].Height); eventData.ShouldNotBeNull(); eventData.BlockHash.ShouldBe(_kernelTestHelper.BestBranchBlockList[10].GetHash()); eventData.BlockHeight.ShouldBe(_kernelTestHelper.BestBranchBlockList[10].Height); eventData.PreviousIrreversibleBlockHash.ShouldBe(_kernelTestHelper.BestBranchBlockList[6].GetHash()); eventData.PreviousIrreversibleBlockHeight.ShouldBe(_kernelTestHelper.BestBranchBlockList[6].Height); var blockLink = await _chainManager.GetChainBlockLinkAsync(_kernelTestHelper.BestBranchBlockList[10].GetHash()); while (blockLink != null) { blockLink.IsIrreversibleBlock.ShouldBeTrue(); var chainBlockIndex = await _chainManager.GetChainBlockIndexAsync(blockLink.Height); chainBlockIndex.BlockHash.ShouldBe(blockLink.BlockHash); blockLink = await _chainManager.GetChainBlockLinkAsync(blockLink.PreviousBlockHash); } } { // Set lib failed eventData = null; await _fullBlockchainService.SetIrreversibleBlockAsync(chain, _kernelTestHelper.BestBranchBlockList[9] .Height, _kernelTestHelper.BestBranchBlockList[9].GetHash()); eventData.ShouldBeNull(); } }
public async Task Set_IrreversibleBlock_Test() { var chain = await _fullBlockchainService.GetChainAsync(); { // LIB height: 7 // // Height: 1 -> 2 -> 3 -> 4 -> 5 -> 6 -> 7 -> 8 -> 9 -> 10 -> 11 -> 12 -> 13 -> 14 // Best Branch: a -> b -> c -> d -> e -> f -> g -> h -> i -> j -> k // Longest Branch: (h)-> l -> m -> n -> o -> p // Fork Branch: (e)-> q -> r -> s -> t -> u // Unlinked Branch: v -> w -> x -> y -> z await _fullBlockchainService.SetIrreversibleBlockAsync(chain, _kernelTestHelper.BestBranchBlockList[6] .Height, _kernelTestHelper.BestBranchBlockList[6].GetHash()); chain = await _fullBlockchainService.GetChainAsync(); chain.LastIrreversibleBlockHash.ShouldBe(_kernelTestHelper.BestBranchBlockList[6].GetHash()); chain.LastIrreversibleBlockHeight.ShouldBe(_kernelTestHelper.BestBranchBlockList[6].Height); chain.Branches.Count.ShouldBe(3); chain.NotLinkedBlocks.Count.ShouldBe(5); BlocksShouldExist(_kernelTestHelper.BestBranchBlockList.Select(b => b.GetHash()).ToList()); BlocksShouldExist(_kernelTestHelper.LongestBranchBlockList.Select(b => b.GetHash()).ToList()); BlocksShouldExist(_kernelTestHelper.ForkBranchBlockList.Select(b => b.GetHash()).ToList()); BlocksShouldExist(_kernelTestHelper.UnlinkedBranchBlockList.Select(b => b.GetHash()).ToList()); } { // LIB height: 9 // // Height: 1 -> 2 -> 3 -> 4 -> 5 -> 6 -> 7 -> 8 -> 9 -> 10 -> 11 -> 12 -> 13 -> 14 // Best Branch: a -> b -> c -> d -> e -> f -> g -> h -> i -> j -> k // Longest Branch: (h)-> l -> m -> n -> o -> p // Fork Branch: (-) (e)-> q -> r -> s -> t -> u // Unlinked Branch: v -> w -> x -> y -> z await _fullBlockchainService.SetIrreversibleBlockAsync(chain, _kernelTestHelper.BestBranchBlockList[8] .Height, _kernelTestHelper.BestBranchBlockList[8].GetHash()); chain = await _fullBlockchainService.GetChainAsync(); chain.LastIrreversibleBlockHash.ShouldBe(_kernelTestHelper.BestBranchBlockList[8].GetHash()); chain.LastIrreversibleBlockHeight.ShouldBe(_kernelTestHelper.BestBranchBlockList[8].Height); chain.Branches.Count.ShouldBe(2); chain.NotLinkedBlocks.Count.ShouldBe(5); BlocksShouldNotExist(_kernelTestHelper.ForkBranchBlockList.Select(b => b.GetHash()).ToList()); BlocksShouldExist(_kernelTestHelper.BestBranchBlockList.Select(b => b.GetHash()).ToList()); BlocksShouldExist(_kernelTestHelper.LongestBranchBlockList.Select(b => b.GetHash()).ToList()); BlocksShouldExist(_kernelTestHelper.UnlinkedBranchBlockList.Select(b => b.GetHash()).ToList()); } { // LIB height: 10 // // Height: 1 -> 2 -> 3 -> 4 -> 5 -> 6 -> 7 -> 8 -> 9 -> 10 -> 11 -> 12 -> 13 -> 14 // Best Branch: a -> b -> c -> d -> e -> f -> g -> h -> i -> j -> k // Longest Branch: (-) (h)-> l -> m -> n -> o -> p // Fork Branch: (-) (e)-> q -> r -> s -> t -> u // Unlinked Branch: v -> w -> x -> y -> z await _fullBlockchainService.SetIrreversibleBlockAsync(chain, _kernelTestHelper.BestBranchBlockList[9] .Height, _kernelTestHelper.BestBranchBlockList[9].GetHash()); chain = await _fullBlockchainService.GetChainAsync(); chain.LastIrreversibleBlockHash.ShouldBe(_kernelTestHelper.BestBranchBlockList[9].GetHash()); chain.LastIrreversibleBlockHeight.ShouldBe(_kernelTestHelper.BestBranchBlockList[9].Height); chain.Branches.Count.ShouldBe(1); chain.NotLinkedBlocks.Count.ShouldBe(5); BlocksShouldNotExist(_kernelTestHelper.ForkBranchBlockList.Select(b => b.GetHash()).ToList()); BlocksShouldExist(_kernelTestHelper.BestBranchBlockList.Select(b => b.GetHash()).ToList()); BlocksShouldNotExist(_kernelTestHelper.LongestBranchBlockList.Select(b => b.GetHash()).ToList()); BlocksShouldExist(_kernelTestHelper.UnlinkedBranchBlockList.Select(b => b.GetHash()).ToList()); } { // LIB height: 11 // // Height: 1 -> 2 -> 3 -> 4 -> 5 -> 6 -> 7 -> 8 -> 9 -> 10 -> 11 -> 12 -> 13 -> 14 // Best Branch: a -> b -> c -> d -> e -> f -> g -> h -> i -> j -> k // Longest Branch: (-) (h)-> l -> m -> n -> o -> p // Fork Branch: (-) (e)-> q -> r -> s -> t -> u // Unlinked Branch: v(-) -> w -> x -> y -> z await _fullBlockchainService.SetIrreversibleBlockAsync(chain, _kernelTestHelper.BestBranchBlockList[10] .Height, _kernelTestHelper.BestBranchBlockList[10].GetHash()); chain = await _fullBlockchainService.GetChainAsync(); chain.LastIrreversibleBlockHash.ShouldBe(_kernelTestHelper.BestBranchBlockList[10].GetHash()); chain.LastIrreversibleBlockHeight.ShouldBe(_kernelTestHelper.BestBranchBlockList[10].Height); chain.Branches.Count.ShouldBe(1); chain.NotLinkedBlocks.Count.ShouldBe(4); chain.LongestChainHash.ShouldBe(chain.BestChainHash); chain.LongestChainHeight.ShouldBe(chain.BestChainHeight); BlocksShouldExist(_kernelTestHelper.BestBranchBlockList.Select(b => b.GetHash()).ToList()); BlocksShouldNotExist(_kernelTestHelper.LongestBranchBlockList.Select(b => b.GetHash()).ToList()); BlocksShouldNotExist(_kernelTestHelper.ForkBranchBlockList.Select(b => b.GetHash()).ToList()); BlocksShouldNotExist(new List <Hash> { _kernelTestHelper.UnlinkedBranchBlockList[0].GetHash() }); BlocksShouldExist(new List <Hash> { _kernelTestHelper.UnlinkedBranchBlockList[1].GetHash(), _kernelTestHelper.UnlinkedBranchBlockList[2].GetHash(), _kernelTestHelper.UnlinkedBranchBlockList[3].GetHash(), _kernelTestHelper.UnlinkedBranchBlockList[4].GetHash() }); } }
public async Task Set_IrreversibleBlock_Test() { var chain = await _fullBlockchainService.GetChainAsync(); { // LIB height: 7 // // Height: 1 -> 2 -> 3 -> 4 -> 5 -> 6 -> 7 -> 8 -> 9 -> 10 -> 11 -> 12 -> 13 -> 14 // Best Branch: a -> b -> c -> d -> e -> f -> g -> h -> i -> j -> k // Longest Branch: (h)-> l -> m -> n -> o -> p // Fork Branch: (e)-> q -> r -> s -> t -> u // Unlinked Branch: v -> w -> x -> y -> z await _fullBlockchainService.SetIrreversibleBlockAsync(chain, _kernelTestHelper.BestBranchBlockList[6] .Height, _kernelTestHelper.BestBranchBlockList[6].GetHash()); chain = await _fullBlockchainService.GetChainAsync(); chain.LastIrreversibleBlockHash.ShouldBe(_kernelTestHelper.BestBranchBlockList[6].GetHash()); chain.LastIrreversibleBlockHeight.ShouldBe(_kernelTestHelper.BestBranchBlockList[6].Height); var blockLink = await _chainManager.GetChainBlockLinkAsync(_kernelTestHelper.BestBranchBlockList[6].GetHash()); while (blockLink != null) { blockLink.IsIrreversibleBlock.ShouldBeTrue(); var chainBlockIndex = await _chainManager.GetChainBlockIndexAsync(blockLink.Height); chainBlockIndex.BlockHash.ShouldBe(blockLink.BlockHash); blockLink = await _chainManager.GetChainBlockLinkAsync(blockLink.PreviousBlockHash); } } { // LIB height: 11 // // Height: 1 -> 2 -> 3 -> 4 -> 5 -> 6 -> 7 -> 8 -> 9 -> 10 -> 11 -> 12 -> 13 -> 14 // Best Branch: a -> b -> c -> d -> e -> f -> g -> h -> i -> j -> k // Longest Branch: (-) (h)-> l -> m -> n -> o -> p // Fork Branch: (-) (e)-> q -> r -> s -> t -> u // Unlinked Branch: v(-) -> w -> x -> y -> z await _fullBlockchainService.SetIrreversibleBlockAsync(chain, _kernelTestHelper.BestBranchBlockList[10] .Height, _kernelTestHelper.BestBranchBlockList[10].GetHash()); chain = await _fullBlockchainService.GetChainAsync(); chain.LastIrreversibleBlockHash.ShouldBe(_kernelTestHelper.BestBranchBlockList[10].GetHash()); chain.LastIrreversibleBlockHeight.ShouldBe(_kernelTestHelper.BestBranchBlockList[10].Height); var blockLink = await _chainManager.GetChainBlockLinkAsync(_kernelTestHelper.BestBranchBlockList[10].GetHash()); while (blockLink != null) { blockLink.IsIrreversibleBlock.ShouldBeTrue(); var chainBlockIndex = await _chainManager.GetChainBlockIndexAsync(blockLink.Height); chainBlockIndex.BlockHash.ShouldBe(blockLink.BlockHash); blockLink = await _chainManager.GetChainBlockLinkAsync(blockLink.PreviousBlockHash); } } }