def test_get_tx_status_maturity(self) -> None: from electrumsv.gui.qt.history_list import TxStatus, get_tx_status account = MockWhatever() def _get_utxo(tx_hash: bytes, output_index: int) -> Optional[UTXO]: return UTXO(100, b'', 0, tx_hash, output_index, 1000, 1, None, False, 0) def _have_transaction_data(tx_hash: bytes) -> bool: return True def _get_transaction_metadata(tx_hash: bytes): return TxData(position=0) account.get_transaction_metadata = _get_transaction_metadata account.have_transaction_data = _have_transaction_data account.get_utxo = _get_utxo local_height = 1000 def _get_local_height() -> int: return local_height account._wallet = MockWhatever() account._wallet.get_local_height = _get_local_height timestamp = confs = 1 # Ignored tx_hash = os.urandom(32) height = (local_height - COINBASE_MATURITY) + 1 status = get_tx_status(account, tx_hash, height, confs, timestamp) self.assertEqual(TxStatus.UNMATURED, status) height = (local_height - COINBASE_MATURITY) status = get_tx_status(account, tx_hash, height, confs, timestamp) self.assertEqual(TxStatus.FINAL, status)
def test_get_tx_status_maturity(self) -> None: from electrumsv.gui.qt.history_list import TxStatus, get_tx_status wallet = MockWhatever() def _is_coinbase_transaction(tx_id: str) -> bool: return True def _have_transaction_data(tx_hash: str) -> bool: return True wallet.have_transaction_data = _have_transaction_data wallet.is_coinbase_transaction = _is_coinbase_transaction local_height = 1000 def _get_local_height() -> int: return local_height wallet.get_local_height = _get_local_height timestamp = confs = 1 # Ignored height = (local_height - COINBASE_MATURITY) + 1 status = get_tx_status(wallet, "...", height, confs, timestamp) self.assertEqual(TxStatus.UNMATURED, status) height = (local_height - COINBASE_MATURITY) status = get_tx_status(wallet, "...", height, confs, timestamp) self.assertEqual(TxStatus.FINAL, status)
def test_get_tx_status(self) -> None: from electrumsv.gui.qt.history_list import TxStatus, get_tx_status wallet = MockWhatever() tx = MockWhatever() def _is_coinbase() -> bool: return False tx.is_coinbase = _is_coinbase def _get_transaction(tx_hash: str) -> MockWhatever: return tx wallet.get_transaction = _get_transaction local_height = 1000 def _get_local_height() -> int: return local_height wallet.get_local_height = _get_local_height timestamp = 1 # Ignored height = -1 # Legacy unconfirmed parent. confs = 0 status = get_tx_status(wallet, "...", height, confs, timestamp) self.assertEqual(TxStatus.UNCONFIRMED, status) height = 0 confs = 0 status = get_tx_status(wallet, "...", height, confs, timestamp) self.assertEqual(TxStatus.UNCONFIRMED, status) height = local_height + 1 confs = get_confs_from_height(local_height, height) status = get_tx_status(wallet, "...", height, confs, timestamp) self.assertEqual(TxStatus.UNVERIFIED, status) height = local_height confs = get_confs_from_height(local_height, height) status = get_tx_status(wallet, "...", height, confs, timestamp) self.assertEqual(TxStatus.FINAL, status) height = local_height - 1 confs = get_confs_from_height(local_height, height) status = get_tx_status(wallet, "...", height, confs, timestamp) self.assertEqual(TxStatus.FINAL, status)
def test_get_tx_status(self) -> None: from electrumsv.gui.qt.history_list import TxStatus, get_tx_status account = MockWhatever() def _get_utxo(tx_hash: bytes, output_index: int) -> Optional[UTXO]: return None def _have_transaction_data(tx_hash: bytes) -> bool: return True def _get_transaction_metadata(tx_hash: bytes): return TxData(position=1) account.get_transaction_metadata = _get_transaction_metadata account.have_transaction_data = _have_transaction_data account.get_utxo = _get_utxo local_height = 1000 def _get_local_height() -> int: return local_height account._wallet = MockWhatever() account._wallet.get_local_height = _get_local_height timestamp = 1 # Ignored tx_hash = os.urandom(32) height = -1 # Legacy unconfirmed parent. confs = 0 status = get_tx_status(account, tx_hash, height, confs, timestamp) self.assertEqual(TxStatus.UNCONFIRMED, status) height = 0 confs = 0 status = get_tx_status(account, tx_hash, height, confs, timestamp) self.assertEqual(TxStatus.UNCONFIRMED, status) height = local_height + 1 confs = get_confs_from_height(local_height, height) status = get_tx_status(account, tx_hash, height, confs, timestamp) self.assertEqual(TxStatus.UNVERIFIED, status) height = local_height confs = get_confs_from_height(local_height, height) status = get_tx_status(account, tx_hash, height, confs, timestamp) self.assertEqual(TxStatus.FINAL, status) height = local_height - 1 confs = get_confs_from_height(local_height, height) status = get_tx_status(account, tx_hash, height, confs, timestamp) self.assertEqual(TxStatus.FINAL, status)