-
Notifications
You must be signed in to change notification settings - Fork 2
Add unit tests #14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add unit tests #14
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| package org.bitcoindevkit | ||
|
|
||
| val BIP84_DESCRIPTOR: Descriptor = Descriptor( | ||
| "wpkh(tprv8ZgxMBicQKsPf2qfrEygW6fdYseJDDrVnDv26PH5BHdvSuG6ecCbHqLVof9yZcMoM31z9ur3tTYbSnr1WBqbGX97CbXcmp5H6qeMpyvx35B/84h/1h/1h/0/*)", | ||
| Network.TESTNET | ||
| ) | ||
| val BIP84_CHANGE_DESCRIPTOR: Descriptor = Descriptor( | ||
| "wpkh(tprv8ZgxMBicQKsPf2qfrEygW6fdYseJDDrVnDv26PH5BHdvSuG6ecCbHqLVof9yZcMoM31z9ur3tTYbSnr1WBqbGX97CbXcmp5H6qeMpyvx35B/84h/1h/1h/1/*)", | ||
| Network.TESTNET | ||
| ) | ||
| val BIP86_DESCRIPTOR: Descriptor = Descriptor( | ||
| "tr(tprv8ZgxMBicQKsPf2qfrEygW6fdYseJDDrVnDv26PH5BHdvSuG6ecCbHqLVof9yZcMoM31z9ur3tTYbSnr1WBqbGX97CbXcmp5H6qeMpyvx35B/86h/1h/1h/0/*)", | ||
| Network.TESTNET | ||
| ) | ||
| val BIP86_CHANGE_DESCRIPTOR: Descriptor = Descriptor( | ||
| "tr(tprv8ZgxMBicQKsPf2qfrEygW6fdYseJDDrVnDv26PH5BHdvSuG6ecCbHqLVof9yZcMoM31z9ur3tTYbSnr1WBqbGX97CbXcmp5H6qeMpyvx35B/86h/1h/1h/1/*)", | ||
| Network.TESTNET | ||
| ) | ||
| val NON_EXTENDED_DESCRIPTOR_0: Descriptor = Descriptor( | ||
| descriptor = "wpkh(tprv8ZgxMBicQKsPf2qfrEygW6fdYseJDDrVnDv26PH5BHdvSuG6ecCbHqLVof9yZcMoM31z9ur3tTYbSnr1WBqbGX97CbXcmp5H6qeMpyvx35B/84h/1h/1h/0/0)", | ||
| network = Network.TESTNET | ||
| ) | ||
| val NON_EXTENDED_DESCRIPTOR_1: Descriptor = Descriptor( | ||
| descriptor = "wpkh(tprv8ZgxMBicQKsPf2qfrEygW6fdYseJDDrVnDv26PH5BHdvSuG6ecCbHqLVof9yZcMoM31z9ur3tTYbSnr1WBqbGX97CbXcmp5H6qeMpyvx35B/84h/1h/1h/0/1)", | ||
| network = Network.TESTNET | ||
| ) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| package org.bitcoindevkit | ||
|
|
||
| import org.junit.jupiter.api.Nested | ||
| import org.junit.jupiter.api.Test | ||
| import kotlin.test.assertFails | ||
|
|
||
| class CreatingWalletsTest { | ||
| private val conn: Persister = Persister.newInMemory() | ||
|
|
||
| @Nested | ||
| inner class Success { | ||
| @Test | ||
| fun `Create WPKH wallet`() { | ||
| val wallet: Wallet = Wallet( | ||
| descriptor = BIP84_DESCRIPTOR, | ||
| changeDescriptor = BIP84_CHANGE_DESCRIPTOR, | ||
| network = Network.TESTNET, | ||
| persister = conn | ||
| ) | ||
| } | ||
|
|
||
| @Test | ||
| fun `Create TR wallet`() { | ||
| val wallet: Wallet = Wallet( | ||
| descriptor = BIP86_DESCRIPTOR, | ||
| changeDescriptor = BIP86_CHANGE_DESCRIPTOR, | ||
| network = Network.TESTNET, | ||
| persister = conn | ||
| ) | ||
| } | ||
|
|
||
| @Test | ||
| fun `Create a wallet with a non-extended descriptor`() { | ||
| val wallet: Wallet = Wallet( | ||
| descriptor = NON_EXTENDED_DESCRIPTOR_0, | ||
| changeDescriptor = NON_EXTENDED_DESCRIPTOR_1, | ||
| network = Network.TESTNET, | ||
| persister = conn | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| @Nested | ||
| inner class Failure { | ||
| @Test | ||
| fun `Descriptors do not match provided network`() { | ||
| // The descriptors provided are for Testnet 3, but the wallet attempts to build for mainnet | ||
| assertFails { | ||
| val wallet: Wallet = Wallet( | ||
| descriptor = NON_EXTENDED_DESCRIPTOR_0, | ||
| changeDescriptor = NON_EXTENDED_DESCRIPTOR_1, | ||
| network = Network.BITCOIN, | ||
| persister = conn | ||
| ) | ||
| } | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| package org.bitcoindevkit | ||
|
|
||
| import org.junit.jupiter.api.Nested | ||
| import org.junit.jupiter.api.Test | ||
| import kotlin.test.assertFails | ||
|
|
||
| class DescriptorTest { | ||
| @Nested | ||
| inner class Success { | ||
| @Test | ||
| fun `Create extended WPKH descriptors for all networks`() { | ||
| val descriptor1: Descriptor = Descriptor( | ||
| "wpkh(tprv8ZgxMBicQKsPf2qfrEygW6fdYseJDDrVnDv26PH5BHdvSuG6ecCbHqLVof9yZcMoM31z9ur3tTYbSnr1WBqbGX97CbXcmp5H6qeMpyvx35B/86h/1h/1h/0/*)", | ||
| Network.REGTEST | ||
| ) | ||
| val descriptor2: Descriptor = Descriptor( | ||
| "wpkh(tprv8ZgxMBicQKsPf2qfrEygW6fdYseJDDrVnDv26PH5BHdvSuG6ecCbHqLVof9yZcMoM31z9ur3tTYbSnr1WBqbGX97CbXcmp5H6qeMpyvx35B/86h/1h/1h/0/*)", | ||
| Network.TESTNET | ||
| ) | ||
| val descriptor3: Descriptor = Descriptor( | ||
| "wpkh(tprv8ZgxMBicQKsPf2qfrEygW6fdYseJDDrVnDv26PH5BHdvSuG6ecCbHqLVof9yZcMoM31z9ur3tTYbSnr1WBqbGX97CbXcmp5H6qeMpyvx35B/86h/1h/1h/0/*)", | ||
| Network.TESTNET4 | ||
| ) | ||
| val descriptor4: Descriptor = Descriptor( | ||
| "wpkh(tprv8ZgxMBicQKsPf2qfrEygW6fdYseJDDrVnDv26PH5BHdvSuG6ecCbHqLVof9yZcMoM31z9ur3tTYbSnr1WBqbGX97CbXcmp5H6qeMpyvx35B/86h/1h/1h/0/*)", | ||
| Network.SIGNET | ||
| ) | ||
| val descriptor5: Descriptor = Descriptor( | ||
| "wpkh(xprv9s21ZrQH143K3LRcTnWpaCSYb75ic2rGuSgicmJhSVQSbfaKgPXfa8PhnYszgdcyWLoc8n1E2iHUnskjgGTAyCEpJYv7fqKxUcRNaVngA1V/86h/1h/1h/0/*)", | ||
| Network.BITCOIN | ||
| ) | ||
| } | ||
|
|
||
| @Test | ||
| fun `Create extended TR descriptors for all networks`() { | ||
| val descriptor1: Descriptor = Descriptor( | ||
| "tr(tprv8ZgxMBicQKsPf2qfrEygW6fdYseJDDrVnDv26PH5BHdvSuG6ecCbHqLVof9yZcMoM31z9ur3tTYbSnr1WBqbGX97CbXcmp5H6qeMpyvx35B/86h/1h/1h/0/*)", | ||
| Network.REGTEST | ||
| ) | ||
| val descriptor2: Descriptor = Descriptor( | ||
| "tr(tprv8ZgxMBicQKsPf2qfrEygW6fdYseJDDrVnDv26PH5BHdvSuG6ecCbHqLVof9yZcMoM31z9ur3tTYbSnr1WBqbGX97CbXcmp5H6qeMpyvx35B/86h/1h/1h/0/*)", | ||
| Network.TESTNET | ||
| ) | ||
| val descriptor3: Descriptor = Descriptor( | ||
| "tr(tprv8ZgxMBicQKsPf2qfrEygW6fdYseJDDrVnDv26PH5BHdvSuG6ecCbHqLVof9yZcMoM31z9ur3tTYbSnr1WBqbGX97CbXcmp5H6qeMpyvx35B/86h/1h/1h/0/*)", | ||
|
||
| Network.TESTNET4 | ||
| ) | ||
| val descriptor4: Descriptor = Descriptor( | ||
| "tr(tprv8ZgxMBicQKsPf2qfrEygW6fdYseJDDrVnDv26PH5BHdvSuG6ecCbHqLVof9yZcMoM31z9ur3tTYbSnr1WBqbGX97CbXcmp5H6qeMpyvx35B/86h/1h/1h/0/*)", | ||
| Network.SIGNET | ||
| ) | ||
| val descriptor5: Descriptor = Descriptor( | ||
| "tr(xprv9s21ZrQH143K3LRcTnWpaCSYb75ic2rGuSgicmJhSVQSbfaKgPXfa8PhnYszgdcyWLoc8n1E2iHUnskjgGTAyCEpJYv7fqKxUcRNaVngA1V/86h/1h/1h/0/*)", | ||
| Network.BITCOIN | ||
| ) | ||
| } | ||
|
|
||
| @Test | ||
| fun `Create non-extended descriptors for all networks`() { | ||
| val descriptor1: Descriptor = Descriptor( | ||
| "tr(tprv8ZgxMBicQKsPf2qfrEygW6fdYseJDDrVnDv26PH5BHdvSuG6ecCbHqLVof9yZcMoM31z9ur3tTYbSnr1WBqbGX97CbXcmp5H6qeMpyvx35B/86h/1h/1h/0/0)", | ||
| Network.REGTEST | ||
| ) | ||
| val descriptor2: Descriptor = Descriptor( | ||
| "tr(tprv8ZgxMBicQKsPf2qfrEygW6fdYseJDDrVnDv26PH5BHdvSuG6ecCbHqLVof9yZcMoM31z9ur3tTYbSnr1WBqbGX97CbXcmp5H6qeMpyvx35B/86h/1h/1h/0/0)", | ||
| Network.TESTNET | ||
| ) | ||
| val descriptor3: Descriptor = Descriptor( | ||
| "tr(tprv8ZgxMBicQKsPf2qfrEygW6fdYseJDDrVnDv26PH5BHdvSuG6ecCbHqLVof9yZcMoM31z9ur3tTYbSnr1WBqbGX97CbXcmp5H6qeMpyvx35B/86h/1h/1h/0/0)", | ||
| Network.TESTNET4 | ||
| ) | ||
| val descriptor4: Descriptor = Descriptor( | ||
| "tr(tprv8ZgxMBicQKsPf2qfrEygW6fdYseJDDrVnDv26PH5BHdvSuG6ecCbHqLVof9yZcMoM31z9ur3tTYbSnr1WBqbGX97CbXcmp5H6qeMpyvx35B/86h/1h/1h/0/0)", | ||
| Network.SIGNET | ||
| ) | ||
| val descriptor5: Descriptor = Descriptor( | ||
| "tr(xprv9s21ZrQH143K3LRcTnWpaCSYb75ic2rGuSgicmJhSVQSbfaKgPXfa8PhnYszgdcyWLoc8n1E2iHUnskjgGTAyCEpJYv7fqKxUcRNaVngA1V/86h/1h/1h/0/0)", | ||
| Network.BITCOIN | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| @Nested | ||
| inner class Failure { | ||
| @Test | ||
| fun `Cannot create addr() descriptor`() { | ||
| assertFails { | ||
| val descriptor: Descriptor = Descriptor( | ||
| "addr(tb1qhjys9wxlfykmte7ftryptx975uqgd6kcm6a7z4)", | ||
| Network.TESTNET | ||
| ) | ||
| } | ||
| } | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is for WPKH I would think the path should be m/84 not m/86.
I am a bit surprised this worked.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same for the rest as well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ooops yep.
The reason why it works is that these bips are simply conventions. You can use any path you want. And this is what makes those strings dangerous to build manually; we see mistakes like this everywhere, even with very advanced bitcoin devs. This is why BDK developed the descriptor templates.
Good catch!