def client_send_revoc_reg_def(looper, txnPoolNodeSet, sdk_wallet_client,
                              sdk_pool_handle, build_revoc_def_by_default,
                              claim_def, tconf):
    # We need to have claim_def to send revocation txns
    Authoriser.auth_map = None
    OLD_ANYONE_CAN_WRITE = tconf.ANYONE_CAN_WRITE
    tconf.ANYONE_CAN_WRITE = True

    claim_def_req = sdk_sign_request_from_dict(looper, sdk_wallet_client,
                                               claim_def)
    sdk_send_and_check([json.dumps(claim_def_req)], looper, txnPoolNodeSet,
                       sdk_pool_handle)

    tconf.ANYONE_CAN_WRITE = OLD_ANYONE_CAN_WRITE
    Authoriser.auth_map = None

    _, author_did = sdk_wallet_client
    revoc_reg = build_revoc_def_by_default
    revoc_reg['operation'][CRED_DEF_ID] = \
        make_state_path_for_claim_def(author_did,
                                      str(claim_def_req['operation'][CLAIM_DEF_SCHEMA_REF]),
                                      claim_def_req['operation'][CLAIM_DEF_SIGNATURE_TYPE],
                                      claim_def_req['operation'][CLAIM_DEF_TAG]
                                      ).decode()
    revoc_req = sdk_sign_request_from_dict(looper, sdk_wallet_client,
                                           revoc_reg['operation'])
    _, revoc_reply = sdk_send_and_check([json.dumps(revoc_req)], looper,
                                        txnPoolNodeSet, sdk_pool_handle)[0]
    return revoc_req
Beispiel #2
0
def do_transfer(txnPoolNodeSet,
                sdk_pool_handle,
                helpers,
                looper,
                sdk_wallet,
                addresses,
                amount,
                sign=False):
    [address_giver, address_receiver] = addresses

    inputs = helpers.general.get_utxo_addresses([address_giver])[0]
    change = sum([utxo["amount"] for utxo in inputs]) - amount
    outputs = [
        {
            ADDRESS: address_receiver,
            AMOUNT: amount
        },
        {
            ADDRESS: address_giver,
            AMOUNT: change
        },
    ]

    request = helpers.request.transfer(inputs, outputs)
    _, request._identifier = sdk_wallet
    requests = sdk_sign_request_objects(looper, sdk_wallet, [request]) \
        if sign else [json.dumps(request.as_dict)]
    sdk_send_and_check(requests, looper, txnPoolNodeSet, sdk_pool_handle)
def test_6_nodes_pool_cannot_reach_quorum_with_2_disconnected(
        txnPoolNodeSet, looper, sdk_pool_handle,
        sdk_wallet_client):
    '''
    Check that we can not reach consensus when more than n-f nodes
    are disconnected: disconnect 2 of 6 nodes
    '''
    faulties = nodes_by_rank(txnPoolNodeSet)[-faultyNodes:]

    current_node_set = set(txnPoolNodeSet)
    for node in faulties:
        for r in node.replicas.values():
            assert not r.isPrimary
        disconnect_node_and_ensure_disconnected(
            looper, current_node_set, node, stopNode=False)
        current_node_set.remove(node)

    reqs = sdk_signed_random_requests(looper, sdk_wallet_client, 1)
    with pytest.raises(PoolLedgerTimeoutException):
        sdk_send_and_check(reqs, looper, txnPoolNodeSet, sdk_pool_handle)
    check_request_is_not_returned_to_nodes(
        txnPoolNodeSet, sdk_json_to_request_object(json.loads(reqs[0])))

    # The following reconnection of nodes is needed in this test to avoid
    # pytest process hangup
    for node in faulties:
        current_node_set.add(node)
        reconnect_node_and_ensure_connected(looper, current_node_set, node)
Beispiel #4
0
def test_6_nodes_pool_cannot_reach_quorum_with_2_disconnected(
        txnPoolNodeSet, looper, sdk_pool_handle,
        sdk_wallet_client):
    '''
    Check that we can not reach consensus when more than n-f nodes
    are disconnected: disconnect 2 of 6 nodes
    '''
    faulties = nodes_by_rank(txnPoolNodeSet)[-faultyNodes:]

    current_node_set = set(txnPoolNodeSet)
    for node in faulties:
        for r in node.replicas:
            assert not r.isPrimary
        disconnect_node_and_ensure_disconnected(
            looper, current_node_set, node, stopNode=False)
        current_node_set.remove(node)

    reqs = sdk_signed_random_requests(looper, sdk_wallet_client, 1)
    with pytest.raises(TimeoutError):
        sdk_send_and_check(reqs, looper, txnPoolNodeSet, sdk_pool_handle)
    check_request_is_not_returned_to_nodes(
        txnPoolNodeSet, sdk_json_to_request_object(json.loads(reqs[0])))

    # The following reconnection of nodes is needed in this test to avoid
    # pytest process hangup
    for node in faulties:
        current_node_set.add(node)
        reconnect_node_and_ensure_connected(looper, current_node_set, node)
Beispiel #5
0
def test_revoc_send_twice(send_revoc_def, sdk_pool_handle, looper,
                          txnPoolNodeSet):
    # 1. Send revocation definition
    req = send_revoc_def
    # 2. Resend revocation definition
    sdk_send_and_check([json.dumps(req)], looper, txnPoolNodeSet,
                       sdk_pool_handle)
Beispiel #6
0
def send_claim_def(looper,
                   txnPoolNodeSet,
                   sdk_wallet_steward,
                   sdk_pool_handle,
                   claim_def):
    req = sdk_sign_request_from_dict(looper, sdk_wallet_steward, claim_def)
    sdk_send_and_check([json.dumps(req)], looper, txnPoolNodeSet, sdk_pool_handle)
    return req
def test_6_nodes_pool_cannot_reach_quorum_with_2_faulty(afterElection, looper,
                                                        txnPoolNodeSet, prepared1,
                                                        sdk_wallet_client, sdk_pool_handle):
    reqs = sdk_signed_random_requests(looper, sdk_wallet_client, 1)
    with pytest.raises(PoolLedgerTimeoutException):
        sdk_send_and_check(reqs, looper, txnPoolNodeSet, sdk_pool_handle)
    check_request_is_not_returned_to_nodes(
        txnPoolNodeSet, sdk_json_to_request_object(json.loads(reqs[0])))
Beispiel #8
0
def test_6_nodes_pool_cannot_reach_quorum_with_2_faulty(
        afterElection, looper, txnPoolNodeSet, prepared1, sdk_wallet_client,
        sdk_pool_handle):
    reqs = sdk_signed_random_requests(looper, sdk_wallet_client, 1)
    with pytest.raises(TimeoutError):
        sdk_send_and_check(reqs, looper, txnPoolNodeSet, sdk_pool_handle)
    check_request_is_not_returned_to_nodes(
        txnPoolNodeSet, sdk_json_to_request_object(json.loads(reqs[0])))
Beispiel #9
0
def create_revoc_reg_entry(looper, txnPoolNodeSet, sdk_pool_handle, build_revoc, claim_def, wallet):
    revoc_def_req = create_revoc_reg_def(looper, txnPoolNodeSet, sdk_pool_handle, build_revoc,
                                         claim_def, wallet)

    rev_reg_entry = build_revoc_reg_entry_for_given_revoc_reg_def(revoc_def_req)
    rev_reg_entry[VALUE][REVOKED] = [1, 2, 3, 4, 5]
    del rev_reg_entry[VALUE][PREV_ACCUM]
    rev_entry_req = sdk_sign_request_from_dict(looper, wallet, rev_reg_entry)
    sdk_send_and_check([json.dumps(rev_entry_req)], looper, txnPoolNodeSet, sdk_pool_handle)
    return rev_entry_req
Beispiel #10
0
def test_client_can_send_revoc_reg_entry(looper,
                                         client_send_revoc_reg_def,
                                         sdk_wallet_client,
                                         txnPoolNodeSet,
                                         sdk_pool_handle):
    revoc_def_req = client_send_revoc_reg_def
    rev_reg_entry = build_revoc_reg_entry_for_given_revoc_reg_def(revoc_def_req)
    rev_reg_entry[VALUE][REVOKED] = [1, 2, 3, 4, 5]
    del rev_reg_entry[VALUE][PREV_ACCUM]
    rev_entry_req = sdk_sign_request_from_dict(looper, sdk_wallet_client, rev_reg_entry)
    sdk_send_and_check([json.dumps(rev_entry_req)], looper, txnPoolNodeSet, sdk_pool_handle)
def test_6_nodes_pool_cannot_reach_quorum_with_2_disconnected(
        txnPoolNodeSet, looper, sdk_pool_handle, sdk_wallet_client):
    '''
    Check that we can not reach consensus when more than n-f nodes are disconnected:
    disconnect 2 of 6 nodes
    '''
    stop_nodes(looper, txnPoolNodeSet)
    reqs = sdk_signed_random_requests(looper, sdk_wallet_client, 1)
    with pytest.raises(AssertionError):
        sdk_send_and_check(reqs, looper, txnPoolNodeSet, sdk_pool_handle)
    check_request_is_not_returned_to_nodes(
        txnPoolNodeSet, sdk_json_to_request_object(json.loads(reqs[0])))
Beispiel #12
0
def test_repeated_request_not_processed_if_already_ordered(
        looper, txnPoolNodeSet, sdk_pool_handle, sdk_wallet_client):
    delta = txnPoolNodeSet[3]
    initial_ledger_size = delta.domainLedger.size

    one_req = sdk_signed_random_requests(looper, sdk_wallet_client, 1)
    sdk_send_and_check(one_req, looper, txnPoolNodeSet, sdk_pool_handle)

    sdk_send_signed_requests(sdk_pool_handle, one_req)
    looper.runFor(waits.expectedTransactionExecutionTime(len(txnPoolNodeSet)))

    for node in txnPoolNodeSet:
        assert node.domainLedger.size - initial_ledger_size == 1
def test_repeated_request_not_processed_if_already_ordered(
        looper, txnPoolNodeSet, sdk_pool_handle, sdk_wallet_client):
    delta = txnPoolNodeSet[3]
    initial_ledger_size = delta.domainLedger.size

    one_req = sdk_signed_random_requests(looper, sdk_wallet_client, 1)
    sdk_send_and_check(one_req, looper, txnPoolNodeSet, sdk_pool_handle)

    sdk_send_signed_requests(sdk_pool_handle, one_req)
    looper.runFor(waits.expectedTransactionExecutionTime(len(txnPoolNodeSet)))

    for node in txnPoolNodeSet:
        assert node.domainLedger.size - initial_ledger_size == 1
def test_client_can_send_claim_def(looper, txnPoolNodeSet, sdk_wallet_client,
                                   sdk_wallet_trust_anchor, sdk_pool_handle,
                                   claim_def):
    # Trust anchor can create claim_def in any case
    req = sdk_sign_request_from_dict(looper, sdk_wallet_trust_anchor,
                                     claim_def)
    sdk_send_and_check([json.dumps(req)], looper, txnPoolNodeSet,
                       sdk_pool_handle)

    # Client can create claim_def if ANYONE_CAN_WRITE flag set to False
    req = sdk_sign_request_from_dict(looper, sdk_wallet_client, claim_def)
    sdk_send_and_check([json.dumps(req)], looper, txnPoolNodeSet,
                       sdk_pool_handle)
Beispiel #15
0
def test_catchup_during_3pc(tconf, looper, txnPoolNodeSet, sdk_wallet_client,
                            sdk_pool_handle):
    reqs = sdk_signed_random_requests(looper, sdk_wallet_client,
                                      tconf.Max3PCBatchSize)
    non_primary_replica = getNonPrimaryReplicas(txnPoolNodeSet, instId=0)[0]

    # Simulate catch-up (add txns to ledger):
    # add txns corresponding to the requests after we got enough COMMITs to
    # order, but before ordering.
    add_txns_to_ledger_before_order(
        non_primary_replica,
        [json.loads(req) for req in reqs[:tconf.Max3PCBatchSize]])
    sdk_send_and_check(reqs, looper, txnPoolNodeSet, sdk_pool_handle)
    checkNodesHaveSameRoots(txnPoolNodeSet)
Beispiel #16
0
def test_belated_propagate_not_processed_if_already_ordered(
        looper, txnPoolNodeSet, sdk_pool_handle, sdk_wallet_client):
    delta = txnPoolNodeSet[3]
    initial_ledger_size = delta.domainLedger.size
    delta.nodeIbStasher.delay(ppgDelay(300, 'Gamma'))

    one_req = sdk_signed_random_requests(looper, sdk_wallet_client, 1)
    sdk_send_and_check(one_req, looper, txnPoolNodeSet, sdk_pool_handle)

    delta.nodeIbStasher.reset_delays_and_process_delayeds()
    looper.runFor(waits.expectedTransactionExecutionTime(len(txnPoolNodeSet)))

    for node in txnPoolNodeSet:
        assert node.domainLedger.size - initial_ledger_size == 1
def test_client_cant_send_claim_def(looper,
                                    txnPoolNodeSet,
                                    sdk_wallet_client,
                                    sdk_wallet_endorser,
                                    sdk_pool_handle,
                                    claim_def):
    # Endorser can create claim_def
    req = sdk_sign_request_from_dict(looper, sdk_wallet_endorser, claim_def)
    sdk_send_and_check([json.dumps(req)], looper, txnPoolNodeSet, sdk_pool_handle)

    # Client cant send create
    req = sdk_sign_request_from_dict(looper, sdk_wallet_client, claim_def)
    req = sdk_send_signed_requests(sdk_pool_handle, [json.dumps(req)])
    sdk_get_bad_response(looper, req, RequestRejectedException, 'Rule for this action is')
Beispiel #18
0
def send_revoc_reg_def_by_demand(looper, txnPoolNodeSet, sdk_wallet_steward,
                                 sdk_pool_handle, send_claim_def,
                                 build_revoc_def_by_demand):
    _, author_did = sdk_wallet_steward
    claim_def_req = send_claim_def
    revoc_reg = build_revoc_def_by_demand
    revoc_reg['operation'][CRED_DEF_ID] = build_path_for_claim_def(
        author_did, claim_def_req['operation']["signature_type"],
        str(claim_def_req['operation']["ref"]))
    revoc_req = sdk_sign_request_from_dict(looper, sdk_wallet_steward,
                                           revoc_reg['operation'])
    sdk_send_and_check([json.dumps(revoc_req)], looper, txnPoolNodeSet,
                       sdk_pool_handle)
    return revoc_req
def test_belated_propagate_not_processed_if_already_ordered(
        looper, txnPoolNodeSet, sdk_pool_handle, sdk_wallet_client):
    delta = txnPoolNodeSet[3]
    initial_ledger_size = delta.domainLedger.size
    delta.nodeIbStasher.delay(ppgDelay(300, 'Gamma'))

    one_req = sdk_signed_random_requests(looper, sdk_wallet_client, 1)
    sdk_send_and_check(one_req, looper, txnPoolNodeSet, sdk_pool_handle)

    delta.nodeIbStasher.reset_delays_and_process_delayeds()
    looper.runFor(waits.expectedTransactionExecutionTime(len(txnPoolNodeSet)))

    for node in txnPoolNodeSet:
        assert node.domainLedger.size - initial_ledger_size == 1
def test_client_cant_send_claim_def(looper, txnPoolNodeSet, sdk_wallet_client,
                                    sdk_wallet_trust_anchor, sdk_pool_handle,
                                    claim_def):
    # Trust anchor can create claim_def in any case
    req = sdk_sign_request_from_dict(looper, sdk_wallet_trust_anchor,
                                     claim_def)
    sdk_send_and_check([json.dumps(req)], looper, txnPoolNodeSet,
                       sdk_pool_handle)

    # Client cant send create if ANYONE_CAN_WRITE flag set to True
    req = sdk_sign_request_from_dict(looper, sdk_wallet_client, claim_def)
    req = sdk_send_signed_requests(sdk_pool_handle, [json.dumps(req)])
    sdk_get_bad_response(looper, req, RequestRejectedException,
                         'None role cannot add claim def')
Beispiel #21
0
def send_revoc_reg_def_by_demand(looper,
                                  txnPoolNodeSet,
                                  sdk_wallet_steward,
                                  sdk_pool_handle,
                                  send_claim_def,
                                 build_revoc_def_by_demand):
    _, author_did = sdk_wallet_steward
    claim_def_req = send_claim_def
    revoc_reg = build_revoc_def_by_demand
    revoc_reg['operation'][CRED_DEF_ID] = build_path_for_claim_def(author_did,
                                                                   claim_def_req['operation']["signature_type"],
                                                                   str(claim_def_req['operation']["ref"]))
    revoc_req = sdk_sign_request_from_dict(looper, sdk_wallet_steward, revoc_reg['operation'])
    sdk_send_and_check([json.dumps(revoc_req)], looper, txnPoolNodeSet, sdk_pool_handle)
    return revoc_req
Beispiel #22
0
def send_revoc_reg_def_by_demand(looper, txnPoolNodeSet, sdk_wallet_steward,
                                 sdk_pool_handle, send_claim_def,
                                 build_revoc_def_by_demand):
    _, author_did = sdk_wallet_steward
    claim_def_req = send_claim_def
    revoc_reg = build_revoc_def_by_demand
    revoc_reg['operation'][CRED_DEF_ID] = make_state_path_for_claim_def(
        author_did, str(claim_def_req['operation'][CLAIM_DEF_SCHEMA_REF]),
        claim_def_req['operation'][CLAIM_DEF_SIGNATURE_TYPE],
        claim_def_req['operation'][CLAIM_DEF_TAG]).decode()
    revoc_req = sdk_sign_request_from_dict(looper, sdk_wallet_steward,
                                           revoc_reg['operation'])
    sdk_send_and_check([json.dumps(revoc_req)], looper, txnPoolNodeSet,
                       sdk_pool_handle)
    return revoc_req
Beispiel #23
0
def test_send_get_revoc_reg_def(looper, txnPoolNodeSet, sdk_wallet_steward,
                                sdk_pool_handle,
                                send_revoc_reg_def_by_default):
    _, author_did = sdk_wallet_steward
    revoc_req, _ = send_revoc_reg_def_by_default
    revoc_reg_def_id = revoc_req['operation'][ID]
    get_revoc_reg_def_req = {
        ID:
        ":".join([
            author_did, domain.MARKER_REVOC_DEF,
            revoc_req['operation'][CRED_DEF_ID],
            revoc_req['operation'][REVOC_TYPE], revoc_req['operation'][TAG]
        ]),
        TXN_TYPE:
        GET_REVOC_REG_DEF,
        REVOC_TYPE:
        revoc_req['operation'][REVOC_TYPE],
    }
    get_revoc_reg_def_req = sdk_sign_request_from_dict(looper,
                                                       sdk_wallet_steward,
                                                       get_revoc_reg_def_req)
    replies = sdk_send_and_check([json.dumps(get_revoc_reg_def_req)], looper,
                                 txnPoolNodeSet, sdk_pool_handle)
    req, reply = replies[0]
    compare_request_reply(revoc_req, reply)
def test_send_get_revoc_reg_def(looper,
                                txnPoolNodeSet,
                                sdk_wallet_steward,
                                sdk_pool_handle,
                                send_revoc_reg_def_by_default):
    _, author_did = sdk_wallet_steward
    revoc_req, _ = send_revoc_reg_def_by_default
    revoc_reg_def_id = revoc_req['operation'][ID]
    get_revoc_reg_def_req = {
        ID: ":".join([author_did,
                      domain.MARKER_REVOC_DEF,
                      revoc_req['operation'][CRED_DEF_ID],
                      revoc_req['operation'][REVOC_TYPE],
                      revoc_req['operation'][TAG]]),
        TXN_TYPE: GET_REVOC_REG_DEF,
    }
    get_revoc_reg_def_req = sdk_sign_request_from_dict(looper,
                                                       sdk_wallet_steward,
                                                       get_revoc_reg_def_req)
    replies = sdk_send_and_check([json.dumps(get_revoc_reg_def_req)],
                                 looper,
                                 txnPoolNodeSet,
                                 sdk_pool_handle)
    req, reply = replies[0]
    compare_request_reply(revoc_req, reply)
Beispiel #25
0
 def send_revoc_reg_def(self, claim_def_req=None, author_did=None, wallet=None, revoc_reg_def=None):
     claim_def_req = claim_def_req if claim_def_req else self.claim_def_req
     wallet = wallet or self.trustee_wallet
     req = revoc_reg_def if revoc_reg_def else self.build_revoc_def_by_default(claim_def_req,
                                                                               author_did=author_did,
                                                                               wallet=wallet)
     return sdk_send_and_check([json.dumps(req)], self.looper, self.env.txnPoolNodeSet, self.sdk_pool_handle)
Beispiel #26
0
def test_trust_anchor_not_owner_cant_create_revoc_reg_entry(looper,
                                                            txnPoolNodeSet,
                                                            sdk_wallet_trustee,
                                                            sdk_wallet_trust_anchor,
                                                            sdk_pool_handle,
                                                            build_revoc_def_by_default,
                                                            claim_def, tconf):
    revoc_def_req_trustee = create_revoc_reg_def(looper, txnPoolNodeSet, sdk_pool_handle, build_revoc_def_by_default,
                                                 claim_def, sdk_wallet_trustee)

    rev_reg_entry = build_revoc_reg_entry_for_given_revoc_reg_def(revoc_def_req_trustee)
    rev_reg_entry[VALUE][REVOKED] = [1, 2, 3, 4, 5]
    del rev_reg_entry[VALUE][PREV_ACCUM]
    rev_entry_req_trust_anchor = sdk_sign_request_from_dict(looper, sdk_wallet_trust_anchor, rev_reg_entry)
    with pytest.raises(RequestRejectedException):
        sdk_send_and_check([json.dumps(rev_entry_req_trust_anchor)], looper, txnPoolNodeSet, sdk_pool_handle)
def send_revoc_reg_def(looper,
                       txnPoolNodeSet,
                       sdk_wallet_steward,
                       sdk_pool_handle,
                       send_claim_def,
                       build_revoc_def_by_default):
    _, author_did = sdk_wallet_steward
    claim_def_req = send_claim_def
    revoc_reg = build_revoc_def_by_default
    revoc_reg['operation'][CRED_DEF_ID] = ":".join([author_did,
                                                    domain.MARKER_CLAIM_DEF,
                                                    claim_def_req['operation']["signature_type"],
                                                    str(claim_def_req['operation']["ref"])])
    revoc_req = sdk_sign_request_from_dict(looper, sdk_wallet_steward, revoc_reg['operation'])
    sdk_send_and_check([json.dumps(revoc_req)], looper, txnPoolNodeSet, sdk_pool_handle)
    return revoc_req
def test_send_with_from_by_demand(looper, txnPoolNodeSet, sdk_pool_handle,
                                  sdk_wallet_steward,
                                  send_revoc_reg_entry_by_demand,
                                  build_get_revoc_reg_delta):
    # We save timestamp of state changes.
    # looper and txnPoolNodeSet has "module", therefore,
    # when we send request with FROM section, it's not a clean situation
    looper.runFor(3)
    # Assume, that send_revoc_reg_entry_by_demand will add into issued [1,2,3,4,5]
    rev_reg_req1, rev_reg_reply1 = send_revoc_reg_entry_by_demand
    rev_reg_req1['operation'][VALUE][ISSUED] = []
    # Revoked [1,2,3], Issued now must be [4,5]
    rev_reg_req1['operation'][VALUE][REVOKED] = [1, 2, 3]
    rev_reg_req1['operation'][VALUE][PREV_ACCUM] = rev_reg_req1['operation'][
        VALUE][ACCUM]
    rev_reg_req1['operation'][VALUE][ACCUM] = randomString(10)
    rev_reg_req2, rev_reg_reply2 = sdk_send_and_check([
        json.dumps(
            sdk_sign_request_from_dict(looper, sdk_wallet_steward,
                                       rev_reg_req1['operation']))
    ], looper, txnPoolNodeSet, sdk_pool_handle)[0]
    # Issued [10, 11]
    rev_reg_req2['operation'][VALUE][ISSUED] = [10, 11]
    rev_reg_req2['operation'][VALUE][REVOKED] = []
    rev_reg_req2['operation'][VALUE][PREV_ACCUM] = rev_reg_req2['operation'][
        VALUE][ACCUM]
    rev_reg_req2['operation'][VALUE][ACCUM] = randomString(10)
    rev_reg_req3, rev_reg_reply3 = sdk_send_and_check([
        json.dumps(
            sdk_sign_request_from_dict(looper, sdk_wallet_steward,
                                       rev_reg_req2['operation']))
    ], looper, txnPoolNodeSet, sdk_pool_handle)[0]
    reg_delta_req = copy.deepcopy(build_get_revoc_reg_delta)
    reg_delta_req['operation'][REVOC_REG_DEF_ID] = rev_reg_req1['operation'][
        REVOC_REG_DEF_ID]
    reg_delta_req['operation'][FROM] = get_txn_time(rev_reg_reply1['result'])
    reg_delta_req['operation'][TO] = get_txn_time(
        rev_reg_reply3['result']) + 1000
    get_reply = sdk_send_and_check([json.dumps(reg_delta_req)], looper,
                                   txnPoolNodeSet, sdk_pool_handle)[0][1]
    assert get_reply['result'][DATA][STATE_PROOF_FROM]
    assert get_reply['result'][DATA][VALUE][REVOKED] == [1, 2, 3]
    assert get_reply['result'][DATA][VALUE][ISSUED] == [10, 11]
    assert get_reply['result'][DATA][VALUE][ACCUM_TO][VALUE][
        ACCUM] == rev_reg_req3['operation'][VALUE][ACCUM]
    assert get_reply['result'][DATA][VALUE][ACCUM_FROM][VALUE][ACCUM] == \
           get_payload_data(rev_reg_reply1['result'])[VALUE][ACCUM]
Beispiel #29
0
def test_not_owner_steward_cant_edit_revoc_reg_entry(
        looper, txnPoolNodeSet, sdk_wallet_steward, sdk_wallet_trust_anchor,
        sdk_pool_handle, build_revoc_def_by_steward, claim_def, tconf):
    revoc_entry_req_steward = create_revoc_reg_entry(
        looper, txnPoolNodeSet, sdk_pool_handle, build_revoc_def_by_steward,
        claim_def, sdk_wallet_trust_anchor)

    revoc_entry_req_steward['operation'][VALUE][REVOKED] = [6, 7, 8]
    revoc_entry_req_steward['operation'][VALUE][
        PREV_ACCUM] = revoc_entry_req_steward['operation'][VALUE][ACCUM]

    revoc_entry_req_steward['operation'][VALUE][ACCUM] = randomString(10)
    revoc_entry_req_steward = sdk_sign_request_from_dict(
        looper, sdk_wallet_steward, revoc_entry_req_steward['operation'])
    with pytest.raises(RequestRejectedException):
        sdk_send_and_check([json.dumps(revoc_entry_req_steward)], looper,
                           txnPoolNodeSet, sdk_pool_handle)
def test_belated_request_not_processed_after_view_change(
        looper, txnPoolNodeSet, sdk_pool_handle, sdk_wallet_client):
    delta = txnPoolNodeSet[3]
    initial_ledger_size = delta.domainLedger.size
    delta.clientIbStasher.delay(req_delay(300))

    one_req = sdk_signed_random_requests(looper, sdk_wallet_client, 1)
    sdk_send_and_check(one_req, looper, txnPoolNodeSet, sdk_pool_handle)

    ensure_view_change(looper, txnPoolNodeSet)
    ensureElectionsDone(looper, txnPoolNodeSet)

    delta.clientIbStasher.reset_delays_and_process_delayeds()
    looper.runFor(waits.expectedTransactionExecutionTime(len(txnPoolNodeSet)))

    for node in txnPoolNodeSet:
        assert node.domainLedger.size - initial_ledger_size == 1
Beispiel #31
0
 def sdk_send_and_check(self, requests_signed, timeout=None):
     return plenum_helper.sdk_send_and_check(
         requests_signed,
         self._looper,
         self._node_pool,
         self._pool_handle,
         timeout
     )
Beispiel #32
0
def test_belated_request_not_processed_after_view_change(
        looper, txnPoolNodeSet, sdk_pool_handle, sdk_wallet_client):
    delta = txnPoolNodeSet[3]
    initial_ledger_size = delta.domainLedger.size
    delta.clientIbStasher.delay(req_delay(300))

    one_req = sdk_signed_random_requests(looper, sdk_wallet_client, 1)
    sdk_send_and_check(one_req, looper, txnPoolNodeSet, sdk_pool_handle)

    ensure_view_change(looper, txnPoolNodeSet)
    ensureElectionsDone(looper, txnPoolNodeSet)

    delta.clientIbStasher.reset_delays_and_process_delayeds()
    looper.runFor(waits.expectedTransactionExecutionTime(len(txnPoolNodeSet)))

    for node in txnPoolNodeSet:
        assert node.domainLedger.size - initial_ledger_size == 1
def test_send_with_from_by_demand(looper,
        txnPoolNodeSet,
        sdk_pool_handle,
        sdk_wallet_steward,
        send_revoc_reg_entry_by_demand,
        build_get_revoc_reg_delta):
    # We save timestamp of state changes.
    # looper and txnPoolNodeSet has "module", therefore,
    # when we send request with FROM section, it's not a clean situation
    looper.runFor(3)
    # Assume, that send_revoc_reg_entry_by_demand will add into issued [1,2,3,4,5]
    rev_reg_req1, rev_reg_reply1 = send_revoc_reg_entry_by_demand
    rev_reg_req1['operation'][VALUE][ISSUED] = []
    # Revoked [1,2,3], Issued now must be [4,5]
    rev_reg_req1['operation'][VALUE][REVOKED] = [1, 2, 3]
    rev_reg_req1['operation'][VALUE][PREV_ACCUM] = rev_reg_req1['operation'][VALUE][ACCUM]
    rev_reg_req1['operation'][VALUE][ACCUM] = randomString(10)
    rev_reg_req2, rev_reg_reply2 = sdk_send_and_check(
        [json.dumps(sdk_sign_request_from_dict(
            looper, sdk_wallet_steward, rev_reg_req1['operation']))],
        looper,
        txnPoolNodeSet,
        sdk_pool_handle)[0]
    # Issued [10, 11]
    rev_reg_req2['operation'][VALUE][ISSUED] = [10, 11]
    rev_reg_req2['operation'][VALUE][REVOKED] = []
    rev_reg_req2['operation'][VALUE][PREV_ACCUM] = rev_reg_req2['operation'][VALUE][ACCUM]
    rev_reg_req2['operation'][VALUE][ACCUM] = randomString(10)
    rev_reg_req3, rev_reg_reply3 = sdk_send_and_check(
        [json.dumps(sdk_sign_request_from_dict(
            looper, sdk_wallet_steward, rev_reg_req2['operation']))],
        looper,
        txnPoolNodeSet,
        sdk_pool_handle)[0]
    reg_delta_req = copy.deepcopy(build_get_revoc_reg_delta)
    reg_delta_req['operation'][REVOC_REG_DEF_ID] = rev_reg_req1['operation'][REVOC_REG_DEF_ID]
    reg_delta_req['operation'][FROM] = get_txn_time(rev_reg_reply1['result'])
    reg_delta_req['operation'][TO] = get_txn_time(rev_reg_reply3['result']) + 1000
    get_reply = sdk_send_and_check([json.dumps(reg_delta_req)], looper, txnPoolNodeSet, sdk_pool_handle)[0][1]
    assert get_reply['result'][DATA][STATE_PROOF_FROM]
    assert get_reply['result'][DATA][VALUE][REVOKED] == [1, 2, 3]
    assert get_reply['result'][DATA][VALUE][ISSUED] == [10, 11]
    assert get_reply['result'][DATA][VALUE][ACCUM_TO][VALUE][ACCUM] == rev_reg_req3['operation'][VALUE][ACCUM]
    assert get_reply['result'][DATA][VALUE][ACCUM_FROM][VALUE][ACCUM] == \
           get_payload_data(rev_reg_reply1['result'])[VALUE][ACCUM]
Beispiel #34
0
def create_revoc_reg_def(looper, txnPoolNodeSet, sdk_pool_handle, build_revoc,
                         claim_def, wallet):
    # We need to have claim_def to send revocation txns
    # must be signed by trust anchor since ANYONE_CAN_WRITE is false

    claim_def_req = sdk_sign_request_from_dict(looper, wallet, claim_def)
    sdk_send_and_check([json.dumps(claim_def_req)], looper, txnPoolNodeSet, sdk_pool_handle)

    _, author_did = wallet
    revoc_reg = build_revoc
    revoc_reg['operation'][CRED_DEF_ID] = \
        make_state_path_for_claim_def(author_did,
                                      str(claim_def_req['operation'][CLAIM_DEF_SCHEMA_REF]),
                                      claim_def_req['operation'][CLAIM_DEF_SIGNATURE_TYPE],
                                      claim_def_req['operation'][CLAIM_DEF_TAG]
                                      ).decode()
    revoc_req = sdk_sign_request_from_dict(looper, wallet, revoc_reg['operation'])
    _, revoc_reply = sdk_send_and_check([json.dumps(revoc_req)], looper, txnPoolNodeSet, sdk_pool_handle)[0]
    return revoc_req
def test_send_revoc_reg_def(looper, txnPoolNodeSet, sdk_wallet_steward,
                            sdk_pool_handle, build_revoc_def_by_default,
                            send_claim_def):
    txns_count_before = set([n.domainLedger.size for n in txnPoolNodeSet])
    assert len(txns_count_before) == 1, "Ledger size for nodes are not equal"
    _, author_did = sdk_wallet_steward
    claim_def_req = send_claim_def[0]
    revoc_req = build_revoc_def_by_default
    revoc_req['operation'][CRED_DEF_ID] = make_state_path_for_claim_def(
        author_did, str(claim_def_req['operation'][CLAIM_DEF_SCHEMA_REF]),
        claim_def_req['operation'][CLAIM_DEF_SIGNATURE_TYPE],
        claim_def_req['operation'][CLAIM_DEF_TAG]).decode()
    revoc_req = sdk_sign_request_from_dict(looper, sdk_wallet_steward,
                                           revoc_req['operation'])
    sdk_send_and_check([json.dumps(revoc_req)], looper, txnPoolNodeSet,
                       sdk_pool_handle)
    txns_count_after = set([n.domainLedger.size for n in txnPoolNodeSet])
    assert len(txns_count_after) == 1, "Ledger size for nodes are not equal"
    # REVOC_REG_DEF transaction was written
    assert txns_count_after.pop() - txns_count_before.pop() == 1
Beispiel #36
0
def client_send_revoc_reg_def(looper,
                              txnPoolNodeSet,
                              sdk_wallet_client,
                              sdk_pool_handle,
                              build_revoc_def_by_default,
                              claim_def):
    claim_def_req = sdk_sign_request_from_dict(looper, sdk_wallet_client, claim_def)
    sdk_send_and_check([json.dumps(claim_def_req)], looper, txnPoolNodeSet, sdk_pool_handle)

    _, author_did = sdk_wallet_client
    revoc_reg = build_revoc_def_by_default
    revoc_reg['operation'][CRED_DEF_ID] = \
        make_state_path_for_claim_def(author_did,
                                      str(claim_def_req['operation'][CLAIM_DEF_SCHEMA_REF]),
                                      claim_def_req['operation'][CLAIM_DEF_SIGNATURE_TYPE],
                                      claim_def_req['operation'][CLAIM_DEF_TAG]
                                      ).decode()
    revoc_req = sdk_sign_request_from_dict(looper, sdk_wallet_client, revoc_reg['operation'])
    _, revoc_reply = sdk_send_and_check([json.dumps(revoc_req)], looper, txnPoolNodeSet, sdk_pool_handle)[0]
    return revoc_req
def test_state_proof_returned_for_get_revoc_reg_delta(looper,
                                                      txnPoolNodeSet,
                                                      sdk_pool_handle,
                                                      sdk_wallet_steward,
                                                      send_revoc_reg_entry_by_default,
                                                      build_get_revoc_reg_delta):
    # We save timestamp of state changes.
    # looper and txnPoolNodeSet has "module" scope, therefore,
    # when we send request with FROM section, it's not a clean situation
    looper.runFor(3)
    # Assume, that send_revoc_reg_entry_by_default will add into revoked [1,2,3,4,5]
    rev_reg_req1, rev_reg_reply1 = send_revoc_reg_entry_by_default
    rev_reg_req1['operation'][VALUE][REVOKED] = []
    # Issue [1,2,3], Revoked now must be [4,5]
    rev_reg_req1['operation'][VALUE][ISSUED] = [1, 2, 3]
    rev_reg_req1['operation'][VALUE][PREV_ACCUM] = rev_reg_req1['operation'][VALUE][ACCUM]
    rev_reg_req1['operation'][VALUE][ACCUM] = randomString(10)
    rev_reg_req2, rev_reg_reply2 = sdk_send_and_check(
        [json.dumps(sdk_sign_request_from_dict(
            looper, sdk_wallet_steward, rev_reg_req1['operation']))],
        looper,
        txnPoolNodeSet,
        sdk_pool_handle)[0]
    # Revoke [10, 11]
    rev_reg_req2['operation'][VALUE][REVOKED] = [10, 11]
    rev_reg_req2['operation'][VALUE][ISSUED] = []
    rev_reg_req2['operation'][VALUE][PREV_ACCUM] = rev_reg_req2['operation'][VALUE][ACCUM]
    rev_reg_req2['operation'][VALUE][ACCUM] = randomString(10)
    rev_reg_req3, rev_reg_reply3 = sdk_send_and_check(
        [json.dumps(sdk_sign_request_from_dict(
            looper, sdk_wallet_steward, rev_reg_req2['operation']))],
        looper,
        txnPoolNodeSet,
        sdk_pool_handle)[0]
    reg_delta_req = copy.deepcopy(build_get_revoc_reg_delta)
    reg_delta_req['operation'][REVOC_REG_DEF_ID] = rev_reg_req1['operation'][REVOC_REG_DEF_ID]
    reg_delta_req['operation'][FROM] = get_txn_time(rev_reg_reply1['result'])
    reg_delta_req['operation'][TO] = get_txn_time(rev_reg_reply3['result']) + 1000
    sdk_reply = sdk_send_and_check([json.dumps(reg_delta_req)], looper, txnPoolNodeSet, sdk_pool_handle)
    reply = sdk_reply[0][1]
    check_valid_proof(reply)
Beispiel #38
0
def test_state_proof_returned_for_get_revoc_reg_delta(
        looper, txnPoolNodeSet, sdk_pool_handle, sdk_wallet_steward,
        send_revoc_reg_entry_by_default, build_get_revoc_reg_delta):
    # We save timestamp of state changes.
    # looper and txnPoolNodeSet has "module" scope, therefore,
    # when we send request with FROM section, it's not a clean situation
    looper.runFor(3)
    # Assume, that send_revoc_reg_entry_by_default will add into revoked [1,2,3,4,5]
    rev_reg_req1, rev_reg_reply1 = send_revoc_reg_entry_by_default
    rev_reg_req1['operation'][VALUE][REVOKED] = []
    # Issue [1,2,3], Revoked now must be [4,5]
    rev_reg_req1['operation'][VALUE][ISSUED] = [1, 2, 3]
    rev_reg_req1['operation'][VALUE][PREV_ACCUM] = rev_reg_req1['operation'][
        VALUE][ACCUM]
    rev_reg_req1['operation'][VALUE][ACCUM] = randomString(10)
    rev_reg_req2, rev_reg_reply2 = sdk_send_and_check([
        json.dumps(
            sdk_sign_request_from_dict(looper, sdk_wallet_steward,
                                       rev_reg_req1['operation']))
    ], looper, txnPoolNodeSet, sdk_pool_handle)[0]
    # Revoke [10, 11]
    rev_reg_req2['operation'][VALUE][REVOKED] = [10, 11]
    rev_reg_req2['operation'][VALUE][ISSUED] = []
    rev_reg_req2['operation'][VALUE][PREV_ACCUM] = rev_reg_req2['operation'][
        VALUE][ACCUM]
    rev_reg_req2['operation'][VALUE][ACCUM] = randomString(10)
    rev_reg_req3, rev_reg_reply3 = sdk_send_and_check([
        json.dumps(
            sdk_sign_request_from_dict(looper, sdk_wallet_steward,
                                       rev_reg_req2['operation']))
    ], looper, txnPoolNodeSet, sdk_pool_handle)[0]
    reg_delta_req = copy.deepcopy(build_get_revoc_reg_delta)
    reg_delta_req['operation'][REVOC_REG_DEF_ID] = rev_reg_req1['operation'][
        REVOC_REG_DEF_ID]
    reg_delta_req['operation'][FROM] = get_txn_time(rev_reg_reply1['result'])
    reg_delta_req['operation'][TO] = get_txn_time(
        rev_reg_reply3['result']) + 1000
    sdk_reply = sdk_send_and_check([json.dumps(reg_delta_req)], looper,
                                   txnPoolNodeSet, sdk_pool_handle)
    reply = sdk_reply[0][1]
    check_valid_proof(reply)
def test_state_proof_returned_for_get_revoc_reg(looper,
                                                txnPoolNodeSet,
                                                sdk_pool_handle,
                                                send_revoc_reg_entry_by_default,
                                                build_get_revoc_reg_entry):
    rev_entry_req, reg_reply = send_revoc_reg_entry_by_default
    get_revoc_reg = copy.deepcopy(build_get_revoc_reg_entry)
    get_revoc_reg['operation'][REVOC_REG_DEF_ID] = rev_entry_req['operation'][REVOC_REG_DEF_ID]
    get_revoc_reg['operation'][TIMESTAMP] = get_utc_epoch() + 1000
    sdk_reply = sdk_send_and_check([json.dumps(get_revoc_reg)], looper, txnPoolNodeSet, sdk_pool_handle)
    reply = sdk_reply[0][1]
    check_valid_proof(reply)
def test_state_proof_returned_for_get_revoc_reg_delta_with_only_to(
        looper, txnPoolNodeSet, sdk_pool_handle, sdk_wallet_steward,
        send_revoc_reg_entry_by_default, build_get_revoc_reg_delta):
    rev_reg_req, rev_reg_reply = send_revoc_reg_entry_by_default
    reg_delta_req = copy.deepcopy(build_get_revoc_reg_delta)
    del reg_delta_req['operation'][FROM]
    reg_delta_req['operation'][REVOC_REG_DEF_ID] = rev_reg_req['operation'][
        REVOC_REG_DEF_ID]
    reg_delta_req['operation'][TO] = get_utc_epoch() + 1000
    get_reply = sdk_send_and_check([json.dumps(reg_delta_req)], looper,
                                   txnPoolNodeSet, sdk_pool_handle)[0][1]
    check_valid_proof(get_reply)
def test_send_get_revoc_reg_later_then_first_entry(looper,
                            txnPoolNodeSet,
                            sdk_pool_handle,
                            send_revoc_reg_entry_by_default,
                            build_get_revoc_reg_entry):
    rev_entry_req, reg_reply = send_revoc_reg_entry_by_default
    get_revoc_reg = copy.deepcopy(build_get_revoc_reg_entry)
    get_revoc_reg['operation'][REVOC_REG_DEF_ID] = rev_entry_req['operation'][REVOC_REG_DEF_ID]
    get_revoc_reg['operation'][TIMESTAMP] = get_utc_epoch() + 1000
    sdk_reply = sdk_send_and_check([json.dumps(get_revoc_reg)], looper, txnPoolNodeSet, sdk_pool_handle)
    reply = sdk_reply[0][1]
    assert rev_entry_req['operation'][REVOC_REG_DEF_ID] == reply['result'][REVOC_REG_DEF_ID]
    assert rev_entry_req['operation'][VALUE][ACCUM] == reply['result']['data'][VALUE][ACCUM]
def test_state_proof_returned_for_get_revoc_reg_delta_with_only_to(
                                                      looper,
                                                      txnPoolNodeSet,
                                                      sdk_pool_handle,
                                                      sdk_wallet_steward,
                                                      send_revoc_reg_entry_by_default,
                                                      build_get_revoc_reg_delta):
    rev_reg_req, rev_reg_reply = send_revoc_reg_entry_by_default
    reg_delta_req = copy.deepcopy(build_get_revoc_reg_delta)
    del reg_delta_req['operation'][FROM]
    reg_delta_req['operation'][REVOC_REG_DEF_ID] = rev_reg_req['operation'][REVOC_REG_DEF_ID]
    reg_delta_req['operation'][TO] = get_utc_epoch() + 1000
    sdk_reply = sdk_send_and_check([json.dumps(reg_delta_req)], looper, txnPoolNodeSet, sdk_pool_handle)
    reply = sdk_reply[0][1]
    check_valid_proof(reply)
def test_send_with_only_to_by_demand(looper,
                            txnPoolNodeSet,
                            sdk_pool_handle,
                            send_revoc_reg_entry_by_demand,
                            build_get_revoc_reg_delta):
    rev_entry_req, reg_reply = send_revoc_reg_entry_by_demand
    get_revoc_reg_delta = copy.deepcopy(build_get_revoc_reg_delta)
    del get_revoc_reg_delta['operation'][FROM]
    get_revoc_reg_delta['operation'][REVOC_REG_DEF_ID] = rev_entry_req['operation'][REVOC_REG_DEF_ID]
    get_revoc_reg_delta['operation'][TO] = get_utc_epoch() + 1000
    sdk_reply = sdk_send_and_check([json.dumps(get_revoc_reg_delta)], looper, txnPoolNodeSet, sdk_pool_handle)
    reply = sdk_reply[0][1]
    assert rev_entry_req['operation'][REVOC_REG_DEF_ID] == reply['result'][REVOC_REG_DEF_ID]
    assert rev_entry_req['operation'][VALUE][ACCUM] == reply['result'][DATA][VALUE][ACCUM_TO][VALUE][ACCUM]
    assert rev_entry_req['operation'][VALUE][ISSUED] == reply['result'][DATA][VALUE][ISSUED]
Beispiel #44
0
def send_revoc_reg_entry_by_demand(looper,
                         txnPoolNodeSet,
                         sdk_wallet_steward,
                         sdk_pool_handle,
                         send_revoc_reg_def_by_demand):
    revoc_def_req = send_revoc_reg_def_by_demand
    rev_reg_entry = build_revoc_reg_entry_for_given_revoc_reg_def(revoc_def_req)
    rev_reg_entry[VALUE][ISSUED] = [1, 2, 3, 4, 5]
    del rev_reg_entry[VALUE][PREV_ACCUM]
    rev_entry_req = sdk_sign_request_from_dict(looper, sdk_wallet_steward, rev_reg_entry)
    reg_entry_replies = sdk_send_and_check([json.dumps(rev_entry_req)],
                       looper,
                       txnPoolNodeSet,
                       sdk_pool_handle)
    return reg_entry_replies[0]
def test_state_proof_returned_for_delta_with_None_reply(
                                                      looper,
                                                      txnPoolNodeSet,
                                                      sdk_pool_handle,
                                                      sdk_wallet_steward,
                                                      send_revoc_reg_entry_by_default,
                                                      build_get_revoc_reg_delta):
    rev_reg_req, rev_reg_reply = send_revoc_reg_entry_by_default
    reg_delta_req = copy.deepcopy(build_get_revoc_reg_delta)
    del reg_delta_req['operation'][FROM]
    reg_delta_req['operation'][REVOC_REG_DEF_ID] = rev_reg_req['operation'][REVOC_REG_DEF_ID]
    reg_delta_req['operation'][TO] = get_utc_epoch() - 1000
    sdk_reply = sdk_send_and_check([json.dumps(reg_delta_req)], looper, txnPoolNodeSet, sdk_pool_handle)
    reply = sdk_reply[0][1]
    assert STATE_PROOF not in reply['result']
def test_send_earlier_then_first_entry_by_demand(
        looper,
        txnPoolNodeSet,
        sdk_pool_handle,
        send_revoc_reg_entry_by_demand,
        build_get_revoc_reg_delta):
    rev_entry_req, reg_reply = send_revoc_reg_entry_by_demand
    get_revoc_reg_delta = copy.deepcopy(build_get_revoc_reg_delta)
    del get_revoc_reg_delta['operation'][FROM]
    get_revoc_reg_delta['operation'][REVOC_REG_DEF_ID] = rev_entry_req['operation'][REVOC_REG_DEF_ID]
    get_revoc_reg_delta['operation'][TO] = get_utc_epoch() - 1000
    sdk_reply = sdk_send_and_check([json.dumps(get_revoc_reg_delta)], looper, txnPoolNodeSet, sdk_pool_handle)
    reply = sdk_reply[0][1]
    assert reply['result'][DATA][REVOC_REG_DEF_ID] == rev_entry_req['operation'][REVOC_REG_DEF_ID]
    assert VALUE not in reply['result'][DATA]
    assert REVOC_TYPE not in reply['result'][DATA]
    assert reply['result'][f.SEQ_NO.nm] is None
    assert reply['result'][TXN_TIME] is None
def test_get_revoc_reg_def_from_uncommited(looper,
                                           txnPoolNodeSet,
                                           sdk_wallet_steward,
                                           sdk_pool_handle,
                                           send_revoc_reg_def_by_default):
    # REVOC_REG_DEF was added into pool by send_revoc_reg_def_by_default fixture

    _, author_did = sdk_wallet_steward
    revoc_req, _ = send_revoc_reg_def_by_default
    new_maxCredNum = 100
    revoc_req['operation'][VALUE][MAX_CRED_NUM] = new_maxCredNum
    revoc_req = sdk_sign_request_from_dict(looper, sdk_wallet_steward, revoc_req['operation'])

    # We apply transacttion, which will be not commited

    for node in txnPoolNodeSet:
        node.getDomainReqHandler().apply(Request(**revoc_req), int(time.time()))
    get_revoc_reg_def_req = {
        ID: ":".join([author_did,
                      domain.MARKER_REVOC_DEF,
                      revoc_req['operation'][CRED_DEF_ID],
                      revoc_req['operation'][REVOC_TYPE],
                      revoc_req['operation'][TAG]]),
        TXN_TYPE: GET_REVOC_REG_DEF,
    }
    get_revoc_reg_def_req = sdk_sign_request_from_dict(looper,
                                                       sdk_wallet_steward,
                                                       get_revoc_reg_def_req)

    # Send GET_REVOC_REG_DEF query.
    # We expects that commited REVOC_REG_DEF transaction will be returned

    replies = sdk_send_and_check([json.dumps(get_revoc_reg_def_req)],
                                 looper,
                                 txnPoolNodeSet,
                                 sdk_pool_handle)
    req, reply = replies[0]
    assert new_maxCredNum != reply['result']['data'][VALUE][MAX_CRED_NUM]
def test_state_proof_returned_for_get_revoc_reg_def(looper,
                                                    txnPoolNodeSet,
                                                    sdk_wallet_steward,
                                                    sdk_pool_handle,
                                                    send_revoc_reg_def_by_default):
    _, author_did = sdk_wallet_steward
    revoc_req, _ = send_revoc_reg_def_by_default
    get_revoc_reg_def_req = {
        ID: ":".join([author_did,
                      domain.MARKER_REVOC_DEF,
                      revoc_req['operation'][CRED_DEF_ID],
                      revoc_req['operation'][REVOC_TYPE],
                      revoc_req['operation'][TAG]]),
        TXN_TYPE: GET_REVOC_REG_DEF,
    }
    get_revoc_reg_def_req = sdk_sign_request_from_dict(looper,
                                                       sdk_wallet_steward,
                                                       get_revoc_reg_def_req)
    sdk_reply = sdk_send_and_check([json.dumps(get_revoc_reg_def_req)],
                                 looper,
                                 txnPoolNodeSet,
                                 sdk_pool_handle)
    reply = sdk_reply[0][1]
    check_valid_proof(reply)
def test_unordered_state_reverted_before_catchup(
        tconf, looper, txnPoolNodeSet, sdk_wallet_client, sdk_pool_handle):
    """
    Check that unordered state is reverted before starting catchup:
    - save the initial state on a node
    - slow down processing of COMMITs
    - send requests
    - wait until other nodes come to consensus
    - call start of catch-up
    - check that the state of the slow node is reverted and equal to the initial one.
    """
    # CONFIG

    ledger_id = DOMAIN_LEDGER_ID
    non_primary_node = getNonPrimaryReplicas(txnPoolNodeSet, instId=0)[0].node
    non_primary_ledger = non_primary_node.getLedger(ledger_id)
    non_primary_state = non_primary_node.getState(ledger_id)

    # send reqs and make sure we are at the same state

    reqs = sdk_signed_random_requests(looper, sdk_wallet_client, 10)
    sdk_send_and_check(reqs, looper, txnPoolNodeSet, sdk_pool_handle)
    checkNodesHaveSameRoots(txnPoolNodeSet)

    # the state of the node before
    committed_ledger_before = non_primary_ledger.tree.root_hash
    uncommitted_ledger_before = non_primary_ledger.uncommittedRootHash
    committed_state_before = non_primary_state.committedHeadHash
    uncommitted_state_before = non_primary_state.headHash

    # EXECUTE

    # Delay commit requests on the node
    delay_c = 60
    non_primary_node.nodeIbStasher.delay(cDelay(delay_c))

    # send requests
    reqs = sdk_send_random_requests(looper, sdk_pool_handle, sdk_wallet_client, tconf.Max3PCBatchSize)
    sdk_get_replies(looper, reqs, timeout=40)

    committed_ledger_during_3pc = non_primary_node.getLedger(
        ledger_id).tree.root_hash
    uncommitted_ledger_during_3pc = non_primary_node.getLedger(
        ledger_id).uncommittedRootHash
    committed_state_during_3pc = non_primary_node.getState(
        ledger_id).committedHeadHash
    uncommitted_state_during_3pc = non_primary_node.getState(
        ledger_id).headHash

    # start catchup
    non_primary_node.ledgerManager.preCatchupClbk(ledger_id)

    committed_ledger_reverted = non_primary_ledger.tree.root_hash
    uncommitted_ledger_reverted = non_primary_ledger.uncommittedRootHash
    committed_state_reverted = non_primary_state.committedHeadHash
    uncommitted_state_reverted = non_primary_state.headHash

    # CHECK

    # check that initial uncommitted state differs from the state during 3PC
    #  but committed does not
    assert committed_ledger_before == committed_ledger_during_3pc
    assert uncommitted_ledger_before != uncommitted_ledger_during_3pc
    assert committed_state_before == committed_state_during_3pc
    assert uncommitted_state_before != uncommitted_state_during_3pc

    assert committed_ledger_before == committed_ledger_reverted
    assert uncommitted_ledger_before == uncommitted_ledger_reverted
    assert committed_state_before == committed_state_reverted
    assert uncommitted_state_before == uncommitted_state_reverted