diff --git a/bdk-swift/Tests/BitcoinDevKitTests/LiveTxBuilderTests.swift b/bdk-swift/Tests/BitcoinDevKitTests/LiveTxBuilderTests.swift index 691a339a..60c270c2 100644 --- a/bdk-swift/Tests/BitcoinDevKitTests/LiveTxBuilderTests.swift +++ b/bdk-swift/Tests/BitcoinDevKitTests/LiveTxBuilderTests.swift @@ -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/*)", @@ -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/") @@ -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/") diff --git a/bdk-swift/Tests/BitcoinDevKitTests/LiveWalletTests.swift b/bdk-swift/Tests/BitcoinDevKitTests/LiveWalletTests.swift index a38f0a33..43bcc665 100644 --- a/bdk-swift/Tests/BitcoinDevKitTests/LiveWalletTests.swift +++ b/bdk-swift/Tests/BitcoinDevKitTests/LiveWalletTests.swift @@ -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/*)", @@ -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/") @@ -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/") diff --git a/bdk-swift/Tests/BitcoinDevKitTests/OfflineWalletTests.swift b/bdk-swift/Tests/BitcoinDevKitTests/OfflineWalletTests.swift index 07eabd84..330f7af7 100644 --- a/bdk-swift/Tests/BitcoinDevKitTests/OfflineWalletTests.swift +++ b/bdk-swift/Tests/BitcoinDevKitTests/OfflineWalletTests.swift @@ -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) @@ -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 )