-
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.
- Loading branch information
Showing
6 changed files
with
166 additions
and
90 deletions.
There are no files selected for viewing
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
70 changes: 34 additions & 36 deletions
70
bdk-android/lib/src/androidTest/kotlin/org/bitcoindevkit/AndroidLibTest.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 |
---|---|---|
@@ -1,59 +1,57 @@ | ||
package org.bitcoindevkit | ||
|
||
import org.junit.Assert.* | ||
import org.junit.Test | ||
import android.app.Application | ||
import android.content.Context.MODE_PRIVATE | ||
import androidx.test.core.app.ApplicationProvider | ||
import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
import org.junit.runner.RunWith | ||
import org.slf4j.Logger | ||
import org.slf4j.LoggerFactory | ||
import java.io.File | ||
import kotlin.test.Test | ||
import kotlin.test.assertEquals | ||
import kotlin.test.assertTrue | ||
|
||
/** | ||
* Instrumented test, which will execute on an Android device. | ||
* | ||
* See [testing documentation](http://d.android.com/tools/testing). | ||
*/ | ||
@RunWith(AndroidJUnit4::class) | ||
class AndroidLibTest { | ||
@Test | ||
fun testNetwork() { | ||
val signetNetwork = Network.SIGNET | ||
} | ||
class WalletTest { | ||
|
||
@Test | ||
fun testDescriptorBip86() { | ||
val mnemonic = Mnemonic(WordCount.WORDS12) | ||
val descriptorSecretKey = DescriptorSecretKey(Network.TESTNET, mnemonic, null) | ||
val descriptor = Descriptor.newBip86(descriptorSecretKey, KeychainKind.EXTERNAL, Network.TESTNET) | ||
val mnemonic: Mnemonic = Mnemonic(WordCount.WORDS12) | ||
val descriptorSecretKey: DescriptorSecretKey = DescriptorSecretKey(Network.TESTNET, mnemonic, null) | ||
val descriptor: 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") | ||
@Test | ||
fun testNewAddress() { | ||
val descriptor: Descriptor = Descriptor( | ||
"wpkh([c258d2e4/84h/1h/0h]tpubDDYkZojQFQjht8Tm4jsS3iuEmKjTiEGjG6KnuFNKKJb5A6ZUCUZKdvLdSDWofKi4ToRCwb9poe1XdqfUnP4jaJjCB2Zwv11ZLgSbnZSNecE/0/*)", | ||
Network.TESTNET | ||
) | ||
val wallet: Wallet = Wallet.newNoPersist( | ||
descriptor, | ||
null, | ||
Network.TESTNET | ||
) | ||
val addressInfo: AddressInfo = wallet.getAddress(AddressIndex.New) | ||
|
||
assertEquals("tb1qzg4mckdh50nwdm9hkzq06528rsu73hjxxzem3e", addressInfo.address.asString()) | ||
} | ||
|
||
@Test | ||
fun testBalance() { | ||
val descriptor = Descriptor("wpkh(tprv8ZgxMBicQKsPf2qfrEygW6fdYseJDDrVnDv26PH5BHdvSuG6ecCbHqLVof9yZcMoM31z9ur3tTYbSnr1WBqbGX97CbXcmp5H6qeMpyvx35B/84h/1h/0h/0/*)", Network.TESTNET) | ||
val wallet = Wallet.newNoPersist(descriptor, null, Network.TESTNET) | ||
val descriptor: Descriptor = Descriptor( | ||
"wpkh([c258d2e4/84h/1h/0h]tpubDDYkZojQFQjht8Tm4jsS3iuEmKjTiEGjG6KnuFNKKJb5A6ZUCUZKdvLdSDWofKi4ToRCwb9poe1XdqfUnP4jaJjCB2Zwv11ZLgSbnZSNecE/0/*)", | ||
Network.TESTNET | ||
) | ||
val wallet: Wallet = Wallet.newNoPersist( | ||
descriptor, | ||
null, | ||
Network.TESTNET | ||
) | ||
|
||
assert(wallet.getBalance().total() == 0uL) | ||
assertEquals(0uL, wallet.getBalance().total()) | ||
} | ||
|
||
// @Test | ||
// fun testSyncedBalance() { | ||
// val descriptor = Descriptor("wpkh(tprv8ZgxMBicQKsPf2qfrEygW6fdYseJDDrVnDv26PH5BHdvSuG6ecCbHqLVof9yZcMoM31z9ur3tTYbSnr1WBqbGX97CbXcmp5H6qeMpyvx35B/84h/1h/0h/0/*)", Network.TESTNET) | ||
// val wallet = Wallet.newNoPersist(descriptor, null, Network.TESTNET) | ||
// val esploraClient = EsploraClient("https://mempool.space/testnet/api") | ||
// // val esploraClient = EsploraClient("https://blockstream.info/testnet/api") | ||
// val update = esploraClient.scan(wallet, 10uL, 1uL) | ||
// wallet.applyUpdate(update) | ||
// println("Balance: ${wallet.getBalance().total()}") | ||
// } | ||
} | ||
} |
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
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
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 |
---|---|---|
@@ -1,21 +1,41 @@ | ||
import bdkpython as bdk | ||
import unittest | ||
|
||
class TestSimpleWallet(unittest.TestCase): | ||
|
||
descriptor = bdk.Descriptor("wpkh([c258d2e4/84h/1h/0h]tpubDDYkZojQFQjht8Tm4jsS3iuEmKjTiEGjG6KnuFNKKJb5A6ZUCUZKdvLdSDWofKi4ToRCwb9poe1XdqfUnP4jaJjCB2Zwv11ZLgSbnZSNecE/0/*)", bdk.Network.TESTNET) | ||
def test_descriptor_bip86(self): | ||
mnemonic: bdk.Mnemonic = bdk.Mnemonic(bdk.WordCount.WORDS12) | ||
descriptor_secret_key: bdk.DescriptorSecretKey = bdk.DescriptorSecretKey(bdk.Network.TESTNET, mnemonic, None) | ||
descriptor: bdk.Descriptor = bdk.Descriptor.new_bip86(descriptor_secret_key, bdk.KeychainKind.EXTERNAL, bdk.Network.TESTNET) | ||
|
||
class TestSimpleBip84Wallet(unittest.TestCase): | ||
self.assertTrue(descriptor.as_string().startswith("tr"), "Bip86 Descriptor does not start with 'tr'") | ||
|
||
def test_address_bip84_testnet(self): | ||
wallet = bdk.Wallet.new_no_persist( | ||
descriptor=descriptor, | ||
change_descriptor=None, | ||
network=bdk.Network.TESTNET, | ||
def test_new_address(self): | ||
descriptor: bdk.Descriptor = bdk.Descriptor( | ||
"wpkh([c258d2e4/84h/1h/0h]tpubDDYkZojQFQjht8Tm4jsS3iuEmKjTiEGjG6KnuFNKKJb5A6ZUCUZKdvLdSDWofKi4ToRCwb9poe1XdqfUnP4jaJjCB2Zwv11ZLgSbnZSNecE/0/*)", | ||
bdk.Network.TESTNET | ||
) | ||
address_info = wallet.get_address(bdk.AddressIndex.LAST_UNUSED()) | ||
address = address_info.address.as_string() | ||
# print(f"New address is {address}") | ||
assert address == "tb1qzg4mckdh50nwdm9hkzq06528rsu73hjxxzem3e", f"Wrong address {address}, should be tb1qzg4mckdh50nwdm9hkzq06528rsu73hjxxzem3e" | ||
wallet: Wallet = bdk.Wallet.new_no_persist( | ||
descriptor, | ||
None, | ||
bdk.Network.TESTNET | ||
) | ||
address_info: bdk.AddressInfo = wallet.get_address(bdk.AddressIndex.NEW()) | ||
|
||
self.assertEqual("tb1qzg4mckdh50nwdm9hkzq06528rsu73hjxxzem3e", address_info.address.as_string()) | ||
|
||
def test_balance(self): | ||
descriptor: bdk.Descriptor = bdk.Descriptor( | ||
"wpkh([c258d2e4/84h/1h/0h]tpubDDYkZojQFQjht8Tm4jsS3iuEmKjTiEGjG6KnuFNKKJb5A6ZUCUZKdvLdSDWofKi4ToRCwb9poe1XdqfUnP4jaJjCB2Zwv11ZLgSbnZSNecE/0/*)", | ||
bdk.Network.TESTNET | ||
) | ||
wallet: Wallet = bdk.Wallet.new_no_persist( | ||
descriptor, | ||
None, | ||
bdk.Network.TESTNET | ||
) | ||
|
||
self.assertEqual(wallet.get_balance().total(), 0) | ||
|
||
if __name__ == '__main__': | ||
unittest.main() |
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