2021-04-02 14:02:22 +02:00
|
|
|
# standard imports
|
|
|
|
import unittest
|
|
|
|
|
2021-05-28 11:13:01 +02:00
|
|
|
# external imports
|
|
|
|
from hexathon import add_0x
|
|
|
|
|
2021-04-02 14:02:22 +02:00
|
|
|
# local imports
|
|
|
|
from chainqueue.db.models.tx import TxCache
|
|
|
|
from chainqueue.error import NotLocalTxError
|
2021-05-28 11:13:01 +02:00
|
|
|
from chainqueue.sql.state import *
|
|
|
|
from chainqueue.sql.query import get_tx_cache
|
2021-04-02 14:02:22 +02:00
|
|
|
|
|
|
|
# test imports
|
2021-08-26 10:05:56 +02:00
|
|
|
from tests.chainqueue_base import TestTxBase
|
2021-04-02 14:02:22 +02:00
|
|
|
|
|
|
|
class TestTxCache(TestTxBase):
|
|
|
|
|
|
|
|
def test_mine(self):
|
|
|
|
with self.assertRaises(NotLocalTxError):
|
|
|
|
TxCache.set_final(self.tx_hash, 1024, 13, session=self.session)
|
|
|
|
|
2021-05-28 11:13:01 +02:00
|
|
|
set_ready(self.chain_spec, self.tx_hash, session=self.session)
|
|
|
|
set_reserved(self.chain_spec, self.tx_hash, session=self.session)
|
|
|
|
set_sent(self.chain_spec, self.tx_hash, session=self.session)
|
|
|
|
set_final(self.chain_spec, self.tx_hash, block=1024, session=self.session)
|
2021-04-02 14:02:22 +02:00
|
|
|
|
|
|
|
with self.assertRaises(NotLocalTxError):
|
|
|
|
TxCache.set_final(self.tx_hash, 1023, 13, session=self.session)
|
|
|
|
|
|
|
|
TxCache.set_final(self.tx_hash, 1024, 13, session=self.session)
|
|
|
|
|
|
|
|
self.session.commit()
|
|
|
|
|
|
|
|
txc = TxCache.load(self.tx_hash)
|
|
|
|
self.assertEqual(txc.tx_index, 13)
|
|
|
|
|
|
|
|
|
2021-04-02 14:45:05 +02:00
|
|
|
def test_get(self):
|
|
|
|
tx_extended_dict = get_tx_cache(self.chain_spec, self.tx_hash)
|
2021-05-28 11:13:01 +02:00
|
|
|
self.assertEqual(tx_extended_dict['tx_hash'], add_0x(self.tx_hash))
|
2021-04-02 14:45:05 +02:00
|
|
|
|
|
|
|
|
2021-04-02 14:02:22 +02:00
|
|
|
if __name__ == '__main__':
|
|
|
|
unittest.main()
|