def test_process_message_req_preprepare_without_preprepare(message_req_service: MessageReqService, external_bus, data, pp): key = (pp.viewNo, pp.ppSeqNo) data.sent_preprepares.pop(key) message_req = MessageReq(**{ f.MSG_TYPE.nm: PREPREPARE, f.PARAMS.nm: {f.INST_ID.nm: data.inst_id, f.VIEW_NO.nm: key[0], f.PP_SEQ_NO.nm: key[1]}, }) frm = "frm" message_req_service.process_message_req(message_req, frm) assert len(external_bus.sent_messages) == 0
def test_process_message_req_incorrect_inst_id( message_req_service: MessageReqService, external_bus, data): key = (data.view_no, 1) message_req = MessageReq( **{ f.MSG_TYPE.nm: PREPREPARE, f.PARAMS.nm: { f.INST_ID.nm: data.inst_id + 1, f.VIEW_NO.nm: key[0], f.PP_SEQ_NO.nm: key[1] }, }) message_req_service.process_message_req(message_req, "frm") assert len(external_bus.sent_messages) == 0
def test_process_message_req_with_incorrect_type( message_req_service: MessageReqService, external_bus, data, pp): msg_type = LEDGER_STATUS key = (data.view_no, 1) message_req = MessageReq( **{ f.MSG_TYPE.nm: msg_type, f.PARAMS.nm: { f.INST_ID.nm: data.inst_id, f.VIEW_NO.nm: key[0], f.PP_SEQ_NO.nm: key[1] }, }) message_req_service.process_message_req(message_req, "frm") assert len(external_bus.sent_messages) == 0
def test_process_message_req_commit(message_req_service: MessageReqService, external_bus, data, commit): key = (commit.viewNo, commit.ppSeqNo) message_req = MessageReq(**{ f.MSG_TYPE.nm: COMMIT, f.PARAMS.nm: {f.INST_ID.nm: data.inst_id, f.VIEW_NO.nm: key[0], f.PP_SEQ_NO.nm: key[1]}, }) frm = "frm" message_req_service.process_message_req(message_req, frm) assert len(external_bus.sent_messages) == 1 assert external_bus.sent_messages[0] == (MessageRep(message_req.msg_type, message_req.params, data.commits[key].msg), [frm])
def test_process_message_req_preprepare(message_req_service: MessageReqService, external_bus, data, pp): key = (pp.viewNo, pp.ppSeqNo) message_req = MessageReq(**{ f.MSG_TYPE.nm: PREPREPARE, f.PARAMS.nm: {f.INST_ID.nm: data.inst_id, f.VIEW_NO.nm: key[0], f.PP_SEQ_NO.nm: key[1]}, }) frm = "frm" message_req_service.process_message_req(message_req, frm) assert len(external_bus.sent_messages) == 1 assert external_bus.sent_messages[0] == (MessageRep(message_req.msg_type, message_req.params, data.sent_preprepares[key]), [frm])
def test_process_message_req_commit_without_commit(message_req_service: MessageReqService, external_bus, data, commit): key = (commit.viewNo, commit.ppSeqNo) other_node_name = "other_node" data.commits.clear() data.commits.addVote(commit, other_node_name) assert not data.commits.hasCommitFrom(commit, data.name) assert data.commits.hasCommitFrom(commit, other_node_name) message_req = MessageReq(**{ f.MSG_TYPE.nm: COMMIT, f.PARAMS.nm: {f.INST_ID.nm: data.inst_id, f.VIEW_NO.nm: key[0], f.PP_SEQ_NO.nm: key[1]}, }) frm = "frm" message_req_service.process_message_req(message_req, frm) assert len(external_bus.sent_messages) == 0
def test_process_message_req_handler_raise_ex( message_req_service: MessageReqService, external_bus, data): msg_type = PREPREPARE key = (data.view_no, 1) message_req = MessageReq( **{ f.MSG_TYPE.nm: msg_type, f.PARAMS.nm: { f.INST_ID.nm: data.inst_id, f.VIEW_NO.nm: key[0], f.PP_SEQ_NO.nm: key[1] }, }) message_req_service.handlers[ msg_type].process_message_req = lambda msg: raise_ex() message_req_service.process_message_req(message_req, "frm") assert len(external_bus.sent_messages) == 0
def test_process_message_req_prepare_without_prepare( message_req_service: MessageReqService, external_bus, data, prepare): key = (prepare.viewNo, prepare.ppSeqNo) other_node_name = "other_node" data.prepares.clear() data.prepares.addVote(prepare, other_node_name) assert not data.prepares.hasPrepareFrom(prepare, data.name) assert data.prepares.hasPrepareFrom(prepare, other_node_name) message_req = MessageReq( **{ f.MSG_TYPE.nm: PREPARE, f.PARAMS.nm: { f.INST_ID.nm: data.inst_id, f.VIEW_NO.nm: key[0], f.PP_SEQ_NO.nm: key[1] }, }) frm = "frm" message_req_service.process_message_req(message_req, frm) assert len(external_bus.sent_messages) == 0