def test_state_proof_returned_for_get_nym(looper, nodeSetWithOneNodeResponding, sdk_user_wallet_a, sdk_pool_handle, sdk_wallet_client, sdk_wallet_endorser): """ Tests that state proof is returned in the reply for GET_NYM transactions. Use different submitter and reader! """ _, dest = sdk_user_wallet_a nym_operation = {TARGET_NYM: dest, TXN_TYPE: NYM} sdk_submit_operation_and_get_result(looper, sdk_pool_handle, sdk_wallet_endorser, nym_operation) get_nym_operation = {TARGET_NYM: dest, TXN_TYPE: GET_NYM} result = sdk_submit_operation_and_get_result(looper, sdk_pool_handle, sdk_wallet_client, get_nym_operation) assert DATA in result assert result[DATA] data = domain_state_serializer.deserialize(result[DATA]) assert ROLE in data assert VERKEY in data assert f.IDENTIFIER.nm in data assert result[TXN_TIME] check_valid_proof(result)
def test_send_get_rich_schema_obj_by_no_metadata(looper, sdk_pool_handle, sdk_wallet_endorser, txn_type, rs_type, content, absent_meta): rs_id = randomString() rs_name = randomString() rs_version = '1.0' sdk_write_rich_schema_object_and_check(looper, sdk_wallet_endorser, sdk_pool_handle, txn_type=txn_type, rs_id=rs_id, rs_name=rs_name, rs_version=rs_version, rs_type=rs_type, rs_content=content) get_rich_schema_by_metadata_operation = { TXN_TYPE: GET_RICH_SCHEMA_OBJECT_BY_METADATA, RS_NAME: rs_name, RS_VERSION: rs_version, RS_TYPE: rs_type } get_rich_schema_by_metadata_operation.pop(absent_meta, None) with pytest.raises(RequestNackedException, match='missed fields'): sdk_submit_operation_and_get_result( looper, sdk_pool_handle, sdk_wallet_endorser, get_rich_schema_by_metadata_operation)
def test_send_get_rich_schema_obj_by_no_id(looper, sdk_pool_handle, sdk_wallet_endorser, txn_type, rs_type, content): rs_id = randomString() rs_name = randomString() rs_version = '1.0' sdk_write_rich_schema_object_and_check(looper, sdk_wallet_endorser, sdk_pool_handle, txn_type=txn_type, rs_id=rs_id, rs_name=rs_name, rs_version=rs_version, rs_type=rs_type, rs_content=content) get_rich_schema_by_id_operation = { TXN_TYPE: GET_RICH_SCHEMA_OBJECT_BY_ID, } with pytest.raises(RequestNackedException, match='missed fields'): sdk_submit_operation_and_get_result(looper, sdk_pool_handle, sdk_wallet_endorser, get_rich_schema_by_id_operation)
def test_send_get_rich_schema_obj_by_id_disabled_by_default(looper, sdk_pool_handle, sdk_wallet_endorser, txn_type, rs_type, content, rs_id, rs_name, rs_version, write_rich_schema): get_rich_schema_by_id_operation = { TXN_TYPE: GET_RICH_SCHEMA_OBJECT_BY_ID, RS_ID: rs_id, } with pytest.raises(RequestNackedException, match='RichSchema queries are disabled'): sdk_submit_operation_and_get_result(looper, sdk_pool_handle, sdk_wallet_endorser, get_rich_schema_by_id_operation)
def test_send_get_rich_schema_obj_by_no_id(looper, sdk_pool_handle, sdk_wallet_endorser, write_rich_schema, txn_type, rs_type, content, rs_id, rs_name, rs_version): get_rich_schema_by_id_operation = { TXN_TYPE: GET_RICH_SCHEMA_OBJECT_BY_ID, } with pytest.raises(RequestNackedException, match='missed fields'): sdk_submit_operation_and_get_result(looper, sdk_pool_handle, sdk_wallet_endorser, get_rich_schema_by_id_operation)
def test_state_proof_returned_for_get_context(looper, nodeSetWithOneNodeResponding, sdk_wallet_endorser, sdk_pool_handle, sdk_wallet_client): """ Tests that state proof is returned in the reply for GET_CONTEXT transactions. Use different submitter and reader! """ _, dest = sdk_wallet_endorser context_name = "test_context" context_version = "1.0" meta = { CONTEXT_NAME: context_name, CONTEXT_VERSION: context_version, RS_TYPE: CONTEXT_TYPE, } data = SIMPLE_CONTEXT context_operation = {TXN_TYPE: SET_CONTEXT, DATA: data, META: meta} sdk_submit_operation_and_get_result(looper, sdk_pool_handle, sdk_wallet_endorser, context_operation) get_context_operation = { TARGET_NYM: dest, TXN_TYPE: GET_CONTEXT, META: { CONTEXT_NAME: context_name, CONTEXT_VERSION: context_version, RS_TYPE: CONTEXT_TYPE } } result = sdk_submit_operation_and_get_result(looper, sdk_pool_handle, sdk_wallet_client, get_context_operation) assert DATA in result rdata = result.get(DATA) assert rdata assert DATA in rdata data = rdata[DATA] assert CONTEXT_CONTEXT in data assert data == SIMPLE_CONTEXT assert META in rdata meta = rdata[META] assert NAME in meta assert VERSION in meta assert result[TXN_TIME] check_valid_proof(result)
def test_state_proof_returned_for_get_rich_schema_obj_by_metadata( looper, nodeSetWithOneNodeResponding, sdk_wallet_endorser, sdk_pool_handle, sdk_wallet_client, write_rich_schema, txn_type, rs_type, content, rs_id, rs_name, rs_version): """ Tests that state proof is returned in the reply for GET_RICH_SCHEMA_OBJECT_BY_METADATA. Use different submitter and reader! """ get_rich_schema_by_metadata_operation = { TXN_TYPE: GET_RICH_SCHEMA_OBJECT_BY_METADATA, RS_NAME: rs_name, RS_VERSION: rs_version, RS_TYPE: rs_type } result = sdk_submit_operation_and_get_result( looper, sdk_pool_handle, sdk_wallet_client, get_rich_schema_by_metadata_operation) expected_data = SortedDict({ 'id': rs_id, 'rsType': rs_type, 'rsName': rs_name, 'rsVersion': rs_version, 'content': content, 'from': sdk_wallet_endorser[1] }) assert SortedDict(result['data']) == expected_data assert result['seqNo'] assert result['txnTime'] assert result['state_proof'] check_valid_proof(result)
def makeGetAttrRequest(looper, sdk_pool_handle, sdk_wallet, nym, raw): op = { TARGET_NYM: nym, TXN_TYPE: GET_ATTR, RAW: raw } return sdk_submit_operation_and_get_result(looper, sdk_pool_handle, sdk_wallet, op)
def test_send_get_rich_schema_obj_by_invalid_metadata( looper, sdk_pool_handle, sdk_wallet_endorser, txn_type, rs_type, content, invalid_meta_name, invalid_meta_value): rs_id = randomString() rs_name = randomString() rs_version = '1.0' sdk_write_rich_schema_object_and_check(looper, sdk_wallet_endorser, sdk_pool_handle, txn_type=txn_type, rs_id=rs_id, rs_name=rs_name, rs_version=rs_version, rs_type=rs_type, rs_content=content) get_rich_schema_by_metadata_operation = { TXN_TYPE: GET_RICH_SCHEMA_OBJECT_BY_METADATA, RS_NAME: rs_name, RS_VERSION: rs_version, RS_TYPE: rs_type } get_rich_schema_by_metadata_operation[ invalid_meta_name] = invalid_meta_value result = sdk_submit_operation_and_get_result( looper, sdk_pool_handle, sdk_wallet_endorser, get_rich_schema_by_metadata_operation) assert result['data'] is None assert result['seqNo'] is None assert result['txnTime'] is None assert result['state_proof'] check_valid_proof(result)
def test_state_proof_returned_for_get_attr(looper, nodeSetWithOneNodeResponding, sdk_added_raw_attribute, attributeName, attributeData, sdk_pool_handle, sdk_wallet_client): """ Tests that state proof is returned in the reply for GET_ATTR transactions. Use different submitter and reader! """ get_attr_operation = { TARGET_NYM: sdk_added_raw_attribute['result']['txn']['data']['dest'], TXN_TYPE: GET_ATTR, RAW: attributeName } result = sdk_submit_operation_and_get_result(looper, sdk_pool_handle, sdk_wallet_client, get_attr_operation) expected_data = attrib_raw_data_serializer.deserialize(attributeData) assert DATA in result data = attrib_raw_data_serializer.deserialize(result[DATA]) assert data == expected_data assert result[TXN_TIME] check_valid_proof(result)
def test_send_get_rich_schema_obj_by_invalid_id(looper, sdk_pool_handle, sdk_wallet_endorser, txn_type, rs_type, content): rs_id = randomString() rs_name = randomString() rs_version = '1.0' sdk_write_rich_schema_object_and_check(looper, sdk_wallet_endorser, sdk_pool_handle, txn_type=txn_type, rs_id=rs_id, rs_name=rs_name, rs_version=rs_version, rs_type=rs_type, rs_content=content) get_rich_schema_by_id_operation = { TXN_TYPE: GET_RICH_SCHEMA_OBJECT_BY_ID, RS_ID: randomString(), } result = sdk_submit_operation_and_get_result( looper, sdk_pool_handle, sdk_wallet_endorser, get_rich_schema_by_id_operation) assert result['data'] is None assert result['seqNo'] is None assert result['txnTime'] is None assert result['state_proof'] check_valid_proof(result)
def makeGetNymRequest(looper, sdk_pool_handle, sdk_wallet, nym): op = { TARGET_NYM: nym, TXN_TYPE: GET_NYM, } return sdk_submit_operation_and_get_result(looper, sdk_pool_handle, sdk_wallet, op)
def test_send_get_rich_schema_obj_by_metadata(looper, sdk_pool_handle, sdk_wallet_endorser, sdk_wallet_client, write_rich_schema, txn_type, rs_type, content, rs_id, rs_name, rs_version): get_rich_schema_by_metadata_operation = { TXN_TYPE: GET_RICH_SCHEMA_OBJECT_BY_METADATA, RS_NAME: rs_name, RS_VERSION: rs_version, RS_TYPE: rs_type } result = sdk_submit_operation_and_get_result( looper, sdk_pool_handle, sdk_wallet_client, get_rich_schema_by_metadata_operation) expected_data = SortedDict({ 'id': rs_id, 'rsType': rs_type, 'rsName': rs_name, 'rsVersion': rs_version, 'content': json.dumps(content), 'from': sdk_wallet_endorser[1], 'endorser': None, 'ver': None }) assert SortedDict(result['data']) == expected_data assert result['seqNo'] assert result['txnTime'] assert result['state_proof'] check_valid_proof(result)
def test_state_proof_returned_for_get_schema(looper, nodeSetWithOneNodeResponding, sdk_wallet_endorser, sdk_pool_handle, sdk_wallet_client): """ Tests that state proof is returned in the reply for GET_SCHEMA transactions. Use different submitter and reader! """ _, dest = sdk_wallet_endorser schema_name = "test_schema" schema_version = "1.0" schema_attr_names = ["width", "height"] data = { SCHEMA_NAME: schema_name, SCHEMA_VERSION: schema_version, SCHEMA_ATTR_NAMES: schema_attr_names } schema_operation = { TXN_TYPE: SCHEMA, DATA: data } sdk_submit_operation_and_get_result(looper, sdk_pool_handle, sdk_wallet_endorser, schema_operation) get_schema_operation = { TARGET_NYM: dest, TXN_TYPE: GET_SCHEMA, DATA: { NAME: schema_name, VERSION: schema_version, } } result = sdk_submit_operation_and_get_result(looper, sdk_pool_handle, sdk_wallet_client, get_schema_operation) assert DATA in result data = result.get(DATA) assert data assert SCHEMA_ATTR_NAMES in data assert data[SCHEMA_ATTR_NAMES] == schema_attr_names assert NAME in data assert VERSION in data assert result[TXN_TIME] check_valid_proof(result)
def makeGetClaimDefRequest(looper, sdk_pool_handle, sdk_wallet): op = { TXN_TYPE: GET_CLAIM_DEF, ORIGIN: '1' * 16, # must be a valid DID REF: 1, SIGNATURE_TYPE: 'any' } return sdk_submit_operation_and_get_result(looper, sdk_pool_handle, sdk_wallet, op)
def test_client_gets_read_reply_from_1_node_only(looper, nodeSetWithOneNodeResponding, sdk_added_raw_attribute, attributeName, sdk_pool_handle, sdk_wallet_trustee): """ Tests that client could send get-requests to only one node instead of n """ # Prepare and send get-request get_attr_operation = { TARGET_NYM: sdk_added_raw_attribute['result']['txn']['data']['dest'], TXN_TYPE: GET_ATTR, RAW: attributeName } sdk_submit_operation_and_get_result(looper, sdk_pool_handle, sdk_wallet_trustee, get_attr_operation)
def makeGetSchemaRequest(looper, sdk_pool_handle, sdk_wallet, nym): op = { TARGET_NYM: nym, TXN_TYPE: GET_SCHEMA, DATA: { NAME: 'foo', VERSION: '1.0', } } return sdk_submit_operation_and_get_result(looper, sdk_pool_handle, sdk_wallet, op)
def test_state_proof_returned_for_get_claim_def(looper, nodeSetWithOneNodeResponding, sdk_wallet_endorser, sdk_pool_handle, sdk_wallet_client, send_schema_seq_no): """ Tests that state proof is returned in the reply for GET_CLAIM_DEF transactions. Use different submitter and reader! """ _, dest = sdk_wallet_endorser data = {"primary": {'N': '123'}, REVOCATION: {'h0': '456'}} claim_def_operation = { TXN_TYPE: CLAIM_DEF, CLAIM_DEF_SCHEMA_REF: send_schema_seq_no, DATA: data, CLAIM_DEF_SIGNATURE_TYPE: 'CL', CLAIM_DEF_TAG: "tag1" } sdk_submit_operation_and_get_result(looper, sdk_pool_handle, sdk_wallet_endorser, claim_def_operation) get_claim_def_operation = { CLAIM_DEF_FROM: dest, TXN_TYPE: GET_CLAIM_DEF, CLAIM_DEF_SCHEMA_REF: send_schema_seq_no, CLAIM_DEF_SIGNATURE_TYPE: 'CL', CLAIM_DEF_TAG: "tag1" } result = sdk_submit_operation_and_get_result(looper, sdk_pool_handle, sdk_wallet_client, get_claim_def_operation) expected_data = data assert DATA in result data = result.get(DATA) assert data assert data == expected_data assert result[TXN_TIME] check_valid_proof(result)
def test_state_proof_returned_for_missing_attr(looper, nodeSetWithOneNodeResponding, attributeName, sdk_pool_handle, sdk_wallet_trust_anchor): """ Tests that state proof is returned in the reply for GET_ATTR transactions """ _, dest = sdk_wallet_trust_anchor get_attr_operation = { TARGET_NYM: dest, TXN_TYPE: GET_ATTR, RAW: attributeName } result = sdk_submit_operation_and_get_result(looper, sdk_pool_handle, sdk_wallet_trust_anchor, get_attr_operation) check_no_data_and_valid_proof(result)
def test_state_proof_returned_for_missing_get_rich_schema_obj_by_id( looper, nodeSetWithOneNodeResponding, sdk_wallet_endorser, sdk_pool_handle, sdk_wallet_client): """ Tests that state proof is returned in the reply for GET_RICH_SCHEMA_OBJECT_BY_ID. Use different submitter and reader! """ rs_id = randomString() get_rich_schema_by_id_operation = { TXN_TYPE: GET_RICH_SCHEMA_OBJECT_BY_ID, RS_ID: rs_id, } result = sdk_submit_operation_and_get_result( looper, sdk_pool_handle, sdk_wallet_client, get_rich_schema_by_id_operation) check_no_data_and_valid_proof(result)
def test_state_proof_returned_for_missing_claim_def(looper, nodeSetWithOneNodeResponding, sdk_pool_handle, sdk_wallet_trust_anchor): """ Tests that state proof is returned in the reply for GET_CLAIM_DEF transactions """ _, dest = sdk_wallet_trust_anchor get_claim_def_operation = { CLAIM_DEF_FROM: dest, TXN_TYPE: GET_CLAIM_DEF, CLAIM_DEF_SCHEMA_REF: 12, CLAIM_DEF_SIGNATURE_TYPE: 'CL' } result = sdk_submit_operation_and_get_result(looper, sdk_pool_handle, sdk_wallet_trust_anchor, get_claim_def_operation) check_no_data_and_valid_proof(result)
def test_state_proof_returned_for_missing_nym(looper, nodeSetWithOneNodeResponding, sdk_pool_handle, sdk_wallet_endorser, sdk_user_wallet_a): """ Tests that state proof is returned in the reply for GET_NYM transactions """ # Make not existing id _, dest = sdk_user_wallet_a dest = dest[:-3] dest += "fff" get_nym_operation = {TARGET_NYM: dest, TXN_TYPE: GET_NYM} result = sdk_submit_operation_and_get_result(looper, sdk_pool_handle, sdk_wallet_endorser, get_nym_operation) check_no_data_and_valid_proof(result)
def test_state_proof_returned_for_missing_get_rich_schema_obj_by_metadata( looper, nodeSetWithOneNodeResponding, sdk_wallet_endorser, sdk_pool_handle, sdk_wallet_client, rs_type): """ Tests that state proof is returned in the reply for GET_RICH_SCHEMA_OBJECT_BY_ID. Use different submitter and reader! """ rs_name = randomString() rs_version = '1.0' get_rich_schema_by_metadata_operation = { TXN_TYPE: GET_RICH_SCHEMA_OBJECT_BY_METADATA, RS_NAME: rs_name, RS_VERSION: rs_version, RS_TYPE: rs_type } result = sdk_submit_operation_and_get_result( looper, sdk_pool_handle, sdk_wallet_client, get_rich_schema_by_metadata_operation) check_no_data_and_valid_proof(result)
def test_state_proof_returned_for_get_rich_schema_obj_by_id( looper, nodeSetWithOneNodeResponding, sdk_wallet_endorser, sdk_pool_handle, sdk_wallet_client, txn_type, rs_type, content): """ Tests that state proof is returned in the reply for GET_RICH_SCHEMA_OBJECT_BY_ID. Use different submitter and reader! """ rs_id = randomString() rs_name = randomString() rs_version = '1.0' sdk_write_rich_schema_object_and_check(looper, sdk_wallet_endorser, sdk_pool_handle, txn_type=txn_type, rs_id=rs_id, rs_name=rs_name, rs_version=rs_version, rs_type=rs_type, rs_content=content) get_rich_schema_by_id_operation = { TXN_TYPE: GET_RICH_SCHEMA_OBJECT_BY_ID, RS_ID: rs_id, } result = sdk_submit_operation_and_get_result( looper, sdk_pool_handle, sdk_wallet_client, get_rich_schema_by_id_operation) expected_data = SortedDict({ 'id': rs_id, 'rsType': rs_type, 'rsName': rs_name, 'rsVersion': rs_version, 'content': content, 'from': sdk_wallet_endorser[1] }) assert SortedDict(result['data']) == expected_data assert result['seqNo'] assert result['txnTime'] assert result['state_proof'] check_valid_proof(result)
def test_send_get_rich_schema_obj_by_id(looper, sdk_pool_handle, sdk_wallet_endorser, txn_type, rs_type, content): rs_id = randomString() rs_name = randomString() rs_version = '1.0' sdk_write_rich_schema_object_and_check(looper, sdk_wallet_endorser, sdk_pool_handle, txn_type=txn_type, rs_id=rs_id, rs_name=rs_name, rs_version=rs_version, rs_type=rs_type, rs_content=content) get_rich_schema_by_id_operation = { TXN_TYPE: GET_RICH_SCHEMA_OBJECT_BY_ID, RS_ID: rs_id, } result = sdk_submit_operation_and_get_result( looper, sdk_pool_handle, sdk_wallet_endorser, get_rich_schema_by_id_operation) expected_data = SortedDict({ 'id': rs_id, 'rsType': rs_type, 'rsName': rs_name, 'rsVersion': rs_version, 'content': json.dumps(content), 'from': sdk_wallet_endorser[1], 'endorser': None, 'ver': None }) assert SortedDict(result['data']) == expected_data assert result['seqNo'] assert result['txnTime'] assert result['state_proof'] check_valid_proof(result)
def test_state_proof_returned_for_missing_schema(looper, nodeSetWithOneNodeResponding, sdk_pool_handle, sdk_wallet_trust_anchor): """ Tests that state proof is returned in the reply for GET_SCHEMA transactions """ _, dest = sdk_wallet_trust_anchor schema_name = "test_schema" schema_version = "1.0" get_schema_operation = { TARGET_NYM: dest, TXN_TYPE: GET_SCHEMA, DATA: { SCHEMA_NAME: schema_name, SCHEMA_VERSION: schema_version, } } result = sdk_submit_operation_and_get_result(looper, sdk_pool_handle, sdk_wallet_trust_anchor, get_schema_operation) assert SCHEMA_ATTR_NAMES not in result[DATA] check_valid_proof(result)
def test_state_proof_returned_for_missing_context(looper, nodeSet, sdk_pool_handle, sdk_wallet_endorser): """ Tests that state proof is returned in the reply for GET_CONTEXT transactions """ _, dest = sdk_wallet_endorser context_name = "test_context" context_version = "1.0" get_context_operation = { TARGET_NYM: dest, TXN_TYPE: GET_CONTEXT, META: { CONTEXT_NAME: context_name, CONTEXT_VERSION: context_version, RS_TYPE: CONTEXT_TYPE } } result = sdk_submit_operation_and_get_result(looper, sdk_pool_handle, sdk_wallet_endorser, get_context_operation) assert not result[DATA] check_valid_proof(result)