ZcashLightClientKit/ZcashLightClientKitTests/ZcashLightClientKitTests.swift

72 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
2019-05-08 06:44:12 -07:00
@testable import ZcashLightClientKit
class ZcashLightClientKitTests: XCTestCase {
var latestBlockHeight: BlockHeight!
var service: LightWalletGRPCService!
2019-05-08 06:44:12 -07:00
override func setUp() {
super.setUp()
2021-05-07 11:50:50 -07:00
service = LightWalletGRPCService(endpoint: LightWalletEndpointBuilder.default)
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!
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
}
}
2019-05-08 06:44:12 -07:00
class Environment {
static let lightwalletdKey = "LIGHTWALLETD_ADDRESS"
2019-05-08 06:44:12 -07:00
}