コード例 #1
0
        public void Will_not_serve_receipts_requests_above_512()
        {
            StatusMessageSerializer   statusMessageSerializer = new StatusMessageSerializer();
            ReceiptsMessageSerializer receiptMessageSerializer
                = new ReceiptsMessageSerializer(MainnetSpecProvider.Instance);
            GetReceiptsMessageSerializer getReceiptMessageSerializer
                = new GetReceiptsMessageSerializer();
            MessageSerializationService serializationService = new MessageSerializationService();

            serializationService.Register(statusMessageSerializer);
            serializationService.Register(receiptMessageSerializer);
            serializationService.Register(getReceiptMessageSerializer);

            ISyncServer          syncServer      = Substitute.For <ISyncServer>();
            Eth63ProtocolHandler protocolHandler = new Eth63ProtocolHandler(
                _session,
                serializationService,
                Substitute.For <INodeStatsManager>(),
                syncServer,
                Substitute.For <ITxPool>(),
                LimboLogs.Instance);

            StatusMessage statusMessage = new StatusMessage();
            Packet        statusPacket  =
                new Packet("eth", Eth62MessageCode.Status, statusMessageSerializer.Serialize(statusMessage));

            GetReceiptsMessage getReceiptsMessage = new GetReceiptsMessage(
                Enumerable.Repeat(Keccak.Zero, 513).ToArray());
            Packet getReceiptsPacket =
                new Packet("eth", Eth63MessageCode.GetReceipts, getReceiptMessageSerializer.Serialize(getReceiptsMessage));

            protocolHandler.HandleMessage(statusPacket);
            Assert.Throws <EthSyncException>(() => protocolHandler.HandleMessage(getReceiptsPacket));
        }
コード例 #2
0
        public async Task Can_request_and_handle_receipts()
        {
            Context ctx = new Context();
            StatusMessageSerializer   statusMessageSerializer = new StatusMessageSerializer();
            ReceiptsMessageSerializer receiptMessageSerializer
                = new ReceiptsMessageSerializer(MainnetSpecProvider.Instance);
            MessageSerializationService serializationService = new MessageSerializationService();

            serializationService.Register(statusMessageSerializer);
            serializationService.Register(receiptMessageSerializer);

            Eth63ProtocolHandler protocolHandler = new Eth63ProtocolHandler(
                ctx.Session,
                serializationService,
                Substitute.For <INodeStatsManager>(),
                Substitute.For <ISyncServer>(),
                Substitute.For <ITxPool>(),
                LimboLogs.Instance);

            var receipts = Enumerable.Repeat(
                Enumerable.Repeat(Build.A.Receipt.WithAllFieldsFilled.TestObject, 100).ToArray(),
                1000).ToArray(); // TxReceipt[1000][100]

            StatusMessage statusMessage = new StatusMessage();
            Packet        statusPacket  =
                new Packet("eth", Eth62MessageCode.Status, statusMessageSerializer.Serialize(statusMessage));

            ReceiptsMessage receiptsMsg    = new ReceiptsMessage(receipts);
            Packet          receiptsPacket =
                new Packet("eth", Eth63MessageCode.Receipts, receiptMessageSerializer.Serialize(receiptsMsg));

            protocolHandler.HandleMessage(statusPacket);
            Task <TxReceipt[][]> task = protocolHandler.GetReceipts(
                Enumerable.Repeat(Keccak.Zero, 1000).ToArray(),
                CancellationToken.None);

            protocolHandler.HandleMessage(receiptsPacket);

            var result = await task;

            result.Should().HaveCount(1000);
        }
コード例 #3
0
        public void Will_not_send_messages_larger_than_2MB()
        {
            Context ctx = new Context();
            StatusMessageSerializer   statusMessageSerializer = new StatusMessageSerializer();
            ReceiptsMessageSerializer receiptMessageSerializer
                = new ReceiptsMessageSerializer(MainnetSpecProvider.Instance);
            GetReceiptsMessageSerializer getReceiptMessageSerializer
                = new GetReceiptsMessageSerializer();
            MessageSerializationService serializationService = new MessageSerializationService();

            serializationService.Register(statusMessageSerializer);
            serializationService.Register(receiptMessageSerializer);
            serializationService.Register(getReceiptMessageSerializer);

            ISyncServer          syncServer      = Substitute.For <ISyncServer>();
            Eth63ProtocolHandler protocolHandler = new Eth63ProtocolHandler(
                ctx.Session,
                serializationService,
                Substitute.For <INodeStatsManager>(),
                syncServer,
                Substitute.For <ITxPool>(),
                LimboLogs.Instance);

            syncServer.GetReceipts(Arg.Any <Keccak>()).Returns(
                Enumerable.Repeat(Build.A.Receipt.WithAllFieldsFilled.TestObject, 512).ToArray());

            StatusMessage statusMessage = new StatusMessage();
            Packet        statusPacket  =
                new Packet("eth", Eth62MessageCode.Status, statusMessageSerializer.Serialize(statusMessage));

            GetReceiptsMessage getReceiptsMessage = new GetReceiptsMessage(
                Enumerable.Repeat(Keccak.Zero, 512).ToArray());
            Packet getReceiptsPacket =
                new Packet("eth", Eth63MessageCode.GetReceipts, getReceiptMessageSerializer.Serialize(getReceiptsMessage));

            protocolHandler.HandleMessage(statusPacket);
            protocolHandler.HandleMessage(getReceiptsPacket);
            ctx.Session.Received().DeliverMessage(Arg.Is <ReceiptsMessage>(r => r.TxReceipts.Length == 14));
        }