public void SyncFromHeight_NegativeHeight_ThrowsWalletException() { Assert.Throws <WalletException>(() => { this.chain = new ConcurrentChain(this.network); var lightWalletSyncManager = new LightWalletSyncManager(this.LoggerFactory.Object, this.walletManager.Object, this.chain, this.network, this.blockNotification.Object, this.signals.Object, this.nodeLifetime.Object, this.asyncLoopFactory.Object, this.consensusManager.Object); lightWalletSyncManager.SyncFromHeight(-1); }); }
public void SyncFromHeight_ChainTipAfterGivenHeight_StartsSyncFromGivenHeight() { this.chain = WalletTestsHelpers.GenerateChainWithHeight(2, this.network); var lightWalletSyncManager = new LightWalletSyncManager(this.LoggerFactory.Object, this.walletManager.Object, this.chain, this.network, this.blockNotification.Object, this.signals.Object, this.nodeLifetime.Object, this.asyncLoopFactory.Object, this.consensusManager.Object); lightWalletSyncManager.SyncFromHeight(1); uint256 expectedBlockHash = this.chain.GetBlock(1).HashBlock; this.blockNotification.Verify(b => b.SyncFrom(expectedBlockHash)); Assert.Equal(lightWalletSyncManager.WalletTip.HashBlock, expectedBlockHash); this.walletManager.VerifySet(b => b.WalletTipHash = expectedBlockHash); }
public void SyncFromHeight_EmptyChain_StartsAsyncLoopToCatchup() { this.chain = new ConcurrentChain(this.network); var lightWalletSyncManager = new LightWalletSyncManager(this.LoggerFactory.Object, this.walletManager.Object, this.chain, this.network, this.blockNotification.Object, this.signals.Object, this.nodeLifetime.Object, this.asyncLoopFactory.Object, this.consensusManager.Object); lightWalletSyncManager.SyncFromHeight(3); this.asyncLoopFactory.Verify( a => a.RunUntil( "LightWalletSyncManager.SyncFromHeight", It.IsAny <CancellationToken>(), It.IsAny <Func <bool> >(), It.IsAny <Action>(), It.IsAny <Action <Exception> >(), TimeSpans.FiveSeconds)); this.nodeLifetime.VerifyGet(n => n.ApplicationStopping); }
public void SyncFromHeight_ChainTipBeforeGivenHeight_StartsAsyncLoopToCatchupChain() { var asyncLoop = new Mock <IAsyncLoop>(); this.chain = WalletTestsHelpers.GenerateChainWithHeight(2, this.network); var lightWalletSyncManager = new LightWalletSyncManager(this.LoggerFactory.Object, this.walletManager.Object, this.chain, this.network, this.blockNotification.Object, this.signals.Object, this.nodeLifetime.Object, this.asyncLoopFactory.Object, this.consensusManager.Object); lightWalletSyncManager.SyncFromHeight(3); this.asyncLoopFactory.Verify( a => a.RunUntil( "LightWalletSyncManager.SyncFromHeight", It.IsAny <CancellationToken>(), It.IsAny <Func <bool> >(), It.IsAny <Action>(), It.IsAny <Action <Exception> >(), TimeSpans.FiveSeconds)); this.nodeLifetime.VerifyGet(n => n.ApplicationStopping); }
public void Stop_DisposesDependencies() { this.chain = WalletTestsHelpers.GenerateChainWithHeight(1, this.network); var blockSub = new Mock <IDisposable>(); var transSub = new Mock <IDisposable>(); this.signals.Setup(s => s.SubscribeForBlocksConnected(It.IsAny <BlockObserver>())) .Returns(blockSub.Object); this.signals.Setup(s => s.SubscribeForTransactions(It.IsAny <TransactionObserver>())) .Returns(transSub.Object); this.walletManager.SetupGet(w => w.ContainsWallets) .Returns(false); var asyncLoop = new Mock <IAsyncLoop>(); this.asyncLoopFactory.Setup( a => a.RunUntil( "LightWalletSyncManager.SyncFromHeight", It.IsAny <CancellationToken>(), It.IsAny <Func <bool> >(), It.IsAny <Action>(), It.IsAny <Action <Exception> >(), TimeSpans.FiveSeconds)) .Returns(asyncLoop.Object); var lightWalletSyncManager = new LightWalletSyncManager(this.LoggerFactory.Object, this.walletManager.Object, this.chain, this.network, this.blockNotification.Object, this.signals.Object, this.nodeLifetime.Object, this.asyncLoopFactory.Object, this.consensusManager.Object); lightWalletSyncManager.Start(); lightWalletSyncManager.SyncFromHeight(3); lightWalletSyncManager.Stop(); asyncLoop.Verify(b => b.Dispose()); blockSub.Verify(b => b.Dispose()); transSub.Verify(b => b.Dispose()); }