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(bcd_data_stream.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(bcd_data_stream.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(bcd_data_stream.SerializationError): s.write_compact_size(-1) self.assertEquals( s.input.encode('hex'), '0001fcfdfd00fdfffffe00000100feffffffffff0000000001000000ffffffffffffffffff' ) for v in values: self.assertEquals(s.read_compact_size(), v) with self.assertRaises(IndexError): s.read_compact_size()