Merge pull request #1302 from LukasKorba/1301-foundTransactions-don't-emit-after-rewind
[#1301] foundTransactions don't emit after rewind
This commit is contained in:
commit
8aeafa2f9b
|
@ -22,7 +22,7 @@ actor CompactBlockProcessor {
|
|||
private var syncTask: Task<Void, Error>?
|
||||
|
||||
private let actions: [CBPState: Action]
|
||||
private var context: ActionContext
|
||||
var context: ActionContext
|
||||
|
||||
private(set) var config: Configuration
|
||||
private let configProvider: ConfigProvider
|
||||
|
@ -346,6 +346,8 @@ extension CompactBlockProcessor {
|
|||
} catch {
|
||||
return await context.completion(.failure(error))
|
||||
}
|
||||
|
||||
await resetContext(restoreLastEnhancedHeight: false)
|
||||
|
||||
await context.completion(.success(rewindBlockHeight))
|
||||
}
|
||||
|
@ -615,10 +617,12 @@ extension CompactBlockProcessor {
|
|||
}
|
||||
}
|
||||
|
||||
private func resetContext() async {
|
||||
let lastEnhancedheight = await context.lastEnhancedHeight
|
||||
func resetContext(restoreLastEnhancedHeight: Bool = true) async {
|
||||
let lastEnhancedHeight = await context.lastEnhancedHeight
|
||||
context = ActionContextImpl(state: .idle)
|
||||
await context.update(lastEnhancedHeight: lastEnhancedheight)
|
||||
if restoreLastEnhancedHeight {
|
||||
await context.update(lastEnhancedHeight: lastEnhancedHeight)
|
||||
}
|
||||
}
|
||||
|
||||
private func syncStarted() async {
|
||||
|
|
|
@ -9,7 +9,7 @@ import XCTest
|
|||
@testable import TestUtils
|
||||
@testable import ZcashLightClientKit
|
||||
|
||||
final class ActionContextStateTests: XCTestCase {
|
||||
final class ActionContextStateTests: ZcashTestCase {
|
||||
func testPreviousState() async throws {
|
||||
let syncContext = ActionContextImpl(state: .idle)
|
||||
|
||||
|
@ -32,4 +32,61 @@ final class ActionContextStateTests: XCTestCase {
|
|||
XCTFail("syncContext.prevState is not expected to be nil.")
|
||||
}
|
||||
}
|
||||
|
||||
func testActionContextReset_DefaultBehaviour() async throws {
|
||||
let testCoordinator: TestCoordinator! = try await TestCoordinator(
|
||||
alias: .default,
|
||||
container: mockContainer,
|
||||
walletBirthday: 10,
|
||||
network: ZcashTestnet(),
|
||||
callPrepareInConstructor: false
|
||||
)
|
||||
|
||||
await testCoordinator.synchronizer.blockProcessor.context.update(lastEnhancedHeight: 1_500_000)
|
||||
|
||||
let contextLastEnhancedHeight = await testCoordinator.synchronizer.blockProcessor.context.lastEnhancedHeight
|
||||
|
||||
XCTAssertEqual(contextLastEnhancedHeight, 1_500_000)
|
||||
|
||||
await testCoordinator.synchronizer.blockProcessor.resetContext()
|
||||
|
||||
let contextLastEnhancedHeightAfterReset = await testCoordinator.synchronizer.blockProcessor.context.lastEnhancedHeight
|
||||
|
||||
XCTAssertEqual(
|
||||
contextLastEnhancedHeightAfterReset,
|
||||
1_500_000,
|
||||
"""
|
||||
testActionContextReset_DefaultBehaviour: The context after reset should restore the last enhanced height,
|
||||
received \(String(describing: contextLastEnhancedHeightAfterReset)) instead
|
||||
"""
|
||||
)
|
||||
}
|
||||
|
||||
func testActionContextReset_LastEnhancedHeightReset() async throws {
|
||||
let testCoordinator: TestCoordinator! = try await TestCoordinator(
|
||||
alias: .default,
|
||||
container: mockContainer,
|
||||
walletBirthday: 10,
|
||||
network: ZcashTestnet(),
|
||||
callPrepareInConstructor: false
|
||||
)
|
||||
|
||||
await testCoordinator.synchronizer.blockProcessor.context.update(lastEnhancedHeight: 1_500_000)
|
||||
|
||||
let contextLastEnhancedHeight = await testCoordinator.synchronizer.blockProcessor.context.lastEnhancedHeight
|
||||
|
||||
XCTAssertEqual(contextLastEnhancedHeight, 1_500_000)
|
||||
|
||||
await testCoordinator.synchronizer.blockProcessor.resetContext(restoreLastEnhancedHeight: false)
|
||||
|
||||
let contextLastEnhancedHeightAfterReset = await testCoordinator.synchronizer.blockProcessor.context.lastEnhancedHeight
|
||||
|
||||
XCTAssertNil(
|
||||
contextLastEnhancedHeightAfterReset,
|
||||
"""
|
||||
testActionContextReset_LastEnhancedHeightReset: The context after reset should be nil when forced,
|
||||
received \(String(describing: contextLastEnhancedHeightAfterReset)) instead
|
||||
"""
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue