2021-12-07 10:25:42 -05:00
|
|
|
import bdkpython as bdk
|
2022-05-11 16:02:49 -04:00
|
|
|
import unittest
|
2021-12-07 10:25:42 -05:00
|
|
|
|
2022-05-11 16:09:59 -04:00
|
|
|
descriptor = "wpkh([c258d2e4/84h/1h/0h]tpubDDYkZojQFQjht8Tm4jsS3iuEmKjTiEGjG6KnuFNKKJb5A6ZUCUZKdvLdSDWofKi4ToRCwb9poe1XdqfUnP4jaJjCB2Zwv11ZLgSbnZSNecE/0/*)"
|
2022-05-06 15:24:41 -04:00
|
|
|
db_config = bdk.DatabaseConfig.MEMORY()
|
2022-05-11 16:02:49 -04:00
|
|
|
blockchain_config = bdk.BlockchainConfig.ELECTRUM(
|
|
|
|
bdk.ElectrumConfig(
|
|
|
|
"ssl://electrum.blockstream.info:60002",
|
|
|
|
None,
|
|
|
|
5,
|
|
|
|
None,
|
|
|
|
100
|
|
|
|
)
|
2021-12-07 10:25:42 -05:00
|
|
|
)
|
2022-05-11 16:02:49 -04:00
|
|
|
blockchain = bdk.Blockchain(blockchain_config)
|
2021-12-07 10:25:42 -05:00
|
|
|
|
|
|
|
|
2022-05-11 16:02:49 -04:00
|
|
|
class TestSimpleBip84Wallet(unittest.TestCase):
|
|
|
|
|
|
|
|
def test_address_bip84_testnet(self):
|
|
|
|
wallet = bdk.Wallet(
|
|
|
|
descriptor=descriptor,
|
|
|
|
change_descriptor=None,
|
|
|
|
network=bdk.Network.TESTNET,
|
|
|
|
database_config=db_config
|
|
|
|
)
|
2022-06-23 15:21:48 -04:00
|
|
|
address_info = wallet.get_address(bdk.AddressIndex.LAST_UNUSED)
|
|
|
|
address = address_info.address
|
2022-05-11 16:02:49 -04:00
|
|
|
# print(f"New address is {address}")
|
2022-05-11 16:09:59 -04:00
|
|
|
assert address == "tb1qzg4mckdh50nwdm9hkzq06528rsu73hjxxzem3e", f"Wrong address {address}, should be tb1qzg4mckdh50nwdm9hkzq06528rsu73hjxxzem3e"
|
2021-12-07 10:25:42 -05:00
|
|
|
|
2022-05-11 16:02:49 -04:00
|
|
|
def test_wallet_balance(self):
|
|
|
|
wallet = bdk.Wallet(
|
|
|
|
descriptor=descriptor,
|
|
|
|
change_descriptor=None,
|
|
|
|
network=bdk.Network.TESTNET,
|
|
|
|
database_config=db_config,
|
|
|
|
)
|
|
|
|
wallet.sync(blockchain, None)
|
|
|
|
balance = wallet.get_balance()
|
2022-09-22 11:02:41 -04:00
|
|
|
# print(f"Balance is {balance.total} sat")
|
|
|
|
assert balance.total > 0, "Balance is 0, send testnet coins to tb1qzg4mckdh50nwdm9hkzq06528rsu73hjxxzem3e"
|
2022-05-06 15:24:41 -04:00
|
|
|
|
|
|
|
|
2022-05-11 16:02:49 -04:00
|
|
|
if __name__ == '__main__':
|
|
|
|
unittest.main()
|