-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add offline tests for wallet new_or_load method
- Loading branch information
1 parent
3302610
commit 7ed3366
Showing
4 changed files
with
84 additions
and
0 deletions.
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
bdk-jvm/lib/src/test/kotlin/org/bitcoindevkit/OfflinePersistenceTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package org.bitcoindevkit | ||
|
||
import kotlin.test.Test | ||
import kotlin.test.assertEquals | ||
|
||
class OfflinePersistenceTest { | ||
private val persistenceFilePath = run { | ||
val currentDirectory = System.getProperty("user.dir") | ||
val dbFileName = "pre_existing_wallet_persistence_test.sqlite" | ||
"$currentDirectory/src/test/resources/$dbFileName" | ||
} | ||
private val descriptor: Descriptor = Descriptor( | ||
"wpkh(tprv8ZgxMBicQKsPf2qfrEygW6fdYseJDDrVnDv26PH5BHdvSuG6ecCbHqLVof9yZcMoM31z9ur3tTYbSnr1WBqbGX97CbXcmp5H6qeMpyvx35B/84h/1h/0h/0/*)", | ||
Network.SIGNET | ||
) | ||
private val changeDescriptor: Descriptor = Descriptor( | ||
"wpkh(tprv8ZgxMBicQKsPf2qfrEygW6fdYseJDDrVnDv26PH5BHdvSuG6ecCbHqLVof9yZcMoM31z9ur3tTYbSnr1WBqbGX97CbXcmp5H6qeMpyvx35B/84h/1h/0h/1/*)", | ||
Network.SIGNET | ||
) | ||
|
||
@Test | ||
fun testPersistence() { | ||
val sqliteStore: SqliteStore = SqliteStore(persistenceFilePath) | ||
val initialChangeSet: ChangeSet? = sqliteStore.read() | ||
assert(initialChangeSet != null) { "ChangeSet should not be null after loading a valid database" } | ||
val wallet: Wallet = Wallet.newOrLoad( | ||
descriptor, | ||
changeDescriptor, | ||
initialChangeSet, | ||
Network.SIGNET, | ||
) | ||
val addressInfo: AddressInfo = wallet.revealNextAddress(KeychainKind.EXTERNAL) | ||
println("Address: $addressInfo") | ||
|
||
assertEquals( | ||
expected = 7u, | ||
actual = addressInfo.index, | ||
) | ||
assertEquals( | ||
expected = "tb1qan3lldunh37ma6c0afeywgjyjgnyc8uz975zl2", | ||
actual = addressInfo.address.toString(), | ||
) | ||
} | ||
} |
Binary file added
BIN
+56 KB
bdk-jvm/lib/src/test/resources/pre_existing_wallet_persistence_test.sqlite
Binary file not shown.
40 changes: 40 additions & 0 deletions
40
bdk-swift/Tests/BitcoinDevKitTests/OfflinePersistenceTests.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import XCTest | ||
@testable import BitcoinDevKit | ||
|
||
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 { | ||
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) | ||
} | ||
|
||
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, | ||
changeSet: initialChangeSet, | ||
network: .signet | ||
) | ||
let nextAddress: AddressInfo = wallet.revealNextAddress(keychain: KeychainKind.external) | ||
print("Address: \(nextAddress)") | ||
|
||
XCTAssertTrue(nextAddress.address.description == "tb1qan3lldunh37ma6c0afeywgjyjgnyc8uz975zl2") | ||
XCTAssertTrue(nextAddress.index == 7) | ||
} | ||
} |
Binary file not shown.