2021-11-22 14:17:03 -08:00
|
|
|
import XCTest
|
|
|
|
@testable import BitcoinDevKit
|
|
|
|
|
|
|
|
final class BitcoinDevKitTests: XCTestCase {
|
2023-10-25 15:25:16 -05:00
|
|
|
|
|
|
|
func testDescriptorBip86() {
|
|
|
|
let mnemonic: Mnemonic = Mnemonic(wordCount: WordCount.words12)
|
|
|
|
let descriptorSecretKey: DescriptorSecretKey = DescriptorSecretKey(
|
|
|
|
network: Network.testnet,
|
|
|
|
mnemonic: mnemonic,
|
|
|
|
password: nil
|
|
|
|
)
|
|
|
|
let descriptor: Descriptor = Descriptor.newBip86(
|
|
|
|
secretKey: descriptorSecretKey,
|
|
|
|
keychain: KeychainKind.external,
|
|
|
|
network: Network.testnet
|
|
|
|
)
|
|
|
|
|
|
|
|
XCTAssertTrue(descriptor.asString().hasPrefix("tr"), "Bip86 Descriptor does not start with 'tr'")
|
|
|
|
}
|
|
|
|
|
|
|
|
func testNewAddress() throws {
|
|
|
|
let descriptor: Descriptor = try Descriptor(
|
2022-12-14 19:52:43 -05:00
|
|
|
descriptor: "wpkh([c258d2e4/84h/1h/0h]tpubDDYkZojQFQjht8Tm4jsS3iuEmKjTiEGjG6KnuFNKKJb5A6ZUCUZKdvLdSDWofKi4ToRCwb9poe1XdqfUnP4jaJjCB2Zwv11ZLgSbnZSNecE/0/*)",
|
2023-10-25 15:25:16 -05:00
|
|
|
network: Network.testnet
|
|
|
|
)
|
|
|
|
let wallet: Wallet = try Wallet.newNoPersist(
|
|
|
|
descriptor: descriptor,
|
|
|
|
changeDescriptor: nil,
|
|
|
|
network: .testnet
|
2022-12-14 19:52:43 -05:00
|
|
|
)
|
2023-10-25 15:25:16 -05:00
|
|
|
let addressInfo: AddressInfo = wallet.getAddress(addressIndex: AddressIndex.new)
|
|
|
|
|
2023-10-17 12:33:35 -04:00
|
|
|
XCTAssertEqual(addressInfo.address.asString(), "tb1qzg4mckdh50nwdm9hkzq06528rsu73hjxxzem3e")
|
2021-11-22 14:17:03 -08:00
|
|
|
}
|
2023-10-25 15:25:16 -05:00
|
|
|
|
|
|
|
func testBalance() throws {
|
|
|
|
let descriptor: Descriptor = try Descriptor(
|
|
|
|
descriptor: "wpkh([c258d2e4/84h/1h/0h]tpubDDYkZojQFQjht8Tm4jsS3iuEmKjTiEGjG6KnuFNKKJb5A6ZUCUZKdvLdSDWofKi4ToRCwb9poe1XdqfUnP4jaJjCB2Zwv11ZLgSbnZSNecE/0/*)",
|
|
|
|
network: Network.testnet
|
|
|
|
)
|
|
|
|
let wallet: Wallet = try Wallet.newNoPersist(
|
|
|
|
descriptor: descriptor,
|
|
|
|
changeDescriptor: nil,
|
|
|
|
network: .testnet
|
|
|
|
)
|
|
|
|
|
|
|
|
XCTAssertEqual(wallet.getBalance().total(), 0)
|
|
|
|
}
|
2023-10-17 12:33:35 -04:00
|
|
|
|
2023-10-25 15:25:16 -05:00
|
|
|
// 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)
|
2023-10-17 12:33:35 -04:00
|
|
|
//
|
2023-10-25 15:25:16 -05:00
|
|
|
// XCTAssertEqual(wallet.getBalance().total(), 0)
|
|
|
|
// }
|
|
|
|
|
2021-11-22 14:17:03 -08:00
|
|
|
}
|