public void Can_sync_on_split_of_length_6() { BlockTree miner1Tree = Build.A.BlockTree(_genesisBlock).OfChainLength(6).TestObject; ISyncPeer miner1 = new SyncPeerMock(miner1Tree); ManualResetEvent resetEvent = new ManualResetEvent(false); _synchronizer.SyncEvent += (sender, args) => { if (args.SyncEvent == SyncEvent.Completed || args.SyncEvent == SyncEvent.Failed) { resetEvent.Set(); } }; _pool.Start(); _synchronizer.Start(); _pool.AddPeer(miner1); resetEvent.WaitOne(_standardTimeoutUnit); Assert.AreEqual(miner1Tree.BestSuggested.Hash, _blockTree.BestSuggested.Hash, "client agrees with miner before split"); miner1Tree.AddBranch(7, 0, 1); Assert.AreNotEqual(miner1Tree.BestSuggested.Hash, _blockTree.BestSuggested.Hash, "client does not agree with miner after split"); resetEvent.Reset(); _syncServer.AddNewBlock(miner1Tree.RetrieveHeadBlock(), miner1.Node); resetEvent.WaitOne(_standardTimeoutUnit); Assert.AreEqual(miner1Tree.BestSuggested.Hash, _blockTree.BestSuggested.Hash, "client agrees with miner after split"); }
public async Task Can_sync_on_split_of_length_6() { BlockTree miner1Tree = Build.A.BlockTree(_genesisBlock).OfChainLength(6).TestObject; ISynchronizationPeer miner1 = new SynchronizationPeerMock(miner1Tree); ManualResetEvent resetEvent = new ManualResetEvent(false); _manager.SyncEvent += (sender, args) => { resetEvent.Set(); }; Task addMiner1Task = _manager.AddPeer(miner1); await Task.WhenAll(addMiner1Task); resetEvent.WaitOne(TimeSpan.FromSeconds(1)); Assert.AreEqual(miner1Tree.BestSuggested.Hash, _blockTree.BestSuggested.Hash, "client agrees with miner before split"); miner1Tree.AddBranch(7, 0, 1); Assert.AreNotEqual(miner1Tree.BestSuggested.Hash, _blockTree.BestSuggested.Hash, "client does not agree with miner after split"); resetEvent.Reset(); _manager.AddNewBlock(miner1Tree.RetrieveHeadBlock(), miner1.NodeId); resetEvent.WaitOne(TimeSpan.FromSeconds(1)); Assert.AreEqual(miner1Tree.BestSuggested.Hash, _blockTree.BestSuggested.Hash, "client agrees with miner after split"); }