ZcashLightClientKit/Tests/DarksideTests/ZcashLightClientKitTests.swift

62 lines
1.8 KiB
Swift
Raw Normal View History

2019-05-08 06:44:12 -07:00
//
// ZcashLightClientKitTests.swift
// ZcashLightClientKitTests
//
// Created by Jack Grigg on 5/8/19.
// Copyright © 2019 Electric Coin Company. All rights reserved.
//
import XCTest
import GRPC
2022-02-28 09:03:20 -08:00
@testable import TestUtils
2019-05-08 06:44:12 -07:00
@testable import ZcashLightClientKit
2021-09-23 06:26:41 -07:00
// swiftlint:disable implicitly_unwrapped_optional force_try force_unwrapping
2019-05-08 06:44:12 -07:00
class ZcashLightClientKitTests: XCTestCase {
var latestBlockHeight: BlockHeight!
var service: LightWalletGRPCService!
2021-09-23 06:26:41 -07:00
2019-05-08 06:44:12 -07:00
override func setUp() {
super.setUp()
2021-07-28 09:59:10 -07:00
service = LightWalletGRPCService(endpoint: LightWalletEndpoint(address: Constants.address, port: 9067))
latestBlockHeight = try! service.latestBlock().compactBlockHeight()!
2019-05-08 06:44:12 -07:00
}
2019-05-08 06:44:12 -07:00
override func tearDown() {
super.tearDown()
service = nil
latestBlockHeight = nil
2019-05-08 06:44:12 -07:00
}
func testEnvironmentLaunch() {
let address = Constants.address
XCTAssertFalse(address.isEmpty, "Your \'\(Environment.lightwalletdKey)\' key is missing from your launch environment variables")
2019-05-08 06:44:12 -07:00
}
func testService() {
// and that it has a non-zero size
XCTAssert(latestBlockHeight > 0)
}
func testBlockRangeServiceTilLastest() {
let expectedCount: BlockHeight = 99
var count: BlockHeight = 0
let startHeight = latestBlockHeight - expectedCount
let endHeight = latestBlockHeight!
2021-09-23 06:26:41 -07:00
var blocks: [CompactBlock] = []
guard let call = try? service!.blockRange(startHeight: startHeight, endHeight: endHeight, result: {
blocks.append($0)
count += 1
}) else {
XCTFail("failed to create getBlockRange( \(startHeight) ..<= \(endHeight)")
return
2019-05-08 06:44:12 -07:00
}
_ = try! call.status.wait()
XCTAssertEqual(expectedCount + 1, count)
2019-05-08 06:44:12 -07:00
}
}