41 lines
1.4 KiB
Python
41 lines
1.4 KiB
Python
import unittest
|
|
from onionrblocks import universalrules
|
|
import kasten
|
|
|
|
from time import time
|
|
from math import floor
|
|
|
|
class TestUniversalRules(unittest.TestCase):
|
|
|
|
def test_block_is_sane_max_size(self):
|
|
packed = kasten.generator.pack.pack(b"1"*6000000, b"tst", 0)
|
|
self.assertRaises(
|
|
universalrules.BlockTooLarge,
|
|
universalrules.check_block_sanity, packed)
|
|
|
|
def test_block_future_skew_ok(self):
|
|
t = floor(time()) + 120
|
|
packed = kasten.generator.pack.pack(b"1"*10, b"tst", 0, timestamp=t)
|
|
universalrules.check_block_sanity(packed)
|
|
|
|
def test_block_future_skew_not_ok(self):
|
|
t = floor(time()) + 121
|
|
packed = kasten.generator.pack.pack(b"1"*10, b"tst", 0, timestamp=t)
|
|
self.assertRaises(
|
|
universalrules.BlockFutureSkewedBeyondMax,
|
|
universalrules.check_block_sanity, packed)
|
|
|
|
def test_block_not_expired(self):
|
|
packed = kasten.generator.pack.pack(b"1"*10, b"tst", 0, app_metadata={"expire": 7})
|
|
self.assertRaises(
|
|
universalrules.BlockExpired,
|
|
universalrules.check_block_sanity, packed)
|
|
|
|
def test_block_expired(self):
|
|
t = floor(time()) - 6
|
|
packed = kasten.generator.pack.pack(b"1"*10, b"tst", 0, timestamp=t, app_metadata={"expire": 6})
|
|
self.assertRaises(
|
|
universalrules.BlockExpired,
|
|
universalrules.check_block_sanity, packed)
|
|
|
|
unittest.main() |