diff --git a/plenum/client/client.py b/plenum/client/client.py index d6ee701de0..57072dad81 100644 --- a/plenum/client/client.py +++ b/plenum/client/client.py @@ -5,6 +5,7 @@ """ import copy +import json import os import random import time diff --git a/plenum/common/constants.py b/plenum/common/constants.py index 6e6343eee0..ff3813f8b5 100644 --- a/plenum/common/constants.py +++ b/plenum/common/constants.py @@ -118,6 +118,7 @@ STEWARD = Roles.STEWARD.value TRUSTEE = Roles.TRUSTEE.value STEWARD_STRING = 'STEWARD' +TRUSTEE_STRING = 'TRUSTEE' # TXNs NODE = PlenumTransactions.NODE.value diff --git a/plenum/test/batching_3pc/helper.py b/plenum/test/batching_3pc/helper.py index 4def1d28df..cd67489980 100644 --- a/plenum/test/batching_3pc/helper.py +++ b/plenum/test/batching_3pc/helper.py @@ -6,8 +6,6 @@ from plenum.common.txn_util import reqToTxn from plenum.common.messages.node_messages import ThreePhaseType from plenum.common.util import check_if_all_equal_in_list -from plenum.test.helper import waitForSufficientRepliesForRequests, \ - send_signed_requests def checkNodesHaveSameRoots(nodes, checkUnCommitted=True, @@ -58,12 +56,6 @@ def addRoot(root, collection): assert len(txnRoots) == 1 -def send_and_check(signed_reqs, looper, txnPoolNodeSet, client): - reqs = send_signed_requests(client, signed_reqs) - waitForSufficientRepliesForRequests(looper, client, requests=reqs) - checkNodesHaveSameRoots(txnPoolNodeSet) - - def add_txns_to_ledger_before_order(replica, reqs): added = False origMethod = replica.tryOrder diff --git a/plenum/test/blacklist/test_blacklist_client.py b/plenum/test/blacklist/test_blacklist_client.py index b35d3ce784..2599f0c338 100644 --- a/plenum/test/blacklist/test_blacklist_client.py +++ b/plenum/test/blacklist/test_blacklist_client.py @@ -1,26 +1,37 @@ +import json + import pytest +from plenum.common.constants import CURRENT_PROTOCOL_VERSION +from plenum.common.exceptions import RequestNackedException +from plenum.test.helper import sdk_random_request_objects, sdk_send_signed_requests, \ + sdk_get_and_check_replies from stp_core.loop.eventually import eventually from plenum.test import waits -from plenum.test.malicious_behaviors_client import makeClientFaulty, \ - sendsUnsignedRequest - - -@pytest.fixture(scope="module") -def setup(client1): - makeClientFaulty(client1, sendsUnsignedRequest) # noinspection PyIncorrectDocstring,PyUnusedLocal,PyShadowingNames -def testDoNotBlacklistClient(setup, looper, txnPoolNodeSet, client1, sent1): +def testDoNotBlacklistClient(looper, txnPoolNodeSet, + sdk_wallet_client, sdk_pool_handle, + poolTxnClientNames): """ Client should be not be blacklisted by node on sending an unsigned request """ - + client_name = poolTxnClientNames[0] + _, did = sdk_wallet_client # No node should blacklist the client + req_obj = sdk_random_request_objects(1, identifier=did, + protocol_version=CURRENT_PROTOCOL_VERSION)[0] + + reqs = sdk_send_signed_requests(sdk_pool_handle, [json.dumps(req_obj.as_dict)]) + + with pytest.raises(RequestNackedException) as e: + sdk_get_and_check_replies(looper, reqs) + assert 'MissingSignature' in e._excinfo[1].args[0] + def chk(): for node in txnPoolNodeSet: - assert not node.isClientBlacklisted(client1.name) + assert not node.isClientBlacklisted(client_name) timeout = waits.expectedClientToPoolConnectionTimeout(len(txnPoolNodeSet)) looper.run(eventually(chk, retryWait=1, timeout=timeout)) diff --git a/plenum/test/bls/helper.py b/plenum/test/bls/helper.py index b7f20a9dbf..77a0126d4a 100644 --- a/plenum/test/bls/helper.py +++ b/plenum/test/bls/helper.py @@ -7,15 +7,15 @@ from crypto.bls.bls_multi_signature import MultiSignatureValue from state.pruning_state import PruningState from common.serializers.serialization import state_roots_serializer, proof_nodes_serializer -from plenum.common.constants import DOMAIN_LEDGER_ID, ALIAS, BLS_KEY, STATE_PROOF, TXN_TYPE, MULTI_SIGNATURE, \ +from plenum.common.constants import DOMAIN_LEDGER_ID, STATE_PROOF, TXN_TYPE, MULTI_SIGNATURE, \ MULTI_SIGNATURE_PARTICIPANTS, MULTI_SIGNATURE_SIGNATURE, MULTI_SIGNATURE_VALUE from plenum.common.keygen_utils import init_bls_keys from plenum.common.messages.node_messages import Commit, Prepare, PrePrepare -from plenum.common.util import get_utc_epoch, randomString, random_from_alphabet, hexToFriendly -from plenum.test.helper import sendRandomRequests, waitForSufficientRepliesForRequests, sdk_send_random_and_check -from plenum.test.node_catchup.helper import waitNodeDataEquality, ensureClientConnectedToNodesAndPoolLedgerSame +from plenum.common.util import get_utc_epoch, randomString, hexToFriendly +from plenum.test.helper import sdk_send_random_and_check from plenum.test.node_request.helper import sdk_ensure_pool_functional -from plenum.test.pool_transactions.helper import updateNodeData, sdk_send_update_node, \ +from plenum.test.node_catchup.helper import waitNodeDataEquality +from plenum.test.pool_transactions.helper import sdk_send_update_node, \ sdk_pool_refresh from stp_core.common.log import getlogger @@ -65,45 +65,6 @@ def sdk_check_bls_multi_sig_after_send(looper, txnPoolNodeSet, assert multi_sigs.count(multi_sigs[0]) == len(multi_sigs) -def sdk_check_bls_multi_sig_after_send(looper, txnPoolNodeSet, - sdk_pool_handle, sdk_wallet_handle, - saved_multi_sigs_count): - # at least two because first request could have no - # signature since state can be clear - number_of_requests = 3 - - # 1. send requests - # Using loop to avoid 3pc batching - state_roots = [] - for i in range(number_of_requests): - sdk_send_random_and_check(looper, txnPoolNodeSet, sdk_pool_handle, - sdk_wallet_handle, 1) - waitNodeDataEquality(looper, txnPoolNodeSet[0], *txnPoolNodeSet[:-1]) - state_roots.append( - state_roots_serializer.serialize( - bytes(txnPoolNodeSet[0].getState(DOMAIN_LEDGER_ID).committedHeadHash))) - - # 2. get all saved multi-sigs - multi_sigs_for_batch = [] - for state_root in state_roots: - multi_sigs = [] - for node in txnPoolNodeSet: - multi_sig = node.bls_bft.bls_store.get(state_root) - if multi_sig: - multi_sigs.append(multi_sig) - multi_sigs_for_batch.append(multi_sigs) - - # 3. check how many multi-sigs are saved - for multi_sigs in multi_sigs_for_batch: - assert len(multi_sigs) == saved_multi_sigs_count, \ - "{} != {}".format(len(multi_sigs), saved_multi_sigs_count) - - # 3. check that bls multi-sig is the same for all nodes we get PrePrepare for (that is for all expect the last one) - for multi_sigs in multi_sigs_for_batch[:-1]: - if multi_sigs: - assert multi_sigs.count(multi_sigs[0]) == len(multi_sigs) - - def process_commits_for_key(key, pre_prepare, bls_bfts): for sender_bls_bft in bls_bfts: commit = create_commit_bls_sig( @@ -203,29 +164,6 @@ def create_prepare(req_key, state_root): return Prepare(*params) -def change_bls_key(looper, txnPoolNodeSet, - node, - steward_client, steward_wallet, - add_wrong=False): - new_blspk = init_bls_keys(node.keys_dir, node.name) - - key_in_txn = \ - new_blspk \ - if not add_wrong \ - else ''.join(random_from_alphabet(32, base58.alphabet)) - - node_data = { - ALIAS: node.name, - BLS_KEY: key_in_txn - } - - updateNodeData(looper, steward_client, steward_wallet, node, node_data) - waitNodeDataEquality(looper, node, *txnPoolNodeSet[:-1]) - ensureClientConnectedToNodesAndPoolLedgerSame(looper, steward_client, - *txnPoolNodeSet) - return new_blspk - - def sdk_change_bls_key(looper, txnPoolNodeSet, node, sdk_pool_handle, diff --git a/plenum/test/bls/test_bls_key_registry_pool_manager.py b/plenum/test/bls/test_bls_key_registry_pool_manager.py index d305ccfc81..ae1fb0f83f 100644 --- a/plenum/test/bls/test_bls_key_registry_pool_manager.py +++ b/plenum/test/bls/test_bls_key_registry_pool_manager.py @@ -1,10 +1,9 @@ import base58 import pytest from plenum.bls.bls_key_register_pool_manager import BlsKeyRegisterPoolManager -from plenum.common.constants import NODE, TXN_TYPE, BLS_KEY, DATA, ALIAS +from plenum.common.constants import NODE, TXN_TYPE, BLS_KEY, DATA from plenum.common.util import randomString from plenum.test.bls.helper import sdk_change_bls_key -from plenum.test.pool_transactions.helper import updateNodeData nodeCount = 4 @@ -83,17 +82,3 @@ def test_get_key_for_old_root_keys_changed(bls_key_register_ledger, new_pool_root_hash) assert bls_key assert bls_key == new_bls_key - - -def change_bls_keys(new_bls_key, node, - looper, client, wallet): - node_data = { - ALIAS: node.name, - BLS_KEY: new_bls_key - } - updateNodeData(looper, - client, - wallet, - node, - node_data) - return diff --git a/plenum/test/checkpoints/test_checkpoint_stabilization_after_catchup.py b/plenum/test/checkpoints/test_checkpoint_stabilization_after_catchup.py index 0e35fc1eb2..65cd81aee2 100644 --- a/plenum/test/checkpoints/test_checkpoint_stabilization_after_catchup.py +++ b/plenum/test/checkpoints/test_checkpoint_stabilization_after_catchup.py @@ -9,8 +9,8 @@ def test_second_checkpoint_after_catchup_can_be_stabilized( - chkFreqPatched, looper, txnPoolNodeSet, steward1, sdk_wallet_steward, - sdk_wallet_client, sdk_pool_handle, tdir, client_tdir, tconf, + chkFreqPatched, looper, txnPoolNodeSet, sdk_wallet_steward, + sdk_wallet_client, sdk_pool_handle, tdir, tconf, allPluginsPath): _, new_node = sdk_add_new_steward_and_node( looper, sdk_pool_handle, sdk_wallet_steward, diff --git a/plenum/test/cli/helper.py b/plenum/test/cli/helper.py index aa94017932..a5b57890dd 100644 --- a/plenum/test/cli/helper.py +++ b/plenum/test/cli/helper.py @@ -17,10 +17,8 @@ from stp_core.common.util import Singleton from stp_core.loop.eventually import eventually from stp_core.common.log import getlogger -from plenum.common.util import getMaxFailures from plenum.test.cli.mock_output import MockOutput from plenum.test.cli.test_keyring import createNewKeyring -from plenum.test.helper import waitForSufficientRepliesForRequests from plenum.test.spy_helpers import getAllArgs from plenum.test.test_client import TestClient from plenum.test.test_node import TestNode, checkPoolReady @@ -28,8 +26,6 @@ from pygments.token import Token from functools import partial from plenum.test import waits -from plenum.common import util -from plenum.common.request import Request logger = getlogger() @@ -255,52 +251,6 @@ def createClientAndConnect(cli, nodeNames, clientName): waitClientConnected(cli, nodeNames, clientName) -def checkRequest(cli, operation): - cName = "Joe" - cli.enterCmd("new client {}".format(cName)) - # Let client connect to the nodes - - nodeNames = list(cli.nodes.keys()) - waitClientConnected(cli, nodeNames, cName) - - # Send request to all nodes - - createNewKeyring(cName, cli) - - cli.enterCmd("new key {}".format("testkey1")) - assert 'Key created in wallet {}'.format(cName) in cli.lastCmdOutput - - cli.enterCmd('client {} send {}'.format(cName, operation)) - client = cli.clients[cName] - wallet = cli.wallets[cName] # type: Wallet - # Ensure client gets back the replies - lastReqId = client.reqRepStore.lastReqId - - request = Request(identifier=wallet.defaultId, - reqId=lastReqId, - protocolVersion=CURRENT_PROTOCOL_VERSION) - - waitForSufficientRepliesForRequests(cli.looper, client, - requests=[request]) - - txn, status = client.getReply(wallet.defaultId, lastReqId) - - # Ensure the cli shows appropriate output - cli.enterCmd('client {} show {}'.format(cName, lastReqId)) - printeds = cli.printeds - printedReply = printeds[1] - printedStatus = printeds[0] - # txnTimePattern = "'txnTime', \d+\.*\d*" - # txnIdPattern = "'txnId', '" + txn['txnId'] + "'" - txnTimePattern = "\'txnTime\': \d+\.*\d*" - # DEPR - # txnIdPattern = "\'txnId\': '" + txn['txnId'] + "'" - # assert re.search(txnIdPattern, printedReply['msg']) - assert re.search(txnTimePattern, printedReply['msg']) - assert printedStatus['msg'] == "Status: {}".format(status) - return client, wallet - - def newCLI(looper, basedir, ledger_base_dir, cliClass=TestCli, nodeClass=TestNode, @@ -681,7 +631,6 @@ def restartCliAndAssert(cli, do, expectedRestoredWalletName, assert len(cli._activeWallet.identifiers) == expectedIdentifiers - def _newStewardsAddedByName(cli): cli.enterCmd( "add genesis transaction {nym} for 59d9225473451efffe6b36dbcaefdbf7b1895de62084509a7f5b58bf01d06418 role={role}".format( @@ -705,7 +654,6 @@ def _newStewardsAddedByValue(cli): nym=NYM, role=Roles.STEWARD.name)) - def _newNodesAddedByName(cli): cli.enterCmd( 'add genesis transaction {node} for 59d9225473451efffe6b36dbcaefdbf7b1895de62084509a7f5b58bf01d06418 by 59d9225473451efffe6b36dbcaefdbf7b1895de62084509a7f5b58bf01d06418 with data ' diff --git a/plenum/test/cli/test_client_request.py b/plenum/test/cli/test_client_request.py deleted file mode 100644 index 775cb4a22f..0000000000 --- a/plenum/test/cli/test_client_request.py +++ /dev/null @@ -1,9 +0,0 @@ -from plenum.test.cli.helper import checkRequest - - -def testClientRequest(cli, validNodeNames, createAllNodes): - """ - Test client sending request and checking reply and status - """ - operation = '{"amount": 12, "type": "buy"}' - checkRequest(cli, operation) diff --git a/plenum/test/cli/test_log_filtering.py b/plenum/test/cli/test_log_filtering.py deleted file mode 100644 index 60bcda3762..0000000000 --- a/plenum/test/cli/test_log_filtering.py +++ /dev/null @@ -1,30 +0,0 @@ -import types - -from plenum.common.constants import CURRENT_PROTOCOL_VERSION -from plenum.test.cli.helper import checkRequest -from plenum.test.helper import waitForSufficientRepliesForRequests -from plenum.common.request import Request - - -def testLogFiltering(cli, validNodeNames, createAllNodes): - msg = '{"amount": 20, "type": "buy"}' - client, wallet = checkRequest(cli, msg) - - x = client.handleOneNodeMsg - - def handleOneNodeMsg(self, wrappedMsg, excludeFromCli=None): - return x(wrappedMsg, excludeFromCli=True) - - client.handleOneNodeMsg = types.MethodType(handleOneNodeMsg, client) - client.nodestack.msgHandler = client.handleOneNodeMsg - msg = '{"amount": 30, "type": "buy"}' - cli.enterCmd('client {} send {}'.format(client.name, msg)) - - lastRequestId = client.reqRepStore.lastReqId - request = Request(identifier=wallet.defaultId, - reqId=lastRequestId, - protocolVersion=CURRENT_PROTOCOL_VERSION) - waitForSufficientRepliesForRequests(cli.looper, client, - requests=[request]) - - assert "got msg from node" not in cli.lastCmdOutput diff --git a/plenum/test/client/conftest.py b/plenum/test/client/conftest.py index ce56e5d181..31d54d8220 100644 --- a/plenum/test/client/conftest.py +++ b/plenum/test/client/conftest.py @@ -2,6 +2,7 @@ from plenum.test.conftest import getValueFromModule from plenum.client.client import Client +from plenum.test.helper import sdk_json_to_request_object from plenum.test.malicious_behaviors_client import makeClientFaulty @@ -16,4 +17,5 @@ def passThroughReqAcked1(sent1): # Overriding reqAcked1 in conftest.py to do nothing because the client # shouldn't see ReqAck msgs from all the nodes, since it only sent REQUESTs # to some. - return sent1 + request = sdk_json_to_request_object(sent1[0][0]) + return request diff --git a/plenum/test/client/test_client.py b/plenum/test/client/test_client.py index 6fac1f3c0f..8dabcd3744 100644 --- a/plenum/test/client/test_client.py +++ b/plenum/test/client/test_client.py @@ -6,28 +6,18 @@ from stp_core.loop.eventually import eventually from plenum.common.exceptions import MissingSignature from stp_core.common.log import getlogger -from plenum.common.constants import OP_FIELD_NAME, REQACK from plenum.common.types import f from plenum.server.node import Node from plenum.test import waits from plenum.test.helper import \ - checkLastClientReqForNode, getRepliesFromClientInbox, \ - waitForSufficientRepliesForRequests, assertLength, \ - sdk_signed_random_requests, sdk_send_signed_requests, \ - sdk_json_to_request_object + checkLastClientReqForNode, sdk_signed_random_requests, \ + sdk_send_signed_requests, sdk_json_to_request_object, \ + sdk_get_and_check_replies, sdk_send_random_request nodeCount = 7 F = getMaxFailures(nodeCount) -whitelist = ['signer not configured so not signing', - 'for EmptySignature', - 'discarding message', - 'found legacy entry', - 'public key from disk', - 'verification key from disk', - 'got error while verifying message'] # warnings - logger = getlogger() @@ -84,46 +74,13 @@ def testRequestFullRoundTrip(replied1, client1): # noinspection PyIncorrectDocstring -def testEveryNodeRepliesWithNoFaultyNodes(looper, client1, replied1): - """ - Every node will send a reply to the client when there are no faulty nodes in - the system - """ - - def chk(): - receivedReplies = getRepliesFromClientInbox(client1.inBox, - replied1.reqId) - print(receivedReplies) - assert len(receivedReplies) == nodeCount - - looper.run(eventually(chk)) - - -# noinspection PyIncorrectDocstring -def testReplyWhenRequestAlreadyExecuted(looper, txnPoolNodeSet, client1, sent1): +def testReplyWhenRequestAlreadyExecuted(looper, txnPoolNodeSet, sdk_pool_handle, + sdk_wallet_client, sent1): """ When a request has already been executed the previously executed reply will be sent again to the client. An acknowledgement will not be sent for a repeated request. """ - waitForSufficientRepliesForRequests(looper, client1, requests=[sent1]) - - originalRequestResponsesLen = nodeCount * 2 - duplicateRequestRepliesLen = nodeCount # for a duplicate request we need to - - message_parts, err_msg = \ - client1.nodestack.prepare_for_sending(sent1, None) - - for part in message_parts: - client1.nodestack._enqueueIntoAllRemotes(part, None) - - def chk(): - assertLength([response for response in client1.inBox - if (response[0].get(f.RESULT.nm) and - response[0][f.RESULT.nm][f.REQ_ID.nm] == sent1.reqId) or - (response[0].get(OP_FIELD_NAME) == REQACK and - response[0].get(f.REQ_ID.nm) == sent1.reqId)], - originalRequestResponsesLen + duplicateRequestRepliesLen) - - responseTimeout = waits.expectedTransactionExecutionTime(nodeCount) - looper.run(eventually(chk, retryWait=1, timeout=responseTimeout)) + sdk_get_and_check_replies(looper, sent1) + req = sdk_send_random_request(looper, sdk_pool_handle, sdk_wallet_client) + sdk_get_and_check_replies(looper, [req]) diff --git a/plenum/test/client/test_client_request_nack.py b/plenum/test/client/test_client_request_nack.py index 2f4ca3e445..23e8cef023 100644 --- a/plenum/test/client/test_client_request_nack.py +++ b/plenum/test/client/test_client_request_nack.py @@ -20,14 +20,6 @@ def restrictiveVerifier(txnPoolNodeSet): n.opVerifiers = [TestVerifier()] -@pytest.fixture(scope="module") -def request1(wallet1): - op = {"type": "buy", - "amount": 999} - req = wallet1.signOp(op) - return req - - @pytest.mark.skip(reason="old style plugin") def testRequestFullRoundTrip(restrictiveVerifier, sdk_pool_handle, diff --git a/plenum/test/client/test_client_resends_not_confirmed_request.py b/plenum/test/client/test_client_resends_not_confirmed_request.py deleted file mode 100644 index b5c09ac2f0..0000000000 --- a/plenum/test/client/test_client_resends_not_confirmed_request.py +++ /dev/null @@ -1,50 +0,0 @@ -import random - -from stp_core.common.log import getlogger -from plenum.test.client.conftest import passThroughReqAcked1 -from plenum.test.helper import send_signed_requests, \ - waitForSufficientRepliesForRequests -from plenum.test.malicious_behaviors_client import \ - genDoesntSendRequestToSomeNodes - -logger = getlogger() - -nodeCount = 4 -clientFault = genDoesntSendRequestToSomeNodes("AlphaC") -reqAcked1 = passThroughReqAcked1 -nodes_with_bls = 0 - - -def test_client_resends_not_confirmed_request(looper, - client1, - wallet1, - txnPoolNodeSet): - """ - Check that client resends request to all nodes if it was previously sent - to one node but reply cannot be verified - """ - client = client1 - wallet = wallet1 - - initial_submit_count = client.spylog.count(client.submitReqs) - initial_resent_count = client.spylog.count(client.resendRequests) - - def sign_and_send(op): - signed = wallet.signOp(op) - return send_signed_requests(client, [signed]) - - buy = {'type': 'buy', 'amount': random.randint(10, 100)} - requests = sign_and_send(buy) - waitForSufficientRepliesForRequests(looper, client, requests=requests) - - buy = {'type': 'get_buy'} - client._read_only_requests.add('get_buy') - requests = sign_and_send(buy) - waitForSufficientRepliesForRequests(looper, client, requests=requests) - - # submitReqs should be called twice: first for but and then got get_buy - assert initial_submit_count + 2 == \ - client.spylog.count(client.submitReqs) - - assert initial_resent_count + 1 == \ - client.spylog.count(client.resendRequests) diff --git a/plenum/test/client/test_client_sends_get_request_to_one_node.py b/plenum/test/client/test_client_sends_get_request_to_one_node.py deleted file mode 100644 index 0ea6a1d61e..0000000000 --- a/plenum/test/client/test_client_sends_get_request_to_one_node.py +++ /dev/null @@ -1,91 +0,0 @@ -import random - -from plenum.test.spy_helpers import getAllArgs -from stp_core.common.log import getlogger -from stp_core.loop.eventually import eventually -from plenum.test.client.conftest import passThroughReqAcked1 - -from plenum.test.helper import stopNodes, send_signed_requests -from plenum.test.malicious_behaviors_client import \ - genDoesntSendRequestToSomeNodes - -logger = getlogger() - -nodeCount = 4 -clientFault = genDoesntSendRequestToSomeNodes("AlphaC") -reqAcked1 = passThroughReqAcked1 - - -def test_client_sends_get_request_to_one_node(looper, - client1, - wallet1, - txnPoolNodeSet): - """ - Check that client sends read only request to one node only - """ - client = client1 - wallet = wallet1 - - def sign_and_send(op): - signed = wallet.signOp(op) - send_signed_requests(client, [signed]) - - logger.info("Send set request") - buy = {'type': 'buy', 'amount': random.randint(10, 100)} - sign_and_send(buy) - - send_args = getAllArgs(client, client.send) - rids = send_args[0]['rids'] - assert len(rids) > 1 - - logger.info("Send get request") - get_buy = {'type': 'get_buy'} - client._read_only_requests.add('get_buy') - sign_and_send(get_buy) - - send_args = getAllArgs(client, client.send) - rids = send_args[0]['rids'] - assert len(rids) == 1 - - -def test_client_can_send_get_request_to_one_node(looper, - client1, - wallet1, - txnPoolNodeSet): - """ - Check that read only request can be sent - without having connection to all nodes - """ - client = client1 - wallet = wallet1 - - logger.info("Stopping nodes") - nodes_to_stop = list(txnPoolNodeSet)[1:] - stopNodes(nodes_to_stop, looper) - - def sign_and_send(op): - signed = wallet.signOp(op) - send_signed_requests(client, [signed]) - - def check_client_disconnected(): - assert not client.hasSufficientConnections - - logger.info("Ensure that client has disconnected from the stopped nodes") - # TODO non-default timeout - looper.run(eventually(check_client_disconnected, retryWait=1)) - - initial_submit_count = client.spylog.count(client.submitReqs) - initial_send_count = client.spylog.count(client.send) - - logger.info("Send set request") - buy = {'type': 'buy', 'amount': random.randint(10, 100)} - sign_and_send(buy) - assert initial_submit_count + 1 == client.spylog.count(client.submitReqs) - assert initial_send_count == client.spylog.count(client.send) - - logger.info("Send get request") - get_buy = {'type': 'get_buy'} - client._read_only_requests.add('get_buy') - sign_and_send(get_buy) - assert initial_submit_count + 2 == client.spylog.count(client.submitReqs) - assert initial_send_count + 1 == client.spylog.count(client.send) diff --git a/plenum/test/client/test_client_sends_to_less_nodes.py b/plenum/test/client/test_client_sends_to_less_nodes.py deleted file mode 100644 index 5facd46649..0000000000 --- a/plenum/test/client/test_client_sends_to_less_nodes.py +++ /dev/null @@ -1,18 +0,0 @@ -from plenum.test.client.conftest import passThroughReqAcked1 - -from plenum.client.client import Client -from plenum.test.malicious_behaviors_client import \ - genDoesntSendRequestToSomeNodes - -nodeCount = 4 -clientFault = genDoesntSendRequestToSomeNodes(skipCount=3) -reqAcked1 = passThroughReqAcked1 - - -# noinspection PyIncorrectDocstring -def testReplyWhenRequestSentToLessThanFPlusOneNodes(looper, txnPoolNodeSet, - fClient: Client, replied1): - """ - In a system with no faulty nodes, even if the client sends the request to - one node it will get replies from all the nodes. - """ diff --git a/plenum/test/client/test_faulty_client_with_faulty_node.py b/plenum/test/client/test_faulty_client_with_faulty_node.py index c0cc8e766c..d254a685ec 100644 --- a/plenum/test/client/test_faulty_client_with_faulty_node.py +++ b/plenum/test/client/test_faulty_client_with_faulty_node.py @@ -5,12 +5,8 @@ from plenum.test.helper import whitelistNode from plenum.test.malicious_behaviors_node import makeNodeFaulty, changesRequest -from plenum.test.malicious_behaviors_client import \ - genDoesntSendRequestToSomeNodes - nodeCount = 4 faultyNodes = 1 -clientFault = genDoesntSendRequestToSomeNodes("GammaC", "DeltaC") reqAcked1 = passThroughReqAcked1 whitelist = ['for InvalidSignature', 'discarding message'] @@ -25,11 +21,12 @@ def nodeChangesRequest(txnPoolNodeSet): [node for node in txnPoolNodeSet if node != alpha], InvalidSignature.code) makeNodeFaulty(alpha, changesRequest, ) + for node in txnPoolNodeSet[3:]: node.clientstack.stop() # noinspection PyIncorrectDocstring,PyUnusedLocal,PyShadowingNames def testReplyUnaffectedByFaultyNode(looper, txnPoolNodeSet, nodeChangesRequest, - fClient, replied1): + replied1): """ Client is malicious - sends requests to Alpha and Beta only Node Alpha is malicious - it alters the request diff --git a/plenum/test/client/test_protocol_version.py b/plenum/test/client/test_protocol_version.py index da3b89426e..ee90d4910a 100644 --- a/plenum/test/client/test_protocol_version.py +++ b/plenum/test/client/test_protocol_version.py @@ -1,10 +1,8 @@ import pytest from plenum.common.constants import CURRENT_PROTOCOL_VERSION -from plenum.common.request import Request -from plenum.test.helper import waitForSufficientRepliesForRequests, \ - send_signed_requests, checkReqNackWithReason, random_request_objects, \ - sign_request_objects, random_requests -from stp_core.loop.eventually import eventually +from plenum.common.exceptions import RequestNackedException +from plenum.test.helper import sdk_send_signed_requests, \ + sdk_get_and_check_replies, sdk_random_request_objects, sdk_sign_request_objects @pytest.yield_fixture(scope="function", params=['1', '2']) @@ -13,58 +11,49 @@ def request_num(request): def test_request_no_protocol_version(looper, txnPoolNodeSet, - client1, - wallet1, + sdk_pool_handle, + sdk_wallet_client, request_num): - reqs = random_request_objects(request_num, protocol_version=None) - reqs = sign_request_objects(wallet1, reqs) - for req in reqs: - assert req.protocolVersion is None + _, did = sdk_wallet_client + reqs_obj = sdk_random_request_objects(request_num, identifier=did, + protocol_version=None) + for req_obj in reqs_obj: + assert req_obj.protocolVersion == None - send_signed_requests(client1, reqs) - waitForSufficientRepliesForRequests(looper, client1, requests=reqs) - - -def test_version_not_set_by_default(looper, txnPoolNodeSet, - client1, - wallet1, - request_num): - req_dicts = random_requests(request_num) - reqs = [Request(operation=op) for op in req_dicts] - for req in reqs: - assert req.protocolVersion is None - reqs = sign_request_objects(wallet1, reqs) - for req in reqs: - assert req.protocolVersion is None - - send_signed_requests(client1, reqs) - waitForSufficientRepliesForRequests(looper, client1, requests=reqs) + signed_reqs = sdk_sign_request_objects(looper, sdk_wallet_client, reqs_obj) + reqs = sdk_send_signed_requests(sdk_pool_handle, signed_reqs) + sdk_get_and_check_replies(looper, reqs) def test_request_with_correct_version(looper, - txnPoolNodeSet, client1, - wallet1, + txnPoolNodeSet, + sdk_pool_handle, + sdk_wallet_client, request_num): - reqs = random_request_objects(request_num, protocol_version=CURRENT_PROTOCOL_VERSION) - reqs = sign_request_objects(wallet1, reqs) - for req in reqs: - assert req.protocolVersion == CURRENT_PROTOCOL_VERSION + _, did = sdk_wallet_client + reqs_obj = sdk_random_request_objects(request_num, identifier=did, + protocol_version=CURRENT_PROTOCOL_VERSION) + for req_obj in reqs_obj: + assert req_obj.protocolVersion == CURRENT_PROTOCOL_VERSION - send_signed_requests(client1, reqs) - waitForSufficientRepliesForRequests(looper, client1, requests=reqs) + signed_reqs = sdk_sign_request_objects(looper, sdk_wallet_client, reqs_obj) + reqs = sdk_send_signed_requests(sdk_pool_handle, signed_reqs) + sdk_get_and_check_replies(looper, reqs) -def test_request_with_invalid_version(looper, txnPoolNodeSet, - client1, - wallet1, +def test_request_with_invalid_version(looper, + txnPoolNodeSet, + sdk_pool_handle, + sdk_wallet_client, request_num): - reqs = random_request_objects(request_num, protocol_version=-1) - reqs = sign_request_objects(wallet1, reqs) - for req in reqs: - assert req.protocolVersion == -1 - - send_signed_requests(client1, reqs) - for node in txnPoolNodeSet: - looper.run(eventually(checkReqNackWithReason, client1, - 'Unknown protocol version value -1', - node.clientstack.name, retryWait=1)) + _, did = sdk_wallet_client + reqs_obj = sdk_random_request_objects(request_num, identifier=did, + protocol_version=-1) + for req_obj in reqs_obj: + assert req_obj.protocolVersion == -1 + + signed_reqs = sdk_sign_request_objects(looper, sdk_wallet_client, reqs_obj) + reqs = sdk_send_signed_requests(sdk_pool_handle, signed_reqs) + with pytest.raises(RequestNackedException)as e: + sdk_get_and_check_replies(looper, reqs) + assert 'Unknown protocol version value -1' in e._excinfo[1].args[0] diff --git a/plenum/test/conftest.py b/plenum/test/conftest.py index 70ef4b611f..adbedf4402 100644 --- a/plenum/test/conftest.py +++ b/plenum/test/conftest.py @@ -49,11 +49,11 @@ from plenum.common.types import PLUGIN_TYPE_STATS_CONSUMER, f from plenum.common.util import getNoInstances from plenum.server.notifier_plugin_manager import PluginManager -from plenum.test.helper import randomOperation, \ - checkReqAck, checkLastClientReqForNode, waitForSufficientRepliesForRequests, \ +from plenum.test.helper import checkLastClientReqForNode, \ waitForViewChange, requestReturnedToNode, randomText, \ mockGetInstalledDistributions, mockImportModule, chk_all_funcs, \ - create_new_test_node + create_new_test_node, sdk_json_to_request_object, sdk_send_random_requests, \ + sdk_get_and_check_replies from plenum.test.node_request.node_request_helper import checkPrePrepared, \ checkPropagated, checkPrepared, checkCommitted from plenum.test.plugin.helper import getPluginPath @@ -444,15 +444,6 @@ def stewardAndWallet1(looper, txnPoolNodeSet, poolTxnStewardData, client.stop() -@pytest.fixture(scope="module") -def steward1(looper, txnPoolNodeSet, stewardAndWallet1): - steward, wallet = stewardAndWallet1 - looper.add(steward) - ensureClientConnectedToNodesAndPoolLedgerSame(looper, steward, - *txnPoolNodeSet) - return steward - - @pytest.fixture(scope="module") def client1(looper, clientAndWallet1): client = clientAndWallet1[0] @@ -467,46 +458,26 @@ def wallet1(clientAndWallet1): @pytest.fixture(scope="module") -def request1(wallet1): - op = randomOperation() - req = wallet1.signOp(op) - return req +def sent1(looper, sdk_pool_handle, + sdk_wallet_client): + request_couple_json = sdk_send_random_requests( + looper, sdk_pool_handle, sdk_wallet_client, 1) + return request_couple_json @pytest.fixture(scope="module") -def sent1(client1, request1): - return client1.submitReqs(request1)[0][0] - - -@pytest.fixture(scope="module") -def reqAcked1(looper, txnPoolNodeSet, client1, sent1, faultyNodes): +def reqAcked1(looper, txnPoolNodeSet, sent1, faultyNodes): numerOfNodes = len(txnPoolNodeSet) + request = sdk_json_to_request_object(sent1[0][0]) + # Wait until request received by all nodes propTimeout = waits.expectedClientToPoolRequestDeliveryTime(numerOfNodes) - coros = [partial(checkLastClientReqForNode, node, sent1) + coros = [partial(checkLastClientReqForNode, node, request) for node in txnPoolNodeSet] - # looper.run(eventuallyAll(*coros, - # totalTimeout=propTimeout, - # acceptableFails=faultyNodes)) chk_all_funcs(looper, coros, acceptable_fails=faultyNodes, timeout=propTimeout) - - # Wait until sufficient number of acks received - coros2 = [ - partial( - checkReqAck, - client1, - node, - sent1.identifier, - sent1.reqId) for node in txnPoolNodeSet] - ackTimeout = waits.expectedReqAckQuorumTime() - # looper.run(eventuallyAll(*coros2, - # totalTimeout=ackTimeout, - # acceptableFails=faultyNodes)) - chk_all_funcs(looper, coros2, acceptable_fails=faultyNodes, - timeout=ackTimeout) - return sent1 + return request @pytest.fixture(scope="module") @@ -549,7 +520,7 @@ def preprepared1(looper, txnPoolNodeSet, propagated1, faultyNodes): @pytest.fixture(scope="module") -def prepared1(looper, txnPoolNodeSet, client1, preprepared1, faultyNodes): +def prepared1(looper, txnPoolNodeSet, preprepared1, faultyNodes): checkPrepared(looper, txnPoolNodeSet, preprepared1, @@ -559,7 +530,7 @@ def prepared1(looper, txnPoolNodeSet, client1, preprepared1, faultyNodes): @pytest.fixture(scope="module") -def committed1(looper, txnPoolNodeSet, client1, prepared1, faultyNodes): +def committed1(looper, txnPoolNodeSet, prepared1, faultyNodes): checkCommitted(looper, txnPoolNodeSet, prepared1, @@ -569,14 +540,17 @@ def committed1(looper, txnPoolNodeSet, client1, prepared1, faultyNodes): @pytest.fixture(scope="module") -def replied1(looper, txnPoolNodeSet, client1, committed1, wallet1, faultyNodes): +def replied1(looper, txnPoolNodeSet, sdk_wallet_client, + committed1, faultyNodes, sent1): numOfNodes = len(txnPoolNodeSet) numOfInstances = getNoInstances(numOfNodes) quorum = numOfInstances * (numOfNodes - faultyNodes) + _, did = sdk_wallet_client + def checkOrderedCount(): resp = [requestReturnedToNode(node, - wallet1.defaultId, + did, committed1.reqId, instId) for node in txnPoolNodeSet for instId in range(numOfInstances)] @@ -587,7 +561,7 @@ def checkOrderedCount(): retryWait=1, timeout=orderingTimeout)) - waitForSufficientRepliesForRequests(looper, client1, requests=[committed1]) + sdk_get_and_check_replies(looper, sent1) return committed1 diff --git a/plenum/test/helper.py b/plenum/test/helper.py index 6588382cbd..bf5b01749a 100644 --- a/plenum/test/helper.py +++ b/plenum/test/helper.py @@ -20,8 +20,7 @@ from ledger.genesis_txn.genesis_txn_file_util import genesis_txn_file from plenum.client.client import Client -from plenum.client.wallet import Wallet -from plenum.common.constants import DOMAIN_LEDGER_ID, OP_FIELD_NAME, REPLY, REQACK, REQNACK, REJECT, \ +from plenum.common.constants import DOMAIN_LEDGER_ID, OP_FIELD_NAME, REPLY, REQNACK, REJECT, \ CURRENT_PROTOCOL_VERSION from plenum.common.exceptions import RequestNackedException, RequestRejectedException, CommonSdkIOException, \ PoolLedgerTimeoutException @@ -35,9 +34,8 @@ from plenum.test.msgs import randomMsg from plenum.test.spy_helpers import getLastClientReqReceivedForNode, getAllArgs, getAllReturnVals, \ getAllMsgReceivedForNode -from plenum.test.test_client import TestClient, genTestClient -from plenum.test.test_node import TestNode, TestReplica, TestNodeSet, \ - checkNodesConnected, ensureElectionsDone, NodeRef, getPrimaryReplica +from plenum.test.test_node import TestNode, TestReplica, \ + getPrimaryReplica from stp_core.common.log import getlogger from stp_core.loop.eventually import eventuallyAll, eventually from stp_core.loop.looper import Looper @@ -76,6 +74,7 @@ def check_sufficient_replies_received(client: Client, .format(full_request_id)) +# TODO: delete after removal from node def waitForSufficientRepliesForRequests(looper, client, *, # To force usage of names @@ -188,55 +187,6 @@ def assertEquality(observed: Any, expected: Any, details=None): "was {}, details: {}".format(observed, expected, details) -def setupNodesAndClient( - looper: Looper, - nodes: Sequence[TestNode], - nodeReg=None, - tmpdir=None): - looper.run(checkNodesConnected(nodes)) - ensureElectionsDone(looper=looper, nodes=nodes) - return setupClient(looper, nodes, nodeReg=nodeReg, tmpdir=tmpdir) - - -def setupClient(looper: Looper, - nodes: Sequence[TestNode] = None, - nodeReg=None, - tmpdir=None, - identifier=None, - verkey=None): - client1, wallet = genTestClient(nodes=nodes, - nodeReg=nodeReg, - tmpdir=tmpdir, - identifier=identifier, - verkey=verkey) - looper.add(client1) - looper.run(client1.ensureConnectedToNodes()) - return client1, wallet - - -def setupClients(count: int, - looper: Looper, - nodes: Sequence[TestNode] = None, - nodeReg=None, - tmpdir=None): - wallets = {} - clients = {} - for i in range(count): - name = "test-wallet-{}".format(i) - wallet = Wallet(name) - idr, _ = wallet.addIdentifier() - verkey = wallet.getVerkey(idr) - client, _ = setupClient(looper, - nodes, - nodeReg, - tmpdir, - identifier=idr, - verkey=verkey) - clients[client.name] = client - wallets[client.name] = wallet - return clients, wallets - - def randomOperation(): return { "type": "buy", @@ -253,29 +203,6 @@ def random_request_objects(count, protocol_version): return [Request(operation=op, protocolVersion=protocol_version) for op in req_dicts] -def sign_request_objects(wallet, reqs: Sequence): - return [wallet.signRequest(req) for req in reqs] - - -def sign_requests(wallet, reqs: Sequence): - return [wallet.signOp(req) for req in reqs] - - -def signed_random_requests(wallet, count): - reqs = random_requests(count) - return sign_requests(wallet, reqs) - - -def send_signed_requests(client: Client, signed_reqs: Sequence): - return client.submitReqs(*signed_reqs)[0] - - -def sendRandomRequests(wallet: Wallet, client: Client, count: int): - logger.debug('Sending {} random requests'.format(count)) - return send_signed_requests(client, - signed_random_requests(wallet, count)) - - def buildCompletedTxnFromReply(request, reply: Reply) -> Dict: txn = request.operation txn.update(reply) @@ -434,12 +361,6 @@ def check_request_is_not_returned_to_nodes(txnPoolNodeSet, request): inst_id) -def verify_request_not_replied_and_not_ordered(request, looper, client, nodes): - with pytest.raises(AssertionError): - waitForSufficientRepliesForRequests(looper, client, requests=[request]) - check_request_is_not_returned_to_nodes(nodes, request) - - def checkPrePrepareReqSent(replica: TestReplica, req: Request): prePreparesSent = getAllArgs(replica, replica.sendPrePrepare) expectedDigest = TestReplica.batchDigest([req]) @@ -483,64 +404,6 @@ def checkSufficientCommitReqRecvd(replicas: Iterable[TestReplica], viewNo: int, assert received > minimum -def checkReqAck(client, node, idr, reqId, update: Dict[str, str] = None): - rec = {OP_FIELD_NAME: REQACK, f.REQ_ID.nm: reqId, f.IDENTIFIER.nm: idr} - if update: - rec.update(update) - expected = (rec, node.clientstack.name) - # More than one matching message could be present in the client's inBox - # since client on not receiving request under timeout might have retried - # the request - assert client.inBox.count(expected) > 0 - - -def checkReqNackWithReason(client, reason: str, sender: str): - found = False - for msg, sdr in client.inBox: - if msg[OP_FIELD_NAME] == REQNACK and reason in msg.get( - f.REASON.nm, "") and sdr == sender: - found = True - break - assert found, "there is no Nack with reason: {}".format(reason) - - -def wait_negative_resp(looper, client, reason, sender, timeout, chk_method): - return looper.run(eventually(chk_method, - client, - reason, - sender, - timeout=timeout)) - - -def waitReqNackWithReason(looper, client, reason: str, sender: str): - timeout = waits.expectedReqNAckQuorumTime() - return wait_negative_resp(looper, client, reason, sender, timeout, - checkReqNackWithReason) - - -def checkRejectWithReason(client, reason: str, sender: str): - found = False - for msg, sdr in client.inBox: - if msg[OP_FIELD_NAME] == REJECT and reason in msg.get( - f.REASON.nm, "") and sdr == sender: - found = True - break - assert found - - -def waitRejectWithReason(looper, client, reason: str, sender: str): - timeout = waits.expectedReqRejectQuorumTime() - return wait_negative_resp(looper, client, reason, sender, timeout, - checkRejectWithReason) - - -def ensureRejectsRecvd(looper, nodes, client, reason, timeout=5): - for node in nodes: - looper.run(eventually(checkRejectWithReason, client, reason, - node.clientstack.name, retryWait=1, - timeout=timeout)) - - def checkViewNoForNodes(nodes: Iterable[TestNode], expectedViewNo: int = None): """ Checks if all the given nodes have the expected view no @@ -946,6 +809,14 @@ def sdk_sign_and_submit_req_obj(looper, pool_handle, sdk_wallet, req_obj): return sdk_send_signed_requests(pool_handle, [s_req])[0] +def sdk_sign_and_submit_op(looper, pool_handle, sdk_wallet, op): + _, did = sdk_wallet + req_obj = sdk_gen_request(op, protocol_version=CURRENT_PROTOCOL_VERSION, + identifier=did) + s_req = sdk_sign_request_objects(looper, sdk_wallet, [req_obj])[0] + return sdk_send_signed_requests(pool_handle, [s_req])[0] + + def sdk_get_reply(looper, sdk_req_resp, timeout=None): req_json, resp_task = sdk_req_resp # TODO: change timeout evaluating logic, when sdk will can tuning timeout from outside @@ -1105,3 +976,9 @@ def sdk_json_couples_to_request_list(json_couples): for json_couple in json_couples: req_list.append(sdk_json_to_request_object(json_couple[0])) return req_list + + +def sdk_get_bad_response(looper, reqs, exception, message): + with pytest.raises(exception) as e: + sdk_get_and_check_replies(looper, reqs) + assert message in e._excinfo[1].args[0] diff --git a/plenum/test/instances/test_instance_cannot_become_active_with_less_than_four_servers.py b/plenum/test/instances/test_instance_cannot_become_active_with_less_than_four_servers.py index cbeab558d7..f45c414466 100644 --- a/plenum/test/instances/test_instance_cannot_become_active_with_less_than_four_servers.py +++ b/plenum/test/instances/test_instance_cannot_become_active_with_less_than_four_servers.py @@ -2,12 +2,12 @@ import pytest -from plenum.test.node_request.helper import get_node_by_name from stp_core.loop.eventually import eventually from stp_core.common.log import getlogger from plenum.common.startable import Status from plenum.test.greek import genNodeNames from plenum.test.helper import addNodeBack, ordinal +from plenum.test.node_request.helper import get_node_by_name from plenum.test.test_node import checkNodesConnected, \ checkNodeRemotes from plenum.test.test_stack import CONNECTED, JOINED_NOT_ALLOWED diff --git a/plenum/test/instances/test_msgs_from_slow_instances.py b/plenum/test/instances/test_msgs_from_slow_instances.py index 9cdb67fde0..5f762ed0b9 100644 --- a/plenum/test/instances/test_msgs_from_slow_instances.py +++ b/plenum/test/instances/test_msgs_from_slow_instances.py @@ -7,9 +7,6 @@ from plenum.test.delayers import delayerMsgTuple from plenum.test.test_node import TestNode from plenum.test import waits -from plenum.test.node_request.conftest import committed1, \ - prepared1, preprepared1, propagated1, reqAcked1, \ - sent1, noRetryReq, faultyNodes nodeCount = 4 diff --git a/plenum/test/instances/test_multiple_commit.py b/plenum/test/instances/test_multiple_commit.py index feac6ea9e2..c00d2a9bdd 100644 --- a/plenum/test/instances/test_multiple_commit.py +++ b/plenum/test/instances/test_multiple_commit.py @@ -12,9 +12,6 @@ sendDuplicate3PhaseMsg from plenum.test.test_node import getNonPrimaryReplicas, getPrimaryReplica from plenum.test import waits -from plenum.test.node_request.conftest import committed1, \ - prepared1, preprepared1, propagated1, reqAcked1, \ - sent1, noRetryReq, faultyNodes @pytest.fixture("module") diff --git a/plenum/test/instances/test_multiple_pre_prepare.py b/plenum/test/instances/test_multiple_pre_prepare.py index b326c054ce..7f0b040573 100644 --- a/plenum/test/instances/test_multiple_pre_prepare.py +++ b/plenum/test/instances/test_multiple_pre_prepare.py @@ -12,9 +12,6 @@ sendDuplicate3PhaseMsg from plenum.test.test_node import getNonPrimaryReplicas, getPrimaryReplica from plenum.test import waits -from plenum.test.node_request.conftest import committed1, \ - prepared1, preprepared1, propagated1, reqAcked1, \ - sent1, noRetryReq, faultyNodes @pytest.fixture("module") diff --git a/plenum/test/instances/test_multiple_prepare.py b/plenum/test/instances/test_multiple_prepare.py index ae34618a77..f0aba95d84 100644 --- a/plenum/test/instances/test_multiple_prepare.py +++ b/plenum/test/instances/test_multiple_prepare.py @@ -11,9 +11,6 @@ sendDuplicate3PhaseMsg from plenum.test.test_node import getNonPrimaryReplicas, getPrimaryReplica from plenum.test import waits -from plenum.test.node_request.conftest import committed1, \ - prepared1, preprepared1, propagated1, reqAcked1, \ - sent1, noRetryReq, faultyNodes @pytest.fixture("module") diff --git a/plenum/test/instances/test_pre_prepare_digest.py b/plenum/test/instances/test_pre_prepare_digest.py index cc528504b7..285c9c28e9 100644 --- a/plenum/test/instances/test_pre_prepare_digest.py +++ b/plenum/test/instances/test_pre_prepare_digest.py @@ -12,9 +12,6 @@ send3PhaseMsgWithIncorrectDigest from plenum.test.test_node import getNonPrimaryReplicas, getPrimaryReplica from plenum.test import waits -from plenum.test.node_request.conftest import committed1, \ - prepared1, preprepared1, propagated1, reqAcked1, \ - sent1, noRetryReq, faultyNodes @pytest.fixture("module") diff --git a/plenum/test/instances/test_prepare_digest.py b/plenum/test/instances/test_prepare_digest.py index b9692a8629..1afc2a6ebc 100644 --- a/plenum/test/instances/test_prepare_digest.py +++ b/plenum/test/instances/test_prepare_digest.py @@ -11,9 +11,6 @@ send3PhaseMsgWithIncorrectDigest from plenum.test.test_node import getNonPrimaryReplicas, getPrimaryReplica from plenum.test import waits -from plenum.test.node_request.conftest import committed1, \ - prepared1, preprepared1, propagated1, reqAcked1, \ - sent1, noRetryReq, faultyNodes @pytest.fixture("module") diff --git a/plenum/test/node_catchup/helper.py b/plenum/test/node_catchup/helper.py index 1ed9b2cf13..c2b1c304b6 100644 --- a/plenum/test/node_catchup/helper.py +++ b/plenum/test/node_catchup/helper.py @@ -3,10 +3,6 @@ from plenum.common.util import check_if_all_equal_in_list from stp_core.common.log import getlogger -from typing import Iterable - -from plenum.common.constants import POOL_LEDGER_ID, DOMAIN_LEDGER_ID, \ - CONFIG_LEDGER_ID from stp_core.loop.eventually import eventually from stp_core.types import HA from plenum.test.helper import checkLedgerEquality, checkStateEquality, \ diff --git a/plenum/test/node_catchup/test_catchup_scenarios.py b/plenum/test/node_catchup/test_catchup_scenarios.py index 761103beab..48b316fd88 100644 --- a/plenum/test/node_catchup/test_catchup_scenarios.py +++ b/plenum/test/node_catchup/test_catchup_scenarios.py @@ -1,11 +1,11 @@ import pytest -from plenum.test.node_request.helper import sdk_ensure_pool_functional from stp_core.loop.eventually import eventually from stp_core.common.log import getlogger from plenum.common.startable import Mode from plenum.test.delayers import cqDelay from plenum.test.helper import sdk_send_random_requests +from plenum.test.node_request.helper import sdk_ensure_pool_functional from plenum.test.test_node import checkNodesConnected from plenum.test import waits diff --git a/plenum/test/node_catchup/test_discard_view_no.py b/plenum/test/node_catchup/test_discard_view_no.py index d7625f96e3..ff1275a914 100644 --- a/plenum/test/node_catchup/test_discard_view_no.py +++ b/plenum/test/node_catchup/test_discard_view_no.py @@ -6,9 +6,8 @@ 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.test_node import checkProtocolInstanceSetup, \ + getPrimaryReplica from plenum.test import waits whitelist = ['found legacy entry'] # warnings @@ -17,7 +16,7 @@ def testNodeDiscardMessageFromUnknownView(txnPoolNodeSet, sdk_node_set_with_node_added_after_some_txns, sdk_new_node_caught_up, - allPluginsPath, wallet1): + allPluginsPath, sdk_wallet_client): """ Node discards 3-phase or ViewChangeDone messages from view nos that it does not know of (view nos before it joined the pool) @@ -41,13 +40,14 @@ def testNodeDiscardMessageFromUnknownView(txnPoolNodeSet, messageTimeout = waits.expectedNodeToNodeMessageDeliveryTime() # 3 pc msg (PrePrepare) needs to be discarded + _, did = sdk_wallet_client primaryRepl = getPrimaryReplica(txnPoolNodeSet) three_pc = PrePrepare( 0, viewNo, 10, get_utc_epoch(), - [[wallet1.defaultId, Request.gen_req_id()]], + [[did, Request.gen_req_id()]], 1, "random digest", DOMAIN_LEDGER_ID, diff --git a/plenum/test/node_catchup/test_no_catchup_if_got_from_3pc.py b/plenum/test/node_catchup/test_no_catchup_if_got_from_3pc.py index 7cd38b51b3..ab5cb937a9 100644 --- a/plenum/test/node_catchup/test_no_catchup_if_got_from_3pc.py +++ b/plenum/test/node_catchup/test_no_catchup_if_got_from_3pc.py @@ -1,10 +1,9 @@ -from plenum.test.node_request.helper import sdk_ensure_pool_functional - from plenum.common.constants import DOMAIN_LEDGER_ID from plenum.common.messages.node_messages import Commit, ConsistencyProof from plenum.test.delayers import cpDelay, cDelay from plenum.test.helper import send_reqs_batches_and_get_suff_replies +from plenum.test.node_request.helper import sdk_ensure_pool_functional from plenum.test.node_catchup.helper import ensure_all_nodes_have_same_data, \ waitNodeDataInequality, waitNodeDataEquality from plenum.test.spy_helpers import getAllReturnVals diff --git a/plenum/test/node_catchup/test_remove_request_keys_post_catchup.py b/plenum/test/node_catchup/test_remove_request_keys_post_catchup.py index 6a1ce12f4e..abddc2ec62 100644 --- a/plenum/test/node_catchup/test_remove_request_keys_post_catchup.py +++ b/plenum/test/node_catchup/test_remove_request_keys_post_catchup.py @@ -12,7 +12,7 @@ @pytest.fixture(scope='module', params=['some', 'all']) -def setup(request, looper, txnPoolNodeSet, client1, wallet1): +def setup(request, looper, txnPoolNodeSet): slow_node = getNonPrimaryReplicas(txnPoolNodeSet, 0)[1].node fast_nodes = [n for n in txnPoolNodeSet if n != slow_node] # Delay catchup reply so that the test gets time to make the check, diff --git a/plenum/test/node_request/conftest.py b/plenum/test/node_request/conftest.py deleted file mode 100644 index 333adc5220..0000000000 --- a/plenum/test/node_request/conftest.py +++ /dev/null @@ -1,96 +0,0 @@ -import pytest - -from functools import partial - -from plenum.test.conftest import getValueFromModule - -from plenum.test import waits -from plenum.test.helper import checkLastClientReqForNode, \ - chk_all_funcs, sdk_json_to_request_object, sdk_send_random_requests -from plenum.test.node_request.node_request_helper import checkPrePrepared, \ - checkPropagated, checkPrepared -from plenum.test.node_request.node_request_helper import checkCommitted - -from plenum.common.util import getNoInstances - - -@pytest.fixture(scope="module") -def committed1(looper, txnPoolNodeSet, prepared1, faultyNodes): - checkCommitted(looper, - txnPoolNodeSet, - prepared1, - range(getNoInstances(len(txnPoolNodeSet))), - faultyNodes) - return prepared1 - - -@pytest.fixture(scope="module") -def prepared1(looper, txnPoolNodeSet, preprepared1, faultyNodes): - checkPrepared(looper, - txnPoolNodeSet, - preprepared1, - range(getNoInstances(len(txnPoolNodeSet))), - faultyNodes) - return preprepared1 - - -@pytest.fixture(scope="module") -def preprepared1(looper, txnPoolNodeSet, propagated1, faultyNodes): - checkPrePrepared(looper, - txnPoolNodeSet, - propagated1, - range(getNoInstances(len(txnPoolNodeSet))), - faultyNodes) - return propagated1 - - -@pytest.fixture(scope="module") -def propagated1(looper, - txnPoolNodeSet, - reqAcked1, - faultyNodes): - checkPropagated(looper, txnPoolNodeSet, reqAcked1, faultyNodes) - return reqAcked1 - - -@pytest.fixture(scope="module") -def reqAcked1(looper, txnPoolNodeSet, sent1, faultyNodes): - numerOfNodes = len(txnPoolNodeSet) - - request = sdk_json_to_request_object(sent1[0][0]) - - # Wait until request received by all nodes - propTimeout = waits.expectedClientToPoolRequestDeliveryTime(numerOfNodes) - coros = [partial(checkLastClientReqForNode, node, request) - for node in txnPoolNodeSet] - chk_all_funcs(looper, coros, acceptable_fails=faultyNodes, - timeout=propTimeout) - return request - - -@pytest.fixture(scope="module") -def sent1(looper, sdk_pool_handle, - sdk_wallet_client): - request_couple_json = sdk_send_random_requests( - looper, sdk_pool_handle, sdk_wallet_client, 1) - return request_couple_json - - -@pytest.fixture(scope="module") -def noRetryReq(tconf, request): - oldRetryAck = tconf.CLIENT_MAX_RETRY_ACK - oldRetryReply = tconf.CLIENT_MAX_RETRY_REPLY - tconf.CLIENT_MAX_RETRY_ACK = 0 - tconf.CLIENT_MAX_RETRY_REPLY = 0 - - def reset(): - tconf.CLIENT_MAX_RETRY_ACK = oldRetryAck - tconf.CLIENT_MAX_RETRY_REPLY = oldRetryReply - - request.addfinalizer(reset) - return tconf - - -@pytest.fixture(scope="module") -def faultyNodes(request): - return getValueFromModule(request, "faultyNodes", 0) diff --git a/plenum/test/node_request/helper.py b/plenum/test/node_request/helper.py index 997296e2f4..e20ce1a555 100644 --- a/plenum/test/node_request/helper.py +++ b/plenum/test/node_request/helper.py @@ -1,12 +1,9 @@ import operator + from plenum.test.helper import sdk_send_batches_of_random_and_check from plenum.test.node_catchup.helper import ensure_all_nodes_have_same_data -def get_node_by_name(txnPoolNodeSet, name): - return next(node for node in txnPoolNodeSet if node.name == name) - - def nodes_by_rank(txnPoolNodeSet): return [t[1] for t in sorted([(node.rank, node) for node in txnPoolNodeSet], @@ -22,3 +19,7 @@ def sdk_ensure_pool_functional(looper, nodes, sdk_wallet, sdk_pool, num_reqs, num_batches) ensure_all_nodes_have_same_data(looper, nodes) + + +def get_node_by_name(txnPoolNodeSet, name): + return next(node for node in txnPoolNodeSet if node.name == name) diff --git a/plenum/test/node_request/test_different_ledger_request_interleave.py b/plenum/test/node_request/test_different_ledger_request_interleave.py index 4102e26208..57bc5f83d0 100644 --- a/plenum/test/node_request/test_different_ledger_request_interleave.py +++ b/plenum/test/node_request/test_different_ledger_request_interleave.py @@ -1,7 +1,6 @@ -from plenum.test.node_request.helper import sdk_ensure_pool_functional - from plenum.test.helper import sdk_send_random_and_check, sdk_send_random_requests, \ sdk_eval_timeout, sdk_get_and_check_replies +from plenum.test.node_request.helper import sdk_ensure_pool_functional from plenum.test.node_catchup.helper import ensure_all_nodes_have_same_data from plenum.test.pool_transactions.helper import sdk_add_new_nym, \ prepare_new_node_data, prepare_node_request, sdk_sign_and_send_prepared_request diff --git a/plenum/test/node_request/test_order/test_request_ordering_2.py b/plenum/test/node_request/test_order/test_request_ordering_2.py index 6790f016d2..7e9811b7a3 100644 --- a/plenum/test/node_request/test_order/test_request_ordering_2.py +++ b/plenum/test/node_request/test_order/test_request_ordering_2.py @@ -2,9 +2,7 @@ from stp_core.loop.eventually import eventually from stp_core.common.log import getlogger from plenum.common.messages.node_messages import PrePrepare, Commit -from plenum.test.helper import sendRandomRequests, \ - waitForSufficientRepliesForRequests, checkLedgerEquality, checkAllLedgersEqual, sdk_send_random_and_check, \ - sdk_send_random_requests, sdk_get_replies, sdk_eval_timeout, sdk_get_and_check_replies +from plenum.test.helper import sdk_send_random_requests, sdk_get_and_check_replies from plenum.test.test_node import getNonPrimaryReplicas, getPrimaryReplica from plenum.test import waits diff --git a/plenum/test/plugin/demo_plugin/test_plugin_basic.py b/plenum/test/plugin/demo_plugin/test_plugin_basic.py index aa36471a65..4585764647 100644 --- a/plenum/test/plugin/demo_plugin/test_plugin_basic.py +++ b/plenum/test/plugin/demo_plugin/test_plugin_basic.py @@ -1,11 +1,14 @@ -from plenum.test.helper import checkReqNackWithReason, sdk_gen_request, \ - sdk_sign_and_submit_req_obj, sdk_get_reply -from plenum.common.constants import CURRENT_PROTOCOL_VERSION, TXN_TYPE, DATA +import pytest + +from plenum.common.exceptions import RequestNackedException +from plenum.test.helper import sdk_gen_request, \ + sdk_sign_and_submit_req_obj, sdk_get_reply, sdk_sign_request_objects, sdk_send_signed_requests, \ + sdk_get_and_check_replies +from plenum.common.constants import TXN_TYPE, DATA from plenum.common.request import Request from plenum.common.util import randomString from plenum.test.plugin.demo_plugin import AUCTION_LEDGER_ID, dummy_field_length from plenum.test.plugin.demo_plugin.constants import GET_BAL -from stp_core.loop.eventually import eventually def test_plugin_setup(txn_pool_node_set_post_creation): @@ -19,8 +22,7 @@ def test_plugin_setup(txn_pool_node_set_post_creation): assert AUCTION_LEDGER_ID in node.states -def test_plugin_client_req_fields(txn_pool_node_set_post_creation, looper, stewardWallet, - steward1, +def test_plugin_client_req_fields(txn_pool_node_set_post_creation, looper, sdk_wallet_steward, sdk_pool_handle): """ Test that plugin's addition of request fields and their validation is @@ -39,12 +41,11 @@ def test_plugin_client_req_fields(txn_pool_node_set_post_creation, looper, stewa sdk_get_reply(looper, req) # Invalid field value results in proper failure - req = Request(operation=op, reqId=Request.gen_req_id(), - protocolVersion=CURRENT_PROTOCOL_VERSION, - identifier=stewardWallet.defaultId, - fix_length_dummy=randomString(dummy_field_length + 1)) - steward1.submitReqs(req) - for node in txn_pool_node_set_post_creation: - looper.run(eventually(checkReqNackWithReason, steward1, - 'should have length', - node.clientstack.name, retryWait=1)) + _, did = sdk_wallet_steward + req = sdk_gen_request(op, identifier=did, fix_length_dummy=randomString(dummy_field_length + 1)) + reqs = sdk_sign_request_objects(looper, sdk_wallet_steward, [req]) + reqs = sdk_send_signed_requests(sdk_pool_handle, reqs) + + with pytest.raises(RequestNackedException) as e: + sdk_get_and_check_replies(looper, reqs) + assert 'should have length' in e._excinfo[1].args[0] diff --git a/plenum/test/plugin/helper.py b/plenum/test/plugin/helper.py index ebf92b7ae1..ad6e694372 100644 --- a/plenum/test/plugin/helper.py +++ b/plenum/test/plugin/helper.py @@ -10,24 +10,5 @@ def getPluginPath(name): return os.path.join(curPath, name) -def submitOp(wallet, client, op): - req = wallet.signOp(op) - client.submitReqs(req) - return req - - -class App: - - def __init__(self, wallet: Wallet, client: TestClient, looper): - self.wallet = wallet - self.client = client - self.looper = looper - - def submit(self, op): - req = self.wallet.signOp(op) - self.client.submitReqs(req) - return req - - def makeReason(common, specific): return '{} [caused by {}]'.format(common, specific) diff --git a/plenum/test/pool_transactions/conftest.py b/plenum/test/pool_transactions/conftest.py index 94930f90e5..7ace61bc13 100644 --- a/plenum/test/pool_transactions/conftest.py +++ b/plenum/test/pool_transactions/conftest.py @@ -1,11 +1,10 @@ import pytest from plenum.common.util import randomString -from plenum.test.test_node import checkNodesConnected -from plenum.test.node_catchup.helper import \ - ensureClientConnectedToNodesAndPoolLedgerSame -from plenum.test.pool_transactions.helper import addNewStewardAndNode, \ - buildPoolClientAndWallet, addNewSteward, sdk_add_new_steward_and_node, sdk_pool_refresh +from plenum.test.test_node import checkNodesConnected, TestNode +from plenum.test.pool_transactions.helper import \ + sdk_add_new_steward_and_node, sdk_pool_refresh + @pytest.fixture(scope="module") @@ -18,32 +17,6 @@ def tconf(tconf, request): return tconf -@pytest.fixture("module") -def nodeThetaAdded(looper, txnPoolNodeSet, tdir, client_tdir, - tconf, steward1, stewardWallet, allPluginsPath, testNodeClass=None, - testClientClass=None, name=None): - newStewardName = "testClientSteward" + randomString(3) - newNodeName = name or "Theta" - newSteward, newStewardWallet, newNode = addNewStewardAndNode(looper, - steward1, - stewardWallet, - newStewardName, - newNodeName, - tdir, - client_tdir, - tconf, - allPluginsPath, - nodeClass=testNodeClass, - clientClass=testClientClass) - txnPoolNodeSet.append(newNode) - looper.run(checkNodesConnected(txnPoolNodeSet)) - ensureClientConnectedToNodesAndPoolLedgerSame(looper, steward1, - *txnPoolNodeSet) - ensureClientConnectedToNodesAndPoolLedgerSame(looper, newSteward, - *txnPoolNodeSet) - return newSteward, newStewardWallet, newNode - - @pytest.fixture(scope='module') def sdk_node_theta_added(looper, txnPoolNodeSet, @@ -52,7 +25,7 @@ def sdk_node_theta_added(looper, sdk_pool_handle, sdk_wallet_steward, allPluginsPath, - testNodeClass=None, + testNodeClass=TestNode, name=None): new_steward_name = "testClientSteward" + randomString(3) new_node_name = name or "Theta" @@ -64,17 +37,9 @@ def sdk_node_theta_added(looper, new_node_name, tdir, tconf, - allPluginsPath) + allPluginsPath, + nodeClass=testNodeClass) txnPoolNodeSet.append(new_node) looper.run(checkNodesConnected(txnPoolNodeSet)) sdk_pool_refresh(looper, sdk_pool_handle) return new_steward_wallet, new_node - - -@pytest.fixture(scope="function") -def newAdHocSteward(looper, client_tdir, steward1, stewardWallet): - newStewardName = "testClientSteward" + randomString(3) - newSteward, newStewardWallet = addNewSteward(looper, client_tdir, steward1, - stewardWallet, - newStewardName) - return newSteward, newStewardWallet diff --git a/plenum/test/pool_transactions/helper.py b/plenum/test/pool_transactions/helper.py index 37fae0f3cf..ff2613e694 100644 --- a/plenum/test/pool_transactions/helper.py +++ b/plenum/test/pool_transactions/helper.py @@ -3,142 +3,55 @@ from indy.did import create_and_store_my_did from indy.ledger import build_node_request, build_nym_request, build_get_txn_request from indy.pool import refresh_pool_ledger -from plenum.test.node_catchup.helper import waitNodeDataEquality, \ - ensureClientConnectedToNodesAndPoolLedgerSame -from plenum.test.node_request.helper import sdk_ensure_pool_functional +from plenum.test.node_catchup.helper import waitNodeDataEquality from stp_core.loop.looper import Looper from stp_core.types import HA from typing import Iterable, Union, Callable -from plenum.client.client import Client from plenum.client.wallet import Wallet -from plenum.common.constants import STEWARD, TXN_TYPE, NYM, ROLE, TARGET_NYM, ALIAS, \ - NODE_PORT, CLIENT_IP, NODE_IP, DATA, NODE, CLIENT_PORT, VERKEY, SERVICES, \ - VALIDATOR, BLS_KEY, CLIENT_STACK_SUFFIX, STEWARD_STRING +from plenum.common.constants import VERKEY, VALIDATOR, STEWARD_STRING from plenum.common.keygen_utils import initNodeKeysForBothStacks from plenum.common.signer_simple import SimpleSigner from plenum.common.signer_did import DidSigner from plenum.common.util import randomString, hexToFriendly -from plenum.test.helper import waitForSufficientRepliesForRequests, \ - sdk_sign_request_objects, sdk_send_signed_requests, \ - sdk_json_to_request_object, sdk_get_and_check_replies +from plenum.test.helper import sdk_sign_request_objects, \ + sdk_send_signed_requests, sdk_json_to_request_object, \ + sdk_get_and_check_replies, sdk_sign_request_strings +from plenum.test.node_request.helper import sdk_ensure_pool_functional from plenum.test.test_client import TestClient, genTestClient from plenum.test.test_node import TestNode, \ ensure_node_disconnected, checkNodesConnected -from stp_core.loop.eventually import eventually from stp_core.network.port_dispenser import genHa from plenum.common.config_helper import PNodeConfigHelper from stp_core.common.log import getlogger -from indy.error import ErrorCode, IndyError - logger = getlogger() - REFRESH_TRY_COUNT = 4 -def new_client_request(role, name, creatorWallet): - wallet = Wallet(name) - wallet.addIdentifier() - idr = wallet.defaultId - - op = { - TXN_TYPE: NYM, - TARGET_NYM: idr, - ALIAS: name, - VERKEY: wallet.getVerkey(idr) - } - - if role: - op[ROLE] = role - - return creatorWallet.signOp(op), wallet - - -def sendAddNewClient(role, name, creatorClient, creatorWallet): - req, wallet = new_client_request(role, name, creatorWallet) - creatorClient.submitReqs(req) - return req, wallet +def new_client_request(role, name, looper, sdk_wallet): + wh, did = sdk_wallet + seed = randomString(32) + (named_did, named_verkey) = looper.loop.run_until_complete( + create_and_store_my_did(wh, json.dumps({'seed': seed}))) + nym_request = looper.loop.run_until_complete( + build_nym_request(did, named_did, named_verkey, + name, role)) + return sdk_sign_request_strings(looper, sdk_wallet, + [json.loads(nym_request)])[0] -def addNewClient(role, looper, creatorClient: Client, creatorWallet: Wallet, - name: str): - req, wallet = sendAddNewClient(role, name, creatorClient, creatorWallet) - waitForSufficientRepliesForRequests(looper, creatorClient, - requests=[req]) - return wallet - - -def sendAddNewNode(tdir, tconf, newNodeName, stewardClient, stewardWallet, - transformOpFunc=None): - sigseed, verkey, bls_key, nodeIp, nodePort, clientIp, clientPort = \ - prepare_new_node_data(tconf, tdir, newNodeName) - return send_new_node_txn(sigseed, - nodeIp, nodePort, clientIp, clientPort, - bls_key, - newNodeName, stewardClient, stewardWallet, - transformOpFunc) - - -def prepare_new_node_data(tconf, tdir, - newNodeName): +def prepare_new_node_data(tconf, tdir, newNodeName, configClass=PNodeConfigHelper): sigseed = randomString(32).encode() (nodeIp, nodePort), (clientIp, clientPort) = genHa(2) - config_helper = PNodeConfigHelper(newNodeName, tconf, chroot=tdir) + config_helper = configClass(newNodeName, tconf, chroot=tdir) _, verkey, bls_key = initNodeKeysForBothStacks(newNodeName, config_helper.keys_dir, sigseed, override=True) return sigseed, verkey, bls_key, nodeIp, nodePort, clientIp, clientPort -def send_new_node_txn(sigseed, - nodeIp, nodePort, clientIp, clientPort, - bls_key, - newNodeName, stewardClient, stewardWallet, - transformOpFunc=None): - nodeSigner = SimpleSigner(seed=sigseed) - op = { - TXN_TYPE: NODE, - TARGET_NYM: nodeSigner.identifier, - DATA: { - NODE_IP: nodeIp, - NODE_PORT: nodePort, - CLIENT_IP: clientIp, - CLIENT_PORT: clientPort, - ALIAS: newNodeName, - SERVICES: [VALIDATOR, ], - BLS_KEY: bls_key - } - } - if transformOpFunc is not None: - transformOpFunc(op) - - req = stewardWallet.signOp(op) - stewardClient.submitReqs(req) - return req, \ - op[DATA].get(NODE_IP), op[DATA].get(NODE_PORT), \ - op[DATA].get(CLIENT_IP), op[DATA].get(CLIENT_PORT), \ - sigseed - - -def addNewNode(looper, stewardClient, stewardWallet, newNodeName, tdir, tconf, - allPluginsPath=None, autoStart=True, nodeClass=TestNode, - transformOpFunc=None, do_post_node_creation: Callable = None): - nodeClass = nodeClass or TestNode - req, nodeIp, nodePort, clientIp, clientPort, sigseed \ - = sendAddNewNode(tdir, tconf, newNodeName, stewardClient, stewardWallet, - transformOpFunc) - waitForSufficientRepliesForRequests(looper, stewardClient, - requests=[req]) - - return create_and_start_new_node(looper, newNodeName, tdir, sigseed, - (nodeIp, nodePort), (clientIp, clientPort), - tconf, autoStart, allPluginsPath, - nodeClass, - do_post_node_creation=do_post_node_creation) - - def start_not_added_node(looper, tdir, tconf, allPluginsPath, newNodeName): @@ -161,32 +74,33 @@ def add_started_node(looper, node_ha, client_ha, txnPoolNodeSet, - client_tdir, - stewardClient, stewardWallet, - sigseed, + sdk_pool_handle, + sdk_wallet_steward, bls_key): ''' Adds already created node to the pool, that is sends NODE txn. Makes sure that node is actually added and connected to all otehr nodes. ''' - newSteward, newStewardWallet = addNewSteward(looper, client_tdir, - stewardClient, stewardWallet, - "Steward" + new_node.name, - clientClass=TestClient) + new_steward_wallet_handle = sdk_add_new_nym(looper, sdk_pool_handle, + sdk_wallet_steward, + "Steward" + new_node.name, + role=STEWARD_STRING) node_name = new_node.name - send_new_node_txn(sigseed, - node_ha[0], - node_ha[1], - client_ha[0], - client_ha[1], - bls_key, - node_name, - newSteward, newStewardWallet) + node_dest = hexToFriendly(new_node.nodestack.verhex) + sdk_send_update_node(looper, new_steward_wallet_handle, + sdk_pool_handle, node_dest, node_name, + node_ha[0], node_ha[1], + client_ha[0], client_ha[1], + services=[VALIDATOR], + bls_key=bls_key) txnPoolNodeSet.append(new_node) looper.run(checkNodesConnected(txnPoolNodeSet)) - ensureClientConnectedToNodesAndPoolLedgerSame(looper, newSteward, *txnPoolNodeSet) + sdk_pool_refresh(looper, sdk_pool_handle) + sdk_ensure_pool_functional(looper, txnPoolNodeSet, + sdk_wallet_steward, + sdk_pool_handle) waitNodeDataEquality(looper, new_node, *txnPoolNodeSet[:-1]) @@ -202,14 +116,16 @@ def create_and_start_new_node( auto_start, plugin_path, nodeClass, - do_post_node_creation: Callable = None): + do_post_node_creation: Callable = None, + configClass=PNodeConfigHelper): node = new_node(node_name=node_name, tdir=tdir, node_ha=node_ha, client_ha=client_ha, tconf=tconf, plugin_path=plugin_path, - nodeClass=nodeClass) + nodeClass=nodeClass, + configClass=configClass) if do_post_node_creation: do_post_node_creation(node) if auto_start: @@ -224,8 +140,9 @@ def new_node( client_ha, tconf, plugin_path, - nodeClass): - config_helper = PNodeConfigHelper(node_name, tconf, chroot=tdir) + nodeClass, + configClass=PNodeConfigHelper): + config_helper = configClass(node_name, tconf, chroot=tdir) node = nodeClass(node_name, config_helper=config_helper, config=tconf, @@ -234,45 +151,6 @@ def new_node( return node -def addNewSteward(looper, client_tdir, - creatorClient, creatorWallet, stewardName, - clientClass=TestClient): - clientClass = clientClass or TestClient - newStewardWallet = addNewClient(STEWARD, looper, creatorClient, - creatorWallet, stewardName) - newSteward = clientClass(name=stewardName, - nodeReg=None, ha=genHa(), - basedirpath=client_tdir) - - looper.add(newSteward) - looper.run(newSteward.ensureConnectedToNodes()) - return newSteward, newStewardWallet - - -def addNewStewardAndNode(looper, creatorClient, creatorWallet, stewardName, - newNodeName, tdir, client_tdir, tconf, allPluginsPath=None, - autoStart=True, nodeClass=TestNode, - clientClass=TestClient, transformNodeOpFunc=None, - do_post_node_creation: Callable = None): - newSteward, newStewardWallet = addNewSteward(looper, client_tdir, creatorClient, - creatorWallet, stewardName, - clientClass=clientClass) - - newNode = addNewNode( - looper, - newSteward, - newStewardWallet, - newNodeName, - tdir, - tconf, - allPluginsPath, - autoStart=autoStart, - nodeClass=nodeClass, - transformOpFunc=transformNodeOpFunc, - do_post_node_creation=do_post_node_creation) - return newSteward, newStewardWallet, newNode - - def sdk_add_new_steward_and_node(looper, sdk_pool_handle, sdk_wallet_steward, @@ -291,7 +169,7 @@ def sdk_add_new_steward_and_node(looper, sdk_wallet_steward, alias=new_steward_name, role=STEWARD_STRING) - newNode = sdk_add_new_node( + new_node = sdk_add_new_node( looper, sdk_pool_handle, new_steward_wallet_handle, @@ -301,22 +179,23 @@ def sdk_add_new_steward_and_node(looper, allPluginsPath, autoStart=autoStart, nodeClass=nodeClass, - transformOpFunc=transformNodeOpFunc, do_post_node_creation=do_post_node_creation, services=services) - return new_steward_wallet_handle, newNode + return new_steward_wallet_handle, new_node def sdk_add_new_nym(looper, sdk_pool_handle, creators_wallet, - alias=None, role=None, seed=None): + alias=None, role=None, seed=None, + dest=None, verkey=None,skipverkey=False): seed = seed or randomString(32) + alias = alias or randomString(5) wh, _ = creators_wallet # filling nym request and getting steward did # if role == None, we are adding client nym_request, new_did = looper.loop.run_until_complete( prepare_nym_request(creators_wallet, seed, - alias, role)) + alias, role, dest, verkey, skipverkey)) # sending request using 'sdk_' functions request_couple = sdk_sign_and_send_prepared_request(looper, creators_wallet, @@ -333,7 +212,7 @@ def sdk_add_new_node(looper, new_node_name, tdir, tconf, allPluginsPath=None, autoStart=True, nodeClass=TestNode, - transformOpFunc=None, do_post_node_creation: Callable = None, + do_post_node_creation: Callable = None, services=[VALIDATOR]): nodeClass = nodeClass or TestNode sigseed, verkey, bls_key, nodeIp, nodePort, clientIp, clientPort = \ @@ -363,16 +242,22 @@ def sdk_add_new_node(looper, (nodeIp, nodePort), (clientIp, clientPort), tconf, autoStart, allPluginsPath, nodeClass, - do_post_node_creation=do_post_node_creation) + do_post_node_creation=do_post_node_creation, + configClass=PNodeConfigHelper) + + +async def prepare_schema_request(wallet, named_seed, alias, role): + pass -async def prepare_nym_request(wallet, named_seed, alias, role): +async def prepare_nym_request(wallet, named_seed, alias, + role, dest=None, verkey=None, skipverkey=False): wh, submitter_did = wallet - (named_did, named_verkey) = await create_and_store_my_did(wh, - json.dumps({ - 'seed': named_seed, - 'cid': True}) - ) + (named_did, named_verkey) = \ + await create_and_store_my_did(wh, json.dumps({'seed': named_seed})) + named_did = dest or named_did + named_verkey = verkey or named_verkey + named_verkey = None if skipverkey else named_verkey nym_request = await build_nym_request(submitter_did, named_did, named_verkey, alias, role) return nym_request, named_did @@ -417,19 +302,6 @@ def sdk_sign_and_send_prepared_request(looper, sdk_wallet, sdk_pool_handle, stri return request_couple -def sendUpdateNode(stewardClient, stewardWallet, node, node_data): - nodeNym = hexToFriendly(node.nodestack.verhex) - op = { - TXN_TYPE: NODE, - TARGET_NYM: nodeNym, - DATA: node_data, - } - - req = stewardWallet.signOp(op) - stewardClient.submitReqs(req) - return req - - def sdk_send_update_node(looper, sdk_submitter_wallet, sdk_pool_handle, destination, alias, @@ -460,16 +332,11 @@ def sdk_send_update_node(looper, sdk_submitter_wallet, return reply -def updateNodeData(looper, stewardClient, stewardWallet, node, node_data): - req = sendUpdateNode(stewardClient, stewardWallet, node, node_data) - waitForSufficientRepliesForRequests(looper, stewardClient, - requests=[req]) - - def sdk_pool_refresh(looper, sdk_pool_handle): looper.loop.run_until_complete( refresh_pool_ledger(sdk_pool_handle)) + def sdk_build_get_txn_request(looper, steward_did, data): request = looper.loop.run_until_complete( build_get_txn_request(steward_did, data)) @@ -517,31 +384,6 @@ def update_node_data_and_reconnect(looper, txnPoolNodeSet, return restartedNode -def changeNodeKeys(looper, stewardClient, stewardWallet, node, verkey): - nodeNym = hexToFriendly(node.nodestack.verhex) - - op = { - TXN_TYPE: NODE, - TARGET_NYM: nodeNym, - VERKEY: verkey, - DATA: { - ALIAS: node.name - } - } - req = stewardWallet.signOp(op) - stewardClient.submitReqs(req) - - waitForSufficientRepliesForRequests(looper, stewardClient, - requests=[req]) - - node.nodestack.clearLocalRoleKeep() - node.nodestack.clearRemoteRoleKeeps() - node.nodestack.clearAllDir() - node.clientstack.clearLocalRoleKeep() - node.clientstack.clearRemoteRoleKeeps() - node.clientstack.clearAllDir() - - def sdk_change_node_keys(looper, node, sdk_wallet_steward, sdk_pool_handle, verkey): _, steward_did = sdk_wallet_steward node_dest = hexToFriendly(node.nodestack.verhex) @@ -566,37 +408,24 @@ def sdk_change_node_keys(looper, node, sdk_wallet_steward, sdk_pool_handle, verk node.clientstack.clearAllDir() -def suspendNode(looper, stewardClient, stewardWallet, nodeNym, nodeName): - op = { - TXN_TYPE: NODE, - TARGET_NYM: nodeNym, - DATA: { - SERVICES: [], - ALIAS: nodeName - } - } - req = stewardWallet.signOp(op) - stewardClient.submitReqs(req) +def demote_node(looper, steward_wallet, sdk_pool_handle, + node): + node_nym = hexToFriendly(node.nodestack.verhex) + sdk_send_update_node(looper, steward_wallet, + sdk_pool_handle, node_nym, node.name, + None, None, + None, None, + services=[]) - waitForSufficientRepliesForRequests(looper, stewardClient, - requests=[req]) - -def cancelNodeSuspension(looper, stewardClient, stewardWallet, nodeNym, - nodeName): - op = { - TXN_TYPE: NODE, - TARGET_NYM: nodeNym, - DATA: { - SERVICES: [VALIDATOR], - ALIAS: nodeName - } - } - - req = stewardWallet.signOp(op) - stewardClient.submitReqs(req) - waitForSufficientRepliesForRequests(looper, stewardClient, - requests=[req]) +def promote_node(looper, steward_wallet, sdk_pool_handle, + node): + node_nym = hexToFriendly(node.nodestack.verhex) + sdk_send_update_node(looper, steward_wallet, + sdk_pool_handle, node_nym, node.name, + None, None, + None, None, + services=[VALIDATOR]) def buildPoolClientAndWallet(clientData, tempDir, clientClass=None, walletClass=None): @@ -611,16 +440,6 @@ def buildPoolClientAndWallet(clientData, tempDir, clientClass=None, walletClass= return client, w -def new_client(looper, poolTxnClientData, txnPoolNodeSet, client_tdir): - client, wallet = buildPoolClientAndWallet(poolTxnClientData, - client_tdir) - looper.add(client) - looper.run(client.ensureConnectedToNodes()) - ensureClientConnectedToNodesAndPoolLedgerSame(looper, client, - *txnPoolNodeSet) - return client, wallet - - def disconnectPoolNode(poolNodes: Iterable, disconnect: Union[str, TestNode], stopNode=True): @@ -704,30 +523,6 @@ def reconnect_node_and_ensure_connected(looper: Looper, looper.run(checkNodesConnected(poolNodes, customTimeout=timeout)) -def add_2_nodes(looper, existing_nodes, steward, steward_wallet, - tdir, client_tdir, tconf, all_plugins_path, names=None): - assert names is None or (isinstance(names, list) and len(names) == 2) - names = names or ("Zeta", "Eta") - new_nodes = [] - for node_name in names: - new_steward_name = "testClientSteward" + randomString(3) - new_steward, new_steward_wallet, new_node = addNewStewardAndNode(looper, - steward, - steward_wallet, - new_steward_name, - node_name, - tdir, - client_tdir, - tconf, - all_plugins_path) - existing_nodes.append(new_node) - looper.run(checkNodesConnected(existing_nodes)) - waitNodeDataEquality(looper, new_node, *existing_nodes[:-1]) - new_nodes.append(new_node) - - return new_nodes - - def sdk_add_2_nodes(looper, txnPoolNodeSet, sdk_pool_handle, sdk_wallet_steward, tdir, tconf, allPluginsPath): diff --git a/plenum/test/pool_transactions/test_client_with_pool_txns.py b/plenum/test/pool_transactions/test_client_with_pool_txns.py index 241e8fc526..6748061d82 100644 --- a/plenum/test/pool_transactions/test_client_with_pool_txns.py +++ b/plenum/test/pool_transactions/test_client_with_pool_txns.py @@ -1,10 +1,9 @@ -from plenum.test.node_request.helper import sdk_ensure_pool_functional - from plenum.test.pool_transactions.helper import sdk_pool_refresh from stp_core.loop.eventually import eventually from stp_core.common.log import getlogger from plenum.test import waits from plenum.test.helper import sdk_send_random_and_check +from plenum.test.node_request.helper import sdk_ensure_pool_functional from plenum.test.test_node import checkNodesConnected, TestNode, \ ensureElectionsDone from plenum.common.config_helper import PNodeConfigHelper diff --git a/plenum/test/pool_transactions/test_nodes_with_pool_txns.py b/plenum/test/pool_transactions/test_nodes_with_pool_txns.py index 429ca7cd11..aab57513a0 100644 --- a/plenum/test/pool_transactions/test_nodes_with_pool_txns.py +++ b/plenum/test/pool_transactions/test_nodes_with_pool_txns.py @@ -6,7 +6,6 @@ from plenum.common.exceptions import RequestRejectedException, \ RequestNackedException -from plenum.test.node_request.helper import sdk_ensure_pool_functional from plenum.common.constants import DATA, TARGET_NYM, \ NODE_IP, NODE_PORT, CLIENT_IP, CLIENT_PORT, STEWARD_STRING @@ -15,6 +14,7 @@ from plenum.test import waits from plenum.test.helper import sdk_send_random_and_check, \ sdk_get_and_check_replies +from plenum.test.node_request.helper import sdk_ensure_pool_functional from plenum.test.pool_transactions.helper import sdk_add_new_node, \ sdk_add_2_nodes, sdk_pool_refresh, sdk_add_new_nym, prepare_new_node_data, \ prepare_node_request, sdk_sign_and_send_prepared_request diff --git a/plenum/test/pool_transactions/test_start_many_nodes.py b/plenum/test/pool_transactions/test_start_many_nodes.py index 2286bffd50..49221e5ced 100644 --- a/plenum/test/pool_transactions/test_start_many_nodes.py +++ b/plenum/test/pool_transactions/test_start_many_nodes.py @@ -1,9 +1,9 @@ # Start with 8 nodes -from plenum.test.node_request.helper import sdk_ensure_pool_functional from plenum.common.constants import NYM, ROLE, STEWARD from plenum.common.constants import TXN_TYPE from plenum.test.helper import assertEquality +from plenum.test.node_request.helper import sdk_ensure_pool_functional nodeCount = 8 diff --git a/plenum/test/pool_transactions/test_suspend_node.py b/plenum/test/pool_transactions/test_suspend_node.py index 46e76cfe99..701493f029 100644 --- a/plenum/test/pool_transactions/test_suspend_node.py +++ b/plenum/test/pool_transactions/test_suspend_node.py @@ -1,92 +1,59 @@ import pytest -from plenum.client.client import Client + +from stp_core.network.exceptions import RemoteNotFound + +from plenum.test.helper import sendMessageAndCheckDelivery + +from plenum.test.node_request.helper import sdk_ensure_pool_functional +from plenum.test.view_change.helper import start_stopped_node + from stp_core.loop.eventually import eventually -from plenum.common.constants import CLIENT_STACK_SUFFIX -from plenum.common.util import hexToFriendly from plenum.server.node import Node -from plenum.test.helper import waitForSufficientRepliesForRequests -from plenum.test.node_catchup.helper import \ - ensureClientConnectedToNodesAndPoolLedgerSame -from plenum.test.pool_transactions.helper import suspendNode, \ - buildPoolClientAndWallet, cancelNodeSuspension -from plenum.test.test_node import TestNode, checkNodesConnected +from plenum.test.pool_transactions.helper import demote_node, \ + promote_node, sdk_pool_refresh +from plenum.test.test_node import checkNodesConnected -def checkNodeNotInNodeReg(nodeOrClient, nodeName): - if isinstance(nodeOrClient, Node): - assert nodeName not in nodeOrClient.nodeReg - assert nodeName not in nodeOrClient.nodestack.connecteds - elif isinstance(nodeOrClient, Client): - clientStackName = nodeName + CLIENT_STACK_SUFFIX - assert clientStackName not in nodeOrClient.nodeReg - assert clientStackName not in nodeOrClient.nodestack.connecteds +def checkNodeNotInNodeReg(node, nodeName): + if isinstance(node, Node): + assert nodeName not in node.nodeReg + assert nodeName not in node.nodestack.connecteds else: raise ValueError("pass a node or client object as first argument") -@pytest.mark.skip(reason="SOV-383") def testStewardSuspendsNode(looper, txnPoolNodeSet, - tdirWithPoolTxns, tconf, - steward1, stewardWallet, - nodeThetaAdded, + tdir, tconf, + sdk_pool_handle, + sdk_wallet_steward, + sdk_node_theta_added, poolTxnStewardData, allPluginsPath): - newSteward, newStewardWallet, newNode = nodeThetaAdded - newNodeNym = hexToFriendly(newNode.nodestack.verhex) - suspendNode(looper, newSteward, newStewardWallet, newNodeNym, newNode.name) + new_steward_wallet, new_node = sdk_node_theta_added + demote_node(looper, new_steward_wallet, sdk_pool_handle, new_node) # Check suspended node does not exist in any nodeReg or remotes of # nodes or clients txnPoolNodeSet = txnPoolNodeSet[:-1] for node in txnPoolNodeSet: - looper.run(eventually(checkNodeNotInNodeReg, node, newNode.name)) - for client in (steward1, newSteward): - looper.run(eventually(checkNodeNotInNodeReg, client, newNode.name)) - - # Check a client can send request and receive replies - # req = sendRandomRequest(newStewardWallet, newSteward) - waitForSufficientRepliesForRequests(looper, newSteward, - requests=[req]) - - # Check that a restarted client or node does not connect to the suspended + looper.run(eventually(checkNodeNotInNodeReg, node, new_node.name)) + # Check that a node does not connect to the suspended # node - steward1.stop() - looper.removeProdable(steward1) - steward1, stewardWallet = buildPoolClientAndWallet(poolTxnStewardData, - tdirWithPoolTxns) - looper.add(steward1) - ensureClientConnectedToNodesAndPoolLedgerSame(looper, steward1, - *txnPoolNodeSet) - looper.run(eventually(checkNodeNotInNodeReg, steward1, newNode.name)) - - newNode.stop() - looper.removeProdable(newNode) + sdk_ensure_pool_functional(looper, txnPoolNodeSet, new_steward_wallet, sdk_pool_handle) + with pytest.raises(RemoteNotFound): + looper.loop.run_until_complete(sendMessageAndCheckDelivery(txnPoolNodeSet[0], new_node)) - # TODO: There is a bug that if a primary node is turned off, it sends - # duplicate Pre-Prepare and gets blacklisted. Here is the gist - # https://gist.github.com/lovesh/c16989616ebb6856f9fa2905c14dc4b7 - oldNodeIdx, oldNode = [(i, n) for i, n in enumerate(txnPoolNodeSet) - if not n.hasPrimary][0] - oldNode.stop() - looper.removeProdable(oldNode) - oldNode = TestNode(oldNode.name, basedirpath=tdirWithPoolTxns, base_data_dir=tdirWithPoolTxns, - config=tconf, pluginPaths=allPluginsPath) - looper.add(oldNode) - txnPoolNodeSet[oldNodeIdx] = oldNode - looper.run(checkNodesConnected(txnPoolNodeSet)) - looper.run(eventually(checkNodeNotInNodeReg, oldNode, newNode.name)) + new_node.stop() + looper.removeProdable(new_node) # Check that a node whose suspension is revoked can reconnect to other # nodes and clients can also connect to that node - cancelNodeSuspension(looper, newSteward, newStewardWallet, newNodeNym, - newNode.name) - nodeTheta = TestNode(newNode.name, basedirpath=tdirWithPoolTxns, base_data_dir=tdirWithPoolTxns, - config=tconf, pluginPaths=allPluginsPath, - ha=newNode.nodestack.ha, cliha=newNode.clientstack.ha) - looper.add(nodeTheta) + + promote_node(looper, new_steward_wallet, sdk_pool_handle, new_node) + nodeTheta = start_stopped_node(new_node, looper, tconf, + tdir, allPluginsPath, + delay_instance_change_msgs=False) txnPoolNodeSet.append(nodeTheta) looper.run(checkNodesConnected(txnPoolNodeSet)) - ensureClientConnectedToNodesAndPoolLedgerSame(looper, steward1, - *txnPoolNodeSet) - ensureClientConnectedToNodesAndPoolLedgerSame(looper, newSteward, - *txnPoolNodeSet) + sdk_pool_refresh(looper, sdk_pool_handle) + sdk_ensure_pool_functional(looper, txnPoolNodeSet, sdk_wallet_steward, sdk_pool_handle) diff --git a/plenum/test/pool_transactions/test_txn_pool_manager.py b/plenum/test/pool_transactions/test_txn_pool_manager.py index a0cba2d1ef..af5b40da63 100644 --- a/plenum/test/pool_transactions/test_txn_pool_manager.py +++ b/plenum/test/pool_transactions/test_txn_pool_manager.py @@ -1,8 +1,9 @@ import pytest + from plenum.common.util import hexToFriendly from plenum.common.constants import TARGET_NYM, TXN_TYPE, NODE, CLIENT_STACK_SUFFIX -from plenum.test.pool_transactions.helper import sdk_send_update_node +from plenum.test.pool_transactions.helper import sdk_send_update_node, demote_node nodeCount = 7 nodes_wth_bls = 0 @@ -34,19 +35,11 @@ def test_get_nym_by_name_demoted(txnPoolNodeSet, pool_node_txns, looper, sdk_wallet_steward, sdk_pool_handle): # sdk_wallet_steward fixture is a steward for [0] node, # so we can do things below: - demote_node(txnPoolNodeSet[0], looper, sdk_wallet_steward, sdk_pool_handle) + demote_node(looper, sdk_wallet_steward, sdk_pool_handle, + txnPoolNodeSet[0]) check_get_nym_by_name(txnPoolNodeSet, pool_node_txns) -def demote_node(node, looper, sdk_steward_wallet, sdk_pool_handle): - node_dest = hexToFriendly(node.nodestack.verhex) - sdk_send_update_node(looper, sdk_steward_wallet, sdk_pool_handle, - node_dest, node.name, - None, None, - None, None, - services=[]) - - def check_get_nym_by_name(txnPoolNodeSet, pool_node_txns): for i in range(nodeCount): node = txnPoolNodeSet[i] diff --git a/plenum/test/primary_selection/conftest.py b/plenum/test/primary_selection/conftest.py index 2b512f051f..fb2d2efa66 100644 --- a/plenum/test/primary_selection/conftest.py +++ b/plenum/test/primary_selection/conftest.py @@ -5,18 +5,7 @@ from plenum.test.primary_selection.helper import check_newly_added_nodes, \ getPrimaryNodesIdxs from plenum.test.pool_transactions.helper import buildPoolClientAndWallet -from plenum.test.pool_transactions.conftest import nodeThetaAdded, \ - sdk_node_theta_added - - -@pytest.fixture(scope="module") -def one_node_added(looper, txnPoolNodeSet, nodeThetaAdded): - # New node knows primary same primary as others and has rank greater - # than others - _, _, new_node = nodeThetaAdded - waitNodeDataEquality(looper, new_node, *txnPoolNodeSet[:-1]) - check_newly_added_nodes(looper, txnPoolNodeSet, [new_node]) - return new_node +from plenum.test.pool_transactions.conftest import sdk_node_theta_added @pytest.fixture(scope='module') @@ -35,22 +24,6 @@ def txnPoolMasterNodes(txnPoolNodeSet): return txnPoolNodeSet[primariesIdxs[0]], txnPoolNodeSet[primariesIdxs[1]] -@pytest.fixture(scope="module") -def stewardAndWalletForMasterNode(looper, poolTxnData, poolTxnStewardNames, - tdirWithClientPoolTxns, txnPoolNodeSet, txnPoolMasterNodes): - primariesIdxs = getPrimaryNodesIdxs(txnPoolNodeSet) - master_node = txnPoolMasterNodes[0] - stewardName = poolTxnStewardNames[primariesIdxs[0]] - stewardsSeed = poolTxnData["seeds"][stewardName].encode() - - stewardClient, stewardWallet = buildPoolClientAndWallet( - (stewardName, stewardsSeed), tdirWithClientPoolTxns) - looper.add(stewardClient) - looper.run(stewardClient.ensureConnectedToNodes()) - - return stewardClient, stewardWallet - - @pytest.fixture(scope="module") def checkpoint_size(tconf, request): oldChkFreq = tconf.CHK_FREQ diff --git a/plenum/test/primary_selection/test_add_node_to_pool_with_large_ppseqno.py b/plenum/test/primary_selection/test_add_node_to_pool_with_large_ppseqno.py index 854bb9c644..2bec935656 100644 --- a/plenum/test/primary_selection/test_add_node_to_pool_with_large_ppseqno.py +++ b/plenum/test/primary_selection/test_add_node_to_pool_with_large_ppseqno.py @@ -1,8 +1,8 @@ import pytest -from plenum.test.node_request.helper import sdk_ensure_pool_functional from plenum.common.util import randomString from plenum.test.helper import sdk_send_random_and_check +from plenum.test.node_request.helper import sdk_ensure_pool_functional from plenum.test.view_change.helper import ensure_several_view_change from plenum.test.pool_transactions.helper import sdk_add_new_steward_and_node from plenum.test.test_node import checkNodesConnected diff --git a/plenum/test/primary_selection/test_add_node_with_f_changed.py b/plenum/test/primary_selection/test_add_node_with_f_changed.py index 8ebe438813..ac0d4c8013 100644 --- a/plenum/test/primary_selection/test_add_node_with_f_changed.py +++ b/plenum/test/primary_selection/test_add_node_with_f_changed.py @@ -3,7 +3,7 @@ from plenum.test.node_catchup.helper import waitNodeDataEquality from plenum.common.util import randomString from plenum.test.test_node import checkNodesConnected -from plenum.test.pool_transactions.helper import addNewStewardAndNode +from plenum.test.pool_transactions.helper import sdk_add_new_steward_and_node from plenum.test import waits logger = getlogger() @@ -26,19 +26,19 @@ def tconf(tconf): tconf.RETRY_TIMEOUT_NOT_RESTRICTED = old_timeout_not_restricted -def add_new_node(looper, nodes, steward, steward_wallet, - tdir, client_tdir, tconf, all_plugins_path, name=None): +def add_new_node(looper, nodes, sdk_pool_handle, sdk_wallet_steward, + tdir, tconf, all_plugins_path, name=None): node_name = name or randomString(5) new_steward_name = "testClientSteward" + randomString(3) - new_steward, new_steward_wallet, new_node = addNewStewardAndNode(looper, - steward, - steward_wallet, - new_steward_name, - node_name, - tdir, - client_tdir, - tconf, - all_plugins_path) + new_steward_wallet_handle, new_node = \ + sdk_add_new_steward_and_node(looper, + sdk_pool_handle, + sdk_wallet_steward, + new_steward_name, + node_name, + tdir, + tconf, + all_plugins_path) nodes.append(new_node) looper.run(checkNodesConnected(nodes, customTimeout=60)) timeout = waits.expectedPoolCatchupTime(nodeCount=len(nodes)) @@ -48,46 +48,41 @@ def add_new_node(looper, nodes, steward, steward_wallet, def test_add_node_with_f_changed(looper, txnPoolNodeSet, tdir, tconf, - allPluginsPath, steward1, stewardWallet, - client_tdir, limitTestRunningTime): - + allPluginsPath, sdk_pool_handle, + sdk_wallet_steward, limitTestRunningTime): nodes = txnPoolNodeSet add_new_node(looper, nodes, - steward1, - stewardWallet, + sdk_pool_handle, + sdk_wallet_steward, tdir, - client_tdir, tconf, allPluginsPath, name="Node5") add_new_node(looper, nodes, - steward1, - stewardWallet, + sdk_pool_handle, + sdk_wallet_steward, tdir, - client_tdir, tconf, allPluginsPath, name="Node6") add_new_node(looper, nodes, - steward1, - stewardWallet, + sdk_pool_handle, + sdk_wallet_steward, tdir, - client_tdir, tconf, allPluginsPath, name="Node7") add_new_node(looper, nodes, - steward1, - stewardWallet, + sdk_pool_handle, + sdk_wallet_steward, tdir, - client_tdir, tconf, allPluginsPath, name="Node8") # check that all nodes have equal number of replica assert len(set([n.replicas.num_replicas for n in txnPoolNodeSet])) == 1 - assert txnPoolNodeSet[-1].replicas.num_replicas == txnPoolNodeSet[-1].requiredNumberOfInstances \ No newline at end of file + assert txnPoolNodeSet[-1].replicas.num_replicas == txnPoolNodeSet[-1].requiredNumberOfInstances diff --git a/plenum/test/primary_selection/test_recover_after_demoted.py b/plenum/test/primary_selection/test_recover_after_demoted.py index 3386b99031..9838f60de1 100644 --- a/plenum/test/primary_selection/test_recover_after_demoted.py +++ b/plenum/test/primary_selection/test_recover_after_demoted.py @@ -1,9 +1,6 @@ -from plenum.common.constants import ALIAS, SERVICES - from plenum.test.helper import sdk_send_random_and_check, waitForViewChange from plenum.test.node_catchup.helper import ensure_all_nodes_have_same_data -from plenum.test.pool_transactions.helper import updateNodeData, \ - buildPoolClientAndWallet +from plenum.test.pool_transactions.helper import demote_node from plenum.test.view_change.helper import ensure_view_change_by_primary_restart from stp_core.common.log import getlogger @@ -13,25 +10,12 @@ def demote_primary_node(looper, initial_pool_of_nodes, pool_of_nodes, - poolTxnStewardNames, - poolTxnData, - tdirWithClientPoolTxns): + sdk_pool_handle, + sdk_wallet_stewards): demoted_node = [node for node in pool_of_nodes if node.has_master_primary][0] indx = initial_pool_of_nodes.index(demoted_node) - steward_name = poolTxnStewardNames[indx] - stewards_seed = poolTxnData["seeds"][steward_name].encode() - - stewardClient, stewardWallet = buildPoolClientAndWallet( - (steward_name, stewards_seed), tdirWithClientPoolTxns) - looper.add(stewardClient) - looper.run(stewardClient.ensureConnectedToNodes()) - - node_data = { - ALIAS: demoted_node.name, - SERVICES: [] - } - updateNodeData(looper, stewardClient, - stewardWallet, demoted_node, node_data) + demote_node(looper, sdk_wallet_stewards[indx], + sdk_pool_handle, demoted_node) pool_of_nodes = list(set(pool_of_nodes) - {demoted_node}) return pool_of_nodes @@ -41,9 +25,7 @@ def test_restart_primaries_then_demote( looper, txnPoolNodeSet, tconf, tdir, allPluginsPath, sdk_pool_handle, sdk_wallet_steward, - poolTxnStewardNames, - poolTxnData, - tdirWithClientPoolTxns): + sdk_wallet_stewards): """ """ logger.info("1. Restart Node1") @@ -75,9 +57,8 @@ def test_restart_primaries_then_demote( pool_of_nodes = demote_primary_node(looper, txnPoolNodeSet, pool_of_nodes, - poolTxnStewardNames, - poolTxnData, - tdirWithClientPoolTxns) + sdk_pool_handle, + sdk_wallet_stewards) # make sure view changed waitForViewChange(looper, pool_of_nodes, expectedViewNo=3) diff --git a/plenum/test/propagate/test_propagate_recvd_after_request.py b/plenum/test/propagate/test_propagate_recvd_after_request.py index 88559c8c2b..f9a5a56af6 100644 --- a/plenum/test/propagate/test_propagate_recvd_after_request.py +++ b/plenum/test/propagate/test_propagate_recvd_after_request.py @@ -1,6 +1,7 @@ import pytest from plenum.common.constants import PROPAGATE +from plenum.test.helper import sdk_json_to_request_object from stp_core.loop.eventually import eventually from plenum.common.messages.node_messages import Propagate from plenum.test.delayers import delay, msg_rep_delay @@ -23,6 +24,7 @@ def setup(txnPoolNodeSet): def testPropagateRecvdAfterRequest(setup, looper, txnPoolNodeSet, sent1): A, B, C, D = txnPoolNodeSet # type: TestNode + sent1 = sdk_json_to_request_object(sent1[0][0]) def x(): # A should have received a request from the client diff --git a/plenum/test/script/helper.py b/plenum/test/script/helper.py index 423e77ef67..8bd339ea78 100644 --- a/plenum/test/script/helper.py +++ b/plenum/test/script/helper.py @@ -23,7 +23,8 @@ def looper(txnPoolNodesLooper): def changeNodeHa(looper, txnPoolNodeSet, tdirWithClientPoolTxns, tconf, shouldBePrimary, tdir, - sdk_pool_handle, sdk_wallet_stewards): + sdk_pool_handle, sdk_wallet_stewards, + sdk_wallet_client): # prepare new ha for node and client stack subjectedNode = None node_index = None @@ -74,5 +75,5 @@ def changeNodeHa(looper, txnPoolNodeSet, tdirWithClientPoolTxns, sdk_pool_refresh(looper, sdk_pool_handle) sdk_send_random_and_check(looper, txnPoolNodeSet, sdk_pool_handle, - sdk_wallet_steward, + sdk_wallet_client, 8) diff --git a/plenum/test/script/test_change_non_primary_node_ha.py b/plenum/test/script/test_change_non_primary_node_ha.py index 6f0b5f258f..ec409f76d2 100644 --- a/plenum/test/script/test_change_non_primary_node_ha.py +++ b/plenum/test/script/test_change_non_primary_node_ha.py @@ -15,7 +15,8 @@ @pytest.mark.skipif('sys.platform == "win32"', reason='SOV-330') def testChangeNodeHaForNonPrimary(looper, txnPoolNodeSet, tdirWithClientPoolTxns, poolTxnData, poolTxnStewardNames, tconf, tdir, - sdk_pool_handle, sdk_wallet_stewards): + sdk_pool_handle, sdk_wallet_stewards, + sdk_wallet_client): changeNodeHa(looper, txnPoolNodeSet, tdirWithClientPoolTxns, @@ -23,4 +24,5 @@ def testChangeNodeHaForNonPrimary(looper, txnPoolNodeSet, tdirWithClientPoolTxns shouldBePrimary=False, tdir=tdir, sdk_pool_handle=sdk_pool_handle, - sdk_wallet_stewards=sdk_wallet_stewards) + sdk_wallet_stewards=sdk_wallet_stewards, + sdk_wallet_client=sdk_wallet_client) diff --git a/plenum/test/script/test_change_primary_node_ha.py b/plenum/test/script/test_change_primary_node_ha.py index 953e54ff50..320f61c870 100644 --- a/plenum/test/script/test_change_primary_node_ha.py +++ b/plenum/test/script/test_change_primary_node_ha.py @@ -16,7 +16,8 @@ @pytest.mark.skipif('sys.platform == "win32"', reason='SOV-330') def testChangeNodeHaForPrimary(looper, txnPoolNodeSet, tdirWithClientPoolTxns, poolTxnData, poolTxnStewardNames, tconf, tdir, - sdk_pool_handle, sdk_wallet_stewards): + sdk_pool_handle, sdk_wallet_stewards, + sdk_wallet_client): changeNodeHa(looper, txnPoolNodeSet, tdirWithClientPoolTxns, @@ -24,4 +25,5 @@ def testChangeNodeHaForPrimary(looper, txnPoolNodeSet, tdirWithClientPoolTxns, shouldBePrimary=True, tdir=tdir, sdk_pool_handle=sdk_pool_handle, - sdk_wallet_stewards=sdk_wallet_stewards) + sdk_wallet_stewards=sdk_wallet_stewards, + sdk_wallet_client=sdk_wallet_client) diff --git a/plenum/test/signing/test_signing.py b/plenum/test/signing/test_signing.py index b06814c321..05f10a2306 100644 --- a/plenum/test/signing/test_signing.py +++ b/plenum/test/signing/test_signing.py @@ -1,5 +1,6 @@ import pytest +from plenum.test.helper import sdk_json_to_request_object from stp_core.loop.eventually import eventually from plenum.common.exceptions import InsufficientCorrectSignatures from stp_core.common.log import getlogger @@ -38,6 +39,7 @@ def testOneNodeAltersAClientRequest(looper, setup, evilAlpha, sent1): + sent1 = sdk_json_to_request_object(sent1[0][0]) checkPropagated(looper, txnPoolNodeSet, sent1, faultyNodes) goodNodes = setup.goodNodes diff --git a/plenum/test/storage/test_client_req_rep_store.py b/plenum/test/storage/test_client_req_rep_store.py deleted file mode 100644 index 3676e9c351..0000000000 --- a/plenum/test/storage/test_client_req_rep_store.py +++ /dev/null @@ -1,7 +0,0 @@ -def testReqAcks(replied1, client1): - reqId = replied1.reqId - identifier = replied1.identifier - assert len(client1.nodeReg) == len(client1.reqRepStore.getAcks(identifier, - reqId)) - assert set(client1.nodeReg.keys()) == \ - set(client1.reqRepStore.getAcks(identifier, reqId)) diff --git a/plenum/test/storage/test_hash_stores.py b/plenum/test/storage/test_hash_stores.py index 8dde45542c..9a58287f18 100644 --- a/plenum/test/storage/test_hash_stores.py +++ b/plenum/test/storage/test_hash_stores.py @@ -37,7 +37,7 @@ def testReadWrite(hashStore, nodesLeaves): assert onebyone == multiple -def testRecoverLedgerFromHashStore(hashStore, tdir): +def testRecoverLedgerFromHashStore(hashStore, tconf, tdir): cleanup(hashStore) tree = CompactMerkleTree(hashStore=hashStore) ledger = Ledger(tree=tree, dataDir=tdir) diff --git a/plenum/test/test_dirty_read.py b/plenum/test/test_dirty_read.py index 681988cf2f..72b5e09e50 100644 --- a/plenum/test/test_dirty_read.py +++ b/plenum/test/test_dirty_read.py @@ -1,10 +1,9 @@ -from plenum.common.types import f -from plenum.test.helper import getRepliesFromClientInbox, \ - send_signed_requests, \ - waitForSufficientRepliesForRequests, sdk_send_random_and_check, sdk_get_and_check_replies -from plenum.common.constants import GET_TXN, DATA, TXN_TYPE, DOMAIN_LEDGER_ID +from plenum.test.helper import sdk_send_random_and_check, \ + sdk_get_and_check_replies +from plenum.common.constants import DATA from plenum.common.messages.node_messages import Ordered -from plenum.test.pool_transactions.helper import sdk_build_get_txn_request, sdk_sign_and_send_prepared_request +from plenum.test.pool_transactions.helper import sdk_build_get_txn_request, \ + sdk_sign_and_send_prepared_request from stp_core.common.log import getlogger logger = getlogger() diff --git a/plenum/test/test_node_basic.py b/plenum/test/test_node_basic.py index c35317f520..733298d373 100644 --- a/plenum/test/test_node_basic.py +++ b/plenum/test/test_node_basic.py @@ -5,8 +5,8 @@ from plenum.test.node_helpers.node_helper import getProtocolInstanceNums from plenum.common.util import getMaxFailures from stp_core.common.util import adict -from plenum.test.helper import checkNodesConnected, \ - sendMessageAndCheckDelivery, msgAll +from plenum.test.helper import sendMessageAndCheckDelivery, msgAll +from plenum.test.test_node import checkNodesConnected from plenum.test.msgs import randomMsg nodeCount = 4 diff --git a/plenum/test/test_req_authenticator.py b/plenum/test/test_req_authenticator.py index ec675b3398..e5683c45c1 100644 --- a/plenum/test/test_req_authenticator.py +++ b/plenum/test/test_req_authenticator.py @@ -1,12 +1,15 @@ +import json + import pytest +from indy.did import key_for_did from plenum.common.constants import TXN_TYPE, DATA, GET_TXN, DOMAIN_LEDGER_ID from plenum.common.exceptions import NoAuthenticatorFound from plenum.common.types import f from plenum.common.util import randomString from plenum.server.client_authn import SimpleAuthNr, CoreAuthNr from plenum.server.req_authenticator import ReqAuthenticator -from plenum.test.plugin.helper import submitOp +from plenum.test.helper import sdk_sign_and_submit_op from plenum.test.pool_transactions.helper import new_client_request @@ -38,7 +41,9 @@ def test_authenticator_registration(pre_reqs, registration): assert req_authnr.get_authnr_by_type(CoreAuthNr) == core_authnr -def test_authentication(pre_reqs, registration, client1, wallet1): +def test_authentication(looper, pre_reqs, registration, + sdk_wallet_client, + sdk_pool_handle): _, core_authnr, req_authnr = pre_reqs # Remove simple_authnr @@ -51,9 +56,10 @@ def test_authentication(pre_reqs, registration, client1, wallet1): DATA: 1 } # Just creating the request - req = submitOp(wallet1, client1, op) + req = sdk_sign_and_submit_op(looper, sdk_pool_handle, + sdk_wallet_client, op) with pytest.raises(NoAuthenticatorFound): - req_authnr.authenticate(req.as_dict) + req_authnr.authenticate(req[0]) # Empty set for query txn type op = { @@ -62,11 +68,13 @@ def test_authentication(pre_reqs, registration, client1, wallet1): DATA: 1 } # Just creating the request - req = submitOp(wallet1, client1, op) - assert set() == req_authnr.authenticate(req.as_dict) + req = sdk_sign_and_submit_op(looper, sdk_pool_handle, + sdk_wallet_client, op) + assert set() == req_authnr.authenticate(req[0]) # identifier for write type - req, new_wallet = new_client_request(None, randomString(), wallet1) - core_authnr.addIdr(wallet1.defaultId, - wallet1.getVerkey(wallet1.defaultId)) - assert req_authnr.authenticate(req.as_dict) == {wallet1.defaultId, } + wh, did = sdk_wallet_client + req = new_client_request(None, randomString(), looper, sdk_wallet_client) + core_authnr.addIdr(did, + looper.loop.run_until_complete(key_for_did(sdk_pool_handle, wh, did))) + assert req_authnr.authenticate(json.loads(req)) == {did, } diff --git a/plenum/test/test_request_executed_once_and_without_failing_behind.py b/plenum/test/test_request_executed_once_and_without_failing_behind.py index 36c2533f13..8ff934d3d4 100644 --- a/plenum/test/test_request_executed_once_and_without_failing_behind.py +++ b/plenum/test/test_request_executed_once_and_without_failing_behind.py @@ -1,9 +1,6 @@ from plenum.common.constants import DOMAIN_LEDGER_ID from plenum.common.messages.node_messages import Checkpoint -from plenum.test.helper import \ - send_signed_requests, \ - waitForSufficientRepliesForRequests, \ - random_requests +from plenum.test.helper import sdk_send_random_and_check def set_checkpoint_faking(replica): @@ -20,8 +17,8 @@ def send(msg, stat=None): def test_request_executed_once_and_without_failing_behind(tconf, looper, txnPoolNodeSet, - client1, - wallet1): + sdk_pool_handle, + sdk_wallet_client): """ Checks that all requests executed only once and without failing behind in wrote transactions @@ -41,16 +38,12 @@ def test_request_executed_once_and_without_failing_behind(tconf, looper, for replica in node.replicas: set_checkpoint_faking(replica) - requests = [wallet1.signOp(req) - for req in random_requests(number_of_requests)] + replies = sdk_send_random_and_check(looper, txnPoolNodeSet, + sdk_pool_handle, + sdk_wallet_client, + number_of_requests) - for request in requests: - send_signed_requests(client1, [request]) - waitForSufficientRepliesForRequests(looper, - client1, - requests=[request]) - - expected = [request.reqId for request in requests] + expected = [request[0]['reqId'] for request in replies] for node in txnPoolNodeSet: real_ledger_state = [txn[1]['reqId'] for txn in node.getLedger(DOMAIN_LEDGER_ID).getAllTxn() if 'reqId' in txn[1]] diff --git a/plenum/test/validator_info/test_validator_info.py b/plenum/test/validator_info/test_validator_info.py index 020d5bc245..89122876bb 100644 --- a/plenum/test/validator_info/test_validator_info.py +++ b/plenum/test/validator_info/test_validator_info.py @@ -5,21 +5,16 @@ import pytest import re -from plenum.common.constants import TXN_TYPE, GET_TXN, DATA, NODE, \ - CURRENT_PROTOCOL_VERSION, DOMAIN_LEDGER_ID -from plenum.common.request import Request -from plenum.common.types import f -from plenum.common.util import getTimeBasedId +from plenum.common.constants import TXN_TYPE, NODE from plenum.server.validator_info_tool import ValidatorNodeInfoTool -from plenum.test import waits -from plenum.test.helper import check_sufficient_replies_received, \ - sdk_send_random_and_check + +from plenum.test.helper import sdk_send_random_and_check # noinspection PyUnresolvedReferences from plenum.test.node_catchup.helper import ensureClientConnectedToNodesAndPoolLedgerSame -from plenum.test.pool_transactions.helper import disconnect_node_and_ensure_disconnected +from plenum.test.pool_transactions.helper import disconnect_node_and_ensure_disconnected, sdk_build_get_txn_request, \ + sdk_sign_and_send_prepared_request from plenum.test.test_client import genTestClient from stp_core.common.constants import ZMQ_NETWORK_PROTOCOL -from stp_core.loop.eventually import eventually TEST_NODE_NAME = 'Alpha' INFO_FILENAME = '{}_info.json'.format(TEST_NODE_NAME.lower()) @@ -113,7 +108,7 @@ def test_validator_info_file_metrics_avg_read_field_valid(info, read_txn_and_get_latest_info ): assert info['metrics']['average-per-second']['read-transactions'] == 0 - latest_info = read_txn_and_get_latest_info(GET_TXN) + latest_info = read_txn_and_get_latest_info() assert latest_info['metrics']['average-per-second']['read-transactions'] > 0 @@ -216,29 +211,18 @@ def node(txnPoolNodeSet): @pytest.fixture -def read_txn_and_get_latest_info(txnPoolNodesLooper, patched_dump_info_period, - client_and_wallet, info_path): - client, wallet = client_and_wallet - - def read_wrapped(txn_type): - op = { - TXN_TYPE: txn_type, - f.LEDGER_ID.nm: DOMAIN_LEDGER_ID, - DATA: 1 - } - req = Request(identifier=wallet.defaultId, - operation=op, reqId=getTimeBasedId(), - protocolVersion=CURRENT_PROTOCOL_VERSION) - client.submitReqs(req) - - timeout = waits.expectedTransactionExecutionTime( - len(client.inBox)) - - txnPoolNodesLooper.run( - eventually(check_sufficient_replies_received, - client, req.identifier, req.reqId, - retryWait=1, timeout=timeout)) - txnPoolNodesLooper.runFor(patched_dump_info_period) +def read_txn_and_get_latest_info(looper, sdk_wallet_steward, + sdk_pool_handle, info_path, + patched_dump_info_period): + def read_wrapped(): + _, steward_did = sdk_wallet_steward + request = sdk_build_get_txn_request(looper, steward_did, 1) + sdk_sign_and_send_prepared_request(looper, + sdk_wallet_steward, + sdk_pool_handle, + request) + + looper.runFor(patched_dump_info_period) return load_info(info_path) return read_wrapped @@ -268,13 +252,3 @@ def wrapped(): return load_info(info_path) return wrapped - - -@pytest.fixture -def client_and_wallet(txnPoolNodesLooper, tdirWithClientPoolTxns, txnPoolNodeSet): - client, wallet = genTestClient(tmpdir=tdirWithClientPoolTxns, nodes=txnPoolNodeSet, - name='reader', usePoolLedger=True) - txnPoolNodesLooper.add(client) - ensureClientConnectedToNodesAndPoolLedgerSame(txnPoolNodesLooper, client, - *txnPoolNodeSet) - return client, wallet diff --git a/plenum/test/view_change/test_6th_node_join_after_view_change_by_primary_restart.py b/plenum/test/view_change/test_6th_node_join_after_view_change_by_primary_restart.py index a55a8672da..c0059774a7 100644 --- a/plenum/test/view_change/test_6th_node_join_after_view_change_by_primary_restart.py +++ b/plenum/test/view_change/test_6th_node_join_after_view_change_by_primary_restart.py @@ -117,7 +117,7 @@ def test_6th_node_join_after_view_change_by_master_restart( timeout = waits.expectedPoolCatchupTime(nodeCount=len(pool_of_nodes)) for node in pool_of_nodes: - looper.run(eventually(catchuped, node, timeout=2 * timeout)) + looper.run(eventually(catchuped, node, timeout=3 * timeout)) sdk_send_random_and_check(looper, txnPoolNodeSet, sdk_pool_handle, sdk_wallet_steward, 2) new_psi_node = add_new_node(looper, diff --git a/plenum/test/view_change/test_new_node_joins_after_view_change.py b/plenum/test/view_change/test_new_node_joins_after_view_change.py index 8b8c6f3dbc..2b197980d7 100644 --- a/plenum/test/view_change/test_new_node_joins_after_view_change.py +++ b/plenum/test/view_change/test_new_node_joins_after_view_change.py @@ -10,8 +10,8 @@ from stp_core.loop.eventually import eventually from plenum.test.helper import checkViewNoForNodes, sdk_send_random_and_check -from plenum.test.pool_transactions.conftest import nodeThetaAdded -from plenum.test.primary_selection.conftest import one_node_added +from plenum.test.pool_transactions.conftest import sdk_node_theta_added +from plenum.test.primary_selection.conftest import sdk_one_node_added from stp_core.common.log import getlogger @@ -33,8 +33,8 @@ def all_nodes_view_change( @pytest.fixture(scope='module') def new_node_in_correct_view(all_nodes_view_change, looper, txnPoolNodeSet, - one_node_added, sdk_pool_handle, sdk_wallet_client): - new_node = one_node_added + sdk_one_node_added, sdk_pool_handle, sdk_wallet_client): + new_node = sdk_one_node_added looper.run(eventually(checkViewNoForNodes, txnPoolNodeSet, retryWait=1, timeout=10)) assert len(getAllReturnVals(new_node.view_changer, diff --git a/plenum/test/view_change/test_no_instance_change_before_node_is_ready.py b/plenum/test/view_change/test_no_instance_change_before_node_is_ready.py index b532f6917f..c637dfa7ea 100644 --- a/plenum/test/view_change/test_no_instance_change_before_node_is_ready.py +++ b/plenum/test/view_change/test_no_instance_change_before_node_is_ready.py @@ -18,8 +18,7 @@ def tconf(tconf): def test_no_instance_change_on_primary_disconnection_for_not_ready_node( looper, txnPoolNodeSet, tdir, tconf, - allPluginsPath, steward1, stewardWallet, - client_tdir): + allPluginsPath, sdk_pool_handle, sdk_wallet_steward): """ Test steps: 1. create a new node, but don't add it to the pool (so not send NODE txn), so that the node is not ready. @@ -48,9 +47,9 @@ def test_no_instance_change_on_primary_disconnection_for_not_ready_node( node_ha, client_ha, txnPoolNodeSet, - client_tdir, - steward1, stewardWallet, - sigseed, bls_key) + sdk_pool_handle, + sdk_wallet_steward, + bls_key) # 5. wait for more than VIEW_CHANGE_TIMEOUT (a timeout for initial check for disconnected primary) looper.runFor(tconf.VIEW_CHANGE_TIMEOUT + 2) diff --git a/plenum/test/view_change/test_node_detecting_lag_from_view_change_messages.py b/plenum/test/view_change/test_node_detecting_lag_from_view_change_messages.py index c4def36f7b..d2734cfcd8 100644 --- a/plenum/test/view_change/test_node_detecting_lag_from_view_change_messages.py +++ b/plenum/test/view_change/test_node_detecting_lag_from_view_change_messages.py @@ -5,7 +5,7 @@ from plenum.common.util import compare_3PC_keys from plenum.test.delayers import delay_3pc_messages, icDelay, cDelay from plenum.test.helper import send_reqs_batches_and_get_suff_replies, \ - sendRandomRequests, sdk_send_random_requests + sdk_send_random_requests from plenum.test.node_catchup.helper import ensure_all_nodes_have_same_data from plenum.test.spy_helpers import get_count from plenum.test.test_node import getNonPrimaryReplicas diff --git a/plenum/test/view_change/test_queueing_req_from_future_view.py b/plenum/test/view_change/test_queueing_req_from_future_view.py index 33b042992e..b879264766 100644 --- a/plenum/test/view_change/test_queueing_req_from_future_view.py +++ b/plenum/test/view_change/test_queueing_req_from_future_view.py @@ -50,7 +50,6 @@ def chk_fut_view(view_no, is_empty): [lagging_node]) # send more requests that will be queued for the lagged node - # sendReqsToNodesAndVerifySuffReplies(looper, wallet1, client1, 3) reqs = sdk_send_random_requests(looper, sdk_pool_handle, sdk_wallet_client, 5) l = looper.run(eventually(chk_fut_view, old_view_no + 1, False, diff --git a/plenum/test/view_change/test_view_change_min_cathup_timeout.py b/plenum/test/view_change/test_view_change_min_cathup_timeout.py index cfeea99227..292b5a2a12 100644 --- a/plenum/test/view_change/test_view_change_min_cathup_timeout.py +++ b/plenum/test/view_change/test_view_change_min_cathup_timeout.py @@ -1,9 +1,9 @@ import types import pytest -from plenum.test.node_request.helper import sdk_ensure_pool_functional from plenum.test.helper import waitForViewChange, sdk_send_random_and_check +from plenum.test.node_request.helper import sdk_ensure_pool_functional from plenum.test.node_catchup.helper import ensure_all_nodes_have_same_data from plenum.test.test_node import ensureElectionsDone from stp_core.loop.exceptions import EventuallyTimeoutException diff --git a/plenum/test/view_change/test_view_change_timeout.py b/plenum/test/view_change/test_view_change_timeout.py index c2197d0802..ddc0f8d958 100644 --- a/plenum/test/view_change/test_view_change_timeout.py +++ b/plenum/test/view_change/test_view_change_timeout.py @@ -1,8 +1,8 @@ import pytest -from plenum.test.node_request.helper import sdk_ensure_pool_functional from plenum.test.delayers import reset_delays_and_process_delayeds, vcd_delay from plenum.test.helper import waitForViewChange, stopNodes +from plenum.test.node_request.helper import sdk_ensure_pool_functional from plenum.test.node_catchup.helper import ensure_all_nodes_have_same_data from plenum.test.spy_helpers import get_count, getAllReturnVals from plenum.test.test_node import get_master_primary_node, \ diff --git a/scripts/load.py b/scripts/load.py deleted file mode 100644 index ab87114dc0..0000000000 --- a/scripts/load.py +++ /dev/null @@ -1,45 +0,0 @@ -from time import perf_counter - -from plenum.client.client import Client -from plenum.client.wallet import Wallet -from plenum.test.helper import sendRandomRequests, \ - waitForSufficientRepliesForRequests -from stp_core.network.port_dispenser import genHa -from stp_core.loop.looper import Looper -from plenum.common.signer_simple import SimpleSigner -from stp_core.types import HA -from plenum.common.config_util import getConfig - -numReqs = 10000 -splits = 5 - - -def load(): - port = genHa()[1] - ha = HA('0.0.0.0', port) - name = "hello" - wallet = Wallet(name) - wallet.addIdentifier( - signer=SimpleSigner(seed=b'000000000000000000000000Steward1')) - client = Client(name, ha=ha) - with Looper(debug=getConfig().LOOPER_DEBUG) as looper: - looper.add(client) - print('Will send {} reqs in all'.format(numReqs)) - requests = sendRandomRequests(wallet, client, numReqs) - start = perf_counter() - for i in range(0, numReqs, numReqs // splits): - print('Will wait for {} now'.format(numReqs // splits)) - s = perf_counter() - reqs = requests[i:i + numReqs // splits + 1] - waitForSufficientRepliesForRequests(looper, client, - requests=reqs, - customTimeoutPerReq=3) - print('>>> Got replies for {} requests << in {}'. - format(numReqs // splits, perf_counter() - s)) - end = perf_counter() - print('>>>{}<<<'.format(end - start)) - exit(0) - - -if __name__ == "__main__": - load()