test_rlp_decoder.py (1611B)
1 # standard imports 2 import os 3 import unittest 4 import logging 5 import ctypes 6 7 # local imports 8 from pylibrlp import RLPEncoder 9 10 logging.basicConfig(level=logging.DEBUG) 11 logg = logging.getLogger() 12 13 14 class TestRlpDecoder(unittest.TestCase): 15 16 def setUp(self): 17 self.encoder = RLPEncoder(1024) 18 19 20 def test_decode_single_string(self): 21 b = b'\x83\x66\x6f\x6f' 22 v = self.encoder.decode(b) 23 self.assertEqual(v, b'foo') 24 25 26 def test_decode_single_string(self): 27 b = b'\xc4\x83\x66\x6f\x6f' 28 v = self.encoder.decode(b) 29 self.assertEqual(v, [b'foo']) 30 31 32 def test_decode_multiple_adjacent(self): 33 b = bytes.fromhex('f86801843b9aca008252089416cfb63467452ecf15e9d6ac48e9b4da628716c482040083666f6f26a0d825b2e797550c144f5e8acae452bd81e1947fdcbc3430240e44e967b82181f4a030856f4a51a8e9464b506490f4c7d391c386efe1134cabb546dfa4260f801c6a') 34 v = self.encoder.decode(b) 35 36 t = [ 37 bytes.fromhex('01'), 38 bytes.fromhex('3b9aca00'), 39 bytes.fromhex('5208'), 40 bytes.fromhex('16CfB63467452eCf15E9d6aC48E9B4DA628716C4'), 41 bytes.fromhex('0400'), 42 bytes.fromhex('666f6f'), 43 bytes.fromhex('26'), 44 bytes.fromhex('d825b2e797550c144f5e8acae452bd81e1947fdcbc3430240e44e967b82181f4'), 45 bytes.fromhex('30856f4a51a8e9464b506490f4c7d391c386efe1134cabb546dfa4260f801c6a'), 46 ] 47 for i in range(len(t)): 48 logg.debug('checking {}: {} {}'.format(i, v[i], t[i])) 49 self.assertEqual(v[i], t[i]) 50 51 52 if __name__ == '__main__': 53 unittest.main()