chainqueue

Blockchain transaction queue control
Info | Log | Files | Refs | LICENSE

test_tx_cache.py (1350B)


      1 # standard imports
      2 import unittest
      3 
      4 # external imports
      5 from hexathon import add_0x
      6 
      7 # local imports
      8 from chainqueue.db.models.tx import TxCache
      9 from chainqueue.error import NotLocalTxError
     10 from chainqueue.sql.state import *
     11 from chainqueue.sql.query import get_tx_cache
     12 
     13 # test imports
     14 from tests.chainqueue_base import TestTxBase
     15 
     16 class TestTxCache(TestTxBase):
     17 
     18     def test_mine(self):
     19         with self.assertRaises(NotLocalTxError):
     20             TxCache.set_final(self.tx_hash, 1024, 13, session=self.session)
     21 
     22         set_ready(self.chain_spec, self.tx_hash, session=self.session)
     23         set_reserved(self.chain_spec, self.tx_hash, session=self.session)
     24         set_sent(self.chain_spec, self.tx_hash, session=self.session)
     25         set_final(self.chain_spec, self.tx_hash, block=1024, session=self.session)
     26 
     27         with self.assertRaises(NotLocalTxError):
     28             TxCache.set_final(self.tx_hash, 1023, 13, session=self.session)
     29 
     30         TxCache.set_final(self.tx_hash, 1024, 13, session=self.session)
     31 
     32         self.session.commit()
     33 
     34         txc = TxCache.load(self.tx_hash)
     35         self.assertEqual(txc.tx_index, 13)
     36 
     37 
     38     def test_get(self):
     39         tx_extended_dict = get_tx_cache(self.chain_spec, self.tx_hash)
     40         self.assertEqual(tx_extended_dict['tx_hash'], add_0x(self.tx_hash))
     41 
     42 
     43 if __name__ == '__main__':
     44     unittest.main()