Fix tests related to blocks downloading
- Call `setSyncRange()` in tests. - Little update to `BlockDownloader` API so it makes more sense.
This commit is contained in:
parent
c736dd37fb
commit
84d8002ddb
|
@ -830,7 +830,7 @@ actor CompactBlockProcessor {
|
|||
|
||||
do {
|
||||
await blockDownloader.setDownloadLimit(processingRange.upperBound + (2 * batchSize))
|
||||
await blockDownloader.startDownload(maxBlockBufferSize: config.downloadBufferSize, syncRange: range)
|
||||
await blockDownloader.startDownload(maxBlockBufferSize: config.downloadBufferSize)
|
||||
|
||||
try await blockDownloader.waitUntilRequestedBlocksAreDownloaded(in: processingRange)
|
||||
} catch {
|
||||
|
|
|
@ -43,8 +43,7 @@ protocol BlockDownloader {
|
|||
///
|
||||
/// - Parameters:
|
||||
/// - maxBlockBufferSize: Number of blocks that is held in memory before blocks are written to disk.
|
||||
/// - syncRange: Whole range in which blocks should be downloaded. This should be sync range.
|
||||
func startDownload(maxBlockBufferSize: Int, syncRange: CompactBlockRange) async
|
||||
func startDownload(maxBlockBufferSize: Int) async
|
||||
|
||||
/// Stop download. This method cancels Task used for downloading. And then it is waiting until internal `isDownloading` flag is set to `false`
|
||||
func stopDownload() async
|
||||
|
@ -64,6 +63,7 @@ actor BlockDownloaderImpl {
|
|||
let logger: Logger
|
||||
|
||||
private var downloadStream: BlockDownloaderStream?
|
||||
private var syncRange: CompactBlockRange?
|
||||
|
||||
private var downloadToHeight: BlockHeight = 0
|
||||
private var isDownloading = false
|
||||
|
@ -86,10 +86,10 @@ actor BlockDownloaderImpl {
|
|||
self.logger = logger
|
||||
}
|
||||
|
||||
private func doDownload(maxBlockBufferSize: Int, syncRange: CompactBlockRange) async {
|
||||
private func doDownload(maxBlockBufferSize: Int) async {
|
||||
lastError = nil
|
||||
do {
|
||||
guard let downloadStream = self.downloadStream else {
|
||||
guard let downloadStream = self.downloadStream, let syncRange = self.syncRange else {
|
||||
logger.error("Dont have downloadStream. Trying to download blocks before sync range is not set.")
|
||||
throw ZcashError.blockDownloadSyncRangeNotSet
|
||||
}
|
||||
|
@ -132,7 +132,7 @@ actor BlockDownloaderImpl {
|
|||
range upper bound: \(range.upperBound)
|
||||
new downloadToHeight: \(downloadToHeight)
|
||||
""")
|
||||
await startDownload(maxBlockBufferSize: maxBlockBufferSize, syncRange: syncRange)
|
||||
await startDownload(maxBlockBufferSize: maxBlockBufferSize)
|
||||
logger.debug("finishing after start download")
|
||||
} else {
|
||||
logger.debug("Finished downloading with range: \(range.lowerBound)...\(range.upperBound)")
|
||||
|
@ -225,9 +225,10 @@ extension BlockDownloaderImpl: BlockDownloader {
|
|||
|
||||
func setSyncRange(_ range: CompactBlockRange) async throws {
|
||||
downloadStream = try await compactBlocksDownloadStream(startHeight: range.lowerBound, targetHeight: range.upperBound)
|
||||
syncRange = range
|
||||
}
|
||||
|
||||
func startDownload(maxBlockBufferSize: Int, syncRange: CompactBlockRange) async {
|
||||
func startDownload(maxBlockBufferSize: Int) async {
|
||||
guard task == nil else {
|
||||
logger.debug("Download already in progress.")
|
||||
return
|
||||
|
@ -235,7 +236,7 @@ extension BlockDownloaderImpl: BlockDownloader {
|
|||
isDownloading = true
|
||||
task = Task.detached() { [weak self] in
|
||||
// Solve when self is nil, task should be niled.
|
||||
await self?.doDownload(maxBlockBufferSize: maxBlockBufferSize, syncRange: syncRange)
|
||||
await self?.doDownload(maxBlockBufferSize: maxBlockBufferSize)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -211,7 +211,6 @@ private extension View {
|
|||
ZcashTransaction.Overview.Column.minedHeight > (latestHeight - ZcashSDK.defaultStaleTolerance)
|
||||
)
|
||||
)
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@ public enum ZcashTransaction {
|
|||
public struct Overview {
|
||||
/// Represents the transaction state based on current height of the chain,
|
||||
/// mined height and expiry height of a transaction.
|
||||
public enum State {
|
||||
public enum State {
|
||||
/// transaction has a `minedHeight` that's greater or equal than
|
||||
/// `ZcashSDK.defaultStaleTolerance` confirmations.
|
||||
case confirmed
|
||||
|
@ -22,9 +22,10 @@ public enum ZcashTransaction {
|
|||
/// transaction has no
|
||||
case expired
|
||||
|
||||
init(currentHeight: BlockHeight,
|
||||
minedHeight: BlockHeight?,
|
||||
expiredUnmined: Bool
|
||||
init(
|
||||
currentHeight: BlockHeight,
|
||||
minedHeight: BlockHeight?,
|
||||
expiredUnmined: Bool
|
||||
) {
|
||||
guard !expiredUnmined else {
|
||||
self = .expired
|
||||
|
@ -226,7 +227,6 @@ public extension ZcashTransaction.Overview {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Capabilities of an entity that can be uniquely identified by a raw transaction id
|
||||
*/
|
||||
|
|
|
@ -137,11 +137,10 @@ class WalletTransactionEncoder: TransactionEncoder {
|
|||
let response = try await self.lightWalletService.submit(spendTransaction: transaction.raw)
|
||||
|
||||
guard response.errorCode >= 0 else {
|
||||
throw TransactionEncoderError.submitError(code: Int(response.errorCode) , message: response.errorMessage)
|
||||
throw TransactionEncoderError.submitError(code: Int(response.errorCode), message: response.errorMessage)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
func ensureParams(spend: URL, output: URL) -> Bool {
|
||||
let readableSpend = FileManager.default.isReadableFile(atPath: spend.path)
|
||||
let readableOutput = FileManager.default.isReadableFile(atPath: output.path)
|
||||
|
|
|
@ -1065,8 +1065,9 @@ class BalanceTests: XCTestCase {
|
|||
*/
|
||||
XCTAssertEqual(expectedBalance, previousTotalBalance)
|
||||
|
||||
let transactionRepo = TransactionSQLDAO(dbProvider: SimpleConnectionProvider(
|
||||
path: coordinator.synchronizer.initializer.dataDbURL.absoluteString
|
||||
let transactionRepo = TransactionSQLDAO(
|
||||
dbProvider: SimpleConnectionProvider(
|
||||
path: coordinator.synchronizer.initializer.dataDbURL.absoluteString
|
||||
)
|
||||
)
|
||||
|
||||
|
|
|
@ -208,7 +208,7 @@ class PendingTransactionUpdatesTest: XCTestCase {
|
|||
let clearedTransactions = await coordinator.synchronizer
|
||||
.transactions
|
||||
|
||||
let clearedTransaction = clearedTransactions.first(where: { $0.rawID == afterStagePendingTx.rawID } )
|
||||
let clearedTransaction = clearedTransactions.first(where: { $0.rawID == afterStagePendingTx.rawID })
|
||||
|
||||
XCTAssertEqual(clearedTransaction!.value.amount, afterStagePendingTx.value.amount)
|
||||
XCTAssertNil(supposedlyPendingUnexistingTransaction)
|
||||
|
|
|
@ -466,7 +466,6 @@ class SynchronizerDarksideTests: XCTestCase {
|
|||
XCTAssertEqual(states[5], expectedStates[5])
|
||||
XCTAssertEqual(states[7], expectedStates[7])
|
||||
|
||||
|
||||
try coordinator.service.applyStaged(nextLatestHeight: 663_200)
|
||||
|
||||
sleep(2)
|
||||
|
@ -538,7 +537,6 @@ class SynchronizerDarksideTests: XCTestCase {
|
|||
XCTAssertEqual(states[2], secondBatchOfExpectedStates[2])
|
||||
XCTAssertEqual(states[3], secondBatchOfExpectedStates[3])
|
||||
XCTAssertEqual(states[4], secondBatchOfExpectedStates[4])
|
||||
|
||||
}
|
||||
|
||||
func testSyncAfterWipeWorks() async throws {
|
||||
|
|
|
@ -217,7 +217,8 @@ class BlockScanTests: XCTestCase {
|
|||
do {
|
||||
let blockDownloader = await compactBlockProcessor.blockDownloader
|
||||
await blockDownloader.setDownloadLimit(range.upperBound)
|
||||
await blockDownloader.startDownload(maxBlockBufferSize: 10, syncRange: range)
|
||||
try await blockDownloader.setSyncRange(range)
|
||||
await blockDownloader.startDownload(maxBlockBufferSize: 10)
|
||||
try await blockDownloader.waitUntilRequestedBlocksAreDownloaded(in: range)
|
||||
|
||||
XCTAssertFalse(Task.isCancelled)
|
||||
|
|
|
@ -105,7 +105,8 @@ class BlockStreamingTest: XCTestCase {
|
|||
do {
|
||||
let blockDownloader = await compactBlockProcessor.blockDownloader
|
||||
await blockDownloader.setDownloadLimit(latestBlockHeight)
|
||||
await blockDownloader.startDownload(maxBlockBufferSize: 10, syncRange: startHeight...latestBlockHeight)
|
||||
try await blockDownloader.setSyncRange(startHeight...latestBlockHeight)
|
||||
await blockDownloader.startDownload(maxBlockBufferSize: 10)
|
||||
try await blockDownloader.waitUntilRequestedBlocksAreDownloaded(in: startHeight...latestBlockHeight)
|
||||
} catch {
|
||||
XCTAssertTrue(Task.isCancelled)
|
||||
|
@ -164,7 +165,8 @@ class BlockStreamingTest: XCTestCase {
|
|||
do {
|
||||
let blockDownloader = await compactBlockProcessor.blockDownloader
|
||||
await blockDownloader.setDownloadLimit(latestBlockHeight)
|
||||
await blockDownloader.startDownload(maxBlockBufferSize: 10, syncRange: startHeight...latestBlockHeight)
|
||||
try await blockDownloader.setSyncRange(startHeight...latestBlockHeight)
|
||||
await blockDownloader.startDownload(maxBlockBufferSize: 10)
|
||||
try await blockDownloader.waitUntilRequestedBlocksAreDownloaded(in: startHeight...latestBlockHeight)
|
||||
} catch {
|
||||
if let lwdError = error as? ZcashError {
|
||||
|
|
|
@ -583,7 +583,7 @@ class CombineSynchronizerOfflineTests: XCTestCase {
|
|||
}
|
||||
|
||||
func testGetRecipientsForClearedTransaction() {
|
||||
let expectedRecipient: TransactionRecipient = TransactionRecipient.address(.transparent(self.data.transparentAddress))
|
||||
let expectedRecipient = TransactionRecipient.address(.transparent(self.data.transparentAddress))
|
||||
|
||||
synchronizerMock.getRecipientsForClearedTransactionClosure = { receivedTransaction in
|
||||
XCTAssertEqual(receivedTransaction.id, self.data.clearedTransaction.id)
|
||||
|
|
Loading…
Reference in New Issue