2019-10-18 11:45:19 -07:00
|
|
|
//
|
|
|
|
// DownloadOperationTests.swift
|
|
|
|
// ZcashLightClientKitTests
|
|
|
|
//
|
|
|
|
// Created by Francisco Gindre on 10/16/19.
|
|
|
|
// Copyright © 2019 Electric Coin Company. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
import XCTest
|
|
|
|
import SQLite
|
|
|
|
@testable import ZcashLightClientKit
|
|
|
|
class DownloadOperationTests: XCTestCase {
|
|
|
|
|
|
|
|
var operationQueue = OperationQueue()
|
|
|
|
|
|
|
|
override func tearDown() {
|
|
|
|
// Put teardown code here. This method is called after the invocation of each test method in the class.
|
|
|
|
operationQueue.cancelAllOperations()
|
|
|
|
}
|
|
|
|
|
|
|
|
func testSingleOperation() {
|
|
|
|
let expect = XCTestExpectation(description: self.description)
|
|
|
|
|
|
|
|
let service = LightWalletGRPCService(channel: ChannelProvider().channel())
|
|
|
|
let storage = try! TestDbBuilder.inMemoryCompactBlockStorage()
|
|
|
|
let downloader = CompactBlockDownloader(service: service, storage: storage)
|
|
|
|
let blockCount = 100
|
2020-02-26 08:54:48 -08:00
|
|
|
let range = ZcashSDK.SAPLING_ACTIVATION_HEIGHT ... ZcashSDK.SAPLING_ACTIVATION_HEIGHT + blockCount
|
2019-10-18 11:45:19 -07:00
|
|
|
let downloadOperation = CompactBlockDownloadOperation(downloader: downloader, range: range)
|
|
|
|
|
2019-10-30 13:18:57 -07:00
|
|
|
downloadOperation.completionHandler = { (finished, cancelled) in
|
2019-10-18 11:45:19 -07:00
|
|
|
expect.fulfill()
|
|
|
|
XCTAssertTrue(finished)
|
|
|
|
XCTAssertFalse(cancelled)
|
|
|
|
}
|
|
|
|
|
2019-10-30 13:18:57 -07:00
|
|
|
downloadOperation.errorHandler = { (error) in
|
|
|
|
XCTFail("Donwload Operation failed with error: \(error)")
|
|
|
|
}
|
|
|
|
|
2019-10-18 11:45:19 -07:00
|
|
|
operationQueue.addOperation(downloadOperation)
|
|
|
|
|
2019-12-03 09:11:24 -08:00
|
|
|
wait(for: [expect], timeout: 10)
|
2019-10-18 11:45:19 -07:00
|
|
|
|
2020-02-26 08:54:48 -08:00
|
|
|
XCTAssertEqual(try! storage.latestHeight(),range.upperBound)
|
2019-10-18 11:45:19 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|