public void Start_BlockNotChain_ReorgsWalletManagerUsingWallet() { this.storeSettings.AmountOfBlocksToKeep = 0; this.chainIndexer = WalletTestsHelpers.GenerateChainWithHeight(5, KnownNetworks.StratisMain); this.walletManager.SetupGet(w => w.WalletTipHash) .Returns(new uint256(125)); // try to load non-existing block to get chain to return null. ChainedHeader forkBlock = this.chainIndexer.GetHeader(3); // use a block as the fork to recover to. uint256 forkBlockHash = forkBlock.Header.GetHash(); this.walletManager.Setup(w => w.GetFirstWalletBlockLocator()) .Returns(new Collection <uint256> { forkBlockHash }); var walletSyncManager = new WalletSyncManager(this.LoggerFactory.Object, this.walletManager.Object, this.chainIndexer, KnownNetworks.StratisMain, this.blockStore.Object, this.storeSettings, this.signals, this.asyncProvider); walletSyncManager.Start(); // verify the walletmanager is reorged using the fork block and it's tip is set to it. this.walletManager.Verify(w => w.RemoveBlocks(It.Is <ChainedHeader>(c => c.Header.GetHash() == forkBlockHash))); this.walletManager.VerifySet(w => w.WalletTipHash = forkBlockHash); Assert.Equal(walletSyncManager.WalletTip.HashBlock.ToString(), forkBlock.HashBlock.ToString()); }
public void Start_BlockNotChain_ReorgsWalletManagerUsingWallet() { this.storeSettings.Prune = false; this.chain = WalletTestsHelpers.GenerateChainWithHeight(5, Network.PurpleMain); this.walletManager.SetupGet(w => w.WalletTipHash) .Returns(new uint256(125)); // try to load non-existing block to get chain to return null. var forkBlock = this.chain.GetBlock(3); // use a block as the fork to recover to. var forkBlockHash = forkBlock.Header.GetHash(); this.walletManager.Setup(w => w.GetFirstWalletBlockLocator()) .Returns(new Collection <uint256> { forkBlockHash }); var walletSyncManager = new WalletSyncManager(this.LoggerFactory.Object, this.walletManager.Object, this.chain, Network.PurpleMain, this.blockStoreCache.Object, this.storeSettings, this.nodeLifetime.Object); walletSyncManager.Start(); // verify the walletmanager is reorged using the fork block and it's tip is set to it. this.walletManager.Verify(w => w.RemoveBlocks(It.Is <ChainedBlock>(c => c.Header.GetHash() == forkBlockHash))); this.walletManager.VerifySet(w => w.WalletTipHash = forkBlockHash); Assert.Equal(walletSyncManager.WalletTip.HashBlock.ToString(), forkBlock.HashBlock.ToString()); }
public void Start_HavingPrunedStoreSetting_ThrowsWalletException() { this.storeSettings.Prune = true; var walletSyncManager = new WalletSyncManager(this.LoggerFactory.Object, this.walletManager.Object, this.chain, Network.StratisMain, this.blockStoreCache.Object, this.storeSettings, this.nodeLifetime.Object); Assert.Throws <WalletException>(() => { walletSyncManager.Start(); }); }
public void Start_HavingPrunedStoreSetting_ThrowsWalletException() { this.storeSettings.AmountOfBlocksToKeep = 1; this.storeSettings.PruningEnabled = true; var walletSyncManager = new WalletSyncManager(this.LoggerFactory.Object, this.walletManager.Object, this.chainIndexer, KnownNetworks.StratisMain, this.blockStore.Object, this.storeSettings, this.signals, this.asyncProvider); Assert.Throws <WalletException>(() => { walletSyncManager.Start(); }); }
public void Start_BlockOnChain_DoesNotReorgWalletManager() { this.storeSettings.AmountOfBlocksToKeep = 0; this.chainIndexer = WalletTestsHelpers.PrepareChainWithBlock(); this.walletManager.Setup(w => w.WalletTipHash) .Returns(this.chainIndexer.Tip.Header.GetHash()); var walletSyncManager = new WalletSyncManager(this.LoggerFactory.Object, this.walletManager.Object, this.chainIndexer, KnownNetworks.StratisMain, this.blockStore.Object, this.storeSettings, this.signals, this.asyncProvider); walletSyncManager.Start(); this.walletManager.Verify(w => w.GetFirstWalletBlockLocator(), Times.Exactly(0)); this.walletManager.Verify(w => w.RemoveBlocks(It.IsAny <ChainedHeader>()), Times.Exactly(0)); }
public void Start_BlockOnChain_DoesNotReorgWalletManager() { this.storeSettings.Prune = false; this.chain = WalletTestsHelpers.PrepareChainWithBlock(); this.walletManager.Setup(w => w.WalletTipHash) .Returns(this.chain.Tip.Header.GetHash()); var walletSyncManager = new WalletSyncManager(this.LoggerFactory.Object, this.walletManager.Object, this.chain, Network.StratisMain, this.blockStoreCache.Object, this.storeSettings, this.nodeLifetime.Object); walletSyncManager.Start(); this.walletManager.Verify(w => w.GetFirstWalletBlockLocator(), Times.Exactly(0)); this.walletManager.Verify(w => w.RemoveBlocks(It.IsAny <ChainedHeader>()), Times.Exactly(0)); }