pylibrlp

Python3 wrapper for librlp
git clone git://git.defalsify.org/pylibrlp.git
Log | Files | Refs | LICENSE

commit 4f6a89256be3765d0361894eda6b1cf5e20883f2
parent 0b751a79243e71bf14420ec9db8a929ad0e8a703
Author: nolash <dev@holbrook.no>
Date:   Sun, 11 Apr 2021 17:50:27 +0200

Add discovery of so file, eth-tx-like test

Diffstat:
Mrlpstream/__init__.py | 20++++++++++++++------
Mtests/test_rlp_encoder.py | 19++++++++++++++++++-
2 files changed, 32 insertions(+), 7 deletions(-)

diff --git a/rlpstream/__init__.py b/rlpstream/__init__.py @@ -1,20 +1,28 @@ # standard imports +import sys +import re import os -import logging import ctypes import ctypes.util -logg = logging.getLogger().getChild('rlpstream.init') - -script_dir = os.path.dirname(__file__) LIBRLP_RLP_MAX_LIST_DEPTH = 1024 __path_librlp = ctypes.util.find_library('rlp') + +if __path_librlp == None: + v = sys.version_info + re_so = r'^rlp.cpython-' + str(v[0]) + str(v[1]) + '.*\.so$' + script_dir = os.path.dirname(__file__) + root_dir = os.path.join(script_dir, '..') + for f in os.listdir(root_dir): + if re.match(re_so, f): + __path_librlp = os.path.join(root_dir, f) + break + if __path_librlp == None: - __path_librlp = os.path.join(script_dir, '..', 'rlp.cpython-39-x86_64-linux-gnu.so') + raise ImportError('missing librlp shared library') -logg.debug('using librlp path {}'.format(__path_librlp)) librlp = ctypes.CDLL(__path_librlp) diff --git a/tests/test_rlp_encoder.py b/tests/test_rlp_encoder.py @@ -1,4 +1,5 @@ # standard imports +import os import unittest import logging import ctypes @@ -16,7 +17,6 @@ class TestRlpEncoder(unittest.TestCase): self.encoder = RLPEncoder(1024) - def test_encode_single(self): v = b'foo' b = self.encoder.encode(v) print(b.hex()) @@ -33,5 +33,22 @@ class TestRlpEncoder(unittest.TestCase): b = self.encoder.encode(v) print(b.hex()) + + def test_encode_multiple_adjacent(self): + v = [ + bytes.fromhex('01'), + bytes.fromhex('3b9aca00'), + bytes.fromhex('5208'), + bytes.fromhex('3102ac39709f178c0f5e87d05908609d8e09d820'), + bytes.fromhex('0400'), + bytes.fromhex('666f6f'), + bytes.fromhex('01'), + os.urandom(32), + os.urandom(32), + ] + b = self.encoder.encode(v) + print(b.hex()) + + if __name__ == '__main__': unittest.main()