onionrblocks/tests/test_blockcreator.py

38 lines
1.2 KiB
Python
Raw Normal View History

from binascii import a2b_hex
from onionrblocks.generators import anonvdf
import unittest
import kasten
from onionrblocks.blockcreator import create_anonvdf_block
def get_rounds_for_ttl_seconds(seconds: int, size_bytes: int):
second_cost = 4
byte_cost = 10
return (seconds * second_cost) + (size_bytes * byte_cost)
class TestBlockCreator(unittest.TestCase):
2022-01-30 02:19:07 +00:00
def test_create_anonvdf_verify(self):
bl = create_anonvdf_block(b"Test", "txt", 3600)
packed = bl.raw
kasten.Kasten(bl.id, packed, anonvdf.AnonVDFGenerator, auto_check_generator=True)
print(bl.id)
fake_id = b'01' + bl.id[2:]
self.assertRaises(kasten.exceptions.InvalidID, kasten.Kasten, fake_id, packed, anonvdf.AnonVDFGenerator, auto_check_generator=True)
fake_id = bytearray(bl.id)
fake_id[32] = 13
fake_id[34] = 13
fake_id[120] = 13
fake_id = bytes(fake_id).replace(b'\r', b'')
print(fake_id.replace(b'\r', b''))
2022-01-30 02:19:07 +00:00
kasten.Kasten(bl.id, packed, anonvdf.AnonVDFGenerator, auto_check_generator=True)
self.assertRaises(kasten.exceptions.InvalidID, kasten.Kasten, fake_id, packed, anonvdf.AnonVDFGenerator, auto_check_generator=True)
unittest.main()