2022-12-01 08:57:13 -08:00
|
|
|
//
|
|
|
|
// CompactBlockProcessorOfflineTests.swift
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// Created by Michal Fousek on 15.12.2022.
|
|
|
|
//
|
|
|
|
|
|
|
|
import XCTest
|
|
|
|
@testable import TestUtils
|
|
|
|
@testable import ZcashLightClientKit
|
|
|
|
|
|
|
|
class CompactBlockProcessorOfflineTests: XCTestCase {
|
2023-02-02 08:58:12 -08:00
|
|
|
let testFileManager = FileManager()
|
2023-03-31 10:10:35 -07:00
|
|
|
var testTempDirectory: URL!
|
2023-02-02 08:58:12 -08:00
|
|
|
|
|
|
|
override func setUpWithError() throws {
|
|
|
|
try super.setUpWithError()
|
2023-03-31 10:10:35 -07:00
|
|
|
testTempDirectory = Environment.uniqueTestTempDirectory
|
|
|
|
try self.testFileManager.createDirectory(at: testTempDirectory, withIntermediateDirectories: false)
|
2023-02-02 08:58:12 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
override func tearDownWithError() throws {
|
|
|
|
try super.tearDownWithError()
|
2023-03-31 10:10:35 -07:00
|
|
|
try FileManager.default.removeItem(at: testTempDirectory)
|
2023-02-02 08:58:12 -08:00
|
|
|
}
|
|
|
|
|
2022-12-01 08:57:13 -08:00
|
|
|
func testComputeProcessingRangeForSingleLoop() async throws {
|
2023-02-02 08:58:12 -08:00
|
|
|
let network = ZcashNetworkBuilder.network(for: .testnet)
|
2023-03-31 10:10:35 -07:00
|
|
|
let rustBackend = ZcashRustBackend.makeForTests(fsBlockDbRoot: testTempDirectory, networkType: .testnet)
|
2023-02-02 08:58:12 -08:00
|
|
|
|
2022-12-01 08:57:13 -08:00
|
|
|
let processorConfig = CompactBlockProcessor.Configuration.standard(
|
2023-02-02 08:58:12 -08:00
|
|
|
for: network,
|
2022-12-01 08:57:13 -08:00
|
|
|
walletBirthday: ZcashNetworkBuilder.network(for: .testnet).constants.saplingActivationHeight
|
|
|
|
)
|
|
|
|
|
|
|
|
let service = MockLightWalletService(
|
|
|
|
latestBlockHeight: 690000,
|
2023-03-22 05:47:32 -07:00
|
|
|
service: LightWalletServiceFactory(endpoint: LightWalletEndpointBuilder.eccTestnet).make()
|
2022-12-01 08:57:13 -08:00
|
|
|
)
|
2023-02-02 08:58:12 -08:00
|
|
|
|
|
|
|
let storage = FSCompactBlockRepository(
|
2023-02-09 04:58:49 -08:00
|
|
|
fsBlockDbRoot: testTempDirectory,
|
2023-02-02 08:58:12 -08:00
|
|
|
metadataStore: FSMetadataStore.live(
|
|
|
|
fsBlockDbRoot: testTempDirectory,
|
2023-03-31 10:10:35 -07:00
|
|
|
rustBackend: rustBackend,
|
2023-03-22 05:47:32 -07:00
|
|
|
logger: logger
|
2023-02-02 08:58:12 -08:00
|
|
|
),
|
|
|
|
blockDescriptor: .live,
|
2023-03-22 05:47:32 -07:00
|
|
|
contentProvider: DirectoryListingProviders.defaultSorted,
|
|
|
|
logger: logger
|
2023-02-02 08:58:12 -08:00
|
|
|
)
|
|
|
|
|
2023-03-22 05:47:32 -07:00
|
|
|
let processor = CompactBlockProcessor(
|
|
|
|
service: service,
|
|
|
|
storage: storage,
|
2023-03-31 10:10:35 -07:00
|
|
|
rustBackend: rustBackend,
|
2023-03-22 05:47:32 -07:00
|
|
|
config: processorConfig,
|
|
|
|
metrics: SDKMetrics(),
|
2023-04-14 00:08:37 -07:00
|
|
|
logger: logger,
|
|
|
|
latestBlocksDataProvider: LatestBlocksDataProviderMock()
|
2023-03-22 05:47:32 -07:00
|
|
|
)
|
2022-12-01 08:57:13 -08:00
|
|
|
|
|
|
|
let fullRange = 0...1000
|
|
|
|
|
|
|
|
var range = await processor.computeSingleLoopDownloadRange(fullRange: fullRange, loopCounter: 0, batchSize: 100)
|
|
|
|
XCTAssertEqual(range, 0...99)
|
|
|
|
|
|
|
|
range = await processor.computeSingleLoopDownloadRange(fullRange: fullRange, loopCounter: 5, batchSize: 100)
|
|
|
|
XCTAssertEqual(range, 500...599)
|
|
|
|
|
|
|
|
range = await processor.computeSingleLoopDownloadRange(fullRange: fullRange, loopCounter: 10, batchSize: 100)
|
|
|
|
XCTAssertEqual(range, 1000...1000)
|
|
|
|
}
|
|
|
|
}
|