1
# -*- coding: UTF-8 -*-
2
from __future__ import unicode_literals
5
from rlp import SerializationError, utils
6
from rlp.sedes import Binary
14
('\x00' * 20): (b'\x00' * 20),
18
assert b1.serialize(k) == f[k]
19
for d in ([], 5, str):
20
with pytest.raises(SerializationError):
23
b2 = Binary.fixed_length(5)
26
b'\x00\x01\x02\x03\x04': b'\x00\x01\x02\x03\x04',
27
utils.str_to_bytes('ababa'): b'ababa'
30
assert b2.serialize(k) == f[k]
32
for d in ('asdf', 'asdfgh', '', 'bababa'):
33
with pytest.raises(SerializationError):
41
b'\x00\x01\x02': b'\x00\x01\x02'
44
assert b3.serialize(k) == f[k]
45
for d in ('', 'a', 'abcde', 'äää'):
46
with pytest.raises(SerializationError):
49
b4 = Binary(min_length=3)
50
f = {'abc': b'abc', 'abcd': b'abcd', ('x' * 132): (b'x' * 132)}
52
assert b4.serialize(k) == f[k]
53
for d in ('ab', '', 'a', 'xy'):
54
with pytest.raises(SerializationError):
57
b5 = Binary(max_length=3)
58
f = {'': b'', 'ab': b'ab', 'abc': b'abc'}
60
assert b5.serialize(k) == f[k]
61
for d in ('abcd', 'vwxyz', 'a' * 32):
62
with pytest.raises(SerializationError):
65
b6 = Binary(min_length=3, max_length=5, allow_empty=True)
66
f = {'': b'', 'abc': b'abc', 'abcd': b'abcd', 'abcde': b'abcde'}
68
assert b6.serialize(k) == f[k]
69
for d in ('a', 'ab', 'abcdef', 'abcdefgh' * 10):
70
with pytest.raises(SerializationError):