def test_cache_with_preload(self): tx_id = os.urandom(10).hex() tx_input = DBTxInput("address_string", "hash", 10, 10) tx_output = DBTxOutput("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, "teststore") self.assertTrue(tx_id in cache._cache) self.assertEqual(1, len(cache._cache[tx_id])) self.assertEqual(tx_xput, cache._cache[tx_id][0])
def test_cache_get_entries(self): tx_id = os.urandom(10).hex() tx_input = DBTxInput("address_string", "hash", 10, 10) tx_output = DBTxOutput("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, "teststore") entries = cache.get_entries(tx_id) self.assertEqual(1, len(entries)) self.assertEqual(tx_xput, entries[0])
def test_cache_delete(self): tx_id = os.urandom(10).hex() tx_input = DBTxInput("address_string", "hash", 10, 10) tx_output = DBTxOutput("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, "teststore") 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))
def test_cache_add(self): tx_id = os.urandom(10).hex() tx_input = DBTxInput("address_string", "hash", 10, 10) tx_output = DBTxOutput("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)]) # Check the caching layer has the entry. self.assertTrue(tx_id in cache._cache) self.assertEqual(1, len(cache._cache[tx_id])) self.assertEqual(tx_xput, cache._cache[tx_id][0]) # Check the store has the entry. entries = tx_store.get_entries(tx_id) self.assertEqual(1, len(entries)) self.assertEqual(tx_xput, entries[0])