def _view_change_acks(vc, vc_frm, primary, count): digest = ViewChangeService._view_change_digest(vc) non_senders = [ name for name in validators if name not in [vc_frm, primary] ] ack_frms = random.sample(non_senders, count) return [(ViewChangeAck(viewNo=vc.viewNo, name=vc_frm, digest=digest), ack_frm) for ack_frm in ack_frms]
def test_non_primary_responds_to_view_change_message_with_view_change_ack_to_new_primary( some_item, other_item, validators, primary, view_change_service, initial_view_no, view_change_message): non_primary_name = some_item(validators, exclude=[primary(initial_view_no + 1)]) service = view_change_service(non_primary_name) vc = view_change_message(initial_view_no + 1) frm = other_item(validators, exclude=[non_primary_name]) service._network.process_incoming(vc, frm) assert len(service._network.sent_messages) == 1 msg, dst = service._network.sent_messages[0] assert dst == service._data.primary_name assert isinstance(msg, ViewChangeAck) assert msg.viewNo == vc.viewNo assert msg.name == frm assert msg.digest == ViewChangeService._view_change_digest(vc)
def test_different_view_change_messages_have_different_digests( view_change_message, random): vc = view_change_message(random.integer(0, 10000)) other_vc = view_change_message(random.integer(0, 10000)) assert ViewChangeService._view_change_digest( vc) != ViewChangeService._view_change_digest(other_vc)
def test_view_change_digest_is_256_bit_hexdigest(view_change_message, random): vc = view_change_message(random.integer(0, 10000)) digest = ViewChangeService._view_change_digest(vc) assert isinstance(digest, str) assert len(digest) == 64 assert all(v in string.hexdigits for v in digest)