Beispiel #1
0
    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])
Beispiel #2
0
 def test_pack_unpack(self):
     address_string = "address_string1"
     prevout_tx_hash = "prevout_tx_hash1"
     prev_idx = 20
     amount = 5555
     txin1 = DBTxInput(address_string, prevout_tx_hash, prev_idx, amount)
     packed_raw = self.store._pack_value(txin1)
     address_string2, prevout_tx_hash2, prev_idx2, 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.prev_idx, prev_idx2)
     self.assertEqual(txin1.amount, amount2)
Beispiel #3
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])
Beispiel #4
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])