Skip to content

Commit

Permalink
fix: live tests
Browse files Browse the repository at this point in the history
  • Loading branch information
reez committed Mar 6, 2024
1 parent b249dae commit 2dd6ee3
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 17 deletions.
20 changes: 15 additions & 5 deletions bdk-swift/Tests/BitcoinDevKitTests/LiveTxBuilderTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,27 @@ import XCTest
@testable import BitcoinDevKit

final class LiveTxBuilderTests: XCTestCase {
override func tearDownWithError() throws {
var dbFilePath: URL!

override func setUpWithError() throws {
super.setUp()
let fileManager = FileManager.default
let dbFileName = "bdk_persistence.db"
let documentDirectory = fileManager.urls(for: .documentDirectory, in: .userDomainMask).first!
let dbFilePath: URL = documentDirectory.appendingPathComponent(dbFileName)
let uniqueDbFileName = "bdk_persistence_\(UUID().uuidString).db"
dbFilePath = documentDirectory.appendingPathComponent(uniqueDbFileName)

if fileManager.fileExists(atPath: dbFilePath.path) {
try fileManager.removeItem(at: dbFilePath)
}
}

override func tearDownWithError() throws {
let fileManager = FileManager.default
if fileManager.fileExists(atPath: dbFilePath.path) {
try fileManager.removeItem(at: dbFilePath)
}
}

func testTxBuilder() throws {
let descriptor = try Descriptor(
descriptor: "wpkh(tprv8ZgxMBicQKsPf2qfrEygW6fdYseJDDrVnDv26PH5BHdvSuG6ecCbHqLVof9yZcMoM31z9ur3tTYbSnr1WBqbGX97CbXcmp5H6qeMpyvx35B/84h/1h/0h/0/*)",
Expand All @@ -21,7 +31,7 @@ final class LiveTxBuilderTests: XCTestCase {
let wallet = try Wallet(
descriptor: descriptor,
changeDescriptor: nil,
persistenceBackendPath: "bdk_persistence.db",
persistenceBackendPath: dbFilePath.path,
network: .testnet
)
let esploraClient = EsploraClient(url: "https://esplora.testnet.kuutamo.cloud/")
Expand Down Expand Up @@ -56,7 +66,7 @@ final class LiveTxBuilderTests: XCTestCase {
let wallet = try Wallet(
descriptor: descriptor,
changeDescriptor: changeDescriptor,
persistenceBackendPath: "bdk_persistence.db",
persistenceBackendPath: dbFilePath.path,
network: .testnet
)
let esploraClient = EsploraClient(url: "https://esplora.testnet.kuutamo.cloud/")
Expand Down
20 changes: 15 additions & 5 deletions bdk-swift/Tests/BitcoinDevKitTests/LiveWalletTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,27 @@ import XCTest
@testable import BitcoinDevKit

final class LiveWalletTests: XCTestCase {
override func tearDownWithError() throws {
var dbFilePath: URL!

override func setUpWithError() throws {
super.setUp()
let fileManager = FileManager.default
let dbFileName = "bdk_persistence.db"
let documentDirectory = fileManager.urls(for: .documentDirectory, in: .userDomainMask).first!
let dbFilePath: URL = documentDirectory.appendingPathComponent(dbFileName)
let uniqueDbFileName = "bdk_persistence_\(UUID().uuidString).db"
dbFilePath = documentDirectory.appendingPathComponent(uniqueDbFileName)

if fileManager.fileExists(atPath: dbFilePath.path) {
try fileManager.removeItem(at: dbFilePath)
}
}

override func tearDownWithError() throws {
let fileManager = FileManager.default
if fileManager.fileExists(atPath: dbFilePath.path) {
try fileManager.removeItem(at: dbFilePath)
}
}

func testSyncedBalance() throws {
let descriptor = try Descriptor(
descriptor: "wpkh(tprv8ZgxMBicQKsPf2qfrEygW6fdYseJDDrVnDv26PH5BHdvSuG6ecCbHqLVof9yZcMoM31z9ur3tTYbSnr1WBqbGX97CbXcmp5H6qeMpyvx35B/84h/1h/0h/0/*)",
Expand All @@ -21,7 +31,7 @@ final class LiveWalletTests: XCTestCase {
let wallet = try Wallet(
descriptor: descriptor,
changeDescriptor: nil,
persistenceBackendPath: "bdk_persistence.db",
persistenceBackendPath: dbFilePath.path,
network: .testnet
)
let esploraClient = EsploraClient(url: "https://esplora.testnet.kuutamo.cloud/")
Expand Down Expand Up @@ -52,7 +62,7 @@ final class LiveWalletTests: XCTestCase {
let wallet = try Wallet(
descriptor: descriptor,
changeDescriptor: nil,
persistenceBackendPath: "bdk_persistence.db",
persistenceBackendPath: dbFilePath.path,
network: .testnet
)
let esploraClient = EsploraClient(url: "https://esplora.testnet.kuutamo.cloud/")
Expand Down
24 changes: 17 additions & 7 deletions bdk-swift/Tests/BitcoinDevKitTests/OfflineWalletTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,36 @@ import XCTest
@testable import BitcoinDevKit

final class OfflineWalletTests: XCTestCase {
override func tearDownWithError() throws {
var dbFilePath: URL!

override func setUpWithError() throws {
super.setUp()
let fileManager = FileManager.default
let dbFileName = "bdk_persistence.db"
let documentDirectory = fileManager.urls(for: .documentDirectory, in: .userDomainMask).first!
let dbFilePath: URL = documentDirectory.appendingPathComponent(dbFileName)
let uniqueDbFileName = "bdk_persistence_\(UUID().uuidString).db"
dbFilePath = documentDirectory.appendingPathComponent(uniqueDbFileName)

if fileManager.fileExists(atPath: dbFilePath.path) {
try fileManager.removeItem(at: dbFilePath)
}
}

override func tearDownWithError() throws {
let fileManager = FileManager.default
if fileManager.fileExists(atPath: dbFilePath.path) {
try fileManager.removeItem(at: dbFilePath)
}
}

func testNewAddress() throws {
let descriptor: Descriptor = try Descriptor(
descriptor: "wpkh([c258d2e4/84h/1h/0h]tpubDDYkZojQFQjht8Tm4jsS3iuEmKjTiEGjG6KnuFNKKJb5A6ZUCUZKdvLdSDWofKi4ToRCwb9poe1XdqfUnP4jaJjCB2Zwv11ZLgSbnZSNecE/0/*)",
network: Network.testnet
)
let wallet: Wallet = try Wallet(
let wallet = try Wallet(
descriptor: descriptor,
changeDescriptor: nil,
persistenceBackendPath: "bdk_persistence.db",
persistenceBackendPath: dbFilePath.path,
network: .testnet
)
let addressInfo: AddressInfo = wallet.getAddress(addressIndex: AddressIndex.new)
Expand All @@ -43,10 +53,10 @@ final class OfflineWalletTests: XCTestCase {
descriptor: "wpkh([c258d2e4/84h/1h/0h]tpubDDYkZojQFQjht8Tm4jsS3iuEmKjTiEGjG6KnuFNKKJb5A6ZUCUZKdvLdSDWofKi4ToRCwb9poe1XdqfUnP4jaJjCB2Zwv11ZLgSbnZSNecE/0/*)",
network: Network.testnet
)
let wallet: Wallet = try Wallet(
let wallet = try Wallet(
descriptor: descriptor,
changeDescriptor: nil,
persistenceBackendPath: "bdk_persistence.db",
persistenceBackendPath: dbFilePath.path,
network: .testnet
)

Expand Down

0 comments on commit 2dd6ee3

Please sign in to comment.