onionrblocks/tests/test_blockcreator.py

33 lines
1.6 KiB
Python

from onionrblocks.generators import anonvdf
import unittest
import kasten
from onionrblocks.blockcreator import create_anonvdf_block
class TestBlockCreator(unittest.TestCase):
def test_create_anonvdf(self):
bl = create_anonvdf_block(b"Test", "txt", 3600)
# (rounds - (size_bytes * cls.byte_cost)) // cls.second_cost
expected_rounds = (3600 * 26) + (len(bl.get_packed()) * 1000) - 1000
self.assertEqual(expected_rounds, bl.get_metadata()['rds'])
def test_create_anonvdf_half_hour(self):
bl = create_anonvdf_block(b"Test", "txt", 1800)
expected_rounds = (len(bl.get_packed()) * anonvdf.AnonVDFGenerator.byte_cost) + (1800 * anonvdf.AnonVDFGenerator.second_cost) - 1000
self.assertEqual(expected_rounds, bl.get_metadata()['rds'])
def test_create_anonvdf_odd(self):
#(rounds - (size_bytes * cls.byte_cost)) // cls.second_cost
bl = create_anonvdf_block(b"Test", "txt", 1303)
expected_rounds = (len(bl.get_packed()) * anonvdf.AnonVDFGenerator.byte_cost) + (1303 * anonvdf.AnonVDFGenerator.second_cost) + 1000
self.assertEqual(expected_rounds, bl.get_metadata()['rds'])
def test_create_anonvdf_verify(self):
bl = create_anonvdf_block(b"Test", "txt", 3600)
expected_rounds = (len(bl.get_packed()) * anonvdf.AnonVDFGenerator.byte_cost) + (3600 * anonvdf.AnonVDFGenerator.second_cost) - 1000
self.assertEqual(expected_rounds, bl.get_metadata()['rds'])
packed = bl.get_packed()
id = bl.id
kasten.Kasten(id, packed, anonvdf.AnonVDFGenerator, auto_check_generator=True)
unittest.main()