adb: change API of util.TxMinedInfo: height() is now always SPV-ed
This commit is contained in:
@@ -80,7 +80,7 @@ class TestWalletPaymentRequests(ElectrumTestCase):
|
||||
self.assertEqual(PR_UNCONFIRMED, wallet1.get_invoice_status(pr))
|
||||
# tx gets mined
|
||||
wallet1.db.put('stored_height', 1010)
|
||||
tx_info = TxMinedInfo(height=1001,
|
||||
tx_info = TxMinedInfo(_height=1001,
|
||||
timestamp=pr.get_time() + 100,
|
||||
txpos=1,
|
||||
header_hash="01"*32)
|
||||
@@ -111,7 +111,7 @@ class TestWalletPaymentRequests(ElectrumTestCase):
|
||||
self.assertEqual(PR_UNCONFIRMED, wallet1.get_invoice_status(pr))
|
||||
# tx gets mined
|
||||
wallet1.db.put('stored_height', 1010)
|
||||
tx_info = TxMinedInfo(height=1001,
|
||||
tx_info = TxMinedInfo(_height=1001,
|
||||
timestamp=pr.get_time() + 100,
|
||||
txpos=1,
|
||||
header_hash="01"*32)
|
||||
@@ -141,7 +141,7 @@ class TestWalletPaymentRequests(ElectrumTestCase):
|
||||
wallet1.adb.receive_tx_callback(tx, tx_height=TX_HEIGHT_UNCONFIRMED)
|
||||
self.assertEqual(PR_UNCONFIRMED, wallet1.get_invoice_status(pr))
|
||||
# tx mined in the past (before invoice creation)
|
||||
tx_info = TxMinedInfo(height=990,
|
||||
tx_info = TxMinedInfo(_height=990,
|
||||
timestamp=pr.get_time() + 100,
|
||||
txpos=1,
|
||||
header_hash="01" * 32)
|
||||
|
||||
@@ -2,6 +2,8 @@ import unittest
|
||||
import logging
|
||||
from unittest import mock
|
||||
import asyncio
|
||||
import dataclasses
|
||||
|
||||
from aiorpcx import timeout_after
|
||||
|
||||
from electrum import storage, bitcoin, keystore, wallet
|
||||
@@ -152,7 +154,7 @@ class TestTxBatcher(ElectrumTestCase):
|
||||
# tx1 gets confirmed, tx2 gets removed
|
||||
wallet.adb.receive_tx_callback(tx1, tx_height=1)
|
||||
tx_mined_status = wallet.adb.get_tx_height(tx1.txid())
|
||||
wallet.adb.add_verified_tx(tx1.txid(), tx_mined_status._replace(conf=1))
|
||||
wallet.adb.add_verified_tx(tx1.txid(), dataclasses.replace(tx_mined_status, conf=1))
|
||||
assert wallet.adb.get_transaction(tx1.txid()) is not None
|
||||
assert wallet.adb.get_transaction(tx1_prime.txid()) is None
|
||||
# txbatcher creates tx2
|
||||
@@ -195,7 +197,7 @@ class TestTxBatcher(ElectrumTestCase):
|
||||
# tx1 gets confirmed
|
||||
wallet.adb.receive_tx_callback(tx1, tx_height=1)
|
||||
tx_mined_status = wallet.adb.get_tx_height(tx1.txid())
|
||||
wallet.adb.add_verified_tx(tx1.txid(), tx_mined_status._replace(conf=1))
|
||||
wallet.adb.add_verified_tx(tx1.txid(), dataclasses.replace(tx_mined_status, conf=1))
|
||||
|
||||
tx2 = await self.network.next_tx()
|
||||
assert len(tx2.outputs()) == 2
|
||||
@@ -209,6 +211,8 @@ class TestTxBatcher(ElectrumTestCase):
|
||||
wallet = self._create_wallet()
|
||||
wallet.adb.db.transactions[SWAPDATA.funding_txid] = tx = Transaction(SWAP_FUNDING_TX)
|
||||
wallet.adb.receive_tx_callback(tx, tx_height=1)
|
||||
tx_mined_status = wallet.adb.get_tx_height(tx.txid())
|
||||
wallet.adb.add_verified_tx(tx.txid(), dataclasses.replace(tx_mined_status, conf=1))
|
||||
wallet.txbatcher.add_sweep_input('default', SWAP_SWEEP_INFO)
|
||||
tx = await self.network.next_tx()
|
||||
txid = tx.txid()
|
||||
|
||||
@@ -164,7 +164,7 @@ class FakeADB:
|
||||
def get_tx_height(self, txid):
|
||||
# because we use a current timestamp, and history is empty,
|
||||
# FxThread.history_rate will use spot prices
|
||||
return TxMinedInfo(height=10, conf=10, timestamp=int(time.time()), header_hash='def')
|
||||
return TxMinedInfo(_height=10, conf=10, timestamp=int(time.time()), header_hash='def')
|
||||
|
||||
class FakeWallet:
|
||||
def __init__(self, fiat_value):
|
||||
|
||||
@@ -2924,7 +2924,7 @@ class TestWalletSending(ElectrumTestCase):
|
||||
assert payment_txid
|
||||
# save payment_tx as LOCAL and UNSIGNED
|
||||
wallet.adb.add_transaction(payment_tx)
|
||||
self.assertEqual(TX_HEIGHT_LOCAL, wallet.adb.get_tx_height(payment_txid).height)
|
||||
self.assertEqual(TX_HEIGHT_LOCAL, wallet.adb.get_tx_height(payment_txid).height())
|
||||
self.assertEqual(1, len(wallet.get_spendable_coins(nonlocal_only=True)))
|
||||
self.assertEqual(2, len(wallet.get_spendable_coins(nonlocal_only=False)))
|
||||
# transition payment_tx to mempool (but it is still unsigned!)
|
||||
@@ -2937,13 +2937,13 @@ class TestWalletSending(ElectrumTestCase):
|
||||
# but the wallet db does not yet have the corresponding full tx.
|
||||
# In such cases, we instead want the txid to be considered LOCAL.
|
||||
wallet.adb.receive_tx_callback(payment_tx, tx_height=TX_HEIGHT_UNCONFIRMED)
|
||||
self.assertEqual(TX_HEIGHT_LOCAL, wallet.adb.get_tx_height(payment_txid).height)
|
||||
self.assertEqual(TX_HEIGHT_LOCAL, wallet.adb.get_tx_height(payment_txid).height())
|
||||
self.assertEqual(1, len(wallet.get_spendable_coins(nonlocal_only=True)))
|
||||
self.assertEqual(2, len(wallet.get_spendable_coins(nonlocal_only=False)))
|
||||
# wallet gets signed tx (e.g. from network). payment_tx is now considered to be in mempool
|
||||
wallet.sign_transaction(payment_tx, password=None)
|
||||
wallet.adb.receive_tx_callback(payment_tx, tx_height=TX_HEIGHT_UNCONFIRMED)
|
||||
self.assertEqual(TX_HEIGHT_UNCONFIRMED, wallet.adb.get_tx_height(payment_txid).height)
|
||||
self.assertEqual(TX_HEIGHT_UNCONFIRMED, wallet.adb.get_tx_height(payment_txid).height())
|
||||
self.assertEqual(2, len(wallet.get_spendable_coins(nonlocal_only=True)))
|
||||
self.assertEqual(2, len(wallet.get_spendable_coins(nonlocal_only=False)))
|
||||
|
||||
@@ -2962,10 +2962,10 @@ class TestWalletSending(ElectrumTestCase):
|
||||
assert payment_txid
|
||||
# save payment_tx as LOCAL and UNSIGNED
|
||||
wallet.adb.add_transaction(payment_tx)
|
||||
self.assertEqual(TX_HEIGHT_LOCAL, wallet.adb.get_tx_height(payment_txid).height)
|
||||
self.assertEqual(TX_HEIGHT_LOCAL, wallet.adb.get_tx_height(payment_txid).height())
|
||||
# mark payment_tx as future
|
||||
wallet.adb.set_future_tx(payment_txid, wanted_height=300)
|
||||
self.assertEqual(TX_HEIGHT_FUTURE, wallet.adb.get_tx_height(payment_txid).height)
|
||||
self.assertEqual(TX_HEIGHT_FUTURE, wallet.adb.get_tx_height(payment_txid).height())
|
||||
|
||||
@mock.patch.object(wallet.Abstract_Wallet, 'save_db')
|
||||
async def test_imported_wallet_usechange_off(self, mock_save_db):
|
||||
@@ -4458,7 +4458,7 @@ class TestWalletHistory_HelperFns(ElectrumTestCase):
|
||||
wallet1.adb.add_transaction(tx)
|
||||
# let's see if the calculated feerate correct:
|
||||
self.assertEqual((3, 'Local [26.3 sat/vB]'),
|
||||
wallet1.get_tx_status(tx.txid(), TxMinedInfo(height=TX_HEIGHT_LOCAL, conf=0)))
|
||||
wallet1.get_tx_status(tx.txid(), TxMinedInfo(_height=TX_HEIGHT_LOCAL, conf=0)))
|
||||
|
||||
@mock.patch.object(wallet.Abstract_Wallet, 'save_db')
|
||||
async def test_get_tx_status_feerate_for_local_2of3_multisig_signed_tx(self, mock_save_db):
|
||||
@@ -4481,7 +4481,7 @@ class TestWalletHistory_HelperFns(ElectrumTestCase):
|
||||
wallet1.adb.add_transaction(tx)
|
||||
# let's see if the calculated feerate correct:
|
||||
self.assertEqual((3, 'Local [26.3 sat/vB]'),
|
||||
wallet1.get_tx_status(tx.txid(), TxMinedInfo(height=TX_HEIGHT_LOCAL, conf=0)))
|
||||
wallet1.get_tx_status(tx.txid(), TxMinedInfo(_height=TX_HEIGHT_LOCAL, conf=0)))
|
||||
|
||||
|
||||
class TestImportedWallet(ElectrumTestCase):
|
||||
|
||||
Reference in New Issue
Block a user