Skip to content

Commit

Permalink
swift: adding unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
reez committed Jul 18, 2023
1 parent bc182c7 commit 33b78c7
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions bdk-swift/Tests/BitcoinDevKitTests/BitcoinDevKitTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import XCTest
@testable import BitcoinDevKit

final class BitcoinDevKitTests: XCTestCase {

func testMemoryWalletNewAddress() throws {
let desc = try Descriptor(
descriptor: "wpkh([c258d2e4/84h/1h/0h]tpubDDYkZojQFQjht8Tm4jsS3iuEmKjTiEGjG6KnuFNKKJb5A6ZUCUZKdvLdSDWofKi4ToRCwb9poe1XdqfUnP4jaJjCB2Zwv11ZLgSbnZSNecE/0/*)",
Expand All @@ -12,4 +13,35 @@ final class BitcoinDevKitTests: XCTestCase {
let addressInfo = try wallet.getAddress(addressIndex: AddressIndex.new)
XCTAssertEqual(addressInfo.address.asString(), "bcrt1qzg4mckdh50nwdm9hkzq06528rsu73hjxytqkxs")
}

private let descriptor = "wpkh([c258d2e4/84h/1h/0h]tpubDDYkZojQFQjht8Tm4jsS3iuEmKjTiEGjG6KnuFNKKJb5A6ZUCUZKdvLdSDWofKi4ToRCwb9poe1XdqfUnP4jaJjCB2Zwv11ZLgSbnZSNecE/0/*)"
let databaseConfig = DatabaseConfig.memory
let blockchainConfig = BlockchainConfig.electrum(
config: ElectrumConfig(
url: "ssl://electrum.blockstream.info:60002",
socks5: nil,
retry: 5,
timeout: nil,
stopGap: 100,
validateDomain: true
)
)

func testMemoryWalletBalance() throws {
let descriptor = try Descriptor(
descriptor: descriptor,
network: .testnet
)
let blockchain = try Blockchain(config: blockchainConfig)
let wallet = try Wallet(descriptor: descriptor, changeDescriptor: nil, network: Network.testnet, databaseConfig: databaseConfig)
try wallet.sync(
blockchain: blockchain,
progress: nil
)
let balance = try wallet.getBalance().total

XCTAssertTrue(balance > 0)
}


}

0 comments on commit 33b78c7

Please sign in to comment.