Add filter tests
This commit is contained in:
@@ -10,10 +10,12 @@ import hashlib
|
||||
from chainlib.chain import ChainSpec
|
||||
from chainqueue.cache import CacheTokenTx
|
||||
from chainlib.error import RPCException
|
||||
from chainlib.status import Status as TxStatus
|
||||
|
||||
# local imports
|
||||
from chaind.adapters.new import ChaindFsAdapter
|
||||
from chaind.driver import QueueDriver
|
||||
from chaind.filter import StateFilter
|
||||
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
logg = logging.getLogger()
|
||||
@@ -26,7 +28,7 @@ class MockCacheAdapter(CacheTokenTx):
|
||||
h = hashlib.sha256()
|
||||
h.update(v.encode('utf-8'))
|
||||
z = h.digest()
|
||||
tx.tx_hash = z.hex()
|
||||
tx.hash = z.hex()
|
||||
return tx
|
||||
|
||||
|
||||
@@ -46,6 +48,14 @@ class MockDispatcher:
|
||||
pass
|
||||
|
||||
|
||||
class MockTx:
|
||||
|
||||
def __init__(self, tx_hash, status=TxStatus.SUCCESS):
|
||||
self.hash = tx_hash
|
||||
self.status = status
|
||||
|
||||
|
||||
|
||||
class TestChaindFs(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
@@ -89,5 +99,27 @@ class TestChaindFs(unittest.TestCase):
|
||||
self.assertEqual(len(txs), 1)
|
||||
|
||||
|
||||
def test_fs_filter(self):
|
||||
drv = QueueDriver(self.adapter)
|
||||
|
||||
data = os.urandom(128).hex()
|
||||
hsh = self.adapter.put(data)
|
||||
|
||||
fltr = StateFilter(self.adapter)
|
||||
tx = MockTx(hsh)
|
||||
fltr.filter(None, None, tx)
|
||||
|
||||
|
||||
def test_fs_filter_fail(self):
|
||||
drv = QueueDriver(self.adapter)
|
||||
|
||||
data = os.urandom(128).hex()
|
||||
hsh = self.adapter.put(data)
|
||||
|
||||
fltr = StateFilter(self.adapter)
|
||||
tx = MockTx(hsh, TxStatus.ERROR)
|
||||
fltr.filter(None, None, tx)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
||||
Reference in New Issue
Block a user