<commit_before>from plenum.test.pool_transactions.helper import sdk_add_new_nym_without_waiting
from stp_core.loop.eventually import eventually

from plenum.test.delayers import ppDelay, cDelay, pDelay

from plenum.test.stasher import delay_rules


def test_check_cdp_pp_storages(looper, txnPoolNodeSet, sdk_pool_handle, sdk_wallet_steward):
    def check_all_empty(replica, reverse=False):
        check_preprepared_empty(replica, reverse)
        check_prepared_empty(replica, reverse)

    def check_preprepared_empty(replica, reverse=False):
        statement_pp = bool(replica._consensus_data.preprepared)
        statement_pp ^= reverse
        assert not statement_pp

    def check_prepared_empty(replica, reverse=False):
        statement_p = bool(replica._consensus_data.prepared)
        statement_p ^= reverse
        assert not statement_p

    def operation_for_replicas(operation, node_set=txnPoolNodeSet, reverse=False):
        for node in node_set:
            operation(node.master_replica, reverse)

    node_stashers = [n.nodeIbStasher for n in txnPoolNodeSet]

    with delay_rules(node_stashers, cDelay()):
        with delay_rules(node_stashers, pDelay()):
            with delay_rules(node_stashers, ppDelay()):
                sdk_add_new_nym_without_waiting(looper, sdk_pool_handle, sdk_wallet_steward)
                looper.run(eventually(operation_for_replicas, check_all_empty, txnPoolNodeSet[1:]))
                looper.run(eventually(operation_for_replicas, check_preprepared_empty, txnPoolNodeSet[0:1], True))
            looper.run(eventually(operation_for_replicas, check_preprepared_empty, txnPoolNodeSet, True))
        looper.run(eventually(operation_for_replicas, check_prepared_empty, txnPoolNodeSet, True))
    looper.run(eventually(operation_for_replicas, check_all_empty, txnPoolNodeSet, True))<commit_msg>INDY-2137: fix test<commit_after>from plenum.test.pool_transactions.helper import sdk_add_new_nym_without_waiting
from stp_core.loop.eventually import eventually

from plenum.test.delayers import ppDelay, pDelay

from plenum.test.stasher import delay_rules


def test_check_cdp_pp_storages(looper, txnPoolNodeSet, sdk_pool_handle, sdk_wallet_steward):
    def check_all_empty(replica):
        assert not bool(replica._consensus_data.preprepared)
        assert not bool(replica._consensus_data.prepared)

    def check_preprepared_not_empty(replica):
        assert bool(replica._consensus_data.preprepared)

    def check_prepared_not_empty(replica):
        assert bool(replica._consensus_data.prepared)

    def operation_for_replicas(operation, node_set=txnPoolNodeSet):
        for node in node_set:
            operation(node.master_replica)

    node_stashers = [n.nodeIbStasher for n in txnPoolNodeSet]

    with delay_rules(node_stashers, pDelay()):
        with delay_rules(node_stashers, ppDelay()):
            sdk_add_new_nym_without_waiting(looper, sdk_pool_handle, sdk_wallet_steward)
            looper.run(eventually(operation_for_replicas, check_all_empty, txnPoolNodeSet[1:]))
            looper.run(eventually(operation_for_replicas, check_preprepared_not_empty, txnPoolNodeSet[0:1]))
        looper.run(eventually(operation_for_replicas, check_preprepared_not_empty, txnPoolNodeSet))
    looper.run(eventually(operation_for_replicas, check_prepared_not_empty, txnPoolNodeSet))
{'fraction_non_alphanumeric': 0.07375335921170499, 'fraction_numerical': 0.002985965959988056, 'mean_word_length': 4.866900175131349, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5101537', 'n_tokens_mistral': 1129, 'n_tokens_neox': 1119, 'n_words': 171}