From 92588c9f96798a3fe0af4976a7a65dff7bff46af Mon Sep 17 00:00:00 2001 From: Kevin Froman Date: Tue, 10 Sep 2019 20:59:31 -0500 Subject: [PATCH] more work on blocks tests --- onionr/tests/test_blocks.py | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/onionr/tests/test_blocks.py b/onionr/tests/test_blocks.py index 8dfa103f..242b4bfa 100755 --- a/onionr/tests/test_blocks.py +++ b/onionr/tests/test_blocks.py @@ -2,23 +2,32 @@ import sys, os sys.path.append(".") import unittest, uuid, hashlib -import nacl.exceptions -import nacl.signing, nacl.hash, nacl.encoding -TEST_DIR = 'testdata/%s-%s' % (uuid.uuid4(), os.path.basename(__file__)) + '/' -print("Test directory:", TEST_DIR) -os.environ["ONIONR_HOME"] = TEST_DIR + import onionrblocks import onionrstorage from utils import createdirs from onionrutils import bytesconverter -createdirs.create_dirs() +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): + setup_test() message = 'hello world' bl = onionrblocks.insert(message) + self.assertTrue(bl.startswith('0')) self.assertIn(bytesconverter.str_to_bytes(message), onionrstorage.getData(bl)) - #def test_encrypted_insert(self): - # key_pair_1 = nacl.signing.SigningKey.generate(encoder=nacl.encoding.base32) + 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) unittest.main() \ No newline at end of file