Make all methods in ZcashKeyDerivationBackendWelding non async
It looks like that some methods in `ZcashKeyDerivationBackendWelding` were left async by mistake. There is no reason for any method there to be async. After this change no method in `DerivationTool` has to async. It makes things much easier.
This commit is contained in:
parent
724d410fad
commit
5f162d01f8
|
@ -32,13 +32,11 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
|
|||
}
|
||||
|
||||
var sharedViewingKey: UnifiedFullViewingKey {
|
||||
get async {
|
||||
let derivationTool = DerivationTool(networkType: kZcashNetwork.networkType)
|
||||
let spendingKey = try! await derivationTool
|
||||
.deriveUnifiedSpendingKey(seed: DemoAppConfig.defaultSeed, accountIndex: 0)
|
||||
let derivationTool = DerivationTool(networkType: kZcashNetwork.networkType)
|
||||
let spendingKey = try! derivationTool
|
||||
.deriveUnifiedSpendingKey(seed: DemoAppConfig.defaultSeed, accountIndex: 0)
|
||||
|
||||
return try! await derivationTool.deriveUnifiedFullViewingKey(from: spendingKey)
|
||||
}
|
||||
return try! derivationTool.deriveUnifiedFullViewingKey(from: spendingKey)
|
||||
}
|
||||
|
||||
var sharedWallet: Initializer {
|
||||
|
|
|
@ -15,7 +15,7 @@ class GetUTXOsViewController: UIViewController {
|
|||
@IBOutlet weak var totalBalanceLabel: UILabel!
|
||||
@IBOutlet weak var messageLabel: UILabel!
|
||||
@IBOutlet weak var shieldFundsButton: UIButton!
|
||||
|
||||
|
||||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
|
||||
|
@ -24,10 +24,10 @@ class GetUTXOsViewController: UIViewController {
|
|||
|
||||
func updateUI() {
|
||||
let synchronizer = SDKSynchronizer.shared
|
||||
|
||||
|
||||
Task { @MainActor in
|
||||
let tAddress = (try? await synchronizer.getTransparentAddress(accountIndex: 0))?.stringEncoded ?? "no t-address found"
|
||||
|
||||
|
||||
self.transparentAddressLabel.text = tAddress
|
||||
|
||||
// swiftlint:disable:next force_try
|
||||
|
@ -39,26 +39,24 @@ class GetUTXOsViewController: UIViewController {
|
|||
}
|
||||
|
||||
@IBAction func shieldFunds(_ sender: Any) {
|
||||
Task { @MainActor in
|
||||
do {
|
||||
let derivationTool = DerivationTool(networkType: kZcashNetwork.networkType)
|
||||
|
||||
let usk = try await derivationTool.deriveUnifiedSpendingKey(seed: DemoAppConfig.defaultSeed, accountIndex: 0)
|
||||
|
||||
KRProgressHUD.showMessage("🛡 Shielding 🛡")
|
||||
|
||||
Task { @MainActor in
|
||||
let transaction = try await AppDelegate.shared.sharedSynchronizer.shieldFunds(
|
||||
spendingKey: usk,
|
||||
memo: try Memo(string: "shielding is fun!"),
|
||||
shieldingThreshold: Zatoshi(10000)
|
||||
)
|
||||
KRProgressHUD.dismiss()
|
||||
self.messageLabel.text = "funds shielded \(transaction)"
|
||||
}
|
||||
} catch {
|
||||
self.messageLabel.text = "Shielding failed \(error)"
|
||||
do {
|
||||
let derivationTool = DerivationTool(networkType: kZcashNetwork.networkType)
|
||||
|
||||
let usk = try derivationTool.deriveUnifiedSpendingKey(seed: DemoAppConfig.defaultSeed, accountIndex: 0)
|
||||
|
||||
KRProgressHUD.showMessage("🛡 Shielding 🛡")
|
||||
|
||||
Task { @MainActor in
|
||||
let transaction = try await AppDelegate.shared.sharedSynchronizer.shieldFunds(
|
||||
spendingKey: usk,
|
||||
memo: try Memo(string: "shielding is fun!"),
|
||||
shieldingThreshold: Zatoshi(10000)
|
||||
)
|
||||
KRProgressHUD.dismiss()
|
||||
self.messageLabel.text = "funds shielded \(transaction)"
|
||||
}
|
||||
} catch {
|
||||
self.messageLabel.text = "Shielding failed \(error)"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -43,14 +43,12 @@ class SendViewController: UIViewController {
|
|||
self.view.addGestureRecognizer(tapRecognizer)
|
||||
setUp()
|
||||
|
||||
Task { @MainActor in
|
||||
closureSynchronizer.prepare(
|
||||
with: DemoAppConfig.defaultSeed,
|
||||
viewingKeys: [await AppDelegate.shared.sharedViewingKey],
|
||||
walletBirthday: DemoAppConfig.defaultBirthdayHeight
|
||||
) { result in
|
||||
loggerProxy.debug("Prepare result: \(result)")
|
||||
}
|
||||
closureSynchronizer.prepare(
|
||||
with: DemoAppConfig.defaultSeed,
|
||||
viewingKeys: [AppDelegate.shared.sharedViewingKey],
|
||||
walletBirthday: DemoAppConfig.defaultBirthdayHeight
|
||||
) { result in
|
||||
loggerProxy.debug("Prepare result: \(result)")
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -219,7 +217,7 @@ class SendViewController: UIViewController {
|
|||
}
|
||||
|
||||
let derivationTool = DerivationTool(networkType: kZcashNetwork.networkType)
|
||||
guard let spendingKey = try? await derivationTool.deriveUnifiedSpendingKey(seed: DemoAppConfig.defaultSeed, accountIndex: 0) else {
|
||||
guard let spendingKey = try? derivationTool.deriveUnifiedSpendingKey(seed: DemoAppConfig.defaultSeed, accountIndex: 0) else {
|
||||
loggerProxy.error("NO SPENDING KEY")
|
||||
return
|
||||
}
|
||||
|
|
|
@ -70,8 +70,8 @@ class SyncBlocksListViewController: UIViewController {
|
|||
do {
|
||||
if syncStatus == .unprepared {
|
||||
let derivationTool = DerivationTool(networkType: kZcashNetwork.networkType)
|
||||
let spendingKey = try await derivationTool.deriveUnifiedSpendingKey(seed: synchronizerData.seed, accountIndex: 0)
|
||||
let viewingKey = try await derivationTool.deriveUnifiedFullViewingKey(from: spendingKey)
|
||||
let spendingKey = try derivationTool.deriveUnifiedSpendingKey(seed: synchronizerData.seed, accountIndex: 0)
|
||||
let viewingKey = try derivationTool.deriveUnifiedFullViewingKey(from: spendingKey)
|
||||
|
||||
_ = try! await synchronizer.prepare(
|
||||
with: synchronizerData.seed,
|
||||
|
|
|
@ -120,7 +120,7 @@ struct ZcashKeyDerivationBackend: ZcashKeyDerivationBackendWelding {
|
|||
func deriveUnifiedSpendingKey(
|
||||
from seed: [UInt8],
|
||||
accountIndex: Int32
|
||||
) async throws -> UnifiedSpendingKey {
|
||||
) throws -> UnifiedSpendingKey {
|
||||
let binaryKeyPtr = seed.withUnsafeBufferPointer { seedBufferPtr in
|
||||
return zcashlc_derive_spending_key(
|
||||
seedBufferPtr.baseAddress,
|
||||
|
@ -139,7 +139,7 @@ struct ZcashKeyDerivationBackend: ZcashKeyDerivationBackendWelding {
|
|||
return binaryKey.unsafeToUnifiedSpendingKey(network: networkType)
|
||||
}
|
||||
|
||||
func deriveUnifiedFullViewingKey(from spendingKey: UnifiedSpendingKey) async throws -> UnifiedFullViewingKey {
|
||||
func deriveUnifiedFullViewingKey(from spendingKey: UnifiedSpendingKey) throws -> UnifiedFullViewingKey {
|
||||
let extfvk = try spendingKey.bytes.withUnsafeBufferPointer { uskBufferPtr -> UnsafeMutablePointer<CChar> in
|
||||
guard let extfvk = zcashlc_spending_key_to_full_viewing_key(
|
||||
uskBufferPtr.baseAddress,
|
||||
|
|
|
@ -60,7 +60,7 @@ protocol ZcashKeyDerivationBackendWelding {
|
|||
/// - Parameter seed: a Byte Array with the seed
|
||||
/// - Parameter accountIndex:account index that the key can spend from
|
||||
/// - Throws: `rustDeriveUnifiedSpendingKey` if rust layer returns error.
|
||||
func deriveUnifiedSpendingKey(from seed: [UInt8], accountIndex: Int32) async throws -> UnifiedSpendingKey
|
||||
func deriveUnifiedSpendingKey(from seed: [UInt8], accountIndex: Int32) throws -> UnifiedSpendingKey
|
||||
|
||||
/// Derives a `UnifiedFullViewingKey` from a `UnifiedSpendingKey`
|
||||
/// - Parameter spendingKey: the `UnifiedSpendingKey` to derive from
|
||||
|
@ -68,7 +68,7 @@ protocol ZcashKeyDerivationBackendWelding {
|
|||
/// - Throws:
|
||||
/// - `rustDeriveUnifiedFullViewingKey` if rust layer returns error.
|
||||
/// - `rustDeriveUnifiedFullViewingKeyInvalidDerivedKey` if derived viewing key is invalid.
|
||||
func deriveUnifiedFullViewingKey(from spendingKey: UnifiedSpendingKey) async throws -> UnifiedFullViewingKey
|
||||
func deriveUnifiedFullViewingKey(from spendingKey: UnifiedSpendingKey) throws -> UnifiedFullViewingKey
|
||||
|
||||
/// Returns the Sapling receiver within the given Unified Address, if any.
|
||||
/// - Parameter uAddr: a `UnifiedAddress`
|
||||
|
|
|
@ -24,17 +24,13 @@ public protocol KeyDeriving {
|
|||
/// - `derivationToolSpendingKeyInvalidAccount` if the `accountIndex` is invalid.
|
||||
/// - some `ZcashError.rust*` error if the derivation fails.
|
||||
/// - Returns a `UnifiedSpendingKey`
|
||||
func deriveUnifiedSpendingKey(seed: [UInt8], accountIndex: Int) async throws -> UnifiedSpendingKey
|
||||
func deriveUnifiedSpendingKey(seed: [UInt8], accountIndex: Int, completion: @escaping (Result<UnifiedSpendingKey, Error>) -> Void)
|
||||
func deriveUnifiedSpendingKey(seed: [UInt8], accountIndex: Int) -> SinglePublisher<UnifiedSpendingKey, Error>
|
||||
func deriveUnifiedSpendingKey(seed: [UInt8], accountIndex: Int) throws -> UnifiedSpendingKey
|
||||
|
||||
/// Given a spending key, return the associated viewing key.
|
||||
/// - Parameter spendingKey: the `UnifiedSpendingKey` from which to derive the `UnifiedFullViewingKey` from.
|
||||
/// - Throws: some `ZcashError.rust*` error if the derivation fails.
|
||||
/// - Returns: the viewing key that corresponds to the spending key.
|
||||
func deriveUnifiedFullViewingKey(from spendingKey: UnifiedSpendingKey) async throws -> UnifiedFullViewingKey
|
||||
func deriveUnifiedFullViewingKey(from spendingKey: UnifiedSpendingKey, completion: @escaping (Result<UnifiedFullViewingKey, Error>) -> Void)
|
||||
func deriveUnifiedFullViewingKey(from spendingKey: UnifiedSpendingKey) -> SinglePublisher<UnifiedFullViewingKey, Error>
|
||||
func deriveUnifiedFullViewingKey(from spendingKey: UnifiedSpendingKey) throws -> UnifiedFullViewingKey
|
||||
|
||||
/// Extracts the `SaplingAddress` from the given `UnifiedAddress`
|
||||
/// - Parameter address: the `UnifiedAddress`
|
||||
|
@ -76,20 +72,8 @@ public class DerivationTool: KeyDeriving {
|
|||
/// Given a spending key, return the associated viewing key.
|
||||
/// - Parameter spendingKey: the `UnifiedSpendingKey` from which to derive the `UnifiedFullViewingKey` from.
|
||||
/// - Returns: the viewing key that corresponds to the spending key.
|
||||
public func deriveUnifiedFullViewingKey(from spendingKey: UnifiedSpendingKey) async throws -> UnifiedFullViewingKey {
|
||||
try await backend.deriveUnifiedFullViewingKey(from: spendingKey)
|
||||
}
|
||||
|
||||
public func deriveUnifiedFullViewingKey(from spendingKey: UnifiedSpendingKey, completion: @escaping (Result<UnifiedFullViewingKey, Error>) -> Void) {
|
||||
AsyncToClosureGateway.executeThrowingAction(completion) { [backend] in
|
||||
return try await backend.deriveUnifiedFullViewingKey(from: spendingKey)
|
||||
}
|
||||
}
|
||||
|
||||
public func deriveUnifiedFullViewingKey(from spendingKey: UnifiedSpendingKey) -> SinglePublisher<UnifiedFullViewingKey, Error> {
|
||||
AsyncToCombineGateway.executeThrowingAction() { [backend] in
|
||||
return try await backend.deriveUnifiedFullViewingKey(from: spendingKey)
|
||||
}
|
||||
public func deriveUnifiedFullViewingKey(from spendingKey: UnifiedSpendingKey) throws -> UnifiedFullViewingKey {
|
||||
try backend.deriveUnifiedFullViewingKey(from: spendingKey)
|
||||
}
|
||||
|
||||
/// Given a seed and a number of accounts, return the associated spending keys.
|
||||
|
@ -97,23 +81,9 @@ public class DerivationTool: KeyDeriving {
|
|||
/// - Parameter numberOfAccounts: the number of accounts to use. Multiple accounts are not fully
|
||||
/// supported so the default value of 1 is recommended.
|
||||
/// - Returns: the spending keys that correspond to the seed, formatted as Strings.
|
||||
public func deriveUnifiedSpendingKey(seed: [UInt8], accountIndex: Int) async throws -> UnifiedSpendingKey {
|
||||
public func deriveUnifiedSpendingKey(seed: [UInt8], accountIndex: Int) throws -> UnifiedSpendingKey {
|
||||
guard accountIndex >= 0, let accountIndex = Int32(exactly: accountIndex) else { throw ZcashError.derivationToolSpendingKeyInvalidAccount }
|
||||
return try await backend.deriveUnifiedSpendingKey(from: seed, accountIndex: accountIndex)
|
||||
}
|
||||
|
||||
public func deriveUnifiedSpendingKey(seed: [UInt8], accountIndex: Int, completion: @escaping (Result<UnifiedSpendingKey, Error>) -> Void) {
|
||||
AsyncToClosureGateway.executeThrowingAction(completion) { [backend] in
|
||||
guard accountIndex >= 0, let accountIndex = Int32(exactly: accountIndex) else { throw ZcashError.derivationToolSpendingKeyInvalidAccount }
|
||||
return try await backend.deriveUnifiedSpendingKey(from: seed, accountIndex: accountIndex)
|
||||
}
|
||||
}
|
||||
|
||||
public func deriveUnifiedSpendingKey(seed: [UInt8], accountIndex: Int) -> SinglePublisher<UnifiedSpendingKey, Error> {
|
||||
AsyncToCombineGateway.executeThrowingAction() { [backend] in
|
||||
guard accountIndex >= 0, let accountIndex = Int32(exactly: accountIndex) else { throw ZcashError.derivationToolSpendingKeyInvalidAccount }
|
||||
return try await backend.deriveUnifiedSpendingKey(from: seed, accountIndex: accountIndex)
|
||||
}
|
||||
return try backend.deriveUnifiedSpendingKey(from: seed, accountIndex: accountIndex)
|
||||
}
|
||||
|
||||
public func receiverTypecodesFromUnifiedAddress(_ address: UnifiedAddress) throws -> [UnifiedAddress.ReceiverTypecodes] {
|
||||
|
|
|
@ -87,8 +87,8 @@ class TransactionEnhancementTests: XCTestCase {
|
|||
let dbInit = try await rustBackend.initDataDb(seed: nil)
|
||||
|
||||
let derivationTool = DerivationTool(networkType: network.networkType)
|
||||
let spendingKey = try await derivationTool.deriveUnifiedSpendingKey(seed: Environment.seedBytes, accountIndex: 0)
|
||||
let viewingKey = try await derivationTool.deriveUnifiedFullViewingKey(from: spendingKey)
|
||||
let spendingKey = try derivationTool.deriveUnifiedSpendingKey(seed: Environment.seedBytes, accountIndex: 0)
|
||||
let viewingKey = try derivationTool.deriveUnifiedFullViewingKey(from: spendingKey)
|
||||
|
||||
do {
|
||||
try await rustBackend.initAccountsTable(ufvks: [viewingKey])
|
||||
|
|
|
@ -147,8 +147,8 @@ class BlockScanTests: XCTestCase {
|
|||
}
|
||||
|
||||
let derivationTool = DerivationTool(networkType: .testnet)
|
||||
let spendingKey = try await derivationTool.deriveUnifiedSpendingKey(seed: Array(seed.utf8), accountIndex: 0)
|
||||
let viewingKey = try await derivationTool.deriveUnifiedFullViewingKey(from: spendingKey)
|
||||
let spendingKey = try derivationTool.deriveUnifiedSpendingKey(seed: Array(seed.utf8), accountIndex: 0)
|
||||
let viewingKey = try derivationTool.deriveUnifiedFullViewingKey(from: spendingKey)
|
||||
|
||||
do {
|
||||
try await rustBackend.initAccountsTable(ufvks: [viewingKey])
|
||||
|
|
|
@ -100,8 +100,8 @@ class ClosureSynchronizerOfflineTests: XCTestCase {
|
|||
XCTAssertEqual(synchronizer.connectionState, .reconnecting)
|
||||
}
|
||||
|
||||
func testPrepareSucceed() async throws {
|
||||
let mockedViewingKey = await data.viewingKey
|
||||
func testPrepareSucceed() throws {
|
||||
let mockedViewingKey = data.viewingKey
|
||||
synchronizerMock.prepareWithViewingKeysWalletBirthdayClosure = { receivedSeed, receivedViewingKeys, receivedWalletBirthday in
|
||||
XCTAssertEqual(receivedSeed, self.data.seed)
|
||||
XCTAssertEqual(receivedViewingKeys, [mockedViewingKey])
|
||||
|
@ -124,8 +124,8 @@ class ClosureSynchronizerOfflineTests: XCTestCase {
|
|||
wait(for: [expectation], timeout: 0.5)
|
||||
}
|
||||
|
||||
func testPrepareThrowsError() async throws {
|
||||
let mockedViewingKey = await data.viewingKey
|
||||
func testPrepareThrowsError() throws {
|
||||
let mockedViewingKey = data.viewingKey
|
||||
synchronizerMock.prepareWithViewingKeysWalletBirthdayClosure = { _, _, _ in
|
||||
throw "Some error"
|
||||
}
|
||||
|
@ -312,11 +312,11 @@ class ClosureSynchronizerOfflineTests: XCTestCase {
|
|||
wait(for: [expectation], timeout: 0.5)
|
||||
}
|
||||
|
||||
func testSendToAddressSucceed() async throws {
|
||||
func testSendToAddressSucceed() throws {
|
||||
let amount = Zatoshi(100)
|
||||
let recipient: Recipient = .transparent(data.transparentAddress)
|
||||
let memo: Memo = .text(try MemoText("Some message"))
|
||||
let mockedSpendingKey = await data.spendingKey
|
||||
let mockedSpendingKey = data.spendingKey
|
||||
|
||||
synchronizerMock
|
||||
.sendToAddressSpendingKeyZatoshiToAddressMemoClosure = { receivedSpendingKey, receivedZatoshi, receivedToAddress, receivedMemo in
|
||||
|
@ -342,11 +342,11 @@ class ClosureSynchronizerOfflineTests: XCTestCase {
|
|||
wait(for: [expectation], timeout: 0.5)
|
||||
}
|
||||
|
||||
func testSendToAddressThrowsError() async throws {
|
||||
func testSendToAddressThrowsError() throws {
|
||||
let amount = Zatoshi(100)
|
||||
let recipient: Recipient = .transparent(data.transparentAddress)
|
||||
let memo: Memo = .text(try MemoText("Some message"))
|
||||
let mockedSpendingKey = await data.spendingKey
|
||||
let mockedSpendingKey = data.spendingKey
|
||||
|
||||
synchronizerMock.sendToAddressSpendingKeyZatoshiToAddressMemoClosure = { _, _, _, _ in
|
||||
throw "Some error"
|
||||
|
@ -366,10 +366,10 @@ class ClosureSynchronizerOfflineTests: XCTestCase {
|
|||
wait(for: [expectation], timeout: 0.5)
|
||||
}
|
||||
|
||||
func testShieldFundsSucceed() async throws {
|
||||
func testShieldFundsSucceed() throws {
|
||||
let memo: Memo = .text(try MemoText("Some message"))
|
||||
let shieldingThreshold = Zatoshi(1)
|
||||
let mockedSpendingKey = await data.spendingKey
|
||||
let mockedSpendingKey = data.spendingKey
|
||||
|
||||
synchronizerMock.shieldFundsSpendingKeyMemoShieldingThresholdClosure = { receivedSpendingKey, receivedMemo, receivedShieldingThreshold in
|
||||
XCTAssertEqual(receivedSpendingKey, mockedSpendingKey)
|
||||
|
@ -393,10 +393,10 @@ class ClosureSynchronizerOfflineTests: XCTestCase {
|
|||
wait(for: [expectation], timeout: 0.5)
|
||||
}
|
||||
|
||||
func testShieldFundsThrowsError() async throws {
|
||||
func testShieldFundsThrowsError() throws {
|
||||
let memo: Memo = .text(try MemoText("Some message"))
|
||||
let shieldingThreshold = Zatoshi(1)
|
||||
let mockedSpendingKey = await data.spendingKey
|
||||
let mockedSpendingKey = data.spendingKey
|
||||
|
||||
synchronizerMock.shieldFundsSpendingKeyMemoShieldingThresholdClosure = { _, _, _ in
|
||||
throw "Some error"
|
||||
|
|
|
@ -100,8 +100,8 @@ class CombineSynchronizerOfflineTests: XCTestCase {
|
|||
XCTAssertEqual(synchronizer.connectionState, .reconnecting)
|
||||
}
|
||||
|
||||
func testPrepareSucceed() async throws {
|
||||
let mockedViewingKey = await self.data.viewingKey
|
||||
func testPrepareSucceed() throws {
|
||||
let mockedViewingKey = self.data.viewingKey
|
||||
synchronizerMock.prepareWithViewingKeysWalletBirthdayClosure = { receivedSeed, receivedViewingKeys, receivedWalletBirthday in
|
||||
XCTAssertEqual(receivedSeed, self.data.seed)
|
||||
XCTAssertEqual(receivedViewingKeys, [mockedViewingKey])
|
||||
|
@ -130,8 +130,8 @@ class CombineSynchronizerOfflineTests: XCTestCase {
|
|||
wait(for: [expectation], timeout: 0.5)
|
||||
}
|
||||
|
||||
func testPrepareThrowsError() async throws {
|
||||
let mockedViewingKey = await self.data.viewingKey
|
||||
func testPrepareThrowsError() throws {
|
||||
let mockedViewingKey = self.data.viewingKey
|
||||
synchronizerMock.prepareWithViewingKeysWalletBirthdayClosure = { _, _, _ in
|
||||
throw "Some error"
|
||||
}
|
||||
|
@ -319,11 +319,11 @@ class CombineSynchronizerOfflineTests: XCTestCase {
|
|||
wait(for: [expectation], timeout: 0.5)
|
||||
}
|
||||
|
||||
func testSendToAddressSucceed() async throws {
|
||||
func testSendToAddressSucceed() throws {
|
||||
let amount = Zatoshi(100)
|
||||
let recipient: Recipient = .transparent(data.transparentAddress)
|
||||
let memo: Memo = .text(try MemoText("Some message"))
|
||||
let mockedSpendingKey = await data.spendingKey
|
||||
let mockedSpendingKey = data.spendingKey
|
||||
|
||||
synchronizerMock
|
||||
.sendToAddressSpendingKeyZatoshiToAddressMemoClosure = { receivedSpendingKey, receivedZatoshi, receivedToAddress, receivedMemo in
|
||||
|
@ -355,11 +355,11 @@ class CombineSynchronizerOfflineTests: XCTestCase {
|
|||
wait(for: [expectation], timeout: 0.5)
|
||||
}
|
||||
|
||||
func testSendToAddressThrowsError() async throws {
|
||||
func testSendToAddressThrowsError() throws {
|
||||
let amount = Zatoshi(100)
|
||||
let recipient: Recipient = .transparent(data.transparentAddress)
|
||||
let memo: Memo = .text(try MemoText("Some message"))
|
||||
let mockedSpendingKey = await data.spendingKey
|
||||
let mockedSpendingKey = data.spendingKey
|
||||
|
||||
synchronizerMock.sendToAddressSpendingKeyZatoshiToAddressMemoClosure = { _, _, _, _ in
|
||||
throw "Some error"
|
||||
|
@ -386,10 +386,10 @@ class CombineSynchronizerOfflineTests: XCTestCase {
|
|||
wait(for: [expectation], timeout: 0.5)
|
||||
}
|
||||
|
||||
func testShieldFundsSucceed() async throws {
|
||||
func testShieldFundsSucceed() throws {
|
||||
let memo: Memo = .text(try MemoText("Some message"))
|
||||
let shieldingThreshold = Zatoshi(1)
|
||||
let mockedSpendingKey = await data.spendingKey
|
||||
let mockedSpendingKey = data.spendingKey
|
||||
|
||||
synchronizerMock.shieldFundsSpendingKeyMemoShieldingThresholdClosure = { receivedSpendingKey, receivedMemo, receivedShieldingThreshold in
|
||||
XCTAssertEqual(receivedSpendingKey, mockedSpendingKey)
|
||||
|
@ -419,10 +419,10 @@ class CombineSynchronizerOfflineTests: XCTestCase {
|
|||
wait(for: [expectation], timeout: 0.5)
|
||||
}
|
||||
|
||||
func testShieldFundsThrowsError() async throws {
|
||||
func testShieldFundsThrowsError() throws {
|
||||
let memo: Memo = .text(try MemoText("Some message"))
|
||||
let shieldingThreshold = Zatoshi(1)
|
||||
let mockedSpendingKey = await data.spendingKey
|
||||
let mockedSpendingKey = data.spendingKey
|
||||
|
||||
synchronizerMock.shieldFundsSpendingKeyMemoShieldingThresholdClosure = { _, _, _ in
|
||||
throw "Some error"
|
||||
|
|
|
@ -50,33 +50,33 @@ class DerivationToolMainnetTests: XCTestCase {
|
|||
let derivationTool = TestsData(networkType: .mainnet).derivationTools
|
||||
let expectedTransparentAddress = TransparentAddress(validatedEncoding: "t1dRJRY7GmyeykJnMH38mdQoaZtFhn1QmGz")
|
||||
|
||||
func testDeriveViewingKeysFromSeed() async throws {
|
||||
func testDeriveViewingKeysFromSeed() throws {
|
||||
let seedBytes = [UInt8](seedData)
|
||||
|
||||
let spendingKey = try await derivationTool.deriveUnifiedSpendingKey(seed: seedBytes, accountIndex: 0)
|
||||
let viewingKey = try await derivationTool.deriveUnifiedFullViewingKey(from: spendingKey)
|
||||
let spendingKey = try derivationTool.deriveUnifiedSpendingKey(seed: seedBytes, accountIndex: 0)
|
||||
let viewingKey = try derivationTool.deriveUnifiedFullViewingKey(from: spendingKey)
|
||||
|
||||
XCTAssertEqual(expectedViewingKey, viewingKey)
|
||||
}
|
||||
|
||||
func testDeriveViewingKeyFromSpendingKeys() async throws {
|
||||
let viewingKey = try await derivationTool.deriveUnifiedFullViewingKey(from: expectedSpendingKey)
|
||||
func testDeriveViewingKeyFromSpendingKeys() throws {
|
||||
let viewingKey = try derivationTool.deriveUnifiedFullViewingKey(from: expectedSpendingKey)
|
||||
XCTAssertEqual(expectedViewingKey, viewingKey)
|
||||
}
|
||||
|
||||
func testDeriveSpendingKeysFromSeed() async throws {
|
||||
func testDeriveSpendingKeysFromSeed() throws {
|
||||
let seedBytes = [UInt8](seedData)
|
||||
|
||||
let spendingKey = try await derivationTool.deriveUnifiedSpendingKey(seed: seedBytes, accountIndex: 0)
|
||||
let spendingKey = try derivationTool.deriveUnifiedSpendingKey(seed: seedBytes, accountIndex: 0)
|
||||
|
||||
XCTAssertEqual(expectedSpendingKey, spendingKey)
|
||||
}
|
||||
|
||||
func testDeriveUnifiedSpendingKeyFromSeed() async throws {
|
||||
func testDeriveUnifiedSpendingKeyFromSeed() throws {
|
||||
let account = 0
|
||||
let seedBytes = [UInt8](seedData)
|
||||
|
||||
_ = try await derivationTool.deriveUnifiedSpendingKey(seed: seedBytes, accountIndex: account)
|
||||
_ = try derivationTool.deriveUnifiedSpendingKey(seed: seedBytes, accountIndex: account)
|
||||
}
|
||||
|
||||
func testGetTransparentAddressFromUA() throws {
|
||||
|
@ -104,12 +104,12 @@ class DerivationToolMainnetTests: XCTestCase {
|
|||
)
|
||||
}
|
||||
|
||||
func testDeriveQuiteALotOfUnifiedKeysFromSeed() async throws {
|
||||
func testDeriveQuiteALotOfUnifiedKeysFromSeed() throws {
|
||||
let numberOfAccounts: Int = 10
|
||||
var ufvks: [UnifiedFullViewingKey] = []
|
||||
for i in 0..<numberOfAccounts {
|
||||
let spendingKey = try await derivationTool.deriveUnifiedSpendingKey(seed: [UInt8](seedData), accountIndex: i)
|
||||
let viewingKey = try await derivationTool.deriveUnifiedFullViewingKey(from: spendingKey)
|
||||
let spendingKey = try derivationTool.deriveUnifiedSpendingKey(seed: [UInt8](seedData), accountIndex: i)
|
||||
let viewingKey = try derivationTool.deriveUnifiedFullViewingKey(from: spendingKey)
|
||||
ufvks.append(viewingKey)
|
||||
}
|
||||
|
||||
|
|
|
@ -58,11 +58,11 @@ class DerivationToolTestnetTests: XCTestCase {
|
|||
let derivationTool = TestsData(networkType: .testnet).derivationTools
|
||||
let expectedTransparentAddress = TransparentAddress(validatedEncoding: "tmXuTnE11JojToagTqxXUn6KvdxDE3iLKbp")
|
||||
|
||||
func testDeriveViewingKeysFromSeed() async throws {
|
||||
func testDeriveViewingKeysFromSeed() throws {
|
||||
let seedBytes = [UInt8](seedData)
|
||||
|
||||
let spendingKey = try await derivationTool.deriveUnifiedSpendingKey(seed: seedBytes, accountIndex: 0)
|
||||
let viewingKey = try await derivationTool.deriveUnifiedFullViewingKey(from: spendingKey)
|
||||
let spendingKey = try derivationTool.deriveUnifiedSpendingKey(seed: seedBytes, accountIndex: 0)
|
||||
let viewingKey = try derivationTool.deriveUnifiedFullViewingKey(from: spendingKey)
|
||||
|
||||
XCTAssertEqual(expectedViewingKey, viewingKey)
|
||||
}
|
||||
|
@ -74,19 +74,19 @@ class DerivationToolTestnetTests: XCTestCase {
|
|||
// )
|
||||
}
|
||||
|
||||
func testDeriveSpendingKeysFromSeed() async throws {
|
||||
func testDeriveSpendingKeysFromSeed() throws {
|
||||
let seedBytes = [UInt8](seedData)
|
||||
|
||||
let spendingKey = try await derivationTool.deriveUnifiedSpendingKey(seed: seedBytes, accountIndex: 0)
|
||||
let spendingKey = try derivationTool.deriveUnifiedSpendingKey(seed: seedBytes, accountIndex: 0)
|
||||
|
||||
XCTAssertEqual(expectedSpendingKey, spendingKey)
|
||||
}
|
||||
|
||||
func testDeriveUnifiedSpendingKeyFromSeed() async throws {
|
||||
func testDeriveUnifiedSpendingKeyFromSeed() throws {
|
||||
let account = 0
|
||||
let seedBytes = [UInt8](seedData)
|
||||
|
||||
_ = try await derivationTool.deriveUnifiedSpendingKey(seed: seedBytes, accountIndex: account)
|
||||
_ = try derivationTool.deriveUnifiedSpendingKey(seed: seedBytes, accountIndex: account)
|
||||
}
|
||||
|
||||
func testGetTransparentAddressFromUA() throws {
|
||||
|
@ -114,12 +114,12 @@ class DerivationToolTestnetTests: XCTestCase {
|
|||
)
|
||||
}
|
||||
|
||||
func testDeriveQuiteALotOfUnifiedKeysFromSeed() async throws {
|
||||
func testDeriveQuiteALotOfUnifiedKeysFromSeed() throws {
|
||||
let numberOfAccounts: Int = 10
|
||||
var ufvks: [UnifiedFullViewingKey] = []
|
||||
for i in 0..<numberOfAccounts {
|
||||
let spendingKey = try await derivationTool.deriveUnifiedSpendingKey(seed: [UInt8](seedData), accountIndex: i)
|
||||
let viewingKey = try await derivationTool.deriveUnifiedFullViewingKey(from: spendingKey)
|
||||
let spendingKey = try derivationTool.deriveUnifiedSpendingKey(seed: [UInt8](seedData), accountIndex: i)
|
||||
let viewingKey = try derivationTool.deriveUnifiedFullViewingKey(from: spendingKey)
|
||||
ufvks.append(viewingKey)
|
||||
}
|
||||
|
||||
|
|
|
@ -258,11 +258,11 @@ class SynchronizerOfflineTests: XCTestCase {
|
|||
|
||||
do {
|
||||
let derivationTool = DerivationTool(networkType: network.networkType)
|
||||
let spendingKey = try await derivationTool.deriveUnifiedSpendingKey(
|
||||
let spendingKey = try derivationTool.deriveUnifiedSpendingKey(
|
||||
seed: Environment.seedBytes,
|
||||
accountIndex: 0
|
||||
)
|
||||
let viewingKey = try await derivationTool.deriveUnifiedFullViewingKey(from: spendingKey)
|
||||
let viewingKey = try derivationTool.deriveUnifiedFullViewingKey(from: spendingKey)
|
||||
_ = try await synchronizer.prepare(with: Environment.seedBytes, viewingKeys: [viewingKey], walletBirthday: 123000)
|
||||
XCTFail("Failure of prepare is expected.")
|
||||
} catch {
|
||||
|
|
|
@ -37,8 +37,8 @@ class WalletTests: XCTestCase {
|
|||
|
||||
func testWalletInitialization() async throws {
|
||||
let derivationTool = TestsData(networkType: network.networkType).derivationTools
|
||||
let spendingKey = try await derivationTool.deriveUnifiedSpendingKey(seed: seedData.bytes, accountIndex: 0)
|
||||
let viewingKey = try await derivationTool.deriveUnifiedFullViewingKey(from: spendingKey)
|
||||
let spendingKey = try derivationTool.deriveUnifiedSpendingKey(seed: seedData.bytes, accountIndex: 0)
|
||||
let viewingKey = try derivationTool.deriveUnifiedFullViewingKey(from: spendingKey)
|
||||
|
||||
let wallet = Initializer(
|
||||
cacheDbURL: nil,
|
||||
|
|
|
@ -57,11 +57,11 @@ class SynchronizerTests: XCTestCase {
|
|||
return
|
||||
}
|
||||
let seedBytes = [UInt8](seedData)
|
||||
let spendingKey = try await derivationTool.deriveUnifiedSpendingKey(
|
||||
let spendingKey = try derivationTool.deriveUnifiedSpendingKey(
|
||||
seed: seedBytes,
|
||||
accountIndex: 0
|
||||
)
|
||||
let ufvk = try await derivationTool.deriveUnifiedFullViewingKey(from: spendingKey)
|
||||
let ufvk = try derivationTool.deriveUnifiedFullViewingKey(from: spendingKey)
|
||||
let network = ZcashNetworkBuilder.network(for: .mainnet)
|
||||
let endpoint = LightWalletEndpoint(address: "lightwalletd.electriccoin.co", port: 9067, secure: true)
|
||||
|
||||
|
|
|
@ -82,12 +82,12 @@ class TestCoordinator {
|
|||
|
||||
let derivationTool = DerivationTool(networkType: network.networkType)
|
||||
|
||||
self.spendingKey = try await derivationTool.deriveUnifiedSpendingKey(
|
||||
self.spendingKey = try derivationTool.deriveUnifiedSpendingKey(
|
||||
seed: Environment.seedBytes,
|
||||
accountIndex: 0
|
||||
)
|
||||
|
||||
self.viewingKey = try await derivationTool.deriveUnifiedFullViewingKey(from: spendingKey)
|
||||
self.viewingKey = try derivationTool.deriveUnifiedFullViewingKey(from: spendingKey)
|
||||
self.birthday = walletBirthday
|
||||
self.network = network
|
||||
|
||||
|
|
|
@ -90,16 +90,8 @@ class TestsData {
|
|||
}()
|
||||
|
||||
var seed: [UInt8] = Environment.seedBytes
|
||||
var spendingKey: UnifiedSpendingKey {
|
||||
get async {
|
||||
try! await derivationTools.deriveUnifiedSpendingKey(seed: seed, accountIndex: 0)
|
||||
}
|
||||
}
|
||||
var viewingKey: UnifiedFullViewingKey {
|
||||
get async {
|
||||
try! await derivationTools.deriveUnifiedFullViewingKey(from: spendingKey)
|
||||
}
|
||||
}
|
||||
var spendingKey: UnifiedSpendingKey { try! derivationTools.deriveUnifiedSpendingKey(seed: seed, accountIndex: 0) }
|
||||
var viewingKey: UnifiedFullViewingKey { try! derivationTools.deriveUnifiedFullViewingKey(from: spendingKey) }
|
||||
var birthday: BlockHeight = 123000
|
||||
|
||||
init(networkType: NetworkType) {
|
||||
|
|
Loading…
Reference in New Issue