ZcashLightClientKit/Tests/NetworkTests/DownloadOperationTests.swift

52 lines
1.7 KiB
Swift
Raw Normal View History

//
// DownloadOperationTests.swift
// 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
@testable import ZcashLightClientKit
2021-09-23 06:26:41 -07:00
// swiftlint:disable force_try
class DownloadOperationTests: XCTestCase {
var operationQueue = OperationQueue()
2021-07-28 09:59:10 -07:00
var network = ZcashNetworkBuilder.network(for: .testnet)
2021-09-23 06:26:41 -07:00
override func tearDown() {
2021-09-23 06:26:41 -07:00
super.tearDown()
operationQueue.cancelAllOperations()
}
func testSingleOperation() {
let expect = XCTestExpectation(description: self.description)
2021-07-28 15:25:47 -07:00
let service = LightWalletGRPCService(endpoint: LightWalletEndpointBuilder.eccTestnet)
let storage = try! TestDbBuilder.inMemoryCompactBlockStorage()
let downloader = CompactBlockDownloader(service: service, storage: storage)
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
let downloadOperation = CompactBlockDownloadOperation(downloader: downloader, range: range)
2021-09-23 06:26:41 -07:00
downloadOperation.completionHandler = { finished, cancelled in
expect.fulfill()
XCTAssertTrue(finished)
XCTAssertFalse(cancelled)
}
2021-09-23 06:26:41 -07:00
downloadOperation.errorHandler = { error in
XCTFail("Donwload Operation failed with error: \(error)")
}
operationQueue.addOperation(downloadOperation)
wait(for: [expect], timeout: 10)
2021-09-23 06:26:41 -07:00
XCTAssertEqual(try! storage.latestHeight(), range.upperBound)
}
}