def nonPrimaryReceivesCorrectNumberOfPREPREPAREs():
            """
            1. no of PRE-PREPARE received by non-primaries must be 1
            with zero faults in system, and 0 faults in system.
            """
            passes = 0
            for npr in nonPrimaryReplicas:
                l4 = len([
                    param for param in getAllArgs(
                        npr._ordering_service,
                        npr._ordering_service._add_to_pre_prepares)
                    if param['pp'].reqIdr[0] == propagated1.digest and
                    param['pp'].digest == OrderingService.generate_pp_digest([
                        propagated1.digest,
                    ], get_original_viewno(param['pp']), param['pp'].ppTime)
                ])

                numOfMsgsWithZFN = 1
                numOfMsgsWithFaults = 0

                passes += msgCountOK(nodesSize, faultyNodes, l4,
                                     numOfMsgsWithZFN, numOfMsgsWithFaults)

            assert passes >= len(nonPrimaryReplicas) - faultyNodes, \
                '2Non-primary receives correct number of pre-prepare -- {}'.format(passes)
        def primarySentsCorrectNumberOfPREPREPAREs():
            """
            1. no of PRE-PREPARE sent by primary is 1 with or without
            fault in system but, when primary is faulty no of sent PRE_PREPARE
             will be zero and primary must be marked as malicious.
            """
            actualMsgs = len([
                param for param in getAllArgs(
                    primary._ordering_service,
                    primary._ordering_service.send_pre_prepare)
                if param['ppReq'].reqIdr[0] == propagated1.digest
                and param['ppReq'].digest ==
                primary._ordering_service.generate_pp_digest(
                    [propagated1.digest], get_original_viewno(
                        param['ppReq']), param['ppReq'].ppTime)
            ])

            numOfMsgsWithZFN = 1

            # TODO: Considering, Primary is not faulty and will always send
            # PRE-PREPARE. Write separate test for testing when Primary
            # is faulty
            assert msgCountOK(nodesSize, faultyNodes, actualMsgs,
                              numOfMsgsWithZFN, numOfMsgsWithZFN
                              ), 'Primary sends correct number of per-prepare'
 def from_pre_prepare(pre_prepare, state_root, txn_root, primaries,
                      valid_digests):
     return ThreePcBatch(
         ledger_id=pre_prepare.ledgerId,
         inst_id=pre_prepare.instId,
         view_no=pre_prepare.viewNo,
         pp_seq_no=pre_prepare.ppSeqNo,
         pp_time=pre_prepare.ppTime,
         # do not trust PrePrepare's root hashes and use the current replica's ones
         state_root=state_root,
         txn_root=txn_root,
         primaries=primaries,
         valid_digests=valid_digests,
         has_audit_txn=f.AUDIT_TXN_ROOT_HASH.nm in pre_prepare
         and pre_prepare.auditTxnRootHash is not None,
         original_view_no=get_original_viewno(pre_prepare))
def test_pp_storages_ordering(pre_prepare, orderer: OrderingService):
    orderer.generate_pp_digest(pre_prepare.reqIdr,
                               get_original_viewno(pre_prepare),
                               pre_prepare.ppTime)