2019-09-08 09:48:16 +00:00
|
|
|
import sys, os
|
|
|
|
sys.path.append(".")
|
2019-11-21 09:26:23 +00:00
|
|
|
sys.path.append("src/")
|
2019-09-08 09:48:16 +00:00
|
|
|
import unittest, uuid
|
2020-07-24 07:57:44 +00:00
|
|
|
from time import sleep
|
2019-09-08 09:48:16 +00:00
|
|
|
|
2019-09-11 03:56:20 +00:00
|
|
|
TEST_DIR = 'testdata/%s-%s' % (uuid.uuid4(), os.path.basename(__file__)) + '/'
|
|
|
|
os.environ["ONIONR_HOME"] = TEST_DIR
|
2020-11-22 00:43:59 +00:00
|
|
|
from utils import createdirs
|
|
|
|
createdirs.create_dirs()
|
|
|
|
from onionrcrypto import getourkeypair
|
|
|
|
getourkeypair.get_keypair()
|
2019-09-11 03:56:20 +00:00
|
|
|
import config
|
2019-09-08 09:48:16 +00:00
|
|
|
import logger
|
|
|
|
import onionrsetup as setup
|
|
|
|
import onionrblocks
|
|
|
|
import filepaths
|
|
|
|
import onionrexceptions
|
2019-09-21 23:49:24 +00:00
|
|
|
from onionrblocks import storagecounter
|
2019-09-08 09:48:16 +00:00
|
|
|
import onionrstorage
|
|
|
|
|
|
|
|
def _test_setup():
|
|
|
|
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()
|
|
|
|
setup.setup_config()
|
|
|
|
|
|
|
|
class TestStorageCounter(unittest.TestCase):
|
|
|
|
def test_basic_amount(self):
|
|
|
|
_test_setup()
|
2019-09-11 03:56:20 +00:00
|
|
|
|
2019-09-08 09:48:16 +00:00
|
|
|
self.assertIsNotNone(config.get('allocations.disk'))
|
2019-09-11 02:53:28 +00:00
|
|
|
self.assertGreaterEqual(config.get('allocations.disk'), 1000000)
|
2020-07-24 07:57:44 +00:00
|
|
|
|
2019-09-08 09:48:16 +00:00
|
|
|
def test_insert_too_much(self):
|
|
|
|
_test_setup()
|
|
|
|
config.set('allocations.disk', 1000)
|
|
|
|
self.assertRaises(onionrexceptions.DiskAllocationReached, onionrblocks.insert, "test")
|
|
|
|
|
|
|
|
def test_count(self):
|
|
|
|
_test_setup()
|
|
|
|
counter = storagecounter.StorageCounter()
|
2020-07-24 07:57:44 +00:00
|
|
|
start_value = counter.amount
|
2019-09-08 09:48:16 +00:00
|
|
|
b_hash = onionrblocks.insert("test")
|
2020-07-24 07:57:44 +00:00
|
|
|
sleep(0.1)
|
|
|
|
self.assertGreater(counter.amount, start_value)
|
2019-09-08 09:48:16 +00:00
|
|
|
onionrstorage.removeblock.remove_block(b_hash)
|
2020-07-24 07:57:44 +00:00
|
|
|
sleep(0.1)
|
|
|
|
self.assertEqual(counter.amount, start_value)
|
|
|
|
|
2019-09-08 09:48:16 +00:00
|
|
|
|
2019-09-13 02:22:25 +00:00
|
|
|
unittest.main()
|