From adba4be099a98e49fe76141fb44c835979480152 Mon Sep 17 00:00:00 2001 From: Kevin Froman Date: Sun, 22 Nov 2020 00:43:59 +0000 Subject: [PATCH] fix tests --- scripts/disable-dev-config.py | 4 ++-- static-data/default_config.json | 7 +++---- tests/runtime-result.txt | 2 +- tests/test_database_actions.py | 16 ++++++++++------ tests/test_default_config_json.py | 8 +++++--- tests/test_keymanager.py | 6 ++++-- tests/test_networkmerger.py | 9 ++++++--- tests/test_onionr_threads.py | 8 ++++++-- tests/test_onionrusers.py | 7 +++++-- tests/test_peerprofiles.py | 10 ++++++---- tests/test_runtime_result.py | 2 +- tests/test_setupkvvars.py | 5 ++++- tests/test_storagecounter.py | 6 ++++-- tests/test_timeinsert.py | 6 ++++-- tests/test_upload_session.py | 4 ++++ tests/test_vanity.py | 4 ++++ tests/test_waitforsetvars.py | 6 +++++- tests/test_zfill.py | 4 ++++ 18 files changed, 78 insertions(+), 36 deletions(-) diff --git a/scripts/disable-dev-config.py b/scripts/disable-dev-config.py index ca337a12..d2b847b8 100755 --- a/scripts/disable-dev-config.py +++ b/scripts/disable-dev-config.py @@ -18,8 +18,8 @@ conf['general']['display_header'] = True conf['general']['security_level'] = 0 conf['general']['use_bootstrap_list'] = True conf['onboarding']['done'] = False -conf['general']['minimum_block_pow'] = 5 -conf['general']['minimum_send_pow'] = 5 +conf['general']['minimum_block_pow'] = 6 +conf['general']['minimum_send_pow'] = 6 conf['log']['file']['remove_on_exit'] = True conf['transports']['lan'] = True conf['transports']['tor'] = True diff --git a/static-data/default_config.json b/static-data/default_config.json index 8cb8e486..11973b86 100755 --- a/static-data/default_config.json +++ b/static-data/default_config.json @@ -14,8 +14,8 @@ "hide_created_blocks": true, "insert_deniable_blocks": true, "max_block_age": 2678400, - "minimum_block_pow": 5, - "minimum_send_pow": 5, + "minimum_block_pow": 6, + "minimum_send_pow": 6, "public_key": "", "random_bind_ip": true, "security_level": 0, @@ -45,8 +45,7 @@ "minimum_score": -100 }, "plugins": { - "disabled": [ - ], + "disabled": [], "enabled": [] }, "statistics": { diff --git a/tests/runtime-result.txt b/tests/runtime-result.txt index 468a8265..f0198367 100644 --- a/tests/runtime-result.txt +++ b/tests/runtime-result.txt @@ -1 +1 @@ -1603867091 \ No newline at end of file +1606002757 \ No newline at end of file diff --git a/tests/test_database_actions.py b/tests/test_database_actions.py index 06e2baa5..2fc51dfd 100644 --- a/tests/test_database_actions.py +++ b/tests/test_database_actions.py @@ -6,12 +6,16 @@ import unittest, uuid, sqlite3 TEST_DIR = 'testdata/%s-%s' % (uuid.uuid4(), os.path.basename(__file__)) + '/' print("Test directory:", TEST_DIR) os.environ["ONIONR_HOME"] = TEST_DIR -from urllib.request import pathname2url -from coredb import keydb from utils import createdirs createdirs.create_dirs() +from onionrcrypto import getourkeypair +getourkeypair.get_keypair() +from urllib.request import pathname2url +from coredb import keydb + + class OnionrTests(unittest.TestCase): - + def test_address_add(self): testAddresses = ['facebookcorewwwi.onion', '56kmnycrvepfarolhnx6t2dvmldfeyg7jdymwgjb7jjzg47u2lqw2sad.onion', '5bvb5ncnfr4dlsfriwczpzcvo65kn7fnnlnt2ln7qvhzna2xaldq.b32.i2p'] for address in testAddresses: @@ -19,7 +23,7 @@ class OnionrTests(unittest.TestCase): dbAddresses = keydb.listkeys.list_adders() for address in testAddresses: self.assertIn(address, dbAddresses) - + invalidAddresses = [None, '', ' ', '\t', '\n', ' test ', 24, 'fake.onion', 'fake.b32.i2p'] for address in invalidAddresses: try: @@ -28,8 +32,8 @@ class OnionrTests(unittest.TestCase): pass dbAddresses = keydb.listkeys.list_adders() for address in invalidAddresses: - self.assertNotIn(address, dbAddresses) - + self.assertNotIn(address, dbAddresses) + def test_address_info(self): adder = 'nytimes3xbfgragh.onion' keydb.addkeys.add_address(adder) diff --git a/tests/test_default_config_json.py b/tests/test_default_config_json.py index c8aa14d6..b50db4b2 100644 --- a/tests/test_default_config_json.py +++ b/tests/test_default_config_json.py @@ -5,10 +5,12 @@ import unittest, uuid, json TEST_DIR = 'testdata/%s-%s' % (uuid.uuid4(), os.path.basename(__file__)) + '/' print("Test directory:", TEST_DIR) os.environ["ONIONR_HOME"] = TEST_DIR -import onionrblocks from utils import createdirs -from utils import readstatic createdirs.create_dirs() +from onionrcrypto import getourkeypair +getourkeypair.get_keypair() +from utils import readstatic +import onionrblocks class OnionrConfig(unittest.TestCase): def test_default_file(self): json.loads(readstatic.read_static('default_config.json')) @@ -45,7 +47,7 @@ class OnionrConfig(unittest.TestCase): self.assertEqual(conf['peers']['max_connect'], 1000) self.assertEqual(conf['peers']['max_stored_peers'], 10000000) self.assertEqual(conf['peers']['minimum_score'], -100) - self.assertEqual(conf['plugins']['disabled'], ['chat']) + self.assertEqual(conf['plugins']['disabled'], []) self.assertEqual(conf['plugins']['enabled'], []) self.assertEqual(conf['timers']['getBlocks'], 10) self.assertEqual(conf['timers']['lookupBlocks'], 25) diff --git a/tests/test_keymanager.py b/tests/test_keymanager.py index 818354af..bb0be810 100644 --- a/tests/test_keymanager.py +++ b/tests/test_keymanager.py @@ -8,10 +8,12 @@ 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() from coredb import keydb import onionrsetup as setup, keymanager, filepaths from onionrutils import stringvalidators -createdirs.create_dirs() +from onionrcrypto import getourkeypair +getourkeypair.get_keypair() setup.setup_config() pub_key = keymanager.KeyManager().getPubkeyList()[0] class KeyManagerTest(unittest.TestCase): @@ -35,5 +37,5 @@ class KeyManagerTest(unittest.TestCase): manager.removeKey(new_key) with open(filepaths.keys_file, 'r') as keyfile: self.assertNotIn(new_key, keyfile.read()) - + unittest.main() diff --git a/tests/test_networkmerger.py b/tests/test_networkmerger.py index 755d2e7b..5fb70be8 100644 --- a/tests/test_networkmerger.py +++ b/tests/test_networkmerger.py @@ -7,11 +7,14 @@ import unittest, uuid 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() +from onionrcrypto import getourkeypair +getourkeypair.get_keypair() from utils import networkmerger from coredb import keydb import onionrsetup as setup -from utils import createdirs -createdirs.create_dirs() setup.setup_config() class NetworkMergerTest(unittest.TestCase): def test_valid_merge(self): @@ -21,7 +24,7 @@ class NetworkMergerTest(unittest.TestCase): self.assertIn('mporbyyjhmz2c62shctbi3ngrslne5lpcyav6uzhxok45iblodhgjoad.onion', added) self.assertNotIn('inwalidkcorewwi.onion', added) self.assertIn('facebookcorewwwi.onion', added) - + def test_invalid_mergeself(self): adders = 'facebookc0rewwi.onion,sdfsdfsdf.onion, ssdf324, null, \n' networkmerger.mergeAdders(adders) diff --git a/tests/test_onionr_threads.py b/tests/test_onionr_threads.py index ce3539c7..efced56b 100644 --- a/tests/test_onionr_threads.py +++ b/tests/test_onionr_threads.py @@ -8,12 +8,16 @@ from time import sleep 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() +from onionrcrypto import getourkeypair +getourkeypair.get_keypair() + from utils import networkmerger from coredb import keydb import onionrsetup as setup -from utils import createdirs from onionrthreads import add_onionr_thread -createdirs.create_dirs() + setup.setup_config() class OnionrThreadsTests(unittest.TestCase): diff --git a/tests/test_onionrusers.py b/tests/test_onionrusers.py index de5b56a2..13354871 100644 --- a/tests/test_onionrusers.py +++ b/tests/test_onionrusers.py @@ -7,14 +7,17 @@ import json 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() +from onionrcrypto import getourkeypair +getourkeypair.get_keypair() import onionrexceptions from onionrusers import onionrusers from onionrusers import contactmanager import onionrcrypto as crypto from coredb import keydb -from utils import identifyhome, createdirs -createdirs.create_dirs() +from utils import identifyhome class OnionrUserTests(unittest.TestCase): ''' Tests both the onionrusers class and the contactmanager (which inherits it) diff --git a/tests/test_peerprofiles.py b/tests/test_peerprofiles.py index 160fdc4c..d6061de1 100644 --- a/tests/test_peerprofiles.py +++ b/tests/test_peerprofiles.py @@ -7,13 +7,15 @@ import base64 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() +from onionrcrypto import getourkeypair +getourkeypair.get_keypair() from onionrpeers import peerprofiles import onionrexceptions from coredb import keydb -from utils import createdirs from onionrutils import stringvalidators, epoch TEST_PEER = '3n5wclq4w4pfkcfmjcpqrjluctpm2tzt7etfblavf42cntv6hrerkzyb.onion' -createdirs.create_dirs() def rand_fake_adder_generator(): rand_bytes = os.urandom(35) @@ -30,11 +32,11 @@ class TestPeerProfiles(unittest.TestCase): self.assertRaises(onionrexceptions.InvalidAddress, peerprofiles.PeerProfiles, "invalid") def test_valid_init(self): peerprofiles.PeerProfiles(test_peers.pop()) - + def test_load_score(self): p = peerprofiles.PeerProfiles(test_peers.pop()) self.assertEqual(p.score, 0) - + def test_inc_score(self): p = peerprofiles.PeerProfiles(test_peers.pop()) s = 0 diff --git a/tests/test_runtime_result.py b/tests/test_runtime_result.py index f0642c36..14911c23 100644 --- a/tests/test_runtime_result.py +++ b/tests/test_runtime_result.py @@ -19,7 +19,7 @@ class TestRuntimeFile(unittest.TestCase): def test_runtime_result(self): self.assertTrue(os.path.exists(SUCCESS_FILE)) with open(SUCCESS_FILE, 'r') as result_file: - self.assertLess(math.floor(time.time()) - int(result_file.read()), 1800) + self.assertLess(math.floor(time.time()) - int(result_file.read()), 3800) unittest.main() diff --git a/tests/test_setupkvvars.py b/tests/test_setupkvvars.py index f2143195..54c01638 100644 --- a/tests/test_setupkvvars.py +++ b/tests/test_setupkvvars.py @@ -12,11 +12,14 @@ import setupkvvars 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() +from onionrcrypto import getourkeypair +getourkeypair.get_keypair() from utils import networkmerger from coredb import keydb import onionrsetup as setup from utils import createdirs -createdirs.create_dirs() setup.setup_config() class SetupKVVarsTest(unittest.TestCase): diff --git a/tests/test_storagecounter.py b/tests/test_storagecounter.py index 1b2d2369..bc1ddf6c 100644 --- a/tests/test_storagecounter.py +++ b/tests/test_storagecounter.py @@ -6,11 +6,13 @@ from time import sleep TEST_DIR = 'testdata/%s-%s' % (uuid.uuid4(), os.path.basename(__file__)) + '/' os.environ["ONIONR_HOME"] = TEST_DIR +from utils import createdirs +createdirs.create_dirs() +from onionrcrypto import getourkeypair +getourkeypair.get_keypair() import config import logger -from utils import createdirs import onionrsetup as setup -from utils import createdirs import onionrblocks import filepaths import onionrexceptions diff --git a/tests/test_timeinsert.py b/tests/test_timeinsert.py index c351aaff..6c92ef6f 100644 --- a/tests/test_timeinsert.py +++ b/tests/test_timeinsert.py @@ -6,12 +6,14 @@ import unittest, uuid 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() +from onionrcrypto import getourkeypair +getourkeypair.get_keypair() from onionrblocks import time_insert from onionrblocks import onionrblockapi from onionrsetup import setup_config, setup_default_plugins -from utils import createdirs -createdirs.create_dirs() setup_config() setup_default_plugins() diff --git a/tests/test_upload_session.py b/tests/test_upload_session.py index ba32bb2e..438f3a1f 100644 --- a/tests/test_upload_session.py +++ b/tests/test_upload_session.py @@ -7,6 +7,10 @@ TEST_DIR = 'testdata/%s-%s' % (uuid.uuid4(), os.path.basename(__file__)) + '/' print("Test directory:", TEST_DIR) os.environ["ONIONR_HOME"] = TEST_DIR import hashlib +from utils import createdirs +createdirs.create_dirs() +from onionrcrypto import getourkeypair +getourkeypair.get_keypair() from communicatorutils import uploadblocks def hash_generator(): diff --git a/tests/test_vanity.py b/tests/test_vanity.py index 75b5db1c..debb4773 100644 --- a/tests/test_vanity.py +++ b/tests/test_vanity.py @@ -6,6 +6,10 @@ TEST_DIR = 'testdata/%s-%s' % (uuid.uuid4(), os.path.basename(__file__)) + '/' print("Test directory:", TEST_DIR) os.environ["ONIONR_HOME"] = TEST_DIR import unittest +from utils import createdirs +createdirs.create_dirs() +from onionrcrypto import getourkeypair +getourkeypair.get_keypair() import vanityonionr import niceware diff --git a/tests/test_waitforsetvars.py b/tests/test_waitforsetvars.py index c2e276a2..a5a41195 100644 --- a/tests/test_waitforsetvars.py +++ b/tests/test_waitforsetvars.py @@ -5,6 +5,10 @@ import unittest, uuid, time, threading TEST_DIR = 'testdata/%s-%s' % (uuid.uuid4(), os.path.basename(__file__)) + '/' os.environ["ONIONR_HOME"] = TEST_DIR +from utils import createdirs +createdirs.create_dirs() +from onionrcrypto import getourkeypair +getourkeypair.get_keypair() from etc import waitforsetvar def set_test_var_delay(obj, delay=0): @@ -23,7 +27,7 @@ class TestWaitForSetVar(unittest.TestCase): threading.Thread(target=set_test_var_delay, args=[test_object, -1]).start() waitforsetvar.wait_for_set_var(test_object, 'test_var') self.assertTrue(test_object.test_var) - + def test_zero_wait(self): test_object = lambda: None threading.Thread(target=set_test_var_delay, args=[test_object, 0]).start() diff --git a/tests/test_zfill.py b/tests/test_zfill.py index dca76314..6fcaeb66 100644 --- a/tests/test_zfill.py +++ b/tests/test_zfill.py @@ -5,6 +5,10 @@ print("Test directory:", TEST_DIR) os.environ["ONIONR_HOME"] = TEST_DIR sys.path.append(".") sys.path.append("src/") +from utils import createdirs +createdirs.create_dirs() +from onionrcrypto import getourkeypair +getourkeypair.get_keypair() from utils import reconstructhash