public async Task HandleEvent_Test() { var eventData = new PeerConnectedEventData ( new NodeInfo { Endpoint = "127.0.0.1:1234", Pubkey = ByteString.CopyFromUtf8("Pubkey") }, HashHelper.ComputeFrom("BestChainHash"), 100 ); AnnouncementReceivedEventData announcementEventData = null; _eventBus.Subscribe <AnnouncementReceivedEventData>(d => { announcementEventData = d; return(Task.CompletedTask); }); await _peerConnectedEventHandler.HandleEventAsync(eventData); var nodes = await _peerDiscoveryService.GetNodesAsync(1); nodes.Nodes[0].ShouldBe(eventData.NodeInfo); announcementEventData.ShouldNotBeNull(); announcementEventData.Announce.BlockHash.ShouldBe(eventData.BestChainHash); announcementEventData.Announce.BlockHeight.ShouldBe(eventData.BestChainHeight); announcementEventData.SenderPubKey.ShouldBe(eventData.NodeInfo.Pubkey.ToHex()); }
public async Task AnnounceAsync_Success() { AnnouncementReceivedEventData received = null; _eventBus.Subscribe <AnnouncementReceivedEventData>(a => { received = a; return(Task.CompletedTask); }); var header = new BlockAnnouncement { BlockHeight = 100, BlockHash = Hash.FromRawBytes(new byte[] { 9, 2 }) }; await _grpcPeer.SendAnnouncementAsync(header); received.ShouldNotBeNull(); received.Announce.BlockHeight.ShouldBe(100); }
public async Task AnnounceAsync_Success() { AnnouncementReceivedEventData received = null; _eventBus.Subscribe <AnnouncementReceivedEventData>(a => { received = a; return(Task.CompletedTask); }); var header = new PeerNewBlockAnnouncement { BlockHeight = 100, BlockHash = Hash.Generate(), BlockTime = DateTime.UtcNow.ToTimestamp() }; await _grpcPeer.AnnounceAsync(header); received.ShouldNotBeNull(); received.Announce.BlockHeight.ShouldBe(100); }