Skip to content

Commit

Permalink
test: clean up persistence test for bdk-swift
Browse files Browse the repository at this point in the history
  • Loading branch information
thunderbiscuit committed Jul 1, 2024
1 parent 7e5897b commit 323eb08
Show file tree
Hide file tree
Showing 9 changed files with 70 additions and 61 deletions.
6 changes: 5 additions & 1 deletion bdk-swift/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ let package = Package(
),
.testTarget(
name: "BitcoinDevKitTests",
dependencies: ["BitcoinDevKit"]),
dependencies: ["BitcoinDevKit"],
resources: [
.copy("Resources/pre_existing_wallet_persistence_test.sqlite")
]
),
]
)
17 changes: 9 additions & 8 deletions bdk-swift/Tests/BitcoinDevKitTests/LiveElectrumClientTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
16 changes: 8 additions & 8 deletions bdk-swift/Tests/BitcoinDevKitTests/LiveMemoryWalletTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
16 changes: 9 additions & 7 deletions bdk-swift/Tests/BitcoinDevKitTests/LiveTransactionTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
16 changes: 8 additions & 8 deletions bdk-swift/Tests/BitcoinDevKitTests/LiveTxBuilderTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
16 changes: 8 additions & 8 deletions bdk-swift/Tests/BitcoinDevKitTests/LiveWalletTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
29 changes: 16 additions & 13 deletions bdk-swift/Tests/BitcoinDevKitTests/OfflinePersistenceTests.swift
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
15 changes: 7 additions & 8 deletions bdk-swift/Tests/BitcoinDevKitTests/OfflineWalletTests.swift
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down

0 comments on commit 323eb08

Please sign in to comment.