ZcashLightClientKit/Tests/OfflineTests/TransactionRepositoryTests....

252 lines
9.2 KiB
Swift
Raw Normal View History

//
// TransactionRepositoryTests.swift
// ZcashLightClientKit-Unit-Tests
//
// Created by Francisco Gindre on 11/16/19.
//
import XCTest
2022-02-28 09:03:20 -08:00
@testable import TestUtils
@testable import ZcashLightClientKit
2021-09-23 06:26:41 -07:00
class TransactionRepositoryTests: XCTestCase {
var transactionRepository: TransactionRepository!
2022-10-21 14:19:08 -07:00
override func setUp() async throws {
try await super.setUp()
let rustBackend = ZcashRustBackend.makeForTests(
dbData: TestDbBuilder.prePopulatedMainnetDataDbURL()!,
fsBlockDbRoot: Environment.uniqueTestTempDirectory,
networkType: .mainnet
)
[#888] Make actor from ZcashRustBackendWelding Closes #888. - `ZcashRustBackend` is actor now. So majority of methods in this actor are now async. - Some methods stayed `static` in `ZcashRustBackend`. It would be hard to pass instance of the `ZcashRustBackend` to the places where these methods are used in static manner. And it would change lot of APIs. But it isn't problem from technical perspective because these methods would be `nonisolated` otherwise. - Methods `lastError()` and `getLastError()` in `ZcashRustBackend` are now private. This makes sure that ther won't be aby race condition between other methods and these two error methods. - All the methods for which was `lastError()` used in code now throw error. So `lastError()` is no longer needed outside of the `ZcashRustBackend`. - There are in the public API related to `DerivationTool`. - `DerivationTool` now requires instance of the `ZcashRustBackend`. And `ZcashRustBackend` isn't public type. So `DerivationTool` doesn't have any public constructor now. It can be created only via `Initializer.makeDerivationTool()` instance method. - `deriveUnifiedSpendingKey()` and `deriveUnifiedFullViewingKey()` in `DerivationTool` are now async. It is because these are using `ZcashRustBackend` inside. `DerivationTool` offers alternative (closure and combine) APIs. But downside is that there is no sync API to dervie spending key or viewing key. - Some methods of the `DerivationTool` are now static. These methods don't use anything that requires instance of the `DerivationTool` inside. [#888] Use Sourcery to generate mocks - I wrote mock for `Synchronizer` manually. And it's tedious and long and boring work. - Now `ZcashRustBackendWelding` is changed a lot so it means `MockRustBackend` must be changed a lot. So I decided to introduce `sourcery` to generate mocks from protocols so we don't have to do it manually ever. - To generate mocks go to `ZcashLightClientKit/Tests/TestUtils/Sourcery` directory and run `generateMocks.sh` script. - Your protocol must be mentioned in `AutoMockable.swift` file. Generated mocks are in `AutoMockable.generated.swift` file. [#888] Fix Offline tests - Offline tests target now runs and tests are green. - There is log of changes in tests. But logic is not changed. - Updated `AutoMockable.stencil` so sourcery is able to generate mock as actor when protocol is marked with: `// sourcery: mockActor`. - Last few updates in `ZcashRustBackendWelding`. In previous PR `rewindCacheToHeight` methods was overlooked and it didn't throw error. - Removed `MockRustBackend` and using generated `ZCashRustBackendWeldingMock` instead. - Using generated `SynchronizerMock`. [#888] Fix NetworkTests - Changed a bit how rust backend mock is used in the tests. Introduced `RustBackendMockHelper`. There are some state variables that must be preserved within one instance of the mock. This helper does exactly this. It keeps this state variables in the memory and helping mock to work as expected. [#888] Fix Darkside tests Create ZcashKeyDeriving internal protocol Use New DerivationTool that does not require RustBackend Remove duplicated methods that had been copied over [#888] Fix potentially broken tests I broke the tests because I moved `testTempDirectory` from each `TestCase` to the `Environment`. By this I caused that each tests uses exactly same URL. Which is directly against purpose of `testTempDirectory`. So now each test calls this one and store it to local variable. So each test has unique URL. [#888] Add ability to mock nonisolated methods to AutoMockable.stencil [#888] Add changelog and fix the documentation in ZcashRustBackendWelding [#888] Rename derivation rust backend protocol and remove static methods - Renamed `ZcashKeyDeriving` to `ZcashKeyDerivationBackendWelding`. So the naming scheme is same as for `ZcashRustBackendWelding`. - `ZcashKeyDerivationBackend` is now struct instead of enum. - Methods in `ZcashKeyDerivationBackendWelding` (except one) are no longer static. Because of this the respective methods in `DerivationTool` aren't also static anymore.
2023-03-31 10:10:35 -07:00
transactionRepository = try! await TestDbBuilder.transactionRepository(rustBackend: rustBackend)
}
override func tearDown() {
2021-09-23 06:26:41 -07:00
super.tearDown()
transactionRepository = nil
}
func testCount() async throws {
let count = try await self.transactionRepository.countAll()
XCTAssertNotNil(count)
XCTAssertEqual(count, 21)
}
func testCountUnmined() async throws {
let count = try await self.transactionRepository.countUnmined()
XCTAssertNotNil(count)
XCTAssertEqual(count, 0)
}
func testFindInRange() async throws {
let transactions = try await self.transactionRepository.find(in: 663218...663974, limit: 3, kind: .received)
XCTAssertEqual(transactions.count, 3)
XCTAssertEqual(transactions[0].minedHeight, 663974)
XCTAssertEqual(transactions[0].isSentTransaction, false)
XCTAssertEqual(transactions[1].minedHeight, 663953)
XCTAssertEqual(transactions[1].isSentTransaction, false)
XCTAssertEqual(transactions[2].minedHeight, 663229)
XCTAssertEqual(transactions[2].isSentTransaction, false)
}
func testFindByTxId() async throws {
2022-10-21 14:19:08 -07:00
let id = Data(fromHexEncodedString: "01af48bcc4e9667849a073b8b5c539a0fc19de71aac775377929dc6567a36eff")!
let transaction = try await self.transactionRepository.find(rawID: id)
XCTAssertEqual(transaction.rawID, id)
2022-10-21 14:19:08 -07:00
XCTAssertEqual(transaction.minedHeight, 663922)
XCTAssertEqual(transaction.index, 1)
}
func testFindAllSentTransactions() async throws {
let transactions = try await self.transactionRepository.find(offset: 0, limit: Int.max, kind: .sent)
XCTAssertEqual(transactions.count, 13)
transactions.forEach { XCTAssertEqual($0.isSentTransaction, true) }
}
func testFindAllReceivedTransactions() async throws {
let transactions = try await self.transactionRepository.find(offset: 0, limit: Int.max, kind: .received)
XCTAssertEqual(transactions.count, 8)
transactions.forEach { XCTAssertEqual($0.isSentTransaction, false) }
}
func testFindAllTransactions() async throws {
let transactions = try await self.transactionRepository.find(offset: 0, limit: Int.max, kind: .all)
XCTAssertEqual(transactions.count, 21)
}
func testFindReceivedOffsetLimit() async throws {
let transactions = try await self.transactionRepository.findReceived(offset: 3, limit: 3)
XCTAssertEqual(transactions.count, 3)
[#959] Fix `v_transactions` view issues with value (#963) This change switches to a new (future) version of the rust crates that will get rid of the sent and received transactions Views in favor of a `v_transaction` view that will do better accounting of outgoing and incoming funds. Additionally it will support an outputs view for seeing the inner details of transactions enabling the SDKs tell the users the precise movement of value that a tx causes in its multiple possible ways according to the protocol. the `v_tx_outputs` view is not yet implemented. Sent and Received transaction sub-types are kept for compatibility purposes but they are generated from Overviews instead of queried from a specific view. In the transaction Overview the value represents the whole value transfer for the transaction from the point of view of a given account including fees. This means that the value for a single transaction Overview struct represents the addition or subtraction of ZEC value to the account's balance. Future updates will give clients the possibility to drill into the inner workings of those value changes in a per-output basis for each transaction. Also, the field `pending_unmined` field was added to `v_transactions` so that wallets can query `DataDb` for pending but yet unmined txs This will prepare the field for removing the notion of a "PendingDb" and its nuances. Also updated test database `darkside_data.db` Closes #959 Closes #971 ZcashLightClientKitSample main target broken swiftlint script Demo App improvements: Show Short date and value on transaction list
2023-04-18 05:10:56 -07:00
XCTAssertEqual(transactions[0].minedHeight, 663229)
XCTAssertEqual(transactions[1].minedHeight, 663218)
XCTAssertEqual(transactions[2].minedHeight, 663202)
}
func testFindSentOffsetLimit() async throws {
let transactions = try await self.transactionRepository.findSent(offset: 3, limit: 3)
XCTAssertEqual(transactions.count, 3)
XCTAssertEqual(transactions[0].minedHeight, 664022)
XCTAssertEqual(transactions[1].minedHeight, 664012)
XCTAssertEqual(transactions[2].minedHeight, 663956)
}
func testGetTransactionOutputs() async throws {
let rawID = Data(fromHexEncodedString: "08cb5838ffd2c18ce15e7e8c50174940cd9526fff37601986f5480b7ca07e534")!
let outputs = try await self.transactionRepository.getTransactionOutputs(for: rawID)
XCTAssertEqual(outputs.count, 2)
}
func testFindMemoForTransaction() async throws {
let rawID = Data(fromHexEncodedString: "08cb5838ffd2c18ce15e7e8c50174940cd9526fff37601986f5480b7ca07e534")!
let transaction = ZcashTransaction.Overview(
[#959] Fix `v_transactions` view issues with value (#963) This change switches to a new (future) version of the rust crates that will get rid of the sent and received transactions Views in favor of a `v_transaction` view that will do better accounting of outgoing and incoming funds. Additionally it will support an outputs view for seeing the inner details of transactions enabling the SDKs tell the users the precise movement of value that a tx causes in its multiple possible ways according to the protocol. the `v_tx_outputs` view is not yet implemented. Sent and Received transaction sub-types are kept for compatibility purposes but they are generated from Overviews instead of queried from a specific view. In the transaction Overview the value represents the whole value transfer for the transaction from the point of view of a given account including fees. This means that the value for a single transaction Overview struct represents the addition or subtraction of ZEC value to the account's balance. Future updates will give clients the possibility to drill into the inner workings of those value changes in a per-output basis for each transaction. Also, the field `pending_unmined` field was added to `v_transactions` so that wallets can query `DataDb` for pending but yet unmined txs This will prepare the field for removing the notion of a "PendingDb" and its nuances. Also updated test database `darkside_data.db` Closes #959 Closes #971 ZcashLightClientKitSample main target broken swiftlint script Demo App improvements: Show Short date and value on transaction list
2023-04-18 05:10:56 -07:00
accountId: 0,
blockTime: nil,
expiryHeight: nil,
fee: nil,
index: nil,
hasChange: false,
memoCount: 0,
minedHeight: nil,
raw: nil,
rawID: rawID,
receivedNoteCount: 0,
sentNoteCount: 0,
[#959] Fix `v_transactions` view issues with value (#963) This change switches to a new (future) version of the rust crates that will get rid of the sent and received transactions Views in favor of a `v_transaction` view that will do better accounting of outgoing and incoming funds. Additionally it will support an outputs view for seeing the inner details of transactions enabling the SDKs tell the users the precise movement of value that a tx causes in its multiple possible ways according to the protocol. the `v_tx_outputs` view is not yet implemented. Sent and Received transaction sub-types are kept for compatibility purposes but they are generated from Overviews instead of queried from a specific view. In the transaction Overview the value represents the whole value transfer for the transaction from the point of view of a given account including fees. This means that the value for a single transaction Overview struct represents the addition or subtraction of ZEC value to the account's balance. Future updates will give clients the possibility to drill into the inner workings of those value changes in a per-output basis for each transaction. Also, the field `pending_unmined` field was added to `v_transactions` so that wallets can query `DataDb` for pending but yet unmined txs This will prepare the field for removing the notion of a "PendingDb" and its nuances. Also updated test database `darkside_data.db` Closes #959 Closes #971 ZcashLightClientKitSample main target broken swiftlint script Demo App improvements: Show Short date and value on transaction list
2023-04-18 05:10:56 -07:00
value: Zatoshi(-1000),
isExpiredUmined: false
)
let memos = try await self.transactionRepository.findMemos(for: transaction)
[#959] Fix `v_transactions` view issues with value (#963) This change switches to a new (future) version of the rust crates that will get rid of the sent and received transactions Views in favor of a `v_transaction` view that will do better accounting of outgoing and incoming funds. Additionally it will support an outputs view for seeing the inner details of transactions enabling the SDKs tell the users the precise movement of value that a tx causes in its multiple possible ways according to the protocol. the `v_tx_outputs` view is not yet implemented. Sent and Received transaction sub-types are kept for compatibility purposes but they are generated from Overviews instead of queried from a specific view. In the transaction Overview the value represents the whole value transfer for the transaction from the point of view of a given account including fees. This means that the value for a single transaction Overview struct represents the addition or subtraction of ZEC value to the account's balance. Future updates will give clients the possibility to drill into the inner workings of those value changes in a per-output basis for each transaction. Also, the field `pending_unmined` field was added to `v_transactions` so that wallets can query `DataDb` for pending but yet unmined txs This will prepare the field for removing the notion of a "PendingDb" and its nuances. Also updated test database `darkside_data.db` Closes #959 Closes #971 ZcashLightClientKitSample main target broken swiftlint script Demo App improvements: Show Short date and value on transaction list
2023-04-18 05:10:56 -07:00
guard memos.count == 1 else {
XCTFail("Expected transaction to have one memo, found \(memos.count)")
[#959] Fix `v_transactions` view issues with value (#963) This change switches to a new (future) version of the rust crates that will get rid of the sent and received transactions Views in favor of a `v_transaction` view that will do better accounting of outgoing and incoming funds. Additionally it will support an outputs view for seeing the inner details of transactions enabling the SDKs tell the users the precise movement of value that a tx causes in its multiple possible ways according to the protocol. the `v_tx_outputs` view is not yet implemented. Sent and Received transaction sub-types are kept for compatibility purposes but they are generated from Overviews instead of queried from a specific view. In the transaction Overview the value represents the whole value transfer for the transaction from the point of view of a given account including fees. This means that the value for a single transaction Overview struct represents the addition or subtraction of ZEC value to the account's balance. Future updates will give clients the possibility to drill into the inner workings of those value changes in a per-output basis for each transaction. Also, the field `pending_unmined` field was added to `v_transactions` so that wallets can query `DataDb` for pending but yet unmined txs This will prepare the field for removing the notion of a "PendingDb" and its nuances. Also updated test database `darkside_data.db` Closes #959 Closes #971 ZcashLightClientKitSample main target broken swiftlint script Demo App improvements: Show Short date and value on transaction list
2023-04-18 05:10:56 -07:00
return
}
XCTAssertEqual(memos[0].toString(), "Some funds")
}
func testFindMemoForReceivedTransaction() async throws {
let rawID = Data(fromHexEncodedString: "1f49cfcfcdebd5cb9085d9ff2efbcda87121dda13f2c791113fcf2e79ba82108")!
[#1001] Remove PendingDb in favor of `v_transactions` and `v_tx_output` Views (#1001) Removes `PendingTransactionEntity` and all of its related components. Pending items are still tracked and visualized by the existing APIs but they are retrieved from the `TransactionRepository` instead by returning `ZcashTransaction.Overview` instead. `pendingDbURL` is removed from every place it was required. Its deletion is responsibility of wallet developers. `ClearedTransactions` are now just `transactions`. `MigrationManager` is deleted. Now all migrations are in charge of the rust welding layer. `PendingTransactionDao.swift` is removed. Implementation of `AccountEntity` called `Account` is now `DbAccount` `ZcashTransaction.Overview` can be checked for "pending-ness" by calling `.isPending(latestHeight:)` latest height must be provided so that minedHeight can be compared with the lastest and the `defaultStaleTolerance` constant. `TransactionRecipient` is now a public type. protocol `PendingTransactionRepository` is removed. `TransactionManagerError` and `PersistentTransactionManager` are deleted. `OutboundTransactionManager` is deleted and replaced by `TransactionEncoder` which now incorporates `submit(encoded:)` functionality `WalletTransactionEncoder` now uses a `LightWalletService` to submit the encoded transactions. Add changelog changes Delete references to PendingDb from tests and documentation. Fixes some typos. Adds the ability to trace transaction repository SQL queries from test Fix rebase conflicts and generate code [#837] Memo tests regarding transparent address Closes #837 Add model for transaction output Point to FFI branch Fix issue where sync wouldn't resume after wipe. Becasue GRPC channel would be closed Fix Tests Fix testPendingTransactionMinedHeightUpdated Fix testLastStates [#921] Fix broken SynchronizerDarksideTests Add ZcashTransaction.Output API to Synchronizer Changelog + comment fix Add Assertions for transaction outputs and recipients Point to FFI 0.3.1 Fix Demo App Compiler errors Fix Demo App Compiler errors fix cacheDb warnings Fix Tests and compiler errors of rebase build demo app Remove `ZcashTransaction.Sent` and `.Received`. Add `.State` and tests Fix SPM warning PR Suggestions Removes errors that are not used anymore fix warnings
2023-05-05 10:30:47 -07:00
let transaction = ZcashTransaction.Overview(
accountId: 0,
blockTime: 1,
expiryHeight: nil,
[#1001] Remove PendingDb in favor of `v_transactions` and `v_tx_output` Views (#1001) Removes `PendingTransactionEntity` and all of its related components. Pending items are still tracked and visualized by the existing APIs but they are retrieved from the `TransactionRepository` instead by returning `ZcashTransaction.Overview` instead. `pendingDbURL` is removed from every place it was required. Its deletion is responsibility of wallet developers. `ClearedTransactions` are now just `transactions`. `MigrationManager` is deleted. Now all migrations are in charge of the rust welding layer. `PendingTransactionDao.swift` is removed. Implementation of `AccountEntity` called `Account` is now `DbAccount` `ZcashTransaction.Overview` can be checked for "pending-ness" by calling `.isPending(latestHeight:)` latest height must be provided so that minedHeight can be compared with the lastest and the `defaultStaleTolerance` constant. `TransactionRecipient` is now a public type. protocol `PendingTransactionRepository` is removed. `TransactionManagerError` and `PersistentTransactionManager` are deleted. `OutboundTransactionManager` is deleted and replaced by `TransactionEncoder` which now incorporates `submit(encoded:)` functionality `WalletTransactionEncoder` now uses a `LightWalletService` to submit the encoded transactions. Add changelog changes Delete references to PendingDb from tests and documentation. Fixes some typos. Adds the ability to trace transaction repository SQL queries from test Fix rebase conflicts and generate code [#837] Memo tests regarding transparent address Closes #837 Add model for transaction output Point to FFI branch Fix issue where sync wouldn't resume after wipe. Becasue GRPC channel would be closed Fix Tests Fix testPendingTransactionMinedHeightUpdated Fix testLastStates [#921] Fix broken SynchronizerDarksideTests Add ZcashTransaction.Output API to Synchronizer Changelog + comment fix Add Assertions for transaction outputs and recipients Point to FFI 0.3.1 Fix Demo App Compiler errors Fix Demo App Compiler errors fix cacheDb warnings Fix Tests and compiler errors of rebase build demo app Remove `ZcashTransaction.Sent` and `.Received`. Add `.State` and tests Fix SPM warning PR Suggestions Removes errors that are not used anymore fix warnings
2023-05-05 10:30:47 -07:00
fee: nil,
index: 0,
[#1001] Remove PendingDb in favor of `v_transactions` and `v_tx_output` Views (#1001) Removes `PendingTransactionEntity` and all of its related components. Pending items are still tracked and visualized by the existing APIs but they are retrieved from the `TransactionRepository` instead by returning `ZcashTransaction.Overview` instead. `pendingDbURL` is removed from every place it was required. Its deletion is responsibility of wallet developers. `ClearedTransactions` are now just `transactions`. `MigrationManager` is deleted. Now all migrations are in charge of the rust welding layer. `PendingTransactionDao.swift` is removed. Implementation of `AccountEntity` called `Account` is now `DbAccount` `ZcashTransaction.Overview` can be checked for "pending-ness" by calling `.isPending(latestHeight:)` latest height must be provided so that minedHeight can be compared with the lastest and the `defaultStaleTolerance` constant. `TransactionRecipient` is now a public type. protocol `PendingTransactionRepository` is removed. `TransactionManagerError` and `PersistentTransactionManager` are deleted. `OutboundTransactionManager` is deleted and replaced by `TransactionEncoder` which now incorporates `submit(encoded:)` functionality `WalletTransactionEncoder` now uses a `LightWalletService` to submit the encoded transactions. Add changelog changes Delete references to PendingDb from tests and documentation. Fixes some typos. Adds the ability to trace transaction repository SQL queries from test Fix rebase conflicts and generate code [#837] Memo tests regarding transparent address Closes #837 Add model for transaction output Point to FFI branch Fix issue where sync wouldn't resume after wipe. Becasue GRPC channel would be closed Fix Tests Fix testPendingTransactionMinedHeightUpdated Fix testLastStates [#921] Fix broken SynchronizerDarksideTests Add ZcashTransaction.Output API to Synchronizer Changelog + comment fix Add Assertions for transaction outputs and recipients Point to FFI 0.3.1 Fix Demo App Compiler errors Fix Demo App Compiler errors fix cacheDb warnings Fix Tests and compiler errors of rebase build demo app Remove `ZcashTransaction.Sent` and `.Received`. Add `.State` and tests Fix SPM warning PR Suggestions Removes errors that are not used anymore fix warnings
2023-05-05 10:30:47 -07:00
hasChange: false,
memoCount: 1,
minedHeight: 0,
raw: nil,
rawID: rawID,
[#1001] Remove PendingDb in favor of `v_transactions` and `v_tx_output` Views (#1001) Removes `PendingTransactionEntity` and all of its related components. Pending items are still tracked and visualized by the existing APIs but they are retrieved from the `TransactionRepository` instead by returning `ZcashTransaction.Overview` instead. `pendingDbURL` is removed from every place it was required. Its deletion is responsibility of wallet developers. `ClearedTransactions` are now just `transactions`. `MigrationManager` is deleted. Now all migrations are in charge of the rust welding layer. `PendingTransactionDao.swift` is removed. Implementation of `AccountEntity` called `Account` is now `DbAccount` `ZcashTransaction.Overview` can be checked for "pending-ness" by calling `.isPending(latestHeight:)` latest height must be provided so that minedHeight can be compared with the lastest and the `defaultStaleTolerance` constant. `TransactionRecipient` is now a public type. protocol `PendingTransactionRepository` is removed. `TransactionManagerError` and `PersistentTransactionManager` are deleted. `OutboundTransactionManager` is deleted and replaced by `TransactionEncoder` which now incorporates `submit(encoded:)` functionality `WalletTransactionEncoder` now uses a `LightWalletService` to submit the encoded transactions. Add changelog changes Delete references to PendingDb from tests and documentation. Fixes some typos. Adds the ability to trace transaction repository SQL queries from test Fix rebase conflicts and generate code [#837] Memo tests regarding transparent address Closes #837 Add model for transaction output Point to FFI branch Fix issue where sync wouldn't resume after wipe. Becasue GRPC channel would be closed Fix Tests Fix testPendingTransactionMinedHeightUpdated Fix testLastStates [#921] Fix broken SynchronizerDarksideTests Add ZcashTransaction.Output API to Synchronizer Changelog + comment fix Add Assertions for transaction outputs and recipients Point to FFI 0.3.1 Fix Demo App Compiler errors Fix Demo App Compiler errors fix cacheDb warnings Fix Tests and compiler errors of rebase build demo app Remove `ZcashTransaction.Sent` and `.Received`. Add `.State` and tests Fix SPM warning PR Suggestions Removes errors that are not used anymore fix warnings
2023-05-05 10:30:47 -07:00
receivedNoteCount: 1,
sentNoteCount: 0,
value: .zero,
isExpiredUmined: false
)
let memos = try await self.transactionRepository.findMemos(for: transaction)
XCTAssertEqual(memos.count, 1)
[#959] Fix `v_transactions` view issues with value (#963) This change switches to a new (future) version of the rust crates that will get rid of the sent and received transactions Views in favor of a `v_transaction` view that will do better accounting of outgoing and incoming funds. Additionally it will support an outputs view for seeing the inner details of transactions enabling the SDKs tell the users the precise movement of value that a tx causes in its multiple possible ways according to the protocol. the `v_tx_outputs` view is not yet implemented. Sent and Received transaction sub-types are kept for compatibility purposes but they are generated from Overviews instead of queried from a specific view. In the transaction Overview the value represents the whole value transfer for the transaction from the point of view of a given account including fees. This means that the value for a single transaction Overview struct represents the addition or subtraction of ZEC value to the account's balance. Future updates will give clients the possibility to drill into the inner workings of those value changes in a per-output basis for each transaction. Also, the field `pending_unmined` field was added to `v_transactions` so that wallets can query `DataDb` for pending but yet unmined txs This will prepare the field for removing the notion of a "PendingDb" and its nuances. Also updated test database `darkside_data.db` Closes #959 Closes #971 ZcashLightClientKitSample main target broken swiftlint script Demo App improvements: Show Short date and value on transaction list
2023-04-18 05:10:56 -07:00
XCTAssertEqual(memos[0].toString(), "first mainnet tx from the SDK")
}
func testFindMemoForSentTransaction() async throws {
let rawID = Data(fromHexEncodedString: "08cb5838ffd2c18ce15e7e8c50174940cd9526fff37601986f5480b7ca07e534")!
[#1001] Remove PendingDb in favor of `v_transactions` and `v_tx_output` Views (#1001) Removes `PendingTransactionEntity` and all of its related components. Pending items are still tracked and visualized by the existing APIs but they are retrieved from the `TransactionRepository` instead by returning `ZcashTransaction.Overview` instead. `pendingDbURL` is removed from every place it was required. Its deletion is responsibility of wallet developers. `ClearedTransactions` are now just `transactions`. `MigrationManager` is deleted. Now all migrations are in charge of the rust welding layer. `PendingTransactionDao.swift` is removed. Implementation of `AccountEntity` called `Account` is now `DbAccount` `ZcashTransaction.Overview` can be checked for "pending-ness" by calling `.isPending(latestHeight:)` latest height must be provided so that minedHeight can be compared with the lastest and the `defaultStaleTolerance` constant. `TransactionRecipient` is now a public type. protocol `PendingTransactionRepository` is removed. `TransactionManagerError` and `PersistentTransactionManager` are deleted. `OutboundTransactionManager` is deleted and replaced by `TransactionEncoder` which now incorporates `submit(encoded:)` functionality `WalletTransactionEncoder` now uses a `LightWalletService` to submit the encoded transactions. Add changelog changes Delete references to PendingDb from tests and documentation. Fixes some typos. Adds the ability to trace transaction repository SQL queries from test Fix rebase conflicts and generate code [#837] Memo tests regarding transparent address Closes #837 Add model for transaction output Point to FFI branch Fix issue where sync wouldn't resume after wipe. Becasue GRPC channel would be closed Fix Tests Fix testPendingTransactionMinedHeightUpdated Fix testLastStates [#921] Fix broken SynchronizerDarksideTests Add ZcashTransaction.Output API to Synchronizer Changelog + comment fix Add Assertions for transaction outputs and recipients Point to FFI 0.3.1 Fix Demo App Compiler errors Fix Demo App Compiler errors fix cacheDb warnings Fix Tests and compiler errors of rebase build demo app Remove `ZcashTransaction.Sent` and `.Received`. Add `.State` and tests Fix SPM warning PR Suggestions Removes errors that are not used anymore fix warnings
2023-05-05 10:30:47 -07:00
let transaction = ZcashTransaction.Overview(
accountId: 0,
blockTime: 1,
expiryHeight: nil,
[#1001] Remove PendingDb in favor of `v_transactions` and `v_tx_output` Views (#1001) Removes `PendingTransactionEntity` and all of its related components. Pending items are still tracked and visualized by the existing APIs but they are retrieved from the `TransactionRepository` instead by returning `ZcashTransaction.Overview` instead. `pendingDbURL` is removed from every place it was required. Its deletion is responsibility of wallet developers. `ClearedTransactions` are now just `transactions`. `MigrationManager` is deleted. Now all migrations are in charge of the rust welding layer. `PendingTransactionDao.swift` is removed. Implementation of `AccountEntity` called `Account` is now `DbAccount` `ZcashTransaction.Overview` can be checked for "pending-ness" by calling `.isPending(latestHeight:)` latest height must be provided so that minedHeight can be compared with the lastest and the `defaultStaleTolerance` constant. `TransactionRecipient` is now a public type. protocol `PendingTransactionRepository` is removed. `TransactionManagerError` and `PersistentTransactionManager` are deleted. `OutboundTransactionManager` is deleted and replaced by `TransactionEncoder` which now incorporates `submit(encoded:)` functionality `WalletTransactionEncoder` now uses a `LightWalletService` to submit the encoded transactions. Add changelog changes Delete references to PendingDb from tests and documentation. Fixes some typos. Adds the ability to trace transaction repository SQL queries from test Fix rebase conflicts and generate code [#837] Memo tests regarding transparent address Closes #837 Add model for transaction output Point to FFI branch Fix issue where sync wouldn't resume after wipe. Becasue GRPC channel would be closed Fix Tests Fix testPendingTransactionMinedHeightUpdated Fix testLastStates [#921] Fix broken SynchronizerDarksideTests Add ZcashTransaction.Output API to Synchronizer Changelog + comment fix Add Assertions for transaction outputs and recipients Point to FFI 0.3.1 Fix Demo App Compiler errors Fix Demo App Compiler errors fix cacheDb warnings Fix Tests and compiler errors of rebase build demo app Remove `ZcashTransaction.Sent` and `.Received`. Add `.State` and tests Fix SPM warning PR Suggestions Removes errors that are not used anymore fix warnings
2023-05-05 10:30:47 -07:00
fee: nil,
index: 0,
[#1001] Remove PendingDb in favor of `v_transactions` and `v_tx_output` Views (#1001) Removes `PendingTransactionEntity` and all of its related components. Pending items are still tracked and visualized by the existing APIs but they are retrieved from the `TransactionRepository` instead by returning `ZcashTransaction.Overview` instead. `pendingDbURL` is removed from every place it was required. Its deletion is responsibility of wallet developers. `ClearedTransactions` are now just `transactions`. `MigrationManager` is deleted. Now all migrations are in charge of the rust welding layer. `PendingTransactionDao.swift` is removed. Implementation of `AccountEntity` called `Account` is now `DbAccount` `ZcashTransaction.Overview` can be checked for "pending-ness" by calling `.isPending(latestHeight:)` latest height must be provided so that minedHeight can be compared with the lastest and the `defaultStaleTolerance` constant. `TransactionRecipient` is now a public type. protocol `PendingTransactionRepository` is removed. `TransactionManagerError` and `PersistentTransactionManager` are deleted. `OutboundTransactionManager` is deleted and replaced by `TransactionEncoder` which now incorporates `submit(encoded:)` functionality `WalletTransactionEncoder` now uses a `LightWalletService` to submit the encoded transactions. Add changelog changes Delete references to PendingDb from tests and documentation. Fixes some typos. Adds the ability to trace transaction repository SQL queries from test Fix rebase conflicts and generate code [#837] Memo tests regarding transparent address Closes #837 Add model for transaction output Point to FFI branch Fix issue where sync wouldn't resume after wipe. Becasue GRPC channel would be closed Fix Tests Fix testPendingTransactionMinedHeightUpdated Fix testLastStates [#921] Fix broken SynchronizerDarksideTests Add ZcashTransaction.Output API to Synchronizer Changelog + comment fix Add Assertions for transaction outputs and recipients Point to FFI 0.3.1 Fix Demo App Compiler errors Fix Demo App Compiler errors fix cacheDb warnings Fix Tests and compiler errors of rebase build demo app Remove `ZcashTransaction.Sent` and `.Received`. Add `.State` and tests Fix SPM warning PR Suggestions Removes errors that are not used anymore fix warnings
2023-05-05 10:30:47 -07:00
hasChange: false,
memoCount: 1,
minedHeight: nil,
raw: nil,
rawID: rawID,
[#1001] Remove PendingDb in favor of `v_transactions` and `v_tx_output` Views (#1001) Removes `PendingTransactionEntity` and all of its related components. Pending items are still tracked and visualized by the existing APIs but they are retrieved from the `TransactionRepository` instead by returning `ZcashTransaction.Overview` instead. `pendingDbURL` is removed from every place it was required. Its deletion is responsibility of wallet developers. `ClearedTransactions` are now just `transactions`. `MigrationManager` is deleted. Now all migrations are in charge of the rust welding layer. `PendingTransactionDao.swift` is removed. Implementation of `AccountEntity` called `Account` is now `DbAccount` `ZcashTransaction.Overview` can be checked for "pending-ness" by calling `.isPending(latestHeight:)` latest height must be provided so that minedHeight can be compared with the lastest and the `defaultStaleTolerance` constant. `TransactionRecipient` is now a public type. protocol `PendingTransactionRepository` is removed. `TransactionManagerError` and `PersistentTransactionManager` are deleted. `OutboundTransactionManager` is deleted and replaced by `TransactionEncoder` which now incorporates `submit(encoded:)` functionality `WalletTransactionEncoder` now uses a `LightWalletService` to submit the encoded transactions. Add changelog changes Delete references to PendingDb from tests and documentation. Fixes some typos. Adds the ability to trace transaction repository SQL queries from test Fix rebase conflicts and generate code [#837] Memo tests regarding transparent address Closes #837 Add model for transaction output Point to FFI branch Fix issue where sync wouldn't resume after wipe. Becasue GRPC channel would be closed Fix Tests Fix testPendingTransactionMinedHeightUpdated Fix testLastStates [#921] Fix broken SynchronizerDarksideTests Add ZcashTransaction.Output API to Synchronizer Changelog + comment fix Add Assertions for transaction outputs and recipients Point to FFI 0.3.1 Fix Demo App Compiler errors Fix Demo App Compiler errors fix cacheDb warnings Fix Tests and compiler errors of rebase build demo app Remove `ZcashTransaction.Sent` and `.Received`. Add `.State` and tests Fix SPM warning PR Suggestions Removes errors that are not used anymore fix warnings
2023-05-05 10:30:47 -07:00
receivedNoteCount: 0,
sentNoteCount: 2,
value: .zero,
isExpiredUmined: false
)
let memos = try await self.transactionRepository.findMemos(for: transaction)
XCTAssertEqual(memos.count, 1)
XCTAssertEqual(memos[0].toString(), "Some funds")
}
func testFindAllPerformance() {
// This is an example of a performance test case.
self.measure {
let expectation = expectation(description: "Measure")
Task(priority: .userInitiated) {
// Put the code you want to measure the time of here.
do {
_ = try await self.transactionRepository.find(offset: 0, limit: Int.max, kind: .all)
expectation.fulfill()
} catch {
XCTFail("find all failed")
}
}
wait(for: [expectation], timeout: 2)
}
}
func testFindAllFrom() async throws {
let rawID = Data(fromHexEncodedString: "5d9b91e31a6d3f94844a4c330e727a2d5d0643f6caa6c75573b28aefe859e8d2")!
let transaction = try await self.transactionRepository.find(rawID: rawID)
let transactionsFrom = try await self.transactionRepository.find(from: transaction, limit: Int.max, kind: .all)
XCTAssertEqual(transactionsFrom.count, 15)
transactionsFrom.forEach { preceededTransaction in
guard let precedingHeight = preceededTransaction.minedHeight, let transactionHeight = transaction.minedHeight else {
XCTFail("Transactions are missing mined heights.")
return
}
guard let precedingBlockTime = preceededTransaction.blockTime, let transactionBlockTime = transaction.blockTime else {
XCTFail("Transactions are missing block time.")
return
}
XCTAssertLessThanOrEqual(precedingHeight, transactionHeight)
XCTAssertLessThan(precedingBlockTime, transactionBlockTime)
}
}
}
extension Data {
init?(fromHexEncodedString string: String) {
// Convert 0 ... 9, a ... f, A ...F to their decimal value,
// return nil for all other input characters
2021-09-23 06:26:41 -07:00
func decodeNibble(bytes: UInt16) -> UInt8? {
switch bytes {
case 0x30 ... 0x39:
2021-09-23 06:26:41 -07:00
return UInt8(bytes - 0x30)
case 0x41 ... 0x46:
2021-09-23 06:26:41 -07:00
return UInt8(bytes - 0x41 + 10)
case 0x61 ... 0x66:
2021-09-23 06:26:41 -07:00
return UInt8(bytes - 0x61 + 10)
default:
return nil
}
}
2021-09-23 06:26:41 -07:00
self.init(capacity: string.utf16.count / 2)
var even = true
var byte: UInt8 = 0
2021-09-23 06:26:41 -07:00
for char in string.utf16 {
guard let val = decodeNibble(bytes: char) else { return nil }
if even {
byte = val << 4
} else {
byte += val
self.append(byte)
}
2021-09-23 06:26:41 -07:00
even.toggle()
}
guard even else { return nil }
}
}