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 SyncFromHeight_NoBlockWithGivenHeightOnChain_ThrowsWalletException() { this.chain = WalletTestsHelpers.GenerateChainWithHeight(1, Network.PurpleMain); var walletSyncManager = new WalletSyncManager(this.LoggerFactory.Object, this.walletManager.Object, this.chain, Network.PurpleMain, this.blockStoreCache.Object, this.storeSettings, this.nodeLifetime.Object); Assert.Throws <WalletException>(() => { walletSyncManager.SyncFromHeight(2); }); }
public void SyncFromDate_GivenDateNotMatchingBlocksOnChain_UpdatesUsingFirstBlock() { this.chain = WalletTestsHelpers.GenerateChainWithHeight(3, Network.PurpleMain); var walletSyncManager = new WalletSyncManager(this.LoggerFactory.Object, this.walletManager.Object, this.chain, Network.PurpleMain, this.blockStoreCache.Object, this.storeSettings, this.nodeLifetime.Object); walletSyncManager.SyncFromDate(new System.DateTime(1900, 1, 1)); // date before any block. var expectedHash = this.chain.GetBlock(1).HashBlock; Assert.Equal(walletSyncManager.WalletTip.HashBlock, expectedHash); this.walletManager.VerifySet(w => w.WalletTipHash = expectedHash); }
public void SyncFromHeight_BlockWithHeightOnChain_UpdatesWalletTipOnWalletAndWalletSyncManagers() { this.chain = WalletTestsHelpers.GenerateChainWithHeight(3, Network.PurpleMain); var walletSyncManager = new WalletSyncManager(this.LoggerFactory.Object, this.walletManager.Object, this.chain, Network.PurpleMain, this.blockStoreCache.Object, this.storeSettings, this.nodeLifetime.Object); walletSyncManager.SyncFromHeight(2); var expectedHash = this.chain.GetBlock(2).HashBlock; Assert.Equal(walletSyncManager.WalletTip.HashBlock, expectedHash); this.walletManager.VerifySet(w => w.WalletTipHash = expectedHash); }
public void SyncFromDate_GivenDateMatchingBlocksOnChain_UpdatesUsingClosestBlock() { this.chain = WalletTestsHelpers.GenerateChainWithHeight(3, Network.PurpleMain); var walletSyncManager = new WalletSyncManager(this.LoggerFactory.Object, this.walletManager.Object, this.chain, Network.PurpleMain, this.blockStoreCache.Object, this.storeSettings, this.nodeLifetime.Object); walletSyncManager.SyncFromDate(this.chain.GetBlock(3).Header.BlockTime.DateTime.AddDays(2)); var expectedHash = this.chain.GetBlock(3).HashBlock; Assert.Equal(walletSyncManager.WalletTip.HashBlock, expectedHash); this.walletManager.VerifySet(w => w.WalletTipHash = expectedHash); }