Onionr/tests/test_blocks.py

41 lines
1.3 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
2020-04-03 06:44:26 +00:00
import secrets
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
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
from onionrblocks import onionrblockapi
2020-04-03 06:44:26 +00:00
from onionrproofs.vdf import verify
from onionrcrypto.hashers import sha3_hash
2019-09-11 01:59:31 +00:00
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()
2020-04-03 06:44:26 +00:00
message = 'hello world' + secrets.token_hex(5)
2019-09-10 22:35:44 +00:00
bl = onionrblocks.insert(message)
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()