<commit_before>import time
from functools import partial

import pytest

from stp_core.loop.eventually import eventually
from plenum.common.types import Nomination, PrePrepare
from plenum.common.util import randomString
from plenum.common.constants import DOMAIN_LEDGER_ID
from plenum.test.helper import checkDiscardMsg
from plenum.test.view_change.helper import ensure_view_change
from plenum.test.node_catchup.helper import waitNodeDataEquality
from plenum.test.pool_transactions.helper import addNewStewardAndNode
from plenum.test.test_node import checkNodesConnected, \
    checkProtocolInstanceSetup, getPrimaryReplica
from plenum.test import waits


whitelist = ['found legacy entry']  # warnings

def testNodeDiscardMessageFromUnknownView(txnPoolNodeSet,
                                          nodeSetWithNodeAddedAfterSomeTxns,
                                          newNodeCaughtUp, tdirWithPoolTxns,
                                          tconf, allPluginsPath):
    """
    Node discards 3-phase and election messages from view nos that it does not
    know of (view nos before it joined the pool)
    :return:
    """
    looper, nodeX, client, wallet, _, _ = nodeSetWithNodeAddedAfterSomeTxns
    viewNo = nodeX.viewNo

    # Force two view changes: node discards msgs which have viewNo
    # at least two less than node's. Current protocol implementation
    # needs to hold messages from the previous view as well as
    # from the current view.
    ensure_view_change(looper, txnPoolNodeSet, client, wallet)
    ensure_view_change(looper, txnPoolNodeSet, client, wallet)

    newStewardName = "testClientSteward" + randomString(3)
    nodeName = "Theta"
    _, _, nodeTheta = addNewStewardAndNode(looper, client,
                                           wallet,
                                           newStewardName,
                                           nodeName,
                                           tdirWithPoolTxns, tconf,
                                           allPluginsPath)
    txnPoolNodeSet.append(nodeTheta)
    looper.run(checkNodesConnected(txnPoolNodeSet))
    looper.run(client.ensureConnectedToNodes())
    waitNodeDataEquality(looper, nodeTheta, *txnPoolNodeSet[:-1])
    checkProtocolInstanceSetup(looper, txnPoolNodeSet, retryWait=1)
    electMsg = Nomination(nodeX.name, 0, viewNo,
                          nodeX.replicas[0].lastOrderedPPSeqNo[1])
<commit_msg>use correct signature of helper method<commit_after>import time
from functools import partial

import pytest

from stp_core.loop.eventually import eventually
from plenum.common.types import Nomination, PrePrepare
from plenum.common.util import randomString
from plenum.common.constants import DOMAIN_LEDGER_ID
from plenum.test.helper import checkDiscardMsg
from plenum.test.view_change.helper import ensure_view_change
from plenum.test.node_catchup.helper import waitNodeDataEquality
from plenum.test.pool_transactions.helper import addNewStewardAndNode
from plenum.test.test_node import checkNodesConnected, \
    checkProtocolInstanceSetup, getPrimaryReplica
from plenum.test import waits


whitelist = ['found legacy entry']  # warnings

def testNodeDiscardMessageFromUnknownView(txnPoolNodeSet,
                                          nodeSetWithNodeAddedAfterSomeTxns,
                                          newNodeCaughtUp, tdirWithPoolTxns,
                                          tconf, allPluginsPath):
    """
    Node discards 3-phase and election messages from view nos that it does not
    know of (view nos before it joined the pool)
    :return:
    """
    looper, nodeX, client, wallet, _, _ = nodeSetWithNodeAddedAfterSomeTxns
    viewNo = nodeX.viewNo

    # Force two view changes: node discards msgs which have viewNo
    # at least two less than node's. Current protocol implementation
    # needs to hold messages from the previous view as well as
    # from the current view.
    ensure_view_change(looper, txnPoolNodeSet)
    ensure_view_change(looper, txnPoolNodeSet)

    newStewardName = "testClientSteward" + randomString(3)
    nodeName = "Theta"
    _, _, nodeTheta = addNewStewardAndNode(looper, client,
                                           wallet,
                                           newStewardName,
                                           nodeName,
                                           tdirWithPoolTxns, tconf,
                                           allPluginsPath)
    txnPoolNodeSet.append(nodeTheta)
    looper.run(checkNodesConnected(txnPoolNodeSet))
    looper.run(client.ensureConnectedToNodes())
    waitNodeDataEquality(looper, nodeTheta, *txnPoolNodeSet[:-1])
    checkProtocolInstanceSetup(looper, txnPoolNodeSet, retryWait=1)
    electMsg = Nomination(nodeX.name, 0, viewNo,
                          nodeX.replicas[0].lastOrderedPPSeqNo[1])

{'fraction_non_alphanumeric': 0.057767691355477616, 'fraction_numerical': 0.0028883845677738808, 'mean_word_length': 2.5335276967930027, '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': 32, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6712859', 'n_tokens_mistral': 1270, 'n_tokens_neox': 1261, 'n_words': 327}