2024-06-26 16:02:05 -04:00
|
|
|
import XCTest
|
|
|
|
@testable import BitcoinDevKit
|
|
|
|
|
2024-07-01 10:25:01 -04:00
|
|
|
final class OfflinePersistenceTests: XCTestCase {
|
|
|
|
private let descriptor = try! Descriptor(
|
2024-06-26 16:02:05 -04:00
|
|
|
descriptor: "wpkh(tprv8ZgxMBicQKsPf2qfrEygW6fdYseJDDrVnDv26PH5BHdvSuG6ecCbHqLVof9yZcMoM31z9ur3tTYbSnr1WBqbGX97CbXcmp5H6qeMpyvx35B/84h/1h/0h/0/*)",
|
|
|
|
network: Network.signet
|
2024-07-01 10:25:01 -04:00
|
|
|
)
|
|
|
|
private let changeDescriptor = try! Descriptor(
|
|
|
|
descriptor: "wpkh(tprv8ZgxMBicQKsPf2qfrEygW6fdYseJDDrVnDv26PH5BHdvSuG6ecCbHqLVof9yZcMoM31z9ur3tTYbSnr1WBqbGX97CbXcmp5H6qeMpyvx35B/84h/1h/0h/1/*)",
|
|
|
|
network: Network.signet
|
|
|
|
)
|
2024-06-26 16:02:05 -04:00
|
|
|
var dbFilePath: URL!
|
|
|
|
|
|
|
|
override func setUpWithError() throws {
|
|
|
|
super.setUp()
|
2024-07-01 10:25:01 -04:00
|
|
|
|
|
|
|
guard let resourceUrl = Bundle.module.url(
|
|
|
|
forResource: "pre_existing_wallet_persistence_test",
|
|
|
|
withExtension: "sqlite"
|
|
|
|
) else {
|
|
|
|
print("error finding resourceURL")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
dbFilePath = resourceUrl
|
2024-06-26 16:02:05 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func testPersistence() throws {
|
|
|
|
let sqliteStore = try! SqliteStore(path: dbFilePath.path)
|
|
|
|
let initialChangeSet = try! sqliteStore.read()
|
|
|
|
let wallet = try Wallet.newOrLoad(
|
|
|
|
descriptor: descriptor,
|
|
|
|
changeDescriptor: changeDescriptor,
|
|
|
|
changeSet: initialChangeSet,
|
|
|
|
network: .signet
|
|
|
|
)
|
|
|
|
let nextAddress: AddressInfo = wallet.revealNextAddress(keychain: KeychainKind.external)
|
|
|
|
print("Address: \(nextAddress)")
|
|
|
|
|
|
|
|
XCTAssertTrue(nextAddress.address.description == "tb1qan3lldunh37ma6c0afeywgjyjgnyc8uz975zl2")
|
|
|
|
XCTAssertTrue(nextAddress.index == 7)
|
|
|
|
}
|
|
|
|
}
|