[#1323] Fix warnings generated by use of NSLock in async context
- Added `DBActor` which is custom global actor that protects access to Data DB. This replaces `globalDBLock`. - `ZcashRustBackend` isn't actor anymore but functions in this are protected by `DBActor`. - Regenerated mock for `ZcashRustBackendWelding`. It probably causes lot of changes because mock for actor is very different than mock for any other protocol. - Updated tests so those compile.
This commit is contained in:
parent
5644f8913f
commit
a7a4d779ef
|
@ -37,7 +37,7 @@ extension UTXOFetcherImpl: UTXOFetcher {
|
|||
) async throws -> (inserted: [UnspentTransactionOutputEntity], skipped: [UnspentTransactionOutputEntity]) {
|
||||
try Task.checkCancellation()
|
||||
|
||||
let accounts = try accountRepository.getAll()
|
||||
let accounts = try await accountRepository.getAll()
|
||||
.map { $0.account }
|
||||
|
||||
var tAddresses: [TransparentAddress] = []
|
||||
|
|
|
@ -8,22 +8,6 @@
|
|||
import Foundation
|
||||
import SQLite
|
||||
|
||||
extension Connection {
|
||||
public func scalarLocked<V: Value>(_ query: ScalarQuery<V?>) throws -> V.ValueType? {
|
||||
globalDBLock.lock()
|
||||
defer { globalDBLock.unlock() }
|
||||
|
||||
return try scalar(query)
|
||||
}
|
||||
|
||||
public func scalarLocked<V: Value>(_ query: ScalarQuery<V>) throws -> V {
|
||||
globalDBLock.lock()
|
||||
defer { globalDBLock.unlock() }
|
||||
|
||||
return try scalar(query)
|
||||
}
|
||||
}
|
||||
|
||||
class TransactionSQLDAO: TransactionRepository {
|
||||
enum NotesTableStructure {
|
||||
static let transactionID = Expression<Int>("tx")
|
||||
|
@ -55,17 +39,17 @@ class TransactionSQLDAO: TransactionRepository {
|
|||
true
|
||||
}
|
||||
|
||||
func countAll() async throws -> Int {
|
||||
@DBActor func countAll() async throws -> Int {
|
||||
do {
|
||||
return try connection().scalarLocked(transactionsView.count)
|
||||
return try connection().scalar(transactionsView.count)
|
||||
} catch {
|
||||
throw ZcashError.transactionRepositoryCountAll(error)
|
||||
}
|
||||
}
|
||||
|
||||
func countUnmined() async throws -> Int {
|
||||
@DBActor func countUnmined() async throws -> Int {
|
||||
do {
|
||||
return try connection().scalarLocked(transactionsView.filter(ZcashTransaction.Overview.Column.minedHeight == nil).count)
|
||||
return try connection().scalar(transactionsView.filter(ZcashTransaction.Overview.Column.minedHeight == nil).count)
|
||||
} catch {
|
||||
throw ZcashError.transactionRepositoryCountUnmined(error)
|
||||
}
|
||||
|
@ -76,7 +60,7 @@ class TransactionSQLDAO: TransactionRepository {
|
|||
.filter(ZcashTransaction.Overview.Column.rawID == Blob(bytes: rawID.bytes))
|
||||
.limit(1)
|
||||
|
||||
return try execute(query) { try ZcashTransaction.Overview(row: $0) }
|
||||
return try await execute(query) { try ZcashTransaction.Overview(row: $0) }
|
||||
}
|
||||
|
||||
func find(offset: Int, limit: Int, kind: TransactionKind) async throws -> [ZcashTransaction.Overview] {
|
||||
|
@ -85,7 +69,7 @@ class TransactionSQLDAO: TransactionRepository {
|
|||
.filterQueryFor(kind: kind)
|
||||
.limit(limit, offset: offset)
|
||||
|
||||
return try execute(query) { try ZcashTransaction.Overview(row: $0) }
|
||||
return try await execute(query) { try ZcashTransaction.Overview(row: $0) }
|
||||
}
|
||||
|
||||
func find(in range: CompactBlockRange, limit: Int, kind: TransactionKind) async throws -> [ZcashTransaction.Overview] {
|
||||
|
@ -98,7 +82,7 @@ class TransactionSQLDAO: TransactionRepository {
|
|||
.filterQueryFor(kind: kind)
|
||||
.limit(limit)
|
||||
|
||||
return try execute(query) { try ZcashTransaction.Overview(row: $0) }
|
||||
return try await execute(query) { try ZcashTransaction.Overview(row: $0) }
|
||||
}
|
||||
|
||||
func find(from transaction: ZcashTransaction.Overview, limit: Int, kind: TransactionKind) async throws -> [ZcashTransaction.Overview] {
|
||||
|
@ -119,7 +103,7 @@ class TransactionSQLDAO: TransactionRepository {
|
|||
.filterQueryFor(kind: kind)
|
||||
.limit(limit)
|
||||
|
||||
return try execute(query) { try ZcashTransaction.Overview(row: $0) }
|
||||
return try await execute(query) { try ZcashTransaction.Overview(row: $0) }
|
||||
}
|
||||
|
||||
func findReceived(offset: Int, limit: Int) async throws -> [ZcashTransaction.Overview] {
|
||||
|
@ -128,7 +112,7 @@ class TransactionSQLDAO: TransactionRepository {
|
|||
.order((ZcashTransaction.Overview.Column.minedHeight ?? BlockHeight.max).desc)
|
||||
.limit(limit, offset: offset)
|
||||
|
||||
return try execute(query) { try ZcashTransaction.Overview(row: $0) }
|
||||
return try await execute(query) { try ZcashTransaction.Overview(row: $0) }
|
||||
}
|
||||
|
||||
func findSent(offset: Int, limit: Int) async throws -> [ZcashTransaction.Overview] {
|
||||
|
@ -137,7 +121,7 @@ class TransactionSQLDAO: TransactionRepository {
|
|||
.order((ZcashTransaction.Overview.Column.minedHeight ?? BlockHeight.max).desc)
|
||||
.limit(limit, offset: offset)
|
||||
|
||||
return try execute(query) { try ZcashTransaction.Overview(row: $0) }
|
||||
return try await execute(query) { try ZcashTransaction.Overview(row: $0) }
|
||||
}
|
||||
|
||||
func findPendingTransactions(latestHeight: BlockHeight, offset: Int, limit: Int) async throws -> [ZcashTransaction.Overview] {
|
||||
|
@ -146,7 +130,7 @@ class TransactionSQLDAO: TransactionRepository {
|
|||
.order((ZcashTransaction.Overview.Column.minedHeight ?? BlockHeight.max).desc)
|
||||
.limit(limit, offset: offset)
|
||||
|
||||
return try execute(query) { try ZcashTransaction.Overview(row: $0) }
|
||||
return try await execute(query) { try ZcashTransaction.Overview(row: $0) }
|
||||
}
|
||||
|
||||
func findMemos(for transaction: ZcashTransaction.Overview) async throws -> [Memo] {
|
||||
|
@ -162,23 +146,20 @@ class TransactionSQLDAO: TransactionRepository {
|
|||
let query = self.txOutputsView
|
||||
.filter(ZcashTransaction.Output.Column.rawID == Blob(bytes: rawID.bytes))
|
||||
|
||||
return try execute(query) { try ZcashTransaction.Output(row: $0) }
|
||||
return try await execute(query) { try ZcashTransaction.Output(row: $0) }
|
||||
}
|
||||
|
||||
func getRecipients(for rawID: Data) async throws -> [TransactionRecipient] {
|
||||
try await getTransactionOutputs(for: rawID).map { $0.recipient }
|
||||
}
|
||||
|
||||
private func execute<Entity>(_ query: View, createEntity: (Row) throws -> Entity) throws -> Entity {
|
||||
let entities: [Entity] = try execute(query, createEntity: createEntity)
|
||||
private func execute<Entity>(_ query: View, createEntity: (Row) throws -> Entity) async throws -> Entity {
|
||||
let entities: [Entity] = try await execute(query, createEntity: createEntity)
|
||||
guard let entity = entities.first else { throw ZcashError.transactionRepositoryEntityNotFound }
|
||||
return entity
|
||||
}
|
||||
|
||||
private func execute<Entity>(_ query: View, createEntity: (Row) throws -> Entity) throws -> [Entity] {
|
||||
globalDBLock.lock()
|
||||
defer { globalDBLock.unlock() }
|
||||
|
||||
@DBActor private func execute<Entity>(_ query: View, createEntity: (Row) throws -> Entity) async throws -> [Entity] {
|
||||
do {
|
||||
let entities = try connection()
|
||||
.prepare(query)
|
||||
|
|
|
@ -92,7 +92,7 @@ class UnspentTransactionOutputSQLDAO: UnspentTransactionOutputRepository {
|
|||
try await createTableIfNeeded()
|
||||
}
|
||||
|
||||
private func createTableIfNeeded() async throws {
|
||||
@DBActor private func createTableIfNeeded() async throws {
|
||||
let stringStatement =
|
||||
"""
|
||||
CREATE TABLE IF NOT EXISTS utxos (
|
||||
|
@ -109,9 +109,6 @@ class UnspentTransactionOutputSQLDAO: UnspentTransactionOutputRepository {
|
|||
)
|
||||
"""
|
||||
do {
|
||||
globalDBLock.lock()
|
||||
defer { globalDBLock.unlock() }
|
||||
|
||||
try dbProvider.connection().run(stringStatement)
|
||||
} catch {
|
||||
throw ZcashError.unspentTransactionOutputDAOCreateTable(error)
|
||||
|
@ -119,11 +116,8 @@ class UnspentTransactionOutputSQLDAO: UnspentTransactionOutputRepository {
|
|||
}
|
||||
|
||||
/// - Throws: `unspentTransactionOutputDAOStore` if sqlite query fails.
|
||||
func store(utxos: [UnspentTransactionOutputEntity]) async throws {
|
||||
@DBActor func store(utxos: [UnspentTransactionOutputEntity]) async throws {
|
||||
do {
|
||||
globalDBLock.lock()
|
||||
defer { globalDBLock.unlock() }
|
||||
|
||||
let db = try dbProvider.connection()
|
||||
try db.transaction {
|
||||
for utxo in utxos.map({ $0 as? UTXO ?? $0.asUTXO() }) {
|
||||
|
@ -136,11 +130,8 @@ class UnspentTransactionOutputSQLDAO: UnspentTransactionOutputRepository {
|
|||
}
|
||||
|
||||
/// - Throws: `unspentTransactionOutputDAOClearAll` if sqlite query fails.
|
||||
func clearAll(address: String?) async throws {
|
||||
@DBActor func clearAll(address: String?) async throws {
|
||||
do {
|
||||
globalDBLock.lock()
|
||||
defer { globalDBLock.unlock() }
|
||||
|
||||
if let tAddr = address {
|
||||
try dbProvider.connection().run(table.filter(TableColumns.address == tAddr).delete())
|
||||
} else {
|
||||
|
@ -185,14 +176,14 @@ class UnspentTransactionOutputSQLDAO: UnspentTransactionOutputRepository {
|
|||
}
|
||||
|
||||
/// - Throws: `unspentTransactionOutputDAOBalance` if sqlite query fails.
|
||||
func balance(address: String, latestHeight: BlockHeight) async throws -> WalletBalance {
|
||||
@DBActor func balance(address: String, latestHeight: BlockHeight) async throws -> WalletBalance {
|
||||
do {
|
||||
let verified = try dbProvider.connection().scalarLocked(
|
||||
let verified = try dbProvider.connection().scalar(
|
||||
table.select(TableColumns.valueZat.sum)
|
||||
.filter(TableColumns.address == address)
|
||||
.filter(TableColumns.height <= latestHeight - ZcashSDK.defaultStaleTolerance)
|
||||
) ?? 0
|
||||
let total = try dbProvider.connection().scalarLocked(
|
||||
let total = try dbProvider.connection().scalar(
|
||||
table.select(TableColumns.valueZat.sum)
|
||||
.filter(TableColumns.address == address)
|
||||
) ?? 0
|
||||
|
|
|
@ -40,9 +40,9 @@ extension DbAccount: Hashable {
|
|||
}
|
||||
|
||||
protocol AccountRepository {
|
||||
func getAll() throws -> [AccountEntity]
|
||||
func findBy(account: Int) throws -> AccountEntity?
|
||||
func update(_ account: AccountEntity) throws
|
||||
func getAll() async throws -> [AccountEntity]
|
||||
func findBy(account: Int) async throws -> AccountEntity?
|
||||
func update(_ account: AccountEntity) async throws
|
||||
}
|
||||
|
||||
class AccountSQDAO: AccountRepository {
|
||||
|
@ -64,11 +64,8 @@ class AccountSQDAO: AccountRepository {
|
|||
/// - Throws:
|
||||
/// - `accountDAOGetAllCantDecode` if account data fetched from the db can't be decoded to the `Account` object.
|
||||
/// - `accountDAOGetAll` if sqlite query fetching account data failed.
|
||||
func getAll() throws -> [AccountEntity] {
|
||||
@DBActor func getAll() async throws -> [AccountEntity] {
|
||||
do {
|
||||
globalDBLock.lock()
|
||||
defer { globalDBLock.unlock() }
|
||||
|
||||
return try dbProvider.connection()
|
||||
.prepare(table)
|
||||
.map { row -> DbAccount in
|
||||
|
@ -90,12 +87,9 @@ class AccountSQDAO: AccountRepository {
|
|||
/// - Throws:
|
||||
/// - `accountDAOFindByCantDecode` if account data fetched from the db can't be decoded to the `Account` object.
|
||||
/// - `accountDAOFindBy` if sqlite query fetching account data failed.
|
||||
func findBy(account: Int) throws -> AccountEntity? {
|
||||
@DBActor func findBy(account: Int) async throws -> AccountEntity? {
|
||||
let query = table.filter(TableColums.account == account).limit(1)
|
||||
do {
|
||||
globalDBLock.lock()
|
||||
defer { globalDBLock.unlock() }
|
||||
|
||||
return try dbProvider.connection()
|
||||
.prepare(query)
|
||||
.map {
|
||||
|
@ -118,16 +112,13 @@ class AccountSQDAO: AccountRepository {
|
|||
/// - Throws:
|
||||
/// - `accountDAOUpdate` if sqlite query updating account failed.
|
||||
/// - `accountDAOUpdatedZeroRows` if sqlite query updating account pass but it affects 0 rows.
|
||||
func update(_ account: AccountEntity) throws {
|
||||
@DBActor func update(_ account: AccountEntity) async throws {
|
||||
guard let acc = account as? DbAccount else {
|
||||
throw ZcashError.accountDAOUpdateInvalidAccount
|
||||
}
|
||||
|
||||
let updatedRows: Int
|
||||
do {
|
||||
globalDBLock.lock()
|
||||
defer { globalDBLock.unlock() }
|
||||
|
||||
updatedRows = try dbProvider.connection().run(table.filter(TableColums.account == acc.account).update(acc))
|
||||
} catch {
|
||||
throw ZcashError.accountDAOUpdate(error)
|
||||
|
@ -142,30 +133,33 @@ class AccountSQDAO: AccountRepository {
|
|||
|
||||
class CachingAccountDao: AccountRepository {
|
||||
let dao: AccountRepository
|
||||
lazy var cache: [Int: AccountEntity] = {
|
||||
var accountCache: [Int: AccountEntity] = [:]
|
||||
guard let all = try? dao.getAll() else {
|
||||
return accountCache
|
||||
}
|
||||
private var cacheLoaded = false
|
||||
private var cache: [Int: AccountEntity] = [:]
|
||||
|
||||
for acc in all {
|
||||
accountCache[acc.account] = acc
|
||||
}
|
||||
|
||||
return accountCache
|
||||
}()
|
||||
|
||||
init(dao: AccountRepository) {
|
||||
self.dao = dao
|
||||
}
|
||||
|
||||
func getAll() throws -> [AccountEntity] {
|
||||
|
||||
private func loadCache() async {
|
||||
guard !cacheLoaded else { return }
|
||||
cacheLoaded = true
|
||||
guard let all = try? await dao.getAll() else {
|
||||
return
|
||||
}
|
||||
|
||||
for acc in all {
|
||||
cache[acc.account] = acc
|
||||
}
|
||||
}
|
||||
|
||||
func getAll() async throws -> [AccountEntity] {
|
||||
await loadCache()
|
||||
guard cache.isEmpty else {
|
||||
return cache.values.sorted(by: { $0.account < $1.account })
|
||||
}
|
||||
|
||||
let all = try dao.getAll()
|
||||
|
||||
let all = try await dao.getAll()
|
||||
|
||||
for acc in all {
|
||||
cache[acc.account] = acc
|
||||
}
|
||||
|
@ -173,19 +167,20 @@ class CachingAccountDao: AccountRepository {
|
|||
return all
|
||||
}
|
||||
|
||||
func findBy(account: Int) throws -> AccountEntity? {
|
||||
func findBy(account: Int) async throws -> AccountEntity? {
|
||||
await loadCache()
|
||||
if let acc = cache[account] {
|
||||
return acc
|
||||
}
|
||||
|
||||
let acc = try dao.findBy(account: account)
|
||||
let acc = try await dao.findBy(account: account)
|
||||
cache[account] = acc
|
||||
|
||||
return acc
|
||||
}
|
||||
|
||||
func update(_ account: AccountEntity) throws {
|
||||
try dao.update(account)
|
||||
func update(_ account: AccountEntity) async throws {
|
||||
try await dao.update(account)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -423,7 +423,7 @@ public class Initializer {
|
|||
self.walletBirthday = checkpoint.height
|
||||
|
||||
// If there are no accounts it must be created, the default amount of accounts is 1
|
||||
if let seed, try accountRepository.getAll().isEmpty {
|
||||
if let seed, try await accountRepository.getAll().isEmpty {
|
||||
var chainTip: UInt32?
|
||||
|
||||
if walletMode == .restoreWallet {
|
||||
|
|
|
@ -9,9 +9,7 @@
|
|||
import Foundation
|
||||
import libzcashlc
|
||||
|
||||
let globalDBLock = NSLock()
|
||||
|
||||
actor ZcashRustBackend: ZcashRustBackendWelding {
|
||||
struct ZcashRustBackend: ZcashRustBackendWelding {
|
||||
let minimumConfirmations: UInt32 = 10
|
||||
let useZIP317Fees = false
|
||||
|
||||
|
@ -21,7 +19,7 @@ actor ZcashRustBackend: ZcashRustBackendWelding {
|
|||
let outputParamsPath: (String, UInt)
|
||||
let keyDeriving: ZcashKeyDerivationBackendWelding
|
||||
|
||||
nonisolated let networkType: NetworkType
|
||||
let networkType: NetworkType
|
||||
|
||||
static var tracingEnabled = false
|
||||
/// Creates instance of `ZcashRustBackend`.
|
||||
|
@ -49,7 +47,7 @@ actor ZcashRustBackend: ZcashRustBackendWelding {
|
|||
}
|
||||
}
|
||||
|
||||
func createAccount(seed: [UInt8], treeState: TreeState, recoverUntil: UInt32?) async throws -> UnifiedSpendingKey {
|
||||
@DBActor func createAccount(seed: [UInt8], treeState: TreeState, recoverUntil: UInt32?) async throws -> UnifiedSpendingKey {
|
||||
var rUntil: Int64 = -1
|
||||
|
||||
if let recoverUntil {
|
||||
|
@ -57,8 +55,7 @@ actor ZcashRustBackend: ZcashRustBackendWelding {
|
|||
}
|
||||
|
||||
let treeStateBytes = try treeState.serializedData(partial: false).bytes
|
||||
|
||||
globalDBLock.lock()
|
||||
|
||||
let ffiBinaryKeyPtr = zcashlc_create_account(
|
||||
dbData.0,
|
||||
dbData.1,
|
||||
|
@ -69,7 +66,6 @@ actor ZcashRustBackend: ZcashRustBackendWelding {
|
|||
rUntil,
|
||||
networkType.networkId
|
||||
)
|
||||
globalDBLock.unlock()
|
||||
|
||||
guard let ffiBinaryKeyPtr else {
|
||||
throw ZcashError.rustCreateAccount(lastErrorMessage(fallback: "`createAccount` failed with unknown error"))
|
||||
|
@ -80,7 +76,7 @@ actor ZcashRustBackend: ZcashRustBackendWelding {
|
|||
return ffiBinaryKeyPtr.pointee.unsafeToUnifiedSpendingKey(network: networkType)
|
||||
}
|
||||
|
||||
func createToAddress(
|
||||
@DBActor func createToAddress(
|
||||
usk: UnifiedSpendingKey,
|
||||
to address: String,
|
||||
value: Int64,
|
||||
|
@ -88,7 +84,6 @@ actor ZcashRustBackend: ZcashRustBackendWelding {
|
|||
) async throws -> Data {
|
||||
var contiguousTxIdBytes = ContiguousArray<UInt8>([UInt8](repeating: 0x0, count: 32))
|
||||
|
||||
globalDBLock.lock()
|
||||
let success = contiguousTxIdBytes.withUnsafeMutableBufferPointer { txIdBytePtr in
|
||||
usk.bytes.withUnsafeBufferPointer { uskPtr in
|
||||
zcashlc_create_to_address(
|
||||
|
@ -110,7 +105,6 @@ actor ZcashRustBackend: ZcashRustBackendWelding {
|
|||
)
|
||||
}
|
||||
}
|
||||
globalDBLock.unlock()
|
||||
|
||||
guard success else {
|
||||
throw ZcashError.rustCreateToAddress(lastErrorMessage(fallback: "`createToAddress` failed with unknown error"))
|
||||
|
@ -121,8 +115,7 @@ actor ZcashRustBackend: ZcashRustBackendWelding {
|
|||
}
|
||||
}
|
||||
|
||||
func decryptAndStoreTransaction(txBytes: [UInt8], minedHeight: Int32) async throws {
|
||||
globalDBLock.lock()
|
||||
@DBActor func decryptAndStoreTransaction(txBytes: [UInt8], minedHeight: Int32) async throws {
|
||||
let result = zcashlc_decrypt_and_store_transaction(
|
||||
dbData.0,
|
||||
dbData.1,
|
||||
|
@ -131,17 +124,14 @@ actor ZcashRustBackend: ZcashRustBackendWelding {
|
|||
UInt32(minedHeight),
|
||||
networkType.networkId
|
||||
)
|
||||
globalDBLock.unlock()
|
||||
|
||||
guard result != 0 else {
|
||||
throw ZcashError.rustDecryptAndStoreTransaction(lastErrorMessage(fallback: "`decryptAndStoreTransaction` failed with unknown error"))
|
||||
}
|
||||
}
|
||||
|
||||
func getBalance(account: Int32) async throws -> Int64 {
|
||||
globalDBLock.lock()
|
||||
@DBActor func getBalance(account: Int32) async throws -> Int64 {
|
||||
let balance = zcashlc_get_balance(dbData.0, dbData.1, account, networkType.networkId)
|
||||
globalDBLock.unlock()
|
||||
|
||||
guard balance >= 0 else {
|
||||
throw ZcashError.rustGetBalance(Int(account), lastErrorMessage(fallback: "Error getting total balance from account \(account)"))
|
||||
|
@ -150,15 +140,13 @@ actor ZcashRustBackend: ZcashRustBackendWelding {
|
|||
return balance
|
||||
}
|
||||
|
||||
func getCurrentAddress(account: Int32) async throws -> UnifiedAddress {
|
||||
globalDBLock.lock()
|
||||
@DBActor func getCurrentAddress(account: Int32) async throws -> UnifiedAddress {
|
||||
let addressCStr = zcashlc_get_current_address(
|
||||
dbData.0,
|
||||
dbData.1,
|
||||
account,
|
||||
networkType.networkId
|
||||
)
|
||||
globalDBLock.unlock()
|
||||
|
||||
guard let addressCStr else {
|
||||
throw ZcashError.rustGetCurrentAddress(lastErrorMessage(fallback: "`getCurrentAddress` failed with unknown error"))
|
||||
|
@ -173,15 +161,13 @@ actor ZcashRustBackend: ZcashRustBackendWelding {
|
|||
return UnifiedAddress(validatedEncoding: address, networkType: networkType)
|
||||
}
|
||||
|
||||
func getNearestRewindHeight(height: Int32) async throws -> Int32 {
|
||||
globalDBLock.lock()
|
||||
@DBActor func getNearestRewindHeight(height: Int32) async throws -> Int32 {
|
||||
let result = zcashlc_get_nearest_rewind_height(
|
||||
dbData.0,
|
||||
dbData.1,
|
||||
height,
|
||||
networkType.networkId
|
||||
)
|
||||
globalDBLock.unlock()
|
||||
|
||||
guard result > 0 else {
|
||||
throw ZcashError.rustGetNearestRewindHeight(lastErrorMessage(fallback: "`getNearestRewindHeight` failed with unknown error"))
|
||||
|
@ -190,15 +176,13 @@ actor ZcashRustBackend: ZcashRustBackendWelding {
|
|||
return result
|
||||
}
|
||||
|
||||
func getNextAvailableAddress(account: Int32) async throws -> UnifiedAddress {
|
||||
globalDBLock.lock()
|
||||
@DBActor func getNextAvailableAddress(account: Int32) async throws -> UnifiedAddress {
|
||||
let addressCStr = zcashlc_get_next_available_address(
|
||||
dbData.0,
|
||||
dbData.1,
|
||||
account,
|
||||
networkType.networkId
|
||||
)
|
||||
globalDBLock.unlock()
|
||||
|
||||
guard let addressCStr else {
|
||||
throw ZcashError.rustGetNextAvailableAddress(lastErrorMessage(fallback: "`getNextAvailableAddress` failed with unknown error"))
|
||||
|
@ -213,7 +197,7 @@ actor ZcashRustBackend: ZcashRustBackendWelding {
|
|||
return UnifiedAddress(validatedEncoding: address, networkType: networkType)
|
||||
}
|
||||
|
||||
func getMemo(txId: Data, outputIndex: UInt16) async throws -> Memo? {
|
||||
@DBActor func getMemo(txId: Data, outputIndex: UInt16) async throws -> Memo? {
|
||||
guard txId.count == 32 else {
|
||||
throw ZcashError.rustGetMemoInvalidTxIdLength
|
||||
}
|
||||
|
@ -221,30 +205,26 @@ actor ZcashRustBackend: ZcashRustBackendWelding {
|
|||
var contiguousMemoBytes = ContiguousArray<UInt8>(MemoBytes.empty().bytes)
|
||||
var success = false
|
||||
|
||||
globalDBLock.lock()
|
||||
contiguousMemoBytes.withUnsafeMutableBufferPointer { memoBytePtr in
|
||||
success = zcashlc_get_memo(dbData.0, dbData.1, txId.bytes, outputIndex, memoBytePtr.baseAddress, networkType.networkId)
|
||||
}
|
||||
globalDBLock.unlock()
|
||||
|
||||
guard success else { return nil }
|
||||
|
||||
return (try? MemoBytes(contiguousBytes: contiguousMemoBytes)).flatMap { try? $0.intoMemo() }
|
||||
}
|
||||
|
||||
func getTransparentBalance(account: Int32) async throws -> Int64 {
|
||||
@DBActor func getTransparentBalance(account: Int32) async throws -> Int64 {
|
||||
guard account >= 0 else {
|
||||
throw ZcashError.rustGetTransparentBalanceNegativeAccount(Int(account))
|
||||
}
|
||||
|
||||
globalDBLock.lock()
|
||||
let balance = zcashlc_get_total_transparent_balance_for_account(
|
||||
dbData.0,
|
||||
dbData.1,
|
||||
networkType.networkId,
|
||||
account
|
||||
)
|
||||
globalDBLock.unlock()
|
||||
|
||||
guard balance >= 0 else {
|
||||
throw ZcashError.rustGetTransparentBalance(
|
||||
|
@ -256,8 +236,7 @@ actor ZcashRustBackend: ZcashRustBackendWelding {
|
|||
return balance
|
||||
}
|
||||
|
||||
func getVerifiedBalance(account: Int32) async throws -> Int64 {
|
||||
globalDBLock.lock()
|
||||
@DBActor func getVerifiedBalance(account: Int32) async throws -> Int64 {
|
||||
let balance = zcashlc_get_verified_balance(
|
||||
dbData.0,
|
||||
dbData.1,
|
||||
|
@ -265,7 +244,6 @@ actor ZcashRustBackend: ZcashRustBackendWelding {
|
|||
networkType.networkId,
|
||||
minimumConfirmations
|
||||
)
|
||||
globalDBLock.unlock()
|
||||
|
||||
guard balance >= 0 else {
|
||||
throw ZcashError.rustGetVerifiedBalance(
|
||||
|
@ -277,12 +255,11 @@ actor ZcashRustBackend: ZcashRustBackendWelding {
|
|||
return balance
|
||||
}
|
||||
|
||||
func getVerifiedTransparentBalance(account: Int32) async throws -> Int64 {
|
||||
@DBActor func getVerifiedTransparentBalance(account: Int32) async throws -> Int64 {
|
||||
guard account >= 0 else {
|
||||
throw ZcashError.rustGetVerifiedTransparentBalanceNegativeAccount(Int(account))
|
||||
}
|
||||
|
||||
globalDBLock.lock()
|
||||
let balance = zcashlc_get_verified_transparent_balance_for_account(
|
||||
dbData.0,
|
||||
dbData.1,
|
||||
|
@ -290,7 +267,6 @@ actor ZcashRustBackend: ZcashRustBackendWelding {
|
|||
account,
|
||||
minimumConfirmations
|
||||
)
|
||||
globalDBLock.unlock()
|
||||
|
||||
guard balance >= 0 else {
|
||||
throw ZcashError.rustGetVerifiedTransparentBalance(
|
||||
|
@ -302,10 +278,8 @@ actor ZcashRustBackend: ZcashRustBackendWelding {
|
|||
return balance
|
||||
}
|
||||
|
||||
func initDataDb(seed: [UInt8]?) async throws -> DbInitResult {
|
||||
globalDBLock.lock()
|
||||
@DBActor func initDataDb(seed: [UInt8]?) async throws -> DbInitResult {
|
||||
let initResult = zcashlc_init_data_database(dbData.0, dbData.1, seed, UInt(seed?.count ?? 0), networkType.networkId)
|
||||
globalDBLock.unlock()
|
||||
|
||||
switch initResult {
|
||||
case 0: // ok
|
||||
|
@ -317,17 +291,15 @@ actor ZcashRustBackend: ZcashRustBackendWelding {
|
|||
}
|
||||
}
|
||||
|
||||
func initBlockMetadataDb() async throws {
|
||||
globalDBLock.lock()
|
||||
@DBActor func initBlockMetadataDb() async throws {
|
||||
let result = zcashlc_init_block_metadata_db(fsBlockDbRoot.0, fsBlockDbRoot.1)
|
||||
globalDBLock.unlock()
|
||||
|
||||
guard result else {
|
||||
throw ZcashError.rustInitBlockMetadataDb(lastErrorMessage(fallback: "`initBlockMetadataDb` failed with unknown error"))
|
||||
}
|
||||
}
|
||||
|
||||
func writeBlocksMetadata(blocks: [ZcashCompactBlock]) async throws {
|
||||
@DBActor func writeBlocksMetadata(blocks: [ZcashCompactBlock]) async throws {
|
||||
var ffiBlockMetaVec: [FFIBlockMeta] = []
|
||||
|
||||
for block in blocks {
|
||||
|
@ -376,9 +348,7 @@ actor ZcashRustBackend: ZcashRustBackendWelding {
|
|||
|
||||
fsBlocks.initialize(to: meta)
|
||||
|
||||
globalDBLock.lock()
|
||||
let res = zcashlc_write_block_metadata(fsBlockDbRoot.0, fsBlockDbRoot.1, fsBlocks)
|
||||
globalDBLock.unlock()
|
||||
|
||||
guard res else {
|
||||
throw ZcashError.rustWriteBlocksMetadata(lastErrorMessage(fallback: "`writeBlocksMetadata` failed with unknown error"))
|
||||
|
@ -386,10 +356,8 @@ actor ZcashRustBackend: ZcashRustBackendWelding {
|
|||
}
|
||||
}
|
||||
|
||||
func latestCachedBlockHeight() async throws -> BlockHeight {
|
||||
globalDBLock.lock()
|
||||
@DBActor func latestCachedBlockHeight() async throws -> BlockHeight {
|
||||
let height = zcashlc_latest_cached_block_height(fsBlockDbRoot.0, fsBlockDbRoot.1)
|
||||
globalDBLock.unlock()
|
||||
|
||||
if height >= 0 {
|
||||
return BlockHeight(height)
|
||||
|
@ -400,15 +368,13 @@ actor ZcashRustBackend: ZcashRustBackendWelding {
|
|||
}
|
||||
}
|
||||
|
||||
func listTransparentReceivers(account: Int32) async throws -> [TransparentAddress] {
|
||||
globalDBLock.lock()
|
||||
@DBActor func listTransparentReceivers(account: Int32) async throws -> [TransparentAddress] {
|
||||
let encodedKeysPtr = zcashlc_list_transparent_receivers(
|
||||
dbData.0,
|
||||
dbData.1,
|
||||
account,
|
||||
networkType.networkId
|
||||
)
|
||||
globalDBLock.unlock()
|
||||
|
||||
guard let encodedKeysPtr else {
|
||||
throw ZcashError.rustListTransparentReceivers(lastErrorMessage(fallback: "`listTransparentReceivers` failed with unknown error"))
|
||||
|
@ -433,14 +399,13 @@ actor ZcashRustBackend: ZcashRustBackendWelding {
|
|||
return addresses
|
||||
}
|
||||
|
||||
func putUnspentTransparentOutput(
|
||||
@DBActor func putUnspentTransparentOutput(
|
||||
txid: [UInt8],
|
||||
index: Int,
|
||||
script: [UInt8],
|
||||
value: Int64,
|
||||
height: BlockHeight
|
||||
) async throws {
|
||||
globalDBLock.lock()
|
||||
let result = zcashlc_put_utxo(
|
||||
dbData.0,
|
||||
dbData.1,
|
||||
|
@ -453,34 +418,29 @@ actor ZcashRustBackend: ZcashRustBackendWelding {
|
|||
Int32(height),
|
||||
networkType.networkId
|
||||
)
|
||||
globalDBLock.unlock()
|
||||
|
||||
guard result else {
|
||||
throw ZcashError.rustPutUnspentTransparentOutput(lastErrorMessage(fallback: "`putUnspentTransparentOutput` failed with unknown error"))
|
||||
}
|
||||
}
|
||||
|
||||
func rewindToHeight(height: Int32) async throws {
|
||||
globalDBLock.lock()
|
||||
@DBActor func rewindToHeight(height: Int32) async throws {
|
||||
let result = zcashlc_rewind_to_height(dbData.0, dbData.1, height, networkType.networkId)
|
||||
globalDBLock.unlock()
|
||||
|
||||
guard result else {
|
||||
throw ZcashError.rustRewindToHeight(height, lastErrorMessage(fallback: "`rewindToHeight` failed with unknown error"))
|
||||
}
|
||||
}
|
||||
|
||||
func rewindCacheToHeight(height: Int32) async throws {
|
||||
globalDBLock.lock()
|
||||
@DBActor func rewindCacheToHeight(height: Int32) async throws {
|
||||
let result = zcashlc_rewind_fs_block_cache_to_height(fsBlockDbRoot.0, fsBlockDbRoot.1, height)
|
||||
globalDBLock.unlock()
|
||||
|
||||
guard result else {
|
||||
throw ZcashError.rustRewindCacheToHeight(lastErrorMessage(fallback: "`rewindCacheToHeight` failed with unknown error"))
|
||||
}
|
||||
}
|
||||
|
||||
func putSaplingSubtreeRoots(startIndex: UInt64, roots: [SubtreeRoot]) async throws {
|
||||
@DBActor func putSaplingSubtreeRoots(startIndex: UInt64, roots: [SubtreeRoot]) async throws {
|
||||
var ffiSubtreeRootsVec: [FfiSubtreeRoot] = []
|
||||
|
||||
for root in roots {
|
||||
|
@ -528,9 +488,7 @@ actor ZcashRustBackend: ZcashRustBackendWelding {
|
|||
|
||||
rootsPtr.initialize(to: roots)
|
||||
|
||||
globalDBLock.lock()
|
||||
let res = zcashlc_put_sapling_subtree_roots(dbData.0, dbData.1, startIndex, rootsPtr, networkType.networkId)
|
||||
globalDBLock.unlock()
|
||||
|
||||
guard res else {
|
||||
throw ZcashError.rustPutSaplingSubtreeRoots(lastErrorMessage(fallback: "`putSaplingSubtreeRoots` failed with unknown error"))
|
||||
|
@ -538,20 +496,16 @@ actor ZcashRustBackend: ZcashRustBackendWelding {
|
|||
}
|
||||
}
|
||||
|
||||
func updateChainTip(height: Int32) async throws {
|
||||
globalDBLock.lock()
|
||||
@DBActor func updateChainTip(height: Int32) async throws {
|
||||
let result = zcashlc_update_chain_tip(dbData.0, dbData.1, height, networkType.networkId)
|
||||
globalDBLock.unlock()
|
||||
|
||||
guard result else {
|
||||
throw ZcashError.rustUpdateChainTip(lastErrorMessage(fallback: "`updateChainTip` failed with unknown error"))
|
||||
}
|
||||
}
|
||||
|
||||
func fullyScannedHeight() async throws -> BlockHeight? {
|
||||
globalDBLock.lock()
|
||||
@DBActor func fullyScannedHeight() async throws -> BlockHeight? {
|
||||
let height = zcashlc_fully_scanned_height(dbData.0, dbData.1, networkType.networkId)
|
||||
globalDBLock.unlock()
|
||||
|
||||
if height >= 0 {
|
||||
return BlockHeight(height)
|
||||
|
@ -562,10 +516,8 @@ actor ZcashRustBackend: ZcashRustBackendWelding {
|
|||
}
|
||||
}
|
||||
|
||||
func maxScannedHeight() async throws -> BlockHeight? {
|
||||
globalDBLock.lock()
|
||||
@DBActor func maxScannedHeight() async throws -> BlockHeight? {
|
||||
let height = zcashlc_max_scanned_height(dbData.0, dbData.1, networkType.networkId)
|
||||
globalDBLock.unlock()
|
||||
|
||||
if height >= 0 {
|
||||
return BlockHeight(height)
|
||||
|
@ -576,10 +528,8 @@ actor ZcashRustBackend: ZcashRustBackendWelding {
|
|||
}
|
||||
}
|
||||
|
||||
func getScanProgress() async throws -> ScanProgress? {
|
||||
globalDBLock.lock()
|
||||
@DBActor func getScanProgress() async throws -> ScanProgress? {
|
||||
let result = zcashlc_get_scan_progress(dbData.0, dbData.1, networkType.networkId)
|
||||
globalDBLock.unlock()
|
||||
|
||||
if result.denominator == 0 {
|
||||
switch result.numerator {
|
||||
|
@ -593,10 +543,8 @@ actor ZcashRustBackend: ZcashRustBackendWelding {
|
|||
}
|
||||
}
|
||||
|
||||
func suggestScanRanges() async throws -> [ScanRange] {
|
||||
globalDBLock.lock()
|
||||
@DBActor func suggestScanRanges() async throws -> [ScanRange] {
|
||||
let scanRangesPtr = zcashlc_suggest_scan_ranges(dbData.0, dbData.1, networkType.networkId)
|
||||
globalDBLock.unlock()
|
||||
|
||||
guard let scanRangesPtr else {
|
||||
throw ZcashError.rustSuggestScanRanges(lastErrorMessage(fallback: "`suggestScanRanges` failed with unknown error"))
|
||||
|
@ -623,24 +571,21 @@ actor ZcashRustBackend: ZcashRustBackendWelding {
|
|||
return scanRanges
|
||||
}
|
||||
|
||||
func scanBlocks(fromHeight: Int32, limit: UInt32 = 0) async throws {
|
||||
globalDBLock.lock()
|
||||
@DBActor func scanBlocks(fromHeight: Int32, limit: UInt32 = 0) async throws {
|
||||
let result = zcashlc_scan_blocks(fsBlockDbRoot.0, fsBlockDbRoot.1, dbData.0, dbData.1, fromHeight, limit, networkType.networkId)
|
||||
globalDBLock.unlock()
|
||||
|
||||
guard result != 0 else {
|
||||
throw ZcashError.rustScanBlocks(lastErrorMessage(fallback: "`scanBlocks` failed with unknown error"))
|
||||
}
|
||||
}
|
||||
|
||||
func shieldFunds(
|
||||
@DBActor func shieldFunds(
|
||||
usk: UnifiedSpendingKey,
|
||||
memo: MemoBytes?,
|
||||
shieldingThreshold: Zatoshi
|
||||
) async throws -> Data {
|
||||
var contiguousTxIdBytes = ContiguousArray<UInt8>([UInt8](repeating: 0x0, count: 32))
|
||||
|
||||
globalDBLock.lock()
|
||||
let success = contiguousTxIdBytes.withUnsafeMutableBufferPointer { txIdBytePtr in
|
||||
usk.bytes.withUnsafeBufferPointer { uskBuffer in
|
||||
zcashlc_shield_funds(
|
||||
|
@ -661,7 +606,6 @@ actor ZcashRustBackend: ZcashRustBackendWelding {
|
|||
)
|
||||
}
|
||||
}
|
||||
globalDBLock.unlock()
|
||||
|
||||
guard success else {
|
||||
throw ZcashError.rustShieldFunds(lastErrorMessage(fallback: "`shieldFunds` failed with unknown error"))
|
||||
|
@ -672,7 +616,7 @@ actor ZcashRustBackend: ZcashRustBackendWelding {
|
|||
}
|
||||
}
|
||||
|
||||
nonisolated func consensusBranchIdFor(height: Int32) throws -> Int32 {
|
||||
func consensusBranchIdFor(height: Int32) throws -> Int32 {
|
||||
let branchId = zcashlc_branch_id_for_height(height, networkType.networkId)
|
||||
|
||||
guard branchId != -1 else {
|
||||
|
|
|
@ -18,7 +18,6 @@ public enum DbInitResult {
|
|||
case seedRequired
|
||||
}
|
||||
|
||||
// sourcery: mockActor
|
||||
protocol ZcashRustBackendWelding {
|
||||
/// Adds the next available account-level spend authority, given the current set of [ZIP 316]
|
||||
/// account identifiers known, to the wallet database.
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
//
|
||||
// DBActor.swift
|
||||
//
|
||||
//
|
||||
// Created by Michal Fousek on 07.12.2023.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
/// Global actor used to protect access to the Data DB.
|
||||
@globalActor
|
||||
enum DBActor {
|
||||
actor Actor { }
|
||||
typealias ActorType = Actor
|
||||
static let shared = Actor()
|
||||
static var sharedUnownedExecutor: UnownedSerialExecutor { shared.unownedExecutor }
|
||||
}
|
|
@ -104,8 +104,8 @@ class CompactBlockReorgTests: ZcashTestCase {
|
|||
loggingPolicy: .default(.debug)
|
||||
)
|
||||
|
||||
await self.rustBackendMockHelper.rustBackendMock.setPutSaplingSubtreeRootsStartIndexRootsClosure { _, _ in }
|
||||
await self.rustBackendMockHelper.rustBackendMock.setUpdateChainTipHeightClosure { _ in }
|
||||
self.rustBackendMockHelper.rustBackendMock.putSaplingSubtreeRootsStartIndexRootsClosure = { _, _ in }
|
||||
self.rustBackendMockHelper.rustBackendMock.updateChainTipHeightClosure = { _ in }
|
||||
|
||||
mockContainer.mock(type: LatestBlocksDataProvider.self, isSingleton: true) { [self] _ in
|
||||
LatestBlocksDataProviderImpl(service: service, rustBackend: self.rustBackend)
|
||||
|
|
|
@ -67,7 +67,11 @@ class CheckpointSourceTests: XCTestCase {
|
|||
height: 1520000,
|
||||
hash: "0014a50344a6a43b02421286f6db15dad50cea54f3f0858f044ad0f1b845c395",
|
||||
time: 1628358967,
|
||||
saplingTree: "017d0620dbe96cb488e44dccfde260cf599c23c4ca689589d2e1ad743ec6770a6d00100000000000000000000001bab80e68a5c63460d1e5c94ef540940792fa4703fa488b09fdfded97f8ec8a3d00013d2fd009bf8a22d68f720eac19c411c99014ed9c5f85d5942e15d1fc039e28680001f08f39275112dd8905b854170b7f247cf2df18454d4fa94e6e4f9320cca05f24011f8322ef806eb2430dc4a7a41c1b344bea5be946efc7b4349c1c9edb14ff9d39",
|
||||
saplingTree: """
|
||||
017d0620dbe96cb488e44dccfde260cf599c23c4ca689589d2e1ad743ec6770a6d00100000000000000000000001bab80e68a5c63460d1e5c94ef540940792fa4703fa48\
|
||||
8b09fdfded97f8ec8a3d00013d2fd009bf8a22d68f720eac19c411c99014ed9c5f85d5942e15d1fc039e28680001f08f39275112dd8905b854170b7f247cf2df18454d4f\
|
||||
a94e6e4f9320cca05f24011f8322ef806eb2430dc4a7a41c1b344bea5be946efc7b4349c1c9edb14ff9d39
|
||||
""",
|
||||
orchardTree: nil
|
||||
)
|
||||
|
||||
|
|
|
@ -54,7 +54,7 @@ final class ActionContextStateTests: ZcashTestCase {
|
|||
|
||||
XCTAssertEqual(
|
||||
contextLastEnhancedHeightAfterReset,
|
||||
1_500_000,
|
||||
1_500_000,
|
||||
"""
|
||||
testActionContextReset_DefaultBehaviour: The context after reset should restore the last enhanced height,
|
||||
received \(String(describing: contextLastEnhancedHeightAfterReset)) instead
|
||||
|
|
|
@ -30,8 +30,8 @@ final class ProcessSuggestedScanRangesActionTests: ZcashTestCase {
|
|||
loggerMock.infoFileFunctionLineClosure = { _, _, _, _ in }
|
||||
|
||||
let tupple = setupAction(loggerMock)
|
||||
await tupple.rustBackendMock.setSuggestScanRangesClosure({ [] })
|
||||
|
||||
tupple.rustBackendMock.suggestScanRangesClosure = { [] }
|
||||
|
||||
let processSuggestedScanRangesActionAction = tupple.action
|
||||
|
||||
do {
|
||||
|
@ -58,9 +58,9 @@ final class ProcessSuggestedScanRangesActionTests: ZcashTestCase {
|
|||
loggerMock.debugFileFunctionLineClosure = { _, _, _, _ in }
|
||||
|
||||
let tupple = setupAction(loggerMock)
|
||||
await tupple.rustBackendMock.setSuggestScanRangesClosure({ [
|
||||
tupple.rustBackendMock.suggestScanRangesClosure = { [
|
||||
ScanRange(range: 0..<10, priority: .chainTip)
|
||||
] })
|
||||
] }
|
||||
|
||||
let processSuggestedScanRangesActionAction = tupple.action
|
||||
|
||||
|
@ -119,12 +119,11 @@ final class ProcessSuggestedScanRangesActionTests: ZcashTestCase {
|
|||
for: ZcashNetworkBuilder.network(for: underlyingNetworkType), walletBirthday: 0
|
||||
)
|
||||
|
||||
let rustBackendMock = ZcashRustBackendWeldingMock(
|
||||
consensusBranchIdForHeightClosure: { height in
|
||||
XCTAssertEqual(height, 2, "")
|
||||
return -1026109260
|
||||
}
|
||||
)
|
||||
let rustBackendMock = ZcashRustBackendWeldingMock()
|
||||
rustBackendMock.consensusBranchIdForHeightClosure = { height in
|
||||
XCTAssertEqual(height, 2, "")
|
||||
return -1026109260
|
||||
}
|
||||
|
||||
let lightWalletdInfoMock = LightWalletdInfoMock()
|
||||
lightWalletdInfoMock.underlyingConsensusBranchID = underlyingConsensusBranchID
|
||||
|
|
|
@ -92,15 +92,14 @@ final class RewindActionTests: ZcashTestCase {
|
|||
_ loggerMock: LoggerMock = LoggerMock(),
|
||||
_ blockDownloaderServiceMock: BlockDownloaderServiceMock = BlockDownloaderServiceMock()
|
||||
) async -> RewindAction {
|
||||
let rustBackendMock = ZcashRustBackendWeldingMock(
|
||||
consensusBranchIdForHeightClosure: { height in
|
||||
XCTAssertEqual(height, 2, "")
|
||||
return -1026109260
|
||||
}
|
||||
)
|
||||
|
||||
await rustBackendMock.setRewindToHeightHeightClosure({ _ in })
|
||||
let rustBackendMock = ZcashRustBackendWeldingMock()
|
||||
rustBackendMock.consensusBranchIdForHeightClosure = { height in
|
||||
XCTAssertEqual(height, 2, "")
|
||||
return -1026109260
|
||||
}
|
||||
|
||||
rustBackendMock.rewindToHeightHeightClosure = { _ in }
|
||||
|
||||
mockContainer.mock(type: ZcashRustBackendWelding.self, isSingleton: true) { _ in rustBackendMock }
|
||||
mockContainer.mock(type: BlockDownloaderService.self, isSingleton: true) { _ in blockDownloaderServiceMock }
|
||||
mockContainer.mock(type: BlockDownloader.self, isSingleton: true) { _ in blockDownloaderMock }
|
||||
|
|
|
@ -133,12 +133,11 @@ final class ScanActionTests: ZcashTestCase {
|
|||
_ loggerMock: LoggerMock,
|
||||
_ latestBlocksDataProvider: LatestBlocksDataProvider = LatestBlocksDataProviderMock()
|
||||
) -> ScanAction {
|
||||
let rustBackendMock = ZcashRustBackendWeldingMock(
|
||||
consensusBranchIdForHeightClosure: { height in
|
||||
XCTAssertEqual(height, 2, "")
|
||||
return -1026109260
|
||||
}
|
||||
)
|
||||
let rustBackendMock = ZcashRustBackendWeldingMock()
|
||||
rustBackendMock.consensusBranchIdForHeightClosure = { height in
|
||||
XCTAssertEqual(height, 2, "")
|
||||
return -1026109260
|
||||
}
|
||||
|
||||
mockContainer.mock(type: ZcashRustBackendWelding.self, isSingleton: true) { _ in rustBackendMock }
|
||||
mockContainer.mock(type: BlockScanner.self, isSingleton: true) { _ in blockScannerMock }
|
||||
|
|
|
@ -115,14 +115,13 @@ final class UpdateChainTipActionTests: ZcashTestCase {
|
|||
for: ZcashNetworkBuilder.network(for: underlyingNetworkType), walletBirthday: 0
|
||||
)
|
||||
|
||||
let rustBackendMock = ZcashRustBackendWeldingMock(
|
||||
consensusBranchIdForHeightClosure: { height in
|
||||
XCTAssertEqual(height, 2, "")
|
||||
return -1026109260
|
||||
}
|
||||
)
|
||||
let rustBackendMock = ZcashRustBackendWeldingMock()
|
||||
rustBackendMock.consensusBranchIdForHeightClosure = { height in
|
||||
XCTAssertEqual(height, 2, "")
|
||||
return -1026109260
|
||||
}
|
||||
|
||||
await rustBackendMock.setUpdateChainTipHeightClosure({ _ in })
|
||||
rustBackendMock.updateChainTipHeightClosure = { _ in }
|
||||
|
||||
let lightWalletdInfoMock = LightWalletdInfoMock()
|
||||
lightWalletdInfoMock.underlyingConsensusBranchID = underlyingConsensusBranchID
|
||||
|
|
|
@ -70,7 +70,7 @@ final class UpdateSubtreeRootsActionTests: ZcashTestCase {
|
|||
continuation.finish()
|
||||
}
|
||||
}
|
||||
await tupple.rustBackendMock.setPutSaplingSubtreeRootsStartIndexRootsClosure({ _, _ in })
|
||||
tupple.rustBackendMock.putSaplingSubtreeRootsStartIndexRootsClosure = { _, _ in }
|
||||
|
||||
do {
|
||||
let context = ActionContextMock.default()
|
||||
|
@ -100,7 +100,7 @@ final class UpdateSubtreeRootsActionTests: ZcashTestCase {
|
|||
continuation.finish()
|
||||
}
|
||||
}
|
||||
await tupple.rustBackendMock.setPutSaplingSubtreeRootsStartIndexRootsThrowableError("putSaplingFailed")
|
||||
tupple.rustBackendMock.putSaplingSubtreeRootsStartIndexRootsThrowableError = "putSaplingFailed"
|
||||
|
||||
do {
|
||||
let context = ActionContextMock.default()
|
||||
|
@ -127,12 +127,11 @@ final class UpdateSubtreeRootsActionTests: ZcashTestCase {
|
|||
for: ZcashNetworkBuilder.network(for: underlyingNetworkType), walletBirthday: 0
|
||||
)
|
||||
|
||||
let rustBackendMock = ZcashRustBackendWeldingMock(
|
||||
consensusBranchIdForHeightClosure: { height in
|
||||
XCTAssertEqual(height, 2, "")
|
||||
return -1026109260
|
||||
}
|
||||
)
|
||||
let rustBackendMock = ZcashRustBackendWeldingMock()
|
||||
rustBackendMock.consensusBranchIdForHeightClosure = { height in
|
||||
XCTAssertEqual(height, 2, "")
|
||||
return -1026109260
|
||||
}
|
||||
|
||||
let lightWalletdInfoMock = LightWalletdInfoMock()
|
||||
lightWalletdInfoMock.underlyingConsensusBranchID = underlyingConsensusBranchID
|
||||
|
|
|
@ -135,12 +135,11 @@ final class ValidateServerActionTests: ZcashTestCase {
|
|||
for: ZcashNetworkBuilder.network(for: underlyingNetworkType), walletBirthday: 0
|
||||
)
|
||||
|
||||
let rustBackendMock = ZcashRustBackendWeldingMock(
|
||||
consensusBranchIdForHeightClosure: { height in
|
||||
XCTAssertEqual(height, 2, "")
|
||||
return -1026109260
|
||||
}
|
||||
)
|
||||
let rustBackendMock = ZcashRustBackendWeldingMock()
|
||||
rustBackendMock.consensusBranchIdForHeightClosure = { height in
|
||||
XCTAssertEqual(height, 2, "")
|
||||
return -1026109260
|
||||
}
|
||||
|
||||
let lightWalletdInfoMock = LightWalletdInfoMock()
|
||||
lightWalletdInfoMock.underlyingConsensusBranchID = underlyingConsensusBranchID
|
||||
|
|
|
@ -414,7 +414,7 @@ final class FsBlockStorageTests: ZcashTestCase {
|
|||
return
|
||||
}
|
||||
let mockBackend = await RustBackendMockHelper(rustBackend: rustBackend)
|
||||
await mockBackend.rustBackendMock.setWriteBlocksMetadataBlocksThrowableError(ZcashError.rustWriteBlocksMetadataAllocationProblem)
|
||||
mockBackend.rustBackendMock.writeBlocksMetadataBlocksThrowableError = ZcashError.rustWriteBlocksMetadataAllocationProblem
|
||||
|
||||
do {
|
||||
try await FSMetadataStore.saveBlocksMeta(
|
||||
|
@ -434,7 +434,7 @@ final class FsBlockStorageTests: ZcashTestCase {
|
|||
let expectedHeight = BlockHeight(1000)
|
||||
|
||||
let mockBackend = await RustBackendMockHelper(rustBackend: rustBackend)
|
||||
await mockBackend.rustBackendMock.setRewindCacheToHeightHeightThrowableError(ZcashError.rustRewindToHeight(Int32(expectedHeight), "oops"))
|
||||
mockBackend.rustBackendMock.rewindCacheToHeightHeightThrowableError = ZcashError.rustRewindToHeight(Int32(expectedHeight), "oops")
|
||||
|
||||
do {
|
||||
try await FSMetadataStore.live(
|
||||
|
|
|
@ -2046,35 +2046,23 @@ class ZcashFileManagerMock: ZcashFileManager {
|
|||
}
|
||||
|
||||
}
|
||||
actor ZcashRustBackendWeldingMock: ZcashRustBackendWelding {
|
||||
class ZcashRustBackendWeldingMock: ZcashRustBackendWelding {
|
||||
|
||||
nonisolated let consensusBranchIdForHeightClosure: ((Int32) throws -> Int32)?
|
||||
|
||||
init(
|
||||
consensusBranchIdForHeightClosure: ((Int32) throws -> Int32)? = nil
|
||||
) {
|
||||
self.consensusBranchIdForHeightClosure = consensusBranchIdForHeightClosure
|
||||
}
|
||||
|
||||
// MARK: - createAccount
|
||||
|
||||
var createAccountSeedTreeStateRecoverUntilThrowableError: Error?
|
||||
func setCreateAccountSeedTreeStateRecoverUntilThrowableError(_ param: Error?) async {
|
||||
createAccountSeedTreeStateRecoverUntilThrowableError = param
|
||||
}
|
||||
var createAccountSeedTreeStateRecoverUntilCallsCount = 0
|
||||
var createAccountSeedTreeStateRecoverUntilCalled: Bool {
|
||||
return createAccountSeedTreeStateRecoverUntilCallsCount > 0
|
||||
}
|
||||
var createAccountSeedTreeStateRecoverUntilReceivedArguments: (seed: [UInt8], treeState: TreeState, recoverUntil: UInt32?)?
|
||||
var createAccountSeedTreeStateRecoverUntilReturnValue: UnifiedSpendingKey!
|
||||
func setCreateAccountSeedTreeStateRecoverUntilReturnValue(_ param: UnifiedSpendingKey) async {
|
||||
createAccountSeedTreeStateRecoverUntilReturnValue = param
|
||||
}
|
||||
var createAccountSeedTreeStateRecoverUntilClosure: (([UInt8], TreeState, UInt32?) async throws -> UnifiedSpendingKey)?
|
||||
func setCreateAccountSeedTreeStateRecoverUntilClosure(_ param: (([UInt8], TreeState, UInt32?) async throws -> UnifiedSpendingKey)?) async {
|
||||
createAccountSeedTreeStateRecoverUntilClosure = param
|
||||
}
|
||||
|
||||
func createAccount(seed: [UInt8], treeState: TreeState, recoverUntil: UInt32?) async throws -> UnifiedSpendingKey {
|
||||
if let error = createAccountSeedTreeStateRecoverUntilThrowableError {
|
||||
|
@ -2092,22 +2080,13 @@ actor ZcashRustBackendWeldingMock: ZcashRustBackendWelding {
|
|||
// MARK: - createToAddress
|
||||
|
||||
var createToAddressUskToValueMemoThrowableError: Error?
|
||||
func setCreateToAddressUskToValueMemoThrowableError(_ param: Error?) async {
|
||||
createToAddressUskToValueMemoThrowableError = param
|
||||
}
|
||||
var createToAddressUskToValueMemoCallsCount = 0
|
||||
var createToAddressUskToValueMemoCalled: Bool {
|
||||
return createToAddressUskToValueMemoCallsCount > 0
|
||||
}
|
||||
var createToAddressUskToValueMemoReceivedArguments: (usk: UnifiedSpendingKey, address: String, value: Int64, memo: MemoBytes?)?
|
||||
var createToAddressUskToValueMemoReturnValue: Data!
|
||||
func setCreateToAddressUskToValueMemoReturnValue(_ param: Data) async {
|
||||
createToAddressUskToValueMemoReturnValue = param
|
||||
}
|
||||
var createToAddressUskToValueMemoClosure: ((UnifiedSpendingKey, String, Int64, MemoBytes?) async throws -> Data)?
|
||||
func setCreateToAddressUskToValueMemoClosure(_ param: ((UnifiedSpendingKey, String, Int64, MemoBytes?) async throws -> Data)?) async {
|
||||
createToAddressUskToValueMemoClosure = param
|
||||
}
|
||||
|
||||
func createToAddress(usk: UnifiedSpendingKey, to address: String, value: Int64, memo: MemoBytes?) async throws -> Data {
|
||||
if let error = createToAddressUskToValueMemoThrowableError {
|
||||
|
@ -2125,18 +2104,12 @@ actor ZcashRustBackendWeldingMock: ZcashRustBackendWelding {
|
|||
// MARK: - decryptAndStoreTransaction
|
||||
|
||||
var decryptAndStoreTransactionTxBytesMinedHeightThrowableError: Error?
|
||||
func setDecryptAndStoreTransactionTxBytesMinedHeightThrowableError(_ param: Error?) async {
|
||||
decryptAndStoreTransactionTxBytesMinedHeightThrowableError = param
|
||||
}
|
||||
var decryptAndStoreTransactionTxBytesMinedHeightCallsCount = 0
|
||||
var decryptAndStoreTransactionTxBytesMinedHeightCalled: Bool {
|
||||
return decryptAndStoreTransactionTxBytesMinedHeightCallsCount > 0
|
||||
}
|
||||
var decryptAndStoreTransactionTxBytesMinedHeightReceivedArguments: (txBytes: [UInt8], minedHeight: Int32)?
|
||||
var decryptAndStoreTransactionTxBytesMinedHeightClosure: (([UInt8], Int32) async throws -> Void)?
|
||||
func setDecryptAndStoreTransactionTxBytesMinedHeightClosure(_ param: (([UInt8], Int32) async throws -> Void)?) async {
|
||||
decryptAndStoreTransactionTxBytesMinedHeightClosure = param
|
||||
}
|
||||
|
||||
func decryptAndStoreTransaction(txBytes: [UInt8], minedHeight: Int32) async throws {
|
||||
if let error = decryptAndStoreTransactionTxBytesMinedHeightThrowableError {
|
||||
|
@ -2150,22 +2123,13 @@ actor ZcashRustBackendWeldingMock: ZcashRustBackendWelding {
|
|||
// MARK: - getBalance
|
||||
|
||||
var getBalanceAccountThrowableError: Error?
|
||||
func setGetBalanceAccountThrowableError(_ param: Error?) async {
|
||||
getBalanceAccountThrowableError = param
|
||||
}
|
||||
var getBalanceAccountCallsCount = 0
|
||||
var getBalanceAccountCalled: Bool {
|
||||
return getBalanceAccountCallsCount > 0
|
||||
}
|
||||
var getBalanceAccountReceivedAccount: Int32?
|
||||
var getBalanceAccountReturnValue: Int64!
|
||||
func setGetBalanceAccountReturnValue(_ param: Int64) async {
|
||||
getBalanceAccountReturnValue = param
|
||||
}
|
||||
var getBalanceAccountClosure: ((Int32) async throws -> Int64)?
|
||||
func setGetBalanceAccountClosure(_ param: ((Int32) async throws -> Int64)?) async {
|
||||
getBalanceAccountClosure = param
|
||||
}
|
||||
|
||||
func getBalance(account: Int32) async throws -> Int64 {
|
||||
if let error = getBalanceAccountThrowableError {
|
||||
|
@ -2183,22 +2147,13 @@ actor ZcashRustBackendWeldingMock: ZcashRustBackendWelding {
|
|||
// MARK: - getCurrentAddress
|
||||
|
||||
var getCurrentAddressAccountThrowableError: Error?
|
||||
func setGetCurrentAddressAccountThrowableError(_ param: Error?) async {
|
||||
getCurrentAddressAccountThrowableError = param
|
||||
}
|
||||
var getCurrentAddressAccountCallsCount = 0
|
||||
var getCurrentAddressAccountCalled: Bool {
|
||||
return getCurrentAddressAccountCallsCount > 0
|
||||
}
|
||||
var getCurrentAddressAccountReceivedAccount: Int32?
|
||||
var getCurrentAddressAccountReturnValue: UnifiedAddress!
|
||||
func setGetCurrentAddressAccountReturnValue(_ param: UnifiedAddress) async {
|
||||
getCurrentAddressAccountReturnValue = param
|
||||
}
|
||||
var getCurrentAddressAccountClosure: ((Int32) async throws -> UnifiedAddress)?
|
||||
func setGetCurrentAddressAccountClosure(_ param: ((Int32) async throws -> UnifiedAddress)?) async {
|
||||
getCurrentAddressAccountClosure = param
|
||||
}
|
||||
|
||||
func getCurrentAddress(account: Int32) async throws -> UnifiedAddress {
|
||||
if let error = getCurrentAddressAccountThrowableError {
|
||||
|
@ -2216,22 +2171,13 @@ actor ZcashRustBackendWeldingMock: ZcashRustBackendWelding {
|
|||
// MARK: - getNearestRewindHeight
|
||||
|
||||
var getNearestRewindHeightHeightThrowableError: Error?
|
||||
func setGetNearestRewindHeightHeightThrowableError(_ param: Error?) async {
|
||||
getNearestRewindHeightHeightThrowableError = param
|
||||
}
|
||||
var getNearestRewindHeightHeightCallsCount = 0
|
||||
var getNearestRewindHeightHeightCalled: Bool {
|
||||
return getNearestRewindHeightHeightCallsCount > 0
|
||||
}
|
||||
var getNearestRewindHeightHeightReceivedHeight: Int32?
|
||||
var getNearestRewindHeightHeightReturnValue: Int32!
|
||||
func setGetNearestRewindHeightHeightReturnValue(_ param: Int32) async {
|
||||
getNearestRewindHeightHeightReturnValue = param
|
||||
}
|
||||
var getNearestRewindHeightHeightClosure: ((Int32) async throws -> Int32)?
|
||||
func setGetNearestRewindHeightHeightClosure(_ param: ((Int32) async throws -> Int32)?) async {
|
||||
getNearestRewindHeightHeightClosure = param
|
||||
}
|
||||
|
||||
func getNearestRewindHeight(height: Int32) async throws -> Int32 {
|
||||
if let error = getNearestRewindHeightHeightThrowableError {
|
||||
|
@ -2249,22 +2195,13 @@ actor ZcashRustBackendWeldingMock: ZcashRustBackendWelding {
|
|||
// MARK: - getNextAvailableAddress
|
||||
|
||||
var getNextAvailableAddressAccountThrowableError: Error?
|
||||
func setGetNextAvailableAddressAccountThrowableError(_ param: Error?) async {
|
||||
getNextAvailableAddressAccountThrowableError = param
|
||||
}
|
||||
var getNextAvailableAddressAccountCallsCount = 0
|
||||
var getNextAvailableAddressAccountCalled: Bool {
|
||||
return getNextAvailableAddressAccountCallsCount > 0
|
||||
}
|
||||
var getNextAvailableAddressAccountReceivedAccount: Int32?
|
||||
var getNextAvailableAddressAccountReturnValue: UnifiedAddress!
|
||||
func setGetNextAvailableAddressAccountReturnValue(_ param: UnifiedAddress) async {
|
||||
getNextAvailableAddressAccountReturnValue = param
|
||||
}
|
||||
var getNextAvailableAddressAccountClosure: ((Int32) async throws -> UnifiedAddress)?
|
||||
func setGetNextAvailableAddressAccountClosure(_ param: ((Int32) async throws -> UnifiedAddress)?) async {
|
||||
getNextAvailableAddressAccountClosure = param
|
||||
}
|
||||
|
||||
func getNextAvailableAddress(account: Int32) async throws -> UnifiedAddress {
|
||||
if let error = getNextAvailableAddressAccountThrowableError {
|
||||
|
@ -2282,22 +2219,13 @@ actor ZcashRustBackendWeldingMock: ZcashRustBackendWelding {
|
|||
// MARK: - getMemo
|
||||
|
||||
var getMemoTxIdOutputIndexThrowableError: Error?
|
||||
func setGetMemoTxIdOutputIndexThrowableError(_ param: Error?) async {
|
||||
getMemoTxIdOutputIndexThrowableError = param
|
||||
}
|
||||
var getMemoTxIdOutputIndexCallsCount = 0
|
||||
var getMemoTxIdOutputIndexCalled: Bool {
|
||||
return getMemoTxIdOutputIndexCallsCount > 0
|
||||
}
|
||||
var getMemoTxIdOutputIndexReceivedArguments: (txId: Data, outputIndex: UInt16)?
|
||||
var getMemoTxIdOutputIndexReturnValue: Memo?
|
||||
func setGetMemoTxIdOutputIndexReturnValue(_ param: Memo?) async {
|
||||
getMemoTxIdOutputIndexReturnValue = param
|
||||
}
|
||||
var getMemoTxIdOutputIndexClosure: ((Data, UInt16) async throws -> Memo?)?
|
||||
func setGetMemoTxIdOutputIndexClosure(_ param: ((Data, UInt16) async throws -> Memo?)?) async {
|
||||
getMemoTxIdOutputIndexClosure = param
|
||||
}
|
||||
|
||||
func getMemo(txId: Data, outputIndex: UInt16) async throws -> Memo? {
|
||||
if let error = getMemoTxIdOutputIndexThrowableError {
|
||||
|
@ -2315,22 +2243,13 @@ actor ZcashRustBackendWeldingMock: ZcashRustBackendWelding {
|
|||
// MARK: - getTransparentBalance
|
||||
|
||||
var getTransparentBalanceAccountThrowableError: Error?
|
||||
func setGetTransparentBalanceAccountThrowableError(_ param: Error?) async {
|
||||
getTransparentBalanceAccountThrowableError = param
|
||||
}
|
||||
var getTransparentBalanceAccountCallsCount = 0
|
||||
var getTransparentBalanceAccountCalled: Bool {
|
||||
return getTransparentBalanceAccountCallsCount > 0
|
||||
}
|
||||
var getTransparentBalanceAccountReceivedAccount: Int32?
|
||||
var getTransparentBalanceAccountReturnValue: Int64!
|
||||
func setGetTransparentBalanceAccountReturnValue(_ param: Int64) async {
|
||||
getTransparentBalanceAccountReturnValue = param
|
||||
}
|
||||
var getTransparentBalanceAccountClosure: ((Int32) async throws -> Int64)?
|
||||
func setGetTransparentBalanceAccountClosure(_ param: ((Int32) async throws -> Int64)?) async {
|
||||
getTransparentBalanceAccountClosure = param
|
||||
}
|
||||
|
||||
func getTransparentBalance(account: Int32) async throws -> Int64 {
|
||||
if let error = getTransparentBalanceAccountThrowableError {
|
||||
|
@ -2348,22 +2267,13 @@ actor ZcashRustBackendWeldingMock: ZcashRustBackendWelding {
|
|||
// MARK: - initDataDb
|
||||
|
||||
var initDataDbSeedThrowableError: Error?
|
||||
func setInitDataDbSeedThrowableError(_ param: Error?) async {
|
||||
initDataDbSeedThrowableError = param
|
||||
}
|
||||
var initDataDbSeedCallsCount = 0
|
||||
var initDataDbSeedCalled: Bool {
|
||||
return initDataDbSeedCallsCount > 0
|
||||
}
|
||||
var initDataDbSeedReceivedSeed: [UInt8]?
|
||||
var initDataDbSeedReturnValue: DbInitResult!
|
||||
func setInitDataDbSeedReturnValue(_ param: DbInitResult) async {
|
||||
initDataDbSeedReturnValue = param
|
||||
}
|
||||
var initDataDbSeedClosure: (([UInt8]?) async throws -> DbInitResult)?
|
||||
func setInitDataDbSeedClosure(_ param: (([UInt8]?) async throws -> DbInitResult)?) async {
|
||||
initDataDbSeedClosure = param
|
||||
}
|
||||
|
||||
func initDataDb(seed: [UInt8]?) async throws -> DbInitResult {
|
||||
if let error = initDataDbSeedThrowableError {
|
||||
|
@ -2381,22 +2291,13 @@ actor ZcashRustBackendWeldingMock: ZcashRustBackendWelding {
|
|||
// MARK: - listTransparentReceivers
|
||||
|
||||
var listTransparentReceiversAccountThrowableError: Error?
|
||||
func setListTransparentReceiversAccountThrowableError(_ param: Error?) async {
|
||||
listTransparentReceiversAccountThrowableError = param
|
||||
}
|
||||
var listTransparentReceiversAccountCallsCount = 0
|
||||
var listTransparentReceiversAccountCalled: Bool {
|
||||
return listTransparentReceiversAccountCallsCount > 0
|
||||
}
|
||||
var listTransparentReceiversAccountReceivedAccount: Int32?
|
||||
var listTransparentReceiversAccountReturnValue: [TransparentAddress]!
|
||||
func setListTransparentReceiversAccountReturnValue(_ param: [TransparentAddress]) async {
|
||||
listTransparentReceiversAccountReturnValue = param
|
||||
}
|
||||
var listTransparentReceiversAccountClosure: ((Int32) async throws -> [TransparentAddress])?
|
||||
func setListTransparentReceiversAccountClosure(_ param: ((Int32) async throws -> [TransparentAddress])?) async {
|
||||
listTransparentReceiversAccountClosure = param
|
||||
}
|
||||
|
||||
func listTransparentReceivers(account: Int32) async throws -> [TransparentAddress] {
|
||||
if let error = listTransparentReceiversAccountThrowableError {
|
||||
|
@ -2414,22 +2315,13 @@ actor ZcashRustBackendWeldingMock: ZcashRustBackendWelding {
|
|||
// MARK: - getVerifiedBalance
|
||||
|
||||
var getVerifiedBalanceAccountThrowableError: Error?
|
||||
func setGetVerifiedBalanceAccountThrowableError(_ param: Error?) async {
|
||||
getVerifiedBalanceAccountThrowableError = param
|
||||
}
|
||||
var getVerifiedBalanceAccountCallsCount = 0
|
||||
var getVerifiedBalanceAccountCalled: Bool {
|
||||
return getVerifiedBalanceAccountCallsCount > 0
|
||||
}
|
||||
var getVerifiedBalanceAccountReceivedAccount: Int32?
|
||||
var getVerifiedBalanceAccountReturnValue: Int64!
|
||||
func setGetVerifiedBalanceAccountReturnValue(_ param: Int64) async {
|
||||
getVerifiedBalanceAccountReturnValue = param
|
||||
}
|
||||
var getVerifiedBalanceAccountClosure: ((Int32) async throws -> Int64)?
|
||||
func setGetVerifiedBalanceAccountClosure(_ param: ((Int32) async throws -> Int64)?) async {
|
||||
getVerifiedBalanceAccountClosure = param
|
||||
}
|
||||
|
||||
func getVerifiedBalance(account: Int32) async throws -> Int64 {
|
||||
if let error = getVerifiedBalanceAccountThrowableError {
|
||||
|
@ -2447,22 +2339,13 @@ actor ZcashRustBackendWeldingMock: ZcashRustBackendWelding {
|
|||
// MARK: - getVerifiedTransparentBalance
|
||||
|
||||
var getVerifiedTransparentBalanceAccountThrowableError: Error?
|
||||
func setGetVerifiedTransparentBalanceAccountThrowableError(_ param: Error?) async {
|
||||
getVerifiedTransparentBalanceAccountThrowableError = param
|
||||
}
|
||||
var getVerifiedTransparentBalanceAccountCallsCount = 0
|
||||
var getVerifiedTransparentBalanceAccountCalled: Bool {
|
||||
return getVerifiedTransparentBalanceAccountCallsCount > 0
|
||||
}
|
||||
var getVerifiedTransparentBalanceAccountReceivedAccount: Int32?
|
||||
var getVerifiedTransparentBalanceAccountReturnValue: Int64!
|
||||
func setGetVerifiedTransparentBalanceAccountReturnValue(_ param: Int64) async {
|
||||
getVerifiedTransparentBalanceAccountReturnValue = param
|
||||
}
|
||||
var getVerifiedTransparentBalanceAccountClosure: ((Int32) async throws -> Int64)?
|
||||
func setGetVerifiedTransparentBalanceAccountClosure(_ param: ((Int32) async throws -> Int64)?) async {
|
||||
getVerifiedTransparentBalanceAccountClosure = param
|
||||
}
|
||||
|
||||
func getVerifiedTransparentBalance(account: Int32) async throws -> Int64 {
|
||||
if let error = getVerifiedTransparentBalanceAccountThrowableError {
|
||||
|
@ -2480,18 +2363,12 @@ actor ZcashRustBackendWeldingMock: ZcashRustBackendWelding {
|
|||
// MARK: - rewindToHeight
|
||||
|
||||
var rewindToHeightHeightThrowableError: Error?
|
||||
func setRewindToHeightHeightThrowableError(_ param: Error?) async {
|
||||
rewindToHeightHeightThrowableError = param
|
||||
}
|
||||
var rewindToHeightHeightCallsCount = 0
|
||||
var rewindToHeightHeightCalled: Bool {
|
||||
return rewindToHeightHeightCallsCount > 0
|
||||
}
|
||||
var rewindToHeightHeightReceivedHeight: Int32?
|
||||
var rewindToHeightHeightClosure: ((Int32) async throws -> Void)?
|
||||
func setRewindToHeightHeightClosure(_ param: ((Int32) async throws -> Void)?) async {
|
||||
rewindToHeightHeightClosure = param
|
||||
}
|
||||
|
||||
func rewindToHeight(height: Int32) async throws {
|
||||
if let error = rewindToHeightHeightThrowableError {
|
||||
|
@ -2505,18 +2382,12 @@ actor ZcashRustBackendWeldingMock: ZcashRustBackendWelding {
|
|||
// MARK: - rewindCacheToHeight
|
||||
|
||||
var rewindCacheToHeightHeightThrowableError: Error?
|
||||
func setRewindCacheToHeightHeightThrowableError(_ param: Error?) async {
|
||||
rewindCacheToHeightHeightThrowableError = param
|
||||
}
|
||||
var rewindCacheToHeightHeightCallsCount = 0
|
||||
var rewindCacheToHeightHeightCalled: Bool {
|
||||
return rewindCacheToHeightHeightCallsCount > 0
|
||||
}
|
||||
var rewindCacheToHeightHeightReceivedHeight: Int32?
|
||||
var rewindCacheToHeightHeightClosure: ((Int32) async throws -> Void)?
|
||||
func setRewindCacheToHeightHeightClosure(_ param: ((Int32) async throws -> Void)?) async {
|
||||
rewindCacheToHeightHeightClosure = param
|
||||
}
|
||||
|
||||
func rewindCacheToHeight(height: Int32) async throws {
|
||||
if let error = rewindCacheToHeightHeightThrowableError {
|
||||
|
@ -2530,18 +2401,12 @@ actor ZcashRustBackendWeldingMock: ZcashRustBackendWelding {
|
|||
// MARK: - putSaplingSubtreeRoots
|
||||
|
||||
var putSaplingSubtreeRootsStartIndexRootsThrowableError: Error?
|
||||
func setPutSaplingSubtreeRootsStartIndexRootsThrowableError(_ param: Error?) async {
|
||||
putSaplingSubtreeRootsStartIndexRootsThrowableError = param
|
||||
}
|
||||
var putSaplingSubtreeRootsStartIndexRootsCallsCount = 0
|
||||
var putSaplingSubtreeRootsStartIndexRootsCalled: Bool {
|
||||
return putSaplingSubtreeRootsStartIndexRootsCallsCount > 0
|
||||
}
|
||||
var putSaplingSubtreeRootsStartIndexRootsReceivedArguments: (startIndex: UInt64, roots: [SubtreeRoot])?
|
||||
var putSaplingSubtreeRootsStartIndexRootsClosure: ((UInt64, [SubtreeRoot]) async throws -> Void)?
|
||||
func setPutSaplingSubtreeRootsStartIndexRootsClosure(_ param: ((UInt64, [SubtreeRoot]) async throws -> Void)?) async {
|
||||
putSaplingSubtreeRootsStartIndexRootsClosure = param
|
||||
}
|
||||
|
||||
func putSaplingSubtreeRoots(startIndex: UInt64, roots: [SubtreeRoot]) async throws {
|
||||
if let error = putSaplingSubtreeRootsStartIndexRootsThrowableError {
|
||||
|
@ -2555,18 +2420,12 @@ actor ZcashRustBackendWeldingMock: ZcashRustBackendWelding {
|
|||
// MARK: - updateChainTip
|
||||
|
||||
var updateChainTipHeightThrowableError: Error?
|
||||
func setUpdateChainTipHeightThrowableError(_ param: Error?) async {
|
||||
updateChainTipHeightThrowableError = param
|
||||
}
|
||||
var updateChainTipHeightCallsCount = 0
|
||||
var updateChainTipHeightCalled: Bool {
|
||||
return updateChainTipHeightCallsCount > 0
|
||||
}
|
||||
var updateChainTipHeightReceivedHeight: Int32?
|
||||
var updateChainTipHeightClosure: ((Int32) async throws -> Void)?
|
||||
func setUpdateChainTipHeightClosure(_ param: ((Int32) async throws -> Void)?) async {
|
||||
updateChainTipHeightClosure = param
|
||||
}
|
||||
|
||||
func updateChainTip(height: Int32) async throws {
|
||||
if let error = updateChainTipHeightThrowableError {
|
||||
|
@ -2580,21 +2439,12 @@ actor ZcashRustBackendWeldingMock: ZcashRustBackendWelding {
|
|||
// MARK: - fullyScannedHeight
|
||||
|
||||
var fullyScannedHeightThrowableError: Error?
|
||||
func setFullyScannedHeightThrowableError(_ param: Error?) async {
|
||||
fullyScannedHeightThrowableError = param
|
||||
}
|
||||
var fullyScannedHeightCallsCount = 0
|
||||
var fullyScannedHeightCalled: Bool {
|
||||
return fullyScannedHeightCallsCount > 0
|
||||
}
|
||||
var fullyScannedHeightReturnValue: BlockHeight?
|
||||
func setFullyScannedHeightReturnValue(_ param: BlockHeight?) async {
|
||||
fullyScannedHeightReturnValue = param
|
||||
}
|
||||
var fullyScannedHeightClosure: (() async throws -> BlockHeight?)?
|
||||
func setFullyScannedHeightClosure(_ param: (() async throws -> BlockHeight?)?) async {
|
||||
fullyScannedHeightClosure = param
|
||||
}
|
||||
|
||||
func fullyScannedHeight() async throws -> BlockHeight? {
|
||||
if let error = fullyScannedHeightThrowableError {
|
||||
|
@ -2611,21 +2461,12 @@ actor ZcashRustBackendWeldingMock: ZcashRustBackendWelding {
|
|||
// MARK: - maxScannedHeight
|
||||
|
||||
var maxScannedHeightThrowableError: Error?
|
||||
func setMaxScannedHeightThrowableError(_ param: Error?) async {
|
||||
maxScannedHeightThrowableError = param
|
||||
}
|
||||
var maxScannedHeightCallsCount = 0
|
||||
var maxScannedHeightCalled: Bool {
|
||||
return maxScannedHeightCallsCount > 0
|
||||
}
|
||||
var maxScannedHeightReturnValue: BlockHeight?
|
||||
func setMaxScannedHeightReturnValue(_ param: BlockHeight?) async {
|
||||
maxScannedHeightReturnValue = param
|
||||
}
|
||||
var maxScannedHeightClosure: (() async throws -> BlockHeight?)?
|
||||
func setMaxScannedHeightClosure(_ param: (() async throws -> BlockHeight?)?) async {
|
||||
maxScannedHeightClosure = param
|
||||
}
|
||||
|
||||
func maxScannedHeight() async throws -> BlockHeight? {
|
||||
if let error = maxScannedHeightThrowableError {
|
||||
|
@ -2642,21 +2483,12 @@ actor ZcashRustBackendWeldingMock: ZcashRustBackendWelding {
|
|||
// MARK: - getScanProgress
|
||||
|
||||
var getScanProgressThrowableError: Error?
|
||||
func setGetScanProgressThrowableError(_ param: Error?) async {
|
||||
getScanProgressThrowableError = param
|
||||
}
|
||||
var getScanProgressCallsCount = 0
|
||||
var getScanProgressCalled: Bool {
|
||||
return getScanProgressCallsCount > 0
|
||||
}
|
||||
var getScanProgressReturnValue: ScanProgress?
|
||||
func setGetScanProgressReturnValue(_ param: ScanProgress?) async {
|
||||
getScanProgressReturnValue = param
|
||||
}
|
||||
var getScanProgressClosure: (() async throws -> ScanProgress?)?
|
||||
func setGetScanProgressClosure(_ param: (() async throws -> ScanProgress?)?) async {
|
||||
getScanProgressClosure = param
|
||||
}
|
||||
|
||||
func getScanProgress() async throws -> ScanProgress? {
|
||||
if let error = getScanProgressThrowableError {
|
||||
|
@ -2673,21 +2505,12 @@ actor ZcashRustBackendWeldingMock: ZcashRustBackendWelding {
|
|||
// MARK: - suggestScanRanges
|
||||
|
||||
var suggestScanRangesThrowableError: Error?
|
||||
func setSuggestScanRangesThrowableError(_ param: Error?) async {
|
||||
suggestScanRangesThrowableError = param
|
||||
}
|
||||
var suggestScanRangesCallsCount = 0
|
||||
var suggestScanRangesCalled: Bool {
|
||||
return suggestScanRangesCallsCount > 0
|
||||
}
|
||||
var suggestScanRangesReturnValue: [ScanRange]!
|
||||
func setSuggestScanRangesReturnValue(_ param: [ScanRange]) async {
|
||||
suggestScanRangesReturnValue = param
|
||||
}
|
||||
var suggestScanRangesClosure: (() async throws -> [ScanRange])?
|
||||
func setSuggestScanRangesClosure(_ param: (() async throws -> [ScanRange])?) async {
|
||||
suggestScanRangesClosure = param
|
||||
}
|
||||
|
||||
func suggestScanRanges() async throws -> [ScanRange] {
|
||||
if let error = suggestScanRangesThrowableError {
|
||||
|
@ -2704,18 +2527,12 @@ actor ZcashRustBackendWeldingMock: ZcashRustBackendWelding {
|
|||
// MARK: - scanBlocks
|
||||
|
||||
var scanBlocksFromHeightLimitThrowableError: Error?
|
||||
func setScanBlocksFromHeightLimitThrowableError(_ param: Error?) async {
|
||||
scanBlocksFromHeightLimitThrowableError = param
|
||||
}
|
||||
var scanBlocksFromHeightLimitCallsCount = 0
|
||||
var scanBlocksFromHeightLimitCalled: Bool {
|
||||
return scanBlocksFromHeightLimitCallsCount > 0
|
||||
}
|
||||
var scanBlocksFromHeightLimitReceivedArguments: (fromHeight: Int32, limit: UInt32)?
|
||||
var scanBlocksFromHeightLimitClosure: ((Int32, UInt32) async throws -> Void)?
|
||||
func setScanBlocksFromHeightLimitClosure(_ param: ((Int32, UInt32) async throws -> Void)?) async {
|
||||
scanBlocksFromHeightLimitClosure = param
|
||||
}
|
||||
|
||||
func scanBlocks(fromHeight: Int32, limit: UInt32) async throws {
|
||||
if let error = scanBlocksFromHeightLimitThrowableError {
|
||||
|
@ -2729,18 +2546,12 @@ actor ZcashRustBackendWeldingMock: ZcashRustBackendWelding {
|
|||
// MARK: - putUnspentTransparentOutput
|
||||
|
||||
var putUnspentTransparentOutputTxidIndexScriptValueHeightThrowableError: Error?
|
||||
func setPutUnspentTransparentOutputTxidIndexScriptValueHeightThrowableError(_ param: Error?) async {
|
||||
putUnspentTransparentOutputTxidIndexScriptValueHeightThrowableError = param
|
||||
}
|
||||
var putUnspentTransparentOutputTxidIndexScriptValueHeightCallsCount = 0
|
||||
var putUnspentTransparentOutputTxidIndexScriptValueHeightCalled: Bool {
|
||||
return putUnspentTransparentOutputTxidIndexScriptValueHeightCallsCount > 0
|
||||
}
|
||||
var putUnspentTransparentOutputTxidIndexScriptValueHeightReceivedArguments: (txid: [UInt8], index: Int, script: [UInt8], value: Int64, height: BlockHeight)?
|
||||
var putUnspentTransparentOutputTxidIndexScriptValueHeightClosure: (([UInt8], Int, [UInt8], Int64, BlockHeight) async throws -> Void)?
|
||||
func setPutUnspentTransparentOutputTxidIndexScriptValueHeightClosure(_ param: (([UInt8], Int, [UInt8], Int64, BlockHeight) async throws -> Void)?) async {
|
||||
putUnspentTransparentOutputTxidIndexScriptValueHeightClosure = param
|
||||
}
|
||||
|
||||
func putUnspentTransparentOutput(txid: [UInt8], index: Int, script: [UInt8], value: Int64, height: BlockHeight) async throws {
|
||||
if let error = putUnspentTransparentOutputTxidIndexScriptValueHeightThrowableError {
|
||||
|
@ -2754,22 +2565,13 @@ actor ZcashRustBackendWeldingMock: ZcashRustBackendWelding {
|
|||
// MARK: - shieldFunds
|
||||
|
||||
var shieldFundsUskMemoShieldingThresholdThrowableError: Error?
|
||||
func setShieldFundsUskMemoShieldingThresholdThrowableError(_ param: Error?) async {
|
||||
shieldFundsUskMemoShieldingThresholdThrowableError = param
|
||||
}
|
||||
var shieldFundsUskMemoShieldingThresholdCallsCount = 0
|
||||
var shieldFundsUskMemoShieldingThresholdCalled: Bool {
|
||||
return shieldFundsUskMemoShieldingThresholdCallsCount > 0
|
||||
}
|
||||
var shieldFundsUskMemoShieldingThresholdReceivedArguments: (usk: UnifiedSpendingKey, memo: MemoBytes?, shieldingThreshold: Zatoshi)?
|
||||
var shieldFundsUskMemoShieldingThresholdReturnValue: Data!
|
||||
func setShieldFundsUskMemoShieldingThresholdReturnValue(_ param: Data) async {
|
||||
shieldFundsUskMemoShieldingThresholdReturnValue = param
|
||||
}
|
||||
var shieldFundsUskMemoShieldingThresholdClosure: ((UnifiedSpendingKey, MemoBytes?, Zatoshi) async throws -> Data)?
|
||||
func setShieldFundsUskMemoShieldingThresholdClosure(_ param: ((UnifiedSpendingKey, MemoBytes?, Zatoshi) async throws -> Data)?) async {
|
||||
shieldFundsUskMemoShieldingThresholdClosure = param
|
||||
}
|
||||
|
||||
func shieldFunds(usk: UnifiedSpendingKey, memo: MemoBytes?, shieldingThreshold: Zatoshi) async throws -> Data {
|
||||
if let error = shieldFundsUskMemoShieldingThresholdThrowableError {
|
||||
|
@ -2786,25 +2588,36 @@ actor ZcashRustBackendWeldingMock: ZcashRustBackendWelding {
|
|||
|
||||
// MARK: - consensusBranchIdFor
|
||||
|
||||
var consensusBranchIdForHeightThrowableError: Error?
|
||||
var consensusBranchIdForHeightCallsCount = 0
|
||||
var consensusBranchIdForHeightCalled: Bool {
|
||||
return consensusBranchIdForHeightCallsCount > 0
|
||||
}
|
||||
var consensusBranchIdForHeightReceivedHeight: Int32?
|
||||
var consensusBranchIdForHeightReturnValue: Int32!
|
||||
var consensusBranchIdForHeightClosure: ((Int32) throws -> Int32)?
|
||||
|
||||
nonisolated func consensusBranchIdFor(height: Int32) throws -> Int32 {
|
||||
try consensusBranchIdForHeightClosure!(height)
|
||||
func consensusBranchIdFor(height: Int32) throws -> Int32 {
|
||||
if let error = consensusBranchIdForHeightThrowableError {
|
||||
throw error
|
||||
}
|
||||
consensusBranchIdForHeightCallsCount += 1
|
||||
consensusBranchIdForHeightReceivedHeight = height
|
||||
if let closure = consensusBranchIdForHeightClosure {
|
||||
return try closure(height)
|
||||
} else {
|
||||
return consensusBranchIdForHeightReturnValue
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - initBlockMetadataDb
|
||||
|
||||
var initBlockMetadataDbThrowableError: Error?
|
||||
func setInitBlockMetadataDbThrowableError(_ param: Error?) async {
|
||||
initBlockMetadataDbThrowableError = param
|
||||
}
|
||||
var initBlockMetadataDbCallsCount = 0
|
||||
var initBlockMetadataDbCalled: Bool {
|
||||
return initBlockMetadataDbCallsCount > 0
|
||||
}
|
||||
var initBlockMetadataDbClosure: (() async throws -> Void)?
|
||||
func setInitBlockMetadataDbClosure(_ param: (() async throws -> Void)?) async {
|
||||
initBlockMetadataDbClosure = param
|
||||
}
|
||||
|
||||
func initBlockMetadataDb() async throws {
|
||||
if let error = initBlockMetadataDbThrowableError {
|
||||
|
@ -2817,18 +2630,12 @@ actor ZcashRustBackendWeldingMock: ZcashRustBackendWelding {
|
|||
// MARK: - writeBlocksMetadata
|
||||
|
||||
var writeBlocksMetadataBlocksThrowableError: Error?
|
||||
func setWriteBlocksMetadataBlocksThrowableError(_ param: Error?) async {
|
||||
writeBlocksMetadataBlocksThrowableError = param
|
||||
}
|
||||
var writeBlocksMetadataBlocksCallsCount = 0
|
||||
var writeBlocksMetadataBlocksCalled: Bool {
|
||||
return writeBlocksMetadataBlocksCallsCount > 0
|
||||
}
|
||||
var writeBlocksMetadataBlocksReceivedBlocks: [ZcashCompactBlock]?
|
||||
var writeBlocksMetadataBlocksClosure: (([ZcashCompactBlock]) async throws -> Void)?
|
||||
func setWriteBlocksMetadataBlocksClosure(_ param: (([ZcashCompactBlock]) async throws -> Void)?) async {
|
||||
writeBlocksMetadataBlocksClosure = param
|
||||
}
|
||||
|
||||
func writeBlocksMetadata(blocks: [ZcashCompactBlock]) async throws {
|
||||
if let error = writeBlocksMetadataBlocksThrowableError {
|
||||
|
@ -2842,21 +2649,12 @@ actor ZcashRustBackendWeldingMock: ZcashRustBackendWelding {
|
|||
// MARK: - latestCachedBlockHeight
|
||||
|
||||
var latestCachedBlockHeightThrowableError: Error?
|
||||
func setLatestCachedBlockHeightThrowableError(_ param: Error?) async {
|
||||
latestCachedBlockHeightThrowableError = param
|
||||
}
|
||||
var latestCachedBlockHeightCallsCount = 0
|
||||
var latestCachedBlockHeightCalled: Bool {
|
||||
return latestCachedBlockHeightCallsCount > 0
|
||||
}
|
||||
var latestCachedBlockHeightReturnValue: BlockHeight!
|
||||
func setLatestCachedBlockHeightReturnValue(_ param: BlockHeight) async {
|
||||
latestCachedBlockHeightReturnValue = param
|
||||
}
|
||||
var latestCachedBlockHeightClosure: (() async throws -> BlockHeight)?
|
||||
func setLatestCachedBlockHeightClosure(_ param: (() async throws -> BlockHeight)?) async {
|
||||
latestCachedBlockHeightClosure = param
|
||||
}
|
||||
|
||||
func latestCachedBlockHeight() async throws -> BlockHeight {
|
||||
if let error = latestCachedBlockHeightThrowableError {
|
||||
|
|
|
@ -58,59 +58,58 @@ class RustBackendMockHelper {
|
|||
rustBackend: ZcashRustBackendWelding,
|
||||
consensusBranchID: Int32? = nil
|
||||
) async {
|
||||
self.rustBackendMock = ZcashRustBackendWeldingMock(
|
||||
consensusBranchIdForHeightClosure: { height in
|
||||
if let consensusBranchID {
|
||||
return consensusBranchID
|
||||
} else {
|
||||
return try rustBackend.consensusBranchIdFor(height: height)
|
||||
}
|
||||
self.rustBackendMock = ZcashRustBackendWeldingMock()
|
||||
rustBackendMock.consensusBranchIdForHeightClosure = { height in
|
||||
if let consensusBranchID {
|
||||
return consensusBranchID
|
||||
} else {
|
||||
return try rustBackend.consensusBranchIdFor(height: height)
|
||||
}
|
||||
)
|
||||
await setupDefaultMock(rustBackend: rustBackend)
|
||||
}
|
||||
setupDefaultMock(rustBackend: rustBackend)
|
||||
}
|
||||
|
||||
private func setupDefaultMock(rustBackend: ZcashRustBackendWelding) async {
|
||||
await rustBackendMock.setLatestCachedBlockHeightReturnValue(.empty())
|
||||
await rustBackendMock.setInitBlockMetadataDbClosure() { }
|
||||
await rustBackendMock.setWriteBlocksMetadataBlocksClosure() { _ in }
|
||||
await rustBackendMock.setGetTransparentBalanceAccountReturnValue(0)
|
||||
await rustBackendMock.setGetVerifiedBalanceAccountReturnValue(0)
|
||||
await rustBackendMock.setListTransparentReceiversAccountReturnValue([])
|
||||
await rustBackendMock.setGetCurrentAddressAccountThrowableError(ZcashError.rustGetCurrentAddress("mocked error"))
|
||||
await rustBackendMock.setGetNextAvailableAddressAccountThrowableError(ZcashError.rustGetNextAvailableAddress("mocked error"))
|
||||
await rustBackendMock.setCreateAccountSeedTreeStateRecoverUntilThrowableError(ZcashError.rustInitAccountsTableViewingKeyCotainsNullBytes)
|
||||
await rustBackendMock.setGetMemoTxIdOutputIndexReturnValue(nil)
|
||||
await rustBackendMock.setInitDataDbSeedReturnValue(.seedRequired)
|
||||
await rustBackendMock.setGetNearestRewindHeightHeightReturnValue(-1)
|
||||
await rustBackendMock.setPutUnspentTransparentOutputTxidIndexScriptValueHeightClosure() { _, _, _, _, _ in }
|
||||
await rustBackendMock.setCreateToAddressUskToValueMemoThrowableError(ZcashError.rustCreateToAddress("mocked error"))
|
||||
await rustBackendMock.setShieldFundsUskMemoShieldingThresholdThrowableError(ZcashError.rustShieldFunds("mocked error"))
|
||||
await rustBackendMock.setDecryptAndStoreTransactionTxBytesMinedHeightThrowableError(ZcashError.rustDecryptAndStoreTransaction("mock fail"))
|
||||
private func setupDefaultMock(rustBackend: ZcashRustBackendWelding) {
|
||||
rustBackendMock.latestCachedBlockHeightReturnValue = .empty()
|
||||
rustBackendMock.initBlockMetadataDbClosure = { }
|
||||
rustBackendMock.writeBlocksMetadataBlocksClosure = { _ in }
|
||||
rustBackendMock.getTransparentBalanceAccountReturnValue = 0
|
||||
rustBackendMock.getVerifiedBalanceAccountReturnValue = 0
|
||||
rustBackendMock.listTransparentReceiversAccountReturnValue = []
|
||||
rustBackendMock.getCurrentAddressAccountThrowableError = ZcashError.rustGetCurrentAddress("mocked error")
|
||||
rustBackendMock.getNextAvailableAddressAccountThrowableError = ZcashError.rustGetNextAvailableAddress("mocked error")
|
||||
rustBackendMock.createAccountSeedTreeStateRecoverUntilThrowableError = ZcashError.rustInitAccountsTableViewingKeyCotainsNullBytes
|
||||
rustBackendMock.getMemoTxIdOutputIndexReturnValue = nil
|
||||
rustBackendMock.initDataDbSeedReturnValue = .seedRequired
|
||||
rustBackendMock.getNearestRewindHeightHeightReturnValue = -1
|
||||
rustBackendMock.putUnspentTransparentOutputTxidIndexScriptValueHeightClosure = { _, _, _, _, _ in }
|
||||
rustBackendMock.createToAddressUskToValueMemoThrowableError = ZcashError.rustCreateToAddress("mocked error")
|
||||
rustBackendMock.shieldFundsUskMemoShieldingThresholdThrowableError = ZcashError.rustShieldFunds("mocked error")
|
||||
rustBackendMock.decryptAndStoreTransactionTxBytesMinedHeightThrowableError = ZcashError.rustDecryptAndStoreTransaction("mock fail")
|
||||
|
||||
await rustBackendMock.setInitDataDbSeedClosure() { seed in
|
||||
rustBackendMock.initDataDbSeedClosure = { seed in
|
||||
return try await rustBackend.initDataDb(seed: seed)
|
||||
}
|
||||
|
||||
await rustBackendMock.setGetBalanceAccountClosure() { account in
|
||||
rustBackendMock.getBalanceAccountClosure = { account in
|
||||
return try await rustBackend.getBalance(account: account)
|
||||
}
|
||||
|
||||
await rustBackendMock.setGetVerifiedBalanceAccountClosure() { account in
|
||||
rustBackendMock.getVerifiedBalanceAccountClosure = { account in
|
||||
return try await rustBackend.getVerifiedBalance(account: account)
|
||||
}
|
||||
|
||||
await rustBackendMock.setRewindToHeightHeightClosure() { height in
|
||||
rustBackendMock.rewindToHeightHeightClosure = { height in
|
||||
try await rustBackend.rewindToHeight(height: height)
|
||||
}
|
||||
|
||||
await rustBackendMock.setRewindCacheToHeightHeightClosure() { _ in }
|
||||
rustBackendMock.rewindCacheToHeightHeightClosure = { _ in }
|
||||
|
||||
await rustBackendMock.setSuggestScanRangesClosure() {
|
||||
rustBackendMock.suggestScanRangesClosure = {
|
||||
try await rustBackend.suggestScanRanges()
|
||||
}
|
||||
|
||||
await rustBackendMock.setScanBlocksFromHeightLimitClosure() { fromHeight, limit in
|
||||
rustBackendMock.scanBlocksFromHeightLimitClosure = { fromHeight, limit in
|
||||
try await rustBackend.scanBlocks(fromHeight: fromHeight, limit: limit)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -55,7 +55,7 @@ enum TestDbBuilder {
|
|||
}
|
||||
|
||||
static func prepopulatedDataDbProvider(rustBackend: ZcashRustBackend) async throws -> ConnectionProvider? {
|
||||
let provider = SimpleConnectionProvider(path: (await rustBackend.dbData).0, readonly: true)
|
||||
let provider = SimpleConnectionProvider(path: (rustBackend.dbData).0, readonly: true)
|
||||
|
||||
let initResult = try await rustBackend.initDataDb(seed: Environment.seedBytes)
|
||||
|
||||
|
|
Loading…
Reference in New Issue