2019-10-30 13:18:57 -07:00
|
|
|
//
|
|
|
|
// FakeService.swift
|
|
|
|
// ZcashLightClientKitTests
|
|
|
|
//
|
|
|
|
// Created by Francisco Gindre on 10/23/19.
|
|
|
|
// Copyright © 2019 Electric Coin Company. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
import Foundation
|
2019-12-03 07:19:44 -08:00
|
|
|
import SwiftProtobuf
|
2019-10-30 13:18:57 -07:00
|
|
|
@testable import ZcashLightClientKit
|
2019-12-03 07:19:44 -08:00
|
|
|
|
|
|
|
struct LightWalletServiceMockResponse: LightWalletServiceResponse {
|
|
|
|
var errorCode: Int32
|
|
|
|
var errorMessage: String
|
|
|
|
var unknownFields: UnknownStorage
|
|
|
|
}
|
2021-09-23 06:26:41 -07:00
|
|
|
|
2021-05-28 15:45:18 -07:00
|
|
|
struct MockCancellable: CancellableCall {
|
|
|
|
func cancel() {}
|
|
|
|
}
|
2021-09-23 06:26:41 -07:00
|
|
|
|
2019-10-30 13:18:57 -07:00
|
|
|
class MockLightWalletService: LightWalletService {
|
2021-06-17 16:58:30 -07:00
|
|
|
var mockLightDInfo: LightWalletdInfo?
|
|
|
|
var queue = DispatchQueue(label: "mock service queue")
|
2021-09-23 06:26:41 -07:00
|
|
|
|
|
|
|
@discardableResult
|
|
|
|
func blockStream(
|
|
|
|
startHeight: BlockHeight,
|
|
|
|
endHeight: BlockHeight,
|
|
|
|
result: @escaping (Result<GRPCResult, LightWalletServiceError>) -> Void,
|
|
|
|
handler: @escaping (ZcashCompactBlock) -> Void,
|
|
|
|
progress: @escaping (BlockProgress) -> Void
|
|
|
|
) -> CancellableCall {
|
2021-05-28 15:45:18 -07:00
|
|
|
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] {
|
|
|
|
[]
|
|
|
|
}
|
|
|
|
|
2021-09-23 06:26:41 -07:00
|
|
|
func fetchUTXOs(
|
|
|
|
for tAddress: String,
|
|
|
|
height: BlockHeight,
|
|
|
|
result: @escaping (Result<[UnspentTransactionOutputEntity], LightWalletServiceError>) -> Void
|
|
|
|
) {
|
2021-04-02 15:18:16 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
func fetchUTXOs(for tAddresses: [String], height: BlockHeight) throws -> [UnspentTransactionOutputEntity] {
|
|
|
|
[]
|
|
|
|
}
|
|
|
|
|
2021-09-23 06:26:41 -07:00
|
|
|
func fetchUTXOs(
|
|
|
|
for tAddresses: [String],
|
|
|
|
height: BlockHeight,
|
|
|
|
result: @escaping (Result<[UnspentTransactionOutputEntity], LightWalletServiceError>) -> Void
|
|
|
|
) {
|
2021-04-02 15:18:16 -07:00
|
|
|
}
|
|
|
|
|
2021-09-23 06:26:41 -07:00
|
|
|
func fetchUTXOs(
|
|
|
|
for tAddress: String,
|
|
|
|
result: @escaping (Result<[UnspentTransactionOutputEntity], LightWalletServiceError>) -> Void
|
|
|
|
) {
|
2020-12-11 13:07:51 -08:00
|
|
|
}
|
|
|
|
|
2021-07-28 15:25:47 -07:00
|
|
|
private var service: LightWalletService
|
2020-04-23 10:11:03 -07:00
|
|
|
|
2020-06-03 16:18:57 -07:00
|
|
|
var latestHeight: BlockHeight
|
|
|
|
|
2021-07-28 15:25:47 -07:00
|
|
|
init(latestBlockHeight: BlockHeight, service: LightWalletService) {
|
2019-10-30 13:18:57 -07:00
|
|
|
self.latestHeight = latestBlockHeight
|
2021-07-28 15:25:47 -07:00
|
|
|
self.service = service
|
2019-10-30 13:18:57 -07:00
|
|
|
}
|
2021-07-28 15:25:47 -07:00
|
|
|
|
2019-10-30 13:18:57 -07:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2020-02-26 08:54:48 -08:00
|
|
|
func blockRange(_ range: CompactBlockRange, result: @escaping (Result<[ZcashCompactBlock], LightWalletServiceError>) -> Void) {
|
2019-10-30 13:18:57 -07:00
|
|
|
self.service.blockRange(range, result: result)
|
|
|
|
}
|
|
|
|
|
|
|
|
func blockRange(_ range: CompactBlockRange) throws -> [ZcashCompactBlock] {
|
|
|
|
try self.service.blockRange(range)
|
|
|
|
}
|
|
|
|
|
2019-12-03 07:19:44 -08:00
|
|
|
func submit(spendTransaction: Data, result: @escaping (Result<LightWalletServiceResponse, LightWalletServiceError>) -> Void) {
|
2022-07-29 11:20:55 -07:00
|
|
|
DispatchQueue.global(qos: .default).asyncAfter(deadline: .now() + 1) {
|
2019-12-03 07:19:44 -08:00
|
|
|
result(.success(LightWalletServiceMockResponse(errorCode: 0, errorMessage: "", unknownFields: UnknownStorage())))
|
|
|
|
}
|
|
|
|
}
|
2019-10-30 13:18:57 -07:00
|
|
|
|
2019-12-03 07:19:44 -08:00
|
|
|
func submit(spendTransaction: Data) throws -> LightWalletServiceResponse {
|
|
|
|
return LightWalletServiceMockResponse(errorCode: 0, errorMessage: "", unknownFields: UnknownStorage())
|
|
|
|
}
|
2020-06-03 16:18:57 -07:00
|
|
|
|
|
|
|
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) {
|
|
|
|
}
|
2019-10-30 13:18:57 -07:00
|
|
|
}
|