Add change tx state, move queue state

This commit is contained in:
nolash
2021-06-01 13:26:09 +02:00
parent 565a58252a
commit bdd678fb3f
4 changed files with 83 additions and 3 deletions

View File

@@ -8,6 +8,7 @@ import os
# local imports
from chainqueue.fs.cache import FsQueue
from chainqueue.fs.dir import HexDir
from chainqueue.enum import StatusBits
logging.basicConfig(level=logging.DEBUG)
logg = logging.getLogger()
@@ -37,6 +38,29 @@ class HexDirTest(unittest.TestCase):
f.close()
self.assertEqual(r, b'\x00' * 8)
def test_change(self):
tx_hash = os.urandom(32)
tx_content = os.urandom(128)
self.q.add(tx_hash, tx_content)
self.q.set(tx_hash, StatusBits.QUEUED)
(tx_status, tx_content_retrieved) = self.q.get(tx_hash)
status = int.from_bytes(tx_status, byteorder='big')
self.assertEqual(status & StatusBits.QUEUED, StatusBits.QUEUED)
def test_move(self):
tx_hash = os.urandom(32)
tx_content = os.urandom(128)
self.q.add(tx_hash, tx_content)
self.q.move(tx_hash, 'new', 'ready')
f = open(os.path.join(self.q.path_state['ready'], tx_hash.hex()), 'rb')
r = f.read()
f.close()
self.assertEqual(r, b'\x00' * 8)
if __name__ == '__main__':
unittest.main()

View File

@@ -71,5 +71,14 @@ class HexDirTest(unittest.TestCase):
self.assertEqual(b'ff', r)
def test_get(self):
self.hexdir.add(b'\xde\xad\xbe\xef', b'foo', b'ab')
self.hexdir.add(b'\xbe\xef\xfe\xed', b'bar', b'cd')
self.hexdir.add(b'\x01\x02\x03\x04', b'baz', b'ef')
(prefix, key) = self.hexdir.get(1)
self.assertEqual(b'\xbe\xef\xfe\xed', key)
self.assertEqual(b'cd', prefix)
if __name__ == '__main__':
unittest.main()