PR Suggestions

`XCAsyncTestCase` does not work as intended but `wait {}` does what
we need.

restored `needsToStartScanningWhenStopped` as a Bool var on actor

fixed Enhancement test
This commit is contained in:
Francisco Gindre 2022-10-31 20:17:05 -03:00
parent 1c8e06742a
commit a0d02c4d57
13 changed files with 88 additions and 111 deletions

View File

@ -318,6 +318,7 @@ public actor CompactBlockProcessor {
}
}
private var needsToStartScanningWhenStopped = false
var config: Configuration {
willSet {
self.stop()
@ -500,6 +501,7 @@ 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!!!!")
self.needsToStartScanningWhenStopped = true
}
return
}
@ -596,7 +598,7 @@ public actor CompactBlockProcessor {
self.backoffTimer?.invalidate()
self.backoffTimer = nil
cancelableTask = Task(priority: .userInitiated) { [weak self] in
cancelableTask = Task(priority: .userInitiated) {
do {
try await compactBlockStreamDownload(
blockBufferSize: config.downloadBufferSize,
@ -607,12 +609,14 @@ public actor CompactBlockProcessor {
try await compactBlockBatchScanning(range: range)
try await compactBlockEnhancement(range: range)
try await fetchUnspentTxOutputs(range: range)
//state = .stopped
} catch {
if !(Task.isCancelled) {
await fail(error)
} else {
state = .stopped
if needsToStartScanningWhenStopped {
await nextBatch()
}
}
}
}
@ -837,7 +841,7 @@ public actor CompactBlockProcessor {
)
state = .synced
await setTimer()
NotificationCenter.default.post(
NotificationCenter.default.mainThreadPost(
name: Notification.Name.blockProcessorIdle,
object: self,
userInfo: nil

View File

@ -11,7 +11,7 @@ import XCTest
// swiftlint:disable implicitly_unwrapped_optional force_unwrapping type_body_length
//@MainActor
class AdvancedReOrgTests: XCAsyncTestCase {
class AdvancedReOrgTests: XCTestCase {
// TODO: Parameterize this from environment?
// swiftlint:disable:next line_length
var seedPhrase = "still champion voice habit trend flight survey between bitter process artefact blind carbon truly provide dizzy crush flush breeze blouse charge solid fish spread"
@ -32,17 +32,21 @@ class AdvancedReOrgTests: XCAsyncTestCase {
let chainName = "main"
let network = DarksideWalletDNetwork()
override func asyncSetUpWithError() async throws {
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)
override func setUpWithError() throws {
try super.setUpWithError()
wait { [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)
}
}
override func asyncTearDownWithError() async throws {
override func tearDownWithError() throws {
super.tearDownWithError()
NotificationCenter.default.removeObserver(self)
try coordinator.stop()
try? FileManager.default.removeItem(at: coordinator.databases.cacheDB)

View File

@ -30,15 +30,16 @@ class BalanceTests: XCTestCase {
override func setUpWithError() throws {
try super.setUpWithError()
Task{ @MainActor [self] in
wait { [self] in
self.coordinator = try await TestCoordinator(
seed: seedPhrase,
walletBirthday: birthday,
seed: self.seedPhrase,
walletBirthday: self.birthday,
channelProvider: ChannelProvider(),
network: network
network: self.network
)
try coordinator.reset(saplingActivation: 663150, branchID: "e9ff75a6", chainName: "main")
}
try coordinator.reset(saplingActivation: 663150, branchID: "e9ff75a6", chainName: "main")
}
/**

View File

@ -33,16 +33,17 @@ class DarksideSanityCheckTests: XCTestCase {
override func setUpWithError() throws {
try super.setUpWithError()
Task { @MainActor [self] in
wait { [self] in
self.coordinator = try await TestCoordinator(
seed: seedPhrase,
walletBirthday: birthday,
seed: self.seedPhrase,
walletBirthday: self.birthday,
channelProvider: ChannelProvider(),
network: network
network: self.network
)
try self.coordinator.reset(saplingActivation: self.birthday, branchID: self.branchID, chainName: self.chainName)
try self.coordinator.resetBlocks(dataset: .default)
}
try coordinator.reset(saplingActivation: birthday, branchID: branchID, chainName: chainName)
try coordinator.resetBlocks(dataset: .default)
}
override func tearDownWithError() throws {
@ -76,7 +77,7 @@ class DarksideSanityCheckTests: XCTestCase {
wait(for: [syncExpectation], timeout: 5)
let blocksDao = BlockSQLDAO(dbProvider: SimpleConnectionProvider(path: coordinator.databases.dataDB.absoluteString, readonly: true))
let blocksDao = BlockSQLDAO(dbProvider: SimpleConnectionProvider(path: coordinator.databases.dataDB.absoluteString, readonly: false))
let firstBlock = try blocksDao.block(at: expectedFirstBlock.height)
let lastBlock = try blocksDao.block(at: expectedLastBlock.height)

View File

@ -31,20 +31,19 @@ class PendingTransactionUpdatesTest: XCTestCase {
let network = DarksideWalletDNetwork()
override func setUpWithError() throws {
try super.setUpWithError()
Task{ @MainActor in
coordinator = try await TestCoordinator(
seed: seedPhrase,
walletBirthday: birthday,
wait {
self.coordinator = try await TestCoordinator(
seed: self.seedPhrase,
walletBirthday: self.birthday,
channelProvider: ChannelProvider(),
network: network
network: self.network
)
}
try coordinator.reset(saplingActivation: 663150, branchID: "e9ff75a6", chainName: "main")
try self.coordinator.reset(saplingActivation: 663150, branchID: "e9ff75a6", chainName: "main")
}
}
override func tearDownWithError() throws {
try super.tearDownWithError()
NotificationCenter.default.removeObserver(self)
try coordinator.stop()
try? FileManager.default.removeItem(at: coordinator.databases.cacheDB)

View File

@ -47,29 +47,28 @@ class ReOrgTests: XCTestCase {
override func setUpWithError() throws {
try super.setUpWithError()
NotificationCenter.default.addObserver(
self,
selector: #selector(handleReOrgNotification(_:)),
name: Notification.Name.blockProcessorHandledReOrg,
object: nil
)
Task{ @MainActor [self] in
coordinator = try await TestCoordinator(
seed: seedPhrase,
walletBirthday: birthday,
channelProvider: ChannelProvider(),
network: network
wait { [self] in
NotificationCenter.default.addObserver(
self,
selector: #selector(self.handleReOrgNotification(_:)),
name: Notification.Name.blockProcessorHandledReOrg,
object: nil
)
}
try coordinator.reset(saplingActivation: birthday, branchID: branchID, chainName: chainName)
try coordinator.resetBlocks(dataset: .default)
self.coordinator = try await TestCoordinator(
seed: self.seedPhrase,
walletBirthday: self.birthday,
channelProvider: ChannelProvider(),
network: self.network
)
try self.coordinator.reset(saplingActivation: self.birthday, branchID: self.branchID, chainName: self.chainName)
try self.coordinator.resetBlocks(dataset: .default)
}
}
override func tearDownWithError() throws {
try super.tearDownWithError()
try? FileManager.default.removeItem(at: coordinator.databases.cacheDB)
try? FileManager.default.removeItem(at: coordinator.databases.dataDB)
try? FileManager.default.removeItem(at: coordinator.databases.pendingDB)

View File

@ -34,20 +34,20 @@ class RewindRescanTests: XCTestCase {
override func setUpWithError() throws {
try super.setUpWithError()
Task{ @MainActor [self] in
wait { [self] in
self.coordinator = try await TestCoordinator(
seed: seedPhrase,
walletBirthday: birthday,
seed: self.seedPhrase,
walletBirthday: self.birthday,
channelProvider: ChannelProvider(),
network: network
network: self.network
)
try self.coordinator.reset(saplingActivation: 663150, branchID: "e9ff75a6", chainName: "main")
}
try coordinator.reset(saplingActivation: 663150, branchID: "e9ff75a6", chainName: "main")
}
override func tearDownWithError() throws {
try super.tearDownWithError()
NotificationCenter.default.removeObserver(self)
try coordinator.stop()

View File

@ -34,15 +34,16 @@ class SychronizerDarksideTests: XCTestCase {
override func setUpWithError() throws {
try super.setUpWithError()
Task{ @MainActor [self] in
coordinator = try await TestCoordinator(
seed: seedPhrase,
walletBirthday: birthday,
wait { [self] in
self.coordinator = try await TestCoordinator(
seed: self.seedPhrase,
walletBirthday: self.birthday,
channelProvider: ChannelProvider(),
network: network
network: self.network
)
try self.coordinator.reset(saplingActivation: 663150, branchID: "e9ff75a6", chainName: "main")
}
try coordinator.reset(saplingActivation: 663150, branchID: "e9ff75a6", chainName: "main")
}
override func tearDownWithError() throws {

View File

@ -34,16 +34,16 @@ final class SynchronizerTests: XCTestCase {
override func setUpWithError() throws {
try super.setUpWithError()
Task { @MainActor [self] in
coordinator = try await TestCoordinator(
seed: seedPhrase,
walletBirthday: birthday + 50, //don't use an exact birthday, users never do.
wait { [self] in
self.coordinator = try await TestCoordinator(
seed: self.seedPhrase,
walletBirthday:self.birthday + 50, //don't use an exact birthday, users never do.
channelProvider: ChannelProvider(),
network: network
network: self.network
)
}
try coordinator.reset(saplingActivation: 663150, branchID: self.branchID, chainName: self.chainName)
try coordinator.reset(saplingActivation: 663150, branchID: self.branchID, chainName: self.chainName)
}
}
override func tearDownWithError() throws {

View File

@ -83,8 +83,6 @@ class TransactionEnhancementTests: XCTestCase {
return
}
guard case .success = dbInit else {
XCTFail("Failed to initDataDb. Expected `.success` got: \(String(describing: dbInit))")
return
@ -150,7 +148,7 @@ class TransactionEnhancementTests: XCTestCase {
await processor.start()
}
func testBasicEnhacement() async throws {
func testBasicEnhancement() async throws {
let targetLatestHeight = BlockHeight(663200)
do {

View File

@ -30,22 +30,20 @@ class Z2TReceiveTests: XCTestCase {
override func setUpWithError() throws {
try super.setUpWithError()
Task{ @MainActor [self] in
coordinator = try await TestCoordinator(
seed: seedPhrase,
walletBirthday: birthday,
wait { [self] in
self.coordinator = try await TestCoordinator(
seed: self.seedPhrase,
walletBirthday: self.birthday,
channelProvider: ChannelProvider(),
network: network
network: self.network
)
}
try coordinator.reset(saplingActivation: 663150, branchID: self.branchID, chainName: self.chainName)
try coordinator.reset(saplingActivation: 663150, branchID: self.branchID, chainName: self.chainName)
}
}
override func tearDownWithError() throws {
try super.tearDownWithError()
NotificationCenter.default.removeObserver(self)
try coordinator.stop()

View File

@ -9,28 +9,8 @@
///
import Foundation
import XCTest
class XCAsyncTestCase: XCTestCase {
func asyncSetUpWithError() async throws {
fatalError("Must override")
}
func asyncTearDownWithError() async throws {
fatalError("Must override")
}
override func setUpWithError() throws {
wait {
try await self.asyncSetUpWithError()
}
}
override func tearDownWithError() throws {
wait {
try await self.asyncTearDownWithError()
}
}
extension XCTestCase {
func wait(asyncBlock: @escaping (() async throws -> Void)) {
let semaphore = DispatchSemaphore(value: 0)
Task.init {

View File

@ -1,10 +1,6 @@
Pod::Spec.new do |s|
s.name = 'ZcashLightClientKit'
<<<<<<< HEAD
s.version = '0.17.0-alpha.2'
=======
s.version = '0.16.13-beta'
>>>>>>> master
s.summary = 'Zcash Light Client wallet SDK for iOS'
s.description = <<-DESC
@ -25,11 +21,7 @@ Pod::Spec.new do |s|
s.ios.deployment_target = '13.0'
s.dependency 'gRPC-Swift', '~> 1.8.0'
s.dependency 'SQLite.swift', '~> 0.13.0'
<<<<<<< HEAD
s.dependency 'libzcashlc', '0.1.0-beta.1'
=======
s.dependency 'libzcashlc', '0.0.3'
>>>>>>> master
s.static_framework = true
end