Skip to content

Commit

Permalink
tests: update all tests
Browse files Browse the repository at this point in the history
  • Loading branch information
reez committed Oct 26, 2023
1 parent 00cd55b commit c426c54
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 5 additions & 6 deletions bdk-jvm/lib/src/test/kotlin/org/bitcoindevkit/JvmLibTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
77 changes: 56 additions & 21 deletions bdk-swift/Tests/BitcoinDevKitTests/BitcoinDevKitTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
// }

}

0 comments on commit c426c54

Please sign in to comment.