Exemple #1
0
    def test_get_metadata(self):
        # Full entry caching for non-settled transactions, otherwise only metadata.
        bytedata_set_1 = bytes.fromhex(tx_hex_1)
        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 = bytes.fromhex(tx_hex_2)
        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._cache[tx_hash_1]
        assert cache.have_transaction_data_cached(tx_hash_1)

        entry = cache._cache[tx_hash_2]
        assert not cache.have_transaction_data_cached(tx_hash_2)
Exemple #2
0
    def test_get_transaction_after_metadata(self):
        # Getting an entry for a settled transaction should update from metadata-only to full.
        bytedata_set = bytes.fromhex(tx_hex_1)
        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._cache[tx_hash]
        assert not cache.have_transaction_data_cached(tx_hash)

        # Entry request will hit the database.
        entry = cache.get_entry(tx_hash)
        assert cache.have_transaction_data_cached(tx_hash)

        cached_entry_2 = cache._cache[tx_hash]
        assert entry.metadata == cached_entry_2.metadata
        assert entry.flags == cached_entry_2.flags