def test_get_transaction_after_metadata(self): # Getting an entry for a settled transaction should update from metadata-only to full. bytedata_set = os.urandom(10) tx_hash = bitcoinx.double_sha256(bytedata_set) metadata_set = TxData(height=1, fee=2, position=None, date_added=1, date_updated=1) with SynchronousWriter() as writer: self.store.create([(tx_hash, metadata_set, bytedata_set, TxFlags.StateSettled, None)], completion_callback=writer.get_callback()) assert writer.succeeded() cache = TransactionCache(self.store) metadata_get = cache.get_metadata(tx_hash) assert metadata_get is not None # Initial priming of cache will be only metadata. cached_entry_1 = cache.get_cached_entry(tx_hash) assert cached_entry_1.is_metadata_cached() assert not cached_entry_1.is_bytedata_cached() # Entry request will hit the database. entry = cache.get_entry(tx_hash) assert entry.is_metadata_cached() assert entry.is_bytedata_cached() cached_entry_2 = cache.get_cached_entry(tx_hash) assert entry == cached_entry_2
def test_get_metadata(self): # Full entry caching for non-settled transactions, otherwise only metadata. bytedata_set_1 = os.urandom(10) tx_hash_1 = bitcoinx.double_sha256(bytedata_set_1) metadata_set_1 = TxData(height=None, fee=2, position=None, date_added=1, date_updated=1) bytedata_set_2 = os.urandom(10) tx_hash_2 = bitcoinx.double_sha256(bytedata_set_2) metadata_set_2 = TxData(height=1, fee=2, position=10, date_added=1, date_updated=1) with SynchronousWriter() as writer: self.store.create([ (tx_hash_1, metadata_set_1, bytedata_set_1, TxFlags.Unset, None), (tx_hash_2, metadata_set_2, bytedata_set_2, TxFlags.StateSettled, None), ], completion_callback=writer.get_callback()) assert writer.succeeded() cache = TransactionCache(self.store) metadata_get = cache.get_metadata(tx_hash_1) assert metadata_set_1.height == metadata_get.height assert metadata_set_1.fee == metadata_get.fee assert metadata_set_1.position == metadata_get.position metadata_get = cache.get_metadata(tx_hash_2) assert metadata_set_2.height == metadata_get.height assert metadata_set_2.fee == metadata_get.fee assert metadata_set_2.position == metadata_get.position entry = cache.get_cached_entry(tx_hash_1) assert entry.is_metadata_cached() assert entry.is_bytedata_cached() entry = cache.get_cached_entry(tx_hash_2) assert entry.is_metadata_cached() assert not entry.is_bytedata_cached()