Get Address Example, API improvements, test fixes (#10)

This commit is contained in:
Francisco Gindre 2019-11-01 16:59:16 -03:00 committed by GitHub
parent b1887cc1b6
commit bce2bd0d7e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 255 additions and 54 deletions

View File

@ -7,6 +7,7 @@
objects = {
/* Begin PBXBuildFile section */
0D756A94236C761E009B041B /* GetAddressViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0D756A93236C761E009B041B /* GetAddressViewController.swift */; };
0D907F162322CC5900D641FE /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0D907F152322CC5900D641FE /* AppDelegate.swift */; };
0D907F182322CC5900D641FE /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0D907F172322CC5900D641FE /* ViewController.swift */; };
0D907F1B2322CC5900D641FE /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 0D907F192322CC5900D641FE /* Main.storyboard */; };
@ -39,6 +40,7 @@
/* End PBXContainerItemProxy section */
/* Begin PBXFileReference section */
0D756A93236C761E009B041B /* GetAddressViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GetAddressViewController.swift; sourceTree = "<group>"; };
0D907F122322CC5900D641FE /* ZcashLightClientSample.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = ZcashLightClientSample.app; sourceTree = BUILT_PRODUCTS_DIR; };
0D907F152322CC5900D641FE /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
0D907F172322CC5900D641FE /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = "<group>"; };
@ -93,6 +95,14 @@
/* End PBXFrameworksBuildPhase section */
/* Begin PBXGroup section */
0D756A92236C75FE009B041B /* Get Address */ = {
isa = PBXGroup;
children = (
0D756A93236C761E009B041B /* GetAddressViewController.swift */,
);
path = "Get Address";
sourceTree = "<group>";
};
0D907F092322CC5900D641FE = {
isa = PBXGroup;
children = (
@ -118,6 +128,7 @@
0D907F142322CC5900D641FE /* ZcashLightClientSample */ = {
isa = PBXGroup;
children = (
0D756A92236C75FE009B041B /* Get Address */,
0DDFB33A236B733700AED892 /* Latest Block Height */,
0D907F152322CC5900D641FE /* AppDelegate.swift */,
0D907F172322CC5900D641FE /* ViewController.swift */,
@ -246,7 +257,7 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 1020;
LastUpgradeCheck = 1020;
LastUpgradeCheck = 1110;
ORGANIZATIONNAME = "Electric Coin Company";
TargetAttributes = {
0D907F112322CC5900D641FE = {
@ -400,6 +411,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
0D756A94236C761E009B041B /* GetAddressViewController.swift in Sources */,
0D907F182322CC5900D641FE /* ViewController.swift in Sources */,
0DDFB33C236B743000AED892 /* LatestHeightViewController.swift in Sources */,
0DDFB33E236B844900AED892 /* DemoAppConfig.swift in Sources */,

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1020"
LastUpgradeVersion = "1110"
version = "1.3">
<BuildAction
parallelizeBuildables = "NO"

View File

@ -7,15 +7,28 @@
//
import UIKit
import ZcashLightClientKit
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
private var wallet: Wallet?
var addresses: [String]?
var sharedWallet: Wallet {
if let wallet = wallet {
return wallet
} else {
let wallet = Wallet(cacheDbURL:try! __cacheDbURL() , dataDbURL: try! __dataDbURL())
self.addresses = try! wallet.initialize(seedProvider: DemoAppConfig(), walletBirthdayHeight: BlockHeight(DemoAppConfig.birthdayHeight)) // Init or DIE
self.wallet = wallet
return wallet
}
}
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
_ = self.sharedWallet
return true
}
@ -43,4 +56,27 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
}
/**
The functions below are convenience functions for THIS SAMPLE APP.
*/
extension DemoAppConfig: SeedProvider {}
extension Wallet {
static var shared: Wallet {
(UIApplication.shared.delegate as! AppDelegate).sharedWallet // AppDelegate or DIE.
}
}
func __documentsDirectory() throws -> URL {
try FileManager.default.url(for: .documentDirectory, in: .userDomainMask, appropriateFor: nil, create: true)
}
func __cacheDbURL() throws -> URL {
try __documentsDirectory().appendingPathComponent("cache.db", isDirectory: false)
}
func __dataDbURL() throws -> URL {
try __documentsDirectory().appendingPathComponent("data.db", isDirectory: false)
}

View File

@ -19,9 +19,29 @@
<sections>
<tableViewSection id="HAA-1f-le3">
<cells>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="default" indentationWidth="10" textLabel="AMo-WC-MIN" style="IBUITableViewCellStyleDefault" id="rCB-Ax-4Nk">
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="default" indentationWidth="10" textLabel="Dic-ex-pwz" style="IBUITableViewCellStyleDefault" id="thm-RZ-Mhh">
<rect key="frame" x="0.0" y="28" width="414" height="43.5"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="thm-RZ-Mhh" id="zOR-bL-Uwc">
<rect key="frame" x="0.0" y="0.0" width="414" height="43.5"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" insetsLayoutMarginsFromSafeArea="NO" text="Get Address" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="Dic-ex-pwz">
<rect key="frame" x="20" y="0.0" width="374" height="43.5"/>
<autoresizingMask key="autoresizingMask"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
</subviews>
</tableViewCellContentView>
<connections>
<segue destination="Rx9-1X-8Gi" kind="show" id="YDj-7N-giN"/>
</connections>
</tableViewCell>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="default" indentationWidth="10" textLabel="AMo-WC-MIN" style="IBUITableViewCellStyleDefault" id="rCB-Ax-4Nk">
<rect key="frame" x="0.0" y="71.5" width="414" height="43.5"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="rCB-Ax-4Nk" id="ac2-bZ-mAy">
<rect key="frame" x="0.0" y="0.0" width="414" height="43.5"/>
<autoresizingMask key="autoresizingMask"/>
@ -53,6 +73,39 @@
</objects>
<point key="canvasLocation" x="828" y="40"/>
</scene>
<!--Get Addreses-->
<scene sceneID="zFi-Pu-g6Q">
<objects>
<viewController title="Get Addreses" id="Rx9-1X-8Gi" customClass="GetAddressViewController" customModule="ZcashLightClientSample" customModuleProvider="target" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="5WU-Pu-1e9">
<rect key="frame" x="0.0" y="0.0" width="414" height="896"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="center" lineBreakMode="characterWrap" numberOfLines="0" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="X0E-Ba-xxX">
<rect key="frame" x="16" y="50" width="382" height="796"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
</subviews>
<color key="backgroundColor" systemColor="systemBackgroundColor" cocoaTouchSystemColor="whiteColor"/>
<constraints>
<constraint firstItem="jVy-LO-XKe" firstAttribute="trailing" secondItem="X0E-Ba-xxX" secondAttribute="trailing" constant="16" id="FqK-H1-XgY"/>
<constraint firstItem="X0E-Ba-xxX" firstAttribute="centerX" secondItem="5WU-Pu-1e9" secondAttribute="centerX" id="UK8-Jg-oK4"/>
<constraint firstItem="X0E-Ba-xxX" firstAttribute="centerY" secondItem="5WU-Pu-1e9" secondAttribute="centerY" id="VGo-Dc-2EC"/>
<constraint firstItem="jVy-LO-XKe" firstAttribute="bottom" secondItem="X0E-Ba-xxX" secondAttribute="bottom" constant="16" id="Wth-O9-0B1"/>
</constraints>
<viewLayoutGuide key="safeArea" id="jVy-LO-XKe"/>
</view>
<navigationItem key="navigationItem" title="Get Address" largeTitleDisplayMode="always" id="Uvy-EM-bSo"/>
<connections>
<outlet property="addressLabel" destination="X0E-Ba-xxX" id="9es-sw-gO5"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="kr1-B6-akA" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="1800" y="-445"/>
</scene>
<!--Latest Height View Controller-->
<scene sceneID="4pw-mR-qER">
<objects>
@ -94,7 +147,7 @@
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="mVQ-br-4uP" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="1528.985507246377" y="3.3482142857142856"/>
<point key="canvasLocation" x="1745" y="261"/>
</scene>
<!--Navigation Controller-->
<scene sceneID="0ru-sC-FRK">

View File

@ -0,0 +1,42 @@
//
// GetAddressViewController.swift
// ZcashLightClientSample
//
// Created by Francisco Gindre on 11/1/19.
// Copyright © 2019 Electric Coin Company. All rights reserved.
//
import UIKit
import ZcashLightClientKit
class GetAddressViewController: UIViewController {
@IBOutlet weak var addressLabel: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
addressLabel.text = legibleAddresses() ?? "No Addresses found"
}
/*
// MARK: - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
// Get the new view controller using segue.destination.
// Pass the selected object to the new view controller.
}
*/
func legibleAddresses() -> String? {
Wallet.shared.getAddress()
}
}
extension SeedProvider {
func seed() -> [UInt8] {
Array(DemoAppConfig.address.utf8)
}
}

View File

@ -151,7 +151,9 @@ class CompactBlockProcessor {
// TODO: check if this validation makes sense at all
// try validateConfiguration()
guard rustBackend.initDataDb(dbData: config.dataDb) else {
do {
try rustBackend.initDataDb(dbData: config.dataDb)
} catch {
throw CompactBlockProcessorError.dataDbInitFailed(path: config.dataDb.absoluteString)
}

View File

@ -7,13 +7,10 @@
//
import Foundation
enum RustWeldingError: Error {
case genericError(message: String)
}
class ZcashRustBackend: ZcashRustBackendWelding {
static func lastError() -> Error? {
static func lastError() -> RustWeldingError? {
guard let message = getLastError() else { return nil }
return RustWeldingError.genericError(message: message)
}
@ -33,9 +30,14 @@ class ZcashRustBackend: ZcashRustBackendWelding {
/**
* Sets up the internal structure of the data database.
*/
static func initDataDb(dbData: URL) -> Bool {
static func initDataDb(dbData: URL) throws {
let dbData = dbData.osStr()
return zcashlc_init_data_database(dbData.0, dbData.1) != 0
guard zcashlc_init_data_database(dbData.0, dbData.1) != 0 else {
if let error = lastError() {
throw throwDataDbError(error)
}
throw RustWeldingError.dataDbInitFailed(message: "unknown error")
}
}
static func initAccountsTable(dbData: URL, seed: [UInt8], accounts: Int32) -> [String]? {
@ -53,9 +55,14 @@ class ZcashRustBackend: ZcashRustBackendWelding {
return extsks
}
static func initBlocksTable(dbData: URL, height: Int32, hash: String, time: UInt32, saplingTree: String) -> Bool {
static func initBlocksTable(dbData: URL, height: Int32, hash: String, time: UInt32, saplingTree: String) throws {
let dbData = dbData.osStr()
return zcashlc_init_blocks_table(dbData.0, dbData.1, height, [CChar](hash.utf8CString), time, [CChar](saplingTree.utf8CString)) != 0
guard zcashlc_init_blocks_table(dbData.0, dbData.1, height, [CChar](hash.utf8CString), time, [CChar](saplingTree.utf8CString)) != 0 else {
if let error = lastError() {
throw throwDataDbError(error)
}
throw RustWeldingError.dataDbInitFailed(message: "Unknown Error")
}
}
static func getAddress(dbData: URL, account: Int32) -> String? {
@ -121,6 +128,17 @@ class ZcashRustBackend: ZcashRustBackendWelding {
let outputParams = outputParams.osStr()
return zcashlc_send_to_address(dbData.0, dbData.1, account, extsk, to, value, memo, spendParams.0, spendParams.1, outputParams.0, outputParams.1)
}
}
private extension ZcashRustBackend {
static func throwDataDbError(_ error: RustWeldingError) -> Error {
if case RustWeldingError.genericError(let message) = error, message.contains("is not empty") {
return RustWeldingError.dataDbNotEmpty
}
return RustWeldingError.dataDbInitFailed(message: error.localizedDescription)
}
}
private extension URL {

View File

@ -8,20 +8,26 @@
import Foundation
enum RustWeldingError: Error {
case genericError(message: String)
case dataDbInitFailed(message: String)
case dataDbNotEmpty
}
struct ZcashRustBackendWeldingConstants {
static let validChain: Int32 = -1
}
protocol ZcashRustBackendWelding {
static func lastError() -> Error?
static func lastError() -> RustWeldingError?
static func getLastError() -> String?
static func initDataDb(dbData: URL) -> Bool
static func initDataDb(dbData: URL) throws
static func initAccountsTable(dbData: URL, seed: [UInt8], accounts: Int32) -> [String]?
static func initBlocksTable(dbData: URL, height: Int32, hash: String, time: UInt32, saplingTree: String) -> Bool
static func initBlocksTable(dbData: URL, height: Int32, hash: String, time: UInt32, saplingTree: String) throws
static func getAddress(dbData: URL, account: Int32) -> String?

View File

@ -15,43 +15,57 @@ import Foundation
public enum WalletError: Error {
case cacheDbInitFailed
case dataDbInitFailed
case accountInitFailed
case falseStart
}
public class Wallet {
private var rustBackend: ZcashRustBackendWelding.Type = ZcashRustBackend.self
private var dataDbURL: URL
private var lowerBoundHeight: BlockHeight = SAPLING_ACTIVATION_HEIGHT
private var cacheDbURL: URL
private var paramDestination: URL
private var accountIDs: [Int]
private var seedProvider: SeedProvider
private var walletBirthday: WalletBirthday
private var compactBlockStorage: CompactBlockStoring?
private var dataDbURL: URL
init(cacheDbURL: URL, dataDbURL: URL, paramDestination: URL, seedProvider: SeedProvider, walletBirthday: WalletBirthday, accountIDs: [Int] = [0]) {
self.dataDbURL = dataDbURL
self.paramDestination = paramDestination
self.accountIDs = accountIDs
self.seedProvider = seedProvider
public init (cacheDbURL: URL, dataDbURL: URL) {
self.cacheDbURL = cacheDbURL
self.walletBirthday = walletBirthday
self.dataDbURL = dataDbURL
}
public func initalize(firstRunStartHeight: BlockHeight = SAPLING_ACTIVATION_HEIGHT) throws {
public func initialize(seedProvider: SeedProvider, walletBirthdayHeight: BlockHeight, numberOfAccounts: Int = 1) throws -> [String]? {
guard rustBackend.initDataDb(dbData: dataDbURL) else {
do {
try rustBackend.initDataDb(dbData: dataDbURL)
} catch RustWeldingError.dataDbNotEmpty {
// this is fine
} catch {
throw WalletError.dataDbInitFailed
}
guard let birthday = WalletBirthday.birthday(with: walletBirthdayHeight) else {
throw WalletError.falseStart
}
lowerBoundHeight = birthday.height
do {
try rustBackend.initBlocksTable(dbData: dataDbURL, height: Int32(birthday.height), hash: birthday.hash, time: birthday.time, saplingTree: birthday.tree)
} catch RustWeldingError.dataDbNotEmpty {
// this is fine
} catch {
throw WalletError.dataDbInitFailed
}
self.compactBlockStorage = CompactBlockStorage(connectionProvider: SimpleConnectionProvider(path: cacheDbURL.absoluteString))
guard let accounts = rustBackend.initAccountsTable(dbData: dataDbURL, seed: seedProvider.seed(), accounts: Int32(numberOfAccounts)) else {
throw rustBackend.lastError() ?? WalletError.accountInitFailed
}
return accounts
}
public func latestBlockHeight() -> BlockHeight {
(try? self.compactBlockStorage?.latestHeight()) ?? BlockHeight.empty()
public func getAddress(index account: Int = 0) -> String? {
return rustBackend.getAddress(dbData: dataDbURL, account: Int32(account))
}
}
/**
@ -76,6 +90,28 @@ public class Wallet {
public struct WalletBirthday {
var height: BlockHeight = -1
var hash: String = ""
var time: TimeInterval = -1
var time: UInt32 = 0
var tree: String = ""
}
// TODO: remove this in favor of loading these from disk
public extension WalletBirthday {
static func birthday(with height: BlockHeight) -> WalletBirthday? {
switch height {
case 280_000:
return WalletBirthday(height: 280000, hash: "000420e7fcc3a49d729479fb0b560dd7b8617b178a08e9e389620a9d1dd6361a", time: 1535262293, tree: "000000")
case 421720:
return WalletBirthday(height: 421720, hash: "001ede53476a31a91da3313eddf4e41409fb7f4e003840700557b576024d09b4", time: 1550762014, tree: "015495a30aef9e18b9c774df6a9fcd583748c8bba1a6348e70f59bc9f0c2bc673b000f00000000018054b75173b577dc36f2c80dfc41f83d6716557597f74ec54436df32d4466d57000120f1825067a52ca973b07431199d5866a0d46ef231d08aa2f544665936d5b4520168d782e3d028131f59e9296c75de5a101898c5e53108e45baa223c608d6c3d3d01fb0a8d465b57c15d793c742df9470b116ddf06bd30d42123fdb7becef1fd63640001a86b141bdb55fd5f5b2e880ea4e07caf2bbf1ac7b52a9f504977913068a917270001dd960b6c11b157d1626f0768ec099af9385aea3f31c91111a8c5b899ffb99e6b0192acd61b1853311b0bf166057ca433e231c93ab5988844a09a91c113ebc58e18019fbfd76ad6d98cafa0174391546e7022afe62e870e20e16d57c4c419a5c2bb69")
case 425865:
return WalletBirthday(height: 425865, hash: "0011c4de26004e564347b8af218ca16cd07b08c4159b1cc9c43afa6cb8807bed", time: 1551215770, tree: "01881e4da7e4767ee8a144a32ab8a5719a513bb05854477773bb55e6cd7f15055201f8a99a3a5ae3528ec2fc0bda9652b6728aecb08bf364e06ac511fd6654d782720f019ef0b9bdd075c38519fa4ab8210fe7e94c609f52672796e33e3cab58b1602831000001f803bf338ff1526b2ca527288974cb9be3fe240a2eadb7507e46ba59eaddb9320129fc0148ac088a6aa509f8f64ef79fda92232020369b58a12b32c05b6f428f22015e3dd0950c442940bd015c2176f7c817f22104f54c61159727483188c539dc13000000013589be9e2d9e9e38fd78b1e8eaec5b5f5167bf7fd2b1c95c316fa366a24cac4c01a86b141bdb55fd5f5b2e880ea4e07caf2bbf1ac7b52a9f504977913068a917270001dd960b6c11b157d1626f0768ec099af9385aea3f31c91111a8c5b899ffb99e6b0192acd61b1853311b0bf166057ca433e231c93ab5988844a09a91c113ebc58e18019fbfd76ad6d98cafa0174391546e7022afe62e870e20e16d57c4c419a5c2bb69")
case 518000:
return WalletBirthday(height: 518000, hash: "000ba586d734c295f0bc034be229b1c96cb040f9d4929efdb5d2b187eeb238fb", time: 1560645743, tree: "01a4f5240a88a6eb4ffbda7961a1430506aad1a50ba011593f02c243d968feb0550010000140f91773b4ab669846e5bcb96f60e68256c49a27872a98e9d5ce50b30a0c434e0000018968663d6a7b444591de83f8a07223113f5de7e8203807adacc7677c3bcd4f420194c7ecac0ef6d702d475680ec32051fdf6368af0c459ab450009c001bcbf7a5300000001f0eead5192c3b3ab7208429877570676647e448210332c6da7e18660b142b80e01b98b14cab05247195b3b3be3dd8639bae99a0dd10bed1282ac25b62a134afd7200000000011f8322ef806eb2430dc4a7a41c1b344bea5be946efc7b4349c1c9edb14ff9d39")
case 523240:
return WalletBirthday(height: 523240, hash: "00000c33da2196f0ed1bda71043f671fc69a0212e01f892653e212ab358f6b79", time: 1561002603, tree: "01d3e02bc1c2d66762f370b329a3063067701ad66c44b40285686bc8ff25f5616f00100154bff87bd0bda3b70a6d7754eca261de15fee3cd9bc53073a232e07fc3261e27000001a54dcaccb4c5e578aef89f2a3b4e3c3d8a487e6e904c5da5916118d721948d07000000000118fa9c6fef4963049dc7002a13bb0021d5e950591e48c9e5f2cbd1199429b80401f0eead5192c3b3ab7208429877570676647e448210332c6da7e18660b142b80e01b98b14cab05247195b3b3be3dd8639bae99a0dd10bed1282ac25b62a134afd7200000000011f8322ef806eb2430dc4a7a41c1b344bea5be946efc7b4349c1c9edb14ff9d39")
case 620000:
return WalletBirthday(height: 620000, hash: "005f97953c8e1265d6b45f4435ffa32918e53e8f0025c286a4080c3eab167197", time: 1569572035, tree: "0170cf036ea1ea3c6e08432e18b6a372ca0b8b83671cc13ab0cf9e28c182f6c36f00100000013f3fc2c16ac4780f1c472ca65534ab08911f325a9edde5ea7f24364b47c9a95300017621b12e518cbbbdb7511ab423e0bddda412ed61ed3cff5be2140de65d6a0069010576153a5a2098812e7a028c37c3398e186f398c9b07bc199784ab97e5535c3e0000019a6ce2f0f7dbb2de493a315abf62d8ca96ccc701f116b6ddfae33870a2183d3c01c9d3564eff54ebc328eab2e4f1150c3637f4f47516f879a0cfebdf49fe7b1d5201c104705fac60a85596010e41260d07f3a64f38f37a112eaef41cd9d736edc5270145e3d4899fcd7f0f1236ae31eafb3f4b65ad6b11a17eae1729cec09bd3afa01a000000011f8322ef806eb2430dc4a7a41c1b344bea5be946efc7b4349c1c9edb14ff9d39")
default:
return nil
}
}
}

View File

@ -13,9 +13,10 @@ class BlockDownloaderTests: XCTestCase {
var downloader: CompactBlockDownloading!
var service: LightWalletService!
var storage: CompactBlockStoring!
var cacheDB = try! __cacheDbURL()
override func setUp() {
service = LightWalletGRPCService(channel: ChannelProvider().channel())
storage = try! TestDbBuilder.inMemoryCompactBlockStorage()
storage = try! TestDbBuilder.diskCompactBlockStorage(at: cacheDB)
downloader = CompactBlockDownloader(service: service, storage: storage)
}
@ -24,6 +25,7 @@ class BlockDownloaderTests: XCTestCase {
service = nil
storage = nil
downloader = nil
try? FileManager.default.removeItem(at: cacheDB)
}
func testSmallDownloadAsync() {

View File

@ -38,10 +38,7 @@ class BlockScanOperationTests: XCTestCase {
}
func testSingleDownloadAndScanOperation() {
guard rustWelding.initDataDb(dbData: dataDbURL) else {
XCTFail("could not initialize data DB")
return
}
XCTAssertNoThrow(try rustWelding.initDataDb(dbData: dataDbURL))
let downloadStartedExpect = XCTestExpectation(description: self.description + "download started")
let downloadExpect = XCTestExpectation(description: self.description + "download")

View File

@ -45,7 +45,7 @@ class CompactBlockProcessorTests: XCTestCase {
override func tearDown() {
try! FileManager.default.removeItem(at: processorConfig.cacheDb)
try! FileManager.default.removeItem(at: processorConfig.dataDb)
try? FileManager.default.removeItem(at: processorConfig.dataDb)
downloadStartedExpect.unsubscribeFromNotifications()
stopNotificationExpectation.unsubscribeFromNotifications()
updatedNotificationExpectation.unsubscribeFromNotifications()

View File

@ -31,14 +31,12 @@ class WalletTests: XCTestCase {
func testWalletInitialization() {
let wallet = Wallet(rustWelding: ZcashRustBackend.self, cacheDbURL: cacheData, dataDbURL: dbData, paramDestination: paramDestination, seedProvider: SampleSeedProvider(), walletBirthday: WalletBirthdayProvider.testBirthday)
let wallet = Wallet(cacheDbURL: cacheData, dataDbURL: dbData)
XCTAssertNoThrow(try wallet.initalize())
XCTAssertNoThrow(try wallet.initialize(seedProvider: SampleSeedProvider(), walletBirthdayHeight: SAPLING_ACTIVATION_HEIGHT))
// fileExists actually sucks, so attempting to delete the file and checking what happens is far better :)
XCTAssertNoThrow( try FileManager.default.removeItem(at: dbData!) )
XCTAssertEqual(wallet.latestBlockHeight(), BlockHeight.empty())
XCTAssertNoThrow( try FileManager.default.removeItem(at: cacheData!) )
}

View File

@ -26,8 +26,7 @@ class ZcashRustBackendTests: XCTestCase {
func testInitAndGetAddress() {
let seed = "seed"
XCTAssert(ZcashRustBackend.initDataDb(dbData: dbData!))
XCTAssertEqual(ZcashRustBackend.getLastError(), nil)
XCTAssertNoThrow(try ZcashRustBackend.initDataDb(dbData: dbData!))
let _ = ZcashRustBackend.initAccountsTable(dbData: dbData!, seed: Array(seed.utf8), accounts: 1)
XCTAssertEqual(ZcashRustBackend.getLastError(), nil)
@ -48,10 +47,10 @@ class ZcashRustBackendTests: XCTestCase {
return
}
let seed = "seed"
XCTAssertTrue(ZcashRustBackend.initDataDb(dbData: dbData!))
XCTAssertNoThrow(try ZcashRustBackend.initDataDb(dbData: dbData!))
XCTAssertEqual(ZcashRustBackend.getLastError(), nil)
let _ = ZcashRustBackend.initAccountsTable(dbData: dbData!, seed: Array(seed.utf8), accounts: 1)
XCTAssertNotNil(ZcashRustBackend.initAccountsTable(dbData: dbData!, seed: Array(seed.utf8), accounts: 1))
XCTAssertEqual(ZcashRustBackend.getLastError(), nil)
let addr = ZcashRustBackend.getAddress(dbData: dbData!, account: 0)