Example #1
0
 def test_pack_unpack(self):
     address_string1 = "12345"
     out_tx_n1 = 20
     amount1 = 5555
     is_coinbase1 = False
     txout1 = DBTxOutput(address_string1, out_tx_n1, amount1, is_coinbase1)
     packed_raw = self.store._pack_value(txout1)
     txout2 = self.store._unpack_value(packed_raw)
     self.assertEqual(txout1.address_string, txout2.address_string)
     self.assertEqual(txout1.out_tx_n, txout2.out_tx_n)
     self.assertEqual(txout1.amount, txout2.amount)
     self.assertEqual(txout1.is_coinbase, txout2.is_coinbase)
Example #2
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])
Example #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])
Example #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])