Fix compiler errors

This commit is contained in:
Francisco Gindre 2022-10-31 09:57:10 -03:00
parent dbd4b8934c
commit 01d85f5748
17 changed files with 107 additions and 91 deletions

View File

@ -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(

View File

@ -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.

View File

@ -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?

View File

@ -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)
}

View File

@ -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")
}

View File

@ -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)
}

View File

@ -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")
}

View File

@ -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)
}

View File

@ -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")
}

View File

@ -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()
}

View File

@ -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")
}

View File

@ -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)
}

View File

@ -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 {

View File

@ -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)
}

View File

@ -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 {

View File

@ -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")
}

View File

@ -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,