- plugin integrated - errors resolved - warnings resolved - package.swift macos platform version 10_15 -> 12
This commit is contained in:
parent
dcc6ef1757
commit
372ea5af70
|
@ -2,23 +2,22 @@
|
|||
# https://github.com/raywenderlich/swift-style-guide
|
||||
|
||||
excluded:
|
||||
- Pods
|
||||
- ZcashLightClientKit/Service/ProtoBuf
|
||||
- ZcashLightClientKitTests/proto
|
||||
- xctemplates
|
||||
- Sources/ZcashLightClientKit/Service/ProtoBuf/compact_formats.pb.swift
|
||||
- Sources/ZcashLightClientKit/Service/ProtoBuf/service.pb.swift
|
||||
- Sources/ZcashLightClientKit/Service/ProtoBuf/service.grpc.swift
|
||||
- Tests/TestUtils/proto
|
||||
- Tests/TestUtils/TestVector.swift
|
||||
- Tests/OfflineTests/BirthdayTests.swift
|
||||
- ZcashLightClientKitTests/Constants.generated.swift
|
||||
|
||||
included:
|
||||
- Example/ZcashLightClientSample/ZcashLIghtClientSample
|
||||
- ZcashLightClientKit
|
||||
- ZcashLightClientKitTests
|
||||
|
||||
disabled_rules:
|
||||
- notification_center_detachment
|
||||
- orphaned_doc_comment
|
||||
- todo
|
||||
- unused_capture_list
|
||||
- nesting # allow for types to be nested, common pattern in Swift
|
||||
- multiple_closures_with_trailing_closure
|
||||
- multiple_closures_with_trailing_closure
|
||||
- generic_type_name # allow for arbitrarily long generic type names
|
||||
|
||||
opt_in_rules:
|
||||
|
@ -66,7 +65,7 @@ opt_in_rules:
|
|||
- vertical_whitespace_opening_braces
|
||||
- weak_delegate
|
||||
- yoda_condition
|
||||
|
||||
- todos
|
||||
|
||||
custom_rules:
|
||||
array_constructor:
|
||||
|
@ -100,6 +99,15 @@ custom_rules:
|
|||
message: "The swift NSLog function should not be used."
|
||||
severity: error
|
||||
|
||||
todos:
|
||||
included: ".*\\.swift"
|
||||
name: "TODO"
|
||||
regex: '(TODO|FIXME):\ ([^\[]|\[[^#]|\[#[^1-9])'
|
||||
message: "TODO or FIXME without issue number. Format TODO: [#...]"
|
||||
severity: warning
|
||||
match_kinds:
|
||||
- comment
|
||||
|
||||
|
||||
attributes:
|
||||
always_on_same_line:
|
||||
|
@ -117,14 +125,18 @@ legacy_hashing: error
|
|||
|
||||
identifier_name:
|
||||
excluded:
|
||||
- i
|
||||
- id
|
||||
- db
|
||||
- nf
|
||||
- e
|
||||
- x
|
||||
- y
|
||||
- z
|
||||
- to
|
||||
- at
|
||||
- lhs
|
||||
- rhs
|
||||
- ok
|
||||
- db
|
||||
- ua
|
||||
- nf
|
||||
- tx
|
||||
- as
|
||||
|
||||
indentation_width:
|
||||
indentation_width: 4
|
||||
|
|
|
@ -1,5 +1,14 @@
|
|||
{
|
||||
"pins" : [
|
||||
{
|
||||
"identity" : "collectionconcurrencykit",
|
||||
"kind" : "remoteSourceControl",
|
||||
"location" : "https://github.com/JohnSundell/CollectionConcurrencyKit.git",
|
||||
"state" : {
|
||||
"revision" : "b4f23e24b5a1bff301efc5e70871083ca029ff95",
|
||||
"version" : "0.2.0"
|
||||
}
|
||||
},
|
||||
{
|
||||
"identity" : "grpc-swift",
|
||||
"kind" : "remoteSourceControl",
|
||||
|
@ -54,6 +63,15 @@
|
|||
"revision" : "a3fd9f079d6c9ac3095ee3ef2369a68c29ba04db"
|
||||
}
|
||||
},
|
||||
{
|
||||
"identity" : "sourcekitten",
|
||||
"kind" : "remoteSourceControl",
|
||||
"location" : "https://github.com/jpsim/SourceKitten.git",
|
||||
"state" : {
|
||||
"revision" : "fc12c0f182c5cf80781dd933b17a82eb98bd7c61",
|
||||
"version" : "0.33.1"
|
||||
}
|
||||
},
|
||||
{
|
||||
"identity" : "sqlite.swift",
|
||||
"kind" : "remoteSourceControl",
|
||||
|
@ -63,6 +81,15 @@
|
|||
"version" : "0.14.1"
|
||||
}
|
||||
},
|
||||
{
|
||||
"identity" : "swift-argument-parser",
|
||||
"kind" : "remoteSourceControl",
|
||||
"location" : "https://github.com/apple/swift-argument-parser.git",
|
||||
"state" : {
|
||||
"revision" : "fddd1c00396eed152c45a46bea9f47b98e59301d",
|
||||
"version" : "1.2.0"
|
||||
}
|
||||
},
|
||||
{
|
||||
"identity" : "swift-crypto",
|
||||
"kind" : "remoteSourceControl",
|
||||
|
@ -135,6 +162,50 @@
|
|||
"version" : "1.19.0"
|
||||
}
|
||||
},
|
||||
{
|
||||
"identity" : "swift-syntax",
|
||||
"kind" : "remoteSourceControl",
|
||||
"location" : "https://github.com/apple/swift-syntax.git",
|
||||
"state" : {
|
||||
"revision" : "76d01195182593ff34f5ada1ab0910fae190fc9c"
|
||||
}
|
||||
},
|
||||
{
|
||||
"identity" : "swiftlint",
|
||||
"kind" : "remoteSourceControl",
|
||||
"location" : "https://github.com/realm/SwiftLint.git",
|
||||
"state" : {
|
||||
"branch" : "a876e86",
|
||||
"revision" : "a876e860ee0e166a05428f430888de5d798c0f8d"
|
||||
}
|
||||
},
|
||||
{
|
||||
"identity" : "swiftytexttable",
|
||||
"kind" : "remoteSourceControl",
|
||||
"location" : "https://github.com/scottrhoyt/SwiftyTextTable.git",
|
||||
"state" : {
|
||||
"revision" : "c6df6cf533d120716bff38f8ff9885e1ce2a4ac3",
|
||||
"version" : "0.9.0"
|
||||
}
|
||||
},
|
||||
{
|
||||
"identity" : "swxmlhash",
|
||||
"kind" : "remoteSourceControl",
|
||||
"location" : "https://github.com/drmohundro/SWXMLHash.git",
|
||||
"state" : {
|
||||
"revision" : "4d0f62f561458cbe1f732171e625f03195151b60",
|
||||
"version" : "7.0.1"
|
||||
}
|
||||
},
|
||||
{
|
||||
"identity" : "yams",
|
||||
"kind" : "remoteSourceControl",
|
||||
"location" : "https://github.com/jpsim/Yams.git",
|
||||
"state" : {
|
||||
"revision" : "01835dc202670b5bb90d07f3eae41867e9ed29f6",
|
||||
"version" : "5.0.1"
|
||||
}
|
||||
},
|
||||
{
|
||||
"identity" : "zcash-light-client-ffi",
|
||||
"kind" : "remoteSourceControl",
|
||||
|
|
|
@ -357,8 +357,8 @@ extension SDKSynchronizer {
|
|||
case .unprepared:
|
||||
return "Unprepared 😅"
|
||||
|
||||
case .error(let e):
|
||||
return "Error: \(e.localizedDescription)"
|
||||
case .error(let error):
|
||||
return "Error: \(error.localizedDescription)"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,9 +9,9 @@
|
|||
import XCTest
|
||||
@testable import ZcashLightClientKit
|
||||
@testable import ZcashLightClientSample
|
||||
|
||||
// this test exists only for travis ci to build the demo app
|
||||
class ZcashLightClientSampleTests: XCTestCase {
|
||||
|
||||
func testExample() throws {
|
||||
XCTAssertTrue(true)
|
||||
}
|
||||
|
|
|
@ -5,18 +5,19 @@ let package = Package(
|
|||
name: "ZcashLightClientKit",
|
||||
platforms: [
|
||||
.iOS(.v13),
|
||||
.macOS(.v10_15)
|
||||
.macOS(.v12)
|
||||
],
|
||||
products: [
|
||||
.library(
|
||||
name: "ZcashLightClientKit",
|
||||
targets: ["ZcashLightClientKit"]
|
||||
),
|
||||
)
|
||||
],
|
||||
dependencies: [
|
||||
.package(url: "https://github.com/grpc/grpc-swift.git", from: "1.8.0"),
|
||||
.package(url: "https://github.com/stephencelis/SQLite.swift.git", from: "0.14.1"),
|
||||
.package(name:"libzcashlc", url: "https://github.com/zcash-hackworks/zcash-light-client-ffi", from: "0.1.1"),
|
||||
.package(url: "https://github.com/realm/SwiftLint.git", revision: "a876e86"),
|
||||
.package(name: "libzcashlc", url: "https://github.com/zcash-hackworks/zcash-light-client-ffi", from: "0.1.1")
|
||||
],
|
||||
targets: [
|
||||
.target(
|
||||
|
@ -24,7 +25,7 @@ let package = Package(
|
|||
dependencies: [
|
||||
.product(name: "SQLite", package: "SQLite.swift"),
|
||||
.product(name: "GRPC", package: "grpc-swift"),
|
||||
.product(name: "libzcashlc", package: "libzcashlc"),
|
||||
.product(name: "libzcashlc", package: "libzcashlc")
|
||||
],
|
||||
exclude: [
|
||||
"Service/ProtoBuf/proto/compact_formats.proto",
|
||||
|
@ -32,7 +33,8 @@ let package = Package(
|
|||
],
|
||||
resources: [
|
||||
.copy("Resources/checkpoints")
|
||||
]
|
||||
],
|
||||
plugins: [.plugin(name: "SwiftLintPlugin", package: "SwiftLint")]
|
||||
),
|
||||
.target(
|
||||
name: "TestUtils",
|
||||
|
@ -51,19 +53,23 @@ let package = Package(
|
|||
),
|
||||
.testTarget(
|
||||
name: "OfflineTests",
|
||||
dependencies: ["ZcashLightClientKit", "TestUtils"]
|
||||
dependencies: ["ZcashLightClientKit", "TestUtils"],
|
||||
plugins: [.plugin(name: "SwiftLintPlugin", package: "SwiftLint")]
|
||||
),
|
||||
.testTarget(
|
||||
name: "NetworkTests",
|
||||
dependencies: ["ZcashLightClientKit", "TestUtils"]
|
||||
dependencies: ["ZcashLightClientKit", "TestUtils"],
|
||||
plugins: [.plugin(name: "SwiftLintPlugin", package: "SwiftLint")]
|
||||
),
|
||||
.testTarget(
|
||||
name: "DarksideTests",
|
||||
dependencies: ["ZcashLightClientKit", "TestUtils"]
|
||||
dependencies: ["ZcashLightClientKit", "TestUtils"],
|
||||
plugins: [.plugin(name: "SwiftLintPlugin", package: "SwiftLint")]
|
||||
),
|
||||
.testTarget(
|
||||
name: "PerformanceTests",
|
||||
dependencies: ["ZcashLightClientKit", "TestUtils"]
|
||||
dependencies: ["ZcashLightClientKit", "TestUtils"],
|
||||
plugins: [.plugin(name: "SwiftLintPlugin", package: "SwiftLint")]
|
||||
)
|
||||
]
|
||||
)
|
||||
|
|
|
@ -43,10 +43,11 @@ class CompactBlockStorage: CompactBlockDAO {
|
|||
|
||||
let db = try dbProvider.connection()
|
||||
|
||||
try db.run(compactBlocks.create(ifNotExists: true) { table in
|
||||
table.column(height, primaryKey: true)
|
||||
table.column(data)
|
||||
}
|
||||
try db.run(
|
||||
compactBlocks.create(ifNotExists: true) { table in
|
||||
table.column(height, primaryKey: true)
|
||||
table.column(data)
|
||||
}
|
||||
)
|
||||
|
||||
try db.run(compactBlocks.createIndex(height, ifNotExists: true))
|
||||
|
|
|
@ -13,14 +13,15 @@ class MigrationManager {
|
|||
case none = 0
|
||||
}
|
||||
|
||||
// swiftlint:disable identifier_name
|
||||
enum PendingDbMigration: Int32, CaseIterable {
|
||||
case none = 0
|
||||
case v1 = 1
|
||||
case v2 = 2
|
||||
}
|
||||
|
||||
static let nextCacheDbMigration: CacheDbMigration = CacheDbMigration.none
|
||||
static let nextPendingDbMigration: PendingDbMigration = PendingDbMigration.v2
|
||||
static let nextCacheDbMigration = CacheDbMigration.none
|
||||
static let nextPendingDbMigration = PendingDbMigration.v2
|
||||
|
||||
var cacheDb: ConnectionProvider
|
||||
var pendingDb: ConnectionProvider
|
||||
|
@ -52,8 +53,8 @@ private extension MigrationManager {
|
|||
"Latest version is: \(Self.nextPendingDbMigration.rawValue - 1)"
|
||||
)
|
||||
|
||||
for v in (currentPendingDbVersion..<Self.nextPendingDbMigration.rawValue) {
|
||||
switch PendingDbMigration(rawValue: v) {
|
||||
for version in (currentPendingDbVersion..<Self.nextPendingDbMigration.rawValue) {
|
||||
switch PendingDbMigration(rawValue: version) {
|
||||
case .some(.none):
|
||||
try migratePendingDbV1()
|
||||
case .some(.v1):
|
||||
|
@ -63,7 +64,7 @@ private extension MigrationManager {
|
|||
// unreachable due to the bound on the loop.
|
||||
break
|
||||
case nil:
|
||||
throw StorageError.migrationFailedWithMessage(message: "Invalid migration version: \(v).")
|
||||
throw StorageError.migrationFailedWithMessage(message: "Invalid migration version: \(version).")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -89,8 +90,8 @@ private extension MigrationManager {
|
|||
}
|
||||
|
||||
try pendingDb.connection().transaction(.immediate) {
|
||||
try pendingDb.connection().execute(statement);
|
||||
try pendingDb.connection().setUserVersion(PendingDbMigration.v1.rawValue);
|
||||
try pendingDb.connection().execute(statement)
|
||||
try pendingDb.connection().setUserVersion(PendingDbMigration.v1.rawValue)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -144,8 +145,8 @@ private extension MigrationManager {
|
|||
DROP TABLE pending_transactions_old
|
||||
"""
|
||||
|
||||
try pendingDb.connection().execute(statement);
|
||||
try pendingDb.connection().setUserVersion(PendingDbMigration.v2.rawValue);
|
||||
try pendingDb.connection().execute(statement)
|
||||
try pendingDb.connection().setUserVersion(PendingDbMigration.v2.rawValue)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -158,14 +159,14 @@ private extension MigrationManager {
|
|||
"Latest version is: \(Self.nextCacheDbMigration.rawValue)"
|
||||
)
|
||||
|
||||
for v in (currentCacheDbVersion..<Self.nextCacheDbMigration.rawValue) {
|
||||
switch CacheDbMigration(rawValue: v) {
|
||||
for version in (currentCacheDbVersion..<Self.nextCacheDbMigration.rawValue) {
|
||||
switch CacheDbMigration(rawValue: version) {
|
||||
case .some(.none):
|
||||
// we have no migrations to run; this case should ordinarily be
|
||||
// unreachable due to the bound on the loop.
|
||||
break
|
||||
case nil:
|
||||
throw StorageError.migrationFailedWithMessage(message: "Invalid migration version: \(v).")
|
||||
throw StorageError.migrationFailedWithMessage(message: "Invalid migration version: \(version).")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,7 +9,6 @@
|
|||
import Foundation
|
||||
|
||||
extension CompactBlockProcessor {
|
||||
|
||||
class BlocksDownloadStream {
|
||||
let stream: AsyncThrowingStream<ZcashCompactBlock, Error>
|
||||
var iterator: AsyncThrowingStream<ZcashCompactBlock, Error>.Iterator
|
||||
|
|
|
@ -40,7 +40,12 @@ extension CompactBlockProcessor {
|
|||
throw error
|
||||
}
|
||||
|
||||
guard rustBackend.decryptAndStoreTransaction(dbData: config.dataDb, txBytes: rawBytes, minedHeight: Int32(minedHeight), networkType: config.network.networkType) else {
|
||||
guard rustBackend.decryptAndStoreTransaction(
|
||||
dbData: config.dataDb,
|
||||
txBytes: rawBytes,
|
||||
minedHeight: Int32(minedHeight),
|
||||
networkType: config.network.networkType
|
||||
) else {
|
||||
throw EnhancementError.decryptError(
|
||||
error: rustBackend.lastError() ?? .genericError(message: "`decryptAndStoreTransaction` failed. No message available")
|
||||
)
|
||||
|
@ -91,7 +96,6 @@ extension CompactBlockProcessor {
|
|||
)
|
||||
)
|
||||
await internalSyncProgress.set(confirmedTx.minedHeight, .latestEnhancedHeight)
|
||||
|
||||
} catch {
|
||||
retries += 1
|
||||
LoggerProxy.error("could not enhance txId \(transaction.transactionId.toHexStringTxId()) - Error: \(error)")
|
||||
|
|
|
@ -138,8 +138,8 @@ public extension Notification.Name {
|
|||
static let blockProcessorStatusChanged = Notification.Name(rawValue: "CompactBlockProcessorStatusChanged")
|
||||
|
||||
/**
|
||||
Notification sent when a compact block processor starts syncing
|
||||
*/
|
||||
Notification sent when a compact block processor starts syncing
|
||||
*/
|
||||
static let blockProcessorStartedSyncing = Notification.Name(rawValue: "CompactBlockProcessorStartedSyncing")
|
||||
|
||||
/**
|
||||
|
@ -202,11 +202,9 @@ public extension Notification.Name {
|
|||
static let blockProcessorConnectivityStateChanged = Notification.Name("CompactBlockProcessorConnectivityStateChanged")
|
||||
}
|
||||
|
||||
|
||||
/// The compact block processor is in charge of orchestrating the download and caching of compact blocks from a LightWalletEndpoint
|
||||
/// when started the processor downloads does a download - validate - scan cycle until it reaches latest height on the blockchain.
|
||||
actor CompactBlockProcessor {
|
||||
|
||||
/// Compact Block Processor configuration
|
||||
///
|
||||
/// Property: cacheDbPath absolute file path of the DB where raw, unprocessed compact blocks are stored.
|
||||
|
@ -308,7 +306,7 @@ actor CompactBlockProcessor {
|
|||
/**
|
||||
was processing but erred
|
||||
*/
|
||||
case error(_ e: Error)
|
||||
case error(_ error: Error)
|
||||
|
||||
/// Download sapling param files if needed.
|
||||
case handlingSaplingFiles
|
||||
|
@ -487,9 +485,9 @@ actor CompactBlockProcessor {
|
|||
|
||||
guard shouldStart else {
|
||||
switch self.state {
|
||||
case .error(let e):
|
||||
case .error(let error):
|
||||
// max attempts have been reached
|
||||
LoggerProxy.info("max retry attempts reached with error: \(e)")
|
||||
LoggerProxy.info("max retry attempts reached with error: \(error)")
|
||||
notifyError(CompactBlockProcessorError.maxAttemptsReached(attempts: self.maxAttempts))
|
||||
state = .stopped
|
||||
case .stopped:
|
||||
|
@ -549,7 +547,7 @@ actor CompactBlockProcessor {
|
|||
throw error
|
||||
}
|
||||
|
||||
// FIXME: this should be done on the rust layer
|
||||
// FIXME: [#719] this should be done on the rust layer, https://github.com/zcash/ZcashLightClientKit/issues/719
|
||||
let rewindHeight = max(Int32(nearestHeight - 1), Int32(config.walletBirthday))
|
||||
guard rustBackend.rewindToHeight(dbData: config.dataDb, height: rewindHeight, networkType: self.config.network.networkType) else {
|
||||
let error = rustBackend.lastError() ?? RustWeldingError.genericError(message: "unknown error rewinding to height \(height)")
|
||||
|
@ -679,7 +677,7 @@ actor CompactBlockProcessor {
|
|||
for i in 0..<loopsCount {
|
||||
let processingRange = computeSingleLoopDownloadRange(fullRange: range, loopCounter: i, batchSize: batchSize)
|
||||
|
||||
LoggerProxy.debug("Sync loop #\(i+1) range: \(processingRange.lowerBound)...\(processingRange.upperBound)")
|
||||
LoggerProxy.debug("Sync loop #\(i + 1) range: \(processingRange.lowerBound)...\(processingRange.upperBound)")
|
||||
|
||||
try await downloadAndStoreBlocks(
|
||||
using: downloadStream,
|
||||
|
@ -701,19 +699,19 @@ actor CompactBlockProcessor {
|
|||
}
|
||||
|
||||
/*
|
||||
Here range for one batch is computed. For example if we want to sync blocks 0...1000 with batchSize 100 we want to generage blocks like
|
||||
this:
|
||||
0...99
|
||||
100...199
|
||||
200...299
|
||||
300...399
|
||||
...
|
||||
900...999
|
||||
1000...1000
|
||||
*/
|
||||
Here range for one batch is computed. For example if we want to sync blocks 0...1000 with batchSize 100 we want to generage blocks like
|
||||
this:
|
||||
0...99
|
||||
100...199
|
||||
200...299
|
||||
300...399
|
||||
...
|
||||
900...999
|
||||
1000...1000
|
||||
*/
|
||||
func computeSingleLoopDownloadRange(fullRange: CompactBlockRange, loopCounter: Int, batchSize: BlockHeight) -> CompactBlockRange {
|
||||
let lowerBound = fullRange.lowerBound + (loopCounter * batchSize)
|
||||
let upperBound = min(fullRange.lowerBound + ((loopCounter+1) * batchSize) - 1, fullRange.upperBound)
|
||||
let upperBound = min(fullRange.lowerBound + ((loopCounter + 1) * batchSize) - 1, fullRange.upperBound)
|
||||
return lowerBound...upperBound
|
||||
}
|
||||
|
||||
|
@ -777,7 +775,7 @@ actor CompactBlockProcessor {
|
|||
}
|
||||
|
||||
func fail(_ error: Error) async {
|
||||
// todo specify: failure
|
||||
// TODO: [#713] specify: failure. https://github.com/zcash/ZcashLightClientKit/issues/713
|
||||
LoggerProxy.error("\(error)")
|
||||
cancelableTask?.cancel()
|
||||
self.retryAttempts += 1
|
||||
|
@ -934,12 +932,12 @@ actor CompactBlockProcessor {
|
|||
guard let self = self else { return }
|
||||
if await self.shouldStart {
|
||||
LoggerProxy.debug(
|
||||
"""
|
||||
Timer triggered: Starting compact Block processor!.
|
||||
Processor State: \(await self.state)
|
||||
latestHeight: \(try await self.transactionRepository.lastScannedHeight())
|
||||
attempts: \(await self.retryAttempts)
|
||||
"""
|
||||
"""
|
||||
Timer triggered: Starting compact Block processor!.
|
||||
Processor State: \(await self.state)
|
||||
latestHeight: \(try await self.transactionRepository.lastScannedHeight())
|
||||
attempts: \(await self.retryAttempts)
|
||||
"""
|
||||
)
|
||||
await self.start()
|
||||
} else if await self.maxAttemptsReached {
|
||||
|
@ -993,7 +991,7 @@ actor CompactBlockProcessor {
|
|||
userInfo: [CompactBlockProcessorNotificationKey.error: mapError(err)]
|
||||
)
|
||||
}
|
||||
// TODO: encapsulate service errors better
|
||||
// TODO: [#713] encapsulate service errors better, https://github.com/zcash/ZcashLightClientKit/issues/713
|
||||
}
|
||||
|
||||
extension CompactBlockProcessor.Configuration {
|
||||
|
@ -1081,8 +1079,9 @@ extension CompactBlockProcessor {
|
|||
try rustBackend.getVerifiedTransparentBalance(
|
||||
dbData: config.dataDb,
|
||||
account: Int32(accountIndex),
|
||||
networkType: config.network.networkType)
|
||||
),
|
||||
networkType: config.network.networkType
|
||||
)
|
||||
),
|
||||
total: Zatoshi(
|
||||
try rustBackend.getTransparentBalance(
|
||||
dbData: config.dataDb,
|
||||
|
@ -1098,7 +1097,10 @@ extension CompactBlockProcessor {
|
|||
func refreshUTXOs(tAddress: TransparentAddress, startHeight: BlockHeight) async throws -> RefreshedUTXOs {
|
||||
let dataDb = self.config.dataDb
|
||||
|
||||
let stream: AsyncThrowingStream<UnspentTransactionOutputEntity, Error> = downloader.fetchUnspentTransactionOutputs(tAddress: tAddress.stringEncoded, startHeight: startHeight)
|
||||
let stream: AsyncThrowingStream<UnspentTransactionOutputEntity, Error> = downloader.fetchUnspentTransactionOutputs(
|
||||
tAddress: tAddress.stringEncoded,
|
||||
startHeight: startHeight
|
||||
)
|
||||
var utxos: [UnspentTransactionOutputEntity] = []
|
||||
|
||||
do {
|
||||
|
@ -1116,7 +1118,7 @@ extension CompactBlockProcessor {
|
|||
var skipped: [UnspentTransactionOutputEntity] = []
|
||||
for utxo in utxos {
|
||||
do {
|
||||
try self.rustBackend.putUnspentTransparentOutput(
|
||||
if try self.rustBackend.putUnspentTransparentOutput(
|
||||
dbData: dataDb,
|
||||
txid: utxo.txid.bytes,
|
||||
index: utxo.index,
|
||||
|
@ -1124,7 +1126,11 @@ extension CompactBlockProcessor {
|
|||
value: Int64(utxo.valueZat),
|
||||
height: utxo.height,
|
||||
networkType: self.config.network.networkType
|
||||
) ? refreshed.append(utxo) : skipped.append(utxo)
|
||||
) {
|
||||
refreshed.append(utxo)
|
||||
} else {
|
||||
skipped.append(utxo)
|
||||
}
|
||||
} catch {
|
||||
LoggerProxy.info("failed to put utxo - error: \(error)")
|
||||
skipped.append(utxo)
|
||||
|
@ -1205,6 +1211,7 @@ extension CompactBlockProcessor: EnhancementStreamDelegate {
|
|||
|
||||
extension CompactBlockProcessor {
|
||||
enum NextStateHelper {
|
||||
// swiftlint:disable:next function_parameter_count
|
||||
static func nextStateAsync(
|
||||
service: LightWalletService,
|
||||
downloader: CompactBlockDownloading,
|
||||
|
|
|
@ -9,7 +9,6 @@
|
|||
import Foundation
|
||||
|
||||
extension CompactBlockProcessor {
|
||||
|
||||
func scanBlocks(at range: CompactBlockRange, totalProgressRange: CompactBlockRange) async throws {
|
||||
try await compactBlockBatchScanning(range: range, totalProgressRange: totalProgressRange) { [weak self] lastScannedHeight in
|
||||
let progress = BlockProgress(
|
||||
|
@ -40,7 +39,7 @@ extension CompactBlockProcessor {
|
|||
|
||||
let previousScannedHeight = lastScannedHeight
|
||||
|
||||
// TODO: remove this arbitrary batch size https://github.com/zcash/ZcashLightClientKit/issues/576
|
||||
// TODO: [#576] remove this arbitrary batch size https://github.com/zcash/ZcashLightClientKit/issues/576
|
||||
let batchSize = scanBatchSize(startScanHeight: previousScannedHeight + 1, network: self.config.network.networkType)
|
||||
|
||||
let scanStartTime = Date()
|
||||
|
@ -93,6 +92,7 @@ extension CompactBlockProcessor {
|
|||
}
|
||||
}
|
||||
|
||||
// swiftlint:disable:next strict_fileprivate
|
||||
fileprivate func scanBatchSize(startScanHeight height: BlockHeight, network: NetworkType) -> UInt32 {
|
||||
assert(config.scanningBatchSize > 0, "ZcashSDK.DefaultScanningBatch must be larger than 0!")
|
||||
guard network == .mainnet else {
|
||||
|
|
|
@ -42,7 +42,6 @@ extension CompactBlockProcessor {
|
|||
LoggerProxy.debug("Warning: compactBlockValidation cancelled")
|
||||
}
|
||||
LoggerProxy.debug("validateChainFinished")
|
||||
break
|
||||
|
||||
default:
|
||||
let error = CompactBlockValidationError.validationFailed(height: BlockHeight(result))
|
||||
|
|
|
@ -46,7 +46,7 @@ extension CompactBlockProcessor {
|
|||
let startTime = Date()
|
||||
for utxo in utxos {
|
||||
do {
|
||||
try rustBackend.putUnspentTransparentOutput(
|
||||
if try rustBackend.putUnspentTransparentOutput(
|
||||
dbData: config.dataDb,
|
||||
txid: utxo.txid.bytes,
|
||||
index: utxo.index,
|
||||
|
@ -54,7 +54,11 @@ extension CompactBlockProcessor {
|
|||
value: Int64(utxo.valueZat),
|
||||
height: utxo.height,
|
||||
networkType: config.network.networkType
|
||||
) ? refreshed.append(utxo) : skipped.append(utxo)
|
||||
) {
|
||||
refreshed.append(utxo)
|
||||
} else {
|
||||
skipped.append(utxo)
|
||||
}
|
||||
|
||||
await internalSyncProgress.set(utxo.height, .latestUTXOFetchedHeight)
|
||||
} catch {
|
||||
|
|
|
@ -26,13 +26,13 @@ protocol InternalSyncProgressStorage {
|
|||
func integer(forKey defaultName: String) -> Int
|
||||
func set(_ value: Int, forKey defaultName: String)
|
||||
func set(_ value: Bool, forKey defaultName: String)
|
||||
@discardableResult func synchronize() -> Bool
|
||||
@discardableResult
|
||||
func synchronize() -> Bool
|
||||
}
|
||||
|
||||
extension UserDefaults: InternalSyncProgressStorage { }
|
||||
|
||||
actor InternalSyncProgress {
|
||||
|
||||
enum Key: String, CaseIterable {
|
||||
case latestDownloadedBlockHeight
|
||||
case latestEnhancedHeight
|
||||
|
@ -41,15 +41,15 @@ actor InternalSyncProgress {
|
|||
|
||||
private let storage: InternalSyncProgressStorage
|
||||
|
||||
var latestDownloadedBlockHeight: BlockHeight { get { get(.latestDownloadedBlockHeight) } }
|
||||
var latestEnhancedHeight: BlockHeight { get { get(.latestEnhancedHeight) } }
|
||||
var latestUTXOFetchedHeight: BlockHeight { get { get(.latestUTXOFetchedHeight) } }
|
||||
var latestDownloadedBlockHeight: BlockHeight { load(.latestDownloadedBlockHeight) }
|
||||
var latestEnhancedHeight: BlockHeight { load(.latestEnhancedHeight) }
|
||||
var latestUTXOFetchedHeight: BlockHeight { load(.latestUTXOFetchedHeight) }
|
||||
|
||||
init(storage: InternalSyncProgressStorage) {
|
||||
self.storage = storage
|
||||
}
|
||||
|
||||
func get(_ key: Key) -> BlockHeight {
|
||||
func load(_ key: Key) -> BlockHeight {
|
||||
storage.integer(forKey: key.rawValue)
|
||||
}
|
||||
|
||||
|
@ -60,7 +60,7 @@ actor InternalSyncProgress {
|
|||
|
||||
func rewind(to: BlockHeight) {
|
||||
Key.allCases.forEach { key in
|
||||
let finalRewindHeight = min(self.get(key), to)
|
||||
let finalRewindHeight = min(load(key), to)
|
||||
self.set(finalRewindHeight, key)
|
||||
}
|
||||
}
|
||||
|
@ -113,10 +113,10 @@ actor InternalSyncProgress {
|
|||
latestEnhancedHeight > latestBlockHeight ||
|
||||
latestUTXOFetchedHeight > latestBlockHeight {
|
||||
return .wait(latestHeight: latestBlockHeight, latestDownloadHeight: latestDownloadedBlockHeight)
|
||||
} else if latestDownloadedBlockHeight < latestBlockHeight ||
|
||||
latestScannedHeight < latestBlockHeight ||
|
||||
latestEnhancedHeight < latestEnhancedHeight ||
|
||||
latestUTXOFetchedHeight < latestBlockHeight {
|
||||
} else if latestDownloadedBlockHeight < latestBlockHeight ||
|
||||
latestScannedHeight < latestBlockHeight ||
|
||||
latestEnhancedHeight < latestEnhancedHeight ||
|
||||
latestUTXOFetchedHeight < latestBlockHeight {
|
||||
let ranges = computeSyncRanges(
|
||||
birthday: walletBirthday,
|
||||
latestBlockHeight: latestBlockHeight,
|
||||
|
@ -137,7 +137,7 @@ actor InternalSyncProgress {
|
|||
// blocks instead of downloading new ones.
|
||||
let downloadedButUnscannedRange: CompactBlockRange?
|
||||
if latestScannedHeight < latestDownloadedBlockHeight {
|
||||
downloadedButUnscannedRange = latestScannedHeight+1...latestDownloadedBlockHeight
|
||||
downloadedButUnscannedRange = latestScannedHeight + 1...latestDownloadedBlockHeight
|
||||
} else {
|
||||
downloadedButUnscannedRange = nil
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@ class NotificationSender {
|
|||
static let `default` = NotificationSender()
|
||||
private let queue = DispatchQueue(label: "NotificationsSender")
|
||||
|
||||
func post(name aName: Notification.Name, object anObject: Any?, userInfo aUserInfo: [AnyHashable : Any]? = nil) {
|
||||
func post(name aName: Notification.Name, object anObject: Any?, userInfo aUserInfo: [AnyHashable: Any]? = nil) {
|
||||
let notification = Notification(name: aName, object: anObject, userInfo: aUserInfo)
|
||||
post(notification: notification)
|
||||
}
|
||||
|
|
|
@ -63,9 +63,7 @@ struct BundleCheckpointURLProvider {
|
|||
var url: (NetworkType) -> URL
|
||||
}
|
||||
|
||||
|
||||
extension BundleCheckpointURLProvider {
|
||||
|
||||
/// Attempts to resolve the platform by checking `#if os(macOS)` build corresponds to a MacOS target
|
||||
/// `#else` branch of that condition will assume iOS is the target platform
|
||||
static var `default` = BundleCheckpointURLProvider { networkType in
|
||||
|
@ -101,7 +99,7 @@ extension BundleCheckpointURLProvider {
|
|||
)?
|
||||
.deletingLastPathComponent() ?? Checkpoint.mainnetCheckpointDirectory
|
||||
case .testnet:
|
||||
return Bundle.module.url(
|
||||
return Bundle.module.url(
|
||||
forResource: "280000",
|
||||
withExtension: "json",
|
||||
subdirectory: "checkpoints/testnet/",
|
||||
|
|
|
@ -8,12 +8,12 @@
|
|||
import Foundation
|
||||
|
||||
extension Checkpoint {
|
||||
static let testnetMin = Checkpoint(
|
||||
height: 280000,
|
||||
hash: "000420e7fcc3a49d729479fb0b560dd7b8617b178a08e9e389620a9d1dd6361a",
|
||||
time: 1535262293,
|
||||
saplingTree: "000000"
|
||||
)
|
||||
|
||||
static let testnetCheckpointDirectory = Bundle.module.bundleURL.appendingPathComponent("checkpoints/testnet/")
|
||||
static let testnetMin = Checkpoint(
|
||||
height: 280000,
|
||||
hash: "000420e7fcc3a49d729479fb0b560dd7b8617b178a08e9e389620a9d1dd6361a",
|
||||
time: 1535262293,
|
||||
saplingTree: "000000"
|
||||
)
|
||||
|
||||
static let testnetCheckpointDirectory = Bundle.module.bundleURL.appendingPathComponent("checkpoints/testnet/")
|
||||
}
|
||||
|
|
|
@ -64,7 +64,6 @@ class ZcashMainnet: ZcashNetwork {
|
|||
Constants of ZcashLightClientKit. this constants don't
|
||||
*/
|
||||
public enum ZcashSDK {
|
||||
|
||||
/// The number of zatoshi that equal 1 ZEC.
|
||||
public static var zatoshiPerZEC: BlockHeight = 100_000_000
|
||||
|
||||
|
@ -75,7 +74,7 @@ public enum ZcashSDK {
|
|||
/// by the rust backend but it is helpful to know what it is set to and should be kept in sync.
|
||||
public static var expiryOffset = 20
|
||||
|
||||
// mark: Defaults
|
||||
// MARK: Defaults
|
||||
|
||||
/// Default size of batches of blocks to request from the compact block service. Which was used both for scanning and downloading.
|
||||
/// consider basing your code assumptions on `DefaultDownloadBatch` and `DefaultScanningBatch` instead.
|
||||
|
|
|
@ -8,7 +8,6 @@
|
|||
import Foundation
|
||||
import SQLite
|
||||
struct PendingTransaction: PendingTransactionEntity, Decodable, Encodable {
|
||||
|
||||
enum CodingKeys: String, CodingKey {
|
||||
case toAddress = "to_address"
|
||||
case toInternalAccount = "to_internal"
|
||||
|
@ -147,7 +146,7 @@ struct PendingTransaction: PendingTransactionEntity, Decodable, Encodable {
|
|||
|
||||
var toAddress: String?
|
||||
var accountId: Int?
|
||||
switch (self.recipient) {
|
||||
switch recipient {
|
||||
case .address(let recipient):
|
||||
toAddress = recipient.stringEncoded
|
||||
case .internalAccount(let acct):
|
||||
|
|
|
@ -167,8 +167,8 @@ class UnspentTransactionOutputSQLDAO: UnspentTransactionOutputRepository {
|
|||
) ?? 0
|
||||
|
||||
return WalletBalance(
|
||||
verified: Zatoshi(Int64(verified)),
|
||||
total: Zatoshi(Int64(total))
|
||||
verified: Zatoshi(Int64(verified)),
|
||||
total: Zatoshi(Int64(total))
|
||||
)
|
||||
} catch {
|
||||
throw StorageError.operationFailed
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
import Foundation
|
||||
|
||||
public protocol UnspentTransactionOutputEntity {
|
||||
// TODO: Remove address field?
|
||||
// TODO: [#714] Remove address field?, https://github.com/zcash/ZcashLightClientKit/issues/714
|
||||
var address: String { get set }
|
||||
var txid: Data { get set }
|
||||
var index: Int { get set }
|
||||
|
|
|
@ -22,7 +22,7 @@ extension SynchronizerError: LocalizedError {
|
|||
return "An error occurred when syncing. Message: \(message)"
|
||||
case .maxRetryAttemptsReached(attempts: let attempts):
|
||||
return "An error occurred. We made \(attempts) retry attempts."
|
||||
case .connectionError(status: let status, message: let message):
|
||||
case let .connectionError(status: status, message: message):
|
||||
return "There's a connection error. Status #\(status). Message: \(message)"
|
||||
case .networkTimeout:
|
||||
return "Network Timeout. Please check Internet connection"
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
|
||||
public protocol Undescribable: CustomStringConvertible, CustomDebugStringConvertible, CustomLeafReflectable {}
|
||||
|
||||
|
||||
extension Undescribable {
|
||||
public var description: String {
|
||||
return "--redacted--"
|
||||
|
|
|
@ -60,7 +60,6 @@ The [cash.z.wallet.sdk.block.CompactBlockProcessor] handles all the remaining Ru
|
|||
functionality, related to processing blocks.
|
||||
*/
|
||||
public class Initializer {
|
||||
|
||||
public enum InitializationResult {
|
||||
case success
|
||||
case seedRequired
|
||||
|
@ -262,7 +261,6 @@ public class Initializer {
|
|||
return balance
|
||||
}
|
||||
|
||||
|
||||
/// get (unverified) balance from the given account index
|
||||
/// - Parameter account: the index of the account
|
||||
/// - Returns: balance in `Zatoshi`
|
||||
|
@ -297,7 +295,7 @@ public class Initializer {
|
|||
dbData: dataDbURL,
|
||||
account: Int32(index),
|
||||
networkType: network.networkType
|
||||
) else { return .zero}
|
||||
) else { return .zero }
|
||||
|
||||
return Zatoshi(balance)
|
||||
}
|
||||
|
@ -338,7 +336,6 @@ enum CompactBlockProcessorBuilder {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
extension InitializerError: LocalizedError {
|
||||
public var errorDescription: String? {
|
||||
switch self {
|
||||
|
@ -354,7 +351,6 @@ extension InitializerError: LocalizedError {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/// Synchronous helpers that support clients that don't use structured concurrency yet
|
||||
extension Initializer {
|
||||
func getCurrentAddress(accountIndex: Int) -> UnifiedAddress? {
|
||||
|
|
|
@ -60,7 +60,7 @@ public class SDKMetrics {
|
|||
public var cumulativeSummaries: [CumulativeSummary] = []
|
||||
public var syncReport: SyncReport?
|
||||
var isEnabled = false
|
||||
var reports: [Operation : [BlockMetricReport]] = [:]
|
||||
var reports: [Operation: [BlockMetricReport]] = [:]
|
||||
|
||||
/// `SDKMetrics` is disabled by default. Any pushed data are simply ignored until `enableMetrics()` is called.
|
||||
public func enableMetrics() {
|
||||
|
@ -129,7 +129,7 @@ public class SDKMetrics {
|
|||
|
||||
/// A method allowing users of the `SDKMetrics` to pop the RAW data out of the system. This time for all measured operations
|
||||
/// with option to either leave data in the storage or flushing it out and start the next batch of collecting new ones.
|
||||
public func popAllBlockReports(flush: Bool = false) -> [Operation : [BlockMetricReport]] {
|
||||
public func popAllBlockReports(flush: Bool = false) -> [Operation: [BlockMetricReport]] {
|
||||
defer {
|
||||
if flush { clearAllBlockReports() }
|
||||
}
|
||||
|
|
|
@ -63,7 +63,7 @@ public extension Memo {
|
|||
|
||||
case .arbitrary(var arbitraryBytes):
|
||||
arbitraryBytes.insert(0xFF, at: 0)
|
||||
return try MemoBytes(bytes:arbitraryBytes)
|
||||
return try MemoBytes(bytes: arbitraryBytes)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -73,7 +73,7 @@ public struct MemoText: Equatable {
|
|||
public private(set) var string: String
|
||||
|
||||
init(_ string: String) throws {
|
||||
let trimmedString = String(string.reversed().drop(while: { $0 == "\u{0}"}).reversed())
|
||||
let trimmedString = String(string.reversed().drop(while: { $0 == "\u{0}" }).reversed())
|
||||
|
||||
guard trimmedString.count == string.count else {
|
||||
throw MemoBytes.Errors.endsWithNullBytes
|
||||
|
@ -132,6 +132,7 @@ public struct MemoBytes: Equatable {
|
|||
}
|
||||
|
||||
public static func empty() -> Self {
|
||||
// swiftlint:disable:next force_try
|
||||
try! Self(bytes: .emptyMemoBytes)
|
||||
}
|
||||
}
|
||||
|
@ -219,11 +220,14 @@ extension Array where Element == UInt8 {
|
|||
|
||||
extension String {
|
||||
public init?(validatingUTF8 cString: UnsafePointer<UInt8>) {
|
||||
guard let (s, _) = String.decodeCString(cString, as: UTF8.self,
|
||||
repairingInvalidCodeUnits: false) else {
|
||||
guard let (str, _) = String.decodeCString(
|
||||
cString,
|
||||
as: UTF8.self,
|
||||
repairingInvalidCodeUnits: false
|
||||
) else {
|
||||
return nil
|
||||
}
|
||||
self = s
|
||||
self = str
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -47,9 +47,7 @@ public struct TransparentAccountPrivKey: Equatable, Undescribable {
|
|||
var encoding: String
|
||||
}
|
||||
|
||||
/**
|
||||
A ZIP 316 Unified Full Viewing Key.
|
||||
*/
|
||||
/// A ZIP 316 Unified Full Viewing Key.
|
||||
public struct UnifiedFullViewingKey: Equatable, StringEncoded, Undescribable {
|
||||
var encoding: String
|
||||
|
||||
|
@ -268,13 +266,13 @@ public enum Recipient: Equatable, StringEncoded {
|
|||
}
|
||||
|
||||
static func forEncodedAddress(encoded: String) -> (Recipient, NetworkType)? {
|
||||
return DerivationTool.getAddressMetadata(encoded).map { m in
|
||||
switch m.addressType {
|
||||
return DerivationTool.getAddressMetadata(encoded).map { metadata in
|
||||
switch metadata.addressType {
|
||||
case .p2pkh: return (.transparent(TransparentAddress(validatedEncoding: encoded)),
|
||||
m.networkType)
|
||||
case .p2sh: return (.transparent(TransparentAddress(validatedEncoding: encoded)), m.networkType)
|
||||
case .sapling: return (.sapling(SaplingAddress(validatedEncoding: encoded)), m.networkType)
|
||||
case .unified: return (.unified(UnifiedAddress(validatedEncoding: encoded)), m.networkType)
|
||||
metadata.networkType)
|
||||
case .p2sh: return (.transparent(TransparentAddress(validatedEncoding: encoded)), metadata.networkType)
|
||||
case .sapling: return (.sapling(SaplingAddress(validatedEncoding: encoded)), metadata.networkType)
|
||||
case .unified: return (.unified(UnifiedAddress(validatedEncoding: encoded)), metadata.networkType)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -283,8 +281,8 @@ public enum Recipient: Equatable, StringEncoded {
|
|||
public struct WalletBalance: Equatable {
|
||||
public var verified: Zatoshi
|
||||
public var total: Zatoshi
|
||||
|
||||
public init(verified: Zatoshi, total: Zatoshi) {
|
||||
|
||||
public init(verified: Zatoshi, total: Zatoshi) {
|
||||
self.verified = verified
|
||||
self.total = total
|
||||
}
|
||||
|
|
|
@ -90,7 +90,6 @@ public extension NSDecimalNumber {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
extension Zatoshi: Codable {
|
||||
enum CodingKeys: String, CodingKey {
|
||||
case amount
|
||||
|
|
|
@ -80,7 +80,6 @@ class ZcashRustBackend: ZcashRustBackendWelding {
|
|||
accountIndex: Int32,
|
||||
networkType: NetworkType
|
||||
) throws -> UnifiedSpendingKey {
|
||||
|
||||
let binaryKeyPtr = seed.withUnsafeBufferPointer { seedBufferPtr in
|
||||
return zcashlc_derive_spending_key(
|
||||
seedBufferPtr.baseAddress,
|
||||
|
@ -256,7 +255,7 @@ class ZcashRustBackend: ZcashRustBackendWelding {
|
|||
var contiguousMemoBytes = ContiguousArray<UInt8>(MemoBytes.empty().bytes)
|
||||
var success = false
|
||||
|
||||
contiguousMemoBytes.withUnsafeMutableBytes{ memoBytePtr in
|
||||
contiguousMemoBytes.withUnsafeMutableBytes { memoBytePtr in
|
||||
success = zcashlc_get_sent_memo(dbData.0, dbData.1, idNote, memoBytePtr.baseAddress, networkType.networkId)
|
||||
}
|
||||
|
||||
|
@ -283,7 +282,7 @@ class ZcashRustBackend: ZcashRustBackendWelding {
|
|||
)
|
||||
|
||||
guard balance >= 0 else {
|
||||
throw throwBalanceError(account: account, lastError(), fallbackMessage: "Error getting Total Transparent balance from account \(account)")
|
||||
throw throwBalanceError(account: account, lastError(), fallbackMessage: "Error getting Total Transparent balance from account \(account)")
|
||||
}
|
||||
|
||||
return balance
|
||||
|
@ -326,7 +325,11 @@ class ZcashRustBackend: ZcashRustBackendWelding {
|
|||
)
|
||||
|
||||
guard balance >= 0 else {
|
||||
throw throwBalanceError(account: account, lastError(), fallbackMessage: "Error getting verified transparent balance from account \(account)")
|
||||
throw throwBalanceError(
|
||||
account: account,
|
||||
lastError(),
|
||||
fallbackMessage: "Error getting verified transparent balance from account \(account)"
|
||||
)
|
||||
}
|
||||
|
||||
return balance
|
||||
|
@ -360,7 +363,7 @@ class ZcashRustBackend: ZcashRustBackendWelding {
|
|||
}
|
||||
|
||||
guard let network = NetworkType.forNetworkId(networkId),
|
||||
let addrType = AddressType.forId(addrId)
|
||||
let addrType = AddressType.forId(addrId)
|
||||
else {
|
||||
return nil
|
||||
}
|
||||
|
@ -399,7 +402,7 @@ class ZcashRustBackend: ZcashRustBackendWelding {
|
|||
static func initDataDb(dbData: URL, seed: [UInt8]?, networkType: NetworkType) throws -> DbInitResult {
|
||||
let dbData = dbData.osStr()
|
||||
switch zcashlc_init_data_database(dbData.0, dbData.1, seed, UInt(seed?.count ?? 0), networkType.networkId) {
|
||||
case 0: //ok
|
||||
case 0: // ok
|
||||
return DbInitResult.success
|
||||
case 1:
|
||||
return DbInitResult.seedRequired
|
||||
|
@ -408,7 +411,7 @@ class ZcashRustBackend: ZcashRustBackendWelding {
|
|||
}
|
||||
}
|
||||
|
||||
static func isValidSaplingAddress(_ address: String, networkType: NetworkType) -> Bool {
|
||||
static func isValidSaplingAddress(_ address: String, networkType: NetworkType) -> Bool {
|
||||
guard !address.containsCStringNullBytesBeforeStringEnding() else {
|
||||
return false
|
||||
}
|
||||
|
@ -416,7 +419,7 @@ class ZcashRustBackend: ZcashRustBackendWelding {
|
|||
return zcashlc_is_valid_shielded_address([CChar](address.utf8CString), networkType.networkId)
|
||||
}
|
||||
|
||||
static func isValidTransparentAddress(_ address: String, networkType: NetworkType) -> Bool {
|
||||
static func isValidTransparentAddress(_ address: String, networkType: NetworkType) -> Bool {
|
||||
guard !address.containsCStringNullBytesBeforeStringEnding() else {
|
||||
return false
|
||||
}
|
||||
|
@ -463,7 +466,7 @@ class ZcashRustBackend: ZcashRustBackendWelding {
|
|||
) throws {
|
||||
let dbData = dbData.osStr()
|
||||
|
||||
var ffiUfvks = [FFIEncodedKey]()
|
||||
var ffiUfvks: [FFIEncodedKey] = []
|
||||
for ufvk in ufvks {
|
||||
guard !ufvk.encoding.containsCStringNullBytesBeforeStringEnding() else {
|
||||
throw RustWeldingError.invalidInput(message: "`UFVK` contains null bytes.")
|
||||
|
@ -558,7 +561,7 @@ class ZcashRustBackend: ZcashRustBackendWelding {
|
|||
|
||||
defer { zcashlc_free_keys(encodedKeysPtr) }
|
||||
|
||||
var addresses = [TransparentAddress]()
|
||||
var addresses: [TransparentAddress] = []
|
||||
|
||||
for i in (0 ..< Int(encodedKeysPtr.pointee.len)) {
|
||||
let key = encodedKeysPtr.pointee.ptr.advanced(by: i).pointee
|
||||
|
@ -642,13 +645,12 @@ class ZcashRustBackend: ZcashRustBackendWelding {
|
|||
}
|
||||
|
||||
static func deriveUnifiedFullViewingKey(from spendingKey: UnifiedSpendingKey, networkType: NetworkType) throws -> UnifiedFullViewingKey {
|
||||
|
||||
let extfvk = try spendingKey.bytes.withUnsafeBufferPointer { uskBufferPtr -> UnsafeMutablePointer<CChar> in
|
||||
guard let extfvk = zcashlc_spending_key_to_full_viewing_key(
|
||||
uskBufferPtr.baseAddress,
|
||||
UInt(spendingKey.bytes.count),
|
||||
networkType.networkId
|
||||
) else {
|
||||
uskBufferPtr.baseAddress,
|
||||
UInt(spendingKey.bytes.count),
|
||||
networkType.networkId
|
||||
) else {
|
||||
throw lastError() ?? .genericError(message: "No error message available")
|
||||
}
|
||||
|
||||
|
@ -664,7 +666,6 @@ class ZcashRustBackend: ZcashRustBackendWelding {
|
|||
return UnifiedFullViewingKey(validatedEncoding: derived, account: spendingKey.account)
|
||||
}
|
||||
|
||||
|
||||
static func receiverTypecodesOnUnifiedAddress(_ address: String) throws -> [UInt32] {
|
||||
guard !address.containsCStringNullBytesBeforeStringEnding() else {
|
||||
throw RustWeldingError.invalidInput(message: "`address` contains null bytes.")
|
||||
|
@ -672,16 +673,15 @@ class ZcashRustBackend: ZcashRustBackendWelding {
|
|||
|
||||
var len = UInt(0)
|
||||
|
||||
guard let typecodesPointer = zcashlc_get_typecodes_for_unified_address_receivers(
|
||||
guard let typecodesPointer = zcashlc_get_typecodes_for_unified_address_receivers(
|
||||
[CChar](address.utf8CString),
|
||||
&len
|
||||
),
|
||||
len > 0
|
||||
else {
|
||||
), len > 0
|
||||
else {
|
||||
throw RustWeldingError.malformedStringInput
|
||||
}
|
||||
|
||||
var typecodes = [UInt32]()
|
||||
var typecodes: [UInt32] = []
|
||||
|
||||
for typecodeIndex in 0 ..< Int(len) {
|
||||
let pointer = typecodesPointer.advanced(by: typecodeIndex)
|
||||
|
@ -748,7 +748,8 @@ extension FFIBinaryKey {
|
|||
.init(
|
||||
network: network,
|
||||
bytes: self.encoding.toByteArray(
|
||||
length: Int(self.encoding_len)),
|
||||
length: Int(self.encoding_len)
|
||||
),
|
||||
account: self.account_id
|
||||
)
|
||||
}
|
||||
|
@ -757,7 +758,7 @@ extension FFIBinaryKey {
|
|||
extension UnsafeMutablePointer where Pointee == UInt8 {
|
||||
/// copies the bytes pointed on
|
||||
func toByteArray(length: Int) -> [UInt8] {
|
||||
var bytes = [UInt8]()
|
||||
var bytes: [UInt8] = []
|
||||
|
||||
for index in 0 ..< length {
|
||||
bytes.append(self.advanced(by: index).pointee)
|
||||
|
@ -767,7 +768,6 @@ extension UnsafeMutablePointer where Pointee == UInt8 {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
extension RustWeldingError: LocalizedError {
|
||||
var errorDescription: String? {
|
||||
switch self {
|
||||
|
@ -789,7 +789,7 @@ extension RustWeldingError: LocalizedError {
|
|||
return "`.saplingSpendParametersNotFound` sapling parameters not present at specified URL"
|
||||
case .unableToDeriveKeys:
|
||||
return "`.unableToDeriveKeys` the requested keys could not be derived from the source provided"
|
||||
case .getBalanceError(let account, let error):
|
||||
case let .getBalanceError(account, error):
|
||||
return "`.getBalanceError` could not retrieve balance from account: \(account), error:\(error)"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -67,6 +67,7 @@ protocol ZcashRustBackendWelding {
|
|||
/// - Parameter spendParamsPath: path escaped String for the filesystem locations where the spend parameters are located
|
||||
/// - Parameter outputParamsPath: path escaped String for the filesystem locations where the output parameters are located
|
||||
/// - Parameter networkType: network type of this key
|
||||
// swiftlint:disable:next function_parameter_count
|
||||
static func createToAddress(
|
||||
dbData: URL,
|
||||
usk: UnifiedSpendingKey,
|
||||
|
@ -94,8 +95,8 @@ protocol ZcashRustBackendWelding {
|
|||
networkType: NetworkType
|
||||
) -> Bool
|
||||
|
||||
/// Derives and returns a unified spending key from the given seed for the given account ID.
|
||||
/// Returns the binary encoding of the spending key. The caller should manage the memory of (and store, if necessary) the returned spending key in a secure fashion.
|
||||
/// Derives and returns a unified spending key from the given seed for the given account ID.
|
||||
/// Returns the binary encoding of the spending key. The caller should manage the memory of (and store, if necessary) the returned spending key in a secure fashion.
|
||||
/// - Parameter seed: a Byte Array with the seed
|
||||
/// - Parameter accountIndex:account index that the key can spend from
|
||||
/// - Parameter networkType: network type of this key
|
||||
|
@ -170,7 +171,6 @@ protocol ZcashRustBackendWelding {
|
|||
networkType: NetworkType
|
||||
) -> String?
|
||||
|
||||
|
||||
/// get received memo from note
|
||||
/// - Parameters:
|
||||
/// - dbData: location of the data db file
|
||||
|
@ -264,7 +264,7 @@ protocol ZcashRustBackendWelding {
|
|||
|
||||
/// Returns the network and address type for the given Zcash address string,
|
||||
/// if the string represents a valid Zcash address.
|
||||
static func getAddressMetadata(_ address: String) -> AddressMetadata?
|
||||
static func getAddressMetadata(_ address: String) -> AddressMetadata?
|
||||
|
||||
/// Validates the if the given string is a valid Sapling Address
|
||||
/// - Parameter address: UTF-8 encoded String to validate
|
||||
|
@ -306,7 +306,7 @@ protocol ZcashRustBackendWelding {
|
|||
/// - Parameter networkType: network type of this key
|
||||
/// - Returns: true when the encoded string is a valid UFVK. false in any other case
|
||||
/// - Throws: Error when there's another problem not related to validity of the string in question
|
||||
static func isValidUnifiedFullViewingKey(_ ufvk: String, networkType: NetworkType) -> Bool
|
||||
static func isValidUnifiedFullViewingKey(_ ufvk: String, networkType: NetworkType) -> Bool
|
||||
|
||||
/// initialize the blocks table from a given checkpoint (height, hash, time, saplingTree and networkType)
|
||||
/// - Parameters:
|
||||
|
@ -348,7 +348,6 @@ protocol ZcashRustBackendWelding {
|
|||
networkType: NetworkType
|
||||
) throws -> Int64
|
||||
|
||||
|
||||
/// Get the verified cached transparent balance for the given account
|
||||
/// - Parameters:
|
||||
/// - dbData: location of the data db
|
||||
|
@ -393,7 +392,6 @@ protocol ZcashRustBackendWelding {
|
|||
networkType: NetworkType
|
||||
) -> Bool
|
||||
|
||||
|
||||
/// Scans new blocks added to the cache for any transactions received by the tracked
|
||||
/// accounts.
|
||||
/// This function pays attention only to cached blocks with heights greater than the
|
||||
|
@ -419,7 +417,6 @@ protocol ZcashRustBackendWelding {
|
|||
networkType: NetworkType
|
||||
) -> Bool
|
||||
|
||||
|
||||
/// puts a UTXO into the data db database
|
||||
/// - Parameters:
|
||||
/// - dbData: location of the data db file
|
||||
|
@ -456,7 +453,7 @@ protocol ZcashRustBackendWelding {
|
|||
spendParamsPath: String,
|
||||
outputParamsPath: String,
|
||||
networkType: NetworkType
|
||||
) -> Int64 // swiftlint:disable function_parameter_count
|
||||
) -> Int64
|
||||
|
||||
/// Obtains the available receiver typecodes for the given String encoded Unified Address
|
||||
/// - Parameter address: public key represented as a String
|
||||
|
@ -464,7 +461,6 @@ protocol ZcashRustBackendWelding {
|
|||
/// - Throws `RustWeldingError.invalidInput(message: String)` when the UA is either invalid or malformed
|
||||
static func receiverTypecodesOnUnifiedAddress(_ address: String) throws -> [UInt32]
|
||||
|
||||
|
||||
/// Gets the consensus branch id for the given height
|
||||
/// - Parameter height: the height you what to know the branch id for
|
||||
/// - Parameter networkType: the network type
|
||||
|
@ -473,7 +469,6 @@ protocol ZcashRustBackendWelding {
|
|||
networkType: NetworkType
|
||||
) throws -> Int32
|
||||
|
||||
|
||||
/// Derives a `UnifiedFullViewingKey` from a `UnifiedSpendingKey`
|
||||
/// - Parameter spendingKey: the `UnifiedSpendingKey` to derive from
|
||||
/// - Parameter networkType: the network type
|
||||
|
|
|
@ -260,7 +260,8 @@ extension LightWalletGRPCService: LightWalletService {
|
|||
for tAddress: String,
|
||||
height: BlockHeight,
|
||||
result: @escaping (Result<[UnspentTransactionOutputEntity], LightWalletServiceError>
|
||||
) -> Void) {
|
||||
) -> Void
|
||||
) {
|
||||
queue.async { [weak self] in
|
||||
guard let self = self else { return }
|
||||
let arg = GetAddressUtxosArg.with { utxoArgs in
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -8,7 +8,6 @@
|
|||
|
||||
import Foundation
|
||||
|
||||
|
||||
/// Represents errors thrown by a Synchronizer
|
||||
public enum SynchronizerError: Error {
|
||||
case initFailed(message: String) // ZcashLightClientKit.SynchronizerError error 0.
|
||||
|
@ -48,7 +47,6 @@ extension ShieldFundsError: LocalizedError {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/// Represent the connection state to the lightwalletd server
|
||||
public enum ConnectionState {
|
||||
/// not in use
|
||||
|
@ -67,11 +65,9 @@ public enum ConnectionState {
|
|||
case shutdown
|
||||
}
|
||||
|
||||
|
||||
/// Primary interface for interacting with the SDK. Defines the contract that specific
|
||||
/// implementations like SdkSynchronizer fulfill.
|
||||
public protocol Synchronizer {
|
||||
|
||||
/// Value representing the Status of this Synchronizer. As the status changes, it will be also notified
|
||||
var status: SyncStatus { get }
|
||||
|
||||
|
@ -82,10 +78,10 @@ public protocol Synchronizer {
|
|||
/// Extended Viewing Keys and a wallet birthday found in the initializer object
|
||||
func prepare(with seed: [UInt8]?) async throws -> Initializer.InitializationResult
|
||||
|
||||
///Starts this synchronizer within the given scope.
|
||||
/// Starts this synchronizer within the given scope.
|
||||
///
|
||||
///Implementations should leverage structured concurrency and
|
||||
///cancel all jobs when this scope completes.
|
||||
/// Implementations should leverage structured concurrency and
|
||||
/// cancel all jobs when this scope completes.
|
||||
func start(retry: Bool) throws
|
||||
|
||||
/// Stop this synchronizer. Implementations should ensure that calling this method cancels all jobs that were created by this instance.
|
||||
|
@ -111,7 +107,6 @@ public protocol Synchronizer {
|
|||
/// - Parameter zatoshi: the amount to send in Zatoshi.
|
||||
/// - Parameter toAddress: the recipient's address.
|
||||
/// - Parameter memo: an `Optional<Memo>`with the memo to include as part of the transaction. send `nil` when sending to transparent receivers otherwise the function will throw an error
|
||||
// swiftlint:disable:next function_parameter_count
|
||||
func sendToAddress(
|
||||
spendingKey: UnifiedSpendingKey,
|
||||
zatoshi: Zatoshi,
|
||||
|
@ -154,7 +149,7 @@ public protocol Synchronizer {
|
|||
/// - from: the confirmed transaction from which the query should start from or nil to retrieve from the most recent transaction
|
||||
/// - limit: the maximum amount of items this should return if available
|
||||
/// - Returns: an array with the given Transactions or nil
|
||||
func allConfirmedTransactions(from transaction: ConfirmedTransactionEntity?, limit: Int) throws -> [ConfirmedTransactionEntity]?
|
||||
func allConfirmedTransactions(from transaction: ConfirmedTransactionEntity?, limit: Int) throws -> [ConfirmedTransactionEntity]?
|
||||
|
||||
/// Returns the latest block height from the provided Lightwallet endpoint
|
||||
func latestHeight(result: @escaping (Result<BlockHeight, Error>) -> Void)
|
||||
|
@ -163,7 +158,6 @@ public protocol Synchronizer {
|
|||
/// Blocking
|
||||
func latestHeight() async throws -> BlockHeight
|
||||
|
||||
|
||||
/// Returns the latests UTXOs for the given address from the specified height on
|
||||
func refreshUTXOs(address: TransparentAddress, from height: BlockHeight) async throws -> RefreshedUTXOs
|
||||
|
||||
|
@ -174,7 +168,6 @@ public protocol Synchronizer {
|
|||
@available(*, deprecated, message: "This function will be removed soon, use the one returning a `Zatoshi` value instead")
|
||||
func getShieldedBalance(accountIndex: Int) -> Int64
|
||||
|
||||
|
||||
/// Returns the shielded total balance (includes verified and unverified balance)
|
||||
func getShieldedBalance(accountIndex: Int) -> Zatoshi
|
||||
|
||||
|
@ -185,7 +178,6 @@ public protocol Synchronizer {
|
|||
/// Returns the shielded verified balance (anchor is 10 blocks back)
|
||||
func getShieldedVerifiedBalance(accountIndex: Int) -> Zatoshi
|
||||
|
||||
|
||||
/// Rescans the known blocks with the current keys. If this is called while sync process is in progress then
|
||||
/// `SynchronizerError.rewindError(CompactBlockProcessorError.rewindAttemptWhileProcessing)` is thrown.
|
||||
///
|
||||
|
@ -203,7 +195,6 @@ public protocol Synchronizer {
|
|||
}
|
||||
|
||||
public enum SyncStatus: Equatable {
|
||||
|
||||
/// Indicates that this Synchronizer is actively preparing to start,
|
||||
/// which usually involves setting up database tables, migrations or
|
||||
/// taking other maintenance steps that need to occur after an upgrade.
|
||||
|
|
|
@ -196,7 +196,7 @@ public class SDKSynchronizer: Synchronizer {
|
|||
name: .synchronizerStarted,
|
||||
object: self,
|
||||
userInfo: [
|
||||
NotificationKeys.synchronizerState : state
|
||||
NotificationKeys.synchronizerState: state
|
||||
]
|
||||
)
|
||||
|
||||
|
@ -459,8 +459,7 @@ public class SDKSynchronizer: Synchronizer {
|
|||
throw SynchronizerError.parameterMissing(underlyingError: error)
|
||||
}
|
||||
|
||||
if case Recipient.transparent = toAddress,
|
||||
memo != nil {
|
||||
if case Recipient.transparent = toAddress, memo != nil {
|
||||
throw SynchronizerError.generalError(message: "Memos can't be sent to transparent addresses.")
|
||||
}
|
||||
|
||||
|
@ -479,7 +478,6 @@ public class SDKSynchronizer: Synchronizer {
|
|||
// let's see if there are funds to shield
|
||||
let accountIndex = Int(spendingKey.account)
|
||||
do {
|
||||
|
||||
let tBalance = try await self.getTransparentBalance(accountIndex: accountIndex)
|
||||
|
||||
// Verify that at least there are funds for the fee. Ideally this logic will be improved by the shielding wallet.
|
||||
|
@ -487,9 +485,14 @@ public class SDKSynchronizer: Synchronizer {
|
|||
throw ShieldFundsError.insuficientTransparentFunds
|
||||
}
|
||||
|
||||
let shieldingSpend = try transactionManager.initSpend(zatoshi: tBalance.verified, recipient: .internalAccount(spendingKey.account), memo: try memo.asMemoBytes(), from: accountIndex)
|
||||
let shieldingSpend = try transactionManager.initSpend(
|
||||
zatoshi: tBalance.verified,
|
||||
recipient: .internalAccount(spendingKey.account),
|
||||
memo: try memo.asMemoBytes(),
|
||||
from: accountIndex
|
||||
)
|
||||
|
||||
// TODO: Task will be removed when this method is changed to async, issue 487, https://github.com/zcash/ZcashLightClientKit/issues/487
|
||||
// TODO: [#487] Task will be removed when this method is changed to async, issue 487, https://github.com/zcash/ZcashLightClientKit/issues/487
|
||||
let transaction = try await transactionManager.encodeShieldingTransaction(
|
||||
spendingKey: spendingKey,
|
||||
pendingTransaction: shieldingSpend
|
||||
|
@ -573,9 +576,9 @@ public class SDKSynchronizer: Synchronizer {
|
|||
guard initializer.isValidTransparentAddress(address) else {
|
||||
throw SynchronizerError.generalError(message: "invalid t-address")
|
||||
}
|
||||
|
||||
|
||||
let stream = initializer.lightWalletService.fetchUTXOs(for: address, height: network.constants.saplingActivationHeight)
|
||||
|
||||
|
||||
do {
|
||||
var utxos: [UnspentTransactionOutputEntity] = []
|
||||
for try await transactionEntity in stream {
|
||||
|
@ -697,9 +700,9 @@ public class SDKSynchronizer: Synchronizer {
|
|||
)
|
||||
}
|
||||
|
||||
|
||||
// swiftlint:disable:next strict_fileprivate
|
||||
fileprivate func snapshotState() async -> SDKSynchronizer.SynchronizerState {
|
||||
return SynchronizerState(
|
||||
SynchronizerState(
|
||||
shieldedBalance: WalletBalance(
|
||||
verified: initializer.getVerifiedBalance(),
|
||||
total: initializer.getBalance()
|
||||
|
@ -738,8 +741,8 @@ public class SDKSynchronizer: Synchronizer {
|
|||
NotificationSender.default.post(name: Notification.Name.synchronizerEnhancing, object: self)
|
||||
case .fetching:
|
||||
NotificationSender.default.post(name: Notification.Name.synchronizerFetching, object: self)
|
||||
case .error(let e):
|
||||
self.notifyFailure(e)
|
||||
case .error(let error):
|
||||
self.notifyFailure(error)
|
||||
}
|
||||
}
|
||||
// MARK: book keeping
|
||||
|
@ -870,7 +873,6 @@ extension SDKSynchronizer {
|
|||
public func getTransparentAddress(accountIndex: Int) -> TransparentAddress? {
|
||||
self.getUnifiedAddress(accountIndex: accountIndex)?.transparentReceiver()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
import GRPC
|
||||
|
|
|
@ -20,7 +20,6 @@ public protocol KeyValidation {
|
|||
}
|
||||
|
||||
public protocol KeyDeriving {
|
||||
|
||||
/// Given the seed bytes tand the account index, return the UnifiedSpendingKey
|
||||
/// - Parameter seed: `[Uint8]` seed bytes
|
||||
/// - Parameter accountNumber: `Int` with the account number
|
||||
|
@ -142,7 +141,6 @@ extension DerivationTool: KeyValidation {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
extension TransparentAddress {
|
||||
/// This constructor is for internal use for Strings encodings that are assumed to be
|
||||
/// already validated by another function. only for internal use. Unless you are
|
||||
|
@ -161,7 +159,7 @@ extension SaplingAddress {
|
|||
init(validatedEncoding: String) {
|
||||
self.encoding = validatedEncoding
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension UnifiedAddress {
|
||||
/// This constructor is for internal use for Strings encodings that are assumed to be
|
||||
|
@ -184,7 +182,6 @@ extension UnifiedFullViewingKey {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
extension SaplingExtendedFullViewingKey {
|
||||
/// This constructor is for internal use for Strings encodings that are assumed to be
|
||||
/// already validated by another function. only for internal use. Unless you are
|
||||
|
@ -195,7 +192,6 @@ extension SaplingExtendedFullViewingKey {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
extension SaplingExtendedSpendingKey {
|
||||
/// This constructor is for internal use for Strings encodings that are assumed to be
|
||||
/// already validated by another function. only for internal use. Unless you are
|
||||
|
|
|
@ -92,7 +92,10 @@ class PersistentTransactionManager: OutboundTransactionManager {
|
|||
} catch MemoBytes.Errors.invalidUTF8 {
|
||||
throw TransactionManagerError.shieldingEncodingFailed(pendingTransaction, reason: "Memo contains invalid UTF-8 bytes")
|
||||
} catch MemoBytes.Errors.tooLong(let length) {
|
||||
throw TransactionManagerError.shieldingEncodingFailed(pendingTransaction, reason: "Memo is too long. expected 512 bytes, received \(length)")
|
||||
throw TransactionManagerError.shieldingEncodingFailed(
|
||||
pendingTransaction,
|
||||
reason: "Memo is too long. expected 512 bytes, received \(length)"
|
||||
)
|
||||
} catch {
|
||||
throw error
|
||||
}
|
||||
|
@ -104,17 +107,20 @@ class PersistentTransactionManager: OutboundTransactionManager {
|
|||
) async throws -> PendingTransactionEntity {
|
||||
do {
|
||||
var toAddress: String?
|
||||
switch (pendingTransaction.recipient) {
|
||||
case .address(let addr):
|
||||
toAddress = addr.stringEncoded
|
||||
case .internalAccount(_):
|
||||
throw TransactionManagerError.cannotEncodeInternalTx(pendingTransaction)
|
||||
switch pendingTransaction.recipient {
|
||||
case .address(let addr):
|
||||
toAddress = addr.stringEncoded
|
||||
case .internalAccount: break
|
||||
}
|
||||
|
||||
guard let toAddress else {
|
||||
throw TransactionManagerError.cannotEncodeInternalTx(pendingTransaction)
|
||||
}
|
||||
|
||||
let encodedTransaction = try await self.encoder.createTransaction(
|
||||
spendingKey: spendingKey,
|
||||
zatoshi: pendingTransaction.value,
|
||||
to: toAddress!,
|
||||
to: toAddress,
|
||||
memoBytes: try pendingTransaction.memo?.intoMemoBytes(),
|
||||
from: pendingTransaction.accountIndex
|
||||
)
|
||||
|
|
|
@ -29,7 +29,6 @@ protocol TransactionEncoder {
|
|||
/// - Parameter to: string containing the recipient address
|
||||
/// - Parameter MemoBytes: string containing the memo (optional)
|
||||
/// - Parameter accountIndex: index of the account that will be used to send the funds
|
||||
// swiftlint:disable:next function_parameter_count
|
||||
func createTransaction(
|
||||
spendingKey: UnifiedSpendingKey,
|
||||
zatoshi: Zatoshi,
|
||||
|
@ -54,7 +53,7 @@ protocol TransactionEncoder {
|
|||
from accountIndex: Int
|
||||
) async throws -> EncodedTransaction
|
||||
|
||||
///Fetch the Transaction Entity from the encoded representation
|
||||
/// Fetch the Transaction Entity from the encoded representation
|
||||
/// - Parameter encodedTransaction: The encoded transaction to expand
|
||||
/// - Returns: a TransactionEntity based on the given Encoded Transaction
|
||||
/// - Throws: a TransactionEncoderError
|
||||
|
|
|
@ -159,7 +159,8 @@ class WalletTransactionEncoder: TransactionEncoder {
|
|||
let readableSpend = FileManager.default.isReadableFile(atPath: spend.path)
|
||||
let readableOutput = FileManager.default.isReadableFile(atPath: output.path)
|
||||
|
||||
return readableSpend && readableOutput // Todo: change this to something that makes sense
|
||||
// TODO: [#713] change this to something that makes sense, https://github.com/zcash/ZcashLightClientKit/issues/713
|
||||
return readableSpend && readableOutput
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -9,14 +9,13 @@ import XCTest
|
|||
@testable import TestUtils
|
||||
@testable import ZcashLightClientKit
|
||||
|
||||
// swiftlint:disable implicitly_unwrapped_optional force_unwrapping type_body_length
|
||||
//@MainActor
|
||||
// swiftlint:disable implicitly_unwrapped_optional force_unwrapping force_try type_body_length file_length cyclomatic_complexity
|
||||
class AdvancedReOrgTests: XCTestCase {
|
||||
// TODO: Parameterize this from environment?
|
||||
// TODO: [#715] Parameterize this from environment, https://github.com/zcash/ZcashLightClientKit/issues/715
|
||||
// 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"
|
||||
|
||||
// TODO: Parameterize this from environment
|
||||
// TODO: [#715] Parameterize this from environment, https://github.com/zcash/ZcashLightClientKit/issues/715
|
||||
let testRecipientAddress = "zs17mg40levjezevuhdp5pqrd52zere7r7vrjgdwn5sj4xsqtm20euwahv9anxmwr3y3kmwuz8k55a"
|
||||
|
||||
let sendAmount = Zatoshi(1000)
|
||||
|
@ -36,7 +35,7 @@ class AdvancedReOrgTests: XCTestCase {
|
|||
try super.setUpWithError()
|
||||
self.coordinator = try TestCoordinator(
|
||||
seed: seedPhrase,
|
||||
walletBirthday: birthday + 50, //don't use an exact birthday, users never do.
|
||||
walletBirthday: birthday + 50, // don't use an exact birthday, users never do.
|
||||
channelProvider: ChannelProvider(),
|
||||
network: network
|
||||
)
|
||||
|
@ -67,7 +66,6 @@ class AdvancedReOrgTests: XCTestCase {
|
|||
reorgExpectation.fulfill()
|
||||
}
|
||||
|
||||
|
||||
/// pre-condition: know balances before tx at received_Tx_height arrives
|
||||
/// 1. Setup w/ default dataset
|
||||
/// 2. applyStaged(received_Tx_height)
|
||||
|
@ -278,7 +276,6 @@ class AdvancedReOrgTests: XCTestCase {
|
|||
XCTAssertEqual(initialTotalBalance + receivedTx.value, finalReorgTxTotalBalance)
|
||||
}
|
||||
|
||||
|
||||
/// An outbound, unconfirmed transaction in a specific block changes height in the event of a reorg
|
||||
///
|
||||
///
|
||||
|
@ -427,7 +424,8 @@ class AdvancedReOrgTests: XCTestCase {
|
|||
*/
|
||||
let pMinedHeight = synchronizer.pendingTransactions.first?.minedHeight
|
||||
XCTAssertEqual(pMinedHeight, sentTxHeight)
|
||||
XCTAssertEqual(initialTotalBalance - sendAmount - Zatoshi(1000), synchronizer.initializer.getBalance()) // fee change on this branch
|
||||
// fee change on this branch
|
||||
XCTAssertEqual(initialTotalBalance - sendAmount - Zatoshi(1000), synchronizer.initializer.getBalance())
|
||||
continuation.resume()
|
||||
afterReOrgExpectation.fulfill()
|
||||
}, error: self.handleError)
|
||||
|
@ -450,7 +448,7 @@ class AdvancedReOrgTests: XCTestCase {
|
|||
let lastSyncExpectation = XCTestExpectation(description: "sync to confirmation")
|
||||
try await withCheckedThrowingContinuation { continuation in
|
||||
do {
|
||||
try coordinator.sync(completion: { synchronizer in
|
||||
try coordinator.sync(completion: { _ in
|
||||
lastSyncExpectation.fulfill()
|
||||
continuation.resume()
|
||||
}, error: self.handleError)
|
||||
|
@ -582,7 +580,6 @@ class AdvancedReOrgTests: XCTestCase {
|
|||
XCTAssertEqual(afterReOrgVerifiedBalance, initialVerifiedBalance)
|
||||
}
|
||||
|
||||
|
||||
/// Steps:
|
||||
/// 1. sync up to an incoming transaction (incomingTxHeight + 1)
|
||||
/// 1a. save balances
|
||||
|
@ -756,7 +753,7 @@ class AdvancedReOrgTests: XCTestCase {
|
|||
*/
|
||||
try await withCheckedThrowingContinuation { continuation in
|
||||
do {
|
||||
try coordinator.sync(completion: { synchronizer in
|
||||
try coordinator.sync(completion: { _ in
|
||||
firstSyncExpectation.fulfill()
|
||||
continuation.resume()
|
||||
}, error: self.handleError)
|
||||
|
@ -829,7 +826,7 @@ class AdvancedReOrgTests: XCTestCase {
|
|||
|
||||
try await withCheckedThrowingContinuation { continuation in
|
||||
do {
|
||||
try coordinator.sync(completion: { synchronizer in
|
||||
try coordinator.sync(completion: { _ in
|
||||
secondSyncExpectation.fulfill()
|
||||
continuation.resume()
|
||||
}, error: self.handleError)
|
||||
|
@ -874,7 +871,7 @@ class AdvancedReOrgTests: XCTestCase {
|
|||
|
||||
try await withCheckedThrowingContinuation { continuation in
|
||||
do {
|
||||
try coordinator.sync(completion: { synchronizer in
|
||||
try coordinator.sync(completion: { _ in
|
||||
afterReorgExpectation.fulfill()
|
||||
continuation.resume()
|
||||
}, error: self.handleError)
|
||||
|
@ -909,7 +906,7 @@ class AdvancedReOrgTests: XCTestCase {
|
|||
*/
|
||||
try await withCheckedThrowingContinuation { continuation in
|
||||
do {
|
||||
try coordinator.sync(completion: { synchronizer in
|
||||
try coordinator.sync(completion: { _ in
|
||||
yetAnotherExpectation.fulfill()
|
||||
continuation.resume()
|
||||
}, error: self.handleError)
|
||||
|
@ -946,7 +943,7 @@ class AdvancedReOrgTests: XCTestCase {
|
|||
*/
|
||||
try await withCheckedThrowingContinuation { continuation in
|
||||
do {
|
||||
try coordinator.sync(completion: { synchronizer in
|
||||
try coordinator.sync(completion: { _ in
|
||||
thisIsTheLastExpectationIPromess.fulfill()
|
||||
continuation.resume()
|
||||
}, error: self.handleError)
|
||||
|
@ -983,7 +980,6 @@ class AdvancedReOrgTests: XCTestCase {
|
|||
)
|
||||
}
|
||||
|
||||
|
||||
/// Uses the zcash-hackworks data set.
|
||||
|
||||
/// A Re Org occurs at 663195, and sweeps an Inbound Tx that appears later on the chain.
|
||||
|
@ -1143,8 +1139,7 @@ class AdvancedReOrgTests: XCTestCase {
|
|||
*/
|
||||
try await withCheckedThrowingContinuation { continuation in
|
||||
do {
|
||||
try coordinator.sync(completion: { synchronizer in
|
||||
|
||||
try coordinator.sync(completion: { _ in
|
||||
continuation.resume()
|
||||
firstSyncExpectation.fulfill()
|
||||
}, error: self.handleError)
|
||||
|
@ -1217,7 +1212,7 @@ class AdvancedReOrgTests: XCTestCase {
|
|||
|
||||
try await withCheckedThrowingContinuation { continuation in
|
||||
do {
|
||||
try coordinator.sync(completion: { synchronizer in
|
||||
try coordinator.sync(completion: { _ in
|
||||
secondSyncExpectation.fulfill()
|
||||
continuation.resume()
|
||||
}, error: self.handleError)
|
||||
|
@ -1237,7 +1232,7 @@ class AdvancedReOrgTests: XCTestCase {
|
|||
|
||||
try await withCheckedThrowingContinuation { continuation in
|
||||
do {
|
||||
try coordinator.sync(completion: { synchronizer in
|
||||
try coordinator.sync(completion: { _ in
|
||||
reorgSyncExpectation.fulfill()
|
||||
continuation.resume()
|
||||
}, error: self.handleError)
|
||||
|
@ -1264,7 +1259,7 @@ class AdvancedReOrgTests: XCTestCase {
|
|||
|
||||
try await withCheckedThrowingContinuation { continuation in
|
||||
do {
|
||||
try coordinator.sync(completion: { synchronizer in
|
||||
try coordinator.sync(completion: { _ in
|
||||
lastSyncExpectation.fulfill()
|
||||
continuation.resume()
|
||||
}, error: self.handleError)
|
||||
|
|
|
@ -11,11 +11,11 @@ import XCTest
|
|||
|
||||
// swiftlint:disable type_body_length implicitly_unwrapped_optional force_unwrapping file_length
|
||||
class BalanceTests: XCTestCase {
|
||||
// TODO: Parameterize this from environment?
|
||||
// TODO: [#715] Parameterize this from environment, https://github.com/zcash/ZcashLightClientKit/issues/715?
|
||||
// swiftlint:disable:next line_length
|
||||
let 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"
|
||||
|
||||
// TODO: Parameterize this from environment
|
||||
// TODO: [#715] Parameterize this from environment, https://github.com/zcash/ZcashLightClientKit/issues/715
|
||||
let testRecipientAddress = "zs17mg40levjezevuhdp5pqrd52zere7r7vrjgdwn5sj4xsqtm20euwahv9anxmwr3y3kmwuz8k55a"
|
||||
let sendAmount = Zatoshi(1000)
|
||||
let defaultLatestHeight: BlockHeight = 663188
|
||||
|
@ -60,7 +60,7 @@ class BalanceTests: XCTestCase {
|
|||
|
||||
try await withCheckedThrowingContinuation { continuation in
|
||||
do {
|
||||
try coordinator.sync(completion: { synchronizer in
|
||||
try coordinator.sync(completion: { _ in
|
||||
firstSyncExpectation.fulfill()
|
||||
continuation.resume()
|
||||
}, error: self.handleError)
|
||||
|
@ -178,7 +178,7 @@ class BalanceTests: XCTestCase {
|
|||
}
|
||||
try await withCheckedThrowingContinuation { continuation in
|
||||
do {
|
||||
try coordinator.sync(completion: { synchronizer in
|
||||
try coordinator.sync(completion: { _ in
|
||||
confirmExpectation.fulfill()
|
||||
continuation.resume()
|
||||
}, error: self.handleError)
|
||||
|
@ -218,7 +218,7 @@ class BalanceTests: XCTestCase {
|
|||
|
||||
try await withCheckedThrowingContinuation { continuation in
|
||||
do {
|
||||
try coordinator.sync(completion: { synchronizer in
|
||||
try coordinator.sync(completion: { _ in
|
||||
firstSyncExpectation.fulfill()
|
||||
continuation.resume()
|
||||
}, error: self.handleError)
|
||||
|
@ -336,7 +336,7 @@ class BalanceTests: XCTestCase {
|
|||
}
|
||||
try await withCheckedThrowingContinuation { continuation in
|
||||
do {
|
||||
try coordinator.sync(completion: { synchronizer in
|
||||
try coordinator.sync(completion: { _ in
|
||||
confirmExpectation.fulfill()
|
||||
continuation.resume()
|
||||
}, error: self.handleError)
|
||||
|
@ -377,7 +377,7 @@ class BalanceTests: XCTestCase {
|
|||
|
||||
try await withCheckedThrowingContinuation { continuation in
|
||||
do {
|
||||
try coordinator.sync(completion: { synchronizer in
|
||||
try coordinator.sync(completion: { _ in
|
||||
firstSyncExpectation.fulfill()
|
||||
continuation.resume()
|
||||
}, error: self.handleError)
|
||||
|
@ -493,7 +493,7 @@ class BalanceTests: XCTestCase {
|
|||
}
|
||||
try await withCheckedThrowingContinuation { continuation in
|
||||
do {
|
||||
try coordinator.sync(completion: { synchronizer in
|
||||
try coordinator.sync(completion: { _ in
|
||||
confirmExpectation.fulfill()
|
||||
continuation.resume()
|
||||
}, error: self.handleError)
|
||||
|
@ -540,7 +540,7 @@ class BalanceTests: XCTestCase {
|
|||
|
||||
try await withCheckedThrowingContinuation { continuation in
|
||||
do {
|
||||
try coordinator.sync(completion: { synchronizer in
|
||||
try coordinator.sync(completion: { _ in
|
||||
self.syncedExpectation.fulfill()
|
||||
continuation.resume()
|
||||
}, error: self.handleError)
|
||||
|
@ -574,12 +574,9 @@ class BalanceTests: XCTestCase {
|
|||
pendingTx = transaction
|
||||
self.sentTransactionExpectation.fulfill()
|
||||
} catch {
|
||||
/*
|
||||
balance should be the same as before sending if transaction failed
|
||||
*/
|
||||
// balance should be the same as before sending if transaction failed
|
||||
XCTAssertEqual(self.coordinator.synchronizer.initializer.getVerifiedBalance(), presendVerifiedBalance)
|
||||
XCTFail("sendToAddress failed: \(error)")
|
||||
|
||||
}
|
||||
|
||||
XCTAssertTrue(coordinator.synchronizer.initializer.getVerifiedBalance() > .zero)
|
||||
|
@ -604,7 +601,7 @@ class BalanceTests: XCTestCase {
|
|||
try await withCheckedThrowingContinuation { continuation in
|
||||
do {
|
||||
try coordinator.sync(
|
||||
completion: { synchronizer in
|
||||
completion: { _ in
|
||||
mineExpectation.fulfill()
|
||||
continuation.resume()
|
||||
}, error: { error in
|
||||
|
@ -724,7 +721,7 @@ class BalanceTests: XCTestCase {
|
|||
sleep(2)
|
||||
try await withCheckedThrowingContinuation { continuation in
|
||||
do {
|
||||
try coordinator.sync(completion: { synchronizer in
|
||||
try coordinator.sync(completion: { _ in
|
||||
self.syncedExpectation.fulfill()
|
||||
continuation.resume()
|
||||
}, error: self.handleError)
|
||||
|
@ -800,7 +797,7 @@ class BalanceTests: XCTestCase {
|
|||
try await withCheckedThrowingContinuation { continuation in
|
||||
do {
|
||||
try coordinator.sync(
|
||||
completion: { synchronizer in
|
||||
completion: { _ in
|
||||
mineExpectation.fulfill()
|
||||
continuation.resume()
|
||||
}, error: { error in
|
||||
|
@ -891,7 +888,7 @@ class BalanceTests: XCTestCase {
|
|||
*/
|
||||
try await withCheckedThrowingContinuation { continuation in
|
||||
do {
|
||||
try coordinator.sync(completion: { synchronizer in
|
||||
try coordinator.sync(completion: { _ in
|
||||
self.syncedExpectation.fulfill()
|
||||
continuation.resume()
|
||||
}, error: self.handleError)
|
||||
|
@ -1071,7 +1068,7 @@ class BalanceTests: XCTestCase {
|
|||
sleep(2)
|
||||
try await withCheckedThrowingContinuation { continuation in
|
||||
do {
|
||||
try coordinator.sync(completion: { synchronizer in
|
||||
try coordinator.sync(completion: { _ in
|
||||
self.syncedExpectation.fulfill()
|
||||
continuation.resume()
|
||||
}, error: self.handleError)
|
||||
|
@ -1121,7 +1118,7 @@ class BalanceTests: XCTestCase {
|
|||
sleep(2)
|
||||
try await withCheckedThrowingContinuation { continuation in
|
||||
do {
|
||||
try coordinator.sync(completion: { synchronizer in
|
||||
try coordinator.sync(completion: { _ in
|
||||
expirationSyncExpectation.fulfill()
|
||||
continuation.resume()
|
||||
}, error: self.handleError)
|
||||
|
|
|
@ -36,6 +36,7 @@ class BlockDownloaderTests: XCTestCase {
|
|||
}
|
||||
|
||||
override func tearDown() {
|
||||
super.tearDown()
|
||||
service = nil
|
||||
storage = nil
|
||||
downloader = nil
|
||||
|
|
|
@ -12,10 +12,10 @@ import XCTest
|
|||
|
||||
// swiftlint:disable implicitly_unwrapped_optional
|
||||
class DarksideSanityCheckTests: XCTestCase {
|
||||
// TODO: Parameterize this from environment?
|
||||
// TODO: [#715] Parameterize this from environment, https://github.com/zcash/ZcashLightClientKit/issues/715?
|
||||
// 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"
|
||||
// TODO: Parameterize this from environment
|
||||
// TODO: [#715] Parameterize this from environment, https://github.com/zcash/ZcashLightClientKit/issues/715
|
||||
let testRecipientAddress = "zs17mg40levjezevuhdp5pqrd52zere7r7vrjgdwn5sj4xsqtm20euwahv9anxmwr3y3kmwuz8k55a"
|
||||
|
||||
let sendAmount: Int64 = 1000
|
||||
|
@ -66,11 +66,11 @@ class DarksideSanityCheckTests: XCTestCase {
|
|||
syncExpectation.fulfill()
|
||||
},
|
||||
error: { error in
|
||||
guard let e = error else {
|
||||
guard let error else {
|
||||
XCTFail("failed with unknown error")
|
||||
return
|
||||
}
|
||||
XCTFail("failed with error: \(e)")
|
||||
XCTFail("failed with error: \(error)")
|
||||
return
|
||||
}
|
||||
)
|
||||
|
|
|
@ -11,10 +11,10 @@ import XCTest
|
|||
|
||||
// swiftlint:disable implicitly_unwrapped_optional
|
||||
class PendingTransactionUpdatesTest: XCTestCase {
|
||||
// TODO: Parameterize this from environment?
|
||||
// TODO: [#715] Parameterize this from environment, https://github.com/zcash/ZcashLightClientKit/issues/715?
|
||||
// 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"
|
||||
// TODO: Parameterize this from environment
|
||||
// TODO: [#715] Parameterize this from environment, https://github.com/zcash/ZcashLightClientKit/issues/715
|
||||
let testRecipientAddress = "zs17mg40levjezevuhdp5pqrd52zere7r7vrjgdwn5sj4xsqtm20euwahv9anxmwr3y3kmwuz8k55a"
|
||||
|
||||
let sendAmount: Int64 = 1000
|
||||
|
@ -42,6 +42,7 @@ class PendingTransactionUpdatesTest: XCTestCase {
|
|||
}
|
||||
|
||||
override func tearDownWithError() throws {
|
||||
try super.tearDownWithError()
|
||||
NotificationCenter.default.removeObserver(self)
|
||||
try coordinator.stop()
|
||||
try? FileManager.default.removeItem(at: coordinator.databases.cacheDB)
|
||||
|
@ -80,7 +81,7 @@ class PendingTransactionUpdatesTest: XCTestCase {
|
|||
LoggerProxy.info("1a. sync to latest height")
|
||||
try await withCheckedThrowingContinuation { continuation in
|
||||
do {
|
||||
try coordinator.sync(completion: { synchronizer in
|
||||
try coordinator.sync(completion: { _ in
|
||||
firstSyncExpectation.fulfill()
|
||||
continuation.resume()
|
||||
}, error: self.handleError)
|
||||
|
@ -171,7 +172,7 @@ class PendingTransactionUpdatesTest: XCTestCase {
|
|||
|
||||
try await withCheckedThrowingContinuation { continuation in
|
||||
do {
|
||||
try coordinator.sync(completion: { synchronizer in
|
||||
try coordinator.sync(completion: { _ in
|
||||
secondSyncExpectation.fulfill()
|
||||
continuation.resume()
|
||||
}, error: self.handleError)
|
||||
|
@ -215,7 +216,7 @@ class PendingTransactionUpdatesTest: XCTestCase {
|
|||
|
||||
try await withCheckedThrowingContinuation { continuation in
|
||||
do {
|
||||
try coordinator.sync(completion: { synchronizer in
|
||||
try coordinator.sync(completion: { _ in
|
||||
syncToConfirmExpectation.fulfill()
|
||||
continuation.resume()
|
||||
}, error: self.handleError)
|
||||
|
|
|
@ -23,10 +23,10 @@ basic reorg test. Scan, get a reorg and then reach latest height.
|
|||
*/
|
||||
// swiftlint:disable implicitly_unwrapped_optional print_function_usage function_parameter_count
|
||||
class ReOrgTests: XCTestCase {
|
||||
// TODO: Parameterize this from environment?
|
||||
// TODO: [#715] Parameterize this from environment, https://github.com/zcash/ZcashLightClientKit/issues/715?
|
||||
// swiftlint:disable:next line_length
|
||||
let 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"
|
||||
// TODO: Parameterize this from environment
|
||||
// TODO: [#715] Parameterize this from environment, https://github.com/zcash/ZcashLightClientKit/issues/715
|
||||
let testRecipientAddress = "zs17mg40levjezevuhdp5pqrd52zere7r7vrjgdwn5sj4xsqtm20euwahv9anxmwr3y3kmwuz8k55a"
|
||||
let sendAmount: Int64 = 1000
|
||||
let defaultLatestHeight: BlockHeight = 663175
|
||||
|
@ -67,6 +67,7 @@ class ReOrgTests: XCTestCase {
|
|||
}
|
||||
|
||||
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)
|
||||
|
|
|
@ -9,14 +9,14 @@ import XCTest
|
|||
@testable import TestUtils
|
||||
@testable import ZcashLightClientKit
|
||||
|
||||
// FIXME: disabled until this is resolved https://github.com/zcash/ZcashLightClientKit/issues/586
|
||||
// FIXME: [#586] disabled until this is resolved https://github.com/zcash/ZcashLightClientKit/issues/586
|
||||
// swiftlint:disable type_body_length implicitly_unwrapped_optional force_try
|
||||
class RewindRescanTests: XCTestCase {
|
||||
// TODO: Parameterize this from environment?
|
||||
// TODO: [#715] Parameterize this from environment, https://github.com/zcash/ZcashLightClientKit/issues/715?
|
||||
// swiftlint:disable:next line_length
|
||||
let 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"
|
||||
|
||||
// TODO: Parameterize this from environment
|
||||
// TODO: [#715] Parameterize this from environment, https://github.com/zcash/ZcashLightClientKit/issues/715
|
||||
let testRecipientAddress = try! Recipient("zs17mg40levjezevuhdp5pqrd52zere7r7vrjgdwn5sj4xsqtm20euwahv9anxmwr3y3kmwuz8k55a", network: .mainnet)
|
||||
let sendAmount: Int64 = 1000
|
||||
let defaultLatestHeight: BlockHeight = 663175
|
||||
|
@ -142,7 +142,7 @@ class RewindRescanTests: XCTestCase {
|
|||
|
||||
try await withCheckedThrowingContinuation { continuation in
|
||||
do {
|
||||
try coordinator.sync(completion: { synchronizer in
|
||||
try coordinator.sync(completion: { _ in
|
||||
firstSyncExpectation.fulfill()
|
||||
continuation.resume()
|
||||
}, error: self.handleError)
|
||||
|
@ -178,7 +178,7 @@ class RewindRescanTests: XCTestCase {
|
|||
|
||||
try await withCheckedThrowingContinuation { continuation in
|
||||
do {
|
||||
try coordinator.sync(completion: { synchronizer in
|
||||
try coordinator.sync(completion: { _ in
|
||||
secondScanExpectation.fulfill()
|
||||
continuation.resume()
|
||||
}, error: self.handleError)
|
||||
|
@ -273,7 +273,7 @@ class RewindRescanTests: XCTestCase {
|
|||
|
||||
try await withCheckedThrowingContinuation { continuation in
|
||||
do {
|
||||
try coordinator.sync(completion: { synchronizer in
|
||||
try coordinator.sync(completion: { _ in
|
||||
firstSyncExpectation.fulfill()
|
||||
continuation.resume()
|
||||
}, error: self.handleError)
|
||||
|
@ -410,7 +410,7 @@ class RewindRescanTests: XCTestCase {
|
|||
|
||||
try await withCheckedThrowingContinuation { continuation in
|
||||
do {
|
||||
try coordinator.sync(completion: { synchronizer in
|
||||
try coordinator.sync(completion: { _ in
|
||||
confirmExpectation.fulfill()
|
||||
continuation.resume()
|
||||
}, error: self.handleError)
|
||||
|
|
|
@ -9,17 +9,19 @@
|
|||
import XCTest
|
||||
@testable import TestUtils
|
||||
@testable import ZcashLightClientKit
|
||||
// FIXME: disabled until https://github.com/zcash/ZcashLightClientKit/issues/587 fixed
|
||||
|
||||
// FIXME: [#587] disabled until https://github.com/zcash/ZcashLightClientKit/issues/587 fixed
|
||||
class ShieldFundsTests: XCTestCase {
|
||||
// TODO: Parameterize this from environment?
|
||||
// TODO: [#715] Parameterize this from environment, https://github.com/zcash/ZcashLightClientKit/issues/715?
|
||||
// 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"
|
||||
|
||||
// TODO: Parameterize this from environment
|
||||
// TODO: [#715] Parameterize this from environment, https://github.com/zcash/ZcashLightClientKit/issues/715
|
||||
let testRecipientAddress = "zs17mg40levjezevuhdp5pqrd52zere7r7vrjgdwn5sj4xsqtm20euwahv9anxmwr3y3kmwuz8k55a"
|
||||
|
||||
let sendAmount = Zatoshi(1000)
|
||||
var birthday: BlockHeight = 1631000
|
||||
// swiftlint:disable:next implicitly_unwrapped_optional
|
||||
var coordinator: TestCoordinator!
|
||||
var syncedExpectation = XCTestExpectation(description: "synced")
|
||||
var sentTransactionExpectation = XCTestExpectation(description: "sent")
|
||||
|
@ -83,6 +85,7 @@ class ShieldFundsTests: XCTestCase {
|
|||
/// 15. sync up to the new chain tip
|
||||
/// verify that the shielded transactions are confirmed
|
||||
///
|
||||
// swiftlint:disable:next cyclomatic_complexity
|
||||
func testShieldFunds() async throws {
|
||||
// 1. load the dataset
|
||||
try coordinator.service.useDataset(from: "https://raw.githubusercontent.com/zcash-hackworks/darksidewalletd-test-data/master/shield-funds/1631000.txt")
|
||||
|
@ -99,15 +102,16 @@ class ShieldFundsTests: XCTestCase {
|
|||
|
||||
var initialTransparentBalance: WalletBalance = try await coordinator.synchronizer.getTransparentBalance(accountIndex: 0)
|
||||
|
||||
let utxo = try GetAddressUtxosReply(jsonString: """
|
||||
{
|
||||
"txid": "3md9M0OOpPBsF02Rp2b7CJZMpv093bjLuSCIG1RPioU=",
|
||||
"script": "dqkU1mkF+eETNMCYyJs0OZcygn0KDi+IrA==",
|
||||
"valueZat": "10000",
|
||||
"height": "1631177",
|
||||
"address": "t1dRJRY7GmyeykJnMH38mdQoaZtFhn1QmGz"
|
||||
}
|
||||
""")
|
||||
let utxo = try GetAddressUtxosReply(jsonString:
|
||||
"""
|
||||
{
|
||||
"txid": "3md9M0OOpPBsF02Rp2b7CJZMpv093bjLuSCIG1RPioU=",
|
||||
"script": "dqkU1mkF+eETNMCYyJs0OZcygn0KDi+IrA==",
|
||||
"valueZat": "10000",
|
||||
"height": "1631177",
|
||||
"address": "t1dRJRY7GmyeykJnMH38mdQoaZtFhn1QmGz"
|
||||
}
|
||||
""")
|
||||
// 2. applyStaged to `utxoHeight - 1`
|
||||
try coordinator.service.applyStaged(nextLatestHeight: utxoHeight - 1)
|
||||
sleep(2)
|
||||
|
@ -160,7 +164,7 @@ class ShieldFundsTests: XCTestCase {
|
|||
// 6. Sync and find the UXTO on chain.
|
||||
try await withCheckedThrowingContinuation { continuation in
|
||||
do {
|
||||
try coordinator.sync(completion: { synchronizer in
|
||||
try coordinator.sync(completion: { _ in
|
||||
shouldContinue = true
|
||||
tFundsDetectionExpectation.fulfill()
|
||||
continuation.resume()
|
||||
|
@ -190,7 +194,7 @@ class ShieldFundsTests: XCTestCase {
|
|||
// 8. sync up to chain tip.
|
||||
try await withCheckedThrowingContinuation { continuation in
|
||||
do {
|
||||
try coordinator.sync(completion: { synchronizer in
|
||||
try coordinator.sync(completion: { _ in
|
||||
shouldContinue = true
|
||||
tFundsConfirmationSyncExpectation.fulfill()
|
||||
continuation.resume()
|
||||
|
@ -238,8 +242,10 @@ class ShieldFundsTests: XCTestCase {
|
|||
// when funds are shielded the UTXOs should be marked as spend and not shown on the balance.
|
||||
// now balance should be zero shielded, zero transaparent.
|
||||
// verify that the balance has been marked as spent regardless of confirmation
|
||||
XCTAssertEqual(postShieldingBalance.verified, Zatoshi(10000)) //FIXME: this should be zero
|
||||
XCTAssertEqual(postShieldingBalance.total, Zatoshi(10000)) //FIXME: this should be zero
|
||||
// FIXME: [#720] this should be zero, https://github.com/zcash/ZcashLightClientKit/issues/720
|
||||
XCTAssertEqual(postShieldingBalance.verified, Zatoshi(10000))
|
||||
// FIXME: [#720] this should be zero, https://github.com/zcash/ZcashLightClientKit/issues/720
|
||||
XCTAssertEqual(postShieldingBalance.total, Zatoshi(10000))
|
||||
XCTAssertEqual(coordinator.synchronizer.getShieldedBalance(), .zero)
|
||||
|
||||
// 10. clear the UTXO from darksidewalletd's cache
|
||||
|
@ -269,7 +275,7 @@ class ShieldFundsTests: XCTestCase {
|
|||
shouldContinue = false
|
||||
try await withCheckedThrowingContinuation { continuation in
|
||||
do {
|
||||
try coordinator.sync(completion: { synchronizer in
|
||||
try coordinator.sync(completion: { _ in
|
||||
shouldContinue = true
|
||||
postShieldSyncExpectation.fulfill()
|
||||
continuation.resume()
|
||||
|
@ -288,9 +294,12 @@ class ShieldFundsTests: XCTestCase {
|
|||
// Fees at the time of writing the tests are 1000 zatoshi as defined on ZIP-313
|
||||
let postShieldingShieldedBalance = try await coordinator.synchronizer.getTransparentBalance(accountIndex: 0)
|
||||
|
||||
XCTAssertEqual(postShieldingShieldedBalance.total, Zatoshi(10000)) //FIXME: this should be zero
|
||||
XCTAssertEqual(postShieldingShieldedBalance.verified, Zatoshi(10000)) //FIXME: this should be zero
|
||||
XCTAssertEqual(coordinator.synchronizer.getShieldedBalance(), .zero) //FIXME: this should be 9000
|
||||
// FIXME: [#720] this should be zero, https://github.com/zcash/ZcashLightClientKit/issues/720
|
||||
XCTAssertEqual(postShieldingShieldedBalance.total, Zatoshi(10000))
|
||||
// FIXME: [#720] this should be zero, https://github.com/zcash/ZcashLightClientKit/issues/720
|
||||
XCTAssertEqual(postShieldingShieldedBalance.verified, Zatoshi(10000))
|
||||
// FIXME: [#720] this should be 9000, https://github.com/zcash/ZcashLightClientKit/issues/720
|
||||
XCTAssertEqual(coordinator.synchronizer.getShieldedBalance(), .zero)
|
||||
|
||||
// 14. proceed confirm the shielded funds by staging ten more blocks
|
||||
try coordinator.service.applyStaged(nextLatestHeight: utxoHeight + 10 + 1 + 10)
|
||||
|
@ -303,7 +312,7 @@ class ShieldFundsTests: XCTestCase {
|
|||
// 15. sync up to the new chain tip
|
||||
try await withCheckedThrowingContinuation { continuation in
|
||||
do {
|
||||
try coordinator.sync(completion: { synchronizer in
|
||||
try coordinator.sync(completion: { _ in
|
||||
shouldContinue = true
|
||||
confirmationExpectation.fulfill()
|
||||
continuation.resume()
|
||||
|
@ -319,7 +328,9 @@ class ShieldFundsTests: XCTestCase {
|
|||
guard shouldContinue else { return }
|
||||
|
||||
// verify that there's a confirmed transaction that's the shielding transaction
|
||||
let clearedTransaction = coordinator.synchronizer.clearedTransactions.first(where: { $0.rawTransactionId == shieldingPendingTx?.rawTransactionId })
|
||||
let clearedTransaction = coordinator.synchronizer.clearedTransactions.first(
|
||||
where: { $0.rawTransactionId == shieldingPendingTx?.rawTransactionId }
|
||||
)
|
||||
|
||||
XCTAssertNotNil(clearedTransaction)
|
||||
|
||||
|
@ -327,7 +338,6 @@ class ShieldFundsTests: XCTestCase {
|
|||
let postShieldingConfirmationShieldedBalance = try await coordinator.synchronizer.getTransparentBalance(accountIndex: 0)
|
||||
XCTAssertEqual(postShieldingConfirmationShieldedBalance.total, .zero)
|
||||
XCTAssertEqual(postShieldingConfirmationShieldedBalance.verified, .zero)
|
||||
|
||||
}
|
||||
|
||||
func handleError(_ error: Error?) {
|
||||
|
@ -338,6 +348,4 @@ class ShieldFundsTests: XCTestCase {
|
|||
}
|
||||
XCTFail("Failed with error: \(testError)")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -12,11 +12,11 @@ import Combine
|
|||
|
||||
// swiftlint:disable implicitly_unwrapped_optional
|
||||
class SychronizerDarksideTests: XCTestCase {
|
||||
// TODO: Parameterize this from environment?
|
||||
// TODO: [#715] Parameterize this from environment, https://github.com/zcash/ZcashLightClientKit/issues/715?
|
||||
// swiftlint:disable:next line_length
|
||||
let 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"
|
||||
|
||||
// TODO: Parameterize this from environment
|
||||
// TODO: [#715] Parameterize this from environment, https://github.com/zcash/ZcashLightClientKit/issues/715
|
||||
let testRecipientAddress = "zs17mg40levjezevuhdp5pqrd52zere7r7vrjgdwn5sj4xsqtm20euwahv9anxmwr3y3kmwuz8k55a"
|
||||
let sendAmount: Int64 = 1000
|
||||
let defaultLatestHeight: BlockHeight = 663175
|
||||
|
@ -133,10 +133,9 @@ class SychronizerDarksideTests: XCTestCase {
|
|||
}
|
||||
|
||||
func testLastStates() throws {
|
||||
var disposeBag: [AnyCancellable] = []
|
||||
|
||||
var disposeBag = [AnyCancellable]()
|
||||
|
||||
var states = [SDKSynchronizer.SynchronizerState]()
|
||||
var states: [SDKSynchronizer.SynchronizerState] = []
|
||||
|
||||
try FakeChainBuilder.buildChain(darksideWallet: self.coordinator.service, branchID: branchID, chainName: chainName)
|
||||
let receivedTxHeight: BlockHeight = 663188
|
||||
|
@ -236,7 +235,6 @@ class SychronizerDarksideTests: XCTestCase {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
extension Zatoshi: CustomDebugStringConvertible {
|
||||
public var debugDescription: String {
|
||||
"Zatoshi(\(self.amount))"
|
||||
|
|
|
@ -9,14 +9,13 @@ import XCTest
|
|||
@testable import TestUtils
|
||||
@testable import ZcashLightClientKit
|
||||
|
||||
// swiftlint:disable implicitly_unwrapped_optional force_unwrapping type_body_length
|
||||
// swiftlint:disable implicitly_unwrapped_optional force_unwrapping
|
||||
final class SynchronizerTests: XCTestCase {
|
||||
|
||||
// TODO: Parameterize this from environment?
|
||||
// TODO: [#715] Parameterize this from environment, https://github.com/zcash/ZcashLightClientKit/issues/715?
|
||||
// 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"
|
||||
|
||||
// TODO: Parameterize this from environment
|
||||
// TODO: [#715] Parameterize this from environment, https://github.com/zcash/ZcashLightClientKit/issues/715
|
||||
let testRecipientAddress = "zs17mg40levjezevuhdp5pqrd52zere7r7vrjgdwn5sj4xsqtm20euwahv9anxmwr3y3kmwuz8k55a"
|
||||
|
||||
let sendAmount = Zatoshi(1000)
|
||||
|
@ -36,7 +35,7 @@ final class SynchronizerTests: XCTestCase {
|
|||
try super.setUpWithError()
|
||||
self.coordinator = try TestCoordinator(
|
||||
seed: self.seedPhrase,
|
||||
walletBirthday:self.birthday + 50, //don't use an exact birthday, users never do.
|
||||
walletBirthday: self.birthday + 50, // don't use an exact birthday, users never do.
|
||||
channelProvider: ChannelProvider(),
|
||||
network: self.network
|
||||
)
|
||||
|
@ -124,6 +123,5 @@ final class SynchronizerTests: XCTestCase {
|
|||
|
||||
func hookToReOrgNotification() {
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(handleReorg(_:)), name: .blockProcessorHandledReOrg, object: nil)
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -62,11 +62,10 @@ class TransactionEnhancementTests: XCTestCase {
|
|||
let ufvks = [
|
||||
try DerivationTool(networkType: network.networkType)
|
||||
.deriveUnifiedSpendingKey(seed: TestSeed().seed(), accountIndex: 0)
|
||||
.map{
|
||||
.map {
|
||||
try DerivationTool(networkType: network.networkType)
|
||||
.deriveUnifiedFullViewingKey(from: $0)
|
||||
}
|
||||
|
||||
]
|
||||
do {
|
||||
try rustBackend.initAccountsTable(
|
||||
|
@ -75,7 +74,7 @@ class TransactionEnhancementTests: XCTestCase {
|
|||
networkType: network.networkType
|
||||
)
|
||||
} catch {
|
||||
XCTFail("Failed to init accounts table error: " + String(describing: rustBackend.getLastError()))
|
||||
XCTFail("Failed to init accounts table error: \(String(describing: rustBackend.getLastError()))")
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
@ -9,12 +9,14 @@ import XCTest
|
|||
@testable import TestUtils
|
||||
@testable import ZcashLightClientKit
|
||||
|
||||
// swiftlint:disable force_unwrapping implicitly_unwrapped_optional
|
||||
// swiftlint:disable force_unwrapping implicitly_unwrapped_optional force_try
|
||||
class Z2TReceiveTests: XCTestCase {
|
||||
// TODO: [#715] Parameterize this from environment, https://github.com/zcash/ZcashLightClientKit/issues/715?
|
||||
// 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" // TODO: Parameterize this from environment?
|
||||
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"
|
||||
|
||||
let testRecipientAddress = "t1dRJRY7GmyeykJnMH38mdQoaZtFhn1QmGz" // TODO: Parameterize this from environment
|
||||
// TODO: [#715] Parameterize this from environment, https://github.com/zcash/ZcashLightClientKit/issues/715
|
||||
let testRecipientAddress = "t1dRJRY7GmyeykJnMH38mdQoaZtFhn1QmGz"
|
||||
|
||||
let sendAmount: Int64 = 1000
|
||||
var birthday: BlockHeight = 663150
|
||||
|
@ -85,7 +87,7 @@ class Z2TReceiveTests: XCTestCase {
|
|||
*/
|
||||
try await withCheckedThrowingContinuation { continuation in
|
||||
do {
|
||||
try coordinator.sync(completion: { synchronizer in
|
||||
try coordinator.sync(completion: { _ in
|
||||
preTxExpectation.fulfill()
|
||||
continuation.resume()
|
||||
}, error: self.handleError)
|
||||
|
@ -101,7 +103,7 @@ class Z2TReceiveTests: XCTestCase {
|
|||
4. create transaction
|
||||
*/
|
||||
do {
|
||||
let _ = try await coordinator.synchronizer.sendToAddress(
|
||||
_ = try await coordinator.synchronizer.sendToAddress(
|
||||
spendingKey: coordinator.spendingKeys!.first!,
|
||||
zatoshi: sendAmount,
|
||||
toAddress: try! Recipient(testRecipientAddress, network: self.network.networkType),
|
||||
|
@ -114,6 +116,7 @@ class Z2TReceiveTests: XCTestCase {
|
|||
if case let SynchronizerError.generalError(message) = error {
|
||||
XCTAssertEqual(message, "Memos can't be sent to transparent addresses.")
|
||||
} else {
|
||||
// swiftlint:disable:next line_length
|
||||
XCTFail("expected SynchronizerError.genericError(\"Memos can't be sent to transparent addresses.\") but received \(error.localizedDescription)")
|
||||
}
|
||||
return
|
||||
|
@ -138,7 +141,7 @@ class Z2TReceiveTests: XCTestCase {
|
|||
*/
|
||||
try await withCheckedThrowingContinuation { continuation in
|
||||
do {
|
||||
try coordinator.sync(completion: { synchronizer in
|
||||
try coordinator.sync(completion: { _ in
|
||||
preTxExpectation.fulfill()
|
||||
continuation.resume()
|
||||
}, error: self.handleError)
|
||||
|
|
|
@ -19,6 +19,7 @@ class BlockScanTests: XCTestCase {
|
|||
var dataDbURL: URL!
|
||||
var spendParamsURL: URL!
|
||||
var outputParamsURL: URL!
|
||||
// swiftlint:disable:next line_length
|
||||
var saplingExtendedKey = SaplingExtendedFullViewingKey(validatedEncoding: "zxviewtestsapling1qw88ayg8qqqqpqyhg7jnh9mlldejfqwu46pm40ruwstd8znq3v3l4hjf33qcu2a5e36katshcfhcxhzgyfugj2lkhmt40j45cv38rv3frnghzkxcx73k7m7afw9j7ujk7nm4dx5mv02r26umxqgar7v3x390w2h3crqqgjsjly7jy4vtwzrmustm5yudpgcydw7x78awca8wqjvkqj8p8e3ykt7lrgd7xf92fsfqjs5vegfsja4ekzpfh5vtccgvs5747xqm6qflmtqpr8s9u")
|
||||
|
||||
var walletBirthDay = Checkpoint.birthday(
|
||||
|
@ -138,7 +139,6 @@ class BlockScanTests: XCTestCase {
|
|||
.deriveUnifiedSpendingKey(seed: Array(seed.utf8), accountIndex: 0)
|
||||
.map { try derivationTool.deriveUnifiedFullViewingKey(from: $0) }
|
||||
|
||||
|
||||
do {
|
||||
try self.rustWelding.initAccountsTable(
|
||||
dbData: self.dataDbURL,
|
||||
|
|
|
@ -168,7 +168,7 @@ class CompactBlockProcessorTests: XCTestCase {
|
|||
expectedSyncRanges = SyncRanges(
|
||||
latestBlockHeight: latestBlockchainHeight,
|
||||
downloadedButUnscannedRange: 1...latestDownloadedHeight,
|
||||
downloadAndScanRange: latestDownloadedHeight+1...latestBlockchainHeight,
|
||||
downloadAndScanRange: latestDownloadedHeight + 1...latestBlockchainHeight,
|
||||
enhanceRange: processorConfig.walletBirthday...latestBlockchainHeight,
|
||||
fetchUTXORange: processorConfig.walletBirthday...latestBlockchainHeight
|
||||
)
|
||||
|
@ -196,7 +196,7 @@ class CompactBlockProcessorTests: XCTestCase {
|
|||
expectedSyncRanges = SyncRanges(
|
||||
latestBlockHeight: latestBlockchainHeight,
|
||||
downloadedButUnscannedRange: 1...latestDownloadedHeight,
|
||||
downloadAndScanRange: latestDownloadedHeight+1...latestBlockchainHeight,
|
||||
downloadAndScanRange: latestDownloadedHeight + 1...latestBlockchainHeight,
|
||||
enhanceRange: processorConfig.walletBirthday...latestBlockchainHeight,
|
||||
fetchUTXORange: processorConfig.walletBirthday...latestBlockchainHeight
|
||||
)
|
||||
|
|
|
@ -47,7 +47,7 @@ class CompactBlockReorgTests: XCTestCase {
|
|||
|
||||
guard case .success = try ZcashRustBackend.initDataDb(dbData: processorConfig.dataDb, seed: nil, networkType: .testnet) else {
|
||||
XCTFail("initDataDb failed. Expected Success but got .seedRequired")
|
||||
return
|
||||
return
|
||||
}
|
||||
|
||||
let storage = CompactBlockStorage.init(connectionProvider: SimpleConnectionProvider(path: processorConfig.cacheDb.absoluteString))
|
||||
|
|
|
@ -25,7 +25,7 @@ class LightWalletServiceTests: XCTestCase {
|
|||
service = LightWalletGRPCService(endpoint: LightWalletEndpointBuilder.eccTestnet)
|
||||
}
|
||||
|
||||
/// FIXME: check whether this test is still valid on in memory lwd implementation
|
||||
// FIXME: [#721] check whether this test is still valid on in memory lwd implementation, https://github.com/zcash/ZcashLightClientKit/issues/721
|
||||
// func testFailure() {
|
||||
//
|
||||
// let expect = XCTestExpectation(description: self.description)
|
||||
|
|
|
@ -287,7 +287,6 @@ class BlockBatchValidationTests: XCTestCase {
|
|||
let mockRust = MockRustBackend.self
|
||||
mockRust.consensusBranchID = 0xd34db4d
|
||||
|
||||
|
||||
var nextBatch: CompactBlockProcessor.NextState?
|
||||
do {
|
||||
nextBatch = try await CompactBlockProcessor.NextStateHelper.nextStateAsync(
|
||||
|
@ -303,7 +302,7 @@ class BlockBatchValidationTests: XCTestCase {
|
|||
XCTFail("this shouldn't happen: \(error)")
|
||||
}
|
||||
|
||||
guard let _ = nextBatch else {
|
||||
guard nextBatch != nil else {
|
||||
XCTFail("result should not be nil")
|
||||
return
|
||||
}
|
||||
|
@ -311,7 +310,7 @@ class BlockBatchValidationTests: XCTestCase {
|
|||
XCTAssertTrue(
|
||||
{
|
||||
switch (nextBatch, expectedResult) {
|
||||
case (let .wait(latestHeight, latestDownloadHeight), let .wait(expectedLatestHeight, exectedLatestDownloadHeight)):
|
||||
case let (.wait(latestHeight, latestDownloadHeight), .wait(expectedLatestHeight, exectedLatestDownloadHeight)):
|
||||
return latestHeight == expectedLatestHeight && latestDownloadHeight == exectedLatestDownloadHeight
|
||||
default:
|
||||
return false
|
||||
|
@ -334,7 +333,7 @@ class BlockBatchValidationTests: XCTestCase {
|
|||
let ranges = SyncRanges(
|
||||
latestBlockHeight: expectedLatestHeight,
|
||||
downloadedButUnscannedRange: nil,
|
||||
downloadAndScanRange: expectedStoreLatestHeight+1...expectedLatestHeight,
|
||||
downloadAndScanRange: expectedStoreLatestHeight + 1...expectedLatestHeight,
|
||||
enhanceRange: walletBirthday...expectedLatestHeight,
|
||||
fetchUTXORange: walletBirthday...expectedLatestHeight
|
||||
)
|
||||
|
@ -392,15 +391,15 @@ class BlockBatchValidationTests: XCTestCase {
|
|||
XCTFail("this shouldn't happen: \(error)")
|
||||
}
|
||||
|
||||
guard let _ = nextBatch else {
|
||||
guard nextBatch != nil else {
|
||||
XCTFail("result should not be nil")
|
||||
return
|
||||
}
|
||||
|
||||
XCTAssertTrue(
|
||||
{
|
||||
switch (nextBatch, expectedResult) {
|
||||
case (.processNewBlocks(let ranges), .processNewBlocks(let expectedRanges)):
|
||||
switch (nextBatch, expectedResult) {
|
||||
case let (.processNewBlocks(ranges), .processNewBlocks(expectedRanges)):
|
||||
return ranges == expectedRanges
|
||||
default:
|
||||
return false
|
||||
|
@ -477,16 +476,15 @@ class BlockBatchValidationTests: XCTestCase {
|
|||
XCTFail("this shouldn't happen: \(error)")
|
||||
}
|
||||
|
||||
guard let _ = nextBatch else {
|
||||
guard nextBatch != nil else {
|
||||
XCTFail("result should not be nil")
|
||||
return
|
||||
}
|
||||
|
||||
XCTAssertTrue(
|
||||
{
|
||||
|
||||
switch (nextBatch, expectedResult) {
|
||||
case (.finishProcessing(let height), .finishProcessing(let expectedHeight)):
|
||||
case let (.finishProcessing(height), .finishProcessing(expectedHeight)):
|
||||
return height == expectedHeight
|
||||
default:
|
||||
return false
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
// Created by Michal Fousek on 15.12.2022.
|
||||
//
|
||||
|
||||
|
||||
import XCTest
|
||||
@testable import TestUtils
|
||||
@testable import ZcashLightClientKit
|
||||
|
|
|
@ -4,15 +4,18 @@
|
|||
//
|
||||
// Created by Francisco Gindre on 10/9/20.
|
||||
//
|
||||
//swiftlint:disable force_unwrapping
|
||||
|
||||
import XCTest
|
||||
@testable import ZcashLightClientKit
|
||||
|
||||
// swiftlint:disable line_length force_unwrapping
|
||||
class DerivationToolMainnetTests: XCTestCase {
|
||||
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" //TODO: Parameterize this from environment?
|
||||
var seedData: Data = Data(base64Encoded: "9VDVOZZZOWWHpZtq1Ebridp3Qeux5C+HwiRR0g7Oi7HgnMs8Gfln83+/Q1NnvClcaSwM4ADFL1uZHxypEWlWXg==")!
|
||||
// TODO: [#715] Parameterize this from environment, https://github.com/zcash/ZcashLightClientKit/issues/715
|
||||
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"
|
||||
var seedData = Data(base64Encoded: "9VDVOZZZOWWHpZtq1Ebridp3Qeux5C+HwiRR0g7Oi7HgnMs8Gfln83+/Q1NnvClcaSwM4ADFL1uZHxypEWlWXg==")!
|
||||
|
||||
let testRecipientAddress = UnifiedAddress(validatedEncoding: "u1l9f0l4348negsncgr9pxd9d3qaxagmqv3lnexcplmufpq7muffvfaue6ksevfvd7wrz7xrvn95rc5zjtn7ugkmgh5rnxswmcj30y0pw52pn0zjvy38rn2esfgve64rj5pcmazxgpyuj") //TODO: Parameterize this from environment
|
||||
// TODO: [#715] Parameterize this from environment, https://github.com/zcash/ZcashLightClientKit/issues/715
|
||||
let testRecipientAddress = UnifiedAddress(validatedEncoding: "u1l9f0l4348negsncgr9pxd9d3qaxagmqv3lnexcplmufpq7muffvfaue6ksevfvd7wrz7xrvn95rc5zjtn7ugkmgh5rnxswmcj30y0pw52pn0zjvy38rn2esfgve64rj5pcmazxgpyuj")
|
||||
|
||||
let expectedSpendingKey = UnifiedSpendingKey(
|
||||
network: .mainnet,
|
||||
|
@ -50,7 +53,6 @@ class DerivationToolMainnetTests: XCTestCase {
|
|||
let spendingKey = try derivationTool.deriveUnifiedSpendingKey(seed: seedBytes, accountIndex: 0)
|
||||
|
||||
XCTAssertEqual(expectedSpendingKey, spendingKey)
|
||||
|
||||
}
|
||||
|
||||
func testDeriveUnifiedSpendingKeyFromSeed() throws {
|
||||
|
@ -81,7 +83,6 @@ class DerivationToolMainnetTests: XCTestCase {
|
|||
seed: [UInt8](seedData),
|
||||
accountIndex: $0
|
||||
)
|
||||
|
||||
})
|
||||
.map {
|
||||
try derivationTool.deriveUnifiedFullViewingKey(
|
||||
|
@ -104,7 +105,7 @@ class DerivationToolMainnetTests: XCTestCase {
|
|||
|
||||
XCTAssertFalse(derivationTool.isValidSaplingExtendedSpendingKey(wrongSpendingKey))
|
||||
}
|
||||
// TODO: Address encoding does not catch this test https://github.com/zcash/ZcashLightClientKit/issues/509
|
||||
// TODO: [#509] Address encoding does not catch this test https://github.com/zcash/ZcashLightClientKit/issues/509
|
||||
// func testSpendingKeyValidationThrowsWhenWrongNetwork() throws {
|
||||
// XCTAssertThrowsError(try derivationTool.isValidExtendedSpendingKey("secret-extended-key-test1qdxykmuaqqqqpqqg3x5c02p4rhw0rtszr8ln4xl7g6wg6qzsqgn445qsu3cq4vd6lk8xce3d4jw7s8ln5yjp6fqv2g0nzue2hc0kv5t004vklvlenncscq9flwh5vf5qnv0hnync72n7gjn70u47765v3kyrxytx50g730svvmhhlazn5rj8mshh470fkrmzg4xarhrqlygg8f486307ujhndwhsw2h7ddzf89k3534aeu0ypz2tjgrzlcqtat380vhe8awm03f58cqe49swv"))
|
||||
// }
|
||||
|
|
|
@ -9,10 +9,16 @@
|
|||
import XCTest
|
||||
@testable import ZcashLightClientKit
|
||||
|
||||
// swiftlint:disable line_length force_unwrapping
|
||||
class DerivationToolTestnetTests: XCTestCase {
|
||||
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" //TODO: Parameterize this from environment?
|
||||
var seedData: Data = Data(base64Encoded: "9VDVOZZZOWWHpZtq1Ebridp3Qeux5C+HwiRR0g7Oi7HgnMs8Gfln83+/Q1NnvClcaSwM4ADFL1uZHxypEWlWXg==")!
|
||||
let testRecipientAddress = UnifiedAddress(validatedEncoding: "utest1uqmec4a2njqz2z2rwppchsd06qe7a0jh4jmsqr0yy99m9er9646zlxunf3v8qr0hncgv86e8a62vxy0qa32qzetmj8s57yudmyx9zav6f52nurclsqjkqtjtpz6vg679p6wkczpl2wu") //TODO: Parameterize this from environment
|
||||
// TODO: [#715] Parameterize this from environment, https://github.com/zcash/ZcashLightClientKit/issues/715
|
||||
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"
|
||||
|
||||
// TODO: [#715] Parameterize this from environment, https://github.com/zcash/ZcashLightClientKit/issues/715
|
||||
var seedData = Data(base64Encoded: "9VDVOZZZOWWHpZtq1Ebridp3Qeux5C+HwiRR0g7Oi7HgnMs8Gfln83+/Q1NnvClcaSwM4ADFL1uZHxypEWlWXg==")!
|
||||
|
||||
// TODO: [#715] Parameterize this from environment, https://github.com/zcash/ZcashLightClientKit/issues/715
|
||||
let testRecipientAddress = UnifiedAddress(validatedEncoding: "utest1uqmec4a2njqz2z2rwppchsd06qe7a0jh4jmsqr0yy99m9er9646zlxunf3v8qr0hncgv86e8a62vxy0qa32qzetmj8s57yudmyx9zav6f52nurclsqjkqtjtpz6vg679p6wkczpl2wu")
|
||||
|
||||
let expectedSpendingKey = UnifiedSpendingKey(
|
||||
network: .testnet,
|
||||
|
@ -52,7 +58,6 @@ class DerivationToolTestnetTests: XCTestCase {
|
|||
let spendingKey = try derivationTool.deriveUnifiedSpendingKey(seed: seedBytes, accountIndex: 0)
|
||||
|
||||
XCTAssertEqual(expectedSpendingKey, spendingKey)
|
||||
|
||||
}
|
||||
|
||||
func testDeriveUnifiedSpendingKeyFromSeed() throws {
|
||||
|
@ -70,7 +75,7 @@ class DerivationToolTestnetTests: XCTestCase {
|
|||
}
|
||||
|
||||
func testIsValidViewingKey() throws {
|
||||
XCTAssertTrue( DerivationTool.rustwelding.isValidSaplingExtendedFullViewingKey("zxviewtestsapling1qdxykmuaqqqqpqqg3x5c02p4rhw0rtszr8ln4xl7g6wg6qzsqgn445qsu3cq4vd6l5smlqrckkl2x5rnrauzc4gp665q3zyw0qf2sfdsx5wpp832htfavqk72uchuuvq2dpmgk8jfaza5t5l56u66fpx0sr8ewp9s3wj2txavmhhlazn5rj8mshh470fkrmzg4xarhrqlygg8f486307ujhndwhsw2h7ddzf89k3534aeu0ypz2tjgrzlcqtat380vhe8awm03f58cqgegsaj",networkType: .testnet))
|
||||
XCTAssertTrue( DerivationTool.rustwelding.isValidSaplingExtendedFullViewingKey("zxviewtestsapling1qdxykmuaqqqqpqqg3x5c02p4rhw0rtszr8ln4xl7g6wg6qzsqgn445qsu3cq4vd6l5smlqrckkl2x5rnrauzc4gp665q3zyw0qf2sfdsx5wpp832htfavqk72uchuuvq2dpmgk8jfaza5t5l56u66fpx0sr8ewp9s3wj2txavmhhlazn5rj8mshh470fkrmzg4xarhrqlygg8f486307ujhndwhsw2h7ddzf89k3534aeu0ypz2tjgrzlcqtat380vhe8awm03f58cqgegsaj", networkType: .testnet))
|
||||
|
||||
XCTAssertFalse( DerivationTool.rustwelding.isValidSaplingExtendedFullViewingKey("zxviews1q0dm7hkzky5skvnd9ldwj2u8fz2ry94s5q8p9lyp3j96yckudmp087d2jr2rnfuvjp7f56v78vpe658vljjddj7s645q399jd7", networkType: .testnet))
|
||||
}
|
||||
|
@ -83,7 +88,6 @@ class DerivationToolTestnetTests: XCTestCase {
|
|||
seed: [UInt8](seedData),
|
||||
accountIndex: $0
|
||||
)
|
||||
|
||||
})
|
||||
.map {
|
||||
try derivationTool.deriveUnifiedFullViewingKey(
|
||||
|
@ -106,9 +110,8 @@ class DerivationToolTestnetTests: XCTestCase {
|
|||
|
||||
XCTAssertFalse(derivationTool.isValidSaplingExtendedSpendingKey(wrongSpendingKey))
|
||||
}
|
||||
// TODO: Address encoding does not catch this test https://github.com/zcash/ZcashLightClientKit/issues/509
|
||||
// TODO: [#509] Address encoding does not catch this test https://github.com/zcash/ZcashLightClientKit/issues/509
|
||||
// func testSpendingKeyValidationThrowsWhenWrongNetwork() throws {
|
||||
// XCTAssertThrowsError(try derivationTool.isValidExtendedSpendingKey("secret-extended-key-test1qdxykmuaqqqqpqqg3x5c02p4rhw0rtszr8ln4xl7g6wg6qzsqgn445qsu3cq4vd6lk8xce3d4jw7s8ln5yjp6fqv2g0nzue2hc0kv5t004vklvlenncscq9flwh5vf5qnv0hnync72n7gjn70u47765v3kyrxytx50g730svvmhhlazn5rj8mshh470fkrmzg4xarhrqlygg8f486307ujhndwhsw2h7ddzf89k3534aeu0ypz2tjgrzlcqtat380vhe8awm03f58cqe49swv"))
|
||||
// }
|
||||
}
|
||||
|
||||
|
|
|
@ -8,10 +8,8 @@
|
|||
import XCTest
|
||||
import ZcashLightClientKit
|
||||
class ErrorLocalizationTests: XCTestCase {
|
||||
|
||||
func testLocalizedError() throws {
|
||||
let sychronizerError = SynchronizerError.networkTimeout as Error
|
||||
XCTAssertEqual(sychronizerError.localizedDescription, "Network Timeout. Please check Internet connection")
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -9,8 +9,8 @@
|
|||
import XCTest
|
||||
@testable import ZcashLightClientKit
|
||||
|
||||
// swiftlint:disable implicitly_unwrapped_optional
|
||||
class InternalSyncProgressTests: XCTestCase {
|
||||
|
||||
var storage: InternalSyncProgressStorage!
|
||||
var internalSyncProgress: InternalSyncProgress!
|
||||
|
||||
|
|
|
@ -22,7 +22,10 @@ class MemoTests: XCTestCase {
|
|||
*/
|
||||
func testMemoLength() throws {
|
||||
XCTAssertEqual(validMemoData.count, 512)
|
||||
XCTAssertEqual(validMemoData.asZcashTransactionMemo()!.trimmingCharacters(in: .controlCharacters).count, Self.validMemoDataExpectedString.count)
|
||||
XCTAssertEqual(
|
||||
validMemoData.asZcashTransactionMemo()!.trimmingCharacters(in: .controlCharacters).count,
|
||||
Self.validMemoDataExpectedString.count
|
||||
)
|
||||
}
|
||||
/**
|
||||
Verify support for common unicode characters
|
||||
|
|
|
@ -9,7 +9,7 @@ import XCTest
|
|||
@testable import TestUtils
|
||||
@testable import ZcashLightClientKit
|
||||
|
||||
// swiftlint:disable implicitly_unwrapped_optional
|
||||
// swiftlint:disable implicitly_unwrapped_optional force_try
|
||||
class NotesRepositoryTests: XCTestCase {
|
||||
var sentNotesRepository: SentNotesRepository!
|
||||
var receivedNotesRepository: ReceivedNoteRepository!
|
||||
|
|
|
@ -89,13 +89,10 @@ class NullBytesTests: XCTestCase {
|
|||
}
|
||||
}
|
||||
|
||||
// TODO: [#716] fix, https://github.com/zcash/ZcashLightClientKit/issues/716
|
||||
func testderiveExtendedFullViewingKeyWithNullBytes() throws {
|
||||
|
||||
// TODO: fix
|
||||
// // swiftlint:disable:next line_length
|
||||
// let wrongSpendingKeys = SaplingExtendedSpendingKey(validatedEncoding: "secret-extended-key-main1qw28psv0qqqqpqr2ru0kss5equx6h0xjsuk5299xrsgdqnhe0cknkl8uqff34prwkyuegyhh5d4rdr8025nl7e0hm8r2txx3fuea5mq\0uy3wnsr9tlajsg4wwvw0xcfk8357k4h850rgj72kt4rx3fjdz99zs9f4neda35cq8tn3848yyvlg4w38gx75cyv9jdpve77x9eq6rtl6d9qyh8det4edevlnc70tg5kse670x50764gzhy60dta0yv3wsd4fsuaz686lgszc7nc9vv") // this spending key corresponds to the "demo app reference seed"
|
||||
//
|
||||
// // swiftlint:disable:next line_length
|
||||
// let goodSpendingKeys = SaplingExtendedSpendingKey(validatedEncoding: "secret-extended-key-main1qw28psv0qqqqpqr2ru0kss5equx6h0xjsuk5299xrsgdqnhe0cknkl8uqff34prwkyuegyhh5d4rdr8025nl7e0hm8r2txx3fuea5mquy3wnsr9tlajsg4wwvw0xcfk8357k4h850rgj72kt4rx3fjdz99zs9f4neda35cq8tn3848yyvlg4w38gx75cyv9jdpve77x9eq6rtl6d9qyh8det4edevlnc70tg5kse670x50764gzhy60dta0yv3wsd4fsuaz686lgszc7nc9vv")
|
||||
//
|
||||
// XCTAssertThrowsError(
|
||||
|
@ -136,7 +133,7 @@ class NullBytesTests: XCTestCase {
|
|||
|
||||
let nonNullTrailedString = "This Is a memo with text and trailing null bytes"
|
||||
|
||||
let trimmedString = String(nullTrailedString.reversed().drop(while: { $0 == "\u{0}"}).reversed())
|
||||
let trimmedString = String(nullTrailedString.reversed().drop(while: { $0 == "\u{0}" }).reversed())
|
||||
|
||||
XCTAssertEqual(trimmedString, nonNullTrailedString)
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
import XCTest
|
||||
@testable import ZcashLightClientKit
|
||||
final class RecipientTests: XCTestCase {
|
||||
// swiftlint:disable:next line_length
|
||||
let uaString = "u1l9f0l4348negsncgr9pxd9d3qaxagmqv3lnexcplmufpq7muffvfaue6ksevfvd7wrz7xrvn95rc5zjtn7ugkmgh5rnxswmcj30y0pw52pn0zjvy38rn2esfgve64rj5pcmazxgpyuj"
|
||||
|
||||
let saplingString = "zs1vp7kvlqr4n9gpehztr76lcn6skkss9p8keqs3nv8avkdtjrcctrvmk9a7u494kluv756jeee5k0"
|
||||
|
@ -41,6 +42,5 @@ final class RecipientTests: XCTestCase {
|
|||
|
||||
XCTAssertEqual(recipient?.0, .sapling(SaplingAddress(validatedEncoding: address)))
|
||||
XCTAssertEqual(recipient?.1, .mainnet)
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@ import XCTest
|
|||
@testable import TestUtils
|
||||
@testable import ZcashLightClientKit
|
||||
|
||||
// swiftlint:disable implicitly_unwrapped_optional force_unwrapping
|
||||
// swiftlint:disable implicitly_unwrapped_optional force_unwrapping force_try
|
||||
class TransactionRepositoryTests: XCTestCase {
|
||||
var transactionRepository: TransactionRepository!
|
||||
|
||||
|
|
|
@ -20,6 +20,7 @@ struct EnclosingStruct {
|
|||
var someStructure: SomeStructure
|
||||
}
|
||||
|
||||
// swiftlint:disable print_function_usage
|
||||
final class UndescribableTests: XCTestCase {
|
||||
func testDescriptionIsRedacted() throws {
|
||||
let info = "important info"
|
||||
|
@ -52,10 +53,10 @@ final class UndescribableTests: XCTestCase {
|
|||
func testMirroringIsRedacted() {
|
||||
let info = "important info"
|
||||
let someStructure = SomeStructure(info: info)
|
||||
var s = ""
|
||||
debugPrint(someStructure, to: &s)
|
||||
XCTAssertFalse(s.contains(info))
|
||||
XCTAssertEqual(s, "--redacted--\n")
|
||||
var str = ""
|
||||
debugPrint(someStructure, to: &str)
|
||||
XCTAssertFalse(str.contains(info))
|
||||
XCTAssertEqual(str, "--redacted--\n")
|
||||
}
|
||||
|
||||
func testLocalizedErrorIsRedacted() {
|
||||
|
@ -86,11 +87,12 @@ final class UndescribableTests: XCTestCase {
|
|||
}
|
||||
|
||||
func testSpendingKeyCantBeDescribed() {
|
||||
// swiftlint:disable:next line_length
|
||||
let key = SaplingExtendedFullViewingKey(validatedEncoding: "zxviewtestsapling1qdxykmuaqqqqpqqg3x5c02p4rhw0rtszr8ln4xl7g6wg6qzsqgn445qsu3cq4vd6l5smlqrckkl2x5rnrauzc4gp665q3zyw0qf2sfdsx5wpp832htfavqk72uchuuvq2dpmgk8jfaza5t5l56u66fpx0sr8ewp9s3wj2txavmhhlazn5rj8mshh470fkrmzg4xarhrqlygg8f486307ujhndwhsw2h7ddzf89k3534aeu0ypz2tjgrzlcqtat380vhe8awm03f58cqgegsaj")
|
||||
|
||||
var s = ""
|
||||
debugPrint(key, to: &s)
|
||||
var str = ""
|
||||
debugPrint(key, to: &str)
|
||||
|
||||
XCTAssertEqual(s, "--redacted--\n")
|
||||
XCTAssertEqual(str, "--redacted--\n")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,8 +8,8 @@
|
|||
import XCTest
|
||||
@testable import ZcashLightClientKit
|
||||
import TestUtils
|
||||
final class UnifiedTypecodesTests: XCTestCase {
|
||||
|
||||
final class UnifiedTypecodesTests: XCTestCase {
|
||||
func testVectorBuilding() throws {
|
||||
guard let testVectors = TestVector.testVectors else {
|
||||
XCTFail("fail to construct vectors")
|
||||
|
@ -21,8 +21,9 @@ final class UnifiedTypecodesTests: XCTestCase {
|
|||
|
||||
func testUnifiedAddressHasTransparentSaplingReceiversBackend() throws {
|
||||
guard let testVectors = TestVector.testVectors,
|
||||
let firstVector = testVectors.first,
|
||||
let uAddress = firstVector.unified_addr else {
|
||||
let firstVector = testVectors.first,
|
||||
let uAddress = firstVector.unified_addr
|
||||
else {
|
||||
XCTFail("fail to construct vectors")
|
||||
return
|
||||
}
|
||||
|
@ -36,13 +37,13 @@ final class UnifiedTypecodesTests: XCTestCase {
|
|||
|
||||
func testUnifiedAddressHasTransparentSaplingReceivers() throws {
|
||||
guard let testVectors = TestVector.testVectors,
|
||||
let firstVector = testVectors.first,
|
||||
let uAddress = firstVector.unified_addr else {
|
||||
let firstVector = testVectors.first,
|
||||
let uAddress = firstVector.unified_addr
|
||||
else {
|
||||
XCTFail("fail to construct vectors")
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
let address = UnifiedAddress(validatedEncoding: uAddress)
|
||||
|
||||
let typecodes = try DerivationTool.receiverTypecodesFromUnifiedAddress(address)
|
||||
|
@ -65,6 +66,7 @@ final class UnifiedTypecodesTests: XCTestCase {
|
|||
}
|
||||
|
||||
func testExtractTypecode() throws {
|
||||
// swiftlint:disable:next line_length
|
||||
let ua = UnifiedAddress(validatedEncoding: "u1l9f0l4348negsncgr9pxd9d3qaxagmqv3lnexcplmufpq7muffvfaue6ksevfvd7wrz7xrvn95rc5zjtn7ugkmgh5rnxswmcj30y0pw52pn0zjvy38rn2esfgve64rj5pcmazxgpyuj")
|
||||
XCTAssertEqual(try ua.availableReceiverTypecodes(), [.sapling, .p2pkh])
|
||||
}
|
||||
|
|
|
@ -36,7 +36,7 @@ class WalletTests: XCTestCase {
|
|||
func testWalletInitialization() throws {
|
||||
let derivationTool = DerivationTool(networkType: network.networkType)
|
||||
let ufvk = try derivationTool.deriveUnifiedSpendingKey(seed: seedData.bytes, accountIndex: 0)
|
||||
.map( { try derivationTool.deriveUnifiedFullViewingKey(from: $0) })
|
||||
.map({ try derivationTool.deriveUnifiedFullViewingKey(from: $0) })
|
||||
let wallet = Initializer(
|
||||
cacheDbURL: try __cacheDbURL(),
|
||||
dataDbURL: try __dataDbURL(),
|
||||
|
@ -61,7 +61,7 @@ class WalletTests: XCTestCase {
|
|||
|
||||
// fileExists actually sucks, so attempting to delete the file and checking what happens is far better :)
|
||||
XCTAssertNoThrow( try FileManager.default.removeItem(at: dbData!) )
|
||||
// TODO: Initialize cacheDB on start, will be done when Synchronizer is ready and integrated
|
||||
// TODO: [#717] Initialize cacheDB on start, will be done when Synchronizer is ready and integrated, https://github.com/zcash/ZcashLightClientKit/issues/717
|
||||
// XCTAssertNoThrow( try FileManager.default.removeItem(at: cacheData!) )
|
||||
}
|
||||
}
|
||||
|
|
|
@ -46,7 +46,7 @@ class ZcashRustBackendTests: XCTestCase {
|
|||
return
|
||||
}
|
||||
|
||||
XCTAssertThrowsError(try ZcashRustBackend.createAccount(dbData: dbData!, seed: Array(seed.utf8), networkType: networkType))
|
||||
XCTAssertThrowsError(try ZcashRustBackend.createAccount(dbData: dbData!, seed: Array(seed.utf8), networkType: networkType))
|
||||
}
|
||||
|
||||
func testInitAndScanBlocks() throws {
|
||||
|
@ -57,19 +57,21 @@ class ZcashRustBackendTests: XCTestCase {
|
|||
let seed = "testreferencealicetestreferencealice"
|
||||
|
||||
var dbInit: DbInitResult!
|
||||
XCTAssertNoThrow(try { dbInit = try ZcashRustBackend.initDataDb(dbData: self.dbData!, seed: Array(seed.utf8), networkType: self.networkType) }())
|
||||
XCTAssertNoThrow(try { dbInit = try ZcashRustBackend.initDataDb(
|
||||
dbData: self.dbData!,
|
||||
seed: Array(seed.utf8),
|
||||
networkType: self.networkType
|
||||
) }())
|
||||
|
||||
guard case .success = dbInit else {
|
||||
XCTFail("Failed to initDataDb. Expected `.success` got: \(String(describing: dbInit))")
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
XCTAssertEqual(ZcashRustBackend.getLastError(), nil)
|
||||
let ufvks = [
|
||||
try DerivationTool(networkType: networkType).deriveUnifiedSpendingKey(seed: Array(seed.utf8), accountIndex: 0)
|
||||
.deriveFullViewingKey()
|
||||
|
||||
]
|
||||
do {
|
||||
try ZcashRustBackend.initAccountsTable(dbData: dbData!, ufvks: ufvks, networkType: networkType)
|
||||
|
@ -89,6 +91,7 @@ class ZcashRustBackendTests: XCTestCase {
|
|||
|
||||
let addr = try ZcashRustBackend.getCurrentAddress(dbData: dbData!, account: 0, networkType: networkType)
|
||||
XCTAssertEqual(ZcashRustBackend.getLastError(), nil)
|
||||
// swiftlint:disable:next line_length
|
||||
XCTAssertEqual(addr.saplingReceiver()?.stringEncoded, Optional("ztestsapling12k9m98wmpjts2m56wc60qzhgsfvlpxcwah268xk5yz4h942sd58jy3jamqyxjwums6hw7kfa4cc"))
|
||||
|
||||
XCTAssertTrue(ZcashRustBackend.scanBlocks(dbCache: cacheDb, dbData: dbData, networkType: networkType))
|
||||
|
@ -145,7 +148,7 @@ class ZcashRustBackendTests: XCTestCase {
|
|||
.success
|
||||
)
|
||||
|
||||
var usk: UnifiedSpendingKey?;
|
||||
var usk: UnifiedSpendingKey?
|
||||
XCTAssertNoThrow(
|
||||
usk = try ZcashRustBackend.createAccount(
|
||||
dbData: tempDBs.dataDB,
|
||||
|
@ -160,8 +163,7 @@ class ZcashRustBackendTests: XCTestCase {
|
|||
}
|
||||
.compactMap({ $0.transparentReceiver() })
|
||||
|
||||
|
||||
let expectedUAs = testVector.map{
|
||||
let expectedUAs = testVector.map {
|
||||
UnifiedAddress(validatedEncoding: $0.unified_addr!)
|
||||
}
|
||||
|
||||
|
@ -169,8 +171,8 @@ class ZcashRustBackendTests: XCTestCase {
|
|||
XCTFail("not enough transparent receivers")
|
||||
return
|
||||
}
|
||||
var uAddresses = [UnifiedAddress]()
|
||||
for i in (0 ... 2) {
|
||||
var uAddresses: [UnifiedAddress] = []
|
||||
for i in 0...2 {
|
||||
uAddresses.append(
|
||||
try ZcashRustBackend.getCurrentAddress(
|
||||
dbData: tempDBs.dataDB,
|
||||
|
@ -179,7 +181,7 @@ class ZcashRustBackendTests: XCTestCase {
|
|||
)
|
||||
)
|
||||
|
||||
if (i < 2) {
|
||||
if i < 2 {
|
||||
_ = try ZcashRustBackend.getNextAvailableAddress(
|
||||
dbData: tempDBs.dataDB,
|
||||
account: 0,
|
||||
|
@ -188,7 +190,6 @@ class ZcashRustBackendTests: XCTestCase {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
XCTAssertEqual(
|
||||
uAddresses,
|
||||
expectedUAs
|
||||
|
@ -207,7 +208,6 @@ class ZcashRustBackendTests: XCTestCase {
|
|||
}
|
||||
|
||||
func testGetMetadataFromAddress() throws {
|
||||
|
||||
let recipientAddress = "zs17mg40levjezevuhdp5pqrd52zere7r7vrjgdwn5sj4xsqtm20euwahv9anxmwr3y3kmwuz8k55a"
|
||||
|
||||
let metadata = ZcashRustBackend.getAddressMetadata(recipientAddress)
|
||||
|
|
|
@ -9,7 +9,6 @@ import XCTest
|
|||
@testable import ZcashLightClientKit
|
||||
|
||||
class Zip302MemoTests: XCTestCase {
|
||||
|
||||
/// Zip-302 specifies "the byte 0xF6 followed by 511 0x00 bytes, indicating 'no memo'"
|
||||
func testEmptyMemoBytesHasF6LeadByteAndThenZeroes() throws {
|
||||
XCTAssertEqual(MemoBytes.empty().bytes, Self.emptyMemoBytes)
|
||||
|
@ -70,7 +69,7 @@ class Zip302MemoTests: XCTestCase {
|
|||
XCTAssertEqual(
|
||||
memo,
|
||||
.future(futureMemoBytes),
|
||||
"Failed to create a Future memo starting with \(String(format:"%02X", firstByte))"
|
||||
"Failed to create a Future memo starting with \(String(format: "%02X", firstByte))"
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -84,6 +83,7 @@ class Zip302MemoTests: XCTestCase {
|
|||
}
|
||||
|
||||
func testItThrowsTooLongWhenCreatingAMemoFromAValidButTooLongString() throws {
|
||||
// swiftlint:disable:next line_length
|
||||
let tooLongString = "thiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiis iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiis aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa veeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeryyyyyyyyyyyyyyyyyyyyyyyyyy looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong meeeeeeeeeeeeeeeeeeemooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo but it's now a bit too long"
|
||||
|
||||
XCTAssertThrowsError(try Memo(string: tooLongString)) { err in
|
||||
|
@ -93,16 +93,17 @@ class Zip302MemoTests: XCTestCase {
|
|||
}
|
||||
|
||||
switch error {
|
||||
case .tooLong(let length) :
|
||||
XCTAssertEqual(length, 513)
|
||||
|
||||
default:
|
||||
XCTFail("Expected `MemoBytes.Errors.TooLong` error but found \(err.localizedDescription)")
|
||||
case .tooLong(let length):
|
||||
XCTAssertEqual(length, 513)
|
||||
|
||||
default:
|
||||
XCTFail("Expected `MemoBytes.Errors.TooLong` error but found \(err.localizedDescription)")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func testItCreatesAMemoFromAValidAndShortEnoughText() throws {
|
||||
// swiftlint:disable:next line_length
|
||||
let almostTooLongString = "thiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiis iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiis aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa veeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeryyyyyyyyyyyyyyyyyyyyyyyyyy looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong meeeeeeeeeeeeeeeeeeemooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo but it's just short enough"
|
||||
|
||||
let memo = try Memo(string: almostTooLongString)
|
||||
|
@ -114,6 +115,7 @@ class Zip302MemoTests: XCTestCase {
|
|||
|
||||
func testItThrowsTooLongWhenMemoCharacterCountIsLongEnoughButIsTooLongInBytes() {
|
||||
/// This string's count it 512 characters, but when converted to UTF8 bytes, it has 515 bytes.
|
||||
// swiftlint:disable:next line_length
|
||||
let almostTooLongString = "thiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiis iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiis aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa veeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeryyyyyyyyyyyyyyyyyyyyyyyyyy looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong meeeeeeeeeeeeeeeeeeemooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo but it's just short is it😛"
|
||||
|
||||
XCTAssertThrowsError(try Memo(string: almostTooLongString)) { err in
|
||||
|
@ -222,21 +224,23 @@ class Zip302MemoTests: XCTestCase {
|
|||
}
|
||||
|
||||
func testMemoLenght1CharTooLong () {
|
||||
// swiftlint:disable:next line_length
|
||||
let tooLongString = "thiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiis iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiis aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa veeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeryyyyyyyyyyyyyyyyyyyyyyyyyy looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong meeeeeeeeeeeeeeeeeeemooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo but it's now a bit too long"
|
||||
|
||||
XCTAssertEqual(Memo.length(for: tooLongString), 513)
|
||||
}
|
||||
|
||||
func testTextIsVisibleFitButExceedsLimit() {
|
||||
// swiftlint:disable:next line_length
|
||||
let tooLongStringThatVisiblyFits = "thiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiis iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiis aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa veeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeryyyyyyyyyyyyyyyyyyyyyyyyyy looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong meeeeeeeeeeeeeeeeemooooooooooooooooooooooooooooooooooooooong. Visibly fit, but it exceeds the byte limit. 👩👩👧👧"
|
||||
XCTAssertEqual(MemoBytes.capacity, tooLongStringThatVisiblyFits.count) // this assertion proves that the count of visible characters is within the limit
|
||||
// this assertion proves that the count of visible characters is within the limit
|
||||
XCTAssertEqual(MemoBytes.capacity, tooLongStringThatVisiblyFits.count)
|
||||
XCTAssertTrue(Memo.length(for: tooLongStringThatVisiblyFits) > MemoBytes.capacity)
|
||||
|
||||
XCTAssertEqual(Memo.length(for: tooLongStringThatVisiblyFits), 536)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
extension Zip302MemoTests {
|
||||
static let emptyMemoBytes: [UInt8] = [
|
||||
0xf6, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
|
|
|
@ -29,7 +29,7 @@ final class SDKMetricsTests: XCTestCase {
|
|||
if let reports = SDKMetrics.shared.reports[.downloadBlocks], let report = reports.first {
|
||||
XCTAssertEqual(report, SDKMetrics.BlockMetricReport.placeholderA)
|
||||
} else {
|
||||
XCTFail()
|
||||
XCTFail("Not expected to fail.")
|
||||
}
|
||||
|
||||
SDKMetrics.shared.disableMetrics()
|
||||
|
@ -43,7 +43,7 @@ final class SDKMetricsTests: XCTestCase {
|
|||
if let reports = SDKMetrics.shared.popBlock(operation: .downloadBlocks), let report = reports.first {
|
||||
XCTAssertEqual(report, SDKMetrics.BlockMetricReport.placeholderA)
|
||||
} else {
|
||||
XCTFail()
|
||||
XCTFail("Not expected to fail.")
|
||||
}
|
||||
|
||||
SDKMetrics.shared.disableMetrics()
|
||||
|
|
|
@ -9,6 +9,7 @@ import XCTest
|
|||
@testable import ZcashLightClientKit
|
||||
@testable import TestUtils
|
||||
|
||||
// swiftlint:disable line_length
|
||||
class SynchronizerTests: XCTestCase {
|
||||
class MockLatestBlockHeightProvider: LatestBlockHeightProvider {
|
||||
let birthday: BlockHeight
|
||||
|
@ -22,16 +23,19 @@ class SynchronizerTests: XCTestCase {
|
|||
}
|
||||
}
|
||||
|
||||
// swiftlint:disable:next implicitly_unwrapped_optional
|
||||
var coordinator: TestCoordinator!
|
||||
|
||||
// swiftlint:disable:next line_length
|
||||
let seedPhrase = "wish puppy smile loan doll curve hole maze file ginger hair nose key relax knife witness cannon grab despair throw review deal slush frame"
|
||||
var birthday: BlockHeight = 1_730_000
|
||||
|
||||
@MainActor
|
||||
func testHundredBlocksSync() async throws {
|
||||
let derivationTool = DerivationTool(networkType: .mainnet)
|
||||
let seedData: Data = Data(base64Encoded: "9VDVOZZZOWWHpZtq1Ebridp3Qeux5C+HwiRR0g7Oi7HgnMs8Gfln83+/Q1NnvClcaSwM4ADFL1uZHxypEWlWXg==")!
|
||||
guard let seedData = Data(base64Encoded: "9VDVOZZZOWWHpZtq1Ebridp3Qeux5C+HwiRR0g7Oi7HgnMs8Gfln83+/Q1NnvClcaSwM4ADFL1uZHxypEWlWXg==") else {
|
||||
XCTFail("seedData expected to be successfuly instantiated.")
|
||||
return
|
||||
}
|
||||
let seedBytes = [UInt8](seedData)
|
||||
let spendingKey = try derivationTool.deriveUnifiedSpendingKey(
|
||||
seed: seedBytes,
|
||||
|
@ -71,7 +75,9 @@ class SynchronizerTests: XCTestCase {
|
|||
|
||||
let internalSyncProgress = InternalSyncProgress(storage: UserDefaults.standard)
|
||||
await internalSyncProgress.rewind(to: birthday)
|
||||
await (synchronizer.blockProcessor.service as? LightWalletGRPCService)?.latestBlockHeightProvider = MockLatestBlockHeightProvider(birthday: self.birthday + 99)
|
||||
await (synchronizer.blockProcessor.service as? LightWalletGRPCService)?.latestBlockHeightProvider = MockLatestBlockHeightProvider(
|
||||
birthday: self.birthday + 99
|
||||
)
|
||||
|
||||
try synchronizer.start()
|
||||
|
||||
|
|
|
@ -119,7 +119,7 @@ class DarksideWalletService: LightWalletService {
|
|||
metaState.saplingActivation = Int32(saplingActivation)
|
||||
metaState.branchID = branchID
|
||||
metaState.chainName = chainName
|
||||
// TODO: complete meta state correctly
|
||||
// TODO: [#718] complete meta state correctly, https://github.com/zcash/ZcashLightClientKit/issues/718
|
||||
_ = try darksideService.reset(metaState).response.wait()
|
||||
}
|
||||
|
||||
|
@ -206,4 +206,3 @@ class DarksideWalletDNetwork: ZcashNetwork {
|
|||
var constants: NetworkConstants.Type = DarksideWalletDConstants.self
|
||||
var networkType = NetworkType.mainnet
|
||||
}
|
||||
|
||||
|
|
|
@ -55,9 +55,7 @@ extension LightWalletServiceMockResponse {
|
|||
}
|
||||
|
||||
class MockRustBackend: ZcashRustBackendWelding {
|
||||
static func initAccountsTable(dbData: URL, ufvks: [ZcashLightClientKit.UnifiedFullViewingKey], networkType: ZcashLightClientKit.NetworkType) throws {
|
||||
|
||||
}
|
||||
static func initAccountsTable(dbData: URL, ufvks: [ZcashLightClientKit.UnifiedFullViewingKey], networkType: ZcashLightClientKit.NetworkType) throws { }
|
||||
|
||||
static func createToAddress(dbData: URL, usk: ZcashLightClientKit.UnifiedSpendingKey, to address: String, value: Int64, memo: ZcashLightClientKit.MemoBytes?, spendParamsPath: String, outputParamsPath: String, networkType: ZcashLightClientKit.NetworkType) -> Int64 {
|
||||
-1
|
||||
|
@ -75,13 +73,9 @@ class MockRustBackend: ZcashRustBackendWelding {
|
|||
0
|
||||
}
|
||||
|
||||
static func getTransparentBalance(dbData: URL, account: Int32, networkType: ZcashLightClientKit.NetworkType) throws -> Int64 {
|
||||
0
|
||||
}
|
||||
static func getTransparentBalance(dbData: URL, account: Int32, networkType: ZcashLightClientKit.NetworkType) throws -> Int64 { 0 }
|
||||
|
||||
static func getVerifiedTransparentBalance(dbData: URL, account: Int32, networkType: ZcashLightClientKit.NetworkType) throws -> Int64 {
|
||||
0
|
||||
}
|
||||
static func getVerifiedTransparentBalance(dbData: URL, account: Int32, networkType: ZcashLightClientKit.NetworkType) throws -> Int64 { 0 }
|
||||
|
||||
static func listTransparentReceivers(dbData: URL, account: Int32, networkType: ZcashLightClientKit.NetworkType) throws -> [ZcashLightClientKit.TransparentAddress] {
|
||||
[]
|
||||
|
@ -123,13 +117,9 @@ class MockRustBackend: ZcashRustBackendWelding {
|
|||
throw KeyDerivationErrors.unableToDerive
|
||||
}
|
||||
|
||||
static func getReceivedMemo(dbData: URL, idNote: Int64, networkType: ZcashLightClientKit.NetworkType) -> ZcashLightClientKit.Memo? {
|
||||
nil
|
||||
}
|
||||
static func getReceivedMemo(dbData: URL, idNote: Int64, networkType: ZcashLightClientKit.NetworkType) -> ZcashLightClientKit.Memo? { nil }
|
||||
|
||||
static func getSentMemo(dbData: URL, idNote: Int64, networkType: ZcashLightClientKit.NetworkType) -> ZcashLightClientKit.Memo? {
|
||||
nil
|
||||
}
|
||||
static func getSentMemo(dbData: URL, idNote: Int64, networkType: ZcashLightClientKit.NetworkType) -> ZcashLightClientKit.Memo? { nil }
|
||||
|
||||
static func createToAddress(dbData: URL, usk: ZcashLightClientKit.UnifiedSpendingKey, to address: String, value: Int64, memo: ZcashLightClientKit.MemoBytes, spendParamsPath: String, outputParamsPath: String, networkType: ZcashLightClientKit.NetworkType) -> Int64 {
|
||||
-1
|
||||
|
@ -143,9 +133,7 @@ class MockRustBackend: ZcashRustBackendWelding {
|
|||
throw RustWeldingError.unableToDeriveKeys
|
||||
}
|
||||
|
||||
static func isValidSaplingExtendedSpendingKey(_ key: String, networkType: ZcashLightClientKit.NetworkType) -> Bool {
|
||||
false
|
||||
}
|
||||
static func isValidSaplingExtendedSpendingKey(_ key: String, networkType: ZcashLightClientKit.NetworkType) -> Bool { false }
|
||||
|
||||
static func deriveSaplingExtendedFullViewingKeys(seed: [UInt8], accounts: Int32, networkType: ZcashLightClientKit.NetworkType) throws -> [ZcashLightClientKit.SaplingExtendedFullViewingKey]? {
|
||||
nil
|
||||
|
@ -159,22 +147,13 @@ class MockRustBackend: ZcashRustBackendWelding {
|
|||
nil
|
||||
}
|
||||
|
||||
|
||||
public func deriveViewingKeys(seed: [UInt8], numberOfAccounts: Int) throws -> [UnifiedFullViewingKey] {
|
||||
[]
|
||||
}
|
||||
public func deriveViewingKeys(seed: [UInt8], numberOfAccounts: Int) throws -> [UnifiedFullViewingKey] { [] }
|
||||
|
||||
static func getNearestRewindHeight(dbData: URL, height: Int32, networkType: NetworkType) -> Int32 {
|
||||
-1
|
||||
}
|
||||
static func getNearestRewindHeight(dbData: URL, height: Int32, networkType: NetworkType) -> Int32 { -1 }
|
||||
|
||||
static func network(dbData: URL, address: String, sinceHeight: BlockHeight, networkType: NetworkType) throws -> Int32 {
|
||||
-1
|
||||
}
|
||||
static func network(dbData: URL, address: String, sinceHeight: BlockHeight, networkType: NetworkType) throws -> Int32 { -1 }
|
||||
|
||||
static func initAccountsTable(dbData: URL, ufvks: [UnifiedFullViewingKey], networkType: NetworkType) throws -> Bool {
|
||||
false
|
||||
}
|
||||
static func initAccountsTable(dbData: URL, ufvks: [UnifiedFullViewingKey], networkType: NetworkType) throws -> Bool { false }
|
||||
|
||||
static func putUnspentTransparentOutput(
|
||||
dbData: URL,
|
||||
|
@ -214,17 +193,11 @@ class MockRustBackend: ZcashRustBackendWelding {
|
|||
throw KeyDerivationErrors.unableToDerive
|
||||
}
|
||||
|
||||
static func isValidSaplingExtendedFullViewingKey(_ key: String, networkType: NetworkType) -> Bool {
|
||||
false
|
||||
}
|
||||
static func isValidSaplingExtendedFullViewingKey(_ key: String, networkType: NetworkType) -> Bool { false }
|
||||
|
||||
static func isValidUnifiedFullViewingKey(_ ufvk: String, networkType: NetworkType) -> Bool {
|
||||
false
|
||||
}
|
||||
static func isValidUnifiedFullViewingKey(_ ufvk: String, networkType: NetworkType) -> Bool { false }
|
||||
|
||||
static func deriveSaplingExtendedSpendingKeys(seed: [UInt8], accounts: Int32, networkType: NetworkType) throws -> [SaplingExtendedSpendingKey]? {
|
||||
nil
|
||||
}
|
||||
static func deriveSaplingExtendedSpendingKeys(seed: [UInt8], accounts: Int32, networkType: NetworkType) throws -> [SaplingExtendedSpendingKey]? { nil }
|
||||
|
||||
static func consensusBranchIdFor(height: Int32, networkType: NetworkType) throws -> Int32 {
|
||||
guard let consensus = consensusBranchID else {
|
||||
|
|
|
@ -173,19 +173,19 @@ class TestCoordinator {
|
|||
}
|
||||
|
||||
@objc func synchronizerDisconnected(_ notification: Notification) {
|
||||
/// TODO: See if we need hooks for this
|
||||
// TODO: [#713] See if we need hooks for this, https://github.com/zcash/ZcashLightClientKit/issues/713
|
||||
}
|
||||
|
||||
@objc func synchronizerStarted(_ notification: Notification) {
|
||||
/// TODO: See if we need hooks for this
|
||||
// TODO: [#713] See if we need hooks for this, https://github.com/zcash/ZcashLightClientKit/issues/713
|
||||
}
|
||||
|
||||
@objc func synchronizerStopped(_ notification: Notification) {
|
||||
/// TODO: See if we need hooks for this
|
||||
// TODO: [#713] See if we need hooks for this, https://github.com/zcash/ZcashLightClientKit/issues/713
|
||||
}
|
||||
|
||||
@objc func synchronizerSyncing(_ notification: Notification) {
|
||||
/// TODO: See if we need hooks for this
|
||||
// TODO: [#713] See if we need hooks for this, https://github.com/zcash/ZcashLightClientKit/issues/713
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -338,9 +338,8 @@ enum TestSynchronizerBuilder {
|
|||
loggerProxy: Logger? = nil
|
||||
) async throws -> (spendingKeys: [UnifiedSpendingKey]?, synchronizer: SDKSynchronizer) {
|
||||
let spendingKey = try DerivationTool(networkType: network.networkType)
|
||||
.deriveUnifiedSpendingKey(seed: seedBytes, accountIndex: 0)
|
||||
.deriveUnifiedSpendingKey(seed: seedBytes, accountIndex: 0)
|
||||
|
||||
|
||||
let uvk = try DerivationTool(networkType: network.networkType)
|
||||
.deriveUnifiedFullViewingKey(from: spendingKey)
|
||||
|
||||
|
|
|
@ -84,10 +84,10 @@ class TestDbBuilder {
|
|||
networkType: .mainnet
|
||||
)
|
||||
|
||||
switch (initResult) {
|
||||
case .success: return provider
|
||||
case .seedRequired:
|
||||
throw StorageError.migrationFailedWithMessage(message: "Seed value required to initialize the wallet database")
|
||||
switch initResult {
|
||||
case .success: return provider
|
||||
case .seedRequired:
|
||||
throw StorageError.migrationFailedWithMessage(message: "Seed value required to initialize the wallet database")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@ enum Environment {
|
|||
static let lightwalletdKey = "LIGHTWALLETD_ADDRESS"
|
||||
}
|
||||
|
||||
public struct Constants {
|
||||
public enum Constants {
|
||||
static let address: String = ProcessInfo.processInfo.environment[Environment.lightwalletdKey] ?? "localhost"
|
||||
}
|
||||
|
||||
|
@ -47,8 +47,8 @@ class ChannelProvider {
|
|||
let channel = connectionBuilder
|
||||
.withKeepalive(
|
||||
ClientConnectionKeepalive(
|
||||
interval: .seconds(15),
|
||||
timeout: .seconds(10)
|
||||
interval: .seconds(15),
|
||||
timeout: .seconds(10)
|
||||
)
|
||||
)
|
||||
.connect(host: endpoint.host, port: endpoint.port)
|
||||
|
|
Loading…
Reference in New Issue