Esempio n. 1
0
    def test_cache_with_preload(self):
        tx_id = os.urandom(10).hex()
        tx_input = wallet_database.TxInput("address_string", "hash", 10, 10)
        tx_output = wallet_database.TxOutput("address_string", 10, 10, False)

        for tx_xput, tx_store in ((tx_input, self.txin_store),
                                  (tx_output, self.txout_store)):
            tx_store.add_entries([(tx_id, tx_xput)])

            cache = wallet_database.TxXputCache(tx_store)
            self.assertTrue(tx_id in cache._cache)
            self.assertEqual(1, len(cache._cache[tx_id]))
            self.assertEqual(tx_xput, cache._cache[tx_id][0])
Esempio n. 2
0
    def test_cache_get_entries(self):
        tx_id = os.urandom(10).hex()
        tx_input = wallet_database.TxInput("address_string", "hash", 10, 10)
        tx_output = wallet_database.TxOutput("address_string", 10, 10, False)

        for tx_xput, tx_store in ((tx_input, self.txin_store),
                                  (tx_output, self.txout_store)):
            tx_store.add_entries([(tx_id, tx_xput)])
            cache = wallet_database.TxXputCache(tx_store)
            entries = cache.get_entries(tx_id)

            self.assertEqual(1, len(entries))
            self.assertEqual(tx_xput, entries[0])
Esempio n. 3
0
 def test_pack_unpack(self):
     address_string = "address_string1"
     prevout_tx_hash = "prevout_tx_hash1"
     prevout_n = 20
     amount = 5555
     txin1 = wallet_database.TxInput(address_string, prevout_tx_hash,
                                     prevout_n, amount)
     packed_raw = self.store._pack_value(txin1)
     address_string2, prevout_tx_hash2, prevout_n2, amount2 = self.store._unpack_value(
         packed_raw)
     self.assertEqual(txin1.address_string, address_string2)
     self.assertEqual(txin1.prevout_tx_hash, prevout_tx_hash2)
     self.assertEqual(txin1.prevout_n, prevout_n2)
     self.assertEqual(txin1.amount, amount2)
Esempio n. 4
0
    def test_cache_delete(self):
        tx_id = os.urandom(10).hex()
        tx_input = wallet_database.TxInput("address_string", "hash", 10, 10)
        tx_output = wallet_database.TxOutput("address_string", 10, 10, False)

        for tx_xput, tx_store in ((tx_input, self.txin_store),
                                  (tx_output, self.txout_store)):
            cache = wallet_database.TxXputCache(tx_store)
            cache.add_entries([(tx_id, tx_xput)])
            cache.delete_entries([(tx_id, tx_xput)])

            # Check the caching layer no longer has the entry.
            self.assertEqual(0, len(cache._cache[tx_id]))

            # Check the store no longer has the entry.
            entries = tx_store.get_entries(tx_id)
            self.assertEqual(0, len(entries))