Skip to content

Commit

Permalink
Fix: Compare correct UTC times
Browse files Browse the repository at this point in the history
  • Loading branch information
Cryp Toon committed May 14, 2024
1 parent fc64228 commit ad6e32c
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 2 deletions.
4 changes: 2 additions & 2 deletions bitcoinlib/wallets.py
Original file line number Diff line number Diff line change
Expand Up @@ -3678,9 +3678,9 @@ def transactions_remove_unconfirmed(self, hours_old=0, account_id=None, network=
:return:
"""
txs = self.transactions(account_id=account_id, network=network)
t = datetime.now() - timedelta(hours=hours_old)
td = datetime.utcnow() - timedelta(hours=hours_old)
for tx in txs:
if not tx.confirmations and tx.date < t:
if not tx.confirmations and tx.date < td:
self.transaction_delete(tx.txid)

def _objects_by_key_id(self, key_id):
Expand Down
50 changes: 50 additions & 0 deletions tests/test_wallets.py
Original file line number Diff line number Diff line change
Expand Up @@ -2896,3 +2896,53 @@ def test_wallet_transactions_bumpfee(self):
t = w.send_to('blt1qm89pcm4392vj93q9s2ft8saqzm4paruzj95a83', 199900000, fee=100000,
broadcast=True)
self.assertRaisesRegex(TransactionError, "Not enough unspent inputs found for transaction", t.bumpfee)

def test_wallet_transaction_remove_unconfirmed(self):
pkm = 'monitor orphan turtle stage december special'
w = wallet_create_or_open("wallet_remove_old_unconfirmed_transactions", keys=pkm,
network='bitcoinlib_test', db_uri=self.database_uri)
w.get_keys(number_of_keys=4)
utxos = [
{
"address": "blt1q4dugy6d7qz7226mk6ast3nz23z7ctd80mymle3",
"script": "",
"confirmations": 2,
"output_n": 1,
"txid": "e6192f6dafa689ac8889b466d2dd3eb2bb55b76c7305b4a2a6a31de6c9991aeb",
"value": 1829810
},
{
"address": "blt1q82l3c2d37yjxe0r9a7qn9v7c9y7hnaxp398kc0",
"script": "",
"confirmations": 0,
"output_n": 0,
"txid": "5891c85595193d0565fe418d5c5192c1297eafbef36c28bcab2ac3341ee68e71",
"value": 2389180
},
{
"address": "blt1qdtez8t797m74ar8wuvedw50jmycefwstfk8ulz",
"script": "",
"confirmations": 100,
"output_n": 0,
"txid": "7e87a63a0233615a5719a782a0b1c85de521151d8648e7d7244155a2caf7dd47",
"value": 99389180
},
{
"address": "blt1qdtez8t797m74ar8wuvedw50jmycefwstfk8ulz",
"script": "",
"confirmations": 100,
"output_n": 0,
"txid": "a4ef4aef09839a681419b80d5b6228b0089af39a4483896c9ac106192ac1ec34",
"value": 838180
},
]
w.utxos_update(utxos=utxos)
w.send_to('blt1qvtaw9m9ut96ykt2n2kdra8jpv3m5z2s8krqwsv', 50000, broadcast=True)
self.assertEqual(len(w.utxos()), 5)
self.assertEqual(w.balance(), 104441651)
w.transactions_remove_unconfirmed(1)
self.assertEqual(len(w.utxos()), 5)
self.assertEqual(w.balance(), 104441651)
w.transactions_remove_unconfirmed(0)
self.assertEqual(len(w.utxos()), 3)
self.assertEqual(w.balance(), 102057170)

0 comments on commit ad6e32c

Please sign in to comment.