2019-10-18 11:45:19 -07:00
|
|
|
//
|
|
|
|
// WalletTests.swift
|
|
|
|
// ZcashLightClientKitTests
|
|
|
|
//
|
|
|
|
// Created by Francisco Gindre on 13/09/2019.
|
|
|
|
// Copyright © 2019 Electric Coin Company. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
import Foundation
|
|
|
|
import XCTest
|
2022-02-28 09:03:20 -08:00
|
|
|
@testable import TestUtils
|
2019-10-18 11:45:19 -07:00
|
|
|
@testable import ZcashLightClientKit
|
|
|
|
|
2023-02-02 08:58:12 -08:00
|
|
|
// swiftlint:disable implicitly_unwrapped_optional force_unwrapping
|
2019-10-18 11:45:19 -07:00
|
|
|
class WalletTests: XCTestCase {
|
2023-02-02 08:58:12 -08:00
|
|
|
let testTempDirectory = URL(fileURLWithPath: NSString(
|
|
|
|
string: NSTemporaryDirectory()
|
|
|
|
)
|
|
|
|
.appendingPathComponent("tmp-\(Int.random(in: 0 ... .max))"))
|
|
|
|
|
|
|
|
let testFileManager = FileManager()
|
|
|
|
|
2019-10-18 11:45:19 -07:00
|
|
|
var dbData: URL! = nil
|
|
|
|
var paramDestination: URL! = nil
|
2021-07-28 09:59:10 -07:00
|
|
|
var network = ZcashNetworkBuilder.network(for: .testnet)
|
2021-09-23 06:26:41 -07:00
|
|
|
var seedData = Data(base64Encoded: "9VDVOZZZOWWHpZtq1Ebridp3Qeux5C+HwiRR0g7Oi7HgnMs8Gfln83+/Q1NnvClcaSwM4ADFL1uZHxypEWlWXg==")!
|
|
|
|
|
2023-02-02 08:58:12 -08:00
|
|
|
override func setUpWithError() throws {
|
|
|
|
try super.setUpWithError()
|
|
|
|
dbData = try __dataDbURL()
|
|
|
|
try self.testFileManager.createDirectory(at: self.testTempDirectory, withIntermediateDirectories: false)
|
|
|
|
paramDestination = try __documentsDirectory().appendingPathComponent("parameters")
|
2019-10-18 11:45:19 -07:00
|
|
|
}
|
|
|
|
|
2023-02-02 08:58:12 -08:00
|
|
|
override func tearDownWithError() throws {
|
|
|
|
try super.tearDownWithError()
|
|
|
|
if testFileManager.fileExists(atPath: dbData.absoluteString) {
|
|
|
|
try testFileManager.trashItem(at: dbData, resultingItemURL: nil)
|
2019-10-18 11:45:19 -07:00
|
|
|
}
|
2023-02-02 08:58:12 -08:00
|
|
|
try? self.testFileManager.removeItem(at: self.testTempDirectory)
|
2019-10-18 11:45:19 -07:00
|
|
|
}
|
|
|
|
|
2022-11-23 10:05:49 -08:00
|
|
|
func testWalletInitialization() throws {
|
2021-07-28 09:59:10 -07:00
|
|
|
let derivationTool = DerivationTool(networkType: network.networkType)
|
2022-10-02 19:11:17 -07:00
|
|
|
let ufvk = try derivationTool.deriveUnifiedSpendingKey(seed: seedData.bytes, accountIndex: 0)
|
2023-01-18 08:09:04 -08:00
|
|
|
.map({ try derivationTool.deriveUnifiedFullViewingKey(from: $0) })
|
2021-09-23 06:26:41 -07:00
|
|
|
let wallet = Initializer(
|
2023-02-02 08:58:12 -08:00
|
|
|
fsBlockDbRoot: self.testTempDirectory,
|
2021-09-23 06:26:41 -07:00
|
|
|
dataDbURL: try __dataDbURL(),
|
|
|
|
pendingDbURL: try TestDbBuilder.pendingTransactionsDbURL(),
|
|
|
|
endpoint: LightWalletEndpointBuilder.default,
|
|
|
|
network: network,
|
|
|
|
spendParamsURL: try __spendParamsURL(),
|
|
|
|
outputParamsURL: try __outputParamsURL(),
|
2022-10-02 19:11:17 -07:00
|
|
|
viewingKeys: [ufvk],
|
2021-09-23 06:26:41 -07:00
|
|
|
walletBirthday: 663194
|
|
|
|
)
|
2021-07-28 09:59:10 -07:00
|
|
|
|
|
|
|
let synchronizer = try SDKSynchronizer(initializer: wallet)
|
2022-10-27 03:51:38 -07:00
|
|
|
do {
|
2022-11-28 22:40:45 -08:00
|
|
|
guard case .success = try synchronizer.prepare(with: seedData.bytes) else {
|
2022-10-31 05:57:10 -07:00
|
|
|
XCTFail("Failed to initDataDb. Expected `.success` got: `.seedRequired`")
|
|
|
|
return
|
|
|
|
}
|
2022-10-27 03:51:38 -07:00
|
|
|
} catch {
|
2023-02-07 12:03:02 -08:00
|
|
|
XCTFail("shouldn't fail here. Got error: \(error)")
|
2022-10-27 03:51:38 -07:00
|
|
|
}
|
2021-07-28 09:59:10 -07:00
|
|
|
|
|
|
|
// fileExists actually sucks, so attempting to delete the file and checking what happens is far better :)
|
|
|
|
XCTAssertNoThrow( try FileManager.default.removeItem(at: dbData!) )
|
|
|
|
}
|
2019-10-18 11:45:19 -07:00
|
|
|
}
|