ZcashLightClientKit/Tests/OfflineTests
Francisco Gindre 6b7fbdd908
[#895] Add Sync Session ID Synchronizer State (#906)
Closes #895

Add Sync Session ID to `SynchronizerState`.

A SyncSession is an attempt to sync the blockchain within the lifetime of a Synchronizer.
A Synchronizer can sync many times, when synced it will refresh every ~20 seconds +- random padding.
each sync attempt will have a different UUID even if it's from the same instance of SDKSynchronizer.

**How are SyncSessions are delimited? With `SyncStatus` changes.**

changes from [`.unprepared`|`.error`|`.disconnected`|`.stopped`] to `.syncing` assign a new sessionID to the synchronizer.

Any other transitions won't.

`areTwoStatusesDifferent ` was refactored to a helper function of `SyncStatus`

**How are IDs generated?**

ID generation is not mandated but delegated to a protocol `SyncSessionIDGenerator`.
Tests inject their own deterministic generator to avoid test flakiness.

Default implementation of SyncSessionIDGenerator is

````Swift
struct UniqueSyncSessionIDGenerator {}

extension UniqueSyncSessionIDGenerator: SyncSessionIDGenerator {
    func nextID() -> UUID {
        UUID()
    }
}
````

**SyncSession Pseudo-Atomicity and thread safety**

SyncSession is a type alias of a GenericActor holding a UUID

````
typealias SyncSession = GenericActor<UUID>

extension SyncSession {
    /// updates the current sync session to a new value with the given generator
    /// - Parameters generator: a `SyncSessionIDGenerator`
    /// - returns: the `UUID` of the newly updated value.
    @discardableResult
    func newSession(with generator: SyncSessionIDGenerator) async -> UUID {
        return await self.update(generator.nextID())
    }
}
````

Closes #895

SessionTicker struct to control session transitions.

switching to `.unprepared` now makes syncID to be `.nullID`
2023-04-07 09:02:05 -03:00
..
DerivationToolTests Merge pull request #779 from Chlup/two_swiftlint_configs 2023-02-15 09:31:41 +01:00
BirthdayTests.swift [#778] Add swiflint config file only for tests 2023-02-13 13:36:58 +01:00
BlockBatchValidationTests.swift [#469] Make ZcashRustBackendWelding async 2023-03-30 19:08:56 +02:00
ClosureSynchronizerOfflineTests.swift [#895] Add Sync Session ID Synchronizer State (#906) 2023-04-07 09:02:05 -03:00
CombineSynchronizerOfflineTests.swift [#895] Add Sync Session ID Synchronizer State (#906) 2023-04-07 09:02:05 -03:00
CompactBlockProcessorOfflineTests.swift [#209] Add support for multiple instances of the SDKSynchronizer 2023-03-27 20:42:52 +02:00
CompactBlockRepositoryTests.swift [#469] Make ZcashRustBackendWelding async 2023-03-30 19:08:56 +02:00
ErrorLocalizationTests.swift [#711] Add Swiftlint plug in to SDK (#722) 2023-01-18 17:09:04 +01:00
FsBlockStorageTests.swift [#469] Make ZcashRustBackendWelding async 2023-03-30 19:08:56 +02:00
InitializerOfflineTests.swift [#209] Add support for multiple instances of the SDKSynchronizer 2023-03-27 20:42:52 +02:00
InternalSyncProgressTests.swift [#209] Add support for multiple instances of the SDKSynchronizer 2023-03-27 20:42:52 +02:00
MemoTests.swift [#778] Add swiflint config file only for tests 2023-02-13 13:36:58 +01:00
NotesRepositoryTests.swift [#469] Make ZcashRustBackendWelding async 2023-03-30 19:08:56 +02:00
NullBytesTests.swift [#469] Make ZcashRustBackendWelding async 2023-03-30 19:08:56 +02:00
PagedTransactionRepositoryTests.swift [#484] Use async for TransactionsRepository 2023-03-28 10:17:14 +02:00
PendingTransactionRepositoryTests.swift [#209] Add support for multiple instances of the SDKSynchronizer 2023-03-27 20:42:52 +02:00
RawTransactionTests.swift [#796] Fix tests 2023-02-16 17:14:31 +01:00
RecipientTests.swift Update code to to comply better with linter rules 2023-02-13 12:18:08 +01:00
SynchronizerOfflineTests.swift [#895] Add Sync Session ID Synchronizer State (#906) 2023-04-07 09:02:05 -03:00
TransactionRepositoryTests.swift [#469] Make ZcashRustBackendWelding async 2023-03-30 19:08:56 +02:00
TxIdTests.swift [#778] Add swiflint config file only for tests 2023-02-13 13:36:58 +01:00
UndescribableTests.swift [#778] Add swiflint config file only for tests 2023-02-13 13:36:58 +01:00
UnifiedTypecodesTests.swift Update code to to comply better with linter rules 2023-02-13 12:18:08 +01:00
WalletTests.swift [#209] Add support for multiple instances of the SDKSynchronizer 2023-03-27 20:42:52 +02:00
ZatoshiTests.swift Fix typos 2022-12-31 12:50:16 +02:00
ZcashRustBackendTests.swift [#469] Make ZcashRustBackendWelding async 2023-03-30 19:08:56 +02:00
Zip302MemoTests.swift Update code to to comply better with linter rules 2023-02-13 12:18:08 +01:00