def testDemoteNodeWhichWasNeverActive(looper, nodeSet, sdk_pool_handle, sdk_wallet_trustee, tdir, tconf, allPluginsPath): """ Add a node without services field and check that the ledger does not contain the `services` field and check that it can be demoted and the ledger has `services` as empty list """ new_steward_wallet, new_node = sdk_node_theta_added( looper, nodeSet, tdir, tconf, sdk_pool_handle, sdk_wallet_trustee, allPluginsPath, node_config_helper_class=NodeConfigHelper, testNodeClass=TestNode, name="Node-" + randomString(5), services=None) looper.runFor(tconf.PROPAGATE_REQUEST_DELAY * 1.5) for node in nodeSet[:nodeCount]: txn = [t for _, t in node.poolLedger.getAllTxn()][-1] txn_data = get_payload_data(txn) assert txn_data[TARGET_NYM] == hexToFriendly(new_node.nodestack.verhex) assert SERVICES not in txn_data[DATA] demote_node(looper, new_steward_wallet, sdk_pool_handle, new_node) for node in nodeSet[:nodeCount]: txn = [t for _, t in node.poolLedger.getAllTxn()][-1] txn_data = get_payload_data(txn) assert txn_data[TARGET_NYM] == hexToFriendly(new_node.nodestack.verhex) assert SERVICES in txn_data[DATA] and txn_data[DATA][SERVICES] == []
def testSuspendNode(looper, sdk_pool_handle, sdk_wallet_trustee, nodeSet, tdir, tconf, allPluginsPath): """ Suspend a node and then cancel suspension. Suspend while suspended to test that there is no error """ start_view_no = nodeSet[0].viewNo new_steward_wallet, new_node = sdk_node_theta_added( looper, nodeSet, tdir, tconf, sdk_pool_handle, sdk_wallet_trustee, allPluginsPath, node_config_helper_class=NodeConfigHelper, testNodeClass=TestNode, name="Node-" + randomString(5)) waitForViewChange(looper=looper, txnPoolNodeSet=nodeSet, expectedViewNo=start_view_no + 1) ensureElectionsDone(looper=looper, nodes=nodeSet) demote_node(looper, sdk_wallet_trustee, sdk_pool_handle, new_node) _wait_view_change_finish(looper, nodeSet[:-1], start_view_no + 1) demote_node(looper, sdk_wallet_trustee, sdk_pool_handle, new_node) promote_node(looper, sdk_wallet_trustee, sdk_pool_handle, new_node) _wait_view_change_finish(looper, nodeSet[:-1], start_view_no + 2) promote_node(looper, sdk_wallet_trustee, sdk_pool_handle, new_node)
def test_requests_post_multiple_new_nodes( looper, nodeSet, tconf, tdir, sdk_pool_handle, sdk_wallet_trustee, allPluginsPath, some_transactions_done): new_nodes = [] for node_name in ('Zeta', 'Eta'): new_steward_wallet, new_node = sdk_node_theta_added(looper, nodeSet, tdir, tconf, sdk_pool_handle, sdk_wallet_trustee, allPluginsPath, node_config_helper_class=NodeConfigHelper, testNodeClass=TestNode, name=node_name) new_nodes.append(new_node) for _ in range(5): sdk_add_new_nym(looper, sdk_pool_handle, sdk_wallet_trustee) for new_node in new_nodes: waitNodeDataEquality(looper, new_node, *nodeSet[:-2]) for _ in range(5): sdk_add_new_nym(looper, sdk_pool_handle, sdk_wallet_trustee)
def test_state_recovering_for_auth_rule(nodeSet, looper, sdk_pool_handle, sdk_wallet_steward, sdk_wallet_trustee, tdir, tconf, allPluginsPath, valid_upgrade, auth_keys, monkeypatch): version1 = "1.1.58" version2 = "1.1.88" # send POOL_UPGRADE to write in a ledger sdk_ensure_upgrade_sent(looper, sdk_pool_handle, sdk_wallet_trustee, valid_upgrade) send_node_upgrades(nodeSet, version1, looper, count=1) send_auth_rule(looper, sdk_pool_handle, sdk_wallet_trustee, auth_keys[0]) send_node_upgrades(nodeSet, version1, looper) for n in nodeSet: handler = n.write_manager.request_handlers.get(AUTH_RULE)[0] handler_for_1_9_1 = n.write_manager._request_handlers_with_version.get( (AUTH_RULE, "1.9.1"))[0] monkeypatch.setattr(handler, '_update_auth_constraint', handler_for_1_9_1._update_auth_constraint) send_auth_rule(looper, sdk_pool_handle, sdk_wallet_trustee, auth_keys[1]) monkeypatch.undo() send_node_upgrades(nodeSet, version2, looper) send_auth_rule(looper, sdk_pool_handle, sdk_wallet_trustee, auth_keys[2]) new_steward_wallet, new_node = sdk_node_theta_added( looper, nodeSet, tdir, tconf, sdk_pool_handle, sdk_wallet_trustee, allPluginsPath, node_config_helper_class=NodeConfigHelper, testNodeClass=TestNode) waitNodeDataEquality(looper, new_node, *nodeSet[:-1], exclude_from_check=['check_last_ordered_3pc_backup'])
def test_new_node_catchup_update_projection(looper, nodeSet, tconf, tdir, sdk_pool_handle, sdk_wallet_trustee, allPluginsPath, some_transactions_done): """ A node which receives txns from catchup updates both ledger and projection 4 nodes start up and some txns happen, after txns are done, new node joins and starts catching up, the node should not process requests while catchup is in progress. Make sure the new requests are coming from the new NYMs added while the node was offline or catching up. """ # Create a new node and stop it. new_steward_wallet, new_node = sdk_node_theta_added(looper, nodeSet, tdir, tconf, sdk_pool_handle, sdk_wallet_trustee, allPluginsPath, node_config_helper_class=NodeConfigHelper, testNodeClass=TestNode) waitNodeDataEquality(looper, new_node, *nodeSet[:-1]) ta_count = 2 np_count = 2 new_txn_count = 2 * ta_count + np_count # Since ATTRIB txn is done for TA old_ledger_sizes = {} new_ledger_sizes = {} old_projection_sizes = {} new_projection_sizes = {} old_seq_no_map_sizes = {} new_seq_no_map_sizes = {} def get_ledger_size(node): return len(node.domainLedger) def get_projection_size(node): domain_state = node.getState(DOMAIN_LEDGER_ID) return len(domain_state.as_dict) def get_seq_no_map_size(node): return node.seqNoDB.size def fill_counters(ls, ps, ss, nodes): for n in nodes: ls[n.name] = get_ledger_size(n) ps[n.name] = get_projection_size(n) ss[n.name] = get_seq_no_map_size(n) def check_sizes(nodes): for node in nodes: assert new_ledger_sizes[node.name] - \ old_ledger_sizes[node.name] == new_txn_count assert new_projection_sizes[node.name] - \ old_projection_sizes[node.name] == new_txn_count assert new_seq_no_map_sizes[node.name] - \ old_seq_no_map_sizes[node.name] == new_txn_count # Stop a node and note down the sizes of ledger and projection (state) other_nodes = nodeSet[:-1] fill_counters(old_ledger_sizes, old_projection_sizes, old_seq_no_map_sizes, other_nodes) new_node.cleanupOnStopping = False # new_node.stop() # looper.removeProdable(new_node) # ensure_node_disconnected(looper, new_node, other_nodes) disconnect_node_and_ensure_disconnected(looper, nodeSet, new_node.name) looper.removeProdable(name=new_node.name) trust_anchors = [] attributes = [] for i in range(ta_count): trust_anchors.append( sdk_add_new_nym(looper, sdk_pool_handle, sdk_wallet_trustee, role='TRUST_ANCHOR', alias='TA' + str(i))) attributes.append((randomString(6), randomString(10))) sdk_add_raw_attribute(looper, sdk_pool_handle, trust_anchors[-1], *attributes[-1]) non_privileged = [] for i in range(np_count): non_privileged.append( sdk_add_new_nym(looper, sdk_pool_handle, sdk_wallet_trustee, alias='NP' + str(i))) checkNodeDataForEquality(nodeSet[0], *other_nodes) fill_counters(new_ledger_sizes, new_projection_sizes, new_seq_no_map_sizes, other_nodes) # The size difference should be same as number of new NYM txns check_sizes(other_nodes) new_node = start_stopped_node(new_node, looper, tconf, tdir, allPluginsPath) nodeSet[-1] = new_node fill_counters(old_ledger_sizes, old_projection_sizes, old_seq_no_map_sizes, [new_node]) looper.run(checkNodesConnected(nodeSet)) waitNodeDataEquality(looper, new_node, *other_nodes) fill_counters(new_ledger_sizes, new_projection_sizes, new_seq_no_map_sizes, [new_node]) check_sizes([new_node]) # Set the old counters to be current ledger and projection size fill_counters(old_ledger_sizes, old_projection_sizes, old_seq_no_map_sizes, nodeSet) more_nyms_count = 2 for wh in trust_anchors: for i in range(more_nyms_count): non_privileged.append(sdk_add_new_nym(looper, sdk_pool_handle, wh, alias='NP1' + str(i))) # The new node should process transactions done by Nyms added to its # ledger while catchup fill_counters(new_ledger_sizes, new_projection_sizes, new_seq_no_map_sizes, nodeSet) new_txn_count = more_nyms_count * len(trust_anchors) check_sizes(nodeSet)
def test_new_node_catchup_update_projection(looper, nodeSet, tconf, tdir, sdk_pool_handle, sdk_wallet_trustee, allPluginsPath, some_transactions_done): """ A node which receives txns from catchup updates both ledger and projection 4 nodes start up and some txns happen, after txns are done, new node joins and starts catching up, the node should not process requests while catchup is in progress. Make sure the new requests are coming from the new NYMs added while the node was offline or catching up. """ # Create a new node and stop it. new_steward_wallet, new_node = sdk_node_theta_added(looper, nodeSet, tdir, tconf, sdk_pool_handle, sdk_wallet_trustee, allPluginsPath, node_config_helper_class=NodeConfigHelper, testNodeClass=TestNode) waitNodeDataEquality(looper, new_node, *nodeSet[:-1]) ta_count = 2 np_count = 2 new_txn_count = 2 * ta_count + np_count # Since ATTRIB txn is done for TA old_ledger_sizes = {} new_ledger_sizes = {} old_projection_sizes = {} new_projection_sizes = {} old_seq_no_map_sizes = {} new_seq_no_map_sizes = {} def get_ledger_size(node): return len(node.domainLedger) def get_projection_size(node): domain_state = node.getState(DOMAIN_LEDGER_ID) return len(domain_state.as_dict) def get_seq_no_map_size(node): return node.seqNoDB.size def fill_counters(ls, ps, ss, nodes): for n in nodes: ls[n.name] = get_ledger_size(n) ps[n.name] = get_projection_size(n) ss[n.name] = get_seq_no_map_size(n) def check_sizes(nodes): for node in nodes: assert new_ledger_sizes[node.name] - \ old_ledger_sizes[node.name] == new_txn_count assert new_projection_sizes[node.name] - \ old_projection_sizes[node.name] == new_txn_count assert new_seq_no_map_sizes[node.name] - \ old_seq_no_map_sizes[node.name] == new_txn_count # Stop a node and note down the sizes of ledger and projection (state) other_nodes = nodeSet[:-1] fill_counters(old_ledger_sizes, old_projection_sizes, old_seq_no_map_sizes, other_nodes) new_node.cleanupOnStopping = False # new_node.stop() # looper.removeProdable(new_node) # ensure_node_disconnected(looper, new_node, other_nodes) disconnect_node_and_ensure_disconnected(looper, nodeSet, new_node.name) looper.removeProdable(name=new_node.name) trust_anchors = [] attributes = [] for i in range(ta_count): trust_anchors.append( sdk_add_new_nym(looper, sdk_pool_handle, sdk_wallet_trustee, role='TRUST_ANCHOR', alias='TA' + str(i))) attributes.append((randomString(6), randomString(10))) sdk_add_raw_attribute(looper, sdk_pool_handle, trust_anchors[-1], *attributes[-1]) non_privileged = [] for i in range(np_count): non_privileged.append( sdk_add_new_nym(looper, sdk_pool_handle, sdk_wallet_trustee, alias='NP' + str(i))) checkNodeDataForEquality(nodeSet[0], *other_nodes) fill_counters(new_ledger_sizes, new_projection_sizes, new_seq_no_map_sizes, other_nodes) # The size difference should be same as number of new NYM txns check_sizes(other_nodes) new_node = start_stopped_node(new_node, looper, tconf, tdir, allPluginsPath) nodeSet[-1] = new_node fill_counters(old_ledger_sizes, old_projection_sizes, old_seq_no_map_sizes, [new_node]) looper.run(checkNodesConnected(nodeSet)) sdk_pool_refresh(looper, sdk_pool_handle) waitNodeDataEquality(looper, new_node, *other_nodes) fill_counters(new_ledger_sizes, new_projection_sizes, new_seq_no_map_sizes, [new_node]) check_sizes([new_node]) # Set the old counters to be current ledger and projection size fill_counters(old_ledger_sizes, old_projection_sizes, old_seq_no_map_sizes, nodeSet) more_nyms_count = 2 for wh in trust_anchors: for i in range(more_nyms_count): non_privileged.append(sdk_add_new_nym(looper, sdk_pool_handle, wh, alias='NP1' + str(i))) # The new node should process transactions done by Nyms added to its # ledger while catchup fill_counters(new_ledger_sizes, new_projection_sizes, new_seq_no_map_sizes, nodeSet) new_txn_count = more_nyms_count * len(trust_anchors) check_sizes(nodeSet)