def create_specific_node_request(looper, steward_wallet_handle,
                                 tconf, tdir, new_node_name=randomString(5),
                                 new_node_ip=None, new_node_port=None, new_client_ip=None,
                                 new_client_port=None):
    sigseed, verkey, bls_key, node_ip, node_port, client_ip, client_port, key_proof = \
        prepare_new_node_data(tconf, tdir, new_node_name)

    node_ip = new_node_ip if new_node_ip else node_ip
    node_port = new_node_port if new_node_port else node_port
    client_ip = new_client_ip if new_client_ip else client_ip
    client_port = new_client_port if new_client_port else client_port

    _, steward_did = steward_wallet_handle
    node_request = looper.loop.run_until_complete(
        prepare_node_request(steward_did,
                             new_node_name=new_node_name,
                             clientIp=client_ip,
                             clientPort=client_port,
                             nodeIp=node_ip,
                             nodePort=node_port,
                             bls_key=bls_key,
                             sigseed=sigseed,
                             services=[VALIDATOR],
                             key_proof=key_proof))
    return node_request
def create_specific_node_request(looper,
                                 steward_wallet_handle,
                                 tconf,
                                 tdir,
                                 new_node_name=randomString(5),
                                 new_node_ip=None,
                                 new_node_port=None,
                                 new_client_ip=None,
                                 new_client_port=None):
    sigseed, verkey, bls_key, node_ip, node_port, client_ip, client_port, key_proof = \
        prepare_new_node_data(tconf, tdir, new_node_name)

    node_ip = new_node_ip if new_node_ip else node_ip
    node_port = new_node_port if new_node_port else node_port
    client_ip = new_client_ip if new_client_ip else client_ip
    client_port = new_client_port if new_client_port else client_port

    _, steward_did = steward_wallet_handle
    node_request = looper.loop.run_until_complete(
        prepare_node_request(steward_did,
                             new_node_name=new_node_name,
                             clientIp=client_ip,
                             clientPort=client_port,
                             nodeIp=node_ip,
                             nodePort=node_port,
                             bls_key=bls_key,
                             sigseed=sigseed,
                             services=[VALIDATOR],
                             key_proof=key_proof))
    return node_request
def test_add_node_with_invalid_key_proof(looper, sdk_pool_handle,
                                         sdk_wallet_steward, tdir, tconf,
                                         allPluginsPath):
    new_node_name = "NewNode"
    sigseed, verkey, bls_key, nodeIp, nodePort, clientIp, clientPort, key_proof = \
        prepare_new_node_data(tconf, tdir, new_node_name)
    # change key_proof
    key_proof = key_proof.upper()

    # filling node request
    _, steward_did = sdk_wallet_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,
                             services=[VALIDATOR],
                             key_proof=key_proof))

    # sending request using 'sdk_' functions
    request_couple = sdk_sign_and_send_prepared_request(
        looper, sdk_wallet_steward, sdk_pool_handle, node_request)

    # waitng for replies
    with pytest.raises(RequestNackedException) as e:
        sdk_get_and_check_replies(looper, [request_couple])
        assert "Proof of possession {} " \
               "is incorrect for BLS key {}".format(key_proof, bls_key) \
               in e._excinfo[1].args[0]
예제 #4
0
    def _build_node(self,
                    steward_wallet_handle,
                    tconf,
                    tdir,
                    services=[VALIDATOR],
                    node_name=None,
                    node_data=None):
        if not node_name:
            node_name = randomString(10)
            print(node_name)
        sigseed, verkey, bls_key, nodeIp, nodePort, clientIp, clientPort, key_proof = \
            prepare_new_node_data(tconf, tdir, node_name) if not node_data else node_data

        # filling node request
        _, steward_did = steward_wallet_handle
        node_request = self.looper.loop.run_until_complete(
            prepare_node_request(steward_did,
                                 new_node_name=node_name,
                                 clientIp=clientIp,
                                 clientPort=clientPort,
                                 nodeIp=nodeIp,
                                 nodePort=nodePort,
                                 bls_key=bls_key,
                                 sigseed=sigseed,
                                 services=services,
                                 key_proof=key_proof))
        node_data = sigseed, verkey, bls_key, nodeIp, nodePort, clientIp, clientPort, key_proof
        return node_request, node_data, node_name
def testStewardCannotAddNodeWithOutFullFieldsSet(looper, tdir, tconf,
                                                 txnPoolNodeSet,
                                                 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.
    """
    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, key_proof = \
        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,
                             key_proof=key_proof))

    # case from the ticket
    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)

    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 'missed fields - node_port' in e._excinfo[1].args[0]

    for fn in (NODE_IP, CLIENT_IP, NODE_PORT, CLIENT_PORT):
        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
        with pytest.raises(RequestNackedException) as e:
            sdk_get_and_check_replies(looper, [request_couple])
        assert 'missed fields' in e._excinfo[1].args[0]
예제 #6
0
def test_catchup_after_replica_addition(looper, sdk_pool_handle, txnPoolNodeSet,
                                        sdk_wallet_steward, tdir, tconf, allPluginsPath):
    view_no = txnPoolNodeSet[-1].viewNo
    sdk_send_random_and_check(looper, txnPoolNodeSet,
                              sdk_pool_handle, sdk_wallet_steward, 1)
    waitNodeDataEquality(looper, *txnPoolNodeSet)

    # create node
    new_node_name = "Theta"
    sigseed, verkey, bls_key, nodeIp, nodePort, clientIp, clientPort, key_proof = \
        prepare_new_node_data(tconf, tdir, new_node_name)
    new_node = create_and_start_new_node(looper=looper, node_name=new_node_name,
                                         tdir=tdir, sigseed=sigseed,
                                         node_ha=(nodeIp, nodePort), client_ha=(clientIp, clientPort),
                                         tconf=tconf, auto_start=True, plugin_path=allPluginsPath,
                                         nodeClass=TestNode)

    _send_txn_for_creating_node(looper, sdk_pool_handle, sdk_wallet_steward, tdir, new_node_name, clientIp,
                                clientPort, nodeIp, nodePort, bls_key, sigseed, key_proof)

    txnPoolNodeSet.append(new_node)
    looper.run(checkNodesConnected(txnPoolNodeSet))

    looper.run(eventually(lambda: assertExp(n.viewNo == view_no + 1 for n in txnPoolNodeSet)))
    waitNodeDataEquality(looper, *txnPoolNodeSet)
    sdk_send_random_and_check(looper, txnPoolNodeSet, sdk_pool_handle,
                              sdk_wallet_steward, 1)
    waitNodeDataEquality(looper, *txnPoolNodeSet, exclude_from_check=['check_last_ordered_3pc'])
예제 #7
0
파일: conftest.py 프로젝트: nwyee/indy-node
def sdk_node_theta_added(looper,
                         txnPoolNodeSet,
                         tdir,
                         tconf,
                         sdk_pool_handle,
                         sdk_wallet_trustee,
                         allPluginsPath,
                         node_config_helper_class,
                         testNodeClass,
                         name=None):
    new_steward_name = "testClientSteward" + randomString(3)
    new_node_name = name or "Theta"

    new_steward_wallet = sdk_add_new_nym(looper,
                                         sdk_pool_handle,
                                         sdk_wallet_trustee,
                                         alias=new_steward_name,
                                         role=STEWARD_STRING)

    sigseed, verkey, bls_key, nodeIp, nodePort, clientIp, clientPort, key_proof = \
        prepare_new_node_data(tconf, tdir, new_node_name,
                              configClass=node_config_helper_class)

    # filling node request
    _, steward_did = new_steward_wallet
    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,
                             services=[VALIDATOR],
                             key_proof=key_proof))

    # sending request using 'sdk_' functions
    request_couple = sdk_sign_and_send_prepared_request(
        looper, new_steward_wallet, sdk_pool_handle, node_request)

    # waitng for replies
    sdk_get_and_check_replies(looper, [request_couple])

    new_node = create_and_start_new_node(looper,
                                         new_node_name,
                                         tdir,
                                         sigseed, (nodeIp, nodePort),
                                         (clientIp, clientPort),
                                         tconf,
                                         True,
                                         allPluginsPath,
                                         testNodeClass,
                                         configClass=node_config_helper_class)

    txnPoolNodeSet.append(new_node)
    looper.run(checkNodesConnected(txnPoolNodeSet))
    sdk_pool_refresh(looper, sdk_pool_handle)
    return new_steward_wallet, new_node
def testStewardCannotAddNodeWithOutFullFieldsSet(looper, tdir, tconf,
                                                 txnPoolNodeSet,
                                                 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.
    """
    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
    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)

    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):
        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
        with pytest.raises(RequestNackedException) as e:
            sdk_get_and_check_replies(looper, [request_couple])
        assert 'missed fields' in e._excinfo[1].args[0]
def test_send_node_with_invalid_dest_verkey(looper, sdk_pool_handle,
                                            sdk_wallet_steward, tdir, tconf):
    node_name = "Psi"
    new_steward_name = "testClientSteward" + randomString(3)
    new_steward_wallet_handle = sdk_add_new_nym(looper,
                                                sdk_pool_handle,
                                                sdk_wallet_steward,
                                                alias=new_steward_name,
                                                role=STEWARD_STRING)
    sigseed, verkey, bls_key, nodeIp, nodePort, clientIp, clientPort, key_proof = \
        prepare_new_node_data(tconf, tdir, node_name)

    # Invalid dest passes static validation
    assert len(base58.b58decode(invalid_dest)) == 32

    _, steward_did = new_steward_wallet_handle
    node_request = looper.loop.run_until_complete(
        prepare_node_request(steward_did,
                             new_node_name=node_name,
                             clientIp=clientIp,
                             clientPort=clientPort,
                             nodeIp=nodeIp,
                             nodePort=nodePort,
                             bls_key=bls_key,
                             destination=invalid_dest,
                             services=[VALIDATOR],
                             key_proof=key_proof))

    request_couple = sdk_sign_and_send_prepared_request(
        looper, new_steward_wallet_handle, sdk_pool_handle, node_request)
    sdk_get_bad_response(looper, [request_couple], RequestNackedException,
                         'Node\'s dest is not correct Ed25519 key.')

    node_request = looper.loop.run_until_complete(
        prepare_node_request(steward_did,
                             new_node_name=node_name,
                             clientIp=clientIp,
                             clientPort=clientPort,
                             nodeIp=nodeIp,
                             nodePort=nodePort,
                             bls_key=bls_key,
                             sigseed=sigseed,
                             services=[VALIDATOR],
                             key_proof=key_proof))

    node_request = json.loads(node_request)
    node_request['operation'][VERKEY] = invalid_dest
    node_request = json.dumps(node_request)

    request_couple = sdk_sign_and_send_prepared_request(
        looper, new_steward_wallet_handle, sdk_pool_handle, node_request)
    sdk_get_bad_response(looper, [request_couple], RequestNackedException,
                         'Node\'s verkey is not correct Ed25519 key.')
예제 #10
0
def sdk_node_theta_added(looper,
                         txnPoolNodeSet,
                         tdir,
                         tconf,
                         sdk_pool_handle,
                         sdk_wallet_trustee,
                         allPluginsPath,
                         node_config_helper_class,
                         testNodeClass,
                         name=None):
    new_steward_name = "testClientSteward" + randomString(3)
    new_node_name = name or "Theta"

    new_steward_wallet = sdk_add_new_nym(looper,
                                         sdk_pool_handle,
                                         sdk_wallet_trustee,
                                         alias=new_steward_name,
                                         role=STEWARD_STRING)

    sigseed, verkey, bls_key, nodeIp, nodePort, clientIp, clientPort = \
        prepare_new_node_data(tconf, tdir, new_node_name,
                              configClass=node_config_helper_class)

    # filling node request
    _, steward_did = new_steward_wallet
    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,
                             services=[VALIDATOR]))

    # sending request using 'sdk_' functions
    request_couple = sdk_sign_and_send_prepared_request(looper, new_steward_wallet,
                                                        sdk_pool_handle, node_request)

    # waitng for replies
    sdk_get_and_check_replies(looper, [request_couple])

    new_node = create_and_start_new_node(looper, new_node_name, tdir, sigseed,
                                         (nodeIp, nodePort), (clientIp, clientPort),
                                         tconf, True, allPluginsPath,
                                         testNodeClass,
                                         configClass=node_config_helper_class)

    txnPoolNodeSet.append(new_node)
    looper.run(checkNodesConnected(txnPoolNodeSet))
    sdk_pool_refresh(looper, sdk_pool_handle)
    return new_steward_wallet, new_node
def testStewardCannotAddNodeWithInvalidHa(looper, tdir, tconf,
                                          txnPoolNodeSet,
                                          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.
    """
    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(
            (NODE_IP, CLIENT_IP), ('127.0.0.1 ', '256.0.0.1', '0.0.0.0')
        ),
        itertools.product(
            (NODE_PORT, CLIENT_PORT), ('foo', '9700',
                                       0, 65535 + 1, 4351683546843518184)
        ),
    )

    for field, value in tests:
        # create a transform function for each test
        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
        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]
예제 #12
0
def build_node_request(looper, tconf, tdir, sdk_wallet):
    new_node_name = 'Node' + randomString(3)
    sigseed, verkey, bls_key, nodeIp, nodePort, clientIp, clientPort, key_proof = \
        prepare_new_node_data(tconf, tdir, new_node_name)

    _, steward_did = sdk_wallet
    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,
                             services=[],
                             key_proof=key_proof))
    return node_request
def testStewardCannotAddNodeWithNonBase58VerKey(looper, tdir, tconf,
                                                txnPoolNodeSet,
                                                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.
    """
    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()
    nodeSigner = SimpleSigner(seed=sigseed)
    b = base58.b58decode(nodeSigner.identifier)
    hexVerKey = bytearray(b).hex()

    request_json = json.loads(node_request)
    request_json['operation'][TARGET_NYM] = hexVerKey
    node_request = json.dumps(request_json)

    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 'client request invalid' in e._excinfo[1].args[0]
def test_different_ledger_request_interleave(tconf, looper, txnPoolNodeSet,
                                             sdk_one_node_added, tdir,
                                             tdirWithPoolTxns, allPluginsPath,
                                             sdk_pool_handle,
                                             sdk_wallet_client,
                                             sdk_wallet_steward):
    """
    Send pool and domain ledger requests such that they interleave, and do
    view change in between and verify the pool is functional
    """
    new_node = sdk_one_node_added
    sdk_send_random_and_check(looper, txnPoolNodeSet, sdk_pool_handle,
                              sdk_wallet_client, 2)
    ensure_all_nodes_have_same_data(looper, txnPoolNodeSet)

    # Send domain ledger requests but don't wait for replies
    requests = sdk_send_random_requests(looper, sdk_pool_handle,
                                        sdk_wallet_client, 2)

    # Add another node by sending pool ledger request
    _, new_theta = sdk_node_theta_added(looper,
                                        txnPoolNodeSet,
                                        tdir,
                                        tconf,
                                        sdk_pool_handle,
                                        sdk_wallet_steward,
                                        allPluginsPath,
                                        name='new_theta')

    # Send more domain ledger requests but don't wait for replies
    requests.extend(
        sdk_send_random_requests(looper, sdk_pool_handle, sdk_wallet_client,
                                 3))

    # Do view change without waiting for replies
    ensure_view_change(looper, nodes=txnPoolNodeSet)
    checkProtocolInstanceSetup(looper, txnPoolNodeSet, retryWait=1)

    # Make sure all requests are completed
    total_timeout = sdk_eval_timeout(len(requests), len(txnPoolNodeSet))
    sdk_get_and_check_replies(looper, requests, timeout=total_timeout)
    sdk_ensure_pool_functional(looper, txnPoolNodeSet, sdk_wallet_client,
                               sdk_pool_handle)
    new_steward_wallet, steward_did = sdk_add_new_nym(looper,
                                                      sdk_pool_handle,
                                                      sdk_wallet_steward,
                                                      'another_ste',
                                                      role='STEWARD')

    # Send another pool ledger request (NODE) but don't wait for completion of
    # request
    next_node_name = 'next_node'

    sigseed, verkey, bls_key, nodeIp, nodePort, clientIp, clientPort, key_proof = \
        prepare_new_node_data(tconf, tdir, next_node_name)
    node_req = looper.loop.run_until_complete(
        prepare_node_request(steward_did,
                             new_node_name=next_node_name,
                             clientIp=clientIp,
                             clientPort=clientPort,
                             nodeIp=nodeIp,
                             nodePort=nodePort,
                             bls_key=bls_key,
                             sigseed=sigseed,
                             key_proof=key_proof))

    sdk_wallet = (new_steward_wallet, steward_did)
    request_couple = sdk_sign_and_send_prepared_request(
        looper, sdk_wallet, sdk_pool_handle, node_req)

    # Send more domain ledger requests but don't wait for replies
    request_couples = [
        request_couple, *sdk_send_random_requests(looper, sdk_pool_handle,
                                                  sdk_wallet_client, 5)
    ]

    # Make sure all requests are completed
    total_timeout = sdk_eval_timeout(len(request_couples), len(txnPoolNodeSet))
    sdk_get_and_check_replies(looper, request_couples, timeout=total_timeout)

    # Make sure pool is functional
    sdk_ensure_pool_functional(looper, txnPoolNodeSet, sdk_wallet_client,
                               sdk_pool_handle)
def test_different_ledger_request_interleave(tconf, looper, txnPoolNodeSet,
                                             sdk_one_node_added,
                                             tdir,
                                             tdirWithPoolTxns,
                                             allPluginsPath,
                                             sdk_pool_handle, sdk_wallet_client,
                                             sdk_wallet_steward):
    """
    Send pool and domain ledger requests such that they interleave, and do
    view change in between and verify the pool is functional
    """
    new_node = sdk_one_node_added
    sdk_send_random_and_check(looper, txnPoolNodeSet, sdk_pool_handle,
                              sdk_wallet_client, 2)
    ensure_all_nodes_have_same_data(looper, txnPoolNodeSet)

    # Send domain ledger requests but don't wait for replies
    requests = sdk_send_random_requests(looper, sdk_pool_handle,
                                        sdk_wallet_client, 2)

    # Add another node by sending pool ledger request
    _, new_theta = sdk_node_theta_added(looper,
                                        txnPoolNodeSet,
                                        tdir,
                                        tconf,
                                        sdk_pool_handle,
                                        sdk_wallet_steward,
                                        allPluginsPath,
                                        name='new_theta')

    # Send more domain ledger requests but don't wait for replies
    requests.extend(sdk_send_random_requests(looper, sdk_pool_handle,
                                             sdk_wallet_client, 3))

    # Do view change without waiting for replies
    ensure_view_change(looper, nodes=txnPoolNodeSet)
    checkProtocolInstanceSetup(looper, txnPoolNodeSet, retryWait=1)

    # Make sure all requests are completed
    total_timeout = sdk_eval_timeout(len(requests), len(txnPoolNodeSet))
    sdk_get_and_check_replies(looper, requests, timeout=total_timeout)
    sdk_ensure_pool_functional(looper, txnPoolNodeSet,
                               sdk_wallet_client, sdk_pool_handle)
    new_steward_wallet, steward_did = sdk_add_new_nym(looper,
                                                      sdk_pool_handle,
                                                      sdk_wallet_steward,
                                                      'another_ste',
                                                      role='STEWARD')

    # Send another pool ledger request (NODE) but don't wait for completion of
    # request
    next_node_name = 'next_node'

    sigseed, verkey, bls_key, nodeIp, nodePort, clientIp, clientPort, key_proof = \
        prepare_new_node_data(tconf, tdir, next_node_name)
    node_req = looper.loop.run_until_complete(
        prepare_node_request(steward_did,
                             new_node_name=next_node_name,
                             clientIp=clientIp,
                             clientPort=clientPort,
                             nodeIp=nodeIp,
                             nodePort=nodePort,
                             bls_key=bls_key,
                             sigseed=sigseed,
                             key_proof=key_proof))

    sdk_wallet = (new_steward_wallet, steward_did)
    request_couple = sdk_sign_and_send_prepared_request(looper, sdk_wallet,
                                                        sdk_pool_handle,
                                                        node_req)

    # Send more domain ledger requests but don't wait for replies
    request_couples = [request_couple, *
    sdk_send_random_requests(looper, sdk_pool_handle,
                             sdk_wallet_client, 5)]

    # Make sure all requests are completed
    total_timeout = sdk_eval_timeout(len(request_couples), len(txnPoolNodeSet))
    sdk_get_and_check_replies(looper, request_couples, timeout=total_timeout)

    # Make sure pool is functional
    sdk_ensure_pool_functional(looper, txnPoolNodeSet,
                               sdk_wallet_client, sdk_pool_handle)
def test_commit_signature_validation_integration(looper,
                                                 txnPoolNodeSet,
                                                 sdk_pool_handle,
                                                 sdk_wallet_steward,
                                                 sdk_wallet_client,
                                                 tconf,
                                                 tdir):
    '''
    All nodes receive PrePrepare1(txn1 for pool_ledger)
    Nodes 1, 2 ordered txn1 and nodes 3, 4 did not.
    All nodes  receive PrePrepare2(txn2 for domain_ledger)
    Nodes 3, 4 receive commits from nodes 1, 2
    Nodes 3, 4 ordered txn1
    Check that all nodes ordered txn2
    '''
    fast_nodes = txnPoolNodeSet[:2]
    slow_nodes = txnPoolNodeSet[2:]

    sdk_send_random_and_check(looper, txnPoolNodeSet, sdk_pool_handle,
                              sdk_wallet_steward, 1)

    # create new steward
    new_steward_wallet_handle = sdk_add_new_nym(looper,
                                                sdk_pool_handle,
                                                sdk_wallet_steward,
                                                alias="testClientSteward945",
                                                role=STEWARD_STRING)

    sigseed, verkey, bls_key, nodeIp, nodePort, clientIp, clientPort, key_proof = \
        prepare_new_node_data(tconf, tdir, "new_node")

    # create node request to add new demote node
    _, steward_did = new_steward_wallet_handle
    node_request = looper.loop.run_until_complete(
        prepare_node_request(steward_did,
                             new_node_name="new_node",
                             clientIp=clientIp,
                             clientPort=clientPort,
                             nodeIp=nodeIp,
                             nodePort=nodePort,
                             bls_key=bls_key,
                             sigseed=sigseed,
                             services=[],
                             key_proof=key_proof))

    first_ordered = txnPoolNodeSet[0].master_last_ordered_3PC
    with ord_delay(slow_nodes):
        request1 = sdk_sign_and_send_prepared_request(looper, new_steward_wallet_handle,
                                                      sdk_pool_handle, node_request)

        key1 = get_key_from_req(request1[0])

        def check_nodes_receive_pp(view_no, seq_no):
            for node in txnPoolNodeSet:
                assert node.master_replica.getPrePrepare(view_no, seq_no)

        looper.run(eventually(check_nodes_receive_pp, first_ordered[0], first_ordered[1] + 1))

        def check_fast_nodes_ordered_request():
            for n in fast_nodes:
                assert key1 not in n.requests or n.requests[key1].executed
            for n in slow_nodes:
                assert not n.requests[key1].executed

        looper.run(eventually(check_fast_nodes_ordered_request))

        request2 = sdk_send_random_request(looper, sdk_pool_handle, sdk_wallet_client)
        looper.run(eventually(check_nodes_receive_pp, first_ordered[0], first_ordered[1] + 2))

        def check_nodes_receive_commits(view_no, seq_no):
            for node in txnPoolNodeSet:
                assert len(node.master_replica.commits[view_no, seq_no].voters) >= node.f + 1
        looper.run(eventually(check_nodes_receive_commits, first_ordered[0], first_ordered[1] + 2))

    sdk_get_and_check_replies(looper, [request1])
    sdk_get_and_check_replies(looper, [request2])
def bls_keys(tconf, tdir):
    new_node_name = "NewNode"
    _, _, bls_key, _, _, _, _, key_proof = prepare_new_node_data(
        tconf, tdir, new_node_name)
    return bls_key, key_proof
def test_commit_signature_validation_integration(looper,
                                                 txnPoolNodeSet,
                                                 sdk_pool_handle,
                                                 sdk_wallet_steward,
                                                 sdk_wallet_client,
                                                 tconf,
                                                 tdir):
    '''
    All nodes receive PrePrepare1(txn1 for pool_ledger)
    Nodes 1, 2 ordered txn1 and nodes 3, 4 did not.
    All nodes  receive PrePrepare2(txn2 for domain_ledger)
    Nodes 3, 4 receive commits from nodes 1, 2
    Nodes 3, 4 ordered txn1
    Check that all nodes ordered txn2
    '''
    fast_nodes = txnPoolNodeSet[:2]
    slow_nodes = txnPoolNodeSet[2:]

    sdk_send_random_and_check(looper, txnPoolNodeSet, sdk_pool_handle,
                              sdk_wallet_steward, 1)

    # create new steward
    new_steward_wallet_handle = sdk_add_new_nym(looper,
                                                sdk_pool_handle,
                                                sdk_wallet_steward,
                                                alias="testClientSteward945",
                                                role=STEWARD_STRING)

    sigseed, verkey, bls_key, nodeIp, nodePort, clientIp, clientPort, key_proof = \
        prepare_new_node_data(tconf, tdir, "new_node")

    # create node request to add new demote node
    _, steward_did = new_steward_wallet_handle
    node_request = looper.loop.run_until_complete(
        prepare_node_request(steward_did,
                             new_node_name="new_node",
                             clientIp=clientIp,
                             clientPort=clientPort,
                             nodeIp=nodeIp,
                             nodePort=nodePort,
                             bls_key=bls_key,
                             sigseed=sigseed,
                             services=[],
                             key_proof=key_proof))

    first_ordered = txnPoolNodeSet[0].master_last_ordered_3PC
    with ord_delay(slow_nodes):
        request1 = sdk_sign_and_send_prepared_request(looper, new_steward_wallet_handle,
                                                      sdk_pool_handle, node_request)

        key1 = get_key_from_req(request1[0])

        def check_nodes_receive_pp(view_no, seq_no):
            for node in txnPoolNodeSet:
                assert node.master_replica._ordering_service.get_preprepare(view_no, seq_no)

        looper.run(eventually(check_nodes_receive_pp, first_ordered[0], first_ordered[1] + 1))

        def check_fast_nodes_ordered_request():
            for n in fast_nodes:
                assert key1 not in n.requests or n.requests[key1].executed
            for n in slow_nodes:
                assert not n.requests[key1].executed

        looper.run(eventually(check_fast_nodes_ordered_request))

        request2 = sdk_send_random_request(looper, sdk_pool_handle, sdk_wallet_client)
        looper.run(eventually(check_nodes_receive_pp, first_ordered[0], first_ordered[1] + 2))

        def check_nodes_receive_commits(view_no, seq_no):
            for node in txnPoolNodeSet:
                assert len(node.master_replica._ordering_service.commits[view_no, seq_no].voters) >= node.f + 1
        looper.run(eventually(check_nodes_receive_commits, first_ordered[0], first_ordered[1] + 2))

    sdk_get_and_check_replies(looper, [request1])
    sdk_get_and_check_replies(looper, [request2])