public void Can_create_a_final_batch()
        {
            LoadScenario(_64BodiesWithOneTxEachFollowedByEmpty);
            ReceiptsSyncBatch request = _feed.PrepareRequest().Result;

            request.Should().NotBeNull();
            request !.MinNumber.Should().Be(1024);
            request.Prioritized.Should().Be(true);
        }
        public void Returns_same_batch_until_filled()
        {
            LoadScenario(_256BodiesWithOneTxEach);
            ReceiptsSyncBatch request = _feed.PrepareRequest().Result;

            _feed.HandleResponse(request);
            ReceiptsSyncBatch request2 = _feed.PrepareRequest().Result;

            request2.Should().Be(request);
        }
        public void If_comes_back_empty_then_it_can_be_reused()
        {
            LoadScenario(_1024BodiesWithOneTxEach);
            ReceiptsSyncBatch          batch          = _feed.PrepareRequest().Result;
            SyncResponseHandlingResult handlingResult = _feed.HandleResponse(batch);

            handlingResult.Should().Be(SyncResponseHandlingResult.NotAssigned);
            ReceiptsSyncBatch batch2 = _feed.PrepareRequest().Result;

            batch2.Should().BeSameAs(batch);
            batch2.Retries.Should().Be(1);
        }
        public void When_configured_to_skip_receipts_then_finishes_immediately()
        {
            LoadScenario(_256BodiesWithOneTxEach);
            _syncConfig.DownloadReceiptsInFastSync = false;

            ReceiptsSyncBatch request = _feed.PrepareRequest().Result;

            request.Should().BeNull();
            _feed.CurrentState.Should().Be(SyncFeedState.Finished);
            _measuredProgress.HasEnded.Should().BeTrue();
            _measuredProgressQueue.HasEnded.Should().BeTrue();
        }
        public void If_comes_back_filled_with_empty_responses_then_it_can_be_reused()
        {
            LoadScenario(_1024BodiesWithOneTxEach);
            ReceiptsSyncBatch batch = _feed.PrepareRequest().Result;

            batch.Response = new TxReceipt[batch.Request.Length][];
            SyncResponseHandlingResult handlingResult = _feed.HandleResponse(batch);

            handlingResult.Should().Be(SyncResponseHandlingResult.NoProgress);
            ReceiptsSyncBatch batch2 = _feed.PrepareRequest().Result;

            batch2.Should().BeSameAs(batch);
            batch2.Retries.Should().Be(1);
        }
        public void Can_create_a_smaller_request()
        {
            int expectedBatchSize = 64;

            LoadScenario(_64BodiesWithOneTxEach);
            ReceiptsSyncBatch request = _feed.PrepareRequest().Result;

            request.Should().NotBeNull();
            request.MinNumber.Should().Be(_pivotNumber - expectedBatchSize + 1);
            request.Blocks.Length.Should().Be(expectedBatchSize);
            request.Predecessors.Length.Should().Be(expectedBatchSize);
            request.Request.Length.Should().Be(expectedBatchSize);
            request.StartNumber.Should().Be(_pivotNumber - expectedBatchSize + 1);
            request.EndNumber.Should().Be(_pivotNumber);
            request.On.Should().Be(long.MaxValue);
            request.Description.Should().NotBeNull();
            request.Prioritized.Should().Be(true);
        }
        public void Can_create_non_geth_requests()
        {
            int expectedBatchSize = 256;

            _syncConfig.UseGethLimitsInFastBlocks = false;
            LoadScenario(_256BodiesWithOneTxEach, _syncConfig);
            ReceiptsSyncBatch request = _feed.PrepareRequest().Result;

            request.Should().NotBeNull();
            request.MinNumber.Should().Be(_pivotNumber - expectedBatchSize + 1);
            request.Blocks.Length.Should().Be(expectedBatchSize);
            request.Predecessors.Length.Should().Be(expectedBatchSize);
            request.Request.Length.Should().Be(expectedBatchSize);
            request.StartNumber.Should().Be(_pivotNumber - expectedBatchSize + 1);
            request.EndNumber.Should().Be(_pivotNumber);
            request.On.Should().Be(long.MaxValue);
            request.Description.Should().NotBeNull();
            request.Prioritized.Should().Be(true);
        }