2019-10-18 11:45:19 -07:00
|
|
|
//
|
2022-09-01 05:58:41 -07:00
|
|
|
// DownloadTests.swift
|
2019-10-18 11:45:19 -07:00
|
|
|
// ZcashLightClientKitTests
|
|
|
|
//
|
|
|
|
// Created by Francisco Gindre on 10/16/19.
|
|
|
|
// Copyright © 2019 Electric Coin Company. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
import XCTest
|
|
|
|
import SQLite
|
2022-02-28 09:03:20 -08:00
|
|
|
@testable import TestUtils
|
2019-10-18 11:45:19 -07:00
|
|
|
@testable import ZcashLightClientKit
|
2021-09-23 06:26:41 -07:00
|
|
|
|
2022-09-01 05:58:41 -07:00
|
|
|
class DownloadTests: XCTestCase {
|
2023-02-02 08:58:12 -08:00
|
|
|
let testTempDirectory = URL(fileURLWithPath: NSString(
|
|
|
|
string: NSTemporaryDirectory()
|
|
|
|
)
|
|
|
|
.appendingPathComponent("tmp-\(Int.random(in: 0 ... .max))"))
|
|
|
|
|
|
|
|
let testFileManager = FileManager()
|
|
|
|
|
2021-07-28 09:59:10 -07:00
|
|
|
var network = ZcashNetworkBuilder.network(for: .testnet)
|
2021-09-23 06:26:41 -07:00
|
|
|
|
2023-02-02 08:58:12 -08:00
|
|
|
override func setUpWithError() throws {
|
|
|
|
try super.setUpWithError()
|
|
|
|
|
|
|
|
try self.testFileManager.createDirectory(at: self.testTempDirectory, withIntermediateDirectories: false)
|
|
|
|
}
|
|
|
|
|
|
|
|
override func tearDownWithError() throws {
|
|
|
|
try super.tearDownWithError()
|
|
|
|
try? testFileManager.removeItem(at: testTempDirectory)
|
2019-10-18 11:45:19 -07:00
|
|
|
}
|
|
|
|
|
2022-09-01 05:58:41 -07:00
|
|
|
func testSingleDownload() async throws {
|
2023-02-03 02:23:35 -08:00
|
|
|
let service = LightWalletServiceFactory(endpoint: LightWalletEndpointBuilder.eccTestnet, connectionStateChange: { _, _ in }).make()
|
2023-02-02 08:58:12 -08:00
|
|
|
|
|
|
|
let realRustBackend = ZcashRustBackend.self
|
|
|
|
|
|
|
|
let storage = FSCompactBlockRepository(
|
|
|
|
cacheDirectory: testTempDirectory,
|
|
|
|
metadataStore: FSMetadataStore.live(
|
|
|
|
fsBlockDbRoot: testTempDirectory,
|
|
|
|
rustBackend: realRustBackend
|
|
|
|
),
|
|
|
|
blockDescriptor: .live,
|
|
|
|
contentProvider: DirectoryListingProviders.defaultSorted
|
|
|
|
)
|
|
|
|
|
|
|
|
try storage.create()
|
|
|
|
|
2019-10-18 11:45:19 -07:00
|
|
|
let blockCount = 100
|
2021-09-15 05:21:29 -07:00
|
|
|
let activationHeight = network.constants.saplingActivationHeight
|
2021-07-28 09:59:10 -07:00
|
|
|
let range = activationHeight ... activationHeight + blockCount
|
2019-10-18 11:45:19 -07:00
|
|
|
|
2022-09-01 05:58:41 -07:00
|
|
|
let processorConfig = CompactBlockProcessor.Configuration.standard(
|
|
|
|
for: network,
|
|
|
|
walletBirthday: network.constants.saplingActivationHeight
|
|
|
|
)
|
2023-02-02 08:58:12 -08:00
|
|
|
|
2022-09-01 05:58:41 -07:00
|
|
|
let compactBlockProcessor = CompactBlockProcessor(
|
|
|
|
service: service,
|
|
|
|
storage: storage,
|
2023-02-02 08:58:12 -08:00
|
|
|
backend: realRustBackend,
|
2022-09-01 05:58:41 -07:00
|
|
|
config: processorConfig
|
|
|
|
)
|
2019-10-18 11:45:19 -07:00
|
|
|
|
2022-09-01 05:58:41 -07:00
|
|
|
do {
|
2023-01-31 02:11:00 -08:00
|
|
|
try await compactBlockProcessor.blockDownloaderService.downloadBlockRange(range)
|
2022-09-01 05:58:41 -07:00
|
|
|
} catch {
|
|
|
|
XCTFail("Download failed with error: \(error)")
|
2019-10-30 13:18:57 -07:00
|
|
|
}
|
|
|
|
|
2023-02-02 08:58:12 -08:00
|
|
|
XCTAssertEqual(storage.latestHeight(), range.upperBound)
|
2019-10-18 11:45:19 -07:00
|
|
|
}
|
|
|
|
}
|