From 06778a7640fe1dc2d6d7c09a01610a8633c7b0a0 Mon Sep 17 00:00:00 2001 From: ArtObr Date: Tue, 6 Mar 2018 11:56:49 +0300 Subject: [PATCH] [INDY-1171] Integrate pool_transactions tests with libindy (#541) * Additional checks for sdk_ functions Signed-off-by: ArtObr * Fix for exception handling and new function for "json to object" converting Signed-off-by: ArtObr * Space and the end Signed-off-by: ArtObr * Most of test integrated with txnPoolNodeSet Signed-off-by: ArtObr * 3 test left to do Signed-off-by: ArtObr * two tests left in INDY-1019. Others integrated Signed-off-by: ArtObr * Little fixes Signed-off-by: ArtObr * Import resolve, TODO added Signed-off-by: ArtObr * New line at the end Signed-off-by: ArtObr * TODO for import added Signed-off-by: ArtObr * Unused looper import removed Signed-off-by: ArtObr * One more test integrated with sdk Signed-off-by: ArtObr * Fixtures for prev test Signed-off-by: ArtObr * Unused import removed Signed-off-by: ArtObr * Start of integration Signed-off-by: ArtObr * Changes for test_different_request integration with sdk Signed-off-by: ArtObr * helper changes commited Signed-off-by: ArtObr * INDY-1172 done with chages at pool_transactions Signed-off-by: ArtObr * little fix Signed-off-by: ArtObr * Code structure changes Signed-off-by: ArtObr * Additinal code structure changes Signed-off-by: ArtObr * Started sdk integration of tests Signed-off-by: ArtObr * Review fixes Signed-off-by: ArtObr * LibIndy versions update Signed-off-by: ArtObr * temp Signed-off-by: ArtObr * ha persist test done Signed-off-by: ArtObr * more tests done Signed-off-by: ArtObr * review fixes Signed-off-by: ArtObr * More tests done, some problems Signed-off-by: ArtObr * more tests done Signed-off-by: ArtObr * temp Signed-off-by: ArtObr * more tests Signed-off-by: ArtObr * all tests done, except one. need more of exception handling Signed-off-by: ArtObr * exception handling made. One test strange behaviour left Signed-off-by: ArtObr * Exception handling additional fixes Signed-off-by: ArtObr * Exception handling fixes. wrapper for builder Signed-off-by: ArtObr * little tests fix Signed-off-by: ArtObr --- plenum/common/constants.py | 5 + plenum/common/exceptions.py | 16 + plenum/common/messages/fields.py | 2 +- plenum/test/helper.py | 18 +- plenum/test/input_validation/helper.py | 4 +- ...est_different_ledger_request_interleave.py | 2 +- plenum/test/pool_transactions/conftest.py | 3 +- plenum/test/pool_transactions/helper.py | 225 +++++++++----- .../pool_transactions/test_adding_stewards.py | 68 +++-- ...t_change_ha_persists_post_nodes_restart.py | 72 +++-- .../test_client_change_ha.py | 37 --- .../test_client_with_pool_txns.py | 78 +---- .../pool_transactions/test_get_txn_request.py | 237 +++++++-------- .../test_nodes_data_changed.py | 187 ++++++------ .../test_nodes_ha_change_back.py | 62 ++-- .../test_nodes_with_pool_txns.py | 274 ++++++++++-------- .../test_start_many_nodes.py | 9 +- .../pool_transactions/test_suspend_node.py | 5 - .../test_txn_pool_manager.py | 36 +-- .../test_z_node_key_changed.py | 54 ++-- plenum/test/sdk/test_sdk_bindings.py | 9 +- 21 files changed, 723 insertions(+), 680 deletions(-) delete mode 100644 plenum/test/pool_transactions/test_client_change_ha.py diff --git a/plenum/common/constants.py b/plenum/common/constants.py index 26625a5b3f..0becd9d1a8 100644 --- a/plenum/common/constants.py +++ b/plenum/common/constants.py @@ -117,6 +117,7 @@ # ROLES STEWARD = Roles.STEWARD.value TRUSTEE = Roles.TRUSTEE.value +STEWARD_STRING = 'STEWARD' # TXNs NODE = PlenumTransactions.NODE.value @@ -169,6 +170,7 @@ class LedgerState(IntEnum): POOL_LEDGER_ID = 0 DOMAIN_LEDGER_ID = 1 CONFIG_LEDGER_ID = 2 +INVALID_LEDGER_ID = 5908 VALID_LEDGER_IDS = (POOL_LEDGER_ID, DOMAIN_LEDGER_ID, CONFIG_LEDGER_ID) @@ -196,3 +198,6 @@ class ReplicaHooks(UniqueSet): RECV_PPR = 5 RECV_PR = 6 RECV_CM = 7 + + +INVALID_SEQ_NO = -23 diff --git a/plenum/common/exceptions.py b/plenum/common/exceptions.py index 605448285e..832afeedf3 100644 --- a/plenum/common/exceptions.py +++ b/plenum/common/exceptions.py @@ -280,3 +280,19 @@ def __init__(self, expLen, actLen, *args, **kwargs): ex_txt = 'Message len {} exceeded allowed limit of {}'.format( actLen, expLen) super().__init__(ex_txt, *args, **kwargs) + + +class RequestNackedException(Exception): + pass + + +class RequestRejectedException(Exception): + pass + + +class CommonSdkIOException(Exception): + pass + + +class PoolLedgerTimeoutException(Exception): + pass diff --git a/plenum/common/messages/fields.py b/plenum/common/messages/fields.py index ab014e1d03..451a657c0c 100644 --- a/plenum/common/messages/fields.py +++ b/plenum/common/messages/fields.py @@ -240,7 +240,7 @@ class NetworkPortField(FieldBase): _base_types = (int,) def _specific_validation(self, val): - if val < 0 or val > 65535: + if val <= 0 or val > 65535: return 'network port out of the range 0-65535' diff --git a/plenum/test/helper.py b/plenum/test/helper.py index be2409fa59..bf7ebf6aea 100644 --- a/plenum/test/helper.py +++ b/plenum/test/helper.py @@ -23,6 +23,8 @@ from plenum.client.wallet import Wallet from plenum.common.constants import DOMAIN_LEDGER_ID, OP_FIELD_NAME, REPLY, REQACK, REQNACK, REJECT, \ CURRENT_PROTOCOL_VERSION +from plenum.common.exceptions import RequestNackedException, RequestRejectedException, CommonSdkIOException, \ + PoolLedgerTimeoutException from plenum.common.messages.node_messages import Reply, PrePrepare, Prepare, Commit from plenum.common.types import f from plenum.common.util import getNoInstances, get_utc_epoch @@ -1057,14 +1059,18 @@ def get_res(task, done_list): def sdk_check_reply(req_res): req, res = req_res if isinstance(res, ErrorCode): - raise AssertionError("Got an error with code {} for request {}" - .format(res, req)) + if res == 307: + raise PoolLedgerTimeoutException('Got PoolLedgerTimeout for request {}' + .format(req)) + else: + raise CommonSdkIOException('Got an error with code {} for request {}' + .format(res, req)) if res['op'] == REQNACK: - raise AssertionError("ReqNack of id {}. Reason: {}" - .format(req['reqId'], res['reason'])) + raise RequestNackedException('ReqNack of id {}. Reason: {}' + .format(req['reqId'], res['reason'])) if res['op'] == REJECT: - raise AssertionError("Reject of id {}. Reason: {}" - .format(req['reqId'], res['reason'])) + raise RequestRejectedException('Reject of id {}. Reason: {}' + .format(req['reqId'], res['reason'])) def sdk_get_and_check_replies(looper, sdk_req_resp: Sequence, timeout=None): diff --git a/plenum/test/input_validation/helper.py b/plenum/test/input_validation/helper.py index 76a45f5fef..c8f253adea 100644 --- a/plenum/test/input_validation/helper.py +++ b/plenum/test/input_validation/helper.py @@ -183,11 +183,11 @@ class NetworkPortField(TestFieldBase): @property def negative_test_cases(self): - return -1, 65535 + 1 + return 0, -1, 65535 + 1 @property def positive_test_cases(self): - return 0, 9700, 65535 + return 0 + 1, 9700, 65535 class NetworkIpAddressField(TestFieldBase): 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 4a0f508961..4102e26208 100644 --- a/plenum/test/node_request/test_different_ledger_request_interleave.py +++ b/plenum/test/node_request/test_different_ledger_request_interleave.py @@ -70,7 +70,7 @@ def test_different_ledger_request_interleave(tconf, looper, txnPoolNodeSet, sigseed, verkey, bls_key, nodeIp, nodePort, clientIp, clientPort = \ prepare_new_node_data(tconf, tdir, next_node_name) node_req = looper.loop.run_until_complete( - prepare_node_request(next_node_name, steward_did, clientIp, + prepare_node_request(steward_did, next_node_name, clientIp, clientPort, nodeIp, nodePort, bls_key, sigseed)) diff --git a/plenum/test/pool_transactions/conftest.py b/plenum/test/pool_transactions/conftest.py index f39bd79903..521af7e208 100644 --- a/plenum/test/pool_transactions/conftest.py +++ b/plenum/test/pool_transactions/conftest.py @@ -92,8 +92,7 @@ def sdk_node_theta_added(looper, new_node_name, tdir, tconf, - allPluginsPath, - nodeClass=testNodeClass) + allPluginsPath) txnPoolNodeSet.append(new_node) looper.run(checkNodesConnected(txnPoolNodeSet)) sdk_pool_refresh(looper, sdk_pool_handle) diff --git a/plenum/test/pool_transactions/helper.py b/plenum/test/pool_transactions/helper.py index ba9aed7d7b..5a6bd8a159 100644 --- a/plenum/test/pool_transactions/helper.py +++ b/plenum/test/pool_transactions/helper.py @@ -1,7 +1,7 @@ import json from indy.did import create_and_store_my_did -from indy.ledger import build_node_request, build_nym_request +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 @@ -13,14 +13,13 @@ 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 + VALIDATOR, BLS_KEY, CLIENT_STACK_SUFFIX, 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_gen_request, sdk_sign_and_submit_req_obj, sdk_get_reply, \ - sdk_eval_timeout, sdk_sign_request_objects, sdk_send_signed_requests, \ + sdk_sign_request_objects, sdk_send_signed_requests, \ sdk_json_to_request_object, sdk_get_and_check_replies from plenum.test.test_client import TestClient, genTestClient from plenum.test.test_node import TestNode, \ @@ -276,32 +275,31 @@ def sdk_add_new_steward_and_node(looper, autoStart=True, nodeClass=TestNode, transformNodeOpFunc=None, - do_post_node_creation: Callable = None): - new_steward_wallet, steward_did = sdk_add_new_nym(looper, - sdk_pool_handle, - sdk_wallet_steward, - alias=new_steward_name, - role='STEWARD') - + do_post_node_creation: Callable = None, + services=[VALIDATOR]): + new_steward_wallet_handle = sdk_add_new_nym(looper, + sdk_pool_handle, + sdk_wallet_steward, + alias=new_steward_name, + role=STEWARD_STRING) newNode = sdk_add_new_node( looper, sdk_pool_handle, - new_steward_wallet, + new_steward_wallet_handle, new_node_name, - steward_did, tdir, tconf, allPluginsPath, autoStart=autoStart, nodeClass=nodeClass, transformOpFunc=transformNodeOpFunc, - do_post_node_creation=do_post_node_creation) - return new_steward_wallet, newNode + do_post_node_creation=do_post_node_creation, + services=services) + return new_steward_wallet_handle, newNode def sdk_add_new_nym(looper, sdk_pool_handle, creators_wallet, - alias=None, role=None, node_count=None, - seed=None): + alias=None, role=None, seed=None): seed = seed or randomString(32) wh, _ = creators_wallet @@ -322,31 +320,36 @@ def sdk_add_new_nym(looper, sdk_pool_handle, creators_wallet, def sdk_add_new_node(looper, sdk_pool_handle, - new_steward_wallet, + steward_wallet_handle, new_node_name, - steward_did, tdir, tconf, allPluginsPath=None, autoStart=True, nodeClass=TestNode, transformOpFunc=None, do_post_node_creation: Callable = None, - node_count=None): + services=[VALIDATOR]): nodeClass = nodeClass or TestNode sigseed, verkey, bls_key, nodeIp, nodePort, clientIp, clientPort = \ prepare_new_node_data(tconf, tdir, new_node_name) # filling node request + _, steward_did = steward_wallet_handle node_request = looper.loop.run_until_complete( - prepare_node_request(new_node_name, steward_did, - clientIp, clientPort, - nodeIp, nodePort, - bls_key, sigseed)) + prepare_node_request(steward_did, + new_node_name=new_node_name, + clientIp=clientIp, + clientPort=clientPort, + nodeIp=nodeIp, + nodePort=nodePort, + bls_key=bls_key, + sigseed=sigseed, + services=services)) # sending request using 'sdk_' functions - wallet_handle = (new_steward_wallet, steward_did) - request_couple = sdk_sign_and_send_prepared_request(looper, wallet_handle, + request_couple = sdk_sign_and_send_prepared_request(looper, steward_wallet_handle, sdk_pool_handle, node_request) # waitng for replies sdk_get_and_check_replies(looper, [request_couple]) + return create_and_start_new_node(looper, new_node_name, tdir, sigseed, (nodeIp, nodePort), (clientIp, clientPort), tconf, autoStart, allPluginsPath, @@ -366,19 +369,33 @@ async def prepare_nym_request(wallet, named_seed, alias, role): return nym_request, named_did -async def prepare_node_request(new_node_name, steward_did, clientIp, - clientPort, nodeIp, nodePort, bls_key, sigseed): - data = { - 'alias': new_node_name, - 'client_ip': clientIp, - 'client_port': clientPort, - 'node_ip': nodeIp, - 'node_port': nodePort, - 'services': ["VALIDATOR"], - 'blskey': bls_key - } - nodeSigner = SimpleSigner(seed=sigseed) - destination = nodeSigner.identifier +async def prepare_node_request(steward_did, new_node_name=None, clientIp=None, + clientPort=None, nodeIp=None, nodePort=None, bls_key=None, + sigseed=None, destination=None, services=[VALIDATOR]): + use_sigseed = sigseed is not None + use_dest = destination is not None + if use_sigseed == use_dest: + raise AttributeError('You should provide only one of: sigseed or destination') + if use_sigseed: + nodeSigner = SimpleSigner(seed=sigseed) + destination = nodeSigner.identifier + + data = {} + if new_node_name is not None: + data['alias'] = new_node_name + if clientIp is not None: + data['client_ip'] = clientIp + if clientPort is not None: + data['client_port'] = clientPort + if nodeIp is not None: + data['node_ip'] = nodeIp + if nodePort is not None: + data['node_port'] = nodePort + if bls_key is not None: + data['blskey'] = bls_key + if services is not None: + data['services'] = services + node_request = await build_node_request(steward_did, destination, json.dumps(data)) return node_request @@ -404,27 +421,36 @@ def sendUpdateNode(stewardClient, stewardWallet, node, node_data): return req -def updateNodeData(looper, stewardClient, stewardWallet, node, node_data): - req = sendUpdateNode(stewardClient, stewardWallet, node, node_data) - waitForSufficientRepliesForRequests(looper, stewardClient, - requests=[req]) +def sdk_send_update_node(looper, sdk_submitter_wallet, sdk_pool_handle, + destination, alias, + node_ip, node_port, + client_ip, client_port, + services=[VALIDATOR]): + _, submitter_did = sdk_submitter_wallet + # filling node request + node_request = looper.loop.run_until_complete( + prepare_node_request(submitter_did, + new_node_name=alias, + clientIp=client_ip, + clientPort=client_port, + nodeIp=node_ip, + nodePort=node_port, + destination=destination, + services=services)) + # sending request using 'sdk_' functions + request_couple = sdk_sign_and_send_prepared_request(looper, sdk_submitter_wallet, + sdk_pool_handle, node_request) -def sdk_send_update_node(looper, sdk_pool, sdk_wallet_steward, node, node_data): - node_dest = hexToFriendly(node.nodestack.verhex) - op = { - TXN_TYPE: NODE, - TARGET_NYM: node_dest, - DATA: node_data, - } - req_obj = sdk_gen_request(op, identifier=sdk_wallet_steward[1]) - return sdk_sign_and_submit_req_obj(looper, sdk_pool, sdk_wallet_steward, req_obj) + # waitng for replies + reply = sdk_get_and_check_replies(looper, [request_couple])[0][1] + return reply -def sdk_update_node_data(looper, sdk_pool, sdk_wallet_steward, node, node_data): - node_req = sdk_send_update_node(sdk_wallet_steward, node, node_data) - _, j_resp = sdk_get_reply(looper, node_req) - assert j_resp['result'] +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): @@ -432,23 +458,37 @@ def sdk_pool_refresh(looper, sdk_pool_handle): refresh_pool_ledger(sdk_pool_handle)) -def updateNodeDataAndReconnect(looper, steward, stewardWallet, node, - node_data, tdir, tconf, txnPoolNodeSet): - updateNodeData(looper, steward, stewardWallet, node, node_data) +def sdk_build_get_txn_request(looper, steward_did, data): + request = looper.loop.run_until_complete( + build_get_txn_request(steward_did, data)) + return request + + +def update_node_data_and_reconnect(looper, txnPoolNodeSet, + steward_wallet, + sdk_pool_handle, + node, + new_node_ip, new_node_port, + new_client_ip, new_client_port, + tdir, tconf): + node_ha = node.nodestack.ha + cli_ha = node.clientstack.ha + node_dest = hexToFriendly(node.nodestack.verhex) + sdk_send_update_node(looper, steward_wallet, sdk_pool_handle, + node_dest, node.name, + new_node_ip, new_node_port, + new_client_ip, new_client_port) # restart the Node with new HA node.stop() - node_alias = node_data.get(ALIAS, None) or node.name - node_ip = node_data.get(NODE_IP, None) or node.nodestack.ha.host - node_port = node_data.get(NODE_PORT, None) or node.nodestack.ha.port - client_ip = node_data.get(CLIENT_IP, None) or node.clientstack.ha.host - client_port = node_data.get(CLIENT_PORT, None) or node.clientstack.ha.port looper.removeProdable(name=node.name) - config_helper = PNodeConfigHelper(node_alias, tconf, chroot=tdir) - restartedNode = TestNode(node_alias, + config_helper = PNodeConfigHelper(node.name, tconf, chroot=tdir) + restartedNode = TestNode(node.name, config_helper=config_helper, config=tconf, - ha=HA(node_ip, node_port), - cliha=HA(client_ip, client_port)) + ha=HA(new_node_ip or node_ha.host, + new_node_port or node_ha.port), + cliha=HA(new_client_ip or cli_ha.host, + new_client_port or cli_ha.port)) looper.add(restartedNode) # replace node in txnPoolNodeSet @@ -460,6 +500,7 @@ def updateNodeDataAndReconnect(looper, steward, stewardWallet, node, txnPoolNodeSet[idx] = restartedNode looper.run(checkNodesConnected(txnPoolNodeSet)) + sdk_pool_refresh(looper, sdk_pool_handle) return restartedNode @@ -488,6 +529,30 @@ def changeNodeKeys(looper, stewardClient, stewardWallet, node, verkey): 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) + node_request = looper.loop.run_until_complete( + prepare_node_request(steward_did, + new_node_name=node.name, + destination=node_dest)) + + request_json = json.loads(node_request) + request_json['operation'][VERKEY] = verkey + node_request1 = json.dumps(request_json) + + request_couple = sdk_sign_and_send_prepared_request(looper, sdk_wallet_steward, + sdk_pool_handle, node_request1) + sdk_get_and_check_replies(looper, [request_couple]) + + node.nodestack.clearLocalRoleKeep() + node.nodestack.clearRemoteRoleKeeps() + node.nodestack.clearAllDir() + node.clientstack.clearLocalRoleKeep() + node.clientstack.clearRemoteRoleKeeps() + node.clientstack.clearAllDir() + + def suspendNode(looper, stewardClient, stewardWallet, nodeNym, nodeName): op = { TXN_TYPE: NODE, @@ -648,3 +713,27 @@ def add_2_nodes(looper, existing_nodes, steward, steward_wallet, new_nodes.append(new_node) return new_nodes + + +def sdk_add_2_nodes(looper, txnPoolNodeSet, + sdk_pool_handle, sdk_wallet_steward, + tdir, tconf, allPluginsPath): + names = ("Zeta", "Eta") + new_nodes = [] + for node_name in names: + new_steward_name = "testClientSteward" + randomString(3) + new_steward_wallet, new_node = \ + sdk_add_new_steward_and_node(looper, + sdk_pool_handle, + sdk_wallet_steward, + new_steward_name, + node_name, + tdir, + tconf, + allPluginsPath) + txnPoolNodeSet.append(new_node) + looper.run(checkNodesConnected(txnPoolNodeSet)) + waitNodeDataEquality(looper, new_node, *txnPoolNodeSet[:-1]) + sdk_pool_refresh(looper, sdk_pool_handle) + new_nodes.append(new_node) + return new_nodes diff --git a/plenum/test/pool_transactions/test_adding_stewards.py b/plenum/test/pool_transactions/test_adding_stewards.py index 10f56bb717..b96d2ff7e5 100644 --- a/plenum/test/pool_transactions/test_adding_stewards.py +++ b/plenum/test/pool_transactions/test_adding_stewards.py @@ -1,8 +1,11 @@ import pytest -from plenum.common.constants import STEWARD -from plenum.test.helper import waitRejectWithReason -from plenum.test.pool_transactions.helper import addNewClient, sendAddNewClient +from plenum.common.constants import STEWARD_STRING +from plenum.common.exceptions import RequestRejectedException +from plenum.common.util import randomString +from plenum.test.helper import sdk_get_replies, sdk_eval_timeout, sdk_check_reply +from plenum.test.pool_transactions.helper import sdk_add_new_nym, \ + prepare_nym_request, sdk_sign_and_send_prepared_request @pytest.fixture(scope="module") @@ -17,33 +20,40 @@ def reset(): return tconf -def testOnlyAStewardCanAddAnotherSteward(looper, txnPoolNodeSet, - tdirWithPoolTxns, poolTxnClientData, - steward1, stewardWallet, - client1, wallet1, client1Connected): - addNewClient(STEWARD, looper, steward1, stewardWallet, "testSteward1") +def testOnlyAStewardCanAddAnotherSteward(looper, + txnPoolNodeSet, + sdk_pool_handle, + sdk_wallet_steward, + sdk_wallet_client): + sdk_add_new_nym(looper, sdk_pool_handle, sdk_wallet_steward, + alias='testSteward' + randomString(3), role=STEWARD_STRING) - sendAddNewClient(STEWARD, "testSteward2", client1, wallet1) - for node in txnPoolNodeSet: - waitRejectWithReason( - looper, - client1, - 'Only Steward is allowed to do these transactions', - node.clientstack.name) + seed = randomString(32) + wh, _ = sdk_wallet_client + nym_request, steward_did = looper.loop.run_until_complete( + prepare_nym_request(sdk_wallet_client, seed, + 'testSteward2', 'STEWARD')) -def testStewardsCanBeAddedOnlyTillAThresholdIsReached(looper, tconf, + request_couple = sdk_sign_and_send_prepared_request(looper, sdk_wallet_client, + sdk_pool_handle, nym_request) + total_timeout = sdk_eval_timeout(1, len(txnPoolNodeSet)) + request_couple = sdk_get_replies(looper, [request_couple], total_timeout)[0] + with pytest.raises(RequestRejectedException) as e: + sdk_check_reply(request_couple) + assert 'Only Steward is allowed to do these transactions' in e._excinfo[1].args[0] + + +def testStewardsCanBeAddedOnlyTillAThresholdIsReached(looper, txnPoolNodeSet, - tdirWithPoolTxns, - poolTxnStewardData, - steward1, stewardWallet): - addNewClient(STEWARD, looper, steward1, stewardWallet, "testSteward3") - - sendAddNewClient(STEWARD, "testSteward4", steward1, stewardWallet) - for node in txnPoolNodeSet: - waitRejectWithReason(looper, steward1, - 'New stewards cannot be added by other ' - 'stewards as there are already {} ' - 'stewards in the system'.format( - tconf.stewardThreshold), - node.clientstack.name) + sdk_pool_handle, + sdk_wallet_steward, + tconf): + sdk_add_new_nym(looper, sdk_pool_handle, sdk_wallet_steward, + alias='testSteward' + randomString(3), role=STEWARD_STRING) + with pytest.raises(RequestRejectedException) as e: + sdk_add_new_nym(looper, sdk_pool_handle, sdk_wallet_steward, + alias='testSteward' + randomString(3), role=STEWARD_STRING) + error_message = 'New stewards cannot be added by other stewards as there ' \ + 'are already {} stewards in the system'.format(tconf.stewardThreshold) + assert error_message in e._excinfo[1].args[0] diff --git a/plenum/test/pool_transactions/test_change_ha_persists_post_nodes_restart.py b/plenum/test/pool_transactions/test_change_ha_persists_post_nodes_restart.py index eae52c4755..35d461b86a 100644 --- a/plenum/test/pool_transactions/test_change_ha_persists_post_nodes_restart.py +++ b/plenum/test/pool_transactions/test_change_ha_persists_post_nodes_restart.py @@ -1,40 +1,44 @@ -from plenum.common.constants import ALIAS, NODE_IP, NODE_PORT, CLIENT_IP, CLIENT_PORT +from plenum.common.util import hexToFriendly, randomString from stp_core.common.log import getlogger -from plenum.test.node_catchup.helper import waitNodeDataEquality, \ - ensureClientConnectedToNodesAndPoolLedgerSame -from plenum.test.pool_transactions.helper import updateNodeData, \ - buildPoolClientAndWallet +from plenum.test.node_catchup.helper import waitNodeDataEquality +from plenum.test.node_request.helper import sdk_ensure_pool_functional +from plenum.test.pool_transactions.helper import sdk_send_update_node, sdk_pool_refresh, \ + sdk_add_new_steward_and_node from plenum.test.test_node import TestNode, checkNodesConnected from stp_core.network.port_dispenser import genHa from plenum.common.config_helper import PNodeConfigHelper +from plenum.test.pool_transactions.conftest import looper logger = getlogger() -whitelist = ['found legacy entry', "doesn't match", "reconciling nodeReg", - "missing", "conflicts", "matches", "nodeReg", - "conflicting address", "got error while verifying message"] +def testChangeHaPersistsPostNodesRestart(looper, txnPoolNodeSet, + tdir, tconf, + sdk_pool_handle, + sdk_wallet_client, + sdk_wallet_steward): + new_steward_wallet, new_node = \ + sdk_add_new_steward_and_node(looper, + sdk_pool_handle, + sdk_wallet_steward, + 'AnotherSteward' + randomString(4), + 'AnotherNode' + randomString(4), + tdir, + tconf) + txnPoolNodeSet.append(new_node) + looper.run(checkNodesConnected(txnPoolNodeSet)) + sdk_pool_refresh(looper, sdk_pool_handle) - -def testChangeHaPersistsPostNodesRestart(looper, txnPoolNodeSet, tdir, tdirWithPoolTxns, - tdirWithClientPoolTxns, tconf, steward1, - stewardWallet, nodeThetaAdded, - poolTxnClientData): - newSteward, newStewardWallet, newNode = nodeThetaAdded - nodeNewHa, clientNewHa = genHa(2) - logger.debug("{} changing HAs to {} {}".format(newNode, nodeNewHa, - clientNewHa)) + node_new_ha, client_new_ha = genHa(2) + logger.debug("{} changing HAs to {} {}".format(new_node, node_new_ha, + client_new_ha)) # Making the change HA txn an confirming its succeeded - op = { - ALIAS: newNode.name, - NODE_IP: nodeNewHa.host, - NODE_PORT: nodeNewHa.port, - CLIENT_IP: clientNewHa.host, - CLIENT_PORT: clientNewHa.port, - } - updateNodeData(looper, newSteward, newStewardWallet, newNode, - op) + node_dest = hexToFriendly(new_node.nodestack.verhex) + sdk_send_update_node(looper, new_steward_wallet, sdk_pool_handle, + node_dest, new_node.name, + node_new_ha.host, node_new_ha.port, + client_new_ha.host, client_new_ha.port) # Stopping existing nodes for node in txnPoolNodeSet: @@ -54,21 +58,15 @@ def testChangeHaPersistsPostNodesRestart(looper, txnPoolNodeSet, tdir, tdirWithP restartedNodes.append(restartedNode) # Starting the node whose HA was changed - config_helper = PNodeConfigHelper(newNode.name, tconf, chroot=tdir) - node = TestNode(newNode.name, + config_helper = PNodeConfigHelper(new_node.name, tconf, chroot=tdir) + node = TestNode(new_node.name, config_helper=config_helper, config=tconf, - ha=nodeNewHa, cliha=clientNewHa) + ha=node_new_ha, cliha=client_new_ha) looper.add(node) restartedNodes.append(node) looper.run(checkNodesConnected(restartedNodes)) waitNodeDataEquality(looper, node, *restartedNodes[:-1]) - - # Building a new client that reads from the genesis txn file - # but is able to connect to all nodes - client, wallet = buildPoolClientAndWallet(poolTxnClientData, - tdirWithClientPoolTxns) - looper.add(client) - ensureClientConnectedToNodesAndPoolLedgerSame(looper, client, - *restartedNodes) + sdk_pool_refresh(looper, sdk_pool_handle) + sdk_ensure_pool_functional(looper, restartedNodes, sdk_wallet_client, sdk_pool_handle) diff --git a/plenum/test/pool_transactions/test_client_change_ha.py b/plenum/test/pool_transactions/test_client_change_ha.py deleted file mode 100644 index 96963723e9..0000000000 --- a/plenum/test/pool_transactions/test_client_change_ha.py +++ /dev/null @@ -1,37 +0,0 @@ -import os -import shutil - -from plenum.test.node_catchup.helper import \ - ensureClientConnectedToNodesAndPoolLedgerSame -from plenum.test.pool_transactions.helper import buildPoolClientAndWallet -from plenum.test.test_client import genTestClient -from stp_core.network.port_dispenser import genHa - -whitelist = ['client already added'] - - -def testClientReconnectUsingDifferentHa(looper, txnPoolNodeSet, tdirWithPoolTxns, - tdirWithClientPoolTxns, poolTxnClientData): - """ - Client should not be able to connect to nodes even after it has changed - its HA. Since running on a local environment, only checking change of port. - Dont know how to change IP. - :return: - """ - # TODO: Check for change of IP too - client, wallet = buildPoolClientAndWallet(poolTxnClientData, - tdirWithClientPoolTxns) - looper.add(client) - ensureClientConnectedToNodesAndPoolLedgerSame(looper, client, - *txnPoolNodeSet) - keys_dir = os.path.join(client.keys_dir, client.name) - client.stop() - looper.removeProdable(client) - - ha = genHa() - client, _ = genTestClient(txnPoolNodeSet, identifier=wallet.defaultId, - ha=ha, tmpdir=tdirWithClientPoolTxns, - usePoolLedger=True, name=client.name) - looper.add(client) - ensureClientConnectedToNodesAndPoolLedgerSame(looper, client, - *txnPoolNodeSet) 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 816ea97fbe..241e8fc526 100644 --- a/plenum/test/pool_transactions/test_client_with_pool_txns.py +++ b/plenum/test/pool_transactions/test_client_with_pool_txns.py @@ -1,12 +1,10 @@ +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.common.util import randomString, bootstrapClientKeys from plenum.test import waits -from plenum.test.helper import sendReqsToNodesAndVerifySuffReplies, \ - sendRandomRequest, waitForSufficientRepliesForRequests -from plenum.test.node_catchup.helper import \ - ensureClientConnectedToNodesAndPoolLedgerSame -from plenum.test.test_client import genTestClient +from plenum.test.helper import sdk_send_random_and_check from plenum.test.test_node import checkNodesConnected, TestNode, \ ensureElectionsDone from plenum.common.config_helper import PNodeConfigHelper @@ -14,62 +12,16 @@ logger = getlogger() -def testClientUsingPoolTxns(looper, txnPoolNodeSet, poolTxnClient): - """ - Client should not be using node registry but pool transaction file - :return: - """ - client, wallet = poolTxnClient - looper.add(client) - ensureClientConnectedToNodesAndPoolLedgerSame(looper, client, - *txnPoolNodeSet) - - -def testClientConnectAfterRestart(looper, txnPoolNodeSet, tdirWithClientPoolTxns): - cname = "testClient" + randomString(5) - newClient, _ = genTestClient(tmpdir=tdirWithClientPoolTxns, name=cname, - usePoolLedger=True) - logger.debug("{} starting at {}".format(newClient, newClient.nodestack.ha)) - looper.add(newClient) - logger.debug("Public keys of client {} {}".format( - newClient.nodestack.prihex, - newClient.nodestack.pubhex)) - logger.debug("Signer keys of client {} {}".format( - newClient.nodestack.keyhex, - newClient.nodestack.verhex)) - looper.run(newClient.ensureConnectedToNodes()) - newClient.stop() - looper.removeProdable(newClient) - newClient, _ = genTestClient(tmpdir=tdirWithClientPoolTxns, name=cname, - usePoolLedger=True) - logger.debug("{} again starting at {}".format(newClient, - newClient.nodestack.ha)) - looper.add(newClient) - logger.debug("Public keys of client {} {}".format( - newClient.nodestack.prihex, - newClient.nodestack.pubhex)) - logger.debug("Signer keys of client {} {}".format( - newClient.nodestack.keyhex, - newClient.nodestack.verhex)) - looper.run(newClient.ensureConnectedToNodes()) - - -def testClientConnectToRestartedNodes(looper, txnPoolNodeSet, tdirWithPoolTxns, - tdir, tdirWithClientPoolTxns, - poolTxnClientNames, poolTxnData, tconf, - poolTxnNodeNames, allPluginsPath): - name = poolTxnClientNames[-1] - newClient, w = genTestClient(tmpdir=tdirWithClientPoolTxns, nodes=txnPoolNodeSet, - name=name, usePoolLedger=True) - looper.add(newClient) - ensureClientConnectedToNodesAndPoolLedgerSame(looper, newClient, - *txnPoolNodeSet) - sendReqsToNodesAndVerifySuffReplies(looper, w, newClient, 1, 1) +def testClientConnectToRestartedNodes(looper, txnPoolNodeSet, + tdir, tconf, + poolTxnNodeNames, allPluginsPath, + sdk_wallet_new_client, + sdk_pool_handle): + sdk_send_random_and_check(looper, txnPoolNodeSet, sdk_pool_handle, sdk_wallet_new_client, 1) for node in txnPoolNodeSet: node.stop() looper.removeProdable(node) - # looper.run(newClient.ensureDisconnectedToNodes(timeout=60)) txnPoolNodeSet = [] for nm in poolTxnNodeNames: config_helper = PNodeConfigHelper(nm, tconf, chroot=tdir) @@ -88,11 +40,5 @@ def chk(): timeout = waits.expectedPoolGetReadyTimeout(len(txnPoolNodeSet)) looper.run(eventually(chk, retryWait=1, timeout=timeout)) - bootstrapClientKeys(w.defaultId, w.getVerkey(), txnPoolNodeSet) - - req = sendRandomRequest(w, newClient) - waitForSufficientRepliesForRequests(looper, newClient, requests=[req]) - ensureClientConnectedToNodesAndPoolLedgerSame(looper, newClient, - *txnPoolNodeSet) - - sendReqsToNodesAndVerifySuffReplies(looper, w, newClient, 3, 1) + sdk_pool_refresh(looper, sdk_pool_handle) + sdk_ensure_pool_functional(looper, txnPoolNodeSet, sdk_wallet_new_client, sdk_pool_handle) diff --git a/plenum/test/pool_transactions/test_get_txn_request.py b/plenum/test/pool_transactions/test_get_txn_request.py index 5a5265058e..c7ea50ef7f 100644 --- a/plenum/test/pool_transactions/test_get_txn_request.py +++ b/plenum/test/pool_transactions/test_get_txn_request.py @@ -1,129 +1,132 @@ -from plenum.common.constants import POOL_LEDGER_ID, DOMAIN_LEDGER_ID, CLIENT_BLACKLISTER_SUFFIX, \ - NODE_BLACKLISTER_SUFFIX, NODE_PRIMARY_STORAGE_SUFFIX, HS_FILE, HS_LEVELDB, TXN_TYPE, LedgerState, LEDGER_STATUS, \ - CLIENT_STACK_SUFFIX, PRIMARY_SELECTION_PREFIX, VIEW_CHANGE_PREFIX, OP_FIELD_NAME, CATCH_UP_PREFIX, NYM, \ - POOL_TXN_TYPES, GET_TXN, DATA, MONITORING_PREFIX, TXN_TIME, VERKEY, TARGET_NYM, ROLE, STEWARD, TRUSTEE, ALIAS, \ - NODE_IP, CURRENT_PROTOCOL_VERSION +import json + +import pytest + from random import randint -from plenum.common.types import f -from plenum.test.pool_transactions.helper import sendAddNewClient +from plenum.common.constants import INVALID_LEDGER_ID, \ + INVALID_SEQ_NO, DATA +from plenum.common.exceptions import RequestNackedException +from plenum.test.pool_transactions.helper import \ + sdk_sign_and_send_prepared_request, prepare_nym_request, \ + sdk_build_get_txn_request from stp_core.loop.eventually import eventually -from plenum.test import waits -from plenum.test.helper import check_sufficient_replies_received, \ - waitReqNackWithReason -from plenum.common.util import getMaxFailures -from plenum.common.request import Request +from plenum.test.helper import sdk_get_and_check_replies +from plenum.common.util import getMaxFailures, randomString c_delay = 10 fValue = getMaxFailures(4) def test_get_txn_for_invalid_ledger_id(looper, txnPoolNodeSet, - steward1, stewardWallet): - op = { - TXN_TYPE: GET_TXN, - f.LEDGER_ID.nm: 5908, - DATA: 1 - } - req = Request(identifier=stewardWallet.defaultId, - operation=op, reqId=Request.gen_req_id(), - protocolVersion=CURRENT_PROTOCOL_VERSION) - steward1.submitReqs(req) - for node in txnPoolNodeSet: - waitReqNackWithReason(looper, steward1, 'expected one of', - node.clientstack.name) + sdk_wallet_steward, + sdk_pool_handle): + _, steward_did = sdk_wallet_steward + request = sdk_build_get_txn_request(looper, steward_did, 1) + + # setting incorrect Ledger_ID + request_json = json.loads(request) + request_json['operation']['ledgerId'] = INVALID_LEDGER_ID + request = json.dumps(request_json) + + request_couple = \ + sdk_sign_and_send_prepared_request(looper, + sdk_wallet_steward, + sdk_pool_handle, + request) + with pytest.raises(RequestNackedException) as e: + sdk_get_and_check_replies(looper, [request_couple]) + assert 'expected one of' in e._excinfo[1].args[0] def test_get_txn_for_invalid_seq_no(looper, txnPoolNodeSet, - steward1, stewardWallet): - op = { - TXN_TYPE: GET_TXN, - f.LEDGER_ID.nm: DOMAIN_LEDGER_ID, - DATA: -23 - } - req = Request(identifier=stewardWallet.defaultId, - operation=op, reqId=Request.gen_req_id(), - protocolVersion=CURRENT_PROTOCOL_VERSION) - steward1.submitReqs(req) - for node in txnPoolNodeSet: - waitReqNackWithReason(looper, steward1, 'cannot be smaller', - node.clientstack.name) - - -def test_get_txn_for_existing_seq_no(looper, steward1, stewardWallet): - op = { - TXN_TYPE: GET_TXN, - DATA: 1 - } - - def chk(): - nonlocal op - req = Request(identifier=stewardWallet.defaultId, - operation=op, reqId=Request.gen_req_id(), - protocolVersion=CURRENT_PROTOCOL_VERSION) - steward1.submitReqs(req) - - timeout = waits.expectedTransactionExecutionTime( - len(steward1.inBox)) + c_delay - get_txn_response = \ - looper.run(eventually(check_sufficient_replies_received, - steward1, req.identifier, req.reqId, - retryWait=1, timeout=timeout)) - - assert get_txn_response[DATA] - - # Check with and without ledger id - chk() - op[f.LEDGER_ID.nm] = DOMAIN_LEDGER_ID - chk() - - -def test_get_txn_for_non_existing_seq_no(looper, steward1, stewardWallet): - op = { - TXN_TYPE: GET_TXN, - f.LEDGER_ID.nm: DOMAIN_LEDGER_ID, - DATA: randint(100, 1000) - } - req = Request(identifier=stewardWallet.defaultId, - operation=op, reqId=Request.gen_req_id(), - protocolVersion=CURRENT_PROTOCOL_VERSION) - steward1.submitReqs(req) - - timeout = waits.expectedTransactionExecutionTime( - len(steward1.inBox)) + c_delay - get_txn_response = \ - looper.run(eventually(check_sufficient_replies_received, - steward1, req.identifier, req.reqId, - retryWait=1, timeout=timeout)) - - assert not get_txn_response[DATA] - - -def test_get_txn_response_as_expected(looper, steward1, stewardWallet): - req, wallet = sendAddNewClient(STEWARD, "name", steward1, stewardWallet) - - timeout = waits.expectedTransactionExecutionTime( - len(steward1.inBox)) + c_delay - nym_response = \ - looper.run(eventually(check_sufficient_replies_received, - steward1, req.identifier, req.reqId, - retryWait=1, timeout=timeout)) - op = { - TXN_TYPE: GET_TXN, - f.LEDGER_ID.nm: DOMAIN_LEDGER_ID, - DATA: nym_response['seqNo'] - } - req = Request(identifier=stewardWallet.defaultId, - operation=op, reqId=Request.gen_req_id(), - protocolVersion=CURRENT_PROTOCOL_VERSION) - steward1.submitReqs(req) - - get_txn_response = \ - looper.run(eventually(check_sufficient_replies_received, - steward1, req.identifier, req.reqId, - retryWait=1, timeout=timeout)) - - nym_response.pop('txnTime', None) - get_txn_response[DATA].pop('txnTime', None) - - assert nym_response == get_txn_response[DATA] + sdk_wallet_steward, + sdk_pool_handle): + _, steward_did = sdk_wallet_steward + + # setting incorrect data + request = sdk_build_get_txn_request(looper, steward_did, + INVALID_SEQ_NO) + + request_couple = \ + sdk_sign_and_send_prepared_request(looper, + sdk_wallet_steward, + sdk_pool_handle, + request) + with pytest.raises(RequestNackedException) as e: + sdk_get_and_check_replies(looper, [request_couple]) + assert 'cannot be smaller' in e._excinfo[1].args[0] + + +def test_get_txn_for_existing_seq_no(looper, txnPoolNodeSet, + sdk_wallet_steward, + sdk_pool_handle): + _, steward_did = sdk_wallet_steward + for i in range(2): + request = sdk_build_get_txn_request(looper, steward_did, 1) + + # Check with and without ledger id + request_json = json.loads(request) + if i: + request_json['operation']['ledgerId'] = 1 + request = json.dumps(request_json) + + sdk_sign_and_send_prepared_request(looper, + sdk_wallet_steward, + sdk_pool_handle, + request) + + +def test_get_txn_for_non_existing_seq_no(looper, txnPoolNodeSet, + sdk_wallet_steward, + sdk_pool_handle): + _, steward_did = sdk_wallet_steward + + # setting incorrect data + def generate_non_existing_seq_no(): + return randint(500, 1000) + + request = sdk_build_get_txn_request(looper, steward_did, + generate_non_existing_seq_no()) + + request_couple = \ + sdk_sign_and_send_prepared_request(looper, + sdk_wallet_steward, + sdk_pool_handle, + request) + reply = sdk_get_and_check_replies(looper, [request_couple])[0][1] + assert reply['result'][DATA] is None + + +def test_get_txn_response_as_expected(looper, txnPoolNodeSet, + sdk_pool_handle, + sdk_wallet_steward): + seed = randomString(32) + wh, _ = sdk_wallet_steward + + # 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(sdk_wallet_steward, seed, + None, None)) + + # sending request using 'sdk_' functions + request_couple = sdk_sign_and_send_prepared_request( + looper, sdk_wallet_steward, + sdk_pool_handle, nym_request) + + result1 = sdk_get_and_check_replies(looper, + [request_couple])[0][1]['result'] + seqNo = result1['seqNo'] + + _, steward_did = sdk_wallet_steward + request = sdk_build_get_txn_request(looper, steward_did, seqNo) + + request_couple = \ + sdk_sign_and_send_prepared_request(looper, + sdk_wallet_steward, + sdk_pool_handle, + request) + result2 = sdk_get_and_check_replies(looper, + [request_couple])[0][1]['result'] + assert result1 == result2['data'] diff --git a/plenum/test/pool_transactions/test_nodes_data_changed.py b/plenum/test/pool_transactions/test_nodes_data_changed.py index 73500e9b68..9687e96ab4 100644 --- a/plenum/test/pool_transactions/test_nodes_data_changed.py +++ b/plenum/test/pool_transactions/test_nodes_data_changed.py @@ -1,11 +1,13 @@ -from plenum.common.constants import CLIENT_STACK_SUFFIX, DATA, ALIAS, \ - NODE_IP, NODE_PORT, CLIENT_PORT, CLIENT_IP, SERVICES, VALIDATOR -from plenum.common.util import randomString -from plenum.test.helper import waitRejectWithReason -from plenum.test.node_catchup.helper import waitNodeDataEquality, \ - ensureClientConnectedToNodesAndPoolLedgerSame -from plenum.test.pool_transactions.helper import addNewStewardAndNode, \ - sendUpdateNode, updateNodeDataAndReconnect +import pytest + +from plenum.common.exceptions import RequestRejectedException +from plenum.test.node_request.helper import sdk_ensure_pool_functional + +from plenum.common.constants import CLIENT_STACK_SUFFIX +from plenum.common.util import randomString, hexToFriendly +from plenum.test.pool_transactions.helper import sdk_send_update_node, \ + sdk_add_new_steward_and_node, sdk_pool_refresh, \ + update_node_data_and_reconnect from plenum.test.test_node import checkNodesConnected from stp_core.common.log import getlogger @@ -13,12 +15,6 @@ logger = getlogger() -# logged errors to ignore -whitelist = ['found legacy entry', "doesn't match", 'reconciling nodeReg', - 'missing', 'conflicts', 'matches', 'nodeReg', - 'conflicting address', 'unable to send message', - 'got error while verifying message'] - # Whitelisting "got error while verifying message" since a node while not have # initialised a connection for a new node by the time the new node's message @@ -26,104 +22,91 @@ def testNodePortCannotBeChangedByAnotherSteward(looper, txnPoolNodeSet, - steward1, stewardWallet, - nodeThetaAdded): - _, _, newNode = nodeThetaAdded - nodeNewHa = genHa(1) - new_port = nodeNewHa.port - node_ha = txnPoolNodeSet[0].nodeReg[newNode.name] - cli_ha = txnPoolNodeSet[0].cliNodeReg[newNode.name + CLIENT_STACK_SUFFIX] - node_data = { - ALIAS: newNode.name, - NODE_PORT: new_port, - NODE_IP: node_ha.host, - CLIENT_PORT: cli_ha.port, - CLIENT_IP: cli_ha.host, - } - - logger.debug('{} changing port to {} {}'.format(newNode, new_port, - newNode.nodestack.ha.port)) - sendUpdateNode(steward1, stewardWallet, newNode, - node_data) - - for node in txnPoolNodeSet: - waitRejectWithReason(looper, steward1, 'is not a steward of node', - node.clientstack.name) + sdk_wallet_steward, + sdk_pool_handle, + sdk_node_theta_added): + new_steward_wallet, new_node = sdk_node_theta_added + node_new_ha, client_new_ha = genHa(2) + logger.debug("{} changing HAs to {} {}".format(new_node, node_new_ha, + client_new_ha)) + node_dest = hexToFriendly(new_node.nodestack.verhex) + with pytest.raises(RequestRejectedException) as e: + sdk_send_update_node(looper, sdk_wallet_steward, sdk_pool_handle, + node_dest, new_node.name, + node_new_ha.host, node_new_ha.port, + client_new_ha.host, client_new_ha.port) + assert 'is not a steward of node' in e._excinfo[1].args[0] + sdk_pool_refresh(looper, sdk_pool_handle) def test_node_alias_cannot_be_changed(looper, txnPoolNodeSet, - nodeThetaAdded): + sdk_pool_handle, + sdk_node_theta_added): """ The node alias cannot be changed. """ - newSteward, newStewardWallet, newNode = nodeThetaAdded - node_data = {ALIAS: 'foo'} - sendUpdateNode(newSteward, newStewardWallet, newNode, - node_data) - for node in txnPoolNodeSet: - waitRejectWithReason(looper, newSteward, - 'data has conflicts with request data', - node.clientstack.name) - - -def testNodePortChanged(looper, txnPoolNodeSet, tdir, tconf, - steward1, stewardWallet, nodeThetaAdded): + new_steward_wallet, new_node = sdk_node_theta_added + node_dest = hexToFriendly(new_node.nodestack.verhex) + with pytest.raises(RequestRejectedException) as e: + sdk_send_update_node(looper, new_steward_wallet, sdk_pool_handle, + node_dest, 'foo', + None, None, + None, None) + assert 'data has conflicts with request data' in e._excinfo[1].args[0] + sdk_pool_refresh(looper, sdk_pool_handle) + + +def testNodePortChanged(looper, txnPoolNodeSet, + sdk_wallet_steward, + sdk_pool_handle, + sdk_node_theta_added, + tdir, tconf): """ An running node's port is changed """ - newSteward, newStewardWallet, newNode = nodeThetaAdded - nodeNewHa = genHa(1) - new_port = nodeNewHa.port - - node_ha = txnPoolNodeSet[0].nodeReg[newNode.name] - cli_ha = txnPoolNodeSet[0].cliNodeReg[newNode.name + CLIENT_STACK_SUFFIX] - node_data = { - ALIAS: newNode.name, - NODE_PORT: new_port, - NODE_IP: node_ha.host, - CLIENT_PORT: cli_ha.port, - CLIENT_IP: cli_ha.host, - } - - node = updateNodeDataAndReconnect(looper, newSteward, - newStewardWallet, newNode, - node_data, - tdir, tconf, - txnPoolNodeSet) - - waitNodeDataEquality(looper, node, *txnPoolNodeSet[:-1]) - - ensureClientConnectedToNodesAndPoolLedgerSame(looper, steward1, - *txnPoolNodeSet) - ensureClientConnectedToNodesAndPoolLedgerSame(looper, newSteward, - *txnPoolNodeSet) - - -def testAddInactiveNodeThenActivate(looper, txnPoolNodeSet, tdir, client_tdir, - tconf, steward1, stewardWallet, allPluginsPath): - newStewardName = "testClientSteward" + randomString(3) - newNodeName = "Kappa" + new_steward_wallet, new_node = sdk_node_theta_added + + node_new_ha = genHa(1) + new_port = node_new_ha.port + node_ha = txnPoolNodeSet[0].nodeReg[new_node.name] + cli_ha = txnPoolNodeSet[0].cliNodeReg[new_node.name + CLIENT_STACK_SUFFIX] + + update_node_data_and_reconnect(looper, txnPoolNodeSet, + new_steward_wallet, + sdk_pool_handle, + new_node, + node_ha.host, new_port, + cli_ha.host, cli_ha.port, + tdir, tconf) + sdk_ensure_pool_functional(looper, txnPoolNodeSet, new_steward_wallet, sdk_pool_handle) + + +def testAddInactiveNodeThenActivate(looper, txnPoolNodeSet, + sdk_wallet_steward, + sdk_pool_handle, tdir, tconf, allPluginsPath): + new_steward_name = "testClientSteward" + randomString(3) + new_node_name = "Kappa" # adding a new node without SERVICES field # it means the node is in the inactive state - def del_services(op): del op[DATA][SERVICES] - - newSteward, newStewardWallet, newNode = \ - addNewStewardAndNode(looper, - steward1, stewardWallet, - newStewardName, newNodeName, - tdir, client_tdir, tconf, allPluginsPath, - transformNodeOpFunc=del_services) + new_steward_wallet, new_node = \ + sdk_add_new_steward_and_node(looper, + sdk_pool_handle, + sdk_wallet_steward, + new_steward_name, + new_node_name, + tdir, + tconf, + allPluginsPath, + services=None) looper.run(checkNodesConnected(txnPoolNodeSet)) - - # turn the new node on - node_data = { - ALIAS: newNode.name, - SERVICES: [VALIDATOR] - } - - updateNodeDataAndReconnect(looper, newSteward, - newStewardWallet, newNode, - node_data, - tdir, tconf, - txnPoolNodeSet + [newNode]) + sdk_pool_refresh(looper, sdk_pool_handle) + new_node = update_node_data_and_reconnect(looper, txnPoolNodeSet + [new_node], + new_steward_wallet, + sdk_pool_handle, + new_node, + None, None, + None, None, + tdir, tconf) + txnPoolNodeSet.append(new_node) + sdk_ensure_pool_functional(looper, txnPoolNodeSet, new_steward_wallet, sdk_pool_handle) diff --git a/plenum/test/pool_transactions/test_nodes_ha_change_back.py b/plenum/test/pool_transactions/test_nodes_ha_change_back.py index 91a7c72e4b..a6c31eaf5c 100644 --- a/plenum/test/pool_transactions/test_nodes_ha_change_back.py +++ b/plenum/test/pool_transactions/test_nodes_ha_change_back.py @@ -1,11 +1,15 @@ -from plenum.common.constants import ALIAS, NODE_IP, NODE_PORT, CLIENT_IP, CLIENT_PORT -from plenum.test.pool_transactions.helper import updateNodeData +from plenum.common.util import hexToFriendly + +from plenum.test.pool_transactions.helper import sdk_send_update_node from plenum.test.test_node import TestNode, checkNodesConnected from stp_core.network.port_dispenser import genHa from plenum.common.config_helper import PNodeConfigHelper -def testChangeNodeHaBack(looper, txnPoolNodeSet, tdir, tconf, - steward1, stewardWallet, nodeThetaAdded): + +def testChangeNodeHaBack(looper, txnPoolNodeSet, + sdk_pool_handle, + sdk_node_theta_added, + tconf, tdir): """ The case: The Node HA is updated with some HA (let's name it 'correct' HA). @@ -13,46 +17,44 @@ def testChangeNodeHaBack(looper, txnPoolNodeSet, tdir, tconf, ('wrong' HA). The Steward replaces back 'wrong' HA by 'correct' HA sending yet another one NODE txn. """ - - steward, stewardWallet, theta = nodeThetaAdded - clientHa = theta.cliNodeReg['ThetaC'] # use the same client HA + new_steward_wallet, new_node = sdk_node_theta_added + client_ha = new_node.cliNodeReg['ThetaC'] # use the same client HA # do all exercises without the Node - theta.stop() - looper.removeProdable(name=theta.name) + new_node.stop() + looper.removeProdable(name=new_node.name) # step 1: set 'correct' HA - correctNodeHa = genHa(1) - op = { - ALIAS: theta.name, - NODE_IP: correctNodeHa.host, - NODE_PORT: correctNodeHa.port, - CLIENT_IP: clientHa.host, - CLIENT_PORT: clientHa.port, - } - updateNodeData(looper, steward, stewardWallet, theta, - op) + correct_node_ha = genHa(1) + + node_dest = hexToFriendly(new_node.nodestack.verhex) + sdk_send_update_node(looper, new_steward_wallet, sdk_pool_handle, + node_dest, new_node.name, + correct_node_ha.host, correct_node_ha.port, + client_ha.host, client_ha.port) # step 2: set 'wrong' HA - wrongNodeHa = genHa(1) - op.update({NODE_IP: wrongNodeHa.host, NODE_PORT: wrongNodeHa.port}) - updateNodeData(looper, steward, stewardWallet, theta, - op) + wrong_node_ha = genHa(1) + sdk_send_update_node(looper, new_steward_wallet, sdk_pool_handle, + node_dest, new_node.name, + wrong_node_ha.host, wrong_node_ha.port, + client_ha.host, client_ha.port) # step 3: set 'correct' HA back - op.update({NODE_IP: correctNodeHa.host, NODE_PORT: correctNodeHa.port}) - updateNodeData(looper, steward, stewardWallet, theta, - op) + sdk_send_update_node(looper, new_steward_wallet, sdk_pool_handle, + node_dest, new_node.name, + correct_node_ha.host, correct_node_ha.port, + client_ha.host, client_ha.port) # In order to save the time the pool connection is not maintaining # during the steps, only the final result is checked. - config_helper = PNodeConfigHelper(theta.name, tconf, chroot=tdir) - restartedNode = TestNode(theta.name, + config_helper = PNodeConfigHelper(new_node.name, tconf, chroot=tdir) + restartedNode = TestNode(new_node.name, config_helper=config_helper, - config=tconf, ha=correctNodeHa, cliha=clientHa) + config=tconf, ha=correct_node_ha, cliha=client_ha) looper.add(restartedNode) txnPoolNodeSet[-1] = restartedNode looper.run(checkNodesConnected(txnPoolNodeSet)) # check Theta HA for n in txnPoolNodeSet: - assert n.nodeReg['Theta'] == correctNodeHa + assert n.nodeReg['Theta'] == correct_node_ha 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 a526a1f4c1..64fff8c604 100644 --- a/plenum/test/pool_transactions/test_nodes_with_pool_txns.py +++ b/plenum/test/pool_transactions/test_nodes_with_pool_txns.py @@ -1,103 +1,86 @@ import itertools -from copy import copy +import json import base58 +import pytest -from plenum.common.constants import CLIENT_STACK_SUFFIX, DATA, TARGET_NYM, \ - NODE_IP, NODE_PORT, CLIENT_IP, CLIENT_PORT +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 from plenum.common.signer_simple import SimpleSigner from plenum.common.util import getMaxFailures, randomString from plenum.test import waits -from plenum.test.helper import sendReqsToNodesAndVerifySuffReplies, \ - waitRejectWithReason, \ - waitReqNackFromPoolWithReason -from plenum.test.node_catchup.helper import ensureClientConnectedToNodesAndPoolLedgerSame -from plenum.test.pool_transactions.helper import addNewClient, \ - addNewStewardAndNode, sendAddNewNode, add_2_nodes -from plenum.test.test_node import checkNodesConnected, \ - checkProtocolInstanceSetup +from plenum.test.helper import sdk_send_random_and_check, sdk_get_and_check_replies +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 +from plenum.test.test_node import checkProtocolInstanceSetup from stp_core.common.log import getlogger from stp_core.loop.eventually import eventually logger = getlogger() -# logged errors to ignore -whitelist = ['found legacy entry', "doesn't match", 'reconciling nodeReg', - 'missing', 'conflicts', 'matches', 'nodeReg', - 'conflicting address', 'unable to send message', - 'got error while verifying message'] - # Whitelisting "got error while verifying message" since a node while not have # initialised a connection for a new node by the time the new node's message # reaches it -def testStewardCannotAddMoreThanOneNode(looper, txnPoolNodeSet, steward1, - stewardWallet, tdir, tconf, +def testStewardCannotAddMoreThanOneNode(looper, txnPoolNodeSet, sdk_pool_handle, + sdk_wallet_steward, tdir, tconf, allPluginsPath): - newNodeName = "Epsilon" - sendAddNewNode(tdir, tconf, newNodeName, steward1, stewardWallet) - - for node in txnPoolNodeSet: - waitRejectWithReason(looper, steward1, - 'already has a node', - node.clientstack.name) - - -def testNonStewardCannotAddNode(looper, txnPoolNodeSet, client1, - wallet1, client1Connected, tdir, - tconf, allPluginsPath): - newNodeName = "Epsilon" - sendAddNewNode(tdir, tconf, newNodeName, client1, wallet1) - for node in txnPoolNodeSet: - waitRejectWithReason( - looper, client1, 'is not a steward so cannot add a ' - 'new node', node.clientstack.name) - - -def testClientConnectsToNewNode( - looper, - txnPoolNodeSet, - tdir, - client_tdir, - tconf, - steward1, - stewardWallet, - allPluginsPath): + new_node_name = "Epsilon" + with pytest.raises(RequestRejectedException) as e: + sdk_add_new_node(looper, + sdk_pool_handle, + sdk_wallet_steward, + new_node_name, + tdir, + tconf, + allPluginsPath) + assert 'already has a node' in e._excinfo[1].args[0] + sdk_pool_refresh(looper, sdk_pool_handle) + + +def testNonStewardCannotAddNode(looper, txnPoolNodeSet, sdk_pool_handle, + sdk_wallet_client, tdir, tconf, + allPluginsPath): + new_node_name = "Epsilon" + with pytest.raises(RequestRejectedException) as e: + sdk_add_new_node(looper, + sdk_pool_handle, + sdk_wallet_client, + new_node_name, + tdir, + tconf, + allPluginsPath) + assert 'is not a steward so cannot add a ' in e._excinfo[1].args[0] + sdk_pool_refresh(looper, sdk_pool_handle) + + +def testClientConnectsToNewNode(looper, + sdk_pool_handle, + txnPoolNodeSet, + sdk_node_theta_added, + sdk_wallet_client): """ A client should be able to connect to a newly added node """ - newStewardName = "testClientSteward" + randomString(3) - newNodeName = "Epsilon" - oldNodeReg = copy(steward1.nodeReg) - newSteward, newStewardWallet, newNode = addNewStewardAndNode(looper, - steward1, stewardWallet, - newStewardName, newNodeName, - tdir, client_tdir, - tconf, allPluginsPath) - txnPoolNodeSet.append(newNode) - looper.run(checkNodesConnected(txnPoolNodeSet)) - logger.debug("{} connected to the pool".format(newNode)) - - def chkNodeRegRecvd(): - assert (len(steward1.nodeReg) - len(oldNodeReg)) == 1 - assert (newNode.name + CLIENT_STACK_SUFFIX) in steward1.nodeReg + _, new_node = sdk_node_theta_added + logger.debug("{} connected to the pool".format(new_node)) + sdk_send_random_and_check(looper, txnPoolNodeSet, sdk_pool_handle, sdk_wallet_client, 1) - timeout = waits.expectedClientToPoolConnectionTimeout(len(txnPoolNodeSet)) - looper.run(eventually(chkNodeRegRecvd, retryWait=1, timeout=timeout)) - ensureClientConnectedToNodesAndPoolLedgerSame(looper, steward1, - *txnPoolNodeSet) - ensureClientConnectedToNodesAndPoolLedgerSame(looper, newSteward, - *txnPoolNodeSet) - -def testAdd2NewNodes(looper, txnPoolNodeSet, tdir, client_tdir, tconf, steward1, - stewardWallet, allPluginsPath): +def testAdd2NewNodes(looper, txnPoolNodeSet, + sdk_pool_handle, sdk_wallet_steward, + tdir, tconf, allPluginsPath): """ Add 2 new nodes to trigger replica addition and primary election """ - new_nodes = add_2_nodes(looper, txnPoolNodeSet, steward1, stewardWallet, - tdir, client_tdir, tconf, allPluginsPath) + new_nodes = sdk_add_2_nodes(looper, txnPoolNodeSet, + sdk_pool_handle, sdk_wallet_steward, + tdir, tconf, allPluginsPath) for n in new_nodes: logger.debug("{} connected to the pool".format(n)) @@ -111,60 +94,78 @@ def checkFValue(): timeout = waits.expectedClientToPoolConnectionTimeout(len(txnPoolNodeSet)) looper.run(eventually(checkFValue, retryWait=1, timeout=timeout)) checkProtocolInstanceSetup(looper, txnPoolNodeSet, retryWait=1) + sdk_pool_refresh(looper, sdk_pool_handle) def testStewardCannotAddNodeWithOutFullFieldsSet(looper, tdir, tconf, txnPoolNodeSet, - newAdHocSteward): + sdk_pool_handle, + sdk_wallet_steward): """ The case: Steward accidentally sends the NODE txn without full fields set. The expected result: Steward gets NAck response from the pool. """ - newNodeName = "Epsilon" - - newSteward, newStewardWallet = newAdHocSteward + new_node_name = "Epsilon" + + new_steward_wallet_handle = sdk_add_new_nym(looper, + sdk_pool_handle, + sdk_wallet_steward, + alias='New steward' + randomString(3), + role=STEWARD_STRING) + sigseed, verkey, bls_key, nodeIp, nodePort, clientIp, clientPort = \ + prepare_new_node_data(tconf, tdir, new_node_name) + _, steward_did = new_steward_wallet_handle + node_request = looper.loop.run_until_complete( + prepare_node_request(steward_did, + new_node_name=new_node_name, + clientIp=clientIp, + clientPort=clientPort, + nodeIp=nodeIp, + nodePort=nodePort, + bls_key=bls_key, + sigseed=sigseed)) # case from the ticket - def _renameNodePortField(op): - op[DATA].update({NODE_PORT + ' ': op[DATA][NODE_PORT]}) - del op[DATA][NODE_PORT] + request_json = json.loads(node_request) + request_json['operation'][DATA][NODE_PORT + ' '] = request_json['operation'][DATA][NODE_PORT] + del request_json['operation'][DATA][NODE_PORT] + node_request1 = json.dumps(request_json) - sendAddNewNode(tdir, tconf, newNodeName, newSteward, newStewardWallet, - transformOpFunc=_renameNodePortField) - waitReqNackFromPoolWithReason(looper, txnPoolNodeSet, newSteward, - "unknown field") + request_couple = sdk_sign_and_send_prepared_request(looper, new_steward_wallet_handle, + sdk_pool_handle, node_request1) + with pytest.raises(RequestNackedException) as e: + sdk_get_and_check_replies(looper, [request_couple]) + assert 'unknown field' in e._excinfo[1].args[0] for fn in (NODE_IP, CLIENT_IP, NODE_PORT, CLIENT_PORT): - def _tnf(op): del op[DATA][fn] - - sendAddNewNode(tdir, tconf, newNodeName, newSteward, newStewardWallet, - transformOpFunc=_tnf) + request_json = json.loads(node_request) + del request_json['operation'][DATA][fn] + node_request2 = json.dumps(request_json) + request_couple = sdk_sign_and_send_prepared_request(looper, new_steward_wallet_handle, + sdk_pool_handle, node_request2) # wait NAcks with exact message. it does not works for just 'is missed' # because the 'is missed' will check only first few cases - waitReqNackFromPoolWithReason(looper, txnPoolNodeSet, newSteward, - "unknown field") + with pytest.raises(RequestNackedException) as e: + sdk_get_and_check_replies(looper, [request_couple]) + assert 'missed fields' in e._excinfo[1].args[0] def testNodesConnect(txnPoolNodeSet): pass -def testNodesReceiveClientMsgs(looper, txnPoolNodeSet, wallet1, client1, - client1Connected): - ensureClientConnectedToNodesAndPoolLedgerSame(looper, client1, - *txnPoolNodeSet) - sendReqsToNodesAndVerifySuffReplies(looper, wallet1, client1, 1) +def testNodesReceiveClientMsgs(looper, txnPoolNodeSet, sdk_wallet_client, sdk_pool_handle): + sdk_ensure_pool_functional(looper, txnPoolNodeSet, sdk_wallet_client, sdk_pool_handle) -def testAddNewClient(looper, txnPoolNodeSet, steward1, stewardWallet): - wallet = addNewClient(None, looper, steward1, - stewardWallet, randomString()) +def testAddNewClient(looper, txnPoolNodeSet, sdk_wallet_new_client): + _, did = sdk_wallet_new_client def chk(): for node in txnPoolNodeSet: - assert wallet.defaultId in \ + assert did in \ node.clientAuthNr.core_authenticator.clients timeout = waits.expectedTransactionExecutionTime(len(txnPoolNodeSet)) @@ -173,17 +174,28 @@ def chk(): def testStewardCannotAddNodeWithNonBase58VerKey(looper, tdir, tconf, txnPoolNodeSet, - newAdHocSteward): + sdk_pool_handle, + sdk_wallet_new_steward): """ The Case: Steward accidentally sends the NODE txn with a non base58 verkey. The expected result: Steward gets NAck response from the pool. """ - # create a new steward - newSteward, newStewardWallet = newAdHocSteward - - newNodeName = "Epsilon" + new_node_name = "Epsilon" + + sigseed, verkey, bls_key, nodeIp, nodePort, clientIp, clientPort = \ + prepare_new_node_data(tconf, tdir, new_node_name) + _, steward_did = sdk_wallet_new_steward + node_request = looper.loop.run_until_complete( + prepare_node_request(steward_did, + new_node_name=new_node_name, + clientIp=clientIp, + clientPort=clientPort, + nodeIp=nodeIp, + nodePort=nodePort, + bls_key=bls_key, + sigseed=sigseed)) # get hex VerKey sigseed = randomString(32).encode() @@ -191,29 +203,41 @@ def testStewardCannotAddNodeWithNonBase58VerKey(looper, tdir, tconf, b = base58.b58decode(nodeSigner.identifier) hexVerKey = bytearray(b).hex() - def _setHexVerkey(op): - op[TARGET_NYM] = hexVerKey - return op + request_json = json.loads(node_request) + request_json['operation'][TARGET_NYM] = hexVerKey + node_request = json.dumps(request_json) - sendAddNewNode(tdir, tconf, newNodeName, newSteward, newStewardWallet, - transformOpFunc=_setHexVerkey) - waitReqNackFromPoolWithReason(looper, txnPoolNodeSet, newSteward, - 'should not contain the following chars') + request_couple = sdk_sign_and_send_prepared_request(looper, sdk_wallet_new_steward, + sdk_pool_handle, node_request) + with pytest.raises(RequestNackedException) as e: + sdk_get_and_check_replies(looper, [request_couple]) + assert 'should not contain the following chars' in e._excinfo[1].args[0] def testStewardCannotAddNodeWithInvalidHa(looper, tdir, tconf, txnPoolNodeSet, - newAdHocSteward): + sdk_wallet_new_steward, + sdk_pool_handle): """ The case: Steward accidentally sends the NODE txn with an invalid HA. The expected result: Steward gets NAck response from the pool. """ - newNodeName = "Epsilon" - - newSteward, newStewardWallet = newAdHocSteward - + new_node_name = "Epsilon" + + sigseed, verkey, bls_key, nodeIp, nodePort, clientIp, clientPort = \ + prepare_new_node_data(tconf, tdir, new_node_name) + _, steward_did = sdk_wallet_new_steward + node_request = looper.loop.run_until_complete( + prepare_node_request(steward_did, + new_node_name=new_node_name, + clientIp=clientIp, + clientPort=clientPort, + nodeIp=nodeIp, + nodePort=nodePort, + bls_key=bls_key, + sigseed=sigseed)) # a sequence of the test cases for each field tests = itertools.chain( itertools.product( @@ -227,11 +251,15 @@ def testStewardCannotAddNodeWithInvalidHa(looper, tdir, tconf, for field, value in tests: # create a transform function for each test - def _tnf(op): op[DATA].update({field: value}) - - sendAddNewNode(tdir, tconf, newNodeName, newSteward, newStewardWallet, - transformOpFunc=_tnf) + request_json = json.loads(node_request) + request_json['operation'][DATA][field] = value + node_request1 = json.dumps(request_json) + request_couple = sdk_sign_and_send_prepared_request(looper, sdk_wallet_new_steward, + sdk_pool_handle, node_request1) # wait NAcks with exact message. it does not works for just 'is invalid' # because the 'is invalid' will check only first few cases - waitReqNackFromPoolWithReason(looper, txnPoolNodeSet, newSteward, - "invalid network ip address") + with pytest.raises(RequestNackedException) as e: + sdk_get_and_check_replies(looper, [request_couple]) + assert 'invalid network ip address' in e._excinfo[1].args[0] or \ + 'expected types' in e._excinfo[1].args[0] or \ + 'network port out of the range' in e._excinfo[1].args[0] diff --git a/plenum/test/pool_transactions/test_start_many_nodes.py b/plenum/test/pool_transactions/test_start_many_nodes.py index c270cae67b..2286bffd50 100644 --- a/plenum/test/pool_transactions/test_start_many_nodes.py +++ b/plenum/test/pool_transactions/test_start_many_nodes.py @@ -1,19 +1,20 @@ # 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.primary_selection.test_primary_selection_pool_txn import \ - ensure_pool_functional nodeCount = 8 def test_genesis_nodes(looper, txnPoolNodeSet, - client1, wallet1, client1Connected): + sdk_pool_handle, + sdk_wallet_client): assert len(txnPoolNodeSet) == nodeCount for node in txnPoolNodeSet: assertEquality(node.poolLedger.size, nodeCount) stw_count = sum(1 for _, txn in node.domainLedger.getAllTxn() if (txn[TXN_TYPE] == NYM) and (txn.get(ROLE) == STEWARD)) assertEquality(stw_count, nodeCount) - ensure_pool_functional(looper, txnPoolNodeSet, wallet1, client1) + sdk_ensure_pool_functional(looper, txnPoolNodeSet, sdk_wallet_client, sdk_pool_handle) diff --git a/plenum/test/pool_transactions/test_suspend_node.py b/plenum/test/pool_transactions/test_suspend_node.py index bc83b84f38..fd610def2e 100644 --- a/plenum/test/pool_transactions/test_suspend_node.py +++ b/plenum/test/pool_transactions/test_suspend_node.py @@ -12,10 +12,6 @@ buildPoolClientAndWallet, cancelNodeSuspension from plenum.test.test_node import TestNode, checkNodesConnected -whitelist = ['found legacy entry', "doesn't match", 'reconciling nodeReg', - 'missing', 'conflicts', 'matches', 'nodeReg', - 'conflicting address', 'unable to send message'] - def checkNodeNotInNodeReg(nodeOrClient, nodeName): if isinstance(nodeOrClient, Node): @@ -36,7 +32,6 @@ def testStewardSuspendsNode(looper, txnPoolNodeSet, nodeThetaAdded, poolTxnStewardData, allPluginsPath): - newSteward, newStewardWallet, newNode = nodeThetaAdded newNodeNym = hexToFriendly(newNode.nodestack.verhex) suspendNode(looper, newSteward, newStewardWallet, newNodeNym, newNode.name) diff --git a/plenum/test/pool_transactions/test_txn_pool_manager.py b/plenum/test/pool_transactions/test_txn_pool_manager.py index 115012b74b..a0cba2d1ef 100644 --- a/plenum/test/pool_transactions/test_txn_pool_manager.py +++ b/plenum/test/pool_transactions/test_txn_pool_manager.py @@ -1,12 +1,13 @@ import pytest -from plenum.common.constants import TARGET_NYM, TXN_TYPE, NODE, ALIAS, SERVICES, CLIENT_STACK_SUFFIX -from plenum.test.pool_transactions.helper import updateNodeData -from plenum.test.primary_selection.conftest import stewardAndWalletForMasterNode, txnPoolMasterNodes +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 nodeCount = 7 nodes_wth_bls = 0 + @pytest.fixture() def pool_node_txns(poolTxnData): node_txns = [] @@ -15,6 +16,7 @@ def pool_node_txns(poolTxnData): node_txns.append(txn) return node_txns + def test_get_nym_by_name(txnPoolNodeSet, pool_node_txns): check_get_nym_by_name(txnPoolNodeSet, pool_node_txns) @@ -29,23 +31,20 @@ def test_get_nym_by_name_not_in_registry(txnPoolNodeSet, pool_node_txns): def test_get_nym_by_name_demoted(txnPoolNodeSet, pool_node_txns, - looper, stewardAndWalletForMasterNode): - client, wallet = stewardAndWalletForMasterNode - demote_node(txnPoolNodeSet[0], looper, client, wallet) + 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) check_get_nym_by_name(txnPoolNodeSet, pool_node_txns) -def demote_node(node, - looper, client, wallet): - node_data = { - ALIAS: node.name, - SERVICES: [] - } - updateNodeData(looper, - client, - wallet, - node, - node_data) +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): @@ -59,6 +58,3 @@ def check_get_nym_by_name(txnPoolNodeSet, pool_node_txns): assert node_nym assert node_nym == expected_data - - - diff --git a/plenum/test/pool_transactions/test_z_node_key_changed.py b/plenum/test/pool_transactions/test_z_node_key_changed.py index aa366b1c35..d95ca1c779 100644 --- a/plenum/test/pool_transactions/test_z_node_key_changed.py +++ b/plenum/test/pool_transactions/test_z_node_key_changed.py @@ -2,14 +2,15 @@ import base58 import types +from plenum.test.node_request.helper import sdk_ensure_pool_functional + from plenum.common import stack_manager from plenum.common.keygen_utils import initNodeKeysForBothStacks, \ initRemoteKeys from plenum.common.signer_simple import SimpleSigner from plenum.common.util import randomString -from plenum.test.node_catchup.helper import waitNodeDataEquality, \ - ensureClientConnectedToNodesAndPoolLedgerSame -from plenum.test.pool_transactions.helper import changeNodeKeys +from plenum.test.node_catchup.helper import waitNodeDataEquality +from plenum.test.pool_transactions.helper import sdk_change_node_keys from plenum.test.test_node import TestNode, checkNodesConnected from plenum.common.config_helper import PNodeConfigHelper from stp_core.common.log import getlogger @@ -17,35 +18,32 @@ logger = getlogger() -# logged errors to ignore -whitelist = ['found legacy entry', "doesn't match", 'reconciling nodeReg', - 'missing', 'conflicts', 'matches', 'nodeReg', - 'conflicting address', 'unable to send message', - 'got error while verifying message'] + # Whitelisting "got error while verifying message" since a node while not have # initialised a connection for a new node by the time the new node's message # reaches it def testNodeKeysChanged(looper, txnPoolNodeSet, tdir, - tconf, steward1, nodeThetaAdded, + tconf, sdk_node_theta_added, + sdk_pool_handle, allPluginsPath=None): - newSteward, newStewardWallet, newNode = nodeThetaAdded + new_steward_wallet, new_node = sdk_node_theta_added - newNode.stop() - looper.removeProdable(name=newNode.name) - nodeHa, nodeCHa = HA(*newNode.nodestack.ha), HA(*newNode.clientstack.ha) + new_node.stop() + looper.removeProdable(name=new_node.name) + nodeHa, nodeCHa = HA(*new_node.nodestack.ha), HA(*new_node.clientstack.ha) sigseed = randomString(32).encode() verkey = base58.b58encode(SimpleSigner(seed=sigseed).naclSigner.verraw) - changeNodeKeys(looper, newSteward, newStewardWallet, newNode, verkey) + sdk_change_node_keys(looper, new_node, new_steward_wallet, sdk_pool_handle, verkey) - config_helper = PNodeConfigHelper(newNode.name, tconf, chroot=tdir) - initNodeKeysForBothStacks(newNode.name, config_helper.keys_dir, sigseed, + config_helper = PNodeConfigHelper(new_node.name, tconf, chroot=tdir) + initNodeKeysForBothStacks(new_node.name, config_helper.keys_dir, sigseed, override=True) - logger.debug("{} starting with HAs {} {}".format(newNode, nodeHa, nodeCHa)) + logger.debug("{} starting with HAs {} {}".format(new_node, nodeHa, nodeCHa)) - node = TestNode(newNode.name, + node = TestNode(new_node.name, config_helper=config_helper, config=tconf, ha=nodeHa, cliha=nodeCHa, pluginPaths=allPluginsPath) @@ -56,22 +54,20 @@ def testNodeKeysChanged(looper, txnPoolNodeSet, tdir, looper.run(checkNodesConnected(txnPoolNodeSet)) waitNodeDataEquality(looper, node, *txnPoolNodeSet[:-1]) - ensureClientConnectedToNodesAndPoolLedgerSame(looper, steward1, - *txnPoolNodeSet) - ensureClientConnectedToNodesAndPoolLedgerSame(looper, newSteward, - *txnPoolNodeSet) + sdk_ensure_pool_functional(looper, txnPoolNodeSet, new_steward_wallet, sdk_pool_handle) def testNodeInitRemoteKeysErrorsNotSuppressed(looper, txnPoolNodeSet, - nodeThetaAdded, monkeypatch): - + sdk_node_theta_added, + monkeypatch, + sdk_pool_handle): TEST_EXCEPTION_MESSAGE = 'Failed to create some cert files' - newSteward, newStewardWallet, newNode = nodeThetaAdded + new_steward_wallet, new_node = sdk_node_theta_added - newNode.stop() - looper.removeProdable(name=newNode.name) - nodeHa, nodeCHa = HA(*newNode.nodestack.ha), HA(*newNode.clientstack.ha) + new_node.stop() + looper.removeProdable(name=new_node.name) + nodeHa, nodeCHa = HA(*new_node.nodestack.ha), HA(*new_node.clientstack.ha) sigseed = randomString(32).encode() verkey = base58.b58encode(SimpleSigner(seed=sigseed).naclSigner.verraw) @@ -99,6 +95,6 @@ def stackKeysChanged(self, *args, **kwargs): monkeypatch.setattr(stack_manager, 'initRemoteKeys', initRemoteKeysMock) - changeNodeKeys(looper, newSteward, newStewardWallet, newNode, verkey) + sdk_change_node_keys(looper, new_node, new_steward_wallet, sdk_pool_handle, verkey) monkeypatch.undo() diff --git a/plenum/test/sdk/test_sdk_bindings.py b/plenum/test/sdk/test_sdk_bindings.py index b54e63a7b5..a0af950371 100644 --- a/plenum/test/sdk/test_sdk_bindings.py +++ b/plenum/test/sdk/test_sdk_bindings.py @@ -1,7 +1,8 @@ import pytest from plenum.test.pool_transactions.conftest import looper from plenum.test.helper import sdk_send_random_request, \ - sdk_send_random_requests, sdk_get_and_check_replies + sdk_send_random_requests, sdk_get_and_check_replies, sdk_send_random_and_check +from plenum.test.pool_transactions.helper import sdk_pool_refresh def test_sdk_pool_handle(sdk_pool_handle): @@ -79,3 +80,9 @@ def test_sdk_steward_send_many(looper, sdk_pool_handle, sdk_wallet_steward): repl = sdk_get_and_check_replies(looper, resp_task) for _, resp in repl: assert resp['result'] + + +def test_sdk_pool_refresh(looper, txnPoolNodeSet, sdk_pool_handle, sdk_wallet_client): + sdk_pool_refresh(looper, sdk_pool_handle) + sdk_send_random_and_check(looper, txnPoolNodeSet, sdk_pool_handle, + sdk_wallet_client, 1)