Onionr/tests/test_timeinsert.py

45 lines
1.2 KiB
Python
Raw Normal View History

2019-12-27 07:53:18 +00:00
#!/usr/bin/env python3
import sys, os
2019-12-27 07:53:18 +00:00
sys.path.append(".")
sys.path.append("src/")
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
2020-11-22 00:43:59 +00:00
from utils import createdirs
createdirs.create_dirs()
from onionrcrypto import getourkeypair
getourkeypair.get_keypair()
from oldblocks import time_insert
from oldblocks import onionrblockapi
from onionrsetup import setup_config, setup_default_plugins
setup_config()
setup_default_plugins()
2019-12-27 07:53:18 +00:00
import config
config.set("general.minimum_block_pow", 2)
config.set('general.minimum_send_pow', 2)
config.save()
2019-12-27 07:53:18 +00:00
class TestTimeInsert(unittest.TestCase):
def test_time_insert_none(self):
bl = time_insert('test')
self.assertTrue(bl)
bl = onionrblockapi.Block(bl)
self.assertIs(bl.bmetadata['dly'], 0)
def test_time_insert_10(self):
bl = time_insert('test', delay=10)
self.assertTrue(bl)
bl = onionrblockapi.Block(bl)
self.assertIs(bl.bmetadata['dly'], 10)
def test_negative(self):
self.assertRaises(ValueError, time_insert, 'test', delay=-1)
self.assertRaises(ValueError, time_insert, 'test', delay=-10)
unittest.main()