<commit_before>import pytest
from raet.raeting import AutoMode
from plenum.test.conftest import clientAndWallet1
from plenum.test.helper import *
from plenum.common.types import f, OP_FIELD_NAME, Request
# DEPR
# from plenum.persistence.wallet_storage_memory import WalletStorageMemory
from plenum.test.eventually import eventually
from plenum.common.util import getMaxFailures
from plenum.server.node import Node
from plenum.test.helper import NotConnectedToAny, \
    sendReqsToNodesAndVerifySuffReplies
from plenum.test.helper import TestNodeSet, randomOperation, \
    checkLastClientReqForNode, \
    getRepliesFromClientInbox
from plenum.test.helper import checkResponseCorrectnessFromNodes
from plenum.test.helper import sendRandomRequest, genTestClient, \
    checkSufficientRepliesRecvd, assertLength

nodeCount = 7

F = getMaxFailures(nodeCount)

whitelist = ['signer not configured so not signing',
             'for EmptySignature',
             'discarding message',
             'found legacy entry']  # warnings


def checkResponseRecvdFromNodes(client, expectedCount: int):
    respCount = 0
    sign = randomSeed()
    for (resp, nodeNm) in client.inBox:
        if resp.get(OP_FIELD_NAME) in (REQACK, REPLY):
            respCount += 1
            print(client, resp)
    assert respCount == expectedCount


# noinspection PyIncorrectDocstring
def testGeneratedRequestSequencing(tdir_for_func):
    """
    Request ids must be generated in an increasing order
    """
    with TestNodeSet(count=4, tmpdir=tdir_for_func) as nodeSet:
        w = Wallet("test", requestIdStore=TestRequestIdStore())
        w.addSigner()

        operation = randomOperation()

        request = w.signOp(operation)
        assert request.reqId == 1

        request = w.signOp(operation)
        assert request.reqId == 2

        request = w.signOp(randomOperation())
        assert request.reqId == 3

        s2 = w.addSigner()

        request = w.signOp(randomOperation(), s2.identifier)
        assert request.reqId == 1

        request = w.signOp(randomOperation())
        assert request.reqId == 4


# noinspection PyIncorrectDocstring
def testClientShouldNotBeAbleToConnectToNodesNodeStack(pool):
    """
    Client should not be able to connect to nodes in the node's nodestack
    """

    async def go(ctx):
        for n in ctx.nodeset:
            n.nodestack.keep.auto = AutoMode.never

        nodestacksVersion = {k: v.ha for k, v in ctx.nodeset.nodeReg.items()}
        client1, _ = genTestClient(nodeReg=nodestacksVersion, tmpdir=ctx.tmpdir)
        ctx.looper.add(client1)
        with pytest.raises(NotConnectedToAny):
            await client1.ensureConnectedToNodes()

    pool.run(go)


# noinspection PyIncorrectDocstring
def testSendRequestWithoutSignatureFails(pool):
    """
    A client request sent without a signature fails with an EmptySignature
    exception
    """

    async def go(ctx):
        client1, wallet = genTestClient(ctx.nodeset, tmpdir=ctx.tmpdir)

        # remove the client's ability to sign
        assert wallet._getIdData().signer
        wallet._getIdData().signer = None
        assert not wallet._getIdData().signer
<commit_msg>update testSendRequestWithoutSignatureFails test to make it not use removed wallet method _getIdData<commit_after>import pytest
from raet.raeting import AutoMode
from plenum.test.conftest import clientAndWallet1
from plenum.test.helper import *
from plenum.common.types import f, OP_FIELD_NAME, Request
# DEPR
# from plenum.persistence.wallet_storage_memory import WalletStorageMemory
from plenum.test.eventually import eventually
from plenum.common.util import getMaxFailures
from plenum.server.node import Node
from plenum.test.helper import NotConnectedToAny, \
    sendReqsToNodesAndVerifySuffReplies
from plenum.test.helper import TestNodeSet, randomOperation, \
    checkLastClientReqForNode, \
    getRepliesFromClientInbox
from plenum.test.helper import checkResponseCorrectnessFromNodes
from plenum.test.helper import sendRandomRequest, genTestClient, \
    checkSufficientRepliesRecvd, assertLength

nodeCount = 7

F = getMaxFailures(nodeCount)

whitelist = ['signer not configured so not signing',
             'for EmptySignature',
             'discarding message',
             'found legacy entry']  # warnings


def checkResponseRecvdFromNodes(client, expectedCount: int):
    respCount = 0
    sign = randomSeed()
    for (resp, nodeNm) in client.inBox:
        if resp.get(OP_FIELD_NAME) in (REQACK, REPLY):
            respCount += 1
            print(client, resp)
    assert respCount == expectedCount


# noinspection PyIncorrectDocstring
def testGeneratedRequestSequencing(tdir_for_func):
    """
    Request ids must be generated in an increasing order
    """
    with TestNodeSet(count=4, tmpdir=tdir_for_func) as nodeSet:
        w = Wallet("test", requestIdStore=TestRequestIdStore())
        w.addSigner()

        operation = randomOperation()

        request = w.signOp(operation)
        assert request.reqId == 1

        request = w.signOp(operation)
        assert request.reqId == 2

        request = w.signOp(randomOperation())
        assert request.reqId == 3

        s2 = w.addSigner()

        request = w.signOp(randomOperation(), s2.identifier)
        assert request.reqId == 1

        request = w.signOp(randomOperation())
        assert request.reqId == 4


# noinspection PyIncorrectDocstring
def testClientShouldNotBeAbleToConnectToNodesNodeStack(pool):
    """
    Client should not be able to connect to nodes in the node's nodestack
    """

    async def go(ctx):
        for n in ctx.nodeset:
            n.nodestack.keep.auto = AutoMode.never

        nodestacksVersion = {k: v.ha for k, v in ctx.nodeset.nodeReg.items()}
        client1, _ = genTestClient(nodeReg=nodestacksVersion, tmpdir=ctx.tmpdir)
        ctx.looper.add(client1)
        with pytest.raises(NotConnectedToAny):
            await client1.ensureConnectedToNodes()

    pool.run(go)


# noinspection PyIncorrectDocstring
def testSendRequestWithoutSignatureFails(pool):
    """
    A client request sent without a signature fails with an EmptySignature
    exception
    """

    async def go(ctx):
        client1, wallet = genTestClient(ctx.nodeset, tmpdir=ctx.tmpdir)

        # remove the client's ability to sign
        assert wallet.defaultId
        wallet.defaultId = None
        assert not wallet.defaultId

{'fraction_non_alphanumeric': 0.07855031886763104, 'fraction_numerical': 0.004977445948047908, 'mean_word_length': 3.3067649028801074, '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': '1190788', 'n_tokens_mistral': 1885, 'n_tokens_neox': 1854, 'n_words': 479}