def test_get_subject_credential_status(mock_alastria_credential_registry):
    web3_mock = Mock()
    subject_credential_hash = '0x1234'
    subject_address = 'e53d78c1c6fc694a0f29b3f24bee439338acbe3e'
    subject_did = f'did:ala:quor:redT:{subject_address}'
    mock_alastria_credential_registry(
        web3_mock
    ).encodeABI.return_value = 'getSubjectCredentialStatusReturnValue'
    expected_transaction = {
        'to': Web3.toChecksumAddress(CREDENTIAL_REGISTRY_ADDRESS),
        'data': 'getSubjectCredentialStatusReturnValue',
        'gasPrice': 0,
        'gas': 600000,
        'nonce': '0x0'
    }
    service = CredentialRegistryService(web3_mock)

    transaction = service.get_subject_credential_status(
        subject_did, subject_credential_hash)

    mock_alastria_credential_registry.assert_called_with(web3_mock)
    mock_alastria_credential_registry(web3_mock).encodeABI.assert_called_with(
        fn_name='getSubjectCredentialStatus',
        args=[subject_address, subject_credential_hash])
    assert asdict(transaction) == expected_transaction
def test_update_credential_status(mock_alastria_credential_registry,
                                  mock_delegated):
    web3_mock = Mock()
    status = 2
    issuer_credential_hash = '0x1234'
    mock_alastria_credential_registry(
        web3_mock).encodeABI.return_value = 'updateCredentialStatusReturnValue'
    mock_delegated.return_value = 'delegatedReturnValue'
    expected_transaction = {
        'to': Web3.toChecksumAddress(CREDENTIAL_REGISTRY_ADDRESS),
        'data': 'delegatedReturnValue',
        'gasPrice': 0,
        'gas': 600000,
        'nonce': '0x0'
    }
    service = CredentialRegistryService(web3_mock)

    transaction = service.update_credential_status(issuer_credential_hash,
                                                   status)

    mock_alastria_credential_registry.assert_called_with(web3_mock)
    mock_alastria_credential_registry(web3_mock).encodeABI.assert_called_with(
        fn_name='updateCredentialStatus',
        args=[issuer_credential_hash, status])
    mock_delegated.assert_called_with('updateCredentialStatusReturnValue')
    assert asdict(transaction) == expected_transaction
def test_delegated_call(mock_alastria_identity_manager):
    web3_mock = Mock()
    data = 'exampleData'
    mock_alastria_identity_manager(
        web3_mock).encodeABI.return_value = 'delegatedValue'
    service = CredentialRegistryService(web3_mock)

    transaction = service.delegated(data)

    mock_alastria_identity_manager.assert_called_with(web3_mock)
    mock_alastria_identity_manager(web3_mock).encodeABI.assert_called_with(
        fn_name='delegateCall',
        args=[Web3.toChecksumAddress(CREDENTIAL_REGISTRY_ADDRESS), 0, data])
    assert transaction == 'delegatedValue'
def test_get_credential_status(mock_alastria_credential_registry):
    web3_mock = Mock()
    subject_status = 2
    issuer_status = 2
    mock_alastria_credential_registry(
        web3_mock).encodeABI.return_value = 'getCredentialStatusReturnValue'
    expected_transaction = {
        'to': Web3.toChecksumAddress(CREDENTIAL_REGISTRY_ADDRESS),
        'data': 'getCredentialStatusReturnValue',
        'gasPrice': 0,
        'gas': 600000,
        'nonce': '0x0'
    }
    service = CredentialRegistryService(web3_mock)

    transaction = service.get_credential_status(subject_status, issuer_status)

    mock_alastria_credential_registry.assert_called_with(web3_mock)
    mock_alastria_credential_registry(web3_mock).encodeABI.assert_called_with(
        fn_name='getCredentialStatus', args=[subject_status, issuer_status])
    assert asdict(transaction) == expected_transaction
def test_delete_subject_credential(mock_alastria_credential_registry,
                                   mock_delegated):
    web3_mock = Mock()
    subject_credential_hash = '0x1234'
    mock_alastria_credential_registry(
        web3_mock
    ).encodeABI.return_value = 'deleteSubjectCredentialReturnValue'
    mock_delegated.return_value = 'delegatedReturnValue'
    expected_transaction = {
        'to': Web3.toChecksumAddress(CREDENTIAL_REGISTRY_ADDRESS),
        'data': 'delegatedReturnValue',
        'gasPrice': 0,
        'gas': 600000,
        'nonce': '0x0'
    }
    service = CredentialRegistryService(web3_mock)

    transaction = service.delete_subject_credential(subject_credential_hash)

    mock_alastria_credential_registry.assert_called_with(web3_mock)
    mock_alastria_credential_registry(web3_mock).encodeABI.assert_called_with(
        fn_name='deleteSubjectCredential', args=[subject_credential_hash])
    mock_delegated.assert_called_with('deleteSubjectCredentialReturnValue')
    assert asdict(transaction) == expected_transaction