public void ShouldTriggerBlockRequested() { using (DataGetFixture fixture = new DataGetFixture()) using (DataGetSession session = fixture.Start()) { BlockReserved reserved = new BlockReserved { Hash = session.Service.Hash, Peer = PeerHash.Random(), Block = new BlockIndex(1, 0, 3616) }; Trigger handler = Trigger.Bind(ref session.Service.Hooks.OnBlockRequested, data => { data.Hash.Should().Be(session.Service.Hash); data.Peer.Should().Be(reserved.Peer); data.Block.Should().Be(reserved.Block); data.Block.Size.Should().Be(3616); }); session.Service.Start(); session.Service.Handle(reserved); session.Pipeline.Process(); handler.Wait().Should().BeTrue(); } }
public void Handle(BlockReserved data) { context.Queue.Add(() => { context.Dependencies.Glue.SendRequest(data.Peer, data.Block); context.Hooks.CallBlockRequested(data.Hash, data.Peer, data.Block); }); }
public void ShouldSendRequestWhenBlockReserved() { using (DataGetFixture fixture = new DataGetFixture()) using (DataGetSession session = fixture.Start()) { BlockReserved received = new BlockReserved { Peer = PeerHash.Random(), Hash = session.Service.Hash, Block = new BlockIndex(1, 0, 3616) }; session.Service.Start(); session.Service.Handle(received); session.Pipeline.Process(); A.CallTo(() => session.Glue.SendRequest(received.Peer, received.Block)).MustHaveHappened(); } }