public void Get_headers_from_genesis() { var msg = new GetBlockHeadersMessage(); msg.StartBlockHash = TestItem.KeccakA; msg.MaxHeaders = 3; msg.Skip = 1; msg.Reverse = 1; HandleIncomingStatusMessage(); HandleZeroMessage(msg, Eth62MessageCode.GetBlockHeaders); _syncManager.Received().FindHeaders(TestItem.KeccakA, 3, 1, true); }
public void Should_stop_notifying_about_new_blocks_and_new_block_hashes_if_in_PoS() { _gossipPolicy.CanGossipBlocks.Returns(false); _handler = new Eth62ProtocolHandler( _session, _svc, new NodeStatsManager(Substitute.For <ITimerFactory>(), LimboLogs.Instance), _syncManager, _transactionPool, _gossipPolicy, LimboLogs.Instance); _syncManager.Received().StopNotifyingPeersAboutNewBlocks(); }
public async Task Broadcast_NewBlock_on_arrival() { Context ctx = new(); BlockTree remoteBlockTree = Build.A.BlockTree().OfChainLength(10).TestObject; BlockTree localBlockTree = Build.A.BlockTree().OfChainLength(9).TestObject; ctx.SyncServer = new SyncServer( new MemDb(), new MemDb(), localBlockTree, NullReceiptStorage.Instance, Always.Valid, Always.Valid, ctx.PeerPool, StaticSelector.Full, new SyncConfig(), NullWitnessCollector.Instance, Policy.FullGossip, MainnetSpecProvider.Instance, LimboLogs.Instance); ISyncServer remoteServer1 = Substitute.For <ISyncServer>(); SyncPeerMock syncPeerMock1 = new(remoteBlockTree, TestItem.PublicKeyA, remoteSyncServer : remoteServer1); PeerInfo peer1 = new(syncPeerMock1); ISyncServer remoteServer2 = Substitute.For <ISyncServer>(); SyncPeerMock syncPeerMock2 = new(remoteBlockTree, TestItem.PublicKeyB, remoteSyncServer : remoteServer2); PeerInfo peer2 = new(syncPeerMock2); PeerInfo[] peers = { peer1, peer2 }; ctx.PeerPool.AllPeers.Returns(peers); ctx.PeerPool.PeerCount.Returns(peers.Length); ctx.SyncServer.AddNewBlock(remoteBlockTree.Head !, peer1.SyncPeer); await Task.Delay(100); // notifications fire on separate task await Task.WhenAll(syncPeerMock1.Close(), syncPeerMock2.Close()); remoteServer1.DidNotReceive().AddNewBlock(remoteBlockTree.Head !, Arg.Any <ISyncPeer>()); remoteServer2.Received().AddNewBlock(Arg.Is <Block>(b => b.Hash == remoteBlockTree.Head !.Hash), Arg.Any <ISyncPeer>()); }