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-03-22 05:47:32 -07:00
|
|
|
let service = LightWalletServiceFactory(endpoint: LightWalletEndpointBuilder.eccTestnet).make()
|
2023-02-02 08:58:12 -08:00
|
|
|
|
|
|
|
let realRustBackend = ZcashRustBackend.self
|
|
|
|
|
|
|
|
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-22 05:47:32 -07:00
|
|
|
rustBackend: realRustBackend,
|
|
|
|
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-30 03:49:28 -07:00
|
|
|
try await storage.create()
|
2023-02-02 08:58:12 -08:00
|
|
|
|
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,
|
2023-03-22 05:47:32 -07:00
|
|
|
config: processorConfig,
|
|
|
|
metrics: SDKMetrics(),
|
|
|
|
logger: logger
|
2022-09-01 05:58:41 -07:00
|
|
|
)
|
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-03-27 05:26:47 -07:00
|
|
|
|
|
|
|
let latestHeight = await storage.latestHeight()
|
|
|
|
XCTAssertEqual(latestHeight, range.upperBound)
|
2019-10-18 11:45:19 -07:00
|
|
|
}
|
|
|
|
}
|