Merge pull request #1224 from LukasKorba/1223-Requested-height-over-latestheight]-does-not-exist-in-the-block-cache
[#1223] Requested height [over latestheight] does not exist in the bl…
This commit is contained in:
commit
eca88735b4
|
@ -5,8 +5,8 @@
|
|||
"kind" : "remoteSourceControl",
|
||||
"location" : "https://github.com/grpc/grpc-swift.git",
|
||||
"state" : {
|
||||
"revision" : "130467153ff0acd642d2f098b69c1ac33373b24e",
|
||||
"version" : "1.15.0"
|
||||
"revision" : "84bac657e9930d26e9124bac082f26586dc2d209",
|
||||
"version" : "1.19.1"
|
||||
}
|
||||
},
|
||||
{
|
||||
|
@ -104,8 +104,8 @@
|
|||
"kind" : "remoteSourceControl",
|
||||
"location" : "https://github.com/apple/swift-nio.git",
|
||||
"state" : {
|
||||
"revision" : "d1690f85419fdac8d54e350fb6d2ab9fd95afd75",
|
||||
"version" : "2.51.1"
|
||||
"revision" : "cf281631ff10ec6111f2761052aa81896a83a007",
|
||||
"version" : "2.58.0"
|
||||
}
|
||||
},
|
||||
{
|
||||
|
|
|
@ -11,12 +11,10 @@ final class ScanAction {
|
|||
let configProvider: CompactBlockProcessor.ConfigProvider
|
||||
let blockScanner: BlockScanner
|
||||
let logger: Logger
|
||||
let transactionRepository: TransactionRepository
|
||||
|
||||
init(container: DIContainer, configProvider: CompactBlockProcessor.ConfigProvider) {
|
||||
self.configProvider = configProvider
|
||||
blockScanner = container.resolve(BlockScanner.self)
|
||||
transactionRepository = container.resolve(TransactionRepository.self)
|
||||
logger = container.resolve(Logger.self)
|
||||
}
|
||||
|
||||
|
@ -45,7 +43,7 @@ extension ScanAction: Action {
|
|||
return await update(context: context)
|
||||
}
|
||||
|
||||
let batchRange = batchRangeStart...batchRangeStart + config.batchSize
|
||||
let batchRange = batchRangeStart...batchRangeEnd
|
||||
|
||||
logger.debug("Starting scan blocks with range: \(batchRange.lowerBound)...\(batchRange.upperBound)")
|
||||
let totalProgressRange = await context.totalProgressRange
|
||||
|
|
|
@ -12,14 +12,12 @@ import XCTest
|
|||
final class ScanActionTests: ZcashTestCase {
|
||||
func testScanAction_NextAction() async throws {
|
||||
let blockScannerMock = BlockScannerMock()
|
||||
let transactionRepositoryMock = TransactionRepositoryMock()
|
||||
let loggerMock = LoggerMock()
|
||||
|
||||
transactionRepositoryMock.lastScannedHeightReturnValue = 1500
|
||||
loggerMock.debugFileFunctionLineClosure = { _, _, _, _ in }
|
||||
blockScannerMock.scanBlocksAtTotalProgressRangeDidScanClosure = { _, _, _ in 2 }
|
||||
|
||||
let scanAction = setupAction(blockScannerMock, transactionRepositoryMock, loggerMock)
|
||||
let scanAction = setupAction(blockScannerMock, loggerMock)
|
||||
|
||||
let syncContext = ActionContextMock.default()
|
||||
syncContext.lastScannedHeight = 1500
|
||||
|
@ -52,18 +50,13 @@ final class ScanActionTests: ZcashTestCase {
|
|||
|
||||
func testScanAction_EarlyOutForNoDownloadAndScanRangeSet() async throws {
|
||||
let blockScannerMock = BlockScannerMock()
|
||||
let transactionRepositoryMock = TransactionRepositoryMock()
|
||||
let loggerMock = LoggerMock()
|
||||
|
||||
let scanAction = setupAction(blockScannerMock, transactionRepositoryMock, loggerMock)
|
||||
let scanAction = setupAction(blockScannerMock, loggerMock)
|
||||
let syncContext = ActionContextMock.default()
|
||||
|
||||
do {
|
||||
_ = try await scanAction.run(with: syncContext) { _ in }
|
||||
XCTAssertFalse(
|
||||
transactionRepositoryMock.lastScannedHeightCalled,
|
||||
"transactionRepository.lastScannedHeight() is not expected to be called."
|
||||
)
|
||||
XCTAssertFalse(loggerMock.debugFileFunctionLineCalled, "logger.debug(...) is not expected to be called.")
|
||||
XCTAssertFalse(blockScannerMock.scanBlocksAtTotalProgressRangeDidScanCalled, "blockScanner.scanBlocks(...) is not expected to be called.")
|
||||
} catch {
|
||||
|
@ -73,14 +66,17 @@ final class ScanActionTests: ZcashTestCase {
|
|||
|
||||
func testScanAction_StartRangeHigherThanEndRange() async throws {
|
||||
let blockScannerMock = BlockScannerMock()
|
||||
let transactionRepositoryMock = TransactionRepositoryMock()
|
||||
let loggerMock = LoggerMock()
|
||||
|
||||
transactionRepositoryMock.lastScannedHeightReturnValue = 2001
|
||||
|
||||
let scanAction = setupAction(blockScannerMock, transactionRepositoryMock, loggerMock)
|
||||
let scanAction = setupAction(blockScannerMock, loggerMock)
|
||||
let syncContext = ActionContextMock.default()
|
||||
|
||||
syncContext.lastScannedHeight = 2001
|
||||
syncContext.underlyingSyncControlData = SyncControlData(
|
||||
latestBlockHeight: 2000,
|
||||
latestScannedHeight: 1000,
|
||||
firstUnenhancedHeight: nil
|
||||
)
|
||||
|
||||
do {
|
||||
_ = try await scanAction.run(with: syncContext) { _ in }
|
||||
XCTAssertFalse(loggerMock.debugFileFunctionLineCalled, "logger.debug(...) is not expected to be called.")
|
||||
|
@ -90,13 +86,71 @@ final class ScanActionTests: ZcashTestCase {
|
|||
}
|
||||
}
|
||||
|
||||
func testScanAction_EndRangeProperlySetLowerThanBatchSize() async throws {
|
||||
let blockScannerMock = BlockScannerMock()
|
||||
let loggerMock = LoggerMock()
|
||||
|
||||
loggerMock.debugFileFunctionLineClosure = { _, _, _, _ in }
|
||||
blockScannerMock.scanBlocksAtTotalProgressRangeDidScanClosure = { _, _, _ in 2 }
|
||||
|
||||
let scanAction = setupAction(blockScannerMock, loggerMock)
|
||||
let syncContext = ActionContextMock.default()
|
||||
syncContext.lastScannedHeight = 1001
|
||||
syncContext.underlyingTotalProgressRange = 1000...1078
|
||||
syncContext.underlyingSyncControlData = SyncControlData(
|
||||
latestBlockHeight: 1078,
|
||||
latestScannedHeight: 1000,
|
||||
firstUnenhancedHeight: nil
|
||||
)
|
||||
|
||||
do {
|
||||
_ = try await scanAction.run(with: syncContext) { _ in }
|
||||
XCTAssertTrue(loggerMock.debugFileFunctionLineCalled, "logger.debug(...) is expected to be called.")
|
||||
XCTAssertTrue(blockScannerMock.scanBlocksAtTotalProgressRangeDidScanCalled, "blockScanner.scanBlocks(...) is expected to be called.")
|
||||
|
||||
if let scanArguments = blockScannerMock.scanBlocksAtTotalProgressRangeDidScanReceivedArguments {
|
||||
XCTAssertEqual(scanArguments.range.upperBound, 1078)
|
||||
}
|
||||
} catch {
|
||||
XCTFail("testScanAction_EndRangeProperlySetLowerThanBatchSize is not expected to fail. \(error)")
|
||||
}
|
||||
}
|
||||
|
||||
func testScanAction_EndRangeProperlySetBatchSize() async throws {
|
||||
let blockScannerMock = BlockScannerMock()
|
||||
let loggerMock = LoggerMock()
|
||||
|
||||
loggerMock.debugFileFunctionLineClosure = { _, _, _, _ in }
|
||||
blockScannerMock.scanBlocksAtTotalProgressRangeDidScanClosure = { _, _, _ in 2 }
|
||||
|
||||
let scanAction = setupAction(blockScannerMock, loggerMock)
|
||||
let syncContext = ActionContextMock.default()
|
||||
syncContext.lastScannedHeight = 1001
|
||||
syncContext.underlyingTotalProgressRange = 1000...1978
|
||||
syncContext.underlyingSyncControlData = SyncControlData(
|
||||
latestBlockHeight: 1978,
|
||||
latestScannedHeight: 1000,
|
||||
firstUnenhancedHeight: nil
|
||||
)
|
||||
|
||||
do {
|
||||
_ = try await scanAction.run(with: syncContext) { _ in }
|
||||
XCTAssertTrue(loggerMock.debugFileFunctionLineCalled, "logger.debug(...) is expected to be called.")
|
||||
XCTAssertTrue(blockScannerMock.scanBlocksAtTotalProgressRangeDidScanCalled, "blockScanner.scanBlocks(...) is expected to be called.")
|
||||
|
||||
if let scanArguments = blockScannerMock.scanBlocksAtTotalProgressRangeDidScanReceivedArguments {
|
||||
XCTAssertEqual(scanArguments.range.upperBound, 1101)
|
||||
}
|
||||
} catch {
|
||||
XCTFail("testScanAction_EndRangeProperlySetBatchSize is not expected to fail. \(error)")
|
||||
}
|
||||
}
|
||||
|
||||
private func setupAction(
|
||||
_ blockScannerMock: BlockScannerMock,
|
||||
_ transactionRepositoryMock: TransactionRepositoryMock,
|
||||
_ loggerMock: LoggerMock
|
||||
) -> ScanAction {
|
||||
mockContainer.mock(type: BlockScanner.self, isSingleton: true) { _ in blockScannerMock }
|
||||
mockContainer.mock(type: TransactionRepository.self, isSingleton: true) { _ in transactionRepositoryMock }
|
||||
mockContainer.mock(type: Logger.self, isSingleton: true) { _ in loggerMock }
|
||||
|
||||
let config: CompactBlockProcessor.Configuration = .standard(
|
||||
|
|
Loading…
Reference in New Issue