def test_unpack_reply(self): msg = b'hello' primary_id = 0 req_seq_num = 1 packed = bft_msgs.pack_reply(primary_id, req_seq_num, msg) (header, unpacked_msg) = bft_msgs.unpack_reply(packed) self.assertEqual(primary_id, header.primary_id) self.assertEqual(req_seq_num, header.req_seq_num) self.assertEqual(msg, unpacked_msg)
def test_create_empty_rsi_message(self): msg = b'hello' primary_id = 0 req_seq_num = 1 packed = bft_msgs.pack_reply(primary_id, req_seq_num, msg, 0, 0) rsi_reply = rsi.MsgWithReplicaSpecificInfo(packed, 0) self.assertEqual(rsi_reply.sender_id, 0) common_header, common_data = rsi_reply.get_common_reply() self.assertEqual(req_seq_num, common_header.req_seq_num) self.assertEqual(common_data, b'hello')
def test_unpack_reply(self): msg = b'hello' primary_id = 0 req_seq_num = 1 result = 1 rsi_length = 5 packed = bft_msgs.pack_reply(primary_id, req_seq_num, msg, result, rsi_length) (header, unpacked_msg) = bft_msgs.unpack_reply(packed) self.assertEqual(primary_id, header.primary_id) self.assertEqual(req_seq_num, header.req_seq_num) self.assertEqual(result, header.result) self.assertEqual(rsi_length, header.rsi_length) self.assertEqual(msg, unpacked_msg)
def _build_msg(self, msg, primary_id=0, req_seq_num=1, rsi_length=0): return bft_msgs.pack_reply(primary_id, req_seq_num, msg, rsi_length)