def test_checkpoints_removed_on_master_replica_after_catchup_during_view_change(chkFreqPatched, txnPoolNodeSet, view_change_in_progress, clear_checkpoints):
    master_replicas = getAllReplicas(txnPoolNodeSet, 0)
    replica = master_replicas[(- 1)]
    others = master_replicas[:(- 1)]
    node = replica.node
    node.master_replica.last_ordered_3pc = (2, 12)
    replica._checkpointer._checkpoint_state[(6, 10)] = CheckpointState(seqNo=10, digests=[], digest=cp_digest(6, 10), receivedDigests={r.name: cp_digest(6, 10) for r in others}, isStable=True)
    replica._checkpointer._checkpoint_state[(11, 15)] = CheckpointState(seqNo=12, digests=['digest-11', 'digest-12'], digest=None, receivedDigests={}, isStable=False)
    replica._checkpointer._stashed_recvd_checkpoints[2] = {}
    replica._checkpointer._stashed_recvd_checkpoints[2][(11, 15)] = {}
    for r in others:
        replica._checkpointer._stashed_recvd_checkpoints[2][(11, 15)][r.name] = Checkpoint(instId=0, viewNo=2, seqNoStart=11, seqNoEnd=15, digest=cp_digest(11, 15))
    replica._checkpointer._stashed_recvd_checkpoints[2][(16, 20)] = {}
    for r in others:
        replica._checkpointer._stashed_recvd_checkpoints[2][(16, 20)][r.name] = Checkpoint(instId=0, viewNo=2, seqNoStart=16, seqNoEnd=20, digest=cp_digest(16, 20))
    replica._checkpointer._stashed_recvd_checkpoints[2][(21, 25)] = {}
    replica._checkpointer._stashed_recvd_checkpoints[2][(21, 25)][others[0].name] = Checkpoint(instId=0, viewNo=2, seqNoStart=21, seqNoEnd=25, digest=cp_digest(21, 25))
    node.ledgerManager.last_caught_up_3PC = (2, 20)
    audit_ledger = node.getLedger(AUDIT_LEDGER_ID)
    txn_with_last_seq_no = {'txn': {'data': {AUDIT_TXN_VIEW_NO: 2, AUDIT_TXN_PP_SEQ_NO: 20, AUDIT_TXN_PRIMARIES: ['Gamma', 'Delta']}}}
    audit_ledger.get_last_committed_txn = (lambda *args: txn_with_last_seq_no)
    node.allLedgersCaughtUp()
    assert (len(replica._checkpointer._checkpoint_state) == 0)
    assert (len(replica._checkpointer._stashed_recvd_checkpoints) == 1)
    assert (2 in replica._checkpointer._stashed_recvd_checkpoints)
    assert (len(replica._checkpointer._stashed_recvd_checkpoints[2]) == 1)
    assert ((21, 25) in replica._checkpointer._stashed_recvd_checkpoints[2])
    assert (len(replica._checkpointer._stashed_recvd_checkpoints[2][(21, 25)]) == 1)
def test_checkpoints_removed_on_master_replica_after_catchup_during_view_change(chkFreqPatched, txnPoolNodeSet, view_change_in_progress, clear_checkpoints):
    master_replicas = getAllReplicas(txnPoolNodeSet, 0)
    replica = master_replicas[(- 1)]
    others = master_replicas[:(- 1)]
    node = replica.node
    node.master_replica.last_ordered_3pc = (2, 12)
    replica._checkpointer._checkpoint_state[(6, 10)] = CheckpointState(seqNo=10, digests=[], digest=cp_digest(6, 10), receivedDigests={r.name: cp_digest(6, 10) for r in others}, isStable=True)
    replica._checkpointer._checkpoint_state[(11, 15)] = CheckpointState(seqNo=12, digests=['digest-11', 'digest-12'], digest=None, receivedDigests={}, isStable=False)
    replica._checkpointer._stashed_recvd_checkpoints[2] = {}
    replica._checkpointer._stashed_recvd_checkpoints[2][(11, 15)] = {}
    for r in others:
        replica._checkpointer._stashed_recvd_checkpoints[2][(11, 15)][r.name] = Checkpoint(instId=0, viewNo=2, seqNoStart=11, seqNoEnd=15, digest=cp_digest(11, 15))
    replica._checkpointer._stashed_recvd_checkpoints[2][(16, 20)] = {}
    for r in others:
        replica._checkpointer._stashed_recvd_checkpoints[2][(16, 20)][r.name] = Checkpoint(instId=0, viewNo=2, seqNoStart=16, seqNoEnd=20, digest=cp_digest(16, 20))
    replica._checkpointer._stashed_recvd_checkpoints[2][(21, 25)] = {}
    replica._checkpointer._stashed_recvd_checkpoints[2][(21, 25)][others[0].name] = Checkpoint(instId=0, viewNo=2, seqNoStart=21, seqNoEnd=25, digest=cp_digest(21, 25))
    node.ledgerManager.last_caught_up_3PC = (2, 20)
    audit_ledger = node.getLedger(AUDIT_LEDGER_ID)
    txn_with_last_seq_no = {'txn': {'data': {AUDIT_TXN_VIEW_NO: 2, AUDIT_TXN_PP_SEQ_NO: 20, AUDIT_TXN_PRIMARIES: ['Gamma', 'Delta']}}}
    audit_ledger.get_last_committed_txn = (lambda *args: txn_with_last_seq_no)
    node.allLedgersCaughtUp()
    assert (len(replica._checkpointer._checkpoint_state) == 0)
    assert (len(replica._checkpointer._stashed_recvd_checkpoints) == 1)
    assert (2 in replica._checkpointer._stashed_recvd_checkpoints)
    assert (len(replica._checkpointer._stashed_recvd_checkpoints[2]) == 1)
    assert ((21, 25) in replica._checkpointer._stashed_recvd_checkpoints[2])
    assert (len(replica._checkpointer._stashed_recvd_checkpoints[2][(21, 25)]) == 1)