onionr/tests/test_blocks.py

35 lines
1.1 KiB
Python
Raw Normal View History

#!/usr/bin/env python3
import sys, os
sys.path.append(".")
2019-09-13 02:22:25 +00:00
sys.path.append("onionr/")
import unittest, uuid, hashlib
2019-09-11 01:59:31 +00:00
2019-07-25 16:14:13 +00:00
import onionrblocks
2019-09-10 22:35:44 +00:00
import onionrstorage
2019-07-25 16:14:13 +00:00
from utils import createdirs
2019-09-10 22:35:44 +00:00
from onionrutils import bytesconverter
2019-09-11 01:59:31 +00:00
import onionrcrypto
import onionrblockapi
def setup_test():
TEST_DIR = 'testdata/%s-%s' % (uuid.uuid4(), os.path.basename(__file__)) + '/'
print("Test directory:", TEST_DIR)
os.environ["ONIONR_HOME"] = TEST_DIR
createdirs.create_dirs()
class OnionrBlockTests(unittest.TestCase):
def test_plaintext_insert(self):
2019-09-11 01:59:31 +00:00
setup_test()
message = 'hello world'
2019-09-10 22:35:44 +00:00
bl = onionrblocks.insert(message)
2019-09-11 01:59:31 +00:00
self.assertTrue(bl.startswith('0'))
2019-09-10 22:35:44 +00:00
self.assertIn(bytesconverter.str_to_bytes(message), onionrstorage.getData(bl))
2019-09-11 01:59:31 +00:00
def test_encrypted_insert(self):
setup_test()
message = 'hello world2'
bl = onionrblocks.insert(message, asymPeer=onionrcrypto.pub_key)
self.assertIn(bytesconverter.str_to_bytes(message), onionrblockapi.Block(bl, decrypt=True).bcontent)
2019-09-13 02:22:25 +00:00
unittest.main()