[#1046] Implement SaplingParamsAction
- SaplingParamsAction tests - added TODO for TestCoordinator reset() - SaplingParametersHandler mock added
This commit is contained in:
parent
5f9a430a2f
commit
ccb17ef0ea
|
@ -0,0 +1,33 @@
|
|||
//
|
||||
// SaplingParamsActionTests.swift
|
||||
//
|
||||
//
|
||||
// Created by Lukáš Korba on 18.05.2023.
|
||||
//
|
||||
|
||||
import XCTest
|
||||
@testable import TestUtils
|
||||
@testable import ZcashLightClientKit
|
||||
|
||||
final class SaplingParamsActionTests: ZcashTestCase {
|
||||
func testSaplingParamsAction_NextAction() async throws {
|
||||
let loggerMock = LoggerMock()
|
||||
let saplingParametersHandlerMock = SaplingParametersHandlerMock()
|
||||
|
||||
mockContainer.mock(type: Logger.self, isSingleton: true) { _ in loggerMock }
|
||||
mockContainer.mock(type: SaplingParametersHandler.self, isSingleton: true) { _ in saplingParametersHandlerMock }
|
||||
|
||||
let saplingParamsActionAction = SaplingParamsAction(container: mockContainer)
|
||||
|
||||
do {
|
||||
let nextContext = try await saplingParamsActionAction.run(with: .init(state: .handleSaplingParams)) { _ in }
|
||||
let nextState = await nextContext.state
|
||||
XCTAssertTrue(
|
||||
nextState == .scanDownloaded,
|
||||
"nextContext after .handleSaplingParams is expected to be .scanDownloaded but received \(nextState)"
|
||||
)
|
||||
} catch {
|
||||
XCTFail("testSaplingParamsAction_NextAction is not expected to fail. \(error)")
|
||||
}
|
||||
}
|
||||
}
|
|
@ -17,6 +17,7 @@ extension BlockValidator { }
|
|||
extension LightWalletdInfo { }
|
||||
extension LightWalletService { }
|
||||
extension Logger { }
|
||||
extension SaplingParametersHandler { }
|
||||
extension Synchronizer { }
|
||||
extension TransactionRepository { }
|
||||
extension ZcashRustBackendWelding { }
|
||||
|
|
|
@ -426,6 +426,31 @@ class LoggerMock: Logger {
|
|||
errorFileFunctionLineClosure?(message, file, function, line)
|
||||
}
|
||||
|
||||
}
|
||||
class SaplingParametersHandlerMock: SaplingParametersHandler {
|
||||
|
||||
|
||||
init(
|
||||
) {
|
||||
}
|
||||
|
||||
// MARK: - handleIfNeeded
|
||||
|
||||
var handleIfNeededThrowableError: Error?
|
||||
var handleIfNeededCallsCount = 0
|
||||
var handleIfNeededCalled: Bool {
|
||||
return handleIfNeededCallsCount > 0
|
||||
}
|
||||
var handleIfNeededClosure: (() async throws -> Void)?
|
||||
|
||||
func handleIfNeeded() async throws {
|
||||
if let error = handleIfNeededThrowableError {
|
||||
throw error
|
||||
}
|
||||
handleIfNeededCallsCount += 1
|
||||
try await handleIfNeededClosure?()
|
||||
}
|
||||
|
||||
}
|
||||
class SynchronizerMock: Synchronizer {
|
||||
|
||||
|
|
|
@ -212,22 +212,23 @@ extension TestCoordinator {
|
|||
func reset(saplingActivation: BlockHeight, branchID: String, chainName: String) throws {
|
||||
Task {
|
||||
await self.synchronizer.blockProcessor.stop()
|
||||
let config = await self.synchronizer.blockProcessor.config
|
||||
|
||||
let newConfig = CompactBlockProcessor.Configuration(
|
||||
alias: config.alias,
|
||||
fsBlockCacheRoot: config.fsBlockCacheRoot,
|
||||
dataDb: config.dataDb,
|
||||
spendParamsURL: config.spendParamsURL,
|
||||
outputParamsURL: config.outputParamsURL,
|
||||
saplingParamsSourceURL: config.saplingParamsSourceURL,
|
||||
retries: config.retries,
|
||||
maxBackoffInterval: config.maxBackoffInterval,
|
||||
rewindDistance: config.rewindDistance,
|
||||
walletBirthdayProvider: config.walletBirthdayProvider,
|
||||
saplingActivation: saplingActivation,
|
||||
network: config.network
|
||||
)
|
||||
// TODO: [1102] review and potentially fix/remove commented code https://github.com/zcash/ZcashLightClientKit/issues/1102
|
||||
// let config = await self.synchronizer.blockProcessor.config
|
||||
//
|
||||
// let newConfig = CompactBlockProcessor.Configuration(
|
||||
// alias: config.alias,
|
||||
// fsBlockCacheRoot: config.fsBlockCacheRoot,
|
||||
// dataDb: config.dataDb,
|
||||
// spendParamsURL: config.spendParamsURL,
|
||||
// outputParamsURL: config.outputParamsURL,
|
||||
// saplingParamsSourceURL: config.saplingParamsSourceURL,
|
||||
// retries: config.retries,
|
||||
// maxBackoffInterval: config.maxBackoffInterval,
|
||||
// rewindDistance: config.rewindDistance,
|
||||
// walletBirthdayProvider: config.walletBirthdayProvider,
|
||||
// saplingActivation: saplingActivation,
|
||||
// network: config.network
|
||||
// )
|
||||
|
||||
// await self.synchronizer.blockProcessor.update(config: newConfig)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue