2023-10-27 14:13:44 -04:00
|
|
|
import bdkpython as bdk
|
|
|
|
import unittest
|
|
|
|
|
|
|
|
class TestLiveWallet(unittest.TestCase):
|
|
|
|
|
|
|
|
def test_synced_balance(self):
|
|
|
|
descriptor: bdk.Descriptor = bdk.Descriptor(
|
2023-12-07 13:24:39 -06:00
|
|
|
"wpkh(tprv8ZgxMBicQKsPf2qfrEygW6fdYseJDDrVnDv26PH5BHdvSuG6ecCbHqLVof9yZcMoM31z9ur3tTYbSnr1WBqbGX97CbXcmp5H6qeMpyvx35B/84h/1h/0h/0/*)",
|
2023-10-27 14:13:44 -04:00
|
|
|
bdk.Network.TESTNET
|
|
|
|
)
|
2024-02-01 10:34:59 -05:00
|
|
|
# wallet: bdk.Wallet = bdk.Wallet.new_no_persist(
|
|
|
|
# descriptor,
|
|
|
|
# None,
|
|
|
|
# bdk.Network.TESTNET
|
|
|
|
# )
|
|
|
|
# esploraClient: bdk.EsploraClient = bdk.EsploraClient(url = "https://mempool.space/testnet/api")
|
|
|
|
# update = esploraClient.full_scan(
|
|
|
|
# wallet = wallet,
|
|
|
|
# stop_gap = 10,
|
|
|
|
# parallel_requests = 1
|
|
|
|
# )
|
|
|
|
# wallet.apply_update(update)
|
|
|
|
#
|
|
|
|
# self.assertGreater(wallet.get_balance().total, 0)
|
|
|
|
#
|
|
|
|
# print(f"Transactions count: {len(wallet.transactions())}")
|
|
|
|
# transactions = wallet.transactions()[:3]
|
|
|
|
# for tx in transactions:
|
|
|
|
# sent_and_received = wallet.sent_and_received(tx)
|
|
|
|
# print(f"Transaction: {tx.txid()}")
|
|
|
|
# print(f"Sent {sent_and_received.sent}")
|
|
|
|
# print(f"Received {sent_and_received.received}")
|
2023-12-07 13:24:39 -06:00
|
|
|
|
|
|
|
|
2023-11-17 13:25:33 -05:00
|
|
|
def test_broadcast_transaction(self):
|
|
|
|
descriptor: bdk.Descriptor = bdk.Descriptor(
|
|
|
|
"wpkh(tprv8ZgxMBicQKsPf2qfrEygW6fdYseJDDrVnDv26PH5BHdvSuG6ecCbHqLVof9yZcMoM31z9ur3tTYbSnr1WBqbGX97CbXcmp5H6qeMpyvx35B/84h/1h/0h/0/*)",
|
|
|
|
bdk.Network.TESTNET
|
|
|
|
)
|
2024-02-01 10:34:59 -05:00
|
|
|
# wallet: bdk.Wallet = bdk.Wallet.new_no_persist(
|
|
|
|
# descriptor,
|
|
|
|
# None,
|
|
|
|
# bdk.Network.TESTNET
|
|
|
|
# )
|
|
|
|
# esploraClient: bdk.EsploraClient = bdk.EsploraClient(url = "https://mempool.space/testnet/api")
|
|
|
|
# update = esploraClient.full_scan(
|
|
|
|
# wallet = wallet,
|
|
|
|
# stop_gap = 10,
|
|
|
|
# parallel_requests = 1
|
|
|
|
# )
|
|
|
|
# wallet.apply_update(update)
|
|
|
|
#
|
|
|
|
# self.assertGreater(wallet.get_balance().total, 0)
|
|
|
|
#
|
|
|
|
# recipient = bdk.Address(
|
|
|
|
# address = "tb1qrnfslnrve9uncz9pzpvf83k3ukz22ljgees989",
|
|
|
|
# network = bdk.Network.TESTNET
|
|
|
|
# )
|
|
|
|
#
|
|
|
|
# psbt = bdk.TxBuilder().add_recipient(script=recipient.script_pubkey(), amount=4200).fee_rate(fee_rate=bdk.FeeRate.from_sat_per_vb(2.0)).finish(wallet)
|
|
|
|
# # print(psbt.serialize())
|
|
|
|
# self.assertTrue(psbt.serialize().startswith("cHNi"), "The PSBT should start with cHNi")
|
|
|
|
#
|
|
|
|
# walletDidSign = wallet.sign(psbt)
|
|
|
|
# self.assertTrue(walletDidSign)
|
|
|
|
# tx = psbt.extract_tx()
|
|
|
|
# print(f"Transaction Id: {tx.txid}")
|
|
|
|
# fee = wallet.calculate_fee(tx)
|
|
|
|
# print(f"Transaction Fee: {fee}")
|
|
|
|
# fee_rate = wallet.calculate_fee_rate(tx)
|
|
|
|
# print(f"Transaction Fee Rate: {fee_rate.as_sat_per_vb()} sat/vB")
|
|
|
|
#
|
|
|
|
# esploraClient.broadcast(tx)
|
2023-11-17 13:25:33 -05:00
|
|
|
|
2023-10-27 14:13:44 -04:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
unittest.main()
|