def test_update_flags(self): cache = TxCache(self.store) tx_bytes_1 = bytes.fromhex(tx_hex_1) tx_hash_bytes_1 = bitcoinx.double_sha256(tx_bytes_1) tx_id_1 = bitcoinx.hash_to_hex_str(tx_hash_bytes_1) data = TxData(position=11) cache.add([(tx_id_1, data, tx_bytes_1, TxFlags.StateDispatched)]) self.assertTrue(cache.is_cached(tx_id_1)) entry = cache.get_entry(tx_id_1) self.assertEqual( TxFlags.HasByteData | TxFlags.HasPosition | TxFlags.StateDispatched, entry.flags) self.assertIsNotNone(entry.bytedata) cache.update_flags(tx_id_1, TxFlags.StateCleared, TxFlags.HasByteData | TxFlags.HasProofData) entry = cache.get_entry(tx_id_1) store_flags = self.store.get_flags(tx_id_1) expected_flags = TxFlags.HasByteData | TxFlags.HasPosition | TxFlags.StateCleared self.assertEqual( expected_flags, store_flags, f"{TxFlags.to_repr(expected_flags)} != {TxFlags.to_repr(store_flags)}" ) self.assertEqual( expected_flags, entry.flags, f"{TxFlags.to_repr(expected_flags)} != {TxFlags.to_repr(entry.flags)}" ) self.assertIsNotNone(entry.bytedata)
def test_get_height(self): cache = TxCache(self.store) bytedata_1 = bytes.fromhex(tx_hex_1) tx_hash_bytes_1 = bitcoinx.double_sha256(bytedata_1) tx_id_1 = bitcoinx.hash_to_hex_str(tx_hash_bytes_1) metadata_1 = TxData(height=11) cache.add([(tx_id_1, metadata_1, bytedata_1, TxFlags.StateCleared)]) self.assertEqual(11, cache.get_height(tx_id_1)) cache.update_flags(tx_id_1, TxFlags.StateSettled) self.assertEqual(11, cache.get_height(tx_id_1)) cache.update_flags(tx_id_1, TxFlags.StateReceived) self.assertIsNone(cache.get_height(tx_id_1))