Python rlp.sedes() Examples

The following are 5 code examples of rlp.sedes(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module rlp , or try the search function .
Example #1
Source File: speed.py    From pyrlp with MIT License 6 votes vote down vote up
def main(rounds=10000):
    st = time.time()
    d = do_test_serialize(mk_block(), rounds)
    elapsed = time.time() - st
    print('Block serializations / sec: %.2f' % (rounds / elapsed))

    st = time.time()
    d = do_test_deserialize(d, rounds)
    elapsed = time.time() - st
    print('Block deserializations / sec: %.2f' % (rounds / elapsed))

    st = time.time()
    d = do_test_serialize(mk_transaction(), rounds)
    elapsed = time.time() - st
    print('TX serializations / sec: %.2f' % (rounds / elapsed))

    st = time.time()
    d = do_test_deserialize(d, rounds, sedes=Transaction)
    elapsed = time.time() - st
    print('TX deserializations / sec: %.2f' % (rounds / elapsed)) 
Example #2
Source File: make_VMTests.py    From manticore with GNU Affero General Public License v3.0 5 votes vote down vote up
def gen_header(testcases):
    header = f'''"""DO NOT MODIFY: Tests generated from `tests/` with {sys.argv[0]}"""
import unittest
from binascii import unhexlify
from manticore import ManticoreEVM, Plugin
from manticore.utils import config
'''

    if any("logs" in testcase for testcase in testcases.values()):
        body += """
import sha3
import rlp
from rlp.sedes import (
    CountableList,
    BigEndianInt,
    Binary,
)
class Log(rlp.Serializable):
    fields = [
        ('address', Binary.fixed_length(20, allow_empty=True)),
        ('topics', CountableList(BigEndianInt(32))),
        ('data', Binary())
    ]
"""

    header += """consts = config.get_group('core')
consts.mprocessing = consts.mprocessing.single
consts = config.get_group('evm')
consts.oog = 'pedantic'

class EVMTest(unittest.TestCase):
    # https://nose.readthedocs.io/en/latest/doc_tests/test_multiprocess/multiprocess.html#controlling-distribution
    _multiprocess_can_split_ = True
    # https://docs.python.org/3.7/library/unittest.html#unittest.TestCase.maxDiff
    maxDiff = None

"""
    return header 
Example #3
Source File: transactions.py    From py-evm with MIT License 5 votes vote down vote up
def from_base_transaction(cls, transaction: SignedTransactionAPI) -> SignedTransactionAPI:
        return rlp.decode(rlp.encode(transaction), sedes=cls) 
Example #4
Source File: test_lazy.py    From pyrlp with MIT License 5 votes vote down vote up
def test_evaluation_of_lazy_decode_with_list_sedes_and_invalid_value():
    sedes = CountableList(big_endian_int)
    value = [(), (1, 2), b'asdf', (3)]
    invalid_lazy = rlp.decode_lazy(rlp.encode(value), sedes)
    assert invalid_lazy[0] == value[0]
    assert invalid_lazy[1] == value[1]
    with pytest.raises(DeserializationError):
        invalid_lazy[2] 
Example #5
Source File: speed.py    From pyrlp with MIT License 5 votes vote down vote up
def do_test_deserialize(data, rounds=100, sedes=Block):
    for i in range(rounds):
        x = rlp.decode(data, sedes)
    return x