Merge pull request #1117 from LukasKorba/1040-Implement-ClearAlreadyScannedBlocksAction

- Implement ClearAlreadyScannedBlocksAction tests
This commit is contained in:
Lukas Korba 2023-05-23 08:43:05 +02:00 committed by GitHub
commit 23378a5a8d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 40 additions and 0 deletions

View File

@ -0,0 +1,40 @@
//
// ClearAlreadyScannedBlocksActionTests.swift
//
//
// Created by Lukáš Korba on 22.05.2023.
//
import XCTest
@testable import TestUtils
@testable import ZcashLightClientKit
final class ClearAlreadyScannedBlocksActionTests: ZcashTestCase {
func testClearAlreadyScannedBlocksActionTests_NextAction() async throws {
let compactBlockRepositoryMock = CompactBlockRepositoryMock()
let transactionRepositoryMock = TransactionRepositoryMock()
compactBlockRepositoryMock.clearUpToClosure = { _ in }
transactionRepositoryMock.lastScannedHeightReturnValue = 1
mockContainer.mock(type: CompactBlockRepository.self, isSingleton: true) { _ in compactBlockRepositoryMock }
mockContainer.mock(type: TransactionRepository.self, isSingleton: true) { _ in transactionRepositoryMock }
let clearAlreadyScannedBlocksAction = ClearAlreadyScannedBlocksAction(
container: mockContainer
)
do {
let nextContext = try await clearAlreadyScannedBlocksAction.run(with: .init(state: .clearAlreadyScannedBlocks)) { _ in }
XCTAssertTrue(compactBlockRepositoryMock.clearUpToCalled, "storage.clear(upTo:) is expected to be called.")
XCTAssertTrue(transactionRepositoryMock.lastScannedHeightCalled, "transactionRepository.lastScannedHeight() is expected to be called.")
let nextState = await nextContext.state
XCTAssertTrue(
nextState == .enhance,
"nextContext after .clearAlreadyScannedBlocks is expected to be .enhance but received \(nextState)"
)
} catch {
XCTFail("testClearAlreadyScannedBlocksActionTests_NextAction is not expected to fail. \(error)")
}
}
}