public void ProcessBlock_NewBlock_PreviousHashSameAsWalletTip_PassesBlockToManagerWithoutReorg() { var result = WalletTestsHelpers.GenerateChainAndBlocksWithHeight(5, Network.StratisMain); this.chain = result.Chain; var blocks = result.Blocks; var walletSyncManager = new WalletSyncManagerOverride(this.LoggerFactory.Object, this.walletManager.Object, this.chain, Network.StratisMain, this.blockStoreCache.Object, this.storeSettings, this.nodeLifetime.Object); walletSyncManager.SetWalletTip(this.chain.GetBlock(3)); var blockToProcess = blocks[3]; walletSyncManager.ProcessBlock(blockToProcess); //4th block in the list has same prevhash as which is loaded var expectedBlockHash = this.chain.GetBlock(4).Header.GetHash(); Assert.Equal(expectedBlockHash, walletSyncManager.WalletTip.Header.GetHash()); this.walletManager.Verify(w => w.ProcessBlock(It.Is <Block>(b => b.GetHash() == blockToProcess.GetHash()), It.Is <ChainedBlock>(c => c.Header.GetHash() == expectedBlockHash))); }
public void ProcessBlock_NewBlock__BlockOnBestChain_ReOrgWalletManagerUsingBlockStoreCache() { (ChainIndexer Chain, List <Block> Blocks)result = WalletTestsHelpers.GenerateChainAndBlocksWithHeight(5, new StraxMain()); this.SetupMockObjects(result.Chain, result.Blocks); // Set 2nd block as tip. this.walletSyncManager.SyncFromHeight(3, this.walletName); // Process 4th block in the list does not have same prevhash as which is loaded Block blockToProcess = result.Blocks[3]; blockToProcess.SetPrivatePropertyValue("BlockSize", 1L); this.walletSyncManager.OrchestrateWalletSync(); //verify manager processes each missing block until caught up. this.walletRepository.Verify(r => r.ProcessBlocks( It.Is <IEnumerable <(ChainedHeader header, Block block)> >(c => string.Join(",", c.Select(b => b.header.Height)) == "3,4,5"), It.IsAny <string>())); }
public void ProcessBlock_NewBlock_PreviousHashSameAsWalletTip_PassesBlockToManagerWithoutReorg() { (ChainIndexer Chain, List <Block> Blocks)result = WalletTestsHelpers.GenerateChainAndBlocksWithHeight(5, KnownNetworks.StratisMain); this.chainIndexer = result.Chain; List <Block> blocks = result.Blocks; var walletSyncManager = new WalletSyncManagerOverride(this.LoggerFactory.Object, this.walletManager.Object, this.chainIndexer, KnownNetworks.StratisMain, this.blockStore.Object, this.storeSettings, this.signals, this.asyncProvider); walletSyncManager.SetWalletTip(this.chainIndexer.GetHeader(3)); Block blockToProcess = blocks[3]; blockToProcess.SetPrivatePropertyValue("BlockSize", 1L); walletSyncManager.ProcessBlock(blockToProcess); //4th block in the list has same prevhash as which is loaded uint256 expectedBlockHash = this.AssertTipBlockHash(walletSyncManager, 4); this.AssertTipBlockHash(walletSyncManager, 4); this.walletManager.Verify(w => w.ProcessBlock(It.Is <Block>(b => b.GetHash() == blockToProcess.GetHash()), It.Is <ChainedHeader>(c => c.Header.GetHash() == expectedBlockHash))); }