ZcashLightClientKit/ZcashLightClientKitTests/utils/FakeService.swift

115 lines
4.1 KiB
Swift
Raw Normal View History

//
// FakeService.swift
// ZcashLightClientKitTests
//
// Created by Francisco Gindre on 10/23/19.
// Copyright © 2019 Electric Coin Company. All rights reserved.
//
import Foundation
import SwiftProtobuf
@testable import ZcashLightClientKit
struct LightWalletServiceMockResponse: LightWalletServiceResponse {
var errorCode: Int32
var errorMessage: String
var unknownFields: UnknownStorage
}
struct MockCancellable: CancellableCall {
func cancel() {}
}
class MockLightWalletService: LightWalletService {
2021-06-17 16:58:30 -07:00
var mockLightDInfo: LightWalletdInfo?
var queue = DispatchQueue(label: "mock service queue")
2021-06-14 16:37:23 -07:00
@discardableResult func blockStream(startHeight: BlockHeight, endHeight: BlockHeight, result: @escaping (Result<GRPCResult, LightWalletServiceError>) -> Void, handler: @escaping (ZcashCompactBlock) -> Void, progress: @escaping (BlockProgressReporting) -> Void) -> CancellableCall {
return MockCancellable()
}
2021-05-18 07:48:32 -07:00
func getInfo() throws -> LightWalletdInfo {
2021-06-17 16:58:30 -07:00
guard let info = mockLightDInfo else {
throw LightWalletServiceError.generalError(message: "Not Implemented")
}
return info
2021-05-18 07:48:32 -07:00
}
func getInfo(result: @escaping (Result<LightWalletdInfo, LightWalletServiceError>) -> Void) {
2021-06-17 16:58:30 -07:00
queue.async { [weak self] in
guard let info = self?.mockLightDInfo else {
result(.failure(LightWalletServiceError.generalError(message: "Not Implemented")))
return
}
result(.success(info))
}
2021-05-18 07:48:32 -07:00
}
2021-05-07 11:50:50 -07:00
func closeConnection() {
}
2021-04-02 15:18:16 -07:00
func fetchUTXOs(for tAddress: String, height: BlockHeight) throws -> [UnspentTransactionOutputEntity] {
[]
}
func fetchUTXOs(for tAddress: String, height: BlockHeight, result: @escaping (Result<[UnspentTransactionOutputEntity], LightWalletServiceError>) -> Void) {
}
func fetchUTXOs(for tAddresses: [String], height: BlockHeight) throws -> [UnspentTransactionOutputEntity] {
[]
}
func fetchUTXOs(for tAddresses: [String], height: BlockHeight, result: @escaping (Result<[UnspentTransactionOutputEntity], LightWalletServiceError>) -> Void) {
}
2020-12-11 13:07:51 -08:00
func fetchUTXOs(for tAddress: String, result: @escaping (Result<[UnspentTransactionOutputEntity], LightWalletServiceError>) -> Void) {
}
2021-05-07 11:50:50 -07:00
private var service = LightWalletGRPCService(endpoint: LightWalletEndpointBuilder.default)
var latestHeight: BlockHeight
init(latestBlockHeight: BlockHeight) {
self.latestHeight = latestBlockHeight
}
func latestBlockHeight(result: @escaping (Result<BlockHeight, LightWalletServiceError>) -> Void) {
DispatchQueue.global().asyncAfter(deadline: .now() + 1) {
result(.success(self.latestHeight))
}
}
func latestBlockHeight() throws -> BlockHeight {
return self.latestHeight
}
func blockRange(_ range: CompactBlockRange, result: @escaping (Result<[ZcashCompactBlock], LightWalletServiceError>) -> Void) {
self.service.blockRange(range, result: result)
}
func blockRange(_ range: CompactBlockRange) throws -> [ZcashCompactBlock] {
try self.service.blockRange(range)
}
func submit(spendTransaction: Data, result: @escaping (Result<LightWalletServiceResponse, LightWalletServiceError>) -> Void) {
DispatchQueue.global(qos: .userInitiated).asyncAfter(deadline: .now() + 1) {
result(.success(LightWalletServiceMockResponse(errorCode: 0, errorMessage: "", unknownFields: UnknownStorage())))
}
}
func submit(spendTransaction: Data) throws -> LightWalletServiceResponse {
return LightWalletServiceMockResponse(errorCode: 0, errorMessage: "", unknownFields: UnknownStorage())
}
func fetchTransaction(txId: Data) throws -> TransactionEntity {
Transaction(id: 1, transactionId: Data(), created: "Today", transactionIndex: 1, expiryHeight: -1, minedHeight: -1, raw: nil)
}
func fetchTransaction(txId: Data, result: @escaping (Result<TransactionEntity, LightWalletServiceError>) -> Void) {
}
}