2019-02-16 04:08:26 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
import sys, os
|
|
|
|
sys.path.append(".")
|
2019-11-21 09:26:23 +00:00
|
|
|
sys.path.append("src/")
|
2019-02-16 04:08:26 +00:00
|
|
|
import unittest, uuid, hashlib
|
2020-04-03 06:44:26 +00:00
|
|
|
import secrets
|
2019-09-11 01:59:31 +00:00
|
|
|
|
2020-03-04 06:59:29 +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
|
2019-09-21 23:49:24 +00:00
|
|
|
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()
|
|
|
|
|
2019-02-16 04:08:26 +00:00
|
|
|
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))
|
2020-03-04 06:59:29 +00:00
|
|
|
|
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-02-16 04:08:26 +00:00
|
|
|
|
2019-09-13 02:22:25 +00:00
|
|
|
unittest.main()
|