def test_process_message_rep_commit(message_req_service: MessageReqService, external_bus, data, commit): key = (commit.viewNo, commit.ppSeqNo) message_req_service.handlers[COMMIT].requested_messages[key] = None message_rep = MessageRep(**{ 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]}, f.MSG.nm: dict(commit.items()) }) frm = "frm" network_handler = Mock() external_bus.subscribe(Commit, network_handler) message_req_service.process_message_rep(message_rep, frm) network_handler.assert_called_once_with(commit, frm)
def test_process_message_rep_new_view_from_primary(message_req_service: MessageReqService, external_bus, data, new_view_message: NewView): primary = data.primary_name inst_id = data.inst_id message_req_service.handlers[NEW_VIEW].requested_messages[data.view_no] = None message_rep_from_primary = MessageRep(**{ f.MSG_TYPE.nm: NEW_VIEW, f.PARAMS.nm: {f.INST_ID.nm: inst_id, f.VIEW_NO.nm: data.view_no}, f.MSG.nm: dict(new_view_message.items()) }) network_handler = Mock() external_bus.subscribe(NewView, network_handler) message_req_service.process_message_rep(message_rep_from_primary, primary) network_handler.assert_called_once_with(new_view_message, primary)
def test_process_message_rep_preprepare(message_req_service: MessageReqService, external_bus, data, pp): key = (pp.viewNo, pp.ppSeqNo) message_req_service.handlers[PREPREPARE].requested_messages[key] = None message_rep = MessageRep(**{ 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]}, f.MSG.nm: dict(pp.items()) }) frm = "frm" network_handler = Mock() external_bus.subscribe(PrePrepare, network_handler) message_req_service.process_message_rep(message_rep, frm) network_handler.assert_called_once_with(pp, frm)
def test_process_message_rep_with_incorrect_type( message_req_service: MessageReqService, external_bus, data, pp): key = (pp.viewNo, pp.ppSeqNo) message_rep = MessageRep( **{ f.MSG_TYPE.nm: LEDGER_STATUS, f.PARAMS.nm: { f.INST_ID.nm: data.inst_id, f.VIEW_NO.nm: key[0], f.PP_SEQ_NO.nm: key[1] }, f.MSG.nm: dict(pp.items()) }) frm = "frm" network_handler = Mock() external_bus.subscribe(PrePrepare, network_handler) external_bus.subscribe(Prepare, network_handler) external_bus.subscribe(Commit, network_handler) message_req_service.process_message_rep(message_rep, frm) network_handler.assert_not_called()
def test_process_message_rep_view_change_from_one(message_req_service: MessageReqService, external_bus, data, view_change_message: ViewChange): frm = "frm" inst_id = data.inst_id digest = view_change_digest(view_change_message) key = (frm, digest) message_req_service.handlers[VIEW_CHANGE].requested_messages[key] = None message_rep_from_primary = MessageRep(**{ f.MSG_TYPE.nm: VIEW_CHANGE, f.PARAMS.nm: {f.INST_ID.nm: inst_id, f.DIGEST.nm: digest, f.NAME.nm: frm}, f.MSG.nm: dict(view_change_message.items()) }) frm = "frm" network_handler = Mock() external_bus.subscribe(ViewChange, network_handler) network_handler.assert_not_called() message_req_service.process_message_rep(message_rep_from_primary, frm) network_handler.assert_called_once_with(view_change_message, frm)
def test_process_message_rep_invalid_preprepare( message_req_service: MessageReqService, external_bus, data, pp): key = (pp.viewNo, pp.ppSeqNo) msg_type = PREPREPARE message_req_service.handlers[PREPREPARE].requested_messages[key] = None message_rep = MessageRep( **{ 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] }, f.MSG.nm: dict(pp.items()) }) frm = "frm" network_handler = Mock() external_bus.subscribe(PrePrepare, network_handler) message_req_service.handlers[ msg_type].extract_message = lambda msg, frm: raise_ex() message_req_service.process_message_rep(message_rep, frm) network_handler.assert_not_called()