def test_bytes(self): s = transaction.BCDataStream() s.write('foobar') self.assertEquals(s.read_bytes(3), 'foo') self.assertEquals(s.read_bytes(2), 'ba') self.assertEquals(s.read_bytes(4), 'r') self.assertEquals(s.read_bytes(1), '')
def test_string(self): s = transaction.BCDataStream() with self.assertRaises(transaction.SerializationError): s.read_string() msgs = ['Hello', ' ', 'World', '', '!'] for msg in msgs: s.write_string(msg) for msg in msgs: self.assertEquals(s.read_string(), msg) with self.assertRaises(transaction.SerializationError): s.read_string()
def test_compact_size(self): s = transaction.BCDataStream() values = [0, 1, 252, 253, 2**16-1, 2**16, 2**32-1, 2**32, 2**64-1] for v in values: s.write_compact_size(v) with self.assertRaises(transaction.SerializationError): s.write_compact_size(-1) self.assertEqual(bh2u(s.input), '0001fcfdfd00fdfffffe00000100feffffffffff0000000001000000ffffffffffffffffff') for v in values: self.assertEqual(s.read_compact_size(), v) with self.assertRaises(IndexError): s.read_compact_size()