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());
        }
Example #2
0
        public void Start_BlockNotChain_ReorgsWalletManagerUsingWallet()
        {
            this.storeSettings.Prune = false;
            this.chain = WalletTestsHelpers.GenerateChainWithHeight(5, Network.StratisMain);
            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.StratisMain,
                                                          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.SetupMockObjects(WalletTestsHelpers.GenerateChainWithHeight(1, new StraxMain()));

            Assert.Throws <WalletException>(() =>
            {
                this.walletSyncManager.SyncFromHeight(2, this.walletName);
            });
        }
        public void SyncFromHeight_BlockWithHeightOnChain_UpdatesWalletTipOnWalletAndWalletSyncManagers()
        {
            this.SetupMockObjects(WalletTestsHelpers.GenerateChainWithHeight(3, new StraxMain()));

            this.walletSyncManager.SyncFromHeight(2);

            uint256 expectedHash = this.chainIndexer.GetHeader(1).HashBlock;

            Assert.Equal(this.walletTip.HashBlock, expectedHash);
        }
        public void SyncFromDate_GivenDateNotMatchingBlocksOnChain_UpdatesUsingFirstBlock()
        {
            this.SetupMockObjects(WalletTestsHelpers.GenerateChainWithHeight(3, new StraxMain()));

            this.walletSyncManager.SyncFromDate(new DateTime(1900, 1, 1)); // date before any block.

            uint256 expectedHash = this.chainIndexer.GetHeader(0).HashBlock;

            Assert.Equal(this.walletTip.HashBlock, expectedHash);
        }
        public void SyncFromDate_GivenDateMatchingBlocksOnChain_UpdatesUsingClosestBlock()
        {
            this.SetupMockObjects(WalletTestsHelpers.GenerateChainWithHeight(5, new StraxMain()));

            this.walletSyncManager.SyncFromDate(this.chainIndexer.GetHeader(3).Header.BlockTime.DateTime.AddSeconds(1));

            uint256 expectedHash = this.chainIndexer.GetHeader(3).HashBlock;

            Assert.Equal(this.walletTip.HashBlock, expectedHash);
        }
        public void SyncFromHeight_NoBlockWithGivenHeightOnChain_ThrowsWalletException()
        {
            this.chainIndexer = WalletTestsHelpers.GenerateChainWithHeight(1, KnownNetworks.StratisMain);

            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.SyncFromHeight(2);
            });
        }
Example #8
0
        public void SyncFromHeight_NoBlockWithGivenHeightOnChain_ThrowsWalletException()
        {
            this.chain = WalletTestsHelpers.GenerateChainWithHeight(1, Network.StratisMain);

            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.SyncFromHeight(2);
            });
        }
        public void ProcessTransaction_CallsWalletManager()
        {
            this.SetupMockObjects(WalletTestsHelpers.GenerateChainWithHeight(5, new StraxMain()));

            var transaction = new Transaction
            {
                Version = 15
            };

            this.walletSyncManager.ProcessTransaction(transaction);

            this.walletRepository.Verify(w => w.ProcessTransaction(this.walletName, transaction, null));
        }
        public void SyncFromHeight_BlockWithHeightOnChain_UpdatesWalletTipOnWalletAndWalletSyncManagers()
        {
            this.chainIndexer = WalletTestsHelpers.GenerateChainWithHeight(3, KnownNetworks.StratisMain);

            var walletSyncManager = new WalletSyncManager(this.LoggerFactory.Object, this.walletManager.Object, this.chainIndexer, KnownNetworks.StratisMain,
                                                          this.blockStore.Object, this.storeSettings, this.signals, this.asyncProvider);

            walletSyncManager.SyncFromHeight(2);

            uint256 expectedHash = this.chainIndexer.GetHeader(2).HashBlock;

            Assert.Equal(walletSyncManager.WalletTip.HashBlock, expectedHash);
            this.walletManager.VerifySet(w => w.WalletTipHash = expectedHash);
        }
        public void SyncFromDate_GivenDateNotMatchingBlocksOnChain_UpdatesUsingFirstBlock()
        {
            this.chainIndexer = WalletTestsHelpers.GenerateChainWithHeight(3, KnownNetworks.StratisMain);

            var walletSyncManager = new WalletSyncManager(this.LoggerFactory.Object, this.walletManager.Object, this.chainIndexer, KnownNetworks.StratisMain,
                                                          this.blockStore.Object, this.storeSettings, this.signals, this.asyncProvider);

            walletSyncManager.SyncFromDate(new DateTime(1900, 1, 1)); // date before any block.

            uint256 expectedHash = this.chainIndexer.GetHeader(1).HashBlock;

            Assert.Equal(walletSyncManager.WalletTip.HashBlock, expectedHash);
            this.walletManager.VerifySet(w => w.WalletTipHash = expectedHash);
        }
Example #12
0
        public void SyncFromHeight_BlockWithHeightOnChain_UpdatesWalletTipOnWalletAndWalletSyncManagers()
        {
            this.chain = WalletTestsHelpers.GenerateChainWithHeight(3, Network.StratisMain);

            var walletSyncManager = new WalletSyncManager(this.LoggerFactory.Object, this.walletManager.Object, this.chain, Network.StratisMain,
                                                          this.blockStoreCache.Object, this.storeSettings, this.nodeLifetime.Object);

            walletSyncManager.SyncFromHeight(2);

            uint256 expectedHash = this.chain.GetBlock(2).HashBlock;

            Assert.Equal(walletSyncManager.WalletTip.HashBlock, expectedHash);
            this.walletManager.VerifySet(w => w.WalletTipHash = expectedHash);
        }
Example #13
0
        public void SyncFromDate_GivenDateNotMatchingBlocksOnChain_UpdatesUsingFirstBlock()
        {
            this.chain = WalletTestsHelpers.GenerateChainWithHeight(3, Network.StratisMain);

            var walletSyncManager = new WalletSyncManager(this.LoggerFactory.Object, this.walletManager.Object, this.chain, Network.StratisMain,
                                                          this.blockStoreCache.Object, this.storeSettings, this.nodeLifetime.Object);

            walletSyncManager.SyncFromDate(new System.DateTime(1900, 1, 1)); // date before any block.

            uint256 expectedHash = this.chain.GetBlock(1).HashBlock;

            Assert.Equal(walletSyncManager.WalletTip.HashBlock, expectedHash);
            this.walletManager.VerifySet(w => w.WalletTipHash = expectedHash);
        }
Example #14
0
        public void SyncFromDate_GivenDateMatchingBlocksOnChain_UpdatesUsingClosestBlock()
        {
            this.chain = WalletTestsHelpers.GenerateChainWithHeight(3, Network.StratisMain);

            var walletSyncManager = new WalletSyncManager(this.LoggerFactory.Object, this.walletManager.Object, this.chain, Network.StratisMain,
                                                          this.blockStoreCache.Object, this.storeSettings, this.nodeLifetime.Object);

            walletSyncManager.SyncFromDate(this.chain.GetBlock(3).Header.BlockTime.DateTime.AddDays(2));

            uint256 expectedHash = this.chain.GetBlock(3).HashBlock;

            Assert.Equal(walletSyncManager.WalletTip.HashBlock, expectedHash);
            this.walletManager.VerifySet(w => w.WalletTipHash = expectedHash);
        }