fix anonvdf tests

This commit is contained in:
Kevin Froman 2021-01-24 03:24:01 +00:00
parent 505eee6aa3
commit fb0bc2351b

View File

@ -27,11 +27,12 @@ class TestAnonVDF(unittest.TestCase):
anonvdf.AnonVDFGenerator.validate_id(test_id, test_data, rounds=rds)
def test_vdf_block_validate_not_enough(self):
rds = 133240
t = floor(time()) - 60
test_data = kasten.generator.pack.pack(b"test", "tst", app_metadata=None, timestamp=t)
test_id = mimcvdf.vdf_create(test_data, rds)
self.assertRaises(anonvdf.NotEnoughRounds, anonvdf.AnonVDFGenerator.validate_id, test_id, test_data, rounds=rds)
self.assertRaises(anonvdf.InvalidID, anonvdf.AnonVDFGenerator.validate_id, test_id, test_data, rounds=rds-1)
def test_vdf_incermental(self):
last = 1
@ -46,27 +47,31 @@ class TestAnonVDF(unittest.TestCase):
self.assertGreater(newT - t, last)
def test_block_embedded_vdf_rounds(self):
t = floor(time())
rds = 90000 + (4000 * 1000)
test_data = kasten.generator.pack.pack(b"test", "tst", app_metadata={"rds": 900000}, timestamp=t)
rds = (3600 * 26) + (len(test_data) * 1000) - 1000
test_data = kasten.generator.pack.pack(b"test", "tst", app_metadata={"rds": rds}, timestamp=t)
test_vdf = anonvdf.AnonVDFGenerator.generate(test_data, None)
anonvdf.AnonVDFGenerator.validate_id(test_vdf.id, test_data, rounds=None)
def test_block_embedded_vdf_rounds_invalid(self):
t = floor(time())
rds = 90000
test_data = kasten.generator.pack.pack(b"test", "tst", app_metadata={"rds": 900000}, timestamp=t)
rds = (3600 * 26) + (len(test_data) * 1000) - 2000
test_data = kasten.generator.pack.pack(b"test", "tst", app_metadata={"rds": rds}, timestamp=t)
test_vdf = anonvdf.AnonVDFGenerator.generate(test_data, None)
test_vdf = anonvdf.AnonVDFGenerator.generate(test_data)
self.assertRaises(
anonvdf.NotEnoughRounds,
anonvdf.AnonVDFGenerator.validate_id, test_vdf.id, test_data, rounds=None)
anonvdf.InvalidID,
anonvdf.AnonVDFGenerator.validate_id, test_vdf.id, test_data, rounds=50000)
def test_vdf_rounds_seconds(self):
size = 10000
per_byte = 1000
per_second = 25
expected_rounds = (3600 * 25) + 100000
self.assertEqual(anonvdf.AnonVDFGenerator.get_rounds_for_ttl_seconds(3600, 100), expected_rounds)
per_second = 26
expected_rounds = (3600 * per_second) + (size * per_byte)
self.assertEqual(anonvdf.AnonVDFGenerator.get_rounds_for_ttl_seconds(3600, size), expected_rounds)
unittest.main()