コード例 #1
0
def test_binary_fixed_lenght_of_zero():
    sedes = Binary.fixed_length(0)
    assert sedes.serialize(b'') == b''

    with pytest.raises(SerializationError):
        sedes.serialize(b'a')
    with pytest.raises(SerializationError):
        sedes.serialize(b'arst')
コード例 #2
0
ファイル: speed.py プロジェクト: burningsage711/py-rlp-cython
"""
util to benchmark known usecase
"""
import random
import rlp_cython as rlp
from rlp_cython.sedes import big_endian_int, BigEndianInt, Binary, binary, CountableList
from rlp_cython.sedes.serializable import Serializable
import time

address = Binary.fixed_length(20, allow_empty=True)
int20 = BigEndianInt(20)
int32 = BigEndianInt(32)
int256 = BigEndianInt(256)
hash32 = Binary.fixed_length(32)
trie_root = Binary.fixed_length(32, allow_empty=True)


def zpad(x, l):
    return b'\x00' * max(0, l - len(x)) + x


class Transaction(Serializable):
    fields = [
        ('nonce', big_endian_int),
        ('gasprice', big_endian_int),
        ('startgas', big_endian_int),
        ('to', address),
        ('value', big_endian_int),
        ('data', binary),
        ('v', big_endian_int),
        ('r', big_endian_int),
コード例 #3
0
from rlp_cython.sedes import (
    BigEndianInt,
    Binary,
)

from hvm.constants import (
    COLLATION_SIZE, )

address = Binary.fixed_length(20, allow_empty=True)
collation_body = Binary.fixed_length(COLLATION_SIZE)
hash32 = Binary.fixed_length(32)
int32 = BigEndianInt(32)
int256 = BigEndianInt(256)
trie_root = Binary.fixed_length(32, allow_empty=True)
コード例 #4
0
def test_binary_min_length_serialization(value, expected):
    sedes = Binary(min_length=3)
    assert sedes.serialize(value) == expected
コード例 #5
0
def test_binary_variable_length_serialization_wrong_length(value):
    sedes = Binary(2, 4)
    with pytest.raises(SerializationError):
        sedes.serialize(value)
コード例 #6
0
def test_binary_variable_length_serialization(value, expected):
    sedes = Binary(2, 4)
    assert sedes.serialize(value) == expected
コード例 #7
0
def test_binary_fixed_length_serialization_with_wrong_length(value):
    sedes = Binary.fixed_length(5)
    with pytest.raises(SerializationError):
        sedes.serialize(value)
コード例 #8
0
def test_binary_fixed_length_serialization(value, expected):
    sedes = Binary.fixed_length(5)
    assert sedes.serialize(value) == expected
コード例 #9
0
def test_binary_unserializable_values(value):
    sedes = Binary()
    with pytest.raises(SerializationError):
        sedes.serialize(value)
コード例 #10
0
def test_simple_binary_serialization(value, expected):
    sedes = Binary()
    assert sedes.serialize(value) == expected
コード例 #11
0
def test_binary_min_and_max_length_with_allow_empty_wrong_length(value):
    sedes = Binary(min_length=3, max_length=5, allow_empty=True)
    with pytest.raises(SerializationError):
        sedes.serialize(value)
コード例 #12
0
def test_binary_min_and_max_length_with_allow_empty(value, expected):
    sedes = Binary(min_length=3, max_length=5, allow_empty=True)
    assert sedes.serialize(value) == expected
コード例 #13
0
def test_binary_max_length_serialization_wrong_length(value):
    sedes = Binary(max_length=3)
    with pytest.raises(SerializationError):
        sedes.serialize(value)