public void BlockStoreCanRecoverOnStartup() { using (NodeBuilder builder = NodeBuilder.Create()) { var PurpleNodeSync = builder.CreatePurplePowNode(); builder.StartAll(); PurpleNodeSync.NotInIBD(); // generate blocks and wait for the downloader to pickup PurpleNodeSync.SetDummyMinerSecret(new BitcoinSecret(new Key(), PurpleNodeSync.FullNode.Network)); PurpleNodeSync.GeneratePurpleWithMiner(10); TestHelper.WaitLoop(() => TestHelper.IsNodeSynced(PurpleNodeSync)); // set the tip of best chain some blocks in the apst PurpleNodeSync.FullNode.Chain.SetTip(PurpleNodeSync.FullNode.Chain.GetBlock(PurpleNodeSync.FullNode.Chain.Height - 5)); // stop the node it will persist the chain with the reset tip PurpleNodeSync.FullNode.Dispose(); var newNodeInstance = builder.ClonePurpleNode(PurpleNodeSync); // load the node, this should hit the block store recover code newNodeInstance.Start(); // check that store recovered to be the same as the best chain. Assert.Equal(newNodeInstance.FullNode.Chain.Tip.HashBlock, newNodeInstance.FullNode.HighestPersistedBlock().HashBlock); //TestHelper.WaitLoop(() => TestHelper.IsNodeSynced(PurpleNodeSync)); } }
public void WalletCanRecoverOnStartup() { using (NodeBuilder builder = NodeBuilder.Create()) { var PurpleNodeSync = builder.CreatePurplePowNode(); builder.StartAll(); PurpleNodeSync.NotInIBD(); // get a key from the wallet var mnemonic = PurpleNodeSync.FullNode.WalletManager().CreateWallet("123456", "mywallet"); Assert.Equal(12, mnemonic.Words.Length); var addr = PurpleNodeSync.FullNode.WalletManager().GetUnusedAddress(new WalletAccountReference("mywallet", "account 0")); var wallet = PurpleNodeSync.FullNode.WalletManager().GetWalletByName("mywallet"); var key = wallet.GetExtendedPrivateKeyForAddress("123456", addr).PrivateKey; PurpleNodeSync.SetDummyMinerSecret(key.GetBitcoinSecret(PurpleNodeSync.FullNode.Network)); PurpleNodeSync.GeneratePurple(10); TestHelper.WaitLoop(() => TestHelper.IsNodeSynced(PurpleNodeSync)); // set the tip of best chain some blocks in the apst PurpleNodeSync.FullNode.Chain.SetTip(PurpleNodeSync.FullNode.Chain.GetBlock(PurpleNodeSync.FullNode.Chain.Height - 5)); // stop the node it will persist the chain with the reset tip PurpleNodeSync.FullNode.Dispose(); var newNodeInstance = builder.ClonePurpleNode(PurpleNodeSync); // load the node, this should hit the block store recover code newNodeInstance.Start(); // check that store recovered to be the same as the best chain. Assert.Equal(newNodeInstance.FullNode.Chain.Tip.HashBlock, newNodeInstance.FullNode.WalletManager().WalletTipHash); } }