diff --git a/Sources/ZcashLightClientKit/Block/Processor/CompactBlockProcessor.swift b/Sources/ZcashLightClientKit/Block/Processor/CompactBlockProcessor.swift index 6a7f7e36..e2d460e2 100644 --- a/Sources/ZcashLightClientKit/Block/Processor/CompactBlockProcessor.swift +++ b/Sources/ZcashLightClientKit/Block/Processor/CompactBlockProcessor.swift @@ -500,7 +500,6 @@ public actor CompactBlockProcessor { notifyError(CompactBlockProcessorError.maxAttemptsReached(attempts: self.maxAttempts)) case .downloading, .validating, .scanning, .enhancing, .fetching: LoggerProxy.debug("Warning: compact block processor was started while busy!!!!") - needsToStartScanningWhenStopped.set(true) } return } @@ -1000,9 +999,6 @@ extension CompactBlockProcessor { guard accountIndex >= 0 else { throw CompactBlockProcessorError.invalidAccount } - return try utxoCacheBalance(tAddress: tAddress) - } -} return WalletBalance( verified: Zatoshi( diff --git a/Sources/ZcashLightClientKit/Synchronizer.swift b/Sources/ZcashLightClientKit/Synchronizer.swift index 3b51e434..e88c4b69 100644 --- a/Sources/ZcashLightClientKit/Synchronizer.swift +++ b/Sources/ZcashLightClientKit/Synchronizer.swift @@ -93,7 +93,7 @@ public protocol Synchronizer { /// Gets the sapling shielded address for the given account. /// - Parameter accountIndex: the optional accountId whose address is of interest. By default, the first account is used. /// - Returns the address or nil if account index is incorrect - func getSaplingAddress(accountIndex: Int) -> SaplingAddress? + func getSaplingAddress(accountIndex: Int) async -> SaplingAddress? /// Gets the unified address for the given account. /// - Parameter accountIndex: the optional accountId whose address is of interest. By default, the first account is used. diff --git a/Sources/ZcashLightClientKit/Synchronizer/SDKSynchronizer.swift b/Sources/ZcashLightClientKit/Synchronizer/SDKSynchronizer.swift index 100e2534..e24a4207 100644 --- a/Sources/ZcashLightClientKit/Synchronizer/SDKSynchronizer.swift +++ b/Sources/ZcashLightClientKit/Synchronizer/SDKSynchronizer.swift @@ -627,10 +627,10 @@ public class SDKSynchronizer: Synchronizer { /// Returns the last stored transparent balance public func getTransparentBalance(accountIndex: Int) async throws -> WalletBalance { - try blockProcessor.getTransparentBalance(accountIndex: accountIndex) + try await blockProcessor.getTransparentBalance(accountIndex: accountIndex) } - public func rewind(_ policy: RewindPolicy) throws { + public func rewind(_ policy: RewindPolicy) async throws { self.stop() var height: BlockHeight? diff --git a/Tests/DarksideTests/AdvancedReOrgTests.swift b/Tests/DarksideTests/AdvancedReOrgTests.swift index 61448cb8..a0281985 100644 --- a/Tests/DarksideTests/AdvancedReOrgTests.swift +++ b/Tests/DarksideTests/AdvancedReOrgTests.swift @@ -34,12 +34,14 @@ class AdvancedReOrgTests: XCTestCase { override func setUpWithError() throws { try super.setUpWithError() - coordinator = try TestCoordinator( - seed: seedPhrase, - walletBirthday: birthday + 50, //don't use an exact birthday, users never do. - channelProvider: ChannelProvider(), - network: network - ) + Task{ @MainActor [self] in + self.coordinator = try await TestCoordinator( + seed: seedPhrase, + walletBirthday: birthday + 50, //don't use an exact birthday, users never do. + channelProvider: ChannelProvider(), + network: network + ) + } try coordinator.reset(saplingActivation: 663150, branchID: self.branchID, chainName: self.chainName) } diff --git a/Tests/DarksideTests/BalanceTests.swift b/Tests/DarksideTests/BalanceTests.swift index c1a69836..aa91092f 100644 --- a/Tests/DarksideTests/BalanceTests.swift +++ b/Tests/DarksideTests/BalanceTests.swift @@ -30,12 +30,14 @@ class BalanceTests: XCTestCase { override func setUpWithError() throws { try super.setUpWithError() - coordinator = try TestCoordinator( - seed: seedPhrase, - walletBirthday: birthday, - channelProvider: ChannelProvider(), - network: network - ) + Task{ @MainActor [self] in + self.coordinator = try await TestCoordinator( + seed: seedPhrase, + walletBirthday: birthday, + channelProvider: ChannelProvider(), + network: network + ) + } try coordinator.reset(saplingActivation: 663150, branchID: "e9ff75a6", chainName: "main") } diff --git a/Tests/DarksideTests/DarksideSanityCheckTests.swift b/Tests/DarksideTests/DarksideSanityCheckTests.swift index 0df6bf6b..d80af160 100644 --- a/Tests/DarksideTests/DarksideSanityCheckTests.swift +++ b/Tests/DarksideTests/DarksideSanityCheckTests.swift @@ -33,12 +33,14 @@ class DarksideSanityCheckTests: XCTestCase { override func setUpWithError() throws { try super.setUpWithError() - coordinator = try TestCoordinator( - seed: seedPhrase, - walletBirthday: birthday, - channelProvider: ChannelProvider(), - network: network - ) + Task { @MainActor [self] in + self.coordinator = try await TestCoordinator( + seed: seedPhrase, + walletBirthday: birthday, + channelProvider: ChannelProvider(), + network: network + ) + } try coordinator.reset(saplingActivation: birthday, branchID: branchID, chainName: chainName) try coordinator.resetBlocks(dataset: .default) } diff --git a/Tests/DarksideTests/PendingTransactionUpdatesTest.swift b/Tests/DarksideTests/PendingTransactionUpdatesTest.swift index 4756be85..28d17715 100644 --- a/Tests/DarksideTests/PendingTransactionUpdatesTest.swift +++ b/Tests/DarksideTests/PendingTransactionUpdatesTest.swift @@ -31,12 +31,15 @@ class PendingTransactionUpdatesTest: XCTestCase { let network = DarksideWalletDNetwork() override func setUpWithError() throws { try super.setUpWithError() - coordinator = try TestCoordinator( - seed: seedPhrase, - walletBirthday: birthday, - channelProvider: ChannelProvider(), - network: network - ) + Task{ @MainActor in + coordinator = try await TestCoordinator( + seed: seedPhrase, + walletBirthday: birthday, + channelProvider: ChannelProvider(), + network: network + ) + } + try coordinator.reset(saplingActivation: 663150, branchID: "e9ff75a6", chainName: "main") } diff --git a/Tests/DarksideTests/ReOrgTests.swift b/Tests/DarksideTests/ReOrgTests.swift index d0063979..97afc85b 100644 --- a/Tests/DarksideTests/ReOrgTests.swift +++ b/Tests/DarksideTests/ReOrgTests.swift @@ -47,18 +47,23 @@ class ReOrgTests: XCTestCase { override func setUpWithError() throws { try super.setUpWithError() + NotificationCenter.default.addObserver( self, selector: #selector(handleReOrgNotification(_:)), name: Notification.Name.blockProcessorHandledReOrg, object: nil ) - coordinator = try TestCoordinator( - seed: seedPhrase, - walletBirthday: birthday, - channelProvider: ChannelProvider(), - network: network - ) + + Task{ @MainActor [self] in + coordinator = try await TestCoordinator( + seed: seedPhrase, + walletBirthday: birthday, + channelProvider: ChannelProvider(), + network: network + ) + } + try coordinator.reset(saplingActivation: birthday, branchID: branchID, chainName: chainName) try coordinator.resetBlocks(dataset: .default) } diff --git a/Tests/DarksideTests/RewindRescanTests.swift b/Tests/DarksideTests/RewindRescanTests.swift index aa869dcc..8ac8248b 100644 --- a/Tests/DarksideTests/RewindRescanTests.swift +++ b/Tests/DarksideTests/RewindRescanTests.swift @@ -34,14 +34,14 @@ class RewindRescanTests: XCTestCase { override func setUpWithError() throws { try super.setUpWithError() - - coordinator = try TestCoordinator( - seed: seedPhrase, - walletBirthday: birthday, - channelProvider: ChannelProvider(), - network: network - ) - + Task{ @MainActor [self] in + self.coordinator = try await TestCoordinator( + seed: seedPhrase, + walletBirthday: birthday, + channelProvider: ChannelProvider(), + network: network + ) + } try coordinator.reset(saplingActivation: 663150, branchID: "e9ff75a6", chainName: "main") } diff --git a/Tests/DarksideTests/ShieldFundsTests.swift b/Tests/DarksideTests/ShieldFundsTests.swift index 22610b22..1721d6dd 100644 --- a/Tests/DarksideTests/ShieldFundsTests.swift +++ b/Tests/DarksideTests/ShieldFundsTests.swift @@ -30,12 +30,14 @@ class ShieldFundsTests: XCTestCase { override func setUpWithError() throws { try super.setUpWithError() - coordinator = try TestCoordinator( - seed: seedPhrase, - walletBirthday: birthday, - channelProvider: ChannelProvider(), - network: network - ) + Task { @MainActor [self] in + self.coordinator = try await TestCoordinator( + seed: seedPhrase, + walletBirthday: birthday, + channelProvider: ChannelProvider(), + network: network + ) + } try coordinator.reset(saplingActivation: birthday, branchID: self.branchID, chainName: self.chainName) try coordinator.service.clearAddedUTXOs() } diff --git a/Tests/DarksideTests/SychronizerDarksideTests.swift b/Tests/DarksideTests/SychronizerDarksideTests.swift index 53645c2c..e8a7bfb7 100644 --- a/Tests/DarksideTests/SychronizerDarksideTests.swift +++ b/Tests/DarksideTests/SychronizerDarksideTests.swift @@ -34,12 +34,14 @@ class SychronizerDarksideTests: XCTestCase { override func setUpWithError() throws { try super.setUpWithError() - coordinator = try TestCoordinator( - seed: seedPhrase, - walletBirthday: birthday, - channelProvider: ChannelProvider(), - network: network - ) + Task{ @MainActor [self] in + coordinator = try await TestCoordinator( + seed: seedPhrase, + walletBirthday: birthday, + channelProvider: ChannelProvider(), + network: network + ) + } try coordinator.reset(saplingActivation: 663150, branchID: "e9ff75a6", chainName: "main") } diff --git a/Tests/DarksideTests/SynchronizerTests.swift b/Tests/DarksideTests/SynchronizerTests.swift index 12918a99..2393efe1 100644 --- a/Tests/DarksideTests/SynchronizerTests.swift +++ b/Tests/DarksideTests/SynchronizerTests.swift @@ -34,12 +34,15 @@ final class SynchronizerTests: XCTestCase { override func setUpWithError() throws { try super.setUpWithError() - coordinator = try TestCoordinator( - seed: seedPhrase, - walletBirthday: birthday + 50, //don't use an exact birthday, users never do. - channelProvider: ChannelProvider(), - network: network - ) + Task { @MainActor [self] in + coordinator = try await TestCoordinator( + seed: seedPhrase, + walletBirthday: birthday + 50, //don't use an exact birthday, users never do. + channelProvider: ChannelProvider(), + network: network + ) + } + try coordinator.reset(saplingActivation: 663150, branchID: self.branchID, chainName: self.chainName) } diff --git a/Tests/DarksideTests/TransactionEnhancementTests.swift b/Tests/DarksideTests/TransactionEnhancementTests.swift index af7d6987..e2418fa8 100644 --- a/Tests/DarksideTests/TransactionEnhancementTests.swift +++ b/Tests/DarksideTests/TransactionEnhancementTests.swift @@ -147,10 +147,10 @@ class TransactionEnhancementTests: XCTestCase { txFoundNotificationExpectation.subscribe(to: .blockProcessorFoundTransactions, object: processor) idleNotificationExpectation.subscribe(to: .blockProcessorIdle, object: processor) - try await processor.start() + await processor.start() } - func testBasicEnhacement() throws { + func testBasicEnhacement() async throws { let targetLatestHeight = BlockHeight(663200) do { diff --git a/Tests/DarksideTests/Z2TReceiveTests.swift b/Tests/DarksideTests/Z2TReceiveTests.swift index 5dc356ba..da8cd937 100644 --- a/Tests/DarksideTests/Z2TReceiveTests.swift +++ b/Tests/DarksideTests/Z2TReceiveTests.swift @@ -31,12 +31,14 @@ class Z2TReceiveTests: XCTestCase { override func setUpWithError() throws { try super.setUpWithError() - coordinator = try TestCoordinator( - seed: seedPhrase, - walletBirthday: birthday, - channelProvider: ChannelProvider(), - network: network - ) + Task{ @MainActor [self] in + coordinator = try await TestCoordinator( + seed: seedPhrase, + walletBirthday: birthday, + channelProvider: ChannelProvider(), + network: network + ) + } try coordinator.reset(saplingActivation: 663150, branchID: self.branchID, chainName: self.chainName) } diff --git a/Tests/NetworkTests/CompactBlockReorgTests.swift b/Tests/NetworkTests/CompactBlockReorgTests.swift index 22cdce16..18f5cc28 100644 --- a/Tests/NetworkTests/CompactBlockReorgTests.swift +++ b/Tests/NetworkTests/CompactBlockReorgTests.swift @@ -47,7 +47,10 @@ class CompactBlockReorgTests: XCTestCase { info.saplingActivationHeight = UInt64(network.constants.saplingActivationHeight) } - try ZcashRustBackend.initDataDb(dbData: processorConfig.dataDb, networkType: .testnet) + guard case .success = try ZcashRustBackend.initDataDb(dbData: processorConfig.dataDb, seed: nil, networkType: .testnet) else { + XCTFail("initDataDb failed. Expected Success but got .seedRequired") + return + } let storage = CompactBlockStorage.init(connectionProvider: SimpleConnectionProvider(path: processorConfig.cacheDb.absoluteString)) try! storage.createTable() @@ -138,12 +141,8 @@ class CompactBlockReorgTests: XCTestCase { startedScanningNotificationExpectation.subscribe(to: Notification.Name.blockProcessorStartedScanning, object: processor) idleNotificationExpectation.subscribe(to: Notification.Name.blockProcessorFinished, object: processor) reorgNotificationExpectation.subscribe(to: Notification.Name.blockProcessorHandledReOrg, object: processor) - - do { - try await processor.start() - } catch { - XCTFail("shouldn't fail") - } + + await processor.start() } func testNotifiesReorg() async { diff --git a/Tests/OfflineTests/WalletTests.swift b/Tests/OfflineTests/WalletTests.swift index 5132f767..b939c15b 100644 --- a/Tests/OfflineTests/WalletTests.swift +++ b/Tests/OfflineTests/WalletTests.swift @@ -51,12 +51,10 @@ class WalletTests: XCTestCase { let synchronizer = try SDKSynchronizer(initializer: wallet) do { - try await synchronizer.prepare() - - guard case .success = dbInit else { - XCTFail("Failed to initDataDb. Expected `.success` got: \(String(describing: dbInit))") - return - } + guard case .success = try await synchronizer.prepare(with: seedData.bytes) else { + XCTFail("Failed to initDataDb. Expected `.success` got: `.seedRequired`") + return + } } catch { XCTFail("shouldn't fail here") } diff --git a/Tests/TestUtils/TestCoordinator.swift b/Tests/TestUtils/TestCoordinator.swift index 7affee69..f2f517db 100644 --- a/Tests/TestUtils/TestCoordinator.swift +++ b/Tests/TestUtils/TestCoordinator.swift @@ -50,7 +50,7 @@ class TestCoordinator { walletBirthday: BlockHeight, channelProvider: ChannelProvider, network: ZcashNetwork - ) throws { + ) async throws { let derivationTool = DerivationTool(networkType: network.networkType) let spendingKey = try derivationTool.deriveUnifiedSpendingKey( @@ -60,7 +60,7 @@ class TestCoordinator { let ufvk = try derivationTool.deriveUnifiedFullViewingKey(from: spendingKey) - try self.init( + await try self.init( spendingKey: spendingKey, unifiedFullViewingKey: ufvk, walletBirthday: walletBirthday, @@ -75,7 +75,7 @@ class TestCoordinator { walletBirthday: BlockHeight, channelProvider: ChannelProvider, network: ZcashNetwork - ) throws { + ) async throws { self.spendingKey = spendingKey self.birthday = walletBirthday self.channelProvider = channelProvider @@ -93,7 +93,7 @@ class TestCoordinator { let storage = CompactBlockStorage(url: databases.cacheDB, readonly: false) try storage.createTable() - let buildResult = try TestSynchronizerBuilder.build( + let buildResult = try await TestSynchronizerBuilder.build( rustBackend: ZcashRustBackend.self, lowerBoundHeight: self.birthday, cacheDbURL: databases.cacheDB, @@ -291,7 +291,7 @@ enum TestSynchronizerBuilder { network: ZcashNetwork, seed: [UInt8]? = nil, loggerProxy: Logger? = nil - ) throws -> (spendingKeys: [UnifiedSpendingKey]?, synchronizer: SDKSynchronizer) { + ) async throws -> (spendingKeys: [UnifiedSpendingKey]?, synchronizer: SDKSynchronizer) { let initializer = Initializer( cacheDbURL: cacheDbURL, dataDbURL: dataDbURL, @@ -331,7 +331,7 @@ enum TestSynchronizerBuilder { walletBirthday: BlockHeight, network: ZcashNetwork, loggerProxy: Logger? = nil - ) throws -> (spendingKeys: [UnifiedSpendingKey]?, synchronizer: SDKSynchronizer) { + ) async throws -> (spendingKeys: [UnifiedSpendingKey]?, synchronizer: SDKSynchronizer) { let spendingKey = try DerivationTool(networkType: network.networkType) .deriveUnifiedSpendingKey(seed: seedBytes, accountIndex: 0) @@ -339,7 +339,7 @@ enum TestSynchronizerBuilder { let uvk = try DerivationTool(networkType: network.networkType) .deriveUnifiedFullViewingKey(from: spendingKey) - return try build( + return try await build( rustBackend: rustBackend, lowerBoundHeight: lowerBoundHeight, cacheDbURL: cacheDbURL,