onionr/tests/test_blocks.py

45 lines
1.2 KiB
Python
Raw Normal View History

#!/usr/bin/env python3
import sys, os
sys.path.append(".")
2019-11-21 09:26:23 +00:00
sys.path.append("src/")
import unittest, uuid, hashlib
2019-09-11 01:59:31 +00:00
TEST_DIR = 'testdata/%s-%s' % (uuid.uuid4(), os.path.basename(__file__)) + '/'
print("Test directory:", TEST_DIR)
os.environ["ONIONR_HOME"] = TEST_DIR
from utils import createdirs
createdirs.create_dirs()
2019-09-10 22:35:44 +00:00
import onionrstorage
from onionrutils import bytesconverter
2019-09-11 01:59:31 +00:00
import onionrcrypto
from onionrblocks import onionrblockapi
2019-09-11 01:59:31 +00:00
from onionrsetup import setup_config, setup_default_plugins
setup_config()
setup_default_plugins()
import config
config.set("general.minimum_block_pow", 2)
config.set('general.minimum_send_pow', 2)
config.save()
import onionrblocks
2019-09-11 01:59:31 +00:00
class OnionrBlockTests(unittest.TestCase):
def test_plaintext_insert(self):
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):
2019-09-11 01:59:31 +00:00
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()