From 323eb083507a96987c4c29e1e588292f76c4bf64 Mon Sep 17 00:00:00 2001 From: thunderbiscuit Date: Mon, 1 Jul 2024 10:25:01 -0400 Subject: [PATCH] test: clean up persistence test for bdk-swift --- bdk-swift/Package.swift | 6 +++- .../LiveElectrumClientTests.swift | 17 +++++----- .../LiveMemoryWalletTests.swift | 16 +++++----- .../LiveTransactionTests.swift | 16 +++++----- .../LiveTxBuilderTests.swift | 16 +++++----- .../BitcoinDevKitTests/LiveWalletTests.swift | 16 +++++----- .../OfflinePersistenceTests.swift | 29 ++++++++++-------- .../OfflineWalletTests.swift | 15 +++++---- ...re_existing_wallet_persistence_test.sqlite | Bin 9 files changed, 70 insertions(+), 61 deletions(-) rename bdk-swift/{ => Tests/BitcoinDevKitTests/Resources}/pre_existing_wallet_persistence_test.sqlite (100%) diff --git a/bdk-swift/Package.swift b/bdk-swift/Package.swift index f95411a2..004aaa29 100644 --- a/bdk-swift/Package.swift +++ b/bdk-swift/Package.swift @@ -33,6 +33,10 @@ let package = Package( ), .testTarget( name: "BitcoinDevKitTests", - dependencies: ["BitcoinDevKit"]), + dependencies: ["BitcoinDevKit"], + resources: [ + .copy("Resources/pre_existing_wallet_persistence_test.sqlite") + ] + ), ] ) diff --git a/bdk-swift/Tests/BitcoinDevKitTests/LiveElectrumClientTests.swift b/bdk-swift/Tests/BitcoinDevKitTests/LiveElectrumClientTests.swift index d86d6045..2ca9e0b9 100644 --- a/bdk-swift/Tests/BitcoinDevKitTests/LiveElectrumClientTests.swift +++ b/bdk-swift/Tests/BitcoinDevKitTests/LiveElectrumClientTests.swift @@ -2,16 +2,17 @@ import XCTest @testable import BitcoinDevKit private let SIGNET_ELECTRUM_URL = "ssl://mempool.space:60602" -private let descriptor = try! Descriptor( - descriptor: "wpkh(tprv8ZgxMBicQKsPf2qfrEygW6fdYseJDDrVnDv26PH5BHdvSuG6ecCbHqLVof9yZcMoM31z9ur3tTYbSnr1WBqbGX97CbXcmp5H6qeMpyvx35B/84h/1h/0h/0/*)", - network: Network.signet -) -private let changeDescriptor = try! Descriptor( - descriptor: "wpkh(tprv8ZgxMBicQKsPf2qfrEygW6fdYseJDDrVnDv26PH5BHdvSuG6ecCbHqLVof9yZcMoM31z9ur3tTYbSnr1WBqbGX97CbXcmp5H6qeMpyvx35B/84h/1h/0h/1/*)", - network: Network.signet -) final class LiveElectrumClientTests: XCTestCase { + private let descriptor = try! Descriptor( + descriptor: "wpkh(tprv8ZgxMBicQKsPf2qfrEygW6fdYseJDDrVnDv26PH5BHdvSuG6ecCbHqLVof9yZcMoM31z9ur3tTYbSnr1WBqbGX97CbXcmp5H6qeMpyvx35B/84h/1h/0h/0/*)", + network: Network.signet + ) + private let changeDescriptor = try! Descriptor( + descriptor: "wpkh(tprv8ZgxMBicQKsPf2qfrEygW6fdYseJDDrVnDv26PH5BHdvSuG6ecCbHqLVof9yZcMoM31z9ur3tTYbSnr1WBqbGX97CbXcmp5H6qeMpyvx35B/84h/1h/0h/1/*)", + network: Network.signet + ) + func testSyncedBalance() throws { let wallet = try Wallet( descriptor: descriptor, diff --git a/bdk-swift/Tests/BitcoinDevKitTests/LiveMemoryWalletTests.swift b/bdk-swift/Tests/BitcoinDevKitTests/LiveMemoryWalletTests.swift index f042bdc4..4c3282a8 100644 --- a/bdk-swift/Tests/BitcoinDevKitTests/LiveMemoryWalletTests.swift +++ b/bdk-swift/Tests/BitcoinDevKitTests/LiveMemoryWalletTests.swift @@ -3,16 +3,16 @@ import XCTest private let SIGNET_ESPLORA_URL = "http://signet.bitcoindevkit.net" private let TESTNET_ESPLORA_URL = "https://esplora.testnet.kuutamo.cloud" -private let descriptor = try! Descriptor( - descriptor: "wpkh(tprv8ZgxMBicQKsPf2qfrEygW6fdYseJDDrVnDv26PH5BHdvSuG6ecCbHqLVof9yZcMoM31z9ur3tTYbSnr1WBqbGX97CbXcmp5H6qeMpyvx35B/84h/1h/0h/0/*)", - network: Network.signet -) -private let changeDescriptor = try! Descriptor( - descriptor: "wpkh(tprv8ZgxMBicQKsPf2qfrEygW6fdYseJDDrVnDv26PH5BHdvSuG6ecCbHqLVof9yZcMoM31z9ur3tTYbSnr1WBqbGX97CbXcmp5H6qeMpyvx35B/84h/1h/0h/1/*)", - network: Network.signet -) final class LiveMemoryWalletTests: XCTestCase { + private let descriptor = try! Descriptor( + descriptor: "wpkh(tprv8ZgxMBicQKsPf2qfrEygW6fdYseJDDrVnDv26PH5BHdvSuG6ecCbHqLVof9yZcMoM31z9ur3tTYbSnr1WBqbGX97CbXcmp5H6qeMpyvx35B/84h/1h/0h/0/*)", + network: Network.signet + ) + private let changeDescriptor = try! Descriptor( + descriptor: "wpkh(tprv8ZgxMBicQKsPf2qfrEygW6fdYseJDDrVnDv26PH5BHdvSuG6ecCbHqLVof9yZcMoM31z9ur3tTYbSnr1WBqbGX97CbXcmp5H6qeMpyvx35B/84h/1h/0h/1/*)", + network: Network.signet + ) func testSyncedBalance() throws { let wallet = try Wallet( diff --git a/bdk-swift/Tests/BitcoinDevKitTests/LiveTransactionTests.swift b/bdk-swift/Tests/BitcoinDevKitTests/LiveTransactionTests.swift index a4c376cc..ae390e3a 100644 --- a/bdk-swift/Tests/BitcoinDevKitTests/LiveTransactionTests.swift +++ b/bdk-swift/Tests/BitcoinDevKitTests/LiveTransactionTests.swift @@ -3,16 +3,18 @@ import XCTest private let SIGNET_ESPLORA_URL = "http://signet.bitcoindevkit.net" private let TESTNET_ESPLORA_URL = "https://esplora.testnet.kuutamo.cloud" -private let descriptor = try! Descriptor( + + +final class LiveTransactionTests: XCTestCase { + private let descriptor = try! Descriptor( descriptor: "wpkh(tprv8ZgxMBicQKsPf2qfrEygW6fdYseJDDrVnDv26PH5BHdvSuG6ecCbHqLVof9yZcMoM31z9ur3tTYbSnr1WBqbGX97CbXcmp5H6qeMpyvx35B/84h/1h/0h/0/*)", network: Network.signet -) -private let changeDescriptor = try! Descriptor( - descriptor: "wpkh(tprv8ZgxMBicQKsPf2qfrEygW6fdYseJDDrVnDv26PH5BHdvSuG6ecCbHqLVof9yZcMoM31z9ur3tTYbSnr1WBqbGX97CbXcmp5H6qeMpyvx35B/84h/1h/0h/1/*)", - network: Network.signet -) + ) + private let changeDescriptor = try! Descriptor( + descriptor: "wpkh(tprv8ZgxMBicQKsPf2qfrEygW6fdYseJDDrVnDv26PH5BHdvSuG6ecCbHqLVof9yZcMoM31z9ur3tTYbSnr1WBqbGX97CbXcmp5H6qeMpyvx35B/84h/1h/0h/1/*)", + network: Network.signet + ) -final class LiveTransactionTests: XCTestCase { func testSyncedBalance() throws { let wallet = try Wallet( descriptor: descriptor, diff --git a/bdk-swift/Tests/BitcoinDevKitTests/LiveTxBuilderTests.swift b/bdk-swift/Tests/BitcoinDevKitTests/LiveTxBuilderTests.swift index ab415389..b249f416 100644 --- a/bdk-swift/Tests/BitcoinDevKitTests/LiveTxBuilderTests.swift +++ b/bdk-swift/Tests/BitcoinDevKitTests/LiveTxBuilderTests.swift @@ -3,16 +3,16 @@ import XCTest private let SIGNET_ESPLORA_URL = "http://signet.bitcoindevkit.net" private let TESTNET_ESPLORA_URL = "https://esplora.testnet.kuutamo.cloud" -private let descriptor = try! Descriptor( - descriptor: "wpkh(tprv8ZgxMBicQKsPf2qfrEygW6fdYseJDDrVnDv26PH5BHdvSuG6ecCbHqLVof9yZcMoM31z9ur3tTYbSnr1WBqbGX97CbXcmp5H6qeMpyvx35B/84h/1h/0h/0/*)", - network: Network.signet -) -private let changeDescriptor = try! Descriptor( - descriptor: "wpkh(tprv8ZgxMBicQKsPf2qfrEygW6fdYseJDDrVnDv26PH5BHdvSuG6ecCbHqLVof9yZcMoM31z9ur3tTYbSnr1WBqbGX97CbXcmp5H6qeMpyvx35B/84h/1h/0h/1/*)", - network: Network.signet -) final class LiveTxBuilderTests: XCTestCase { + private let descriptor = try! Descriptor( + descriptor: "wpkh(tprv8ZgxMBicQKsPf2qfrEygW6fdYseJDDrVnDv26PH5BHdvSuG6ecCbHqLVof9yZcMoM31z9ur3tTYbSnr1WBqbGX97CbXcmp5H6qeMpyvx35B/84h/1h/0h/0/*)", + network: Network.signet + ) + private let changeDescriptor = try! Descriptor( + descriptor: "wpkh(tprv8ZgxMBicQKsPf2qfrEygW6fdYseJDDrVnDv26PH5BHdvSuG6ecCbHqLVof9yZcMoM31z9ur3tTYbSnr1WBqbGX97CbXcmp5H6qeMpyvx35B/84h/1h/0h/1/*)", + network: Network.signet + ) var dbFilePath: URL! override func setUpWithError() throws { diff --git a/bdk-swift/Tests/BitcoinDevKitTests/LiveWalletTests.swift b/bdk-swift/Tests/BitcoinDevKitTests/LiveWalletTests.swift index b0c62ec4..3ad1701a 100644 --- a/bdk-swift/Tests/BitcoinDevKitTests/LiveWalletTests.swift +++ b/bdk-swift/Tests/BitcoinDevKitTests/LiveWalletTests.swift @@ -3,16 +3,16 @@ import XCTest private let SIGNET_ESPLORA_URL = "http://signet.bitcoindevkit.net" private let TESTNET_ESPLORA_URL = "https://esplora.testnet.kuutamo.cloud" -private let descriptor = try! Descriptor( - descriptor: "wpkh(tprv8ZgxMBicQKsPf2qfrEygW6fdYseJDDrVnDv26PH5BHdvSuG6ecCbHqLVof9yZcMoM31z9ur3tTYbSnr1WBqbGX97CbXcmp5H6qeMpyvx35B/84h/1h/0h/0/*)", - network: Network.signet -) -private let changeDescriptor = try! Descriptor( - descriptor: "wpkh(tprv8ZgxMBicQKsPf2qfrEygW6fdYseJDDrVnDv26PH5BHdvSuG6ecCbHqLVof9yZcMoM31z9ur3tTYbSnr1WBqbGX97CbXcmp5H6qeMpyvx35B/84h/1h/0h/1/*)", - network: Network.signet -) final class LiveWalletTests: XCTestCase { + private let descriptor = try! Descriptor( + descriptor: "wpkh(tprv8ZgxMBicQKsPf2qfrEygW6fdYseJDDrVnDv26PH5BHdvSuG6ecCbHqLVof9yZcMoM31z9ur3tTYbSnr1WBqbGX97CbXcmp5H6qeMpyvx35B/84h/1h/0h/0/*)", + network: Network.signet + ) + private let changeDescriptor = try! Descriptor( + descriptor: "wpkh(tprv8ZgxMBicQKsPf2qfrEygW6fdYseJDDrVnDv26PH5BHdvSuG6ecCbHqLVof9yZcMoM31z9ur3tTYbSnr1WBqbGX97CbXcmp5H6qeMpyvx35B/84h/1h/0h/1/*)", + network: Network.signet + ) var dbFilePath: URL! override func setUpWithError() throws { diff --git a/bdk-swift/Tests/BitcoinDevKitTests/OfflinePersistenceTests.swift b/bdk-swift/Tests/BitcoinDevKitTests/OfflinePersistenceTests.swift index dc1a89c5..b6a15daa 100644 --- a/bdk-swift/Tests/BitcoinDevKitTests/OfflinePersistenceTests.swift +++ b/bdk-swift/Tests/BitcoinDevKitTests/OfflinePersistenceTests.swift @@ -1,30 +1,33 @@ import XCTest @testable import BitcoinDevKit -private let descriptor = try! Descriptor( +final class OfflinePersistenceTests: XCTestCase { + private let descriptor = try! Descriptor( descriptor: "wpkh(tprv8ZgxMBicQKsPf2qfrEygW6fdYseJDDrVnDv26PH5BHdvSuG6ecCbHqLVof9yZcMoM31z9ur3tTYbSnr1WBqbGX97CbXcmp5H6qeMpyvx35B/84h/1h/0h/0/*)", network: Network.signet -) -private let changeDescriptor = try! Descriptor( - descriptor: "wpkh(tprv8ZgxMBicQKsPf2qfrEygW6fdYseJDDrVnDv26PH5BHdvSuG6ecCbHqLVof9yZcMoM31z9ur3tTYbSnr1WBqbGX97CbXcmp5H6qeMpyvx35B/84h/1h/0h/1/*)", - network: Network.signet -) - -final class OfflinePersistenceTests: XCTestCase { + ) + private let changeDescriptor = try! Descriptor( + descriptor: "wpkh(tprv8ZgxMBicQKsPf2qfrEygW6fdYseJDDrVnDv26PH5BHdvSuG6ecCbHqLVof9yZcMoM31z9ur3tTYbSnr1WBqbGX97CbXcmp5H6qeMpyvx35B/84h/1h/0h/1/*)", + network: Network.signet + ) var dbFilePath: URL! override func setUpWithError() throws { super.setUp() - let currentDirectoryURL = URL(fileURLWithPath: FileManager.default.currentDirectoryPath) - let dbFileName = "pre_existing_wallet_persistence_test.sqlite" - dbFilePath = currentDirectoryURL.appendingPathComponent(dbFileName) + + guard let resourceUrl = Bundle.module.url( + forResource: "pre_existing_wallet_persistence_test", + withExtension: "sqlite" + ) else { + print("error finding resourceURL") + return + } + dbFilePath = resourceUrl } func testPersistence() throws { let sqliteStore = try! SqliteStore(path: dbFilePath.path) let initialChangeSet = try! sqliteStore.read() - XCTAssertTrue(initialChangeSet != nil, "ChangeSet should not be nil after loading a valid database") - let wallet = try Wallet.newOrLoad( descriptor: descriptor, changeDescriptor: changeDescriptor, diff --git a/bdk-swift/Tests/BitcoinDevKitTests/OfflineWalletTests.swift b/bdk-swift/Tests/BitcoinDevKitTests/OfflineWalletTests.swift index b63d3864..4f37a382 100644 --- a/bdk-swift/Tests/BitcoinDevKitTests/OfflineWalletTests.swift +++ b/bdk-swift/Tests/BitcoinDevKitTests/OfflineWalletTests.swift @@ -1,16 +1,15 @@ import XCTest @testable import BitcoinDevKit -private let descriptor = try! Descriptor( +final class OfflineWalletTests: XCTestCase { + private let descriptor = try! Descriptor( descriptor: "wpkh(tprv8ZgxMBicQKsPf2qfrEygW6fdYseJDDrVnDv26PH5BHdvSuG6ecCbHqLVof9yZcMoM31z9ur3tTYbSnr1WBqbGX97CbXcmp5H6qeMpyvx35B/84h/1h/0h/0/*)", network: Network.signet -) -private let changeDescriptor = try! Descriptor( - descriptor: "wpkh(tprv8ZgxMBicQKsPf2qfrEygW6fdYseJDDrVnDv26PH5BHdvSuG6ecCbHqLVof9yZcMoM31z9ur3tTYbSnr1WBqbGX97CbXcmp5H6qeMpyvx35B/84h/1h/0h/1/*)", - network: Network.signet -) - -final class OfflineWalletTests: XCTestCase { + ) + private let changeDescriptor = try! Descriptor( + descriptor: "wpkh(tprv8ZgxMBicQKsPf2qfrEygW6fdYseJDDrVnDv26PH5BHdvSuG6ecCbHqLVof9yZcMoM31z9ur3tTYbSnr1WBqbGX97CbXcmp5H6qeMpyvx35B/84h/1h/0h/1/*)", + network: Network.signet + ) var dbFilePath: URL! override func setUpWithError() throws { diff --git a/bdk-swift/pre_existing_wallet_persistence_test.sqlite b/bdk-swift/Tests/BitcoinDevKitTests/Resources/pre_existing_wallet_persistence_test.sqlite similarity index 100% rename from bdk-swift/pre_existing_wallet_persistence_test.sqlite rename to bdk-swift/Tests/BitcoinDevKitTests/Resources/pre_existing_wallet_persistence_test.sqlite