Exemplo n.º 1
0
def test_idr_cache_update_after_catchup(txnPoolNodeSet, looper,
                                        sdk_pool_handle, sdk_wallet_steward,
                                        tconf, tdir, allPluginsPath):
    wallet_handle, identifier = sdk_wallet_steward
    node_to_disconnect = txnPoolNodeSet[-1]
    disconnect_node_and_ensure_disconnected(looper,
                                            txnPoolNodeSet,
                                            node_to_disconnect.name,
                                            stopNode=True)
    looper.removeProdable(node_to_disconnect)

    idr, verkey = createHalfKeyIdentifierAndAbbrevVerkey()
    request = looper.loop.run_until_complete(
        build_nym_request(identifier, idr, verkey, None, None))
    req_signed = looper.loop.run_until_complete(
        sign_request(wallet_handle, identifier, request))
    result = json.loads(
        looper.loop.run_until_complete(
            submit_request(sdk_pool_handle, req_signed)))

    restarted_node = start_stopped_node(node_to_disconnect, looper, tconf,
                                        tdir, allPluginsPath)
    txnPoolNodeSet[-1] = restarted_node
    waitNodeDataEquality(looper, restarted_node, *txnPoolNodeSet[:-1])
    req_handler = restarted_node.get_req_handler(DOMAIN_LEDGER_ID)
    root_hash = req_handler.ts_store.get_equal_or_prev(
        get_txn_time(result['result']))
    key = domain.make_state_path_for_nym(idr)
    from_state = req_handler.state.get_for_root_hash(root_hash=root_hash,
                                                     key=key)
    assert from_state
    deserialized = req_handler.stateSerializer.deserialize(from_state)
    assert deserialized
    items_after = req_handler.idrCache.get(idr)
    assert items_after
def test_idr_cache_update_after_catchup(txnPoolNodeSet,
                                        looper,
                                        sdk_pool_handle,
                                        sdk_wallet_steward,
                                        tconf,
                                        tdir,
                                        allPluginsPath):
    wallet_handle, identifier = sdk_wallet_steward
    node_to_disconnect = txnPoolNodeSet[-1]
    disconnect_node_and_ensure_disconnected(looper,
                                            txnPoolNodeSet,
                                            node_to_disconnect.name,
                                            stopNode=True)
    looper.removeProdable(node_to_disconnect)

    idr, verkey = createHalfKeyIdentifierAndAbbrevVerkey()
    request = looper.loop.run_until_complete(build_nym_request(identifier, idr, verkey, None, None))
    req_signed = looper.loop.run_until_complete(sign_request(wallet_handle, identifier, request))
    result = json.loads(looper.loop.run_until_complete(submit_request(sdk_pool_handle, req_signed)))

    restarted_node = start_stopped_node(node_to_disconnect, looper,
                                        tconf, tdir, allPluginsPath)
    txnPoolNodeSet[-1] = restarted_node
    waitNodeDataEquality(looper, restarted_node, *txnPoolNodeSet[:-1])
    req_handler = restarted_node.getDomainReqHandler()
    root_hash = req_handler.ts_store.get_equal_or_prev(get_txn_time(result['result']))
    key = domain.make_state_path_for_nym(idr)
    from_state = req_handler.state.get_for_root_hash(root_hash=root_hash,
                                                     key=key)
    assert from_state
    deserialized = req_handler.stateSerializer.deserialize(from_state)
    assert deserialized
    items_after = req_handler.idrCache.get(idr)
    assert items_after
def test_idr_cache_update_after_catchup(txnPoolNodeSet,
                                        looper,
                                        sdk_pool_handle,
                                        sdk_wallet_steward):
    wallet_handle, identifier = sdk_wallet_steward
    node_to_disconnect = txnPoolNodeSet[-1]
    req_handler = node_to_disconnect.getDomainReqHandler()
    disconnect_node_and_ensure_disconnected(looper,
                                            txnPoolNodeSet,
                                            node_to_disconnect.name,
                                            stopNode=False)
    looper.runFor(2)
    idr, verkey = createHalfKeyIdentifierAndAbbrevVerkey()

    request = looper.loop.run_until_complete(build_nym_request(identifier, idr, verkey, None, None))
    req_signed = looper.loop.run_until_complete(sign_request(wallet_handle, identifier, request))
    result = json.loads(looper.loop.run_until_complete(submit_request(sdk_pool_handle, req_signed)))

    reconnect_node_and_ensure_connected(looper, txnPoolNodeSet, node_to_disconnect.name)
    waitNodeDataEquality(looper, node_to_disconnect, *txnPoolNodeSet)
    key = domain.make_state_path_for_nym(idr)
    root_hash = req_handler.ts_store.get_equal_or_prev(result['result']['txnTime'])
    from_state = req_handler.state.get_for_root_hash(root_hash=root_hash,
                                                     key=key)
    assert from_state
    deserialized = req_handler.stateSerializer.deserialize(from_state)
    assert deserialized
    items_after = req_handler.idrCache.get(idr)
    assert items_after
Exemplo n.º 4
0
def sdk_sign_request_from_dict(looper, sdk_wallet, op):
    wallet_h, did = sdk_wallet
    request = Request(operation=op, reqId=random.randint(10, 100000),
                      protocolVersion=CURRENT_PROTOCOL_VERSION, identifier=did)
    req_str = json.dumps(request.as_dict)
    resp = looper.loop.run_until_complete(sign_request(wallet_h, did, req_str))
    return json.loads(resp)
Exemplo n.º 5
0
def test_nym_send_twice(looper, sdk_pool_handle, sdk_wallet_steward):
    idr, verkey = createHalfKeyIdentifierAndAbbrevVerkey()

    wallet_handle, identifier = sdk_wallet_steward

    for i in range(2):
        request = looper.loop.run_until_complete(
            build_nym_request(identifier, idr, verkey, None, None))
        req_signed = looper.loop.run_until_complete(
            sign_request(wallet_handle, identifier, request))

        if i == 0:
            result = json.loads(
                looper.loop.run_until_complete(
                    submit_request(sdk_pool_handle, req_signed)))
            assert result['op'] == REPLY
        else:
            # TODO(INDY-1069): Ugly hack to deal with old libindy which raises exception on REJECT,
            # in fact it should be simple:
            # assert result['op'] == REJECT
            try:
                json.loads(
                    looper.loop.run_until_complete(
                        submit_request(sdk_pool_handle, req_signed)))
                assert False
            except IndyError as ex:
                assert ex.error_code == ErrorCode.LedgerInvalidTransaction
Exemplo n.º 6
0
def sdk_sign_request_strings(looper, sdk_wallet, reqs: Sequence):
    wallet_h, did = sdk_wallet
    reqs_str = [json.dumps(req) for req in reqs]
    reqs = [
        looper.loop.run_until_complete(sign_request(wallet_h, did, req))
        for req in reqs_str
    ]
    return reqs
Exemplo n.º 7
0
def sdk_sign_request_from_dict(looper, sdk_wallet, op, reqId=None):
    wallet_h, did = sdk_wallet
    reqId = reqId or random.randint(10, 100000)
    request = Request(operation=op, reqId=reqId,
                      protocolVersion=CURRENT_PROTOCOL_VERSION, identifier=did)
    req_str = json.dumps(request.as_dict)
    resp = looper.loop.run_until_complete(sign_request(wallet_h, did, req_str))
    return json.loads(resp)
Exemplo n.º 8
0
def test_nym_resend(looper, sdk_pool_handle, sdk_wallet_steward):
    idr, verkey = createHalfKeyIdentifierAndAbbrevVerkey()

    wallet_handle, identifier = sdk_wallet_steward

    request = looper.loop.run_until_complete(build_nym_request(identifier, idr, verkey, None, None))
    req_signed = looper.loop.run_until_complete(sign_request(wallet_handle, identifier, request))

    for i in range(2):
        result = json.loads(looper.loop.run_until_complete(submit_request(sdk_pool_handle, req_signed)))
        assert result['op'] == REPLY
Exemplo n.º 9
0
def req(request, looper, sdk_pool_handle, sdk_wallet_steward):
    wallet_handle, identifier = sdk_wallet_steward
    if request.param == "ATTRIB":
        raw = json.dumps({'answer': 42})
        request_json = looper.loop.run_until_complete(
            build_attrib_request(identifier,
                                 identifier,
                                 raw=raw,
                                 xhash=None,
                                 enc=None))
    elif request.param == "SCHEMA":
        _, schema_json = looper.loop.run_until_complete(
            issuer_create_schema(identifier, "name", "1.0",
                                 json.dumps(["first", "last"])))
        request_json = looper.loop.run_until_complete(
            build_schema_request(identifier, schema_json))
    elif request.param == "RS_SCHEMA":
        rs_schema = {'@id': "fakeId234e", '@type': "0od"}
        request_json = build_rs_schema_request(identifier, rs_schema,
                                               "ISO18023_Drivers_License",
                                               "1.1")
    elif request.param == "CLAIM_DEF":
        schema_json, _ = sdk_write_schema(looper, sdk_pool_handle,
                                          sdk_wallet_steward)
        schema_id = json.loads(schema_json)['id']

        request = looper.loop.run_until_complete(
            build_get_schema_request(identifier, schema_id))
        reply = sdk_get_reply(
            looper,
            sdk_sign_and_submit_req(sdk_pool_handle, sdk_wallet_steward,
                                    request))[1]
        _, schema_json = looper.loop.run_until_complete(
            parse_get_schema_response(json.dumps(reply)))

        _, definition_json = looper.loop.run_until_complete(
            issuer_create_and_store_credential_def(
                wallet_handle, identifier, schema_json, "some_tag", "CL",
                json.dumps({"support_revocation": True})))
        request_json = looper.loop.run_until_complete(
            build_cred_def_request(identifier, definition_json))
    elif request.param == "NYM":
        idr, verkey = createHalfKeyIdentifierAndAbbrevVerkey()
        request_json = looper.loop.run_until_complete(
            build_nym_request(identifier, idr, verkey, None, None))

    req_signed = looper.loop.run_until_complete(
        sign_request(wallet_handle, identifier, request_json))
    return Request(**json.loads(req_signed))
Exemplo n.º 10
0
def test_nym_resend(looper, sdk_pool_handle, sdk_wallet_steward):
    idr, verkey = createHalfKeyIdentifierAndAbbrevVerkey()

    wallet_handle, identifier = sdk_wallet_steward

    request = looper.loop.run_until_complete(
        build_nym_request(identifier, idr, verkey, None, None))
    req_signed = looper.loop.run_until_complete(
        sign_request(wallet_handle, identifier, request))

    for i in range(2):
        result = json.loads(
            looper.loop.run_until_complete(
                submit_request(sdk_pool_handle, req_signed)))
        assert result['op'] == REPLY
Exemplo n.º 11
0
def req(req_json, looper, sdk_wallet_steward):
    wallet_handle, identifier = sdk_wallet_steward
    req_signed = looper.loop.run_until_complete(
        sign_request(wallet_handle, identifier, req_json))
    return Request(**json.loads(req_signed))
Exemplo n.º 12
0
def sign_request_dict(looper, sdk_wallet, req_dict):
    wallet_h, did = sdk_wallet
    req_json = looper.loop.run_until_complete(
        sign_request(wallet_h, did, json.dumps(req_dict)))
    return json.loads(req_json)
Exemplo n.º 13
0
def sdk_sign_request_objects(looper, sdk_wallet, reqs: Sequence):
    wallet_h, did = sdk_wallet
    reqs_str = [json.dumps(req.as_dict) for req in reqs]
    resp = [looper.loop.run_until_complete(sign_request(wallet_h, did, req)) for req in reqs_str]
    return resp