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
|
|
|
|
2022-08-25 06:39:59 -07:00
|
|
|
func blockStream(startHeight: BlockHeight, endHeight: BlockHeight) -> AsyncThrowingStream<ZcashCompactBlock, Error> {
|
2022-10-27 03:51:38 -07:00
|
|
|
service.blockStream(startHeight: startHeight, endHeight: endHeight)
|
2022-08-25 06:39:59 -07:00
|
|
|
}
|
|
|
|
|
2021-05-07 11:50:50 -07:00
|
|
|
func closeConnection() {
|
|
|
|
}
|
2022-08-25 06:39:59 -07:00
|
|
|
|
|
|
|
func fetchUTXOs(for tAddress: String, height: BlockHeight) -> AsyncThrowingStream<UnspentTransactionOutputEntity, Error> {
|
2022-10-27 03:51:38 -07:00
|
|
|
service.fetchUTXOs(for: tAddress, height: height)
|
2021-04-02 15:18:16 -07:00
|
|
|
}
|
2022-08-25 06:39:59 -07:00
|
|
|
|
|
|
|
func fetchUTXOs(for tAddresses: [String], height: BlockHeight) -> AsyncThrowingStream<UnspentTransactionOutputEntity, Error> {
|
2022-10-27 03:51:38 -07:00
|
|
|
service.fetchUTXOs(for: tAddresses, height: height)
|
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() throws -> BlockHeight {
|
|
|
|
return self.latestHeight
|
|
|
|
}
|
|
|
|
|
2022-10-03 16:05:11 -07:00
|
|
|
func getInfo() async throws -> LightWalletdInfo {
|
2022-08-25 06:39:59 -07:00
|
|
|
guard let info = mockLightDInfo else {
|
|
|
|
throw LightWalletServiceError.generalError(message: "Not Implemented")
|
|
|
|
}
|
|
|
|
return info
|
|
|
|
}
|
2022-10-03 16:05:11 -07:00
|
|
|
|
2022-08-25 06:39:59 -07:00
|
|
|
func latestBlockHeightAsync() async throws -> BlockHeight {
|
|
|
|
latestHeight
|
|
|
|
}
|
|
|
|
|
|
|
|
func blockRange(_ range: CompactBlockRange) -> AsyncThrowingStream<ZcashCompactBlock, Error> {
|
|
|
|
service.blockRange(range)
|
|
|
|
}
|
|
|
|
|
2022-10-03 16:05:11 -07:00
|
|
|
func submit(spendTransaction: Data) async throws -> LightWalletServiceResponse {
|
2022-08-25 06:39:59 -07:00
|
|
|
LightWalletServiceMockResponse(errorCode: 0, errorMessage: "", unknownFields: UnknownStorage())
|
|
|
|
}
|
|
|
|
|
2022-10-03 16:05:11 -07:00
|
|
|
func fetchTransaction(txId: Data) async throws -> TransactionEntity {
|
2022-08-25 06:39:59 -07:00
|
|
|
Transaction(id: 1, transactionId: Data(), created: "Today", transactionIndex: 1, expiryHeight: -1, minedHeight: -1, raw: nil)
|
|
|
|
}
|
2019-10-30 13:18:57 -07:00
|
|
|
}
|