From c426c5401da89228a91cabe7001864f8b9a3ca5e Mon Sep 17 00:00:00 2001 From: Matthew Date: Wed, 25 Oct 2023 15:25:16 -0500 Subject: [PATCH] tests: update all tests --- .../org/bitcoindevkit/AndroidLibTest.kt | 11 ++- .../kotlin/org/bitcoindevkit/JvmLibTest.kt | 11 ++- .../BitcoinDevKitTests.swift | 77 ++++++++++++++----- 3 files changed, 66 insertions(+), 33 deletions(-) diff --git a/bdk-android/lib/src/androidTest/kotlin/org/bitcoindevkit/AndroidLibTest.kt b/bdk-android/lib/src/androidTest/kotlin/org/bitcoindevkit/AndroidLibTest.kt index 446b4cf2..5bbce7f4 100644 --- a/bdk-android/lib/src/androidTest/kotlin/org/bitcoindevkit/AndroidLibTest.kt +++ b/bdk-android/lib/src/androidTest/kotlin/org/bitcoindevkit/AndroidLibTest.kt @@ -18,24 +18,23 @@ import java.io.File */ @RunWith(AndroidJUnit4::class) class AndroidLibTest { - @Test - fun testNetwork() { - val signetNetwork = Network.SIGNET - } @Test fun testDescriptorBip86() { val mnemonic = Mnemonic(WordCount.WORDS12) val descriptorSecretKey = DescriptorSecretKey(Network.TESTNET, mnemonic, null) val descriptor = Descriptor.newBip86(descriptorSecretKey, KeychainKind.EXTERNAL, Network.TESTNET) + + assertTrue(descriptor.asString().startsWith("tr"), "Bip86 Descriptor does not start with 'tr'"); } @Test fun testUsedWallet() { val descriptor = Descriptor("wpkh(tprv8ZgxMBicQKsPf2qfrEygW6fdYseJDDrVnDv26PH5BHdvSuG6ecCbHqLVof9yZcMoM31z9ur3tTYbSnr1WBqbGX97CbXcmp5H6qeMpyvx35B/84h/1h/0h/0/*)", Network.TESTNET) val wallet = Wallet.newNoPersist(descriptor, null, Network.TESTNET) - val (index, address, keychain) = wallet.getAddress(AddressIndex.LastUnused) - println("Address ${address.asString()} at index $index") + val addressInfo = wallet.getAddress(AddressIndex.LastUnused) + + assert(addressInfo.asString() == "tb1qzg4mckdh50nwdm9hkzq06528rsu73hjxxzem3e") } @Test diff --git a/bdk-jvm/lib/src/test/kotlin/org/bitcoindevkit/JvmLibTest.kt b/bdk-jvm/lib/src/test/kotlin/org/bitcoindevkit/JvmLibTest.kt index c9f665ed..fbadd098 100644 --- a/bdk-jvm/lib/src/test/kotlin/org/bitcoindevkit/JvmLibTest.kt +++ b/bdk-jvm/lib/src/test/kotlin/org/bitcoindevkit/JvmLibTest.kt @@ -3,24 +3,23 @@ package org.bitcoindevkit import org.junit.Test class WalletTest { - @Test - fun testNetwork() { - val signetNetwork = Network.SIGNET - } @Test fun testDescriptorBip86() { val mnemonic = Mnemonic(WordCount.WORDS12) val descriptorSecretKey = DescriptorSecretKey(Network.TESTNET, mnemonic, null) val descriptor = Descriptor.newBip86(descriptorSecretKey, KeychainKind.EXTERNAL, Network.TESTNET) + + assertTrue(descriptor.asString().startsWith("tr"), "Bip86 Descriptor does not start with 'tr'"); } @Test fun testUsedWallet() { val descriptor = Descriptor("wpkh(tprv8ZgxMBicQKsPf2qfrEygW6fdYseJDDrVnDv26PH5BHdvSuG6ecCbHqLVof9yZcMoM31z9ur3tTYbSnr1WBqbGX97CbXcmp5H6qeMpyvx35B/84h/1h/0h/0/*)", Network.TESTNET) val wallet = Wallet.newNoPersist(descriptor, null, Network.TESTNET) - val (index, address, keychain) = wallet.getAddress(AddressIndex.LastUnused) - println("Address ${address.asString()} at index $index") + val addressInfo = wallet.getAddress(AddressIndex.LastUnused) + + assert(addressInfo.asString() == "tb1qzg4mckdh50nwdm9hkzq06528rsu73hjxxzem3e") } @Test diff --git a/bdk-swift/Tests/BitcoinDevKitTests/BitcoinDevKitTests.swift b/bdk-swift/Tests/BitcoinDevKitTests/BitcoinDevKitTests.swift index e2b270d2..e2d61ccf 100644 --- a/bdk-swift/Tests/BitcoinDevKitTests/BitcoinDevKitTests.swift +++ b/bdk-swift/Tests/BitcoinDevKitTests/BitcoinDevKitTests.swift @@ -2,32 +2,67 @@ import XCTest @testable import BitcoinDevKit final class BitcoinDevKitTests: XCTestCase { - func testMemoryWalletNewAddress() throws { - let desc = try Descriptor( + + func testDescriptorBip86() { + let mnemonic = Mnemonic(wordCount: WordCount.words12) + let descriptorSecretKey = DescriptorSecretKey( + network: Network.testnet, + mnemonic: mnemonic, + password: nil + ) + let descriptor = Descriptor.newBip86( + secretKey: descriptorSecretKey, + keychain: KeychainKind.external, + network: Network.testnet + ) + + XCTAssertTrue(descriptor.asString().hasPrefix("tr"), "Bip86 Descriptor does not start with 'tr'") + } + + func testUsedWallet() throws { + let descriptor = try Descriptor( descriptor: "wpkh([c258d2e4/84h/1h/0h]tpubDDYkZojQFQjht8Tm4jsS3iuEmKjTiEGjG6KnuFNKKJb5A6ZUCUZKdvLdSDWofKi4ToRCwb9poe1XdqfUnP4jaJjCB2Zwv11ZLgSbnZSNecE/0/*)", - network: Network.regtest + network: Network.testnet + ) + let wallet = try Wallet.newNoPersist( + descriptor: descriptor, + changeDescriptor: nil, + network: .testnet ) - let wallet = try Wallet.newNoPersist(descriptor: desc, changeDescriptor: nil, network: .testnet) let addressInfo = wallet.getAddress(addressIndex: AddressIndex.lastUnused) + XCTAssertEqual(addressInfo.address.asString(), "tb1qzg4mckdh50nwdm9hkzq06528rsu73hjxxzem3e") } + + func testBalance() throws { + let descriptor = try Descriptor( + descriptor: "wpkh([c258d2e4/84h/1h/0h]tpubDDYkZojQFQjht8Tm4jsS3iuEmKjTiEGjG6KnuFNKKJb5A6ZUCUZKdvLdSDWofKi4ToRCwb9poe1XdqfUnP4jaJjCB2Zwv11ZLgSbnZSNecE/0/*)", + network: Network.testnet + ) + let wallet = try Wallet.newNoPersist( + descriptor: descriptor, + changeDescriptor: nil, + network: .testnet + ) + + XCTAssertEqual(wallet.getBalance().total(), 0) + } -// func testConnectedWalletBalance() throws { -// let descriptor = try Descriptor( -// descriptor: "wpkh(tprv8ZgxMBicQKsPf2qfrEygW6fdYseJDDrVnDv26PH5BHdvSuG6ecCbHqLVof9yZcMoM31z9ur3tTYbSnr1WBqbGX97CbXcmp5H6qeMpyvx35B/84h/1h/0h/0/*)", -// network: Network.testnet -// ) -// let wallet = try Wallet.newNoPersist( -// descriptor: descriptor, -// changeDescriptor: nil, -// network: .testnet -// ) -// -// let esploraClient = EsploraClient(url: "https://mempool.space/testnet/api") -// // val esploraClient = EsploraClient("https://blockstream.info/testnet/api") -// let update = try esploraClient.scan(wallet: wallet, stopGap: 10, parallelRequests: 1) -// try wallet.applyUpdate(update: update) +// func testSyncedBalance() throws { +// let descriptor = try Descriptor( +// descriptor: "wpkh([c258d2e4/84h/1h/0h]tpubDDYkZojQFQjht8Tm4jsS3iuEmKjTiEGjG6KnuFNKKJb5A6ZUCUZKdvLdSDWofKi4ToRCwb9poe1XdqfUnP4jaJjCB2Zwv11ZLgSbnZSNecE/0/*)", +// network: Network.testnet +// ) +// let wallet = try Wallet.newNoPersist( +// descriptor: descriptor, +// changeDescriptor: nil, +// network: .testnet +// ) +// let esploraClient = EsploraClient("https://mempool.space/testnet/api") +// let update = esploraClient.scan(wallet, 10, 1) +// wallet.applyUpdate(update) // -// print("Balance: \(wallet.getBalance().total())") -// } +// XCTAssertEqual(wallet.getBalance().total(), 0) +// } + }